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

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


changeset:   862:4b2d36e5021d
tag:         tip
user:        Walter Landry <wlandry at caltech.edu>
date:        Thu May 12 11:19:19 2011 -0700
files:       Rheology/src/AlignmentSwarmVariable.c Rheology/src/AlignmentSwarmVariable.cxx Rheology/src/Anisotropic.c Rheology/src/Anisotropic.cxx Rheology/src/Arrhenius.c Rheology/src/Arrhenius.cxx Rheology/src/Byerlee.c Rheology/src/Byerlee.cxx Rheology/src/Compressible.c Rheology/src/Compressible.cxx Rheology/src/ConstitutiveMatCartesian_Refactored.c Rheology/src/ConstitutiveMatCartesian_Refactored.cxx Rheology/src/ConstitutiveMat_Refactored.c Rheology/src/ConstitutiveMat_Refactored.cxx Rheology/src/ConstitutiveMatrix.c Rheology/src/ConstitutiveMatrix.cxx Rheology/src/ConstitutiveMatrixCartesian.c Rheology/src/ConstitutiveMatrixCartesian.cxx Rheology/src/DepthDependentViscosity.c Rheology/src/DepthDependentViscosity.cxx Rheology/src/Director.c Rheology/src/Director.cxx Rheology/src/DruckerPrager.c Rheology/src/DruckerPrager.cxx Rheology/src/FaultingMoresiMuhlhaus2006.c Rheology/src/FaultingMoresiMuhlhaus2006.cxx Rheology/src/Finalise.c Rheology/src/Finalise.cxx Rheology/src/FrankKamenetskii.c Rheology/src/FrankKamenetskii.cxx Rheology/src/Init.c Rheology/src/Init.cxx Rheology/src/LinearViscosity.c Rheology/src/LinearViscosity.cxx Rheology/src/MaterialViscosity.c Rheology/src/MaterialViscosity.cxx Rheology/src/MohrCoulomb.c Rheology/src/MohrCoulomb.cxx Rheology/src/MultiRheologyMaterial.c Rheology/src/MultiRheologyMaterial.cxx Rheology/src/NonNewtonian.c Rheology/src/NonNewtonian.cxx Rheology/src/Orthotropic.c Rheology/src/Orthotropic.cxx Rheology/src/OrthotropicAligned.c Rheology/src/OrthotropicAligned.cxx Rheology/src/Pouliquen_etal.c Rheology/src/Pouliquen_etal.cxx Rheology/src/RheologyClass.c Rheology/src/RheologyClass.cxx Rheology/src/RheologyMaterial.c Rheology/src/RheologyMaterial.cxx Rheology/src/Rheology_Register.c Rheology/src/Rheology_Register.cxx Rheology/src/StoreStress.c Rheology/src/StoreStress.cxx Rheology/src/StoreViscosity.c Rheology/src/StoreViscosity.cxx Rheology/src/StrainWeakening.c Rheology/src/StrainWeakening.cxx Rheology/src/ViscosityFieldRheology.c Rheology/src/ViscosityFieldRheology.cxx Rheology/src/VonMises.c Rheology/src/VonMises.cxx Rheology/src/YieldRheology.c Rheology/src/YieldRheology.cxx Rheology/tests/ByerleeYieldingSuite.c Rheology/tests/ByerleeYieldingSuite.cxx Rheology/tests/ConstitutiveMatrixSuite.c Rheology/tests/ConstitutiveMatrixSuite.cxx Rheology/tests/DirectorSuite.c Rheology/tests/DirectorSuite.cxx Rheology/tests/LateralViscosityAnalytic/LateralViscosityAnalytic.c Rheology/tests/LateralViscosityAnalytic/LateralViscosityAnalytic.cxx Rheology/tests/NonNewtonianShearSolution/NonNewtonianShearSolution.c Rheology/tests/NonNewtonianShearSolution/NonNewtonianShearSolution.cxx Rheology/tests/ViscousSuite.c Rheology/tests/ViscousSuite.cxx Rheology/tests/VonMisesYieldingSuite.c Rheology/tests/VonMisesYieldingSuite.cxx Rheology/tests/testYieldCriterion/testYieldCriterion.c Rheology/tests/testYieldCriterion/testYieldCriterion.cxx SConscript SysTest/AnalyticPlugins/DepthDependentAnalytic3D/DepthDependentAnalytic3D.c SysTest/AnalyticPlugins/DepthDependentAnalytic3D/DepthDependentAnalytic3D.cxx SysTest/AnalyticPlugins/LateralViscosityAnalytic/LateralViscosityAnalytic.c SysTest/AnalyticPlugins/LateralViscosityAnalytic/LateralViscosityAnalytic.cxx SysTest/AnalyticPlugins/NonNewtonianShearSolution/NonNewtonianShearSolution.c SysTest/AnalyticPlugins/NonNewtonianShearSolution/NonNewtonianShearSolution.cxx SysTest/AnalyticPlugins/Trubitsyn2006/Trubitsyn2006.c SysTest/AnalyticPlugins/Trubitsyn2006/Trubitsyn2006.cxx SysTest/AnalyticPlugins/VelicIC/VelicIC.c SysTest/AnalyticPlugins/VelicIC/VelicIC.cxx SysTest/AnalyticPlugins/Velic_solA/Analytic_solA.c SysTest/AnalyticPlugins/Velic_solA/Analytic_solA.cxx SysTest/AnalyticPlugins/Velic_solA/solA.c SysTest/AnalyticPlugins/Velic_solA/solA.cxx SysTest/AnalyticPlugins/Velic_solB/Analytic_solB.c SysTest/AnalyticPlugins/Velic_solB/Analytic_solB.cxx SysTest/AnalyticPlugins/Velic_solB/solB.c SysTest/AnalyticPlugins/Velic_solB/solB.cxx SysTest/AnalyticPlugins/Velic_solC/Analytic_solC.c SysTest/AnalyticPlugins/Velic_solC/Analytic_solC.cxx SysTest/AnalyticPlugins/Velic_solC/solC.c SysTest/AnalyticPlugins/Velic_solC/solC.cxx SysTest/AnalyticPlugins/Velic_solCA/Analytic_solCA.c SysTest/AnalyticPlugins/Velic_solCA/Analytic_solCA.cxx SysTest/AnalyticPlugins/Velic_solCA/solCA.c SysTest/AnalyticPlugins/Velic_solCA/solCA.cxx SysTest/AnalyticPlugins/Velic_solCx/Analytic_solCx.c SysTest/AnalyticPlugins/Velic_solCx/Analytic_solCx.cxx SysTest/AnalyticPlugins/Velic_solCx/solCx.c SysTest/AnalyticPlugins/Velic_solCx/solCx.cxx SysTest/AnalyticPlugins/Velic_solDA/Analytic_solDA.c SysTest/AnalyticPlugins/Velic_solDA/Analytic_solDA.cxx SysTest/AnalyticPlugins/Velic_solDA/solDA.c SysTest/AnalyticPlugins/Velic_solDA/solDA.cxx SysTest/AnalyticPlugins/Velic_solE/Analytic_solE.c SysTest/AnalyticPlugins/Velic_solE/Analytic_solE.cxx SysTest/AnalyticPlugins/Velic_solE/solE.c SysTest/AnalyticPlugins/Velic_solE/solE.cxx SysTest/AnalyticPlugins/Velic_solF/Analytic_solF.c SysTest/AnalyticPlugins/Velic_solF/Analytic_solF.cxx SysTest/AnalyticPlugins/Velic_solF/solF.c SysTest/AnalyticPlugins/Velic_solF/solF.cxx SysTest/AnalyticPlugins/Velic_solG/Analytic_solG.c SysTest/AnalyticPlugins/Velic_solG/Analytic_solG.cxx SysTest/AnalyticPlugins/Velic_solG/solG.c SysTest/AnalyticPlugins/Velic_solG/solG.cxx SysTest/AnalyticPlugins/Velic_solH/Analytic_solH.c SysTest/AnalyticPlugins/Velic_solH/Analytic_solH.cxx SysTest/AnalyticPlugins/Velic_solH/solH.c SysTest/AnalyticPlugins/Velic_solH/solH.cxx SysTest/AnalyticPlugins/Velic_solHA/Analytic_solHA.c SysTest/AnalyticPlugins/Velic_solHA/Analytic_solHA.cxx SysTest/AnalyticPlugins/Velic_solHA/solHA.c SysTest/AnalyticPlugins/Velic_solHA/solHA.cxx SysTest/AnalyticPlugins/Velic_solHAy/Analytic_solHAy.c SysTest/AnalyticPlugins/Velic_solHAy/Analytic_solHAy.cxx SysTest/AnalyticPlugins/Velic_solHAy/solHAy.c SysTest/AnalyticPlugins/Velic_solHAy/solHAy.cxx SysTest/AnalyticPlugins/Velic_solHy/Analytic_solHy.c SysTest/AnalyticPlugins/Velic_solHy/Analytic_solHy.cxx SysTest/AnalyticPlugins/Velic_solHy/solHy.c SysTest/AnalyticPlugins/Velic_solHy/solHy.cxx SysTest/AnalyticPlugins/Velic_solI/Analytic_solI.c SysTest/AnalyticPlugins/Velic_solI/Analytic_solI.cxx SysTest/AnalyticPlugins/Velic_solI/solI.c SysTest/AnalyticPlugins/Velic_solI/solI.cxx SysTest/AnalyticPlugins/Velic_solIA/Analytic_solIA.c SysTest/AnalyticPlugins/Velic_solIA/Analytic_solIA.cxx SysTest/AnalyticPlugins/Velic_solIA/solIA.c SysTest/AnalyticPlugins/Velic_solIA/solIA.cxx SysTest/AnalyticPlugins/Velic_solJ/Analytic_solJ.c SysTest/AnalyticPlugins/Velic_solJ/Analytic_solJ.cxx SysTest/AnalyticPlugins/Velic_solJ/solJ.c SysTest/AnalyticPlugins/Velic_solJ/solJ.cxx SysTest/AnalyticPlugins/Velic_solJA/Analytic_solJA.c SysTest/AnalyticPlugins/Velic_solJA/Analytic_solJA.cxx SysTest/AnalyticPlugins/Velic_solJA/solJA.c SysTest/AnalyticPlugins/Velic_solJA/solJA.cxx SysTest/AnalyticPlugins/Velic_solKx/Analytic_solKx.c SysTest/AnalyticPlugins/Velic_solKx/Analytic_solKx.cxx SysTest/AnalyticPlugins/Velic_solKx/solKx.c SysTest/AnalyticPlugins/Velic_solKx/solKx.cxx SysTest/AnalyticPlugins/Velic_solKz/Analytic_solKz.c SysTest/AnalyticPlugins/Velic_solKz/Analytic_solKz.cxx SysTest/AnalyticPlugins/Velic_solKz/solKz.c SysTest/AnalyticPlugins/Velic_solKz/solKz.cxx SysTest/AnalyticPlugins/Velic_solL/Analytic_solL.c SysTest/AnalyticPlugins/Velic_solL/Analytic_solL.cxx SysTest/AnalyticPlugins/Velic_solL/solL.c SysTest/AnalyticPlugins/Velic_solL/solL.cxx SysTest/AnalyticPlugins/Velic_solS/Analytic_solS.c SysTest/AnalyticPlugins/Velic_solS/Analytic_solS.cxx SysTest/AnalyticPlugins/Velic_solS/solS.c SysTest/AnalyticPlugins/Velic_solS/solS.cxx Utils/src/BaseRecoveryFeVar.c Utils/src/BaseRecoveryFeVar.cxx Utils/src/DensityField.c Utils/src/DensityField.cxx Utils/src/DivergenceForce.c Utils/src/DivergenceForce.cxx Utils/src/Finalise.c Utils/src/Finalise.cxx Utils/src/Init.c Utils/src/Init.cxx Utils/src/MixedStabiliserTerm.c Utils/src/MixedStabiliserTerm.cxx Utils/src/NodalPressureField.c Utils/src/NodalPressureField.cxx Utils/src/REP_Algorithm.c Utils/src/REP_Algorithm.cxx Utils/src/RadiogenicHeatingTerm.c Utils/src/RadiogenicHeatingTerm.cxx Utils/src/RecoveredFeVariable.c Utils/src/RecoveredFeVariable.cxx Utils/src/SPR_StrainRate.c Utils/src/SPR_StrainRate.cxx Utils/src/SmoothVelGradField.c Utils/src/SmoothVelGradField.cxx Utils/src/StressBC.c Utils/src/StressBC.cxx Utils/src/StressField.c Utils/src/StressField.cxx Utils/src/TracerOutput.c Utils/src/TracerOutput.cxx Utils/src/UnderworldContext.c Utils/src/UnderworldContext.cxx Utils/src/Underworld_SwarmOutput.c Utils/src/Underworld_SwarmOutput.cxx Utils/src/ViscosityField.c Utils/src/ViscosityField.cxx Utils/src/Wall.c Utils/src/Wall.cxx Utils/src/XDMFGenerator.c Utils/src/XDMFGenerator.cxx libUnderworld/Toolbox/Toolbox.c libUnderworld/Toolbox/Toolbox.cxx libUnderworld/src/Finalise.c libUnderworld/src/Finalise.cxx libUnderworld/src/Init.c libUnderworld/src/Init.cxx libUnderworld/tests/testLibUnderworld.c libUnderworld/tests/testLibUnderworld.cxx plugins/DensityChangeAtDepth/DensityChangeAtDepth.c plugins/DensityChangeAtDepth/DensityChangeAtDepth.cxx plugins/EulerDeform/EulerDeform.c plugins/EulerDeform/EulerDeform.cxx plugins/ExtractPetscObjects/ExtractPetscObjects.c plugins/ExtractPetscObjects/ExtractPetscObjects.cxx plugins/HRS_Erosion/HRS_Erosion.c plugins/HRS_Erosion/HRS_Erosion.cxx plugins/IncompressibleExtensionBC/IncompressibleExtensionBC.c plugins/IncompressibleExtensionBC/IncompressibleExtensionBC.cxx plugins/MeshAdvectionCorrection/MeshAdvectionCorrection.c plugins/MeshAdvectionCorrection/MeshAdvectionCorrection.cxx plugins/MovingMesh/MovingMesh.c plugins/MovingMesh/MovingMesh.cxx plugins/MovingMesh/tests/plugins/testMovingMesh.c plugins/MovingMesh/tests/plugins/testMovingMesh.cxx plugins/Multigrid/Multigrid.c plugins/Multigrid/Multigrid.cxx plugins/Output/AverageTemperature/AverageTemperature.c plugins/Output/AverageTemperature/AverageTemperature.cxx plugins/Output/BoundaryLayers/BoundaryLayers.c plugins/Output/BoundaryLayers/BoundaryLayers.cxx plugins/Output/BuoyancyIntegrals/BuoyancyIntegrals.c plugins/Output/BuoyancyIntegrals/BuoyancyIntegrals.cxx plugins/Output/ConvectionData/ConvectionData.c plugins/Output/ConvectionData/ConvectionData.cxx plugins/Output/CylinderNodeProfiling/CylinderNodeProfiling.c plugins/Output/CylinderNodeProfiling/CylinderNodeProfiling.cxx plugins/Output/Localisation/Localisation.c plugins/Output/Localisation/Localisation.cxx plugins/Output/MaxTemperature/MaxTemperature.c plugins/Output/MaxTemperature/MaxTemperature.cxx plugins/Output/MaxVelocity/MaxVelocity.c plugins/Output/MaxVelocity/MaxVelocity.cxx plugins/Output/Mobility/Mobility.c plugins/Output/Mobility/Mobility.cxx plugins/Output/Nusselt/Nusselt.c plugins/Output/Nusselt/Nusselt.cxx plugins/Output/Nusselt_deltaT/Nusselt_deltaT.c plugins/Output/Nusselt_deltaT/Nusselt_deltaT.cxx plugins/Output/OutputForSPModel/OutputForSPModel.c plugins/Output/OutputForSPModel/OutputForSPModel.cxx plugins/Output/Shfl/Shfl.c plugins/Output/Shfl/Shfl.cxx plugins/Output/VTKOutput/VTKOutput.c plugins/Output/VTKOutput/VTKOutput.cxx plugins/Output/Vrms/Vrms.c plugins/Output/Vrms/Vrms.cxx plugins/ScalingChecks/Ra_Scaling/Ra_Scaling.c plugins/ScalingChecks/Ra_Scaling/Ra_Scaling.cxx plugins/SurfaceProcess/SurfaceProcess.c plugins/SurfaceProcess/SurfaceProcess.cxx plugins/VariableConditions/ShapeFemIC/ShapeFemIC.c plugins/VariableConditions/ShapeFemIC/ShapeFemIC.cxx src/main.c src/main.cxx
description:
Rename .c -> .cxx and make configure automatically use c++


diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/AlignmentSwarmVariable.c
--- a/Rheology/src/AlignmentSwarmVariable.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,193 +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:
-*+    Robert Turnbull
-*+    Vincent Lemiale
-*+    Louis Moresi
-*+    David May
-*+    David Stegman
-*+    Mirko Velic
-*+    Patrick Sunter
-*+    Julian Giordani
-*+
-** $Id: AlignmentSwarmVariable.c 610 2007-10-11 08:09:29Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "AlignmentSwarmVariable.h"
-#include "Director.h"
-
-#include <assert.h>
-#include <string.h>
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type AlignmentSwarmVariable_Type = "AlignmentSwarmVariable";
-
-/* Public Constructor */
-AlignmentSwarmVariable* AlignmentSwarmVariable_New(
-	Name					name,
-	AbstractContext*	context,
-	Swarm*				swarm,
-	Variable*			variable,
-	Index					dofCount,
-	FeVariable*			velocityField,
-	Director*			director )
-{
-   AlignmentSwarmVariable* self = (AlignmentSwarmVariable*) _AlignmentSwarmVariable_DefaultNew( name );
-
-   self->isConstructed = True;
-   _SwarmVariable_Init( (SwarmVariable*)self, context, swarm, variable, dofCount );
-   _AlignmentSwarmVariable_Init( self, velocityField, director );
-
-   return self;
-}
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-AlignmentSwarmVariable* _AlignmentSwarmVariable_New(  ALIGNMENTSWARMVARIABLE_DEFARGS  ) {
-   AlignmentSwarmVariable* self;
-
-   /* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-   assert( _sizeOfSelf >= sizeof(AlignmentSwarmVariable) );
-   self = (AlignmentSwarmVariable*) _SwarmVariable_New(  SWARMVARIABLE_PASSARGS  );
-
-   /* Function pointers for this class that are not on the parent class should be set here */
-
-   return self;
-}
-
-void _AlignmentSwarmVariable_Init( void* druckerPrager, FeVariable* velocityField, Director* director ) {
-   AlignmentSwarmVariable*	self = (AlignmentSwarmVariable*)druckerPrager;
-
-   self->dofCount = 1;
-   self->director = director;
-   self->velocityField = velocityField;
-   /* variable does not store data, so is not checkpointed */
-   self->isCheckpointedAndReloaded = False;
-}
-
-void* _AlignmentSwarmVariable_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                 _sizeOfSelf = sizeof(AlignmentSwarmVariable);
-	Type                                                         type = AlignmentSwarmVariable_Type;
-	Stg_Class_DeleteFunction*                                 _delete = _SwarmVariable_Delete;
-	Stg_Class_PrintFunction*                                   _print = _SwarmVariable_Print;
-	Stg_Class_CopyFunction*                                     _copy = _SwarmVariable_Copy;
-	Stg_Component_DefaultConstructorFunction*     _defaultConstructor = _AlignmentSwarmVariable_DefaultNew;
-	Stg_Component_ConstructFunction*                       _construct = _AlignmentSwarmVariable_AssignFromXML;
-	Stg_Component_BuildFunction*                               _build = _AlignmentSwarmVariable_Build;
-	Stg_Component_InitialiseFunction*                     _initialise = _AlignmentSwarmVariable_Initialise;
-	Stg_Component_ExecuteFunction*                           _execute = _SwarmVariable_Execute;
-	Stg_Component_DestroyFunction*                           _destroy = _AlignmentSwarmVariable_Destroy;
-	AllocationType                                 nameAllocationType = NON_GLOBAL;
-	SwarmVariable_ValueAtFunction*                           _valueAt = _AlignmentSwarmVariable_ValueAt;
-	SwarmVariable_GetGlobalValueFunction*      _getMinGlobalMagnitude = _AlignmentSwarmVariable_GetMinGlobalMagnitude;
-	SwarmVariable_GetGlobalValueFunction*      _getMaxGlobalMagnitude = _AlignmentSwarmVariable_GetMaxGlobalMagnitude;
-
-   return (void*) _AlignmentSwarmVariable_New(  ALIGNMENTSWARMVARIABLE_PASSARGS  );
-}
-
-void _AlignmentSwarmVariable_AssignFromXML( void* druckerPrager, Stg_ComponentFactory* cf, void* data ){
-   AlignmentSwarmVariable*	self = (AlignmentSwarmVariable*)druckerPrager;
-   FeVariable*					velocityField;
-   Director*					director;
-
-   /* AssignFromXML Parent */
-   _SwarmVariable_AssignFromXML( self, cf, data );
-
-   /* AssignFromXML 'AlignmentSwarmVariable' stuff */
-   velocityField = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"VelocityField", FeVariable, True, data  ) ;
-   director = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Director", Director, True, data  ) ;
-
-   _AlignmentSwarmVariable_Init( self, velocityField, director );
-}
-
-void _AlignmentSwarmVariable_Build( void* alignment, void* data ) {
-   AlignmentSwarmVariable* self = (AlignmentSwarmVariable*) alignment;
-
-   /* Build parent */
-   _SwarmVariable_Build( self, data );
-
-   Stg_Component_Build( self->director, data, False );
-   Stg_Component_Build( self->velocityField, data, False );
-}
-
-void _AlignmentSwarmVariable_Initialise( void* alignment, void* data ) {
-   AlignmentSwarmVariable* self = (AlignmentSwarmVariable*) alignment;
-
-   /* Initialise Parent */
-   _SwarmVariable_Initialise( self, data );
-
-   Stg_Component_Initialise( self->director, data, False );
-   Stg_Component_Initialise( self->velocityField, data, False );
-}
-
-void _AlignmentSwarmVariable_Destroy( void* alignment, void* data ) {
-   AlignmentSwarmVariable* self = (AlignmentSwarmVariable*) alignment;
-
-   Stg_Component_Destroy( self->director, data, False );
-   Stg_Component_Destroy( self->velocityField, data, False );
-
-   /* Destroy Parent */
-   _SwarmVariable_Destroy( self, data );
-}
-
-void _AlignmentSwarmVariable_ValueAt( void* alignment, Particle_Index lParticle_I, double* value ) {
-   AlignmentSwarmVariable* self = (AlignmentSwarmVariable*) alignment;
-   GlobalParticle*         particle;
-   XYZ                     normal;
-   double                  velocity[3];
-   Dimension_Index         dim = self->swarm->dim;
-
-   particle = (GlobalParticle*)Swarm_ParticleAt( self->swarm, lParticle_I );
-
-   Director_GetNormal( self->director, particle, normal );
-   FieldVariable_InterpolateValueAt( self->velocityField, particle->coord, velocity );
-   StGermain_VectorNormalise( velocity, self->swarm->dim );
-
-   *value = 1.0 - fabs( StGermain_VectorDotProduct( velocity, normal, dim ) );
-}
-
-double _AlignmentSwarmVariable_GetMinGlobalMagnitude( void* alignment ) {
-   return 0.0;
-}
-double _AlignmentSwarmVariable_GetMaxGlobalMagnitude( void* alignment ) {
-   return 1.0;
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/AlignmentSwarmVariable.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/AlignmentSwarmVariable.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,193 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+    Robert Turnbull
+*+    Vincent Lemiale
+*+    Louis Moresi
+*+    David May
+*+    David Stegman
+*+    Mirko Velic
+*+    Patrick Sunter
+*+    Julian Giordani
+*+
+** $Id: AlignmentSwarmVariable.c 610 2007-10-11 08:09:29Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "AlignmentSwarmVariable.h"
+#include "Director.h"
+
+#include <assert.h>
+#include <string.h>
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type AlignmentSwarmVariable_Type = "AlignmentSwarmVariable";
+
+/* Public Constructor */
+AlignmentSwarmVariable* AlignmentSwarmVariable_New(
+	Name					name,
+	AbstractContext*	context,
+	Swarm*				swarm,
+	Variable*			variable,
+	Index					dofCount,
+	FeVariable*			velocityField,
+	Director*			director )
+{
+   AlignmentSwarmVariable* self = (AlignmentSwarmVariable*) _AlignmentSwarmVariable_DefaultNew( name );
+
+   self->isConstructed = True;
+   _SwarmVariable_Init( (SwarmVariable*)self, context, swarm, variable, dofCount );
+   _AlignmentSwarmVariable_Init( self, velocityField, director );
+
+   return self;
+}
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+AlignmentSwarmVariable* _AlignmentSwarmVariable_New(  ALIGNMENTSWARMVARIABLE_DEFARGS  ) {
+   AlignmentSwarmVariable* self;
+
+   /* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+   assert( _sizeOfSelf >= sizeof(AlignmentSwarmVariable) );
+   self = (AlignmentSwarmVariable*) _SwarmVariable_New(  SWARMVARIABLE_PASSARGS  );
+
+   /* Function pointers for this class that are not on the parent class should be set here */
+
+   return self;
+}
+
+void _AlignmentSwarmVariable_Init( void* druckerPrager, FeVariable* velocityField, Director* director ) {
+   AlignmentSwarmVariable*	self = (AlignmentSwarmVariable*)druckerPrager;
+
+   self->dofCount = 1;
+   self->director = director;
+   self->velocityField = velocityField;
+   /* variable does not store data, so is not checkpointed */
+   self->isCheckpointedAndReloaded = False;
+}
+
+void* _AlignmentSwarmVariable_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                 _sizeOfSelf = sizeof(AlignmentSwarmVariable);
+	Type                                                         type = AlignmentSwarmVariable_Type;
+	Stg_Class_DeleteFunction*                                 _delete = _SwarmVariable_Delete;
+	Stg_Class_PrintFunction*                                   _print = _SwarmVariable_Print;
+	Stg_Class_CopyFunction*                                     _copy = _SwarmVariable_Copy;
+	Stg_Component_DefaultConstructorFunction*     _defaultConstructor = _AlignmentSwarmVariable_DefaultNew;
+	Stg_Component_ConstructFunction*                       _construct = _AlignmentSwarmVariable_AssignFromXML;
+	Stg_Component_BuildFunction*                               _build = _AlignmentSwarmVariable_Build;
+	Stg_Component_InitialiseFunction*                     _initialise = _AlignmentSwarmVariable_Initialise;
+	Stg_Component_ExecuteFunction*                           _execute = _SwarmVariable_Execute;
+	Stg_Component_DestroyFunction*                           _destroy = _AlignmentSwarmVariable_Destroy;
+	AllocationType                                 nameAllocationType = NON_GLOBAL;
+	SwarmVariable_ValueAtFunction*                           _valueAt = _AlignmentSwarmVariable_ValueAt;
+	SwarmVariable_GetGlobalValueFunction*      _getMinGlobalMagnitude = _AlignmentSwarmVariable_GetMinGlobalMagnitude;
+	SwarmVariable_GetGlobalValueFunction*      _getMaxGlobalMagnitude = _AlignmentSwarmVariable_GetMaxGlobalMagnitude;
+
+   return (void*) _AlignmentSwarmVariable_New(  ALIGNMENTSWARMVARIABLE_PASSARGS  );
+}
+
+void _AlignmentSwarmVariable_AssignFromXML( void* druckerPrager, Stg_ComponentFactory* cf, void* data ){
+   AlignmentSwarmVariable*	self = (AlignmentSwarmVariable*)druckerPrager;
+   FeVariable*					velocityField;
+   Director*					director;
+
+   /* AssignFromXML Parent */
+   _SwarmVariable_AssignFromXML( self, cf, data );
+
+   /* AssignFromXML 'AlignmentSwarmVariable' stuff */
+   velocityField = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"VelocityField", FeVariable, True, data  ) ;
+   director = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Director", Director, True, data  ) ;
+
+   _AlignmentSwarmVariable_Init( self, velocityField, director );
+}
+
+void _AlignmentSwarmVariable_Build( void* alignment, void* data ) {
+   AlignmentSwarmVariable* self = (AlignmentSwarmVariable*) alignment;
+
+   /* Build parent */
+   _SwarmVariable_Build( self, data );
+
+   Stg_Component_Build( self->director, data, False );
+   Stg_Component_Build( self->velocityField, data, False );
+}
+
+void _AlignmentSwarmVariable_Initialise( void* alignment, void* data ) {
+   AlignmentSwarmVariable* self = (AlignmentSwarmVariable*) alignment;
+
+   /* Initialise Parent */
+   _SwarmVariable_Initialise( self, data );
+
+   Stg_Component_Initialise( self->director, data, False );
+   Stg_Component_Initialise( self->velocityField, data, False );
+}
+
+void _AlignmentSwarmVariable_Destroy( void* alignment, void* data ) {
+   AlignmentSwarmVariable* self = (AlignmentSwarmVariable*) alignment;
+
+   Stg_Component_Destroy( self->director, data, False );
+   Stg_Component_Destroy( self->velocityField, data, False );
+
+   /* Destroy Parent */
+   _SwarmVariable_Destroy( self, data );
+}
+
+void _AlignmentSwarmVariable_ValueAt( void* alignment, Particle_Index lParticle_I, double* value ) {
+   AlignmentSwarmVariable* self = (AlignmentSwarmVariable*) alignment;
+   GlobalParticle*         particle;
+   XYZ                     normal;
+   double                  velocity[3];
+   Dimension_Index         dim = self->swarm->dim;
+
+   particle = (GlobalParticle*)Swarm_ParticleAt( self->swarm, lParticle_I );
+
+   Director_GetNormal( self->director, particle, normal );
+   FieldVariable_InterpolateValueAt( self->velocityField, particle->coord, velocity );
+   StGermain_VectorNormalise( velocity, self->swarm->dim );
+
+   *value = 1.0 - fabs( StGermain_VectorDotProduct( velocity, normal, dim ) );
+}
+
+double _AlignmentSwarmVariable_GetMinGlobalMagnitude( void* alignment ) {
+   return 0.0;
+}
+double _AlignmentSwarmVariable_GetMaxGlobalMagnitude( void* alignment ) {
+   return 1.0;
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/Anisotropic.c
--- a/Rheology/src/Anisotropic.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,180 +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:
-*+    Robert Turnbull
-*+    Vincent Lemiale
-*+    Louis Moresi
-*+    David May
-*+    David Stegman
-*+    Mirko Velic
-*+    Patrick Sunter
-*+    Julian Giordani
-*+
-** $Id: Anisotropic.c 610 2007-10-11 08:09:29Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "RheologyClass.h"
-#include "Anisotropic.h"
-#include "ConstitutiveMatrix.h"
-#include "Director.h"
-
-#include <assert.h>
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type Anisotropic_Type = "Anisotropic";
-
-/* Public Constructor */
-Anisotropic* Anisotropic_New(
-	Name					name,
-	AbstractContext*	context,
-	Director*			director,
-	double				viscosityRatio )
-{
-   Anisotropic* self = (Anisotropic*) _Anisotropic_DefaultNew( name );
-
-   _Rheology_Init( self, (PICelleratorContext*)context );
-   _Anisotropic_Init( self, director, viscosityRatio ) ;
-
-   self->isConstructed = True;
-   return self;
-}
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-Anisotropic* _Anisotropic_New(  ANISOTROPIC_DEFARGS  )
-{
-   Anisotropic*               self;
-
-   /* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-   assert( _sizeOfSelf >= sizeof(Anisotropic) );
-   self = (Anisotropic*) _Rheology_New(  RHEOLOGY_PASSARGS  );
-
-   return self;
-}
-
-void _Anisotropic_Init( Anisotropic* self, Director* director, double viscosityRatio ) {
-   self->director        = director;
-   self->viscosityRatio  = viscosityRatio;
-}
-
-void* _Anisotropic_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                     _sizeOfSelf = sizeof(Anisotropic);
-	Type                                                             type = Anisotropic_Type;
-	Stg_Class_DeleteFunction*                                     _delete = _Rheology_Delete;
-	Stg_Class_PrintFunction*                                       _print = _Rheology_Print;
-	Stg_Class_CopyFunction*                                         _copy = _Rheology_Copy;
-	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _Anisotropic_DefaultNew;
-	Stg_Component_ConstructFunction*                           _construct = _Anisotropic_AssignFromXML;
-	Stg_Component_BuildFunction*                                   _build = _Anisotropic_Build;
-	Stg_Component_InitialiseFunction*                         _initialise = _Anisotropic_Initialise;
-	Stg_Component_ExecuteFunction*                               _execute = _Rheology_Execute;
-	Stg_Component_DestroyFunction*                               _destroy = _Anisotropic_Destroy;
-	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _Anisotropic_ModifyConstitutiveMatrix;
-
-	/* 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*) _Anisotropic_New(  ANISOTROPIC_PASSARGS  );
-}
-
-void _Anisotropic_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
-   Anisotropic*     self = (Anisotropic*)rheology;
-   Director*        director;
-
-   /* Construct Parent */
-   _Rheology_AssignFromXML( self, cf, data );
-
-   director =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Director", Director, True, data  ) ;
-
-   _Anisotropic_Init(
-         self,
-         director,
-         Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"viscosityRatio", 1.0 )  );
-}
-
-void _Anisotropic_Destroy( void* _self, void* data ) {
-   Anisotropic* self = (Anisotropic*) _self;
-
-   Stg_Component_Destroy( self->director, data, False );
-
-   /* Destroy Parent */
-   _Rheology_Destroy( self, data );
-
-}
-
-void _Anisotropic_Build( void* _self, void* data ) {
-   Anisotropic* self = (Anisotropic*) _self;
-
-   Stg_Component_Build( self->director, data, False );
-
-   /* Build Parent */
-   _Rheology_Build( self, data );
-
-}
-
-void _Anisotropic_Initialise( void* _self, void* data ) {
-   Anisotropic* self = (Anisotropic*) _self;
-
-   Stg_Component_Initialise( self->director, data, False );
-
-   /* Build Parent */
-   _Rheology_Initialise( self, data );
-
-}
-
-
-void _Anisotropic_ModifyConstitutiveMatrix(
-      void*                                              rheology,
-      ConstitutiveMatrix*                                constitutiveMatrix,
-      MaterialPointsSwarm*                               swarm,
-      Element_LocalIndex                                 lElement_I,
-      MaterialPoint*                                     materialPoint,
-      Coord                                              xi )
-{
-   Anisotropic*                   self               = (Anisotropic*) rheology;
-   double                          isotropicViscosity = ConstitutiveMatrix_GetIsotropicViscosity( constitutiveMatrix );
-   double                          deltaViscosity;
-   XYZ                             normal;
-
-   deltaViscosity = isotropicViscosity * (1.0 - self->viscosityRatio);
-   Director_GetNormal( self->director, materialPoint, normal );
-
-   ConstitutiveMatrix_SetSecondViscosity( constitutiveMatrix, deltaViscosity, normal );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/Anisotropic.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/Anisotropic.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,180 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+    Robert Turnbull
+*+    Vincent Lemiale
+*+    Louis Moresi
+*+    David May
+*+    David Stegman
+*+    Mirko Velic
+*+    Patrick Sunter
+*+    Julian Giordani
+*+
+** $Id: Anisotropic.c 610 2007-10-11 08:09:29Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "RheologyClass.h"
+#include "Anisotropic.h"
+#include "ConstitutiveMatrix.h"
+#include "Director.h"
+
+#include <assert.h>
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type Anisotropic_Type = "Anisotropic";
+
+/* Public Constructor */
+Anisotropic* Anisotropic_New(
+	Name					name,
+	AbstractContext*	context,
+	Director*			director,
+	double				viscosityRatio )
+{
+   Anisotropic* self = (Anisotropic*) _Anisotropic_DefaultNew( name );
+
+   _Rheology_Init( self, (PICelleratorContext*)context );
+   _Anisotropic_Init( self, director, viscosityRatio ) ;
+
+   self->isConstructed = True;
+   return self;
+}
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+Anisotropic* _Anisotropic_New(  ANISOTROPIC_DEFARGS  )
+{
+   Anisotropic*               self;
+
+   /* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+   assert( _sizeOfSelf >= sizeof(Anisotropic) );
+   self = (Anisotropic*) _Rheology_New(  RHEOLOGY_PASSARGS  );
+
+   return self;
+}
+
+void _Anisotropic_Init( Anisotropic* self, Director* director, double viscosityRatio ) {
+   self->director        = director;
+   self->viscosityRatio  = viscosityRatio;
+}
+
+void* _Anisotropic_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                     _sizeOfSelf = sizeof(Anisotropic);
+	Type                                                             type = Anisotropic_Type;
+	Stg_Class_DeleteFunction*                                     _delete = _Rheology_Delete;
+	Stg_Class_PrintFunction*                                       _print = _Rheology_Print;
+	Stg_Class_CopyFunction*                                         _copy = _Rheology_Copy;
+	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _Anisotropic_DefaultNew;
+	Stg_Component_ConstructFunction*                           _construct = _Anisotropic_AssignFromXML;
+	Stg_Component_BuildFunction*                                   _build = _Anisotropic_Build;
+	Stg_Component_InitialiseFunction*                         _initialise = _Anisotropic_Initialise;
+	Stg_Component_ExecuteFunction*                               _execute = _Rheology_Execute;
+	Stg_Component_DestroyFunction*                               _destroy = _Anisotropic_Destroy;
+	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _Anisotropic_ModifyConstitutiveMatrix;
+
+	/* 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*) _Anisotropic_New(  ANISOTROPIC_PASSARGS  );
+}
+
+void _Anisotropic_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
+   Anisotropic*     self = (Anisotropic*)rheology;
+   Director*        director;
+
+   /* Construct Parent */
+   _Rheology_AssignFromXML( self, cf, data );
+
+   director =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Director", Director, True, data  ) ;
+
+   _Anisotropic_Init(
+         self,
+         director,
+         Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"viscosityRatio", 1.0 )  );
+}
+
+void _Anisotropic_Destroy( void* _self, void* data ) {
+   Anisotropic* self = (Anisotropic*) _self;
+
+   Stg_Component_Destroy( self->director, data, False );
+
+   /* Destroy Parent */
+   _Rheology_Destroy( self, data );
+
+}
+
+void _Anisotropic_Build( void* _self, void* data ) {
+   Anisotropic* self = (Anisotropic*) _self;
+
+   Stg_Component_Build( self->director, data, False );
+
+   /* Build Parent */
+   _Rheology_Build( self, data );
+
+}
+
+void _Anisotropic_Initialise( void* _self, void* data ) {
+   Anisotropic* self = (Anisotropic*) _self;
+
+   Stg_Component_Initialise( self->director, data, False );
+
+   /* Build Parent */
+   _Rheology_Initialise( self, data );
+
+}
+
+
+void _Anisotropic_ModifyConstitutiveMatrix(
+      void*                                              rheology,
+      ConstitutiveMatrix*                                constitutiveMatrix,
+      MaterialPointsSwarm*                               swarm,
+      Element_LocalIndex                                 lElement_I,
+      MaterialPoint*                                     materialPoint,
+      Coord                                              xi )
+{
+   Anisotropic*                   self               = (Anisotropic*) rheology;
+   double                          isotropicViscosity = ConstitutiveMatrix_GetIsotropicViscosity( constitutiveMatrix );
+   double                          deltaViscosity;
+   XYZ                             normal;
+
+   deltaViscosity = isotropicViscosity * (1.0 - self->viscosityRatio);
+   Director_GetNormal( self->director, materialPoint, normal );
+
+   ConstitutiveMatrix_SetSecondViscosity( constitutiveMatrix, deltaViscosity, normal );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/Arrhenius.c
--- a/Rheology/src/Arrhenius.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,222 +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:
-*+    Robert Turnbull
-*+    Vincent Lemiale
-*+    Louis Moresi
-*+    David May
-*+    David Stegman
-*+    Mirko Velic
-*+    Patrick Sunter
-*+    Julian Giordani
-*+
-** $Id: Arrhenius.c 618 2007-10-29 07:53:04Z RobertTurnbull $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "RheologyClass.h"
-#include "Arrhenius.h"
-#include "ConstitutiveMatrix.h"
-
-#include <assert.h>
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type Arrhenius_Type = "Arrhenius";
-
-/* Public Constructor */
-Arrhenius* Arrhenius_New(
-	Name             name,
-	AbstractContext* context,
-	FeVariable*      temperatureField,
-	double           eta0,
-	double           activationEnergy,
-	double           activationVolume,
-	double           referenceTemp)
-{
-   Arrhenius* self = (Arrhenius*) _Arrhenius_DefaultNew( name );
-
-   _Rheology_Init( self, (PICelleratorContext*)context );
-   _Arrhenius_Init( self, temperatureField, eta0, activationEnergy, activationVolume, referenceTemp );
-   self->isConstructed = True;
-   return self;
-}
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-Arrhenius* _Arrhenius_New(  ARRHENIUS_DEFARGS  )
-{
-   Arrhenius*              self;
-
-   assert( _sizeOfSelf >= sizeof(Arrhenius) );
-   self = (Arrhenius*) _Rheology_New(  RHEOLOGY_PASSARGS  );
-
-   return self;
-}
-
-void _Arrhenius_Init( Arrhenius* self, FeVariable* temperatureField, double eta0, double activationEnergy, double activationVolume, double referenceTemp )
-{
-   self->temperatureField = temperatureField;
-   self->eta0             = eta0;
-   self->activationEnergy = activationEnergy;
-   self->activationVolume = activationVolume;
-   self->referenceTemp    = referenceTemp;
-}
-
-void* _Arrhenius_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                     _sizeOfSelf = sizeof(Arrhenius);
-	Type                                                             type = Arrhenius_Type;
-	Stg_Class_DeleteFunction*                                     _delete = _Rheology_Delete;
-	Stg_Class_PrintFunction*                                       _print = _Rheology_Print;
-	Stg_Class_CopyFunction*                                         _copy = _Rheology_Copy;
-	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _Arrhenius_DefaultNew;
-	Stg_Component_ConstructFunction*                           _construct = _Arrhenius_AssignFromXML;
-	Stg_Component_BuildFunction*                                   _build = _Rheology_Build;
-	Stg_Component_InitialiseFunction*                         _initialise = _Rheology_Initialise;
-	Stg_Component_ExecuteFunction*                               _execute = _Rheology_Execute;
-	Stg_Component_DestroyFunction*                               _destroy = _Rheology_Destroy;
-	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _Arrhenius_ModifyConstitutiveMatrix;
-
-	/* 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*) _Arrhenius_New(  ARRHENIUS_PASSARGS  );
-}
-
-void _Arrhenius_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
-   Arrhenius*     self = (Arrhenius*)rheology;
-   FeVariable*    temperatureField;
-
-   /* Construct Parent */
-   _Rheology_AssignFromXML( self, cf, data );
-
-   /* TODO: 'KeyFallback' soon to be deprecated/updated */
-   temperatureField = Stg_ComponentFactory_ConstructByNameWithKeyFallback( cf, self->name, (Name)"TemperatureField", (Dictionary_Entry_Key)"TemperatureField", FeVariable, True, data  );
-   /*temperatureField = Stg_ComponentFactory_ConstructByKey(
-         cf, self->name, "TemperatureField", FeVariable, True );*/
-
-   _Arrhenius_Init(
-         self,
-         temperatureField,
-         Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"eta0", 1.0  ),
-         Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"activationEnergy", 0.0  ),
-         Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"activationVolume", 0.0  ),
-         Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"referenceTemperature", 1.0 )  );
-}
-
-void _Arrhenius_Destroy( void* _self, void* data ) {
-   Arrhenius* self = (Arrhenius*) _self;
-
-   Stg_Component_Destroy( self->temperatureField, data, False );
-
-   /* Destroy Parent */
-   _Rheology_Destroy( self, data );
-
-}
-
-void _Arrhenius_Build( void* _self, void* data ) {
-   Arrhenius* self = (Arrhenius*) _self;
-
-   Stg_Component_Build( self->temperatureField, data, False );
-
-   /* Build Parent */
-   _Rheology_Build( self, data );
-
-}
-
-void _Arrhenius_Initialise( void* _self, void* data ) {
-   Arrhenius* self = (Arrhenius*) _self;
-
-   Stg_Component_Initialise( self->temperatureField, data, False );
-
-   /* Build Parent */
-   _Rheology_Initialise( self, data );
-
-}
-
-void _Arrhenius_ModifyConstitutiveMatrix(
-      void*                                              rheology,
-      ConstitutiveMatrix*                                constitutiveMatrix,
-      MaterialPointsSwarm*                               swarm,
-      Element_LocalIndex                                 lElement_I,
-      MaterialPoint*                                     materialPoint,
-      Coord                                              xi )
-{
-   Arrhenius*                    self              = (Arrhenius*) rheology;
-   FeVariable*                       temperatureField  = self->temperatureField;
-   double                            eta0;
-   double                            activationEnergy;
-   double                            activationVolume;
-   double                            referenceTemp;
-   double                            temperature;
-   double                            viscosity;
-   double                            depth;
-   double                            height;
-   Coord            min, max;
-   Coord                             coord;
-   FeMesh*                           mesh              = ConstitutiveMatrix_GetMesh( constitutiveMatrix );
-
-   eta0             = self->eta0;
-   activationEnergy = self->activationEnergy;
-   activationVolume = self->activationVolume;
-   referenceTemp    = self->referenceTemp;
-
-   /* Extract geometric extents. */
-   Mesh_GetGlobalCoordRange( mesh, min, max );
-
-   /* Calculate Parameters */
-   FeVariable_InterpolateFromMeshLocalCoord( temperatureField, mesh, lElement_I, xi, &temperature );
-
-   /* If activationVolume is 0 there is no need to calculate the depth of the particle see viscosity line below. */
-   if( activationVolume > (0.0 + 1e-12 )  ) {
-      /* Calculate Depth */
-      height = max[ J_AXIS ];
-
-      /* This rheology assumes particle is an integration points thats can be mapped to a particle
-       * that has no meaningful coord. Best to re-calc the global from local */
-      FeMesh_CoordLocalToGlobal( mesh, lElement_I, xi, coord );
-      depth = height - coord[ J_AXIS ];
-      /* Calculate New Viscosity */
-      viscosity = eta0 * exp(( activationEnergy + activationVolume * depth)/ (temperature + referenceTemp));
-   }
-   else {
-      /* Calculate New Viscosity */
-      viscosity = eta0 * exp(( activationEnergy )/ (temperature + referenceTemp));
-   }
-   ConstitutiveMatrix_SetIsotropicViscosity( constitutiveMatrix, viscosity );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/Arrhenius.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/Arrhenius.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,222 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+    Robert Turnbull
+*+    Vincent Lemiale
+*+    Louis Moresi
+*+    David May
+*+    David Stegman
+*+    Mirko Velic
+*+    Patrick Sunter
+*+    Julian Giordani
+*+
+** $Id: Arrhenius.c 618 2007-10-29 07:53:04Z RobertTurnbull $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "RheologyClass.h"
+#include "Arrhenius.h"
+#include "ConstitutiveMatrix.h"
+
+#include <assert.h>
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type Arrhenius_Type = "Arrhenius";
+
+/* Public Constructor */
+Arrhenius* Arrhenius_New(
+	Name             name,
+	AbstractContext* context,
+	FeVariable*      temperatureField,
+	double           eta0,
+	double           activationEnergy,
+	double           activationVolume,
+	double           referenceTemp)
+{
+   Arrhenius* self = (Arrhenius*) _Arrhenius_DefaultNew( name );
+
+   _Rheology_Init( self, (PICelleratorContext*)context );
+   _Arrhenius_Init( self, temperatureField, eta0, activationEnergy, activationVolume, referenceTemp );
+   self->isConstructed = True;
+   return self;
+}
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+Arrhenius* _Arrhenius_New(  ARRHENIUS_DEFARGS  )
+{
+   Arrhenius*              self;
+
+   assert( _sizeOfSelf >= sizeof(Arrhenius) );
+   self = (Arrhenius*) _Rheology_New(  RHEOLOGY_PASSARGS  );
+
+   return self;
+}
+
+void _Arrhenius_Init( Arrhenius* self, FeVariable* temperatureField, double eta0, double activationEnergy, double activationVolume, double referenceTemp )
+{
+   self->temperatureField = temperatureField;
+   self->eta0             = eta0;
+   self->activationEnergy = activationEnergy;
+   self->activationVolume = activationVolume;
+   self->referenceTemp    = referenceTemp;
+}
+
+void* _Arrhenius_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                     _sizeOfSelf = sizeof(Arrhenius);
+	Type                                                             type = Arrhenius_Type;
+	Stg_Class_DeleteFunction*                                     _delete = _Rheology_Delete;
+	Stg_Class_PrintFunction*                                       _print = _Rheology_Print;
+	Stg_Class_CopyFunction*                                         _copy = _Rheology_Copy;
+	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _Arrhenius_DefaultNew;
+	Stg_Component_ConstructFunction*                           _construct = _Arrhenius_AssignFromXML;
+	Stg_Component_BuildFunction*                                   _build = _Rheology_Build;
+	Stg_Component_InitialiseFunction*                         _initialise = _Rheology_Initialise;
+	Stg_Component_ExecuteFunction*                               _execute = _Rheology_Execute;
+	Stg_Component_DestroyFunction*                               _destroy = _Rheology_Destroy;
+	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _Arrhenius_ModifyConstitutiveMatrix;
+
+	/* 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*) _Arrhenius_New(  ARRHENIUS_PASSARGS  );
+}
+
+void _Arrhenius_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
+   Arrhenius*     self = (Arrhenius*)rheology;
+   FeVariable*    temperatureField;
+
+   /* Construct Parent */
+   _Rheology_AssignFromXML( self, cf, data );
+
+   /* TODO: 'KeyFallback' soon to be deprecated/updated */
+   temperatureField = Stg_ComponentFactory_ConstructByNameWithKeyFallback( cf, self->name, (Name)"TemperatureField", (Dictionary_Entry_Key)"TemperatureField", FeVariable, True, data  );
+   /*temperatureField = Stg_ComponentFactory_ConstructByKey(
+         cf, self->name, "TemperatureField", FeVariable, True );*/
+
+   _Arrhenius_Init(
+         self,
+         temperatureField,
+         Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"eta0", 1.0  ),
+         Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"activationEnergy", 0.0  ),
+         Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"activationVolume", 0.0  ),
+         Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"referenceTemperature", 1.0 )  );
+}
+
+void _Arrhenius_Destroy( void* _self, void* data ) {
+   Arrhenius* self = (Arrhenius*) _self;
+
+   Stg_Component_Destroy( self->temperatureField, data, False );
+
+   /* Destroy Parent */
+   _Rheology_Destroy( self, data );
+
+}
+
+void _Arrhenius_Build( void* _self, void* data ) {
+   Arrhenius* self = (Arrhenius*) _self;
+
+   Stg_Component_Build( self->temperatureField, data, False );
+
+   /* Build Parent */
+   _Rheology_Build( self, data );
+
+}
+
+void _Arrhenius_Initialise( void* _self, void* data ) {
+   Arrhenius* self = (Arrhenius*) _self;
+
+   Stg_Component_Initialise( self->temperatureField, data, False );
+
+   /* Build Parent */
+   _Rheology_Initialise( self, data );
+
+}
+
+void _Arrhenius_ModifyConstitutiveMatrix(
+      void*                                              rheology,
+      ConstitutiveMatrix*                                constitutiveMatrix,
+      MaterialPointsSwarm*                               swarm,
+      Element_LocalIndex                                 lElement_I,
+      MaterialPoint*                                     materialPoint,
+      Coord                                              xi )
+{
+   Arrhenius*                    self              = (Arrhenius*) rheology;
+   FeVariable*                       temperatureField  = self->temperatureField;
+   double                            eta0;
+   double                            activationEnergy;
+   double                            activationVolume;
+   double                            referenceTemp;
+   double                            temperature;
+   double                            viscosity;
+   double                            depth;
+   double                            height;
+   Coord            min, max;
+   Coord                             coord;
+   FeMesh*                           mesh              = ConstitutiveMatrix_GetMesh( constitutiveMatrix );
+
+   eta0             = self->eta0;
+   activationEnergy = self->activationEnergy;
+   activationVolume = self->activationVolume;
+   referenceTemp    = self->referenceTemp;
+
+   /* Extract geometric extents. */
+   Mesh_GetGlobalCoordRange( mesh, min, max );
+
+   /* Calculate Parameters */
+   FeVariable_InterpolateFromMeshLocalCoord( temperatureField, mesh, lElement_I, xi, &temperature );
+
+   /* If activationVolume is 0 there is no need to calculate the depth of the particle see viscosity line below. */
+   if( activationVolume > (0.0 + 1e-12 )  ) {
+      /* Calculate Depth */
+      height = max[ J_AXIS ];
+
+      /* This rheology assumes particle is an integration points thats can be mapped to a particle
+       * that has no meaningful coord. Best to re-calc the global from local */
+      FeMesh_CoordLocalToGlobal( mesh, lElement_I, xi, coord );
+      depth = height - coord[ J_AXIS ];
+      /* Calculate New Viscosity */
+      viscosity = eta0 * exp(( activationEnergy + activationVolume * depth)/ (temperature + referenceTemp));
+   }
+   else {
+      /* Calculate New Viscosity */
+      viscosity = eta0 * exp(( activationEnergy )/ (temperature + referenceTemp));
+   }
+   ConstitutiveMatrix_SetIsotropicViscosity( constitutiveMatrix, viscosity );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/Byerlee.c
--- a/Rheology/src/Byerlee.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,190 +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:
-*+    Robert Turnbull
-*+    Vincent Lemiale
-*+    Louis Moresi
-*+    David May
-*+    David Stegman
-*+    Mirko Velic
-*+    Patrick Sunter
-*+    Julian Giordani
-*+
-** $Id: Byerlee.c 733 2008-05-14 04:55:40Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "RheologyClass.h"
-#include "StrainWeakening.h"
-#include "YieldRheology.h"
-#include "VonMises.h"
-#include "Byerlee.h"
-#include "ConstitutiveMatrix.h"
-
-#include <assert.h>
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type Byerlee_Type = "Byerlee";
-
-
-/* Public Constructor */
-Byerlee* Byerlee_New(
-      Name                  name,
-      AbstractContext*      context,
-      StrainWeakening*      strainWeakening, 
-      MaterialPointsSwarm*  materialPointsSwarm, 
-      double                minVisc, 
-      FeVariable*           strainRateField,
-      SwarmVariable*        swarmStrainRate,
-      double                cohesion,
-      double                cohesionAfterSoftening,
-      Bool                  strainRateSoftening,
-      FeMesh*               mesh,
-      double                depthCoefficient )
-{
-   Byerlee* self = (Byerlee*) _Byerlee_DefaultNew( name );
-
-   _Rheology_Init( self, (PICelleratorContext*)context );
-   _YieldRheology_Init( (YieldRheology*)self, strainWeakening, materialPointsSwarm, minVisc ); 
-   _VonMises_Init( (VonMises*)self, strainRateField, swarmStrainRate, cohesion, cohesionAfterSoftening, strainRateSoftening );
-   _Byerlee_Init( self, mesh, depthCoefficient );
-   self->isConstructed = True;
-   return self;
-}
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-Byerlee* _Byerlee_New(  BYERLEE_DEFARGS  )
-{
-   Byerlee*             self;
-
-   /* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-   assert( _sizeOfSelf >= sizeof(Byerlee) );
-   self = (Byerlee*) _VonMises_New(  VONMISES_PASSARGS  );
-
-   /* Function pointers for this class that are not on the parent class should be set here */
-
-   return self;
-}
-
-void _Byerlee_Init( Byerlee* self, FeMesh* mesh, double depthCoefficient ) {
-   self->mesh = mesh;
-   self->depthCoefficient = depthCoefficient;
-}
-
-void* _Byerlee_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                     _sizeOfSelf = sizeof(Byerlee);
-	Type                                                             type = Byerlee_Type;
-	Stg_Class_DeleteFunction*                                     _delete = _YieldRheology_Delete;
-	Stg_Class_PrintFunction*                                       _print = _YieldRheology_Print;
-	Stg_Class_CopyFunction*                                         _copy = _YieldRheology_Copy;
-	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _Byerlee_DefaultNew;
-	Stg_Component_ConstructFunction*                           _construct = _Byerlee_AssignFromXML;
-	Stg_Component_BuildFunction*                                   _build = _YieldRheology_Build;
-	Stg_Component_InitialiseFunction*                         _initialise = _YieldRheology_Initialise;
-	Stg_Component_ExecuteFunction*                               _execute = _YieldRheology_Execute;
-	Stg_Component_DestroyFunction*                               _destroy = _Byerlee_Destroy;
-	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _YieldRheology_ModifyConstitutiveMatrix;
-	YieldRheology_GetYieldCriterionFunction*           _getYieldCriterion = _Byerlee_GetYieldCriterion;
-	YieldRheology_GetYieldIndicatorFunction*           _getYieldIndicator = _VonMises_GetYieldIndicator;
-	YieldRheology_HasYieldedFunction*                         _hasYielded = _VonMises_HasYielded;
-
-	/* 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*) _Byerlee_New(  BYERLEE_PASSARGS  );
-}
-
-void _Byerlee_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
-   Byerlee*            self           = (Byerlee*)rheology;
-   FeMesh*         mesh;
-
-   /* Construct Parent */
-   _VonMises_AssignFromXML( self, cf, data );
-   /* TODO: "KeyFallback' soon to be deprecated/updated */
-   /*
-   geometry = Stg_ComponentFactory_ConstructByNameWithKeyFallback( cf, self->name, (Name)"geometry", (Dictionary_Entry_Key)"BlockGeometry", BlockGeometry, True, data  );
-   */
-   mesh     = Stg_ComponentFactory_ConstructByNameWithKeyFallback( cf, self->name, (Name)"mesh-linear", (Dictionary_Entry_Key)"FeMesh", FeMesh, True, data  );
-   /*geometry = Stg_ComponentFactory_ConstructByKey(
-         cf, self->name, "BlockGeometry", BlockGeometry, True );
-   mesh     = Stg_ComponentFactory_ConstructByKey(
-         cf, self->name, "FiniteElement_Mesh", FiniteElement_Mesh, True );*/
-
-   _Byerlee_Init(
-         self,
-         mesh,
-         Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"depthCoefficient", 0.0  )  );
-}
-
-void _Byerlee_Destroy( void* rheology, void* data ) {
-   Byerlee*  self = (Byerlee*) rheology;
-   
-   Stg_Component_Destroy( self->mesh, data, False );
-   
-   _VonMises_Destroy( self, data );
-   
-}
-
-
-double _Byerlee_GetYieldCriterion(
-      void*                            rheology,
-      ConstitutiveMatrix*              constitutiveMatrix,
-      MaterialPointsSwarm*             materialPointsSwarm,
-      Element_LocalIndex               lElement_I,
-      MaterialPoint*                   materialPoint,
-      Coord                            xi )
-{
-   Byerlee*                         self             = (Byerlee*) rheology;
-   double                           depth = 0.0;
-   double                           height;
-   Coord           min, max;
-   Coord                            coord;
-
-   /* Calculate Depth */
-   Mesh_GetGlobalCoordRange( self->mesh, min, max );
-   height = max[ J_AXIS ];
-
-   /* This rheology assumes particle is an integration points thats can be mapped to a particle
-    * that has no meaningful coord. Best to re-calc the global from local */
-   FeMesh_CoordLocalToGlobal( self->mesh, lElement_I, xi, coord );
-   depth = height - coord[ J_AXIS ];
-
-   return self->cohesion + self->depthCoefficient * depth;
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/Byerlee.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/Byerlee.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,190 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+    Robert Turnbull
+*+    Vincent Lemiale
+*+    Louis Moresi
+*+    David May
+*+    David Stegman
+*+    Mirko Velic
+*+    Patrick Sunter
+*+    Julian Giordani
+*+
+** $Id: Byerlee.c 733 2008-05-14 04:55:40Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "RheologyClass.h"
+#include "StrainWeakening.h"
+#include "YieldRheology.h"
+#include "VonMises.h"
+#include "Byerlee.h"
+#include "ConstitutiveMatrix.h"
+
+#include <assert.h>
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type Byerlee_Type = "Byerlee";
+
+
+/* Public Constructor */
+Byerlee* Byerlee_New(
+      Name                  name,
+      AbstractContext*      context,
+      StrainWeakening*      strainWeakening, 
+      MaterialPointsSwarm*  materialPointsSwarm, 
+      double                minVisc, 
+      FeVariable*           strainRateField,
+      SwarmVariable*        swarmStrainRate,
+      double                cohesion,
+      double                cohesionAfterSoftening,
+      Bool                  strainRateSoftening,
+      FeMesh*               mesh,
+      double                depthCoefficient )
+{
+   Byerlee* self = (Byerlee*) _Byerlee_DefaultNew( name );
+
+   _Rheology_Init( self, (PICelleratorContext*)context );
+   _YieldRheology_Init( (YieldRheology*)self, strainWeakening, materialPointsSwarm, minVisc ); 
+   _VonMises_Init( (VonMises*)self, strainRateField, swarmStrainRate, cohesion, cohesionAfterSoftening, strainRateSoftening );
+   _Byerlee_Init( self, mesh, depthCoefficient );
+   self->isConstructed = True;
+   return self;
+}
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+Byerlee* _Byerlee_New(  BYERLEE_DEFARGS  )
+{
+   Byerlee*             self;
+
+   /* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+   assert( _sizeOfSelf >= sizeof(Byerlee) );
+   self = (Byerlee*) _VonMises_New(  VONMISES_PASSARGS  );
+
+   /* Function pointers for this class that are not on the parent class should be set here */
+
+   return self;
+}
+
+void _Byerlee_Init( Byerlee* self, FeMesh* mesh, double depthCoefficient ) {
+   self->mesh = mesh;
+   self->depthCoefficient = depthCoefficient;
+}
+
+void* _Byerlee_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                     _sizeOfSelf = sizeof(Byerlee);
+	Type                                                             type = Byerlee_Type;
+	Stg_Class_DeleteFunction*                                     _delete = _YieldRheology_Delete;
+	Stg_Class_PrintFunction*                                       _print = _YieldRheology_Print;
+	Stg_Class_CopyFunction*                                         _copy = _YieldRheology_Copy;
+	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _Byerlee_DefaultNew;
+	Stg_Component_ConstructFunction*                           _construct = _Byerlee_AssignFromXML;
+	Stg_Component_BuildFunction*                                   _build = _YieldRheology_Build;
+	Stg_Component_InitialiseFunction*                         _initialise = _YieldRheology_Initialise;
+	Stg_Component_ExecuteFunction*                               _execute = _YieldRheology_Execute;
+	Stg_Component_DestroyFunction*                               _destroy = _Byerlee_Destroy;
+	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _YieldRheology_ModifyConstitutiveMatrix;
+	YieldRheology_GetYieldCriterionFunction*           _getYieldCriterion = _Byerlee_GetYieldCriterion;
+	YieldRheology_GetYieldIndicatorFunction*           _getYieldIndicator = _VonMises_GetYieldIndicator;
+	YieldRheology_HasYieldedFunction*                         _hasYielded = _VonMises_HasYielded;
+
+	/* 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*) _Byerlee_New(  BYERLEE_PASSARGS  );
+}
+
+void _Byerlee_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
+   Byerlee*            self           = (Byerlee*)rheology;
+   FeMesh*         mesh;
+
+   /* Construct Parent */
+   _VonMises_AssignFromXML( self, cf, data );
+   /* TODO: "KeyFallback' soon to be deprecated/updated */
+   /*
+   geometry = Stg_ComponentFactory_ConstructByNameWithKeyFallback( cf, self->name, (Name)"geometry", (Dictionary_Entry_Key)"BlockGeometry", BlockGeometry, True, data  );
+   */
+   mesh     = Stg_ComponentFactory_ConstructByNameWithKeyFallback( cf, self->name, (Name)"mesh-linear", (Dictionary_Entry_Key)"FeMesh", FeMesh, True, data  );
+   /*geometry = Stg_ComponentFactory_ConstructByKey(
+         cf, self->name, "BlockGeometry", BlockGeometry, True );
+   mesh     = Stg_ComponentFactory_ConstructByKey(
+         cf, self->name, "FiniteElement_Mesh", FiniteElement_Mesh, True );*/
+
+   _Byerlee_Init(
+         self,
+         mesh,
+         Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"depthCoefficient", 0.0  )  );
+}
+
+void _Byerlee_Destroy( void* rheology, void* data ) {
+   Byerlee*  self = (Byerlee*) rheology;
+   
+   Stg_Component_Destroy( self->mesh, data, False );
+   
+   _VonMises_Destroy( self, data );
+   
+}
+
+
+double _Byerlee_GetYieldCriterion(
+      void*                            rheology,
+      ConstitutiveMatrix*              constitutiveMatrix,
+      MaterialPointsSwarm*             materialPointsSwarm,
+      Element_LocalIndex               lElement_I,
+      MaterialPoint*                   materialPoint,
+      Coord                            xi )
+{
+   Byerlee*                         self             = (Byerlee*) rheology;
+   double                           depth = 0.0;
+   double                           height;
+   Coord           min, max;
+   Coord                            coord;
+
+   /* Calculate Depth */
+   Mesh_GetGlobalCoordRange( self->mesh, min, max );
+   height = max[ J_AXIS ];
+
+   /* This rheology assumes particle is an integration points thats can be mapped to a particle
+    * that has no meaningful coord. Best to re-calc the global from local */
+   FeMesh_CoordLocalToGlobal( self->mesh, lElement_I, xi, coord );
+   depth = height - coord[ J_AXIS ];
+
+   return self->cohesion + self->depthCoefficient * depth;
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/Compressible.c
--- a/Rheology/src/Compressible.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,279 +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:
-*+    Robert Turnbull
-*+    Vincent Lemiale
-*+    Louis Moresi
-*+    David May
-*+    David Stegman
-*+    Mirko Velic
-*+    Patrick Sunter
-*+    Julian Giordani
-*+
-** $Id: Compressible.c 610 2007-10-11 08:09:29Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "Compressible.h"
-#include "RheologyMaterial.h"
-
-#include <assert.h>
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type Compressible_Type = "Compressible";
-
-/* Public Constructor */
-
-Compressible* Compressible_New(
-      Name                   name,
-      FiniteElementContext*  context,
-		StiffnessMatrix*       stiffnessMatrix,
-		Swarm*                 swarm,
-		Stg_Component*         extraInfo,
-      FeMesh*                geometryMesh,
-      Materials_Register*    materials_Register,
-      double                 oneOnLambda )
-{
-   Compressible* self = (Compressible*) _Compressible_DefaultNew( name );
-   _StiffnessMatrixTerm_Init( self, context, stiffnessMatrix, swarm, extraInfo );
-   _Compressible_Init( self, geometryMesh, materials_Register, oneOnLambda );
-   self->isConstructed = True;
-   
-   return self;
-}
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-Compressible* _Compressible_New(  COMPRESSIBLE_DEFARGS  )
-{
-   Compressible*              self;
-
-   /* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-   assert( _sizeOfSelf >= sizeof(Compressible) );
-   self = (Compressible*) _StiffnessMatrixTerm_New(  STIFFNESSMATRIXTERM_PASSARGS  );
-
-   return self;
-}
-
-void _Compressible_Init(
-      Compressible*        self,
-      FeMesh*              geometryMesh,
-      Materials_Register*  materials_Register,
-      double               oneOnLambda )
-{
-
-   self->oneOnLambda            = oneOnLambda;
-   self->geometryMesh           = geometryMesh;
-   self->materials_Register     = materials_Register;
-}
-
-
-void _Compressible_Destroy( void* compressible, void* data ) {
-   Compressible*    self = (Compressible*)compressible;
-
-   Stg_Component_Destroy( self->geometryMesh, data, False );
-   _StiffnessMatrixTerm_Destroy( self, data );
-}
-
-void _Compressible_Print( void* compressible, Stream* stream ) {
-   Compressible*    self = (Compressible*)compressible;
-
-   _StiffnessMatrixTerm_Print( self, stream );
-
-   Journal_PrintValue( stream, self->oneOnLambda );
-}
-
-void* _Compressible_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                 _sizeOfSelf = sizeof(Compressible);
-	Type                                                         type = Compressible_Type;
-	Stg_Class_DeleteFunction*                                 _delete = _StiffnessMatrixTerm_Delete;
-	Stg_Class_PrintFunction*                                   _print = _Compressible_Print;
-	Stg_Class_CopyFunction*                                     _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*     _defaultConstructor = _Compressible_DefaultNew;
-	Stg_Component_ConstructFunction*                       _construct = _Compressible_AssignFromXML;
-	Stg_Component_BuildFunction*                               _build = _Compressible_Build;
-	Stg_Component_InitialiseFunction*                     _initialise = _Compressible_Initialise;
-	Stg_Component_ExecuteFunction*                           _execute = _Compressible_Execute;
-	Stg_Component_DestroyFunction*                           _destroy = _Compressible_Destroy;
-	StiffnessMatrixTerm_AssembleElementFunction*     _assembleElement = _Compressible_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*) _Compressible_New(  COMPRESSIBLE_PASSARGS  );
-}
-
-
-void _Compressible_AssignFromXML( void* compressible, Stg_ComponentFactory* cf, void* data ){
-   Compressible*     self = (Compressible*)compressible;
-   FeMesh*        geometryMesh;
-   Materials_Register*  materials_Register;
-   PICelleratorContext* context;
-
-   _StiffnessMatrixTerm_AssignFromXML( self, cf, data );
-
-   geometryMesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"GeometryMesh", FeMesh, True, data );
-
-   context = (PICelleratorContext* )self->context;
-   assert( Stg_CheckType( context, PICelleratorContext ) );
-   materials_Register = context->materials_Register;
-   assert( materials_Register );
-
-   _Compressible_Init(
-         self,
-         geometryMesh,
-         materials_Register,
-         Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"oneOnLambda", 10.0 )  );
-
-   /* Make sure that we are using the correct type of swarm
-    * SHOULDN'T THIS BEEN DONE AT THE STIFFNESSMATRIXTERM LEVEL? */
-   Stg_CheckType( self->integrationSwarm, IntegrationPointsSwarm );
-}
-
-void _Compressible_Build( void* compressible, void* data ){
-   _StiffnessMatrixTerm_Build( compressible, data );
-}
-void _Compressible_Initialise( void* compressible, void* data ){
-   _StiffnessMatrixTerm_Initialise( compressible, data );
-}
-void _Compressible_Execute( void* compressible, void* data ){
-   _StiffnessMatrixTerm_Execute( compressible, data );
-}
-
-void _Compressible_AssembleElement(
-		void*                                              compressible,
-		StiffnessMatrix*                                   stiffnessMatrix,
-	 	Element_LocalIndex                                 lElement_I,
-		SystemLinearEquations*                             sle,
-		FiniteElementContext*                              context,
-		double**                                           elStiffMat )
-{
-	Compressible*             self                = (Compressible*)compressible;
-	IntegrationPointsSwarm*   swarm               = (IntegrationPointsSwarm*) self->integrationSwarm;
-	RheologyMaterial*         material;
-	FeVariable*               variable1           = stiffnessMatrix->rowVariable;
-	Dimension_Index           dim                 = stiffnessMatrix->dim;
-	IntegrationPoint*         particle;
-	Particle_InCellIndex      cParticle_I;
-	Particle_InCellIndex      cellParticleCount;
-	Element_NodeIndex         elementNodeCount;
-	Index                     row_I;
-	Index                     col_I;
-	double                    detJac;
-	Cell_Index                cell_I;
-	ElementType*              elementType;
-	Dof_Index                 dofCount;
-	FeMesh*       		  mesh                = variable1->feMesh;
-	double                    Ni[27];
-	double*                   xi;
-	double                    factor;
-	FeMesh*  		  geometryMesh        = self->geometryMesh;
-	ElementType*              geometryElementType;
-	Particle_Index            lParticle_I;
-	double oneOnLambda = 0.0;
-	Bool oneToMany;
-
-	/* Set the element type */
-	elementType         = FeMesh_GetElementType( mesh, lElement_I );
-	geometryElementType = FeMesh_GetElementType( geometryMesh, lElement_I );
-	elementNodeCount    = elementType->nodeCount;
-	dofCount            = elementNodeCount;
-
-	/* Get number of particles per element */
-	cell_I            = CellLayout_MapElementIdToCellId( swarm->cellLayout, lElement_I );
-	cellParticleCount = swarm->cellParticleCountTbl[ cell_I ];
-
-	/*
-	 * Keep a flag indicating whether we are usinga one-to-one swarm mapper or not.
-	 */
-
-	oneToMany = Stg_Class_IsInstance(((IntegrationPointsSwarm*)self->integrationSwarm)->mapper, OneToManyMapper_Type);
-	
-	/* Loop over points to build Stiffness Matrix */
-	for ( cParticle_I = 0 ; cParticle_I < cellParticleCount ; cParticle_I++ ) {
-		particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
-		lParticle_I = swarm->cellParticleTbl[cell_I][cParticle_I];
-
-		if(oneToMany) {
-		    /*
-		     * We're dealing with a one-to-many mapper. We will assemble each material point's
-		     * constitutive matrix and combine them using their weights.
-		     */
-
-		    OneToManyRef *ref;
-		    MaterialPointsSwarm *matSwarm;
-		    int isComp = 0;
-		    int ii;
-
-		    matSwarm = ((OneToManyMapper*)((IntegrationPointsSwarm*)swarm)->mapper)->materialSwarm;
-		    ref = OneToManyMapper_GetMaterialRef(((IntegrationPointsSwarm*)swarm)->mapper, particle);
-		    for(ii = 0; ii < ref->numParticles; ii++) {
-			material = (RheologyMaterial*)MaterialPointsSwarm_GetMaterialAt(matSwarm, ref->particleInds[ii]);
-			if(!material->compressible)
-			    continue;
-			isComp++;
-			oneOnLambda += material->compressible->oneOnLambda;
-		    }
-
-		    if(((float)isComp)/((float)ref->numParticles) < 0.5)
-			continue;
-		    oneOnLambda /= ((double)ref->numParticles);
-		}
-		else {
-
-		    material = (RheologyMaterial*) IntegrationPointsSwarm_GetMaterialAt( swarm, lParticle_I );
-
-		    /* Only make contribution to the compressibility matrix if this material is compressible */
-		    if ( !material->compressible ) 
-			continue;
-
-		    oneOnLambda = material->compressible->oneOnLambda;
-		}
-
-		/* Calculate Determinant of Jacobian and Shape Functions */
-		xi = particle->xi;
-		detJac = ElementType_JacobianDeterminant( geometryElementType, geometryMesh, lElement_I, xi, dim );
-		ElementType_EvaluateShapeFunctionsAt( elementType, xi, Ni );
-		factor = detJac * particle->weight * oneOnLambda;
-
-		for( row_I = 0 ; row_I < dofCount ; row_I++ ) {
-			for( col_I = 0 ; col_I < dofCount ; col_I++ ) {
-				elStiffMat[ row_I ][ col_I ] -= factor * Ni[ row_I ] * Ni[ col_I ];
-			}
-		}
-	}
-}
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/Compressible.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/Compressible.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,279 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+    Robert Turnbull
+*+    Vincent Lemiale
+*+    Louis Moresi
+*+    David May
+*+    David Stegman
+*+    Mirko Velic
+*+    Patrick Sunter
+*+    Julian Giordani
+*+
+** $Id: Compressible.c 610 2007-10-11 08:09:29Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "Compressible.h"
+#include "RheologyMaterial.h"
+
+#include <assert.h>
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type Compressible_Type = "Compressible";
+
+/* Public Constructor */
+
+Compressible* Compressible_New(
+      Name                   name,
+      FiniteElementContext*  context,
+		StiffnessMatrix*       stiffnessMatrix,
+		Swarm*                 swarm,
+		Stg_Component*         extraInfo,
+      FeMesh*                geometryMesh,
+      Materials_Register*    materials_Register,
+      double                 oneOnLambda )
+{
+   Compressible* self = (Compressible*) _Compressible_DefaultNew( name );
+   _StiffnessMatrixTerm_Init( self, context, stiffnessMatrix, swarm, extraInfo );
+   _Compressible_Init( self, geometryMesh, materials_Register, oneOnLambda );
+   self->isConstructed = True;
+   
+   return self;
+}
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+Compressible* _Compressible_New(  COMPRESSIBLE_DEFARGS  )
+{
+   Compressible*              self;
+
+   /* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+   assert( _sizeOfSelf >= sizeof(Compressible) );
+   self = (Compressible*) _StiffnessMatrixTerm_New(  STIFFNESSMATRIXTERM_PASSARGS  );
+
+   return self;
+}
+
+void _Compressible_Init(
+      Compressible*        self,
+      FeMesh*              geometryMesh,
+      Materials_Register*  materials_Register,
+      double               oneOnLambda )
+{
+
+   self->oneOnLambda            = oneOnLambda;
+   self->geometryMesh           = geometryMesh;
+   self->materials_Register     = materials_Register;
+}
+
+
+void _Compressible_Destroy( void* compressible, void* data ) {
+   Compressible*    self = (Compressible*)compressible;
+
+   Stg_Component_Destroy( self->geometryMesh, data, False );
+   _StiffnessMatrixTerm_Destroy( self, data );
+}
+
+void _Compressible_Print( void* compressible, Stream* stream ) {
+   Compressible*    self = (Compressible*)compressible;
+
+   _StiffnessMatrixTerm_Print( self, stream );
+
+   Journal_PrintValue( stream, self->oneOnLambda );
+}
+
+void* _Compressible_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                 _sizeOfSelf = sizeof(Compressible);
+	Type                                                         type = Compressible_Type;
+	Stg_Class_DeleteFunction*                                 _delete = _StiffnessMatrixTerm_Delete;
+	Stg_Class_PrintFunction*                                   _print = _Compressible_Print;
+	Stg_Class_CopyFunction*                                     _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*     _defaultConstructor = _Compressible_DefaultNew;
+	Stg_Component_ConstructFunction*                       _construct = _Compressible_AssignFromXML;
+	Stg_Component_BuildFunction*                               _build = _Compressible_Build;
+	Stg_Component_InitialiseFunction*                     _initialise = _Compressible_Initialise;
+	Stg_Component_ExecuteFunction*                           _execute = _Compressible_Execute;
+	Stg_Component_DestroyFunction*                           _destroy = _Compressible_Destroy;
+	StiffnessMatrixTerm_AssembleElementFunction*     _assembleElement = _Compressible_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*) _Compressible_New(  COMPRESSIBLE_PASSARGS  );
+}
+
+
+void _Compressible_AssignFromXML( void* compressible, Stg_ComponentFactory* cf, void* data ){
+   Compressible*     self = (Compressible*)compressible;
+   FeMesh*        geometryMesh;
+   Materials_Register*  materials_Register;
+   PICelleratorContext* context;
+
+   _StiffnessMatrixTerm_AssignFromXML( self, cf, data );
+
+   geometryMesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"GeometryMesh", FeMesh, True, data );
+
+   context = (PICelleratorContext* )self->context;
+   assert( Stg_CheckType( context, PICelleratorContext ) );
+   materials_Register = context->materials_Register;
+   assert( materials_Register );
+
+   _Compressible_Init(
+         self,
+         geometryMesh,
+         materials_Register,
+         Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"oneOnLambda", 10.0 )  );
+
+   /* Make sure that we are using the correct type of swarm
+    * SHOULDN'T THIS BEEN DONE AT THE STIFFNESSMATRIXTERM LEVEL? */
+   Stg_CheckType( self->integrationSwarm, IntegrationPointsSwarm );
+}
+
+void _Compressible_Build( void* compressible, void* data ){
+   _StiffnessMatrixTerm_Build( compressible, data );
+}
+void _Compressible_Initialise( void* compressible, void* data ){
+   _StiffnessMatrixTerm_Initialise( compressible, data );
+}
+void _Compressible_Execute( void* compressible, void* data ){
+   _StiffnessMatrixTerm_Execute( compressible, data );
+}
+
+void _Compressible_AssembleElement(
+		void*                                              compressible,
+		StiffnessMatrix*                                   stiffnessMatrix,
+	 	Element_LocalIndex                                 lElement_I,
+		SystemLinearEquations*                             sle,
+		FiniteElementContext*                              context,
+		double**                                           elStiffMat )
+{
+	Compressible*             self                = (Compressible*)compressible;
+	IntegrationPointsSwarm*   swarm               = (IntegrationPointsSwarm*) self->integrationSwarm;
+	RheologyMaterial*         material;
+	FeVariable*               variable1           = stiffnessMatrix->rowVariable;
+	Dimension_Index           dim                 = stiffnessMatrix->dim;
+	IntegrationPoint*         particle;
+	Particle_InCellIndex      cParticle_I;
+	Particle_InCellIndex      cellParticleCount;
+	Element_NodeIndex         elementNodeCount;
+	Index                     row_I;
+	Index                     col_I;
+	double                    detJac;
+	Cell_Index                cell_I;
+	ElementType*              elementType;
+	Dof_Index                 dofCount;
+	FeMesh*       		  mesh                = variable1->feMesh;
+	double                    Ni[27];
+	double*                   xi;
+	double                    factor;
+	FeMesh*  		  geometryMesh        = self->geometryMesh;
+	ElementType*              geometryElementType;
+	Particle_Index            lParticle_I;
+	double oneOnLambda = 0.0;
+	Bool oneToMany;
+
+	/* Set the element type */
+	elementType         = FeMesh_GetElementType( mesh, lElement_I );
+	geometryElementType = FeMesh_GetElementType( geometryMesh, lElement_I );
+	elementNodeCount    = elementType->nodeCount;
+	dofCount            = elementNodeCount;
+
+	/* Get number of particles per element */
+	cell_I            = CellLayout_MapElementIdToCellId( swarm->cellLayout, lElement_I );
+	cellParticleCount = swarm->cellParticleCountTbl[ cell_I ];
+
+	/*
+	 * Keep a flag indicating whether we are usinga one-to-one swarm mapper or not.
+	 */
+
+	oneToMany = Stg_Class_IsInstance(((IntegrationPointsSwarm*)self->integrationSwarm)->mapper, OneToManyMapper_Type);
+	
+	/* Loop over points to build Stiffness Matrix */
+	for ( cParticle_I = 0 ; cParticle_I < cellParticleCount ; cParticle_I++ ) {
+		particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
+		lParticle_I = swarm->cellParticleTbl[cell_I][cParticle_I];
+
+		if(oneToMany) {
+		    /*
+		     * We're dealing with a one-to-many mapper. We will assemble each material point's
+		     * constitutive matrix and combine them using their weights.
+		     */
+
+		    OneToManyRef *ref;
+		    MaterialPointsSwarm *matSwarm;
+		    int isComp = 0;
+		    int ii;
+
+		    matSwarm = ((OneToManyMapper*)((IntegrationPointsSwarm*)swarm)->mapper)->materialSwarm;
+		    ref = OneToManyMapper_GetMaterialRef(((IntegrationPointsSwarm*)swarm)->mapper, particle);
+		    for(ii = 0; ii < ref->numParticles; ii++) {
+			material = (RheologyMaterial*)MaterialPointsSwarm_GetMaterialAt(matSwarm, ref->particleInds[ii]);
+			if(!material->compressible)
+			    continue;
+			isComp++;
+			oneOnLambda += material->compressible->oneOnLambda;
+		    }
+
+		    if(((float)isComp)/((float)ref->numParticles) < 0.5)
+			continue;
+		    oneOnLambda /= ((double)ref->numParticles);
+		}
+		else {
+
+		    material = (RheologyMaterial*) IntegrationPointsSwarm_GetMaterialAt( swarm, lParticle_I );
+
+		    /* Only make contribution to the compressibility matrix if this material is compressible */
+		    if ( !material->compressible ) 
+			continue;
+
+		    oneOnLambda = material->compressible->oneOnLambda;
+		}
+
+		/* Calculate Determinant of Jacobian and Shape Functions */
+		xi = particle->xi;
+		detJac = ElementType_JacobianDeterminant( geometryElementType, geometryMesh, lElement_I, xi, dim );
+		ElementType_EvaluateShapeFunctionsAt( elementType, xi, Ni );
+		factor = detJac * particle->weight * oneOnLambda;
+
+		for( row_I = 0 ; row_I < dofCount ; row_I++ ) {
+			for( col_I = 0 ; col_I < dofCount ; col_I++ ) {
+				elStiffMat[ row_I ][ col_I ] -= factor * Ni[ row_I ] * Ni[ col_I ];
+			}
+		}
+	}
+}
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/ConstitutiveMatCartesian_Refactored.c
--- a/Rheology/src/ConstitutiveMatCartesian_Refactored.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,521 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: ConstitutiveMatCartesian_Refactored.c 803 2008-09-11 05:22:20Z LukeHodkinson $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "Rheology_Register.h"
-#include "ConstitutiveMat_Refactored.h"
-#include "ConstitutiveMatCartesian_Refactored.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <assert.h>
-#include <string.h>
-#include <time.h>
-
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type ConstitutiveMatCartesian_Refactored_Type = "ConstitutiveMatCartesian_Refactored";
-
-ConstitutiveMatCartesian_Refactored* ConstitutiveMatCartesian_Refactored_New( 
-	Name							name,
-	Dimension_Index			dim,
-	PICelleratorContext*		context,
-	Materials_Register*		materials_Register )
-{
-  ConstitutiveMatCartesian_Refactored* self = (ConstitutiveMatCartesian_Refactored*)_ConstitutiveMatCartesian_Refactored_DefaultNew( name );
-
-	self->isConstructed = True;
-	_ConstitutiveMat_Refactored_Init( self, dim, context, materials_Register );
-	_ConstitutiveMatCartesian_Refactored_Init( self );
-
-	return self;
-}
-
-void* _ConstitutiveMatCartesian_Refactored_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                        _sizeOfSelf = sizeof(ConstitutiveMatCartesian_Refactored);
-	Type                                                                type = ConstitutiveMatCartesian_Refactored_Type;
-	Stg_Class_DeleteFunction*                                        _delete = _ConstitutiveMatCartesian_Refactored_Delete;
-	Stg_Class_PrintFunction*                                          _print = _ConstitutiveMatCartesian_Refactored_Print;
-	Stg_Class_CopyFunction*                                            _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*            _defaultConstructor = _ConstitutiveMatCartesian_Refactored_DefaultNew;
-	Stg_Component_ConstructFunction*                              _construct = _ConstitutiveMatCartesian_Refactored_AssignFromXML;
-	Stg_Component_BuildFunction*                                      _build = _ConstitutiveMatCartesian_Refactored_Build;
-	Stg_Component_InitialiseFunction*                            _initialise = _ConstitutiveMatCartesian_Refactored_Initialise;
-	Stg_Component_ExecuteFunction*                                  _execute = _ConstitutiveMatCartesian_Refactored_Execute;
-	Stg_Component_DestroyFunction*                                  _destroy = _ConstitutiveMatCartesian_Refactored_Destroy;
-	AllocationType                                        nameAllocationType = NON_GLOBAL;
-	ConstitutiveMat_Refactored_SetValueFunc*                       _setValue = _ConstitutiveMatCartesian_Refactored_SetValueInAllEntries;
-	ConstitutiveMat_Refactored_GetValueFunc*                   _getViscosity = _ConstitutiveMatCartesian_Refactored_GetIsotropicViscosity;
-	ConstitutiveMat_Refactored_SetValueFunc*            _isotropicCorrection = _ConstitutiveMatCartesian_Refactored_IsotropicCorrection;
-	ConstitutiveMat_Refactored_SetSecondViscosityFunc*   _setSecondViscosity = _ConstitutiveMatCartesian_Refactored_SetSecondViscosity;
-	ConstitutiveMat_Refactored_Assemble_D_B_Func*              _assemble_D_B = _ConstitutiveMatCartesian_Refactored_Assemble_D_B;
-	ConstitutiveMat_Refactored_CalculateStressFunc*         _calculateStress = _ConstitutiveMatCartesian_Refactored_CalculateStress;
-
-	return (void*)_ConstitutiveMatCartesian_Refactored_New(  CONSTITUTIVEMATCARTESIAN_REFACTORED_PASSARGS  );
-}
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-ConstitutiveMatCartesian_Refactored* _ConstitutiveMatCartesian_Refactored_New(  CONSTITUTIVEMATCARTESIAN_REFACTORED_DEFARGS  ) {
-	ConstitutiveMatCartesian_Refactored* self;
-	
-	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree.
-		At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-	assert( _sizeOfSelf >= sizeof(ConstitutiveMatCartesian_Refactored) );
-	self = (ConstitutiveMatCartesian_Refactored*) _ConstitutiveMat_Refactored_New(  CONSTITUTIVEMAT_REFACTORED_PASSARGS  );
-	
-	/* Function pointers for this class that are not on the parent class should be set here */
-	
-	return self;
-}
-
-void _ConstitutiveMatCartesian_Refactored_Init( void* constitutiveMatrix ) {
-	ConstitutiveMatCartesian_Refactored* self = (ConstitutiveMatCartesian_Refactored*)constitutiveMatrix;
-
-	self->rowSize = StGermain_nSymmetricTensorVectorComponents( self->dim );
-	self->columnSize = StGermain_nSymmetricTensorVectorComponents( self->dim );
-}
-
-void _ConstitutiveMatCartesian_Refactored_Delete( void* constitutiveMatrix ) {
-	ConstitutiveMatCartesian_Refactored* self = (ConstitutiveMatCartesian_Refactored*)constitutiveMatrix;
-
-	_ConstitutiveMat_Refactored_Delete( self );
-}
-
-void _ConstitutiveMatCartesian_Refactored_Print( void* constitutiveMatrix, Stream* stream ) {
-	ConstitutiveMatCartesian_Refactored* self = (ConstitutiveMatCartesian_Refactored*)constitutiveMatrix;
-	
-	_ConstitutiveMat_Refactored_Print( self, stream );
-
-	/* General info */
-}
-void _ConstitutiveMatCartesian_Refactored_AssignFromXML( void* constitutiveMatrix, Stg_ComponentFactory* cf, void* data ) {
-	ConstitutiveMatCartesian_Refactored* self = (ConstitutiveMatCartesian_Refactored*)constitutiveMatrix;
-
-	/* Construct Parent */
-	_ConstitutiveMat_Refactored_AssignFromXML( self, cf, data );
-
-	_ConstitutiveMatCartesian_Refactored_Init( self );
-}
-
-void _ConstitutiveMatCartesian_Refactored_Build( void* constitutiveMatrix, void* data ) {
-	ConstitutiveMatCartesian_Refactored*             self             = (ConstitutiveMatCartesian_Refactored*)constitutiveMatrix;
-
-	_ConstitutiveMat_Refactored_Build( self, data );
-}
-
-void _ConstitutiveMatCartesian_Refactored_Initialise( void* constitutiveMatrix, void* data ) {
-	ConstitutiveMatCartesian_Refactored*             self             = (ConstitutiveMatCartesian_Refactored*)constitutiveMatrix;
-
-	_ConstitutiveMat_Refactored_Initialise( self, data );
-}
-
-void _ConstitutiveMatCartesian_Refactored_Execute( void* constitutiveMatrix, void* data ) {
-	_ConstitutiveMat_Refactored_Execute( constitutiveMatrix, data );
-}
-
-void _ConstitutiveMatCartesian_Refactored_Destroy( void* constitutiveMatrix, void* data ) {
-	_ConstitutiveMat_Refactored_Destroy( constitutiveMatrix, data );
-}
-
-void _ConstitutiveMatCartesian_Refactored_SetValueInAllEntries( void* constitutiveMatrix, double value ) {
-	ConstitutiveMat_Refactored* self   = (ConstitutiveMat_Refactored*) constitutiveMatrix;
-
-	self->_setValue = ( self->dim == 2 ? 
-			_ConstitutiveMatCartesian_Refactored2D_SetValueInAllEntries :
-			_ConstitutiveMatCartesian_Refactored3D_SetValueInAllEntries );
-
-	ConstitutiveMat_Refactored_SetValueInAllEntries( self, value );
-}
-
-void _ConstitutiveMatCartesian_Refactored2D_SetValueInAllEntries( void* constitutiveMatrix, double value ) {
-	ConstitutiveMat_Refactored* self   = (ConstitutiveMat_Refactored*) constitutiveMatrix;
-
-	if ( fabs( value ) < 1.0e-20 ) 
-		ConstitutiveMat_Refactored_ZeroMatrix( self );
-	else {
-		double**            D      = self->matrixData;
-
-		D[0][0] = D[0][1] = D[0][2] = value;
-		D[1][0] = D[1][1] = D[1][2] = value;
-		D[2][0] = D[2][1] = D[2][2] = value;
-	
-		self->isDiagonal = False;
-	}
-}
-
-void _ConstitutiveMatCartesian_Refactored3D_SetValueInAllEntries( void* _constitutiveMatrix, double value ) {
-	ConstitutiveMat_Refactored* self   = (ConstitutiveMat_Refactored*)_constitutiveMatrix;
-
-	if ( fabs( value ) < 1.0e-20 ) 
-		ConstitutiveMat_Refactored_ZeroMatrix( self );
-	else {
-		double**            D      = self->matrixData;
-
-		D[0][0] = D[0][1] = D[0][2] = D[0][3] = D[0][4] = D[0][5] = value;
-		D[1][0] = D[1][1] = D[1][2] = D[1][3] = D[1][4] = D[1][5] = value;
-		D[2][0] = D[2][1] = D[2][2] = D[2][3] = D[2][4] = D[2][5] = value;
-		D[3][0] = D[3][1] = D[3][2] = D[3][3] = D[3][4] = D[3][5] = value;
-		D[4][0] = D[4][1] = D[4][2] = D[4][3] = D[4][4] = D[4][5] = value;
-		D[5][0] = D[5][1] = D[5][2] = D[5][3] = D[5][4] = D[5][5] = value;
-	
-		self->isDiagonal = False;
-	}
-}
-
-double _ConstitutiveMatCartesian_Refactored_GetIsotropicViscosity( void* constitutiveMatrix ) {
-	ConstitutiveMat_Refactored* self   = (ConstitutiveMat_Refactored*) constitutiveMatrix;
-
-	self->_getViscosity = ( self->dim == 2 ? 
-			_ConstitutiveMatCartesian_Refactored2D_GetIsotropicViscosity :
-			_ConstitutiveMatCartesian_Refactored3D_GetIsotropicViscosity );
-
-	return ConstitutiveMat_Refactored_GetIsotropicViscosity( self );
-}
-
-double _ConstitutiveMatCartesian_Refactored2D_GetIsotropicViscosity( void* constitutiveMatrix ) {
-	ConstitutiveMat_Refactored* self = (ConstitutiveMat_Refactored*) constitutiveMatrix;
-
-	return self->matrixData[2][2];
-}
-
-double _ConstitutiveMatCartesian_Refactored3D_GetIsotropicViscosity( void* constitutiveMatrix ) {
-	ConstitutiveMat_Refactored* self = (ConstitutiveMat_Refactored*) constitutiveMatrix;
-
-	return self->matrixData[3][3];
-}
-
-void _ConstitutiveMatCartesian_Refactored_IsotropicCorrection( void* constitutiveMatrix, double isotropicCorrection ) {
-	ConstitutiveMat_Refactored* self   = (ConstitutiveMat_Refactored*) constitutiveMatrix;
-
-	self->_isotropicCorrection = ( self->dim == 2 ? 
-			_ConstitutiveMatCartesian_Refactored2D_IsotropicCorrection :
-			_ConstitutiveMatCartesian_Refactored3D_IsotropicCorrection );
-
-	ConstitutiveMat_Refactored_IsotropicCorrection( self, isotropicCorrection );
-}
-
-void _ConstitutiveMatCartesian_Refactored2D_IsotropicCorrection( void* constitutiveMatrix, double isotropicCorrection ) {
-	ConstitutiveMat_Refactored* self   = (ConstitutiveMat_Refactored*) constitutiveMatrix;
-	double**            D      = self->matrixData;
-		
-	D[0][0] += 2.0 * isotropicCorrection;
-	D[1][1] += 2.0 * isotropicCorrection;
-	D[2][2] += isotropicCorrection;
-}
-
-void _ConstitutiveMatCartesian_Refactored3D_IsotropicCorrection( void* constitutiveMatrix, double isotropicCorrection ) {
-	ConstitutiveMat_Refactored* self   = (ConstitutiveMat_Refactored*) constitutiveMatrix;
-	double**            D      = self->matrixData;
-
-	D[0][0] += 2.0 * isotropicCorrection;
-	D[1][1] += 2.0 * isotropicCorrection;
-	D[2][2] += 2.0 * isotropicCorrection;
-	
-	D[3][3] += isotropicCorrection;
-	D[4][4] += isotropicCorrection;
-	D[5][5] += isotropicCorrection;
-}
-
-void _ConstitutiveMatCartesian_Refactored_SetSecondViscosity( void* constitutiveMatrix, double deltaViscosity, XYZ director ) {
-	ConstitutiveMat_Refactored* self   = (ConstitutiveMat_Refactored*) constitutiveMatrix;
-
-	self->_setSecondViscosity = ( self->dim == 2 ? 
-			_ConstitutiveMatCartesian_Refactored2D_SetSecondViscosity :
-			_ConstitutiveMatCartesian_Refactored3D_SetSecondViscosity );
-
-	ConstitutiveMat_Refactored_SetSecondViscosity( self, deltaViscosity, director );
-}
-
-void _ConstitutiveMatCartesian_Refactored2D_SetSecondViscosity( void* constitutiveMatrix, double deltaViscosity, XYZ director ) {
-	ConstitutiveMat_Refactored* self      = (ConstitutiveMat_Refactored*) constitutiveMatrix;
-	double**            D         = self->matrixData;
-	double              n1        = director[ I_AXIS ];
-	double              n2        = director[ J_AXIS ];
-	double              a0;
-	double              a1;
-
-	a0 = 4.0 * deltaViscosity * n1 * n1 * n2 * n2;
-	a1 = 2.0 * deltaViscosity * n1 * n2 * (n2*n2 - n1*n1);
-
-	D[0][0] += -a0 ;	D[0][1] +=  a0 ;	D[0][2] += -a1 ;
-	D[1][0] +=  a0 ;	D[1][1] += -a0 ;	D[1][2] +=  a1 ;
-	D[2][0] += -a1 ;	D[2][1] +=  a1 ;	D[2][2] +=  a0 - deltaViscosity ;
-
-	self->isDiagonal = False;
-}
-
-void _ConstitutiveMatCartesian_Refactored3D_SetSecondViscosity( void* constitutiveMatrix, double deltaViscosity, XYZ director ) {
-	ConstitutiveMat_Refactored* self      = (ConstitutiveMat_Refactored*) constitutiveMatrix;
-	double**            D         = self->matrixData;
-	double              n1        = director[ I_AXIS ];
-	double              n2        = director[ J_AXIS ];
-	double              n3        = director[ K_AXIS ];
-	double              a00,a01,a02,a03,a04,a05;
-	double                  a11,a12,a13,a14,a15;
-	double                      a22,a23,a24,a25;
-	double                          a33,a34,a35;
-	double                              a44,a45;
-	double                                  a55;	
-
-	a00 = -4 * n1*n1 * ( 1 - n1*n1 ) * deltaViscosity; 
-	a01 =  4 * n1*n1 * n2*n2 * deltaViscosity; 
-	a02 =  4 * n1*n1 * n3*n3 * deltaViscosity; 
-	a03 =  2 * n1*n2 * (2*n1*n1-1) * deltaViscosity;
-	a04 =  2 * n1*n3 * (2*n1*n1-1) * deltaViscosity; 
-	a05 =  4 * n1*n1 * n2*n3 * deltaViscosity;
-		 
-	a11= 4 * n2*n2 * (n2*n2-1) * deltaViscosity; 
-	a12= 4 * n2*n2 * n3*n3 * deltaViscosity; 
-	a13= 2 * n1*n2 * (2*n2*n2-1) * deltaViscosity; 
-	a14= 4 * n1*n2 * n2*n3 * deltaViscosity;  
-	a15= 2 * n2*n3 * (2*n2*n2-1) * deltaViscosity;
-		
-	a22 = 4 * n3*n3 * (n3*n3-1) * deltaViscosity; 
-	a23 = 4 * n1*n2 * n3*n3 * deltaViscosity; 
-	a24 = 2 * n1*n3 * (2*n3*n3-1) * deltaViscosity;
-	a25 = 2 * n2*n3 * (2*n3*n3-1) * deltaViscosity;
-	 
-	a33 = (4 * n1*n1 * n2*n2 - n1*n1 - n2*n2) * deltaViscosity; 
-	a34 = (4 * n1*n1 * n2*n3 - n2*n3) * deltaViscosity; 
-	a35 = (4 * n1*n2 * n2*n3 - n1*n3) * deltaViscosity;
-	
-	a44 = (4 * n1*n1 * n3*n3 - n1*n1 -n3*n3) * deltaViscosity; 
-	a45 = (4 * n1*n2 * n3*n3 - n1*n2) * deltaViscosity;
-
-	a55 = (4 * n3*n3 * n2*n2 - n3*n3 - n2*n2) * deltaViscosity;
-		
-	/* D_{anisotropic} to D */
-	D[0][0] += a00 ; D[0][1] += a01 ; D[0][2] += a02 ; D[0][3] += a03 ; D[0][4] += a04 ; D[0][5] += a05 ;
-	D[1][0] += a01 ; D[1][1] += a11 ; D[1][2] += a12 ; D[1][3] += a13 ; D[1][4] += a14 ; D[1][5] += a15 ;
-	D[2][0] += a02 ; D[2][1] += a12 ; D[2][2] += a22 ; D[2][3] += a23 ; D[2][4] += a24 ; D[2][5] += a25 ;
-	D[3][0] += a03 ; D[3][1] += a13 ; D[3][2] += a23 ; D[3][3] += a33 ; D[3][4] += a34 ; D[3][5] += a35 ;
-	D[4][0] += a04 ; D[4][1] += a14 ; D[4][2] += a24 ; D[4][3] += a34 ; D[4][4] += a44 ; D[4][5] += a45 ;
-	D[5][0] += a05 ; D[5][1] += a15 ; D[5][2] += a25 ; D[5][3] += a35 ; D[5][4] += a45 ; D[5][5] += a55 ;
-
-	self->isDiagonal = False;
-}
-
-
-void _ConstitutiveMatCartesian_Refactored_Assemble_D_B( void* constitutiveMatrix, double** GNx, Node_Index node_I, double** D_B ) {
-	ConstitutiveMat_Refactored* self   = (ConstitutiveMat_Refactored*) constitutiveMatrix;
-
-	self->_assemble_D_B = ( self->dim == 2 ? 
-			_ConstitutiveMatCartesian_Refactored2D_Assemble_D_B :
-			_ConstitutiveMatCartesian_Refactored3D_Assemble_D_B );
-
-	ConstitutiveMat_Refactored_Assemble_D_B( self, GNx, node_I, D_B );
-}
-
-/*
-[B] = [ d/dx,     0  ]
-      [    0,  d/dy  ]
-      [ d/dy,  d/dx  ]  */
-void _ConstitutiveMatCartesian_Refactored2D_Assemble_D_B( void* constitutiveMatrix, double** GNx, Node_Index node_I, double** D_B ){
-	ConstitutiveMat_Refactored* self = (ConstitutiveMat_Refactored*) constitutiveMatrix;
-	double**            D    = self->matrixData;
-	double              d_dx = GNx[ I_AXIS ][ node_I ];
-	double              d_dy = GNx[ J_AXIS ][ node_I ];
-
-	if (self->isDiagonal) {
-		D_B[0][0] = D[0][0] * d_dx;
-		D_B[0][1] = 0.0;
-				
-		D_B[1][0] = 0.0;
-		D_B[1][1] = D[1][1] * d_dy;
-				
-		D_B[2][0] = D[2][2] * d_dy;
-		D_B[2][1] = D[2][2] * d_dx;		
-	}
-	else {
-		D_B[0][0] = D[0][0] * d_dx + D[0][2] * d_dy;
-		D_B[0][1] = D[0][1] * d_dy + D[0][2] * d_dx;
-				
-		D_B[1][0] = D[1][0] * d_dx + D[1][2] * d_dy;
-		D_B[1][1] = D[1][1] * d_dy + D[1][2] * d_dx;
-				
-		D_B[2][0] = D[2][0] * d_dx + D[2][2] * d_dy;
-		D_B[2][1] = D[2][1] * d_dy + D[2][2] * d_dx;
-	}
-}
-
-
-/*
-[B] = [ d/dx,     0,      0  ]
-      [    0,  d/dy,      0  ]
-      [    0,     0,   d/dx  ]
-      [ d/dy,  d/dx,      0  ] 
-      [ d/dz,     0,   d/dx  ]
-      [    0,  d/dz,   d/dy  ] */
-void _ConstitutiveMatCartesian_Refactored3D_Assemble_D_B( void* constitutiveMatrix, double** GNx, Node_Index node_I, double** D_B ){
-	ConstitutiveMat_Refactored* self = (ConstitutiveMat_Refactored*) constitutiveMatrix;
-	double**            D    = self->matrixData;
-	double              d_dx = GNx[ I_AXIS ][ node_I ];
-	double              d_dy = GNx[ J_AXIS ][ node_I ];
-	double              d_dz = GNx[ K_AXIS ][ node_I ];
-
-	if (self->isDiagonal) {
-		D_B[0][0] = D[0][0] * d_dx;
-		D_B[0][1] = 0.0;
-		D_B[0][2] = 0.0;
-		
-		D_B[1][0] = 0.0;
-		D_B[1][1] = D[1][1] * d_dy;
-		D_B[1][2] = 0.0;
-
-		D_B[2][0] = 0.0;
-		D_B[2][1] = 0.0;
-		D_B[2][2] = D[2][2] * d_dz;
-
-		D_B[3][0] = D[3][3] * d_dy;
-		D_B[3][1] = D[3][3] * d_dx;
-		D_B[3][2] = 0.0;
-
-		D_B[4][0] = D[4][4] * d_dz;
-		D_B[4][1] = 0.0;
-		D_B[4][2] = D[4][4] * d_dx;
-			
-		D_B[5][0] = 0.0;
-		D_B[5][1] = D[5][5] * d_dz;
-		D_B[5][2] = D[5][5] * d_dy;
-	}
-	else {
-		D_B[0][0] = D[0][0] * d_dx + D[0][3] * d_dy + D[0][4] * d_dz;
-		D_B[0][1] = D[0][1] * d_dy + D[0][3] * d_dx + D[0][5] * d_dz;
-		D_B[0][2] = D[0][2] * d_dz + D[0][4] * d_dx + D[0][5] * d_dy;
-		
-		D_B[1][0] = D[1][0] * d_dx + D[1][3] * d_dy + D[1][4] * d_dz;
-		D_B[1][1] = D[1][1] * d_dy + D[1][3] * d_dx + D[1][5] * d_dz;
-		D_B[1][2] = D[1][2] * d_dz + D[1][4] * d_dx + D[1][5] * d_dy;
-
-		D_B[2][0] = D[2][0] * d_dx + D[2][3] * d_dy + D[2][4] * d_dz;
-		D_B[2][1] = D[2][1] * d_dy + D[2][3] * d_dx + D[2][5] * d_dz;
-		D_B[2][2] = D[2][2] * d_dz + D[2][4] * d_dx + D[2][5] * d_dy;
-
-		D_B[3][0] = D[3][0] * d_dx + D[3][3] * d_dy + D[3][4] * d_dz;
-		D_B[3][1] = D[3][1] * d_dy + D[3][3] * d_dx + D[3][5] * d_dz;
-		D_B[3][2] = D[3][2] * d_dz + D[3][4] * d_dx + D[3][5] * d_dy;
-
-		D_B[4][0] = D[4][0] * d_dx + D[4][3] * d_dy + D[4][4] * d_dz;
-		D_B[4][1] = D[4][1] * d_dy + D[4][3] * d_dx + D[4][5] * d_dz;
-		D_B[4][2] = D[4][2] * d_dz + D[4][4] * d_dx + D[4][5] * d_dy;
-			
-		D_B[5][0] = D[5][0] * d_dx + D[5][3] * d_dy + D[5][4] * d_dz;
-		D_B[5][1] = D[5][1] * d_dy + D[5][3] * d_dx + D[5][5] * d_dz;
-		D_B[5][2] = D[5][2] * d_dz + D[5][4] * d_dx + D[5][5] * d_dy;
-	}
-}
-
-
-void _ConstitutiveMatCartesian_Refactored_CalculateStress( void* constitutiveMatrix, SymmetricTensor strainRate, SymmetricTensor stress ) {
-	ConstitutiveMat_Refactored* self   = (ConstitutiveMat_Refactored*) constitutiveMatrix;
-
-	self->_calculateStress = ( self->dim == 2 ? 
-			_ConstitutiveMatCartesian_Refactored2D_CalculateStress :
-			_ConstitutiveMatCartesian_Refactored3D_CalculateStress );
-
-	ConstitutiveMat_Refactored_CalculateStress( self, strainRate, stress );
-}
-
-void _ConstitutiveMatCartesian_Refactored2D_CalculateStress( void* constitutiveMatrix, SymmetricTensor strainRate, SymmetricTensor stress ) {
-	ConstitutiveMat_Refactored* self = (ConstitutiveMat_Refactored*) constitutiveMatrix;
-	double**            D    = self->matrixData;
-
-	if (self->isDiagonal) {
-		stress[0] = D[0][0] * strainRate[0];
-		stress[1] = D[1][1] * strainRate[1];
-		stress[2] = D[2][2] * 2.0 * strainRate[2];
-	}
-	else {
-		stress[0] = D[0][0] * strainRate[0] + D[0][1] * strainRate[1] + D[0][2] * 2.0 * strainRate[2];
-		stress[1] = D[1][0] * strainRate[0] + D[1][1] * strainRate[1] + D[1][2] * 2.0 * strainRate[2];
-		stress[2] = D[2][0] * strainRate[0] + D[2][1] * strainRate[1] + D[2][2] * 2.0 * strainRate[2];
-	}
-}
-
-
-
-void _ConstitutiveMatCartesian_Refactored3D_CalculateStress( void* constitutiveMatrix, SymmetricTensor strainRate, SymmetricTensor stress ) {
-	ConstitutiveMat_Refactored* self = (ConstitutiveMat_Refactored*) constitutiveMatrix;
-	double**            D    = self->matrixData;
-	          	
-	if (self->isDiagonal) {
-		stress[0] = D[0][0] * strainRate[0];
-		stress[1] = D[1][1] * strainRate[1];
-		stress[2] = D[2][2] * strainRate[2];
-		stress[3] = D[3][3] * 2.0 * strainRate[3];
-		stress[4] = D[4][4] * 2.0 * strainRate[4];
-		stress[5] = D[5][5] * 2.0 * strainRate[5];
-	}
-	else {
-		stress[0] = D[0][0] * strainRate[0] + D[0][1] * strainRate[1] + D[0][2] * strainRate[2] 
-			+ 2.0 * (D[0][3] * strainRate[3] + D[0][4] * strainRate[4] + D[0][5] * strainRate[5]);
-
-		stress[1] = D[1][0] * strainRate[0] + D[1][1] * strainRate[1] + D[1][2] * strainRate[2] 
-			+ 2.0 * (D[1][3] * strainRate[3] + D[1][4] * strainRate[4] + D[1][5] * strainRate[5]);
-
-		stress[2] = D[2][0] * strainRate[0] + D[2][1] * strainRate[1] + D[2][2] * strainRate[2] 
-			+ 2.0 * (D[2][3] * strainRate[3] + D[2][4] * strainRate[4] + D[2][5] * strainRate[5]);
-
-		stress[3] = D[3][0] * strainRate[0] + D[3][1] * strainRate[1] + D[3][2] * strainRate[2] 
-			+ 2.0 * (D[3][3] * strainRate[3] + D[3][4] * strainRate[4] + D[3][5] * strainRate[5]);
-
-		stress[4] = D[4][0] * strainRate[0] + D[4][1] * strainRate[1] + D[4][2] * strainRate[2] 
-			+ 2.0 * (D[4][3] * strainRate[3] + D[4][4] * strainRate[4] + D[4][5] * strainRate[5]);
-
-		stress[5] = D[5][0] * strainRate[0] + D[5][1] * strainRate[1] + D[5][2] * strainRate[2] 
-			+ 2.0 * (D[5][3] * strainRate[3] + D[5][4] * strainRate[4] + D[5][5] * strainRate[5]);
-	}
-}
-
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/ConstitutiveMatCartesian_Refactored.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/ConstitutiveMatCartesian_Refactored.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,521 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: ConstitutiveMatCartesian_Refactored.c 803 2008-09-11 05:22:20Z LukeHodkinson $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "Rheology_Register.h"
+#include "ConstitutiveMat_Refactored.h"
+#include "ConstitutiveMatCartesian_Refactored.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <string.h>
+#include <time.h>
+
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type ConstitutiveMatCartesian_Refactored_Type = "ConstitutiveMatCartesian_Refactored";
+
+ConstitutiveMatCartesian_Refactored* ConstitutiveMatCartesian_Refactored_New( 
+	Name							name,
+	Dimension_Index			dim,
+	PICelleratorContext*		context,
+	Materials_Register*		materials_Register )
+{
+  ConstitutiveMatCartesian_Refactored* self = (ConstitutiveMatCartesian_Refactored*)_ConstitutiveMatCartesian_Refactored_DefaultNew( name );
+
+	self->isConstructed = True;
+	_ConstitutiveMat_Refactored_Init( self, dim, context, materials_Register );
+	_ConstitutiveMatCartesian_Refactored_Init( self );
+
+	return self;
+}
+
+void* _ConstitutiveMatCartesian_Refactored_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                        _sizeOfSelf = sizeof(ConstitutiveMatCartesian_Refactored);
+	Type                                                                type = ConstitutiveMatCartesian_Refactored_Type;
+	Stg_Class_DeleteFunction*                                        _delete = _ConstitutiveMatCartesian_Refactored_Delete;
+	Stg_Class_PrintFunction*                                          _print = _ConstitutiveMatCartesian_Refactored_Print;
+	Stg_Class_CopyFunction*                                            _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*            _defaultConstructor = _ConstitutiveMatCartesian_Refactored_DefaultNew;
+	Stg_Component_ConstructFunction*                              _construct = _ConstitutiveMatCartesian_Refactored_AssignFromXML;
+	Stg_Component_BuildFunction*                                      _build = _ConstitutiveMatCartesian_Refactored_Build;
+	Stg_Component_InitialiseFunction*                            _initialise = _ConstitutiveMatCartesian_Refactored_Initialise;
+	Stg_Component_ExecuteFunction*                                  _execute = _ConstitutiveMatCartesian_Refactored_Execute;
+	Stg_Component_DestroyFunction*                                  _destroy = _ConstitutiveMatCartesian_Refactored_Destroy;
+	AllocationType                                        nameAllocationType = NON_GLOBAL;
+	ConstitutiveMat_Refactored_SetValueFunc*                       _setValue = _ConstitutiveMatCartesian_Refactored_SetValueInAllEntries;
+	ConstitutiveMat_Refactored_GetValueFunc*                   _getViscosity = _ConstitutiveMatCartesian_Refactored_GetIsotropicViscosity;
+	ConstitutiveMat_Refactored_SetValueFunc*            _isotropicCorrection = _ConstitutiveMatCartesian_Refactored_IsotropicCorrection;
+	ConstitutiveMat_Refactored_SetSecondViscosityFunc*   _setSecondViscosity = _ConstitutiveMatCartesian_Refactored_SetSecondViscosity;
+	ConstitutiveMat_Refactored_Assemble_D_B_Func*              _assemble_D_B = _ConstitutiveMatCartesian_Refactored_Assemble_D_B;
+	ConstitutiveMat_Refactored_CalculateStressFunc*         _calculateStress = _ConstitutiveMatCartesian_Refactored_CalculateStress;
+
+	return (void*)_ConstitutiveMatCartesian_Refactored_New(  CONSTITUTIVEMATCARTESIAN_REFACTORED_PASSARGS  );
+}
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+ConstitutiveMatCartesian_Refactored* _ConstitutiveMatCartesian_Refactored_New(  CONSTITUTIVEMATCARTESIAN_REFACTORED_DEFARGS  ) {
+	ConstitutiveMatCartesian_Refactored* self;
+	
+	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree.
+		At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+	assert( _sizeOfSelf >= sizeof(ConstitutiveMatCartesian_Refactored) );
+	self = (ConstitutiveMatCartesian_Refactored*) _ConstitutiveMat_Refactored_New(  CONSTITUTIVEMAT_REFACTORED_PASSARGS  );
+	
+	/* Function pointers for this class that are not on the parent class should be set here */
+	
+	return self;
+}
+
+void _ConstitutiveMatCartesian_Refactored_Init( void* constitutiveMatrix ) {
+	ConstitutiveMatCartesian_Refactored* self = (ConstitutiveMatCartesian_Refactored*)constitutiveMatrix;
+
+	self->rowSize = StGermain_nSymmetricTensorVectorComponents( self->dim );
+	self->columnSize = StGermain_nSymmetricTensorVectorComponents( self->dim );
+}
+
+void _ConstitutiveMatCartesian_Refactored_Delete( void* constitutiveMatrix ) {
+	ConstitutiveMatCartesian_Refactored* self = (ConstitutiveMatCartesian_Refactored*)constitutiveMatrix;
+
+	_ConstitutiveMat_Refactored_Delete( self );
+}
+
+void _ConstitutiveMatCartesian_Refactored_Print( void* constitutiveMatrix, Stream* stream ) {
+	ConstitutiveMatCartesian_Refactored* self = (ConstitutiveMatCartesian_Refactored*)constitutiveMatrix;
+	
+	_ConstitutiveMat_Refactored_Print( self, stream );
+
+	/* General info */
+}
+void _ConstitutiveMatCartesian_Refactored_AssignFromXML( void* constitutiveMatrix, Stg_ComponentFactory* cf, void* data ) {
+	ConstitutiveMatCartesian_Refactored* self = (ConstitutiveMatCartesian_Refactored*)constitutiveMatrix;
+
+	/* Construct Parent */
+	_ConstitutiveMat_Refactored_AssignFromXML( self, cf, data );
+
+	_ConstitutiveMatCartesian_Refactored_Init( self );
+}
+
+void _ConstitutiveMatCartesian_Refactored_Build( void* constitutiveMatrix, void* data ) {
+	ConstitutiveMatCartesian_Refactored*             self             = (ConstitutiveMatCartesian_Refactored*)constitutiveMatrix;
+
+	_ConstitutiveMat_Refactored_Build( self, data );
+}
+
+void _ConstitutiveMatCartesian_Refactored_Initialise( void* constitutiveMatrix, void* data ) {
+	ConstitutiveMatCartesian_Refactored*             self             = (ConstitutiveMatCartesian_Refactored*)constitutiveMatrix;
+
+	_ConstitutiveMat_Refactored_Initialise( self, data );
+}
+
+void _ConstitutiveMatCartesian_Refactored_Execute( void* constitutiveMatrix, void* data ) {
+	_ConstitutiveMat_Refactored_Execute( constitutiveMatrix, data );
+}
+
+void _ConstitutiveMatCartesian_Refactored_Destroy( void* constitutiveMatrix, void* data ) {
+	_ConstitutiveMat_Refactored_Destroy( constitutiveMatrix, data );
+}
+
+void _ConstitutiveMatCartesian_Refactored_SetValueInAllEntries( void* constitutiveMatrix, double value ) {
+	ConstitutiveMat_Refactored* self   = (ConstitutiveMat_Refactored*) constitutiveMatrix;
+
+	self->_setValue = ( self->dim == 2 ? 
+			_ConstitutiveMatCartesian_Refactored2D_SetValueInAllEntries :
+			_ConstitutiveMatCartesian_Refactored3D_SetValueInAllEntries );
+
+	ConstitutiveMat_Refactored_SetValueInAllEntries( self, value );
+}
+
+void _ConstitutiveMatCartesian_Refactored2D_SetValueInAllEntries( void* constitutiveMatrix, double value ) {
+	ConstitutiveMat_Refactored* self   = (ConstitutiveMat_Refactored*) constitutiveMatrix;
+
+	if ( fabs( value ) < 1.0e-20 ) 
+		ConstitutiveMat_Refactored_ZeroMatrix( self );
+	else {
+		double**            D      = self->matrixData;
+
+		D[0][0] = D[0][1] = D[0][2] = value;
+		D[1][0] = D[1][1] = D[1][2] = value;
+		D[2][0] = D[2][1] = D[2][2] = value;
+	
+		self->isDiagonal = False;
+	}
+}
+
+void _ConstitutiveMatCartesian_Refactored3D_SetValueInAllEntries( void* _constitutiveMatrix, double value ) {
+	ConstitutiveMat_Refactored* self   = (ConstitutiveMat_Refactored*)_constitutiveMatrix;
+
+	if ( fabs( value ) < 1.0e-20 ) 
+		ConstitutiveMat_Refactored_ZeroMatrix( self );
+	else {
+		double**            D      = self->matrixData;
+
+		D[0][0] = D[0][1] = D[0][2] = D[0][3] = D[0][4] = D[0][5] = value;
+		D[1][0] = D[1][1] = D[1][2] = D[1][3] = D[1][4] = D[1][5] = value;
+		D[2][0] = D[2][1] = D[2][2] = D[2][3] = D[2][4] = D[2][5] = value;
+		D[3][0] = D[3][1] = D[3][2] = D[3][3] = D[3][4] = D[3][5] = value;
+		D[4][0] = D[4][1] = D[4][2] = D[4][3] = D[4][4] = D[4][5] = value;
+		D[5][0] = D[5][1] = D[5][2] = D[5][3] = D[5][4] = D[5][5] = value;
+	
+		self->isDiagonal = False;
+	}
+}
+
+double _ConstitutiveMatCartesian_Refactored_GetIsotropicViscosity( void* constitutiveMatrix ) {
+	ConstitutiveMat_Refactored* self   = (ConstitutiveMat_Refactored*) constitutiveMatrix;
+
+	self->_getViscosity = ( self->dim == 2 ? 
+			_ConstitutiveMatCartesian_Refactored2D_GetIsotropicViscosity :
+			_ConstitutiveMatCartesian_Refactored3D_GetIsotropicViscosity );
+
+	return ConstitutiveMat_Refactored_GetIsotropicViscosity( self );
+}
+
+double _ConstitutiveMatCartesian_Refactored2D_GetIsotropicViscosity( void* constitutiveMatrix ) {
+	ConstitutiveMat_Refactored* self = (ConstitutiveMat_Refactored*) constitutiveMatrix;
+
+	return self->matrixData[2][2];
+}
+
+double _ConstitutiveMatCartesian_Refactored3D_GetIsotropicViscosity( void* constitutiveMatrix ) {
+	ConstitutiveMat_Refactored* self = (ConstitutiveMat_Refactored*) constitutiveMatrix;
+
+	return self->matrixData[3][3];
+}
+
+void _ConstitutiveMatCartesian_Refactored_IsotropicCorrection( void* constitutiveMatrix, double isotropicCorrection ) {
+	ConstitutiveMat_Refactored* self   = (ConstitutiveMat_Refactored*) constitutiveMatrix;
+
+	self->_isotropicCorrection = ( self->dim == 2 ? 
+			_ConstitutiveMatCartesian_Refactored2D_IsotropicCorrection :
+			_ConstitutiveMatCartesian_Refactored3D_IsotropicCorrection );
+
+	ConstitutiveMat_Refactored_IsotropicCorrection( self, isotropicCorrection );
+}
+
+void _ConstitutiveMatCartesian_Refactored2D_IsotropicCorrection( void* constitutiveMatrix, double isotropicCorrection ) {
+	ConstitutiveMat_Refactored* self   = (ConstitutiveMat_Refactored*) constitutiveMatrix;
+	double**            D      = self->matrixData;
+		
+	D[0][0] += 2.0 * isotropicCorrection;
+	D[1][1] += 2.0 * isotropicCorrection;
+	D[2][2] += isotropicCorrection;
+}
+
+void _ConstitutiveMatCartesian_Refactored3D_IsotropicCorrection( void* constitutiveMatrix, double isotropicCorrection ) {
+	ConstitutiveMat_Refactored* self   = (ConstitutiveMat_Refactored*) constitutiveMatrix;
+	double**            D      = self->matrixData;
+
+	D[0][0] += 2.0 * isotropicCorrection;
+	D[1][1] += 2.0 * isotropicCorrection;
+	D[2][2] += 2.0 * isotropicCorrection;
+	
+	D[3][3] += isotropicCorrection;
+	D[4][4] += isotropicCorrection;
+	D[5][5] += isotropicCorrection;
+}
+
+void _ConstitutiveMatCartesian_Refactored_SetSecondViscosity( void* constitutiveMatrix, double deltaViscosity, XYZ director ) {
+	ConstitutiveMat_Refactored* self   = (ConstitutiveMat_Refactored*) constitutiveMatrix;
+
+	self->_setSecondViscosity = ( self->dim == 2 ? 
+			_ConstitutiveMatCartesian_Refactored2D_SetSecondViscosity :
+			_ConstitutiveMatCartesian_Refactored3D_SetSecondViscosity );
+
+	ConstitutiveMat_Refactored_SetSecondViscosity( self, deltaViscosity, director );
+}
+
+void _ConstitutiveMatCartesian_Refactored2D_SetSecondViscosity( void* constitutiveMatrix, double deltaViscosity, XYZ director ) {
+	ConstitutiveMat_Refactored* self      = (ConstitutiveMat_Refactored*) constitutiveMatrix;
+	double**            D         = self->matrixData;
+	double              n1        = director[ I_AXIS ];
+	double              n2        = director[ J_AXIS ];
+	double              a0;
+	double              a1;
+
+	a0 = 4.0 * deltaViscosity * n1 * n1 * n2 * n2;
+	a1 = 2.0 * deltaViscosity * n1 * n2 * (n2*n2 - n1*n1);
+
+	D[0][0] += -a0 ;	D[0][1] +=  a0 ;	D[0][2] += -a1 ;
+	D[1][0] +=  a0 ;	D[1][1] += -a0 ;	D[1][2] +=  a1 ;
+	D[2][0] += -a1 ;	D[2][1] +=  a1 ;	D[2][2] +=  a0 - deltaViscosity ;
+
+	self->isDiagonal = False;
+}
+
+void _ConstitutiveMatCartesian_Refactored3D_SetSecondViscosity( void* constitutiveMatrix, double deltaViscosity, XYZ director ) {
+	ConstitutiveMat_Refactored* self      = (ConstitutiveMat_Refactored*) constitutiveMatrix;
+	double**            D         = self->matrixData;
+	double              n1        = director[ I_AXIS ];
+	double              n2        = director[ J_AXIS ];
+	double              n3        = director[ K_AXIS ];
+	double              a00,a01,a02,a03,a04,a05;
+	double                  a11,a12,a13,a14,a15;
+	double                      a22,a23,a24,a25;
+	double                          a33,a34,a35;
+	double                              a44,a45;
+	double                                  a55;	
+
+	a00 = -4 * n1*n1 * ( 1 - n1*n1 ) * deltaViscosity; 
+	a01 =  4 * n1*n1 * n2*n2 * deltaViscosity; 
+	a02 =  4 * n1*n1 * n3*n3 * deltaViscosity; 
+	a03 =  2 * n1*n2 * (2*n1*n1-1) * deltaViscosity;
+	a04 =  2 * n1*n3 * (2*n1*n1-1) * deltaViscosity; 
+	a05 =  4 * n1*n1 * n2*n3 * deltaViscosity;
+		 
+	a11= 4 * n2*n2 * (n2*n2-1) * deltaViscosity; 
+	a12= 4 * n2*n2 * n3*n3 * deltaViscosity; 
+	a13= 2 * n1*n2 * (2*n2*n2-1) * deltaViscosity; 
+	a14= 4 * n1*n2 * n2*n3 * deltaViscosity;  
+	a15= 2 * n2*n3 * (2*n2*n2-1) * deltaViscosity;
+		
+	a22 = 4 * n3*n3 * (n3*n3-1) * deltaViscosity; 
+	a23 = 4 * n1*n2 * n3*n3 * deltaViscosity; 
+	a24 = 2 * n1*n3 * (2*n3*n3-1) * deltaViscosity;
+	a25 = 2 * n2*n3 * (2*n3*n3-1) * deltaViscosity;
+	 
+	a33 = (4 * n1*n1 * n2*n2 - n1*n1 - n2*n2) * deltaViscosity; 
+	a34 = (4 * n1*n1 * n2*n3 - n2*n3) * deltaViscosity; 
+	a35 = (4 * n1*n2 * n2*n3 - n1*n3) * deltaViscosity;
+	
+	a44 = (4 * n1*n1 * n3*n3 - n1*n1 -n3*n3) * deltaViscosity; 
+	a45 = (4 * n1*n2 * n3*n3 - n1*n2) * deltaViscosity;
+
+	a55 = (4 * n3*n3 * n2*n2 - n3*n3 - n2*n2) * deltaViscosity;
+		
+	/* D_{anisotropic} to D */
+	D[0][0] += a00 ; D[0][1] += a01 ; D[0][2] += a02 ; D[0][3] += a03 ; D[0][4] += a04 ; D[0][5] += a05 ;
+	D[1][0] += a01 ; D[1][1] += a11 ; D[1][2] += a12 ; D[1][3] += a13 ; D[1][4] += a14 ; D[1][5] += a15 ;
+	D[2][0] += a02 ; D[2][1] += a12 ; D[2][2] += a22 ; D[2][3] += a23 ; D[2][4] += a24 ; D[2][5] += a25 ;
+	D[3][0] += a03 ; D[3][1] += a13 ; D[3][2] += a23 ; D[3][3] += a33 ; D[3][4] += a34 ; D[3][5] += a35 ;
+	D[4][0] += a04 ; D[4][1] += a14 ; D[4][2] += a24 ; D[4][3] += a34 ; D[4][4] += a44 ; D[4][5] += a45 ;
+	D[5][0] += a05 ; D[5][1] += a15 ; D[5][2] += a25 ; D[5][3] += a35 ; D[5][4] += a45 ; D[5][5] += a55 ;
+
+	self->isDiagonal = False;
+}
+
+
+void _ConstitutiveMatCartesian_Refactored_Assemble_D_B( void* constitutiveMatrix, double** GNx, Node_Index node_I, double** D_B ) {
+	ConstitutiveMat_Refactored* self   = (ConstitutiveMat_Refactored*) constitutiveMatrix;
+
+	self->_assemble_D_B = ( self->dim == 2 ? 
+			_ConstitutiveMatCartesian_Refactored2D_Assemble_D_B :
+			_ConstitutiveMatCartesian_Refactored3D_Assemble_D_B );
+
+	ConstitutiveMat_Refactored_Assemble_D_B( self, GNx, node_I, D_B );
+}
+
+/*
+[B] = [ d/dx,     0  ]
+      [    0,  d/dy  ]
+      [ d/dy,  d/dx  ]  */
+void _ConstitutiveMatCartesian_Refactored2D_Assemble_D_B( void* constitutiveMatrix, double** GNx, Node_Index node_I, double** D_B ){
+	ConstitutiveMat_Refactored* self = (ConstitutiveMat_Refactored*) constitutiveMatrix;
+	double**            D    = self->matrixData;
+	double              d_dx = GNx[ I_AXIS ][ node_I ];
+	double              d_dy = GNx[ J_AXIS ][ node_I ];
+
+	if (self->isDiagonal) {
+		D_B[0][0] = D[0][0] * d_dx;
+		D_B[0][1] = 0.0;
+				
+		D_B[1][0] = 0.0;
+		D_B[1][1] = D[1][1] * d_dy;
+				
+		D_B[2][0] = D[2][2] * d_dy;
+		D_B[2][1] = D[2][2] * d_dx;		
+	}
+	else {
+		D_B[0][0] = D[0][0] * d_dx + D[0][2] * d_dy;
+		D_B[0][1] = D[0][1] * d_dy + D[0][2] * d_dx;
+				
+		D_B[1][0] = D[1][0] * d_dx + D[1][2] * d_dy;
+		D_B[1][1] = D[1][1] * d_dy + D[1][2] * d_dx;
+				
+		D_B[2][0] = D[2][0] * d_dx + D[2][2] * d_dy;
+		D_B[2][1] = D[2][1] * d_dy + D[2][2] * d_dx;
+	}
+}
+
+
+/*
+[B] = [ d/dx,     0,      0  ]
+      [    0,  d/dy,      0  ]
+      [    0,     0,   d/dx  ]
+      [ d/dy,  d/dx,      0  ] 
+      [ d/dz,     0,   d/dx  ]
+      [    0,  d/dz,   d/dy  ] */
+void _ConstitutiveMatCartesian_Refactored3D_Assemble_D_B( void* constitutiveMatrix, double** GNx, Node_Index node_I, double** D_B ){
+	ConstitutiveMat_Refactored* self = (ConstitutiveMat_Refactored*) constitutiveMatrix;
+	double**            D    = self->matrixData;
+	double              d_dx = GNx[ I_AXIS ][ node_I ];
+	double              d_dy = GNx[ J_AXIS ][ node_I ];
+	double              d_dz = GNx[ K_AXIS ][ node_I ];
+
+	if (self->isDiagonal) {
+		D_B[0][0] = D[0][0] * d_dx;
+		D_B[0][1] = 0.0;
+		D_B[0][2] = 0.0;
+		
+		D_B[1][0] = 0.0;
+		D_B[1][1] = D[1][1] * d_dy;
+		D_B[1][2] = 0.0;
+
+		D_B[2][0] = 0.0;
+		D_B[2][1] = 0.0;
+		D_B[2][2] = D[2][2] * d_dz;
+
+		D_B[3][0] = D[3][3] * d_dy;
+		D_B[3][1] = D[3][3] * d_dx;
+		D_B[3][2] = 0.0;
+
+		D_B[4][0] = D[4][4] * d_dz;
+		D_B[4][1] = 0.0;
+		D_B[4][2] = D[4][4] * d_dx;
+			
+		D_B[5][0] = 0.0;
+		D_B[5][1] = D[5][5] * d_dz;
+		D_B[5][2] = D[5][5] * d_dy;
+	}
+	else {
+		D_B[0][0] = D[0][0] * d_dx + D[0][3] * d_dy + D[0][4] * d_dz;
+		D_B[0][1] = D[0][1] * d_dy + D[0][3] * d_dx + D[0][5] * d_dz;
+		D_B[0][2] = D[0][2] * d_dz + D[0][4] * d_dx + D[0][5] * d_dy;
+		
+		D_B[1][0] = D[1][0] * d_dx + D[1][3] * d_dy + D[1][4] * d_dz;
+		D_B[1][1] = D[1][1] * d_dy + D[1][3] * d_dx + D[1][5] * d_dz;
+		D_B[1][2] = D[1][2] * d_dz + D[1][4] * d_dx + D[1][5] * d_dy;
+
+		D_B[2][0] = D[2][0] * d_dx + D[2][3] * d_dy + D[2][4] * d_dz;
+		D_B[2][1] = D[2][1] * d_dy + D[2][3] * d_dx + D[2][5] * d_dz;
+		D_B[2][2] = D[2][2] * d_dz + D[2][4] * d_dx + D[2][5] * d_dy;
+
+		D_B[3][0] = D[3][0] * d_dx + D[3][3] * d_dy + D[3][4] * d_dz;
+		D_B[3][1] = D[3][1] * d_dy + D[3][3] * d_dx + D[3][5] * d_dz;
+		D_B[3][2] = D[3][2] * d_dz + D[3][4] * d_dx + D[3][5] * d_dy;
+
+		D_B[4][0] = D[4][0] * d_dx + D[4][3] * d_dy + D[4][4] * d_dz;
+		D_B[4][1] = D[4][1] * d_dy + D[4][3] * d_dx + D[4][5] * d_dz;
+		D_B[4][2] = D[4][2] * d_dz + D[4][4] * d_dx + D[4][5] * d_dy;
+			
+		D_B[5][0] = D[5][0] * d_dx + D[5][3] * d_dy + D[5][4] * d_dz;
+		D_B[5][1] = D[5][1] * d_dy + D[5][3] * d_dx + D[5][5] * d_dz;
+		D_B[5][2] = D[5][2] * d_dz + D[5][4] * d_dx + D[5][5] * d_dy;
+	}
+}
+
+
+void _ConstitutiveMatCartesian_Refactored_CalculateStress( void* constitutiveMatrix, SymmetricTensor strainRate, SymmetricTensor stress ) {
+	ConstitutiveMat_Refactored* self   = (ConstitutiveMat_Refactored*) constitutiveMatrix;
+
+	self->_calculateStress = ( self->dim == 2 ? 
+			_ConstitutiveMatCartesian_Refactored2D_CalculateStress :
+			_ConstitutiveMatCartesian_Refactored3D_CalculateStress );
+
+	ConstitutiveMat_Refactored_CalculateStress( self, strainRate, stress );
+}
+
+void _ConstitutiveMatCartesian_Refactored2D_CalculateStress( void* constitutiveMatrix, SymmetricTensor strainRate, SymmetricTensor stress ) {
+	ConstitutiveMat_Refactored* self = (ConstitutiveMat_Refactored*) constitutiveMatrix;
+	double**            D    = self->matrixData;
+
+	if (self->isDiagonal) {
+		stress[0] = D[0][0] * strainRate[0];
+		stress[1] = D[1][1] * strainRate[1];
+		stress[2] = D[2][2] * 2.0 * strainRate[2];
+	}
+	else {
+		stress[0] = D[0][0] * strainRate[0] + D[0][1] * strainRate[1] + D[0][2] * 2.0 * strainRate[2];
+		stress[1] = D[1][0] * strainRate[0] + D[1][1] * strainRate[1] + D[1][2] * 2.0 * strainRate[2];
+		stress[2] = D[2][0] * strainRate[0] + D[2][1] * strainRate[1] + D[2][2] * 2.0 * strainRate[2];
+	}
+}
+
+
+
+void _ConstitutiveMatCartesian_Refactored3D_CalculateStress( void* constitutiveMatrix, SymmetricTensor strainRate, SymmetricTensor stress ) {
+	ConstitutiveMat_Refactored* self = (ConstitutiveMat_Refactored*) constitutiveMatrix;
+	double**            D    = self->matrixData;
+	          	
+	if (self->isDiagonal) {
+		stress[0] = D[0][0] * strainRate[0];
+		stress[1] = D[1][1] * strainRate[1];
+		stress[2] = D[2][2] * strainRate[2];
+		stress[3] = D[3][3] * 2.0 * strainRate[3];
+		stress[4] = D[4][4] * 2.0 * strainRate[4];
+		stress[5] = D[5][5] * 2.0 * strainRate[5];
+	}
+	else {
+		stress[0] = D[0][0] * strainRate[0] + D[0][1] * strainRate[1] + D[0][2] * strainRate[2] 
+			+ 2.0 * (D[0][3] * strainRate[3] + D[0][4] * strainRate[4] + D[0][5] * strainRate[5]);
+
+		stress[1] = D[1][0] * strainRate[0] + D[1][1] * strainRate[1] + D[1][2] * strainRate[2] 
+			+ 2.0 * (D[1][3] * strainRate[3] + D[1][4] * strainRate[4] + D[1][5] * strainRate[5]);
+
+		stress[2] = D[2][0] * strainRate[0] + D[2][1] * strainRate[1] + D[2][2] * strainRate[2] 
+			+ 2.0 * (D[2][3] * strainRate[3] + D[2][4] * strainRate[4] + D[2][5] * strainRate[5]);
+
+		stress[3] = D[3][0] * strainRate[0] + D[3][1] * strainRate[1] + D[3][2] * strainRate[2] 
+			+ 2.0 * (D[3][3] * strainRate[3] + D[3][4] * strainRate[4] + D[3][5] * strainRate[5]);
+
+		stress[4] = D[4][0] * strainRate[0] + D[4][1] * strainRate[1] + D[4][2] * strainRate[2] 
+			+ 2.0 * (D[4][3] * strainRate[3] + D[4][4] * strainRate[4] + D[4][5] * strainRate[5]);
+
+		stress[5] = D[5][0] * strainRate[0] + D[5][1] * strainRate[1] + D[5][2] * strainRate[2] 
+			+ 2.0 * (D[5][3] * strainRate[3] + D[5][4] * strainRate[4] + D[5][5] * strainRate[5]);
+	}
+}
+
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/ConstitutiveMat_Refactored.c
--- a/Rheology/src/ConstitutiveMat_Refactored.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,326 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: ConstitutiveMat_Refactored.c 803 2008-09-11 05:22:20Z LukeHodkinson $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "Rheology_Register.h"
-#include "RheologyClass.h"
-#include "ConstitutiveMat_Refactored.h"
-#include "RheologyMaterial.h"
-
-#include <assert.h>
-#include <string.h>
-
-const Type ConstitutiveMat_Refactored_Type = "ConstitutiveMat_Refactored";
-
-ConstitutiveMat_Refactored* _ConstitutiveMat_Refactored_New(  CONSTITUTIVEMAT_REFACTORED_DEFARGS  ) {
-	ConstitutiveMat_Refactored* self;
-	
-	assert( _sizeOfSelf >= sizeof(ConstitutiveMat_Refactored) );
-	
-	/* General info */
-	self = (ConstitutiveMat_Refactored*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
-	
-	/* Virtual functions */
-	self->_setValue            = _setValue;
-	self->_getViscosity        = _getViscosity;
-	self->_isotropicCorrection = _isotropicCorrection;
-	self->_setSecondViscosity  = _setSecondViscosity;
-	self->_assemble_D_B        = _assemble_D_B;
-	self->_calculateStress     = _calculateStress;
-	
-	return self;
-}
-
-void _ConstitutiveMat_Refactored_Init(
-	void*						constitutiveMatrix,
-	Dimension_Index		dim,	
-	PICelleratorContext*	context,	
-	Materials_Register*	materials_Register ) 
-{
-	ConstitutiveMat_Refactored* self = (ConstitutiveMat_Refactored*)constitutiveMatrix;
-	/* General and Function pointers for this class that are not on the parent class should be set here should already be set */
-	
-	/* ConstitutiveMat_Refactored info */
-	self->context = context;
-	self->debug = Journal_MyStream( Debug_Type, self );
-
-	self->matrixData = NULL;
-	self->dim = dim;
-
-	self->materials_Register = materials_Register;
-	self->isDiagonal = False;
-	self->columnSize = 0;
-	self->rowSize = 0;
-
-	/* If we are restarting, there will be an existing valid solution for the velocity, pressure
-	etc fields - thus we record this so any yield rheologies will behave correctly */
-	if ( True == context->loadFromCheckPoint ) {
-		self->previousSolutionExists = True;
-	}
-	else {
-		/* Otherwise, we don't want to set this as true till we've done at least one iteration of the
-		first solve */
-		self->previousSolutionExists = False;
-	}
-
-	self->sle = NULL;
-	self->sleNonLinearIteration_I = 0;
-}
-
-
-void _ConstitutiveMat_Refactored_Delete( void* constitutiveMatrix ) {
-	ConstitutiveMat_Refactored* self = (ConstitutiveMat_Refactored*)constitutiveMatrix;
-	
-	Journal_DPrintf( self->debug, "In %s - for matrix %s\n", __func__, self->name );
-	Memory_Free( self->matrixData );
-
-	/* Stg_Class_Delete parent*/
-	_Stg_Component_Delete( self );
-	
-}
-
-void _ConstitutiveMat_Refactored_Print( void* constitutiveMatrix, Stream* stream ) {
-	ConstitutiveMat_Refactored* self = (ConstitutiveMat_Refactored*)constitutiveMatrix;
-
-	/* General info */
-	Journal_PrintPointer( stream, constitutiveMatrix );
-	Stream_Indent( stream );
-	
-	/* Print parent */
-	_Stg_Component_Print( self, stream );
-	
-	/* Function pointers for this class that are not on the parent class should be set here */
-	Journal_PrintPointer( stream, self->_setValue );
-	Journal_PrintPointer( stream, self->_getViscosity );
-	Journal_PrintPointer( stream, self->_isotropicCorrection );
-	Journal_PrintPointer( stream, self->_setSecondViscosity );
-	Journal_PrintPointer( stream, self->_assemble_D_B );
-	Journal_PrintPointer( stream, self->_calculateStress );
-
-	/* Regular Info */
-	Journal_PrintPointer( stream, self->debug );
-	ConstitutiveMat_Refactored_PrintContents( self, stream );
-				
-	Journal_PrintBool( stream, self->isDiagonal );
-	Journal_PrintValue( stream, self->dim );
-	Journal_PrintValue( stream, self->columnSize );
-	Journal_PrintValue( stream, self->rowSize );
-	Journal_PrintBool( stream, self->previousSolutionExists );
-	
-	Stream_UnIndent( stream );
-}
-
-
-void* _ConstitutiveMat_Refactored_Copy( const void* constitutiveMatrix, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	ConstitutiveMat_Refactored*	self = (ConstitutiveMat_Refactored*)constitutiveMatrix;
-	ConstitutiveMat_Refactored*	newConstitutiveMat_Refactored;
-	
-	/* TODO */ abort();
-	if (deep) {
-		newConstitutiveMat_Refactored->matrixData = Memory_Alloc_2DArray( double, self->columnSize, self->rowSize, (Name)self->name );
-	}
-	return (void* )newConstitutiveMat_Refactored;
-}
-
-void _ConstitutiveMat_Refactored_AssignFromXML( void* constitutiveMatrix, Stg_ComponentFactory* cf, void* data ) {
-	ConstitutiveMat_Refactored*	self = (ConstitutiveMat_Refactored*)constitutiveMatrix;
-	Dimension_Index					dim;
-	Materials_Register*				materialsRegister;
-	PICelleratorContext*				context;
-
-	context = (PICelleratorContext*)Stg_ComponentFactory_ConstructByName( cf, (Name)"context", PICelleratorContext, True, data );
-
-	materialsRegister = context->materials_Register;
-	assert( materialsRegister  );
-
-	dim = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, (Dictionary_Entry_Key)"dim", 0  );
-
-	_ConstitutiveMat_Refactored_Init( self, dim, context, materialsRegister );
-}
-
-void _ConstitutiveMat_Refactored_Build( void* constitutiveMatrix, void* data ) {
-	ConstitutiveMat_Refactored* self = (ConstitutiveMat_Refactored*)constitutiveMatrix;
-	Material_Index      material_I;
-	Material_Index      materialCount = Materials_Register_GetCount( self->materials_Register );
-	RheologyMaterial*   material;
-	Stream*             errorStream = Journal_Register( Error_Type, (Name)self->type  );
-
-	Journal_DPrintf( self->debug, "In %s - for matrix %s\n", __func__, self->name );
-
-	self->matrixData = Memory_Alloc_2DArray( double, self->columnSize, self->rowSize, (Name)self->name  );
-/*
-        self->deriv = AllocArray2D( double, (self->dim + 1), (self->dim + 1) );
-*/
-
-	for ( material_I = 0 ; material_I < materialCount ; material_I++ ) {
-		material = (RheologyMaterial*) Materials_Register_GetByIndex( self->materials_Register, material_I );
-		Journal_Firewall( Stg_Class_IsInstance( material, RheologyMaterial_Type ),
-			errorStream,
-			"Error - in %s(): while checking if each "
-				"RheologyMaterial is non-linear, found a material of type %s, which is "
-				"not a subclass of RheologyMaterial. Currently, if you wish to use the "
-				"underworld constitutive matrix to assemble over a swarm, _every_ material "
-				"must be a RheologyMaterial.\n", __func__, material->type );
-
-		/* calls the StiffnessMatrix_SetNonLinear macro which just sets the isNonLinear flag for the 
-		 * stiffnessMatrix. No longer using stiffnessMatrices, and the isNonLinear flag doesn't seem to
-		 * be used anywhere, so its probably ok not to set it (I HOPE!!!) - dave. 27.02.09 */
-		//if ( RheologyMaterial_IsNonLinear( material ) ) 
-		//	ConstitutiveMat_Refactored_SetToNonLinear( self );
-	}
-}
-
-
-void _ConstitutiveMat_Refactored_Initialise( void* constitutiveMatrix, void* data ) {
-	ConstitutiveMat_Refactored* self          = (ConstitutiveMat_Refactored*)constitutiveMatrix;
-
-	Journal_DPrintf( self->debug, "In %s - for matrix %s\n", __func__, self->name );
-	
-	ConstitutiveMat_Refactored_ZeroMatrix( self ) ;
-}
-
-
-void _ConstitutiveMat_Refactored_Execute( void* constitutiveMatrix, void* data ) {
-	Stg_Component_Execute( constitutiveMatrix, data, False );
-}
-
-void _ConstitutiveMat_Refactored_Destroy( void* constitutiveMatrix, void* data ) {
-	Stg_Component_Destroy( constitutiveMatrix, data, False );
-}
-
-/* +++ Private Functions +++ */
-
-/* +++ Public Functions +++ */
-
-void ConstitutiveMat_Refactored_Assemble( 
-		void*                                              constitutiveMatrix,
-		Element_LocalIndex                                 lElement_I,
-		IntegrationPointsSwarm*				   swarm,
-		int                                                particleIndex,
-		IntegrationPoint*                                  particle )
-{
-	ConstitutiveMat_Refactored*     self          = (ConstitutiveMat_Refactored*)constitutiveMatrix;
-	RheologyMaterial*       material;
-	MaterialPointsSwarm*    materialSwarm;
-	MaterialPoint*          materialPoint;
-
-	/* Big fat assumption!
-	 * Because of Rheology framework vs PIC IP mapping change, ConstitutiveMat_Refactored assumes that
-	 * we are using a one-to-one mapping.
-	 * This is because the Rheology stuff was made based on operating on MaterialPoints
-	 * rather than IntegrationPoints even though its assembling. However it does require xi
-	 * which we are passing from the integration point for speed (rather than re-computing it)
-	 *
-	 * _Init() firewalls this assumption.
-	 *
-	 * Proper fix for this is to reassess the Rheology/ConstitutiveMat_Refactored design
-	 *
-	 * -- Alan 20060421
-	 */
-	material = (RheologyMaterial*) IntegrationPointsSwarm_GetMaterialOn( swarm, particle );
-	materialPoint = OneToOneMapper_GetMaterialPoint( swarm->mapper, particle, &materialSwarm );
-	self->currentParticleIndex = particleIndex;
-
-	/* need to change the interface for this function, so it takes in a new constitutive matrix */
-	/* TODO!!! not sure if passing a ConstitutiveMat_Refactored to this function is going to be a problem !!!TODO */
-	RheologyMaterial_RunRheologies( material, (ConstitutiveMatrix*)self, materialSwarm, lElement_I, materialPoint, particle->xi );
-	Journal_DPrintfL( self->debug, 3, "Viscosity = %g\n", ConstitutiveMat_Refactored_GetIsotropicViscosity( self ) );
-}
-
-void ConstitutiveMat_Refactored_ZeroMatrix( void* constitutiveMatrix ) {
-	ConstitutiveMat_Refactored* self   = (ConstitutiveMat_Refactored*)constitutiveMatrix;
-
-	memset( self->matrixData[0], 0, (self->columnSize * self->rowSize)*sizeof(double) );
-        memset( self->derivs, 0, 3 * 3 * sizeof(double) );
-	self->isDiagonal = True;
-}
-
-void ConstitutiveMat_Refactored_SetIsotropicViscosity( void* constitutiveMatrix, double viscosity ) {
-	ConstitutiveMat_Refactored* self = (ConstitutiveMat_Refactored*)constitutiveMatrix;
-
-	ConstitutiveMat_Refactored_ZeroMatrix( self );
-	ConstitutiveMat_Refactored_IsotropicCorrection( self, viscosity );
-	self->isDiagonal = True;
-}	
-
-void ConstitutiveMat_Refactored_MultiplyByValue( void* constitutiveMatrix, double factor ) {
-	ConstitutiveMat_Refactored* self       = (ConstitutiveMat_Refactored*)constitutiveMatrix;
-	Index               row_I;
-	Index               col_I;
-	Index               columnSize = self->columnSize;
-	Index               rowSize    = self->rowSize;
-	double*             columnValue;
-
-	for ( col_I = 0 ; col_I < columnSize ; col_I++ ) {
-		columnValue = self->matrixData[ col_I ];
-
-		for ( row_I = 0 ; row_I < rowSize ; row_I++ ) {
-			columnValue[ row_I ] *= factor;
-		}
-
-	}
-}
-	
-void ConstitutiveMat_Refactored_PrintContents( void* constitutiveMatrix, Stream* stream ) {
-	ConstitutiveMat_Refactored* self   = (ConstitutiveMat_Refactored*)constitutiveMatrix;
-	Index               row_I;
-	Index               col_I;
-
-	for ( col_I = 0 ; col_I < self->columnSize ; col_I++ ) {
-		for ( row_I = 0 ; row_I < self->rowSize ; row_I++ ) {
-			Journal_Printf( stream, "matrixData[ %u ][ %u ] = %.4g; \t", col_I, row_I, self->matrixData[ col_I ][ row_I ] );
-		}
-		Journal_Printf( stream, "\n" );
-	}
-}
-
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/ConstitutiveMat_Refactored.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/ConstitutiveMat_Refactored.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,326 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: ConstitutiveMat_Refactored.c 803 2008-09-11 05:22:20Z LukeHodkinson $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "Rheology_Register.h"
+#include "RheologyClass.h"
+#include "ConstitutiveMat_Refactored.h"
+#include "RheologyMaterial.h"
+
+#include <assert.h>
+#include <string.h>
+
+const Type ConstitutiveMat_Refactored_Type = "ConstitutiveMat_Refactored";
+
+ConstitutiveMat_Refactored* _ConstitutiveMat_Refactored_New(  CONSTITUTIVEMAT_REFACTORED_DEFARGS  ) {
+	ConstitutiveMat_Refactored* self;
+	
+	assert( _sizeOfSelf >= sizeof(ConstitutiveMat_Refactored) );
+	
+	/* General info */
+	self = (ConstitutiveMat_Refactored*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
+	
+	/* Virtual functions */
+	self->_setValue            = _setValue;
+	self->_getViscosity        = _getViscosity;
+	self->_isotropicCorrection = _isotropicCorrection;
+	self->_setSecondViscosity  = _setSecondViscosity;
+	self->_assemble_D_B        = _assemble_D_B;
+	self->_calculateStress     = _calculateStress;
+	
+	return self;
+}
+
+void _ConstitutiveMat_Refactored_Init(
+	void*						constitutiveMatrix,
+	Dimension_Index		dim,	
+	PICelleratorContext*	context,	
+	Materials_Register*	materials_Register ) 
+{
+	ConstitutiveMat_Refactored* self = (ConstitutiveMat_Refactored*)constitutiveMatrix;
+	/* General and Function pointers for this class that are not on the parent class should be set here should already be set */
+	
+	/* ConstitutiveMat_Refactored info */
+	self->context = context;
+	self->debug = Journal_MyStream( Debug_Type, self );
+
+	self->matrixData = NULL;
+	self->dim = dim;
+
+	self->materials_Register = materials_Register;
+	self->isDiagonal = False;
+	self->columnSize = 0;
+	self->rowSize = 0;
+
+	/* If we are restarting, there will be an existing valid solution for the velocity, pressure
+	etc fields - thus we record this so any yield rheologies will behave correctly */
+	if ( True == context->loadFromCheckPoint ) {
+		self->previousSolutionExists = True;
+	}
+	else {
+		/* Otherwise, we don't want to set this as true till we've done at least one iteration of the
+		first solve */
+		self->previousSolutionExists = False;
+	}
+
+	self->sle = NULL;
+	self->sleNonLinearIteration_I = 0;
+}
+
+
+void _ConstitutiveMat_Refactored_Delete( void* constitutiveMatrix ) {
+	ConstitutiveMat_Refactored* self = (ConstitutiveMat_Refactored*)constitutiveMatrix;
+	
+	Journal_DPrintf( self->debug, "In %s - for matrix %s\n", __func__, self->name );
+	Memory_Free( self->matrixData );
+
+	/* Stg_Class_Delete parent*/
+	_Stg_Component_Delete( self );
+	
+}
+
+void _ConstitutiveMat_Refactored_Print( void* constitutiveMatrix, Stream* stream ) {
+	ConstitutiveMat_Refactored* self = (ConstitutiveMat_Refactored*)constitutiveMatrix;
+
+	/* General info */
+	Journal_PrintPointer( stream, constitutiveMatrix );
+	Stream_Indent( stream );
+	
+	/* Print parent */
+	_Stg_Component_Print( self, stream );
+	
+	/* Function pointers for this class that are not on the parent class should be set here */
+	Journal_PrintPointer( stream, self->_setValue );
+	Journal_PrintPointer( stream, self->_getViscosity );
+	Journal_PrintPointer( stream, self->_isotropicCorrection );
+	Journal_PrintPointer( stream, self->_setSecondViscosity );
+	Journal_PrintPointer( stream, self->_assemble_D_B );
+	Journal_PrintPointer( stream, self->_calculateStress );
+
+	/* Regular Info */
+	Journal_PrintPointer( stream, self->debug );
+	ConstitutiveMat_Refactored_PrintContents( self, stream );
+				
+	Journal_PrintBool( stream, self->isDiagonal );
+	Journal_PrintValue( stream, self->dim );
+	Journal_PrintValue( stream, self->columnSize );
+	Journal_PrintValue( stream, self->rowSize );
+	Journal_PrintBool( stream, self->previousSolutionExists );
+	
+	Stream_UnIndent( stream );
+}
+
+
+void* _ConstitutiveMat_Refactored_Copy( const void* constitutiveMatrix, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	ConstitutiveMat_Refactored*	self = (ConstitutiveMat_Refactored*)constitutiveMatrix;
+	ConstitutiveMat_Refactored*	newConstitutiveMat_Refactored;
+	
+	/* TODO */ abort();
+	if (deep) {
+		newConstitutiveMat_Refactored->matrixData = Memory_Alloc_2DArray( double, self->columnSize, self->rowSize, (Name)self->name );
+	}
+	return (void* )newConstitutiveMat_Refactored;
+}
+
+void _ConstitutiveMat_Refactored_AssignFromXML( void* constitutiveMatrix, Stg_ComponentFactory* cf, void* data ) {
+	ConstitutiveMat_Refactored*	self = (ConstitutiveMat_Refactored*)constitutiveMatrix;
+	Dimension_Index					dim;
+	Materials_Register*				materialsRegister;
+	PICelleratorContext*				context;
+
+	context = (PICelleratorContext*)Stg_ComponentFactory_ConstructByName( cf, (Name)"context", PICelleratorContext, True, data );
+
+	materialsRegister = context->materials_Register;
+	assert( materialsRegister  );
+
+	dim = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, (Dictionary_Entry_Key)"dim", 0  );
+
+	_ConstitutiveMat_Refactored_Init( self, dim, context, materialsRegister );
+}
+
+void _ConstitutiveMat_Refactored_Build( void* constitutiveMatrix, void* data ) {
+	ConstitutiveMat_Refactored* self = (ConstitutiveMat_Refactored*)constitutiveMatrix;
+	Material_Index      material_I;
+	Material_Index      materialCount = Materials_Register_GetCount( self->materials_Register );
+	RheologyMaterial*   material;
+	Stream*             errorStream = Journal_Register( Error_Type, (Name)self->type  );
+
+	Journal_DPrintf( self->debug, "In %s - for matrix %s\n", __func__, self->name );
+
+	self->matrixData = Memory_Alloc_2DArray( double, self->columnSize, self->rowSize, (Name)self->name  );
+/*
+        self->deriv = AllocArray2D( double, (self->dim + 1), (self->dim + 1) );
+*/
+
+	for ( material_I = 0 ; material_I < materialCount ; material_I++ ) {
+		material = (RheologyMaterial*) Materials_Register_GetByIndex( self->materials_Register, material_I );
+		Journal_Firewall( Stg_Class_IsInstance( material, RheologyMaterial_Type ),
+			errorStream,
+			"Error - in %s(): while checking if each "
+				"RheologyMaterial is non-linear, found a material of type %s, which is "
+				"not a subclass of RheologyMaterial. Currently, if you wish to use the "
+				"underworld constitutive matrix to assemble over a swarm, _every_ material "
+				"must be a RheologyMaterial.\n", __func__, material->type );
+
+		/* calls the StiffnessMatrix_SetNonLinear macro which just sets the isNonLinear flag for the 
+		 * stiffnessMatrix. No longer using stiffnessMatrices, and the isNonLinear flag doesn't seem to
+		 * be used anywhere, so its probably ok not to set it (I HOPE!!!) - dave. 27.02.09 */
+		//if ( RheologyMaterial_IsNonLinear( material ) ) 
+		//	ConstitutiveMat_Refactored_SetToNonLinear( self );
+	}
+}
+
+
+void _ConstitutiveMat_Refactored_Initialise( void* constitutiveMatrix, void* data ) {
+	ConstitutiveMat_Refactored* self          = (ConstitutiveMat_Refactored*)constitutiveMatrix;
+
+	Journal_DPrintf( self->debug, "In %s - for matrix %s\n", __func__, self->name );
+	
+	ConstitutiveMat_Refactored_ZeroMatrix( self ) ;
+}
+
+
+void _ConstitutiveMat_Refactored_Execute( void* constitutiveMatrix, void* data ) {
+	Stg_Component_Execute( constitutiveMatrix, data, False );
+}
+
+void _ConstitutiveMat_Refactored_Destroy( void* constitutiveMatrix, void* data ) {
+	Stg_Component_Destroy( constitutiveMatrix, data, False );
+}
+
+/* +++ Private Functions +++ */
+
+/* +++ Public Functions +++ */
+
+void ConstitutiveMat_Refactored_Assemble( 
+		void*                                              constitutiveMatrix,
+		Element_LocalIndex                                 lElement_I,
+		IntegrationPointsSwarm*				   swarm,
+		int                                                particleIndex,
+		IntegrationPoint*                                  particle )
+{
+	ConstitutiveMat_Refactored*     self          = (ConstitutiveMat_Refactored*)constitutiveMatrix;
+	RheologyMaterial*       material;
+	MaterialPointsSwarm*    materialSwarm;
+	MaterialPoint*          materialPoint;
+
+	/* Big fat assumption!
+	 * Because of Rheology framework vs PIC IP mapping change, ConstitutiveMat_Refactored assumes that
+	 * we are using a one-to-one mapping.
+	 * This is because the Rheology stuff was made based on operating on MaterialPoints
+	 * rather than IntegrationPoints even though its assembling. However it does require xi
+	 * which we are passing from the integration point for speed (rather than re-computing it)
+	 *
+	 * _Init() firewalls this assumption.
+	 *
+	 * Proper fix for this is to reassess the Rheology/ConstitutiveMat_Refactored design
+	 *
+	 * -- Alan 20060421
+	 */
+	material = (RheologyMaterial*) IntegrationPointsSwarm_GetMaterialOn( swarm, particle );
+	materialPoint = OneToOneMapper_GetMaterialPoint( swarm->mapper, particle, &materialSwarm );
+	self->currentParticleIndex = particleIndex;
+
+	/* need to change the interface for this function, so it takes in a new constitutive matrix */
+	/* TODO!!! not sure if passing a ConstitutiveMat_Refactored to this function is going to be a problem !!!TODO */
+	RheologyMaterial_RunRheologies( material, (ConstitutiveMatrix*)self, materialSwarm, lElement_I, materialPoint, particle->xi );
+	Journal_DPrintfL( self->debug, 3, "Viscosity = %g\n", ConstitutiveMat_Refactored_GetIsotropicViscosity( self ) );
+}
+
+void ConstitutiveMat_Refactored_ZeroMatrix( void* constitutiveMatrix ) {
+	ConstitutiveMat_Refactored* self   = (ConstitutiveMat_Refactored*)constitutiveMatrix;
+
+	memset( self->matrixData[0], 0, (self->columnSize * self->rowSize)*sizeof(double) );
+        memset( self->derivs, 0, 3 * 3 * sizeof(double) );
+	self->isDiagonal = True;
+}
+
+void ConstitutiveMat_Refactored_SetIsotropicViscosity( void* constitutiveMatrix, double viscosity ) {
+	ConstitutiveMat_Refactored* self = (ConstitutiveMat_Refactored*)constitutiveMatrix;
+
+	ConstitutiveMat_Refactored_ZeroMatrix( self );
+	ConstitutiveMat_Refactored_IsotropicCorrection( self, viscosity );
+	self->isDiagonal = True;
+}	
+
+void ConstitutiveMat_Refactored_MultiplyByValue( void* constitutiveMatrix, double factor ) {
+	ConstitutiveMat_Refactored* self       = (ConstitutiveMat_Refactored*)constitutiveMatrix;
+	Index               row_I;
+	Index               col_I;
+	Index               columnSize = self->columnSize;
+	Index               rowSize    = self->rowSize;
+	double*             columnValue;
+
+	for ( col_I = 0 ; col_I < columnSize ; col_I++ ) {
+		columnValue = self->matrixData[ col_I ];
+
+		for ( row_I = 0 ; row_I < rowSize ; row_I++ ) {
+			columnValue[ row_I ] *= factor;
+		}
+
+	}
+}
+	
+void ConstitutiveMat_Refactored_PrintContents( void* constitutiveMatrix, Stream* stream ) {
+	ConstitutiveMat_Refactored* self   = (ConstitutiveMat_Refactored*)constitutiveMatrix;
+	Index               row_I;
+	Index               col_I;
+
+	for ( col_I = 0 ; col_I < self->columnSize ; col_I++ ) {
+		for ( row_I = 0 ; row_I < self->rowSize ; row_I++ ) {
+			Journal_Printf( stream, "matrixData[ %u ][ %u ] = %.4g; \t", col_I, row_I, self->matrixData[ col_I ][ row_I ] );
+		}
+		Journal_Printf( stream, "\n" );
+	}
+}
+
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/ConstitutiveMatrix.c
--- a/Rheology/src/ConstitutiveMatrix.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,422 +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:
-*+    Robert Turnbull
-*+    Vincent Lemiale
-*+    Louis Moresi
-*+    David May
-*+    David Stegman
-*+    Mirko Velic
-*+    Patrick Sunter
-*+    Julian Giordani
-*+
-** $Id: ConstitutiveMatrix.c 803 2008-09-11 05:22:20Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "Rheology_Register.h"
-#include "RheologyClass.h"
-#include "ConstitutiveMatrix.h"
-#include "RheologyMaterial.h"
-
-#include <assert.h>
-#include <string.h>
-
-const Type ConstitutiveMatrix_Type = "ConstitutiveMatrix";
-
-ConstitutiveMatrix* _ConstitutiveMatrix_New(  CONSTITUTIVEMATRIX_DEFARGS  )
-{
-   ConstitutiveMatrix*  self;
-
-   assert( _sizeOfSelf >= sizeof(ConstitutiveMatrix) );
-
-   /* General info */
-   self = (ConstitutiveMatrix*)_StiffnessMatrixTerm_New(  STIFFNESSMATRIXTERM_PASSARGS  );
-
-   /* Virtual functions */
-   self->_setValue            = _setValue;
-   self->_getViscosity        = _getViscosity;
-   self->_isotropicCorrection = _isotropicCorrection;
-   self->_setSecondViscosity  = _setSecondViscosity;
-   self->_assemble_D_B        = _assemble_D_B;
-   self->_calculateStress     = _calculateStress;
-
-   return self;
-}
-
-void _ConstitutiveMatrix_Init(
-      ConstitutiveMatrix*                     self,
-      Dimension_Index                        dim,
-      Bool                                   storeConstitutiveMatrix )
-{
-   /* General and Function pointers for this class that are not on the parent class should be set here should already be set */
-
-   /* ConstitutiveMatrix info */
-   self->storeConstitutiveMatrix = storeConstitutiveMatrix;
-
-   self->matrixData = NULL;
-   self->dim        = dim;
-   self->isSwarmTypeIntegrationPointsSwarm = Stg_Class_IsInstance( self->integrationSwarm, IntegrationPointsSwarm_Type );
-   Journal_Firewall(
-      self->isSwarmTypeIntegrationPointsSwarm,
-      Journal_MyStream( Error_Type, self ),
-      "Error In %s - ConstitutiveMatrix %s cannot use %s. An instance of IntegrationPointsSwarm is required.\n",
-      __func__,
-      self->name,
-      self->integrationSwarm->name );
-
-   Journal_Firewall(
-      Stg_Class_IsInstance( ((IntegrationPointsSwarm*)self->integrationSwarm)->mapper, OneToOneMapper_Type ) || Stg_Class_IsInstance( ((IntegrationPointsSwarm*)self->integrationSwarm)->mapper, OneToManyMapper_Type ),
-      Journal_MyStream( Error_Type, self ),
-      "Error In %s - ConstitutiveMatrix %s cannot use %s. ConstitutiveMatrix only works with IntegrationPointsSwarms"
-      " which uses one-to-one mapping\n",
-      __func__,
-      self->name,
-      self->integrationSwarm->name );
-
-   Stg_CheckType( self->context, PICelleratorContext );
-
-   self->materials_Register  = ((PICelleratorContext*)self->context)->materials_Register;
-   Journal_Firewall( self->materials_Register!=NULL,
-      Journal_MyStream( Error_Type, self ),
-      "Error - in %s(): \n no materials_Register found \n" , __func__ );
-   
-   self->isDiagonal          = False;
-   self->columnSize          = 0;
-   self->rowSize             = 0;
-
-   /* If we are restarting, there will be an existing valid solution for the velocity, pressure
-   etc fields - thus we record this so any yield rheologies will behave correctly */
-   if ( True == self->context->loadFromCheckPoint ) {
-      self->previousSolutionExists = True;
-   }
-   else {
-      /* Otherwise, we don't want to set this as true till we've done at least one iteration of the
-      first solve */
-      self->previousSolutionExists = False;
-   }
-
-   self->sle = NULL;
-   self->sleNonLinearIteration_I = 0;
-
-}
-
-void _ConstitutiveMatrix_Delete( void* constitutiveMatrix ) {
-   ConstitutiveMatrix* self = (ConstitutiveMatrix*)constitutiveMatrix;
-
-   Journal_DPrintf( self->debug, "In %s - for matrix %s\n", __func__, self->name );
-
-   /* Stg_Class_Delete parent*/
-   _StiffnessMatrixTerm_Delete( self );
-
-}
-
-void _ConstitutiveMatrix_Print( void* constitutiveMatrix, Stream* stream ) {
-   ConstitutiveMatrix* self = (ConstitutiveMatrix*)constitutiveMatrix;
-
-   /* General info */
-   Journal_PrintPointer( stream, constitutiveMatrix );
-   Stream_Indent( stream );
-
-   /* Print parent */
-   _StiffnessMatrixTerm_Print( self, stream );
-
-   /* Function pointers for this class that are not on the parent class should be set here */
-   Journal_PrintPointer( stream, self->_setValue );
-   Journal_PrintPointer( stream, self->_getViscosity );
-   Journal_PrintPointer( stream, self->_isotropicCorrection );
-   Journal_PrintPointer( stream, self->_setSecondViscosity );
-   Journal_PrintPointer( stream, self->_assemble_D_B );
-   Journal_PrintPointer( stream, self->_calculateStress );
-
-   /* Regular Info */
-   Journal_PrintPointer( stream, self->debug );
-   ConstitutiveMatrix_PrintContents( self, stream );
-
-   Journal_PrintBool( stream, self->isDiagonal );
-   Journal_PrintValue( stream, self->dim );
-   Journal_PrintValue( stream, self->columnSize );
-   Journal_PrintValue( stream, self->rowSize );
-   Journal_PrintBool( stream, self->previousSolutionExists );
-
-   Stream_UnIndent( stream );
-}
-
-
-void* _ConstitutiveMatrix_Copy( const void* constitutiveMatrix, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-   ConstitutiveMatrix*  self = (ConstitutiveMatrix*)constitutiveMatrix;
-   ConstitutiveMatrix*  newConstitutiveMatrix;
-
-   /* TODO */ abort();
-   if (deep) {
-      newConstitutiveMatrix->matrixData = Memory_Alloc_2DArray( double, self->columnSize, self->rowSize, (Name)self->name );
-   }
-   return (void* )newConstitutiveMatrix;
-}
-
-void _ConstitutiveMatrix_AssignFromXML( void* constitutiveMatrix, Stg_ComponentFactory* cf, void* data ) {
-   ConstitutiveMatrix*	self = (ConstitutiveMatrix*)constitutiveMatrix;
-   Dimension_Index		dim;
-   Bool						storeConstitutiveMatrix;
-
-   _StiffnessMatrixTerm_AssignFromXML( self, cf, data );
-
-   dim = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, (Dictionary_Entry_Key)"dim", 0  );
-
-   storeConstitutiveMatrix = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"storeConstitutiveMatrix", False  );
-
-   _ConstitutiveMatrix_Init( self, dim, storeConstitutiveMatrix );
-}
-
-void _ConstitutiveMatrix_Build( void* constitutiveMatrix, void* data ) {
-   ConstitutiveMatrix* self = (ConstitutiveMatrix*)constitutiveMatrix;
-   Material_Index      material_I;
-   Material_Index      materialCount = Materials_Register_GetCount( self->materials_Register );
-   RheologyMaterial*   material;
-   Stream*             errorStream = Journal_Register( Error_Type, (Name)self->type  );
-
-   _StiffnessMatrixTerm_Build( self, data );
-
-   Journal_DPrintf( self->debug, "In %s - for matrix %s\n", __func__, self->name );
-
-   self->matrixData = Memory_Alloc_2DArray( double, self->columnSize, self->rowSize, (Name)self->name  );
-/*
-        self->deriv = AllocArray2D( double, (self->dim + 1), (self->dim + 1) );
-*/
-
-   for ( material_I = 0 ; material_I < materialCount ; material_I++ ) {
-      material = (RheologyMaterial*) Materials_Register_GetByIndex( self->materials_Register, material_I );
-      Journal_Firewall( Stg_Class_IsInstance( material, RheologyMaterial_Type ),
-         errorStream,
-         "Error - in %s(): while checking if each "
-            "RheologyMaterial is non-linear, found a material of type %s, which is "
-            "not a subclass of RheologyMaterial. Currently, if you wish to use the "
-            "underworld constitutive matrix to assemble over a swarm, _every_ material "
-            "must be a RheologyMaterial.\n", __func__, material->type );
-
-      if ( RheologyMaterial_IsNonLinear( material ) )
-         ConstitutiveMatrix_SetToNonLinear( self );
-   }
-}
-
-
-void _ConstitutiveMatrix_Initialise( void* constitutiveMatrix, void* data ) {
-   ConstitutiveMatrix* self          = (ConstitutiveMatrix*)constitutiveMatrix;
-
-   Journal_DPrintf( self->debug, "In %s - for matrix %s\n", __func__, self->name );
-
-
-   _StiffnessMatrixTerm_Initialise( self, data );
-
-   ConstitutiveMatrix_ZeroMatrix( self ) ;
-}
-
-
-void _ConstitutiveMatrix_Execute( void* constitutiveMatrix, void* data ) {
-   _StiffnessMatrixTerm_Execute( constitutiveMatrix, data );
-}
-
-void _ConstitutiveMatrix_Destroy( void* constitutiveMatrix, void* data ) {
-   ConstitutiveMatrix* self          = (ConstitutiveMatrix*)constitutiveMatrix;
-
-   Memory_Free( self->matrixData );
-
-   _StiffnessMatrixTerm_Destroy( self, data );
-}
-
-/* +++ Private Functions +++ */
-
-/* +++ Public Functions +++ */
-
-void ConstitutiveMatrix_Assemble(
-      void*                                              constitutiveMatrix,
-      Element_LocalIndex                                 lElement_I,
-      int                                                particleIndex,
-      IntegrationPoint*                                  particle )
-{
-   ConstitutiveMatrix*     self          = (ConstitutiveMatrix*)constitutiveMatrix;
-   IntegrationPointsSwarm* swarm         = (IntegrationPointsSwarm*)self->integrationSwarm;
-   RheologyMaterial*       material;
-   MaterialPointsSwarm*    materialSwarm;
-   MaterialPoint*          materialPoint;
-
-   /* Big fat assumption!
-    * Because of Rheology framework vs PIC IP mapping change, ConstitutiveMatrix assumes that
-    * we are using a one-to-one mapping.
-    * This is because the Rheology stuff was made based on operating on MaterialPoints
-    * rather than IntegrationPoints even though its assembling. However it does require xi
-    * which we are passing from the integration point for speed (rather than re-computing it)
-    *
-    * _Init() firewalls this assumption.
-    *
-    * Proper fix for this is to reassess the Rheology/ConstitutiveMatrix design
-    *
-    * -- Alan 20060421
-    */
-   material = (RheologyMaterial*) IntegrationPointsSwarm_GetMaterialOn( swarm, particle );
-   materialPoint = OneToOneMapper_GetMaterialPoint( swarm->mapper, particle, &materialSwarm );
-   self->currentParticleIndex = particleIndex;
-
-   RheologyMaterial_RunRheologies( material, self, materialSwarm, lElement_I, materialPoint, particle->xi );
-
-  if( self->storeConstitutiveMatrix ) {
-    /* copy the recently calculated self->matrixData, the constitutive matrix, onto the particle extension */
-    double* cMatrix = (double*)ExtensionManager_Get( materialSwarm->particleExtensionMgr, materialPoint, self->storedConstHandle );
-    Index row_I, rowSize = self->rowSize;
-    Index columnSize = self->columnSize;
-
-    /* flatten the matrix into a 1D array */
-    for( row_I = 0 ; row_I < rowSize ; row_I++ )
-      memcpy( &cMatrix[columnSize*row_I], self->matrixData[row_I], columnSize*sizeof(double) );
-  }
-   Journal_DPrintfL( self->debug, 3, "Viscosity = %g\n", ConstitutiveMatrix_GetIsotropicViscosity( self ) );
-}
-
-void ConstitutiveMatrix_AssembleMaterialPoint(void *constitutiveMatrix, int element,
-	MaterialPointsSwarm *matSwarm, int matPointInd)
-{
-	ConstitutiveMatrix *self = (ConstitutiveMatrix*)constitutiveMatrix;
-	RheologyMaterial *material;
-	MaterialPoint *matPoint;
-	double xi[3];
-
-	matPoint = (MaterialPoint*)Swarm_ParticleAt(matSwarm, matPointInd);
-	material = (RheologyMaterial*)MaterialPointsSwarm_GetMaterialOn(matSwarm, matPoint);
-	FeMesh_CoordGlobalToLocal(matSwarm->mesh, element, matPoint->coord, xi);
-	self->currentParticleIndex = matPointInd;
-	RheologyMaterial_RunRheologies(material, self, matSwarm, element, matPoint, xi);
-
-  if( self->storeConstitutiveMatrix ) {
-    /* copy the recently calculated self->matrixData, the constitutive matrix, onto the particle extension */
-    double* cMatrix = (double*)ExtensionManager_Get( matSwarm->particleExtensionMgr, matPoint, self->storedConstHandle );
-    Index row_I, rowSize = self->rowSize;
-    Index columnSize = self->columnSize;
-
-    /* flatten the matrix into a 1D array */
-    for( row_I = 0 ; row_I < rowSize ; row_I++ ) 
-      memcpy( &cMatrix[columnSize*row_I], self->matrixData[row_I], columnSize*sizeof(double) );
-  }
-	Journal_DPrintfL( self->debug, 3, "Viscosity = %g\n", ConstitutiveMatrix_GetIsotropicViscosity( self ) );
-}
-
-void ConstitutiveMatrix_ZeroMatrix( void* constitutiveMatrix ) {
-   ConstitutiveMatrix* self   = (ConstitutiveMatrix*)constitutiveMatrix;
-
-   memset( self->matrixData[0], 0, (self->columnSize * self->rowSize)*sizeof(double) );
-        memset( self->derivs, 0, 3 * 3 * sizeof(double) );
-   self->isDiagonal = True;
-}
-
-void ConstitutiveMatrix_SetIsotropicViscosity( void* constitutiveMatrix, double viscosity ) {
-   ConstitutiveMatrix* self = (ConstitutiveMatrix*)constitutiveMatrix;
-
-   ConstitutiveMatrix_ZeroMatrix( self );
-   ConstitutiveMatrix_IsotropicCorrection( self, viscosity );
-   self->isDiagonal = True;
-}
-
-void ConstitutiveMatrix_MultiplyByValue( void* constitutiveMatrix, double factor ) {
-   ConstitutiveMatrix* self       = (ConstitutiveMatrix*)constitutiveMatrix;
-   Index               row_I;
-   Index               col_I;
-   Index               columnSize = self->columnSize;
-   Index               rowSize    = self->rowSize;
-   double*             columnValue;
-
-   for ( col_I = 0 ; col_I < columnSize ; col_I++ ) {
-      columnValue = self->matrixData[ col_I ];
-
-      for ( row_I = 0 ; row_I < rowSize ; row_I++ ) {
-         columnValue[ row_I ] *= factor;
-      }
-
-   }
-}
-
-void ConstitutiveMatrix_PrintContents( void* constitutiveMatrix, Stream* stream ) {
-   ConstitutiveMatrix* self   = (ConstitutiveMatrix*)constitutiveMatrix;
-   Index               row_I;
-   Index               col_I;
-
-   for ( col_I = 0 ; col_I < self->columnSize ; col_I++ ) {
-      for ( row_I = 0 ; row_I < self->rowSize ; row_I++ ) {
-         Journal_Printf( stream, "matrixData[ %u ][ %u ] = %.4g; \t", col_I, row_I, self->matrixData[ col_I ][ row_I ] );
-      }
-      Journal_Printf( stream, "\n" );
-   }
-}
-
-Index ConstitutiveMatrix_GetParticleConstExtHandle( void* constitutiveMatrix ) {
-  /* Function definition:
-   * gets the handle that defines the "constitutive matrix on particles" extension */
-   ConstitutiveMatrix* self   = (ConstitutiveMatrix*)constitutiveMatrix;
-  return self->storedConstHandle;
-}
-
-void ConstitutiveMatrix_GetStoredMatrixOnParticle(
-    void* constitutiveMatrix,
-    IntegrationPoint* particle,
-    double** cm ) {
-  /* Function definition:
-   * given a integration point the function returns the stored constitutiveMatrix,
-   * if it's defined on the materialPoints, which maps to the int. particle
-   */
-   ConstitutiveMatrix* self   = (ConstitutiveMatrix*)constitutiveMatrix;
-  ExtensionInfo_Index handle = self->storedConstHandle;
-
-  double* ext = (double*)_OneToOneMapper_GetExtensionOn(
-      ((IntegrationPointsSwarm*)self->integrationSwarm)->mapper,
-      particle, handle );
-
-   if( self->dim == 2 ) {
-      cm[0][0] = ext[0]; cm[0][1] = ext[1]; cm[0][2] = ext[2];
-      cm[1][0] = ext[3]; cm[1][1] = ext[4]; cm[1][2] = ext[5];
-      cm[2][0] = ext[6]; cm[2][1] = ext[7]; cm[2][2] = ext[8];
-   } else {
-      cm[0][0] = ext[0]; cm[0][1] = ext[1]; cm[0][2] = ext[2]; cm[0][3] = ext[3] ; cm[0][4] = ext[4]; cm[0][5] = ext[5];
-      cm[1][0] = ext[6]; cm[1][1] = ext[7]; cm[1][2] = ext[8]; cm[1][3] = ext[9] ; cm[1][4] = ext[10]; cm[1][5] = ext[11];
-      cm[2][0] = ext[12]; cm[2][1] = ext[13]; cm[2][2] = ext[14]; cm[2][3] = ext[15] ; cm[2][4] = ext[16]; cm[2][5] = ext[17];
-      cm[3][0] = ext[18]; cm[3][1] = ext[19]; cm[3][2] = ext[20]; cm[3][3] = ext[21] ; cm[3][4] = ext[22]; cm[3][5] = ext[23];
-      cm[4][0] = ext[24]; cm[4][1] = ext[25]; cm[4][2] = ext[26]; cm[4][3] = ext[27] ; cm[4][4] = ext[28]; cm[4][5] = ext[29];
-      cm[5][0] = ext[30]; cm[5][1] = ext[31]; cm[5][2] = ext[32]; cm[5][3] = ext[33] ; cm[5][4] = ext[34]; cm[5][5] = ext[35];
-   }
-}
-
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/ConstitutiveMatrix.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/ConstitutiveMatrix.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,422 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+    Robert Turnbull
+*+    Vincent Lemiale
+*+    Louis Moresi
+*+    David May
+*+    David Stegman
+*+    Mirko Velic
+*+    Patrick Sunter
+*+    Julian Giordani
+*+
+** $Id: ConstitutiveMatrix.c 803 2008-09-11 05:22:20Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "Rheology_Register.h"
+#include "RheologyClass.h"
+#include "ConstitutiveMatrix.h"
+#include "RheologyMaterial.h"
+
+#include <assert.h>
+#include <string.h>
+
+const Type ConstitutiveMatrix_Type = "ConstitutiveMatrix";
+
+ConstitutiveMatrix* _ConstitutiveMatrix_New(  CONSTITUTIVEMATRIX_DEFARGS  )
+{
+   ConstitutiveMatrix*  self;
+
+   assert( _sizeOfSelf >= sizeof(ConstitutiveMatrix) );
+
+   /* General info */
+   self = (ConstitutiveMatrix*)_StiffnessMatrixTerm_New(  STIFFNESSMATRIXTERM_PASSARGS  );
+
+   /* Virtual functions */
+   self->_setValue            = _setValue;
+   self->_getViscosity        = _getViscosity;
+   self->_isotropicCorrection = _isotropicCorrection;
+   self->_setSecondViscosity  = _setSecondViscosity;
+   self->_assemble_D_B        = _assemble_D_B;
+   self->_calculateStress     = _calculateStress;
+
+   return self;
+}
+
+void _ConstitutiveMatrix_Init(
+      ConstitutiveMatrix*                     self,
+      Dimension_Index                        dim,
+      Bool                                   storeConstitutiveMatrix )
+{
+   /* General and Function pointers for this class that are not on the parent class should be set here should already be set */
+
+   /* ConstitutiveMatrix info */
+   self->storeConstitutiveMatrix = storeConstitutiveMatrix;
+
+   self->matrixData = NULL;
+   self->dim        = dim;
+   self->isSwarmTypeIntegrationPointsSwarm = Stg_Class_IsInstance( self->integrationSwarm, IntegrationPointsSwarm_Type );
+   Journal_Firewall(
+      self->isSwarmTypeIntegrationPointsSwarm,
+      Journal_MyStream( Error_Type, self ),
+      "Error In %s - ConstitutiveMatrix %s cannot use %s. An instance of IntegrationPointsSwarm is required.\n",
+      __func__,
+      self->name,
+      self->integrationSwarm->name );
+
+   Journal_Firewall(
+      Stg_Class_IsInstance( ((IntegrationPointsSwarm*)self->integrationSwarm)->mapper, OneToOneMapper_Type ) || Stg_Class_IsInstance( ((IntegrationPointsSwarm*)self->integrationSwarm)->mapper, OneToManyMapper_Type ),
+      Journal_MyStream( Error_Type, self ),
+      "Error In %s - ConstitutiveMatrix %s cannot use %s. ConstitutiveMatrix only works with IntegrationPointsSwarms"
+      " which uses one-to-one mapping\n",
+      __func__,
+      self->name,
+      self->integrationSwarm->name );
+
+   Stg_CheckType( self->context, PICelleratorContext );
+
+   self->materials_Register  = ((PICelleratorContext*)self->context)->materials_Register;
+   Journal_Firewall( self->materials_Register!=NULL,
+      Journal_MyStream( Error_Type, self ),
+      "Error - in %s(): \n no materials_Register found \n" , __func__ );
+   
+   self->isDiagonal          = False;
+   self->columnSize          = 0;
+   self->rowSize             = 0;
+
+   /* If we are restarting, there will be an existing valid solution for the velocity, pressure
+   etc fields - thus we record this so any yield rheologies will behave correctly */
+   if ( True == self->context->loadFromCheckPoint ) {
+      self->previousSolutionExists = True;
+   }
+   else {
+      /* Otherwise, we don't want to set this as true till we've done at least one iteration of the
+      first solve */
+      self->previousSolutionExists = False;
+   }
+
+   self->sle = NULL;
+   self->sleNonLinearIteration_I = 0;
+
+}
+
+void _ConstitutiveMatrix_Delete( void* constitutiveMatrix ) {
+   ConstitutiveMatrix* self = (ConstitutiveMatrix*)constitutiveMatrix;
+
+   Journal_DPrintf( self->debug, "In %s - for matrix %s\n", __func__, self->name );
+
+   /* Stg_Class_Delete parent*/
+   _StiffnessMatrixTerm_Delete( self );
+
+}
+
+void _ConstitutiveMatrix_Print( void* constitutiveMatrix, Stream* stream ) {
+   ConstitutiveMatrix* self = (ConstitutiveMatrix*)constitutiveMatrix;
+
+   /* General info */
+   Journal_PrintPointer( stream, constitutiveMatrix );
+   Stream_Indent( stream );
+
+   /* Print parent */
+   _StiffnessMatrixTerm_Print( self, stream );
+
+   /* Function pointers for this class that are not on the parent class should be set here */
+   Journal_PrintPointer( stream, self->_setValue );
+   Journal_PrintPointer( stream, self->_getViscosity );
+   Journal_PrintPointer( stream, self->_isotropicCorrection );
+   Journal_PrintPointer( stream, self->_setSecondViscosity );
+   Journal_PrintPointer( stream, self->_assemble_D_B );
+   Journal_PrintPointer( stream, self->_calculateStress );
+
+   /* Regular Info */
+   Journal_PrintPointer( stream, self->debug );
+   ConstitutiveMatrix_PrintContents( self, stream );
+
+   Journal_PrintBool( stream, self->isDiagonal );
+   Journal_PrintValue( stream, self->dim );
+   Journal_PrintValue( stream, self->columnSize );
+   Journal_PrintValue( stream, self->rowSize );
+   Journal_PrintBool( stream, self->previousSolutionExists );
+
+   Stream_UnIndent( stream );
+}
+
+
+void* _ConstitutiveMatrix_Copy( const void* constitutiveMatrix, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+   ConstitutiveMatrix*  self = (ConstitutiveMatrix*)constitutiveMatrix;
+   ConstitutiveMatrix*  newConstitutiveMatrix;
+
+   /* TODO */ abort();
+   if (deep) {
+      newConstitutiveMatrix->matrixData = Memory_Alloc_2DArray( double, self->columnSize, self->rowSize, (Name)self->name );
+   }
+   return (void* )newConstitutiveMatrix;
+}
+
+void _ConstitutiveMatrix_AssignFromXML( void* constitutiveMatrix, Stg_ComponentFactory* cf, void* data ) {
+   ConstitutiveMatrix*	self = (ConstitutiveMatrix*)constitutiveMatrix;
+   Dimension_Index		dim;
+   Bool						storeConstitutiveMatrix;
+
+   _StiffnessMatrixTerm_AssignFromXML( self, cf, data );
+
+   dim = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, (Dictionary_Entry_Key)"dim", 0  );
+
+   storeConstitutiveMatrix = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"storeConstitutiveMatrix", False  );
+
+   _ConstitutiveMatrix_Init( self, dim, storeConstitutiveMatrix );
+}
+
+void _ConstitutiveMatrix_Build( void* constitutiveMatrix, void* data ) {
+   ConstitutiveMatrix* self = (ConstitutiveMatrix*)constitutiveMatrix;
+   Material_Index      material_I;
+   Material_Index      materialCount = Materials_Register_GetCount( self->materials_Register );
+   RheologyMaterial*   material;
+   Stream*             errorStream = Journal_Register( Error_Type, (Name)self->type  );
+
+   _StiffnessMatrixTerm_Build( self, data );
+
+   Journal_DPrintf( self->debug, "In %s - for matrix %s\n", __func__, self->name );
+
+   self->matrixData = Memory_Alloc_2DArray( double, self->columnSize, self->rowSize, (Name)self->name  );
+/*
+        self->deriv = AllocArray2D( double, (self->dim + 1), (self->dim + 1) );
+*/
+
+   for ( material_I = 0 ; material_I < materialCount ; material_I++ ) {
+      material = (RheologyMaterial*) Materials_Register_GetByIndex( self->materials_Register, material_I );
+      Journal_Firewall( Stg_Class_IsInstance( material, RheologyMaterial_Type ),
+         errorStream,
+         "Error - in %s(): while checking if each "
+            "RheologyMaterial is non-linear, found a material of type %s, which is "
+            "not a subclass of RheologyMaterial. Currently, if you wish to use the "
+            "underworld constitutive matrix to assemble over a swarm, _every_ material "
+            "must be a RheologyMaterial.\n", __func__, material->type );
+
+      if ( RheologyMaterial_IsNonLinear( material ) )
+         ConstitutiveMatrix_SetToNonLinear( self );
+   }
+}
+
+
+void _ConstitutiveMatrix_Initialise( void* constitutiveMatrix, void* data ) {
+   ConstitutiveMatrix* self          = (ConstitutiveMatrix*)constitutiveMatrix;
+
+   Journal_DPrintf( self->debug, "In %s - for matrix %s\n", __func__, self->name );
+
+
+   _StiffnessMatrixTerm_Initialise( self, data );
+
+   ConstitutiveMatrix_ZeroMatrix( self ) ;
+}
+
+
+void _ConstitutiveMatrix_Execute( void* constitutiveMatrix, void* data ) {
+   _StiffnessMatrixTerm_Execute( constitutiveMatrix, data );
+}
+
+void _ConstitutiveMatrix_Destroy( void* constitutiveMatrix, void* data ) {
+   ConstitutiveMatrix* self          = (ConstitutiveMatrix*)constitutiveMatrix;
+
+   Memory_Free( self->matrixData );
+
+   _StiffnessMatrixTerm_Destroy( self, data );
+}
+
+/* +++ Private Functions +++ */
+
+/* +++ Public Functions +++ */
+
+void ConstitutiveMatrix_Assemble(
+      void*                                              constitutiveMatrix,
+      Element_LocalIndex                                 lElement_I,
+      int                                                particleIndex,
+      IntegrationPoint*                                  particle )
+{
+   ConstitutiveMatrix*     self          = (ConstitutiveMatrix*)constitutiveMatrix;
+   IntegrationPointsSwarm* swarm         = (IntegrationPointsSwarm*)self->integrationSwarm;
+   RheologyMaterial*       material;
+   MaterialPointsSwarm*    materialSwarm;
+   MaterialPoint*          materialPoint;
+
+   /* Big fat assumption!
+    * Because of Rheology framework vs PIC IP mapping change, ConstitutiveMatrix assumes that
+    * we are using a one-to-one mapping.
+    * This is because the Rheology stuff was made based on operating on MaterialPoints
+    * rather than IntegrationPoints even though its assembling. However it does require xi
+    * which we are passing from the integration point for speed (rather than re-computing it)
+    *
+    * _Init() firewalls this assumption.
+    *
+    * Proper fix for this is to reassess the Rheology/ConstitutiveMatrix design
+    *
+    * -- Alan 20060421
+    */
+   material = (RheologyMaterial*) IntegrationPointsSwarm_GetMaterialOn( swarm, particle );
+   materialPoint = OneToOneMapper_GetMaterialPoint( swarm->mapper, particle, &materialSwarm );
+   self->currentParticleIndex = particleIndex;
+
+   RheologyMaterial_RunRheologies( material, self, materialSwarm, lElement_I, materialPoint, particle->xi );
+
+  if( self->storeConstitutiveMatrix ) {
+    /* copy the recently calculated self->matrixData, the constitutive matrix, onto the particle extension */
+    double* cMatrix = (double*)ExtensionManager_Get( materialSwarm->particleExtensionMgr, materialPoint, self->storedConstHandle );
+    Index row_I, rowSize = self->rowSize;
+    Index columnSize = self->columnSize;
+
+    /* flatten the matrix into a 1D array */
+    for( row_I = 0 ; row_I < rowSize ; row_I++ )
+      memcpy( &cMatrix[columnSize*row_I], self->matrixData[row_I], columnSize*sizeof(double) );
+  }
+   Journal_DPrintfL( self->debug, 3, "Viscosity = %g\n", ConstitutiveMatrix_GetIsotropicViscosity( self ) );
+}
+
+void ConstitutiveMatrix_AssembleMaterialPoint(void *constitutiveMatrix, int element,
+	MaterialPointsSwarm *matSwarm, int matPointInd)
+{
+	ConstitutiveMatrix *self = (ConstitutiveMatrix*)constitutiveMatrix;
+	RheologyMaterial *material;
+	MaterialPoint *matPoint;
+	double xi[3];
+
+	matPoint = (MaterialPoint*)Swarm_ParticleAt(matSwarm, matPointInd);
+	material = (RheologyMaterial*)MaterialPointsSwarm_GetMaterialOn(matSwarm, matPoint);
+	FeMesh_CoordGlobalToLocal(matSwarm->mesh, element, matPoint->coord, xi);
+	self->currentParticleIndex = matPointInd;
+	RheologyMaterial_RunRheologies(material, self, matSwarm, element, matPoint, xi);
+
+  if( self->storeConstitutiveMatrix ) {
+    /* copy the recently calculated self->matrixData, the constitutive matrix, onto the particle extension */
+    double* cMatrix = (double*)ExtensionManager_Get( matSwarm->particleExtensionMgr, matPoint, self->storedConstHandle );
+    Index row_I, rowSize = self->rowSize;
+    Index columnSize = self->columnSize;
+
+    /* flatten the matrix into a 1D array */
+    for( row_I = 0 ; row_I < rowSize ; row_I++ ) 
+      memcpy( &cMatrix[columnSize*row_I], self->matrixData[row_I], columnSize*sizeof(double) );
+  }
+	Journal_DPrintfL( self->debug, 3, "Viscosity = %g\n", ConstitutiveMatrix_GetIsotropicViscosity( self ) );
+}
+
+void ConstitutiveMatrix_ZeroMatrix( void* constitutiveMatrix ) {
+   ConstitutiveMatrix* self   = (ConstitutiveMatrix*)constitutiveMatrix;
+
+   memset( self->matrixData[0], 0, (self->columnSize * self->rowSize)*sizeof(double) );
+        memset( self->derivs, 0, 3 * 3 * sizeof(double) );
+   self->isDiagonal = True;
+}
+
+void ConstitutiveMatrix_SetIsotropicViscosity( void* constitutiveMatrix, double viscosity ) {
+   ConstitutiveMatrix* self = (ConstitutiveMatrix*)constitutiveMatrix;
+
+   ConstitutiveMatrix_ZeroMatrix( self );
+   ConstitutiveMatrix_IsotropicCorrection( self, viscosity );
+   self->isDiagonal = True;
+}
+
+void ConstitutiveMatrix_MultiplyByValue( void* constitutiveMatrix, double factor ) {
+   ConstitutiveMatrix* self       = (ConstitutiveMatrix*)constitutiveMatrix;
+   Index               row_I;
+   Index               col_I;
+   Index               columnSize = self->columnSize;
+   Index               rowSize    = self->rowSize;
+   double*             columnValue;
+
+   for ( col_I = 0 ; col_I < columnSize ; col_I++ ) {
+      columnValue = self->matrixData[ col_I ];
+
+      for ( row_I = 0 ; row_I < rowSize ; row_I++ ) {
+         columnValue[ row_I ] *= factor;
+      }
+
+   }
+}
+
+void ConstitutiveMatrix_PrintContents( void* constitutiveMatrix, Stream* stream ) {
+   ConstitutiveMatrix* self   = (ConstitutiveMatrix*)constitutiveMatrix;
+   Index               row_I;
+   Index               col_I;
+
+   for ( col_I = 0 ; col_I < self->columnSize ; col_I++ ) {
+      for ( row_I = 0 ; row_I < self->rowSize ; row_I++ ) {
+         Journal_Printf( stream, "matrixData[ %u ][ %u ] = %.4g; \t", col_I, row_I, self->matrixData[ col_I ][ row_I ] );
+      }
+      Journal_Printf( stream, "\n" );
+   }
+}
+
+Index ConstitutiveMatrix_GetParticleConstExtHandle( void* constitutiveMatrix ) {
+  /* Function definition:
+   * gets the handle that defines the "constitutive matrix on particles" extension */
+   ConstitutiveMatrix* self   = (ConstitutiveMatrix*)constitutiveMatrix;
+  return self->storedConstHandle;
+}
+
+void ConstitutiveMatrix_GetStoredMatrixOnParticle(
+    void* constitutiveMatrix,
+    IntegrationPoint* particle,
+    double** cm ) {
+  /* Function definition:
+   * given a integration point the function returns the stored constitutiveMatrix,
+   * if it's defined on the materialPoints, which maps to the int. particle
+   */
+   ConstitutiveMatrix* self   = (ConstitutiveMatrix*)constitutiveMatrix;
+  ExtensionInfo_Index handle = self->storedConstHandle;
+
+  double* ext = (double*)_OneToOneMapper_GetExtensionOn(
+      ((IntegrationPointsSwarm*)self->integrationSwarm)->mapper,
+      particle, handle );
+
+   if( self->dim == 2 ) {
+      cm[0][0] = ext[0]; cm[0][1] = ext[1]; cm[0][2] = ext[2];
+      cm[1][0] = ext[3]; cm[1][1] = ext[4]; cm[1][2] = ext[5];
+      cm[2][0] = ext[6]; cm[2][1] = ext[7]; cm[2][2] = ext[8];
+   } else {
+      cm[0][0] = ext[0]; cm[0][1] = ext[1]; cm[0][2] = ext[2]; cm[0][3] = ext[3] ; cm[0][4] = ext[4]; cm[0][5] = ext[5];
+      cm[1][0] = ext[6]; cm[1][1] = ext[7]; cm[1][2] = ext[8]; cm[1][3] = ext[9] ; cm[1][4] = ext[10]; cm[1][5] = ext[11];
+      cm[2][0] = ext[12]; cm[2][1] = ext[13]; cm[2][2] = ext[14]; cm[2][3] = ext[15] ; cm[2][4] = ext[16]; cm[2][5] = ext[17];
+      cm[3][0] = ext[18]; cm[3][1] = ext[19]; cm[3][2] = ext[20]; cm[3][3] = ext[21] ; cm[3][4] = ext[22]; cm[3][5] = ext[23];
+      cm[4][0] = ext[24]; cm[4][1] = ext[25]; cm[4][2] = ext[26]; cm[4][3] = ext[27] ; cm[4][4] = ext[28]; cm[4][5] = ext[29];
+      cm[5][0] = ext[30]; cm[5][1] = ext[31]; cm[5][2] = ext[32]; cm[5][3] = ext[33] ; cm[5][4] = ext[34]; cm[5][5] = ext[35];
+   }
+}
+
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/ConstitutiveMatrixCartesian.c
--- a/Rheology/src/ConstitutiveMatrixCartesian.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,757 +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:
-*+    Robert Turnbull
-*+    Vincent Lemiale
-*+    Louis Moresi
-*+    David May
-*+    David Stegman
-*+    Mirko Velic
-*+    Patrick Sunter
-*+    Julian Giordani
-*+
-** $Id: ConstitutiveMatrixCartesian.c 803 2008-09-11 05:22:20Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "Rheology_Register.h"
-#include "ConstitutiveMatrix.h"
-#include "ConstitutiveMatrixCartesian.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <assert.h>
-#include <string.h>
-#include <time.h>
-
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type ConstitutiveMatrixCartesian_Type = "ConstitutiveMatrixCartesian";
-
-ConstitutiveMatrixCartesian* ConstitutiveMatrixCartesian_New(
-      Name                                                name,
-      StiffnessMatrix*                                    stiffnessMatrix,
-      Swarm*                                              swarm,
-      Dimension_Index                                     dim,
-      FiniteElementContext*                               context,
-      Materials_Register*                                 materials_Register )
-{
-   ConstitutiveMatrixCartesian* self = (ConstitutiveMatrixCartesian*) _ConstitutiveMatrixCartesian_DefaultNew( name );
-
-   _StiffnessMatrixTerm_Init( self, context, stiffnessMatrix, swarm, NULL );
-   _ConstitutiveMatrix_Init( (ConstitutiveMatrix*)self, dim, False );
-   _ConstitutiveMatrixCartesian_Init( self );
-   self->isConstructed = True;
-   return self;
-}
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-ConstitutiveMatrixCartesian* _ConstitutiveMatrixCartesian_New(  CONSTITUTIVEMATRIXCARTESIAN_DEFARGS  )
-{
-   ConstitutiveMatrixCartesian* self;
-
-   /* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-   assert( _sizeOfSelf >= sizeof(ConstitutiveMatrixCartesian) );
-   self = (ConstitutiveMatrixCartesian*) _ConstitutiveMatrix_New(  CONSTITUTIVEMATRIX_PASSARGS  );
-
-   /* Function pointers for this class that are not on the parent class should be set here */
-
-   return self;
-}
-
-void _ConstitutiveMatrixCartesian_Init(
-      ConstitutiveMatrixCartesian*                 self )
-{
-   self->rowSize = self->columnSize = StGermain_nSymmetricTensorVectorComponents( self->dim );
-   self->Dtilda_B = Memory_Alloc_2DArray( double, self->rowSize, self->dim, (Name)"D~ times B matrix" );
-
-   if( self->dim == 2 ) {
-      self->_setValue = _ConstitutiveMatrixCartesian2D_SetValueInAllEntries;
-      self->_setSecondViscosity = _ConstitutiveMatrixCartesian2D_SetSecondViscosity;
-      self->_getViscosity = _ConstitutiveMatrixCartesian2D_GetIsotropicViscosity;
-      self->_isotropicCorrection = _ConstitutiveMatrixCartesian2D_IsotropicCorrection;
-      self->_assemble_D_B = _ConstitutiveMatrixCartesian2D_Assemble_D_B;
-      self->_calculateStress = _ConstitutiveMatrixCartesian2D_CalculateStress;
-   } else {
-      self->_setValue = _ConstitutiveMatrixCartesian3D_SetValueInAllEntries;
-      self->_setSecondViscosity = _ConstitutiveMatrixCartesian3D_SetSecondViscosity;
-      self->_getViscosity = _ConstitutiveMatrixCartesian3D_GetIsotropicViscosity;
-      self->_isotropicCorrection = _ConstitutiveMatrixCartesian3D_IsotropicCorrection;
-      self->_assemble_D_B = _ConstitutiveMatrixCartesian3D_Assemble_D_B;
-      self->_calculateStress = _ConstitutiveMatrixCartesian3D_CalculateStress;
-   }
-
-  /* store each particle's constitutiveMatrix */
-  if( self->storeConstitutiveMatrix )
-      ConstitutiveMatrixCartesian_SetupParticleStorage( self );
-
-}
-
-void _ConstitutiveMatrixCartesian_Delete( void* constitutiveMatrix ) {
-   ConstitutiveMatrixCartesian* self = (ConstitutiveMatrixCartesian*)constitutiveMatrix;
-
-   _ConstitutiveMatrix_Delete( self  );
-}
-
-void _ConstitutiveMatrixCartesian_Print( void* constitutiveMatrix, Stream* stream ) {
-   ConstitutiveMatrixCartesian* self = (ConstitutiveMatrixCartesian*)constitutiveMatrix;
-
-   _ConstitutiveMatrix_Print( self, stream );
-
-   /* General info */
-}
-
-void* _ConstitutiveMatrixCartesian_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                  _sizeOfSelf = sizeof(ConstitutiveMatrixCartesian);
-	Type                                                          type = ConstitutiveMatrixCartesian_Type;
-	Stg_Class_DeleteFunction*                                  _delete = _ConstitutiveMatrixCartesian_Delete;
-	Stg_Class_PrintFunction*                                    _print = _ConstitutiveMatrixCartesian_Print;
-	Stg_Class_CopyFunction*                                      _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*      _defaultConstructor = _ConstitutiveMatrixCartesian_DefaultNew;
-	Stg_Component_ConstructFunction*                        _construct = _ConstitutiveMatrixCartesian_AssignFromXML;
-	Stg_Component_BuildFunction*                                _build = _ConstitutiveMatrixCartesian_Build;
-	Stg_Component_InitialiseFunction*                      _initialise = _ConstitutiveMatrixCartesian_Initialise;
-	Stg_Component_ExecuteFunction*                            _execute = _ConstitutiveMatrixCartesian_Execute;
-	Stg_Component_DestroyFunction*                            _destroy = _ConstitutiveMatrixCartesian_Destroy;
-	StiffnessMatrixTerm_AssembleElementFunction*      _assembleElement = _ConstitutiveMatrixCartesian_AssembleElement;
-	ConstitutiveMatrix_SetValueFunc*                         _setValue = NULL;
-	ConstitutiveMatrix_GetValueFunc*                     _getViscosity = NULL;
-	ConstitutiveMatrix_SetValueFunc*              _isotropicCorrection = NULL;
-	ConstitutiveMatrix_SetSecondViscosityFunc*     _setSecondViscosity = NULL;
-	ConstitutiveMatrix_Assemble_D_B_Func*                _assemble_D_B = NULL;
-	ConstitutiveMatrix_CalculateStressFunc*           _calculateStress = NULL;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
-
-   return (void*)_ConstitutiveMatrixCartesian_New(  CONSTITUTIVEMATRIXCARTESIAN_PASSARGS  );
-}
-
-void _ConstitutiveMatrixCartesian_AssignFromXML( void* constitutiveMatrix, Stg_ComponentFactory* cf, void* data ) {
-   ConstitutiveMatrixCartesian*            self             = (ConstitutiveMatrixCartesian*)constitutiveMatrix;
-
-   /* Construct Parent */
-   _ConstitutiveMatrix_AssignFromXML( self, cf, data );
-
-   _ConstitutiveMatrixCartesian_Init( self );
-}
-
-void _ConstitutiveMatrixCartesian_Build( void* constitutiveMatrix, void* data ) {
-   ConstitutiveMatrixCartesian*             self             = (ConstitutiveMatrixCartesian*)constitutiveMatrix;
-
-   _ConstitutiveMatrix_Build( self, data );
-
-   /* Commented out with the section ~line 695
-   if( self->storedConstSwarmVar ) 
-      Stg_Component_Build( self->storedConstSwarmVar, NULL, False );
-     */
-}
-
-void _ConstitutiveMatrixCartesian_Initialise( void* constitutiveMatrix, void* data ) {
-   ConstitutiveMatrixCartesian*             self             = (ConstitutiveMatrixCartesian*)constitutiveMatrix;
-
-   _ConstitutiveMatrix_Initialise( self, data );
-}
-
-void _ConstitutiveMatrixCartesian_Execute( void* constitutiveMatrix, void* data ) {
-   _ConstitutiveMatrix_Execute( constitutiveMatrix, data );
-}
-
-void _ConstitutiveMatrixCartesian_Destroy( void* constitutiveMatrix, void* data ) {
-   ConstitutiveMatrixCartesian* self = (ConstitutiveMatrixCartesian*)constitutiveMatrix;
-
-   Memory_Free( self->Dtilda_B );
-   Memory_Free( self->Ni );
-
-   _ConstitutiveMatrix_Destroy( constitutiveMatrix, data );
-}
-
-void _ConstitutiveMatrixCartesian_AssembleElement(
-      void*                                              constitutiveMatrix,
-      StiffnessMatrix*                                   stiffnessMatrix,
-      Element_LocalIndex                                 lElement_I,
-      SystemLinearEquations*                             sle,
-      FiniteElementContext*                              context,
-      double**                                           elStiffMat )
-{
-   ConstitutiveMatrixCartesian*     self       = (ConstitutiveMatrixCartesian*) constitutiveMatrix;
-   Swarm*                  swarm               = self->integrationSwarm;
-   FeVariable*             variable1           = stiffnessMatrix->rowVariable;
-   Dimension_Index         dim                 = stiffnessMatrix->dim;
-   IntegrationPoint*       particle;
-   Particle_InCellIndex cParticle_I;
-   Particle_InCellIndex cellParticleCount;
-   Element_NodeIndex       elementNodeCount;
-   Node_ElementLocalIndex  rowNode_I;
-   Node_ElementLocalIndex  colNode_I;
-   double**                GNx;
-   double                  detJac;
-   Cell_Index              cell_I;
-   ElementType*            elementType;
-   double                  Bj_x, Bj_y;
-   double                  Bi_x;
-   double                  Bi_y;
-   double                  Bi_z;
-   Dof_Index               rowNodeDof_I;
-   Dof_Index               colNodeDof_I;
-   Dof_Index               nodeDofCount;
-   double**                Dtilda_B;
-   double                  vel[3], velDerivs[9], *Ni, eta;
-   Bool                    oneToMany;
-
-   self->sle = sle;
-
-   /* Set the element type */
-   elementType       = FeMesh_GetElementType( variable1->feMesh, lElement_I );
-   elementNodeCount  = elementType->nodeCount;
-   nodeDofCount      = dim;
-
-   /* allocate */
-   if( elementNodeCount > self->max_nElNodes ) {
-       self->max_nElNodes = elementNodeCount;
-       self->GNx = ReallocArray2D( self->GNx, double, dim, elementNodeCount );
-       self->Ni = ReallocArray( self->Ni, double, elementNodeCount );
-   }
-   GNx = self->GNx;
-   Ni = self->Ni;
-   Dtilda_B = self->Dtilda_B;
-
-   /* Get number of particles per element */
-   cell_I            = CellLayout_MapElementIdToCellId( swarm->cellLayout, lElement_I );
-   cellParticleCount = swarm->cellParticleCountTbl[ cell_I ];
-
-   /* Determine whether this is the first solve for not */
-   Journal_Firewall( sle != NULL, Journal_Register( Error_Type, (Name)ConstitutiveMatrix_Type  ),
-         "In func %s: SLE is NULL.\n", __func__ );
-
-   /* Note: we may have deliberately set the previousSolutionExists flag to true in the
-      parent ConstitutiveMatrix constructor if in restart mode, even if the SLE hasn't executed yet
-      in this run - so only update to the sle's value when SLE is confirming it has
-      executed */
-   if ( True == sle->hasExecuted ) {
-      self->previousSolutionExists = sle->hasExecuted;
-   }
-   self->sleNonLinearIteration_I = sle->nonLinearIteration_I;
-
-   /*
-	* Keep a flag indicating whether we are usinga one-to-one swarm mapper or not.
-	*/
-
-   oneToMany = Stg_Class_IsInstance(((IntegrationPointsSwarm*)self->integrationSwarm)->mapper, OneToManyMapper_Type);
-
-   /* Loop over points to build Stiffness Matrix */
-   for ( cParticle_I = 0 ; cParticle_I < cellParticleCount ; cParticle_I++ ) {
-     particle = (IntegrationPoint*)Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
-
-      /* Calculate Determinant of Jacobian and Shape Function Global Derivatives */
-      ElementType_ShapeFunctionsGlobalDerivs(
-         elementType,
-         variable1->feMesh, lElement_I,
-         particle->xi, dim, &detJac, GNx );
-
-                /* Evalulate velocity and velocity derivatives at this particle. */
-                FeVariable_InterpolateWithinElement(
-                   variable1, lElement_I, particle->xi, vel );
-                FeVariable_InterpolateDerivatives_WithGNx(
-                   variable1, lElement_I, GNx, velDerivs );
-
-        /*
-		 * Assemble constitutive matrix. Note that we have to handle one-to-many swarms
-		 * differently.
-		 */
-
-		if(!oneToMany) {
-		    // TODO : pass in the context here?
-		    ConstitutiveMatrix_Assemble( constitutiveMatrix, lElement_I,
-						 swarm->cellParticleTbl[cell_I][cParticle_I], particle );
-		}
-		else {
-		    /*
-		     * We're dealing with a one-to-many mapper. We will assemble each material point's
-		     * constitutive matrix and combine them using their weights.
-		     */
-
-		    OneToManyRef *ref;
-		    double **matrixData;
-		    int ii, jj, kk;
-
-		    matrixData = Memory_Alloc_2DArray( double, self->columnSize, self->rowSize, (Name)self->name );
-		    memset(matrixData[0], 0, self->columnSize*self->rowSize*sizeof(double));
-		    ref = OneToManyMapper_GetMaterialRef(((IntegrationPointsSwarm*)swarm)->mapper, particle);
-		    for(ii = 0; ii < ref->numParticles; ii++) {
-			/* Assemble this material point. */
-			ConstitutiveMatrix_AssembleMaterialPoint(
-			    constitutiveMatrix, lElement_I,
-			    ((OneToManyMapper*)((IntegrationPointsSwarm*)swarm)->mapper)->materialSwarm,
-			    ref->particleInds[ii]);
-			/* Add to cumulative matrix. */
-			for(jj = 0; jj < self->rowSize; jj++) {
-			    for(kk = 0; kk < self->columnSize; kk++)
-				matrixData[jj][kk] += ref->weights[ii]*self->matrixData[jj][kk];
-			}
-		    }
-		    /* Copy matrix data and free temporary array. */
-		    memcpy(self->matrixData[0], matrixData[0], self->columnSize*self->rowSize*sizeof(double));
-		    Memory_Free(matrixData);
-		}
-
-		eta = self->matrixData[2][2];
-
-      /* Turn D Matrix into D~ Matrix by multiplying in the weight and the detJac (this is a shortcut for speed) */
-      ConstitutiveMatrix_MultiplyByValue( constitutiveMatrix, detJac * particle->weight );
-
-      for( rowNode_I = 0 ; rowNode_I < elementNodeCount ; rowNode_I++ ) {
-         rowNodeDof_I = rowNode_I*nodeDofCount;
-                        Bj_x = GNx[0][rowNode_I];
-                        Bj_y = GNx[1][rowNode_I];
-
-         /* Build D~ * B */
-         ConstitutiveMatrix_Assemble_D_B( constitutiveMatrix, GNx, rowNode_I, Dtilda_B );
-
-         for( colNode_I = 0 ; colNode_I < elementNodeCount ; colNode_I++ ) {
-            colNodeDof_I = colNode_I*nodeDofCount;
-            Bi_x = GNx[ I_AXIS ][colNode_I];
-            Bi_y = GNx[ J_AXIS ][colNode_I];
-
-            /* Build BTrans * ( D~ * B ) */
-            if ( dim == 2 ) {
-          if( !sle->nlFormJacobian ) {
-
-             elStiffMat[ colNodeDof_I     ][ rowNodeDof_I     ] += Bi_x * Dtilda_B[0][0] + Bi_y * Dtilda_B[2][0];
-             elStiffMat[ colNodeDof_I     ][ rowNodeDof_I + 1 ] += Bi_x * Dtilda_B[0][1] + Bi_y * Dtilda_B[2][1];
-             elStiffMat[ colNodeDof_I + 1 ][ rowNodeDof_I     ] += Bi_y * Dtilda_B[1][0] + Bi_x * Dtilda_B[2][0];
-             elStiffMat[ colNodeDof_I + 1 ][ rowNodeDof_I + 1 ] += Bi_y * Dtilda_B[1][1] + Bi_x * Dtilda_B[2][1];
-
-          }
-          else {
-             double DuDx, DuDy, DvDx, DvDy;
-             double DetaDu, DetaDv;
-             double intFac, fac;
-
-             DuDx = velDerivs[0]; DuDy = velDerivs[1];
-             DvDx = velDerivs[2]; DvDy = velDerivs[3];
-             DetaDu = self->derivs[0] * Bj_x + self->derivs[1] * Bj_y + self->derivs[2] * Ni[rowNode_I];
-             DetaDv = self->derivs[3] * Bj_x + self->derivs[4] * Bj_y + self->derivs[5] * Ni[rowNode_I];
-             intFac = particle->weight * detJac;
-
-             fac = eta * Bj_y + DuDy * DetaDu + DvDx * DetaDu;
-             elStiffMat[colNodeDof_I][rowNodeDof_I] +=
-                intFac * (2.0 * Bi_x * (eta * Bj_x + DuDx * DetaDu) + Bi_y * fac);
-             elStiffMat[colNodeDof_I + 1][rowNodeDof_I] +=
-                intFac * (2.0 * Bi_y * DvDy * DetaDu + Bi_x * fac);
-
-             fac = eta * Bj_x + DvDx * DetaDv + DuDy * DetaDv;
-             elStiffMat[colNodeDof_I][rowNodeDof_I + 1] +=
-                intFac * (2.0 * Bi_x * DuDx * DetaDv + Bi_y * fac);
-             elStiffMat[colNodeDof_I + 1][rowNodeDof_I + 1] +=
-                intFac * (2.0 * Bi_y * (eta * Bj_y + DvDy * DetaDv) + Bi_x * fac);
-
-          }
-            }
-            else {
-               Bi_z = GNx[ K_AXIS ][colNode_I];
-
-               elStiffMat[ colNodeDof_I     ][ rowNodeDof_I     ] +=
-                  Bi_x * Dtilda_B[0][0] + Bi_y * Dtilda_B[3][0] + Bi_z * Dtilda_B[4][0];
-               elStiffMat[ colNodeDof_I     ][ rowNodeDof_I + 1 ] +=
-                  Bi_x * Dtilda_B[0][1] + Bi_y * Dtilda_B[3][1] + Bi_z * Dtilda_B[4][1];
-               elStiffMat[ colNodeDof_I     ][ rowNodeDof_I + 2 ] +=
-                  Bi_x * Dtilda_B[0][2] + Bi_y * Dtilda_B[3][2] + Bi_z * Dtilda_B[4][2];
-
-               elStiffMat[ colNodeDof_I + 1 ][ rowNodeDof_I     ] +=
-                  Bi_y * Dtilda_B[1][0] + Bi_x * Dtilda_B[3][0] + Bi_z * Dtilda_B[5][0];
-               elStiffMat[ colNodeDof_I + 1 ][ rowNodeDof_I + 1 ] +=
-                  Bi_y * Dtilda_B[1][1] + Bi_x * Dtilda_B[3][1] + Bi_z * Dtilda_B[5][1];
-               elStiffMat[ colNodeDof_I + 1 ][ rowNodeDof_I + 2 ] +=
-                  Bi_y * Dtilda_B[1][2] + Bi_x * Dtilda_B[3][2] + Bi_z * Dtilda_B[5][2];
-
-               elStiffMat[ colNodeDof_I + 2 ][ rowNodeDof_I     ] +=
-                  Bi_z * Dtilda_B[2][0] + Bi_x * Dtilda_B[4][0] + Bi_y * Dtilda_B[5][0];
-               elStiffMat[ colNodeDof_I + 2 ][ rowNodeDof_I + 1 ] +=
-                  Bi_z * Dtilda_B[2][1] + Bi_x * Dtilda_B[4][1] + Bi_y * Dtilda_B[5][1];
-               elStiffMat[ colNodeDof_I + 2 ][ rowNodeDof_I + 2 ] +=
-                  Bi_z * Dtilda_B[2][2] + Bi_x * Dtilda_B[4][2] + Bi_y * Dtilda_B[5][2];
-            }
-         }
-      }
-   }
-}
-
-void _ConstitutiveMatrixCartesian2D_SetValueInAllEntries( void* constitutiveMatrix, double value ) {
-   ConstitutiveMatrix* self   = (ConstitutiveMatrix*) constitutiveMatrix;
-
-   if ( fabs( value ) < 1.0e-20 )
-      ConstitutiveMatrix_ZeroMatrix( self );
-   else {
-      double**            D      = self->matrixData;
-
-      D[0][0] = D[0][1] = D[0][2] = value;
-      D[1][0] = D[1][1] = D[1][2] = value;
-      D[2][0] = D[2][1] = D[2][2] = value;
-
-      self->isDiagonal = False;
-   }
-}
-
-void _ConstitutiveMatrixCartesian3D_SetValueInAllEntries( void* _constitutiveMatrix, double value ) {
-   ConstitutiveMatrix* self   = (ConstitutiveMatrix*)_constitutiveMatrix;
-
-   if ( fabs( value ) < 1.0e-20 )
-      ConstitutiveMatrix_ZeroMatrix( self );
-   else {
-      double**            D      = self->matrixData;
-
-      D[0][0] = D[0][1] = D[0][2] = D[0][3] = D[0][4] = D[0][5] = value;
-      D[1][0] = D[1][1] = D[1][2] = D[1][3] = D[1][4] = D[1][5] = value;
-      D[2][0] = D[2][1] = D[2][2] = D[2][3] = D[2][4] = D[2][5] = value;
-      D[3][0] = D[3][1] = D[3][2] = D[3][3] = D[3][4] = D[3][5] = value;
-      D[4][0] = D[4][1] = D[4][2] = D[4][3] = D[4][4] = D[4][5] = value;
-      D[5][0] = D[5][1] = D[5][2] = D[5][3] = D[5][4] = D[5][5] = value;
-
-      self->isDiagonal = False;
-   }
-}
-
-double _ConstitutiveMatrixCartesian2D_GetIsotropicViscosity( void* constitutiveMatrix ) {
-   ConstitutiveMatrix* self = (ConstitutiveMatrix*) constitutiveMatrix;
-
-   return self->matrixData[2][2];
-}
-
-double _ConstitutiveMatrixCartesian3D_GetIsotropicViscosity( void* constitutiveMatrix ) {
-   ConstitutiveMatrix* self = (ConstitutiveMatrix*) constitutiveMatrix;
-
-   return self->matrixData[3][3];
-}
-
-void _ConstitutiveMatrixCartesian2D_IsotropicCorrection( void* constitutiveMatrix, double isotropicCorrection ) {
-   ConstitutiveMatrix* self   = (ConstitutiveMatrix*) constitutiveMatrix;
-   double**            D      = self->matrixData;
-
-   D[0][0] += 2.0 * isotropicCorrection;
-   D[1][1] += 2.0 * isotropicCorrection;
-   D[2][2] += isotropicCorrection;
-}
-
-void _ConstitutiveMatrixCartesian3D_IsotropicCorrection( void* constitutiveMatrix, double isotropicCorrection ) {
-   ConstitutiveMatrix* self   = (ConstitutiveMatrix*) constitutiveMatrix;
-   double**            D      = self->matrixData;
-
-   D[0][0] += 2.0 * isotropicCorrection;
-   D[1][1] += 2.0 * isotropicCorrection;
-   D[2][2] += 2.0 * isotropicCorrection;
-
-   D[3][3] += isotropicCorrection;
-   D[4][4] += isotropicCorrection;
-   D[5][5] += isotropicCorrection;
-}
-
-void _ConstitutiveMatrixCartesian2D_SetSecondViscosity( void* constitutiveMatrix, double deltaViscosity, XYZ director ) {
-   ConstitutiveMatrix* self      = (ConstitutiveMatrix*) constitutiveMatrix;
-   double**            D         = self->matrixData;
-   double              n1        = director[ I_AXIS ];
-   double              n2        = director[ J_AXIS ];
-   double              a0;
-   double              a1;
-
-   a0 = 4.0 * deltaViscosity * n1 * n1 * n2 * n2;
-   a1 = 2.0 * deltaViscosity * n1 * n2 * (n2*n2 - n1*n1);
-
-   D[0][0] += -a0 ;  D[0][1] +=  a0 ;  D[0][2] += -a1 ;
-   D[1][0] +=  a0 ;  D[1][1] += -a0 ;  D[1][2] +=  a1 ;
-   D[2][0] += -a1 ;  D[2][1] +=  a1 ;  D[2][2] +=  a0 - deltaViscosity ;
-
-   self->isDiagonal = False;
-}
-
-void _ConstitutiveMatrixCartesian3D_SetSecondViscosity( void* constitutiveMatrix, double deltaViscosity, XYZ director ) {
-   ConstitutiveMatrix* self      = (ConstitutiveMatrix*) constitutiveMatrix;
-   double**            D         = self->matrixData;
-   double              n1        = director[ I_AXIS ];
-   double              n2        = director[ J_AXIS ];
-   double              n3        = director[ K_AXIS ];
-   double              a00,a01,a02,a03,a04,a05;
-   double                  a11,a12,a13,a14,a15;
-   double                      a22,a23,a24,a25;
-   double                          a33,a34,a35;
-   double                              a44,a45;
-   double                                  a55;
-
-   a00 = -4 * n1*n1 * ( 1 - n1*n1 ) * deltaViscosity;
-   a01 =  4 * n1*n1 * n2*n2 * deltaViscosity;
-   a02 =  4 * n1*n1 * n3*n3 * deltaViscosity;
-   a03 =  2 * n1*n2 * (2*n1*n1-1) * deltaViscosity;
-   a04 =  2 * n1*n3 * (2*n1*n1-1) * deltaViscosity;
-   a05 =  4 * n1*n1 * n2*n3 * deltaViscosity;
-
-   a11= 4 * n2*n2 * (n2*n2-1) * deltaViscosity;
-   a12= 4 * n2*n2 * n3*n3 * deltaViscosity;
-   a13= 2 * n1*n2 * (2*n2*n2-1) * deltaViscosity;
-   a14= 4 * n1*n2 * n2*n3 * deltaViscosity;
-   a15= 2 * n2*n3 * (2*n2*n2-1) * deltaViscosity;
-
-   a22 = 4 * n3*n3 * (n3*n3-1) * deltaViscosity;
-   a23 = 4 * n1*n2 * n3*n3 * deltaViscosity;
-   a24 = 2 * n1*n3 * (2*n3*n3-1) * deltaViscosity;
-   a25 = 2 * n2*n3 * (2*n3*n3-1) * deltaViscosity;
-
-   a33 = (4 * n1*n1 * n2*n2 - n1*n1 - n2*n2) * deltaViscosity;
-   a34 = (4 * n1*n1 * n2*n3 - n2*n3) * deltaViscosity;
-   a35 = (4 * n1*n2 * n2*n3 - n1*n3) * deltaViscosity;
-
-   a44 = (4 * n1*n1 * n3*n3 - n1*n1 -n3*n3) * deltaViscosity;
-   a45 = (4 * n1*n2 * n3*n3 - n1*n2) * deltaViscosity;
-
-   a55 = (4 * n3*n3 * n2*n2 - n3*n3 - n2*n2) * deltaViscosity;
-
-   /* D_{anisotropic} to D */
-   D[0][0] += a00 ; D[0][1] += a01 ; D[0][2] += a02 ; D[0][3] += a03 ; D[0][4] += a04 ; D[0][5] += a05 ;
-   D[1][0] += a01 ; D[1][1] += a11 ; D[1][2] += a12 ; D[1][3] += a13 ; D[1][4] += a14 ; D[1][5] += a15 ;
-   D[2][0] += a02 ; D[2][1] += a12 ; D[2][2] += a22 ; D[2][3] += a23 ; D[2][4] += a24 ; D[2][5] += a25 ;
-   D[3][0] += a03 ; D[3][1] += a13 ; D[3][2] += a23 ; D[3][3] += a33 ; D[3][4] += a34 ; D[3][5] += a35 ;
-   D[4][0] += a04 ; D[4][1] += a14 ; D[4][2] += a24 ; D[4][3] += a34 ; D[4][4] += a44 ; D[4][5] += a45 ;
-   D[5][0] += a05 ; D[5][1] += a15 ; D[5][2] += a25 ; D[5][3] += a35 ; D[5][4] += a45 ; D[5][5] += a55 ;
-
-   self->isDiagonal = False;
-}
-
-/*
-[B] = [ d/dx,     0  ]
-      [    0,  d/dy  ]
-      [ d/dy,  d/dx  ]  */
-void _ConstitutiveMatrixCartesian2D_Assemble_D_B( void* constitutiveMatrix, double** GNx, Node_Index node_I, double** D_B ){
-   ConstitutiveMatrix* self = (ConstitutiveMatrix*) constitutiveMatrix;
-   double**            D    = self->matrixData;
-   double              d_dx = GNx[ I_AXIS ][ node_I ];
-   double              d_dy = GNx[ J_AXIS ][ node_I ];
-
-   if (self->isDiagonal) {
-      D_B[0][0] = D[0][0] * d_dx;
-      D_B[0][1] = 0.0;
-
-      D_B[1][0] = 0.0;
-      D_B[1][1] = D[1][1] * d_dy;
-
-      D_B[2][0] = D[2][2] * d_dy;
-      D_B[2][1] = D[2][2] * d_dx;
-   }
-   else {
-      D_B[0][0] = D[0][0] * d_dx + D[0][2] * d_dy;
-      D_B[0][1] = D[0][1] * d_dy + D[0][2] * d_dx;
-
-      D_B[1][0] = D[1][0] * d_dx + D[1][2] * d_dy;
-      D_B[1][1] = D[1][1] * d_dy + D[1][2] * d_dx;
-
-      D_B[2][0] = D[2][0] * d_dx + D[2][2] * d_dy;
-      D_B[2][1] = D[2][1] * d_dy + D[2][2] * d_dx;
-   }
-}
-
-
-/*
-[B] = [ d/dx,     0,      0  ]
-      [    0,  d/dy,      0  ]
-      [    0,     0,   d/dx  ]
-      [ d/dy,  d/dx,      0  ]
-      [ d/dz,     0,   d/dx  ]
-      [    0,  d/dz,   d/dy  ] */
-void _ConstitutiveMatrixCartesian3D_Assemble_D_B( void* constitutiveMatrix, double** GNx, Node_Index node_I, double** D_B ){
-   ConstitutiveMatrix* self = (ConstitutiveMatrix*) constitutiveMatrix;
-   double**            D    = self->matrixData;
-   double              d_dx = GNx[ I_AXIS ][ node_I ];
-   double              d_dy = GNx[ J_AXIS ][ node_I ];
-   double              d_dz = GNx[ K_AXIS ][ node_I ];
-
-   if (self->isDiagonal) {
-      D_B[0][0] = D[0][0] * d_dx;
-      D_B[0][1] = 0.0;
-      D_B[0][2] = 0.0;
-
-      D_B[1][0] = 0.0;
-      D_B[1][1] = D[1][1] * d_dy;
-      D_B[1][2] = 0.0;
-
-      D_B[2][0] = 0.0;
-      D_B[2][1] = 0.0;
-      D_B[2][2] = D[2][2] * d_dz;
-
-      D_B[3][0] = D[3][3] * d_dy;
-      D_B[3][1] = D[3][3] * d_dx;
-      D_B[3][2] = 0.0;
-
-      D_B[4][0] = D[4][4] * d_dz;
-      D_B[4][1] = 0.0;
-      D_B[4][2] = D[4][4] * d_dx;
-
-      D_B[5][0] = 0.0;
-      D_B[5][1] = D[5][5] * d_dz;
-      D_B[5][2] = D[5][5] * d_dy;
-   }
-   else {
-      D_B[0][0] = D[0][0] * d_dx + D[0][3] * d_dy + D[0][4] * d_dz;
-      D_B[0][1] = D[0][1] * d_dy + D[0][3] * d_dx + D[0][5] * d_dz;
-      D_B[0][2] = D[0][2] * d_dz + D[0][4] * d_dx + D[0][5] * d_dy;
-
-      D_B[1][0] = D[1][0] * d_dx + D[1][3] * d_dy + D[1][4] * d_dz;
-      D_B[1][1] = D[1][1] * d_dy + D[1][3] * d_dx + D[1][5] * d_dz;
-      D_B[1][2] = D[1][2] * d_dz + D[1][4] * d_dx + D[1][5] * d_dy;
-
-      D_B[2][0] = D[2][0] * d_dx + D[2][3] * d_dy + D[2][4] * d_dz;
-      D_B[2][1] = D[2][1] * d_dy + D[2][3] * d_dx + D[2][5] * d_dz;
-      D_B[2][2] = D[2][2] * d_dz + D[2][4] * d_dx + D[2][5] * d_dy;
-
-      D_B[3][0] = D[3][0] * d_dx + D[3][3] * d_dy + D[3][4] * d_dz;
-      D_B[3][1] = D[3][1] * d_dy + D[3][3] * d_dx + D[3][5] * d_dz;
-      D_B[3][2] = D[3][2] * d_dz + D[3][4] * d_dx + D[3][5] * d_dy;
-
-      D_B[4][0] = D[4][0] * d_dx + D[4][3] * d_dy + D[4][4] * d_dz;
-      D_B[4][1] = D[4][1] * d_dy + D[4][3] * d_dx + D[4][5] * d_dz;
-      D_B[4][2] = D[4][2] * d_dz + D[4][4] * d_dx + D[4][5] * d_dy;
-
-      D_B[5][0] = D[5][0] * d_dx + D[5][3] * d_dy + D[5][4] * d_dz;
-      D_B[5][1] = D[5][1] * d_dy + D[5][3] * d_dx + D[5][5] * d_dz;
-      D_B[5][2] = D[5][2] * d_dz + D[5][4] * d_dx + D[5][5] * d_dy;
-   }
-}
-
-void _ConstitutiveMatrixCartesian2D_CalculateStress( void* constitutiveMatrix, SymmetricTensor strainRate, SymmetricTensor stress ) {
-   ConstitutiveMatrix* self = (ConstitutiveMatrix*) constitutiveMatrix;
-   double**            D    = self->matrixData;
-
-   if (self->isDiagonal) {
-      stress[0] = D[0][0] * strainRate[0];
-      stress[1] = D[1][1] * strainRate[1];
-      stress[2] = D[2][2] * 2.0 * strainRate[2];
-   }
-   else {
-      stress[0] = D[0][0] * strainRate[0] + D[0][1] * strainRate[1] + D[0][2] * 2.0 * strainRate[2];
-      stress[1] = D[1][0] * strainRate[0] + D[1][1] * strainRate[1] + D[1][2] * 2.0 * strainRate[2];
-      stress[2] = D[2][0] * strainRate[0] + D[2][1] * strainRate[1] + D[2][2] * 2.0 * strainRate[2];
-   }
-}
-
-
-
-void _ConstitutiveMatrixCartesian3D_CalculateStress( void* constitutiveMatrix, SymmetricTensor strainRate, SymmetricTensor stress ) {
-   ConstitutiveMatrix* self = (ConstitutiveMatrix*) constitutiveMatrix;
-   double**            D    = self->matrixData;
-
-   if (self->isDiagonal) {
-      stress[0] = D[0][0] * strainRate[0];
-      stress[1] = D[1][1] * strainRate[1];
-      stress[2] = D[2][2] * strainRate[2];
-      stress[3] = D[3][3] * 2.0 * strainRate[3];
-      stress[4] = D[4][4] * 2.0 * strainRate[4];
-      stress[5] = D[5][5] * 2.0 * strainRate[5];
-   }
-   else {
-      stress[0] = D[0][0] * strainRate[0] + D[0][1] * strainRate[1] + D[0][2] * strainRate[2]
-         + 2.0 * (D[0][3] * strainRate[3] + D[0][4] * strainRate[4] + D[0][5] * strainRate[5]);
-
-      stress[1] = D[1][0] * strainRate[0] + D[1][1] * strainRate[1] + D[1][2] * strainRate[2]
-         + 2.0 * (D[1][3] * strainRate[3] + D[1][4] * strainRate[4] + D[1][5] * strainRate[5]);
-
-      stress[2] = D[2][0] * strainRate[0] + D[2][1] * strainRate[1] + D[2][2] * strainRate[2]
-         + 2.0 * (D[2][3] * strainRate[3] + D[2][4] * strainRate[4] + D[2][5] * strainRate[5]);
-
-      stress[3] = D[3][0] * strainRate[0] + D[3][1] * strainRate[1] + D[3][2] * strainRate[2]
-         + 2.0 * (D[3][3] * strainRate[3] + D[3][4] * strainRate[4] + D[3][5] * strainRate[5]);
-
-      stress[4] = D[4][0] * strainRate[0] + D[4][1] * strainRate[1] + D[4][2] * strainRate[2]
-         + 2.0 * (D[4][3] * strainRate[3] + D[4][4] * strainRate[4] + D[4][5] * strainRate[5]);
-
-      stress[5] = D[5][0] * strainRate[0] + D[5][1] * strainRate[1] + D[5][2] * strainRate[2]
-         + 2.0 * (D[5][3] * strainRate[3] + D[5][4] * strainRate[4] + D[5][5] * strainRate[5]);
-   }
-}
-
-void ConstitutiveMatrixCartesian_SetupParticleStorage( ConstitutiveMatrixCartesian* self ) {
-   /* a function which defines the storage of each particle's constitutive information on the particle,
-    * should be called before the "Build" phase */
-
-   static int beenHere = 0; /* don't want to do this routine twice */
-
-   IntegrationPointsSwarm* swarm = (IntegrationPointsSwarm*)self->integrationSwarm;
-   MaterialPointsSwarm **materialSwarms, *materialSwarm;
-   MaterialPoint particle;
-   int materialSwarmCount;
-   double *cMatrix = NULL;
-
-   if( beenHere ) return;
-
-   beenHere = 1;
-
-   /* get material swram mapped to the integration points,
-   *      * currently only one material point is mapped 26 FEB 09 */
-   materialSwarms = IntegrationPointMapper_GetMaterialPointsSwarms( swarm->mapper, (Index*)(&materialSwarmCount) );
-   assert( materialSwarmCount < 2 );
-   materialSwarm = materialSwarms[0];
-
-   /* add extension to material swarm */
-   self->storedConstHandle = ExtensionManager_Add( materialSwarm->particleExtensionMgr, (Name)self->type, self->rowSize * self->columnSize * sizeof(double)  );
-
-   cMatrix = (double*)ExtensionManager_Get( materialSwarm->particleExtensionMgr, &particle, self->storedConstHandle );
-
-#if 0
-   /*This isn't needed so I've disabled it, 2Dec09, JG*/
-   if( self->dim == 2 ) {
-      /* TODO: clean up this vector logic. The only reson there's an if is because
-      *        * of the list of names the must be given as the final arguments to this function.  */
-      self->storedConstSwarmVar = Swarm_NewVectorVariable( materialSwarm, (Name)"ConstitutiveMatrix", (ArithPointer)cMatrix - (ArithPointer)&particle,
-      Variable_DataType_Double, self->rowSize * self->columnSize,
-      "c00", "c01", "c02", "c10", "c11", "c12", "c20", "c21", "c22" );
-   } else {
-      self->storedConstSwarmVar = Swarm_NewVectorVariable( materialSwarm, (Name)"ConstitutiveMatrix", (ArithPointer)cMatrix - (ArithPointer)&particle,
-      Variable_DataType_Double, self->rowSize * self->columnSize,
-      "c00", "c01", "c02", "c03", "c04", "c05",
-      "c10", "c11", "c12", "c13", "c14", "c15",
-      "c20", "c21", "c22", "c23", "c24", "c25",
-      "c30", "c31", "c32", "c33", "c34", "c35",
-      "c40", "c41", "c42", "c43", "c44", "c45",
-      "c50", "c51", "c52", "c53", "c54", "c55" );
-   }
-
-   /* set the storedConstitutive matrix NOT to be checkpointed */
-   self->storedConstSwarmVar->isCheckpointedAndReloaded = False;
-#endif
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/ConstitutiveMatrixCartesian.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/ConstitutiveMatrixCartesian.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,757 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+    Robert Turnbull
+*+    Vincent Lemiale
+*+    Louis Moresi
+*+    David May
+*+    David Stegman
+*+    Mirko Velic
+*+    Patrick Sunter
+*+    Julian Giordani
+*+
+** $Id: ConstitutiveMatrixCartesian.c 803 2008-09-11 05:22:20Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "Rheology_Register.h"
+#include "ConstitutiveMatrix.h"
+#include "ConstitutiveMatrixCartesian.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <string.h>
+#include <time.h>
+
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type ConstitutiveMatrixCartesian_Type = "ConstitutiveMatrixCartesian";
+
+ConstitutiveMatrixCartesian* ConstitutiveMatrixCartesian_New(
+      Name                                                name,
+      StiffnessMatrix*                                    stiffnessMatrix,
+      Swarm*                                              swarm,
+      Dimension_Index                                     dim,
+      FiniteElementContext*                               context,
+      Materials_Register*                                 materials_Register )
+{
+   ConstitutiveMatrixCartesian* self = (ConstitutiveMatrixCartesian*) _ConstitutiveMatrixCartesian_DefaultNew( name );
+
+   _StiffnessMatrixTerm_Init( self, context, stiffnessMatrix, swarm, NULL );
+   _ConstitutiveMatrix_Init( (ConstitutiveMatrix*)self, dim, False );
+   _ConstitutiveMatrixCartesian_Init( self );
+   self->isConstructed = True;
+   return self;
+}
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+ConstitutiveMatrixCartesian* _ConstitutiveMatrixCartesian_New(  CONSTITUTIVEMATRIXCARTESIAN_DEFARGS  )
+{
+   ConstitutiveMatrixCartesian* self;
+
+   /* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+   assert( _sizeOfSelf >= sizeof(ConstitutiveMatrixCartesian) );
+   self = (ConstitutiveMatrixCartesian*) _ConstitutiveMatrix_New(  CONSTITUTIVEMATRIX_PASSARGS  );
+
+   /* Function pointers for this class that are not on the parent class should be set here */
+
+   return self;
+}
+
+void _ConstitutiveMatrixCartesian_Init(
+      ConstitutiveMatrixCartesian*                 self )
+{
+   self->rowSize = self->columnSize = StGermain_nSymmetricTensorVectorComponents( self->dim );
+   self->Dtilda_B = Memory_Alloc_2DArray( double, self->rowSize, self->dim, (Name)"D~ times B matrix" );
+
+   if( self->dim == 2 ) {
+      self->_setValue = _ConstitutiveMatrixCartesian2D_SetValueInAllEntries;
+      self->_setSecondViscosity = _ConstitutiveMatrixCartesian2D_SetSecondViscosity;
+      self->_getViscosity = _ConstitutiveMatrixCartesian2D_GetIsotropicViscosity;
+      self->_isotropicCorrection = _ConstitutiveMatrixCartesian2D_IsotropicCorrection;
+      self->_assemble_D_B = _ConstitutiveMatrixCartesian2D_Assemble_D_B;
+      self->_calculateStress = _ConstitutiveMatrixCartesian2D_CalculateStress;
+   } else {
+      self->_setValue = _ConstitutiveMatrixCartesian3D_SetValueInAllEntries;
+      self->_setSecondViscosity = _ConstitutiveMatrixCartesian3D_SetSecondViscosity;
+      self->_getViscosity = _ConstitutiveMatrixCartesian3D_GetIsotropicViscosity;
+      self->_isotropicCorrection = _ConstitutiveMatrixCartesian3D_IsotropicCorrection;
+      self->_assemble_D_B = _ConstitutiveMatrixCartesian3D_Assemble_D_B;
+      self->_calculateStress = _ConstitutiveMatrixCartesian3D_CalculateStress;
+   }
+
+  /* store each particle's constitutiveMatrix */
+  if( self->storeConstitutiveMatrix )
+      ConstitutiveMatrixCartesian_SetupParticleStorage( self );
+
+}
+
+void _ConstitutiveMatrixCartesian_Delete( void* constitutiveMatrix ) {
+   ConstitutiveMatrixCartesian* self = (ConstitutiveMatrixCartesian*)constitutiveMatrix;
+
+   _ConstitutiveMatrix_Delete( self  );
+}
+
+void _ConstitutiveMatrixCartesian_Print( void* constitutiveMatrix, Stream* stream ) {
+   ConstitutiveMatrixCartesian* self = (ConstitutiveMatrixCartesian*)constitutiveMatrix;
+
+   _ConstitutiveMatrix_Print( self, stream );
+
+   /* General info */
+}
+
+void* _ConstitutiveMatrixCartesian_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                  _sizeOfSelf = sizeof(ConstitutiveMatrixCartesian);
+	Type                                                          type = ConstitutiveMatrixCartesian_Type;
+	Stg_Class_DeleteFunction*                                  _delete = _ConstitutiveMatrixCartesian_Delete;
+	Stg_Class_PrintFunction*                                    _print = _ConstitutiveMatrixCartesian_Print;
+	Stg_Class_CopyFunction*                                      _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*      _defaultConstructor = _ConstitutiveMatrixCartesian_DefaultNew;
+	Stg_Component_ConstructFunction*                        _construct = _ConstitutiveMatrixCartesian_AssignFromXML;
+	Stg_Component_BuildFunction*                                _build = _ConstitutiveMatrixCartesian_Build;
+	Stg_Component_InitialiseFunction*                      _initialise = _ConstitutiveMatrixCartesian_Initialise;
+	Stg_Component_ExecuteFunction*                            _execute = _ConstitutiveMatrixCartesian_Execute;
+	Stg_Component_DestroyFunction*                            _destroy = _ConstitutiveMatrixCartesian_Destroy;
+	StiffnessMatrixTerm_AssembleElementFunction*      _assembleElement = _ConstitutiveMatrixCartesian_AssembleElement;
+	ConstitutiveMatrix_SetValueFunc*                         _setValue = NULL;
+	ConstitutiveMatrix_GetValueFunc*                     _getViscosity = NULL;
+	ConstitutiveMatrix_SetValueFunc*              _isotropicCorrection = NULL;
+	ConstitutiveMatrix_SetSecondViscosityFunc*     _setSecondViscosity = NULL;
+	ConstitutiveMatrix_Assemble_D_B_Func*                _assemble_D_B = NULL;
+	ConstitutiveMatrix_CalculateStressFunc*           _calculateStress = NULL;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+
+   return (void*)_ConstitutiveMatrixCartesian_New(  CONSTITUTIVEMATRIXCARTESIAN_PASSARGS  );
+}
+
+void _ConstitutiveMatrixCartesian_AssignFromXML( void* constitutiveMatrix, Stg_ComponentFactory* cf, void* data ) {
+   ConstitutiveMatrixCartesian*            self             = (ConstitutiveMatrixCartesian*)constitutiveMatrix;
+
+   /* Construct Parent */
+   _ConstitutiveMatrix_AssignFromXML( self, cf, data );
+
+   _ConstitutiveMatrixCartesian_Init( self );
+}
+
+void _ConstitutiveMatrixCartesian_Build( void* constitutiveMatrix, void* data ) {
+   ConstitutiveMatrixCartesian*             self             = (ConstitutiveMatrixCartesian*)constitutiveMatrix;
+
+   _ConstitutiveMatrix_Build( self, data );
+
+   /* Commented out with the section ~line 695
+   if( self->storedConstSwarmVar ) 
+      Stg_Component_Build( self->storedConstSwarmVar, NULL, False );
+     */
+}
+
+void _ConstitutiveMatrixCartesian_Initialise( void* constitutiveMatrix, void* data ) {
+   ConstitutiveMatrixCartesian*             self             = (ConstitutiveMatrixCartesian*)constitutiveMatrix;
+
+   _ConstitutiveMatrix_Initialise( self, data );
+}
+
+void _ConstitutiveMatrixCartesian_Execute( void* constitutiveMatrix, void* data ) {
+   _ConstitutiveMatrix_Execute( constitutiveMatrix, data );
+}
+
+void _ConstitutiveMatrixCartesian_Destroy( void* constitutiveMatrix, void* data ) {
+   ConstitutiveMatrixCartesian* self = (ConstitutiveMatrixCartesian*)constitutiveMatrix;
+
+   Memory_Free( self->Dtilda_B );
+   Memory_Free( self->Ni );
+
+   _ConstitutiveMatrix_Destroy( constitutiveMatrix, data );
+}
+
+void _ConstitutiveMatrixCartesian_AssembleElement(
+      void*                                              constitutiveMatrix,
+      StiffnessMatrix*                                   stiffnessMatrix,
+      Element_LocalIndex                                 lElement_I,
+      SystemLinearEquations*                             sle,
+      FiniteElementContext*                              context,
+      double**                                           elStiffMat )
+{
+   ConstitutiveMatrixCartesian*     self       = (ConstitutiveMatrixCartesian*) constitutiveMatrix;
+   Swarm*                  swarm               = self->integrationSwarm;
+   FeVariable*             variable1           = stiffnessMatrix->rowVariable;
+   Dimension_Index         dim                 = stiffnessMatrix->dim;
+   IntegrationPoint*       particle;
+   Particle_InCellIndex cParticle_I;
+   Particle_InCellIndex cellParticleCount;
+   Element_NodeIndex       elementNodeCount;
+   Node_ElementLocalIndex  rowNode_I;
+   Node_ElementLocalIndex  colNode_I;
+   double**                GNx;
+   double                  detJac;
+   Cell_Index              cell_I;
+   ElementType*            elementType;
+   double                  Bj_x, Bj_y;
+   double                  Bi_x;
+   double                  Bi_y;
+   double                  Bi_z;
+   Dof_Index               rowNodeDof_I;
+   Dof_Index               colNodeDof_I;
+   Dof_Index               nodeDofCount;
+   double**                Dtilda_B;
+   double                  vel[3], velDerivs[9], *Ni, eta;
+   Bool                    oneToMany;
+
+   self->sle = sle;
+
+   /* Set the element type */
+   elementType       = FeMesh_GetElementType( variable1->feMesh, lElement_I );
+   elementNodeCount  = elementType->nodeCount;
+   nodeDofCount      = dim;
+
+   /* allocate */
+   if( elementNodeCount > self->max_nElNodes ) {
+       self->max_nElNodes = elementNodeCount;
+       self->GNx = ReallocArray2D( self->GNx, double, dim, elementNodeCount );
+       self->Ni = ReallocArray( self->Ni, double, elementNodeCount );
+   }
+   GNx = self->GNx;
+   Ni = self->Ni;
+   Dtilda_B = self->Dtilda_B;
+
+   /* Get number of particles per element */
+   cell_I            = CellLayout_MapElementIdToCellId( swarm->cellLayout, lElement_I );
+   cellParticleCount = swarm->cellParticleCountTbl[ cell_I ];
+
+   /* Determine whether this is the first solve for not */
+   Journal_Firewall( sle != NULL, Journal_Register( Error_Type, (Name)ConstitutiveMatrix_Type  ),
+         "In func %s: SLE is NULL.\n", __func__ );
+
+   /* Note: we may have deliberately set the previousSolutionExists flag to true in the
+      parent ConstitutiveMatrix constructor if in restart mode, even if the SLE hasn't executed yet
+      in this run - so only update to the sle's value when SLE is confirming it has
+      executed */
+   if ( True == sle->hasExecuted ) {
+      self->previousSolutionExists = sle->hasExecuted;
+   }
+   self->sleNonLinearIteration_I = sle->nonLinearIteration_I;
+
+   /*
+	* Keep a flag indicating whether we are usinga one-to-one swarm mapper or not.
+	*/
+
+   oneToMany = Stg_Class_IsInstance(((IntegrationPointsSwarm*)self->integrationSwarm)->mapper, OneToManyMapper_Type);
+
+   /* Loop over points to build Stiffness Matrix */
+   for ( cParticle_I = 0 ; cParticle_I < cellParticleCount ; cParticle_I++ ) {
+     particle = (IntegrationPoint*)Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
+
+      /* Calculate Determinant of Jacobian and Shape Function Global Derivatives */
+      ElementType_ShapeFunctionsGlobalDerivs(
+         elementType,
+         variable1->feMesh, lElement_I,
+         particle->xi, dim, &detJac, GNx );
+
+                /* Evalulate velocity and velocity derivatives at this particle. */
+                FeVariable_InterpolateWithinElement(
+                   variable1, lElement_I, particle->xi, vel );
+                FeVariable_InterpolateDerivatives_WithGNx(
+                   variable1, lElement_I, GNx, velDerivs );
+
+        /*
+		 * Assemble constitutive matrix. Note that we have to handle one-to-many swarms
+		 * differently.
+		 */
+
+		if(!oneToMany) {
+		    // TODO : pass in the context here?
+		    ConstitutiveMatrix_Assemble( constitutiveMatrix, lElement_I,
+						 swarm->cellParticleTbl[cell_I][cParticle_I], particle );
+		}
+		else {
+		    /*
+		     * We're dealing with a one-to-many mapper. We will assemble each material point's
+		     * constitutive matrix and combine them using their weights.
+		     */
+
+		    OneToManyRef *ref;
+		    double **matrixData;
+		    int ii, jj, kk;
+
+		    matrixData = Memory_Alloc_2DArray( double, self->columnSize, self->rowSize, (Name)self->name );
+		    memset(matrixData[0], 0, self->columnSize*self->rowSize*sizeof(double));
+		    ref = OneToManyMapper_GetMaterialRef(((IntegrationPointsSwarm*)swarm)->mapper, particle);
+		    for(ii = 0; ii < ref->numParticles; ii++) {
+			/* Assemble this material point. */
+			ConstitutiveMatrix_AssembleMaterialPoint(
+			    constitutiveMatrix, lElement_I,
+			    ((OneToManyMapper*)((IntegrationPointsSwarm*)swarm)->mapper)->materialSwarm,
+			    ref->particleInds[ii]);
+			/* Add to cumulative matrix. */
+			for(jj = 0; jj < self->rowSize; jj++) {
+			    for(kk = 0; kk < self->columnSize; kk++)
+				matrixData[jj][kk] += ref->weights[ii]*self->matrixData[jj][kk];
+			}
+		    }
+		    /* Copy matrix data and free temporary array. */
+		    memcpy(self->matrixData[0], matrixData[0], self->columnSize*self->rowSize*sizeof(double));
+		    Memory_Free(matrixData);
+		}
+
+		eta = self->matrixData[2][2];
+
+      /* Turn D Matrix into D~ Matrix by multiplying in the weight and the detJac (this is a shortcut for speed) */
+      ConstitutiveMatrix_MultiplyByValue( constitutiveMatrix, detJac * particle->weight );
+
+      for( rowNode_I = 0 ; rowNode_I < elementNodeCount ; rowNode_I++ ) {
+         rowNodeDof_I = rowNode_I*nodeDofCount;
+                        Bj_x = GNx[0][rowNode_I];
+                        Bj_y = GNx[1][rowNode_I];
+
+         /* Build D~ * B */
+         ConstitutiveMatrix_Assemble_D_B( constitutiveMatrix, GNx, rowNode_I, Dtilda_B );
+
+         for( colNode_I = 0 ; colNode_I < elementNodeCount ; colNode_I++ ) {
+            colNodeDof_I = colNode_I*nodeDofCount;
+            Bi_x = GNx[ I_AXIS ][colNode_I];
+            Bi_y = GNx[ J_AXIS ][colNode_I];
+
+            /* Build BTrans * ( D~ * B ) */
+            if ( dim == 2 ) {
+          if( !sle->nlFormJacobian ) {
+
+             elStiffMat[ colNodeDof_I     ][ rowNodeDof_I     ] += Bi_x * Dtilda_B[0][0] + Bi_y * Dtilda_B[2][0];
+             elStiffMat[ colNodeDof_I     ][ rowNodeDof_I + 1 ] += Bi_x * Dtilda_B[0][1] + Bi_y * Dtilda_B[2][1];
+             elStiffMat[ colNodeDof_I + 1 ][ rowNodeDof_I     ] += Bi_y * Dtilda_B[1][0] + Bi_x * Dtilda_B[2][0];
+             elStiffMat[ colNodeDof_I + 1 ][ rowNodeDof_I + 1 ] += Bi_y * Dtilda_B[1][1] + Bi_x * Dtilda_B[2][1];
+
+          }
+          else {
+             double DuDx, DuDy, DvDx, DvDy;
+             double DetaDu, DetaDv;
+             double intFac, fac;
+
+             DuDx = velDerivs[0]; DuDy = velDerivs[1];
+             DvDx = velDerivs[2]; DvDy = velDerivs[3];
+             DetaDu = self->derivs[0] * Bj_x + self->derivs[1] * Bj_y + self->derivs[2] * Ni[rowNode_I];
+             DetaDv = self->derivs[3] * Bj_x + self->derivs[4] * Bj_y + self->derivs[5] * Ni[rowNode_I];
+             intFac = particle->weight * detJac;
+
+             fac = eta * Bj_y + DuDy * DetaDu + DvDx * DetaDu;
+             elStiffMat[colNodeDof_I][rowNodeDof_I] +=
+                intFac * (2.0 * Bi_x * (eta * Bj_x + DuDx * DetaDu) + Bi_y * fac);
+             elStiffMat[colNodeDof_I + 1][rowNodeDof_I] +=
+                intFac * (2.0 * Bi_y * DvDy * DetaDu + Bi_x * fac);
+
+             fac = eta * Bj_x + DvDx * DetaDv + DuDy * DetaDv;
+             elStiffMat[colNodeDof_I][rowNodeDof_I + 1] +=
+                intFac * (2.0 * Bi_x * DuDx * DetaDv + Bi_y * fac);
+             elStiffMat[colNodeDof_I + 1][rowNodeDof_I + 1] +=
+                intFac * (2.0 * Bi_y * (eta * Bj_y + DvDy * DetaDv) + Bi_x * fac);
+
+          }
+            }
+            else {
+               Bi_z = GNx[ K_AXIS ][colNode_I];
+
+               elStiffMat[ colNodeDof_I     ][ rowNodeDof_I     ] +=
+                  Bi_x * Dtilda_B[0][0] + Bi_y * Dtilda_B[3][0] + Bi_z * Dtilda_B[4][0];
+               elStiffMat[ colNodeDof_I     ][ rowNodeDof_I + 1 ] +=
+                  Bi_x * Dtilda_B[0][1] + Bi_y * Dtilda_B[3][1] + Bi_z * Dtilda_B[4][1];
+               elStiffMat[ colNodeDof_I     ][ rowNodeDof_I + 2 ] +=
+                  Bi_x * Dtilda_B[0][2] + Bi_y * Dtilda_B[3][2] + Bi_z * Dtilda_B[4][2];
+
+               elStiffMat[ colNodeDof_I + 1 ][ rowNodeDof_I     ] +=
+                  Bi_y * Dtilda_B[1][0] + Bi_x * Dtilda_B[3][0] + Bi_z * Dtilda_B[5][0];
+               elStiffMat[ colNodeDof_I + 1 ][ rowNodeDof_I + 1 ] +=
+                  Bi_y * Dtilda_B[1][1] + Bi_x * Dtilda_B[3][1] + Bi_z * Dtilda_B[5][1];
+               elStiffMat[ colNodeDof_I + 1 ][ rowNodeDof_I + 2 ] +=
+                  Bi_y * Dtilda_B[1][2] + Bi_x * Dtilda_B[3][2] + Bi_z * Dtilda_B[5][2];
+
+               elStiffMat[ colNodeDof_I + 2 ][ rowNodeDof_I     ] +=
+                  Bi_z * Dtilda_B[2][0] + Bi_x * Dtilda_B[4][0] + Bi_y * Dtilda_B[5][0];
+               elStiffMat[ colNodeDof_I + 2 ][ rowNodeDof_I + 1 ] +=
+                  Bi_z * Dtilda_B[2][1] + Bi_x * Dtilda_B[4][1] + Bi_y * Dtilda_B[5][1];
+               elStiffMat[ colNodeDof_I + 2 ][ rowNodeDof_I + 2 ] +=
+                  Bi_z * Dtilda_B[2][2] + Bi_x * Dtilda_B[4][2] + Bi_y * Dtilda_B[5][2];
+            }
+         }
+      }
+   }
+}
+
+void _ConstitutiveMatrixCartesian2D_SetValueInAllEntries( void* constitutiveMatrix, double value ) {
+   ConstitutiveMatrix* self   = (ConstitutiveMatrix*) constitutiveMatrix;
+
+   if ( fabs( value ) < 1.0e-20 )
+      ConstitutiveMatrix_ZeroMatrix( self );
+   else {
+      double**            D      = self->matrixData;
+
+      D[0][0] = D[0][1] = D[0][2] = value;
+      D[1][0] = D[1][1] = D[1][2] = value;
+      D[2][0] = D[2][1] = D[2][2] = value;
+
+      self->isDiagonal = False;
+   }
+}
+
+void _ConstitutiveMatrixCartesian3D_SetValueInAllEntries( void* _constitutiveMatrix, double value ) {
+   ConstitutiveMatrix* self   = (ConstitutiveMatrix*)_constitutiveMatrix;
+
+   if ( fabs( value ) < 1.0e-20 )
+      ConstitutiveMatrix_ZeroMatrix( self );
+   else {
+      double**            D      = self->matrixData;
+
+      D[0][0] = D[0][1] = D[0][2] = D[0][3] = D[0][4] = D[0][5] = value;
+      D[1][0] = D[1][1] = D[1][2] = D[1][3] = D[1][4] = D[1][5] = value;
+      D[2][0] = D[2][1] = D[2][2] = D[2][3] = D[2][4] = D[2][5] = value;
+      D[3][0] = D[3][1] = D[3][2] = D[3][3] = D[3][4] = D[3][5] = value;
+      D[4][0] = D[4][1] = D[4][2] = D[4][3] = D[4][4] = D[4][5] = value;
+      D[5][0] = D[5][1] = D[5][2] = D[5][3] = D[5][4] = D[5][5] = value;
+
+      self->isDiagonal = False;
+   }
+}
+
+double _ConstitutiveMatrixCartesian2D_GetIsotropicViscosity( void* constitutiveMatrix ) {
+   ConstitutiveMatrix* self = (ConstitutiveMatrix*) constitutiveMatrix;
+
+   return self->matrixData[2][2];
+}
+
+double _ConstitutiveMatrixCartesian3D_GetIsotropicViscosity( void* constitutiveMatrix ) {
+   ConstitutiveMatrix* self = (ConstitutiveMatrix*) constitutiveMatrix;
+
+   return self->matrixData[3][3];
+}
+
+void _ConstitutiveMatrixCartesian2D_IsotropicCorrection( void* constitutiveMatrix, double isotropicCorrection ) {
+   ConstitutiveMatrix* self   = (ConstitutiveMatrix*) constitutiveMatrix;
+   double**            D      = self->matrixData;
+
+   D[0][0] += 2.0 * isotropicCorrection;
+   D[1][1] += 2.0 * isotropicCorrection;
+   D[2][2] += isotropicCorrection;
+}
+
+void _ConstitutiveMatrixCartesian3D_IsotropicCorrection( void* constitutiveMatrix, double isotropicCorrection ) {
+   ConstitutiveMatrix* self   = (ConstitutiveMatrix*) constitutiveMatrix;
+   double**            D      = self->matrixData;
+
+   D[0][0] += 2.0 * isotropicCorrection;
+   D[1][1] += 2.0 * isotropicCorrection;
+   D[2][2] += 2.0 * isotropicCorrection;
+
+   D[3][3] += isotropicCorrection;
+   D[4][4] += isotropicCorrection;
+   D[5][5] += isotropicCorrection;
+}
+
+void _ConstitutiveMatrixCartesian2D_SetSecondViscosity( void* constitutiveMatrix, double deltaViscosity, XYZ director ) {
+   ConstitutiveMatrix* self      = (ConstitutiveMatrix*) constitutiveMatrix;
+   double**            D         = self->matrixData;
+   double              n1        = director[ I_AXIS ];
+   double              n2        = director[ J_AXIS ];
+   double              a0;
+   double              a1;
+
+   a0 = 4.0 * deltaViscosity * n1 * n1 * n2 * n2;
+   a1 = 2.0 * deltaViscosity * n1 * n2 * (n2*n2 - n1*n1);
+
+   D[0][0] += -a0 ;  D[0][1] +=  a0 ;  D[0][2] += -a1 ;
+   D[1][0] +=  a0 ;  D[1][1] += -a0 ;  D[1][2] +=  a1 ;
+   D[2][0] += -a1 ;  D[2][1] +=  a1 ;  D[2][2] +=  a0 - deltaViscosity ;
+
+   self->isDiagonal = False;
+}
+
+void _ConstitutiveMatrixCartesian3D_SetSecondViscosity( void* constitutiveMatrix, double deltaViscosity, XYZ director ) {
+   ConstitutiveMatrix* self      = (ConstitutiveMatrix*) constitutiveMatrix;
+   double**            D         = self->matrixData;
+   double              n1        = director[ I_AXIS ];
+   double              n2        = director[ J_AXIS ];
+   double              n3        = director[ K_AXIS ];
+   double              a00,a01,a02,a03,a04,a05;
+   double                  a11,a12,a13,a14,a15;
+   double                      a22,a23,a24,a25;
+   double                          a33,a34,a35;
+   double                              a44,a45;
+   double                                  a55;
+
+   a00 = -4 * n1*n1 * ( 1 - n1*n1 ) * deltaViscosity;
+   a01 =  4 * n1*n1 * n2*n2 * deltaViscosity;
+   a02 =  4 * n1*n1 * n3*n3 * deltaViscosity;
+   a03 =  2 * n1*n2 * (2*n1*n1-1) * deltaViscosity;
+   a04 =  2 * n1*n3 * (2*n1*n1-1) * deltaViscosity;
+   a05 =  4 * n1*n1 * n2*n3 * deltaViscosity;
+
+   a11= 4 * n2*n2 * (n2*n2-1) * deltaViscosity;
+   a12= 4 * n2*n2 * n3*n3 * deltaViscosity;
+   a13= 2 * n1*n2 * (2*n2*n2-1) * deltaViscosity;
+   a14= 4 * n1*n2 * n2*n3 * deltaViscosity;
+   a15= 2 * n2*n3 * (2*n2*n2-1) * deltaViscosity;
+
+   a22 = 4 * n3*n3 * (n3*n3-1) * deltaViscosity;
+   a23 = 4 * n1*n2 * n3*n3 * deltaViscosity;
+   a24 = 2 * n1*n3 * (2*n3*n3-1) * deltaViscosity;
+   a25 = 2 * n2*n3 * (2*n3*n3-1) * deltaViscosity;
+
+   a33 = (4 * n1*n1 * n2*n2 - n1*n1 - n2*n2) * deltaViscosity;
+   a34 = (4 * n1*n1 * n2*n3 - n2*n3) * deltaViscosity;
+   a35 = (4 * n1*n2 * n2*n3 - n1*n3) * deltaViscosity;
+
+   a44 = (4 * n1*n1 * n3*n3 - n1*n1 -n3*n3) * deltaViscosity;
+   a45 = (4 * n1*n2 * n3*n3 - n1*n2) * deltaViscosity;
+
+   a55 = (4 * n3*n3 * n2*n2 - n3*n3 - n2*n2) * deltaViscosity;
+
+   /* D_{anisotropic} to D */
+   D[0][0] += a00 ; D[0][1] += a01 ; D[0][2] += a02 ; D[0][3] += a03 ; D[0][4] += a04 ; D[0][5] += a05 ;
+   D[1][0] += a01 ; D[1][1] += a11 ; D[1][2] += a12 ; D[1][3] += a13 ; D[1][4] += a14 ; D[1][5] += a15 ;
+   D[2][0] += a02 ; D[2][1] += a12 ; D[2][2] += a22 ; D[2][3] += a23 ; D[2][4] += a24 ; D[2][5] += a25 ;
+   D[3][0] += a03 ; D[3][1] += a13 ; D[3][2] += a23 ; D[3][3] += a33 ; D[3][4] += a34 ; D[3][5] += a35 ;
+   D[4][0] += a04 ; D[4][1] += a14 ; D[4][2] += a24 ; D[4][3] += a34 ; D[4][4] += a44 ; D[4][5] += a45 ;
+   D[5][0] += a05 ; D[5][1] += a15 ; D[5][2] += a25 ; D[5][3] += a35 ; D[5][4] += a45 ; D[5][5] += a55 ;
+
+   self->isDiagonal = False;
+}
+
+/*
+[B] = [ d/dx,     0  ]
+      [    0,  d/dy  ]
+      [ d/dy,  d/dx  ]  */
+void _ConstitutiveMatrixCartesian2D_Assemble_D_B( void* constitutiveMatrix, double** GNx, Node_Index node_I, double** D_B ){
+   ConstitutiveMatrix* self = (ConstitutiveMatrix*) constitutiveMatrix;
+   double**            D    = self->matrixData;
+   double              d_dx = GNx[ I_AXIS ][ node_I ];
+   double              d_dy = GNx[ J_AXIS ][ node_I ];
+
+   if (self->isDiagonal) {
+      D_B[0][0] = D[0][0] * d_dx;
+      D_B[0][1] = 0.0;
+
+      D_B[1][0] = 0.0;
+      D_B[1][1] = D[1][1] * d_dy;
+
+      D_B[2][0] = D[2][2] * d_dy;
+      D_B[2][1] = D[2][2] * d_dx;
+   }
+   else {
+      D_B[0][0] = D[0][0] * d_dx + D[0][2] * d_dy;
+      D_B[0][1] = D[0][1] * d_dy + D[0][2] * d_dx;
+
+      D_B[1][0] = D[1][0] * d_dx + D[1][2] * d_dy;
+      D_B[1][1] = D[1][1] * d_dy + D[1][2] * d_dx;
+
+      D_B[2][0] = D[2][0] * d_dx + D[2][2] * d_dy;
+      D_B[2][1] = D[2][1] * d_dy + D[2][2] * d_dx;
+   }
+}
+
+
+/*
+[B] = [ d/dx,     0,      0  ]
+      [    0,  d/dy,      0  ]
+      [    0,     0,   d/dx  ]
+      [ d/dy,  d/dx,      0  ]
+      [ d/dz,     0,   d/dx  ]
+      [    0,  d/dz,   d/dy  ] */
+void _ConstitutiveMatrixCartesian3D_Assemble_D_B( void* constitutiveMatrix, double** GNx, Node_Index node_I, double** D_B ){
+   ConstitutiveMatrix* self = (ConstitutiveMatrix*) constitutiveMatrix;
+   double**            D    = self->matrixData;
+   double              d_dx = GNx[ I_AXIS ][ node_I ];
+   double              d_dy = GNx[ J_AXIS ][ node_I ];
+   double              d_dz = GNx[ K_AXIS ][ node_I ];
+
+   if (self->isDiagonal) {
+      D_B[0][0] = D[0][0] * d_dx;
+      D_B[0][1] = 0.0;
+      D_B[0][2] = 0.0;
+
+      D_B[1][0] = 0.0;
+      D_B[1][1] = D[1][1] * d_dy;
+      D_B[1][2] = 0.0;
+
+      D_B[2][0] = 0.0;
+      D_B[2][1] = 0.0;
+      D_B[2][2] = D[2][2] * d_dz;
+
+      D_B[3][0] = D[3][3] * d_dy;
+      D_B[3][1] = D[3][3] * d_dx;
+      D_B[3][2] = 0.0;
+
+      D_B[4][0] = D[4][4] * d_dz;
+      D_B[4][1] = 0.0;
+      D_B[4][2] = D[4][4] * d_dx;
+
+      D_B[5][0] = 0.0;
+      D_B[5][1] = D[5][5] * d_dz;
+      D_B[5][2] = D[5][5] * d_dy;
+   }
+   else {
+      D_B[0][0] = D[0][0] * d_dx + D[0][3] * d_dy + D[0][4] * d_dz;
+      D_B[0][1] = D[0][1] * d_dy + D[0][3] * d_dx + D[0][5] * d_dz;
+      D_B[0][2] = D[0][2] * d_dz + D[0][4] * d_dx + D[0][5] * d_dy;
+
+      D_B[1][0] = D[1][0] * d_dx + D[1][3] * d_dy + D[1][4] * d_dz;
+      D_B[1][1] = D[1][1] * d_dy + D[1][3] * d_dx + D[1][5] * d_dz;
+      D_B[1][2] = D[1][2] * d_dz + D[1][4] * d_dx + D[1][5] * d_dy;
+
+      D_B[2][0] = D[2][0] * d_dx + D[2][3] * d_dy + D[2][4] * d_dz;
+      D_B[2][1] = D[2][1] * d_dy + D[2][3] * d_dx + D[2][5] * d_dz;
+      D_B[2][2] = D[2][2] * d_dz + D[2][4] * d_dx + D[2][5] * d_dy;
+
+      D_B[3][0] = D[3][0] * d_dx + D[3][3] * d_dy + D[3][4] * d_dz;
+      D_B[3][1] = D[3][1] * d_dy + D[3][3] * d_dx + D[3][5] * d_dz;
+      D_B[3][2] = D[3][2] * d_dz + D[3][4] * d_dx + D[3][5] * d_dy;
+
+      D_B[4][0] = D[4][0] * d_dx + D[4][3] * d_dy + D[4][4] * d_dz;
+      D_B[4][1] = D[4][1] * d_dy + D[4][3] * d_dx + D[4][5] * d_dz;
+      D_B[4][2] = D[4][2] * d_dz + D[4][4] * d_dx + D[4][5] * d_dy;
+
+      D_B[5][0] = D[5][0] * d_dx + D[5][3] * d_dy + D[5][4] * d_dz;
+      D_B[5][1] = D[5][1] * d_dy + D[5][3] * d_dx + D[5][5] * d_dz;
+      D_B[5][2] = D[5][2] * d_dz + D[5][4] * d_dx + D[5][5] * d_dy;
+   }
+}
+
+void _ConstitutiveMatrixCartesian2D_CalculateStress( void* constitutiveMatrix, SymmetricTensor strainRate, SymmetricTensor stress ) {
+   ConstitutiveMatrix* self = (ConstitutiveMatrix*) constitutiveMatrix;
+   double**            D    = self->matrixData;
+
+   if (self->isDiagonal) {
+      stress[0] = D[0][0] * strainRate[0];
+      stress[1] = D[1][1] * strainRate[1];
+      stress[2] = D[2][2] * 2.0 * strainRate[2];
+   }
+   else {
+      stress[0] = D[0][0] * strainRate[0] + D[0][1] * strainRate[1] + D[0][2] * 2.0 * strainRate[2];
+      stress[1] = D[1][0] * strainRate[0] + D[1][1] * strainRate[1] + D[1][2] * 2.0 * strainRate[2];
+      stress[2] = D[2][0] * strainRate[0] + D[2][1] * strainRate[1] + D[2][2] * 2.0 * strainRate[2];
+   }
+}
+
+
+
+void _ConstitutiveMatrixCartesian3D_CalculateStress( void* constitutiveMatrix, SymmetricTensor strainRate, SymmetricTensor stress ) {
+   ConstitutiveMatrix* self = (ConstitutiveMatrix*) constitutiveMatrix;
+   double**            D    = self->matrixData;
+
+   if (self->isDiagonal) {
+      stress[0] = D[0][0] * strainRate[0];
+      stress[1] = D[1][1] * strainRate[1];
+      stress[2] = D[2][2] * strainRate[2];
+      stress[3] = D[3][3] * 2.0 * strainRate[3];
+      stress[4] = D[4][4] * 2.0 * strainRate[4];
+      stress[5] = D[5][5] * 2.0 * strainRate[5];
+   }
+   else {
+      stress[0] = D[0][0] * strainRate[0] + D[0][1] * strainRate[1] + D[0][2] * strainRate[2]
+         + 2.0 * (D[0][3] * strainRate[3] + D[0][4] * strainRate[4] + D[0][5] * strainRate[5]);
+
+      stress[1] = D[1][0] * strainRate[0] + D[1][1] * strainRate[1] + D[1][2] * strainRate[2]
+         + 2.0 * (D[1][3] * strainRate[3] + D[1][4] * strainRate[4] + D[1][5] * strainRate[5]);
+
+      stress[2] = D[2][0] * strainRate[0] + D[2][1] * strainRate[1] + D[2][2] * strainRate[2]
+         + 2.0 * (D[2][3] * strainRate[3] + D[2][4] * strainRate[4] + D[2][5] * strainRate[5]);
+
+      stress[3] = D[3][0] * strainRate[0] + D[3][1] * strainRate[1] + D[3][2] * strainRate[2]
+         + 2.0 * (D[3][3] * strainRate[3] + D[3][4] * strainRate[4] + D[3][5] * strainRate[5]);
+
+      stress[4] = D[4][0] * strainRate[0] + D[4][1] * strainRate[1] + D[4][2] * strainRate[2]
+         + 2.0 * (D[4][3] * strainRate[3] + D[4][4] * strainRate[4] + D[4][5] * strainRate[5]);
+
+      stress[5] = D[5][0] * strainRate[0] + D[5][1] * strainRate[1] + D[5][2] * strainRate[2]
+         + 2.0 * (D[5][3] * strainRate[3] + D[5][4] * strainRate[4] + D[5][5] * strainRate[5]);
+   }
+}
+
+void ConstitutiveMatrixCartesian_SetupParticleStorage( ConstitutiveMatrixCartesian* self ) {
+   /* a function which defines the storage of each particle's constitutive information on the particle,
+    * should be called before the "Build" phase */
+
+   static int beenHere = 0; /* don't want to do this routine twice */
+
+   IntegrationPointsSwarm* swarm = (IntegrationPointsSwarm*)self->integrationSwarm;
+   MaterialPointsSwarm **materialSwarms, *materialSwarm;
+   MaterialPoint particle;
+   int materialSwarmCount;
+   double *cMatrix = NULL;
+
+   if( beenHere ) return;
+
+   beenHere = 1;
+
+   /* get material swram mapped to the integration points,
+   *      * currently only one material point is mapped 26 FEB 09 */
+   materialSwarms = IntegrationPointMapper_GetMaterialPointsSwarms( swarm->mapper, (Index*)(&materialSwarmCount) );
+   assert( materialSwarmCount < 2 );
+   materialSwarm = materialSwarms[0];
+
+   /* add extension to material swarm */
+   self->storedConstHandle = ExtensionManager_Add( materialSwarm->particleExtensionMgr, (Name)self->type, self->rowSize * self->columnSize * sizeof(double)  );
+
+   cMatrix = (double*)ExtensionManager_Get( materialSwarm->particleExtensionMgr, &particle, self->storedConstHandle );
+
+#if 0
+   /*This isn't needed so I've disabled it, 2Dec09, JG*/
+   if( self->dim == 2 ) {
+      /* TODO: clean up this vector logic. The only reson there's an if is because
+      *        * of the list of names the must be given as the final arguments to this function.  */
+      self->storedConstSwarmVar = Swarm_NewVectorVariable( materialSwarm, (Name)"ConstitutiveMatrix", (ArithPointer)cMatrix - (ArithPointer)&particle,
+      Variable_DataType_Double, self->rowSize * self->columnSize,
+      "c00", "c01", "c02", "c10", "c11", "c12", "c20", "c21", "c22" );
+   } else {
+      self->storedConstSwarmVar = Swarm_NewVectorVariable( materialSwarm, (Name)"ConstitutiveMatrix", (ArithPointer)cMatrix - (ArithPointer)&particle,
+      Variable_DataType_Double, self->rowSize * self->columnSize,
+      "c00", "c01", "c02", "c03", "c04", "c05",
+      "c10", "c11", "c12", "c13", "c14", "c15",
+      "c20", "c21", "c22", "c23", "c24", "c25",
+      "c30", "c31", "c32", "c33", "c34", "c35",
+      "c40", "c41", "c42", "c43", "c44", "c45",
+      "c50", "c51", "c52", "c53", "c54", "c55" );
+   }
+
+   /* set the storedConstitutive matrix NOT to be checkpointed */
+   self->storedConstSwarmVar->isCheckpointedAndReloaded = False;
+#endif
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/DepthDependentViscosity.c
--- a/Rheology/src/DepthDependentViscosity.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,199 +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:
-*+    Robert Turnbull
-*+    Vincent Lemiale
-*+    Louis Moresi
-*+    David May
-*+    David Stegman
-*+    Mirko Velic
-*+    Patrick Sunter
-*+    Julian Giordani
-*+
-** $Id: DepthDependentViscosity.c 610 2007-10-11 08:09:29Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "RheologyClass.h"
-#include "ConstitutiveMatrix.h"
-#include "DepthDependentViscosity.h"
-
-#include <assert.h>
-#include <string.h>
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type DepthDependentViscosity_Type = "DepthDependentViscosity";
-
-/* Public Constructor */
-DepthDependentViscosity* DepthDependentViscosity_New(
-      Name                  name,
-      AbstractContext*      context,
-      FeMesh*               feMesh,
-      double                eta0,
-      double                gamma,
-      Axis                  variationAxis,
-      double                referencePoint )
-{
-   DepthDependentViscosity* self = (DepthDependentViscosity*) _DepthDependentViscosity_DefaultNew( name );
-
-   _Rheology_Init( self, (PICelleratorContext*)context );
-   _DepthDependentViscosity_Init( self, feMesh, eta0, gamma, variationAxis, referencePoint );
-   self->isConstructed = True;
-   return self;
-}
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-DepthDependentViscosity* _DepthDependentViscosity_New(  DEPTHDEPENDENTVISCOSITY_DEFARGS  )
-{
-   DepthDependentViscosity*               self;
-
-   /* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-   assert( _sizeOfSelf >= sizeof(DepthDependentViscosity) );
-   self = (DepthDependentViscosity*) _Rheology_New(  RHEOLOGY_PASSARGS  );
-
-   return self;
-}
-
-void _DepthDependentViscosity_Init( DepthDependentViscosity* self, FeMesh* feMesh, double eta0, double gamma, Axis variationAxis, double referencePoint ) {
-   self->feMesh          = feMesh;
-   self->eta0            = eta0;
-   self->gamma           = gamma;
-   self->variationAxis   = variationAxis;
-   self->referencePoint  = referencePoint;
-}
-
-void* _DepthDependentViscosity_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                     _sizeOfSelf = sizeof(DepthDependentViscosity);
-	Type                                                             type = DepthDependentViscosity_Type;
-	Stg_Class_DeleteFunction*                                     _delete = _Rheology_Delete;
-	Stg_Class_PrintFunction*                                       _print = _Rheology_Print;
-	Stg_Class_CopyFunction*                                         _copy = _Rheology_Copy;
-	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _DepthDependentViscosity_DefaultNew;
-	Stg_Component_ConstructFunction*                           _construct = _DepthDependentViscosity_AssignFromXML;
-	Stg_Component_BuildFunction*                                   _build = _Rheology_Build;
-	Stg_Component_InitialiseFunction*                         _initialise = _Rheology_Initialise;
-	Stg_Component_ExecuteFunction*                               _execute = _Rheology_Execute;
-	Stg_Component_DestroyFunction*                               _destroy = _DepthDependentViscosity_Destroy;
-	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _DepthDependentViscosity_ModifyConstitutiveMatrix;
-
-	/* 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*) _DepthDependentViscosity_New(  DEPTHDEPENDENTVISCOSITY_PASSARGS  );
-}
-
-void _DepthDependentViscosity_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
-   DepthDependentViscosity*  self                   = (DepthDependentViscosity*)rheology;
-   FeMesh*          feMesh;
-   Axis                      variationAxis          = (Axis)0;
-   Name                      variationAxisName;
-   Stream*                   errorStream            = Journal_Register( Error_Type, (Name)self->type  );
-
-   /* Construct Parent */
-   _Rheology_AssignFromXML( self, cf, data );
-
-   feMesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Mesh", FeMesh, True, data  ) ;
-
-   variationAxisName = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"variationAxis", "Y" );
-
-   Journal_Firewall(
-         variationAxisName != NULL && strlen( variationAxisName  ) >= 1,
-         errorStream,
-         "Error in func %s for %s '%s' - Bad 'variationAxis'\n",
-         __func__, self->type, self->name );
-
-   switch ( variationAxisName[0] ) {
-      case 'X': case 'x': case 'I': case 'i': case '0':
-         variationAxis = I_AXIS; break;
-      case 'Y': case 'y': case 'J': case 'j': case '1':
-         variationAxis = J_AXIS; break;
-      case 'Z': case 'z': case 'K': case 'k': case '2':
-         variationAxis = K_AXIS; break;
-      default:
-         Journal_Firewall(
-            False,
-            errorStream,
-            "Error in func %s for %s '%s' - Bad 'variationAxis' in dictionary.\n",
-            __func__, self->type, self->name );
-   }
-
-   _DepthDependentViscosity_Init(
-         self,
-         feMesh,
-         Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"eta0", 1.0  ),
-         Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"gamma", 0.0  ),
-         variationAxis,
-         Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"referencePoint", 0.0 )  );
-}
-
-void _DepthDependentViscosity_Destroy( void* rheology, void* data ) {
-	DepthDependentViscosity* self = (DepthDependentViscosity*) rheology;
-
-	Stg_Component_Destroy( self->feMesh, data, False );
-	/* Destroy parent */
-	_Rheology_Destroy( self, data );
-
-}
-
-
-void _DepthDependentViscosity_ModifyConstitutiveMatrix(
-      void*                                              rheology,
-      ConstitutiveMatrix*                                constitutiveMatrix,
-      MaterialPointsSwarm*                               swarm,
-      Element_LocalIndex                                 lElement_I,
-      MaterialPoint*                                     materialPoint,
-      Coord                                              xi )
-{
-   DepthDependentViscosity*     self              = (DepthDependentViscosity*) rheology;
-   double                            distance;
-   double                            viscosity;
-   Coord                             coord;
-
-   /* This rheology assumes particle is an integration points thats can be mapped to a particle
-    * that has no meaningful coord. Best to re-calc the global from local */
-
-   /* Calculate distance */
-   FeMesh_CoordLocalToGlobal( swarm->mesh, lElement_I, xi, coord );
-   distance = coord[ self->variationAxis ];
-
-   /* Calculate New Viscosity */
-   viscosity = self->eta0 * exp( self->gamma * ( distance - self->referencePoint ) );
-   ConstitutiveMatrix_SetIsotropicViscosity( constitutiveMatrix, viscosity );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/DepthDependentViscosity.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/DepthDependentViscosity.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,199 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+    Robert Turnbull
+*+    Vincent Lemiale
+*+    Louis Moresi
+*+    David May
+*+    David Stegman
+*+    Mirko Velic
+*+    Patrick Sunter
+*+    Julian Giordani
+*+
+** $Id: DepthDependentViscosity.c 610 2007-10-11 08:09:29Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "RheologyClass.h"
+#include "ConstitutiveMatrix.h"
+#include "DepthDependentViscosity.h"
+
+#include <assert.h>
+#include <string.h>
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type DepthDependentViscosity_Type = "DepthDependentViscosity";
+
+/* Public Constructor */
+DepthDependentViscosity* DepthDependentViscosity_New(
+      Name                  name,
+      AbstractContext*      context,
+      FeMesh*               feMesh,
+      double                eta0,
+      double                gamma,
+      Axis                  variationAxis,
+      double                referencePoint )
+{
+   DepthDependentViscosity* self = (DepthDependentViscosity*) _DepthDependentViscosity_DefaultNew( name );
+
+   _Rheology_Init( self, (PICelleratorContext*)context );
+   _DepthDependentViscosity_Init( self, feMesh, eta0, gamma, variationAxis, referencePoint );
+   self->isConstructed = True;
+   return self;
+}
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+DepthDependentViscosity* _DepthDependentViscosity_New(  DEPTHDEPENDENTVISCOSITY_DEFARGS  )
+{
+   DepthDependentViscosity*               self;
+
+   /* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+   assert( _sizeOfSelf >= sizeof(DepthDependentViscosity) );
+   self = (DepthDependentViscosity*) _Rheology_New(  RHEOLOGY_PASSARGS  );
+
+   return self;
+}
+
+void _DepthDependentViscosity_Init( DepthDependentViscosity* self, FeMesh* feMesh, double eta0, double gamma, Axis variationAxis, double referencePoint ) {
+   self->feMesh          = feMesh;
+   self->eta0            = eta0;
+   self->gamma           = gamma;
+   self->variationAxis   = variationAxis;
+   self->referencePoint  = referencePoint;
+}
+
+void* _DepthDependentViscosity_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                     _sizeOfSelf = sizeof(DepthDependentViscosity);
+	Type                                                             type = DepthDependentViscosity_Type;
+	Stg_Class_DeleteFunction*                                     _delete = _Rheology_Delete;
+	Stg_Class_PrintFunction*                                       _print = _Rheology_Print;
+	Stg_Class_CopyFunction*                                         _copy = _Rheology_Copy;
+	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _DepthDependentViscosity_DefaultNew;
+	Stg_Component_ConstructFunction*                           _construct = _DepthDependentViscosity_AssignFromXML;
+	Stg_Component_BuildFunction*                                   _build = _Rheology_Build;
+	Stg_Component_InitialiseFunction*                         _initialise = _Rheology_Initialise;
+	Stg_Component_ExecuteFunction*                               _execute = _Rheology_Execute;
+	Stg_Component_DestroyFunction*                               _destroy = _DepthDependentViscosity_Destroy;
+	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _DepthDependentViscosity_ModifyConstitutiveMatrix;
+
+	/* 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*) _DepthDependentViscosity_New(  DEPTHDEPENDENTVISCOSITY_PASSARGS  );
+}
+
+void _DepthDependentViscosity_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
+   DepthDependentViscosity*  self                   = (DepthDependentViscosity*)rheology;
+   FeMesh*          feMesh;
+   Axis                      variationAxis          = (Axis)0;
+   Name                      variationAxisName;
+   Stream*                   errorStream            = Journal_Register( Error_Type, (Name)self->type  );
+
+   /* Construct Parent */
+   _Rheology_AssignFromXML( self, cf, data );
+
+   feMesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Mesh", FeMesh, True, data  ) ;
+
+   variationAxisName = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"variationAxis", "Y" );
+
+   Journal_Firewall(
+         variationAxisName != NULL && strlen( variationAxisName  ) >= 1,
+         errorStream,
+         "Error in func %s for %s '%s' - Bad 'variationAxis'\n",
+         __func__, self->type, self->name );
+
+   switch ( variationAxisName[0] ) {
+      case 'X': case 'x': case 'I': case 'i': case '0':
+         variationAxis = I_AXIS; break;
+      case 'Y': case 'y': case 'J': case 'j': case '1':
+         variationAxis = J_AXIS; break;
+      case 'Z': case 'z': case 'K': case 'k': case '2':
+         variationAxis = K_AXIS; break;
+      default:
+         Journal_Firewall(
+            False,
+            errorStream,
+            "Error in func %s for %s '%s' - Bad 'variationAxis' in dictionary.\n",
+            __func__, self->type, self->name );
+   }
+
+   _DepthDependentViscosity_Init(
+         self,
+         feMesh,
+         Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"eta0", 1.0  ),
+         Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"gamma", 0.0  ),
+         variationAxis,
+         Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"referencePoint", 0.0 )  );
+}
+
+void _DepthDependentViscosity_Destroy( void* rheology, void* data ) {
+	DepthDependentViscosity* self = (DepthDependentViscosity*) rheology;
+
+	Stg_Component_Destroy( self->feMesh, data, False );
+	/* Destroy parent */
+	_Rheology_Destroy( self, data );
+
+}
+
+
+void _DepthDependentViscosity_ModifyConstitutiveMatrix(
+      void*                                              rheology,
+      ConstitutiveMatrix*                                constitutiveMatrix,
+      MaterialPointsSwarm*                               swarm,
+      Element_LocalIndex                                 lElement_I,
+      MaterialPoint*                                     materialPoint,
+      Coord                                              xi )
+{
+   DepthDependentViscosity*     self              = (DepthDependentViscosity*) rheology;
+   double                            distance;
+   double                            viscosity;
+   Coord                             coord;
+
+   /* This rheology assumes particle is an integration points thats can be mapped to a particle
+    * that has no meaningful coord. Best to re-calc the global from local */
+
+   /* Calculate distance */
+   FeMesh_CoordLocalToGlobal( swarm->mesh, lElement_I, xi, coord );
+   distance = coord[ self->variationAxis ];
+
+   /* Calculate New Viscosity */
+   viscosity = self->eta0 * exp( self->gamma * ( distance - self->referencePoint ) );
+   ConstitutiveMatrix_SetIsotropicViscosity( constitutiveMatrix, viscosity );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/Director.c
--- a/Rheology/src/Director.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,582 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+		Kathleen Humble
-*+
-** $Id: Director.c 629 2007-11-14 05:47:33Z BelindaMay $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "RheologyClass.h"
-#include "YieldRheology.h"
-#include "VonMises.h"
-#include "Director.h"
-#include "ConstitutiveMatrix.h"
-
-#include <assert.h>
-#include <string.h>
-
-/* Define the default initial direction for particles */ 
-#define DIRECTOR_DEFAULT_DIR_X 0.0
-#define DIRECTOR_DEFAULT_DIR_Y 1.0
-#define DIRECTOR_DEFAULT_DIR_Z 0.0
-
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type Director_Type = "Director";
-
-/* Public Constructor */
-Director* Director_New( 
-		Name                   name,
-		DomainContext*         context,
-		TimeIntegrator*        timeIntegrator, 
-		Variable*              variable,
-		Index                  dataCount, 
-		Stg_Component**        data,
-		Bool                   allowFallbackToFirstOrder,
-		FeVariable*            velGradField,
-		MaterialPointsSwarm*   materialPointsSwarm,
-		InitialDirectionType   initialDirectionType,
-		double                 globalInitialDirectionX,
-		double                 globalInitialDirectionY,
-		double                 globalInitialDirectionZ,
-		int                    randomInitialDirectionSeed,
-		Bool                   dontUpdate )
-{
-	Director*	self;
-
-	self = (Director*) _Director_DefaultNew( name );
-	
-	_TimeIntegrand_Init( self, context, timeIntegrator, variable, dataCount, data, allowFallbackToFirstOrder );
-   _Director_Init(
-		self,
-		velGradField,
-		materialPointsSwarm,
-		initialDirectionType,
-		globalInitialDirectionX,
-		globalInitialDirectionY,
-		globalInitialDirectionZ,
-		randomInitialDirectionSeed,
-		dontUpdate );
-
-	self->isConstructed = True;
-	return self;
-}
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-Director* _Director_New(  DIRECTOR_DEFARGS  ) 
-{
-	Director*					self;
-
-	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-	assert( _sizeOfSelf >= sizeof(Director) );
-	self = (Director*) _TimeIntegrand_New(  TIMEINTEGRAND_PASSARGS  );
-	
-	/* Function pointers for this class that are not on the parent class should be set here */
-	
-	return self;
-}
-
-void _Director_Init(
-		Director*                                          self,
-		FeVariable*                                        velGradField,
-		MaterialPointsSwarm*                               materialPointsSwarm,
-		InitialDirectionType                               initialDirectionType,
-		double                                             globalInitialDirectionX,
-		double                                             globalInitialDirectionY,
-		double                                             globalInitialDirectionZ,
-		int                                                randomInitialDirectionSeed,
-		Bool                                               dontUpdate )
-{
-	/* Assign Values */
-	self->velGradField               = velGradField;
-	self->materialPointsSwarm        = materialPointsSwarm;
-	self->dontUpdate                 = dontUpdate;
-	self->globalInitialDirection[ I_AXIS ] = globalInitialDirectionX;
-	self->globalInitialDirection[ J_AXIS ] = globalInitialDirectionY;
-	self->globalInitialDirection[ K_AXIS ] = globalInitialDirectionZ;
-	self->randomInitialDirectionSeed = randomInitialDirectionSeed;
-	StGermain_VectorNormalise( self->globalInitialDirection, materialPointsSwarm->dim );
-	self->initialDirectionType = initialDirectionType;
-	/****** Setup Variables *****/
-
-	/* First check to see if a particle extension has already been created for this swarm */
-	self->particleExtHandle     = ExtensionManager_GetHandle( materialPointsSwarm->particleExtensionMgr, (Name)Director_Type );
-
-	/* If there isn't one then create the particle extension - otherwise just use the one already there*/
-	if ( self->particleExtHandle == (ExtensionInfo_Index) -1  ) {
-		StandardParticle      particle;
-		Director_ParticleExt* particleExt;
-
-		/* Add particle extension */
-		self->particleExtHandle = 
-			ExtensionManager_Add( materialPointsSwarm->particleExtensionMgr, (Name)Director_Type, sizeof(Director_ParticleExt)  );	
-
-		particleExt = (Director_ParticleExt*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, &particle, self->particleExtHandle );
-
-		self->directorSwarmVariable = Swarm_NewVectorVariable( materialPointsSwarm, (Name)"Director", (ArithPointer) &particleExt->director - (ArithPointer) &particle,
-			Variable_DataType_Double,
-			materialPointsSwarm->dim,
-			"DirectorX",
-			"DirectorY",
-			"DirectorZ" );
-		self->dontUpdateParticle = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"dontUpdateParticle", (ArithPointer) &particleExt->dontUpdateParticle - (ArithPointer) &particle, Variable_DataType_Int  );
-	}
-	else {
-		char* variableName;
-
-		/* Get Variables already created */
-		variableName = Stg_Object_AppendSuffix( materialPointsSwarm, (Name)"Director"  );
-		self->directorSwarmVariable = SwarmVariable_Register_GetByName( materialPointsSwarm->swarmVariable_Register, variableName );
-		assert( self->directorSwarmVariable );
-		Memory_Free( variableName );
-		/* Get Variables already created */
-		variableName = Stg_Object_AppendSuffix( materialPointsSwarm, (Name)"dontUpdateParticle"  );
-		self->dontUpdateParticle = SwarmVariable_Register_GetByName( materialPointsSwarm->swarmVariable_Register, variableName );
-		assert( self->dontUpdateParticle );
-		Memory_Free( variableName );
-	}
-	
-	self->variable = self->directorSwarmVariable->variable;
-
-	TimeIntegrator_AppendSetupEP( self->timeIntegrator,
-                                      "Director_UpdateVariables", (void*)Director_UpdateVariables,  self->name, self );
-}
-
-void* _Director_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                               _sizeOfSelf = sizeof(Director);
-	Type                                                       type = Director_Type;
-	Stg_Class_DeleteFunction*                               _delete = _TimeIntegrand_Delete;
-	Stg_Class_PrintFunction*                                 _print = _TimeIntegrand_Print;
-	Stg_Class_CopyFunction*                                   _copy = _TimeIntegrand_Copy;
-	Stg_Component_DefaultConstructorFunction*   _defaultConstructor = _Director_DefaultNew;
-	Stg_Component_ConstructFunction*                     _construct = _Director_AssignFromXML;
-	Stg_Component_BuildFunction*                             _build = _Director_Build;
-	Stg_Component_InitialiseFunction*                   _initialise = _Director_Initialise;
-	Stg_Component_ExecuteFunction*                         _execute = _TimeIntegrand_Execute;
-	Stg_Component_DestroyFunction*                         _destroy = _Director_Destroy;
-	TimeIntegrand_CalculateTimeDerivFunction*  _calculateTimeDeriv = _Director_TimeDerivative;
-	TimeIntegrand_IntermediateFunction*              _intermediate = _Director_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*) _Director_New(  DIRECTOR_PASSARGS  );
-}
-
-void _Director_AssignFromXML( void* director, Stg_ComponentFactory* cf, void* data ){
-	Director*               self           = (Director*)director;
-	MaterialPointsSwarm*    materialPointsSwarm;
-	FeVariable*             velGradField;
-	char*                   initialDirectionTypeName;
-	InitialDirectionType    initialDirectionType;
-	
-	/* Construct Parent */
-	_TimeIntegrand_AssignFromXML( self, cf, data );
-	
-	/* Construct 'Director' stuff */
-	/* TODO: 'KeyFallback' soon to be deprecated/updated */
-        velGradField   = Stg_ComponentFactory_ConstructByNameWithKeyFallback( cf, self->name, (Name)"VelocityGradientsField", (Dictionary_Entry_Key)"VelocityGradientsField", FeVariable, True, data  );
-	/*
-	velGradField   = Stg_ComponentFactory_ConstructByKey( 
-			cf, self->name, "VelocityGradientsField", FeVariable, True );
-	*/		
-	materialPointsSwarm = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"MaterialPointsSwarm", MaterialPointsSwarm, True, data  );
-	
-	
-	/* Define the initial Direction type for the problem
-		The options are: global definition of direction,
-		Random direction,
-		a different direction per material.
-	*/
-	initialDirectionTypeName = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"initialDirectionType", "global" );
-	if (0 == strcasecmp(initialDirectionTypeName, "global")) {
-		initialDirectionType = INIT_DIR_GLOBAL;
-	}
-	else if (0 == strcasecmp(initialDirectionTypeName, "random")) {
-		initialDirectionType = INIT_DIR_RANDOM;
-	}
-	else if (0 == strcasecmp(initialDirectionTypeName,"perMaterial")) {
-		initialDirectionType = INIT_DIR_PER_MAT;
-	}
-	else {
-			Journal_Firewall(False, Journal_Register( Error_Type, (Name)"Director"  ), 
-			"Error in '%s', do not understand initialDirectionType = %s\n."
-			" Options are: \"global\", \"random\" or \"perMaterial\" ", __func__, 
-			initialDirectionTypeName);		
-	}
-	
-	_Director_Init(
-			self, 
-			velGradField,
-			materialPointsSwarm,
-			initialDirectionType,
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"initialDirectionX", DIRECTOR_DEFAULT_DIR_X  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"initialDirectionY", DIRECTOR_DEFAULT_DIR_Y  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"initialDirectionZ", DIRECTOR_DEFAULT_DIR_Z  ),
-			Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"randomInitialDirectionSeed", 1  ),
-			Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"dontUpdate", False )  );
-
-}
-
-void _Director_Build( void* director, void* data ) {
-	Director*                       self               = (Director*) director;
-
-	/* Build parent */
-	_TimeIntegrand_Build( self, data );
-
-	Stg_Component_Build( self->directorSwarmVariable, data, False );
-	Stg_Component_Build( self->dontUpdateParticle, data, False );
-}
-
-void _Director_Initialise( void* director, void* data ) {
-	Director*                       self               = (Director*) director;
-	Particle_Index                  lParticle_I;
-	Particle_Index                  particleLocalCount = self->variable->arraySize;
-	double*                         normal;
-	Dimension_Index                 dim_I;
-
-	/* Initialise Parent */
-	_TimeIntegrand_Initialise( self, data );
-
-	Stg_Component_Initialise( self->materialPointsSwarm, data, False );
-	/* We should only set initial directors if in regular non-restart mode. If in restart mode, then
-	the directors will be set correctly when we re-load the Swarm. */
-	if ( self->context->loadFromCheckPoint == False ) {
-
-      Stg_Component_Initialise( self->directorSwarmVariable, data, False );
-      Stg_Component_Initialise( self->dontUpdateParticle, data, True );
-   
-      /* Update variables */
-      Variable_Update( self->variable );
-
-		particleLocalCount = self->variable->arraySize;
-		if ( self->initialDirectionType == INIT_DIR_GLOBAL ) {
-			for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) {
-				/* Initialise the norm of each director */
-				normal = Variable_GetPtrDouble( self->variable, lParticle_I );
-
-				memcpy( normal, self->globalInitialDirection, sizeof(XYZ) );
-			}	
-		}
-		else if (self->initialDirectionType == INIT_DIR_RANDOM){
-			Particle_Index	gParticle_I;
-			unsigned	approxGlobalParticleCount = particleLocalCount * self->materialPointsSwarm->nProc;
-			unsigned	startIndex = particleLocalCount * self->materialPointsSwarm->myRank;
-			double		norm[3];
-
-			/* create random directions for each particle */
-			srand( self->randomInitialDirectionSeed );
-
-			lParticle_I = 0;
-			for( gParticle_I = 0; gParticle_I < approxGlobalParticleCount; gParticle_I++ ) {
-				for ( dim_I = 0; dim_I < self->materialPointsSwarm->dim; dim_I++ ) {
-					norm[dim_I] = ( (float) rand() - RAND_MAX/2 ) / RAND_MAX;
-				}	
-				if( gParticle_I >= startIndex ) {
-					normal = Variable_GetPtrDouble( self->variable, lParticle_I );
-					for ( dim_I = 0; dim_I < self->materialPointsSwarm->dim; dim_I++ ) {
-						normal[dim_I] = norm[dim_I];
-					}
-					lParticle_I++;
-				}
-				if( lParticle_I >= particleLocalCount )
-					break;
-			}
-/*
-			for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) {
-				normal = Variable_GetPtrDouble( self->variable, lParticle_I );
-				for ( dim_I = 0; dim_I < self->materialPointsSwarm->dim; dim_I++ ) {
-					normal[dim_I] = ( (float) rand() - RAND_MAX/2 ) / RAND_MAX;
-				}	
-				StGermain_VectorNormalise( normal, self->materialPointsSwarm->dim );
-			}
-*/
-		}
-		else if (self->initialDirectionType == INIT_DIR_PER_MAT) {
-			/* Assign initial direction based on material
-			  and check first is material is defined as random.*/
-			Material_Index	materialsCount = Materials_Register_GetCount( self->materialPointsSwarm->materials_Register);
-			XYZ*				materialDirectionVectors;
-			int				material_I;
-			Material*		material;
-			Bool*				randomInitialDirections;
-			int*				randomInitialDirectionSeeds;
-			/* int				materialOfParticle; */
-			
-			materialDirectionVectors = Memory_Alloc_Array(XYZ, materialsCount, "materialDirectionVectors");
-			randomInitialDirectionSeeds = Memory_Alloc_Array(int, materialsCount,
-			"randomInitialDirectionSeeds");
-			randomInitialDirections = Memory_Alloc_Array(Bool, materialsCount,
-			"randomInitialDirections");
-
-			/* Loop over materials and get material properties from dictionary */
-			for ( material_I = 0 ; material_I < materialsCount ; material_I++ ) {
-				material = Materials_Register_GetByIndex( 
-						self->materialPointsSwarm->materials_Register, 
-						material_I );
-				randomInitialDirections[material_I] = Dictionary_GetBool_WithDefault( material->dictionary, (Dictionary_Entry_Key)"randomInitialDirection", False );
-				/* If no value is set, use default value from this file,
-				and not the (not-used) global value */ 
-				if ( randomInitialDirections[material_I] == False) {
-					materialDirectionVectors[ material_I ][0] = 
-						Dictionary_GetDouble_WithDefault( material->dictionary, (Dictionary_Entry_Key)"initialDirectionX", DIRECTOR_DEFAULT_DIR_X  );
-				
-					materialDirectionVectors[ material_I ][1] = 
-						Dictionary_GetDouble_WithDefault( material->dictionary, (Dictionary_Entry_Key)"initialDirectionY", DIRECTOR_DEFAULT_DIR_Y  );				   		
-				
-					materialDirectionVectors[ material_I ][2] = 
-						Dictionary_GetDouble_WithDefault( material->dictionary, (Dictionary_Entry_Key)"initialDirectionZ", DIRECTOR_DEFAULT_DIR_Z  );
-				}
-				else {
-					/* If no random seed set, then use global value ( which if 
-					not set will go to default value) */
-					randomInitialDirectionSeeds[material_I] = Dictionary_GetUnsignedInt_WithDefault(
-							material->dictionary,
-							"randomInitialDirectionSeed", 
-							self->randomInitialDirectionSeed);
-				}
-			}
-			/* Assign value to particle */
-			
-			/* If material is random, set the local srand, 
-			locate all random particles, and set their director */
-			for (material_I = 0; material_I < materialsCount; material_I++) {
-				if (randomInitialDirections[material_I] == True) {
-					Particle_Index	gParticle_I;
-					unsigned	approxGlobalParticleCount = particleLocalCount * self->materialPointsSwarm->nProc;
-					unsigned	startIndex = particleLocalCount * self->materialPointsSwarm->myRank;
-					double		norm[3];
-
-					srand( self->randomInitialDirectionSeed );
-					lParticle_I = 0;
-					for( gParticle_I = 0; gParticle_I < approxGlobalParticleCount; gParticle_I++ ) {
-						for ( dim_I = 0; dim_I < self->materialPointsSwarm->dim; dim_I++ ) {
-							norm[dim_I] = ( (float) rand() - RAND_MAX/2 ) / RAND_MAX;
-						}	
-						if( gParticle_I >= startIndex ) {
-							normal = Variable_GetPtrDouble( self->variable, lParticle_I );
-							for ( dim_I = 0; dim_I < self->materialPointsSwarm->dim; dim_I++ ) {
-								normal[dim_I] = norm[dim_I];
-							}
-							lParticle_I++;
-						}
-						if( lParticle_I >= particleLocalCount )
-							break;
-					}
-#if 0
-					/* create random directions for each particle */
-					srand(randomInitialDirectionSeeds[material_I]);
-					for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ){
-						materialOfParticle = MaterialPointsSwarm_GetMaterialIndexAt( self->materialPointsSwarm, lParticle_I );
-						if (materialOfParticle == material_I){
-							normal = Variable_GetPtrDouble( self->variable, lParticle_I );
-							for ( dim_I = 0; dim_I < self->materialPointsSwarm->dim; dim_I++ ) {
-								normal[dim_I] = ( (float) rand() - RAND_MAX/2 ) / RAND_MAX;
-							}	
-							/* Normalising the direction vector */
-							StGermain_VectorNormalise( normal, self->materialPointsSwarm->dim );
-						}
-					}
-#endif
-				}
-			}
-		    /* For each non-random particle, set the initial direction */
-			for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) {
-				/* Initialise the norm of each director */
-				material_I = MaterialPointsSwarm_GetMaterialIndexAt(
-						self->materialPointsSwarm, 
-						lParticle_I );
-				if (randomInitialDirections[material_I] == False) {
-					normal = Variable_GetPtrDouble(self->variable,lParticle_I);
-					memcpy(normal, materialDirectionVectors[material_I], sizeof(XYZ));
-					StGermain_VectorNormalise( normal, self->materialPointsSwarm->dim );			
-				}
-			}	
-			Memory_Free(materialDirectionVectors);		
-			Memory_Free(randomInitialDirections);
-			Memory_Free(randomInitialDirectionSeeds);
-		}
-		else {
-			Journal_Firewall(False, Journal_Register( Error_Type, (Name)"Director"  ), 
-			"Error in '%s', do not understand self->initialDirectionType = %u\n"
-			"initialDirectionType must match enumerated type, 'InitialDirectionType'"
-			"in Director.h\n", __func__, 
-			self->initialDirectionType);
-		}
-      /* Initialise the dontUpdate flag on each particle */
-      for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) { 
-         Variable_SetValueInt(self->dontUpdateParticle->variable, lParticle_I, 0);
-      }	
-	}
-
-}
-
-void _Director_Destroy( void* _self, void* data ) {
-	Director*          self               = (Director*) _self;
-
-   Stg_Component_Destroy( self->velGradField, data, False );
-   Stg_Component_Destroy( self->materialPointsSwarm, data, False );
-   Stg_Component_Destroy( self->directorSwarmVariable, data, False );
-   Stg_Component_Destroy( self->dontUpdateParticle, data, False );
-	/* Destroy parent */
-	_TimeIntegrand_Destroy( self, data );
-
-}
-
-Bool _Director_TimeDerivative( void* director, Index lParticle_I, double* timeDeriv ) {
-	Director*                self              = (Director*) director;
-	MaterialPointsSwarm*     materialPointsSwarm = self->materialPointsSwarm;
-	TensorArray              velGrad;
-	double*                  normal;
-	Element_LocalIndex       lElement_I;
-	MaterialPoint*           materialPoint = (MaterialPoint*) Swarm_ParticleAt( materialPointsSwarm, lParticle_I );
-	Director_ParticleExt*    particleExt;
-	InterpolationResult      result;
-
-	/* Get particle extension info - this will contain vector with director */
-	particleExt = (Director_ParticleExt*) ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr,
-		materialPoint, self->particleExtHandle );
-	
-	/* Check if this particle should be updated or not */
-	if ( self->dontUpdate || particleExt->dontUpdateParticle ) {
-		memset( timeDeriv, 0, sizeof(double) * materialPointsSwarm->dim );
-		return True;
-	}
-
-	normal     = particleExt->director;
-
-	lElement_I = materialPoint->owningCell;
-	
-	result = FieldVariable_InterpolateValueAt( self->velGradField, materialPoint->coord, velGrad );
-	/* if in debug mode, perform some tests */
-#ifdef DEBUG
-	if ( result == OTHER_PROC || result == OUTSIDE_GLOBAL || isinf(velGrad[0]) || isinf(velGrad[1]) || 
-		( self->materialPointsSwarm->dim == 3 && isinf(velGrad[2]) ) ) 
-	{
-		Journal_Printf( Journal_Register( Error_Type, (Name)self->type  ),
-			"Error in func '%s' for particle with index %u.\n\tPosition (%g, %g, %g)\n\tVelGrad here is (%g, %g, %g)."
-			"\n\tInterpolation result is %s.\n",
-			__func__, lParticle_I, materialPoint->coord[0], materialPoint->coord[1], materialPoint->coord[2], 
-			velGrad[0], velGrad[1], ( self->materialPointsSwarm->dim == 3 ? velGrad[2] : 0.0 ),
-			InterpolationResultToStringMap[result]  );
-		return False;		
-	}
-#endif
-	if ( materialPointsSwarm->dim == 2 ) {
-		timeDeriv[0] = -velGrad[MAP_2D_TENSOR(0,0)] * normal[0] - velGrad[MAP_2D_TENSOR(1,0)] * normal[1];
-		timeDeriv[1] = -velGrad[MAP_2D_TENSOR(0,1)] * normal[0] - velGrad[MAP_2D_TENSOR(1,1)] * normal[1];
-	}
-	else {
-		timeDeriv[0] = -velGrad[MAP_3D_TENSOR(0,0)] * normal[0] - velGrad[MAP_3D_TENSOR(1,0)] * normal[1] - velGrad[MAP_3D_TENSOR(2,0)] * normal[2];
-		timeDeriv[1] = -velGrad[MAP_3D_TENSOR(0,1)] * normal[0] - velGrad[MAP_3D_TENSOR(1,1)] * normal[1] - velGrad[MAP_3D_TENSOR(2,1)] * normal[2];
-		timeDeriv[2] = -velGrad[MAP_3D_TENSOR(0,2)] * normal[0] - velGrad[MAP_3D_TENSOR(1,2)] * normal[1] - velGrad[MAP_3D_TENSOR(2,2)] * normal[2] ;
-	}
-
-	return True;
-}
-
-/* This function is called after each of the time integration steps - 
- * here we just want to normalise the vector */
-void _Director_Intermediate( void* director, Index lParticle_I ) {
-	Director*          self              = (Director*) director;
-	double*            normal;
-	
-	normal = Variable_GetPtrDouble( self->variable, lParticle_I );
-	StGermain_VectorNormalise( normal, self->materialPointsSwarm->dim );
-}
-
-/* Update these variables in case the swarm has been reallocated */
-void Director_UpdateVariables( void* timeIntegrator, Director* self ) {
-	Variable_Update( self->variable );
-	Variable_Update( self->dontUpdateParticle->variable );
-	Variable_Update( self->materialPointsSwarm->particleCoordVariable->variable );
-	Variable_Update( self->materialPointsSwarm->owningCellVariable->variable );
-}
-	
-void Director_GetNormal( void* director, void* particle, XYZ normal ) {
-	Director*             self              = (Director*) director;
-	Director_ParticleExt* particleExt;
-
-	particleExt = (Director_ParticleExt*) 
-		ExtensionManager_Get( self->materialPointsSwarm->particleExtensionMgr, particle, self->particleExtHandle );
-
-	memcpy( normal, particleExt->director, sizeof(XYZ) );
-}
-
-void Director_SetNormal( void* director, void* particle, XYZ normal ) {
-	Director*             self              = (Director*) director;
-	Director_ParticleExt* particleExt;
-	
-	particleExt = (Director_ParticleExt*) 
-			ExtensionManager_Get( self->materialPointsSwarm->particleExtensionMgr, particle, self->particleExtHandle );
-	
-	memcpy( particleExt->director, normal , sizeof(XYZ) );
-}
-
-double* Director_GetNormalPtr( void* director, void* particle) {
-	Director*             self              = (Director*) director;
-	Director_ParticleExt* particleExt;
-	
-	particleExt = (Director_ParticleExt*) 
-			ExtensionManager_Get( self->materialPointsSwarm->particleExtensionMgr, particle, self->particleExtHandle );
-	
-	return particleExt->director;
-}
-
-void Director_SetDontUpdateParticleFlag( void* director, void* particle, Particle_Bool dontUpdateFlag ){
-	Director*             self              = (Director*) director;
-	Director_ParticleExt* particleExt;
-	
-	particleExt = (Director_ParticleExt*) 
-			ExtensionManager_Get( self->materialPointsSwarm->particleExtensionMgr, particle, self->particleExtHandle );
-	
-	particleExt->dontUpdateParticle = dontUpdateFlag;
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/Director.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/Director.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,582 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+		Kathleen Humble
+*+
+** $Id: Director.c 629 2007-11-14 05:47:33Z BelindaMay $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "RheologyClass.h"
+#include "YieldRheology.h"
+#include "VonMises.h"
+#include "Director.h"
+#include "ConstitutiveMatrix.h"
+
+#include <assert.h>
+#include <string.h>
+
+/* Define the default initial direction for particles */ 
+#define DIRECTOR_DEFAULT_DIR_X 0.0
+#define DIRECTOR_DEFAULT_DIR_Y 1.0
+#define DIRECTOR_DEFAULT_DIR_Z 0.0
+
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type Director_Type = "Director";
+
+/* Public Constructor */
+Director* Director_New( 
+		Name                   name,
+		DomainContext*         context,
+		TimeIntegrator*        timeIntegrator, 
+		Variable*              variable,
+		Index                  dataCount, 
+		Stg_Component**        data,
+		Bool                   allowFallbackToFirstOrder,
+		FeVariable*            velGradField,
+		MaterialPointsSwarm*   materialPointsSwarm,
+		InitialDirectionType   initialDirectionType,
+		double                 globalInitialDirectionX,
+		double                 globalInitialDirectionY,
+		double                 globalInitialDirectionZ,
+		int                    randomInitialDirectionSeed,
+		Bool                   dontUpdate )
+{
+	Director*	self;
+
+	self = (Director*) _Director_DefaultNew( name );
+	
+	_TimeIntegrand_Init( self, context, timeIntegrator, variable, dataCount, data, allowFallbackToFirstOrder );
+   _Director_Init(
+		self,
+		velGradField,
+		materialPointsSwarm,
+		initialDirectionType,
+		globalInitialDirectionX,
+		globalInitialDirectionY,
+		globalInitialDirectionZ,
+		randomInitialDirectionSeed,
+		dontUpdate );
+
+	self->isConstructed = True;
+	return self;
+}
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+Director* _Director_New(  DIRECTOR_DEFARGS  ) 
+{
+	Director*					self;
+
+	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+	assert( _sizeOfSelf >= sizeof(Director) );
+	self = (Director*) _TimeIntegrand_New(  TIMEINTEGRAND_PASSARGS  );
+	
+	/* Function pointers for this class that are not on the parent class should be set here */
+	
+	return self;
+}
+
+void _Director_Init(
+		Director*                                          self,
+		FeVariable*                                        velGradField,
+		MaterialPointsSwarm*                               materialPointsSwarm,
+		InitialDirectionType                               initialDirectionType,
+		double                                             globalInitialDirectionX,
+		double                                             globalInitialDirectionY,
+		double                                             globalInitialDirectionZ,
+		int                                                randomInitialDirectionSeed,
+		Bool                                               dontUpdate )
+{
+	/* Assign Values */
+	self->velGradField               = velGradField;
+	self->materialPointsSwarm        = materialPointsSwarm;
+	self->dontUpdate                 = dontUpdate;
+	self->globalInitialDirection[ I_AXIS ] = globalInitialDirectionX;
+	self->globalInitialDirection[ J_AXIS ] = globalInitialDirectionY;
+	self->globalInitialDirection[ K_AXIS ] = globalInitialDirectionZ;
+	self->randomInitialDirectionSeed = randomInitialDirectionSeed;
+	StGermain_VectorNormalise( self->globalInitialDirection, materialPointsSwarm->dim );
+	self->initialDirectionType = initialDirectionType;
+	/****** Setup Variables *****/
+
+	/* First check to see if a particle extension has already been created for this swarm */
+	self->particleExtHandle     = ExtensionManager_GetHandle( materialPointsSwarm->particleExtensionMgr, (Name)Director_Type );
+
+	/* If there isn't one then create the particle extension - otherwise just use the one already there*/
+	if ( self->particleExtHandle == (ExtensionInfo_Index) -1  ) {
+		StandardParticle      particle;
+		Director_ParticleExt* particleExt;
+
+		/* Add particle extension */
+		self->particleExtHandle = 
+			ExtensionManager_Add( materialPointsSwarm->particleExtensionMgr, (Name)Director_Type, sizeof(Director_ParticleExt)  );	
+
+		particleExt = (Director_ParticleExt*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, &particle, self->particleExtHandle );
+
+		self->directorSwarmVariable = Swarm_NewVectorVariable( materialPointsSwarm, (Name)"Director", (ArithPointer) &particleExt->director - (ArithPointer) &particle,
+			Variable_DataType_Double,
+			materialPointsSwarm->dim,
+			"DirectorX",
+			"DirectorY",
+			"DirectorZ" );
+		self->dontUpdateParticle = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"dontUpdateParticle", (ArithPointer) &particleExt->dontUpdateParticle - (ArithPointer) &particle, Variable_DataType_Int  );
+	}
+	else {
+		char* variableName;
+
+		/* Get Variables already created */
+		variableName = Stg_Object_AppendSuffix( materialPointsSwarm, (Name)"Director"  );
+		self->directorSwarmVariable = SwarmVariable_Register_GetByName( materialPointsSwarm->swarmVariable_Register, variableName );
+		assert( self->directorSwarmVariable );
+		Memory_Free( variableName );
+		/* Get Variables already created */
+		variableName = Stg_Object_AppendSuffix( materialPointsSwarm, (Name)"dontUpdateParticle"  );
+		self->dontUpdateParticle = SwarmVariable_Register_GetByName( materialPointsSwarm->swarmVariable_Register, variableName );
+		assert( self->dontUpdateParticle );
+		Memory_Free( variableName );
+	}
+	
+	self->variable = self->directorSwarmVariable->variable;
+
+	TimeIntegrator_AppendSetupEP( self->timeIntegrator,
+                                      "Director_UpdateVariables", (void*)Director_UpdateVariables,  self->name, self );
+}
+
+void* _Director_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                               _sizeOfSelf = sizeof(Director);
+	Type                                                       type = Director_Type;
+	Stg_Class_DeleteFunction*                               _delete = _TimeIntegrand_Delete;
+	Stg_Class_PrintFunction*                                 _print = _TimeIntegrand_Print;
+	Stg_Class_CopyFunction*                                   _copy = _TimeIntegrand_Copy;
+	Stg_Component_DefaultConstructorFunction*   _defaultConstructor = _Director_DefaultNew;
+	Stg_Component_ConstructFunction*                     _construct = _Director_AssignFromXML;
+	Stg_Component_BuildFunction*                             _build = _Director_Build;
+	Stg_Component_InitialiseFunction*                   _initialise = _Director_Initialise;
+	Stg_Component_ExecuteFunction*                         _execute = _TimeIntegrand_Execute;
+	Stg_Component_DestroyFunction*                         _destroy = _Director_Destroy;
+	TimeIntegrand_CalculateTimeDerivFunction*  _calculateTimeDeriv = _Director_TimeDerivative;
+	TimeIntegrand_IntermediateFunction*              _intermediate = _Director_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*) _Director_New(  DIRECTOR_PASSARGS  );
+}
+
+void _Director_AssignFromXML( void* director, Stg_ComponentFactory* cf, void* data ){
+	Director*               self           = (Director*)director;
+	MaterialPointsSwarm*    materialPointsSwarm;
+	FeVariable*             velGradField;
+	char*                   initialDirectionTypeName;
+	InitialDirectionType    initialDirectionType;
+	
+	/* Construct Parent */
+	_TimeIntegrand_AssignFromXML( self, cf, data );
+	
+	/* Construct 'Director' stuff */
+	/* TODO: 'KeyFallback' soon to be deprecated/updated */
+        velGradField   = Stg_ComponentFactory_ConstructByNameWithKeyFallback( cf, self->name, (Name)"VelocityGradientsField", (Dictionary_Entry_Key)"VelocityGradientsField", FeVariable, True, data  );
+	/*
+	velGradField   = Stg_ComponentFactory_ConstructByKey( 
+			cf, self->name, "VelocityGradientsField", FeVariable, True );
+	*/		
+	materialPointsSwarm = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"MaterialPointsSwarm", MaterialPointsSwarm, True, data  );
+	
+	
+	/* Define the initial Direction type for the problem
+		The options are: global definition of direction,
+		Random direction,
+		a different direction per material.
+	*/
+	initialDirectionTypeName = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"initialDirectionType", "global" );
+	if (0 == strcasecmp(initialDirectionTypeName, "global")) {
+		initialDirectionType = INIT_DIR_GLOBAL;
+	}
+	else if (0 == strcasecmp(initialDirectionTypeName, "random")) {
+		initialDirectionType = INIT_DIR_RANDOM;
+	}
+	else if (0 == strcasecmp(initialDirectionTypeName,"perMaterial")) {
+		initialDirectionType = INIT_DIR_PER_MAT;
+	}
+	else {
+			Journal_Firewall(False, Journal_Register( Error_Type, (Name)"Director"  ), 
+			"Error in '%s', do not understand initialDirectionType = %s\n."
+			" Options are: \"global\", \"random\" or \"perMaterial\" ", __func__, 
+			initialDirectionTypeName);		
+	}
+	
+	_Director_Init(
+			self, 
+			velGradField,
+			materialPointsSwarm,
+			initialDirectionType,
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"initialDirectionX", DIRECTOR_DEFAULT_DIR_X  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"initialDirectionY", DIRECTOR_DEFAULT_DIR_Y  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"initialDirectionZ", DIRECTOR_DEFAULT_DIR_Z  ),
+			Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"randomInitialDirectionSeed", 1  ),
+			Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"dontUpdate", False )  );
+
+}
+
+void _Director_Build( void* director, void* data ) {
+	Director*                       self               = (Director*) director;
+
+	/* Build parent */
+	_TimeIntegrand_Build( self, data );
+
+	Stg_Component_Build( self->directorSwarmVariable, data, False );
+	Stg_Component_Build( self->dontUpdateParticle, data, False );
+}
+
+void _Director_Initialise( void* director, void* data ) {
+	Director*                       self               = (Director*) director;
+	Particle_Index                  lParticle_I;
+	Particle_Index                  particleLocalCount = self->variable->arraySize;
+	double*                         normal;
+	Dimension_Index                 dim_I;
+
+	/* Initialise Parent */
+	_TimeIntegrand_Initialise( self, data );
+
+	Stg_Component_Initialise( self->materialPointsSwarm, data, False );
+	/* We should only set initial directors if in regular non-restart mode. If in restart mode, then
+	the directors will be set correctly when we re-load the Swarm. */
+	if ( self->context->loadFromCheckPoint == False ) {
+
+      Stg_Component_Initialise( self->directorSwarmVariable, data, False );
+      Stg_Component_Initialise( self->dontUpdateParticle, data, True );
+   
+      /* Update variables */
+      Variable_Update( self->variable );
+
+		particleLocalCount = self->variable->arraySize;
+		if ( self->initialDirectionType == INIT_DIR_GLOBAL ) {
+			for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) {
+				/* Initialise the norm of each director */
+				normal = Variable_GetPtrDouble( self->variable, lParticle_I );
+
+				memcpy( normal, self->globalInitialDirection, sizeof(XYZ) );
+			}	
+		}
+		else if (self->initialDirectionType == INIT_DIR_RANDOM){
+			Particle_Index	gParticle_I;
+			unsigned	approxGlobalParticleCount = particleLocalCount * self->materialPointsSwarm->nProc;
+			unsigned	startIndex = particleLocalCount * self->materialPointsSwarm->myRank;
+			double		norm[3];
+
+			/* create random directions for each particle */
+			srand( self->randomInitialDirectionSeed );
+
+			lParticle_I = 0;
+			for( gParticle_I = 0; gParticle_I < approxGlobalParticleCount; gParticle_I++ ) {
+				for ( dim_I = 0; dim_I < self->materialPointsSwarm->dim; dim_I++ ) {
+					norm[dim_I] = ( (float) rand() - RAND_MAX/2 ) / RAND_MAX;
+				}	
+				if( gParticle_I >= startIndex ) {
+					normal = Variable_GetPtrDouble( self->variable, lParticle_I );
+					for ( dim_I = 0; dim_I < self->materialPointsSwarm->dim; dim_I++ ) {
+						normal[dim_I] = norm[dim_I];
+					}
+					lParticle_I++;
+				}
+				if( lParticle_I >= particleLocalCount )
+					break;
+			}
+/*
+			for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) {
+				normal = Variable_GetPtrDouble( self->variable, lParticle_I );
+				for ( dim_I = 0; dim_I < self->materialPointsSwarm->dim; dim_I++ ) {
+					normal[dim_I] = ( (float) rand() - RAND_MAX/2 ) / RAND_MAX;
+				}	
+				StGermain_VectorNormalise( normal, self->materialPointsSwarm->dim );
+			}
+*/
+		}
+		else if (self->initialDirectionType == INIT_DIR_PER_MAT) {
+			/* Assign initial direction based on material
+			  and check first is material is defined as random.*/
+			Material_Index	materialsCount = Materials_Register_GetCount( self->materialPointsSwarm->materials_Register);
+			XYZ*				materialDirectionVectors;
+			int				material_I;
+			Material*		material;
+			Bool*				randomInitialDirections;
+			int*				randomInitialDirectionSeeds;
+			/* int				materialOfParticle; */
+			
+			materialDirectionVectors = Memory_Alloc_Array(XYZ, materialsCount, "materialDirectionVectors");
+			randomInitialDirectionSeeds = Memory_Alloc_Array(int, materialsCount,
+			"randomInitialDirectionSeeds");
+			randomInitialDirections = Memory_Alloc_Array(Bool, materialsCount,
+			"randomInitialDirections");
+
+			/* Loop over materials and get material properties from dictionary */
+			for ( material_I = 0 ; material_I < materialsCount ; material_I++ ) {
+				material = Materials_Register_GetByIndex( 
+						self->materialPointsSwarm->materials_Register, 
+						material_I );
+				randomInitialDirections[material_I] = Dictionary_GetBool_WithDefault( material->dictionary, (Dictionary_Entry_Key)"randomInitialDirection", False );
+				/* If no value is set, use default value from this file,
+				and not the (not-used) global value */ 
+				if ( randomInitialDirections[material_I] == False) {
+					materialDirectionVectors[ material_I ][0] = 
+						Dictionary_GetDouble_WithDefault( material->dictionary, (Dictionary_Entry_Key)"initialDirectionX", DIRECTOR_DEFAULT_DIR_X  );
+				
+					materialDirectionVectors[ material_I ][1] = 
+						Dictionary_GetDouble_WithDefault( material->dictionary, (Dictionary_Entry_Key)"initialDirectionY", DIRECTOR_DEFAULT_DIR_Y  );				   		
+				
+					materialDirectionVectors[ material_I ][2] = 
+						Dictionary_GetDouble_WithDefault( material->dictionary, (Dictionary_Entry_Key)"initialDirectionZ", DIRECTOR_DEFAULT_DIR_Z  );
+				}
+				else {
+					/* If no random seed set, then use global value ( which if 
+					not set will go to default value) */
+					randomInitialDirectionSeeds[material_I] = Dictionary_GetUnsignedInt_WithDefault(
+							material->dictionary,
+							"randomInitialDirectionSeed", 
+							self->randomInitialDirectionSeed);
+				}
+			}
+			/* Assign value to particle */
+			
+			/* If material is random, set the local srand, 
+			locate all random particles, and set their director */
+			for (material_I = 0; material_I < materialsCount; material_I++) {
+				if (randomInitialDirections[material_I] == True) {
+					Particle_Index	gParticle_I;
+					unsigned	approxGlobalParticleCount = particleLocalCount * self->materialPointsSwarm->nProc;
+					unsigned	startIndex = particleLocalCount * self->materialPointsSwarm->myRank;
+					double		norm[3];
+
+					srand( self->randomInitialDirectionSeed );
+					lParticle_I = 0;
+					for( gParticle_I = 0; gParticle_I < approxGlobalParticleCount; gParticle_I++ ) {
+						for ( dim_I = 0; dim_I < self->materialPointsSwarm->dim; dim_I++ ) {
+							norm[dim_I] = ( (float) rand() - RAND_MAX/2 ) / RAND_MAX;
+						}	
+						if( gParticle_I >= startIndex ) {
+							normal = Variable_GetPtrDouble( self->variable, lParticle_I );
+							for ( dim_I = 0; dim_I < self->materialPointsSwarm->dim; dim_I++ ) {
+								normal[dim_I] = norm[dim_I];
+							}
+							lParticle_I++;
+						}
+						if( lParticle_I >= particleLocalCount )
+							break;
+					}
+#if 0
+					/* create random directions for each particle */
+					srand(randomInitialDirectionSeeds[material_I]);
+					for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ){
+						materialOfParticle = MaterialPointsSwarm_GetMaterialIndexAt( self->materialPointsSwarm, lParticle_I );
+						if (materialOfParticle == material_I){
+							normal = Variable_GetPtrDouble( self->variable, lParticle_I );
+							for ( dim_I = 0; dim_I < self->materialPointsSwarm->dim; dim_I++ ) {
+								normal[dim_I] = ( (float) rand() - RAND_MAX/2 ) / RAND_MAX;
+							}	
+							/* Normalising the direction vector */
+							StGermain_VectorNormalise( normal, self->materialPointsSwarm->dim );
+						}
+					}
+#endif
+				}
+			}
+		    /* For each non-random particle, set the initial direction */
+			for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) {
+				/* Initialise the norm of each director */
+				material_I = MaterialPointsSwarm_GetMaterialIndexAt(
+						self->materialPointsSwarm, 
+						lParticle_I );
+				if (randomInitialDirections[material_I] == False) {
+					normal = Variable_GetPtrDouble(self->variable,lParticle_I);
+					memcpy(normal, materialDirectionVectors[material_I], sizeof(XYZ));
+					StGermain_VectorNormalise( normal, self->materialPointsSwarm->dim );			
+				}
+			}	
+			Memory_Free(materialDirectionVectors);		
+			Memory_Free(randomInitialDirections);
+			Memory_Free(randomInitialDirectionSeeds);
+		}
+		else {
+			Journal_Firewall(False, Journal_Register( Error_Type, (Name)"Director"  ), 
+			"Error in '%s', do not understand self->initialDirectionType = %u\n"
+			"initialDirectionType must match enumerated type, 'InitialDirectionType'"
+			"in Director.h\n", __func__, 
+			self->initialDirectionType);
+		}
+      /* Initialise the dontUpdate flag on each particle */
+      for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) { 
+         Variable_SetValueInt(self->dontUpdateParticle->variable, lParticle_I, 0);
+      }	
+	}
+
+}
+
+void _Director_Destroy( void* _self, void* data ) {
+	Director*          self               = (Director*) _self;
+
+   Stg_Component_Destroy( self->velGradField, data, False );
+   Stg_Component_Destroy( self->materialPointsSwarm, data, False );
+   Stg_Component_Destroy( self->directorSwarmVariable, data, False );
+   Stg_Component_Destroy( self->dontUpdateParticle, data, False );
+	/* Destroy parent */
+	_TimeIntegrand_Destroy( self, data );
+
+}
+
+Bool _Director_TimeDerivative( void* director, Index lParticle_I, double* timeDeriv ) {
+	Director*                self              = (Director*) director;
+	MaterialPointsSwarm*     materialPointsSwarm = self->materialPointsSwarm;
+	TensorArray              velGrad;
+	double*                  normal;
+	Element_LocalIndex       lElement_I;
+	MaterialPoint*           materialPoint = (MaterialPoint*) Swarm_ParticleAt( materialPointsSwarm, lParticle_I );
+	Director_ParticleExt*    particleExt;
+	InterpolationResult      result;
+
+	/* Get particle extension info - this will contain vector with director */
+	particleExt = (Director_ParticleExt*) ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr,
+		materialPoint, self->particleExtHandle );
+	
+	/* Check if this particle should be updated or not */
+	if ( self->dontUpdate || particleExt->dontUpdateParticle ) {
+		memset( timeDeriv, 0, sizeof(double) * materialPointsSwarm->dim );
+		return True;
+	}
+
+	normal     = particleExt->director;
+
+	lElement_I = materialPoint->owningCell;
+	
+	result = FieldVariable_InterpolateValueAt( self->velGradField, materialPoint->coord, velGrad );
+	/* if in debug mode, perform some tests */
+#ifdef DEBUG
+	if ( result == OTHER_PROC || result == OUTSIDE_GLOBAL || isinf(velGrad[0]) || isinf(velGrad[1]) || 
+		( self->materialPointsSwarm->dim == 3 && isinf(velGrad[2]) ) ) 
+	{
+		Journal_Printf( Journal_Register( Error_Type, (Name)self->type  ),
+			"Error in func '%s' for particle with index %u.\n\tPosition (%g, %g, %g)\n\tVelGrad here is (%g, %g, %g)."
+			"\n\tInterpolation result is %s.\n",
+			__func__, lParticle_I, materialPoint->coord[0], materialPoint->coord[1], materialPoint->coord[2], 
+			velGrad[0], velGrad[1], ( self->materialPointsSwarm->dim == 3 ? velGrad[2] : 0.0 ),
+			InterpolationResultToStringMap[result]  );
+		return False;		
+	}
+#endif
+	if ( materialPointsSwarm->dim == 2 ) {
+		timeDeriv[0] = -velGrad[MAP_2D_TENSOR(0,0)] * normal[0] - velGrad[MAP_2D_TENSOR(1,0)] * normal[1];
+		timeDeriv[1] = -velGrad[MAP_2D_TENSOR(0,1)] * normal[0] - velGrad[MAP_2D_TENSOR(1,1)] * normal[1];
+	}
+	else {
+		timeDeriv[0] = -velGrad[MAP_3D_TENSOR(0,0)] * normal[0] - velGrad[MAP_3D_TENSOR(1,0)] * normal[1] - velGrad[MAP_3D_TENSOR(2,0)] * normal[2];
+		timeDeriv[1] = -velGrad[MAP_3D_TENSOR(0,1)] * normal[0] - velGrad[MAP_3D_TENSOR(1,1)] * normal[1] - velGrad[MAP_3D_TENSOR(2,1)] * normal[2];
+		timeDeriv[2] = -velGrad[MAP_3D_TENSOR(0,2)] * normal[0] - velGrad[MAP_3D_TENSOR(1,2)] * normal[1] - velGrad[MAP_3D_TENSOR(2,2)] * normal[2] ;
+	}
+
+	return True;
+}
+
+/* This function is called after each of the time integration steps - 
+ * here we just want to normalise the vector */
+void _Director_Intermediate( void* director, Index lParticle_I ) {
+	Director*          self              = (Director*) director;
+	double*            normal;
+	
+	normal = Variable_GetPtrDouble( self->variable, lParticle_I );
+	StGermain_VectorNormalise( normal, self->materialPointsSwarm->dim );
+}
+
+/* Update these variables in case the swarm has been reallocated */
+void Director_UpdateVariables( void* timeIntegrator, Director* self ) {
+	Variable_Update( self->variable );
+	Variable_Update( self->dontUpdateParticle->variable );
+	Variable_Update( self->materialPointsSwarm->particleCoordVariable->variable );
+	Variable_Update( self->materialPointsSwarm->owningCellVariable->variable );
+}
+	
+void Director_GetNormal( void* director, void* particle, XYZ normal ) {
+	Director*             self              = (Director*) director;
+	Director_ParticleExt* particleExt;
+
+	particleExt = (Director_ParticleExt*) 
+		ExtensionManager_Get( self->materialPointsSwarm->particleExtensionMgr, particle, self->particleExtHandle );
+
+	memcpy( normal, particleExt->director, sizeof(XYZ) );
+}
+
+void Director_SetNormal( void* director, void* particle, XYZ normal ) {
+	Director*             self              = (Director*) director;
+	Director_ParticleExt* particleExt;
+	
+	particleExt = (Director_ParticleExt*) 
+			ExtensionManager_Get( self->materialPointsSwarm->particleExtensionMgr, particle, self->particleExtHandle );
+	
+	memcpy( particleExt->director, normal , sizeof(XYZ) );
+}
+
+double* Director_GetNormalPtr( void* director, void* particle) {
+	Director*             self              = (Director*) director;
+	Director_ParticleExt* particleExt;
+	
+	particleExt = (Director_ParticleExt*) 
+			ExtensionManager_Get( self->materialPointsSwarm->particleExtensionMgr, particle, self->particleExtHandle );
+	
+	return particleExt->director;
+}
+
+void Director_SetDontUpdateParticleFlag( void* director, void* particle, Particle_Bool dontUpdateFlag ){
+	Director*             self              = (Director*) director;
+	Director_ParticleExt* particleExt;
+	
+	particleExt = (Director_ParticleExt*) 
+			ExtensionManager_Get( self->materialPointsSwarm->particleExtensionMgr, particle, self->particleExtHandle );
+	
+	particleExt->dontUpdateParticle = dontUpdateFlag;
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/DruckerPrager.c
--- a/Rheology/src/DruckerPrager.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,678 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: DruckerPrager.c 743 2008-06-23 01:49:43Z JulianGiordani $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "RheologyClass.h"
-#include "StrainWeakening.h"
-#include "YieldRheology.h"
-#include "VonMises.h"
-#include "DruckerPrager.h"
-#include "ConstitutiveMatrix.h"
-
-#include <assert.h>
-#include <string.h>
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type DruckerPrager_Type = "DruckerPrager";
-
-/* Public Constructor */
-DruckerPrager* DruckerPrager_New(
-	Name                  name,
-	StrainWeakening*      strainWeakening, 
-	MaterialPointsSwarm*  materialPointsSwarm, 
-	double                minVisc, 
-	FeVariable*           strainRateField,
-	SwarmVariable*        swarmStrainRate,
-	double                cohesion,
-	double                cohesionAfterSoftening,
-	Bool                  strainRateSoftening,
-	FeVariable*           pressureField,
-	SwarmVariable*        swarmPressure,
-	double                minimumYieldStress,
-	double                minimumViscosity,
-	double                maxStrainRate,
-	double                frictionCoefficient,
-	double                frictionCoefficientAfterSoftening,
-        double                boundaryCohesion,
-        double                boundaryCohesionAfterSoftening,
-        double                boundaryFrictionCoefficient,
-        double                boundaryFrictionCoefficientAfterSoftening,
-        Bool                  boundaryTop,
-        Bool                  boundaryBottom,
-        Bool                  boundaryLeft,
-        Bool                  boundaryRight,
-        Bool                  boundaryFront,
-        Bool                  boundaryBack,
-        HydrostaticTerm*      hydrostaticTerm)
-{
-   DruckerPrager* self = (DruckerPrager*) _DruckerPrager_DefaultNew( name );
-
-   _Rheology_Init( self, (PICelleratorContext*)self->context );
-   _YieldRheology_Init( (YieldRheology*)self, strainWeakening, materialPointsSwarm, minVisc ); 
-   _VonMises_Init( (VonMises*)self, strainRateField, swarmStrainRate, cohesion, cohesionAfterSoftening, strainRateSoftening );
-   _DruckerPrager_Init( self, pressureField, swarmPressure,
-                        materialPointsSwarm,
-                        frictionCoefficient,
-                        frictionCoefficientAfterSoftening,
-                        boundaryCohesion,
-                        boundaryCohesionAfterSoftening,
-                        boundaryFrictionCoefficient,
-                        boundaryFrictionCoefficientAfterSoftening,
-                        boundaryBottom,
-                        boundaryTop,
-                        boundaryLeft,
-                        boundaryRight,
-                        boundaryFront,
-                        boundaryBack,
-                        minimumYieldStress,
-                        minimumViscosity,
-                        maxStrainRate,
-                        hydrostaticTerm );
-   self->isConstructed = True;
-   return self;
-}
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-DruckerPrager* _DruckerPrager_New(  DRUCKERPRAGER_DEFARGS  ) 
-{
-	DruckerPrager*					self;
-
-	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-	assert( _sizeOfSelf >= sizeof(DruckerPrager) );
-	self = (DruckerPrager*) _VonMises_New(  VONMISES_PASSARGS  );
-	
-	/* Function pointers for this class that are not on the parent class should be set here */
-	
-	return self;
-}
-
-void _DruckerPrager_Init(
-		DruckerPrager*                                     self,
-		FeVariable*                                        pressureField,
-		SwarmVariable*                                     swarmPressure,
-		MaterialPointsSwarm*                               materialPointsSwarm,
-		double                                             frictionCoefficient,
-		double                                             frictionCoefficientAfterSoftening,
-                double                    boundaryCohesion,
-                double                    boundaryCohesionAfterSoftening,
-                double                    boundaryFrictionCoefficient,
-                double                    boundaryFrictionCoefficientAfterSoftening,
-                Bool                      boundaryBottom,
-                Bool                      boundaryTop,
-                Bool                      boundaryLeft,
-                Bool                      boundaryRight,
-                Bool                      boundaryFront,
-                Bool                      boundaryBack,
-                double                    minimumYieldStress,
-                double                    minimumViscosity,
-                double                    maxStrainRate,
-                HydrostaticTerm*          hydrostaticTerm )
-{
-	DruckerPrager_Particle*   particleExt;
-	StandardParticle          materialPoint;
-	
-	self->particleExtHandle = ExtensionManager_Add( materialPointsSwarm->particleExtensionMgr, (Name)DruckerPrager_Type, sizeof(DruckerPrager_Particle) );
-		
-	/* Assign Pointers */
-	self->pressureField       = pressureField;
-	self->frictionCoefficient = frictionCoefficient;
-	self->minimumYieldStress  = minimumYieldStress;
-	self->minimumViscosity    = minimumViscosity;
-	self->maxStrainRate       = maxStrainRate;
-	self->swarmPressure       = swarmPressure;
-	
-	/* Strain softening of Cohesion and friction - (linear
-           weakening is assumed) needs a softening factor between +0
-           and 1 and a reference strain > 0 */
-	self->frictionCoefficientAfterSoftening = frictionCoefficientAfterSoftening;
-	self->boundaryCohesion = boundaryCohesion;
-	self->boundaryFrictionCoefficient = boundaryFrictionCoefficient;
-	self->boundaryCohesionAfterSoftening = boundaryCohesionAfterSoftening;
-	self->boundaryFrictionCoefficientAfterSoftening = boundaryFrictionCoefficientAfterSoftening;
-        self->boundaryBottom=boundaryBottom;
-        self->boundaryTop=boundaryTop;
-        self->boundaryLeft=boundaryLeft;
-        self->boundaryRight=boundaryRight;
-        self->boundaryFront=boundaryFront;
-        self->boundaryBack=boundaryBack;
-
-	self->minimumYieldStress = minimumYieldStress;
-	self->minimumViscosity = minimumViscosity;
-	self->maxStrainRate = maxStrainRate;
-        self->hydrostaticTerm=hydrostaticTerm;
-
-	/* Update Drawing Parameters */
-	EP_PrependClassHook( Context_GetEntryPoint( self->context, AbstractContext_EP_DumpClass ),
-								_DruckerPrager_UpdateDrawParameters, self );
-	
-	particleExt = (DruckerPrager_Particle*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, &materialPoint, self->particleExtHandle );
-	
-	/* Setup Variables for Visualisation */
-	self->brightness = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"DruckerPragerBrightness", (ArithPointer) &particleExt->brightness - (ArithPointer) &materialPoint, Variable_DataType_Float  );
-	
-	self->opacity = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"DruckerPragerOpacity", (ArithPointer) &particleExt->opacity - (ArithPointer) &materialPoint, Variable_DataType_Float  );
-	
-	self->diameter = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"DruckerPragerDiameter", (ArithPointer) &particleExt->diameter - (ArithPointer) &materialPoint, Variable_DataType_Float  );
-
-	/* The tensileFailure variable allows to check whether a materialPoint has failed in tensile mode or not */
-	self->tensileFailure = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"DruckerPragerTensileFailure", (ArithPointer) &particleExt->tensileFailure - (ArithPointer) &materialPoint, Variable_DataType_Char );
-
-        self->curFrictionCoef = 0.0;
-}
-
-void* _DruckerPrager_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                     _sizeOfSelf = sizeof(DruckerPrager);
-	Type                                                             type = DruckerPrager_Type;
-	Stg_Class_DeleteFunction*                                     _delete = _YieldRheology_Delete;
-	Stg_Class_PrintFunction*                                       _print = _YieldRheology_Print;
-	Stg_Class_CopyFunction*                                         _copy = _YieldRheology_Copy;
-	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _DruckerPrager_DefaultNew;
-	Stg_Component_ConstructFunction*                           _construct = _DruckerPrager_AssignFromXML;
-	Stg_Component_BuildFunction*                                   _build = _DruckerPrager_Build;
-	Stg_Component_InitialiseFunction*                         _initialise = _DruckerPrager_Initialise;
-	Stg_Component_ExecuteFunction*                               _execute = _YieldRheology_Execute;
-	Stg_Component_DestroyFunction*                               _destroy = _DruckerPrager_Destroy;
-	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _YieldRheology_ModifyConstitutiveMatrix;
-	YieldRheology_GetYieldCriterionFunction*           _getYieldCriterion = _DruckerPrager_GetYieldCriterion;
-	YieldRheology_GetYieldIndicatorFunction*           _getYieldIndicator = _VonMises_GetYieldIndicator;
-	YieldRheology_HasYieldedFunction*                         _hasYielded = _DruckerPrager_HasYielded;
-
-	/* 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*) _DruckerPrager_New(  DRUCKERPRAGER_PASSARGS   );
-}
-
-void _DruckerPrager_AssignFromXML( void* druckerPrager, Stg_ComponentFactory* cf, void* data ){
-	DruckerPrager*          self           = (DruckerPrager*)druckerPrager;
-	FeVariable*             pressureField = NULL;
-	SwarmVariable*          swarmPressure = NULL;
-	MaterialPointsSwarm*    materialPointsSwarm = NULL;
-
-	/* Construct Parent */
-	_VonMises_AssignFromXML( self, cf, data );
-	
-	pressureField      = (FeVariable *) 
-            Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"PressureField", FeVariable, False, data  );
-   swarmPressure = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"swarmPressure", SwarmVariable, False, data );
-   Journal_Firewall( 
-			( pressureField || swarmPressure ), 
-			Journal_Register( Error_Type, (Name)self->type  ), 
-			"\n Error in component type %s, name '%s'.\n Must specify a PressureField OR a swarmPressure, but not both. \n", self->type, self->name ); 
-			
-	materialPointsSwarm     = (MaterialPointsSwarm*)
-			Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"MaterialPointsSwarm", MaterialPointsSwarm, True, data  );
-		
-	_DruckerPrager_Init( self, 
-			pressureField,
-			swarmPressure,
-			materialPointsSwarm, 
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"frictionCoefficient", 0.0 ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"frictionCoefficientAfterSoftening", 0.0 ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"boundaryCohesion", 0.0 ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"boundaryCohesionAfterSoftening", 0.0 ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"boundaryFrictionCoefficient", 0.0 ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"boundaryFrictionCoefficientAfterSoftening", 0.0 ),
-                        Stg_ComponentFactory_GetBool(  cf,  self->name, (Dictionary_Entry_Key)"boundaryBottom", False ),
-                        Stg_ComponentFactory_GetBool(  cf,  self->name, (Dictionary_Entry_Key)"boundaryTop", False ),
-                        Stg_ComponentFactory_GetBool(  cf,  self->name, (Dictionary_Entry_Key)"boundaryLeft", False ),
-                        Stg_ComponentFactory_GetBool(  cf,  self->name, (Dictionary_Entry_Key)"boundaryRight", False ),
-                        Stg_ComponentFactory_GetBool(  cf,  self->name, (Dictionary_Entry_Key)"boundaryFront", False ),
-                        Stg_ComponentFactory_GetBool(  cf,  self->name, (Dictionary_Entry_Key)"boundaryBack", False ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"minimumYieldStress", 0.0 ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"minimumViscosity", 0.0),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"maxStrainRate", 0.0),
-                        Stg_ComponentFactory_ConstructByKey( cf, self->name, 
-                                                             (Dictionary_Entry_Key)"HydrostaticTerm", HydrostaticTerm, False, data ) );
-}
-
-void _DruckerPrager_Build( void* rheology, void* data ) {
-	DruckerPrager*          self               = (DruckerPrager*) rheology;
-
-	/* Build parent */
-	_VonMises_Build( self, data );
-
-	if(self->pressureField) Stg_Component_Build( self->pressureField, data, False );
-	if(self->swarmPressure) Stg_Component_Build( self->swarmPressure, data, False );
-	Stg_Component_Build( self->brightness, data, False );
-	Stg_Component_Build( self->opacity, data, False );
-	Stg_Component_Build( self->diameter, data, False );
-	Stg_Component_Build( self->tensileFailure, data, False );
-
-}
-
-void _DruckerPrager_Destroy( void* rheology, void* data ) {
-	DruckerPrager*          self               = (DruckerPrager*) rheology;
-
-	if(self->pressureField) Stg_Component_Destroy( self->pressureField, data, False );
-	if(self->swarmPressure) Stg_Component_Destroy( self->swarmPressure, data, False );
-	Stg_Component_Destroy( self->brightness, data, False );
-	Stg_Component_Destroy( self->opacity, data, False );
-	Stg_Component_Destroy( self->diameter, data, False );
-	Stg_Component_Destroy( self->tensileFailure, data, False );
-
-	/* Destroy parent */
-	_VonMises_Destroy( self, data );
-
-}
-
-
-void _DruckerPrager_Initialise( void* rheology, void* data ) {
-	DruckerPrager*                  self                  = (DruckerPrager*) rheology;
-	Particle_Index                  lParticle_I;
-	Particle_Index                  particleLocalCount;
-
-	_VonMises_Initialise( self, data );
-
-	/* Initialise variables that I've created - (mainly just SwarmVariables)
-	 * This will run a Variable_Update for us */
-	if(self->pressureField) Stg_Component_Initialise( self->pressureField, data, False );
-	if(self->swarmPressure) Stg_Component_Initialise( self->swarmPressure, data, False );
-
-	/* We should only set initial conditions if in regular non-restart mode. If in restart mode, then
-	the particle-based variables will be set correcty when we re-load the Swarm. */
-	if ( self->context->loadFromCheckPoint == False ) {
-      Stg_Component_Initialise( self->brightness, data, False );
-      Stg_Component_Initialise( self->opacity, data, False );
-      Stg_Component_Initialise( self->diameter, data, False );
-      Stg_Component_Initialise( self->tensileFailure, data, False );
-
-		/* We don't need to Initialise hasYieldedVariable because it's a parent variable and _YieldRheology_Initialise
-		 * has already been called */
-		particleLocalCount = self->hasYieldedVariable->variable->arraySize;
-
-		for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) { 
-		
-			Variable_SetValueFloat( self->brightness->variable, lParticle_I, 0.0 );
-			Variable_SetValueFloat( self->opacity->variable,    lParticle_I, 0.0 );
-			Variable_SetValueFloat( self->diameter->variable,   lParticle_I, 0.0 );
-		
-			Variable_SetValueChar( self->hasYieldedVariable->variable, lParticle_I, False );
-			Variable_SetValueChar( self->tensileFailure->variable,lParticle_I, False );
-		}
-	}	
-}
-
-double _DruckerPrager_GetYieldCriterion( 
-			void*                            druckerPrager,
-			ConstitutiveMatrix*              constitutiveMatrix,
-			MaterialPointsSwarm*             materialPointsSwarm,
-			Element_LocalIndex               lElement_I,
-			MaterialPoint*                   materialPoint,
-			Coord                            xi )
-{
-	DruckerPrager*                    self             = (DruckerPrager*) druckerPrager;
-        Dimension_Index                   dim = constitutiveMatrix->dim;
-	double                            cohesion;
-	double                            cohesionAfterSoftening;
-	double                            frictionCoefficient;
-	double                            frictionCoefficientAfterSoftening;
-	double                            minimumYieldStress;
-	double                            minimumViscosity;
-	double                            maxStrainRate;
-	double                            effectiveCohesion;
-	double                            effectiveFrictionCoefficient;
-	double                            frictionalStrength;
-	double                            pressure;
-	DruckerPrager_Particle*           particleExt;
-        Cell_Index                        cell_I;
-        Coord                             coord;
-        Element_GlobalIndex	          element_gI = 0;
-        unsigned		          inds[3];
-        Grid*			          elGrid;
-        Bool                              inside_boundary;
-        double                            factor;
-	
-	/* Get Parameters From Rheology */
-	cohesion                           = self->cohesion;
-	cohesionAfterSoftening             = self->cohesionAfterSoftening;
-	frictionCoefficient                = self->frictionCoefficient;
-	frictionCoefficientAfterSoftening  = self->frictionCoefficientAfterSoftening;
-	minimumYieldStress                 = self->minimumYieldStress;
-	minimumViscosity                   = self->minimumViscosity;
-	maxStrainRate                      = self->maxStrainRate;
-	
-	particleExt = (DruckerPrager_Particle*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, materialPoint, self->particleExtHandle );
-
-        if( self->pressureField )
-          FeVariable_InterpolateWithinElement( self->pressureField, lElement_I, xi, &pressure );
-        else {
-          SwarmVariable_ValueAt( self->swarmPressure,
-                                 constitutiveMatrix->currentParticleIndex,
-                                 &pressure );
-        }
-
-        cell_I=CellLayout_MapElementIdToCellId(materialPointsSwarm->cellLayout,
-                                               lElement_I );
-        FeMesh_CoordLocalToGlobal(self->pressureField->feMesh, cell_I, xi, coord);
-        if(self->hydrostaticTerm)
-          {
-            pressure+=HydrostaticTerm_Pressure(self->hydrostaticTerm,coord);
-          }
-
-        /* Normally we add the average of the trace of the stress.
-           With compressible material, you have to do it.  But with
-           stabilized linear pressure elements, the non-zero trace is
-           a numerical artifact.  So we do not add it. */
-
-/*   pressure+=self->trace/dim; */
-
-        /* Calculate frictional strength.  We modify the friction and
-           cohesion because we have grouped terms from the normal
-           stresses and moved it to the yield indicator. */
-	
-
-        /* Big song and dance to see if we are at a boundary that we care about */
-        elGrid = *(Grid**)ExtensionManager_Get(self->pressureField->feMesh->info,
-                                               self->pressureField->feMesh,
-                                               ExtensionManager_GetHandle(self->pressureField->feMesh->info, "elementGrid" ) );
-  
-        element_gI = FeMesh_ElementDomainToGlobal( self->pressureField->feMesh, lElement_I );
-        RegularMeshUtils_Element_1DTo3D( self->pressureField->feMesh, element_gI, inds );
-  
-        inside_boundary=
-          ((self->boundaryBottom && inds[1]==0)
-           || (self->boundaryTop && inds[1]==elGrid->sizes[1]-1)
-           || (self->boundaryLeft && inds[0]==0)
-           || (self->boundaryRight && inds[0]==elGrid->sizes[0]-1)
-           || (dim==3 && ((self->boundaryBack && inds[2]==0)
-                          || (self->boundaryFront && inds[2]==elGrid->sizes[2]-1))))
-          ? True : False;
-
-        effectiveFrictionCoefficient =
-          _DruckerPrager_EffectiveFrictionCoefficient( self, materialPoint,
-                                                       inside_boundary );
-        effectiveCohesion = _DruckerPrager_EffectiveCohesion(self,materialPoint,
-                                                             inside_boundary);
-
-  if(dim==2)
-    {
-      /* effectiveFrictionCoefficient=tan(phi).  If
-         factor=sin(atan(1/tan(phi))) =>
-         factor=cos(phi)=1/sqrt(1+tan(phi)**2) */
-      factor=1/sqrt(1 + effectiveFrictionCoefficient*effectiveFrictionCoefficient);
-      frictionalStrength = effectiveFrictionCoefficient*pressure*factor
-        + effectiveCohesion*factor;
-    }
-  else
-    {
-      double cos_phi, sin_phi;
-      /* cos(phi)=1/sqrt(1+tan(phi)**2) */
-      cos_phi=
-        1/sqrt(1 + effectiveFrictionCoefficient*effectiveFrictionCoefficient);
-      sin_phi=effectiveFrictionCoefficient*cos_phi;
-      factor=2*cos_phi/(sqrt(3.0)*(3-sin_phi));
-
-      /* The full expression is
-
-         sqrt(J2)=p*2*sin(phi)/(sqrt(3)*(3-sin(phi)))
-                  + C*6*cos(phi)/(sqrt(3)*(3-sin(phi)))
-
-         Note the extra factor of 3 for cohesion */
-
-      frictionalStrength = effectiveFrictionCoefficient*factor*pressure
-        + effectiveCohesion*3*factor;
-    }
-  
-  /* If the minimumYieldStress is not set, then use the
-     effective cohesion.  Maybe it should be the modified
-     effective cohesion, though that probably should not matter
-     much. */
-  minimumYieldStress = self->minimumYieldStress;
-  if(minimumYieldStress==0.0)
-    minimumYieldStress=effectiveCohesion;
-  
-  /* Make sure frictionalStrength is above the minimum */
-  if ( frictionalStrength < minimumYieldStress*factor) 
-    frictionalStrength = minimumYieldStress*factor;
-
-  self->yieldCriterion = frictionalStrength;
-  self->curFrictionCoef = effectiveFrictionCoefficient*factor;
-
-  return frictionalStrength;
-}
-
-void _DruckerPrager_HasYielded( 
-		void*                            rheology,
-		ConstitutiveMatrix*              constitutiveMatrix,
-		MaterialPointsSwarm*             materialPointsSwarm,
-		Element_LocalIndex               lElement_I,
-		MaterialPoint*                   materialPoint,
-		double                           yieldCriterion,
-		double                           yieldIndicator )
-{
-   DruckerPrager* self = (DruckerPrager*)rheology;
-   double strainRate=self->strainRateSecondInvariant;
-   double old_viscosity = ConstitutiveMatrix_GetIsotropicViscosity( constitutiveMatrix );
-   double viscosity;
-
-   if(self->maxStrainRate>0 && strainRate>self->maxStrainRate)
-     {
-       viscosity=yieldCriterion/(2*self->maxStrainRate);
-     }
-   else
-     {
-       viscosity = yieldCriterion/(2*strainRate);
-     }
-
-   if(viscosity<self->minimumViscosity)
-     viscosity=self->minimumViscosity;
-
-   ConstitutiveMatrix_SetIsotropicViscosity( constitutiveMatrix, viscosity );
-
-   if( constitutiveMatrix->sle && constitutiveMatrix->sle->nlFormJacobian ) {
-      constitutiveMatrix->derivs[8] += old_viscosity * self->curFrictionCoef / yieldIndicator;
-   }
-
-}
-
-double _DruckerPrager_EffectiveCohesion( void* rheology, void* materialPoint,
-                                       Bool inside_boundary ) {
-	DruckerPrager*    self                          = (DruckerPrager*) rheology;
-	double                         effectiveCohesion;
-	
-        double strainWeakeningRatio = StrainWeakening_CalcRatio( self->strainWeakening, materialPoint );
-
-        if(inside_boundary)
-          {
-            effectiveCohesion=self->boundaryCohesion*(1.0-strainWeakeningRatio)+
-              self->boundaryCohesionAfterSoftening*strainWeakeningRatio;
-          }
-        else
-          {
-            effectiveCohesion = self->cohesion * (1.0 - strainWeakeningRatio) + 
-              self->cohesionAfterSoftening * strainWeakeningRatio;
-          }
-
-	return effectiveCohesion;
-}
-
-double _DruckerPrager_EffectiveFrictionCoefficient( void* rheology, void* materialPoint, Bool inside_boundary ) {
-	DruckerPrager*    self                          = (DruckerPrager*) rheology;
-	double                  effectiveFrictionCoefficient  = 0.0;
-
-        double strainWeakeningRatio = StrainWeakening_CalcRatio( self->strainWeakening, materialPoint );
-	
-        if(inside_boundary)
-          {
-            effectiveFrictionCoefficient =
-              self->boundaryFrictionCoefficient * (1.0 - strainWeakeningRatio) +
-              self->boundaryFrictionCoefficientAfterSoftening
-              *strainWeakeningRatio;	
-          }
-        else
-          {
-            effectiveFrictionCoefficient =
-              self->frictionCoefficient * (1.0 - strainWeakeningRatio) +
-              self->frictionCoefficientAfterSoftening * strainWeakeningRatio;	
-          }
-
-	return effectiveFrictionCoefficient;
-}
-
-void _DruckerPrager_UpdateDrawParameters( void* rheology ) {
-	DruckerPrager*                   self               = (DruckerPrager*) rheology;
-	Particle_Index                   lParticle_I;
-	Particle_Index                   particleLocalCount;
-	StrainWeakening*                 strainWeakening    = self->strainWeakening;
-	MaterialPoint*                   materialPoint;
-	
-	double                           length;
-	double                           brightness;
-	double                           opacity;
-	double                           strainWeakeningRatio;
-	double                           localMaxStrainIncrement;
-	double                           localMeanStrainIncrement;
-	Particle_Index                   localFailed;
-	
-	double                           globalMaxStrainIncrement;
-	double                           globalMeanStrainIncrement;
-	Particle_Index                   globalFailed;
-	
-	double                           averagedGlobalMaxStrainIncrement = 0.0;
-
-	double                           oneOverGlobalMaxStrainIncrement;
-	double                           postFailureWeakeningIncrement;
-   int ierr; /* mpi error code */
-
-	/* Note : this function defines some drawing parameters (brightness, opacity, diameter) as
-	 * functions of the strain weakening - this needs to be improved since most of the parameters
-	 * that define this dependency are hard coded here. We need to have a more flexible way
-	 * to construct the viz parameters as functions of material parameters */
-
-	/* We should only update the drawing parameters if the strain weakening is defined */ 
-	if (strainWeakening==NULL)
-		return;
-	
-	localMaxStrainIncrement = 0.0;
-	localMeanStrainIncrement = 0.0;
-	localFailed = 0;
-
-	/* Update all variables */
-	Variable_Update( self->hasYieldedVariable->variable );
-	Variable_Update( self->brightness->variable );
-	Variable_Update( self->opacity->variable );
-	Variable_Update( self->diameter->variable );
-	Variable_Update( strainWeakening->postFailureWeakeningIncrement->variable );
-
-	particleLocalCount = self->hasYieldedVariable->variable->arraySize;
-	
-	for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) { 
-		if ( Variable_GetValueChar( self->hasYieldedVariable->variable, lParticle_I )) {
-			localFailed++;
-
-			postFailureWeakeningIncrement = 
-					Variable_GetValueDouble( strainWeakening->postFailureWeakeningIncrement->variable, lParticle_I );
-			
-			localMeanStrainIncrement += postFailureWeakeningIncrement;
-		
-			if(localMaxStrainIncrement < postFailureWeakeningIncrement)
-				localMaxStrainIncrement = postFailureWeakeningIncrement;
-		}
-	}
-	
-	ierr = MPI_Allreduce( &localMaxStrainIncrement,  &globalMaxStrainIncrement,  1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );
-	ierr = MPI_Allreduce( &localMeanStrainIncrement, &globalMeanStrainIncrement, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
-	ierr = MPI_Allreduce( &localFailed,              &globalFailed,              1, MPI_INT,    MPI_SUM, MPI_COMM_WORLD );
-	
-	if(globalFailed == 0) 
-		return;
-				
-	globalMeanStrainIncrement /= (double) globalFailed;
-	
-	averagedGlobalMaxStrainIncrement = 
-			0.5 * averagedGlobalMaxStrainIncrement + 
-			0.25 * globalMeanStrainIncrement +
-			0.25 * globalMaxStrainIncrement;
-	
-	/* Let's simply assume that twice the mean is a good place to truncate these values */
-	oneOverGlobalMaxStrainIncrement = 1.0 / averagedGlobalMaxStrainIncrement;
-	
-	for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) { 
-		materialPoint = (MaterialPoint*)Swarm_ParticleAt( strainWeakening->swarm, lParticle_I );
-
-		if ( Variable_GetValueChar( self->hasYieldedVariable->variable, lParticle_I ) == False ||
-					StrainWeakening_GetPostFailureWeakening( strainWeakening, materialPoint ) < 0.0 ) 
-		{
-			Variable_SetValueFloat( self->brightness->variable, lParticle_I, 0.0 );
-			Variable_SetValueFloat( self->opacity->variable, lParticle_I, 0.0 );
-			Variable_SetValueFloat( self->diameter->variable, lParticle_I, 0.0 );
-			continue;
-		}  
-
-		postFailureWeakeningIncrement = 
-				Variable_GetValueDouble( strainWeakening->postFailureWeakeningIncrement->variable, lParticle_I );
-			
-		strainWeakeningRatio = StrainWeakening_CalcRatio( strainWeakening, materialPoint );
-		
-		length     = 0.001 + 0.003 * strainWeakeningRatio;
-		brightness = strainWeakeningRatio * postFailureWeakeningIncrement * oneOverGlobalMaxStrainIncrement;
-		
-		opacity = 0.5 * brightness; 
-		
-		if( brightness > 1.0 )
-			brightness = 1.0;
-		
-		if( opacity > 0.5 )
-			opacity = 0.5;
-		
-		if( opacity < 0.1 )
-			opacity = 0.0;
-		
-		Variable_SetValueFloat( self->brightness->variable, lParticle_I, brightness );
-		Variable_SetValueFloat( self->opacity->variable,    lParticle_I, opacity );
-		Variable_SetValueFloat( self->diameter->variable,   lParticle_I, (float) length );
-	}
-	
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/DruckerPrager.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/DruckerPrager.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,678 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: DruckerPrager.c 743 2008-06-23 01:49:43Z JulianGiordani $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "RheologyClass.h"
+#include "StrainWeakening.h"
+#include "YieldRheology.h"
+#include "VonMises.h"
+#include "DruckerPrager.h"
+#include "ConstitutiveMatrix.h"
+
+#include <assert.h>
+#include <string.h>
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type DruckerPrager_Type = "DruckerPrager";
+
+/* Public Constructor */
+DruckerPrager* DruckerPrager_New(
+	Name                  name,
+	StrainWeakening*      strainWeakening, 
+	MaterialPointsSwarm*  materialPointsSwarm, 
+	double                minVisc, 
+	FeVariable*           strainRateField,
+	SwarmVariable*        swarmStrainRate,
+	double                cohesion,
+	double                cohesionAfterSoftening,
+	Bool                  strainRateSoftening,
+	FeVariable*           pressureField,
+	SwarmVariable*        swarmPressure,
+	double                minimumYieldStress,
+	double                minimumViscosity,
+	double                maxStrainRate,
+	double                frictionCoefficient,
+	double                frictionCoefficientAfterSoftening,
+        double                boundaryCohesion,
+        double                boundaryCohesionAfterSoftening,
+        double                boundaryFrictionCoefficient,
+        double                boundaryFrictionCoefficientAfterSoftening,
+        Bool                  boundaryTop,
+        Bool                  boundaryBottom,
+        Bool                  boundaryLeft,
+        Bool                  boundaryRight,
+        Bool                  boundaryFront,
+        Bool                  boundaryBack,
+        HydrostaticTerm*      hydrostaticTerm)
+{
+   DruckerPrager* self = (DruckerPrager*) _DruckerPrager_DefaultNew( name );
+
+   _Rheology_Init( self, (PICelleratorContext*)self->context );
+   _YieldRheology_Init( (YieldRheology*)self, strainWeakening, materialPointsSwarm, minVisc ); 
+   _VonMises_Init( (VonMises*)self, strainRateField, swarmStrainRate, cohesion, cohesionAfterSoftening, strainRateSoftening );
+   _DruckerPrager_Init( self, pressureField, swarmPressure,
+                        materialPointsSwarm,
+                        frictionCoefficient,
+                        frictionCoefficientAfterSoftening,
+                        boundaryCohesion,
+                        boundaryCohesionAfterSoftening,
+                        boundaryFrictionCoefficient,
+                        boundaryFrictionCoefficientAfterSoftening,
+                        boundaryBottom,
+                        boundaryTop,
+                        boundaryLeft,
+                        boundaryRight,
+                        boundaryFront,
+                        boundaryBack,
+                        minimumYieldStress,
+                        minimumViscosity,
+                        maxStrainRate,
+                        hydrostaticTerm );
+   self->isConstructed = True;
+   return self;
+}
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+DruckerPrager* _DruckerPrager_New(  DRUCKERPRAGER_DEFARGS  ) 
+{
+	DruckerPrager*					self;
+
+	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+	assert( _sizeOfSelf >= sizeof(DruckerPrager) );
+	self = (DruckerPrager*) _VonMises_New(  VONMISES_PASSARGS  );
+	
+	/* Function pointers for this class that are not on the parent class should be set here */
+	
+	return self;
+}
+
+void _DruckerPrager_Init(
+		DruckerPrager*                                     self,
+		FeVariable*                                        pressureField,
+		SwarmVariable*                                     swarmPressure,
+		MaterialPointsSwarm*                               materialPointsSwarm,
+		double                                             frictionCoefficient,
+		double                                             frictionCoefficientAfterSoftening,
+                double                    boundaryCohesion,
+                double                    boundaryCohesionAfterSoftening,
+                double                    boundaryFrictionCoefficient,
+                double                    boundaryFrictionCoefficientAfterSoftening,
+                Bool                      boundaryBottom,
+                Bool                      boundaryTop,
+                Bool                      boundaryLeft,
+                Bool                      boundaryRight,
+                Bool                      boundaryFront,
+                Bool                      boundaryBack,
+                double                    minimumYieldStress,
+                double                    minimumViscosity,
+                double                    maxStrainRate,
+                HydrostaticTerm*          hydrostaticTerm )
+{
+	DruckerPrager_Particle*   particleExt;
+	StandardParticle          materialPoint;
+	
+	self->particleExtHandle = ExtensionManager_Add( materialPointsSwarm->particleExtensionMgr, (Name)DruckerPrager_Type, sizeof(DruckerPrager_Particle) );
+		
+	/* Assign Pointers */
+	self->pressureField       = pressureField;
+	self->frictionCoefficient = frictionCoefficient;
+	self->minimumYieldStress  = minimumYieldStress;
+	self->minimumViscosity    = minimumViscosity;
+	self->maxStrainRate       = maxStrainRate;
+	self->swarmPressure       = swarmPressure;
+	
+	/* Strain softening of Cohesion and friction - (linear
+           weakening is assumed) needs a softening factor between +0
+           and 1 and a reference strain > 0 */
+	self->frictionCoefficientAfterSoftening = frictionCoefficientAfterSoftening;
+	self->boundaryCohesion = boundaryCohesion;
+	self->boundaryFrictionCoefficient = boundaryFrictionCoefficient;
+	self->boundaryCohesionAfterSoftening = boundaryCohesionAfterSoftening;
+	self->boundaryFrictionCoefficientAfterSoftening = boundaryFrictionCoefficientAfterSoftening;
+        self->boundaryBottom=boundaryBottom;
+        self->boundaryTop=boundaryTop;
+        self->boundaryLeft=boundaryLeft;
+        self->boundaryRight=boundaryRight;
+        self->boundaryFront=boundaryFront;
+        self->boundaryBack=boundaryBack;
+
+	self->minimumYieldStress = minimumYieldStress;
+	self->minimumViscosity = minimumViscosity;
+	self->maxStrainRate = maxStrainRate;
+        self->hydrostaticTerm=hydrostaticTerm;
+
+	/* Update Drawing Parameters */
+	EP_PrependClassHook( Context_GetEntryPoint( self->context, AbstractContext_EP_DumpClass ),
+								_DruckerPrager_UpdateDrawParameters, self );
+	
+	particleExt = (DruckerPrager_Particle*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, &materialPoint, self->particleExtHandle );
+	
+	/* Setup Variables for Visualisation */
+	self->brightness = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"DruckerPragerBrightness", (ArithPointer) &particleExt->brightness - (ArithPointer) &materialPoint, Variable_DataType_Float  );
+	
+	self->opacity = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"DruckerPragerOpacity", (ArithPointer) &particleExt->opacity - (ArithPointer) &materialPoint, Variable_DataType_Float  );
+	
+	self->diameter = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"DruckerPragerDiameter", (ArithPointer) &particleExt->diameter - (ArithPointer) &materialPoint, Variable_DataType_Float  );
+
+	/* The tensileFailure variable allows to check whether a materialPoint has failed in tensile mode or not */
+	self->tensileFailure = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"DruckerPragerTensileFailure", (ArithPointer) &particleExt->tensileFailure - (ArithPointer) &materialPoint, Variable_DataType_Char );
+
+        self->curFrictionCoef = 0.0;
+}
+
+void* _DruckerPrager_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                     _sizeOfSelf = sizeof(DruckerPrager);
+	Type                                                             type = DruckerPrager_Type;
+	Stg_Class_DeleteFunction*                                     _delete = _YieldRheology_Delete;
+	Stg_Class_PrintFunction*                                       _print = _YieldRheology_Print;
+	Stg_Class_CopyFunction*                                         _copy = _YieldRheology_Copy;
+	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _DruckerPrager_DefaultNew;
+	Stg_Component_ConstructFunction*                           _construct = _DruckerPrager_AssignFromXML;
+	Stg_Component_BuildFunction*                                   _build = _DruckerPrager_Build;
+	Stg_Component_InitialiseFunction*                         _initialise = _DruckerPrager_Initialise;
+	Stg_Component_ExecuteFunction*                               _execute = _YieldRheology_Execute;
+	Stg_Component_DestroyFunction*                               _destroy = _DruckerPrager_Destroy;
+	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _YieldRheology_ModifyConstitutiveMatrix;
+	YieldRheology_GetYieldCriterionFunction*           _getYieldCriterion = _DruckerPrager_GetYieldCriterion;
+	YieldRheology_GetYieldIndicatorFunction*           _getYieldIndicator = _VonMises_GetYieldIndicator;
+	YieldRheology_HasYieldedFunction*                         _hasYielded = _DruckerPrager_HasYielded;
+
+	/* 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*) _DruckerPrager_New(  DRUCKERPRAGER_PASSARGS   );
+}
+
+void _DruckerPrager_AssignFromXML( void* druckerPrager, Stg_ComponentFactory* cf, void* data ){
+	DruckerPrager*          self           = (DruckerPrager*)druckerPrager;
+	FeVariable*             pressureField = NULL;
+	SwarmVariable*          swarmPressure = NULL;
+	MaterialPointsSwarm*    materialPointsSwarm = NULL;
+
+	/* Construct Parent */
+	_VonMises_AssignFromXML( self, cf, data );
+	
+	pressureField      = (FeVariable *) 
+            Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"PressureField", FeVariable, False, data  );
+   swarmPressure = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"swarmPressure", SwarmVariable, False, data );
+   Journal_Firewall( 
+			( pressureField || swarmPressure ), 
+			Journal_Register( Error_Type, (Name)self->type  ), 
+			"\n Error in component type %s, name '%s'.\n Must specify a PressureField OR a swarmPressure, but not both. \n", self->type, self->name ); 
+			
+	materialPointsSwarm     = (MaterialPointsSwarm*)
+			Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"MaterialPointsSwarm", MaterialPointsSwarm, True, data  );
+		
+	_DruckerPrager_Init( self, 
+			pressureField,
+			swarmPressure,
+			materialPointsSwarm, 
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"frictionCoefficient", 0.0 ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"frictionCoefficientAfterSoftening", 0.0 ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"boundaryCohesion", 0.0 ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"boundaryCohesionAfterSoftening", 0.0 ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"boundaryFrictionCoefficient", 0.0 ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"boundaryFrictionCoefficientAfterSoftening", 0.0 ),
+                        Stg_ComponentFactory_GetBool(  cf,  self->name, (Dictionary_Entry_Key)"boundaryBottom", False ),
+                        Stg_ComponentFactory_GetBool(  cf,  self->name, (Dictionary_Entry_Key)"boundaryTop", False ),
+                        Stg_ComponentFactory_GetBool(  cf,  self->name, (Dictionary_Entry_Key)"boundaryLeft", False ),
+                        Stg_ComponentFactory_GetBool(  cf,  self->name, (Dictionary_Entry_Key)"boundaryRight", False ),
+                        Stg_ComponentFactory_GetBool(  cf,  self->name, (Dictionary_Entry_Key)"boundaryFront", False ),
+                        Stg_ComponentFactory_GetBool(  cf,  self->name, (Dictionary_Entry_Key)"boundaryBack", False ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"minimumYieldStress", 0.0 ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"minimumViscosity", 0.0),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"maxStrainRate", 0.0),
+                        Stg_ComponentFactory_ConstructByKey( cf, self->name, 
+                                                             (Dictionary_Entry_Key)"HydrostaticTerm", HydrostaticTerm, False, data ) );
+}
+
+void _DruckerPrager_Build( void* rheology, void* data ) {
+	DruckerPrager*          self               = (DruckerPrager*) rheology;
+
+	/* Build parent */
+	_VonMises_Build( self, data );
+
+	if(self->pressureField) Stg_Component_Build( self->pressureField, data, False );
+	if(self->swarmPressure) Stg_Component_Build( self->swarmPressure, data, False );
+	Stg_Component_Build( self->brightness, data, False );
+	Stg_Component_Build( self->opacity, data, False );
+	Stg_Component_Build( self->diameter, data, False );
+	Stg_Component_Build( self->tensileFailure, data, False );
+
+}
+
+void _DruckerPrager_Destroy( void* rheology, void* data ) {
+	DruckerPrager*          self               = (DruckerPrager*) rheology;
+
+	if(self->pressureField) Stg_Component_Destroy( self->pressureField, data, False );
+	if(self->swarmPressure) Stg_Component_Destroy( self->swarmPressure, data, False );
+	Stg_Component_Destroy( self->brightness, data, False );
+	Stg_Component_Destroy( self->opacity, data, False );
+	Stg_Component_Destroy( self->diameter, data, False );
+	Stg_Component_Destroy( self->tensileFailure, data, False );
+
+	/* Destroy parent */
+	_VonMises_Destroy( self, data );
+
+}
+
+
+void _DruckerPrager_Initialise( void* rheology, void* data ) {
+	DruckerPrager*                  self                  = (DruckerPrager*) rheology;
+	Particle_Index                  lParticle_I;
+	Particle_Index                  particleLocalCount;
+
+	_VonMises_Initialise( self, data );
+
+	/* Initialise variables that I've created - (mainly just SwarmVariables)
+	 * This will run a Variable_Update for us */
+	if(self->pressureField) Stg_Component_Initialise( self->pressureField, data, False );
+	if(self->swarmPressure) Stg_Component_Initialise( self->swarmPressure, data, False );
+
+	/* We should only set initial conditions if in regular non-restart mode. If in restart mode, then
+	the particle-based variables will be set correcty when we re-load the Swarm. */
+	if ( self->context->loadFromCheckPoint == False ) {
+      Stg_Component_Initialise( self->brightness, data, False );
+      Stg_Component_Initialise( self->opacity, data, False );
+      Stg_Component_Initialise( self->diameter, data, False );
+      Stg_Component_Initialise( self->tensileFailure, data, False );
+
+		/* We don't need to Initialise hasYieldedVariable because it's a parent variable and _YieldRheology_Initialise
+		 * has already been called */
+		particleLocalCount = self->hasYieldedVariable->variable->arraySize;
+
+		for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) { 
+		
+			Variable_SetValueFloat( self->brightness->variable, lParticle_I, 0.0 );
+			Variable_SetValueFloat( self->opacity->variable,    lParticle_I, 0.0 );
+			Variable_SetValueFloat( self->diameter->variable,   lParticle_I, 0.0 );
+		
+			Variable_SetValueChar( self->hasYieldedVariable->variable, lParticle_I, False );
+			Variable_SetValueChar( self->tensileFailure->variable,lParticle_I, False );
+		}
+	}	
+}
+
+double _DruckerPrager_GetYieldCriterion( 
+			void*                            druckerPrager,
+			ConstitutiveMatrix*              constitutiveMatrix,
+			MaterialPointsSwarm*             materialPointsSwarm,
+			Element_LocalIndex               lElement_I,
+			MaterialPoint*                   materialPoint,
+			Coord                            xi )
+{
+	DruckerPrager*                    self             = (DruckerPrager*) druckerPrager;
+        Dimension_Index                   dim = constitutiveMatrix->dim;
+	double                            cohesion;
+	double                            cohesionAfterSoftening;
+	double                            frictionCoefficient;
+	double                            frictionCoefficientAfterSoftening;
+	double                            minimumYieldStress;
+	double                            minimumViscosity;
+	double                            maxStrainRate;
+	double                            effectiveCohesion;
+	double                            effectiveFrictionCoefficient;
+	double                            frictionalStrength;
+	double                            pressure;
+	DruckerPrager_Particle*           particleExt;
+        Cell_Index                        cell_I;
+        Coord                             coord;
+        Element_GlobalIndex	          element_gI = 0;
+        unsigned		          inds[3];
+        Grid*			          elGrid;
+        Bool                              inside_boundary;
+        double                            factor;
+	
+	/* Get Parameters From Rheology */
+	cohesion                           = self->cohesion;
+	cohesionAfterSoftening             = self->cohesionAfterSoftening;
+	frictionCoefficient                = self->frictionCoefficient;
+	frictionCoefficientAfterSoftening  = self->frictionCoefficientAfterSoftening;
+	minimumYieldStress                 = self->minimumYieldStress;
+	minimumViscosity                   = self->minimumViscosity;
+	maxStrainRate                      = self->maxStrainRate;
+	
+	particleExt = (DruckerPrager_Particle*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, materialPoint, self->particleExtHandle );
+
+        if( self->pressureField )
+          FeVariable_InterpolateWithinElement( self->pressureField, lElement_I, xi, &pressure );
+        else {
+          SwarmVariable_ValueAt( self->swarmPressure,
+                                 constitutiveMatrix->currentParticleIndex,
+                                 &pressure );
+        }
+
+        cell_I=CellLayout_MapElementIdToCellId(materialPointsSwarm->cellLayout,
+                                               lElement_I );
+        FeMesh_CoordLocalToGlobal(self->pressureField->feMesh, cell_I, xi, coord);
+        if(self->hydrostaticTerm)
+          {
+            pressure+=HydrostaticTerm_Pressure(self->hydrostaticTerm,coord);
+          }
+
+        /* Normally we add the average of the trace of the stress.
+           With compressible material, you have to do it.  But with
+           stabilized linear pressure elements, the non-zero trace is
+           a numerical artifact.  So we do not add it. */
+
+/*   pressure+=self->trace/dim; */
+
+        /* Calculate frictional strength.  We modify the friction and
+           cohesion because we have grouped terms from the normal
+           stresses and moved it to the yield indicator. */
+	
+
+        /* Big song and dance to see if we are at a boundary that we care about */
+        elGrid = *(Grid**)ExtensionManager_Get(self->pressureField->feMesh->info,
+                                               self->pressureField->feMesh,
+                                               ExtensionManager_GetHandle(self->pressureField->feMesh->info, "elementGrid" ) );
+  
+        element_gI = FeMesh_ElementDomainToGlobal( self->pressureField->feMesh, lElement_I );
+        RegularMeshUtils_Element_1DTo3D( self->pressureField->feMesh, element_gI, inds );
+  
+        inside_boundary=
+          ((self->boundaryBottom && inds[1]==0)
+           || (self->boundaryTop && inds[1]==elGrid->sizes[1]-1)
+           || (self->boundaryLeft && inds[0]==0)
+           || (self->boundaryRight && inds[0]==elGrid->sizes[0]-1)
+           || (dim==3 && ((self->boundaryBack && inds[2]==0)
+                          || (self->boundaryFront && inds[2]==elGrid->sizes[2]-1))))
+          ? True : False;
+
+        effectiveFrictionCoefficient =
+          _DruckerPrager_EffectiveFrictionCoefficient( self, materialPoint,
+                                                       inside_boundary );
+        effectiveCohesion = _DruckerPrager_EffectiveCohesion(self,materialPoint,
+                                                             inside_boundary);
+
+  if(dim==2)
+    {
+      /* effectiveFrictionCoefficient=tan(phi).  If
+         factor=sin(atan(1/tan(phi))) =>
+         factor=cos(phi)=1/sqrt(1+tan(phi)**2) */
+      factor=1/sqrt(1 + effectiveFrictionCoefficient*effectiveFrictionCoefficient);
+      frictionalStrength = effectiveFrictionCoefficient*pressure*factor
+        + effectiveCohesion*factor;
+    }
+  else
+    {
+      double cos_phi, sin_phi;
+      /* cos(phi)=1/sqrt(1+tan(phi)**2) */
+      cos_phi=
+        1/sqrt(1 + effectiveFrictionCoefficient*effectiveFrictionCoefficient);
+      sin_phi=effectiveFrictionCoefficient*cos_phi;
+      factor=2*cos_phi/(sqrt(3.0)*(3-sin_phi));
+
+      /* The full expression is
+
+         sqrt(J2)=p*2*sin(phi)/(sqrt(3)*(3-sin(phi)))
+                  + C*6*cos(phi)/(sqrt(3)*(3-sin(phi)))
+
+         Note the extra factor of 3 for cohesion */
+
+      frictionalStrength = effectiveFrictionCoefficient*factor*pressure
+        + effectiveCohesion*3*factor;
+    }
+  
+  /* If the minimumYieldStress is not set, then use the
+     effective cohesion.  Maybe it should be the modified
+     effective cohesion, though that probably should not matter
+     much. */
+  minimumYieldStress = self->minimumYieldStress;
+  if(minimumYieldStress==0.0)
+    minimumYieldStress=effectiveCohesion;
+  
+  /* Make sure frictionalStrength is above the minimum */
+  if ( frictionalStrength < minimumYieldStress*factor) 
+    frictionalStrength = minimumYieldStress*factor;
+
+  self->yieldCriterion = frictionalStrength;
+  self->curFrictionCoef = effectiveFrictionCoefficient*factor;
+
+  return frictionalStrength;
+}
+
+void _DruckerPrager_HasYielded( 
+		void*                            rheology,
+		ConstitutiveMatrix*              constitutiveMatrix,
+		MaterialPointsSwarm*             materialPointsSwarm,
+		Element_LocalIndex               lElement_I,
+		MaterialPoint*                   materialPoint,
+		double                           yieldCriterion,
+		double                           yieldIndicator )
+{
+   DruckerPrager* self = (DruckerPrager*)rheology;
+   double strainRate=self->strainRateSecondInvariant;
+   double old_viscosity = ConstitutiveMatrix_GetIsotropicViscosity( constitutiveMatrix );
+   double viscosity;
+
+   if(self->maxStrainRate>0 && strainRate>self->maxStrainRate)
+     {
+       viscosity=yieldCriterion/(2*self->maxStrainRate);
+     }
+   else
+     {
+       viscosity = yieldCriterion/(2*strainRate);
+     }
+
+   if(viscosity<self->minimumViscosity)
+     viscosity=self->minimumViscosity;
+
+   ConstitutiveMatrix_SetIsotropicViscosity( constitutiveMatrix, viscosity );
+
+   if( constitutiveMatrix->sle && constitutiveMatrix->sle->nlFormJacobian ) {
+      constitutiveMatrix->derivs[8] += old_viscosity * self->curFrictionCoef / yieldIndicator;
+   }
+
+}
+
+double _DruckerPrager_EffectiveCohesion( void* rheology, void* materialPoint,
+                                       Bool inside_boundary ) {
+	DruckerPrager*    self                          = (DruckerPrager*) rheology;
+	double                         effectiveCohesion;
+	
+        double strainWeakeningRatio = StrainWeakening_CalcRatio( self->strainWeakening, materialPoint );
+
+        if(inside_boundary)
+          {
+            effectiveCohesion=self->boundaryCohesion*(1.0-strainWeakeningRatio)+
+              self->boundaryCohesionAfterSoftening*strainWeakeningRatio;
+          }
+        else
+          {
+            effectiveCohesion = self->cohesion * (1.0 - strainWeakeningRatio) + 
+              self->cohesionAfterSoftening * strainWeakeningRatio;
+          }
+
+	return effectiveCohesion;
+}
+
+double _DruckerPrager_EffectiveFrictionCoefficient( void* rheology, void* materialPoint, Bool inside_boundary ) {
+	DruckerPrager*    self                          = (DruckerPrager*) rheology;
+	double                  effectiveFrictionCoefficient  = 0.0;
+
+        double strainWeakeningRatio = StrainWeakening_CalcRatio( self->strainWeakening, materialPoint );
+	
+        if(inside_boundary)
+          {
+            effectiveFrictionCoefficient =
+              self->boundaryFrictionCoefficient * (1.0 - strainWeakeningRatio) +
+              self->boundaryFrictionCoefficientAfterSoftening
+              *strainWeakeningRatio;	
+          }
+        else
+          {
+            effectiveFrictionCoefficient =
+              self->frictionCoefficient * (1.0 - strainWeakeningRatio) +
+              self->frictionCoefficientAfterSoftening * strainWeakeningRatio;	
+          }
+
+	return effectiveFrictionCoefficient;
+}
+
+void _DruckerPrager_UpdateDrawParameters( void* rheology ) {
+	DruckerPrager*                   self               = (DruckerPrager*) rheology;
+	Particle_Index                   lParticle_I;
+	Particle_Index                   particleLocalCount;
+	StrainWeakening*                 strainWeakening    = self->strainWeakening;
+	MaterialPoint*                   materialPoint;
+	
+	double                           length;
+	double                           brightness;
+	double                           opacity;
+	double                           strainWeakeningRatio;
+	double                           localMaxStrainIncrement;
+	double                           localMeanStrainIncrement;
+	Particle_Index                   localFailed;
+	
+	double                           globalMaxStrainIncrement;
+	double                           globalMeanStrainIncrement;
+	Particle_Index                   globalFailed;
+	
+	double                           averagedGlobalMaxStrainIncrement = 0.0;
+
+	double                           oneOverGlobalMaxStrainIncrement;
+	double                           postFailureWeakeningIncrement;
+   int ierr; /* mpi error code */
+
+	/* Note : this function defines some drawing parameters (brightness, opacity, diameter) as
+	 * functions of the strain weakening - this needs to be improved since most of the parameters
+	 * that define this dependency are hard coded here. We need to have a more flexible way
+	 * to construct the viz parameters as functions of material parameters */
+
+	/* We should only update the drawing parameters if the strain weakening is defined */ 
+	if (strainWeakening==NULL)
+		return;
+	
+	localMaxStrainIncrement = 0.0;
+	localMeanStrainIncrement = 0.0;
+	localFailed = 0;
+
+	/* Update all variables */
+	Variable_Update( self->hasYieldedVariable->variable );
+	Variable_Update( self->brightness->variable );
+	Variable_Update( self->opacity->variable );
+	Variable_Update( self->diameter->variable );
+	Variable_Update( strainWeakening->postFailureWeakeningIncrement->variable );
+
+	particleLocalCount = self->hasYieldedVariable->variable->arraySize;
+	
+	for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) { 
+		if ( Variable_GetValueChar( self->hasYieldedVariable->variable, lParticle_I )) {
+			localFailed++;
+
+			postFailureWeakeningIncrement = 
+					Variable_GetValueDouble( strainWeakening->postFailureWeakeningIncrement->variable, lParticle_I );
+			
+			localMeanStrainIncrement += postFailureWeakeningIncrement;
+		
+			if(localMaxStrainIncrement < postFailureWeakeningIncrement)
+				localMaxStrainIncrement = postFailureWeakeningIncrement;
+		}
+	}
+	
+	ierr = MPI_Allreduce( &localMaxStrainIncrement,  &globalMaxStrainIncrement,  1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );
+	ierr = MPI_Allreduce( &localMeanStrainIncrement, &globalMeanStrainIncrement, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
+	ierr = MPI_Allreduce( &localFailed,              &globalFailed,              1, MPI_INT,    MPI_SUM, MPI_COMM_WORLD );
+	
+	if(globalFailed == 0) 
+		return;
+				
+	globalMeanStrainIncrement /= (double) globalFailed;
+	
+	averagedGlobalMaxStrainIncrement = 
+			0.5 * averagedGlobalMaxStrainIncrement + 
+			0.25 * globalMeanStrainIncrement +
+			0.25 * globalMaxStrainIncrement;
+	
+	/* Let's simply assume that twice the mean is a good place to truncate these values */
+	oneOverGlobalMaxStrainIncrement = 1.0 / averagedGlobalMaxStrainIncrement;
+	
+	for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) { 
+		materialPoint = (MaterialPoint*)Swarm_ParticleAt( strainWeakening->swarm, lParticle_I );
+
+		if ( Variable_GetValueChar( self->hasYieldedVariable->variable, lParticle_I ) == False ||
+					StrainWeakening_GetPostFailureWeakening( strainWeakening, materialPoint ) < 0.0 ) 
+		{
+			Variable_SetValueFloat( self->brightness->variable, lParticle_I, 0.0 );
+			Variable_SetValueFloat( self->opacity->variable, lParticle_I, 0.0 );
+			Variable_SetValueFloat( self->diameter->variable, lParticle_I, 0.0 );
+			continue;
+		}  
+
+		postFailureWeakeningIncrement = 
+				Variable_GetValueDouble( strainWeakening->postFailureWeakeningIncrement->variable, lParticle_I );
+			
+		strainWeakeningRatio = StrainWeakening_CalcRatio( strainWeakening, materialPoint );
+		
+		length     = 0.001 + 0.003 * strainWeakeningRatio;
+		brightness = strainWeakeningRatio * postFailureWeakeningIncrement * oneOverGlobalMaxStrainIncrement;
+		
+		opacity = 0.5 * brightness; 
+		
+		if( brightness > 1.0 )
+			brightness = 1.0;
+		
+		if( opacity > 0.5 )
+			opacity = 0.5;
+		
+		if( opacity < 0.1 )
+			opacity = 0.0;
+		
+		Variable_SetValueFloat( self->brightness->variable, lParticle_I, brightness );
+		Variable_SetValueFloat( self->opacity->variable,    lParticle_I, opacity );
+		Variable_SetValueFloat( self->diameter->variable,   lParticle_I, (float) length );
+	}
+	
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/FaultingMoresiMuhlhaus2006.c
--- a/Rheology/src/FaultingMoresiMuhlhaus2006.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1151 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: FaultingMoresiMuhlhaus2006.c 795 2008-08-29 01:57:10Z LukeHodkinson $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <stdlib.h>
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "RheologyClass.h"
-#include "StrainWeakening.h"
-#include "YieldRheology.h"
-#include "FaultingMoresiMuhlhaus2006.h"
-#include "ConstitutiveMatrix.h"
-#include "Director.h"
-
-#include <assert.h>
-#include <string.h>
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type FaultingMoresiMuhlhaus2006_Type = "FaultingMoresiMuhlhaus2006";
-
-/* Public Constructor */
-FaultingMoresiMuhlhaus2006* FaultingMoresiMuhlhaus2006_New(
-      Name                  name,
-      AbstractContext*      context,
-      StrainWeakening*      strainWeakening, 
-      MaterialPointsSwarm*  materialPointsSwarm, 
-      double                minVisc, 
-		FeVariable*           pressureField,
-		FeVariable*           velocityGradientsField,
-		Director*             director,
-		double                cohesion,
-		double                cohesionAfterSoftening,
-		double                frictionCoefficient,
-		double                frictionCoefficientAfterSoftening,
-		double                minimumYieldStress,
-		Bool                  ignoreOldOrientation,
-		Bool                  updateOrientationAtMaxSoftness,
-		Bool                  updateOrientations,
-		Bool                  isotropicCorrection )
-{
-   FaultingMoresiMuhlhaus2006* self = (FaultingMoresiMuhlhaus2006*) _FaultingMoresiMuhlhaus2006_DefaultNew( name );
-
-	/* Make sure that there is strain weakening */
-	Journal_Firewall(
-		strainWeakening != NULL,
-		Journal_Register( Error_Type, (Name)self->type  ),
-		"Error in func '%s' for %s '%s': FaultingMoresiMuhlhaus2006 rheology needs strain weakening.\n", 
-		__func__, self->type, self->name );
-
-   _Rheology_Init( self, (PICelleratorContext*)context );
-   _YieldRheology_Init( (YieldRheology*)self, strainWeakening, materialPointsSwarm, minVisc ); 
-   _FaultingMoresiMuhlhaus2006_Init(
-		 self,
-		 pressureField,
-		 velocityGradientsField,
-		 materialPointsSwarm,
-		 (FiniteElementContext*)context,
-		 director,
-		 cohesion,
-		 cohesionAfterSoftening,
-		 frictionCoefficient,
-		 frictionCoefficientAfterSoftening,
-		 minimumYieldStress,
-		 ignoreOldOrientation,
-		 updateOrientationAtMaxSoftness,
-		 updateOrientations,
-		 isotropicCorrection);
-
-   self->isConstructed = True;
-   return self;
-}
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-FaultingMoresiMuhlhaus2006* _FaultingMoresiMuhlhaus2006_New(  FAULTINGMORESIMUHLHAUS2006_DEFARGS  ) 
-{
-	FaultingMoresiMuhlhaus2006*					self;
-
-	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-	assert( _sizeOfSelf >= sizeof(FaultingMoresiMuhlhaus2006) );
-	self = (FaultingMoresiMuhlhaus2006*) _YieldRheology_New(  YIELDRHEOLOGY_PASSARGS  );
-	
-	/* Function pointers for this class that are not on the parent class should be set here */
-	
-	return self;
-}
-
-void _FaultingMoresiMuhlhaus2006_Init(
-		FaultingMoresiMuhlhaus2006*                        self,
-		FeVariable*                                        pressureField,
-		FeVariable*                                        velocityGradientsField,
-		MaterialPointsSwarm*                               materialPointsSwarm,
-		FiniteElementContext*                              context,
-		Director*                                          director,
-		double                                             cohesion,
-		double                                             cohesionAfterSoftening,
-		double                                             frictionCoefficient,
-		double                                             frictionCoefficientAfterSoftening,
-		double                                             minimumYieldStress,
-		Bool                                               ignoreOldOrientation,
-		Bool                                               updateOrientationAtMaxSoftness,
-		Bool                                               updateOrientations,
-		Bool                                               isotropicCorrection)
-{
-	FaultingMoresiMuhlhaus2006_Particle* particleExt;
-	StandardParticle                    materialPoint;
-	Dimension_Index                     dim   = materialPointsSwarm->dim;
-	
-	self->materialPointsSwarm     = materialPointsSwarm;
-	self->pressureField           = pressureField;
-	self->velocityGradientsField  = velocityGradientsField;
-	
-	self->director                = director;
-	
-	self->particleExtHandle       = ExtensionManager_Add( materialPointsSwarm->particleExtensionMgr, (Name)FaultingMoresiMuhlhaus2006_Type, sizeof(FaultingMoresiMuhlhaus2006_Particle) );	
-	
-	self->cohesion = cohesion;
-	self->frictionCoefficient = frictionCoefficient;
-	
-	/* Strain softening of Cohesion - (linear weakening is assumed) */
-	/* needs a softening factor between +0 and 1 and a reference strain > 0 */
-	self->cohesionAfterSoftening = cohesionAfterSoftening;
-	
-	/* Strain softening of Friction - (linear weakening is assumed ) */
-	/* needs a softening factor between +0 and 1 and a reference strain > 0 */
-	self->frictionCoefficientAfterSoftening = frictionCoefficientAfterSoftening;
-
-	self->minimumYieldStress = minimumYieldStress;
-	
-	/* Should orientation from previous timestep be tested ? */
-	self->ignoreOldOrientation = ignoreOldOrientation;
-	
-	/* Do we want to update the orientation when maximum softness is reached? */
-	self->updateOrientationAtMaxSoftness = updateOrientationAtMaxSoftness;
-
-	/* Update Drawing Parameters */
-	EP_PrependClassHook( Context_GetEntryPoint( context, AbstractContext_EP_DumpClass ),
-			_FaultingMoresiMuhlhaus2006_UpdateDrawParameters, self );
-
-	particleExt = (FaultingMoresiMuhlhaus2006_Particle*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, &materialPoint, self->particleExtHandle );
-
-	/* Add variables for viz purpose */
-
-	self->slipRate = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"SlipRate", (ArithPointer) &particleExt->slipRate - (ArithPointer) &materialPoint, Variable_DataType_Double  );
-
-	/* slip vector gives the orientation of the failure plane */ 
-	self->slip = Swarm_NewVectorVariable( materialPointsSwarm, (Name)"SlipVector", (ArithPointer) &particleExt->slip - (ArithPointer) &materialPoint, 
-			Variable_DataType_Double, 
-			dim, 
-			"SlipVectorX",
-			"SlipVectorY",
-			"SlipVectorZ" );	
-	
-	/* Some visualisation parameters (brightness, opacity, length, thickness) */
-	self->brightness = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"FaultingMoresiMuhlhaus2006Brightness", (ArithPointer) &particleExt->brightness - (ArithPointer) &materialPoint, Variable_DataType_Float  );
-	
-	self->opacity = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"FaultingMoresiMuhlhaus2006Opacity", (ArithPointer) &particleExt->opacity - (ArithPointer) &materialPoint, Variable_DataType_Float  );
-	
-	self->length = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"FaultingMoresiMuhlhaus2006Length", (ArithPointer) &particleExt->length - (ArithPointer) &materialPoint, Variable_DataType_Float  );
-
-	self->thickness = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"FaultingMoresiMuhlhaus2006Thickness", (ArithPointer) &particleExt->thickness - (ArithPointer) &materialPoint, Variable_DataType_Float  );
-	
-	/* The tensileFailure variable allows to check whether a materialPoint has failed in tensile mode or not */
-	self->tensileFailure = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"FaultingMoresiMuhlhaus2006TensileFailure", (ArithPointer) &particleExt->tensileFailure - (ArithPointer) &materialPoint, Variable_DataType_Char  );
-	
-	self->fullySoftened = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"FaultingMoresiMuhlhaus2006FullySoftened", (ArithPointer) &particleExt->fullySoftened - (ArithPointer) &materialPoint, Variable_DataType_Char );
-	
-	self->updateOrientations  = updateOrientations;
-	self->isotropicCorrection = isotropicCorrection;
-	
-}
-
-void* _FaultingMoresiMuhlhaus2006_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                     _sizeOfSelf = sizeof(FaultingMoresiMuhlhaus2006);
-	Type                                                             type = FaultingMoresiMuhlhaus2006_Type;
-	Stg_Class_DeleteFunction*                                     _delete = _YieldRheology_Delete;
-	Stg_Class_PrintFunction*                                       _print = _YieldRheology_Print;
-	Stg_Class_CopyFunction*                                         _copy = _YieldRheology_Copy;
-	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _FaultingMoresiMuhlhaus2006_DefaultNew;
-	Stg_Component_ConstructFunction*                           _construct = _FaultingMoresiMuhlhaus2006_AssignFromXML;
-	Stg_Component_BuildFunction*                                   _build = _FaultingMoresiMuhlhaus2006_Build;
-	Stg_Component_InitialiseFunction*                         _initialise = _FaultingMoresiMuhlhaus2006_Initialise;
-	Stg_Component_ExecuteFunction*                               _execute = _YieldRheology_Execute;
-	Stg_Component_DestroyFunction*                               _destroy = _FaultingMoresiMuhlhaus2006_Destroy;
-	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _FaultingMoresiMuhlhaus2006_ModifyConstitutiveMatrix;
-	YieldRheology_GetYieldCriterionFunction*           _getYieldCriterion = _FaultingMoresiMuhlhaus2006_GetYieldCriterion;
-	YieldRheology_GetYieldIndicatorFunction*           _getYieldIndicator = _FaultingMoresiMuhlhaus2006_GetYieldIndicator;
-	YieldRheology_HasYieldedFunction*                         _hasYielded = _FaultingMoresiMuhlhaus2006_HasYielded;
-
-	/* 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*) _FaultingMoresiMuhlhaus2006_New(  FAULTINGMORESIMUHLHAUS2006_PASSARGS   );
-}
-
-void _FaultingMoresiMuhlhaus2006_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
-	FaultingMoresiMuhlhaus2006*   self           = (FaultingMoresiMuhlhaus2006*)rheology;
-	FeVariable*                   pressureField;
-	MaterialPointsSwarm*          materialPointsSwarm;
-	FeVariable*                   velocityGradientsField;
-	FiniteElementContext*         context;
-	Director*                     director;
-	
-	/* Construct Parent */
-	_YieldRheology_AssignFromXML( self, cf, data );
-
-	/* Make sure that there is strain weakening */
-	Journal_Firewall(
-		self->strainWeakening != NULL,
-		Journal_Register( Error_Type, (Name)self->type  ),
-		"Error in func '%s' for %s '%s': FaultingMoresiMuhlhaus2006 rheology needs strain weakening.\n", 
-		__func__, self->type, self->name );
-	
-	context                = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", FiniteElementContext, True, data  );
-	materialPointsSwarm    = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"MaterialPointsSwarm", MaterialPointsSwarm, True, data  );
-	pressureField          = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"PressureField", FeVariable, True, data  );
-	velocityGradientsField = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"VelocityGradientsField", FeVariable, True, data  );
-	director               =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Director", Director, True, data  );
-	
-	_FaultingMoresiMuhlhaus2006_Init( 
-			self,
-			pressureField,
-			velocityGradientsField,
-			materialPointsSwarm,  
-			context,
-			director,
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"cohesion", 0.0  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"cohesionAfterSoftening", 0.0  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"frictionCoefficient", 0.0  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"frictionCoefficientAfterSoftening", 0.0  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"minimumYieldStress", 0.0  ),
-			Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"ignoreOldOrientation", False  ),
-			Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"updateOrientationAtMaxSoftness", True  ),
-			Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"updateOrientations", True  ),
-         Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"isotropicCorrection", False ) );
-}
-
-void _FaultingMoresiMuhlhaus2006_Build( void* rheology, void* data ) {
-	FaultingMoresiMuhlhaus2006*  self               = (FaultingMoresiMuhlhaus2006*) rheology;
-
-	/* Build parent */
-	_YieldRheology_Build( self, data );
-
-	Stg_Component_Build( self->slipRate, data, False );
-	Stg_Component_Build( self->slip, data, False );
-	Stg_Component_Build( self->brightness, data, False );
-	Stg_Component_Build( self->opacity, data, False );
-	Stg_Component_Build( self->length, data, False );
-	Stg_Component_Build( self->thickness, data, False );
-	Stg_Component_Build( self->tensileFailure, data, False );
-	Stg_Component_Build( self->fullySoftened, data, False );
-}
-
-void _FaultingMoresiMuhlhaus2006_Initialise( void* rheology, void* data ) {
-	FaultingMoresiMuhlhaus2006*     self                  = (FaultingMoresiMuhlhaus2006*) rheology;
-	XYZ                             normal                = { 0.0,1.0,0.0 };
-	XYZ                             slip                  = { 1.0,0.0,0.0 };
-	double*                         ptr;
-	Particle_Index                  lParticle_I;
-	Particle_Index                  particleLocalCount;
-	double                          normalLength2;
-	double                          invNormalLength;
-	double                          initialDamageFraction;
-	double*                         normalDirector;
-	MaterialPoint*                  materialPoint;
-	Index                           dof_I;
-	Dimension_Index                 dim                   = self->materialPointsSwarm->dim;
-
-	_YieldRheology_Initialise( self, data );
-	
-	/* Initialise these components now just in case this function is called before their own _Initialise function */
-	Stg_Component_Initialise( self->materialPointsSwarm, data, False );
-	Stg_Component_Initialise( self->director, data, False );
-	Stg_Component_Initialise( self->strainWeakening, data, False );
-	
-	/* If restarting from checkpoint, don't change the parameters on the particles */
-	if ( self->context->loadFromCheckPoint == False ) {
-
-      /* Initialise variables that I've created - (mainly just SwarmVariables)
-       * This will run a Variable_Update for us */
-      Stg_Component_Initialise( self->slipRate, data, False );
-      Stg_Component_Initialise( self->slip, data, False );
-      Stg_Component_Initialise( self->brightness, data, False );
-      Stg_Component_Initialise( self->opacity, data, False );
-      Stg_Component_Initialise( self->length, data, False );
-      Stg_Component_Initialise( self->thickness, data, False );
-      Stg_Component_Initialise( self->tensileFailure, data, False );
-      Stg_Component_Initialise( self->fullySoftened, data, False );
-   
-      /* We don't need to Initialise hasYieldedVariable because it's a parent variable and _YieldRheology_Initialise
-       * has already been called */
-      particleLocalCount = self->hasYieldedVariable->variable->arraySize;
-      
-		for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) { 
-			Variable_SetValueChar( self->hasYieldedVariable->variable, lParticle_I, False );
-			Variable_SetValueDouble( self->slipRate->variable, lParticle_I, 0.0 );
-			
-			ptr = Variable_GetPtrDouble( self->slip->variable, lParticle_I );
-			
-			materialPoint = (MaterialPoint*)Swarm_ParticleAt( self->materialPointsSwarm, lParticle_I );
-			normalDirector = Director_GetNormalPtr( self->director, materialPoint);
-			initialDamageFraction = StrainWeakening_GetInitialDamageFraction( self->strainWeakening, materialPoint );
-			
-			/*  Is this out of sync with the other damage model ??
-				Surely the orientation should be randomized for all particles where the initial damage is non-zero ??
-				LM  */
-		
-		
-                        if( initialDamageFraction > 0.0 && (rand() < RAND_MAX*initialDamageFraction)) {
-                           normalLength2 = 0.0;
-					
-                           for( dof_I=0; dof_I < dim ; dof_I++) {
-							  if (3==dim && 1==dof_I){ /* Option: horizontal only in 3D case */
-								normal[dof_I] = 0.0;
-								continue;
-							 }
-								
-                              normal[dof_I] = 1.0 - (2.0 * (double)rand())/(double)RAND_MAX;
-                              normalLength2 += normal[dof_I] * normal[dof_I];
-                           }
-
-
-                           invNormalLength = 1.0/sqrt(normalLength2);
-
-                           for( dof_I=0; dof_I < dim ; dof_I++){
-                              normal[dof_I] *= invNormalLength; 
-                           }
-					
-
-                           /*TODO : improve this initialisation (is it really needed ?)
-                             Dear Dr TODO, If you mean "is the slip really needed" then
-                             I think the answer is "no" .... LM 
-                           */
-                           slip[0] = - normal[1];
-                           slip[1] =   normal[0];
-                           slip[2] =   0.0;
-
-                           memcpy( normalDirector, normal, sizeof(Coord) );
-                           memcpy( ptr, slip, sizeof(Coord) );
-			}
-                        else {
-
-                           /* If not using damage fraction, then just calculate the slip
-                              direction from the existing normal. */
-                           slip[0] = - normalDirector[1];
-                           slip[1] =   normalDirector[0];
-                           slip[2] =   0.0;
-                           memcpy( ptr, slip, sizeof(Coord) );
-
-                        }
-			
-			Variable_SetValueDouble( self->slipRate->variable,      lParticle_I, 0.0   );
-			Variable_SetValueFloat(  self->opacity->variable,       lParticle_I, 0.0   );
-			Variable_SetValueFloat(  self->length->variable,        lParticle_I, 0.0   );
-			Variable_SetValueFloat(  self->thickness->variable,     lParticle_I, 0.0   );
-			Variable_SetValueChar(   self->tensileFailure->variable,lParticle_I, False );
-			Variable_SetValueChar(   self->fullySoftened->variable, lParticle_I, False );
-		}
-	}
-}
-
-void _FaultingMoresiMuhlhaus2006_Destroy( void* rheology, void* data ) {
-	FaultingMoresiMuhlhaus2006* self = (FaultingMoresiMuhlhaus2006*) rheology;
-
-	Stg_Component_Destroy( self->materialPointsSwarm, data, False );
-	Stg_Component_Destroy( self->pressureField, data, False );
-	Stg_Component_Destroy( self->velocityGradientsField, data, False );
-	Stg_Component_Destroy( self->director, data, False );
-	Stg_Component_Destroy( self->slipRate, data, False );
-	Stg_Component_Destroy( self->slip, data, False );
-	Stg_Component_Destroy( self->brightness, data, False );
-	Stg_Component_Destroy( self->opacity, data, False );
-	Stg_Component_Destroy( self->length, data, False );
-	Stg_Component_Destroy( self->thickness, data, False );
-	Stg_Component_Destroy( self->tensileFailure, data, False );
-	Stg_Component_Destroy( self->fullySoftened, data, False );
-
-	/* Destroy parent */
-	_YieldRheology_Destroy( self, data );
-
-}
-	
-void _FaultingMoresiMuhlhaus2006_ModifyConstitutiveMatrix( 
-		void*                                              rheology, 
-		ConstitutiveMatrix*                                constitutiveMatrix,
-		MaterialPointsSwarm*                               materialPointsSwarm,
-		Element_LocalIndex                                 lElement_I,
-		MaterialPoint*                                     materialPoint,
-		Coord                                              xi )
-{
-	FaultingMoresiMuhlhaus2006*     self                  = (FaultingMoresiMuhlhaus2006*) rheology;
-	double                          postFailureWeakening;
-	double                          yieldCriterion;
-	double                          yieldIndicator;  /* A materialPoint will yield if yieldCriterion < yieldIndicator */
-
-	/* Don't want to yield on the first ever solve */
-	if ( constitutiveMatrix->previousSolutionExists == False ) {
-		return;
-	}
-
-	/* Calculate and store values of stress, pressure, velocity gradients, eigenvectors so they are only calculated once */
-	_FaultingMoresiMuhlhaus2006_StoreCurrentParameters( self, constitutiveMatrix, materialPointsSwarm, lElement_I, materialPoint, xi );
-
-	postFailureWeakening = StrainWeakening_GetPostFailureWeakening( self->strainWeakening, materialPoint );
-	
-	/* First part : treatment of the existing weakened directions.
-           Note: If we don't want to update orientations at all that means we want to use
-           the existing preset ones, so we'll always go in here. */
-
-	if( !self->updateOrientations || (!self->ignoreOldOrientation && postFailureWeakening > 0.0) ) {
-	
-		/* tryingOldOrientation is a flag used to know where we are. This is necessary because some parts are treated differently
-		 * if we are dealing with old orientation or with pristine material (see for example _FaultingMoresiMuhlhaus2006_GetYieldIndicator) */
-	
-		self->tryingOldOrientation = True;
-
-		if ( _FaultingMoresiMuhlhaus2006_OldOrientationStillSoftening( self, materialPointsSwarm, materialPoint, constitutiveMatrix->dim ) ) {
-			yieldCriterion = _FaultingMoresiMuhlhaus2006_GetYieldCriterion( self, constitutiveMatrix, materialPointsSwarm,
-				lElement_I, materialPoint, xi );
-			yieldIndicator = _FaultingMoresiMuhlhaus2006_GetYieldIndicator( self, constitutiveMatrix, materialPointsSwarm,
-				lElement_I, materialPoint, xi );
-
-			/* Set a bool to TRUE or FLAG depending on whether a materialPoint has failed or not */
-			YieldRheology_SetParticleFlag( self, materialPointsSwarm, materialPoint, (yieldCriterion < yieldIndicator) );
-			
-			if ( yieldCriterion < yieldIndicator ) {
-				StrainWeakening_AssignIncrement( self->strainWeakening, constitutiveMatrix,
-						materialPointsSwarm, lElement_I, materialPoint, yieldCriterion, yieldIndicator );
-				_FaultingMoresiMuhlhaus2006_HasYielded( self, constitutiveMatrix, materialPointsSwarm, lElement_I, materialPoint,
-						yieldCriterion, yieldIndicator );
-				return;
-			}
-		}
-		 
-		/* 
-		     If it falls through to here, old orientation is now hardening  */
-				
-		YieldRheology_SetParticleFlag( self, materialPointsSwarm, materialPoint, 0 );
-		
-	}
-
-	/* Second part : treatment of pristine material with no previously stored direction  */
-	
-	
-	self->tryingOldOrientation = False;
-	
-	/* This calls the standard yielding Constitutive matrix routine defined on the parent BUT
-		the individual calls are to the FMM routines so this should choose the appropriate softening
-		orientation for pristine material */
-	
-	_YieldRheology_ModifyConstitutiveMatrix( self, constitutiveMatrix, materialPointsSwarm, lElement_I, materialPoint, xi );
-}
-
-double _FaultingMoresiMuhlhaus2006_GetYieldIndicator( 
-		void*                                              rheology,
-		ConstitutiveMatrix*                                constitutiveMatrix,
-		MaterialPointsSwarm*                               materialPointsSwarm,
-		Element_LocalIndex                                 lElement_I,
-		MaterialPoint*                                     materialPoint,
-		Coord                                              xi ) 
-{
-	FaultingMoresiMuhlhaus2006*           self             = (FaultingMoresiMuhlhaus2006*) rheology;
-	double*                               stress           = self->currentStress;
-	Eigenvector*                          eigenvectorList  = self->currentEigenvectorList;
-	double                                sigma_ns;
-	Dimension_Index                       dim              = constitutiveMatrix->dim;
-	FaultingMoresiMuhlhaus2006_Particle*  particleExt;
-	double                                stressMin;
-	double                                stressMax;
-	double                                theta;
-	XYZ                                   normal;	
-	
-	Director_GetNormal( self->director, materialPoint, normal );
-	
-	particleExt = (FaultingMoresiMuhlhaus2006_Particle*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, materialPoint, self->particleExtHandle );
-
-	if ( self->tryingOldOrientation ) {
-		sigma_ns = SymmetricTensor_MultiplyByVectors( stress, normal, particleExt->slip, dim );
-	}
-	else {
-		/* Failure criterion from stress field - 
-		 * we can calculate whether the material has failed at the current stress from the principle stresses 
-		 * (without having to compute the orientation) if it does fail, 
-		 * we can then calculate the orientation for the orthotropy model and history */
-		
-		theta = 0.5 * atan( 1.0/ _FaultingMoresiMuhlhaus2006_EffectiveFrictionCoefficient( self, materialPoint ) );
-		
-		stressMin = eigenvectorList[0].eigenvalue;
-		stressMax = (dim == 2 ? eigenvectorList[1].eigenvalue : eigenvectorList[2].eigenvalue);
-		
-		sigma_ns = 0.5 *  sin( 2.0 * theta ) * ( stressMax - stressMin );
-	}
-	
-	return fabs(sigma_ns);
-}
-
-double _FaultingMoresiMuhlhaus2006_GetYieldCriterion( 
-		void*                                              rheology,
-		ConstitutiveMatrix*                                constitutiveMatrix,
-		MaterialPointsSwarm*                               materialPointsSwarm,
-		Element_LocalIndex                                 lElement_I,
-		MaterialPoint*                                     materialPoint,
-		Coord                                              xi )
-{
-	FaultingMoresiMuhlhaus2006*          self             = (FaultingMoresiMuhlhaus2006*) rheology;
-	double                               minimumYieldStress;
-	double                               effectiveCohesion;
-	double                               effectiveFrictionCoefficient;
-	double                               frictionalStrength;
-	double                               sigma_nn;
-	FaultingMoresiMuhlhaus2006_Particle* particleExt;
-		
-	particleExt = (FaultingMoresiMuhlhaus2006_Particle*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, materialPoint, self->particleExtHandle );
-		
-	/* Calculate frictional strength */
-	effectiveFrictionCoefficient = _FaultingMoresiMuhlhaus2006_EffectiveFrictionCoefficient( self, materialPoint );
-	effectiveCohesion            = _FaultingMoresiMuhlhaus2006_EffectiveCohesion( self, materialPoint , particleExt);
-	sigma_nn                     = _FaultingMoresiMuhlhaus2006_Sigma_nn( self, materialPoint, constitutiveMatrix->dim );
-
-	frictionalStrength = effectiveFrictionCoefficient * sigma_nn + effectiveCohesion;
-
-	/* Check if it should break in tension (strictly : frictionalStrength < tensileStrength and not zero) */
-	particleExt->tensileFailure = (frictionalStrength < 0.0);
-	
-	/* Make sure frictionalStrength is above the minimum */
-	minimumYieldStress = self->minimumYieldStress;
-	
-	if ( frictionalStrength < minimumYieldStress) 
-		frictionalStrength = minimumYieldStress;
-	
-	return frictionalStrength;
-}
-
-void _FaultingMoresiMuhlhaus2006_HasYielded( 
-		void*                                              rheology,
-		ConstitutiveMatrix*                                constitutiveMatrix,
-		MaterialPointsSwarm*                               materialPointsSwarm,
-		Element_LocalIndex                                 lElement_I,
-		MaterialPoint*                                     materialPoint,
-		double                                             yieldCriterion,
-		double                                             yieldIndicator )
-{
-	FaultingMoresiMuhlhaus2006*          self             = (FaultingMoresiMuhlhaus2006*) rheology;
-	double                               beta;
-	double*                              normal;
-	double                               viscosity        = ConstitutiveMatrix_GetIsotropicViscosity( constitutiveMatrix );
-	FaultingMoresiMuhlhaus2006_Particle* particleExt;
-        double corr;
-
-	normal = _FaultingMoresiMuhlhaus2006_UpdateNormalDirection( self, materialPointsSwarm, materialPoint, constitutiveMatrix->dim );
-	
-	beta = 1.0 - yieldCriterion / yieldIndicator;
-        corr = -viscosity * beta;
-        if( (viscosity + corr) < self->minVisc )
-           corr = self->minVisc - viscosity;
-
-        if( self->isotropicCorrection )
-           ConstitutiveMatrix_IsotropicCorrection( constitutiveMatrix, corr );
-        else
-           ConstitutiveMatrix_SetSecondViscosity( constitutiveMatrix, -corr, normal );
-
-	particleExt = (FaultingMoresiMuhlhaus2006_Particle*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, materialPoint, self->particleExtHandle );
-	particleExt->slipRate = self->storedSlipRateValue;
-	
-	/* Set a flag to tell the director that particles which have failed don't need to have their normal updated */
-	Director_SetDontUpdateParticleFlag( self->director, materialPoint, True );
-}
-
-Bool _FaultingMoresiMuhlhaus2006_OldOrientationStillSoftening( void* rheology, MaterialPointsSwarm* materialPointsSwarm, void* materialPoint, Dimension_Index dim ) {
-	FaultingMoresiMuhlhaus2006*           self             = (FaultingMoresiMuhlhaus2006*) rheology;
-	double*                               velocityGradient = self->currentVelocityGradient;
-	double*                               stress           = self->currentStress;
-	FaultingMoresiMuhlhaus2006_Particle*  particleExt;
-	double*                               n;
-	double*                               s;
-	double                                tau_nn;
-	double                                traction[3];
-	double                                dVparalleldXperpendicular;
-	double                                dVparalleldXperpendicular1;
-	XYZ                                   normal;
-	
-	Director_GetNormal( self->director, materialPoint, normal );
-
-	particleExt = (FaultingMoresiMuhlhaus2006_Particle*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, materialPoint, self->particleExtHandle );
-	n = normal;
-	s = particleExt->slip;
-	 
-	/* If an existing weakened direction exists we test this direction for further failure
-	 * The slip direction should be set to the direction of maximum shear stress and stored
-	 * for plotting 
-	 * (it does not need to be updated as a history variable like the director ) */
-	
-	if ( dim == 2 ) {
-		traction[0] = stress[0] * n[0] + stress[2] * n[1];
-		traction[1] = stress[2] * n[0] + stress[1] * n[1];
-		
-		tau_nn =  n[0] * traction[0] + n[1] * traction[1];
-				
-		s[0] = traction[0] - tau_nn * n[0];
-		s[1] = traction[1] - tau_nn * n[1];
-	}
-	
-	else {
-		traction[0] = stress[0] * n[0] + stress[3] * n[1] + stress[4] * n[2];
-		traction[1] = stress[3] * n[0] + stress[1] * n[1] + stress[5] * n[2];
-		traction[2] = stress[4] * n[0] + stress[5] * n[1] + stress[2] * n[2];	
-				
-		tau_nn =  n[0] * traction[0] + n[1] * traction[1] + n[2] * traction[2];
-				
-		s[0] = traction[0] - tau_nn * n[0];
-		s[1] = traction[1] - tau_nn * n[1];
-		s[2] = traction[2] - tau_nn * n[2];
-	}
-	
-	StGermain_VectorNormalise( s, dim );
-	
-	/* Store tau_nn so that we can use it in calculating sigma_nn in _FaultingMoresiMuhlhaus2006_Sigma_nn */
-	self->tau_nn = tau_nn;
-
-	/* Softening direction */
-	dVparalleldXperpendicular  = fabs(TensorArray_MultiplyByVectors( velocityGradient, s, n, dim )) ;
-
-	/* Hardening Direction */
-	dVparalleldXperpendicular1 = fabs(TensorArray_MultiplyByVectors( velocityGradient, n, s, dim )) ;  
-
-	/* Store this value on class in case we need to store it on the materialPoint if it fails */
-	self->storedSlipRateValue = dVparalleldXperpendicular;
-
-	/* We should only continue testing this plane if it is also in the 
-	 * softening orientation with respect to the strain-rate gradient rather than hardening */
-
-        /* The above is untrue if we are keeping the same director normals .  */
-	
-	/* LM: No, I don't think this is true ... in this case we keep the orientation unless it hardens as well */
-			
-	return (dVparalleldXperpendicular1 < dVparalleldXperpendicular) ? True : False; // ? True : !self->updateOrientations;
-}
-
-double* _FaultingMoresiMuhlhaus2006_UpdateNormalDirection( void* rheology, MaterialPointsSwarm* materialPointsSwarm, void* materialPoint, Dimension_Index dim ) {
-	FaultingMoresiMuhlhaus2006*          self                   = (FaultingMoresiMuhlhaus2006*) rheology;
-	FaultingMoresiMuhlhaus2006_Particle* particleExt;
-	double*                              velocityGradient       = self->currentVelocityGradient;
-	Eigenvector*                         eigenvectorList        = self->currentEigenvectorList;
-	double                               strainRate_ns[2];
-	XYZ                                  normal[2];
-	XYZ                                  slip[2];
-	double                               theta;
-	int                                  favourablePlane;
-	double*                              normalDirector;
-	double                               tanPhi;
-	
-	normalDirector = Director_GetNormalPtr( self->director, materialPoint);
-	
-	particleExt = (FaultingMoresiMuhlhaus2006_Particle*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, materialPoint, self->particleExtHandle );
-	
-	/* This function is specific for pristine materials -- 
-	 * We don't need to calculate it for failure in old orientations */
-        if ( self->tryingOldOrientation )
-           return normalDirector;
-	
-        /* Only enter the following conditional if we're interested in
-           updating the director's normal directions. */
-        if( self->updateOrientations ) {
-
-           if ((fabs(tanPhi = _FaultingMoresiMuhlhaus2006_EffectiveFrictionCoefficient( self, materialPoint )))<0.000001)
-              theta = M_PI / 4.0;
-           else
-              theta = 0.5 * atan( 1.0/ tanPhi );
-
-           if (dim == 2){ 
-
-              /* Identify potential failure directions */
-              StGermain_RotateCoordinateAxis( slip[0],   eigenvectorList[0].vector, K_AXIS, +theta);
-              StGermain_RotateCoordinateAxis( slip[1],   eigenvectorList[0].vector, K_AXIS, -theta);
-              StGermain_RotateCoordinateAxis( normal[0], eigenvectorList[0].vector, K_AXIS,  0.5*M_PI + theta);
-              StGermain_RotateCoordinateAxis( normal[1], eigenvectorList[0].vector, K_AXIS,  0.5*M_PI - theta);
-           }
-           else {
-
-              /* Identify potential failure directions */
-              StGermain_RotateVector( slip[0],   eigenvectorList[0].vector, eigenvectorList[1].vector, + theta );
-              StGermain_RotateVector( slip[1],   eigenvectorList[0].vector, eigenvectorList[1].vector, - theta );
-              StGermain_RotateVector( normal[0], eigenvectorList[0].vector, eigenvectorList[1].vector,  0.5*M_PI + theta);
-              StGermain_RotateVector( normal[1], eigenvectorList[0].vector, eigenvectorList[1].vector,  0.5*M_PI - theta);
-           }
-
-           /* Resolve shear strain-rate for the potential failure planes */
-           strainRate_ns[0] = fabs(TensorArray_MultiplyByVectors( velocityGradient, slip[0], normal[0], dim ));
-           strainRate_ns[1] = fabs(TensorArray_MultiplyByVectors( velocityGradient, slip[1], normal[1], dim ));
-
-           /* Choose the plane which is oriented favorably for continued slip */
-
-	
-           favourablePlane = (strainRate_ns[0] > strainRate_ns[1] ? 0 : 1);
-
-           memcpy( normalDirector,      normal[favourablePlane], dim * sizeof(double) );
-           memcpy( particleExt->slip,   slip[favourablePlane],   dim * sizeof(double) );
-
-           self->storedSlipRateValue = strainRate_ns[ favourablePlane ];
-
-        }
-
-        /* If we're not interested in changing director normals, just us e existing ones. */
-        else {
-
-           self->storedSlipRateValue = fabs(TensorArray_MultiplyByVectors(
-                                               velocityGradient, particleExt->slip, normalDirector, dim ));
-
-        }
-
-	return normalDirector;
-}
-
-double _FaultingMoresiMuhlhaus2006_EffectiveCohesion( void* rheology, void* materialPoint, void*  particleExtIn ) {
-	FaultingMoresiMuhlhaus2006*          self                          = (FaultingMoresiMuhlhaus2006*) rheology;
-	double                               effectiveCohesion;
-	FaultingMoresiMuhlhaus2006_Particle* particleExt                   = (FaultingMoresiMuhlhaus2006_Particle*) particleExtIn; 
-	
-	if ( self->tryingOldOrientation || self->ignoreOldOrientation ) {
-		/* If this is the old orientation or old orientations are completely ignored
-		 * then the weakening should be considered here   */
-		
-		double strainWeakeningRatio = StrainWeakening_CalcRatio( self->strainWeakening, materialPoint );
-	
-		effectiveCohesion =  self->cohesion * (1.0 - strainWeakeningRatio) + 
-				self->cohesionAfterSoftening * strainWeakeningRatio;
-				
-		/* Flag particle as fully softened if strainWeakeningRatio > 0.99 */ 
-		
-		particleExt->fullySoftened = ( strainWeakeningRatio > 0.99 );
-	}
-	else {
-		/*	If old orientations are tested first and this is an unbroken direction 
-		 *	then consider material as completely pristine */
-		
-		effectiveCohesion =  self->cohesion;
-	}
-
-	return effectiveCohesion;
-}
-
-double _FaultingMoresiMuhlhaus2006_EffectiveFrictionCoefficient( void* rheology, void* materialPoint ) {
-	FaultingMoresiMuhlhaus2006*    self                          = (FaultingMoresiMuhlhaus2006*) rheology;
-	static double                  effectiveFrictionCoefficient  = 0.0;
-	static int                     prevTryingOldOrientationValue = -1;
-	static void*                   prevParticle                  = NULL;
-
-	/* See if we can return cached value */
-	if ( self->tryingOldOrientation == (Bool) prevTryingOldOrientationValue && materialPoint == prevParticle ) 
-		return effectiveFrictionCoefficient;
-	
-	/* This is a different situation to the cached case - therefore recalculate */
-	if ( self->tryingOldOrientation || self->ignoreOldOrientation ) {
-		/* If this is the old orientation or old orientations are ignored
-		 * then the weakening should be considered here   */
-		double strainWeakeningRatio = StrainWeakening_CalcRatio( self->strainWeakening, materialPoint );
-	
-		effectiveFrictionCoefficient = self->frictionCoefficient * (1.0 - strainWeakeningRatio) +
-				self->frictionCoefficientAfterSoftening * strainWeakeningRatio;	
-	}
-	else {
-		/*	If old orientations are given priority and this is an unbroken direction 
-		 *	then consider material as completely pristine */
-		effectiveFrictionCoefficient =  self->frictionCoefficient;		
-	}
-
-	/* Cache values */
-	prevParticle                  = materialPoint;
-	prevTryingOldOrientationValue = self->tryingOldOrientation;
-
-	return effectiveFrictionCoefficient;
-}
-
-double _FaultingMoresiMuhlhaus2006_Sigma_nn( void* rheology, void* materialPoint, Dimension_Index dim ) {
-	FaultingMoresiMuhlhaus2006*      self             = (FaultingMoresiMuhlhaus2006*) rheology;
-	double                           pressure         = self->currentPressure;
-	Eigenvector*                     eigenvectorList  = self->currentEigenvectorList;
-	double                           tau_nn;
-	double                           sigma_nn;
-
-	if ( self->tryingOldOrientation ) {
-		/* tau_nn has already been calculated in _FaultingMoresiMuhlhaus2006_OldOrientationStillSoftening */
-		tau_nn = self->tau_nn;
-	}
-	else {
-		double stressMin = eigenvectorList[0].eigenvalue;
-		double stressMax = (dim == 2 ? eigenvectorList[1].eigenvalue : eigenvectorList[2].eigenvalue);
-		double theta = 0.5 * atan( 1.0/ _FaultingMoresiMuhlhaus2006_EffectiveFrictionCoefficient( self, materialPoint ) );
-
-		tau_nn = 0.5 * (( stressMax + stressMin ) + cos( 2.0 * theta ) * ( stressMax - stressMin ));
-	}
-
-	sigma_nn = pressure - tau_nn;
-
-	return sigma_nn;
-}
-
-void _FaultingMoresiMuhlhaus2006_UpdateNormalAtMaxSoft( void* rheology, void* materialPoint, Dimension_Index dim, SymmetricTensor strainRate, void* particleExtIn ) {
-	XYZ                                  normal[2];
-	XYZ                                  slip[2];
-	double                               theta;
-	double*                              normalDirector;
-	double                               strainRate_ns[2];
-	int                                  favourablePlane;
-	Eigenvector                          eigenvectorListStrain[2];
-	FaultingMoresiMuhlhaus2006*          self               = (FaultingMoresiMuhlhaus2006*) rheology;
-	FaultingMoresiMuhlhaus2006_Particle* particleExt        = (FaultingMoresiMuhlhaus2006_Particle*) particleExtIn;	
-
-	normalDirector = Director_GetNormalPtr( self->director, materialPoint);
-
-    /* If we don't want to update normals, leave as is. */
-        if( !self->updateOrientations )
-           return;
-
-	SymmetricTensor_CalcAllEigenvectors( strainRate, dim, eigenvectorListStrain );
-	theta = M_PI / 4.0;
-
-	if(dim == 2){
-		StGermain_RotateCoordinateAxis(   slip[0],   eigenvectorListStrain[0].vector, K_AXIS, -theta);
-		StGermain_RotateCoordinateAxis(   slip[1],   eigenvectorListStrain[0].vector, K_AXIS, +theta);
-		StGermain_RotateCoordinateAxis( normal[0],   eigenvectorListStrain[0].vector, K_AXIS, +theta);
-		StGermain_RotateCoordinateAxis( normal[1],   eigenvectorListStrain[0].vector, K_AXIS, -theta);
-	}
-	else{
-		StGermain_RotateVector( slip[0],   eigenvectorListStrain[0].vector, eigenvectorListStrain[1].vector, - theta );
-		StGermain_RotateVector( slip[1],   eigenvectorListStrain[0].vector, eigenvectorListStrain[1].vector, + theta );
-		StGermain_RotateVector( normal[0], eigenvectorListStrain[0].vector, eigenvectorListStrain[1].vector, + theta );
-		StGermain_RotateVector( normal[1], eigenvectorListStrain[0].vector, eigenvectorListStrain[1].vector, - theta );
-	}
-	
-	/* Choose the plane which is oriented favorably for continued slip */
-	strainRate_ns[0] = fabs(TensorArray_MultiplyByVectors( self->currentVelocityGradient, slip[0], normal[0], dim ));
-	strainRate_ns[1] = fabs(TensorArray_MultiplyByVectors( self->currentVelocityGradient, slip[1], normal[1], dim ));
-
-	favourablePlane = strainRate_ns[0] > strainRate_ns[1] ? 0 : 1;
-	memcpy( particleExt->slip,   slip[favourablePlane], dim * sizeof(double) );
-	memcpy( normalDirector,    normal[favourablePlane], dim * sizeof(double) );
-}	
-
-void _FaultingMoresiMuhlhaus2006_StoreCurrentParameters( 
-		void*                                              rheology,
-		ConstitutiveMatrix*                                constitutiveMatrix, 
-		MaterialPointsSwarm*                               materialPointsSwarm,
-		Element_LocalIndex                                 lElement_I, 
-		MaterialPoint*                                     materialPoint,
-		Coord                                              xi ) 
-{
-	FaultingMoresiMuhlhaus2006*          self               = (FaultingMoresiMuhlhaus2006*) rheology;
-	SymmetricTensor                      strainRate;
-	Dimension_Index                      dim                = constitutiveMatrix->dim;
-	FaultingMoresiMuhlhaus2006_Particle* particleExt;
-	
-	particleExt = (FaultingMoresiMuhlhaus2006_Particle*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, materialPoint, self->particleExtHandle );
-	particleExt->slipRate = 0.0;
-	
-	FeVariable_InterpolateWithinElement( self->pressureField, lElement_I, xi, &self->currentPressure );	
-	FeVariable_InterpolateWithinElement( self->velocityGradientsField, lElement_I, xi, self->currentVelocityGradient );
-	TensorArray_GetSymmetricPart( self->currentVelocityGradient, dim, strainRate );
-	ConstitutiveMatrix_CalculateStress( constitutiveMatrix, strainRate, self->currentStress );
-	
-	SymmetricTensor_CalcAllEigenvectors( self->currentStress, dim, self->currentEigenvectorList );
-
-	Director_SetDontUpdateParticleFlag( self->director, materialPoint, False );
-	
-	if( self->updateOrientationAtMaxSoftness ){
-		/* if particle is fully softened, and it is the first non-linear iteration of the current timestep,
-		   then update particle direction */		
-		if( particleExt->fullySoftened && (constitutiveMatrix->sleNonLinearIteration_I == 0) )	
-		  _FaultingMoresiMuhlhaus2006_UpdateNormalAtMaxSoft( rheology, materialPoint, dim, strainRate, particleExt ) ;
-	}
-}
-
-void _FaultingMoresiMuhlhaus2006_UpdateDrawParameters( void* rheology ) {
-	
-	FaultingMoresiMuhlhaus2006*      self               = (FaultingMoresiMuhlhaus2006*) rheology;
-	Particle_Index                   lParticle_I;
-	Particle_Index                   particleLocalCount;
-	StrainWeakening*                 strainWeakening    = self->strainWeakening;
-	GlobalParticle*	  				 materialPoint;
-	double                           slipRate;
-	
-	double                           ratio;
-	double                           length;
-	double                           brightness;
-	double                           opacity;
-	double                           strainWeakeningRatio;
-	double                           localMaxStrainIncrement;
-	double                           localMinStrainIncrement;
-	double                           localMaxSlipRate;
-	double                           localMeanStrainIncrement;
-	double                           localMeanSlipRate;
-	Particle_Index                   localFailed;
-	
-	double                           globalMaxSlipRate;
-	double                           globalMaxStrainIncrement;
-	double                           globalMinStrainIncrement;
-	double                           globalMeanStrainIncrement;
-	double                           globalMeanSlipRate;
-	Particle_Index                   globalFailed;
-	
-	double                           averagedGlobalMaxSlipRate = 0.0;
-	double                           averagedGlobalMaxStrainIncrement = 0.0;
-
-	double                           oneOverGlobalMaxSlipRate;
-	double                           oneOverGlobalMaxStrainIncrement;
-	double                           postFailureWeakeningIncrement;
-	
-	
-	
-	/* This parameter is only needed for the alternative commented out set of parameters */ 
-	/* double                           globalMaxStrainWeakeningRatio    = 0.0; */
-
-        /* Note : this function defines some drawing parameters (brightness, opacity, diameter) as
-	 * functions of the strain weakening - this needs to be improved since most of the parameters
-	 * that define this dependency are hard coded here. We need to have a more flexible way
-	 * to construct the viz parameters as functions of material parameters */
-	
-	localMaxStrainIncrement = -1.0e30;
-	localMinStrainIncrement =  1.0e30;
-	localMeanStrainIncrement = 0.0;
-	localMaxSlipRate = 0.0;
-	localMeanSlipRate = 0.0;
-	localFailed = 0;
-
-	/* Update all variables */
-	Variable_Update( self->hasYieldedVariable->variable );
-	Variable_Update( self->slipRate->variable );
-	Variable_Update( self->brightness->variable );
-	Variable_Update( self->opacity->variable );
-	Variable_Update( self->length->variable );
-	Variable_Update( self->thickness->variable );
-	Variable_Update( strainWeakening->postFailureWeakeningIncrement->variable );
-
-	particleLocalCount = self->hasYieldedVariable->variable->arraySize;
-	
-	for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) { 
-		if ( Variable_GetValueChar( self->hasYieldedVariable->variable, lParticle_I )) {
-			localFailed++;
-			slipRate = Variable_GetValueDouble( self->slipRate->variable, lParticle_I );
-
-			postFailureWeakeningIncrement = 
-				Variable_GetValueDouble( strainWeakening->postFailureWeakeningIncrement->variable, lParticle_I );
-			
-			localMeanSlipRate += slipRate; /* Always positive */
-			localMeanStrainIncrement += fabs(postFailureWeakeningIncrement); /* Positive in failure, negative in healing */
-			
-			if(localMaxSlipRate < slipRate)
-				localMaxSlipRate = slipRate;
-		
-			if(localMaxStrainIncrement < postFailureWeakeningIncrement)
-				localMaxStrainIncrement = postFailureWeakeningIncrement;
-				
-			if(localMinStrainIncrement > postFailureWeakeningIncrement)
-				localMinStrainIncrement = postFailureWeakeningIncrement;
-		}
-	}
-	
-	MPI_Allreduce( &localMaxSlipRate,         &globalMaxSlipRate,         1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );
-	MPI_Allreduce( &localMaxStrainIncrement,  &globalMaxStrainIncrement,  1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );
-	MPI_Allreduce( &localMinStrainIncrement,  &globalMinStrainIncrement,  1, MPI_DOUBLE, MPI_MIN, MPI_COMM_WORLD );
-	MPI_Allreduce( &localMeanSlipRate,        &globalMeanSlipRate,        1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
-	MPI_Allreduce( &localMeanStrainIncrement, &globalMeanStrainIncrement, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
-	MPI_Allreduce( &localFailed,              &globalFailed,              1, MPI_INT,    MPI_SUM, MPI_COMM_WORLD );
-	
-	if(localFailed == 0 || globalFailed == 0) 
-		return;
-				
-	globalMeanStrainIncrement /= (double) globalFailed;
-	globalMeanSlipRate /= (double) globalFailed;
-	
-	averagedGlobalMaxStrainIncrement = 
-		0.5 * averagedGlobalMaxStrainIncrement + 
-		0.25 * globalMeanStrainIncrement +
-		0.25 * globalMaxStrainIncrement;
-	averagedGlobalMaxSlipRate = 
-		0.5 * averagedGlobalMaxSlipRate + 
-		0.25 * globalMaxSlipRate +
-		0.25 * globalMeanSlipRate;
-	
-	fprintf(stderr,"globalMeanStrainIncrement = %g\n",globalMeanStrainIncrement);
-	fprintf(stderr,"globalMaxStrainIncrement  = %g\n",globalMaxStrainIncrement);
-	fprintf(stderr,"globalMinStrainIncrement  = %g\n",globalMinStrainIncrement);
-	fprintf(stderr,"averagedGlobalMaxStrainIncrement = %g\n",averagedGlobalMaxStrainIncrement);
-	fprintf(stderr,"globalMeanSlipRate = %g\n",globalMeanSlipRate); 
-	fprintf(stderr,"averagedGlobalMaxSlipRate = %g\n",averagedGlobalMaxSlipRate);
-	
-	fprintf(stderr,"Number of particles failing = %d/%d\n",localFailed,particleLocalCount);
-	
-	
-	
-	/* Let's simply assume that twice the mean is a good place to truncate these values */
-	oneOverGlobalMaxSlipRate = 1.0 / averagedGlobalMaxSlipRate;
-	oneOverGlobalMaxStrainIncrement = 1.0 / averagedGlobalMaxStrainIncrement;
-	
-	for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) { 
-		materialPoint = (GlobalParticle*) Swarm_ParticleAt( strainWeakening->swarm, lParticle_I );
-
-		if ( Variable_GetValueChar( self->hasYieldedVariable->variable, lParticle_I ) == False ||
-				StrainWeakening_GetPostFailureWeakening( strainWeakening, materialPoint ) < 0.0 ) 
-		{
-			Variable_SetValueFloat( self->brightness->variable, lParticle_I, 0.0 );
-			Variable_SetValueFloat( self->opacity->variable, lParticle_I, 0.0 );
-			Variable_SetValueFloat( self->length->variable, lParticle_I, 0.0 );
-			Variable_SetValueFloat( self->thickness->variable, lParticle_I, 0.0 );
-			continue;
-		}  
-		
-		slipRate = Variable_GetValueDouble( self->slipRate->variable, lParticle_I );
-		strainWeakeningRatio = StrainWeakening_CalcRatio( strainWeakening, materialPoint );
-		
-		postFailureWeakeningIncrement = 
-			Variable_GetValueDouble( strainWeakening->postFailureWeakeningIncrement->variable, lParticle_I );
-		
-		
-		/* Distinguish between healing (e.g. dark) and softening (e.g. light) branches 
-		
-			1. The intensity of the colouring should be proportional to strain rate
-			2. Size of square is proportional to total strain
-			3. The opacity is used to mask out the "uninteresting cases"
-		
-		*/
-		
-				length = 0.025 * strainWeakeningRatio;
-				
-				ratio = postFailureWeakeningIncrement / globalMeanStrainIncrement; // healing v. not 
-				if( ratio < -0.0) {  /* Healing - don't bother with the ones which are fading fast */
-					brightness = 0.0;	
-					opacity = 1.0 + ratio;
-					if(opacity < 0.0)
-						opacity = 0.0;
-				}
-				else {  /* Growing  */
-					brightness = slipRate * oneOverGlobalMaxSlipRate;
-					opacity = (ratio < 1.0 ? ratio : 1.0);
-					
-				}
-				
-		/* x = materialPoint->coord[I_AXIS]; */			
-					
-		/*
-		length     = 0.005 + 0.005 * strainWeakeningRatio;
-		length *= 10;
-		brightness = strainWeakeningRatio * slipRate * oneOverGlobalMaxSlipRate;
-		if( brightness > 1.0 )
-			brightness = 1.0;
-		opacity    = 0.1 + 0.05 * pow(brightness,3.0); 
-		*/
-
-
-
-
-		Variable_SetValueFloat( self->brightness->variable, lParticle_I, brightness );
-		Variable_SetValueFloat( self->opacity->variable,    lParticle_I, opacity );
-		Variable_SetValueFloat( self->length->variable,     lParticle_I, (float) length );
-		Variable_SetValueFloat( self->thickness->variable,  lParticle_I,  0.5 + 10.0 * (float)length );
-	
-		
-	
-	/* This parameter is only needed for the alternative commented out set of parameters */ 
-	/*	if (strainWeakeningRatio>globalMaxStrainWeakeningRatio)
-			globalMaxStrainWeakeningRatio = strainWeakeningRatio;
-	*/
-	}
-	
-	/* This part is another set of parameters that has been used with shear problems.
-	 * it's kept here for now, but it shows that in principle we could define as many set of parameters
-	 * as we want (depending on the problem ?)*/
-	/*
-	for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) { 
-		materialPoint = Swarm_ParticleAt( strainWeakening->materialPointsSwarm, lParticle_I );
-
-		if ( Variable_GetValueChar( self->hasYieldedVariable->variable, lParticle_I ) == False ||
-				StrainWeakening_GetPostFailureWeakening( strainWeakening, materialPoint ) < 0.0 ) 
-		{
-			Variable_SetValueFloat( self->brightness->variable, lParticle_I, 0.0 );
-			Variable_SetValueFloat( self->opacity->variable, lParticle_I, 0.0 );
-			Variable_SetValueFloat( self->length->variable, lParticle_I, 0.0 );
-			Variable_SetValueFloat( self->thickness->variable, lParticle_I, 0.0 );
-			continue;
-		}  
-		
-		slipRate = Variable_GetValueDouble( self->slipRate->variable, lParticle_I );
-		strainWeakeningRatio = StrainWeakening_CalcRatio( strainWeakening, materialPoint );
-		
-		length     = 0.03 + 0.03 * (strainWeakeningRatio/globalMaxStrainWeakeningRatio);
-
-		brightness = 1.0-(strainWeakeningRatio/globalMaxStrainWeakeningRatio);
-		
-		if (brightness > 1.0)
-			brightness = 1.0;
-			
-		opacity    = (slipRate/globalMaxSlipRate);
-		
-		if (opacity > 0.90)
-			opacity = 1.0;/* this condition is to make sure we have enough planes that will be clearly seen. */ /*
-
-		Variable_SetValueFloat( self->brightness->variable, lParticle_I, brightness );
-		Variable_SetValueFloat( self->opacity->variable,    lParticle_I, opacity );
-		Variable_SetValueFloat( self->length->variable,     lParticle_I, (float) length );
-		Variable_SetValueFloat( self->thickness->variable,  lParticle_I,  0.5 + 10.0 * (float)length );
-	}
-	*/
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/FaultingMoresiMuhlhaus2006.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/FaultingMoresiMuhlhaus2006.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,1151 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: FaultingMoresiMuhlhaus2006.c 795 2008-08-29 01:57:10Z LukeHodkinson $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <stdlib.h>
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "RheologyClass.h"
+#include "StrainWeakening.h"
+#include "YieldRheology.h"
+#include "FaultingMoresiMuhlhaus2006.h"
+#include "ConstitutiveMatrix.h"
+#include "Director.h"
+
+#include <assert.h>
+#include <string.h>
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type FaultingMoresiMuhlhaus2006_Type = "FaultingMoresiMuhlhaus2006";
+
+/* Public Constructor */
+FaultingMoresiMuhlhaus2006* FaultingMoresiMuhlhaus2006_New(
+      Name                  name,
+      AbstractContext*      context,
+      StrainWeakening*      strainWeakening, 
+      MaterialPointsSwarm*  materialPointsSwarm, 
+      double                minVisc, 
+		FeVariable*           pressureField,
+		FeVariable*           velocityGradientsField,
+		Director*             director,
+		double                cohesion,
+		double                cohesionAfterSoftening,
+		double                frictionCoefficient,
+		double                frictionCoefficientAfterSoftening,
+		double                minimumYieldStress,
+		Bool                  ignoreOldOrientation,
+		Bool                  updateOrientationAtMaxSoftness,
+		Bool                  updateOrientations,
+		Bool                  isotropicCorrection )
+{
+   FaultingMoresiMuhlhaus2006* self = (FaultingMoresiMuhlhaus2006*) _FaultingMoresiMuhlhaus2006_DefaultNew( name );
+
+	/* Make sure that there is strain weakening */
+	Journal_Firewall(
+		strainWeakening != NULL,
+		Journal_Register( Error_Type, (Name)self->type  ),
+		"Error in func '%s' for %s '%s': FaultingMoresiMuhlhaus2006 rheology needs strain weakening.\n", 
+		__func__, self->type, self->name );
+
+   _Rheology_Init( self, (PICelleratorContext*)context );
+   _YieldRheology_Init( (YieldRheology*)self, strainWeakening, materialPointsSwarm, minVisc ); 
+   _FaultingMoresiMuhlhaus2006_Init(
+		 self,
+		 pressureField,
+		 velocityGradientsField,
+		 materialPointsSwarm,
+		 (FiniteElementContext*)context,
+		 director,
+		 cohesion,
+		 cohesionAfterSoftening,
+		 frictionCoefficient,
+		 frictionCoefficientAfterSoftening,
+		 minimumYieldStress,
+		 ignoreOldOrientation,
+		 updateOrientationAtMaxSoftness,
+		 updateOrientations,
+		 isotropicCorrection);
+
+   self->isConstructed = True;
+   return self;
+}
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+FaultingMoresiMuhlhaus2006* _FaultingMoresiMuhlhaus2006_New(  FAULTINGMORESIMUHLHAUS2006_DEFARGS  ) 
+{
+	FaultingMoresiMuhlhaus2006*					self;
+
+	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+	assert( _sizeOfSelf >= sizeof(FaultingMoresiMuhlhaus2006) );
+	self = (FaultingMoresiMuhlhaus2006*) _YieldRheology_New(  YIELDRHEOLOGY_PASSARGS  );
+	
+	/* Function pointers for this class that are not on the parent class should be set here */
+	
+	return self;
+}
+
+void _FaultingMoresiMuhlhaus2006_Init(
+		FaultingMoresiMuhlhaus2006*                        self,
+		FeVariable*                                        pressureField,
+		FeVariable*                                        velocityGradientsField,
+		MaterialPointsSwarm*                               materialPointsSwarm,
+		FiniteElementContext*                              context,
+		Director*                                          director,
+		double                                             cohesion,
+		double                                             cohesionAfterSoftening,
+		double                                             frictionCoefficient,
+		double                                             frictionCoefficientAfterSoftening,
+		double                                             minimumYieldStress,
+		Bool                                               ignoreOldOrientation,
+		Bool                                               updateOrientationAtMaxSoftness,
+		Bool                                               updateOrientations,
+		Bool                                               isotropicCorrection)
+{
+	FaultingMoresiMuhlhaus2006_Particle* particleExt;
+	StandardParticle                    materialPoint;
+	Dimension_Index                     dim   = materialPointsSwarm->dim;
+	
+	self->materialPointsSwarm     = materialPointsSwarm;
+	self->pressureField           = pressureField;
+	self->velocityGradientsField  = velocityGradientsField;
+	
+	self->director                = director;
+	
+	self->particleExtHandle       = ExtensionManager_Add( materialPointsSwarm->particleExtensionMgr, (Name)FaultingMoresiMuhlhaus2006_Type, sizeof(FaultingMoresiMuhlhaus2006_Particle) );	
+	
+	self->cohesion = cohesion;
+	self->frictionCoefficient = frictionCoefficient;
+	
+	/* Strain softening of Cohesion - (linear weakening is assumed) */
+	/* needs a softening factor between +0 and 1 and a reference strain > 0 */
+	self->cohesionAfterSoftening = cohesionAfterSoftening;
+	
+	/* Strain softening of Friction - (linear weakening is assumed ) */
+	/* needs a softening factor between +0 and 1 and a reference strain > 0 */
+	self->frictionCoefficientAfterSoftening = frictionCoefficientAfterSoftening;
+
+	self->minimumYieldStress = minimumYieldStress;
+	
+	/* Should orientation from previous timestep be tested ? */
+	self->ignoreOldOrientation = ignoreOldOrientation;
+	
+	/* Do we want to update the orientation when maximum softness is reached? */
+	self->updateOrientationAtMaxSoftness = updateOrientationAtMaxSoftness;
+
+	/* Update Drawing Parameters */
+	EP_PrependClassHook( Context_GetEntryPoint( context, AbstractContext_EP_DumpClass ),
+			_FaultingMoresiMuhlhaus2006_UpdateDrawParameters, self );
+
+	particleExt = (FaultingMoresiMuhlhaus2006_Particle*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, &materialPoint, self->particleExtHandle );
+
+	/* Add variables for viz purpose */
+
+	self->slipRate = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"SlipRate", (ArithPointer) &particleExt->slipRate - (ArithPointer) &materialPoint, Variable_DataType_Double  );
+
+	/* slip vector gives the orientation of the failure plane */ 
+	self->slip = Swarm_NewVectorVariable( materialPointsSwarm, (Name)"SlipVector", (ArithPointer) &particleExt->slip - (ArithPointer) &materialPoint, 
+			Variable_DataType_Double, 
+			dim, 
+			"SlipVectorX",
+			"SlipVectorY",
+			"SlipVectorZ" );	
+	
+	/* Some visualisation parameters (brightness, opacity, length, thickness) */
+	self->brightness = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"FaultingMoresiMuhlhaus2006Brightness", (ArithPointer) &particleExt->brightness - (ArithPointer) &materialPoint, Variable_DataType_Float  );
+	
+	self->opacity = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"FaultingMoresiMuhlhaus2006Opacity", (ArithPointer) &particleExt->opacity - (ArithPointer) &materialPoint, Variable_DataType_Float  );
+	
+	self->length = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"FaultingMoresiMuhlhaus2006Length", (ArithPointer) &particleExt->length - (ArithPointer) &materialPoint, Variable_DataType_Float  );
+
+	self->thickness = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"FaultingMoresiMuhlhaus2006Thickness", (ArithPointer) &particleExt->thickness - (ArithPointer) &materialPoint, Variable_DataType_Float  );
+	
+	/* The tensileFailure variable allows to check whether a materialPoint has failed in tensile mode or not */
+	self->tensileFailure = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"FaultingMoresiMuhlhaus2006TensileFailure", (ArithPointer) &particleExt->tensileFailure - (ArithPointer) &materialPoint, Variable_DataType_Char  );
+	
+	self->fullySoftened = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"FaultingMoresiMuhlhaus2006FullySoftened", (ArithPointer) &particleExt->fullySoftened - (ArithPointer) &materialPoint, Variable_DataType_Char );
+	
+	self->updateOrientations  = updateOrientations;
+	self->isotropicCorrection = isotropicCorrection;
+	
+}
+
+void* _FaultingMoresiMuhlhaus2006_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                     _sizeOfSelf = sizeof(FaultingMoresiMuhlhaus2006);
+	Type                                                             type = FaultingMoresiMuhlhaus2006_Type;
+	Stg_Class_DeleteFunction*                                     _delete = _YieldRheology_Delete;
+	Stg_Class_PrintFunction*                                       _print = _YieldRheology_Print;
+	Stg_Class_CopyFunction*                                         _copy = _YieldRheology_Copy;
+	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _FaultingMoresiMuhlhaus2006_DefaultNew;
+	Stg_Component_ConstructFunction*                           _construct = _FaultingMoresiMuhlhaus2006_AssignFromXML;
+	Stg_Component_BuildFunction*                                   _build = _FaultingMoresiMuhlhaus2006_Build;
+	Stg_Component_InitialiseFunction*                         _initialise = _FaultingMoresiMuhlhaus2006_Initialise;
+	Stg_Component_ExecuteFunction*                               _execute = _YieldRheology_Execute;
+	Stg_Component_DestroyFunction*                               _destroy = _FaultingMoresiMuhlhaus2006_Destroy;
+	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _FaultingMoresiMuhlhaus2006_ModifyConstitutiveMatrix;
+	YieldRheology_GetYieldCriterionFunction*           _getYieldCriterion = _FaultingMoresiMuhlhaus2006_GetYieldCriterion;
+	YieldRheology_GetYieldIndicatorFunction*           _getYieldIndicator = _FaultingMoresiMuhlhaus2006_GetYieldIndicator;
+	YieldRheology_HasYieldedFunction*                         _hasYielded = _FaultingMoresiMuhlhaus2006_HasYielded;
+
+	/* 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*) _FaultingMoresiMuhlhaus2006_New(  FAULTINGMORESIMUHLHAUS2006_PASSARGS   );
+}
+
+void _FaultingMoresiMuhlhaus2006_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
+	FaultingMoresiMuhlhaus2006*   self           = (FaultingMoresiMuhlhaus2006*)rheology;
+	FeVariable*                   pressureField;
+	MaterialPointsSwarm*          materialPointsSwarm;
+	FeVariable*                   velocityGradientsField;
+	FiniteElementContext*         context;
+	Director*                     director;
+	
+	/* Construct Parent */
+	_YieldRheology_AssignFromXML( self, cf, data );
+
+	/* Make sure that there is strain weakening */
+	Journal_Firewall(
+		self->strainWeakening != NULL,
+		Journal_Register( Error_Type, (Name)self->type  ),
+		"Error in func '%s' for %s '%s': FaultingMoresiMuhlhaus2006 rheology needs strain weakening.\n", 
+		__func__, self->type, self->name );
+	
+	context                = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", FiniteElementContext, True, data  );
+	materialPointsSwarm    = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"MaterialPointsSwarm", MaterialPointsSwarm, True, data  );
+	pressureField          = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"PressureField", FeVariable, True, data  );
+	velocityGradientsField = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"VelocityGradientsField", FeVariable, True, data  );
+	director               =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Director", Director, True, data  );
+	
+	_FaultingMoresiMuhlhaus2006_Init( 
+			self,
+			pressureField,
+			velocityGradientsField,
+			materialPointsSwarm,  
+			context,
+			director,
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"cohesion", 0.0  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"cohesionAfterSoftening", 0.0  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"frictionCoefficient", 0.0  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"frictionCoefficientAfterSoftening", 0.0  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"minimumYieldStress", 0.0  ),
+			Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"ignoreOldOrientation", False  ),
+			Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"updateOrientationAtMaxSoftness", True  ),
+			Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"updateOrientations", True  ),
+         Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"isotropicCorrection", False ) );
+}
+
+void _FaultingMoresiMuhlhaus2006_Build( void* rheology, void* data ) {
+	FaultingMoresiMuhlhaus2006*  self               = (FaultingMoresiMuhlhaus2006*) rheology;
+
+	/* Build parent */
+	_YieldRheology_Build( self, data );
+
+	Stg_Component_Build( self->slipRate, data, False );
+	Stg_Component_Build( self->slip, data, False );
+	Stg_Component_Build( self->brightness, data, False );
+	Stg_Component_Build( self->opacity, data, False );
+	Stg_Component_Build( self->length, data, False );
+	Stg_Component_Build( self->thickness, data, False );
+	Stg_Component_Build( self->tensileFailure, data, False );
+	Stg_Component_Build( self->fullySoftened, data, False );
+}
+
+void _FaultingMoresiMuhlhaus2006_Initialise( void* rheology, void* data ) {
+	FaultingMoresiMuhlhaus2006*     self                  = (FaultingMoresiMuhlhaus2006*) rheology;
+	XYZ                             normal                = { 0.0,1.0,0.0 };
+	XYZ                             slip                  = { 1.0,0.0,0.0 };
+	double*                         ptr;
+	Particle_Index                  lParticle_I;
+	Particle_Index                  particleLocalCount;
+	double                          normalLength2;
+	double                          invNormalLength;
+	double                          initialDamageFraction;
+	double*                         normalDirector;
+	MaterialPoint*                  materialPoint;
+	Index                           dof_I;
+	Dimension_Index                 dim                   = self->materialPointsSwarm->dim;
+
+	_YieldRheology_Initialise( self, data );
+	
+	/* Initialise these components now just in case this function is called before their own _Initialise function */
+	Stg_Component_Initialise( self->materialPointsSwarm, data, False );
+	Stg_Component_Initialise( self->director, data, False );
+	Stg_Component_Initialise( self->strainWeakening, data, False );
+	
+	/* If restarting from checkpoint, don't change the parameters on the particles */
+	if ( self->context->loadFromCheckPoint == False ) {
+
+      /* Initialise variables that I've created - (mainly just SwarmVariables)
+       * This will run a Variable_Update for us */
+      Stg_Component_Initialise( self->slipRate, data, False );
+      Stg_Component_Initialise( self->slip, data, False );
+      Stg_Component_Initialise( self->brightness, data, False );
+      Stg_Component_Initialise( self->opacity, data, False );
+      Stg_Component_Initialise( self->length, data, False );
+      Stg_Component_Initialise( self->thickness, data, False );
+      Stg_Component_Initialise( self->tensileFailure, data, False );
+      Stg_Component_Initialise( self->fullySoftened, data, False );
+   
+      /* We don't need to Initialise hasYieldedVariable because it's a parent variable and _YieldRheology_Initialise
+       * has already been called */
+      particleLocalCount = self->hasYieldedVariable->variable->arraySize;
+      
+		for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) { 
+			Variable_SetValueChar( self->hasYieldedVariable->variable, lParticle_I, False );
+			Variable_SetValueDouble( self->slipRate->variable, lParticle_I, 0.0 );
+			
+			ptr = Variable_GetPtrDouble( self->slip->variable, lParticle_I );
+			
+			materialPoint = (MaterialPoint*)Swarm_ParticleAt( self->materialPointsSwarm, lParticle_I );
+			normalDirector = Director_GetNormalPtr( self->director, materialPoint);
+			initialDamageFraction = StrainWeakening_GetInitialDamageFraction( self->strainWeakening, materialPoint );
+			
+			/*  Is this out of sync with the other damage model ??
+				Surely the orientation should be randomized for all particles where the initial damage is non-zero ??
+				LM  */
+		
+		
+                        if( initialDamageFraction > 0.0 && (rand() < RAND_MAX*initialDamageFraction)) {
+                           normalLength2 = 0.0;
+					
+                           for( dof_I=0; dof_I < dim ; dof_I++) {
+							  if (3==dim && 1==dof_I){ /* Option: horizontal only in 3D case */
+								normal[dof_I] = 0.0;
+								continue;
+							 }
+								
+                              normal[dof_I] = 1.0 - (2.0 * (double)rand())/(double)RAND_MAX;
+                              normalLength2 += normal[dof_I] * normal[dof_I];
+                           }
+
+
+                           invNormalLength = 1.0/sqrt(normalLength2);
+
+                           for( dof_I=0; dof_I < dim ; dof_I++){
+                              normal[dof_I] *= invNormalLength; 
+                           }
+					
+
+                           /*TODO : improve this initialisation (is it really needed ?)
+                             Dear Dr TODO, If you mean "is the slip really needed" then
+                             I think the answer is "no" .... LM 
+                           */
+                           slip[0] = - normal[1];
+                           slip[1] =   normal[0];
+                           slip[2] =   0.0;
+
+                           memcpy( normalDirector, normal, sizeof(Coord) );
+                           memcpy( ptr, slip, sizeof(Coord) );
+			}
+                        else {
+
+                           /* If not using damage fraction, then just calculate the slip
+                              direction from the existing normal. */
+                           slip[0] = - normalDirector[1];
+                           slip[1] =   normalDirector[0];
+                           slip[2] =   0.0;
+                           memcpy( ptr, slip, sizeof(Coord) );
+
+                        }
+			
+			Variable_SetValueDouble( self->slipRate->variable,      lParticle_I, 0.0   );
+			Variable_SetValueFloat(  self->opacity->variable,       lParticle_I, 0.0   );
+			Variable_SetValueFloat(  self->length->variable,        lParticle_I, 0.0   );
+			Variable_SetValueFloat(  self->thickness->variable,     lParticle_I, 0.0   );
+			Variable_SetValueChar(   self->tensileFailure->variable,lParticle_I, False );
+			Variable_SetValueChar(   self->fullySoftened->variable, lParticle_I, False );
+		}
+	}
+}
+
+void _FaultingMoresiMuhlhaus2006_Destroy( void* rheology, void* data ) {
+	FaultingMoresiMuhlhaus2006* self = (FaultingMoresiMuhlhaus2006*) rheology;
+
+	Stg_Component_Destroy( self->materialPointsSwarm, data, False );
+	Stg_Component_Destroy( self->pressureField, data, False );
+	Stg_Component_Destroy( self->velocityGradientsField, data, False );
+	Stg_Component_Destroy( self->director, data, False );
+	Stg_Component_Destroy( self->slipRate, data, False );
+	Stg_Component_Destroy( self->slip, data, False );
+	Stg_Component_Destroy( self->brightness, data, False );
+	Stg_Component_Destroy( self->opacity, data, False );
+	Stg_Component_Destroy( self->length, data, False );
+	Stg_Component_Destroy( self->thickness, data, False );
+	Stg_Component_Destroy( self->tensileFailure, data, False );
+	Stg_Component_Destroy( self->fullySoftened, data, False );
+
+	/* Destroy parent */
+	_YieldRheology_Destroy( self, data );
+
+}
+	
+void _FaultingMoresiMuhlhaus2006_ModifyConstitutiveMatrix( 
+		void*                                              rheology, 
+		ConstitutiveMatrix*                                constitutiveMatrix,
+		MaterialPointsSwarm*                               materialPointsSwarm,
+		Element_LocalIndex                                 lElement_I,
+		MaterialPoint*                                     materialPoint,
+		Coord                                              xi )
+{
+	FaultingMoresiMuhlhaus2006*     self                  = (FaultingMoresiMuhlhaus2006*) rheology;
+	double                          postFailureWeakening;
+	double                          yieldCriterion;
+	double                          yieldIndicator;  /* A materialPoint will yield if yieldCriterion < yieldIndicator */
+
+	/* Don't want to yield on the first ever solve */
+	if ( constitutiveMatrix->previousSolutionExists == False ) {
+		return;
+	}
+
+	/* Calculate and store values of stress, pressure, velocity gradients, eigenvectors so they are only calculated once */
+	_FaultingMoresiMuhlhaus2006_StoreCurrentParameters( self, constitutiveMatrix, materialPointsSwarm, lElement_I, materialPoint, xi );
+
+	postFailureWeakening = StrainWeakening_GetPostFailureWeakening( self->strainWeakening, materialPoint );
+	
+	/* First part : treatment of the existing weakened directions.
+           Note: If we don't want to update orientations at all that means we want to use
+           the existing preset ones, so we'll always go in here. */
+
+	if( !self->updateOrientations || (!self->ignoreOldOrientation && postFailureWeakening > 0.0) ) {
+	
+		/* tryingOldOrientation is a flag used to know where we are. This is necessary because some parts are treated differently
+		 * if we are dealing with old orientation or with pristine material (see for example _FaultingMoresiMuhlhaus2006_GetYieldIndicator) */
+	
+		self->tryingOldOrientation = True;
+
+		if ( _FaultingMoresiMuhlhaus2006_OldOrientationStillSoftening( self, materialPointsSwarm, materialPoint, constitutiveMatrix->dim ) ) {
+			yieldCriterion = _FaultingMoresiMuhlhaus2006_GetYieldCriterion( self, constitutiveMatrix, materialPointsSwarm,
+				lElement_I, materialPoint, xi );
+			yieldIndicator = _FaultingMoresiMuhlhaus2006_GetYieldIndicator( self, constitutiveMatrix, materialPointsSwarm,
+				lElement_I, materialPoint, xi );
+
+			/* Set a bool to TRUE or FLAG depending on whether a materialPoint has failed or not */
+			YieldRheology_SetParticleFlag( self, materialPointsSwarm, materialPoint, (yieldCriterion < yieldIndicator) );
+			
+			if ( yieldCriterion < yieldIndicator ) {
+				StrainWeakening_AssignIncrement( self->strainWeakening, constitutiveMatrix,
+						materialPointsSwarm, lElement_I, materialPoint, yieldCriterion, yieldIndicator );
+				_FaultingMoresiMuhlhaus2006_HasYielded( self, constitutiveMatrix, materialPointsSwarm, lElement_I, materialPoint,
+						yieldCriterion, yieldIndicator );
+				return;
+			}
+		}
+		 
+		/* 
+		     If it falls through to here, old orientation is now hardening  */
+				
+		YieldRheology_SetParticleFlag( self, materialPointsSwarm, materialPoint, 0 );
+		
+	}
+
+	/* Second part : treatment of pristine material with no previously stored direction  */
+	
+	
+	self->tryingOldOrientation = False;
+	
+	/* This calls the standard yielding Constitutive matrix routine defined on the parent BUT
+		the individual calls are to the FMM routines so this should choose the appropriate softening
+		orientation for pristine material */
+	
+	_YieldRheology_ModifyConstitutiveMatrix( self, constitutiveMatrix, materialPointsSwarm, lElement_I, materialPoint, xi );
+}
+
+double _FaultingMoresiMuhlhaus2006_GetYieldIndicator( 
+		void*                                              rheology,
+		ConstitutiveMatrix*                                constitutiveMatrix,
+		MaterialPointsSwarm*                               materialPointsSwarm,
+		Element_LocalIndex                                 lElement_I,
+		MaterialPoint*                                     materialPoint,
+		Coord                                              xi ) 
+{
+	FaultingMoresiMuhlhaus2006*           self             = (FaultingMoresiMuhlhaus2006*) rheology;
+	double*                               stress           = self->currentStress;
+	Eigenvector*                          eigenvectorList  = self->currentEigenvectorList;
+	double                                sigma_ns;
+	Dimension_Index                       dim              = constitutiveMatrix->dim;
+	FaultingMoresiMuhlhaus2006_Particle*  particleExt;
+	double                                stressMin;
+	double                                stressMax;
+	double                                theta;
+	XYZ                                   normal;	
+	
+	Director_GetNormal( self->director, materialPoint, normal );
+	
+	particleExt = (FaultingMoresiMuhlhaus2006_Particle*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, materialPoint, self->particleExtHandle );
+
+	if ( self->tryingOldOrientation ) {
+		sigma_ns = SymmetricTensor_MultiplyByVectors( stress, normal, particleExt->slip, dim );
+	}
+	else {
+		/* Failure criterion from stress field - 
+		 * we can calculate whether the material has failed at the current stress from the principle stresses 
+		 * (without having to compute the orientation) if it does fail, 
+		 * we can then calculate the orientation for the orthotropy model and history */
+		
+		theta = 0.5 * atan( 1.0/ _FaultingMoresiMuhlhaus2006_EffectiveFrictionCoefficient( self, materialPoint ) );
+		
+		stressMin = eigenvectorList[0].eigenvalue;
+		stressMax = (dim == 2 ? eigenvectorList[1].eigenvalue : eigenvectorList[2].eigenvalue);
+		
+		sigma_ns = 0.5 *  sin( 2.0 * theta ) * ( stressMax - stressMin );
+	}
+	
+	return fabs(sigma_ns);
+}
+
+double _FaultingMoresiMuhlhaus2006_GetYieldCriterion( 
+		void*                                              rheology,
+		ConstitutiveMatrix*                                constitutiveMatrix,
+		MaterialPointsSwarm*                               materialPointsSwarm,
+		Element_LocalIndex                                 lElement_I,
+		MaterialPoint*                                     materialPoint,
+		Coord                                              xi )
+{
+	FaultingMoresiMuhlhaus2006*          self             = (FaultingMoresiMuhlhaus2006*) rheology;
+	double                               minimumYieldStress;
+	double                               effectiveCohesion;
+	double                               effectiveFrictionCoefficient;
+	double                               frictionalStrength;
+	double                               sigma_nn;
+	FaultingMoresiMuhlhaus2006_Particle* particleExt;
+		
+	particleExt = (FaultingMoresiMuhlhaus2006_Particle*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, materialPoint, self->particleExtHandle );
+		
+	/* Calculate frictional strength */
+	effectiveFrictionCoefficient = _FaultingMoresiMuhlhaus2006_EffectiveFrictionCoefficient( self, materialPoint );
+	effectiveCohesion            = _FaultingMoresiMuhlhaus2006_EffectiveCohesion( self, materialPoint , particleExt);
+	sigma_nn                     = _FaultingMoresiMuhlhaus2006_Sigma_nn( self, materialPoint, constitutiveMatrix->dim );
+
+	frictionalStrength = effectiveFrictionCoefficient * sigma_nn + effectiveCohesion;
+
+	/* Check if it should break in tension (strictly : frictionalStrength < tensileStrength and not zero) */
+	particleExt->tensileFailure = (frictionalStrength < 0.0);
+	
+	/* Make sure frictionalStrength is above the minimum */
+	minimumYieldStress = self->minimumYieldStress;
+	
+	if ( frictionalStrength < minimumYieldStress) 
+		frictionalStrength = minimumYieldStress;
+	
+	return frictionalStrength;
+}
+
+void _FaultingMoresiMuhlhaus2006_HasYielded( 
+		void*                                              rheology,
+		ConstitutiveMatrix*                                constitutiveMatrix,
+		MaterialPointsSwarm*                               materialPointsSwarm,
+		Element_LocalIndex                                 lElement_I,
+		MaterialPoint*                                     materialPoint,
+		double                                             yieldCriterion,
+		double                                             yieldIndicator )
+{
+	FaultingMoresiMuhlhaus2006*          self             = (FaultingMoresiMuhlhaus2006*) rheology;
+	double                               beta;
+	double*                              normal;
+	double                               viscosity        = ConstitutiveMatrix_GetIsotropicViscosity( constitutiveMatrix );
+	FaultingMoresiMuhlhaus2006_Particle* particleExt;
+        double corr;
+
+	normal = _FaultingMoresiMuhlhaus2006_UpdateNormalDirection( self, materialPointsSwarm, materialPoint, constitutiveMatrix->dim );
+	
+	beta = 1.0 - yieldCriterion / yieldIndicator;
+        corr = -viscosity * beta;
+        if( (viscosity + corr) < self->minVisc )
+           corr = self->minVisc - viscosity;
+
+        if( self->isotropicCorrection )
+           ConstitutiveMatrix_IsotropicCorrection( constitutiveMatrix, corr );
+        else
+           ConstitutiveMatrix_SetSecondViscosity( constitutiveMatrix, -corr, normal );
+
+	particleExt = (FaultingMoresiMuhlhaus2006_Particle*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, materialPoint, self->particleExtHandle );
+	particleExt->slipRate = self->storedSlipRateValue;
+	
+	/* Set a flag to tell the director that particles which have failed don't need to have their normal updated */
+	Director_SetDontUpdateParticleFlag( self->director, materialPoint, True );
+}
+
+Bool _FaultingMoresiMuhlhaus2006_OldOrientationStillSoftening( void* rheology, MaterialPointsSwarm* materialPointsSwarm, void* materialPoint, Dimension_Index dim ) {
+	FaultingMoresiMuhlhaus2006*           self             = (FaultingMoresiMuhlhaus2006*) rheology;
+	double*                               velocityGradient = self->currentVelocityGradient;
+	double*                               stress           = self->currentStress;
+	FaultingMoresiMuhlhaus2006_Particle*  particleExt;
+	double*                               n;
+	double*                               s;
+	double                                tau_nn;
+	double                                traction[3];
+	double                                dVparalleldXperpendicular;
+	double                                dVparalleldXperpendicular1;
+	XYZ                                   normal;
+	
+	Director_GetNormal( self->director, materialPoint, normal );
+
+	particleExt = (FaultingMoresiMuhlhaus2006_Particle*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, materialPoint, self->particleExtHandle );
+	n = normal;
+	s = particleExt->slip;
+	 
+	/* If an existing weakened direction exists we test this direction for further failure
+	 * The slip direction should be set to the direction of maximum shear stress and stored
+	 * for plotting 
+	 * (it does not need to be updated as a history variable like the director ) */
+	
+	if ( dim == 2 ) {
+		traction[0] = stress[0] * n[0] + stress[2] * n[1];
+		traction[1] = stress[2] * n[0] + stress[1] * n[1];
+		
+		tau_nn =  n[0] * traction[0] + n[1] * traction[1];
+				
+		s[0] = traction[0] - tau_nn * n[0];
+		s[1] = traction[1] - tau_nn * n[1];
+	}
+	
+	else {
+		traction[0] = stress[0] * n[0] + stress[3] * n[1] + stress[4] * n[2];
+		traction[1] = stress[3] * n[0] + stress[1] * n[1] + stress[5] * n[2];
+		traction[2] = stress[4] * n[0] + stress[5] * n[1] + stress[2] * n[2];	
+				
+		tau_nn =  n[0] * traction[0] + n[1] * traction[1] + n[2] * traction[2];
+				
+		s[0] = traction[0] - tau_nn * n[0];
+		s[1] = traction[1] - tau_nn * n[1];
+		s[2] = traction[2] - tau_nn * n[2];
+	}
+	
+	StGermain_VectorNormalise( s, dim );
+	
+	/* Store tau_nn so that we can use it in calculating sigma_nn in _FaultingMoresiMuhlhaus2006_Sigma_nn */
+	self->tau_nn = tau_nn;
+
+	/* Softening direction */
+	dVparalleldXperpendicular  = fabs(TensorArray_MultiplyByVectors( velocityGradient, s, n, dim )) ;
+
+	/* Hardening Direction */
+	dVparalleldXperpendicular1 = fabs(TensorArray_MultiplyByVectors( velocityGradient, n, s, dim )) ;  
+
+	/* Store this value on class in case we need to store it on the materialPoint if it fails */
+	self->storedSlipRateValue = dVparalleldXperpendicular;
+
+	/* We should only continue testing this plane if it is also in the 
+	 * softening orientation with respect to the strain-rate gradient rather than hardening */
+
+        /* The above is untrue if we are keeping the same director normals .  */
+	
+	/* LM: No, I don't think this is true ... in this case we keep the orientation unless it hardens as well */
+			
+	return (dVparalleldXperpendicular1 < dVparalleldXperpendicular) ? True : False; // ? True : !self->updateOrientations;
+}
+
+double* _FaultingMoresiMuhlhaus2006_UpdateNormalDirection( void* rheology, MaterialPointsSwarm* materialPointsSwarm, void* materialPoint, Dimension_Index dim ) {
+	FaultingMoresiMuhlhaus2006*          self                   = (FaultingMoresiMuhlhaus2006*) rheology;
+	FaultingMoresiMuhlhaus2006_Particle* particleExt;
+	double*                              velocityGradient       = self->currentVelocityGradient;
+	Eigenvector*                         eigenvectorList        = self->currentEigenvectorList;
+	double                               strainRate_ns[2];
+	XYZ                                  normal[2];
+	XYZ                                  slip[2];
+	double                               theta;
+	int                                  favourablePlane;
+	double*                              normalDirector;
+	double                               tanPhi;
+	
+	normalDirector = Director_GetNormalPtr( self->director, materialPoint);
+	
+	particleExt = (FaultingMoresiMuhlhaus2006_Particle*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, materialPoint, self->particleExtHandle );
+	
+	/* This function is specific for pristine materials -- 
+	 * We don't need to calculate it for failure in old orientations */
+        if ( self->tryingOldOrientation )
+           return normalDirector;
+	
+        /* Only enter the following conditional if we're interested in
+           updating the director's normal directions. */
+        if( self->updateOrientations ) {
+
+           if ((fabs(tanPhi = _FaultingMoresiMuhlhaus2006_EffectiveFrictionCoefficient( self, materialPoint )))<0.000001)
+              theta = M_PI / 4.0;
+           else
+              theta = 0.5 * atan( 1.0/ tanPhi );
+
+           if (dim == 2){ 
+
+              /* Identify potential failure directions */
+              StGermain_RotateCoordinateAxis( slip[0],   eigenvectorList[0].vector, K_AXIS, +theta);
+              StGermain_RotateCoordinateAxis( slip[1],   eigenvectorList[0].vector, K_AXIS, -theta);
+              StGermain_RotateCoordinateAxis( normal[0], eigenvectorList[0].vector, K_AXIS,  0.5*M_PI + theta);
+              StGermain_RotateCoordinateAxis( normal[1], eigenvectorList[0].vector, K_AXIS,  0.5*M_PI - theta);
+           }
+           else {
+
+              /* Identify potential failure directions */
+              StGermain_RotateVector( slip[0],   eigenvectorList[0].vector, eigenvectorList[1].vector, + theta );
+              StGermain_RotateVector( slip[1],   eigenvectorList[0].vector, eigenvectorList[1].vector, - theta );
+              StGermain_RotateVector( normal[0], eigenvectorList[0].vector, eigenvectorList[1].vector,  0.5*M_PI + theta);
+              StGermain_RotateVector( normal[1], eigenvectorList[0].vector, eigenvectorList[1].vector,  0.5*M_PI - theta);
+           }
+
+           /* Resolve shear strain-rate for the potential failure planes */
+           strainRate_ns[0] = fabs(TensorArray_MultiplyByVectors( velocityGradient, slip[0], normal[0], dim ));
+           strainRate_ns[1] = fabs(TensorArray_MultiplyByVectors( velocityGradient, slip[1], normal[1], dim ));
+
+           /* Choose the plane which is oriented favorably for continued slip */
+
+	
+           favourablePlane = (strainRate_ns[0] > strainRate_ns[1] ? 0 : 1);
+
+           memcpy( normalDirector,      normal[favourablePlane], dim * sizeof(double) );
+           memcpy( particleExt->slip,   slip[favourablePlane],   dim * sizeof(double) );
+
+           self->storedSlipRateValue = strainRate_ns[ favourablePlane ];
+
+        }
+
+        /* If we're not interested in changing director normals, just us e existing ones. */
+        else {
+
+           self->storedSlipRateValue = fabs(TensorArray_MultiplyByVectors(
+                                               velocityGradient, particleExt->slip, normalDirector, dim ));
+
+        }
+
+	return normalDirector;
+}
+
+double _FaultingMoresiMuhlhaus2006_EffectiveCohesion( void* rheology, void* materialPoint, void*  particleExtIn ) {
+	FaultingMoresiMuhlhaus2006*          self                          = (FaultingMoresiMuhlhaus2006*) rheology;
+	double                               effectiveCohesion;
+	FaultingMoresiMuhlhaus2006_Particle* particleExt                   = (FaultingMoresiMuhlhaus2006_Particle*) particleExtIn; 
+	
+	if ( self->tryingOldOrientation || self->ignoreOldOrientation ) {
+		/* If this is the old orientation or old orientations are completely ignored
+		 * then the weakening should be considered here   */
+		
+		double strainWeakeningRatio = StrainWeakening_CalcRatio( self->strainWeakening, materialPoint );
+	
+		effectiveCohesion =  self->cohesion * (1.0 - strainWeakeningRatio) + 
+				self->cohesionAfterSoftening * strainWeakeningRatio;
+				
+		/* Flag particle as fully softened if strainWeakeningRatio > 0.99 */ 
+		
+		particleExt->fullySoftened = ( strainWeakeningRatio > 0.99 );
+	}
+	else {
+		/*	If old orientations are tested first and this is an unbroken direction 
+		 *	then consider material as completely pristine */
+		
+		effectiveCohesion =  self->cohesion;
+	}
+
+	return effectiveCohesion;
+}
+
+double _FaultingMoresiMuhlhaus2006_EffectiveFrictionCoefficient( void* rheology, void* materialPoint ) {
+	FaultingMoresiMuhlhaus2006*    self                          = (FaultingMoresiMuhlhaus2006*) rheology;
+	static double                  effectiveFrictionCoefficient  = 0.0;
+	static int                     prevTryingOldOrientationValue = -1;
+	static void*                   prevParticle                  = NULL;
+
+	/* See if we can return cached value */
+	if ( self->tryingOldOrientation == (Bool) prevTryingOldOrientationValue && materialPoint == prevParticle ) 
+		return effectiveFrictionCoefficient;
+	
+	/* This is a different situation to the cached case - therefore recalculate */
+	if ( self->tryingOldOrientation || self->ignoreOldOrientation ) {
+		/* If this is the old orientation or old orientations are ignored
+		 * then the weakening should be considered here   */
+		double strainWeakeningRatio = StrainWeakening_CalcRatio( self->strainWeakening, materialPoint );
+	
+		effectiveFrictionCoefficient = self->frictionCoefficient * (1.0 - strainWeakeningRatio) +
+				self->frictionCoefficientAfterSoftening * strainWeakeningRatio;	
+	}
+	else {
+		/*	If old orientations are given priority and this is an unbroken direction 
+		 *	then consider material as completely pristine */
+		effectiveFrictionCoefficient =  self->frictionCoefficient;		
+	}
+
+	/* Cache values */
+	prevParticle                  = materialPoint;
+	prevTryingOldOrientationValue = self->tryingOldOrientation;
+
+	return effectiveFrictionCoefficient;
+}
+
+double _FaultingMoresiMuhlhaus2006_Sigma_nn( void* rheology, void* materialPoint, Dimension_Index dim ) {
+	FaultingMoresiMuhlhaus2006*      self             = (FaultingMoresiMuhlhaus2006*) rheology;
+	double                           pressure         = self->currentPressure;
+	Eigenvector*                     eigenvectorList  = self->currentEigenvectorList;
+	double                           tau_nn;
+	double                           sigma_nn;
+
+	if ( self->tryingOldOrientation ) {
+		/* tau_nn has already been calculated in _FaultingMoresiMuhlhaus2006_OldOrientationStillSoftening */
+		tau_nn = self->tau_nn;
+	}
+	else {
+		double stressMin = eigenvectorList[0].eigenvalue;
+		double stressMax = (dim == 2 ? eigenvectorList[1].eigenvalue : eigenvectorList[2].eigenvalue);
+		double theta = 0.5 * atan( 1.0/ _FaultingMoresiMuhlhaus2006_EffectiveFrictionCoefficient( self, materialPoint ) );
+
+		tau_nn = 0.5 * (( stressMax + stressMin ) + cos( 2.0 * theta ) * ( stressMax - stressMin ));
+	}
+
+	sigma_nn = pressure - tau_nn;
+
+	return sigma_nn;
+}
+
+void _FaultingMoresiMuhlhaus2006_UpdateNormalAtMaxSoft( void* rheology, void* materialPoint, Dimension_Index dim, SymmetricTensor strainRate, void* particleExtIn ) {
+	XYZ                                  normal[2];
+	XYZ                                  slip[2];
+	double                               theta;
+	double*                              normalDirector;
+	double                               strainRate_ns[2];
+	int                                  favourablePlane;
+	Eigenvector                          eigenvectorListStrain[2];
+	FaultingMoresiMuhlhaus2006*          self               = (FaultingMoresiMuhlhaus2006*) rheology;
+	FaultingMoresiMuhlhaus2006_Particle* particleExt        = (FaultingMoresiMuhlhaus2006_Particle*) particleExtIn;	
+
+	normalDirector = Director_GetNormalPtr( self->director, materialPoint);
+
+    /* If we don't want to update normals, leave as is. */
+        if( !self->updateOrientations )
+           return;
+
+	SymmetricTensor_CalcAllEigenvectors( strainRate, dim, eigenvectorListStrain );
+	theta = M_PI / 4.0;
+
+	if(dim == 2){
+		StGermain_RotateCoordinateAxis(   slip[0],   eigenvectorListStrain[0].vector, K_AXIS, -theta);
+		StGermain_RotateCoordinateAxis(   slip[1],   eigenvectorListStrain[0].vector, K_AXIS, +theta);
+		StGermain_RotateCoordinateAxis( normal[0],   eigenvectorListStrain[0].vector, K_AXIS, +theta);
+		StGermain_RotateCoordinateAxis( normal[1],   eigenvectorListStrain[0].vector, K_AXIS, -theta);
+	}
+	else{
+		StGermain_RotateVector( slip[0],   eigenvectorListStrain[0].vector, eigenvectorListStrain[1].vector, - theta );
+		StGermain_RotateVector( slip[1],   eigenvectorListStrain[0].vector, eigenvectorListStrain[1].vector, + theta );
+		StGermain_RotateVector( normal[0], eigenvectorListStrain[0].vector, eigenvectorListStrain[1].vector, + theta );
+		StGermain_RotateVector( normal[1], eigenvectorListStrain[0].vector, eigenvectorListStrain[1].vector, - theta );
+	}
+	
+	/* Choose the plane which is oriented favorably for continued slip */
+	strainRate_ns[0] = fabs(TensorArray_MultiplyByVectors( self->currentVelocityGradient, slip[0], normal[0], dim ));
+	strainRate_ns[1] = fabs(TensorArray_MultiplyByVectors( self->currentVelocityGradient, slip[1], normal[1], dim ));
+
+	favourablePlane = strainRate_ns[0] > strainRate_ns[1] ? 0 : 1;
+	memcpy( particleExt->slip,   slip[favourablePlane], dim * sizeof(double) );
+	memcpy( normalDirector,    normal[favourablePlane], dim * sizeof(double) );
+}	
+
+void _FaultingMoresiMuhlhaus2006_StoreCurrentParameters( 
+		void*                                              rheology,
+		ConstitutiveMatrix*                                constitutiveMatrix, 
+		MaterialPointsSwarm*                               materialPointsSwarm,
+		Element_LocalIndex                                 lElement_I, 
+		MaterialPoint*                                     materialPoint,
+		Coord                                              xi ) 
+{
+	FaultingMoresiMuhlhaus2006*          self               = (FaultingMoresiMuhlhaus2006*) rheology;
+	SymmetricTensor                      strainRate;
+	Dimension_Index                      dim                = constitutiveMatrix->dim;
+	FaultingMoresiMuhlhaus2006_Particle* particleExt;
+	
+	particleExt = (FaultingMoresiMuhlhaus2006_Particle*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, materialPoint, self->particleExtHandle );
+	particleExt->slipRate = 0.0;
+	
+	FeVariable_InterpolateWithinElement( self->pressureField, lElement_I, xi, &self->currentPressure );	
+	FeVariable_InterpolateWithinElement( self->velocityGradientsField, lElement_I, xi, self->currentVelocityGradient );
+	TensorArray_GetSymmetricPart( self->currentVelocityGradient, dim, strainRate );
+	ConstitutiveMatrix_CalculateStress( constitutiveMatrix, strainRate, self->currentStress );
+	
+	SymmetricTensor_CalcAllEigenvectors( self->currentStress, dim, self->currentEigenvectorList );
+
+	Director_SetDontUpdateParticleFlag( self->director, materialPoint, False );
+	
+	if( self->updateOrientationAtMaxSoftness ){
+		/* if particle is fully softened, and it is the first non-linear iteration of the current timestep,
+		   then update particle direction */		
+		if( particleExt->fullySoftened && (constitutiveMatrix->sleNonLinearIteration_I == 0) )	
+		  _FaultingMoresiMuhlhaus2006_UpdateNormalAtMaxSoft( rheology, materialPoint, dim, strainRate, particleExt ) ;
+	}
+}
+
+void _FaultingMoresiMuhlhaus2006_UpdateDrawParameters( void* rheology ) {
+	
+	FaultingMoresiMuhlhaus2006*      self               = (FaultingMoresiMuhlhaus2006*) rheology;
+	Particle_Index                   lParticle_I;
+	Particle_Index                   particleLocalCount;
+	StrainWeakening*                 strainWeakening    = self->strainWeakening;
+	GlobalParticle*	  				 materialPoint;
+	double                           slipRate;
+	
+	double                           ratio;
+	double                           length;
+	double                           brightness;
+	double                           opacity;
+	double                           strainWeakeningRatio;
+	double                           localMaxStrainIncrement;
+	double                           localMinStrainIncrement;
+	double                           localMaxSlipRate;
+	double                           localMeanStrainIncrement;
+	double                           localMeanSlipRate;
+	Particle_Index                   localFailed;
+	
+	double                           globalMaxSlipRate;
+	double                           globalMaxStrainIncrement;
+	double                           globalMinStrainIncrement;
+	double                           globalMeanStrainIncrement;
+	double                           globalMeanSlipRate;
+	Particle_Index                   globalFailed;
+	
+	double                           averagedGlobalMaxSlipRate = 0.0;
+	double                           averagedGlobalMaxStrainIncrement = 0.0;
+
+	double                           oneOverGlobalMaxSlipRate;
+	double                           oneOverGlobalMaxStrainIncrement;
+	double                           postFailureWeakeningIncrement;
+	
+	
+	
+	/* This parameter is only needed for the alternative commented out set of parameters */ 
+	/* double                           globalMaxStrainWeakeningRatio    = 0.0; */
+
+        /* Note : this function defines some drawing parameters (brightness, opacity, diameter) as
+	 * functions of the strain weakening - this needs to be improved since most of the parameters
+	 * that define this dependency are hard coded here. We need to have a more flexible way
+	 * to construct the viz parameters as functions of material parameters */
+	
+	localMaxStrainIncrement = -1.0e30;
+	localMinStrainIncrement =  1.0e30;
+	localMeanStrainIncrement = 0.0;
+	localMaxSlipRate = 0.0;
+	localMeanSlipRate = 0.0;
+	localFailed = 0;
+
+	/* Update all variables */
+	Variable_Update( self->hasYieldedVariable->variable );
+	Variable_Update( self->slipRate->variable );
+	Variable_Update( self->brightness->variable );
+	Variable_Update( self->opacity->variable );
+	Variable_Update( self->length->variable );
+	Variable_Update( self->thickness->variable );
+	Variable_Update( strainWeakening->postFailureWeakeningIncrement->variable );
+
+	particleLocalCount = self->hasYieldedVariable->variable->arraySize;
+	
+	for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) { 
+		if ( Variable_GetValueChar( self->hasYieldedVariable->variable, lParticle_I )) {
+			localFailed++;
+			slipRate = Variable_GetValueDouble( self->slipRate->variable, lParticle_I );
+
+			postFailureWeakeningIncrement = 
+				Variable_GetValueDouble( strainWeakening->postFailureWeakeningIncrement->variable, lParticle_I );
+			
+			localMeanSlipRate += slipRate; /* Always positive */
+			localMeanStrainIncrement += fabs(postFailureWeakeningIncrement); /* Positive in failure, negative in healing */
+			
+			if(localMaxSlipRate < slipRate)
+				localMaxSlipRate = slipRate;
+		
+			if(localMaxStrainIncrement < postFailureWeakeningIncrement)
+				localMaxStrainIncrement = postFailureWeakeningIncrement;
+				
+			if(localMinStrainIncrement > postFailureWeakeningIncrement)
+				localMinStrainIncrement = postFailureWeakeningIncrement;
+		}
+	}
+	
+	MPI_Allreduce( &localMaxSlipRate,         &globalMaxSlipRate,         1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );
+	MPI_Allreduce( &localMaxStrainIncrement,  &globalMaxStrainIncrement,  1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );
+	MPI_Allreduce( &localMinStrainIncrement,  &globalMinStrainIncrement,  1, MPI_DOUBLE, MPI_MIN, MPI_COMM_WORLD );
+	MPI_Allreduce( &localMeanSlipRate,        &globalMeanSlipRate,        1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
+	MPI_Allreduce( &localMeanStrainIncrement, &globalMeanStrainIncrement, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
+	MPI_Allreduce( &localFailed,              &globalFailed,              1, MPI_INT,    MPI_SUM, MPI_COMM_WORLD );
+	
+	if(localFailed == 0 || globalFailed == 0) 
+		return;
+				
+	globalMeanStrainIncrement /= (double) globalFailed;
+	globalMeanSlipRate /= (double) globalFailed;
+	
+	averagedGlobalMaxStrainIncrement = 
+		0.5 * averagedGlobalMaxStrainIncrement + 
+		0.25 * globalMeanStrainIncrement +
+		0.25 * globalMaxStrainIncrement;
+	averagedGlobalMaxSlipRate = 
+		0.5 * averagedGlobalMaxSlipRate + 
+		0.25 * globalMaxSlipRate +
+		0.25 * globalMeanSlipRate;
+	
+	fprintf(stderr,"globalMeanStrainIncrement = %g\n",globalMeanStrainIncrement);
+	fprintf(stderr,"globalMaxStrainIncrement  = %g\n",globalMaxStrainIncrement);
+	fprintf(stderr,"globalMinStrainIncrement  = %g\n",globalMinStrainIncrement);
+	fprintf(stderr,"averagedGlobalMaxStrainIncrement = %g\n",averagedGlobalMaxStrainIncrement);
+	fprintf(stderr,"globalMeanSlipRate = %g\n",globalMeanSlipRate); 
+	fprintf(stderr,"averagedGlobalMaxSlipRate = %g\n",averagedGlobalMaxSlipRate);
+	
+	fprintf(stderr,"Number of particles failing = %d/%d\n",localFailed,particleLocalCount);
+	
+	
+	
+	/* Let's simply assume that twice the mean is a good place to truncate these values */
+	oneOverGlobalMaxSlipRate = 1.0 / averagedGlobalMaxSlipRate;
+	oneOverGlobalMaxStrainIncrement = 1.0 / averagedGlobalMaxStrainIncrement;
+	
+	for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) { 
+		materialPoint = (GlobalParticle*) Swarm_ParticleAt( strainWeakening->swarm, lParticle_I );
+
+		if ( Variable_GetValueChar( self->hasYieldedVariable->variable, lParticle_I ) == False ||
+				StrainWeakening_GetPostFailureWeakening( strainWeakening, materialPoint ) < 0.0 ) 
+		{
+			Variable_SetValueFloat( self->brightness->variable, lParticle_I, 0.0 );
+			Variable_SetValueFloat( self->opacity->variable, lParticle_I, 0.0 );
+			Variable_SetValueFloat( self->length->variable, lParticle_I, 0.0 );
+			Variable_SetValueFloat( self->thickness->variable, lParticle_I, 0.0 );
+			continue;
+		}  
+		
+		slipRate = Variable_GetValueDouble( self->slipRate->variable, lParticle_I );
+		strainWeakeningRatio = StrainWeakening_CalcRatio( strainWeakening, materialPoint );
+		
+		postFailureWeakeningIncrement = 
+			Variable_GetValueDouble( strainWeakening->postFailureWeakeningIncrement->variable, lParticle_I );
+		
+		
+		/* Distinguish between healing (e.g. dark) and softening (e.g. light) branches 
+		
+			1. The intensity of the colouring should be proportional to strain rate
+			2. Size of square is proportional to total strain
+			3. The opacity is used to mask out the "uninteresting cases"
+		
+		*/
+		
+				length = 0.025 * strainWeakeningRatio;
+				
+				ratio = postFailureWeakeningIncrement / globalMeanStrainIncrement; // healing v. not 
+				if( ratio < -0.0) {  /* Healing - don't bother with the ones which are fading fast */
+					brightness = 0.0;	
+					opacity = 1.0 + ratio;
+					if(opacity < 0.0)
+						opacity = 0.0;
+				}
+				else {  /* Growing  */
+					brightness = slipRate * oneOverGlobalMaxSlipRate;
+					opacity = (ratio < 1.0 ? ratio : 1.0);
+					
+				}
+				
+		/* x = materialPoint->coord[I_AXIS]; */			
+					
+		/*
+		length     = 0.005 + 0.005 * strainWeakeningRatio;
+		length *= 10;
+		brightness = strainWeakeningRatio * slipRate * oneOverGlobalMaxSlipRate;
+		if( brightness > 1.0 )
+			brightness = 1.0;
+		opacity    = 0.1 + 0.05 * pow(brightness,3.0); 
+		*/
+
+
+
+
+		Variable_SetValueFloat( self->brightness->variable, lParticle_I, brightness );
+		Variable_SetValueFloat( self->opacity->variable,    lParticle_I, opacity );
+		Variable_SetValueFloat( self->length->variable,     lParticle_I, (float) length );
+		Variable_SetValueFloat( self->thickness->variable,  lParticle_I,  0.5 + 10.0 * (float)length );
+	
+		
+	
+	/* This parameter is only needed for the alternative commented out set of parameters */ 
+	/*	if (strainWeakeningRatio>globalMaxStrainWeakeningRatio)
+			globalMaxStrainWeakeningRatio = strainWeakeningRatio;
+	*/
+	}
+	
+	/* This part is another set of parameters that has been used with shear problems.
+	 * it's kept here for now, but it shows that in principle we could define as many set of parameters
+	 * as we want (depending on the problem ?)*/
+	/*
+	for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) { 
+		materialPoint = Swarm_ParticleAt( strainWeakening->materialPointsSwarm, lParticle_I );
+
+		if ( Variable_GetValueChar( self->hasYieldedVariable->variable, lParticle_I ) == False ||
+				StrainWeakening_GetPostFailureWeakening( strainWeakening, materialPoint ) < 0.0 ) 
+		{
+			Variable_SetValueFloat( self->brightness->variable, lParticle_I, 0.0 );
+			Variable_SetValueFloat( self->opacity->variable, lParticle_I, 0.0 );
+			Variable_SetValueFloat( self->length->variable, lParticle_I, 0.0 );
+			Variable_SetValueFloat( self->thickness->variable, lParticle_I, 0.0 );
+			continue;
+		}  
+		
+		slipRate = Variable_GetValueDouble( self->slipRate->variable, lParticle_I );
+		strainWeakeningRatio = StrainWeakening_CalcRatio( strainWeakening, materialPoint );
+		
+		length     = 0.03 + 0.03 * (strainWeakeningRatio/globalMaxStrainWeakeningRatio);
+
+		brightness = 1.0-(strainWeakeningRatio/globalMaxStrainWeakeningRatio);
+		
+		if (brightness > 1.0)
+			brightness = 1.0;
+			
+		opacity    = (slipRate/globalMaxSlipRate);
+		
+		if (opacity > 0.90)
+			opacity = 1.0;/* this condition is to make sure we have enough planes that will be clearly seen. */ /*
+
+		Variable_SetValueFloat( self->brightness->variable, lParticle_I, brightness );
+		Variable_SetValueFloat( self->opacity->variable,    lParticle_I, opacity );
+		Variable_SetValueFloat( self->length->variable,     lParticle_I, (float) length );
+		Variable_SetValueFloat( self->thickness->variable,  lParticle_I,  0.5 + 10.0 * (float)length );
+	}
+	*/
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/Finalise.c
--- a/Rheology/src/Finalise.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,59 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: Finalise.c 610 2007-10-11 08:09:29Z SteveQuenette $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include "Finalise.h"
-
-#include <stdio.h>
-
-Bool Underworld_Rheology_Finalise( void ) {
-	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
-	
-	return True;
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/Finalise.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/Finalise.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,59 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: Finalise.c 610 2007-10-11 08:09:29Z SteveQuenette $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include "Finalise.h"
+
+#include <stdio.h>
+
+Bool Underworld_Rheology_Finalise( void ) {
+	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
+	
+	return True;
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/FrankKamenetskii.c
--- a/Rheology/src/FrankKamenetskii.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,163 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: FrankKamenetskii.c 618 2007-10-29 07:53:04Z RobertTurnbull $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "RheologyClass.h"
-#include "FrankKamenetskii.h"
-#include "ConstitutiveMatrix.h"
-
-#include <assert.h>
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type FrankKamenetskii_Type = "FrankKamenetskii";
-
-/* Public Constructor */
-FrankKamenetskii* FrankKamenetskii_New(
-      Name                  name,
-      AbstractContext*      context,
-      FeVariable*           temperatureField, 
-      double                eta0,
-      double                theta )
-{
-   FrankKamenetskii* self = (FrankKamenetskii*) _FrankKamenetskii_DefaultNew( name );
-
-   _Rheology_Init( self, (PICelleratorContext*)context );
-   _FrankKamenetskii_Init( self, temperatureField, eta0, theta );
-   self->isConstructed = True;
-   return self;
-}
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-FrankKamenetskii* _FrankKamenetskii_New(  FRANKKAMENETSKII_DEFARGS  ) 
-{
-	FrankKamenetskii*					self;
-
-	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-	assert( _sizeOfSelf >= sizeof(FrankKamenetskii) );
-	self = (FrankKamenetskii*) _Rheology_New(  RHEOLOGY_PASSARGS  );
-	
-	return self;
-}
-
-void _FrankKamenetskii_Init( FrankKamenetskii* self, FeVariable* temperatureField, double eta0, double theta ) {
-	self->temperatureField = temperatureField;
-	self->eta0  = eta0;
-	self->theta = theta;
-}
-
-void* _FrankKamenetskii_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                     _sizeOfSelf = sizeof(FrankKamenetskii);
-	Type                                                             type = FrankKamenetskii_Type;
-	Stg_Class_DeleteFunction*                                     _delete = _Rheology_Delete;
-	Stg_Class_PrintFunction*                                       _print = _Rheology_Print;
-	Stg_Class_CopyFunction*                                         _copy = _Rheology_Copy;
-	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _FrankKamenetskii_DefaultNew;
-	Stg_Component_ConstructFunction*                           _construct = _FrankKamenetskii_AssignFromXML;
-	Stg_Component_BuildFunction*                                   _build = _Rheology_Build;
-	Stg_Component_InitialiseFunction*                         _initialise = _Rheology_Initialise;
-	Stg_Component_ExecuteFunction*                               _execute = _Rheology_Execute;
-	Stg_Component_DestroyFunction*                               _destroy = _FrankKamenetskii_Destroy;
-	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _FrankKamenetskii_ModifyConstitutiveMatrix;
-
-	/* 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*) _FrankKamenetskii_New(  FRANKKAMENETSKII_PASSARGS  );
-}
-
-void _FrankKamenetskii_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
-	FrankKamenetskii*  self = (FrankKamenetskii*)rheology;
-	FeVariable* temperatureField;
-
-	/* Construct Parent */
-	_Rheology_AssignFromXML( self, cf, data );
-	
-	/* TODO: KeyFallback soon to be deprecated/updated */
-	temperatureField = Stg_ComponentFactory_ConstructByNameWithKeyFallback( cf, self->name, (Name)"TemperatureField", (Dictionary_Entry_Key)"TemperatureField", FeVariable, True, data  );
-	/*temperatureField = Stg_ComponentFactory_ConstructByKey( cf, self->name, "TemperatureField", FeVariable, True ); */
-	
-	_FrankKamenetskii_Init( 
-			self, 
-			temperatureField,
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"eta0", 1.0  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"theta", 0.0 )  );
-}
-
-void _FrankKamenetskii_Destroy( void* rheology, void* data ) {
-	FrankKamenetskii*          self               = (FrankKamenetskii*) rheology;
-
-	Stg_Component_Destroy( self->temperatureField, data, False );
-
-	/* Destroy parent */
-	_Rheology_Destroy( self, data );
-
-}
-
-void _FrankKamenetskii_ModifyConstitutiveMatrix( 
-		void*                                              rheology, 
-		ConstitutiveMatrix*                                constitutiveMatrix,
-		MaterialPointsSwarm*                               swarm,
-		Element_LocalIndex                                 lElement_I,
-		MaterialPoint*                                     materialPoint,
-		Coord                                              xi )
-{
-	FrankKamenetskii*                 self              = (FrankKamenetskii*) rheology;
-	double                            temperature;
-	double                            viscosity;
-
-	/* Calculate Parameters */
-	FeVariable_InterpolateFromMeshLocalCoord( self->temperatureField, ConstitutiveMatrix_GetMesh( constitutiveMatrix ), lElement_I, xi, &temperature );
-
-	/* Calculate New Viscosity */
-	viscosity = self->eta0 * exp( - self->theta * temperature );
-	ConstitutiveMatrix_SetIsotropicViscosity( constitutiveMatrix, viscosity );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/FrankKamenetskii.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/FrankKamenetskii.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,163 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: FrankKamenetskii.c 618 2007-10-29 07:53:04Z RobertTurnbull $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "RheologyClass.h"
+#include "FrankKamenetskii.h"
+#include "ConstitutiveMatrix.h"
+
+#include <assert.h>
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type FrankKamenetskii_Type = "FrankKamenetskii";
+
+/* Public Constructor */
+FrankKamenetskii* FrankKamenetskii_New(
+      Name                  name,
+      AbstractContext*      context,
+      FeVariable*           temperatureField, 
+      double                eta0,
+      double                theta )
+{
+   FrankKamenetskii* self = (FrankKamenetskii*) _FrankKamenetskii_DefaultNew( name );
+
+   _Rheology_Init( self, (PICelleratorContext*)context );
+   _FrankKamenetskii_Init( self, temperatureField, eta0, theta );
+   self->isConstructed = True;
+   return self;
+}
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+FrankKamenetskii* _FrankKamenetskii_New(  FRANKKAMENETSKII_DEFARGS  ) 
+{
+	FrankKamenetskii*					self;
+
+	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+	assert( _sizeOfSelf >= sizeof(FrankKamenetskii) );
+	self = (FrankKamenetskii*) _Rheology_New(  RHEOLOGY_PASSARGS  );
+	
+	return self;
+}
+
+void _FrankKamenetskii_Init( FrankKamenetskii* self, FeVariable* temperatureField, double eta0, double theta ) {
+	self->temperatureField = temperatureField;
+	self->eta0  = eta0;
+	self->theta = theta;
+}
+
+void* _FrankKamenetskii_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                     _sizeOfSelf = sizeof(FrankKamenetskii);
+	Type                                                             type = FrankKamenetskii_Type;
+	Stg_Class_DeleteFunction*                                     _delete = _Rheology_Delete;
+	Stg_Class_PrintFunction*                                       _print = _Rheology_Print;
+	Stg_Class_CopyFunction*                                         _copy = _Rheology_Copy;
+	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _FrankKamenetskii_DefaultNew;
+	Stg_Component_ConstructFunction*                           _construct = _FrankKamenetskii_AssignFromXML;
+	Stg_Component_BuildFunction*                                   _build = _Rheology_Build;
+	Stg_Component_InitialiseFunction*                         _initialise = _Rheology_Initialise;
+	Stg_Component_ExecuteFunction*                               _execute = _Rheology_Execute;
+	Stg_Component_DestroyFunction*                               _destroy = _FrankKamenetskii_Destroy;
+	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _FrankKamenetskii_ModifyConstitutiveMatrix;
+
+	/* 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*) _FrankKamenetskii_New(  FRANKKAMENETSKII_PASSARGS  );
+}
+
+void _FrankKamenetskii_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
+	FrankKamenetskii*  self = (FrankKamenetskii*)rheology;
+	FeVariable* temperatureField;
+
+	/* Construct Parent */
+	_Rheology_AssignFromXML( self, cf, data );
+	
+	/* TODO: KeyFallback soon to be deprecated/updated */
+	temperatureField = Stg_ComponentFactory_ConstructByNameWithKeyFallback( cf, self->name, (Name)"TemperatureField", (Dictionary_Entry_Key)"TemperatureField", FeVariable, True, data  );
+	/*temperatureField = Stg_ComponentFactory_ConstructByKey( cf, self->name, "TemperatureField", FeVariable, True ); */
+	
+	_FrankKamenetskii_Init( 
+			self, 
+			temperatureField,
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"eta0", 1.0  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"theta", 0.0 )  );
+}
+
+void _FrankKamenetskii_Destroy( void* rheology, void* data ) {
+	FrankKamenetskii*          self               = (FrankKamenetskii*) rheology;
+
+	Stg_Component_Destroy( self->temperatureField, data, False );
+
+	/* Destroy parent */
+	_Rheology_Destroy( self, data );
+
+}
+
+void _FrankKamenetskii_ModifyConstitutiveMatrix( 
+		void*                                              rheology, 
+		ConstitutiveMatrix*                                constitutiveMatrix,
+		MaterialPointsSwarm*                               swarm,
+		Element_LocalIndex                                 lElement_I,
+		MaterialPoint*                                     materialPoint,
+		Coord                                              xi )
+{
+	FrankKamenetskii*                 self              = (FrankKamenetskii*) rheology;
+	double                            temperature;
+	double                            viscosity;
+
+	/* Calculate Parameters */
+	FeVariable_InterpolateFromMeshLocalCoord( self->temperatureField, ConstitutiveMatrix_GetMesh( constitutiveMatrix ), lElement_I, xi, &temperature );
+
+	/* Calculate New Viscosity */
+	viscosity = self->eta0 * exp( - self->theta * temperature );
+	ConstitutiveMatrix_SetIsotropicViscosity( constitutiveMatrix, viscosity );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/Init.c
--- a/Rheology/src/Init.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,132 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: Init.c 750 2008-07-07 02:26:33Z LukeHodkinson $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "Rheology.h"
-
-Bool Underworld_Rheology_Init( int* argc, char** argv[] ) {
-	Stg_ComponentRegister* componentRegister = Stg_ComponentRegister_Get_ComponentRegister();
-
-	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
-
-	Stg_ComponentRegister_Add( componentRegister, ConstitutiveMatrixCartesian_Type, (Name)"0", _ConstitutiveMatrixCartesian_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, MaterialViscosity_Type, (Name)"0", _MaterialViscosity_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, RheologyMaterial_Type, (Name)"0", _RheologyMaterial_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, MultiRheologyMaterial_Type, (Name)"0", _MultiRheologyMaterial_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, Compressible_Type, (Name)"0", _Compressible_DefaultNew  );
-
-	Stg_ComponentRegister_Add( componentRegister, Arrhenius_Type, (Name)"0", _Arrhenius_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, FrankKamenetskii_Type, (Name)"0", _FrankKamenetskii_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, NonNewtonian_Type, (Name)"0", _NonNewtonian_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, LinearViscosity_Type, (Name)"0", _LinearViscosity_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, DepthDependentViscosity_Type, (Name)"0", _DepthDependentViscosity_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, Anisotropic_Type, (Name)"0", _Anisotropic_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, OrthotropicAligned_Type, (Name)"0", _OrthotropicAligned_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, Orthotropic_Type, (Name)"0", _Orthotropic_DefaultNew  );
-	
-	Stg_ComponentRegister_Add( componentRegister, VonMises_Type, (Name)"0", _VonMises_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, Byerlee_Type, (Name)"0", _Byerlee_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, DruckerPrager_Type, (Name)"0", _DruckerPrager_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, FaultingMoresiMuhlhaus2006_Type, (Name)"0", _FaultingMoresiMuhlhaus2006_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, MohrCoulomb_Type, (Name)"0", _MohrCoulomb_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, Pouliquen_etal_Type, (Name)"0", _Pouliquen_etal_DefaultNew  );
-
-	Stg_ComponentRegister_Add( componentRegister, StrainWeakening_Type, (Name)"0", _StrainWeakening_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, Director_Type, (Name)"0", _Director_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, AlignmentSwarmVariable_Type, (Name)"0", _AlignmentSwarmVariable_DefaultNew  );
-	
-	Stg_ComponentRegister_Add( componentRegister, ViscosityFieldRheology_Type, (Name)"0", _ViscosityFieldRheology_DefaultNew  );
-
-	Stg_ComponentRegister_Add( componentRegister, StoreStress_Type, (Name)"0", _StoreStress_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, StoreVisc_Type, (Name)"0", _StoreVisc_DefaultNew  );
-	
-	Stg_ComponentRegister_Add( componentRegister, ConstitutiveMatCartesian_Refactored_Type, (Name)"0", _ConstitutiveMatCartesian_Refactored_DefaultNew  );
-
-	/* Register Parents for type checking */
-	RegisterParent( Rheology_Type,                Stg_Component_Type );
-	RegisterParent( Arrhenius_Type,               Rheology_Type );
-	RegisterParent( FrankKamenetskii_Type,        Rheology_Type );
-	RegisterParent( MaterialViscosity_Type,       Rheology_Type );
-	RegisterParent( NonNewtonian_Type,            Rheology_Type );
-	RegisterParent( DepthDependentViscosity_Type, Rheology_Type );
-	RegisterParent( LinearViscosity_Type,         Rheology_Type );
-	RegisterParent( Anisotropic_Type,             Rheology_Type );
-	RegisterParent( OrthotropicAligned_Type,      Rheology_Type );
-	RegisterParent( Orthotropic_Type,             Rheology_Type );
-
-	RegisterParent( StoreStress_Type,             Rheology_Type );
-	RegisterParent( StoreVisc_Type,               Rheology_Type );
-	
-	RegisterParent( ViscosityFieldRheology_Type,     Rheology_Type );
-	RegisterParent( YieldRheology_Type,              Rheology_Type );
-	RegisterParent( VonMises_Type,                   YieldRheology_Type );
-	RegisterParent( Byerlee_Type,                    VonMises_Type );
-	RegisterParent( DruckerPrager_Type,              VonMises_Type );
-	RegisterParent( FaultingMoresiMuhlhaus2006_Type, YieldRheology_Type );
-	RegisterParent( MohrCoulomb_Type,                YieldRheology_Type );
-	RegisterParent( Pouliquen_etal_Type,             VonMises_Type );
-	
-	RegisterParent( StrainWeakening_Type,         TimeIntegrand_Type );
-	RegisterParent( Director_Type,                TimeIntegrand_Type );
-	RegisterParent( AlignmentSwarmVariable_Type,  SwarmVariable_Type );
-
-	RegisterParent( ConstitutiveMatrix_Type,          StiffnessMatrixTerm_Type );
-	RegisterParent( ConstitutiveMatrixCartesian_Type, ConstitutiveMatrix_Type );
-	RegisterParent( RheologyMaterial_Type,            Material_Type );
-	RegisterParent( MultiRheologyMaterial_Type,       RheologyMaterial_Type );
-	RegisterParent( Compressible_Type,                StiffnessMatrixTerm_Type );
-
-	RegisterParent( ConstitutiveMat_Refactored_Type,          Stg_Component_Type );
-	RegisterParent( ConstitutiveMatCartesian_Refactored_Type, ConstitutiveMat_Refactored_Type );
-
-	return True;
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/Init.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/Init.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,132 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: Init.c 750 2008-07-07 02:26:33Z LukeHodkinson $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "Rheology.h"
+
+Bool Underworld_Rheology_Init( int* argc, char** argv[] ) {
+	Stg_ComponentRegister* componentRegister = Stg_ComponentRegister_Get_ComponentRegister();
+
+	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
+
+	Stg_ComponentRegister_Add( componentRegister, ConstitutiveMatrixCartesian_Type, (Name)"0", _ConstitutiveMatrixCartesian_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, MaterialViscosity_Type, (Name)"0", _MaterialViscosity_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, RheologyMaterial_Type, (Name)"0", _RheologyMaterial_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, MultiRheologyMaterial_Type, (Name)"0", _MultiRheologyMaterial_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, Compressible_Type, (Name)"0", _Compressible_DefaultNew  );
+
+	Stg_ComponentRegister_Add( componentRegister, Arrhenius_Type, (Name)"0", _Arrhenius_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, FrankKamenetskii_Type, (Name)"0", _FrankKamenetskii_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, NonNewtonian_Type, (Name)"0", _NonNewtonian_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, LinearViscosity_Type, (Name)"0", _LinearViscosity_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, DepthDependentViscosity_Type, (Name)"0", _DepthDependentViscosity_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, Anisotropic_Type, (Name)"0", _Anisotropic_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, OrthotropicAligned_Type, (Name)"0", _OrthotropicAligned_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, Orthotropic_Type, (Name)"0", _Orthotropic_DefaultNew  );
+	
+	Stg_ComponentRegister_Add( componentRegister, VonMises_Type, (Name)"0", _VonMises_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, Byerlee_Type, (Name)"0", _Byerlee_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, DruckerPrager_Type, (Name)"0", _DruckerPrager_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, FaultingMoresiMuhlhaus2006_Type, (Name)"0", _FaultingMoresiMuhlhaus2006_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, MohrCoulomb_Type, (Name)"0", _MohrCoulomb_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, Pouliquen_etal_Type, (Name)"0", _Pouliquen_etal_DefaultNew  );
+
+	Stg_ComponentRegister_Add( componentRegister, StrainWeakening_Type, (Name)"0", _StrainWeakening_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, Director_Type, (Name)"0", _Director_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, AlignmentSwarmVariable_Type, (Name)"0", _AlignmentSwarmVariable_DefaultNew  );
+	
+	Stg_ComponentRegister_Add( componentRegister, ViscosityFieldRheology_Type, (Name)"0", _ViscosityFieldRheology_DefaultNew  );
+
+	Stg_ComponentRegister_Add( componentRegister, StoreStress_Type, (Name)"0", _StoreStress_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, StoreVisc_Type, (Name)"0", _StoreVisc_DefaultNew  );
+	
+	Stg_ComponentRegister_Add( componentRegister, ConstitutiveMatCartesian_Refactored_Type, (Name)"0", _ConstitutiveMatCartesian_Refactored_DefaultNew  );
+
+	/* Register Parents for type checking */
+	RegisterParent( Rheology_Type,                Stg_Component_Type );
+	RegisterParent( Arrhenius_Type,               Rheology_Type );
+	RegisterParent( FrankKamenetskii_Type,        Rheology_Type );
+	RegisterParent( MaterialViscosity_Type,       Rheology_Type );
+	RegisterParent( NonNewtonian_Type,            Rheology_Type );
+	RegisterParent( DepthDependentViscosity_Type, Rheology_Type );
+	RegisterParent( LinearViscosity_Type,         Rheology_Type );
+	RegisterParent( Anisotropic_Type,             Rheology_Type );
+	RegisterParent( OrthotropicAligned_Type,      Rheology_Type );
+	RegisterParent( Orthotropic_Type,             Rheology_Type );
+
+	RegisterParent( StoreStress_Type,             Rheology_Type );
+	RegisterParent( StoreVisc_Type,               Rheology_Type );
+	
+	RegisterParent( ViscosityFieldRheology_Type,     Rheology_Type );
+	RegisterParent( YieldRheology_Type,              Rheology_Type );
+	RegisterParent( VonMises_Type,                   YieldRheology_Type );
+	RegisterParent( Byerlee_Type,                    VonMises_Type );
+	RegisterParent( DruckerPrager_Type,              VonMises_Type );
+	RegisterParent( FaultingMoresiMuhlhaus2006_Type, YieldRheology_Type );
+	RegisterParent( MohrCoulomb_Type,                YieldRheology_Type );
+	RegisterParent( Pouliquen_etal_Type,             VonMises_Type );
+	
+	RegisterParent( StrainWeakening_Type,         TimeIntegrand_Type );
+	RegisterParent( Director_Type,                TimeIntegrand_Type );
+	RegisterParent( AlignmentSwarmVariable_Type,  SwarmVariable_Type );
+
+	RegisterParent( ConstitutiveMatrix_Type,          StiffnessMatrixTerm_Type );
+	RegisterParent( ConstitutiveMatrixCartesian_Type, ConstitutiveMatrix_Type );
+	RegisterParent( RheologyMaterial_Type,            Material_Type );
+	RegisterParent( MultiRheologyMaterial_Type,       RheologyMaterial_Type );
+	RegisterParent( Compressible_Type,                StiffnessMatrixTerm_Type );
+
+	RegisterParent( ConstitutiveMat_Refactored_Type,          Stg_Component_Type );
+	RegisterParent( ConstitutiveMatCartesian_Refactored_Type, ConstitutiveMat_Refactored_Type );
+
+	return True;
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/LinearViscosity.c
--- a/Rheology/src/LinearViscosity.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,201 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: LinearViscosity.c 743 2008-06-23 01:49:43Z JulianGiordani $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "RheologyClass.h"
-#include "ConstitutiveMatrix.h"
-#include "LinearViscosity.h"
-
-#include <assert.h>
-#include <string.h>
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type LinearViscosity_Type = "LinearViscosity";
-
-/* Public Constructor */
-LinearViscosity* LinearViscosity_New(
-      Name              name,
-      AbstractContext*  context,
-      double            C,
-      double            X,
-      double            Y,
-      double            Z,
-      double            XY,
-      double            XZ,
-      double            YZ,
-      double            XYZ )
-{
-   LinearViscosity* self = (LinearViscosity*) _LinearViscosity_DefaultNew( name );
-
-   _Rheology_Init( self, (PICelleratorContext*)context );
-   _LinearViscosity_Init( self,
-	     C,
-	     X,
-	     Y,
-	     Z,
-	     XY,
-	     XZ,
-	     YZ,
-	     XYZ );
-
-   self->isConstructed = True;
-   return self;
-}
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-LinearViscosity* _LinearViscosity_New(  LINEARVISCOSITY_DEFARGS  ) 
-{
-	LinearViscosity*					self;
-
-	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-	assert( _sizeOfSelf >= sizeof(LinearViscosity) );
-	self = (LinearViscosity*) _Rheology_New(  RHEOLOGY_PASSARGS  );
-	
-	return self;
-}
-
-void _LinearViscosity_Init( 
-	LinearViscosity* self,
-	double           C,
-	double           X,
-	double           Y,
-	double           Z,
-	double           XY,
-	double           XZ,
-	double           YZ,
-	double           XYZ )
-{
-	self->C          = C;
-	self->X          = X;
-	self->Y          = Y;
-	self->Z          = Z;
-	self->XY         = XY;
-	self->XZ         = XZ;
-	self->YZ         = YZ;
-	self->XYZ        = XYZ;
-}
-
-void* _LinearViscosity_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                     _sizeOfSelf = sizeof(LinearViscosity);
-	Type                                                             type = LinearViscosity_Type;
-	Stg_Class_DeleteFunction*                                     _delete = _Rheology_Delete;
-	Stg_Class_PrintFunction*                                       _print = _Rheology_Print;
-	Stg_Class_CopyFunction*                                         _copy = _Rheology_Copy;
-	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _LinearViscosity_DefaultNew;
-	Stg_Component_ConstructFunction*                           _construct = _LinearViscosity_AssignFromXML;
-	Stg_Component_BuildFunction*                                   _build = _Rheology_Build;
-	Stg_Component_InitialiseFunction*                         _initialise = _Rheology_Initialise;
-	Stg_Component_ExecuteFunction*                               _execute = _Rheology_Execute;
-	Stg_Component_DestroyFunction*                               _destroy = _Rheology_Destroy;
-	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _LinearViscosity_ModifyConstitutiveMatrix;
-
-	/* 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*) _LinearViscosity_New(  LINEARVISCOSITY_PASSARGS  );
-}
-
-void _LinearViscosity_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
-	LinearViscosity*  self                   = (LinearViscosity*)rheology;
-
-	/* Construct Parent */
-	_Rheology_AssignFromXML( self, cf, data );
-	
-	_LinearViscosity_Init( 
-			self, 
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"C", 1.0  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"X", 1.0  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"Y", 1.0  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"Z", 1.0  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"XY", 1.0  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"XZ", 1.0  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"YZ", 1.0  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"XYZ", 1.0 )  );
-}
-
-void _LinearViscosity_ModifyConstitutiveMatrix( 
-		void*                                              rheology, 
-		ConstitutiveMatrix*                                constitutiveMatrix,
-		MaterialPointsSwarm*                               swarm,
-		Element_LocalIndex                                 lElement_I,
-		MaterialPoint*                                     materialPoint,
-		Coord                                              xi )
-{
-	LinearViscosity*  self              = (LinearViscosity*) rheology;
-	double            viscosity;
-	Coord             coord;
-	double            x, y, z;
-	double            C                 = self->C;
-	double            X                 = self->X;
-	double            Y                 = self->Y;
-	double            Z                 = self->Z;
-	double            XY                = self->XY;
-	double            XZ                = self->XZ;
-	double            YZ                = self->YZ;
-	double            XYZ               = self->XYZ;
-	FeMesh*           mesh              = ConstitutiveMatrix_GetMesh( constitutiveMatrix );
-	
-
-	/* This rheology assumes particle is an integration points thats can be mapped to a particle
-	 * that has no meaningful coord. Best to re-calc the global from local */
-	FeMesh_CoordLocalToGlobal( mesh, lElement_I, xi, coord );
-	x = coord[ I_AXIS ];
-	y = coord[ J_AXIS ];
-	z = coord[ K_AXIS ];
-
-	/* Calculate New Viscosity */
-	viscosity = X * x + Y * y + XY * x * y + C;
-	if ( swarm->dim == 3 )
-		viscosity += Z * z + XZ * x * z + YZ * y * z + XYZ * x * y * z;
-		
-	ConstitutiveMatrix_SetIsotropicViscosity( constitutiveMatrix, viscosity );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/LinearViscosity.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/LinearViscosity.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,201 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: LinearViscosity.c 743 2008-06-23 01:49:43Z JulianGiordani $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "RheologyClass.h"
+#include "ConstitutiveMatrix.h"
+#include "LinearViscosity.h"
+
+#include <assert.h>
+#include <string.h>
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type LinearViscosity_Type = "LinearViscosity";
+
+/* Public Constructor */
+LinearViscosity* LinearViscosity_New(
+      Name              name,
+      AbstractContext*  context,
+      double            C,
+      double            X,
+      double            Y,
+      double            Z,
+      double            XY,
+      double            XZ,
+      double            YZ,
+      double            XYZ )
+{
+   LinearViscosity* self = (LinearViscosity*) _LinearViscosity_DefaultNew( name );
+
+   _Rheology_Init( self, (PICelleratorContext*)context );
+   _LinearViscosity_Init( self,
+	     C,
+	     X,
+	     Y,
+	     Z,
+	     XY,
+	     XZ,
+	     YZ,
+	     XYZ );
+
+   self->isConstructed = True;
+   return self;
+}
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+LinearViscosity* _LinearViscosity_New(  LINEARVISCOSITY_DEFARGS  ) 
+{
+	LinearViscosity*					self;
+
+	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+	assert( _sizeOfSelf >= sizeof(LinearViscosity) );
+	self = (LinearViscosity*) _Rheology_New(  RHEOLOGY_PASSARGS  );
+	
+	return self;
+}
+
+void _LinearViscosity_Init( 
+	LinearViscosity* self,
+	double           C,
+	double           X,
+	double           Y,
+	double           Z,
+	double           XY,
+	double           XZ,
+	double           YZ,
+	double           XYZ )
+{
+	self->C          = C;
+	self->X          = X;
+	self->Y          = Y;
+	self->Z          = Z;
+	self->XY         = XY;
+	self->XZ         = XZ;
+	self->YZ         = YZ;
+	self->XYZ        = XYZ;
+}
+
+void* _LinearViscosity_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                     _sizeOfSelf = sizeof(LinearViscosity);
+	Type                                                             type = LinearViscosity_Type;
+	Stg_Class_DeleteFunction*                                     _delete = _Rheology_Delete;
+	Stg_Class_PrintFunction*                                       _print = _Rheology_Print;
+	Stg_Class_CopyFunction*                                         _copy = _Rheology_Copy;
+	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _LinearViscosity_DefaultNew;
+	Stg_Component_ConstructFunction*                           _construct = _LinearViscosity_AssignFromXML;
+	Stg_Component_BuildFunction*                                   _build = _Rheology_Build;
+	Stg_Component_InitialiseFunction*                         _initialise = _Rheology_Initialise;
+	Stg_Component_ExecuteFunction*                               _execute = _Rheology_Execute;
+	Stg_Component_DestroyFunction*                               _destroy = _Rheology_Destroy;
+	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _LinearViscosity_ModifyConstitutiveMatrix;
+
+	/* 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*) _LinearViscosity_New(  LINEARVISCOSITY_PASSARGS  );
+}
+
+void _LinearViscosity_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
+	LinearViscosity*  self                   = (LinearViscosity*)rheology;
+
+	/* Construct Parent */
+	_Rheology_AssignFromXML( self, cf, data );
+	
+	_LinearViscosity_Init( 
+			self, 
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"C", 1.0  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"X", 1.0  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"Y", 1.0  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"Z", 1.0  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"XY", 1.0  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"XZ", 1.0  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"YZ", 1.0  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"XYZ", 1.0 )  );
+}
+
+void _LinearViscosity_ModifyConstitutiveMatrix( 
+		void*                                              rheology, 
+		ConstitutiveMatrix*                                constitutiveMatrix,
+		MaterialPointsSwarm*                               swarm,
+		Element_LocalIndex                                 lElement_I,
+		MaterialPoint*                                     materialPoint,
+		Coord                                              xi )
+{
+	LinearViscosity*  self              = (LinearViscosity*) rheology;
+	double            viscosity;
+	Coord             coord;
+	double            x, y, z;
+	double            C                 = self->C;
+	double            X                 = self->X;
+	double            Y                 = self->Y;
+	double            Z                 = self->Z;
+	double            XY                = self->XY;
+	double            XZ                = self->XZ;
+	double            YZ                = self->YZ;
+	double            XYZ               = self->XYZ;
+	FeMesh*           mesh              = ConstitutiveMatrix_GetMesh( constitutiveMatrix );
+	
+
+	/* This rheology assumes particle is an integration points thats can be mapped to a particle
+	 * that has no meaningful coord. Best to re-calc the global from local */
+	FeMesh_CoordLocalToGlobal( mesh, lElement_I, xi, coord );
+	x = coord[ I_AXIS ];
+	y = coord[ J_AXIS ];
+	z = coord[ K_AXIS ];
+
+	/* Calculate New Viscosity */
+	viscosity = X * x + Y * y + XY * x * y + C;
+	if ( swarm->dim == 3 )
+		viscosity += Z * z + XZ * x * z + YZ * y * z + XYZ * x * y * z;
+		
+	ConstitutiveMatrix_SetIsotropicViscosity( constitutiveMatrix, viscosity );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/MaterialViscosity.c
--- a/Rheology/src/MaterialViscosity.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,151 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: MaterialViscosity.c 610 2007-10-11 08:09:29Z SteveQuenette $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "RheologyClass.h"
-#include "MaterialViscosity.h"
-#include "ConstitutiveMatrix.h"
-
-#include <assert.h>
-#include <string.h>
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type MaterialViscosity_Type = "MaterialViscosity";
-
-/* Public Constructor */
-MaterialViscosity* MaterialViscosity_New(
-      Name                  name,
-      AbstractContext*      context,
-      double                eta0 )
-{
-   MaterialViscosity* self = (MaterialViscosity*) _MaterialViscosity_DefaultNew( name );
-
-   _Rheology_Init( self, (PICelleratorContext*)context );
-   _MaterialViscosity_Init( self, eta0 );
-     
-   self->isConstructed = True;
-   return self;
-}
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-MaterialViscosity* _MaterialViscosity_New(  MATERIALVISCOSITY_DEFARGS  ) 
-{
-	MaterialViscosity*					self;
-
-	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-	assert( _sizeOfSelf >= sizeof(MaterialViscosity) );
-	self = (MaterialViscosity*) _Rheology_New(  RHEOLOGY_PASSARGS  );
-	
-	/* Function pointers for this class that are not on the parent class should be set here */
-	
-	return self;
-}
-
-void _MaterialViscosity_Init( void* rheology, double eta0 ) {
-	MaterialViscosity*  self = (MaterialViscosity*)rheology;
-
-	self->eta0 = eta0;
-}
-
-void* _MaterialViscosity_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                     _sizeOfSelf = sizeof(MaterialViscosity);
-	Type                                                             type = MaterialViscosity_Type;
-	Stg_Class_DeleteFunction*                                     _delete = _Rheology_Delete;
-	Stg_Class_PrintFunction*                                       _print = _Rheology_Print;
-	Stg_Class_CopyFunction*                                         _copy = _Rheology_Copy;
-	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _MaterialViscosity_DefaultNew;
-	Stg_Component_ConstructFunction*                           _construct = _MaterialViscosity_AssignFromXML;
-	Stg_Component_BuildFunction*                                   _build = _Rheology_Build;
-	Stg_Component_InitialiseFunction*                         _initialise = _Rheology_Initialise;
-	Stg_Component_ExecuteFunction*                               _execute = _Rheology_Execute;
-	Stg_Component_DestroyFunction*                               _destroy = _Rheology_Destroy;
-	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _MaterialViscosity_ModifyConstitutiveMatrix;
-
-	/* 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*) _MaterialViscosity_New(  MATERIALVISCOSITY_PASSARGS  );
-}
-
-void _MaterialViscosity_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
-	MaterialViscosity*  self = (MaterialViscosity*)rheology;
-
-	/* Construct Parent */
-	_Rheology_AssignFromXML( self, cf, data );
-	
-	_MaterialViscosity_Init( self, Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"eta0", 1.0 )  );
-}
-
-
-void _MaterialViscosity_ModifyConstitutiveMatrix( 
-		void*                                              rheology, 
-		ConstitutiveMatrix*                                constitutiveMatrix,
-		MaterialPointsSwarm*                               swarm,
-		Element_LocalIndex                                 lElement_I,
-		MaterialPoint*                                     materialPoint,
-		Coord                                              xi )
-{
-	MaterialViscosity*	                      self              = (MaterialViscosity*) rheology;
-
-        ConstitutiveMatrix_SetIsotropicViscosity( constitutiveMatrix, self->eta0 );
-
-        if( constitutiveMatrix->sle && constitutiveMatrix->sle->nlFormJacobian ) {
-           double* derivs = constitutiveMatrix->derivs;
-
-           /* Clear the derivative term. This should be done before any rheology
-              is called, that way we can do nothing here. */
-           memset( derivs, 0, 3 * 3 * sizeof(double) );
-
-        }
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/MaterialViscosity.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/MaterialViscosity.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,151 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: MaterialViscosity.c 610 2007-10-11 08:09:29Z SteveQuenette $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "RheologyClass.h"
+#include "MaterialViscosity.h"
+#include "ConstitutiveMatrix.h"
+
+#include <assert.h>
+#include <string.h>
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type MaterialViscosity_Type = "MaterialViscosity";
+
+/* Public Constructor */
+MaterialViscosity* MaterialViscosity_New(
+      Name                  name,
+      AbstractContext*      context,
+      double                eta0 )
+{
+   MaterialViscosity* self = (MaterialViscosity*) _MaterialViscosity_DefaultNew( name );
+
+   _Rheology_Init( self, (PICelleratorContext*)context );
+   _MaterialViscosity_Init( self, eta0 );
+     
+   self->isConstructed = True;
+   return self;
+}
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+MaterialViscosity* _MaterialViscosity_New(  MATERIALVISCOSITY_DEFARGS  ) 
+{
+	MaterialViscosity*					self;
+
+	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+	assert( _sizeOfSelf >= sizeof(MaterialViscosity) );
+	self = (MaterialViscosity*) _Rheology_New(  RHEOLOGY_PASSARGS  );
+	
+	/* Function pointers for this class that are not on the parent class should be set here */
+	
+	return self;
+}
+
+void _MaterialViscosity_Init( void* rheology, double eta0 ) {
+	MaterialViscosity*  self = (MaterialViscosity*)rheology;
+
+	self->eta0 = eta0;
+}
+
+void* _MaterialViscosity_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                     _sizeOfSelf = sizeof(MaterialViscosity);
+	Type                                                             type = MaterialViscosity_Type;
+	Stg_Class_DeleteFunction*                                     _delete = _Rheology_Delete;
+	Stg_Class_PrintFunction*                                       _print = _Rheology_Print;
+	Stg_Class_CopyFunction*                                         _copy = _Rheology_Copy;
+	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _MaterialViscosity_DefaultNew;
+	Stg_Component_ConstructFunction*                           _construct = _MaterialViscosity_AssignFromXML;
+	Stg_Component_BuildFunction*                                   _build = _Rheology_Build;
+	Stg_Component_InitialiseFunction*                         _initialise = _Rheology_Initialise;
+	Stg_Component_ExecuteFunction*                               _execute = _Rheology_Execute;
+	Stg_Component_DestroyFunction*                               _destroy = _Rheology_Destroy;
+	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _MaterialViscosity_ModifyConstitutiveMatrix;
+
+	/* 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*) _MaterialViscosity_New(  MATERIALVISCOSITY_PASSARGS  );
+}
+
+void _MaterialViscosity_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
+	MaterialViscosity*  self = (MaterialViscosity*)rheology;
+
+	/* Construct Parent */
+	_Rheology_AssignFromXML( self, cf, data );
+	
+	_MaterialViscosity_Init( self, Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"eta0", 1.0 )  );
+}
+
+
+void _MaterialViscosity_ModifyConstitutiveMatrix( 
+		void*                                              rheology, 
+		ConstitutiveMatrix*                                constitutiveMatrix,
+		MaterialPointsSwarm*                               swarm,
+		Element_LocalIndex                                 lElement_I,
+		MaterialPoint*                                     materialPoint,
+		Coord                                              xi )
+{
+	MaterialViscosity*	                      self              = (MaterialViscosity*) rheology;
+
+        ConstitutiveMatrix_SetIsotropicViscosity( constitutiveMatrix, self->eta0 );
+
+        if( constitutiveMatrix->sle && constitutiveMatrix->sle->nlFormJacobian ) {
+           double* derivs = constitutiveMatrix->derivs;
+
+           /* Clear the derivative term. This should be done before any rheology
+              is called, that way we can do nothing here. */
+           memset( derivs, 0, 3 * 3 * sizeof(double) );
+
+        }
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/MohrCoulomb.c
--- a/Rheology/src/MohrCoulomb.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,411 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: MohrCoulomb.c 11997 2008-05-22 18:16:17Z walter $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "RheologyClass.h"
-#include "StrainWeakening.h"
-#include "YieldRheology.h"
-#include "MohrCoulomb.h"
-#include "ConstitutiveMatrix.h"
-
-#include <assert.h>
-#include <string.h>
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type MohrCoulomb_Type = "MohrCoulomb";
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-MohrCoulomb* _MohrCoulomb_New(  MOHRCOULOMB_DEFARGS  ) 
-{
-	MohrCoulomb*					self;
-
-	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-	assert( _sizeOfSelf >= sizeof(MohrCoulomb) );
-	self = (MohrCoulomb*) _YieldRheology_New(  YIELDRHEOLOGY_PASSARGS  );
-	
-	/* Function pointers for this class that are not on the parent class should be set here */
-	
-	return self;
-}
-
-void _MohrCoulomb_Init(    
-		MohrCoulomb*          self,
-		FeVariable*           pressureField,
-		FeVariable*           strainRateField,
-		SwarmVariable*        swarmStrainRate,
-		MaterialPointsSwarm*  materialPointsSwarm,
-		double                cohesion,
-		double                cohesionAfterSoftening,
-		double                frictionCoefficient,
-		double                frictionCoefficientAfterSoftening,
-		double                minimumYieldStress)
-{                                                       
-	self->materialPointsSwarm     = materialPointsSwarm;
-	self->pressureField           = pressureField;
-	self->strainRateField  = strainRateField;
-	
-	self->cohesion = cohesion;
-	self->frictionCoefficient = frictionCoefficient;
-	
-	/* Strain softening of Cohesion - (linear weakening is assumed) */
-	/* needs a softening factor between +0 and 1 and a reference strain > 0 */
-	self->cohesionAfterSoftening = cohesionAfterSoftening;
-	
-	/* Strain softening of Friction - (linear weakening is assumed) */
-	/* needs a softening factor between +0 and 1 and a reference strain > 0 */
-	self->frictionCoefficientAfterSoftening = frictionCoefficientAfterSoftening;
-
-	self->minimumYieldStress = minimumYieldStress;
-}
-
-void* _MohrCoulomb_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                     _sizeOfSelf = sizeof(MohrCoulomb);
-	Type                                                             type = MohrCoulomb_Type;
-	Stg_Class_DeleteFunction*                                     _delete = _YieldRheology_Delete;
-	Stg_Class_PrintFunction*                                       _print = _YieldRheology_Print;
-	Stg_Class_CopyFunction*                                         _copy = _YieldRheology_Copy;
-	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _MohrCoulomb_DefaultNew;
-	Stg_Component_ConstructFunction*                           _construct = _MohrCoulomb_AssignFromXML;
-	Stg_Component_BuildFunction*                                   _build = _MohrCoulomb_Build;
-	Stg_Component_InitialiseFunction*                         _initialise = _MohrCoulomb_Initialise;
-	Stg_Component_ExecuteFunction*                               _execute = _YieldRheology_Execute;
-	Stg_Component_DestroyFunction*                               _destroy = _MohrCoulomb_Destroy;
-	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _MohrCoulomb_ModifyConstitutiveMatrix;
-	YieldRheology_GetYieldCriterionFunction*           _getYieldCriterion = _MohrCoulomb_GetYieldCriterion;
-	YieldRheology_GetYieldIndicatorFunction*           _getYieldIndicator = _MohrCoulomb_GetYieldIndicator;
-	YieldRheology_HasYieldedFunction*                         _hasYielded = _MohrCoulomb_HasYielded;
-
-	/* 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*) _MohrCoulomb_New(  MOHRCOULOMB_PASSARGS  );
-}
-
-void _MohrCoulomb_AssignFromXML( void* rheology, Stg_ComponentFactory* cf,
-                             void *data ){
-	MohrCoulomb*           self = (MohrCoulomb*)rheology;
-	FeVariable*            pressureField;
-	MaterialPointsSwarm*   materialPointsSwarm;
-	FeVariable*            strainRateField;
-	SwarmVariable*         swarmStrainRate;
-	
-	/* Construct Parent */
-	_YieldRheology_AssignFromXML( self, cf, data );
-
-	/* Make sure that there is strain weakening */
-	Journal_Firewall(
-		self->strainWeakening != NULL,
-		Journal_Register( Error_Type, (Name)self->type  ),
-		"Error in func '%s' for %s '%s': MohrCoulomb rheology needs strain weakening.\n", 
-		__func__, self->type, self->name );
-	
-	materialPointsSwarm    = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"MaterialPointsSwarm", MaterialPointsSwarm, True, data  );
-	pressureField          = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"PressureField", FeVariable, True, data  );
-	strainRateField = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"StrainRateField", FeVariable, True, data  );
-
-	swarmStrainRate = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"swarmStrainRate", SwarmVariable, False, data  );
-	
-	_MohrCoulomb_Init( 
-			self,
-			pressureField,
-			strainRateField,
-			swarmStrainRate,
-			materialPointsSwarm, 
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"cohesion", 0.0  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"cohesionAfterSoftening", 0.0  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"frictionCoefficient", 0.0  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"frictionCoefficientAfterSoftening", 0.0  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"minimumYieldStress", 0.0 )  );
-}
-
-void _MohrCoulomb_Build( void* rheology, void* data ) {
-	MohrCoulomb*  self               = (MohrCoulomb*) rheology;
-
-	/* Build parent */
-	_YieldRheology_Build( self, data );
-	
-	Stg_Component_Build(	self->materialPointsSwarm, data, False);
-	Stg_Component_Build(	self->pressureField, data, False);
-	Stg_Component_Build(	self->strainRateField, data, False);
-
-}
-
-void _MohrCoulomb_Initialise( void* rheology, void* data ) {
-	MohrCoulomb*     self                  = (MohrCoulomb*) rheology;
-	Particle_Index                  lParticle_I;
-	Particle_Index                  particleLocalCount;
-
-	_YieldRheology_Initialise( self, data );
-	
-	/* Initialise these components now just in case this function is called before their own _Initialise function */
-	Stg_Component_Initialise( self->materialPointsSwarm, data, False );
-	Stg_Component_Build(	self->pressureField, data, False);	
-	Stg_Component_Initialise( self->strainWeakening, data, False );
-
-	/* We don't need to Initialise hasYieldedVariable because it's a parent variable and _YieldRheology_Initialise
-	 * has already been called */
-	particleLocalCount = self->hasYieldedVariable->variable->arraySize;
-
-	/* If restarting from checkpoint, don't change the parameters on the particles */
-	if ( self->context->loadFromCheckPoint == False ) {
-		for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) { 
-			Variable_SetValueChar( self->hasYieldedVariable->variable, lParticle_I, False );
-                }
-	}
-}
-
-void _MohrCoulomb_Destroy( void* rheology, void* data ) {
-	MohrCoulomb*  self               = (MohrCoulomb*) rheology;
-
-	Stg_Component_Destroy(	self->materialPointsSwarm, data, False);
-	Stg_Component_Destroy(	self->pressureField, data, False);
-	Stg_Component_Destroy(	self->strainRateField, data, False);
-
-	/* Destroy parent */
-	_YieldRheology_Destroy( self, data );
-
-}
-	
-void _MohrCoulomb_ModifyConstitutiveMatrix( 
-		void*                                              rheology, 
-		ConstitutiveMatrix*                                constitutiveMatrix,
-		MaterialPointsSwarm*                               materialPointsSwarm,
-		Element_LocalIndex                                 lElement_I,
-		MaterialPoint*                                     materialPoint,
-		Coord                                              xi )
-{
-	MohrCoulomb*     self                  = (MohrCoulomb*) rheology;
-
-	/* Don't want to yield on the first ever solve */
-	if ( constitutiveMatrix->previousSolutionExists == False ) {
-		return;
-	}
-
-	/* Calculate and store values of stress, pressure, velocity gradients, eigenvectors so they are only calculated once */
-	_MohrCoulomb_StoreCurrentParameters( self, constitutiveMatrix, materialPointsSwarm, lElement_I, materialPoint, xi );
-
-	_YieldRheology_ModifyConstitutiveMatrix( self, constitutiveMatrix, materialPointsSwarm, lElement_I, materialPoint, xi );
-}
-
-double _MohrCoulomb_GetYieldIndicator( 
-		void*                                              rheology,
-		ConstitutiveMatrix*                                constitutiveMatrix,
-		MaterialPointsSwarm*                               materialPointsSwarm,
-		Element_LocalIndex                                 lElement_I,
-		MaterialPoint*                                     materialPoint,
-		Coord                                              xi )
-{
-	MohrCoulomb*           self             = (MohrCoulomb*) rheology;
-	Eigenvector*                          eigenvectorList  = self->currentEigenvectorList;
-	double                                sigma_ns;
-	Dimension_Index                       dim              = constitutiveMatrix->dim;
-	double                                stressMin;
-	double                                stressMax;
-
-        /* The yield indicator is simply the difference in principal
-           stresses.  In 2D, this is the 2nd invariant of the stress
-           tensor. This is not the actual shear stress.  Rather, it is
-           the terms with deviatoric stress, because that scales
-           linearly with viscosity.  So if we scale the viscosity, we
-           only affect the yield indicator. */
-
-        stressMin = eigenvectorList[0].eigenvalue;
-        stressMax = (dim == 2 ? eigenvectorList[1].eigenvalue : eigenvectorList[2].eigenvalue);
-        sigma_ns = 0.5 * ( stressMax - stressMin );
-
-        if(dim==3)
-          {
-            double alpha=_MohrCoulomb_EffectiveFrictionCoefficient( self, materialPoint );
-            double theta = 0.5 * atan( 1.0/ alpha);
-            double factor=1/(sin(2*theta) - alpha*cos(2*theta));
-
-            sigma_ns-=(stressMax+stressMin)*0.5*alpha*factor;
-          }
-	
-	return fabs(sigma_ns);
-}
-
-double _MohrCoulomb_GetYieldCriterion( 
-		void*                                              rheology,
-		ConstitutiveMatrix*                                constitutiveMatrix,
-		MaterialPointsSwarm*                               materialPointsSwarm,
-		Element_LocalIndex                                 lElement_I,
-		MaterialPoint*                                     materialPoint,
-		Coord                                              xi )
-{
-	MohrCoulomb*          self             = (MohrCoulomb*) rheology;
-	double                               minimumYieldStress;
-	double                               effectiveCohesion;
-	double                               effectiveFrictionCoefficient;
-	double                               frictionalStrength;
-
-	FeVariable*                       pressureField  = self->pressureField;  
-	double                            pressure;
-        double theta;
-        double factor;
-
-	FeVariable_InterpolateWithinElement( pressureField, lElement_I, xi, &pressure );
-
-	/* Calculate frictional strength.  We modify the friction and
-           cohesion because we have grouped terms from the normal
-           stresses and moved it to the yield indicator. */
-	effectiveFrictionCoefficient = _MohrCoulomb_EffectiveFrictionCoefficient( self, materialPoint );
-	effectiveCohesion            = _MohrCoulomb_EffectiveCohesion( self, materialPoint );
-
-        theta = 0.5 * atan( 1.0/ effectiveFrictionCoefficient);
-
-        factor=sin(2*theta);
-        
-        frictionalStrength = effectiveFrictionCoefficient * pressure*factor + effectiveCohesion*factor;
-
-        /* If the minimumYieldStress is not set, then use the
-           effective cohesion.  Maybe it should be the modified
-           effective cohesion, though that probably should not matter
-           much. */
-	minimumYieldStress = self->minimumYieldStress;
-        if(minimumYieldStress==0.0)
-          minimumYieldStress=effectiveCohesion;
-	
-	/* Make sure frictionalStrength is above the minimum */
-	if ( frictionalStrength < minimumYieldStress*factor) 
-		frictionalStrength = minimumYieldStress*factor;
-	return frictionalStrength;
-}
-
-/* This scales the viscosity so that the stress is the yield stress.
-   We can simply scale the viscosity by yieldCriterion/yieldIndicator
-   because yieldCriterion does not depend on the deviatoric stress
-   (and thus the viscosity), while the yieldIndicator depends linearly
-   on the deviatoric stresses. */
-
-void _MohrCoulomb_HasYielded( 
-		void*                                              rheology,
-		ConstitutiveMatrix*                                constitutiveMatrix,
-		MaterialPointsSwarm*                               materialPointsSwarm,
-		Element_LocalIndex                                 lElement_I,
-		MaterialPoint*                                     materialPoint,
-		double                                             yieldCriterion,
-		double                                             yieldIndicator )
-{
-  double                           viscosity = ConstitutiveMatrix_GetIsotropicViscosity( constitutiveMatrix );
-
-  double beta=1.0-yieldCriterion/(yieldIndicator);
-  double corr = -viscosity * beta;
-
-  if( (viscosity + corr) < ((MohrCoulomb*)rheology)->minVisc )
-    corr = ((MohrCoulomb*)rheology)->minVisc - viscosity;
-
-  ConstitutiveMatrix_IsotropicCorrection( constitutiveMatrix, corr );
-}
-
-double _MohrCoulomb_EffectiveCohesion( void* rheology, void* materialPoint ) {
-	MohrCoulomb*    self                          = (MohrCoulomb*) rheology;
-	double                         effectiveCohesion;
-	
-        double strainWeakeningRatio = StrainWeakening_CalcRatio( self->strainWeakening, materialPoint );
-	
-        effectiveCohesion =  self->cohesion * (1.0 - strainWeakeningRatio) + 
-          self->cohesionAfterSoftening * strainWeakeningRatio;
-
-	return effectiveCohesion;
-}
-
-double _MohrCoulomb_EffectiveFrictionCoefficient( void* rheology, void* materialPoint ) {
-	MohrCoulomb*    self                          = (MohrCoulomb*) rheology;
-	static double                  effectiveFrictionCoefficient  = 0.0;
-
-        double strainWeakeningRatio = StrainWeakening_CalcRatio( self->strainWeakening, materialPoint );
-	
-        effectiveFrictionCoefficient = self->frictionCoefficient * (1.0 - strainWeakeningRatio) +
-          self->frictionCoefficientAfterSoftening * strainWeakeningRatio;	
-
-	return effectiveFrictionCoefficient;
-}
-
-void _MohrCoulomb_StoreCurrentParameters( 
-		void*                                              rheology,
-		ConstitutiveMatrix*                                constitutiveMatrix, 
-		MaterialPointsSwarm*                               materialPointsSwarm,
-		Element_LocalIndex                                 lElement_I, 
-		MaterialPoint*                                     materialPoint,
-		Coord                                              xi ) 
-{
-	MohrCoulomb*		self = (MohrCoulomb*) rheology;
-	Dimension_Index	dim = constitutiveMatrix->dim;
-	Eigenvector			evectors[3];
-	double				trace;
-	int					i;
-	
-	FeVariable_InterpolateWithinElement( self->pressureField, lElement_I, xi, &self->currentPressure );
-	if( !self->swarmStrainRate ) {
-		FeVariable_InterpolateWithinElement( self->strainRateField, lElement_I, xi, self->currentStrainRate );
-	}
-	else {
-	   SwarmVariable_ValueAt( self->swarmStrainRate, constitutiveMatrix->currentParticleIndex, self->currentStrainRate );
-	}
-
-	SymmetricTensor_GetTrace(self->currentStrainRate, dim, &trace);
-
-	/* Subtract the trace (which should be zero anyway).  We can
-		use TensorMapST3D even for 2D, because it is the same for
-		the xx and yy components */
-	for(i=0;i<dim;++i)
-		self->currentStrainRate[TensorMapST3D[i][i]]-=trace/dim;
-
-	ConstitutiveMatrix_CalculateStress( constitutiveMatrix, self->currentStrainRate, self->currentStress );
-	
-	SymmetricTensor_CalcAllEigenvectors( self->currentStress, dim, self->currentEigenvectorList );
-
-	SymmetricTensor_CalcAllEigenvectors( self->currentStrainRate, dim, evectors);
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/MohrCoulomb.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/MohrCoulomb.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,411 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: MohrCoulomb.c 11997 2008-05-22 18:16:17Z walter $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "RheologyClass.h"
+#include "StrainWeakening.h"
+#include "YieldRheology.h"
+#include "MohrCoulomb.h"
+#include "ConstitutiveMatrix.h"
+
+#include <assert.h>
+#include <string.h>
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type MohrCoulomb_Type = "MohrCoulomb";
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+MohrCoulomb* _MohrCoulomb_New(  MOHRCOULOMB_DEFARGS  ) 
+{
+	MohrCoulomb*					self;
+
+	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+	assert( _sizeOfSelf >= sizeof(MohrCoulomb) );
+	self = (MohrCoulomb*) _YieldRheology_New(  YIELDRHEOLOGY_PASSARGS  );
+	
+	/* Function pointers for this class that are not on the parent class should be set here */
+	
+	return self;
+}
+
+void _MohrCoulomb_Init(    
+		MohrCoulomb*          self,
+		FeVariable*           pressureField,
+		FeVariable*           strainRateField,
+		SwarmVariable*        swarmStrainRate,
+		MaterialPointsSwarm*  materialPointsSwarm,
+		double                cohesion,
+		double                cohesionAfterSoftening,
+		double                frictionCoefficient,
+		double                frictionCoefficientAfterSoftening,
+		double                minimumYieldStress)
+{                                                       
+	self->materialPointsSwarm     = materialPointsSwarm;
+	self->pressureField           = pressureField;
+	self->strainRateField  = strainRateField;
+	
+	self->cohesion = cohesion;
+	self->frictionCoefficient = frictionCoefficient;
+	
+	/* Strain softening of Cohesion - (linear weakening is assumed) */
+	/* needs a softening factor between +0 and 1 and a reference strain > 0 */
+	self->cohesionAfterSoftening = cohesionAfterSoftening;
+	
+	/* Strain softening of Friction - (linear weakening is assumed) */
+	/* needs a softening factor between +0 and 1 and a reference strain > 0 */
+	self->frictionCoefficientAfterSoftening = frictionCoefficientAfterSoftening;
+
+	self->minimumYieldStress = minimumYieldStress;
+}
+
+void* _MohrCoulomb_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                     _sizeOfSelf = sizeof(MohrCoulomb);
+	Type                                                             type = MohrCoulomb_Type;
+	Stg_Class_DeleteFunction*                                     _delete = _YieldRheology_Delete;
+	Stg_Class_PrintFunction*                                       _print = _YieldRheology_Print;
+	Stg_Class_CopyFunction*                                         _copy = _YieldRheology_Copy;
+	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _MohrCoulomb_DefaultNew;
+	Stg_Component_ConstructFunction*                           _construct = _MohrCoulomb_AssignFromXML;
+	Stg_Component_BuildFunction*                                   _build = _MohrCoulomb_Build;
+	Stg_Component_InitialiseFunction*                         _initialise = _MohrCoulomb_Initialise;
+	Stg_Component_ExecuteFunction*                               _execute = _YieldRheology_Execute;
+	Stg_Component_DestroyFunction*                               _destroy = _MohrCoulomb_Destroy;
+	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _MohrCoulomb_ModifyConstitutiveMatrix;
+	YieldRheology_GetYieldCriterionFunction*           _getYieldCriterion = _MohrCoulomb_GetYieldCriterion;
+	YieldRheology_GetYieldIndicatorFunction*           _getYieldIndicator = _MohrCoulomb_GetYieldIndicator;
+	YieldRheology_HasYieldedFunction*                         _hasYielded = _MohrCoulomb_HasYielded;
+
+	/* 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*) _MohrCoulomb_New(  MOHRCOULOMB_PASSARGS  );
+}
+
+void _MohrCoulomb_AssignFromXML( void* rheology, Stg_ComponentFactory* cf,
+                             void *data ){
+	MohrCoulomb*           self = (MohrCoulomb*)rheology;
+	FeVariable*            pressureField;
+	MaterialPointsSwarm*   materialPointsSwarm;
+	FeVariable*            strainRateField;
+	SwarmVariable*         swarmStrainRate;
+	
+	/* Construct Parent */
+	_YieldRheology_AssignFromXML( self, cf, data );
+
+	/* Make sure that there is strain weakening */
+	Journal_Firewall(
+		self->strainWeakening != NULL,
+		Journal_Register( Error_Type, (Name)self->type  ),
+		"Error in func '%s' for %s '%s': MohrCoulomb rheology needs strain weakening.\n", 
+		__func__, self->type, self->name );
+	
+	materialPointsSwarm    = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"MaterialPointsSwarm", MaterialPointsSwarm, True, data  );
+	pressureField          = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"PressureField", FeVariable, True, data  );
+	strainRateField = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"StrainRateField", FeVariable, True, data  );
+
+	swarmStrainRate = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"swarmStrainRate", SwarmVariable, False, data  );
+	
+	_MohrCoulomb_Init( 
+			self,
+			pressureField,
+			strainRateField,
+			swarmStrainRate,
+			materialPointsSwarm, 
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"cohesion", 0.0  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"cohesionAfterSoftening", 0.0  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"frictionCoefficient", 0.0  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"frictionCoefficientAfterSoftening", 0.0  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"minimumYieldStress", 0.0 )  );
+}
+
+void _MohrCoulomb_Build( void* rheology, void* data ) {
+	MohrCoulomb*  self               = (MohrCoulomb*) rheology;
+
+	/* Build parent */
+	_YieldRheology_Build( self, data );
+	
+	Stg_Component_Build(	self->materialPointsSwarm, data, False);
+	Stg_Component_Build(	self->pressureField, data, False);
+	Stg_Component_Build(	self->strainRateField, data, False);
+
+}
+
+void _MohrCoulomb_Initialise( void* rheology, void* data ) {
+	MohrCoulomb*     self                  = (MohrCoulomb*) rheology;
+	Particle_Index                  lParticle_I;
+	Particle_Index                  particleLocalCount;
+
+	_YieldRheology_Initialise( self, data );
+	
+	/* Initialise these components now just in case this function is called before their own _Initialise function */
+	Stg_Component_Initialise( self->materialPointsSwarm, data, False );
+	Stg_Component_Build(	self->pressureField, data, False);	
+	Stg_Component_Initialise( self->strainWeakening, data, False );
+
+	/* We don't need to Initialise hasYieldedVariable because it's a parent variable and _YieldRheology_Initialise
+	 * has already been called */
+	particleLocalCount = self->hasYieldedVariable->variable->arraySize;
+
+	/* If restarting from checkpoint, don't change the parameters on the particles */
+	if ( self->context->loadFromCheckPoint == False ) {
+		for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) { 
+			Variable_SetValueChar( self->hasYieldedVariable->variable, lParticle_I, False );
+                }
+	}
+}
+
+void _MohrCoulomb_Destroy( void* rheology, void* data ) {
+	MohrCoulomb*  self               = (MohrCoulomb*) rheology;
+
+	Stg_Component_Destroy(	self->materialPointsSwarm, data, False);
+	Stg_Component_Destroy(	self->pressureField, data, False);
+	Stg_Component_Destroy(	self->strainRateField, data, False);
+
+	/* Destroy parent */
+	_YieldRheology_Destroy( self, data );
+
+}
+	
+void _MohrCoulomb_ModifyConstitutiveMatrix( 
+		void*                                              rheology, 
+		ConstitutiveMatrix*                                constitutiveMatrix,
+		MaterialPointsSwarm*                               materialPointsSwarm,
+		Element_LocalIndex                                 lElement_I,
+		MaterialPoint*                                     materialPoint,
+		Coord                                              xi )
+{
+	MohrCoulomb*     self                  = (MohrCoulomb*) rheology;
+
+	/* Don't want to yield on the first ever solve */
+	if ( constitutiveMatrix->previousSolutionExists == False ) {
+		return;
+	}
+
+	/* Calculate and store values of stress, pressure, velocity gradients, eigenvectors so they are only calculated once */
+	_MohrCoulomb_StoreCurrentParameters( self, constitutiveMatrix, materialPointsSwarm, lElement_I, materialPoint, xi );
+
+	_YieldRheology_ModifyConstitutiveMatrix( self, constitutiveMatrix, materialPointsSwarm, lElement_I, materialPoint, xi );
+}
+
+double _MohrCoulomb_GetYieldIndicator( 
+		void*                                              rheology,
+		ConstitutiveMatrix*                                constitutiveMatrix,
+		MaterialPointsSwarm*                               materialPointsSwarm,
+		Element_LocalIndex                                 lElement_I,
+		MaterialPoint*                                     materialPoint,
+		Coord                                              xi )
+{
+	MohrCoulomb*           self             = (MohrCoulomb*) rheology;
+	Eigenvector*                          eigenvectorList  = self->currentEigenvectorList;
+	double                                sigma_ns;
+	Dimension_Index                       dim              = constitutiveMatrix->dim;
+	double                                stressMin;
+	double                                stressMax;
+
+        /* The yield indicator is simply the difference in principal
+           stresses.  In 2D, this is the 2nd invariant of the stress
+           tensor. This is not the actual shear stress.  Rather, it is
+           the terms with deviatoric stress, because that scales
+           linearly with viscosity.  So if we scale the viscosity, we
+           only affect the yield indicator. */
+
+        stressMin = eigenvectorList[0].eigenvalue;
+        stressMax = (dim == 2 ? eigenvectorList[1].eigenvalue : eigenvectorList[2].eigenvalue);
+        sigma_ns = 0.5 * ( stressMax - stressMin );
+
+        if(dim==3)
+          {
+            double alpha=_MohrCoulomb_EffectiveFrictionCoefficient( self, materialPoint );
+            double theta = 0.5 * atan( 1.0/ alpha);
+            double factor=1/(sin(2*theta) - alpha*cos(2*theta));
+
+            sigma_ns-=(stressMax+stressMin)*0.5*alpha*factor;
+          }
+	
+	return fabs(sigma_ns);
+}
+
+double _MohrCoulomb_GetYieldCriterion( 
+		void*                                              rheology,
+		ConstitutiveMatrix*                                constitutiveMatrix,
+		MaterialPointsSwarm*                               materialPointsSwarm,
+		Element_LocalIndex                                 lElement_I,
+		MaterialPoint*                                     materialPoint,
+		Coord                                              xi )
+{
+	MohrCoulomb*          self             = (MohrCoulomb*) rheology;
+	double                               minimumYieldStress;
+	double                               effectiveCohesion;
+	double                               effectiveFrictionCoefficient;
+	double                               frictionalStrength;
+
+	FeVariable*                       pressureField  = self->pressureField;  
+	double                            pressure;
+        double theta;
+        double factor;
+
+	FeVariable_InterpolateWithinElement( pressureField, lElement_I, xi, &pressure );
+
+	/* Calculate frictional strength.  We modify the friction and
+           cohesion because we have grouped terms from the normal
+           stresses and moved it to the yield indicator. */
+	effectiveFrictionCoefficient = _MohrCoulomb_EffectiveFrictionCoefficient( self, materialPoint );
+	effectiveCohesion            = _MohrCoulomb_EffectiveCohesion( self, materialPoint );
+
+        theta = 0.5 * atan( 1.0/ effectiveFrictionCoefficient);
+
+        factor=sin(2*theta);
+        
+        frictionalStrength = effectiveFrictionCoefficient * pressure*factor + effectiveCohesion*factor;
+
+        /* If the minimumYieldStress is not set, then use the
+           effective cohesion.  Maybe it should be the modified
+           effective cohesion, though that probably should not matter
+           much. */
+	minimumYieldStress = self->minimumYieldStress;
+        if(minimumYieldStress==0.0)
+          minimumYieldStress=effectiveCohesion;
+	
+	/* Make sure frictionalStrength is above the minimum */
+	if ( frictionalStrength < minimumYieldStress*factor) 
+		frictionalStrength = minimumYieldStress*factor;
+	return frictionalStrength;
+}
+
+/* This scales the viscosity so that the stress is the yield stress.
+   We can simply scale the viscosity by yieldCriterion/yieldIndicator
+   because yieldCriterion does not depend on the deviatoric stress
+   (and thus the viscosity), while the yieldIndicator depends linearly
+   on the deviatoric stresses. */
+
+void _MohrCoulomb_HasYielded( 
+		void*                                              rheology,
+		ConstitutiveMatrix*                                constitutiveMatrix,
+		MaterialPointsSwarm*                               materialPointsSwarm,
+		Element_LocalIndex                                 lElement_I,
+		MaterialPoint*                                     materialPoint,
+		double                                             yieldCriterion,
+		double                                             yieldIndicator )
+{
+  double                           viscosity = ConstitutiveMatrix_GetIsotropicViscosity( constitutiveMatrix );
+
+  double beta=1.0-yieldCriterion/(yieldIndicator);
+  double corr = -viscosity * beta;
+
+  if( (viscosity + corr) < ((MohrCoulomb*)rheology)->minVisc )
+    corr = ((MohrCoulomb*)rheology)->minVisc - viscosity;
+
+  ConstitutiveMatrix_IsotropicCorrection( constitutiveMatrix, corr );
+}
+
+double _MohrCoulomb_EffectiveCohesion( void* rheology, void* materialPoint ) {
+	MohrCoulomb*    self                          = (MohrCoulomb*) rheology;
+	double                         effectiveCohesion;
+	
+        double strainWeakeningRatio = StrainWeakening_CalcRatio( self->strainWeakening, materialPoint );
+	
+        effectiveCohesion =  self->cohesion * (1.0 - strainWeakeningRatio) + 
+          self->cohesionAfterSoftening * strainWeakeningRatio;
+
+	return effectiveCohesion;
+}
+
+double _MohrCoulomb_EffectiveFrictionCoefficient( void* rheology, void* materialPoint ) {
+	MohrCoulomb*    self                          = (MohrCoulomb*) rheology;
+	static double                  effectiveFrictionCoefficient  = 0.0;
+
+        double strainWeakeningRatio = StrainWeakening_CalcRatio( self->strainWeakening, materialPoint );
+	
+        effectiveFrictionCoefficient = self->frictionCoefficient * (1.0 - strainWeakeningRatio) +
+          self->frictionCoefficientAfterSoftening * strainWeakeningRatio;	
+
+	return effectiveFrictionCoefficient;
+}
+
+void _MohrCoulomb_StoreCurrentParameters( 
+		void*                                              rheology,
+		ConstitutiveMatrix*                                constitutiveMatrix, 
+		MaterialPointsSwarm*                               materialPointsSwarm,
+		Element_LocalIndex                                 lElement_I, 
+		MaterialPoint*                                     materialPoint,
+		Coord                                              xi ) 
+{
+	MohrCoulomb*		self = (MohrCoulomb*) rheology;
+	Dimension_Index	dim = constitutiveMatrix->dim;
+	Eigenvector			evectors[3];
+	double				trace;
+	int					i;
+	
+	FeVariable_InterpolateWithinElement( self->pressureField, lElement_I, xi, &self->currentPressure );
+	if( !self->swarmStrainRate ) {
+		FeVariable_InterpolateWithinElement( self->strainRateField, lElement_I, xi, self->currentStrainRate );
+	}
+	else {
+	   SwarmVariable_ValueAt( self->swarmStrainRate, constitutiveMatrix->currentParticleIndex, self->currentStrainRate );
+	}
+
+	SymmetricTensor_GetTrace(self->currentStrainRate, dim, &trace);
+
+	/* Subtract the trace (which should be zero anyway).  We can
+		use TensorMapST3D even for 2D, because it is the same for
+		the xx and yy components */
+	for(i=0;i<dim;++i)
+		self->currentStrainRate[TensorMapST3D[i][i]]-=trace/dim;
+
+	ConstitutiveMatrix_CalculateStress( constitutiveMatrix, self->currentStrainRate, self->currentStress );
+	
+	SymmetricTensor_CalcAllEigenvectors( self->currentStress, dim, self->currentEigenvectorList );
+
+	SymmetricTensor_CalcAllEigenvectors( self->currentStrainRate, dim, evectors);
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/MultiRheologyMaterial.c
--- a/Rheology/src/MultiRheologyMaterial.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,264 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: MultiRheologyMaterial.c 610 2007-10-11 08:09:29Z SteveQuenette $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "RheologyMaterial.h"
-#include "Rheology_Register.h"
-#include "MultiRheologyMaterial.h"
-#include "ConstitutiveMatrix.h"
-#include "Compressible.h"
-#include "RheologyClass.h"
-
-#include <assert.h>
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type MultiRheologyMaterial_Type = "MultiRheologyMaterial";
-
-
-MultiRheologyMaterial* MultiRheologyMaterial_New( 
-	Name						name,
-	PICelleratorContext*	context,
-	Stg_Shape*				shape,
-	Dictionary*				materialDictionary,
-	Materials_Register*	materialRegister,
-	Rheology**				rheologyList,
-	Rheology_Index			rheologyCount,
-	Compressible*			compressible,
-	Rheology***				rheologyListList,
-	Rheology_Index*		rheologyCountList, 
-	Index						rheologyListCount ) 
-{
-  MultiRheologyMaterial* self = (MultiRheologyMaterial*)_MultiRheologyMaterial_DefaultNew( name );
-
-	self->isConstructed = True;
-	_Material_Init( self, context, shape, materialDictionary, materialRegister );
-   _RheologyMaterial_Init( self, rheologyList, rheologyCount, compressible, False );
-	_MultiRheologyMaterial_Init( self, rheologyListList, rheologyCountList, rheologyListCount );
-	
-	return self;
-}
-
-
-void* _MultiRheologyMaterial_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(MultiRheologyMaterial);
-	Type                                                      type = MultiRheologyMaterial_Type;
-	Stg_Class_DeleteFunction*                              _delete = _RheologyMaterial_Delete;
-	Stg_Class_PrintFunction*                                _print = _RheologyMaterial_Print;
-	Stg_Class_CopyFunction*                                  _copy = _RheologyMaterial_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _MultiRheologyMaterial_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _MultiRheologyMaterial_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _RheologyMaterial_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _RheologyMaterial_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _RheologyMaterial_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _MultiRheologyMaterial_Destroy;
-	RheologyMaterial_RunRheologiesFunction*         _runRheologies = _MultiRheologyMaterial_RunRheologies;
-
-	/* 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*) _MultiRheologyMaterial_New(  MULTIRHEOLOGYMATERIAL_PASSARGS  );
-}
-
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-MultiRheologyMaterial* _MultiRheologyMaterial_New(  MULTIRHEOLOGYMATERIAL_DEFARGS  ) 
-{
-	MultiRheologyMaterial*					self;
-
-	/* Call private constructor of parent - this will set virtual functions of parent and continue up
-	 *  the hierarchy tree. At the beginning of the tree it will allocate memory of the size of
-	 *  object and initialise all the memory to zero. */
-	assert( _sizeOfSelf >= sizeof(MultiRheologyMaterial) );
-	self = (MultiRheologyMaterial*) _RheologyMaterial_New(  RHEOLOGYMATERIAL_PASSARGS  );
-
-	return self;
-}
-
-
-void _MultiRheologyMaterial_AssignFromXML( void* material, Stg_ComponentFactory* cf, void* data ){
-	MultiRheologyMaterial*  self = (MultiRheologyMaterial*)material;
-	Rheology***             rheologyListList;
-	Rheology_Index*         rheologyCountList;
-	Index                   rheologyListCount;
-	Index                   rheologyList_I;
-	Dictionary*             currDictionary = Dictionary_GetDictionary( cf->componentDict, self->name );
-	Name                    rheologyName;
-	Dictionary_Entry_Value* multiRheologyList;
-	Dictionary_Entry_Value* rheologyList;
-	Dictionary_Entry_Value* rheologyEntry;
-	Rheology_Index          rheology_I;
-	Stream*                 stream = cf->infoStream;
-
-	_RheologyMaterial_AssignFromXML( self, cf, data );
-
-	multiRheologyList = Dictionary_Get( currDictionary, (Dictionary_Entry_Key)"MultiRheologies"  );
-	Journal_Firewall(
-		multiRheologyList != NULL,
-		Journal_Register( Error_Type, (Name)self->type  ),
-		"Error in func '%s' for %s '%s': MultiRheologyMaterial rheology needs a rheology list.\n", 
-		__func__, self->type, self->name );
-	
-	rheologyListCount = Dictionary_Entry_Value_GetCount( multiRheologyList );
-
-	rheologyCountList = Memory_Alloc_Array( Rheology_Index, rheologyListCount, "rheologyCountList" );
-	rheologyListList = Memory_Alloc_Array( Rheology**, rheologyListCount, "rheologyListList" );
-			
-	Journal_PrintfL( stream, 2, "%s '%s' has %u rheological components.\n", self->type, self->name, rheologyListCount );
-	Stream_Indent( stream );
-
-	for ( rheologyList_I = 0 ; rheologyList_I < rheologyListCount ; rheologyList_I++ ){
-		rheologyList = Dictionary_Entry_Value_GetElement( multiRheologyList, rheologyList_I );
-		rheologyCountList[ rheologyList_I ] = Dictionary_Entry_Value_GetCount( rheologyList );
-	 rheologyListList[ rheologyList_I ] = Memory_Alloc_Array( Rheology*, rheologyCountList[ rheologyList_I ], "rheologyList" );
-	
-		Journal_PrintfL( stream, 2, "%s \"%s's\" rheological component '%u' has %u rheologies.\n", 
-				self->type, self->name, rheologyList_I, rheologyCountList[ rheologyList_I ] );
-
-		Stream_Indent( stream );
-		for ( rheology_I = 0 ; rheology_I < rheologyCountList[ rheologyList_I ] ; rheology_I++ ) {
-			rheologyEntry = Dictionary_Entry_Value_GetElement( rheologyList, rheology_I );
-
-			rheologyName = Dictionary_Entry_Value_AsString( rheologyEntry );
-		
-			Journal_PrintfL( stream, 2, "Rheological component '%u' for %s '%s' needs rheology: '%s'.\n", 
-				rheologyList_I, self->type, self->name, rheologyName );
-
-			rheologyListList[ rheologyList_I ][ rheology_I ] = 
-	Stg_ComponentFactory_ConstructByName( cf, (Name)rheologyName, Rheology, True, data ); 
-		}
-		Stream_UnIndent( stream );
-	}
-	Stream_UnIndent( stream  );
-	
-	_MultiRheologyMaterial_Init( 
-			self,
-			rheologyListList,
-			rheologyCountList,
-			rheologyListCount );
-
-	/* Clean up */
-	for ( rheologyList_I = 0 ; rheologyList_I < rheologyListCount ; rheologyList_I++ ){
-		Memory_Free( rheologyListList[ rheologyList_I ] );
-	}
-	Memory_Free( rheologyListList );
-	Memory_Free( rheologyCountList );
-}
-
-
-void _MultiRheologyMaterial_Init( 
-		MultiRheologyMaterial*  self, 
-		Rheology***             rheologyListList,
-		Rheology_Index*         rheologyCountList, 
-		Index                   rheologyListCount ) 
-{
-	Index          rheology_Register_I;
-	Rheology_Index rheology_I;
-	Rheology*      rheology;
-
-	self->rheology_RegisterCount = rheologyListCount;
-	self->rheology_RegisterList = Memory_Alloc_Array( Rheology_Register*, rheologyListCount, "rheology_RegisterList" );
-	for ( rheology_Register_I = 0 ; rheology_Register_I < rheologyListCount ; rheology_Register_I++ ) {
-		self->rheology_RegisterList[ rheology_Register_I ] = Rheology_Register_New();
-
-		for ( rheology_I = 0 ; rheology_I < rheologyCountList[ rheology_Register_I ] ; rheology_I++ ) {
-			rheology = rheologyListList[ rheology_Register_I ][ rheology_I ];
-			Rheology_Register_Add( self->rheology_Register, rheology );
-			Rheology_Register_Add( self->rheology_RegisterList[ rheology_Register_I ], rheology );
-		}
-	}
-}
-
-
-void _MultiRheologyMaterial_Destroy( void* material, void* data ){
-	MultiRheologyMaterial*  self = (MultiRheologyMaterial*)material;
-	Index                   rheology_Register_I;
-
-	for ( rheology_Register_I = 0 ; rheology_Register_I < self->rheology_RegisterCount ; rheology_Register_I++ ) {
-		Stg_Component_Destroy( self->rheology_RegisterList[ rheology_Register_I ], data, False );
-	}
-	Memory_Free( self->rheology_RegisterList );
-
-	_RheologyMaterial_Destroy( self, data );
-}
-
-
-void _MultiRheologyMaterial_RunRheologies( 	
-		void*                                              material,
-		ConstitutiveMatrix*                                constitutiveMatrix,
-		MaterialPointsSwarm*                               swarm,
-		Element_LocalIndex                                 lElement_I,
-		MaterialPoint*                                     materialPoint,
-		Coord                                              xi )
-{
-	MultiRheologyMaterial*   self                   = (MultiRheologyMaterial*) material;
-	Index                    rheology_RegisterCount = self->rheology_RegisterCount;
-	Index                    rheology_Register_I;
-	double                   oneOnViscosity         = 0.0;
-
-	for ( rheology_Register_I = 0 ; rheology_Register_I < rheology_RegisterCount ; rheology_Register_I++ ) {
-		/* Calculate Isotropic Viscosity for this rheology register */
-		Rheology_Register_RunRheologies( 
-				self->rheology_RegisterList[ rheology_Register_I ],
-				constitutiveMatrix,
-				swarm, 
-				lElement_I,
-				materialPoint,
-				xi );
-
-		oneOnViscosity += 1.0/ConstitutiveMatrix_GetIsotropicViscosity( constitutiveMatrix );
-		
-		/* Initialise for next run through */
-		ConstitutiveMatrix_ZeroMatrix( constitutiveMatrix );
-	}
-
-	ConstitutiveMatrix_SetIsotropicViscosity( constitutiveMatrix, 1.0/oneOnViscosity );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/MultiRheologyMaterial.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/MultiRheologyMaterial.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,264 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: MultiRheologyMaterial.c 610 2007-10-11 08:09:29Z SteveQuenette $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "RheologyMaterial.h"
+#include "Rheology_Register.h"
+#include "MultiRheologyMaterial.h"
+#include "ConstitutiveMatrix.h"
+#include "Compressible.h"
+#include "RheologyClass.h"
+
+#include <assert.h>
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type MultiRheologyMaterial_Type = "MultiRheologyMaterial";
+
+
+MultiRheologyMaterial* MultiRheologyMaterial_New( 
+	Name						name,
+	PICelleratorContext*	context,
+	Stg_Shape*				shape,
+	Dictionary*				materialDictionary,
+	Materials_Register*	materialRegister,
+	Rheology**				rheologyList,
+	Rheology_Index			rheologyCount,
+	Compressible*			compressible,
+	Rheology***				rheologyListList,
+	Rheology_Index*		rheologyCountList, 
+	Index						rheologyListCount ) 
+{
+  MultiRheologyMaterial* self = (MultiRheologyMaterial*)_MultiRheologyMaterial_DefaultNew( name );
+
+	self->isConstructed = True;
+	_Material_Init( self, context, shape, materialDictionary, materialRegister );
+   _RheologyMaterial_Init( self, rheologyList, rheologyCount, compressible, False );
+	_MultiRheologyMaterial_Init( self, rheologyListList, rheologyCountList, rheologyListCount );
+	
+	return self;
+}
+
+
+void* _MultiRheologyMaterial_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(MultiRheologyMaterial);
+	Type                                                      type = MultiRheologyMaterial_Type;
+	Stg_Class_DeleteFunction*                              _delete = _RheologyMaterial_Delete;
+	Stg_Class_PrintFunction*                                _print = _RheologyMaterial_Print;
+	Stg_Class_CopyFunction*                                  _copy = _RheologyMaterial_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _MultiRheologyMaterial_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _MultiRheologyMaterial_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _RheologyMaterial_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _RheologyMaterial_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _RheologyMaterial_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _MultiRheologyMaterial_Destroy;
+	RheologyMaterial_RunRheologiesFunction*         _runRheologies = _MultiRheologyMaterial_RunRheologies;
+
+	/* 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*) _MultiRheologyMaterial_New(  MULTIRHEOLOGYMATERIAL_PASSARGS  );
+}
+
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+MultiRheologyMaterial* _MultiRheologyMaterial_New(  MULTIRHEOLOGYMATERIAL_DEFARGS  ) 
+{
+	MultiRheologyMaterial*					self;
+
+	/* Call private constructor of parent - this will set virtual functions of parent and continue up
+	 *  the hierarchy tree. At the beginning of the tree it will allocate memory of the size of
+	 *  object and initialise all the memory to zero. */
+	assert( _sizeOfSelf >= sizeof(MultiRheologyMaterial) );
+	self = (MultiRheologyMaterial*) _RheologyMaterial_New(  RHEOLOGYMATERIAL_PASSARGS  );
+
+	return self;
+}
+
+
+void _MultiRheologyMaterial_AssignFromXML( void* material, Stg_ComponentFactory* cf, void* data ){
+	MultiRheologyMaterial*  self = (MultiRheologyMaterial*)material;
+	Rheology***             rheologyListList;
+	Rheology_Index*         rheologyCountList;
+	Index                   rheologyListCount;
+	Index                   rheologyList_I;
+	Dictionary*             currDictionary = Dictionary_GetDictionary( cf->componentDict, self->name );
+	Name                    rheologyName;
+	Dictionary_Entry_Value* multiRheologyList;
+	Dictionary_Entry_Value* rheologyList;
+	Dictionary_Entry_Value* rheologyEntry;
+	Rheology_Index          rheology_I;
+	Stream*                 stream = cf->infoStream;
+
+	_RheologyMaterial_AssignFromXML( self, cf, data );
+
+	multiRheologyList = Dictionary_Get( currDictionary, (Dictionary_Entry_Key)"MultiRheologies"  );
+	Journal_Firewall(
+		multiRheologyList != NULL,
+		Journal_Register( Error_Type, (Name)self->type  ),
+		"Error in func '%s' for %s '%s': MultiRheologyMaterial rheology needs a rheology list.\n", 
+		__func__, self->type, self->name );
+	
+	rheologyListCount = Dictionary_Entry_Value_GetCount( multiRheologyList );
+
+	rheologyCountList = Memory_Alloc_Array( Rheology_Index, rheologyListCount, "rheologyCountList" );
+	rheologyListList = Memory_Alloc_Array( Rheology**, rheologyListCount, "rheologyListList" );
+			
+	Journal_PrintfL( stream, 2, "%s '%s' has %u rheological components.\n", self->type, self->name, rheologyListCount );
+	Stream_Indent( stream );
+
+	for ( rheologyList_I = 0 ; rheologyList_I < rheologyListCount ; rheologyList_I++ ){
+		rheologyList = Dictionary_Entry_Value_GetElement( multiRheologyList, rheologyList_I );
+		rheologyCountList[ rheologyList_I ] = Dictionary_Entry_Value_GetCount( rheologyList );
+	 rheologyListList[ rheologyList_I ] = Memory_Alloc_Array( Rheology*, rheologyCountList[ rheologyList_I ], "rheologyList" );
+	
+		Journal_PrintfL( stream, 2, "%s \"%s's\" rheological component '%u' has %u rheologies.\n", 
+				self->type, self->name, rheologyList_I, rheologyCountList[ rheologyList_I ] );
+
+		Stream_Indent( stream );
+		for ( rheology_I = 0 ; rheology_I < rheologyCountList[ rheologyList_I ] ; rheology_I++ ) {
+			rheologyEntry = Dictionary_Entry_Value_GetElement( rheologyList, rheology_I );
+
+			rheologyName = Dictionary_Entry_Value_AsString( rheologyEntry );
+		
+			Journal_PrintfL( stream, 2, "Rheological component '%u' for %s '%s' needs rheology: '%s'.\n", 
+				rheologyList_I, self->type, self->name, rheologyName );
+
+			rheologyListList[ rheologyList_I ][ rheology_I ] = 
+	Stg_ComponentFactory_ConstructByName( cf, (Name)rheologyName, Rheology, True, data ); 
+		}
+		Stream_UnIndent( stream );
+	}
+	Stream_UnIndent( stream  );
+	
+	_MultiRheologyMaterial_Init( 
+			self,
+			rheologyListList,
+			rheologyCountList,
+			rheologyListCount );
+
+	/* Clean up */
+	for ( rheologyList_I = 0 ; rheologyList_I < rheologyListCount ; rheologyList_I++ ){
+		Memory_Free( rheologyListList[ rheologyList_I ] );
+	}
+	Memory_Free( rheologyListList );
+	Memory_Free( rheologyCountList );
+}
+
+
+void _MultiRheologyMaterial_Init( 
+		MultiRheologyMaterial*  self, 
+		Rheology***             rheologyListList,
+		Rheology_Index*         rheologyCountList, 
+		Index                   rheologyListCount ) 
+{
+	Index          rheology_Register_I;
+	Rheology_Index rheology_I;
+	Rheology*      rheology;
+
+	self->rheology_RegisterCount = rheologyListCount;
+	self->rheology_RegisterList = Memory_Alloc_Array( Rheology_Register*, rheologyListCount, "rheology_RegisterList" );
+	for ( rheology_Register_I = 0 ; rheology_Register_I < rheologyListCount ; rheology_Register_I++ ) {
+		self->rheology_RegisterList[ rheology_Register_I ] = Rheology_Register_New();
+
+		for ( rheology_I = 0 ; rheology_I < rheologyCountList[ rheology_Register_I ] ; rheology_I++ ) {
+			rheology = rheologyListList[ rheology_Register_I ][ rheology_I ];
+			Rheology_Register_Add( self->rheology_Register, rheology );
+			Rheology_Register_Add( self->rheology_RegisterList[ rheology_Register_I ], rheology );
+		}
+	}
+}
+
+
+void _MultiRheologyMaterial_Destroy( void* material, void* data ){
+	MultiRheologyMaterial*  self = (MultiRheologyMaterial*)material;
+	Index                   rheology_Register_I;
+
+	for ( rheology_Register_I = 0 ; rheology_Register_I < self->rheology_RegisterCount ; rheology_Register_I++ ) {
+		Stg_Component_Destroy( self->rheology_RegisterList[ rheology_Register_I ], data, False );
+	}
+	Memory_Free( self->rheology_RegisterList );
+
+	_RheologyMaterial_Destroy( self, data );
+}
+
+
+void _MultiRheologyMaterial_RunRheologies( 	
+		void*                                              material,
+		ConstitutiveMatrix*                                constitutiveMatrix,
+		MaterialPointsSwarm*                               swarm,
+		Element_LocalIndex                                 lElement_I,
+		MaterialPoint*                                     materialPoint,
+		Coord                                              xi )
+{
+	MultiRheologyMaterial*   self                   = (MultiRheologyMaterial*) material;
+	Index                    rheology_RegisterCount = self->rheology_RegisterCount;
+	Index                    rheology_Register_I;
+	double                   oneOnViscosity         = 0.0;
+
+	for ( rheology_Register_I = 0 ; rheology_Register_I < rheology_RegisterCount ; rheology_Register_I++ ) {
+		/* Calculate Isotropic Viscosity for this rheology register */
+		Rheology_Register_RunRheologies( 
+				self->rheology_RegisterList[ rheology_Register_I ],
+				constitutiveMatrix,
+				swarm, 
+				lElement_I,
+				materialPoint,
+				xi );
+
+		oneOnViscosity += 1.0/ConstitutiveMatrix_GetIsotropicViscosity( constitutiveMatrix );
+		
+		/* Initialise for next run through */
+		ConstitutiveMatrix_ZeroMatrix( constitutiveMatrix );
+	}
+
+	ConstitutiveMatrix_SetIsotropicViscosity( constitutiveMatrix, 1.0/oneOnViscosity );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/NonNewtonian.c
--- a/Rheology/src/NonNewtonian.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,251 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: NonNewtonian.c 610 2007-10-11 08:09:29Z SteveQuenette $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "RheologyClass.h"
-#include "NonNewtonian.h"
-#include "ConstitutiveMatrix.h"
-
-#include <assert.h>
-#include <float.h>
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type NonNewtonian_Type = "NonNewtonian";
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-NonNewtonian* _NonNewtonian_New(  NONNEWTONIAN_DEFARGS  ) 
-{
-	NonNewtonian*					self;
-
-	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-	assert( _sizeOfSelf >= sizeof(NonNewtonian) );
-	self = (NonNewtonian*) _Rheology_New(  RHEOLOGY_PASSARGS  );
-	
-	return self;
-}
-
-void _NonNewtonian_Init( NonNewtonian* self, FeVariable* strainRateInvField,
-                         FeVariable* temperatureField,
-                         double n,
-                         double T_0,
-                         double T_melt,
-                         double A,
-                         double refStrainRate,
-                         double minViscosity,
-                         double maxViscosity) {
-
-	self->strainRateInvField = strainRateInvField;
-	self->temperatureField = temperatureField;
-
-	self->n = n;
-	self->T_0 = T_0;
-	self->T_melt = T_melt;
-	self->A = A;
-	self->refStrainRate = refStrainRate;
-	self->minViscosity = minViscosity;
-	self->maxViscosity = maxViscosity;
-
-	Rheology_SetToNonLinear( self );
-}
-
-void _NonNewtonian_Build( void* _self, void* data ){
-	NonNewtonian*  self = (NonNewtonian*)_self;
-
-	_Rheology_Build( self, data );
-	
-   Stg_Component_Build( self->strainRateInvField, data, False );
-}
-
-void _NonNewtonian_Initialise( void* _self, void* data ){
-	NonNewtonian*  self = (NonNewtonian*)_self;
-
-   _Rheology_Initialise( self, data );
-
-   Stg_Component_Initialise( self->strainRateInvField, data, False );
-}
-
-void _NonNewtonian_Destroy( void* _self, void* data ){
-	NonNewtonian*  self = (NonNewtonian*)_self;
-
-   Stg_Component_Destroy( self->strainRateInvField, data, False );
-
-	_Rheology_Destroy( self, data );
-}
-
-
-void* _NonNewtonian_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                     _sizeOfSelf = sizeof(NonNewtonian);
-	Type                                                             type = NonNewtonian_Type;
-	Stg_Class_DeleteFunction*                                     _delete = _Rheology_Delete;
-	Stg_Class_PrintFunction*                                       _print = _Rheology_Print;
-	Stg_Class_CopyFunction*                                         _copy = _Rheology_Copy;
-	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _NonNewtonian_DefaultNew;
-	Stg_Component_ConstructFunction*                           _construct = _NonNewtonian_AssignFromXML;
-	Stg_Component_BuildFunction*                                   _build = _NonNewtonian_Build;
-	Stg_Component_InitialiseFunction*                         _initialise = _NonNewtonian_Initialise;
-	Stg_Component_ExecuteFunction*                               _execute = _Rheology_Execute;
-	Stg_Component_DestroyFunction*                               _destroy = _NonNewtonian_Destroy;
-	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _NonNewtonian_ModifyConstitutiveMatrix;
-
-	/* 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*) _NonNewtonian_New(  NONNEWTONIAN_PASSARGS  );
-}
-
-void _NonNewtonian_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
-	NonNewtonian*  self = (NonNewtonian*)rheology;
-	FeVariable    *strainRateInvField, *temperatureField;
-        double refStrainRate;
-	Stream* errorStream = Journal_Register( Error_Type,
-                                                NonNewtonian_Type );
-
-	/* Construct Parent */
-	_Rheology_AssignFromXML( self, cf, data );
-	
-	/* TODO: 'Keyfallback' soon to be deprecated/updated */
-	strainRateInvField = Stg_ComponentFactory_ConstructByNameWithKeyFallback( 
-		cf, 
-		self->name,
-                (Name)"StrainRateInvariantField", 
-		(Name)"StrainRateInvariantField", 
-		FeVariable, 
-		True,
-		data );
-	temperatureField = Stg_ComponentFactory_ConstructByKey(
-		cf, 
-		self->name,
-                "TemperatureField", 
-		FeVariable, 
-		True,
-		data );
-
-        refStrainRate=Stg_ComponentFactory_GetDouble( cf, self->name,
-                                                      "refStrainRate", 0.0 );
-        if(refStrainRate==0.0)
-          Journal_Firewall(0,errorStream,
-                           "refStrainRate must be set to a non-zero number in a NonNewtonian rheology");
-
-	_NonNewtonian_Init( 
-			self,
-			strainRateInvField,
-                        temperatureField,
-			Stg_ComponentFactory_GetDouble( cf, self->name, "n", 1.0 ), 
-			Stg_ComponentFactory_GetDouble( cf, self->name, "T_0", 1.0 ), 
-			Stg_ComponentFactory_GetDouble( cf, self->name, "T_melt", DBL_MAX ), 
-			Stg_ComponentFactory_GetDouble( cf, self->name, "A", 1.0 ), 
-                        refStrainRate,
-			Stg_ComponentFactory_GetDouble( cf, self->name, "minViscosity", 0.0 ) ,
-			Stg_ComponentFactory_GetDouble( cf, self->name, "maxViscosity", 0.0 ) );
-}
-
-void _NonNewtonian_ModifyConstitutiveMatrix( 
-		void*                                              rheology, 
-		ConstitutiveMatrix*                                constitutiveMatrix,
-		MaterialPointsSwarm*                               swarm,
-		Element_LocalIndex                                 lElement_I,
-		MaterialPoint*                                     materialPoint,
-		Coord                                              xi )
-{
-	NonNewtonian*	              self              = (NonNewtonian*) rheology;
-	double                        strainRateInv;
-	double                        minVis;
-	double                        maxVis;
-	double                        viscosity;
-	double                        n, T_0, T_melt, A, T;
-	Stream* errorStream = Journal_Register( Error_Type,
-                                                NonNewtonian_Type );
-
-	n = self->n;
-        T_0=self->T_0;
-        T_melt=self->T_melt;
-        A=self->A;
-	minVis = self->minViscosity;
-	maxVis = self->maxViscosity;
-
-        FeVariable_InterpolateWithinElement(self->temperatureField,
-                                            lElement_I,xi,&T);
-        Journal_Firewall(n!=0 && T!=0 && A!=0,errorStream,
-                         "Error in NonNewtonian: T, n, and A must all be non-zero:\n\tT=%g\n\tn=%g\n\tA=%g\n",T,n,A);
-
-        viscosity=exp(T_0/(n*T))*pow(A,-1/n)/2;
-
-	if ( fabs( n - 1.0 ) > 1.0e-10 )
-          {
-            if ( !constitutiveMatrix->previousSolutionExists )
-              /* on the first ever solve, use a ref strainrate */
-              {
-                strainRateInv = self->refStrainRate;
-              }
-            else
-              {
-                /* Calculate Parameters */
-                FeVariable_InterpolateWithinElement(self->strainRateInvField,
-                                                    lElement_I,xi,&strainRateInv);
-              }
-            /* Calculate New Viscosity */
-            viscosity*= pow(strainRateInv,1.0/n - 1.0);
-          }
-        if(maxVis!=0 && viscosity>maxVis)
-          {
-            viscosity=maxVis;
-          }
-        if(minVis!=0 && viscosity<minVis)
-          {
-            viscosity=minVis;
-          }
-
-        if(T>T_melt)
-          viscosity=minVis;
-
-	ConstitutiveMatrix_SetIsotropicViscosity(constitutiveMatrix,viscosity);
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/NonNewtonian.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/NonNewtonian.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,251 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: NonNewtonian.c 610 2007-10-11 08:09:29Z SteveQuenette $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "RheologyClass.h"
+#include "NonNewtonian.h"
+#include "ConstitutiveMatrix.h"
+
+#include <assert.h>
+#include <float.h>
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type NonNewtonian_Type = "NonNewtonian";
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+NonNewtonian* _NonNewtonian_New(  NONNEWTONIAN_DEFARGS  ) 
+{
+	NonNewtonian*					self;
+
+	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+	assert( _sizeOfSelf >= sizeof(NonNewtonian) );
+	self = (NonNewtonian*) _Rheology_New(  RHEOLOGY_PASSARGS  );
+	
+	return self;
+}
+
+void _NonNewtonian_Init( NonNewtonian* self, FeVariable* strainRateInvField,
+                         FeVariable* temperatureField,
+                         double n,
+                         double T_0,
+                         double T_melt,
+                         double A,
+                         double refStrainRate,
+                         double minViscosity,
+                         double maxViscosity) {
+
+	self->strainRateInvField = strainRateInvField;
+	self->temperatureField = temperatureField;
+
+	self->n = n;
+	self->T_0 = T_0;
+	self->T_melt = T_melt;
+	self->A = A;
+	self->refStrainRate = refStrainRate;
+	self->minViscosity = minViscosity;
+	self->maxViscosity = maxViscosity;
+
+	Rheology_SetToNonLinear( self );
+}
+
+void _NonNewtonian_Build( void* _self, void* data ){
+	NonNewtonian*  self = (NonNewtonian*)_self;
+
+	_Rheology_Build( self, data );
+	
+   Stg_Component_Build( self->strainRateInvField, data, False );
+}
+
+void _NonNewtonian_Initialise( void* _self, void* data ){
+	NonNewtonian*  self = (NonNewtonian*)_self;
+
+   _Rheology_Initialise( self, data );
+
+   Stg_Component_Initialise( self->strainRateInvField, data, False );
+}
+
+void _NonNewtonian_Destroy( void* _self, void* data ){
+	NonNewtonian*  self = (NonNewtonian*)_self;
+
+   Stg_Component_Destroy( self->strainRateInvField, data, False );
+
+	_Rheology_Destroy( self, data );
+}
+
+
+void* _NonNewtonian_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                     _sizeOfSelf = sizeof(NonNewtonian);
+	Type                                                             type = NonNewtonian_Type;
+	Stg_Class_DeleteFunction*                                     _delete = _Rheology_Delete;
+	Stg_Class_PrintFunction*                                       _print = _Rheology_Print;
+	Stg_Class_CopyFunction*                                         _copy = _Rheology_Copy;
+	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _NonNewtonian_DefaultNew;
+	Stg_Component_ConstructFunction*                           _construct = _NonNewtonian_AssignFromXML;
+	Stg_Component_BuildFunction*                                   _build = _NonNewtonian_Build;
+	Stg_Component_InitialiseFunction*                         _initialise = _NonNewtonian_Initialise;
+	Stg_Component_ExecuteFunction*                               _execute = _Rheology_Execute;
+	Stg_Component_DestroyFunction*                               _destroy = _NonNewtonian_Destroy;
+	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _NonNewtonian_ModifyConstitutiveMatrix;
+
+	/* 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*) _NonNewtonian_New(  NONNEWTONIAN_PASSARGS  );
+}
+
+void _NonNewtonian_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
+	NonNewtonian*  self = (NonNewtonian*)rheology;
+	FeVariable    *strainRateInvField, *temperatureField;
+        double refStrainRate;
+	Stream* errorStream = Journal_Register( Error_Type,
+                                                NonNewtonian_Type );
+
+	/* Construct Parent */
+	_Rheology_AssignFromXML( self, cf, data );
+	
+	/* TODO: 'Keyfallback' soon to be deprecated/updated */
+	strainRateInvField = Stg_ComponentFactory_ConstructByNameWithKeyFallback( 
+		cf, 
+		self->name,
+                (Name)"StrainRateInvariantField", 
+		(Name)"StrainRateInvariantField", 
+		FeVariable, 
+		True,
+		data );
+	temperatureField = Stg_ComponentFactory_ConstructByKey(
+		cf, 
+		self->name,
+                "TemperatureField", 
+		FeVariable, 
+		True,
+		data );
+
+        refStrainRate=Stg_ComponentFactory_GetDouble( cf, self->name,
+                                                      "refStrainRate", 0.0 );
+        if(refStrainRate==0.0)
+          Journal_Firewall(0,errorStream,
+                           "refStrainRate must be set to a non-zero number in a NonNewtonian rheology");
+
+	_NonNewtonian_Init( 
+			self,
+			strainRateInvField,
+                        temperatureField,
+			Stg_ComponentFactory_GetDouble( cf, self->name, "n", 1.0 ), 
+			Stg_ComponentFactory_GetDouble( cf, self->name, "T_0", 1.0 ), 
+			Stg_ComponentFactory_GetDouble( cf, self->name, "T_melt", DBL_MAX ), 
+			Stg_ComponentFactory_GetDouble( cf, self->name, "A", 1.0 ), 
+                        refStrainRate,
+			Stg_ComponentFactory_GetDouble( cf, self->name, "minViscosity", 0.0 ) ,
+			Stg_ComponentFactory_GetDouble( cf, self->name, "maxViscosity", 0.0 ) );
+}
+
+void _NonNewtonian_ModifyConstitutiveMatrix( 
+		void*                                              rheology, 
+		ConstitutiveMatrix*                                constitutiveMatrix,
+		MaterialPointsSwarm*                               swarm,
+		Element_LocalIndex                                 lElement_I,
+		MaterialPoint*                                     materialPoint,
+		Coord                                              xi )
+{
+	NonNewtonian*	              self              = (NonNewtonian*) rheology;
+	double                        strainRateInv;
+	double                        minVis;
+	double                        maxVis;
+	double                        viscosity;
+	double                        n, T_0, T_melt, A, T;
+	Stream* errorStream = Journal_Register( Error_Type,
+                                                NonNewtonian_Type );
+
+	n = self->n;
+        T_0=self->T_0;
+        T_melt=self->T_melt;
+        A=self->A;
+	minVis = self->minViscosity;
+	maxVis = self->maxViscosity;
+
+        FeVariable_InterpolateWithinElement(self->temperatureField,
+                                            lElement_I,xi,&T);
+        Journal_Firewall(n!=0 && T!=0 && A!=0,errorStream,
+                         "Error in NonNewtonian: T, n, and A must all be non-zero:\n\tT=%g\n\tn=%g\n\tA=%g\n",T,n,A);
+
+        viscosity=exp(T_0/(n*T))*pow(A,-1/n)/2;
+
+	if ( fabs( n - 1.0 ) > 1.0e-10 )
+          {
+            if ( !constitutiveMatrix->previousSolutionExists )
+              /* on the first ever solve, use a ref strainrate */
+              {
+                strainRateInv = self->refStrainRate;
+              }
+            else
+              {
+                /* Calculate Parameters */
+                FeVariable_InterpolateWithinElement(self->strainRateInvField,
+                                                    lElement_I,xi,&strainRateInv);
+              }
+            /* Calculate New Viscosity */
+            viscosity*= pow(strainRateInv,1.0/n - 1.0);
+          }
+        if(maxVis!=0 && viscosity>maxVis)
+          {
+            viscosity=maxVis;
+          }
+        if(minVis!=0 && viscosity<minVis)
+          {
+            viscosity=minVis;
+          }
+
+        if(T>T_melt)
+          viscosity=minVis;
+
+	ConstitutiveMatrix_SetIsotropicViscosity(constitutiveMatrix,viscosity);
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/Orthotropic.c
--- a/Rheology/src/Orthotropic.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,289 +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
-*%
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "RheologyClass.h"
-#include "ConstitutiveMatrix.h"
-#include "Orthotropic.h"
-
-#include <assert.h>
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type Orthotropic_Type = "Orthotropic";
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-Orthotropic* _Orthotropic_New(  ORTHOTROPIC_DEFARGS  ) 
-{
-	Orthotropic*					self;
-
-	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-	assert( _sizeOfSelf >= sizeof(Orthotropic) );
-	self = (Orthotropic*) _Rheology_New(  RHEOLOGY_PASSARGS  );
-	
-	return self;
-}
-
-void _Orthotropic_Init( Orthotropic* self,
-			/*  MaterialPointsSwarm* materialPointsSwarm, */
-			double C11, double C22, double C33, 
-			double C44, double C55, double C66,
-			double C12, double C13, double C23,
-			double *n, double *m, double *q ) {
-      int i;
-      
-      self->C11  = C11;
-      self->C22  = C22;
-      self->C33  = C33;
-      self->C44  = C44;
-      self->C55  = C55;  
-      self->C66  = C66;
-      self->C12  = C12;
-      self->C13  = C13;
-      self->C23  = C23;
-
-      for(i=0;i<3;i++){
-	    self->n[i] = n[i];
-	    self->m[i] = m[i];
-	    self->q[i] = q[i];
-      }
-}
-
-void* _Orthotropic_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                     _sizeOfSelf = sizeof(Orthotropic);
-	Type                                                             type = Orthotropic_Type;
-	Stg_Class_DeleteFunction*                                     _delete = _Rheology_Delete;
-	Stg_Class_PrintFunction*                                       _print = _Rheology_Print;
-	Stg_Class_CopyFunction*                                         _copy = _Rheology_Copy;
-	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _Orthotropic_DefaultNew;
-	Stg_Component_ConstructFunction*                           _construct = _Orthotropic_AssignFromXML;
-	Stg_Component_BuildFunction*                                   _build = _Rheology_Build;
-	Stg_Component_InitialiseFunction*                         _initialise = _Rheology_Initialise;
-	Stg_Component_ExecuteFunction*                               _execute = _Rheology_Execute;
-	Stg_Component_DestroyFunction*                               _destroy = _Rheology_Destroy;
-	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _Orthotropic_ModifyConstitutiveMatrix;
-
-	/* 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*) _Orthotropic_New(  ORTHOTROPIC_PASSARGS  );
-}
-
-void _Orthotropic_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
-
-	Orthotropic*     self = (Orthotropic*)rheology;
-	double C11;
-	double C22;
-	double C33;
-	double C44;
-	double C55;
-	double C66;
-	double C12;
-	double C13;
-	double C23;
-	double n[3], m[3], q[3];
-
-	/* Construct Parent */
-	_Rheology_AssignFromXML( self, cf, data );
-	
-	/* get parameters */
-	/*******************************************************************
-         The input parameters Cij correspond to the components of the matrix
-         aligned with the directions n,m,q:
-         With the following correspondence between indices and vectors:
-         1 = n,   2 = m, 3 = q.
-         The indices on the vectors correspond to the coordinate system
-         as follows:
-         1 = x 2 = y 3 = z.
-         *******************************************************************/
-	C11 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"C11", True  );
-	C22 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"C22", True  );
-	C33 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"C33", True  );
-	C44 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"C44", True  );
-	C55 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"C55", True  );
-	C66 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"C66", True  );
-	C12 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"C12", True  );
-	C13 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"C13", True  );
-	C23 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"C23", True  );
-	n[0] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"n1", True  );
-	n[1] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"n2", True  );
-	n[2] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"n3", True  );
-	m[0] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"m1", True  );
-	m[1] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"m2", True  );
-	m[2] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"m3", True  );
-	q[0] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"q1", True  );
-	q[1] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"q2", True  );
-	q[2] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"q3", True  );
-
-	_Orthotropic_Init( 
-			self, 
-			C11, C22, C33, C44, C55, C66,
-			C12, C13, C23,
-			n,m,q);
-}
-
-/* how does this get called eventually? */
-void _Orthotropic_ModifyConstitutiveMatrix( 
-		void*                                              rheology, 
-		ConstitutiveMatrix*                                constitutiveMatrix, /* constitutive matrix */
-		MaterialPointsSwarm*                               swarm,
-		Element_LocalIndex                                 lElement_I,
-		MaterialPoint*                                     materialPoint,
-		Coord                                              xi )
-{
-	Orthotropic*	                self = (Orthotropic*) rheology;
-	Dimension_Index                   dim  = swarm->dim;
-
-	int i,j;
-	double**   C  = constitutiveMatrix->matrixData;
-	double n1,n2,n3;
-	double m1,m2,m3;
-	double q1,q2,q3;
-	double C_h11, C_h22, C_h33, C_h44, C_h55, C_h66, C_h12, C_h13, C_h23;
-
-	C_h11 = self->C11;
-	C_h22 = self->C22;
-	C_h33 = self->C33;
-	C_h12 = self->C12;
-	C_h13 = self->C13;
-	C_h23 = self->C23;
-
-	/* the vectors n, m and q must form an orthonormal triad in 3D */
-	n1 = self->n[0];
-	n2 = self->n[1];
-
-	for(i=0;i<dim*(dim+1)/2;i++){
-	      for(j=0;j<dim*(dim+1)/2;j++){
-		    C[i][j] = 0.0;
-	      }
-	}
-	
-
-	if(2==dim) {/* vector m appears implicitly here. m=(-n2,n1) i.e. n dot m = 0 */
-	      C[0][0] = n1*n1*n1*n1*C_h11+2*n1*n1*n2*n2*C_h12-2*n1*n1*n1*n2*C_h12+n2*n2*n2*n2*C_h22-4*n2*n2*n2*n1*C_h23-2*n1*n1*n1*n2*C_h13+4*n1*n1*n2*n2*C_h33;
-	      C[0][1] = C[1][0] = n1*n1*n2*n2*C_h11+n2*n2*n2*n2*C_h12-2*n1*n2*n2*n2*C_h12+n1*n1*n1*n1*C_h12+n2*n2*n1*n1*C_h22-2*n1*n1*n1*n2*C_h23+2*n1*n1*n1*n2*C_h13+2*n2*n2*n2*n1*C_h23-4*n1*n1*n2*n2*C_h33;
-	      C[0][2] = C[2][0] = n1*n1*n1*n2*C_h11+n1*n2*n2*n2*C_h12-2*n1*n1*n2*n2*C_h12-n1*n1*n1*n2*C_h12-n1*n2*n2*n2*C_h22+3*n1*n1*n2*n2*C_h23+n1*n1*n1*n1*C_h13-n1*n1*C_h13*n2*n2-n2*n2*n2*n2*C_h23-2*n1*n1*n1*n2*C_h33+2*n1*n2*n2*n2*C_h33;
-	      C[1][1] = n2*n2*n2*n2*C_h11+2*n1*n1*n2*n2*C_h12+2*n1*n2*n2*n2*C_h12+n1*n1*n1*n1*C_h22+4*n1*n1*n1*n2*C_h23+2*n1*n2*n2*n2*C_h13+4*n1*n1*n2*n2*C_h33;
-	      C[1][2] = C[2][1] = n1*n2*n2*n2*C_h11+n1*n1*n1*n2*C_h12+2*n1*n1*n2*n2*C_h12-n1*n2*n2*n2*C_h12-n1*n1*n1*n2*C_h22-3*n1*n1*n2*n2*C_h23+n1*n1*C_h13*n2*n2-n2*n2*n2*n2*C_h13+n1*n1*n1*n1*C_h23+2*n1*n1*n1*n2*C_h33-2*n1*n2*n2*n2*C_h33;
-	      C[2][2] = n1*n1*n2*n2*C_h11-2*n1*n1*n2*n2*C_h12+n1*n1*n1*n2*C_h12-n1*n2*n2*n2*C_h12+n2*n2*n1*n1*C_h22-2*n1*n1*n1*n2*C_h23+2*n2*n2*n2*n1*C_h23+n1*n1*n1*n2*C_h13-n1*n2*n2*n2*C_h13+C_h33*n1*n1*n1*n1-2*n1*n1*n2*n2*C_h33+C_h33*n2*n2*n2*n2;
-	}
-
-
-	if(3==dim){
-	      m1 = self->m[0];
-	      m2 = self->m[1];
-	      m3 = self->m[2];
-	      n3 = self->n[2];
-	      q1 = self->q[0];
-	      q2 = self->q[1];
-	      q3 = self->q[2];
-	      C_h44 = self->C44;
-	      C_h55 = self->C55;
-	      C_h66 = self->C66;
-
-	      C[0][0] = C_h11*n1*n1*n1*n1+C_h22*m1*m1*m1*m1+C_h33*q1*q1*q1*q1+4*C_h44*n1*n1*m1*m1+4*C_h55*n1*n1*q1*q1+4*C_h66*q1*q1*m1*m1+2*C_h12*n1*n1*m1*m1+2*C_h12*n1*n1*q1*q1+2*C_h23*q1*q1*m1*m1;
-	
-	      C[1][1] = C_h11*n2*n2*n2*n2+C_h22*m2*m2*m2*m2+C_h33*q2*q2*q2*q2+4*C_h44*n2*n2*m2*m2+4*C_h55*n2*n2*q2*q2+4*C_h66*q2*q2*m2*m2+2*C_h12*n2*n2*m2*m2+2*C_h12*n2*n2*q2*q2+2*C_h23*q2*q2*m2*m2;
-
-	      C[1][0]=C[0][1] = C_h11*n1*n1*n2*n2+C_h22*m1*m1*m2*m2+C_h33*q1*q1*q2*q2+4*C_h44*m1*n2*n1*m2+4*C_h55*q1*n2*n1*q2+4*C_h66*m1*q2*q1*m2+C_h12*(n1*n1*m2*m2+m1*m1*n2*n2)+C_h12*(n1*n1*q2*q2+q1*q1*n2*n2)+C_h23*(q1*q1*m2*m2+m1*m1*q2*q2);
-
-	      C[2][2] = C_h11*n3*n3*n3*n3+C_h22*m3*m3*m3*m3+C_h33*q3*q3*q3*q3+4*C_h44*n3*n3*m3*m3+4*C_h55*n3*n3*q3*q3+4*C_h66*q3*q3*m3*m3+2*C_h12*n3*n3*m3*m3+2*C_h12*n3*n3*q3*q3+2*C_h23*q3*q3*m3*m3;
-
-	      C[2][0]=C[0][2] = C_h11*n1*n1*n3*n3+C_h22*m1*m1*m3*m3+C_h33*q1*q1*q3*q3+4*C_h44*n1*m1*n3*m3+4*C_h55*n1*q1*n3*q3+4*C_h66*q1*m1*q3*m3+C_h12*(n1*n1*m3*m3+m1*m1*n3*n3)+C_h12*(n1*n1*q3*q3+q1*q1*n3*n3)+C_h23*(q1*q1*m3*m3+m1*m1*q3*q3);
-
-	      C[2][1]=C[1][2] =  C_h11*n2*n2*n3*n3+C_h22*m2*m2*m3*m3+C_h33*q2*q2*q3*q3+4*C_h44*n2*m2*n3*m3+4*C_h55*n2*q2*n3*q3+4*C_h66*q2*m2*q3*m3+C_h12*(n2*n2*m3*m3+m2*m2*n3*n3)+C_h12*(n2*n2*q3*q3+q2*q2*n3*n3)+C_h23*(q2*q2*m3*m3+m2*m2*q3*q3);
-
-	      C[5][0]=C[0][5] = C_h11*n1*n1*n3*n2+C_h22*m1*m1*m3*m2+C_h33*q1*q1*q3*q2+2*C_h44*m1*n1*(n2*m3+m2*n3)+2*C_h55*q1*n1*(n2*q3+q2*n3)+2*C_h66*m1*q1*(m2*q3+q2*m3)+C_h12*(n1*n1*m3*m2+m1*m1*n3*n2)+C_h12*(n1*n1*q3*q2+q1*q1*n3*n2)+C_h23*(q1*q1*m3*m2+m1*m1*q3*q2);
-
-	      C[4][0]=C[0][4] = C_h11*n1*n1*n1*n3+C_h22*m1*m1*m1*m3+C_h33*q1*q1*q1*q3+2*C_h44*n1*m1*(n3*m1+n1*m3)+2*C_h55*n1*q1*(n3*q1+n1*q3)+2*C_h66*q1*m1*(m1*q3+q1*m3)+C_h12*n1*m1*(n3*m1+n1*m3)+C_h12*n1*q1*(n3*q1+n1*q3)+C_h23*q1*m1*(m1*q3+q1*m3);
-
-	      C[3][0]=C[0][3] =  C_h11*n1*n1*n1*n2+C_h22*m1*m1*m1*m2+C_h33*q1*q1*q1*q2+2*C_h44*m1*n1*(n2*m1+m2*n1)+2*C_h55*q1*n1*(n2*q1+q2*n1)+2*C_h66*m1*q1*(q1*m2+q2*m1)+C_h12*m1*n1*(n2*m1+m2*n1)+C_h12*q1*n1*(n2*q1+q2*n1)+C_h23*m1*q1*(q1*m2+q2*m1);
-
-	      C[5][1]=C[1][5] =  C_h11*n2*n2*n2*n3+C_h22*m2*m2*m2*m3+C_h33*q2*q2*q2*q3+2*C_h44*m2*n2*(n2*m3+m2*n3)+2*C_h55*q2*n2*(n2*q3+q2*n3)+2*C_h66*q2*m2*(m2*q3+q2*m3)+C_h12*m2*n2*(n2*m3+m2*n3)+C_h12*q2*n2*(n2*q3+q2*n3)+C_h23*q2*m2*(m2*q3+q2*m3);
-
-	      C[4][1]=C[1][4] =  C_h11*n2*n2*n1*n3+C_h22*m2*m2*m1*m3+C_h33*q2*q2*q1*q3+2*C_h44*n2*m2*(n3*m1+n1*m3)+2*C_h55*n2*q2*(n3*q1+n1*q3)+2*C_h66*m2*q2*(m1*q3+q1*m3)+C_h12*(n2*n2*m1*m3+m2*m2*n1*n3)+C_h12*(n2*n2*q1*q3+q2*q2*n1*n3)+C_h23*(q2*q2*m1*m3+m2*m2*q1*q3);
-
-	      C[3][1]=C[1][3] =  C_h11*n2*n2*n2*n1+C_h22*m2*m2*m2*m1+C_h33*q2*q2*q2*q1+2*C_h44*m2*n2*(n2*m1+m2*n1)+2*C_h55*q2*n2*(n2*q1+q2*n1)+2*C_h66*q2*m2*(q1*m2+q2*m1)+C_h12*m2*n2*(n2*m1+m2*n1)+C_h12*q2*n2*(n2*q1+q2*n1)+C_h23*q2*m2*(q1*m2+q2*m1);
-
-	      C[5][2]=C[2][5] =  C_h11*n3*n3*n3*n2+C_h22*m3*m3*m3*m2+C_h33*q3*q3*q3*q2+2*C_h44*m3*n3*(n2*m3+m2*n3)+2*C_h55*q3*n3*(n2*q3+q2*n3)+2*C_h66*q3*m3*(m2*q3+q2*m3)+C_h12*m3*n3*(n2*m3+m2*n3)+C_h12*q3*n3*(n2*q3+q2*n3)+C_h23*q3*m3*(m2*q3+q2*m3);
-
-	      C[4][2]=C[2][4] =  C_h11*n3*n3*n3*n1+C_h22*m3*m3*m3*m1+C_h33*q3*q3*q3*q1+2*C_h44*m3*n3*(n3*m1+n1*m3)+2*C_h55*q3*n3*(n3*q1+n1*q3)+2*C_h66*q3*m3*(m1*q3+q1*m3)+C_h12*m3*n3*(n3*m1+n1*m3)+C_h12*q3*n3*(n3*q1+n1*q3)+C_h23*q3*m3*(m1*q3+q1*m3);
-
-	      C[3][2]=C[2][3] =  C_h11*n3*n3*n1*n2+C_h22*m3*m3*m1*m2+C_h33*q3*q3*q1*q2+2*C_h44*n3*m3*(n2*m1+m2*n1)+2*C_h55*n3*q3*(n2*q1+q2*n1)+2*C_h66*m3*q3*(q1*m2+q2*m1)+C_h12*(n3*n3*m1*m2+m3*m3*n1*n2)+C_h12*(n3*n3*q1*q2+q3*q3*n1*n2)+C_h23*(q3*q3*m1*m2+m3*m3*q1*q2);
-
-	      C[5][5] =  C_h11*n2*n2*n3*n3+C_h22*m2*m2*m3*m3+C_h33*q2*q2*q3*q3+C_h44*(n2*m3+m2*n3)*(n2*m3+m2*n3)+C_h55*(n2*q3+q2*n3)*(n2*q3+q2*n3)+C_h66*(m2*q3+q2*m3)*(m2*q3+q2*m3)+2*C_h12*n2*m2*n3*m3+2*C_h12*n2*q2*n3*q3+2*C_h23*q2*m2*q3*m3;
-
-	      C[4][5]=C[5][4] = C_h11*n3*n3*n1*n2+C_h22*m3*m3*m1*m2+C_h33*q3*q3*q1*q2+C_h44*(n3*m1+n1*m3)*(n2*m3+m2*n3)+C_h55*(n3*q1+n1*q3)*(n2*q3+q2*n3)+C_h66*(m1*q3+q1*m3)*(m2*q3+q2*m3)+C_h12*n3*m3*(n2*m1+m2*n1)+C_h12*n3*q3*(n2*q1+q2*n1)+C_h23*m3*q3*(q1*m2+q2*m1);
-
-	      C[3][5]=C[5][3] =  C_h11*n2*n2*n1*n3+C_h22*m2*m2*m1*m3+C_h33*q2*q2*q1*q3+C_h44*(n2*m1+m2*n1)*(n2*m3+m2*n3)+C_h55*(n2*q1+q2*n1)*(n2*q3+q2*n3)+C_h66*(q1*m2+q2*m1)*(m2*q3+q2*m3)+C_h12*n2*m2*(n3*m1+n1*m3)+C_h12*n2*q2*(n3*q1+n1*q3)+C_h23*m2*q2*(m1*q3+q1*m3);
-
-	      C[4][4] = C_h11*n1*n1*n3*n3+C_h22*m1*m1*m3*m3+C_h33*q1*q1*q3*q3+C_h44*(n3*m1+n1*m3)*(n3*m1+n1*m3)+C_h55*(n3*q1+n1*q3)*(n3*q1+n1*q3)+C_h66*(m1*q3+q1*m3)*(m1*q3+q1*m3)+2*C_h12*n1*m1*n3*m3+2*C_h12*n1*q1*n3*q3+2*C_h23*q1*m1*q3*m3;
-
-	      C[3][4]=C[4][3] = C_h11*n1*n1*n3*n2+C_h22*m1*m1*m3*m2+C_h33*q1*q1*q3*q2+C_h44*(n2*m1+m2*n1)*(n3*m1+n1*m3)+C_h55*(n2*q1+q2*n1)*(n3*q1+n1*q3)+C_h66*(q1*m2+q2*m1)*(m1*q3+q1*m3)+C_h12*m1*n1*(n2*m3+m2*n3)+C_h12*q1*n1*(n2*q3+q2*n3)+C_h23*m1*q1*(m2*q3+q2*m3);
-
-	      C[3][3] = C_h11*n1*n1*n2*n2+C_h22*m1*m1*m2*m2+C_h33*q1*q1*q2*q2+C_h44*(n2*m1+m2*n1)*(n2*m1+m2*n1)+C_h55*(n2*q1+q2*n1)*(n2*q1+q2*n1)+C_h66*(q1*m2+q2*m1)*(q1*m2+q2*m1)+2*C_h12*m1*n2*n1*m2+2*C_h12*q1*n2*n1*q2+2*C_h23*m1*q2*q1*m2;
-	}
-
- 
-	constitutiveMatrix->isDiagonal = False;	   
-           /*	   printf("In %s OK\n\n",__func__); */
-           /*	   flag = 1; */
-           /*	} */
-	/*for(i=0;i<dim*(dim+1)/2;i++){ 
-	 	   for(j=0;j<dim*(dim+1)/2;j++){
-			printf("Matrix Data = %g [%d %d]\n",constitutiveMatrix->matrixData[i][j],i,j); 
- 	   } 
- 	}
-	exit(0);*/ 
-}
-
-#if 0
-void _Orthotropic_UpdateDrawParameters( void* rheology ) 
-{
-	Orthotropic*                   self               = (Orthotropic*) rheology;
-	Particle_Index                   lParticle_I;
-	Particle_Index                   particleLocalCount;
-	StandardParticle*                	materialPoint;
-	Dimension_Index                 dim                   = self->materialPointsSwarm->dim;
-	Orthotropic_ParticleExt*            particleExt;   /* this new type is defined in Orthotropic.h */
-
-	/* do stuff */
-}
-#endif
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/Orthotropic.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/Orthotropic.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,289 @@
+	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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
+*%
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "RheologyClass.h"
+#include "ConstitutiveMatrix.h"
+#include "Orthotropic.h"
+
+#include <assert.h>
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type Orthotropic_Type = "Orthotropic";
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+Orthotropic* _Orthotropic_New(  ORTHOTROPIC_DEFARGS  ) 
+{
+	Orthotropic*					self;
+
+	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+	assert( _sizeOfSelf >= sizeof(Orthotropic) );
+	self = (Orthotropic*) _Rheology_New(  RHEOLOGY_PASSARGS  );
+	
+	return self;
+}
+
+void _Orthotropic_Init( Orthotropic* self,
+			/*  MaterialPointsSwarm* materialPointsSwarm, */
+			double C11, double C22, double C33, 
+			double C44, double C55, double C66,
+			double C12, double C13, double C23,
+			double *n, double *m, double *q ) {
+      int i;
+      
+      self->C11  = C11;
+      self->C22  = C22;
+      self->C33  = C33;
+      self->C44  = C44;
+      self->C55  = C55;  
+      self->C66  = C66;
+      self->C12  = C12;
+      self->C13  = C13;
+      self->C23  = C23;
+
+      for(i=0;i<3;i++){
+	    self->n[i] = n[i];
+	    self->m[i] = m[i];
+	    self->q[i] = q[i];
+      }
+}
+
+void* _Orthotropic_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                     _sizeOfSelf = sizeof(Orthotropic);
+	Type                                                             type = Orthotropic_Type;
+	Stg_Class_DeleteFunction*                                     _delete = _Rheology_Delete;
+	Stg_Class_PrintFunction*                                       _print = _Rheology_Print;
+	Stg_Class_CopyFunction*                                         _copy = _Rheology_Copy;
+	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _Orthotropic_DefaultNew;
+	Stg_Component_ConstructFunction*                           _construct = _Orthotropic_AssignFromXML;
+	Stg_Component_BuildFunction*                                   _build = _Rheology_Build;
+	Stg_Component_InitialiseFunction*                         _initialise = _Rheology_Initialise;
+	Stg_Component_ExecuteFunction*                               _execute = _Rheology_Execute;
+	Stg_Component_DestroyFunction*                               _destroy = _Rheology_Destroy;
+	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _Orthotropic_ModifyConstitutiveMatrix;
+
+	/* 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*) _Orthotropic_New(  ORTHOTROPIC_PASSARGS  );
+}
+
+void _Orthotropic_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
+
+	Orthotropic*     self = (Orthotropic*)rheology;
+	double C11;
+	double C22;
+	double C33;
+	double C44;
+	double C55;
+	double C66;
+	double C12;
+	double C13;
+	double C23;
+	double n[3], m[3], q[3];
+
+	/* Construct Parent */
+	_Rheology_AssignFromXML( self, cf, data );
+	
+	/* get parameters */
+	/*******************************************************************
+         The input parameters Cij correspond to the components of the matrix
+         aligned with the directions n,m,q:
+         With the following correspondence between indices and vectors:
+         1 = n,   2 = m, 3 = q.
+         The indices on the vectors correspond to the coordinate system
+         as follows:
+         1 = x 2 = y 3 = z.
+         *******************************************************************/
+	C11 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"C11", True  );
+	C22 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"C22", True  );
+	C33 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"C33", True  );
+	C44 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"C44", True  );
+	C55 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"C55", True  );
+	C66 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"C66", True  );
+	C12 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"C12", True  );
+	C13 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"C13", True  );
+	C23 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"C23", True  );
+	n[0] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"n1", True  );
+	n[1] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"n2", True  );
+	n[2] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"n3", True  );
+	m[0] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"m1", True  );
+	m[1] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"m2", True  );
+	m[2] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"m3", True  );
+	q[0] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"q1", True  );
+	q[1] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"q2", True  );
+	q[2] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"q3", True  );
+
+	_Orthotropic_Init( 
+			self, 
+			C11, C22, C33, C44, C55, C66,
+			C12, C13, C23,
+			n,m,q);
+}
+
+/* how does this get called eventually? */
+void _Orthotropic_ModifyConstitutiveMatrix( 
+		void*                                              rheology, 
+		ConstitutiveMatrix*                                constitutiveMatrix, /* constitutive matrix */
+		MaterialPointsSwarm*                               swarm,
+		Element_LocalIndex                                 lElement_I,
+		MaterialPoint*                                     materialPoint,
+		Coord                                              xi )
+{
+	Orthotropic*	                self = (Orthotropic*) rheology;
+	Dimension_Index                   dim  = swarm->dim;
+
+	int i,j;
+	double**   C  = constitutiveMatrix->matrixData;
+	double n1,n2,n3;
+	double m1,m2,m3;
+	double q1,q2,q3;
+	double C_h11, C_h22, C_h33, C_h44, C_h55, C_h66, C_h12, C_h13, C_h23;
+
+	C_h11 = self->C11;
+	C_h22 = self->C22;
+	C_h33 = self->C33;
+	C_h12 = self->C12;
+	C_h13 = self->C13;
+	C_h23 = self->C23;
+
+	/* the vectors n, m and q must form an orthonormal triad in 3D */
+	n1 = self->n[0];
+	n2 = self->n[1];
+
+	for(i=0;i<dim*(dim+1)/2;i++){
+	      for(j=0;j<dim*(dim+1)/2;j++){
+		    C[i][j] = 0.0;
+	      }
+	}
+	
+
+	if(2==dim) {/* vector m appears implicitly here. m=(-n2,n1) i.e. n dot m = 0 */
+	      C[0][0] = n1*n1*n1*n1*C_h11+2*n1*n1*n2*n2*C_h12-2*n1*n1*n1*n2*C_h12+n2*n2*n2*n2*C_h22-4*n2*n2*n2*n1*C_h23-2*n1*n1*n1*n2*C_h13+4*n1*n1*n2*n2*C_h33;
+	      C[0][1] = C[1][0] = n1*n1*n2*n2*C_h11+n2*n2*n2*n2*C_h12-2*n1*n2*n2*n2*C_h12+n1*n1*n1*n1*C_h12+n2*n2*n1*n1*C_h22-2*n1*n1*n1*n2*C_h23+2*n1*n1*n1*n2*C_h13+2*n2*n2*n2*n1*C_h23-4*n1*n1*n2*n2*C_h33;
+	      C[0][2] = C[2][0] = n1*n1*n1*n2*C_h11+n1*n2*n2*n2*C_h12-2*n1*n1*n2*n2*C_h12-n1*n1*n1*n2*C_h12-n1*n2*n2*n2*C_h22+3*n1*n1*n2*n2*C_h23+n1*n1*n1*n1*C_h13-n1*n1*C_h13*n2*n2-n2*n2*n2*n2*C_h23-2*n1*n1*n1*n2*C_h33+2*n1*n2*n2*n2*C_h33;
+	      C[1][1] = n2*n2*n2*n2*C_h11+2*n1*n1*n2*n2*C_h12+2*n1*n2*n2*n2*C_h12+n1*n1*n1*n1*C_h22+4*n1*n1*n1*n2*C_h23+2*n1*n2*n2*n2*C_h13+4*n1*n1*n2*n2*C_h33;
+	      C[1][2] = C[2][1] = n1*n2*n2*n2*C_h11+n1*n1*n1*n2*C_h12+2*n1*n1*n2*n2*C_h12-n1*n2*n2*n2*C_h12-n1*n1*n1*n2*C_h22-3*n1*n1*n2*n2*C_h23+n1*n1*C_h13*n2*n2-n2*n2*n2*n2*C_h13+n1*n1*n1*n1*C_h23+2*n1*n1*n1*n2*C_h33-2*n1*n2*n2*n2*C_h33;
+	      C[2][2] = n1*n1*n2*n2*C_h11-2*n1*n1*n2*n2*C_h12+n1*n1*n1*n2*C_h12-n1*n2*n2*n2*C_h12+n2*n2*n1*n1*C_h22-2*n1*n1*n1*n2*C_h23+2*n2*n2*n2*n1*C_h23+n1*n1*n1*n2*C_h13-n1*n2*n2*n2*C_h13+C_h33*n1*n1*n1*n1-2*n1*n1*n2*n2*C_h33+C_h33*n2*n2*n2*n2;
+	}
+
+
+	if(3==dim){
+	      m1 = self->m[0];
+	      m2 = self->m[1];
+	      m3 = self->m[2];
+	      n3 = self->n[2];
+	      q1 = self->q[0];
+	      q2 = self->q[1];
+	      q3 = self->q[2];
+	      C_h44 = self->C44;
+	      C_h55 = self->C55;
+	      C_h66 = self->C66;
+
+	      C[0][0] = C_h11*n1*n1*n1*n1+C_h22*m1*m1*m1*m1+C_h33*q1*q1*q1*q1+4*C_h44*n1*n1*m1*m1+4*C_h55*n1*n1*q1*q1+4*C_h66*q1*q1*m1*m1+2*C_h12*n1*n1*m1*m1+2*C_h12*n1*n1*q1*q1+2*C_h23*q1*q1*m1*m1;
+	
+	      C[1][1] = C_h11*n2*n2*n2*n2+C_h22*m2*m2*m2*m2+C_h33*q2*q2*q2*q2+4*C_h44*n2*n2*m2*m2+4*C_h55*n2*n2*q2*q2+4*C_h66*q2*q2*m2*m2+2*C_h12*n2*n2*m2*m2+2*C_h12*n2*n2*q2*q2+2*C_h23*q2*q2*m2*m2;
+
+	      C[1][0]=C[0][1] = C_h11*n1*n1*n2*n2+C_h22*m1*m1*m2*m2+C_h33*q1*q1*q2*q2+4*C_h44*m1*n2*n1*m2+4*C_h55*q1*n2*n1*q2+4*C_h66*m1*q2*q1*m2+C_h12*(n1*n1*m2*m2+m1*m1*n2*n2)+C_h12*(n1*n1*q2*q2+q1*q1*n2*n2)+C_h23*(q1*q1*m2*m2+m1*m1*q2*q2);
+
+	      C[2][2] = C_h11*n3*n3*n3*n3+C_h22*m3*m3*m3*m3+C_h33*q3*q3*q3*q3+4*C_h44*n3*n3*m3*m3+4*C_h55*n3*n3*q3*q3+4*C_h66*q3*q3*m3*m3+2*C_h12*n3*n3*m3*m3+2*C_h12*n3*n3*q3*q3+2*C_h23*q3*q3*m3*m3;
+
+	      C[2][0]=C[0][2] = C_h11*n1*n1*n3*n3+C_h22*m1*m1*m3*m3+C_h33*q1*q1*q3*q3+4*C_h44*n1*m1*n3*m3+4*C_h55*n1*q1*n3*q3+4*C_h66*q1*m1*q3*m3+C_h12*(n1*n1*m3*m3+m1*m1*n3*n3)+C_h12*(n1*n1*q3*q3+q1*q1*n3*n3)+C_h23*(q1*q1*m3*m3+m1*m1*q3*q3);
+
+	      C[2][1]=C[1][2] =  C_h11*n2*n2*n3*n3+C_h22*m2*m2*m3*m3+C_h33*q2*q2*q3*q3+4*C_h44*n2*m2*n3*m3+4*C_h55*n2*q2*n3*q3+4*C_h66*q2*m2*q3*m3+C_h12*(n2*n2*m3*m3+m2*m2*n3*n3)+C_h12*(n2*n2*q3*q3+q2*q2*n3*n3)+C_h23*(q2*q2*m3*m3+m2*m2*q3*q3);
+
+	      C[5][0]=C[0][5] = C_h11*n1*n1*n3*n2+C_h22*m1*m1*m3*m2+C_h33*q1*q1*q3*q2+2*C_h44*m1*n1*(n2*m3+m2*n3)+2*C_h55*q1*n1*(n2*q3+q2*n3)+2*C_h66*m1*q1*(m2*q3+q2*m3)+C_h12*(n1*n1*m3*m2+m1*m1*n3*n2)+C_h12*(n1*n1*q3*q2+q1*q1*n3*n2)+C_h23*(q1*q1*m3*m2+m1*m1*q3*q2);
+
+	      C[4][0]=C[0][4] = C_h11*n1*n1*n1*n3+C_h22*m1*m1*m1*m3+C_h33*q1*q1*q1*q3+2*C_h44*n1*m1*(n3*m1+n1*m3)+2*C_h55*n1*q1*(n3*q1+n1*q3)+2*C_h66*q1*m1*(m1*q3+q1*m3)+C_h12*n1*m1*(n3*m1+n1*m3)+C_h12*n1*q1*(n3*q1+n1*q3)+C_h23*q1*m1*(m1*q3+q1*m3);
+
+	      C[3][0]=C[0][3] =  C_h11*n1*n1*n1*n2+C_h22*m1*m1*m1*m2+C_h33*q1*q1*q1*q2+2*C_h44*m1*n1*(n2*m1+m2*n1)+2*C_h55*q1*n1*(n2*q1+q2*n1)+2*C_h66*m1*q1*(q1*m2+q2*m1)+C_h12*m1*n1*(n2*m1+m2*n1)+C_h12*q1*n1*(n2*q1+q2*n1)+C_h23*m1*q1*(q1*m2+q2*m1);
+
+	      C[5][1]=C[1][5] =  C_h11*n2*n2*n2*n3+C_h22*m2*m2*m2*m3+C_h33*q2*q2*q2*q3+2*C_h44*m2*n2*(n2*m3+m2*n3)+2*C_h55*q2*n2*(n2*q3+q2*n3)+2*C_h66*q2*m2*(m2*q3+q2*m3)+C_h12*m2*n2*(n2*m3+m2*n3)+C_h12*q2*n2*(n2*q3+q2*n3)+C_h23*q2*m2*(m2*q3+q2*m3);
+
+	      C[4][1]=C[1][4] =  C_h11*n2*n2*n1*n3+C_h22*m2*m2*m1*m3+C_h33*q2*q2*q1*q3+2*C_h44*n2*m2*(n3*m1+n1*m3)+2*C_h55*n2*q2*(n3*q1+n1*q3)+2*C_h66*m2*q2*(m1*q3+q1*m3)+C_h12*(n2*n2*m1*m3+m2*m2*n1*n3)+C_h12*(n2*n2*q1*q3+q2*q2*n1*n3)+C_h23*(q2*q2*m1*m3+m2*m2*q1*q3);
+
+	      C[3][1]=C[1][3] =  C_h11*n2*n2*n2*n1+C_h22*m2*m2*m2*m1+C_h33*q2*q2*q2*q1+2*C_h44*m2*n2*(n2*m1+m2*n1)+2*C_h55*q2*n2*(n2*q1+q2*n1)+2*C_h66*q2*m2*(q1*m2+q2*m1)+C_h12*m2*n2*(n2*m1+m2*n1)+C_h12*q2*n2*(n2*q1+q2*n1)+C_h23*q2*m2*(q1*m2+q2*m1);
+
+	      C[5][2]=C[2][5] =  C_h11*n3*n3*n3*n2+C_h22*m3*m3*m3*m2+C_h33*q3*q3*q3*q2+2*C_h44*m3*n3*(n2*m3+m2*n3)+2*C_h55*q3*n3*(n2*q3+q2*n3)+2*C_h66*q3*m3*(m2*q3+q2*m3)+C_h12*m3*n3*(n2*m3+m2*n3)+C_h12*q3*n3*(n2*q3+q2*n3)+C_h23*q3*m3*(m2*q3+q2*m3);
+
+	      C[4][2]=C[2][4] =  C_h11*n3*n3*n3*n1+C_h22*m3*m3*m3*m1+C_h33*q3*q3*q3*q1+2*C_h44*m3*n3*(n3*m1+n1*m3)+2*C_h55*q3*n3*(n3*q1+n1*q3)+2*C_h66*q3*m3*(m1*q3+q1*m3)+C_h12*m3*n3*(n3*m1+n1*m3)+C_h12*q3*n3*(n3*q1+n1*q3)+C_h23*q3*m3*(m1*q3+q1*m3);
+
+	      C[3][2]=C[2][3] =  C_h11*n3*n3*n1*n2+C_h22*m3*m3*m1*m2+C_h33*q3*q3*q1*q2+2*C_h44*n3*m3*(n2*m1+m2*n1)+2*C_h55*n3*q3*(n2*q1+q2*n1)+2*C_h66*m3*q3*(q1*m2+q2*m1)+C_h12*(n3*n3*m1*m2+m3*m3*n1*n2)+C_h12*(n3*n3*q1*q2+q3*q3*n1*n2)+C_h23*(q3*q3*m1*m2+m3*m3*q1*q2);
+
+	      C[5][5] =  C_h11*n2*n2*n3*n3+C_h22*m2*m2*m3*m3+C_h33*q2*q2*q3*q3+C_h44*(n2*m3+m2*n3)*(n2*m3+m2*n3)+C_h55*(n2*q3+q2*n3)*(n2*q3+q2*n3)+C_h66*(m2*q3+q2*m3)*(m2*q3+q2*m3)+2*C_h12*n2*m2*n3*m3+2*C_h12*n2*q2*n3*q3+2*C_h23*q2*m2*q3*m3;
+
+	      C[4][5]=C[5][4] = C_h11*n3*n3*n1*n2+C_h22*m3*m3*m1*m2+C_h33*q3*q3*q1*q2+C_h44*(n3*m1+n1*m3)*(n2*m3+m2*n3)+C_h55*(n3*q1+n1*q3)*(n2*q3+q2*n3)+C_h66*(m1*q3+q1*m3)*(m2*q3+q2*m3)+C_h12*n3*m3*(n2*m1+m2*n1)+C_h12*n3*q3*(n2*q1+q2*n1)+C_h23*m3*q3*(q1*m2+q2*m1);
+
+	      C[3][5]=C[5][3] =  C_h11*n2*n2*n1*n3+C_h22*m2*m2*m1*m3+C_h33*q2*q2*q1*q3+C_h44*(n2*m1+m2*n1)*(n2*m3+m2*n3)+C_h55*(n2*q1+q2*n1)*(n2*q3+q2*n3)+C_h66*(q1*m2+q2*m1)*(m2*q3+q2*m3)+C_h12*n2*m2*(n3*m1+n1*m3)+C_h12*n2*q2*(n3*q1+n1*q3)+C_h23*m2*q2*(m1*q3+q1*m3);
+
+	      C[4][4] = C_h11*n1*n1*n3*n3+C_h22*m1*m1*m3*m3+C_h33*q1*q1*q3*q3+C_h44*(n3*m1+n1*m3)*(n3*m1+n1*m3)+C_h55*(n3*q1+n1*q3)*(n3*q1+n1*q3)+C_h66*(m1*q3+q1*m3)*(m1*q3+q1*m3)+2*C_h12*n1*m1*n3*m3+2*C_h12*n1*q1*n3*q3+2*C_h23*q1*m1*q3*m3;
+
+	      C[3][4]=C[4][3] = C_h11*n1*n1*n3*n2+C_h22*m1*m1*m3*m2+C_h33*q1*q1*q3*q2+C_h44*(n2*m1+m2*n1)*(n3*m1+n1*m3)+C_h55*(n2*q1+q2*n1)*(n3*q1+n1*q3)+C_h66*(q1*m2+q2*m1)*(m1*q3+q1*m3)+C_h12*m1*n1*(n2*m3+m2*n3)+C_h12*q1*n1*(n2*q3+q2*n3)+C_h23*m1*q1*(m2*q3+q2*m3);
+
+	      C[3][3] = C_h11*n1*n1*n2*n2+C_h22*m1*m1*m2*m2+C_h33*q1*q1*q2*q2+C_h44*(n2*m1+m2*n1)*(n2*m1+m2*n1)+C_h55*(n2*q1+q2*n1)*(n2*q1+q2*n1)+C_h66*(q1*m2+q2*m1)*(q1*m2+q2*m1)+2*C_h12*m1*n2*n1*m2+2*C_h12*q1*n2*n1*q2+2*C_h23*m1*q2*q1*m2;
+	}
+
+ 
+	constitutiveMatrix->isDiagonal = False;	   
+           /*	   printf("In %s OK\n\n",__func__); */
+           /*	   flag = 1; */
+           /*	} */
+	/*for(i=0;i<dim*(dim+1)/2;i++){ 
+	 	   for(j=0;j<dim*(dim+1)/2;j++){
+			printf("Matrix Data = %g [%d %d]\n",constitutiveMatrix->matrixData[i][j],i,j); 
+ 	   } 
+ 	}
+	exit(0);*/ 
+}
+
+#if 0
+void _Orthotropic_UpdateDrawParameters( void* rheology ) 
+{
+	Orthotropic*                   self               = (Orthotropic*) rheology;
+	Particle_Index                   lParticle_I;
+	Particle_Index                   particleLocalCount;
+	StandardParticle*                	materialPoint;
+	Dimension_Index                 dim                   = self->materialPointsSwarm->dim;
+	Orthotropic_ParticleExt*            particleExt;   /* this new type is defined in Orthotropic.h */
+
+	/* do stuff */
+}
+#endif
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/OrthotropicAligned.c
--- a/Rheology/src/OrthotropicAligned.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,196 +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
-*%
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "RheologyClass.h"
-#include "ConstitutiveMatrix.h"
-#include "OrthotropicAligned.h"
-
-#include <assert.h>
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type OrthotropicAligned_Type = "OrthotropicAligned";
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-OrthotropicAligned* _OrthotropicAligned_New(  ORTHOTROPICALIGNED_DEFARGS  ) 
-{
-	OrthotropicAligned*					self;
-
-	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-	assert( _sizeOfSelf >= sizeof(OrthotropicAligned) );
-	self = (OrthotropicAligned*) _Rheology_New(  RHEOLOGY_PASSARGS  );
-	
-	return self;
-}
-
-void _OrthotropicAligned_Init( OrthotropicAligned* self,
-                             /*  MaterialPointsSwarm* materialPointsSwarm, */
-			       double viscosity1, double viscosity2, 
-			       double viscosity3, double viscosity4, 
-			       double viscosity5, double viscosity6 ) {
-  /*	self->director         = director; */
-  /*	self->viscosityRatio  = viscosityRatio; */
-/*	OrthotropicAligned_ParticleExt*   particleExt;
-	StandardParticle                  materialPoint;
-	
-	self->particleExtHandle       = ExtensionManager_Add( materialPointsSwarm->particleExtensionMgr, (Name)OrthotropicAligned_Type, sizeof(OrthotropicAligned_ParticleExt) ); */
-        self->viscosity1  = viscosity1;
-	self->viscosity2  = viscosity2;
-	self->viscosity3  = viscosity3;
-	self->viscosity4  = viscosity4;
-	self->viscosity5  = viscosity5;  
-	self->viscosity6  = viscosity6;
-}
-
-void* _OrthotropicAligned_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                     _sizeOfSelf = sizeof(OrthotropicAligned);
-	Type                                                             type = OrthotropicAligned_Type;
-	Stg_Class_DeleteFunction*                                     _delete = _Rheology_Delete;
-	Stg_Class_PrintFunction*                                       _print = _Rheology_Print;
-	Stg_Class_CopyFunction*                                         _copy = _Rheology_Copy;
-	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _OrthotropicAligned_DefaultNew;
-	Stg_Component_ConstructFunction*                           _construct = _OrthotropicAligned_AssignFromXML;
-	Stg_Component_BuildFunction*                                   _build = _Rheology_Build;
-	Stg_Component_InitialiseFunction*                         _initialise = _Rheology_Initialise;
-	Stg_Component_ExecuteFunction*                               _execute = _Rheology_Execute;
-	Stg_Component_DestroyFunction*                               _destroy = _Rheology_Destroy;
-	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _OrthotropicAligned_ModifyConstitutiveMatrix;
-
-	/* 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*) _OrthotropicAligned_New(  ORTHOTROPICALIGNED_PASSARGS   );
-}
-
-void _OrthotropicAligned_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
-	OrthotropicAligned*     self = (OrthotropicAligned*)rheology;
-        /*	Director*        director; */
-	double viscosity1;
-	double viscosity2;
-	double viscosity3;
-	double viscosity4;
-	double viscosity5;
-	double viscosity6;
-
-	/* Construct Parent */
-	_Rheology_AssignFromXML( self, cf, data );
-	
-        /*	director =  Stg_ComponentFactory_ConstructByKey(  cf,  self->name,  "Director", Director,  True  ) ; */
-	viscosity1 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"viscosity1", True  );
-	viscosity2 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"viscosity2", True  );
-	viscosity3 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"viscosity3", True  );
-	viscosity4 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"viscosity4", True  );
-	viscosity5 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"viscosity5", True  );
-	viscosity6 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"viscosity6", True  );
-
-	_OrthotropicAligned_Init( 
-			self, 
-			viscosity1,
-			viscosity2,
-			viscosity3,
-			viscosity4,
-			viscosity5,
-			viscosity6 );
-}
-
-/* how does this get called eventually? */
-void _OrthotropicAligned_ModifyConstitutiveMatrix( 
-		void*                                              rheology, 
-		ConstitutiveMatrix*                                constitutiveMatrix, /* constitutive matrix */
-		MaterialPointsSwarm*                               swarm,
-		Element_LocalIndex                                 lElement_I,
-		MaterialPoint*                                     materialPoint,
-		Coord                                              xi )
-{
-	OrthotropicAligned*	                self = (OrthotropicAligned*) rheology;
-	Dimension_Index                   dim  = swarm->dim;
-        /*	double                          isotropicViscosity = ConstitutiveMatrix_GetIsotropicViscosity( constitutiveMatrix ); */
-        /*	double                          deltaViscosity; */
-        /*	XYZ                             normal; */
-	int i,j;
-	double**   D  = constitutiveMatrix->matrixData;
-        /*	static int flag = 0; */
-        /*	deltaViscosity = isotropicViscosity * (1.0 - self->viscosityRatio); */
-        /*	Director_GetNormal( self->director, materialPoint, normal ); */
-
-        /*	ConstitutiveMatrix_SetSecondViscosity( constitutiveMatrix, deltaViscosity, normal ); */
-	
-        /*	if(!flag){/* if not visited modify matrix else no need to update *\/ */
-        /* Snark dies if I only allow this to be called once.. */
-	/* ahh need to allow it to be called once for every particle */
-	   for(i=0;i<dim*(dim+1)/2;i++){
-	      for(j=0;j<dim*(dim+1)/2;j++){
-		 D[i][j] = 0.0;
-	      }
-	   }
-	   
-	   D[0][0] = self->viscosity1;
-	   D[1][1] = self->viscosity2;
-	   D[2][2] = self->viscosity3;
-	   if(dim == 3){
-	      D[3][3] = self->viscosity4;
-	      D[4][4] = self->viscosity5;
-	      D[5][5] = self->viscosity6;
-	   }
-	   constitutiveMatrix->isDiagonal = True;	   
-           /*	   printf("In %s OK\n\n",__func__); */
-           /*	   flag = 1; */
-           /*	} */
-/* 	for(i=0;i<dim*(dim+1)/2;i++){ */
-/* 	   for(j=0;j<dim*(dim+1)/2;j++){ */
-/* 	      printf("Matrix Data = %g [%d %d]\n",constitutiveMatrix->matrixData[i][j],i,j); */
-/* 	   } */
-/* 	} */
-}
-
-#if 0
-void _OrthotropicAligned_UpdateDrawParameters( void* rheology ) 
-{
-	OrthotropicAligned*                   self               = (OrthotropicAligned*) rheology;
-	Particle_Index                   lParticle_I;
-	Particle_Index                   particleLocalCount;
-	StandardParticle*                	materialPoint;
-	Dimension_Index                 dim                   = self->materialPointsSwarm->dim;
-	OrthotropicAligned_ParticleExt*            particleExt;   /* this new type is defined in OrthotropicAligned.h */
-
-	/* do stuff */
-}
-#endif
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/OrthotropicAligned.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/OrthotropicAligned.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,196 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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
+*%
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "RheologyClass.h"
+#include "ConstitutiveMatrix.h"
+#include "OrthotropicAligned.h"
+
+#include <assert.h>
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type OrthotropicAligned_Type = "OrthotropicAligned";
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+OrthotropicAligned* _OrthotropicAligned_New(  ORTHOTROPICALIGNED_DEFARGS  ) 
+{
+	OrthotropicAligned*					self;
+
+	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+	assert( _sizeOfSelf >= sizeof(OrthotropicAligned) );
+	self = (OrthotropicAligned*) _Rheology_New(  RHEOLOGY_PASSARGS  );
+	
+	return self;
+}
+
+void _OrthotropicAligned_Init( OrthotropicAligned* self,
+                             /*  MaterialPointsSwarm* materialPointsSwarm, */
+			       double viscosity1, double viscosity2, 
+			       double viscosity3, double viscosity4, 
+			       double viscosity5, double viscosity6 ) {
+  /*	self->director         = director; */
+  /*	self->viscosityRatio  = viscosityRatio; */
+/*	OrthotropicAligned_ParticleExt*   particleExt;
+	StandardParticle                  materialPoint;
+	
+	self->particleExtHandle       = ExtensionManager_Add( materialPointsSwarm->particleExtensionMgr, (Name)OrthotropicAligned_Type, sizeof(OrthotropicAligned_ParticleExt) ); */
+        self->viscosity1  = viscosity1;
+	self->viscosity2  = viscosity2;
+	self->viscosity3  = viscosity3;
+	self->viscosity4  = viscosity4;
+	self->viscosity5  = viscosity5;  
+	self->viscosity6  = viscosity6;
+}
+
+void* _OrthotropicAligned_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                     _sizeOfSelf = sizeof(OrthotropicAligned);
+	Type                                                             type = OrthotropicAligned_Type;
+	Stg_Class_DeleteFunction*                                     _delete = _Rheology_Delete;
+	Stg_Class_PrintFunction*                                       _print = _Rheology_Print;
+	Stg_Class_CopyFunction*                                         _copy = _Rheology_Copy;
+	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _OrthotropicAligned_DefaultNew;
+	Stg_Component_ConstructFunction*                           _construct = _OrthotropicAligned_AssignFromXML;
+	Stg_Component_BuildFunction*                                   _build = _Rheology_Build;
+	Stg_Component_InitialiseFunction*                         _initialise = _Rheology_Initialise;
+	Stg_Component_ExecuteFunction*                               _execute = _Rheology_Execute;
+	Stg_Component_DestroyFunction*                               _destroy = _Rheology_Destroy;
+	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _OrthotropicAligned_ModifyConstitutiveMatrix;
+
+	/* 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*) _OrthotropicAligned_New(  ORTHOTROPICALIGNED_PASSARGS   );
+}
+
+void _OrthotropicAligned_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
+	OrthotropicAligned*     self = (OrthotropicAligned*)rheology;
+        /*	Director*        director; */
+	double viscosity1;
+	double viscosity2;
+	double viscosity3;
+	double viscosity4;
+	double viscosity5;
+	double viscosity6;
+
+	/* Construct Parent */
+	_Rheology_AssignFromXML( self, cf, data );
+	
+        /*	director =  Stg_ComponentFactory_ConstructByKey(  cf,  self->name,  "Director", Director,  True  ) ; */
+	viscosity1 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"viscosity1", True  );
+	viscosity2 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"viscosity2", True  );
+	viscosity3 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"viscosity3", True  );
+	viscosity4 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"viscosity4", True  );
+	viscosity5 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"viscosity5", True  );
+	viscosity6 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"viscosity6", True  );
+
+	_OrthotropicAligned_Init( 
+			self, 
+			viscosity1,
+			viscosity2,
+			viscosity3,
+			viscosity4,
+			viscosity5,
+			viscosity6 );
+}
+
+/* how does this get called eventually? */
+void _OrthotropicAligned_ModifyConstitutiveMatrix( 
+		void*                                              rheology, 
+		ConstitutiveMatrix*                                constitutiveMatrix, /* constitutive matrix */
+		MaterialPointsSwarm*                               swarm,
+		Element_LocalIndex                                 lElement_I,
+		MaterialPoint*                                     materialPoint,
+		Coord                                              xi )
+{
+	OrthotropicAligned*	                self = (OrthotropicAligned*) rheology;
+	Dimension_Index                   dim  = swarm->dim;
+        /*	double                          isotropicViscosity = ConstitutiveMatrix_GetIsotropicViscosity( constitutiveMatrix ); */
+        /*	double                          deltaViscosity; */
+        /*	XYZ                             normal; */
+	int i,j;
+	double**   D  = constitutiveMatrix->matrixData;
+        /*	static int flag = 0; */
+        /*	deltaViscosity = isotropicViscosity * (1.0 - self->viscosityRatio); */
+        /*	Director_GetNormal( self->director, materialPoint, normal ); */
+
+        /*	ConstitutiveMatrix_SetSecondViscosity( constitutiveMatrix, deltaViscosity, normal ); */
+	
+        /*	if(!flag){/* if not visited modify matrix else no need to update *\/ */
+        /* Snark dies if I only allow this to be called once.. */
+	/* ahh need to allow it to be called once for every particle */
+	   for(i=0;i<dim*(dim+1)/2;i++){
+	      for(j=0;j<dim*(dim+1)/2;j++){
+		 D[i][j] = 0.0;
+	      }
+	   }
+	   
+	   D[0][0] = self->viscosity1;
+	   D[1][1] = self->viscosity2;
+	   D[2][2] = self->viscosity3;
+	   if(dim == 3){
+	      D[3][3] = self->viscosity4;
+	      D[4][4] = self->viscosity5;
+	      D[5][5] = self->viscosity6;
+	   }
+	   constitutiveMatrix->isDiagonal = True;	   
+           /*	   printf("In %s OK\n\n",__func__); */
+           /*	   flag = 1; */
+           /*	} */
+/* 	for(i=0;i<dim*(dim+1)/2;i++){ */
+/* 	   for(j=0;j<dim*(dim+1)/2;j++){ */
+/* 	      printf("Matrix Data = %g [%d %d]\n",constitutiveMatrix->matrixData[i][j],i,j); */
+/* 	   } */
+/* 	} */
+}
+
+#if 0
+void _OrthotropicAligned_UpdateDrawParameters( void* rheology ) 
+{
+	OrthotropicAligned*                   self               = (OrthotropicAligned*) rheology;
+	Particle_Index                   lParticle_I;
+	Particle_Index                   particleLocalCount;
+	StandardParticle*                	materialPoint;
+	Dimension_Index                 dim                   = self->materialPointsSwarm->dim;
+	OrthotropicAligned_ParticleExt*            particleExt;   /* this new type is defined in OrthotropicAligned.h */
+
+	/* do stuff */
+}
+#endif
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/Pouliquen_etal.c
--- a/Rheology/src/Pouliquen_etal.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,485 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: Pouliquen_etal.c 743 2008-06-23 01:49:43Z VincentLemiale $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "RheologyClass.h"
-#include "StrainWeakening.h"
-#include "YieldRheology.h"
-#include "VonMises.h"
-#include "Pouliquen_etal.h"
-#include "ConstitutiveMatrix.h"
-
-#include <assert.h>
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type Pouliquen_etal_Type = "Pouliquen_etal";
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-Pouliquen_etal* _Pouliquen_etal_New(  POULIQUEN_ETAL_DEFARGS  ) 
-{
-	Pouliquen_etal*					self;
-
-	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-	assert( _sizeOfSelf >= sizeof(Pouliquen_etal) );
-	self = (Pouliquen_etal*) _VonMises_New(  VONMISES_PASSARGS  );
-	
-	/* Function pointers for this class that are not on the parent class should be set here */
-	self->isConstructed = True;
-	return self;
-}
-
-void _Pouliquen_etal_Init(
-		Pouliquen_etal*                                     self,
-		FeVariable*                                        pressureField,
-		FeVariable*                                        strainRateInvField,
-		MaterialPointsSwarm*                               materialPointsSwarm,
-		double                                             minimumYieldStress,
-		double                                             frictionCoefficient,
-		double                                             frictionCoefficientAfterSoftening,
-		double                                             grainDiameter,
-		double                                             Io,
-		double                                             rho_s,
-		double                                             mu_2,
-		double                                             mu_s,
-		double                                             mu_2_afterSoftening,
-		double                                             mu_s_afterSoftening,
-		double                                             maxViscosity,
-		double                                             minViscosity )
-{
-	Pouliquen_etal_Particle*   particleExt;
-	StandardParticle          materialPoint;
-	
-	self->particleExtHandle = ExtensionManager_Add( materialPointsSwarm->particleExtensionMgr, (Name)Pouliquen_etal_Type, sizeof(Pouliquen_etal_Particle) );
-		
-	/* Assign Pointers */
-	self->pressureField       = pressureField;
-	self->strainRateInvField    = strainRateInvField;
-
-	self->frictionCoefficient = frictionCoefficient;
-	self->minimumYieldStress  = minimumYieldStress;
-	
-	/* Strain softening of Friction - (linear weakening is assumed ) */
-	/* needs a softening factor between +0 and 1 and a reference strain > 0 */
-	self->frictionCoefficientAfterSoftening = frictionCoefficientAfterSoftening;
-
-	self->grainDiameter = grainDiameter;
-	self->Io = Io;
-	self->rho_s = rho_s;
-	self->mu_2 = mu_2;
-	self->mu_s = mu_s;
-	self->mu_2_afterSoftening = mu_2_afterSoftening;
-	self->mu_s_afterSoftening = mu_s_afterSoftening;
-	self->maxViscosity = maxViscosity;
-	self->minViscosity = minViscosity;
-
-	/* Update Drawing Parameters */
-	EP_PrependClassHook( Context_GetEntryPoint( self->context, AbstractContext_EP_DumpClass ),
-								_Pouliquen_etal_UpdateDrawParameters, self );
-	
-	particleExt = (Pouliquen_etal_Particle*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, &materialPoint, self->particleExtHandle );
-	
-	/* Setup Variables for Visualisation */
-	self->brightness = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"Pouliquen_etalBrightness", (ArithPointer) &particleExt->brightness - (ArithPointer) &materialPoint, Variable_DataType_Float  );
-	
-	self->opacity = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"Pouliquen_etalOpacity", (ArithPointer) &particleExt->opacity - (ArithPointer) &materialPoint, Variable_DataType_Float  );
-	
-	self->diameter = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"Pouliquen_etalDiameter", (ArithPointer) &particleExt->diameter - (ArithPointer) &materialPoint, Variable_DataType_Float  );
-
-	/* The tensileFailure variable allows to check whether a materialPoint has failed in tensile mode or not */
-	self->tensileFailure = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"Pouliquen_etalTensileFailure", (ArithPointer) &particleExt->tensileFailure - (ArithPointer) &materialPoint, Variable_DataType_Char );
-
-}
-
-void* _Pouliquen_etal_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                     _sizeOfSelf = sizeof(Pouliquen_etal);
-	Type                                                             type = Pouliquen_etal_Type;
-	Stg_Class_DeleteFunction*                                     _delete = _YieldRheology_Delete;
-	Stg_Class_PrintFunction*                                       _print = _YieldRheology_Print;
-	Stg_Class_CopyFunction*                                         _copy = _YieldRheology_Copy;
-	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _Pouliquen_etal_DefaultNew;
-	Stg_Component_ConstructFunction*                           _construct = _Pouliquen_etal_AssignFromXML;
-	Stg_Component_BuildFunction*                                   _build = _Pouliquen_etal_Build;
-	Stg_Component_InitialiseFunction*                         _initialise = _Pouliquen_etal_Initialise;
-	Stg_Component_ExecuteFunction*                               _execute = _YieldRheology_Execute;
-	Stg_Component_DestroyFunction*                               _destroy = _Pouliquen_etal_Destroy;
-	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _YieldRheology_ModifyConstitutiveMatrix;
-	YieldRheology_GetYieldCriterionFunction*           _getYieldCriterion = _Pouliquen_etal_GetYieldCriterion;
-	YieldRheology_GetYieldIndicatorFunction*           _getYieldIndicator = _VonMises_GetYieldIndicator;
-	YieldRheology_HasYieldedFunction*                         _hasYielded = _Pouliquen_etal_HasYielded;
-
-	/* 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*) _Pouliquen_etal_New(  POULIQUEN_ETAL_PASSARGS   );
-}
-
-void _Pouliquen_etal_AssignFromXML( void* pouliquen_etal, Stg_ComponentFactory* cf, void* data ){
-	Pouliquen_etal*          self           = (Pouliquen_etal*)pouliquen_etal;
-	FeVariable*             pressureField;
-	FeVariable*             strainRateInvField;
-	MaterialPointsSwarm*    materialPointsSwarm;
-
-	/* Construct Parent */
-	_VonMises_AssignFromXML( self, cf, data );
-	
-	pressureField      = (FeVariable *) 
-			Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"PressureField", FeVariable, True, data );
-			
-	strainRateInvField      = (FeVariable * ) 
-			Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"StrainRateInvariantField", FeVariable, True, data );
-
-	materialPointsSwarm     = (MaterialPointsSwarm* )
-			Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"MaterialPointsSwarm", MaterialPointsSwarm, True, data  );
-		
-	_Pouliquen_etal_Init( self, 
-			pressureField,
-			strainRateInvField,
-			materialPointsSwarm, 
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"minimumYieldStress", 0.0  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"frictionCoefficient", 0.0  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"frictionCoefficientAfterSoftening", 0.0  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"grainDiameter", 0.0  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"Io", 0.0  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"rho_s", 0.0  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"mu_2", 0.0  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"mu_s", 0.0  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"mu_2_afterSoftening", 0.0  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"mu_s_afterSoftening", 0.0  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"maxViscosity", 0.0  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"minViscosity", 0.0 )   );
-}
-
-void _Pouliquen_etal_Build( void* rheology, void* data ) {
-	Pouliquen_etal*          self               = (Pouliquen_etal*) rheology;
-
-	/* Build parent */
-	_YieldRheology_Build( self, data );
-
-	Stg_Component_Build( self->pressureField, data, False );
-	Stg_Component_Build( self->strainRateInvField, data, False );
-	
-	Stg_Component_Build( self->brightness, data, False );
-	Stg_Component_Build( self->opacity, data, False );
-	Stg_Component_Build( self->diameter, data, False );
-	Stg_Component_Build( self->tensileFailure, data, False );
-
-}
-
-void _Pouliquen_etal_Initialise( void* rheology, void* data ) {
-	Pouliquen_etal*	self = (Pouliquen_etal*) rheology;
-	Particle_Index		lParticle_I;
-	Particle_Index		particleLocalCount;
-
-	_YieldRheology_Initialise( self, data );
-
-   Stg_Component_Initialise( self->pressureField, data, False );
-	Stg_Component_Initialise( self->strainRateInvField, data, False );
-
-	/* We should only set initial conditions if in regular non-restart mode. If in restart mode, then
-	the particle-based variables will be set correcty when we re-load the Swarm. */
-	if ( self->context->loadFromCheckPoint == False ) {
-      /* Initialise variables that I've created - (mainly just SwarmVariables)
-       * This will run a Variable_Update for us */
-      Stg_Component_Initialise( self->brightness, data, False );
-      Stg_Component_Initialise( self->opacity, data, False );
-      Stg_Component_Initialise( self->diameter, data, False );
-      Stg_Component_Initialise( self->tensileFailure, data, False );
-
-		/* We don't need to Initialise hasYieldedVariable because it's a parent variable and _YieldRheology_Initialise
-		 * has already been called */
-		particleLocalCount = self->hasYieldedVariable->variable->arraySize;
-
-		for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) { 
-		
-			Variable_SetValueFloat( self->brightness->variable, lParticle_I, 0.0 );
-			Variable_SetValueFloat( self->opacity->variable,    lParticle_I, 0.0 );
-			Variable_SetValueFloat( self->diameter->variable,   lParticle_I, 0.0 );
-		
-			Variable_SetValueChar( self->hasYieldedVariable->variable, lParticle_I, False );
-			Variable_SetValueChar( self->tensileFailure->variable,lParticle_I, False );
-		}
-	}	
-}
-
-void _Pouliquen_etal_Destroy( void* rheology, void* data ) {
-	Pouliquen_etal*          self               = (Pouliquen_etal*) rheology;
-
-	Stg_Component_Destroy( self->pressureField, data, False );
-	Stg_Component_Destroy( self->strainRateInvField, data, False );
-	
-	Stg_Component_Destroy( self->brightness, data, False );
-	Stg_Component_Destroy( self->opacity, data, False );
-	Stg_Component_Destroy( self->diameter, data, False );
-	Stg_Component_Destroy( self->tensileFailure, data, False );
-
-	/* Destroy parent */
-	_YieldRheology_Destroy( self, data );
-
-}
-
-
-double _Pouliquen_etal_GetYieldCriterion( 
-			void*                            pouliquen_etal,
-			ConstitutiveMatrix*              constitutiveMatrix,
-			MaterialPointsSwarm*             materialPointsSwarm,
-			Element_LocalIndex               lElement_I,
-			MaterialPoint*                   materialPoint,
-			Coord                            xi )
-{
-	Pouliquen_etal*                    self             = (Pouliquen_etal*) pouliquen_etal;
-
-	double                            frictionalStrength;
-	double                            pressure;
-	Pouliquen_etal_Particle*          particleExt;
-	double                            strainRateInv;
-	
-	particleExt = (Pouliquen_etal_Particle*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, materialPoint, self->particleExtHandle );
-
-	FeVariable_InterpolateWithinElement( self->pressureField, lElement_I, xi, &pressure );
-	FeVariable_InterpolateWithinElement( self->strainRateInvField, lElement_I, xi, &strainRateInv );
-
-	particleExt->pressure      = pressure;
-	particleExt->strainRateInv = strainRateInv;
-
-	frictionalStrength = self->mu_s * pressure;
-	//the following is to ensure that every particle is yielding
-	//frictionalStrength = -1.0;	
-
-	return frictionalStrength;
-}
-
-void _Pouliquen_etal_UpdateDrawParameters( void* rheology ) {
-	Pouliquen_etal*                   self               = (Pouliquen_etal*) rheology;
-	Particle_Index                   lParticle_I;
-	Particle_Index                   particleLocalCount;
-	StrainWeakening*                 strainWeakening    = self->strainWeakening;
-	MaterialPoint*                   materialPoint;
-	
-	double                           length;
-	double                           brightness;
-	double                           opacity;
-	double                           strainWeakeningRatio;
-	double                           localMaxStrainIncrement;
-	double                           localMeanStrainIncrement;
-	Particle_Index                   localFailed;
-	
-	double                           globalMaxStrainIncrement;
-	double                           globalMeanStrainIncrement;
-	Particle_Index                   globalFailed;
-	
-	double                           averagedGlobalMaxStrainIncrement = 0.0;
-
-	double                           oneOverGlobalMaxStrainIncrement;
-	double                           postFailureWeakeningIncrement;
-
-	/* Note : this function defines some drawing parameters (brightness, opacity, diameter) as
-	 * functions of the strain weakening - this needs to be improved since most of the parameters
-	 * that define this dependency are hard coded here. We need to have a more flexible way
-	 * to construct the viz parameters as functions of material parameters */
-
-	/* We should only update the drawing parameters if the strain weakening is defined */ 
-	if (strainWeakening==NULL)
-		return;
-	
-	localMaxStrainIncrement = 0.0;
-	localMeanStrainIncrement = 0.0;
-	localFailed = 0;
-
-	/* Update all variables */
-	Variable_Update( self->hasYieldedVariable->variable );
-	Variable_Update( self->brightness->variable );
-	Variable_Update( self->opacity->variable );
-	Variable_Update( self->diameter->variable );
-	Variable_Update( strainWeakening->postFailureWeakeningIncrement->variable );
-
-	particleLocalCount = self->hasYieldedVariable->variable->arraySize;
-	
-	for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) { 
-		if ( Variable_GetValueChar( self->hasYieldedVariable->variable, lParticle_I )) {
-			localFailed++;
-
-			postFailureWeakeningIncrement = 
-					Variable_GetValueDouble( strainWeakening->postFailureWeakeningIncrement->variable, lParticle_I );
-			
-			localMeanStrainIncrement += postFailureWeakeningIncrement;
-		
-			if(localMaxStrainIncrement < postFailureWeakeningIncrement)
-				localMaxStrainIncrement = postFailureWeakeningIncrement;
-		}
-	}
-	
-	MPI_Allreduce( &localMaxStrainIncrement,  &globalMaxStrainIncrement,  1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );
-	MPI_Allreduce( &localMeanStrainIncrement, &globalMeanStrainIncrement, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
-	MPI_Allreduce( &localFailed,              &globalFailed,              1, MPI_INT,    MPI_SUM, MPI_COMM_WORLD );
-	
-	if(globalFailed == 0) 
-		return;
-				
-	globalMeanStrainIncrement /= (double) globalFailed;
-	
-	averagedGlobalMaxStrainIncrement = 
-			0.5 * averagedGlobalMaxStrainIncrement + 
-			0.25 * globalMeanStrainIncrement +
-			0.25 * globalMaxStrainIncrement;
-	
-	/* Let's simply assume that twice the mean is a good place to truncate these values */
-	oneOverGlobalMaxStrainIncrement = 1.0 / averagedGlobalMaxStrainIncrement;
-	
-	for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) { 
-		materialPoint = (MaterialPoint*)Swarm_ParticleAt( strainWeakening->swarm, lParticle_I );
-
-		if ( Variable_GetValueChar( self->hasYieldedVariable->variable, lParticle_I ) == False ||
-					StrainWeakening_GetPostFailureWeakening( strainWeakening, materialPoint ) < 0.0 ) 
-		{
-			Variable_SetValueFloat( self->brightness->variable, lParticle_I, 0.0 );
-			Variable_SetValueFloat( self->opacity->variable, lParticle_I, 0.0 );
-			Variable_SetValueFloat( self->diameter->variable, lParticle_I, 0.0 );
-			continue;
-		}  
-
-		postFailureWeakeningIncrement = 
-				Variable_GetValueDouble( strainWeakening->postFailureWeakeningIncrement->variable, lParticle_I );
-			
-		strainWeakeningRatio = StrainWeakening_CalcRatio( strainWeakening, materialPoint );
-		
-		length     = 0.001 + 0.003 * strainWeakeningRatio;
-		brightness = strainWeakeningRatio * postFailureWeakeningIncrement * oneOverGlobalMaxStrainIncrement;
-		
-		opacity = 0.5 * brightness; 
-		
-		if( brightness > 1.0 )
-			brightness = 1.0;
-		
-		if( opacity > 0.5 )
-			opacity = 0.5;
-		
-		if( opacity < 0.1 )
-			opacity = 0.0;
-		
-		Variable_SetValueFloat( self->brightness->variable, lParticle_I, brightness );
-		Variable_SetValueFloat( self->opacity->variable,    lParticle_I, opacity );
-		Variable_SetValueFloat( self->diameter->variable,   lParticle_I, (float) length );
-	}
-	
-}
-
-void _Pouliquen_etal_HasYielded( 
-		void*                            rheology,
-		ConstitutiveMatrix*              constitutiveMatrix,
-		MaterialPointsSwarm*             materialPointsSwarm,
-		Element_LocalIndex               lElement_I,
-		MaterialPoint*                   materialPoint,
-		double                           yieldCriterion,
-		double                           yieldIndicator )
-{
-	Pouliquen_etal*                  self             = (Pouliquen_etal*) rheology;
-	double                    viscosity;
-	double                    oneOnI;
-	Pouliquen_etal_Particle*         particleExt;
-	double                    mu;
-	double                    strainWeakeningRatio;
-	/*double                    mu_2_afterSoftening =	self->mu_2_afterSoftening;
-	double                    mu_s_afterSoftening =	self->mu_s_afterSoftening;*/
-	double                    effective_mu_s;
-	double                    effective_mu_2;
-	double                    pressure;
-
-	strainWeakeningRatio = StrainWeakening_CalcRatio( self->strainWeakening, materialPoint );
-
-	particleExt = (Pouliquen_etal_Particle*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, materialPoint, self->particleExtHandle );
-
-	if (fabs(particleExt->strainRateInv) <1.0e-10)
-		particleExt->strainRateInv = 1.0e-10;
-
-	/* The initial rheology is only defined for positive pressures.
-	   As the pressure gets closer to a null value, the effective viscosity tends to zero,
-	   which is equivalent to saying that the pressure only acts against the motion when its
-	   compressive. Therefore negative pressures (tensile environment) are equivalent to a null 
-	   pressure in this sense. */
-	if (particleExt->pressure<0) {
-		pressure = 0.0;	
-	}
-	else {
-		pressure = particleExt->pressure;
-	}
-
-	oneOnI = sqrt(pressure/self->rho_s)/(particleExt->strainRateInv*self->grainDiameter);
-
-	/*
-	effective_mu_s =  self->mu_s * (1.0 - strainWeakeningRatio) + 
-			mu_s_afterSoftening * strainWeakeningRatio;	
-	effective_mu_2 =  self->mu_2 * (1.0 - strainWeakeningRatio) + 
-			mu_2_afterSoftening * strainWeakeningRatio;
-	*/
-	effective_mu_s =  self->mu_s;
-	effective_mu_2 =  self->mu_2;
-
-	mu = effective_mu_s + (effective_mu_2-effective_mu_s)/(self->Io*oneOnI+1.);
-
-	viscosity = mu * pressure/particleExt->strainRateInv;
-
-	/*
-	printf("oneOnI=%f self->rho_s=%f strainWeakeningRatio=%f effective_mu_s =%f\n",oneOnI,self->rho_s,strainWeakeningRatio,effective_mu_s );
-	printf("particleExt->pressure=%f particleExt->strainRateInv=%f self->grainDiameter=%f\n",particleExt->pressure,particleExt->strainRateInv,self->grainDiameter);
-	printf("mu=%f viscosity=%f\n",mu,viscosity);
-	*/	
-
-	if (viscosity > self->maxViscosity)
-		viscosity = self->maxViscosity;
-	if (viscosity < self->minViscosity)
-		viscosity = self->minViscosity;
-
-	ConstitutiveMatrix_SetIsotropicViscosity( constitutiveMatrix, viscosity );
-}
-
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/Pouliquen_etal.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/Pouliquen_etal.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,485 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: Pouliquen_etal.c 743 2008-06-23 01:49:43Z VincentLemiale $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "RheologyClass.h"
+#include "StrainWeakening.h"
+#include "YieldRheology.h"
+#include "VonMises.h"
+#include "Pouliquen_etal.h"
+#include "ConstitutiveMatrix.h"
+
+#include <assert.h>
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type Pouliquen_etal_Type = "Pouliquen_etal";
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+Pouliquen_etal* _Pouliquen_etal_New(  POULIQUEN_ETAL_DEFARGS  ) 
+{
+	Pouliquen_etal*					self;
+
+	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+	assert( _sizeOfSelf >= sizeof(Pouliquen_etal) );
+	self = (Pouliquen_etal*) _VonMises_New(  VONMISES_PASSARGS  );
+	
+	/* Function pointers for this class that are not on the parent class should be set here */
+	self->isConstructed = True;
+	return self;
+}
+
+void _Pouliquen_etal_Init(
+		Pouliquen_etal*                                     self,
+		FeVariable*                                        pressureField,
+		FeVariable*                                        strainRateInvField,
+		MaterialPointsSwarm*                               materialPointsSwarm,
+		double                                             minimumYieldStress,
+		double                                             frictionCoefficient,
+		double                                             frictionCoefficientAfterSoftening,
+		double                                             grainDiameter,
+		double                                             Io,
+		double                                             rho_s,
+		double                                             mu_2,
+		double                                             mu_s,
+		double                                             mu_2_afterSoftening,
+		double                                             mu_s_afterSoftening,
+		double                                             maxViscosity,
+		double                                             minViscosity )
+{
+	Pouliquen_etal_Particle*   particleExt;
+	StandardParticle          materialPoint;
+	
+	self->particleExtHandle = ExtensionManager_Add( materialPointsSwarm->particleExtensionMgr, (Name)Pouliquen_etal_Type, sizeof(Pouliquen_etal_Particle) );
+		
+	/* Assign Pointers */
+	self->pressureField       = pressureField;
+	self->strainRateInvField    = strainRateInvField;
+
+	self->frictionCoefficient = frictionCoefficient;
+	self->minimumYieldStress  = minimumYieldStress;
+	
+	/* Strain softening of Friction - (linear weakening is assumed ) */
+	/* needs a softening factor between +0 and 1 and a reference strain > 0 */
+	self->frictionCoefficientAfterSoftening = frictionCoefficientAfterSoftening;
+
+	self->grainDiameter = grainDiameter;
+	self->Io = Io;
+	self->rho_s = rho_s;
+	self->mu_2 = mu_2;
+	self->mu_s = mu_s;
+	self->mu_2_afterSoftening = mu_2_afterSoftening;
+	self->mu_s_afterSoftening = mu_s_afterSoftening;
+	self->maxViscosity = maxViscosity;
+	self->minViscosity = minViscosity;
+
+	/* Update Drawing Parameters */
+	EP_PrependClassHook( Context_GetEntryPoint( self->context, AbstractContext_EP_DumpClass ),
+								_Pouliquen_etal_UpdateDrawParameters, self );
+	
+	particleExt = (Pouliquen_etal_Particle*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, &materialPoint, self->particleExtHandle );
+	
+	/* Setup Variables for Visualisation */
+	self->brightness = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"Pouliquen_etalBrightness", (ArithPointer) &particleExt->brightness - (ArithPointer) &materialPoint, Variable_DataType_Float  );
+	
+	self->opacity = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"Pouliquen_etalOpacity", (ArithPointer) &particleExt->opacity - (ArithPointer) &materialPoint, Variable_DataType_Float  );
+	
+	self->diameter = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"Pouliquen_etalDiameter", (ArithPointer) &particleExt->diameter - (ArithPointer) &materialPoint, Variable_DataType_Float  );
+
+	/* The tensileFailure variable allows to check whether a materialPoint has failed in tensile mode or not */
+	self->tensileFailure = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"Pouliquen_etalTensileFailure", (ArithPointer) &particleExt->tensileFailure - (ArithPointer) &materialPoint, Variable_DataType_Char );
+
+}
+
+void* _Pouliquen_etal_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                     _sizeOfSelf = sizeof(Pouliquen_etal);
+	Type                                                             type = Pouliquen_etal_Type;
+	Stg_Class_DeleteFunction*                                     _delete = _YieldRheology_Delete;
+	Stg_Class_PrintFunction*                                       _print = _YieldRheology_Print;
+	Stg_Class_CopyFunction*                                         _copy = _YieldRheology_Copy;
+	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _Pouliquen_etal_DefaultNew;
+	Stg_Component_ConstructFunction*                           _construct = _Pouliquen_etal_AssignFromXML;
+	Stg_Component_BuildFunction*                                   _build = _Pouliquen_etal_Build;
+	Stg_Component_InitialiseFunction*                         _initialise = _Pouliquen_etal_Initialise;
+	Stg_Component_ExecuteFunction*                               _execute = _YieldRheology_Execute;
+	Stg_Component_DestroyFunction*                               _destroy = _Pouliquen_etal_Destroy;
+	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _YieldRheology_ModifyConstitutiveMatrix;
+	YieldRheology_GetYieldCriterionFunction*           _getYieldCriterion = _Pouliquen_etal_GetYieldCriterion;
+	YieldRheology_GetYieldIndicatorFunction*           _getYieldIndicator = _VonMises_GetYieldIndicator;
+	YieldRheology_HasYieldedFunction*                         _hasYielded = _Pouliquen_etal_HasYielded;
+
+	/* 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*) _Pouliquen_etal_New(  POULIQUEN_ETAL_PASSARGS   );
+}
+
+void _Pouliquen_etal_AssignFromXML( void* pouliquen_etal, Stg_ComponentFactory* cf, void* data ){
+	Pouliquen_etal*          self           = (Pouliquen_etal*)pouliquen_etal;
+	FeVariable*             pressureField;
+	FeVariable*             strainRateInvField;
+	MaterialPointsSwarm*    materialPointsSwarm;
+
+	/* Construct Parent */
+	_VonMises_AssignFromXML( self, cf, data );
+	
+	pressureField      = (FeVariable *) 
+			Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"PressureField", FeVariable, True, data );
+			
+	strainRateInvField      = (FeVariable * ) 
+			Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"StrainRateInvariantField", FeVariable, True, data );
+
+	materialPointsSwarm     = (MaterialPointsSwarm* )
+			Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"MaterialPointsSwarm", MaterialPointsSwarm, True, data  );
+		
+	_Pouliquen_etal_Init( self, 
+			pressureField,
+			strainRateInvField,
+			materialPointsSwarm, 
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"minimumYieldStress", 0.0  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"frictionCoefficient", 0.0  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"frictionCoefficientAfterSoftening", 0.0  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"grainDiameter", 0.0  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"Io", 0.0  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"rho_s", 0.0  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"mu_2", 0.0  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"mu_s", 0.0  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"mu_2_afterSoftening", 0.0  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"mu_s_afterSoftening", 0.0  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"maxViscosity", 0.0  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"minViscosity", 0.0 )   );
+}
+
+void _Pouliquen_etal_Build( void* rheology, void* data ) {
+	Pouliquen_etal*          self               = (Pouliquen_etal*) rheology;
+
+	/* Build parent */
+	_YieldRheology_Build( self, data );
+
+	Stg_Component_Build( self->pressureField, data, False );
+	Stg_Component_Build( self->strainRateInvField, data, False );
+	
+	Stg_Component_Build( self->brightness, data, False );
+	Stg_Component_Build( self->opacity, data, False );
+	Stg_Component_Build( self->diameter, data, False );
+	Stg_Component_Build( self->tensileFailure, data, False );
+
+}
+
+void _Pouliquen_etal_Initialise( void* rheology, void* data ) {
+	Pouliquen_etal*	self = (Pouliquen_etal*) rheology;
+	Particle_Index		lParticle_I;
+	Particle_Index		particleLocalCount;
+
+	_YieldRheology_Initialise( self, data );
+
+   Stg_Component_Initialise( self->pressureField, data, False );
+	Stg_Component_Initialise( self->strainRateInvField, data, False );
+
+	/* We should only set initial conditions if in regular non-restart mode. If in restart mode, then
+	the particle-based variables will be set correcty when we re-load the Swarm. */
+	if ( self->context->loadFromCheckPoint == False ) {
+      /* Initialise variables that I've created - (mainly just SwarmVariables)
+       * This will run a Variable_Update for us */
+      Stg_Component_Initialise( self->brightness, data, False );
+      Stg_Component_Initialise( self->opacity, data, False );
+      Stg_Component_Initialise( self->diameter, data, False );
+      Stg_Component_Initialise( self->tensileFailure, data, False );
+
+		/* We don't need to Initialise hasYieldedVariable because it's a parent variable and _YieldRheology_Initialise
+		 * has already been called */
+		particleLocalCount = self->hasYieldedVariable->variable->arraySize;
+
+		for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) { 
+		
+			Variable_SetValueFloat( self->brightness->variable, lParticle_I, 0.0 );
+			Variable_SetValueFloat( self->opacity->variable,    lParticle_I, 0.0 );
+			Variable_SetValueFloat( self->diameter->variable,   lParticle_I, 0.0 );
+		
+			Variable_SetValueChar( self->hasYieldedVariable->variable, lParticle_I, False );
+			Variable_SetValueChar( self->tensileFailure->variable,lParticle_I, False );
+		}
+	}	
+}
+
+void _Pouliquen_etal_Destroy( void* rheology, void* data ) {
+	Pouliquen_etal*          self               = (Pouliquen_etal*) rheology;
+
+	Stg_Component_Destroy( self->pressureField, data, False );
+	Stg_Component_Destroy( self->strainRateInvField, data, False );
+	
+	Stg_Component_Destroy( self->brightness, data, False );
+	Stg_Component_Destroy( self->opacity, data, False );
+	Stg_Component_Destroy( self->diameter, data, False );
+	Stg_Component_Destroy( self->tensileFailure, data, False );
+
+	/* Destroy parent */
+	_YieldRheology_Destroy( self, data );
+
+}
+
+
+double _Pouliquen_etal_GetYieldCriterion( 
+			void*                            pouliquen_etal,
+			ConstitutiveMatrix*              constitutiveMatrix,
+			MaterialPointsSwarm*             materialPointsSwarm,
+			Element_LocalIndex               lElement_I,
+			MaterialPoint*                   materialPoint,
+			Coord                            xi )
+{
+	Pouliquen_etal*                    self             = (Pouliquen_etal*) pouliquen_etal;
+
+	double                            frictionalStrength;
+	double                            pressure;
+	Pouliquen_etal_Particle*          particleExt;
+	double                            strainRateInv;
+	
+	particleExt = (Pouliquen_etal_Particle*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, materialPoint, self->particleExtHandle );
+
+	FeVariable_InterpolateWithinElement( self->pressureField, lElement_I, xi, &pressure );
+	FeVariable_InterpolateWithinElement( self->strainRateInvField, lElement_I, xi, &strainRateInv );
+
+	particleExt->pressure      = pressure;
+	particleExt->strainRateInv = strainRateInv;
+
+	frictionalStrength = self->mu_s * pressure;
+	//the following is to ensure that every particle is yielding
+	//frictionalStrength = -1.0;	
+
+	return frictionalStrength;
+}
+
+void _Pouliquen_etal_UpdateDrawParameters( void* rheology ) {
+	Pouliquen_etal*                   self               = (Pouliquen_etal*) rheology;
+	Particle_Index                   lParticle_I;
+	Particle_Index                   particleLocalCount;
+	StrainWeakening*                 strainWeakening    = self->strainWeakening;
+	MaterialPoint*                   materialPoint;
+	
+	double                           length;
+	double                           brightness;
+	double                           opacity;
+	double                           strainWeakeningRatio;
+	double                           localMaxStrainIncrement;
+	double                           localMeanStrainIncrement;
+	Particle_Index                   localFailed;
+	
+	double                           globalMaxStrainIncrement;
+	double                           globalMeanStrainIncrement;
+	Particle_Index                   globalFailed;
+	
+	double                           averagedGlobalMaxStrainIncrement = 0.0;
+
+	double                           oneOverGlobalMaxStrainIncrement;
+	double                           postFailureWeakeningIncrement;
+
+	/* Note : this function defines some drawing parameters (brightness, opacity, diameter) as
+	 * functions of the strain weakening - this needs to be improved since most of the parameters
+	 * that define this dependency are hard coded here. We need to have a more flexible way
+	 * to construct the viz parameters as functions of material parameters */
+
+	/* We should only update the drawing parameters if the strain weakening is defined */ 
+	if (strainWeakening==NULL)
+		return;
+	
+	localMaxStrainIncrement = 0.0;
+	localMeanStrainIncrement = 0.0;
+	localFailed = 0;
+
+	/* Update all variables */
+	Variable_Update( self->hasYieldedVariable->variable );
+	Variable_Update( self->brightness->variable );
+	Variable_Update( self->opacity->variable );
+	Variable_Update( self->diameter->variable );
+	Variable_Update( strainWeakening->postFailureWeakeningIncrement->variable );
+
+	particleLocalCount = self->hasYieldedVariable->variable->arraySize;
+	
+	for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) { 
+		if ( Variable_GetValueChar( self->hasYieldedVariable->variable, lParticle_I )) {
+			localFailed++;
+
+			postFailureWeakeningIncrement = 
+					Variable_GetValueDouble( strainWeakening->postFailureWeakeningIncrement->variable, lParticle_I );
+			
+			localMeanStrainIncrement += postFailureWeakeningIncrement;
+		
+			if(localMaxStrainIncrement < postFailureWeakeningIncrement)
+				localMaxStrainIncrement = postFailureWeakeningIncrement;
+		}
+	}
+	
+	MPI_Allreduce( &localMaxStrainIncrement,  &globalMaxStrainIncrement,  1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );
+	MPI_Allreduce( &localMeanStrainIncrement, &globalMeanStrainIncrement, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
+	MPI_Allreduce( &localFailed,              &globalFailed,              1, MPI_INT,    MPI_SUM, MPI_COMM_WORLD );
+	
+	if(globalFailed == 0) 
+		return;
+				
+	globalMeanStrainIncrement /= (double) globalFailed;
+	
+	averagedGlobalMaxStrainIncrement = 
+			0.5 * averagedGlobalMaxStrainIncrement + 
+			0.25 * globalMeanStrainIncrement +
+			0.25 * globalMaxStrainIncrement;
+	
+	/* Let's simply assume that twice the mean is a good place to truncate these values */
+	oneOverGlobalMaxStrainIncrement = 1.0 / averagedGlobalMaxStrainIncrement;
+	
+	for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) { 
+		materialPoint = (MaterialPoint*)Swarm_ParticleAt( strainWeakening->swarm, lParticle_I );
+
+		if ( Variable_GetValueChar( self->hasYieldedVariable->variable, lParticle_I ) == False ||
+					StrainWeakening_GetPostFailureWeakening( strainWeakening, materialPoint ) < 0.0 ) 
+		{
+			Variable_SetValueFloat( self->brightness->variable, lParticle_I, 0.0 );
+			Variable_SetValueFloat( self->opacity->variable, lParticle_I, 0.0 );
+			Variable_SetValueFloat( self->diameter->variable, lParticle_I, 0.0 );
+			continue;
+		}  
+
+		postFailureWeakeningIncrement = 
+				Variable_GetValueDouble( strainWeakening->postFailureWeakeningIncrement->variable, lParticle_I );
+			
+		strainWeakeningRatio = StrainWeakening_CalcRatio( strainWeakening, materialPoint );
+		
+		length     = 0.001 + 0.003 * strainWeakeningRatio;
+		brightness = strainWeakeningRatio * postFailureWeakeningIncrement * oneOverGlobalMaxStrainIncrement;
+		
+		opacity = 0.5 * brightness; 
+		
+		if( brightness > 1.0 )
+			brightness = 1.0;
+		
+		if( opacity > 0.5 )
+			opacity = 0.5;
+		
+		if( opacity < 0.1 )
+			opacity = 0.0;
+		
+		Variable_SetValueFloat( self->brightness->variable, lParticle_I, brightness );
+		Variable_SetValueFloat( self->opacity->variable,    lParticle_I, opacity );
+		Variable_SetValueFloat( self->diameter->variable,   lParticle_I, (float) length );
+	}
+	
+}
+
+void _Pouliquen_etal_HasYielded( 
+		void*                            rheology,
+		ConstitutiveMatrix*              constitutiveMatrix,
+		MaterialPointsSwarm*             materialPointsSwarm,
+		Element_LocalIndex               lElement_I,
+		MaterialPoint*                   materialPoint,
+		double                           yieldCriterion,
+		double                           yieldIndicator )
+{
+	Pouliquen_etal*                  self             = (Pouliquen_etal*) rheology;
+	double                    viscosity;
+	double                    oneOnI;
+	Pouliquen_etal_Particle*         particleExt;
+	double                    mu;
+	double                    strainWeakeningRatio;
+	/*double                    mu_2_afterSoftening =	self->mu_2_afterSoftening;
+	double                    mu_s_afterSoftening =	self->mu_s_afterSoftening;*/
+	double                    effective_mu_s;
+	double                    effective_mu_2;
+	double                    pressure;
+
+	strainWeakeningRatio = StrainWeakening_CalcRatio( self->strainWeakening, materialPoint );
+
+	particleExt = (Pouliquen_etal_Particle*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, materialPoint, self->particleExtHandle );
+
+	if (fabs(particleExt->strainRateInv) <1.0e-10)
+		particleExt->strainRateInv = 1.0e-10;
+
+	/* The initial rheology is only defined for positive pressures.
+	   As the pressure gets closer to a null value, the effective viscosity tends to zero,
+	   which is equivalent to saying that the pressure only acts against the motion when its
+	   compressive. Therefore negative pressures (tensile environment) are equivalent to a null 
+	   pressure in this sense. */
+	if (particleExt->pressure<0) {
+		pressure = 0.0;	
+	}
+	else {
+		pressure = particleExt->pressure;
+	}
+
+	oneOnI = sqrt(pressure/self->rho_s)/(particleExt->strainRateInv*self->grainDiameter);
+
+	/*
+	effective_mu_s =  self->mu_s * (1.0 - strainWeakeningRatio) + 
+			mu_s_afterSoftening * strainWeakeningRatio;	
+	effective_mu_2 =  self->mu_2 * (1.0 - strainWeakeningRatio) + 
+			mu_2_afterSoftening * strainWeakeningRatio;
+	*/
+	effective_mu_s =  self->mu_s;
+	effective_mu_2 =  self->mu_2;
+
+	mu = effective_mu_s + (effective_mu_2-effective_mu_s)/(self->Io*oneOnI+1.);
+
+	viscosity = mu * pressure/particleExt->strainRateInv;
+
+	/*
+	printf("oneOnI=%f self->rho_s=%f strainWeakeningRatio=%f effective_mu_s =%f\n",oneOnI,self->rho_s,strainWeakeningRatio,effective_mu_s );
+	printf("particleExt->pressure=%f particleExt->strainRateInv=%f self->grainDiameter=%f\n",particleExt->pressure,particleExt->strainRateInv,self->grainDiameter);
+	printf("mu=%f viscosity=%f\n",mu,viscosity);
+	*/	
+
+	if (viscosity > self->maxViscosity)
+		viscosity = self->maxViscosity;
+	if (viscosity < self->minViscosity)
+		viscosity = self->minViscosity;
+
+	ConstitutiveMatrix_SetIsotropicViscosity( constitutiveMatrix, viscosity );
+}
+
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/RheologyClass.c
--- a/Rheology/src/RheologyClass.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,121 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: RheologyClass.c 610 2007-10-11 08:09:29Z SteveQuenette $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "ConstitutiveMatrix.h"
-#include "RheologyClass.h"
-
-#include <assert.h>
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type Rheology_Type = "Rheology";
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-Rheology* _Rheology_New(  RHEOLOGY_DEFARGS  ) 
-{
-	Rheology*					self;
-
-	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-	assert( _sizeOfSelf >= sizeof(Rheology) );
-	/* 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 = (Rheology*) _Stg_Component_New(  STG_COMPONENT_PASSARGS  );
-	
-	/* Function pointers for this class that are not on the parent class should be set here */
-	self->_modifyConstitutiveMatrix = _modifyConstitutiveMatrix;
-	
-	return self;
-}
-
-void _Rheology_Init( void* rheology, PICelleratorContext* context )
-{
-	Rheology* self = (Rheology*)rheology;
-
-	self->context = context;
-	self->debug = Journal_Register( Debug_Type, (Name)self->type ); /* TODO make child of Underworld_Debug */
-}
-
-void _Rheology_Delete( void* rheology ) {
-	Rheology*					self = (Rheology*)rheology;
-
-	_Stg_Component_Delete( self  );
-}
-
-void _Rheology_Print( void* rheology, Stream* stream ) {}
-
-void* _Rheology_Copy( const void* rheology, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	Rheology*	self = (Rheology*)rheology;
-
-	/* TODO */ abort();
-	return (void*) self;
-}
-
-void _Rheology_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
-	Rheology*            self = (Rheology*)rheology;
-	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  );
-
-	_Rheology_Init( self, context );
-}
-
-void _Rheology_Build( void* rheology, void* data ) {}
-void _Rheology_Initialise( void* rheology, void* data ) {}
-void _Rheology_Execute( void* rheology, void* data ) {}
-void _Rheology_Destroy( void* rheology, void* data ) {}
-
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/RheologyClass.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/RheologyClass.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,121 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: RheologyClass.c 610 2007-10-11 08:09:29Z SteveQuenette $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "ConstitutiveMatrix.h"
+#include "RheologyClass.h"
+
+#include <assert.h>
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type Rheology_Type = "Rheology";
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+Rheology* _Rheology_New(  RHEOLOGY_DEFARGS  ) 
+{
+	Rheology*					self;
+
+	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+	assert( _sizeOfSelf >= sizeof(Rheology) );
+	/* 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 = (Rheology*) _Stg_Component_New(  STG_COMPONENT_PASSARGS  );
+	
+	/* Function pointers for this class that are not on the parent class should be set here */
+	self->_modifyConstitutiveMatrix = _modifyConstitutiveMatrix;
+	
+	return self;
+}
+
+void _Rheology_Init( void* rheology, PICelleratorContext* context )
+{
+	Rheology* self = (Rheology*)rheology;
+
+	self->context = context;
+	self->debug = Journal_Register( Debug_Type, (Name)self->type ); /* TODO make child of Underworld_Debug */
+}
+
+void _Rheology_Delete( void* rheology ) {
+	Rheology*					self = (Rheology*)rheology;
+
+	_Stg_Component_Delete( self  );
+}
+
+void _Rheology_Print( void* rheology, Stream* stream ) {}
+
+void* _Rheology_Copy( const void* rheology, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	Rheology*	self = (Rheology*)rheology;
+
+	/* TODO */ abort();
+	return (void*) self;
+}
+
+void _Rheology_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
+	Rheology*            self = (Rheology*)rheology;
+	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  );
+
+	_Rheology_Init( self, context );
+}
+
+void _Rheology_Build( void* rheology, void* data ) {}
+void _Rheology_Initialise( void* rheology, void* data ) {}
+void _Rheology_Execute( void* rheology, void* data ) {}
+void _Rheology_Destroy( void* rheology, void* data ) {}
+
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/RheologyMaterial.c
--- a/Rheology/src/RheologyMaterial.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,334 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: RheologyMaterial.c 610 2007-10-11 08:09:29Z SteveQuenette $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "RheologyMaterial.h"
-#include "Rheology_Register.h"
-#include "RheologyClass.h"
-#include "Compressible.h"
-
-#include <assert.h>
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type RheologyMaterial_Type = "RheologyMaterial";
-
-RheologyMaterial* RheologyMaterial_New( 
-	Name						name,
-	PICelleratorContext*	context,
-	Stg_Shape*				shape,
-	Dictionary*				materialDictionary,
-	Materials_Register*	materialRegister,
-	Rheology**				rheologyList,
-	Rheology_Index			rheologyCount,
-	Compressible*			compressible )
-{
-  RheologyMaterial* self = (RheologyMaterial*)_RheologyMaterial_DefaultNew( name );
-
-	self->isConstructed = True;
-	_Material_Init( self, context, shape, materialDictionary, materialRegister );
-	_RheologyMaterial_Init( self, rheologyList, rheologyCount, compressible, False );
-
-	return self;
-}
-
-
-void* _RheologyMaterial_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(RheologyMaterial);
-	Type                                                      type = RheologyMaterial_Type;
-	Stg_Class_DeleteFunction*                              _delete = _RheologyMaterial_Delete;
-	Stg_Class_PrintFunction*                                _print = _RheologyMaterial_Print;
-	Stg_Class_CopyFunction*                                  _copy = _RheologyMaterial_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _RheologyMaterial_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _RheologyMaterial_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _RheologyMaterial_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _RheologyMaterial_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _RheologyMaterial_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _RheologyMaterial_Destroy;
-	RheologyMaterial_RunRheologiesFunction*         _runRheologies = _RheologyMaterial_RunRheologies;
-
-	/* 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*) _RheologyMaterial_New(  RHEOLOGYMATERIAL_PASSARGS  );
-}
-
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-RheologyMaterial* _RheologyMaterial_New(  RHEOLOGYMATERIAL_DEFARGS  ) 
-{
-	RheologyMaterial* self;
-
-	/* Call private constructor of parent - this will set virtual functions of parent and continue up the
- 	 *  hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and
- 	 *  initialise all the memory to zero. */
-	assert( _sizeOfSelf >= sizeof(RheologyMaterial) );
-	self = (RheologyMaterial*) _Material_New(  MATERIAL_PASSARGS  );
-	
-	/* Function pointers for this class that are not on the parent class should be set here */
-	self->_runRheologies = _runRheologies;
-	
-	return self;
-}
-
-
-void _RheologyMaterial_AssignFromXML( void* rheologyMaterial, Stg_ComponentFactory* cf, void* data ){
-	RheologyMaterial*	self = (RheologyMaterial*)rheologyMaterial;
-	Rheology**			rheologyList;
-	Rheology_Index		rheologyCount;
-	Compressible*		compressible;
-	Bool					isCompressible;
-
-	_Material_AssignFromXML( self, cf, data );
-
-	/* Adding this check now as the rheologyList is only applicable to
-		RheologyMaterial and is set to NULL for MultiRheologyMaterial.
-		MultiRheologyMaterial is a child of RheologyMaterial but it is bypassing its
-		parents _AssignFromXML functionality before. */
-	if( strcmp( self->type, "MultiRheologyMaterial" ) == 0 ) {
-		rheologyList = NULL;
-	}
-	else {
-		rheologyList = Stg_ComponentFactory_ConstructByList( cf, self->name, (Dictionary_Entry_Key)"Rheology", Stg_ComponentFactory_Unlimited, Rheology, True, &rheologyCount, data  );
-	}
-
-	compressible = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Compressible", Compressible, False, data  ) ;
-
-	isCompressible = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"isCompressible", False  );
-
-	_RheologyMaterial_Init( self, rheologyList, rheologyCount, compressible, isCompressible );
-
-	if( rheologyList )
-		Memory_Free( rheologyList );
-}
-
-
-void _RheologyMaterial_Init(
-	void*				rheologyMaterial,
-	Rheology**		rheologyList,
-	Rheology_Index	rheologyCount,
-	Compressible*	compressible,
-	Bool				isCompressible )
-{
-	RheologyMaterial*	self = (RheologyMaterial*)rheologyMaterial;
-	Rheology_Index		rheology_I;
-
-	self->compressible = compressible;
-	self->isCompressible = isCompressible;
-	self->rheology_Register = Rheology_Register_New();
-
-	/* Adding this check now as the rheologyList is only applicable to
-		RheologyMaterial and is set to NULL for MultiRheologyMaterial.
-		MultiRheologyMaterial is a child of RheologyMaterial but it is bypassing its
-		parents _AssignFromXML functionality before. */
-	if( strcmp( self->type, "MultiRheologyMaterial" ) != 0 ) {
-      /* Add rheologies */
-      for ( rheology_I = 0 ; rheology_I < rheologyCount ; rheology_I++ ) 
-         Rheology_Register_Add( self->rheology_Register, rheologyList[ rheology_I ] );
-   }
-
-	/*	self->debug = Journal_Register( Debug_Type, (Name)self->type ); /* TODO make child of Underworld_Debug */
-}
-
-
-void _RheologyMaterial_Delete( void* rheologyMaterial ) {
-	RheologyMaterial* self = (RheologyMaterial*)rheologyMaterial;
-
-	Stg_Class_Delete( self->rheology_Register );
-	_Material_Delete( self  );
-}
-
-
-void _RheologyMaterial_Print( void* rheologyMaterial, Stream* stream ) {}
-
-
-void* _RheologyMaterial_Copy( const void* rheologyMaterial, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	RheologyMaterial*	self = (RheologyMaterial*)rheologyMaterial;
-
-	/* TODO */ abort();
-	return (void*) self;
-}
-
-
-void _RheologyMaterial_Build( void* rheologyMaterial, void* data ) {
-	RheologyMaterial*   self                 = (RheologyMaterial*)rheologyMaterial;
-	Rheology_Index      rheologyCount = Rheology_Register_GetCount( self->rheology_Register ); 
-	Rheology*           rheology;
-	Rheology_Index      rheology_I; 
-
-	_Material_Build( self, data );
-	
-	for( rheology_I = 0; rheology_I < rheologyCount ; rheology_I++ ) { 
-		rheology = Rheology_Register_GetByIndex( self->rheology_Register, rheology_I );
-		
-		Stg_Component_Build( rheology, data, False ); 
-	}
-	
-}
-void _RheologyMaterial_Initialise( void* rheologyMaterial, void* data ) {
-	RheologyMaterial*   self                 = (RheologyMaterial*)rheologyMaterial;
-	Rheology_Index      rheologyCount = Rheology_Register_GetCount( self->rheology_Register ); 
-	Rheology*           rheology;
-	Rheology_Index      rheology_I; 
-
-	_Material_Initialise( self, data );
-
-	for( rheology_I = 0; rheology_I < rheologyCount ; rheology_I++ ) { 
-		rheology = Rheology_Register_GetByIndex( self->rheology_Register, rheology_I );
-		
-		Stg_Component_Initialise( rheology, data, False ); 
-	}
-	
-}
-void _RheologyMaterial_Execute( void* rheologyMaterial, void* data ) {
-	RheologyMaterial*   self                 = (RheologyMaterial*)rheologyMaterial;
-	_Material_Execute( self, data );
-}
-void _RheologyMaterial_Destroy( void* rheologyMaterial, void* data ) {
-	RheologyMaterial*   self                 = (RheologyMaterial*)rheologyMaterial;
-	Rheology_Index      rheologyCount = Rheology_Register_GetCount( self->rheology_Register ); 
-	Rheology*           rheology;
-	Rheology_Index      rheology_I; 
-
-	for( rheology_I = 0; rheology_I < rheologyCount ; rheology_I++ ) { 
-		rheology = Rheology_Register_GetByIndex( self->rheology_Register, rheology_I );
-		
-		Stg_Component_Destroy( rheology, data, False ); 
-	}
-	
-	_Material_Destroy( self, data );
-
-}
-
-void RheologyMaterial_RunRheologies( 	
-		void*                                              rheologyMaterial,
-		ConstitutiveMatrix*                                constitutiveMatrix,
-		MaterialPointsSwarm*                               swarm,
-		Element_LocalIndex                                 lElement_I,
-		MaterialPoint*                                     materialPoint,
-		Coord                                              xi ) 
-{
-	RheologyMaterial*   self                 = (RheologyMaterial*)rheologyMaterial;
-
-	self->_runRheologies( self, constitutiveMatrix, swarm, lElement_I, materialPoint, xi );
-}
-
-void _RheologyMaterial_RunRheologies( 	
-		void*                                              rheologyMaterial,
-		ConstitutiveMatrix*                                constitutiveMatrix,
-		MaterialPointsSwarm*                               swarm,
-		Element_LocalIndex                                 lElement_I,
-		MaterialPoint*                                     materialPoint,
-		Coord                                              xi )
-{
-	RheologyMaterial*   self                 = (RheologyMaterial*)rheologyMaterial;
-
-	Rheology_Register_RunRheologies( 
-			self->rheology_Register,
-			constitutiveMatrix,
-			swarm, 
-			lElement_I,
-			materialPoint,
-			xi );
-}
-
-Bool RheologyMaterial_IsNonLinear( void* rheologyMaterial ) {
-	RheologyMaterial*   self                 = (RheologyMaterial*)rheologyMaterial;
-	Rheology_Index      rheology_I; 
-	Rheology_Index      rheologyCount = Rheology_Register_GetCount( self->rheology_Register ); 
-	Rheology*           rheology; 
-	
-	Journal_DFirewall( 
-			rheologyCount > 0, 
-			Journal_Register( Error_Type, (Name)self->type  ), 
-			"No rheologies registered on %s '%s'.\n", self->type, self->name ); 
-	
-	for( rheology_I = 0; rheology_I < rheologyCount ; rheology_I++ ) { 
-		rheology = Rheology_Register_GetByIndex( self->rheology_Register, rheology_I ); 
-		if ( rheology->nonLinear )
-			return True;
-	}
-
-	return False;
-}
-
-Rheology* RheologyMaterial_GetRheologyByType( void* rheologyMaterial, Type type ) {
-	RheologyMaterial*   self                 = (RheologyMaterial*)rheologyMaterial;
-	Rheology_Index      rheology_I; 
-	Rheology_Index      rheologyCount = Rheology_Register_GetCount( self->rheology_Register ); 
-	Rheology*           rheology;
-
-	for( rheology_I = 0; rheology_I < rheologyCount ; rheology_I++ ) { 
-		rheology = Rheology_Register_GetByIndex( self->rheology_Register, rheology_I ); 
-
-		if ( Stg_Class_IsInstance( rheology, type ) )
-			return rheology;
-	}
-
-	return NULL;
-}
-
-Bool RheologyMaterial_HasRheology( void* rheologyMaterial, void* rheology ) {
-	RheologyMaterial*   self                 = (RheologyMaterial*)rheologyMaterial;
-	Rheology_Index      rheology_I; 
-	Rheology_Index      rheologyCount = Rheology_Register_GetCount( self->rheology_Register ); 
-	Rheology*           currRheology;
-	
-	for( rheology_I = 0; rheology_I < rheologyCount ; rheology_I++ ) { 
-		currRheology = Rheology_Register_GetByIndex( self->rheology_Register, rheology_I ); 
-
-		if ( rheology == currRheology )
-			return True;
-	}
-	return False;
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/RheologyMaterial.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/RheologyMaterial.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,334 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: RheologyMaterial.c 610 2007-10-11 08:09:29Z SteveQuenette $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "RheologyMaterial.h"
+#include "Rheology_Register.h"
+#include "RheologyClass.h"
+#include "Compressible.h"
+
+#include <assert.h>
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type RheologyMaterial_Type = "RheologyMaterial";
+
+RheologyMaterial* RheologyMaterial_New( 
+	Name						name,
+	PICelleratorContext*	context,
+	Stg_Shape*				shape,
+	Dictionary*				materialDictionary,
+	Materials_Register*	materialRegister,
+	Rheology**				rheologyList,
+	Rheology_Index			rheologyCount,
+	Compressible*			compressible )
+{
+  RheologyMaterial* self = (RheologyMaterial*)_RheologyMaterial_DefaultNew( name );
+
+	self->isConstructed = True;
+	_Material_Init( self, context, shape, materialDictionary, materialRegister );
+	_RheologyMaterial_Init( self, rheologyList, rheologyCount, compressible, False );
+
+	return self;
+}
+
+
+void* _RheologyMaterial_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(RheologyMaterial);
+	Type                                                      type = RheologyMaterial_Type;
+	Stg_Class_DeleteFunction*                              _delete = _RheologyMaterial_Delete;
+	Stg_Class_PrintFunction*                                _print = _RheologyMaterial_Print;
+	Stg_Class_CopyFunction*                                  _copy = _RheologyMaterial_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _RheologyMaterial_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _RheologyMaterial_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _RheologyMaterial_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _RheologyMaterial_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _RheologyMaterial_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _RheologyMaterial_Destroy;
+	RheologyMaterial_RunRheologiesFunction*         _runRheologies = _RheologyMaterial_RunRheologies;
+
+	/* 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*) _RheologyMaterial_New(  RHEOLOGYMATERIAL_PASSARGS  );
+}
+
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+RheologyMaterial* _RheologyMaterial_New(  RHEOLOGYMATERIAL_DEFARGS  ) 
+{
+	RheologyMaterial* self;
+
+	/* Call private constructor of parent - this will set virtual functions of parent and continue up the
+ 	 *  hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and
+ 	 *  initialise all the memory to zero. */
+	assert( _sizeOfSelf >= sizeof(RheologyMaterial) );
+	self = (RheologyMaterial*) _Material_New(  MATERIAL_PASSARGS  );
+	
+	/* Function pointers for this class that are not on the parent class should be set here */
+	self->_runRheologies = _runRheologies;
+	
+	return self;
+}
+
+
+void _RheologyMaterial_AssignFromXML( void* rheologyMaterial, Stg_ComponentFactory* cf, void* data ){
+	RheologyMaterial*	self = (RheologyMaterial*)rheologyMaterial;
+	Rheology**			rheologyList;
+	Rheology_Index		rheologyCount;
+	Compressible*		compressible;
+	Bool					isCompressible;
+
+	_Material_AssignFromXML( self, cf, data );
+
+	/* Adding this check now as the rheologyList is only applicable to
+		RheologyMaterial and is set to NULL for MultiRheologyMaterial.
+		MultiRheologyMaterial is a child of RheologyMaterial but it is bypassing its
+		parents _AssignFromXML functionality before. */
+	if( strcmp( self->type, "MultiRheologyMaterial" ) == 0 ) {
+		rheologyList = NULL;
+	}
+	else {
+		rheologyList = Stg_ComponentFactory_ConstructByList( cf, self->name, (Dictionary_Entry_Key)"Rheology", Stg_ComponentFactory_Unlimited, Rheology, True, &rheologyCount, data  );
+	}
+
+	compressible = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Compressible", Compressible, False, data  ) ;
+
+	isCompressible = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"isCompressible", False  );
+
+	_RheologyMaterial_Init( self, rheologyList, rheologyCount, compressible, isCompressible );
+
+	if( rheologyList )
+		Memory_Free( rheologyList );
+}
+
+
+void _RheologyMaterial_Init(
+	void*				rheologyMaterial,
+	Rheology**		rheologyList,
+	Rheology_Index	rheologyCount,
+	Compressible*	compressible,
+	Bool				isCompressible )
+{
+	RheologyMaterial*	self = (RheologyMaterial*)rheologyMaterial;
+	Rheology_Index		rheology_I;
+
+	self->compressible = compressible;
+	self->isCompressible = isCompressible;
+	self->rheology_Register = Rheology_Register_New();
+
+	/* Adding this check now as the rheologyList is only applicable to
+		RheologyMaterial and is set to NULL for MultiRheologyMaterial.
+		MultiRheologyMaterial is a child of RheologyMaterial but it is bypassing its
+		parents _AssignFromXML functionality before. */
+	if( strcmp( self->type, "MultiRheologyMaterial" ) != 0 ) {
+      /* Add rheologies */
+      for ( rheology_I = 0 ; rheology_I < rheologyCount ; rheology_I++ ) 
+         Rheology_Register_Add( self->rheology_Register, rheologyList[ rheology_I ] );
+   }
+
+	/*	self->debug = Journal_Register( Debug_Type, (Name)self->type ); /* TODO make child of Underworld_Debug */
+}
+
+
+void _RheologyMaterial_Delete( void* rheologyMaterial ) {
+	RheologyMaterial* self = (RheologyMaterial*)rheologyMaterial;
+
+	Stg_Class_Delete( self->rheology_Register );
+	_Material_Delete( self  );
+}
+
+
+void _RheologyMaterial_Print( void* rheologyMaterial, Stream* stream ) {}
+
+
+void* _RheologyMaterial_Copy( const void* rheologyMaterial, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	RheologyMaterial*	self = (RheologyMaterial*)rheologyMaterial;
+
+	/* TODO */ abort();
+	return (void*) self;
+}
+
+
+void _RheologyMaterial_Build( void* rheologyMaterial, void* data ) {
+	RheologyMaterial*   self                 = (RheologyMaterial*)rheologyMaterial;
+	Rheology_Index      rheologyCount = Rheology_Register_GetCount( self->rheology_Register ); 
+	Rheology*           rheology;
+	Rheology_Index      rheology_I; 
+
+	_Material_Build( self, data );
+	
+	for( rheology_I = 0; rheology_I < rheologyCount ; rheology_I++ ) { 
+		rheology = Rheology_Register_GetByIndex( self->rheology_Register, rheology_I );
+		
+		Stg_Component_Build( rheology, data, False ); 
+	}
+	
+}
+void _RheologyMaterial_Initialise( void* rheologyMaterial, void* data ) {
+	RheologyMaterial*   self                 = (RheologyMaterial*)rheologyMaterial;
+	Rheology_Index      rheologyCount = Rheology_Register_GetCount( self->rheology_Register ); 
+	Rheology*           rheology;
+	Rheology_Index      rheology_I; 
+
+	_Material_Initialise( self, data );
+
+	for( rheology_I = 0; rheology_I < rheologyCount ; rheology_I++ ) { 
+		rheology = Rheology_Register_GetByIndex( self->rheology_Register, rheology_I );
+		
+		Stg_Component_Initialise( rheology, data, False ); 
+	}
+	
+}
+void _RheologyMaterial_Execute( void* rheologyMaterial, void* data ) {
+	RheologyMaterial*   self                 = (RheologyMaterial*)rheologyMaterial;
+	_Material_Execute( self, data );
+}
+void _RheologyMaterial_Destroy( void* rheologyMaterial, void* data ) {
+	RheologyMaterial*   self                 = (RheologyMaterial*)rheologyMaterial;
+	Rheology_Index      rheologyCount = Rheology_Register_GetCount( self->rheology_Register ); 
+	Rheology*           rheology;
+	Rheology_Index      rheology_I; 
+
+	for( rheology_I = 0; rheology_I < rheologyCount ; rheology_I++ ) { 
+		rheology = Rheology_Register_GetByIndex( self->rheology_Register, rheology_I );
+		
+		Stg_Component_Destroy( rheology, data, False ); 
+	}
+	
+	_Material_Destroy( self, data );
+
+}
+
+void RheologyMaterial_RunRheologies( 	
+		void*                                              rheologyMaterial,
+		ConstitutiveMatrix*                                constitutiveMatrix,
+		MaterialPointsSwarm*                               swarm,
+		Element_LocalIndex                                 lElement_I,
+		MaterialPoint*                                     materialPoint,
+		Coord                                              xi ) 
+{
+	RheologyMaterial*   self                 = (RheologyMaterial*)rheologyMaterial;
+
+	self->_runRheologies( self, constitutiveMatrix, swarm, lElement_I, materialPoint, xi );
+}
+
+void _RheologyMaterial_RunRheologies( 	
+		void*                                              rheologyMaterial,
+		ConstitutiveMatrix*                                constitutiveMatrix,
+		MaterialPointsSwarm*                               swarm,
+		Element_LocalIndex                                 lElement_I,
+		MaterialPoint*                                     materialPoint,
+		Coord                                              xi )
+{
+	RheologyMaterial*   self                 = (RheologyMaterial*)rheologyMaterial;
+
+	Rheology_Register_RunRheologies( 
+			self->rheology_Register,
+			constitutiveMatrix,
+			swarm, 
+			lElement_I,
+			materialPoint,
+			xi );
+}
+
+Bool RheologyMaterial_IsNonLinear( void* rheologyMaterial ) {
+	RheologyMaterial*   self                 = (RheologyMaterial*)rheologyMaterial;
+	Rheology_Index      rheology_I; 
+	Rheology_Index      rheologyCount = Rheology_Register_GetCount( self->rheology_Register ); 
+	Rheology*           rheology; 
+	
+	Journal_DFirewall( 
+			rheologyCount > 0, 
+			Journal_Register( Error_Type, (Name)self->type  ), 
+			"No rheologies registered on %s '%s'.\n", self->type, self->name ); 
+	
+	for( rheology_I = 0; rheology_I < rheologyCount ; rheology_I++ ) { 
+		rheology = Rheology_Register_GetByIndex( self->rheology_Register, rheology_I ); 
+		if ( rheology->nonLinear )
+			return True;
+	}
+
+	return False;
+}
+
+Rheology* RheologyMaterial_GetRheologyByType( void* rheologyMaterial, Type type ) {
+	RheologyMaterial*   self                 = (RheologyMaterial*)rheologyMaterial;
+	Rheology_Index      rheology_I; 
+	Rheology_Index      rheologyCount = Rheology_Register_GetCount( self->rheology_Register ); 
+	Rheology*           rheology;
+
+	for( rheology_I = 0; rheology_I < rheologyCount ; rheology_I++ ) { 
+		rheology = Rheology_Register_GetByIndex( self->rheology_Register, rheology_I ); 
+
+		if ( Stg_Class_IsInstance( rheology, type ) )
+			return rheology;
+	}
+
+	return NULL;
+}
+
+Bool RheologyMaterial_HasRheology( void* rheologyMaterial, void* rheology ) {
+	RheologyMaterial*   self                 = (RheologyMaterial*)rheologyMaterial;
+	Rheology_Index      rheology_I; 
+	Rheology_Index      rheologyCount = Rheology_Register_GetCount( self->rheology_Register ); 
+	Rheology*           currRheology;
+	
+	for( rheology_I = 0; rheology_I < rheologyCount ; rheology_I++ ) { 
+		currRheology = Rheology_Register_GetByIndex( self->rheology_Register, rheology_I ); 
+
+		if ( rheology == currRheology )
+			return True;
+	}
+	return False;
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/Rheology_Register.c
--- a/Rheology/src/Rheology_Register.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,90 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: Rheology_Register.c 610 2007-10-11 08:09:29Z SteveQuenette $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "Rheology_Register.h"
-#include "Rheology.h"
-#include <string.h>
-
-const Type Rheology_Register_Type = "Rheology_Register";
-
-Rheology_Register*	Rheology_Register_New( void ) {
-	/* Variables set in this function */
-	SizeT                      _sizeOfSelf = sizeof(Rheology_Register);
-	Type                              type = Rheology_Register_Type;
-	Stg_Class_DeleteFunction*      _delete = _NamedObject_Register_Delete;
-	Stg_Class_PrintFunction*        _print = _NamedObject_Register_Print;
-	Stg_Class_CopyFunction*          _copy = NULL;
-
-	return (Rheology_Register*) _NamedObject_Register_New(  NAMEDOBJECT_REGISTER_PASSARGS  );
-}
-
-void Rheology_Register_RunRheologies( 	
-		Rheology_Register*                                 self,
-		ConstitutiveMatrix*                                constitutiveMatrix,
-		MaterialPointsSwarm*                               swarm,
-		Element_LocalIndex                                 lElement_I,
-		MaterialPoint*                                     materialPoint,
-		Coord                                              xi )
-{
-	Rheology_Index      rheology_I; 
-	Rheology_Index      rheologyCount = Rheology_Register_GetCount( self ); 
-	Rheology*           rheology; 
-	
-	for( rheology_I = 0; rheology_I < rheologyCount ; rheology_I++ ) { 
-		rheology = Rheology_Register_GetByIndex( self, rheology_I ); 
-		Rheology_ModifyConstitutiveMatrix( rheology, constitutiveMatrix, swarm, lElement_I, materialPoint, xi ); 
-	}
-}
-
-
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/Rheology_Register.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/Rheology_Register.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,90 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: Rheology_Register.c 610 2007-10-11 08:09:29Z SteveQuenette $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "Rheology_Register.h"
+#include "Rheology.h"
+#include <string.h>
+
+const Type Rheology_Register_Type = "Rheology_Register";
+
+Rheology_Register*	Rheology_Register_New( void ) {
+	/* Variables set in this function */
+	SizeT                      _sizeOfSelf = sizeof(Rheology_Register);
+	Type                              type = Rheology_Register_Type;
+	Stg_Class_DeleteFunction*      _delete = _NamedObject_Register_Delete;
+	Stg_Class_PrintFunction*        _print = _NamedObject_Register_Print;
+	Stg_Class_CopyFunction*          _copy = NULL;
+
+	return (Rheology_Register*) _NamedObject_Register_New(  NAMEDOBJECT_REGISTER_PASSARGS  );
+}
+
+void Rheology_Register_RunRheologies( 	
+		Rheology_Register*                                 self,
+		ConstitutiveMatrix*                                constitutiveMatrix,
+		MaterialPointsSwarm*                               swarm,
+		Element_LocalIndex                                 lElement_I,
+		MaterialPoint*                                     materialPoint,
+		Coord                                              xi )
+{
+	Rheology_Index      rheology_I; 
+	Rheology_Index      rheologyCount = Rheology_Register_GetCount( self ); 
+	Rheology*           rheology; 
+	
+	for( rheology_I = 0; rheology_I < rheologyCount ; rheology_I++ ) { 
+		rheology = Rheology_Register_GetByIndex( self, rheology_I ); 
+		Rheology_ModifyConstitutiveMatrix( rheology, constitutiveMatrix, swarm, lElement_I, materialPoint, xi ); 
+	}
+}
+
+
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/StoreStress.c
--- a/Rheology/src/StoreStress.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,217 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: StoreStress.c 747 2008-07-04 01:36:54Z LukeHodkinson $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "RheologyClass.h"
-#include "StoreStress.h"
-#include "ConstitutiveMatrix.h"
-
-#include <assert.h>
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type StoreStress_Type = "StoreStress";
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-StoreStress* _StoreStress_New(  STORESTRESS_DEFARGS  ) 
-{
-	StoreStress*					self;
-
-	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-	assert( _sizeOfSelf >= sizeof(StoreStress) );
-	self = (StoreStress*) _Rheology_New(  RHEOLOGY_PASSARGS  );
-	
-	return self;
-}
-
-void _StoreStress_Init(
-	StoreStress*			self,
-	MaterialPointsSwarm*	materialPointsSwarm,
-	FeVariable*				strainRateField )
-{
-	char*                       variableName[6];
-	StandardParticle           particle;
-	StoreStress_ParticleExt*   particleExt;
-	Index                      variable_I;
-	Dimension_Index            dim = materialPointsSwarm->dim;
-		
-	/* Assign Pointers */
-	self->materialPointsSwarm = materialPointsSwarm;
-	self->strainRateField = strainRateField;
-
-	self->particleExtHandle = ExtensionManager_Add( materialPointsSwarm->particleExtensionMgr, (Name)self->type, sizeof( StoreStress_ParticleExt )  );
-	
-	/* Add SwarmVariables for plotting */
-	particleExt = (StoreStress_ParticleExt*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, &particle, self->particleExtHandle );
-
-	if ( dim == 2 ) {
-		variableName[0] = StG_Strdup( "tau_xx" );
-		variableName[1] = StG_Strdup( "tau_yy" );
-		variableName[2] = StG_Strdup( "tau_xy" );
-	}
-	else {
-		variableName[0] = StG_Strdup( "tau_xx" );
-		variableName[1] = StG_Strdup( "tau_yy" );
-		variableName[2] = StG_Strdup( "tau_zz" );
-		variableName[3] = StG_Strdup( "tau_xy" );
-		variableName[4] = StG_Strdup( "tau_xz" );
-		variableName[5] = StG_Strdup( "tau_yz" );
-	}
-	
-	self->materialPointsSwarmVariable = Swarm_NewVectorVariable( materialPointsSwarm, (Name)"StressTensor", (ArithPointer) &particleExt->stress - (ArithPointer) &particle, 
-		Variable_DataType_Double, 
-		StGermain_nSymmetricTensorVectorComponents(dim), 
-		variableName[0],variableName[1],variableName[2],
-		variableName[3],variableName[4],variableName[5]);
-	
-	for( variable_I = 0; variable_I < StGermain_nSymmetricTensorVectorComponents(dim) ; variable_I++ )
-		Memory_Free( variableName[ variable_I ] );
-
-}
-
-void* _StoreStress_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                     _sizeOfSelf = sizeof(StoreStress);
-	Type                                                             type = StoreStress_Type;
-	Stg_Class_DeleteFunction*                                     _delete = _Rheology_Delete;
-	Stg_Class_PrintFunction*                                       _print = _Rheology_Print;
-	Stg_Class_CopyFunction*                                         _copy = _Rheology_Copy;
-	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _StoreStress_DefaultNew;
-	Stg_Component_ConstructFunction*                           _construct = _StoreStress_AssignFromXML;
-	Stg_Component_BuildFunction*                                   _build = _StoreStress_Build;
-	Stg_Component_InitialiseFunction*                         _initialise = _StoreStress_Initialise;
-	Stg_Component_ExecuteFunction*                               _execute = _Rheology_Execute;
-	Stg_Component_DestroyFunction*                               _destroy = _StoreStress_Destroy;
-	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _StoreStress_ModifyConstitutiveMatrix;
-
-	/* 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*) _StoreStress_New(  STORESTRESS_PASSARGS  );
-}
-
-void _StoreStress_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
-	StoreStress*              self              = (StoreStress*)rheology;
-	MaterialPointsSwarm*      materialPointsSwarm;
-	FeVariable*               strainRateField;
-
-	/* Construct Parent */
-	_Rheology_AssignFromXML( self, cf, data );
-
-	materialPointsSwarm = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"MaterialPointsSwarm", MaterialPointsSwarm, True, data  );
-	/* TODO : 'KeyFallback' soon to be deprecated/updated */
-	strainRateField = Stg_ComponentFactory_ConstructByNameWithKeyFallback( cf, self->name, (Name)"StrainRateField", (Dictionary_Entry_Key)"StrainRateField", FeVariable, True, data  );
-	/*
-	strainRateField = Stg_ComponentFactory_ConstructByKey( cf, self->name, 
-			"StrainRateField", FeVariable, True );
-	*/
-
-	_StoreStress_Init( self, materialPointsSwarm, strainRateField );
-}
-
-void _StoreStress_Build( void* _self, void* data ) {
-	StoreStress*  self               = (StoreStress*) _self;
-
-	/* Build parent */
-	_Rheology_Build( self, data );
-
-	Stg_Component_Build(	self->strainRateField, data, False);	
-	Stg_Component_Build(	self->materialPointsSwarm, data, False);
-	Stg_Component_Build(	self->materialPointsSwarmVariable, data, False);
-
-}
-
-void _StoreStress_Initialise( void* _self, void* data ) {
-	StoreStress*  self               = (StoreStress*) _self;
-
-	/* Initialise parent */
-	_Rheology_Initialise( self, data );
-
-	Stg_Component_Initialise(	self->strainRateField, data, False);	
-	Stg_Component_Initialise(	self->materialPointsSwarm, data, False);
-	Stg_Component_Initialise(	self->materialPointsSwarmVariable, data, False);
-
-}
-
-void _StoreStress_Destroy( void* _self, void* data ) {
-	StoreStress*  self               = (StoreStress*) _self;
-
-	Stg_Component_Destroy(	self->strainRateField, data, False);	
-	Stg_Component_Destroy(	self->materialPointsSwarm, data, False);
-	Stg_Component_Destroy(	self->materialPointsSwarmVariable, data, False);
-
-	/* Destroy parent */
-	_Rheology_Destroy( self, data );
-
-}
-
-void _StoreStress_ModifyConstitutiveMatrix( 
-		void*                                              rheology, 
-		ConstitutiveMatrix*                                constitutiveMatrix,
-		MaterialPointsSwarm*                               materialPointsSwarm,
-		Element_LocalIndex                                 lElement_I,
-		MaterialPoint*                                     materialPoint,
-		Coord                                              xi )
-{
-	StoreStress*	                  self              = (StoreStress*) rheology;
-	StoreStress_ParticleExt*          particleExt;
-	SymmetricTensor                   strainRate;
-
-	/*
-	** HAXOR: Throwing this flag in here to try and prevent REP from
-	** overwriting the previously calculated viscosity value. */
-	if ( !constitutiveMatrix->previousSolutionExists )
-	  return;
-
-	particleExt      = (StoreStress_ParticleExt*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, materialPoint, self->particleExtHandle );
-
-	FeVariable_InterpolateWithinElement( self->strainRateField, lElement_I, xi, strainRate );
-	ConstitutiveMatrix_CalculateStress( constitutiveMatrix, strainRate, particleExt->stress );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/StoreStress.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/StoreStress.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,217 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: StoreStress.c 747 2008-07-04 01:36:54Z LukeHodkinson $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "RheologyClass.h"
+#include "StoreStress.h"
+#include "ConstitutiveMatrix.h"
+
+#include <assert.h>
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type StoreStress_Type = "StoreStress";
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+StoreStress* _StoreStress_New(  STORESTRESS_DEFARGS  ) 
+{
+	StoreStress*					self;
+
+	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+	assert( _sizeOfSelf >= sizeof(StoreStress) );
+	self = (StoreStress*) _Rheology_New(  RHEOLOGY_PASSARGS  );
+	
+	return self;
+}
+
+void _StoreStress_Init(
+	StoreStress*			self,
+	MaterialPointsSwarm*	materialPointsSwarm,
+	FeVariable*				strainRateField )
+{
+	char*                       variableName[6];
+	StandardParticle           particle;
+	StoreStress_ParticleExt*   particleExt;
+	Index                      variable_I;
+	Dimension_Index            dim = materialPointsSwarm->dim;
+		
+	/* Assign Pointers */
+	self->materialPointsSwarm = materialPointsSwarm;
+	self->strainRateField = strainRateField;
+
+	self->particleExtHandle = ExtensionManager_Add( materialPointsSwarm->particleExtensionMgr, (Name)self->type, sizeof( StoreStress_ParticleExt )  );
+	
+	/* Add SwarmVariables for plotting */
+	particleExt = (StoreStress_ParticleExt*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, &particle, self->particleExtHandle );
+
+	if ( dim == 2 ) {
+		variableName[0] = StG_Strdup( "tau_xx" );
+		variableName[1] = StG_Strdup( "tau_yy" );
+		variableName[2] = StG_Strdup( "tau_xy" );
+	}
+	else {
+		variableName[0] = StG_Strdup( "tau_xx" );
+		variableName[1] = StG_Strdup( "tau_yy" );
+		variableName[2] = StG_Strdup( "tau_zz" );
+		variableName[3] = StG_Strdup( "tau_xy" );
+		variableName[4] = StG_Strdup( "tau_xz" );
+		variableName[5] = StG_Strdup( "tau_yz" );
+	}
+	
+	self->materialPointsSwarmVariable = Swarm_NewVectorVariable( materialPointsSwarm, (Name)"StressTensor", (ArithPointer) &particleExt->stress - (ArithPointer) &particle, 
+		Variable_DataType_Double, 
+		StGermain_nSymmetricTensorVectorComponents(dim), 
+		variableName[0],variableName[1],variableName[2],
+		variableName[3],variableName[4],variableName[5]);
+	
+	for( variable_I = 0; variable_I < StGermain_nSymmetricTensorVectorComponents(dim) ; variable_I++ )
+		Memory_Free( variableName[ variable_I ] );
+
+}
+
+void* _StoreStress_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                     _sizeOfSelf = sizeof(StoreStress);
+	Type                                                             type = StoreStress_Type;
+	Stg_Class_DeleteFunction*                                     _delete = _Rheology_Delete;
+	Stg_Class_PrintFunction*                                       _print = _Rheology_Print;
+	Stg_Class_CopyFunction*                                         _copy = _Rheology_Copy;
+	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _StoreStress_DefaultNew;
+	Stg_Component_ConstructFunction*                           _construct = _StoreStress_AssignFromXML;
+	Stg_Component_BuildFunction*                                   _build = _StoreStress_Build;
+	Stg_Component_InitialiseFunction*                         _initialise = _StoreStress_Initialise;
+	Stg_Component_ExecuteFunction*                               _execute = _Rheology_Execute;
+	Stg_Component_DestroyFunction*                               _destroy = _StoreStress_Destroy;
+	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _StoreStress_ModifyConstitutiveMatrix;
+
+	/* 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*) _StoreStress_New(  STORESTRESS_PASSARGS  );
+}
+
+void _StoreStress_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
+	StoreStress*              self              = (StoreStress*)rheology;
+	MaterialPointsSwarm*      materialPointsSwarm;
+	FeVariable*               strainRateField;
+
+	/* Construct Parent */
+	_Rheology_AssignFromXML( self, cf, data );
+
+	materialPointsSwarm = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"MaterialPointsSwarm", MaterialPointsSwarm, True, data  );
+	/* TODO : 'KeyFallback' soon to be deprecated/updated */
+	strainRateField = Stg_ComponentFactory_ConstructByNameWithKeyFallback( cf, self->name, (Name)"StrainRateField", (Dictionary_Entry_Key)"StrainRateField", FeVariable, True, data  );
+	/*
+	strainRateField = Stg_ComponentFactory_ConstructByKey( cf, self->name, 
+			"StrainRateField", FeVariable, True );
+	*/
+
+	_StoreStress_Init( self, materialPointsSwarm, strainRateField );
+}
+
+void _StoreStress_Build( void* _self, void* data ) {
+	StoreStress*  self               = (StoreStress*) _self;
+
+	/* Build parent */
+	_Rheology_Build( self, data );
+
+	Stg_Component_Build(	self->strainRateField, data, False);	
+	Stg_Component_Build(	self->materialPointsSwarm, data, False);
+	Stg_Component_Build(	self->materialPointsSwarmVariable, data, False);
+
+}
+
+void _StoreStress_Initialise( void* _self, void* data ) {
+	StoreStress*  self               = (StoreStress*) _self;
+
+	/* Initialise parent */
+	_Rheology_Initialise( self, data );
+
+	Stg_Component_Initialise(	self->strainRateField, data, False);	
+	Stg_Component_Initialise(	self->materialPointsSwarm, data, False);
+	Stg_Component_Initialise(	self->materialPointsSwarmVariable, data, False);
+
+}
+
+void _StoreStress_Destroy( void* _self, void* data ) {
+	StoreStress*  self               = (StoreStress*) _self;
+
+	Stg_Component_Destroy(	self->strainRateField, data, False);	
+	Stg_Component_Destroy(	self->materialPointsSwarm, data, False);
+	Stg_Component_Destroy(	self->materialPointsSwarmVariable, data, False);
+
+	/* Destroy parent */
+	_Rheology_Destroy( self, data );
+
+}
+
+void _StoreStress_ModifyConstitutiveMatrix( 
+		void*                                              rheology, 
+		ConstitutiveMatrix*                                constitutiveMatrix,
+		MaterialPointsSwarm*                               materialPointsSwarm,
+		Element_LocalIndex                                 lElement_I,
+		MaterialPoint*                                     materialPoint,
+		Coord                                              xi )
+{
+	StoreStress*	                  self              = (StoreStress*) rheology;
+	StoreStress_ParticleExt*          particleExt;
+	SymmetricTensor                   strainRate;
+
+	/*
+	** HAXOR: Throwing this flag in here to try and prevent REP from
+	** overwriting the previously calculated viscosity value. */
+	if ( !constitutiveMatrix->previousSolutionExists )
+	  return;
+
+	particleExt      = (StoreStress_ParticleExt*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, materialPoint, self->particleExtHandle );
+
+	FeVariable_InterpolateWithinElement( self->strainRateField, lElement_I, xi, strainRate );
+	ConstitutiveMatrix_CalculateStress( constitutiveMatrix, strainRate, particleExt->stress );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/StoreViscosity.c
--- a/Rheology/src/StoreViscosity.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,183 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: StoreViscosity.c 788 2008-08-15 04:20:57Z LukeHodkinson $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "RheologyClass.h"
-#include "StoreViscosity.h"
-#include "ConstitutiveMatrix.h"
-
-#include <assert.h>
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type StoreVisc_Type = "StoreVisc";
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-StoreVisc* _StoreVisc_New(  STOREVISC_DEFARGS  ) 
-{
-	StoreVisc*					self;
-
-	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-	assert( _sizeOfSelf >= sizeof(StoreVisc) );
-	self = (StoreVisc*) _Rheology_New(  RHEOLOGY_PASSARGS  );
-	
-	return self;
-}
-
-void _StoreVisc_Init(
-	StoreVisc*				self,
-	MaterialPointsSwarm*	materialPointsSwarm )
-{
-	StandardParticle           particle;
-	StoreVisc_ParticleExt*     particleExt;
-		
-	/* Assign Pointers */
-	self->materialPointsSwarm = materialPointsSwarm;
-
-	self->particleExtHandle = ExtensionManager_Add( materialPointsSwarm->particleExtensionMgr, (Name)self->type, sizeof( StoreVisc_ParticleExt )  );
-	
-	/* Add SwarmVariables for plotting */
-	particleExt = (StoreVisc_ParticleExt*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, &particle, self->particleExtHandle );
-	
-	self->swarmVariable = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"Viscosity", (ArithPointer) &particleExt->effVisc - (ArithPointer) &particle, Variable_DataType_Double );
-}
-
-void* _StoreVisc_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                     _sizeOfSelf = sizeof(StoreVisc);
-	Type                                                             type = StoreVisc_Type;
-	Stg_Class_DeleteFunction*                                     _delete = _Rheology_Delete;
-	Stg_Class_PrintFunction*                                       _print = _Rheology_Print;
-	Stg_Class_CopyFunction*                                         _copy = _Rheology_Copy;
-	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _StoreVisc_DefaultNew;
-	Stg_Component_ConstructFunction*                           _construct = _StoreVisc_AssignFromXML;
-	Stg_Component_BuildFunction*                                   _build = _Rheology_Build;
-	Stg_Component_InitialiseFunction*                         _initialise = _Rheology_Initialise;
-	Stg_Component_ExecuteFunction*                               _execute = _Rheology_Execute;
-	Stg_Component_DestroyFunction*                               _destroy = _Rheology_Destroy;
-	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _StoreVisc_ModifyConstitutiveMatrix;
-
-	/* 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*) _StoreVisc_New(  STOREVISC_PASSARGS   );
-}
-
-void _StoreVisc_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
-	StoreVisc*              self              = (StoreVisc*)rheology;
-	MaterialPointsSwarm* materialPointsSwarm;
-
-	/* Construct Parent */
-	_Rheology_AssignFromXML( self, cf, data );
-
-	materialPointsSwarm = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"MaterialPointsSwarm", MaterialPointsSwarm, True, data  );
-
-	_StoreVisc_Init( self, materialPointsSwarm );
-}
-	
-void _StoreVisc_Build( void* _self, void* data ) {
-	StoreVisc*  self               = (StoreVisc*) _self;
-
-	/* Build parent */
-	_Rheology_Build( self, data );
-
-	Stg_Component_Build(	self->swarmVariable, data, False);	
-	Stg_Component_Build(	self->materialPointsSwarm, data, False);
-
-}
-
-void _StoreVisc_Initialise( void* _self, void* data ) {
-	StoreVisc*  self               = (StoreVisc*) _self;
-
-	/* Initialise parent */
-	_Rheology_Initialise( self, data );
-
-	Stg_Component_Initialise(	self->swarmVariable, data, False);	
-	Stg_Component_Initialise(	self->materialPointsSwarm, data, False);
-
-}
-
-void _StoreVisc_Destroy( void* _self, void* data ) {
-	StoreVisc*  self               = (StoreVisc*) _self;
-
-	Stg_Component_Destroy(	self->swarmVariable, data, False);	
-	Stg_Component_Destroy(	self->materialPointsSwarm, data, False);
-
-	/* Destroy parent */
-	_Rheology_Destroy( self, data );
-
-}
-
-void _StoreVisc_ModifyConstitutiveMatrix( 
-		void*                                              rheology, 
-		ConstitutiveMatrix*                                constitutiveMatrix,
-		MaterialPointsSwarm*                               materialPointsSwarm,
-		Element_LocalIndex                                 lElement_I,
-		MaterialPoint*                                     materialPoint,
-		Coord                                              xi )
-{
-	StoreVisc*	                      self              = (StoreVisc*) rheology;
-	StoreVisc_ParticleExt*            particleExt;
-
-#if 0
-	/*
-	** HAXOR: Throwing this flag in here to try and prevent REP from
-	** overwriting the previously calculated viscosity value. */
-	if ( !constitutiveMatrix->previousSolutionExists )
-	  return;
-#endif
-                          
-	/* Get Parameters From Material Extension */
-	particleExt          = (StoreVisc_ParticleExt*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, materialPoint, self->particleExtHandle );
-
-	particleExt->effVisc =  ConstitutiveMatrix_GetIsotropicViscosity(constitutiveMatrix);
-	
-}
-
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/StoreViscosity.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/StoreViscosity.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,183 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: StoreViscosity.c 788 2008-08-15 04:20:57Z LukeHodkinson $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "RheologyClass.h"
+#include "StoreViscosity.h"
+#include "ConstitutiveMatrix.h"
+
+#include <assert.h>
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type StoreVisc_Type = "StoreVisc";
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+StoreVisc* _StoreVisc_New(  STOREVISC_DEFARGS  ) 
+{
+	StoreVisc*					self;
+
+	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+	assert( _sizeOfSelf >= sizeof(StoreVisc) );
+	self = (StoreVisc*) _Rheology_New(  RHEOLOGY_PASSARGS  );
+	
+	return self;
+}
+
+void _StoreVisc_Init(
+	StoreVisc*				self,
+	MaterialPointsSwarm*	materialPointsSwarm )
+{
+	StandardParticle           particle;
+	StoreVisc_ParticleExt*     particleExt;
+		
+	/* Assign Pointers */
+	self->materialPointsSwarm = materialPointsSwarm;
+
+	self->particleExtHandle = ExtensionManager_Add( materialPointsSwarm->particleExtensionMgr, (Name)self->type, sizeof( StoreVisc_ParticleExt )  );
+	
+	/* Add SwarmVariables for plotting */
+	particleExt = (StoreVisc_ParticleExt*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, &particle, self->particleExtHandle );
+	
+	self->swarmVariable = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"Viscosity", (ArithPointer) &particleExt->effVisc - (ArithPointer) &particle, Variable_DataType_Double );
+}
+
+void* _StoreVisc_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                     _sizeOfSelf = sizeof(StoreVisc);
+	Type                                                             type = StoreVisc_Type;
+	Stg_Class_DeleteFunction*                                     _delete = _Rheology_Delete;
+	Stg_Class_PrintFunction*                                       _print = _Rheology_Print;
+	Stg_Class_CopyFunction*                                         _copy = _Rheology_Copy;
+	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _StoreVisc_DefaultNew;
+	Stg_Component_ConstructFunction*                           _construct = _StoreVisc_AssignFromXML;
+	Stg_Component_BuildFunction*                                   _build = _Rheology_Build;
+	Stg_Component_InitialiseFunction*                         _initialise = _Rheology_Initialise;
+	Stg_Component_ExecuteFunction*                               _execute = _Rheology_Execute;
+	Stg_Component_DestroyFunction*                               _destroy = _Rheology_Destroy;
+	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _StoreVisc_ModifyConstitutiveMatrix;
+
+	/* 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*) _StoreVisc_New(  STOREVISC_PASSARGS   );
+}
+
+void _StoreVisc_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
+	StoreVisc*              self              = (StoreVisc*)rheology;
+	MaterialPointsSwarm* materialPointsSwarm;
+
+	/* Construct Parent */
+	_Rheology_AssignFromXML( self, cf, data );
+
+	materialPointsSwarm = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"MaterialPointsSwarm", MaterialPointsSwarm, True, data  );
+
+	_StoreVisc_Init( self, materialPointsSwarm );
+}
+	
+void _StoreVisc_Build( void* _self, void* data ) {
+	StoreVisc*  self               = (StoreVisc*) _self;
+
+	/* Build parent */
+	_Rheology_Build( self, data );
+
+	Stg_Component_Build(	self->swarmVariable, data, False);	
+	Stg_Component_Build(	self->materialPointsSwarm, data, False);
+
+}
+
+void _StoreVisc_Initialise( void* _self, void* data ) {
+	StoreVisc*  self               = (StoreVisc*) _self;
+
+	/* Initialise parent */
+	_Rheology_Initialise( self, data );
+
+	Stg_Component_Initialise(	self->swarmVariable, data, False);	
+	Stg_Component_Initialise(	self->materialPointsSwarm, data, False);
+
+}
+
+void _StoreVisc_Destroy( void* _self, void* data ) {
+	StoreVisc*  self               = (StoreVisc*) _self;
+
+	Stg_Component_Destroy(	self->swarmVariable, data, False);	
+	Stg_Component_Destroy(	self->materialPointsSwarm, data, False);
+
+	/* Destroy parent */
+	_Rheology_Destroy( self, data );
+
+}
+
+void _StoreVisc_ModifyConstitutiveMatrix( 
+		void*                                              rheology, 
+		ConstitutiveMatrix*                                constitutiveMatrix,
+		MaterialPointsSwarm*                               materialPointsSwarm,
+		Element_LocalIndex                                 lElement_I,
+		MaterialPoint*                                     materialPoint,
+		Coord                                              xi )
+{
+	StoreVisc*	                      self              = (StoreVisc*) rheology;
+	StoreVisc_ParticleExt*            particleExt;
+
+#if 0
+	/*
+	** HAXOR: Throwing this flag in here to try and prevent REP from
+	** overwriting the previously calculated viscosity value. */
+	if ( !constitutiveMatrix->previousSolutionExists )
+	  return;
+#endif
+                          
+	/* Get Parameters From Material Extension */
+	particleExt          = (StoreVisc_ParticleExt*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, materialPoint, self->particleExtHandle );
+
+	particleExt->effVisc =  ConstitutiveMatrix_GetIsotropicViscosity(constitutiveMatrix);
+	
+}
+
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/StrainWeakening.c
--- a/Rheology/src/StrainWeakening.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,555 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: StrainWeakening.c 776 2008-08-05 02:39:26Z LouisMoresi $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <stdlib.h>
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "RheologyClass.h"
-#include "YieldRheology.h"
-#include "VonMises.h"
-#include "StrainWeakening.h"
-#include "ConstitutiveMatrix.h"
-
-#include <assert.h>
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type StrainWeakening_Type = "StrainWeakening";
-
-/* Public Constructor */
-StrainWeakening* StrainWeakening_New(
-      Name                                               name,
-		MaterialPointsSwarm*                               swarm,
-		double                                             healingRate,
-		double                                             initialSofteningStrain,
-		double                                             finalSofteningStrain,
-		double                                             initialDamageFraction,
-		double                                             initialDamageWavenumber,
-		double                                             initialDamageWavenumberSinI,
-		double                                             initialDamageWavenumberCosI,
-		double                                             initialDamageWavenumberSinK,
-		double                                             initialDamageWavenumberCosK,
-		double                                             initialDamageFactor,
-		long int                                           randomSeed,
-                Stg_Shape*                                         initialStrainShape,
-                Stg_Shape*                                         strainLimitedShape,
-                double                                             strainLimit
-                                     )
-{
-   StrainWeakening* self = (StrainWeakening*) _StrainWeakening_DefaultNew( name );
-
-   _StrainWeakening_Init(
-	    self,
-	    swarm,
-	    healingRate,
-            initialSofteningStrain,
-            finalSofteningStrain,
-	    initialDamageFraction,
-	    initialDamageWavenumber,
-	    initialDamageWavenumberSinI,
-	    initialDamageWavenumberCosI,
-	    initialDamageWavenumberSinK,
-	    initialDamageWavenumberCosK,
-	    initialDamageFactor,
-	    randomSeed,
-	    initialStrainShape,
-            strainLimitedShape,
-            strainLimit);
-   self->isConstructed = True;
-   return self;
-}
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-StrainWeakening* _StrainWeakening_New(  STRAINWEAKENING_DEFARGS  ) 
-{
-	StrainWeakening*					self;
-
-	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-	assert( _sizeOfSelf >= sizeof(StrainWeakening) );
-	self = (StrainWeakening*) _TimeIntegrand_New(  TIMEINTEGRAND_PASSARGS  );
-	
-	/* Function pointers for this class that are not on the parent class should be set here */
-	self->_calcIncrement = _calcIncrement;
-	
-	return self;
-}
-
-void _StrainWeakening_Init(
-		StrainWeakening*                                   self,
-		MaterialPointsSwarm*                               swarm,
-		double                                             healingRate,
-		double                                             initialSofteningStrain,
-		double                                             finalSofteningStrain,
-		double                                             initialDamageFraction,
-		double                                             initialDamageWavenumber,
-		double                                             initialDamageWavenumberSinI,
-		double                                             initialDamageWavenumberCosI,
-		double                                             initialDamageWavenumberSinK,
-		double                                             initialDamageWavenumberCosK,
-		double                                             initialDamageFactor,
-		long int                                           randomSeed,
-		Stg_Shape*                                         initialStrainShape,
-                Stg_Shape*                                         strainLimitedShape,
-		double                                             strainLimit )
-{
-	/* Assign Values */
-	self->swarm                    = swarm;
-	self->healingRate              = healingRate;
-	self->initialSofteningStrain  = initialSofteningStrain;
-	self->finalSofteningStrain    = finalSofteningStrain;
-	self->initialDamageFraction    = initialDamageFraction;
-	self->initialDamageWavenumber  = initialDamageWavenumber;
-	self->initialDamageWavenumberSinI = initialDamageWavenumberSinI;
-	self->initialDamageWavenumberCosI = initialDamageWavenumberCosI;
-	self->initialDamageWavenumberSinK = initialDamageWavenumberSinK;
-	self->initialDamageWavenumberCosK = initialDamageWavenumberCosK;
-	self->initialDamageFactor         = initialDamageFactor;
-	self->randomSeed                  = randomSeed;
-	self->initialStrainShape          = initialStrainShape;
-	self->strainLimitedShape          = strainLimitedShape;
-	self->strainLimit                 = strainLimit;
-	
-	/****** Setup Variables *****/
-
-	/* First check to see if a particle extension has already been created for this swarm */
-	self->particleExtHandle = ExtensionManager_GetHandle( swarm->particleExtensionMgr, (Name)StrainWeakening_Type );
-
-	/* If there isn't one then create the particle extension - otherwise just use the one already there*/
-	if ( self->particleExtHandle == (ExtensionInfo_Index) -1  ) {
-		StandardParticle             particle;
-		StrainWeakening_ParticleExt* particleExt;
-
-		/* Add particle extension */
-		self->particleExtHandle = 
-			ExtensionManager_Add( swarm->particleExtensionMgr, (Name)StrainWeakening_Type, sizeof(StrainWeakening_ParticleExt)  );	
-
-		particleExt = (StrainWeakening_ParticleExt*)ExtensionManager_Get( swarm->particleExtensionMgr, &particle, self->particleExtHandle );
-
-		/*Add variables for vizualization / analysis purposes */
-		
-		
-		
-		self->postFailureWeakening = Swarm_NewScalarVariable( swarm, (Name)"PostFailureWeakening", (ArithPointer) &particleExt->postFailureWeakening - (ArithPointer) &particle, Variable_DataType_Double  );
-		
-		self->postFailureWeakeningIncrement = Swarm_NewScalarVariable( swarm, (Name)"PostFailureWeakeningIncrement", (ArithPointer) &particleExt->postFailureWeakeningIncrement - (ArithPointer) &particle, Variable_DataType_Double  );
-	}
-	else {
-		char* variableName;
-
-		/* Get Variables already created */
-		variableName = Stg_Object_AppendSuffix( swarm, (Name)"PostFailureWeakening"  );
-		self->postFailureWeakening = SwarmVariable_Register_GetByName( swarm->swarmVariable_Register, variableName );
-		assert( self->postFailureWeakening );
-		Memory_Free( variableName );
-		
-		variableName = Stg_Object_AppendSuffix( swarm, (Name)"PostFailureWeakeningIncrement"  );
-		self->postFailureWeakeningIncrement = SwarmVariable_Register_GetByName( swarm->swarmVariable_Register, variableName );
-		assert( self->postFailureWeakeningIncrement );
-		Memory_Free( variableName );
-	}
-	
-	/* The strain weakening class inherits from the TimeIntegrand class - this class needs a 'Variable' to 
-	 * integrate through time. For the StrainWeakening component this variable is the 'PostFailureWeakening'
-	 * we need to set this explicitly here */
-	self->variable = self->postFailureWeakening->variable;
-	
-	/* Add function to entry point which is called at the end of the time integration steps - 
-	 * this will make all the negative values zero */
-	TimeIntegrator_AppendFinishEP( self->timeIntegrator,
-                                       "StrainWeakening_MakeValuesPositive", (void*)_StrainWeakening_MakeValuesPositive, self->name, self );
-
-}
-
-void* _StrainWeakening_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                               _sizeOfSelf = sizeof(StrainWeakening);
-	Type                                                       type = StrainWeakening_Type;
-	Stg_Class_DeleteFunction*                               _delete = _TimeIntegrand_Delete;
-	Stg_Class_PrintFunction*                                 _print = _TimeIntegrand_Print;
-	Stg_Class_CopyFunction*                                   _copy = _TimeIntegrand_Copy;
-	Stg_Component_DefaultConstructorFunction*   _defaultConstructor = _StrainWeakening_DefaultNew;
-	Stg_Component_ConstructFunction*                     _construct = _StrainWeakening_AssignFromXML;
-	Stg_Component_BuildFunction*                             _build = _StrainWeakening_Build;
-	Stg_Component_InitialiseFunction*                   _initialise = _StrainWeakening_Initialise;
-	Stg_Component_ExecuteFunction*                         _execute = _TimeIntegrand_Execute;
-	Stg_Component_DestroyFunction*                         _destroy = _TimeIntegrand_Destroy;
-	TimeIntegrand_CalculateTimeDerivFunction*  _calculateTimeDeriv = _StrainWeakening_TimeDerivative;
-	TimeIntegrand_IntermediateFunction*              _intermediate = _TimeIntegrand_Intermediate;
-	StrainWeakening_CalcIncrementFunction*           _calcIncrement = _StrainWeakening_CalcIncrementIsotropic;
-
-	/* 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*) _StrainWeakening_New(  STRAINWEAKENING_PASSARGS  );
-}
-
-void _StrainWeakening_AssignFromXML( void* strainWeakening, Stg_ComponentFactory* cf, void* data ){
-	StrainWeakening*        self           = (StrainWeakening*) strainWeakening;
-	MaterialPointsSwarm*    materialPointsSwarm;
-	double                  healingRate;
-	double                  initialSofteningStrain;
-	double                  finalSofteningStrain;
-	double                  initialDamageFraction;
-	double                  initialDamageWavenumber;
-	double                  initialDamageWavenumberSinI;
-	double                  initialDamageWavenumberCosI;
-	double                  initialDamageWavenumberSinK;
-	double                  initialDamageWavenumberCosK;
-	double                  initialDamageFactor;
-	long int                randomSeed;
-	Stg_Shape*              initialStrainShape;
-	Stg_Shape*              strainLimitedShape;
-	double                  strainLimit;
-
-	/* Construct Parent */
-	_TimeIntegrand_AssignFromXML( self, cf, data );
-	
-	materialPointsSwarm     = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"MaterialPointsSwarm", MaterialPointsSwarm, True, data  );
-
-	healingRate                 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"healingRate", 0.0  );
-	initialSofteningStrain  = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"initialSofteningStrain", 0 );
-        /* Backwards compatibility.  Look at softeningStrain and
-           finalSofteningStrain. */
-	finalSofteningStrain    = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"softeningStrain",   HUGE_VAL );
-	finalSofteningStrain    = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"finalSofteningStrain", finalSofteningStrain );
-	initialDamageFraction       = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"initialDamageFraction", 0.0  );
-	initialDamageWavenumber     = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"initialDamageWavenumber", -1.0  );
-	initialDamageWavenumberSinI = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"initialDamageWavenumberSinI", -1.0  );
-	initialDamageWavenumberCosI = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"initialDamageWavenumberCosI", -1.0  );
-	initialDamageWavenumberSinK = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"initialDamageWavenumberSinK", -1.0  );
-	initialDamageWavenumberCosK = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"initialDamageWavenumberCosK", -1.0  );
-	initialDamageFactor         = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"initialDamageFactor", 1.0 );
-	randomSeed                  = (long int ) Stg_ComponentFactory_GetInt( cf, self->name, (Dictionary_Entry_Key)"randomSeed", 0  );
-	initialStrainShape          = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"initialStrainShape", Stg_Shape, False, data  );
-	strainLimitedShape          = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"strainLimitedShape", Stg_Shape, False, data  );
-	strainLimit                 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"strainLimit", 0.0 );
-
-	_StrainWeakening_Init(
-			self, 
-			materialPointsSwarm, 
-			healingRate,
-			initialSofteningStrain,
-			finalSofteningStrain,
-			initialDamageFraction,
-			initialDamageWavenumber, 
-			initialDamageWavenumberSinI, 
-			initialDamageWavenumberCosI, 
-			initialDamageWavenumberSinK, 
-			initialDamageWavenumberCosK, 
-			initialDamageFactor,
-			randomSeed,
-			initialStrainShape,
-                        strainLimitedShape,
-                        strainLimit);
-}
-
-void _StrainWeakening_Build( void* strainWeakening, void* data ) {
-   StrainWeakening*                       self               = (StrainWeakening*) strainWeakening;
-
-   /* Build parent */
-   _TimeIntegrand_Build( self, data );
-
-   Stg_Component_Build( self->postFailureWeakeningIncrement, data, False );
-   Stg_Component_Build( self->postFailureWeakening, data, False );
-   if( self->initialStrainShape ) Stg_Component_Build( self->initialStrainShape, data, False );
-   if( self->strainLimitedShape ) Stg_Component_Build( self->strainLimitedShape, data, False );
-   Stg_Component_Build( self->swarm, data, False );
-   /* The postFailureWeakening doesn't need to be built here because it has already been
-    * built in the TimeIntegrand class
-    * (self->variable = self->postFailureWeakening->variable in _StrainWeakening_Init function) */
-    /* however, i've decided to build it anyway!  JM 09111 */
-}
-
-void _StrainWeakening_Delete( void* _self ) {
-   StrainWeakening* self = (StrainWeakening*) _self;
-
-   Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
-
-   /* Delete Class */
-   _Stg_Component_Delete( self );   
-
-}
-	
-void _StrainWeakening_Destroy( void* _self, void* data ) {
-   StrainWeakening* self = (StrainWeakening*) _self;
-
-   Stg_Component_Destroy( self->postFailureWeakeningIncrement, data, False );
-   Stg_Component_Destroy( self->postFailureWeakening, data, False );
-   if( self->initialStrainShape ) Stg_Component_Destroy( self->initialStrainShape, data, False );
-   if( self->strainLimitedShape ) Stg_Component_Destroy( self->strainLimitedShape, data, False );
-   Stg_Component_Destroy( self->swarm, data, False );
-
-   /* Destroy Parent */
-   _TimeIntegrand_Destroy( self, data );   
-
-}
-
-void _StrainWeakening_Initialise( void* strainWeakening, void* data ) {
-   StrainWeakening*                       self  = (StrainWeakening*) strainWeakening;
-   Particle_Index                         lParticle_I;
-   Particle_Index                         particleLocalCount;
-   Variable*                              positionVariable   = self->swarm->particleCoordVariable->variable;
-   double                                 postFailureWeakening;
-   double*                                coord;
-
-   int myrank;
-
-   /* Initialise Parent */
-   _TimeIntegrand_Initialise( self, data );
-
-   Stg_Component_Initialise( self->swarm, data, False );
-
-   /* We should only set initial conditions if in regular non-restart mode. If in restart mode, then
-   the particle-based variables will be set correcty when we re-load the Swarm. */
-	
-	if ( self->context->loadFromCheckPoint == False ) {
-
-      particleLocalCount = self->variable->arraySize;
-
-      Stg_Component_Initialise( self->postFailureWeakeningIncrement, data, False );
-      Stg_Component_Initialise( self->postFailureWeakening, data, False );
-      if( self->initialStrainShape ) Stg_Component_Initialise( self->initialStrainShape, data, False );
-      if( self->strainLimitedShape ) Stg_Component_Initialise( self->strainLimitedShape, data, False );
-
-      /* Update variables */
-      Variable_Update( positionVariable );
-      Variable_Update( self->variable );
-      Variable_Update( self->postFailureWeakeningIncrement->variable );
-
-		/* Initialise random number generator */
-		if(self->randomSeed==0) {
-         MPI_Comm_rank( self->context->communicator, &myrank);
-         srand( self->randomSeed );
-		}
-		else {
-			srand( self->randomSeed );
-		}
-	
-		for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) {
-			/* Initialise Increment to Zero */
-			Variable_SetValueDouble( self->postFailureWeakeningIncrement->variable, lParticle_I, 0.0 );
-			Variable_SetValueDouble( self->variable, lParticle_I, 0.0 );
-
-			/* Set initial damage parameter
-			 * There is a certain fraction of the number of particles which are given initial strain */
-			
-			postFailureWeakening = 0.0;
-			
-			if ( rand() < RAND_MAX*self->initialDamageFraction ) {
-
-				coord = Variable_GetPtrDouble( positionVariable, lParticle_I );
-				
-				if ( self->initialStrainShape && !Stg_Shape_IsCoordInside( self->initialStrainShape, coord ) ) {
-					Variable_SetValueDouble( self->variable, lParticle_I, postFailureWeakening );
-						continue;
-				}
-				
-				postFailureWeakening = self->initialDamageFactor * rand() * self->finalSofteningStrain/RAND_MAX;
-
-				/* Modulate the initial weakening by a harmonic-squared function with wavenumber(s) specified by
-					the user. */
-				
-				/* Use old definition if new one is not set */
-				
-				if ( self->initialDamageWavenumber > 0.0 && self->initialDamageWavenumberCosI == -1.0 ) {				
-						postFailureWeakening *= 
-							pow(0.5+0.5*cos(M_PI * coord[ I_AXIS ] * self->initialDamageWavenumber),2.0);
-					}
-					
-				/* Alternate phase is appropriate for different bc's and choice of origin */	
-					
-				if ( self->initialDamageWavenumberCosI > 0.0 ) {				
-						postFailureWeakening *= 
-							pow(0.5+0.5*cos(M_PI * coord[ I_AXIS ] * self->initialDamageWavenumberCosI),2.0);
-				}
-				
-				if ( self->initialDamageWavenumberSinI > 0.0 ) {				
-					postFailureWeakening *= 
-						pow(0.5+0.5*sin(M_PI * coord[ I_AXIS ] * self->initialDamageWavenumberSinI),2.0);
-				}
-				
-				if ( self->initialDamageWavenumberCosK > 0.0 ) {				
-					postFailureWeakening *= 
-						pow(0.5+0.5*cos(M_PI * coord[ K_AXIS ] * self->initialDamageWavenumberCosK),2.0);
-				}
-				if ( self->initialDamageWavenumberSinK > 0.0 ) {				
-					postFailureWeakening *= 
-						pow(0.5+0.5*sin(M_PI * coord[ K_AXIS ] * self->initialDamageWavenumberSinK),2.0);
-				}
-			}
-
-			Variable_SetValueDouble( self->variable, lParticle_I, postFailureWeakening );
-		}
-	}	
-}
-
-Bool _StrainWeakening_TimeDerivative( void* strainWeakening, Index lParticle_I, double* timeDeriv ) {
-	StrainWeakening*  self   = (StrainWeakening*) strainWeakening;
-
-	Variable_Update( self->postFailureWeakeningIncrement->variable );
-	*timeDeriv = Variable_GetValueDouble( self->postFailureWeakeningIncrement->variable, lParticle_I );
-
-	return True;
-}
-
-/* This function is called after the time integration steps - 
- * here we just want to make sure that each value is positive */
-void _StrainWeakening_MakeValuesPositive( void* timeIntegrator, void* strainWeakening ) {
-	StrainWeakening*   self   = (StrainWeakening*) strainWeakening;
-	double*            value;
-	Particle_Index     lParticle_I;
-	Particle_Index     particleCount;
-
-	Variable_Update( self->variable );
-	
-
-
-
-	particleCount = self->variable->arraySize;
-	
-	for ( lParticle_I = 0 ; lParticle_I < particleCount ; lParticle_I++ ) {
-		value = Variable_GetPtrDouble( self->variable, lParticle_I );
-                if ( self->strainLimitedShape)
-                  {
-                    double* coord;
-                    coord = Variable_GetPtrDouble( self->swarm->particleCoordVariable->variable, lParticle_I );
-                    if ( Stg_Shape_IsCoordInside( self->strainLimitedShape, coord ))
-                      *value=self->strainLimit;
-                  }
-		if (*value < 0.0)
-			*value = 0.0;
-	}
-}
-
-double _StrainWeakening_CalcIncrementIsotropic( 
-		void*                            strainWeakening,
-		ConstitutiveMatrix*              constitutiveMatrix,
-		MaterialPointsSwarm*             swarm,
-		Element_LocalIndex               lElement_I,
-		MaterialPoint*                   particle,
-		double                           yieldCriterion,
-		double                           yieldIndicator )
-{
-	StrainWeakening*               self             = (StrainWeakening*) strainWeakening;
-	StrainWeakening_ParticleExt*   particleExt;
-	double                         beta             = 1.0 - yieldCriterion / yieldIndicator;
-	double                         healingRate      = self->healingRate;
-	double                         viscosity        = ConstitutiveMatrix_GetIsotropicViscosity( constitutiveMatrix );
-	double 						   postFailureWeakening;
-
-	particleExt = (StrainWeakening_ParticleExt*)ExtensionManager_Get( self->swarm->particleExtensionMgr, particle, self->particleExtHandle );
-	postFailureWeakening = particleExt->postFailureWeakening;
-	
-	if (beta < 0.0)
-		beta = 0.0;
-
-	return(    (yieldCriterion/viscosity) * ( beta/(1.0-beta)    /* growth term depends on plastic strain rate */
-	 		 - healingRate * postFailureWeakening)               /* decay term */
-			);
-}
-
-double StrainWeakening_CalcRatio( void* strainWeakening, void* particle ) {
-	StrainWeakening*             self   = (StrainWeakening*) strainWeakening;
-	StrainWeakening_ParticleExt* particleExt;
-	double                       strainWeakeningRatio;
-
-	if ( self == NULL ) 
-		return 0.0;
-
-	particleExt = (StrainWeakening_ParticleExt*)ExtensionManager_Get( self->swarm->particleExtensionMgr, particle, self->particleExtHandle );
-
-	if ( particleExt->postFailureWeakening < 0.0 ) 
-		particleExt->postFailureWeakening = 0.0;
-
-	strainWeakeningRatio = (particleExt->postFailureWeakening - self->initialSofteningStrain)
-          / (self->finalSofteningStrain - self->initialSofteningStrain);
-
-	if (strainWeakeningRatio > 1.0)
-		strainWeakeningRatio = 1.0;
-	if (strainWeakeningRatio < 0.0)
-		strainWeakeningRatio = 0.0;
-	
-	return strainWeakeningRatio;
-}
-
-void StrainWeakening_AssignIncrement( 
-		void*                            strainWeakening,
-		ConstitutiveMatrix*              constitutiveMatrix,
-		MaterialPointsSwarm*             swarm,
-		Element_LocalIndex               lElement_I,
-		MaterialPoint*                   particle,
-		double                           yieldCriterion,
-		double                           yieldIndicator ) 
-{
-	StrainWeakening*             self   = (StrainWeakening*) strainWeakening;
-	StrainWeakening_ParticleExt* particleExt;
-
-	particleExt = (StrainWeakening_ParticleExt*)ExtensionManager_Get( swarm->particleExtensionMgr, particle, self->particleExtHandle );
-	
-	particleExt->postFailureWeakeningIncrement = 
-		self->_calcIncrement( self, constitutiveMatrix, swarm, lElement_I, particle, yieldCriterion, yieldIndicator );
-}
-
-double StrainWeakening_GetPostFailureWeakening( void* strainWeakening, void* particle ) {
-	StrainWeakening*             self   = (StrainWeakening*) strainWeakening;
-	StrainWeakening_ParticleExt* particleExt;
-
-	particleExt = (StrainWeakening_ParticleExt*)ExtensionManager_Get( self->swarm->particleExtensionMgr, particle, self->particleExtHandle );
-
-	return particleExt->postFailureWeakening;
-}
-
-double StrainWeakening_GetInitialDamageFraction( void* strainWeakening, void* particle ) {
-	StrainWeakening*             self   = (StrainWeakening*) strainWeakening;
-
-	return self->initialDamageFraction;
-}
-
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/StrainWeakening.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/StrainWeakening.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,555 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: StrainWeakening.c 776 2008-08-05 02:39:26Z LouisMoresi $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <stdlib.h>
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "RheologyClass.h"
+#include "YieldRheology.h"
+#include "VonMises.h"
+#include "StrainWeakening.h"
+#include "ConstitutiveMatrix.h"
+
+#include <assert.h>
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type StrainWeakening_Type = "StrainWeakening";
+
+/* Public Constructor */
+StrainWeakening* StrainWeakening_New(
+      Name                                               name,
+		MaterialPointsSwarm*                               swarm,
+		double                                             healingRate,
+		double                                             initialSofteningStrain,
+		double                                             finalSofteningStrain,
+		double                                             initialDamageFraction,
+		double                                             initialDamageWavenumber,
+		double                                             initialDamageWavenumberSinI,
+		double                                             initialDamageWavenumberCosI,
+		double                                             initialDamageWavenumberSinK,
+		double                                             initialDamageWavenumberCosK,
+		double                                             initialDamageFactor,
+		long int                                           randomSeed,
+                Stg_Shape*                                         initialStrainShape,
+                Stg_Shape*                                         strainLimitedShape,
+                double                                             strainLimit
+                                     )
+{
+   StrainWeakening* self = (StrainWeakening*) _StrainWeakening_DefaultNew( name );
+
+   _StrainWeakening_Init(
+	    self,
+	    swarm,
+	    healingRate,
+            initialSofteningStrain,
+            finalSofteningStrain,
+	    initialDamageFraction,
+	    initialDamageWavenumber,
+	    initialDamageWavenumberSinI,
+	    initialDamageWavenumberCosI,
+	    initialDamageWavenumberSinK,
+	    initialDamageWavenumberCosK,
+	    initialDamageFactor,
+	    randomSeed,
+	    initialStrainShape,
+            strainLimitedShape,
+            strainLimit);
+   self->isConstructed = True;
+   return self;
+}
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+StrainWeakening* _StrainWeakening_New(  STRAINWEAKENING_DEFARGS  ) 
+{
+	StrainWeakening*					self;
+
+	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+	assert( _sizeOfSelf >= sizeof(StrainWeakening) );
+	self = (StrainWeakening*) _TimeIntegrand_New(  TIMEINTEGRAND_PASSARGS  );
+	
+	/* Function pointers for this class that are not on the parent class should be set here */
+	self->_calcIncrement = _calcIncrement;
+	
+	return self;
+}
+
+void _StrainWeakening_Init(
+		StrainWeakening*                                   self,
+		MaterialPointsSwarm*                               swarm,
+		double                                             healingRate,
+		double                                             initialSofteningStrain,
+		double                                             finalSofteningStrain,
+		double                                             initialDamageFraction,
+		double                                             initialDamageWavenumber,
+		double                                             initialDamageWavenumberSinI,
+		double                                             initialDamageWavenumberCosI,
+		double                                             initialDamageWavenumberSinK,
+		double                                             initialDamageWavenumberCosK,
+		double                                             initialDamageFactor,
+		long int                                           randomSeed,
+		Stg_Shape*                                         initialStrainShape,
+                Stg_Shape*                                         strainLimitedShape,
+		double                                             strainLimit )
+{
+	/* Assign Values */
+	self->swarm                    = swarm;
+	self->healingRate              = healingRate;
+	self->initialSofteningStrain  = initialSofteningStrain;
+	self->finalSofteningStrain    = finalSofteningStrain;
+	self->initialDamageFraction    = initialDamageFraction;
+	self->initialDamageWavenumber  = initialDamageWavenumber;
+	self->initialDamageWavenumberSinI = initialDamageWavenumberSinI;
+	self->initialDamageWavenumberCosI = initialDamageWavenumberCosI;
+	self->initialDamageWavenumberSinK = initialDamageWavenumberSinK;
+	self->initialDamageWavenumberCosK = initialDamageWavenumberCosK;
+	self->initialDamageFactor         = initialDamageFactor;
+	self->randomSeed                  = randomSeed;
+	self->initialStrainShape          = initialStrainShape;
+	self->strainLimitedShape          = strainLimitedShape;
+	self->strainLimit                 = strainLimit;
+	
+	/****** Setup Variables *****/
+
+	/* First check to see if a particle extension has already been created for this swarm */
+	self->particleExtHandle = ExtensionManager_GetHandle( swarm->particleExtensionMgr, (Name)StrainWeakening_Type );
+
+	/* If there isn't one then create the particle extension - otherwise just use the one already there*/
+	if ( self->particleExtHandle == (ExtensionInfo_Index) -1  ) {
+		StandardParticle             particle;
+		StrainWeakening_ParticleExt* particleExt;
+
+		/* Add particle extension */
+		self->particleExtHandle = 
+			ExtensionManager_Add( swarm->particleExtensionMgr, (Name)StrainWeakening_Type, sizeof(StrainWeakening_ParticleExt)  );	
+
+		particleExt = (StrainWeakening_ParticleExt*)ExtensionManager_Get( swarm->particleExtensionMgr, &particle, self->particleExtHandle );
+
+		/*Add variables for vizualization / analysis purposes */
+		
+		
+		
+		self->postFailureWeakening = Swarm_NewScalarVariable( swarm, (Name)"PostFailureWeakening", (ArithPointer) &particleExt->postFailureWeakening - (ArithPointer) &particle, Variable_DataType_Double  );
+		
+		self->postFailureWeakeningIncrement = Swarm_NewScalarVariable( swarm, (Name)"PostFailureWeakeningIncrement", (ArithPointer) &particleExt->postFailureWeakeningIncrement - (ArithPointer) &particle, Variable_DataType_Double  );
+	}
+	else {
+		char* variableName;
+
+		/* Get Variables already created */
+		variableName = Stg_Object_AppendSuffix( swarm, (Name)"PostFailureWeakening"  );
+		self->postFailureWeakening = SwarmVariable_Register_GetByName( swarm->swarmVariable_Register, variableName );
+		assert( self->postFailureWeakening );
+		Memory_Free( variableName );
+		
+		variableName = Stg_Object_AppendSuffix( swarm, (Name)"PostFailureWeakeningIncrement"  );
+		self->postFailureWeakeningIncrement = SwarmVariable_Register_GetByName( swarm->swarmVariable_Register, variableName );
+		assert( self->postFailureWeakeningIncrement );
+		Memory_Free( variableName );
+	}
+	
+	/* The strain weakening class inherits from the TimeIntegrand class - this class needs a 'Variable' to 
+	 * integrate through time. For the StrainWeakening component this variable is the 'PostFailureWeakening'
+	 * we need to set this explicitly here */
+	self->variable = self->postFailureWeakening->variable;
+	
+	/* Add function to entry point which is called at the end of the time integration steps - 
+	 * this will make all the negative values zero */
+	TimeIntegrator_AppendFinishEP( self->timeIntegrator,
+                                       "StrainWeakening_MakeValuesPositive", (void*)_StrainWeakening_MakeValuesPositive, self->name, self );
+
+}
+
+void* _StrainWeakening_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                               _sizeOfSelf = sizeof(StrainWeakening);
+	Type                                                       type = StrainWeakening_Type;
+	Stg_Class_DeleteFunction*                               _delete = _TimeIntegrand_Delete;
+	Stg_Class_PrintFunction*                                 _print = _TimeIntegrand_Print;
+	Stg_Class_CopyFunction*                                   _copy = _TimeIntegrand_Copy;
+	Stg_Component_DefaultConstructorFunction*   _defaultConstructor = _StrainWeakening_DefaultNew;
+	Stg_Component_ConstructFunction*                     _construct = _StrainWeakening_AssignFromXML;
+	Stg_Component_BuildFunction*                             _build = _StrainWeakening_Build;
+	Stg_Component_InitialiseFunction*                   _initialise = _StrainWeakening_Initialise;
+	Stg_Component_ExecuteFunction*                         _execute = _TimeIntegrand_Execute;
+	Stg_Component_DestroyFunction*                         _destroy = _TimeIntegrand_Destroy;
+	TimeIntegrand_CalculateTimeDerivFunction*  _calculateTimeDeriv = _StrainWeakening_TimeDerivative;
+	TimeIntegrand_IntermediateFunction*              _intermediate = _TimeIntegrand_Intermediate;
+	StrainWeakening_CalcIncrementFunction*           _calcIncrement = _StrainWeakening_CalcIncrementIsotropic;
+
+	/* 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*) _StrainWeakening_New(  STRAINWEAKENING_PASSARGS  );
+}
+
+void _StrainWeakening_AssignFromXML( void* strainWeakening, Stg_ComponentFactory* cf, void* data ){
+	StrainWeakening*        self           = (StrainWeakening*) strainWeakening;
+	MaterialPointsSwarm*    materialPointsSwarm;
+	double                  healingRate;
+	double                  initialSofteningStrain;
+	double                  finalSofteningStrain;
+	double                  initialDamageFraction;
+	double                  initialDamageWavenumber;
+	double                  initialDamageWavenumberSinI;
+	double                  initialDamageWavenumberCosI;
+	double                  initialDamageWavenumberSinK;
+	double                  initialDamageWavenumberCosK;
+	double                  initialDamageFactor;
+	long int                randomSeed;
+	Stg_Shape*              initialStrainShape;
+	Stg_Shape*              strainLimitedShape;
+	double                  strainLimit;
+
+	/* Construct Parent */
+	_TimeIntegrand_AssignFromXML( self, cf, data );
+	
+	materialPointsSwarm     = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"MaterialPointsSwarm", MaterialPointsSwarm, True, data  );
+
+	healingRate                 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"healingRate", 0.0  );
+	initialSofteningStrain  = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"initialSofteningStrain", 0 );
+        /* Backwards compatibility.  Look at softeningStrain and
+           finalSofteningStrain. */
+	finalSofteningStrain    = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"softeningStrain",   HUGE_VAL );
+	finalSofteningStrain    = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"finalSofteningStrain", finalSofteningStrain );
+	initialDamageFraction       = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"initialDamageFraction", 0.0  );
+	initialDamageWavenumber     = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"initialDamageWavenumber", -1.0  );
+	initialDamageWavenumberSinI = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"initialDamageWavenumberSinI", -1.0  );
+	initialDamageWavenumberCosI = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"initialDamageWavenumberCosI", -1.0  );
+	initialDamageWavenumberSinK = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"initialDamageWavenumberSinK", -1.0  );
+	initialDamageWavenumberCosK = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"initialDamageWavenumberCosK", -1.0  );
+	initialDamageFactor         = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"initialDamageFactor", 1.0 );
+	randomSeed                  = (long int ) Stg_ComponentFactory_GetInt( cf, self->name, (Dictionary_Entry_Key)"randomSeed", 0  );
+	initialStrainShape          = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"initialStrainShape", Stg_Shape, False, data  );
+	strainLimitedShape          = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"strainLimitedShape", Stg_Shape, False, data  );
+	strainLimit                 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"strainLimit", 0.0 );
+
+	_StrainWeakening_Init(
+			self, 
+			materialPointsSwarm, 
+			healingRate,
+			initialSofteningStrain,
+			finalSofteningStrain,
+			initialDamageFraction,
+			initialDamageWavenumber, 
+			initialDamageWavenumberSinI, 
+			initialDamageWavenumberCosI, 
+			initialDamageWavenumberSinK, 
+			initialDamageWavenumberCosK, 
+			initialDamageFactor,
+			randomSeed,
+			initialStrainShape,
+                        strainLimitedShape,
+                        strainLimit);
+}
+
+void _StrainWeakening_Build( void* strainWeakening, void* data ) {
+   StrainWeakening*                       self               = (StrainWeakening*) strainWeakening;
+
+   /* Build parent */
+   _TimeIntegrand_Build( self, data );
+
+   Stg_Component_Build( self->postFailureWeakeningIncrement, data, False );
+   Stg_Component_Build( self->postFailureWeakening, data, False );
+   if( self->initialStrainShape ) Stg_Component_Build( self->initialStrainShape, data, False );
+   if( self->strainLimitedShape ) Stg_Component_Build( self->strainLimitedShape, data, False );
+   Stg_Component_Build( self->swarm, data, False );
+   /* The postFailureWeakening doesn't need to be built here because it has already been
+    * built in the TimeIntegrand class
+    * (self->variable = self->postFailureWeakening->variable in _StrainWeakening_Init function) */
+    /* however, i've decided to build it anyway!  JM 09111 */
+}
+
+void _StrainWeakening_Delete( void* _self ) {
+   StrainWeakening* self = (StrainWeakening*) _self;
+
+   Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
+
+   /* Delete Class */
+   _Stg_Component_Delete( self );   
+
+}
+	
+void _StrainWeakening_Destroy( void* _self, void* data ) {
+   StrainWeakening* self = (StrainWeakening*) _self;
+
+   Stg_Component_Destroy( self->postFailureWeakeningIncrement, data, False );
+   Stg_Component_Destroy( self->postFailureWeakening, data, False );
+   if( self->initialStrainShape ) Stg_Component_Destroy( self->initialStrainShape, data, False );
+   if( self->strainLimitedShape ) Stg_Component_Destroy( self->strainLimitedShape, data, False );
+   Stg_Component_Destroy( self->swarm, data, False );
+
+   /* Destroy Parent */
+   _TimeIntegrand_Destroy( self, data );   
+
+}
+
+void _StrainWeakening_Initialise( void* strainWeakening, void* data ) {
+   StrainWeakening*                       self  = (StrainWeakening*) strainWeakening;
+   Particle_Index                         lParticle_I;
+   Particle_Index                         particleLocalCount;
+   Variable*                              positionVariable   = self->swarm->particleCoordVariable->variable;
+   double                                 postFailureWeakening;
+   double*                                coord;
+
+   int myrank;
+
+   /* Initialise Parent */
+   _TimeIntegrand_Initialise( self, data );
+
+   Stg_Component_Initialise( self->swarm, data, False );
+
+   /* We should only set initial conditions if in regular non-restart mode. If in restart mode, then
+   the particle-based variables will be set correcty when we re-load the Swarm. */
+	
+	if ( self->context->loadFromCheckPoint == False ) {
+
+      particleLocalCount = self->variable->arraySize;
+
+      Stg_Component_Initialise( self->postFailureWeakeningIncrement, data, False );
+      Stg_Component_Initialise( self->postFailureWeakening, data, False );
+      if( self->initialStrainShape ) Stg_Component_Initialise( self->initialStrainShape, data, False );
+      if( self->strainLimitedShape ) Stg_Component_Initialise( self->strainLimitedShape, data, False );
+
+      /* Update variables */
+      Variable_Update( positionVariable );
+      Variable_Update( self->variable );
+      Variable_Update( self->postFailureWeakeningIncrement->variable );
+
+		/* Initialise random number generator */
+		if(self->randomSeed==0) {
+         MPI_Comm_rank( self->context->communicator, &myrank);
+         srand( self->randomSeed );
+		}
+		else {
+			srand( self->randomSeed );
+		}
+	
+		for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) {
+			/* Initialise Increment to Zero */
+			Variable_SetValueDouble( self->postFailureWeakeningIncrement->variable, lParticle_I, 0.0 );
+			Variable_SetValueDouble( self->variable, lParticle_I, 0.0 );
+
+			/* Set initial damage parameter
+			 * There is a certain fraction of the number of particles which are given initial strain */
+			
+			postFailureWeakening = 0.0;
+			
+			if ( rand() < RAND_MAX*self->initialDamageFraction ) {
+
+				coord = Variable_GetPtrDouble( positionVariable, lParticle_I );
+				
+				if ( self->initialStrainShape && !Stg_Shape_IsCoordInside( self->initialStrainShape, coord ) ) {
+					Variable_SetValueDouble( self->variable, lParticle_I, postFailureWeakening );
+						continue;
+				}
+				
+				postFailureWeakening = self->initialDamageFactor * rand() * self->finalSofteningStrain/RAND_MAX;
+
+				/* Modulate the initial weakening by a harmonic-squared function with wavenumber(s) specified by
+					the user. */
+				
+				/* Use old definition if new one is not set */
+				
+				if ( self->initialDamageWavenumber > 0.0 && self->initialDamageWavenumberCosI == -1.0 ) {				
+						postFailureWeakening *= 
+							pow(0.5+0.5*cos(M_PI * coord[ I_AXIS ] * self->initialDamageWavenumber),2.0);
+					}
+					
+				/* Alternate phase is appropriate for different bc's and choice of origin */	
+					
+				if ( self->initialDamageWavenumberCosI > 0.0 ) {				
+						postFailureWeakening *= 
+							pow(0.5+0.5*cos(M_PI * coord[ I_AXIS ] * self->initialDamageWavenumberCosI),2.0);
+				}
+				
+				if ( self->initialDamageWavenumberSinI > 0.0 ) {				
+					postFailureWeakening *= 
+						pow(0.5+0.5*sin(M_PI * coord[ I_AXIS ] * self->initialDamageWavenumberSinI),2.0);
+				}
+				
+				if ( self->initialDamageWavenumberCosK > 0.0 ) {				
+					postFailureWeakening *= 
+						pow(0.5+0.5*cos(M_PI * coord[ K_AXIS ] * self->initialDamageWavenumberCosK),2.0);
+				}
+				if ( self->initialDamageWavenumberSinK > 0.0 ) {				
+					postFailureWeakening *= 
+						pow(0.5+0.5*sin(M_PI * coord[ K_AXIS ] * self->initialDamageWavenumberSinK),2.0);
+				}
+			}
+
+			Variable_SetValueDouble( self->variable, lParticle_I, postFailureWeakening );
+		}
+	}	
+}
+
+Bool _StrainWeakening_TimeDerivative( void* strainWeakening, Index lParticle_I, double* timeDeriv ) {
+	StrainWeakening*  self   = (StrainWeakening*) strainWeakening;
+
+	Variable_Update( self->postFailureWeakeningIncrement->variable );
+	*timeDeriv = Variable_GetValueDouble( self->postFailureWeakeningIncrement->variable, lParticle_I );
+
+	return True;
+}
+
+/* This function is called after the time integration steps - 
+ * here we just want to make sure that each value is positive */
+void _StrainWeakening_MakeValuesPositive( void* timeIntegrator, void* strainWeakening ) {
+	StrainWeakening*   self   = (StrainWeakening*) strainWeakening;
+	double*            value;
+	Particle_Index     lParticle_I;
+	Particle_Index     particleCount;
+
+	Variable_Update( self->variable );
+	
+
+
+
+	particleCount = self->variable->arraySize;
+	
+	for ( lParticle_I = 0 ; lParticle_I < particleCount ; lParticle_I++ ) {
+		value = Variable_GetPtrDouble( self->variable, lParticle_I );
+                if ( self->strainLimitedShape)
+                  {
+                    double* coord;
+                    coord = Variable_GetPtrDouble( self->swarm->particleCoordVariable->variable, lParticle_I );
+                    if ( Stg_Shape_IsCoordInside( self->strainLimitedShape, coord ))
+                      *value=self->strainLimit;
+                  }
+		if (*value < 0.0)
+			*value = 0.0;
+	}
+}
+
+double _StrainWeakening_CalcIncrementIsotropic( 
+		void*                            strainWeakening,
+		ConstitutiveMatrix*              constitutiveMatrix,
+		MaterialPointsSwarm*             swarm,
+		Element_LocalIndex               lElement_I,
+		MaterialPoint*                   particle,
+		double                           yieldCriterion,
+		double                           yieldIndicator )
+{
+	StrainWeakening*               self             = (StrainWeakening*) strainWeakening;
+	StrainWeakening_ParticleExt*   particleExt;
+	double                         beta             = 1.0 - yieldCriterion / yieldIndicator;
+	double                         healingRate      = self->healingRate;
+	double                         viscosity        = ConstitutiveMatrix_GetIsotropicViscosity( constitutiveMatrix );
+	double 						   postFailureWeakening;
+
+	particleExt = (StrainWeakening_ParticleExt*)ExtensionManager_Get( self->swarm->particleExtensionMgr, particle, self->particleExtHandle );
+	postFailureWeakening = particleExt->postFailureWeakening;
+	
+	if (beta < 0.0)
+		beta = 0.0;
+
+	return(    (yieldCriterion/viscosity) * ( beta/(1.0-beta)    /* growth term depends on plastic strain rate */
+	 		 - healingRate * postFailureWeakening)               /* decay term */
+			);
+}
+
+double StrainWeakening_CalcRatio( void* strainWeakening, void* particle ) {
+	StrainWeakening*             self   = (StrainWeakening*) strainWeakening;
+	StrainWeakening_ParticleExt* particleExt;
+	double                       strainWeakeningRatio;
+
+	if ( self == NULL ) 
+		return 0.0;
+
+	particleExt = (StrainWeakening_ParticleExt*)ExtensionManager_Get( self->swarm->particleExtensionMgr, particle, self->particleExtHandle );
+
+	if ( particleExt->postFailureWeakening < 0.0 ) 
+		particleExt->postFailureWeakening = 0.0;
+
+	strainWeakeningRatio = (particleExt->postFailureWeakening - self->initialSofteningStrain)
+          / (self->finalSofteningStrain - self->initialSofteningStrain);
+
+	if (strainWeakeningRatio > 1.0)
+		strainWeakeningRatio = 1.0;
+	if (strainWeakeningRatio < 0.0)
+		strainWeakeningRatio = 0.0;
+	
+	return strainWeakeningRatio;
+}
+
+void StrainWeakening_AssignIncrement( 
+		void*                            strainWeakening,
+		ConstitutiveMatrix*              constitutiveMatrix,
+		MaterialPointsSwarm*             swarm,
+		Element_LocalIndex               lElement_I,
+		MaterialPoint*                   particle,
+		double                           yieldCriterion,
+		double                           yieldIndicator ) 
+{
+	StrainWeakening*             self   = (StrainWeakening*) strainWeakening;
+	StrainWeakening_ParticleExt* particleExt;
+
+	particleExt = (StrainWeakening_ParticleExt*)ExtensionManager_Get( swarm->particleExtensionMgr, particle, self->particleExtHandle );
+	
+	particleExt->postFailureWeakeningIncrement = 
+		self->_calcIncrement( self, constitutiveMatrix, swarm, lElement_I, particle, yieldCriterion, yieldIndicator );
+}
+
+double StrainWeakening_GetPostFailureWeakening( void* strainWeakening, void* particle ) {
+	StrainWeakening*             self   = (StrainWeakening*) strainWeakening;
+	StrainWeakening_ParticleExt* particleExt;
+
+	particleExt = (StrainWeakening_ParticleExt*)ExtensionManager_Get( self->swarm->particleExtensionMgr, particle, self->particleExtHandle );
+
+	return particleExt->postFailureWeakening;
+}
+
+double StrainWeakening_GetInitialDamageFraction( void* strainWeakening, void* particle ) {
+	StrainWeakening*             self   = (StrainWeakening*) strainWeakening;
+
+	return self->initialDamageFraction;
+}
+
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/ViscosityFieldRheology.c
--- a/Rheology/src/ViscosityFieldRheology.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,150 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: ViscosityFieldRheology.c 736 2008-05-23 06:05:21Z RobertTurnbull $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "RheologyClass.h"
-#include "ViscosityFieldRheology.h"
-#include "ConstitutiveMatrix.h"
-
-#include <assert.h>
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type ViscosityFieldRheology_Type = "ViscosityFieldRheology";
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-ViscosityFieldRheology* _ViscosityFieldRheology_New(  VISCOSITYFIELDRHEOLOGY_DEFARGS  ) 
-{
-	ViscosityFieldRheology*					self;
-
-	assert( _sizeOfSelf >= sizeof(ViscosityFieldRheology) );
-	self = (ViscosityFieldRheology*) _Rheology_New(  RHEOLOGY_PASSARGS  );
-	
-	return self;
-}
-
-void _ViscosityFieldRheology_Init( ViscosityFieldRheology* self, FeVariable* viscosityField ) 
-{
-	self->viscosityField = viscosityField;
-}
-
-void* _ViscosityFieldRheology_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                     _sizeOfSelf = sizeof(ViscosityFieldRheology);
-	Type                                                             type = ViscosityFieldRheology_Type;
-	Stg_Class_DeleteFunction*                                     _delete = _Rheology_Delete;
-	Stg_Class_PrintFunction*                                       _print = _Rheology_Print;
-	Stg_Class_CopyFunction*                                         _copy = _Rheology_Copy;
-	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _ViscosityFieldRheology_DefaultNew;
-	Stg_Component_ConstructFunction*                           _construct = _ViscosityFieldRheology_AssignFromXML;
-	Stg_Component_BuildFunction*                                   _build = _ViscosityFieldRheology_Build;
-	Stg_Component_InitialiseFunction*                         _initialise = _ViscosityFieldRheology_Initialise;
-	Stg_Component_ExecuteFunction*                               _execute = _Rheology_Execute;
-	Stg_Component_DestroyFunction*                               _destroy = _ViscosityFieldRheology_Destroy;
-	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _ViscosityFieldRheology_ModifyConstitutiveMatrix;
-
-	/* 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*) _ViscosityFieldRheology_New(  VISCOSITYFIELDRHEOLOGY_PASSARGS  );
-}
-
-void _ViscosityFieldRheology_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
-	ViscosityFieldRheology*     self = (ViscosityFieldRheology*)rheology;
-   FeVariable*                 viscosityField = NULL;
-	/* Construct Parent */
-	_Rheology_AssignFromXML( self, cf, data );
-   
-	viscosityField = Stg_ComponentFactory_ConstructByName( cf, (Name)Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"ViscosityField", "ViscosityField"   ), FeVariable, True, data );
-	_ViscosityFieldRheology_Init( self, viscosityField );
-}
-
-void _ViscosityFieldRheology_Build( void* rheology, void* data ){
-	ViscosityFieldRheology*     self = (ViscosityFieldRheology*)rheology;
-
-	_Rheology_Build( self, data );
-
-	Stg_Component_Build( self->viscosityField, data, False );
-
-}
-
-void _ViscosityFieldRheology_Initialise( void* rheology, void* data ){
-	ViscosityFieldRheology*     self = (ViscosityFieldRheology*)rheology;
-
-	_Rheology_Initialise( self, data );
-
-	Stg_Component_Initialise( self->viscosityField, data, False );
-
-}
-
-void _ViscosityFieldRheology_Destroy( void* rheology, void* data ){
-	ViscosityFieldRheology*     self = (ViscosityFieldRheology*)rheology;
-
-	_Rheology_Destroy( self, data );
-
-	Stg_Component_Destroy( self->viscosityField, data, False );
-
-}
-
-void _ViscosityFieldRheology_ModifyConstitutiveMatrix( 
-		void*                                              rheology, 
-		ConstitutiveMatrix*                                constitutiveMatrix,
-		MaterialPointsSwarm*                               swarm,
-		Element_LocalIndex                                 lElement_I,
-		MaterialPoint*                                     materialPoint,
-		Coord                                              xi )
-{
-	ViscosityFieldRheology*	                  self              = (ViscosityFieldRheology*) rheology;
-	FeMesh*                           mesh              = ConstitutiveMatrix_GetMesh( constitutiveMatrix );
-	double viscosity;
-
-	FeVariable_InterpolateFromMeshLocalCoord( self->viscosityField, mesh, lElement_I, xi, &viscosity );
-	ConstitutiveMatrix_SetIsotropicViscosity( constitutiveMatrix, viscosity );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/ViscosityFieldRheology.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/ViscosityFieldRheology.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,150 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: ViscosityFieldRheology.c 736 2008-05-23 06:05:21Z RobertTurnbull $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "RheologyClass.h"
+#include "ViscosityFieldRheology.h"
+#include "ConstitutiveMatrix.h"
+
+#include <assert.h>
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type ViscosityFieldRheology_Type = "ViscosityFieldRheology";
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+ViscosityFieldRheology* _ViscosityFieldRheology_New(  VISCOSITYFIELDRHEOLOGY_DEFARGS  ) 
+{
+	ViscosityFieldRheology*					self;
+
+	assert( _sizeOfSelf >= sizeof(ViscosityFieldRheology) );
+	self = (ViscosityFieldRheology*) _Rheology_New(  RHEOLOGY_PASSARGS  );
+	
+	return self;
+}
+
+void _ViscosityFieldRheology_Init( ViscosityFieldRheology* self, FeVariable* viscosityField ) 
+{
+	self->viscosityField = viscosityField;
+}
+
+void* _ViscosityFieldRheology_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                     _sizeOfSelf = sizeof(ViscosityFieldRheology);
+	Type                                                             type = ViscosityFieldRheology_Type;
+	Stg_Class_DeleteFunction*                                     _delete = _Rheology_Delete;
+	Stg_Class_PrintFunction*                                       _print = _Rheology_Print;
+	Stg_Class_CopyFunction*                                         _copy = _Rheology_Copy;
+	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _ViscosityFieldRheology_DefaultNew;
+	Stg_Component_ConstructFunction*                           _construct = _ViscosityFieldRheology_AssignFromXML;
+	Stg_Component_BuildFunction*                                   _build = _ViscosityFieldRheology_Build;
+	Stg_Component_InitialiseFunction*                         _initialise = _ViscosityFieldRheology_Initialise;
+	Stg_Component_ExecuteFunction*                               _execute = _Rheology_Execute;
+	Stg_Component_DestroyFunction*                               _destroy = _ViscosityFieldRheology_Destroy;
+	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _ViscosityFieldRheology_ModifyConstitutiveMatrix;
+
+	/* 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*) _ViscosityFieldRheology_New(  VISCOSITYFIELDRHEOLOGY_PASSARGS  );
+}
+
+void _ViscosityFieldRheology_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
+	ViscosityFieldRheology*     self = (ViscosityFieldRheology*)rheology;
+   FeVariable*                 viscosityField = NULL;
+	/* Construct Parent */
+	_Rheology_AssignFromXML( self, cf, data );
+   
+	viscosityField = Stg_ComponentFactory_ConstructByName( cf, (Name)Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"ViscosityField", "ViscosityField"   ), FeVariable, True, data );
+	_ViscosityFieldRheology_Init( self, viscosityField );
+}
+
+void _ViscosityFieldRheology_Build( void* rheology, void* data ){
+	ViscosityFieldRheology*     self = (ViscosityFieldRheology*)rheology;
+
+	_Rheology_Build( self, data );
+
+	Stg_Component_Build( self->viscosityField, data, False );
+
+}
+
+void _ViscosityFieldRheology_Initialise( void* rheology, void* data ){
+	ViscosityFieldRheology*     self = (ViscosityFieldRheology*)rheology;
+
+	_Rheology_Initialise( self, data );
+
+	Stg_Component_Initialise( self->viscosityField, data, False );
+
+}
+
+void _ViscosityFieldRheology_Destroy( void* rheology, void* data ){
+	ViscosityFieldRheology*     self = (ViscosityFieldRheology*)rheology;
+
+	_Rheology_Destroy( self, data );
+
+	Stg_Component_Destroy( self->viscosityField, data, False );
+
+}
+
+void _ViscosityFieldRheology_ModifyConstitutiveMatrix( 
+		void*                                              rheology, 
+		ConstitutiveMatrix*                                constitutiveMatrix,
+		MaterialPointsSwarm*                               swarm,
+		Element_LocalIndex                                 lElement_I,
+		MaterialPoint*                                     materialPoint,
+		Coord                                              xi )
+{
+	ViscosityFieldRheology*	                  self              = (ViscosityFieldRheology*) rheology;
+	FeMesh*                           mesh              = ConstitutiveMatrix_GetMesh( constitutiveMatrix );
+	double viscosity;
+
+	FeVariable_InterpolateFromMeshLocalCoord( self->viscosityField, mesh, lElement_I, xi, &viscosity );
+	ConstitutiveMatrix_SetIsotropicViscosity( constitutiveMatrix, viscosity );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/VonMises.c
--- a/Rheology/src/VonMises.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,316 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: VonMises.c 803 2008-09-11 05:22:20Z LukeHodkinson $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <math.h>
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "RheologyClass.h"
-#include "StrainWeakening.h"
-#include "YieldRheology.h"
-#include "VonMises.h"
-#include "ConstitutiveMatrix.h"
-
-#include <assert.h>
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type VonMises_Type = "VonMises";
-
-/* Public Constructor */
-VonMises* VonMises_New(
-	Name                  name,
-	AbstractContext*      context,
-	StrainWeakening*      strainWeakening, 
-	MaterialPointsSwarm*  materialPointsSwarm, 
-	double                minVisc, 
-	FeVariable*           strainRateField,
-	SwarmVariable*        swarmStrainRate,
-	double                cohesion,
-	double                cohesionAfterSoftening,
-	Bool                  strainRateSoftening )
-{
-   VonMises* self = (VonMises*) _VonMises_DefaultNew( name );
-
-   _Rheology_Init( self, (PICelleratorContext*)context );
-   _YieldRheology_Init( (YieldRheology*)self, strainWeakening, materialPointsSwarm, minVisc ); 
-   _VonMises_Init( (VonMises*)self, strainRateField, swarmStrainRate, cohesion, cohesionAfterSoftening, strainRateSoftening );
-
-   self->isConstructed = True;
-   return self;
-}
-
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-VonMises* _VonMises_New(  VONMISES_DEFARGS  ) 
-{
-	VonMises*					self;
-
-	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-	assert( _sizeOfSelf >= sizeof(VonMises) );
-	self = (VonMises*) _YieldRheology_New(  YIELDRHEOLOGY_PASSARGS  );
-	
-	/* Function pointers for this class that are not on the parent class should be set here */
-	
-	return self;
-}
-
-void _VonMises_Init( 
-		VonMises*      self, 
-		FeVariable*    strainRateField,
-		SwarmVariable* swarmStrainRate,
-		double         cohesion, 
-		double         cohesionAfterSoftening,
-		Bool           strainRateSoftening)
-{
-	self->strainRateField        = strainRateField;
-	self->swarmStrainRate        = swarmStrainRate;
-	self->cohesion               = cohesion;
-	
-	/* Strain softening of Cohesion - (linear weakening is assumed) */
-	/* needs a softening factor between +0 and 1 and a reference strain > 0 */
-	self->cohesionAfterSoftening = cohesionAfterSoftening;
-	self->strainRateSoftening    = strainRateSoftening;
-}
-
-void* _VonMises_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                     _sizeOfSelf = sizeof(VonMises);
-	Type                                                             type = VonMises_Type;
-	Stg_Class_DeleteFunction*                                     _delete = _YieldRheology_Delete;
-	Stg_Class_PrintFunction*                                       _print = _YieldRheology_Print;
-	Stg_Class_CopyFunction*                                         _copy = _YieldRheology_Copy;
-	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _VonMises_DefaultNew;
-	Stg_Component_ConstructFunction*                           _construct = _VonMises_AssignFromXML;
-	Stg_Component_BuildFunction*                                   _build = _VonMises_Build;
-	Stg_Component_InitialiseFunction*                         _initialise = _VonMises_Initialise;
-	Stg_Component_ExecuteFunction*                               _execute = _YieldRheology_Execute;
-	Stg_Component_DestroyFunction*                               _destroy = _VonMises_Destroy;
-	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _YieldRheology_ModifyConstitutiveMatrix;
-	YieldRheology_GetYieldCriterionFunction*           _getYieldCriterion = _VonMises_GetYieldCriterion;
-	YieldRheology_GetYieldIndicatorFunction*           _getYieldIndicator = _VonMises_GetYieldIndicator;
-	YieldRheology_HasYieldedFunction*                         _hasYielded = _VonMises_HasYielded;
-
-	/* 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*) _VonMises_New(  VONMISES_PASSARGS  );
-}
-
-void _VonMises_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
-	VonMises*          self           = (VonMises*)rheology;
-	FeVariable*        strainRateField;
-	SwarmVariable*     swarmStrainRate;
-
-	/* Construct Parent */
-	_YieldRheology_AssignFromXML( self, cf, data );
-	
-	strainRateField = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"StrainRateField", FeVariable, False, data  );
-	swarmStrainRate = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"swarmStrainRate", SwarmVariable, False, data );
-   Journal_Firewall( 
-			(strainRateField || self->swarmStrainRate ), 
-			Journal_Register( Error_Type, (Name)self->type  ), 
-			"\n Error in component type %s, name '%s'.\n Must specify a strainRateField OR a swarmStrainRate, but not both. \n", self->type, self->name ); 
-
-	_VonMises_Init( 
-			self, 
-			strainRateField,
-			swarmStrainRate,
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"cohesion", 0.0  ),
-			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"cohesionAfterSoftening", 0.0  ),
-			Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"strainRateSoftening", False )  );
-}
-
-void _VonMises_Destroy( void* rheology, void* data ){
-   VonMises* self = (VonMises*) rheology;
-   
-   if( self->strainRateField ) Stg_Component_Destroy( self->strainRateField, data, False );
-   if( self->swarmStrainRate ) Stg_Component_Destroy( self->swarmStrainRate, data, False );
-   
-   _YieldRheology_Destroy( self, data );
-}
-
-void _VonMises_Build( void* rheology, void* data ){
-   VonMises* self = (VonMises*) rheology;
-   
-   /* build parent */
-   _YieldRheology_Build( self, data );
-   
-   if( self->strainRateField ) Stg_Component_Build( self->strainRateField, data, False );
-   if( self->swarmStrainRate ) Stg_Component_Build( self->swarmStrainRate, data, False );
-   
-}
-
-void _VonMises_Initialise( void* rheology, void* data ){
-   VonMises* self = (VonMises*) rheology;
-   
-   /* Initialise parent */
-   _YieldRheology_Initialise( self, data );
-   
-   if( self->strainRateField ) Stg_Component_Initialise( self->strainRateField, data, False );
-   if( self->swarmStrainRate ) Stg_Component_Initialise( self->swarmStrainRate, data, False );
-   
-}
-
-double _VonMises_GetYieldCriterion( 
-		void*                            rheology,
-		ConstitutiveMatrix*              constitutiveMatrix,
-		MaterialPointsSwarm*             materialPointsSwarm,
-		Element_LocalIndex               lElement_I,
-		MaterialPoint*                   materialPoint,
-		Coord                            xi )
-{
-	VonMises*                         self             = (VonMises*) rheology;
-	double                            strainWeakeningRatio;
-	double                            effectiveCohesion;
-	
-	/* Strain softening of yield stress */
-	strainWeakeningRatio = StrainWeakening_CalcRatio( self->strainWeakening, materialPoint );
-		
-	effectiveCohesion =  self->cohesion * (1.0 - strainWeakeningRatio) + 
-			self->cohesionAfterSoftening * strainWeakeningRatio;
-
-        /* Store current yield criterion for jacobian evaluation. */
-        self->yieldCriterion = effectiveCohesion;
-
-	return effectiveCohesion;
-}
-
-double _VonMises_GetYieldIndicator( 
-		void*                            rheology,
-		ConstitutiveMatrix*              constitutiveMatrix,
-		MaterialPointsSwarm*             materialPointsSwarm,
-		Element_LocalIndex               lElement_I,
-		MaterialPoint*                   materialPoint,
-		Coord                            xi )
-{
-	VonMises*                         self             = (VonMises*) rheology;
-	SymmetricTensor                   strainRate;
-        int i;
-        double stressTrace, strainRateTrace;
-	
-	/* Get Strain Rate */
-	if( self->strainRateField ) {
-	   FeVariable_InterpolateWithinElement(
-	      self->strainRateField, lElement_I, xi, strainRate );
-	}
-	else {
-	   SwarmVariable_ValueAt( self->swarmStrainRate,
-				  constitutiveMatrix->currentParticleIndex,
-				  strainRate );
-	}
-
-	/* Get Stress */
-	ConstitutiveMatrix_CalculateStress( constitutiveMatrix, strainRate,
-                                            self->stress );
-        SymmetricTensor_GetTrace(self->stress, constitutiveMatrix->dim,
-                                 &stressTrace);
-        SymmetricTensor_GetTrace(strainRate, constitutiveMatrix->dim,
-                                 &strainRateTrace);
-
-        for(i=0;i<constitutiveMatrix->dim;++i)
-          {
-            strainRate[TensorMapST3D[i][i]]-=
-              strainRateTrace/constitutiveMatrix->dim;
-            self->stress[TensorMapST3D[i][i]]-=
-              stressTrace/constitutiveMatrix->dim;
-          }
-
-        /* Save the strain rate invariant */
-        self->strainRateSecondInvariant=
-          SymmetricTensor_2ndInvariant( strainRate, constitutiveMatrix->dim );
-
-	self->stressInv = 
-          SymmetricTensor_2ndInvariant( self->stress, constitutiveMatrix->dim );
-
-        self->yieldIndicator = self->stressInv;
-
-	return self->stressInv;
-}
-
-void _VonMises_HasYielded( 
-		void*                            rheology,
-		ConstitutiveMatrix*              constitutiveMatrix,
-		MaterialPointsSwarm*             materialPointsSwarm,
-		Element_LocalIndex               lElement_I,
-		MaterialPoint*                   materialPoint,
-		double                           yieldCriterion,
-		double                           yieldIndicator )
-{
-	VonMises*                 self             = (VonMises*) rheology;
-	double                    viscosity        = ConstitutiveMatrix_GetIsotropicViscosity( constitutiveMatrix );
-
-	if ( self->strainRateSoftening ) {
-		/* TODO - Put this function in a plugin */
-		viscosity = 2.0 * yieldCriterion * yieldCriterion * viscosity / 
-				( yieldCriterion * yieldCriterion + yieldIndicator * yieldIndicator );
-		ConstitutiveMatrix_SetIsotropicViscosity( constitutiveMatrix, viscosity );
-	}
-	else {
-                double beta = 1.0 - yieldCriterion / yieldIndicator;
-                double corr = -viscosity * beta;
-
-		if( (viscosity + corr) < self->minVisc )
-		   corr = self->minVisc - viscosity;
-		ConstitutiveMatrix_IsotropicCorrection( constitutiveMatrix, corr );
-	}
-
-        if( constitutiveMatrix->sle && constitutiveMatrix->sle->nlFormJacobian ) {
-           double* derivs = constitutiveMatrix->derivs;
-           double coef;
-
-           coef = -viscosity * self->yieldCriterion / (2.0 * self->stressInv * self->stressInv * self->stressInv);
-           derivs[0] += coef * 2.0 * viscosity * self->stress[0];
-           derivs[4] += coef * 2.0 * viscosity * self->stress[1];
-           derivs[1] += coef * 2.0 * viscosity * self->stress[2];
-           derivs[3] += coef * 2.0 * viscosity * self->stress[2];
-
-        }
-
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/VonMises.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/VonMises.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,316 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: VonMises.c 803 2008-09-11 05:22:20Z LukeHodkinson $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <math.h>
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "RheologyClass.h"
+#include "StrainWeakening.h"
+#include "YieldRheology.h"
+#include "VonMises.h"
+#include "ConstitutiveMatrix.h"
+
+#include <assert.h>
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type VonMises_Type = "VonMises";
+
+/* Public Constructor */
+VonMises* VonMises_New(
+	Name                  name,
+	AbstractContext*      context,
+	StrainWeakening*      strainWeakening, 
+	MaterialPointsSwarm*  materialPointsSwarm, 
+	double                minVisc, 
+	FeVariable*           strainRateField,
+	SwarmVariable*        swarmStrainRate,
+	double                cohesion,
+	double                cohesionAfterSoftening,
+	Bool                  strainRateSoftening )
+{
+   VonMises* self = (VonMises*) _VonMises_DefaultNew( name );
+
+   _Rheology_Init( self, (PICelleratorContext*)context );
+   _YieldRheology_Init( (YieldRheology*)self, strainWeakening, materialPointsSwarm, minVisc ); 
+   _VonMises_Init( (VonMises*)self, strainRateField, swarmStrainRate, cohesion, cohesionAfterSoftening, strainRateSoftening );
+
+   self->isConstructed = True;
+   return self;
+}
+
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+VonMises* _VonMises_New(  VONMISES_DEFARGS  ) 
+{
+	VonMises*					self;
+
+	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+	assert( _sizeOfSelf >= sizeof(VonMises) );
+	self = (VonMises*) _YieldRheology_New(  YIELDRHEOLOGY_PASSARGS  );
+	
+	/* Function pointers for this class that are not on the parent class should be set here */
+	
+	return self;
+}
+
+void _VonMises_Init( 
+		VonMises*      self, 
+		FeVariable*    strainRateField,
+		SwarmVariable* swarmStrainRate,
+		double         cohesion, 
+		double         cohesionAfterSoftening,
+		Bool           strainRateSoftening)
+{
+	self->strainRateField        = strainRateField;
+	self->swarmStrainRate        = swarmStrainRate;
+	self->cohesion               = cohesion;
+	
+	/* Strain softening of Cohesion - (linear weakening is assumed) */
+	/* needs a softening factor between +0 and 1 and a reference strain > 0 */
+	self->cohesionAfterSoftening = cohesionAfterSoftening;
+	self->strainRateSoftening    = strainRateSoftening;
+}
+
+void* _VonMises_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                     _sizeOfSelf = sizeof(VonMises);
+	Type                                                             type = VonMises_Type;
+	Stg_Class_DeleteFunction*                                     _delete = _YieldRheology_Delete;
+	Stg_Class_PrintFunction*                                       _print = _YieldRheology_Print;
+	Stg_Class_CopyFunction*                                         _copy = _YieldRheology_Copy;
+	Stg_Component_DefaultConstructorFunction*         _defaultConstructor = _VonMises_DefaultNew;
+	Stg_Component_ConstructFunction*                           _construct = _VonMises_AssignFromXML;
+	Stg_Component_BuildFunction*                                   _build = _VonMises_Build;
+	Stg_Component_InitialiseFunction*                         _initialise = _VonMises_Initialise;
+	Stg_Component_ExecuteFunction*                               _execute = _YieldRheology_Execute;
+	Stg_Component_DestroyFunction*                               _destroy = _VonMises_Destroy;
+	Rheology_ModifyConstitutiveMatrixFunction*  _modifyConstitutiveMatrix = _YieldRheology_ModifyConstitutiveMatrix;
+	YieldRheology_GetYieldCriterionFunction*           _getYieldCriterion = _VonMises_GetYieldCriterion;
+	YieldRheology_GetYieldIndicatorFunction*           _getYieldIndicator = _VonMises_GetYieldIndicator;
+	YieldRheology_HasYieldedFunction*                         _hasYielded = _VonMises_HasYielded;
+
+	/* 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*) _VonMises_New(  VONMISES_PASSARGS  );
+}
+
+void _VonMises_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
+	VonMises*          self           = (VonMises*)rheology;
+	FeVariable*        strainRateField;
+	SwarmVariable*     swarmStrainRate;
+
+	/* Construct Parent */
+	_YieldRheology_AssignFromXML( self, cf, data );
+	
+	strainRateField = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"StrainRateField", FeVariable, False, data  );
+	swarmStrainRate = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"swarmStrainRate", SwarmVariable, False, data );
+   Journal_Firewall( 
+			(strainRateField || self->swarmStrainRate ), 
+			Journal_Register( Error_Type, (Name)self->type  ), 
+			"\n Error in component type %s, name '%s'.\n Must specify a strainRateField OR a swarmStrainRate, but not both. \n", self->type, self->name ); 
+
+	_VonMises_Init( 
+			self, 
+			strainRateField,
+			swarmStrainRate,
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"cohesion", 0.0  ),
+			Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"cohesionAfterSoftening", 0.0  ),
+			Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"strainRateSoftening", False )  );
+}
+
+void _VonMises_Destroy( void* rheology, void* data ){
+   VonMises* self = (VonMises*) rheology;
+   
+   if( self->strainRateField ) Stg_Component_Destroy( self->strainRateField, data, False );
+   if( self->swarmStrainRate ) Stg_Component_Destroy( self->swarmStrainRate, data, False );
+   
+   _YieldRheology_Destroy( self, data );
+}
+
+void _VonMises_Build( void* rheology, void* data ){
+   VonMises* self = (VonMises*) rheology;
+   
+   /* build parent */
+   _YieldRheology_Build( self, data );
+   
+   if( self->strainRateField ) Stg_Component_Build( self->strainRateField, data, False );
+   if( self->swarmStrainRate ) Stg_Component_Build( self->swarmStrainRate, data, False );
+   
+}
+
+void _VonMises_Initialise( void* rheology, void* data ){
+   VonMises* self = (VonMises*) rheology;
+   
+   /* Initialise parent */
+   _YieldRheology_Initialise( self, data );
+   
+   if( self->strainRateField ) Stg_Component_Initialise( self->strainRateField, data, False );
+   if( self->swarmStrainRate ) Stg_Component_Initialise( self->swarmStrainRate, data, False );
+   
+}
+
+double _VonMises_GetYieldCriterion( 
+		void*                            rheology,
+		ConstitutiveMatrix*              constitutiveMatrix,
+		MaterialPointsSwarm*             materialPointsSwarm,
+		Element_LocalIndex               lElement_I,
+		MaterialPoint*                   materialPoint,
+		Coord                            xi )
+{
+	VonMises*                         self             = (VonMises*) rheology;
+	double                            strainWeakeningRatio;
+	double                            effectiveCohesion;
+	
+	/* Strain softening of yield stress */
+	strainWeakeningRatio = StrainWeakening_CalcRatio( self->strainWeakening, materialPoint );
+		
+	effectiveCohesion =  self->cohesion * (1.0 - strainWeakeningRatio) + 
+			self->cohesionAfterSoftening * strainWeakeningRatio;
+
+        /* Store current yield criterion for jacobian evaluation. */
+        self->yieldCriterion = effectiveCohesion;
+
+	return effectiveCohesion;
+}
+
+double _VonMises_GetYieldIndicator( 
+		void*                            rheology,
+		ConstitutiveMatrix*              constitutiveMatrix,
+		MaterialPointsSwarm*             materialPointsSwarm,
+		Element_LocalIndex               lElement_I,
+		MaterialPoint*                   materialPoint,
+		Coord                            xi )
+{
+	VonMises*                         self             = (VonMises*) rheology;
+	SymmetricTensor                   strainRate;
+        int i;
+        double stressTrace, strainRateTrace;
+	
+	/* Get Strain Rate */
+	if( self->strainRateField ) {
+	   FeVariable_InterpolateWithinElement(
+	      self->strainRateField, lElement_I, xi, strainRate );
+	}
+	else {
+	   SwarmVariable_ValueAt( self->swarmStrainRate,
+				  constitutiveMatrix->currentParticleIndex,
+				  strainRate );
+	}
+
+	/* Get Stress */
+	ConstitutiveMatrix_CalculateStress( constitutiveMatrix, strainRate,
+                                            self->stress );
+        SymmetricTensor_GetTrace(self->stress, constitutiveMatrix->dim,
+                                 &stressTrace);
+        SymmetricTensor_GetTrace(strainRate, constitutiveMatrix->dim,
+                                 &strainRateTrace);
+
+        for(i=0;i<constitutiveMatrix->dim;++i)
+          {
+            strainRate[TensorMapST3D[i][i]]-=
+              strainRateTrace/constitutiveMatrix->dim;
+            self->stress[TensorMapST3D[i][i]]-=
+              stressTrace/constitutiveMatrix->dim;
+          }
+
+        /* Save the strain rate invariant */
+        self->strainRateSecondInvariant=
+          SymmetricTensor_2ndInvariant( strainRate, constitutiveMatrix->dim );
+
+	self->stressInv = 
+          SymmetricTensor_2ndInvariant( self->stress, constitutiveMatrix->dim );
+
+        self->yieldIndicator = self->stressInv;
+
+	return self->stressInv;
+}
+
+void _VonMises_HasYielded( 
+		void*                            rheology,
+		ConstitutiveMatrix*              constitutiveMatrix,
+		MaterialPointsSwarm*             materialPointsSwarm,
+		Element_LocalIndex               lElement_I,
+		MaterialPoint*                   materialPoint,
+		double                           yieldCriterion,
+		double                           yieldIndicator )
+{
+	VonMises*                 self             = (VonMises*) rheology;
+	double                    viscosity        = ConstitutiveMatrix_GetIsotropicViscosity( constitutiveMatrix );
+
+	if ( self->strainRateSoftening ) {
+		/* TODO - Put this function in a plugin */
+		viscosity = 2.0 * yieldCriterion * yieldCriterion * viscosity / 
+				( yieldCriterion * yieldCriterion + yieldIndicator * yieldIndicator );
+		ConstitutiveMatrix_SetIsotropicViscosity( constitutiveMatrix, viscosity );
+	}
+	else {
+                double beta = 1.0 - yieldCriterion / yieldIndicator;
+                double corr = -viscosity * beta;
+
+		if( (viscosity + corr) < self->minVisc )
+		   corr = self->minVisc - viscosity;
+		ConstitutiveMatrix_IsotropicCorrection( constitutiveMatrix, corr );
+	}
+
+        if( constitutiveMatrix->sle && constitutiveMatrix->sle->nlFormJacobian ) {
+           double* derivs = constitutiveMatrix->derivs;
+           double coef;
+
+           coef = -viscosity * self->yieldCriterion / (2.0 * self->stressInv * self->stressInv * self->stressInv);
+           derivs[0] += coef * 2.0 * viscosity * self->stress[0];
+           derivs[4] += coef * 2.0 * viscosity * self->stress[1];
+           derivs[1] += coef * 2.0 * viscosity * self->stress[2];
+           derivs[3] += coef * 2.0 * viscosity * self->stress[2];
+
+        }
+
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/YieldRheology.c
--- a/Rheology/src/YieldRheology.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,231 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: YieldRheology.c 779 2008-08-06 15:50:41Z LukeHodkinson $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "ConstitutiveMatrix.h"
-#include "RheologyClass.h"
-#include "StrainWeakening.h"
-#include "YieldRheology.h"
-
-#include <assert.h>
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type YieldRheology_Type = "YieldRheology";
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-YieldRheology* _YieldRheology_New(  YIELDRHEOLOGY_DEFARGS  ) 
-{
-	YieldRheology*					self;
-
-	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-	assert( _sizeOfSelf >= sizeof(YieldRheology) );
-	self = (YieldRheology*) _Rheology_New(  RHEOLOGY_PASSARGS  );
-	
-	/* Function pointers for this class that are not on the parent class should be set here */
-	self->_getYieldCriterion = _getYieldCriterion;
-	self->_getYieldIndicator = _getYieldIndicator;
-	self->_hasYielded        = _hasYielded;
-	
-	return self;
-}
-
-void _YieldRheology_Init( YieldRheology* self, StrainWeakening* strainWeakening, MaterialPointsSwarm* materialPointsSwarm, double minVisc )
-{
-	ExtensionInfo_Index     handle             = (ExtensionInfo_Index) -1;
-	self->strainWeakening = strainWeakening;
-
-	Rheology_SetToNonLinear( self );
-	
-	if ( materialPointsSwarm ) {
-		ArithPointer offset; 
-		
-		/* See if the YieldRheology Type has already added an extension to the particle 
-		 * If handle is given a value of '-1' - that means that no extension has been added
-		 * with the YieldRheology_Type
-		 * We should then add the extension */
-		
-		handle = ExtensionManager_GetHandle( materialPointsSwarm->particleExtensionMgr, (Name)YieldRheology_Type );
-		
-		if ( handle == (ExtensionInfo_Index) -1  ) {
-			handle = ExtensionManager_Add( materialPointsSwarm->particleExtensionMgr, (Name)YieldRheology_Type, sizeof(Particle_Bool));
-
-			/* Adding variable for plotting purpose */
-			offset = (ArithPointer ) 
-				ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, NULL, handle );
-
-			self->hasYieldedVariable = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"HasYielded", offset, Variable_DataType_Char  );
-		}
-		else {
-			/* if the variable has already been created - then just store the pointer */
-			char* hasYieldedVariableName = Stg_Object_AppendSuffix( materialPointsSwarm, (Name)"HasYielded"  );
-			self->hasYieldedVariable = SwarmVariable_Register_GetByName( materialPointsSwarm->swarmVariable_Register, hasYieldedVariableName );
-			Memory_Free( hasYieldedVariableName );
-		}
-	}
-	
-	/* Store value of particle extension handle
-	 * if there are no material points - this will be '-1'
-	 * if there are material points - all YieldRheology objects will refer to the same handle */
-	self->hasYieldedParticleExtHandle = handle;
-
-   self->yieldCriterion = 0.0;
-   self->minVisc = minVisc;
-}
-
-
-void _YieldRheology_Delete( void* rheology ) {
-	YieldRheology*					self = (YieldRheology*)rheology;
-	
-	_Stg_Component_Delete( self );
-}
-
-void _YieldRheology_Print( void* rheology, Stream* stream ) {}
-
-void* _YieldRheology_Copy( const void* rheology, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	YieldRheology*	self = (YieldRheology*)rheology;
-
-	/* TODO */ abort();
-	return (void*) self;
-}
-
-void _YieldRheology_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
-	YieldRheology*        self                 = (YieldRheology*)rheology;
-	StrainWeakening*      strainWeakening;
-	MaterialPointsSwarm*  materialPoints;
-	double                minVisc;
-	
-	_Rheology_AssignFromXML( self, cf, data );
-
-	strainWeakening =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"StrainWeakening", StrainWeakening, False, data   ) ;
-
-	materialPoints =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"MaterialPointsSwarm", MaterialPointsSwarm, False, data   ) ;
-
-   minVisc = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"minimumViscosity", 0.0  );
-   
-	_YieldRheology_Init( self, strainWeakening, materialPoints, minVisc );
-}
-
-void _YieldRheology_Build( void* rheology, void* data ) {
-	YieldRheology*                   self          = (YieldRheology*) rheology;
-
-	_Rheology_Build( rheology, data );
-
-	/* This variable only needs to be built if there are material points (hasYieldedVariable is created
-	 * in _YieldRheology_Init only in that case) */
-	
-	if ( self->hasYieldedVariable ) Stg_Component_Build( self->hasYieldedVariable, data, False );
-
-}
-
-void _YieldRheology_Initialise( void* rheology, void* data ) {
-	YieldRheology*                   self          = (YieldRheology*) rheology;
-	
-	_Rheology_Initialise( rheology, data );
-
-	/* This variable only needs to be initialised if there are material points (hasYieldedVariable is created
-	 * in _YieldRheology_Init only in that case) */
-	if ( self->context->loadFromCheckPoint == False )
-      if ( self->hasYieldedVariable ) Stg_Component_Initialise( self->hasYieldedVariable, data, False );
-}
-
-void _YieldRheology_Execute( void* rheology, void* data ) {}
-
-void _YieldRheology_Destroy( void* rheology, void* data ) {
-   YieldRheology* self = (YieldRheology*) rheology;
-   
-   if( self->strainWeakening )     Stg_Component_Destroy( self->strainWeakening, data, False );
-   if ( self->hasYieldedVariable ) Stg_Component_Destroy( self->hasYieldedVariable, data, False );
-   
-   _Rheology_Destroy( self, data ); 
-}
-
-void _YieldRheology_ModifyConstitutiveMatrix( 
-		void*                                              yieldRheology, 
-		ConstitutiveMatrix*                                constitutiveMatrix,
-		MaterialPointsSwarm*                               materialPointsSwarm,
-		Element_LocalIndex                                 lElement_I,
-		MaterialPoint*                                     materialPoint,
-		Coord                                              xi )
-{
-	YieldRheology*                   self          = (YieldRheology*) yieldRheology;
-	double                           yieldCriterion;
-	double                           yieldIndicator; /* A particle will yield if yieldCriterion < yieldIndicator */
-	
-	/* Don't want to yield on the first ever solve */
-	if ( !constitutiveMatrix->previousSolutionExists )
-		return;
-		
-	yieldIndicator = YieldRheology_GetYieldIndicator( self, constitutiveMatrix, materialPointsSwarm, lElement_I, materialPoint, xi );
-	yieldCriterion = YieldRheology_GetYieldCriterion( self, constitutiveMatrix, materialPointsSwarm, lElement_I, materialPoint, xi );
-	
-	/* This function is called before YieldRheology_HasYielded  because :
-	 * If a particle has not yielded, we still need to update the strain weakening for it (it will heal
-	 * in that case rather than weaken)
-	 * If a particle has yielded, the initial viscosity is needed to update the strain weakening. But since this 
-	 * viscosity can be modified in the constitutive matrix by YieldRheology_HasYielded function, we need to do the update 
-	 * before */
-	
-	if ( self->strainWeakening ) {
-		StrainWeakening_AssignIncrement( self->strainWeakening, constitutiveMatrix, materialPointsSwarm,
-			lElement_I, materialPoint, yieldCriterion, yieldIndicator );
-	}
-
-	/* Set a bool to TRUE or FLAG depending on whether a particle has failed or not */
-	YieldRheology_SetParticleFlag( self, materialPointsSwarm, materialPoint, (yieldCriterion < yieldIndicator) );
-
-	/* Test to see if it has yielded */
-	if ( yieldCriterion < yieldIndicator ) {
-		YieldRheology_HasYielded( self, constitutiveMatrix, materialPointsSwarm, lElement_I, materialPoint, yieldCriterion, yieldIndicator );
-	}
-}
-
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/src/YieldRheology.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/src/YieldRheology.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,231 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: YieldRheology.c 779 2008-08-06 15:50:41Z LukeHodkinson $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "ConstitutiveMatrix.h"
+#include "RheologyClass.h"
+#include "StrainWeakening.h"
+#include "YieldRheology.h"
+
+#include <assert.h>
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type YieldRheology_Type = "YieldRheology";
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+YieldRheology* _YieldRheology_New(  YIELDRHEOLOGY_DEFARGS  ) 
+{
+	YieldRheology*					self;
+
+	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+	assert( _sizeOfSelf >= sizeof(YieldRheology) );
+	self = (YieldRheology*) _Rheology_New(  RHEOLOGY_PASSARGS  );
+	
+	/* Function pointers for this class that are not on the parent class should be set here */
+	self->_getYieldCriterion = _getYieldCriterion;
+	self->_getYieldIndicator = _getYieldIndicator;
+	self->_hasYielded        = _hasYielded;
+	
+	return self;
+}
+
+void _YieldRheology_Init( YieldRheology* self, StrainWeakening* strainWeakening, MaterialPointsSwarm* materialPointsSwarm, double minVisc )
+{
+	ExtensionInfo_Index     handle             = (ExtensionInfo_Index) -1;
+	self->strainWeakening = strainWeakening;
+
+	Rheology_SetToNonLinear( self );
+	
+	if ( materialPointsSwarm ) {
+		ArithPointer offset; 
+		
+		/* See if the YieldRheology Type has already added an extension to the particle 
+		 * If handle is given a value of '-1' - that means that no extension has been added
+		 * with the YieldRheology_Type
+		 * We should then add the extension */
+		
+		handle = ExtensionManager_GetHandle( materialPointsSwarm->particleExtensionMgr, (Name)YieldRheology_Type );
+		
+		if ( handle == (ExtensionInfo_Index) -1  ) {
+			handle = ExtensionManager_Add( materialPointsSwarm->particleExtensionMgr, (Name)YieldRheology_Type, sizeof(Particle_Bool));
+
+			/* Adding variable for plotting purpose */
+			offset = (ArithPointer ) 
+				ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, NULL, handle );
+
+			self->hasYieldedVariable = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"HasYielded", offset, Variable_DataType_Char  );
+		}
+		else {
+			/* if the variable has already been created - then just store the pointer */
+			char* hasYieldedVariableName = Stg_Object_AppendSuffix( materialPointsSwarm, (Name)"HasYielded"  );
+			self->hasYieldedVariable = SwarmVariable_Register_GetByName( materialPointsSwarm->swarmVariable_Register, hasYieldedVariableName );
+			Memory_Free( hasYieldedVariableName );
+		}
+	}
+	
+	/* Store value of particle extension handle
+	 * if there are no material points - this will be '-1'
+	 * if there are material points - all YieldRheology objects will refer to the same handle */
+	self->hasYieldedParticleExtHandle = handle;
+
+   self->yieldCriterion = 0.0;
+   self->minVisc = minVisc;
+}
+
+
+void _YieldRheology_Delete( void* rheology ) {
+	YieldRheology*					self = (YieldRheology*)rheology;
+	
+	_Stg_Component_Delete( self );
+}
+
+void _YieldRheology_Print( void* rheology, Stream* stream ) {}
+
+void* _YieldRheology_Copy( const void* rheology, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	YieldRheology*	self = (YieldRheology*)rheology;
+
+	/* TODO */ abort();
+	return (void*) self;
+}
+
+void _YieldRheology_AssignFromXML( void* rheology, Stg_ComponentFactory* cf, void* data ){
+	YieldRheology*        self                 = (YieldRheology*)rheology;
+	StrainWeakening*      strainWeakening;
+	MaterialPointsSwarm*  materialPoints;
+	double                minVisc;
+	
+	_Rheology_AssignFromXML( self, cf, data );
+
+	strainWeakening =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"StrainWeakening", StrainWeakening, False, data   ) ;
+
+	materialPoints =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"MaterialPointsSwarm", MaterialPointsSwarm, False, data   ) ;
+
+   minVisc = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"minimumViscosity", 0.0  );
+   
+	_YieldRheology_Init( self, strainWeakening, materialPoints, minVisc );
+}
+
+void _YieldRheology_Build( void* rheology, void* data ) {
+	YieldRheology*                   self          = (YieldRheology*) rheology;
+
+	_Rheology_Build( rheology, data );
+
+	/* This variable only needs to be built if there are material points (hasYieldedVariable is created
+	 * in _YieldRheology_Init only in that case) */
+	
+	if ( self->hasYieldedVariable ) Stg_Component_Build( self->hasYieldedVariable, data, False );
+
+}
+
+void _YieldRheology_Initialise( void* rheology, void* data ) {
+	YieldRheology*                   self          = (YieldRheology*) rheology;
+	
+	_Rheology_Initialise( rheology, data );
+
+	/* This variable only needs to be initialised if there are material points (hasYieldedVariable is created
+	 * in _YieldRheology_Init only in that case) */
+	if ( self->context->loadFromCheckPoint == False )
+      if ( self->hasYieldedVariable ) Stg_Component_Initialise( self->hasYieldedVariable, data, False );
+}
+
+void _YieldRheology_Execute( void* rheology, void* data ) {}
+
+void _YieldRheology_Destroy( void* rheology, void* data ) {
+   YieldRheology* self = (YieldRheology*) rheology;
+   
+   if( self->strainWeakening )     Stg_Component_Destroy( self->strainWeakening, data, False );
+   if ( self->hasYieldedVariable ) Stg_Component_Destroy( self->hasYieldedVariable, data, False );
+   
+   _Rheology_Destroy( self, data ); 
+}
+
+void _YieldRheology_ModifyConstitutiveMatrix( 
+		void*                                              yieldRheology, 
+		ConstitutiveMatrix*                                constitutiveMatrix,
+		MaterialPointsSwarm*                               materialPointsSwarm,
+		Element_LocalIndex                                 lElement_I,
+		MaterialPoint*                                     materialPoint,
+		Coord                                              xi )
+{
+	YieldRheology*                   self          = (YieldRheology*) yieldRheology;
+	double                           yieldCriterion;
+	double                           yieldIndicator; /* A particle will yield if yieldCriterion < yieldIndicator */
+	
+	/* Don't want to yield on the first ever solve */
+	if ( !constitutiveMatrix->previousSolutionExists )
+		return;
+		
+	yieldIndicator = YieldRheology_GetYieldIndicator( self, constitutiveMatrix, materialPointsSwarm, lElement_I, materialPoint, xi );
+	yieldCriterion = YieldRheology_GetYieldCriterion( self, constitutiveMatrix, materialPointsSwarm, lElement_I, materialPoint, xi );
+	
+	/* This function is called before YieldRheology_HasYielded  because :
+	 * If a particle has not yielded, we still need to update the strain weakening for it (it will heal
+	 * in that case rather than weaken)
+	 * If a particle has yielded, the initial viscosity is needed to update the strain weakening. But since this 
+	 * viscosity can be modified in the constitutive matrix by YieldRheology_HasYielded function, we need to do the update 
+	 * before */
+	
+	if ( self->strainWeakening ) {
+		StrainWeakening_AssignIncrement( self->strainWeakening, constitutiveMatrix, materialPointsSwarm,
+			lElement_I, materialPoint, yieldCriterion, yieldIndicator );
+	}
+
+	/* Set a bool to TRUE or FLAG depending on whether a particle has failed or not */
+	YieldRheology_SetParticleFlag( self, materialPointsSwarm, materialPoint, (yieldCriterion < yieldIndicator) );
+
+	/* Test to see if it has yielded */
+	if ( yieldCriterion < yieldIndicator ) {
+		YieldRheology_HasYielded( self, constitutiveMatrix, materialPointsSwarm, lElement_I, materialPoint, yieldCriterion, yieldIndicator );
+	}
+}
+
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/tests/ByerleeYieldingSuite.c
--- a/Rheology/tests/ByerleeYieldingSuite.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,201 +0,0 @@
-#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 "Underworld/Underworld.h"
-
-/* silly stgermain, I must define this */
-#define CURR_MODULE_NAME "UnderworldContext.c"
-
-const Type ByerleeYieldingSuite_testByerlee2D_Type = "Underworld_testYieldCriterion";
-
-/* Define plugin structure */
-typedef struct {
-   __Codelet
-   YieldRheology_HasYieldedFunction* realHasYieldedFunction;
-   FeMesh*               mesh;
-   XYZ                   min;
-   XYZ                   max;
-   Bool                  hasYielded;
-} ByerleeYielding2D_testYieldCriterion;
-
-/* define global vars .... that's very ugly, but it's only a pcu test */
-ByerleeYielding2D_testYieldCriterion globalSelf;
-
-typedef struct {
-} ByerleeYieldingSuiteData;
-
-void ByerleeYieldingSuite_Setup( ByerleeYieldingSuiteData* data ) { 
-	Journal_Enable_AllTypedStream( False );
-}
-
-void ByerleeYieldingSuite_Teardown( ByerleeYieldingSuiteData* data ) {
-	Journal_Enable_AllTypedStream( True );
-}
-
-double ByerleeYieldingSuite_dt( FiniteElementContext* context ) {
-	if ( context->currentTime >= 0.65 ) {
-		return 0.01;
-	}
-	return HUGE_VAL;
-}
-
-void testByerlee2D_HasYielded( 
-	void*						yieldRheology,
-	ConstitutiveMatrix*	constitutiveMatrix,
-	MaterialPointsSwarm*	materialPointsSwarm,
-	Element_LocalIndex	lElement_I,
-	MaterialPoint*			materialPoint,
-	double					yieldCriterion,
-	double					yieldIndicator ) 
-{
-	Dimension_Index dim_I;
-
-	/* Call real 'HasYielded' function */
-	globalSelf.realHasYieldedFunction( yieldRheology, constitutiveMatrix, materialPointsSwarm, lElement_I, materialPoint, yieldCriterion, yieldIndicator );
-
-	/* Don't output information if this is the first non-linear iteration */
-	if ( constitutiveMatrix->sleNonLinearIteration_I == 0 ) {
-		return;
-	}
-
-	/* Store information */
-	globalSelf.hasYielded = True;
-	for ( dim_I = 0 ; dim_I < constitutiveMatrix->dim ; dim_I++ ) {
-		if ( materialPoint->coord[ dim_I ] < globalSelf.min[ dim_I ] )
-			globalSelf.min[ dim_I ] = materialPoint->coord[ dim_I ];
-		if ( materialPoint->coord[ dim_I ] > globalSelf.max[ dim_I ] )
-			globalSelf.max[ dim_I ] = materialPoint->coord[ dim_I ];
-	}
-}
-
-
-void ByerleeYieldingSuite_Check( FiniteElementContext* context ) {
-	Stream* stream;
-	
-	Journal_Enable_AllTypedStream( True );
-
-	stream = Journal_Register( Dump_Type, (Name)ByerleeYieldingSuite_testByerlee2D_Type );
-
-   if(context->rank == 0){
-      /* Don't do anything if nothing has yielded yet */
-      if ( !globalSelf.hasYielded ) {
-         return;
-      }
-   
-      /* Set the stream to point to our output file (so we can do a diff on it later ) */
-      Stream_Enable( stream, True );
-      Stream_RedirectFile_WithPrependedPath( stream, context->outputPath, "testByerlee2D.dat" );
-   
-      Journal_Printf( stream, "Material yielded at time %12.4g (step %u) within:\n", context->currentTime, context->timeStep ); 
-   
-      /* Output information */
-      Journal_Printf( stream, "\tx: %12.4g - %12.4g\n", globalSelf.min[ I_AXIS ], globalSelf.max[ I_AXIS ] );
-      Journal_Printf( stream, "\ty: %12.4g - %12.4g\n", globalSelf.min[ J_AXIS ], globalSelf.max[ J_AXIS ] );
-      if ( context->dim == 3 ) {
-         Journal_Printf( stream, "\tz: %12.4g - %12.4g\n", globalSelf.min[ K_AXIS ], globalSelf.max[ K_AXIS ] );
-      }
-      Stream_CloseAndFreeFile( stream );
-   }
-	Journal_Enable_AllTypedStream( False );
-}
-
-void ByerleeYieldingSuite_Check_Sync( FiniteElementContext* context ) {
-   Coord mins;
-   Coord maxs;
-   
-   /* get true global max/min */
-
-   MPI_Allreduce( &globalSelf.min[ I_AXIS ], &mins[I_AXIS], 1, MPI_DOUBLE, MPI_MIN, context->communicator );
-   MPI_Allreduce( &globalSelf.min[ J_AXIS ], &mins[J_AXIS], 1, MPI_DOUBLE, MPI_MIN, context->communicator );
-   if ( context->dim == 3 )
-      MPI_Allreduce( &globalSelf.min[ K_AXIS ], &mins[K_AXIS], 1, MPI_DOUBLE, MPI_MIN, context->communicator );
-
-   MPI_Allreduce( &globalSelf.max[ I_AXIS ], &maxs[I_AXIS], 1, MPI_DOUBLE, MPI_MAX, context->communicator );
-   MPI_Allreduce( &globalSelf.max[ J_AXIS ], &maxs[J_AXIS], 1, MPI_DOUBLE, MPI_MAX, context->communicator );
-   if ( context->dim == 3 )
-      MPI_Allreduce( &globalSelf.max[ K_AXIS ], &maxs[K_AXIS], 1, MPI_DOUBLE, MPI_MAX, context->communicator );
-   
-   /* now set to these values */
-   globalSelf.min[ I_AXIS ] = mins[ I_AXIS ];
-   globalSelf.min[ J_AXIS ] = mins[ J_AXIS ];
-   if ( context->dim == 3 )
-      globalSelf.min[ K_AXIS ] = mins[ K_AXIS ];
-   globalSelf.max[ I_AXIS ] = maxs[ I_AXIS ];
-   globalSelf.max[ J_AXIS ] = maxs[ J_AXIS ];
-   if ( context->dim == 3 )
-      globalSelf.max[ K_AXIS ] = maxs[ K_AXIS ];
-}
-
-void ByerleeYieldingSuite_TestByerlee2D( ByerleeYieldingSuiteData* data ) {
-	UnderworldContext*		context;
-	Dictionary*					dictionary;
-	YieldRheology*          yieldRheology;
-	Stg_ComponentFactory*	cf;
-	char							expected_file[PCU_PATH_MAX];
-	char							xml_input[PCU_PATH_MAX];
-
-	/* read in the xml input file */
-	pcu_filename_input( "testByerleeYieldCriterion.xml", xml_input );
-	cf = stgMainInitFromXML( xml_input, MPI_COMM_WORLD, NULL );
-	context = (UnderworldContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context"  );
-	Stream_Enable( context->info, False );
-	Stream_Enable( context->debug, False );
-	Stream_Enable( context->verbose, False );
-	dictionary = context->dictionary;
-
-	stgMainBuildAndInitialise( cf );
-
-	/* get pointer to the mesh */
-	globalSelf.mesh = Stg_ComponentFactory_ConstructByName( cf, (Name)"linearMesh", FeMesh, True, NULL ); 
-	
-	/* Get a pointer the yield rheology that we are trying to test */
-	yieldRheology = (YieldRheology* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"yieldRheology"  );
-	
-	/* Store the pointer to the original 'HasYielded' function */
-	globalSelf.realHasYieldedFunction = yieldRheology->_hasYielded;
-
-	/* Reset this function pointer with our own */
-	yieldRheology->_hasYielded = testByerlee2D_HasYielded;
-
-	/* Get Calculation after one step */
-	context->maxTimeSteps = 1;
-
-	ContextEP_Append( context, AbstractContext_EP_Step, ByerleeYieldingSuite_Check_Sync );
-	ContextEP_Append( context, AbstractContext_EP_Step, ByerleeYieldingSuite_Check );
-	EP_AppendClassHook( Context_GetEntryPoint( context, FiniteElementContext_EP_CalcDt ), ByerleeYieldingSuite_dt, context );
-
-	globalSelf.min[ I_AXIS ] = HUGE_VAL;
-	globalSelf.min[ J_AXIS ] = HUGE_VAL;
-	globalSelf.min[ K_AXIS ] = HUGE_VAL;
-	globalSelf.max[ I_AXIS ] = -HUGE_VAL;
-	globalSelf.max[ J_AXIS ] = -HUGE_VAL;
-	globalSelf.max[ K_AXIS ] = -HUGE_VAL;
-
-	//stgMainLoop( cf );
-	Stg_Component_Execute( context, 0, True );
-
-	MPI_Barrier( context->communicator );
-	pcu_filename_expected( "testByerleeYieldCriterion.expected", expected_file );
-	pcu_check_fileEq( "output/testByerlee2D.dat", expected_file );
-
-   if(context->rank == 0){
-      remove("output/testByerlee2D.dat");
-      remove("output");
-   }
-
-	stgMainDestroy( cf );
-}
-
-void ByerleeYieldingSuite( pcu_suite_t* suite ) {
-   pcu_suite_setData( suite, ByerleeYieldingSuiteData );
-   pcu_suite_setFixtures( suite, ByerleeYieldingSuite_Setup, ByerleeYieldingSuite_Teardown );
-   pcu_suite_addTest( suite, ByerleeYieldingSuite_TestByerlee2D );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/tests/ByerleeYieldingSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/tests/ByerleeYieldingSuite.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,201 @@
+#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 "Underworld/Underworld.h"
+
+/* silly stgermain, I must define this */
+#define CURR_MODULE_NAME "UnderworldContext.c"
+
+const Type ByerleeYieldingSuite_testByerlee2D_Type = "Underworld_testYieldCriterion";
+
+/* Define plugin structure */
+typedef struct {
+   __Codelet
+   YieldRheology_HasYieldedFunction* realHasYieldedFunction;
+   FeMesh*               mesh;
+   XYZ                   min;
+   XYZ                   max;
+   Bool                  hasYielded;
+} ByerleeYielding2D_testYieldCriterion;
+
+/* define global vars .... that's very ugly, but it's only a pcu test */
+ByerleeYielding2D_testYieldCriterion globalSelf;
+
+typedef struct {
+} ByerleeYieldingSuiteData;
+
+void ByerleeYieldingSuite_Setup( ByerleeYieldingSuiteData* data ) { 
+	Journal_Enable_AllTypedStream( False );
+}
+
+void ByerleeYieldingSuite_Teardown( ByerleeYieldingSuiteData* data ) {
+	Journal_Enable_AllTypedStream( True );
+}
+
+double ByerleeYieldingSuite_dt( FiniteElementContext* context ) {
+	if ( context->currentTime >= 0.65 ) {
+		return 0.01;
+	}
+	return HUGE_VAL;
+}
+
+void testByerlee2D_HasYielded( 
+	void*						yieldRheology,
+	ConstitutiveMatrix*	constitutiveMatrix,
+	MaterialPointsSwarm*	materialPointsSwarm,
+	Element_LocalIndex	lElement_I,
+	MaterialPoint*			materialPoint,
+	double					yieldCriterion,
+	double					yieldIndicator ) 
+{
+	Dimension_Index dim_I;
+
+	/* Call real 'HasYielded' function */
+	globalSelf.realHasYieldedFunction( yieldRheology, constitutiveMatrix, materialPointsSwarm, lElement_I, materialPoint, yieldCriterion, yieldIndicator );
+
+	/* Don't output information if this is the first non-linear iteration */
+	if ( constitutiveMatrix->sleNonLinearIteration_I == 0 ) {
+		return;
+	}
+
+	/* Store information */
+	globalSelf.hasYielded = True;
+	for ( dim_I = 0 ; dim_I < constitutiveMatrix->dim ; dim_I++ ) {
+		if ( materialPoint->coord[ dim_I ] < globalSelf.min[ dim_I ] )
+			globalSelf.min[ dim_I ] = materialPoint->coord[ dim_I ];
+		if ( materialPoint->coord[ dim_I ] > globalSelf.max[ dim_I ] )
+			globalSelf.max[ dim_I ] = materialPoint->coord[ dim_I ];
+	}
+}
+
+
+void ByerleeYieldingSuite_Check( FiniteElementContext* context ) {
+	Stream* stream;
+	
+	Journal_Enable_AllTypedStream( True );
+
+	stream = Journal_Register( Dump_Type, (Name)ByerleeYieldingSuite_testByerlee2D_Type );
+
+   if(context->rank == 0){
+      /* Don't do anything if nothing has yielded yet */
+      if ( !globalSelf.hasYielded ) {
+         return;
+      }
+   
+      /* Set the stream to point to our output file (so we can do a diff on it later ) */
+      Stream_Enable( stream, True );
+      Stream_RedirectFile_WithPrependedPath( stream, context->outputPath, "testByerlee2D.dat" );
+   
+      Journal_Printf( stream, "Material yielded at time %12.4g (step %u) within:\n", context->currentTime, context->timeStep ); 
+   
+      /* Output information */
+      Journal_Printf( stream, "\tx: %12.4g - %12.4g\n", globalSelf.min[ I_AXIS ], globalSelf.max[ I_AXIS ] );
+      Journal_Printf( stream, "\ty: %12.4g - %12.4g\n", globalSelf.min[ J_AXIS ], globalSelf.max[ J_AXIS ] );
+      if ( context->dim == 3 ) {
+         Journal_Printf( stream, "\tz: %12.4g - %12.4g\n", globalSelf.min[ K_AXIS ], globalSelf.max[ K_AXIS ] );
+      }
+      Stream_CloseAndFreeFile( stream );
+   }
+	Journal_Enable_AllTypedStream( False );
+}
+
+void ByerleeYieldingSuite_Check_Sync( FiniteElementContext* context ) {
+   Coord mins;
+   Coord maxs;
+   
+   /* get true global max/min */
+
+   MPI_Allreduce( &globalSelf.min[ I_AXIS ], &mins[I_AXIS], 1, MPI_DOUBLE, MPI_MIN, context->communicator );
+   MPI_Allreduce( &globalSelf.min[ J_AXIS ], &mins[J_AXIS], 1, MPI_DOUBLE, MPI_MIN, context->communicator );
+   if ( context->dim == 3 )
+      MPI_Allreduce( &globalSelf.min[ K_AXIS ], &mins[K_AXIS], 1, MPI_DOUBLE, MPI_MIN, context->communicator );
+
+   MPI_Allreduce( &globalSelf.max[ I_AXIS ], &maxs[I_AXIS], 1, MPI_DOUBLE, MPI_MAX, context->communicator );
+   MPI_Allreduce( &globalSelf.max[ J_AXIS ], &maxs[J_AXIS], 1, MPI_DOUBLE, MPI_MAX, context->communicator );
+   if ( context->dim == 3 )
+      MPI_Allreduce( &globalSelf.max[ K_AXIS ], &maxs[K_AXIS], 1, MPI_DOUBLE, MPI_MAX, context->communicator );
+   
+   /* now set to these values */
+   globalSelf.min[ I_AXIS ] = mins[ I_AXIS ];
+   globalSelf.min[ J_AXIS ] = mins[ J_AXIS ];
+   if ( context->dim == 3 )
+      globalSelf.min[ K_AXIS ] = mins[ K_AXIS ];
+   globalSelf.max[ I_AXIS ] = maxs[ I_AXIS ];
+   globalSelf.max[ J_AXIS ] = maxs[ J_AXIS ];
+   if ( context->dim == 3 )
+      globalSelf.max[ K_AXIS ] = maxs[ K_AXIS ];
+}
+
+void ByerleeYieldingSuite_TestByerlee2D( ByerleeYieldingSuiteData* data ) {
+	UnderworldContext*		context;
+	Dictionary*					dictionary;
+	YieldRheology*          yieldRheology;
+	Stg_ComponentFactory*	cf;
+	char							expected_file[PCU_PATH_MAX];
+	char							xml_input[PCU_PATH_MAX];
+
+	/* read in the xml input file */
+	pcu_filename_input( "testByerleeYieldCriterion.xml", xml_input );
+	cf = stgMainInitFromXML( xml_input, MPI_COMM_WORLD, NULL );
+	context = (UnderworldContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context"  );
+	Stream_Enable( context->info, False );
+	Stream_Enable( context->debug, False );
+	Stream_Enable( context->verbose, False );
+	dictionary = context->dictionary;
+
+	stgMainBuildAndInitialise( cf );
+
+	/* get pointer to the mesh */
+	globalSelf.mesh = Stg_ComponentFactory_ConstructByName( cf, (Name)"linearMesh", FeMesh, True, NULL ); 
+	
+	/* Get a pointer the yield rheology that we are trying to test */
+	yieldRheology = (YieldRheology* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"yieldRheology"  );
+	
+	/* Store the pointer to the original 'HasYielded' function */
+	globalSelf.realHasYieldedFunction = yieldRheology->_hasYielded;
+
+	/* Reset this function pointer with our own */
+	yieldRheology->_hasYielded = testByerlee2D_HasYielded;
+
+	/* Get Calculation after one step */
+	context->maxTimeSteps = 1;
+
+	ContextEP_Append( context, AbstractContext_EP_Step, ByerleeYieldingSuite_Check_Sync );
+	ContextEP_Append( context, AbstractContext_EP_Step, ByerleeYieldingSuite_Check );
+	EP_AppendClassHook( Context_GetEntryPoint( context, FiniteElementContext_EP_CalcDt ), ByerleeYieldingSuite_dt, context );
+
+	globalSelf.min[ I_AXIS ] = HUGE_VAL;
+	globalSelf.min[ J_AXIS ] = HUGE_VAL;
+	globalSelf.min[ K_AXIS ] = HUGE_VAL;
+	globalSelf.max[ I_AXIS ] = -HUGE_VAL;
+	globalSelf.max[ J_AXIS ] = -HUGE_VAL;
+	globalSelf.max[ K_AXIS ] = -HUGE_VAL;
+
+	//stgMainLoop( cf );
+	Stg_Component_Execute( context, 0, True );
+
+	MPI_Barrier( context->communicator );
+	pcu_filename_expected( "testByerleeYieldCriterion.expected", expected_file );
+	pcu_check_fileEq( "output/testByerlee2D.dat", expected_file );
+
+   if(context->rank == 0){
+      remove("output/testByerlee2D.dat");
+      remove("output");
+   }
+
+	stgMainDestroy( cf );
+}
+
+void ByerleeYieldingSuite( pcu_suite_t* suite ) {
+   pcu_suite_setData( suite, ByerleeYieldingSuiteData );
+   pcu_suite_setFixtures( suite, ByerleeYieldingSuite_Setup, ByerleeYieldingSuite_Teardown );
+   pcu_suite_addTest( suite, ByerleeYieldingSuite_TestByerlee2D );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/tests/ConstitutiveMatrixSuite.c
--- a/Rheology/tests/ConstitutiveMatrixSuite.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,138 +0,0 @@
-#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 "Underworld/Underworld.h"
-
-/* silly stgermain, I must define this */
-#define CURR_MODULE_NAME "UnderworldContext.c"
-
-typedef struct {
-	UnderworldContext* context;
-} ConstitutiveMatrixSuiteData;
-
-void ConstitutiveMatrixSuite_Setup( ConstitutiveMatrixSuiteData* data ) { 
-	Journal_Enable_AllTypedStream( False );
-}
-
-void ConstitutiveMatrixSuite_Teardown( ConstitutiveMatrixSuiteData* data ) {
-	Journal_Enable_AllTypedStream( True );
-}
-
-void SetMatrixWithSecondViscosity2( ConstitutiveMatrix* constitutiveMatrix, Element_LocalIndex lElement_I, Particle_InCellIndex cParticle_I, void* data ) {
-	XYZ director = { 1.0 , 2.0 , 3.0 };
-
-	StGermain_VectorNormalise( director, constitutiveMatrix->dim );
-
-	ConstitutiveMatrix_SetSecondViscosity( constitutiveMatrix, 2.0, director );
-}
-
-void testConstitutiveMatrix( FiniteElementContext* context ) {
-	Stream*					stream;
-	SymmetricTensor		stress;
-	SymmetricTensor		strainRate = {1, 2, 3, 4, 5, 6};
-	ConstitutiveMatrix*	constitutiveMatrix;
-
-	Journal_Enable_AllTypedStream( True );
-	stream = Journal_Register( Info_Type, (Name)"testConstitutiveMatrix" );
- 
-	constitutiveMatrix = (ConstitutiveMatrix* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"constitutiveMatrix"  );
-
-	/* Create Constitutive Matrix */
-	Stream_RedirectFile_WithPrependedPath( stream, context->outputPath, "output.dat" );
-	
-	Journal_Printf( stream, "Constitutive Matrix after initialisation.\n" );
-	
-	Journal_Printf( stream, "Constitutive Matrix after func 'SetMatrixWithThrees'.\n" );
-	ConstitutiveMatrix_SetValueInAllEntries( constitutiveMatrix, 3.0 );
-	ConstitutiveMatrix_PrintContents( constitutiveMatrix, stream );
-	Journal_PrintBool( stream, constitutiveMatrix->isDiagonal );
-	
-	ConstitutiveMatrix_CalculateStress( constitutiveMatrix, strainRate, stress );
-	Journal_PrintSymmetricTensor( stream, strainRate, constitutiveMatrix->dim );
-	Journal_PrintSymmetricTensor( stream, stress, constitutiveMatrix->dim );
-	
-	Journal_Printf( stream, "Constitutive Matrix after func 'SetMatrixWithViscosity7'.\n" );
-	ConstitutiveMatrix_SetIsotropicViscosity( constitutiveMatrix, 7.0 );
-	ConstitutiveMatrix_PrintContents( constitutiveMatrix, stream );
-	Journal_PrintBool( stream, constitutiveMatrix->isDiagonal );
-
-	Journal_Printf( stream, "Viscosity = %4g\n", ConstitutiveMatrix_GetIsotropicViscosity( constitutiveMatrix ) );
-	ConstitutiveMatrix_CalculateStress( constitutiveMatrix, strainRate, stress );
-	Journal_PrintSymmetricTensor( stream, strainRate, constitutiveMatrix->dim );
-	Journal_PrintSymmetricTensor( stream, stress, constitutiveMatrix->dim );
-	constitutiveMatrix->isDiagonal = False;
-	ConstitutiveMatrix_CalculateStress( constitutiveMatrix, strainRate, stress );
-	Journal_PrintSymmetricTensor( stream, stress, constitutiveMatrix->dim );
-	
-	Journal_Printf( stream, "Constitutive Matrix after func 'SetMatrixWithSecondViscosity2'.\n" );
-	SetMatrixWithSecondViscosity2( constitutiveMatrix, 0, 0, NULL );
-	ConstitutiveMatrix_PrintContents( constitutiveMatrix, stream );
-	Journal_PrintBool( stream, constitutiveMatrix->isDiagonal );
-	
-	ConstitutiveMatrix_CalculateStress( constitutiveMatrix, strainRate, stress );
-	Journal_PrintSymmetricTensor( stream, strainRate, constitutiveMatrix->dim );
-	Journal_PrintSymmetricTensor( stream, stress, constitutiveMatrix->dim );
-
-	Journal_Enable_AllTypedStream( False );
-}
-
-
-void ConstitutiveMatrixSuite_CartesianMatrix2D( ConstitutiveMatrixSuiteData* data ) {
-	Dictionary*					dictionary;
-	UnderworldContext*		context;
-	Stg_ComponentFactory*	cf;
-	char							expected_file[PCU_PATH_MAX], output_file[PCU_PATH_MAX];
-	char							xml_input[PCU_PATH_MAX];
-	char							rFile[PCU_PATH_MAX];
-	int							err;
-
-	pcu_docstring( "This test creates a 2D cartesian constitutive matrix data structure and tests its functionality against an expected file" );
-
-	/* read in the xml input file */
-	pcu_filename_input( "testConstitutiveMatrix_Cartesian2D.xml", xml_input );
-	cf = stgMainInitFromXML( xml_input, MPI_COMM_WORLD, NULL );
-	context = (UnderworldContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context"  );
-	data->context = context;
-	dictionary = context->dictionary;
-
-	/* replace the Execute EP with the function to test the ConstitutiveMatrix */
-	ContextEP_ReplaceAll( context, AbstractContext_EP_Execute, testConstitutiveMatrix );
-
-	/* build and initialise all components */
-	stgMainBuildAndInitialise( cf );
-
-	/* now run the all EPs */
-	stgMainLoop( cf );
-
-	/* create the expected file string */
-	pcu_filename_expected( "testConstitutiveMatrix_Cartesian2D.expected", expected_file );
-
-	/* create the string for the output.dat */
-	strcpy( output_file, context->outputPath );
-	strcat( output_file, "/output.dat" );
-
-	/* check the output file against the expected output file */
-	pcu_check_fileEq( output_file, expected_file );
-
-	/* Now clean output path */
-	sprintf(rFile, "%s/output.dat", data->context->outputPath );
-	err = remove( rFile );
-	if( err == -1 ) printf("Error in %s, can't delete the input.xml\n", __func__);
-
-	/* end the run */
-	stgMainDestroy( cf );
-}
-
-void ConstitutiveMatrixSuite( pcu_suite_t* suite ) {
-   pcu_suite_setData( suite, ConstitutiveMatrixSuiteData );
-   pcu_suite_setFixtures( suite, ConstitutiveMatrixSuite_Setup, ConstitutiveMatrixSuite_Teardown );
-   pcu_suite_addTest( suite, ConstitutiveMatrixSuite_CartesianMatrix2D );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/tests/ConstitutiveMatrixSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/tests/ConstitutiveMatrixSuite.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,138 @@
+#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 "Underworld/Underworld.h"
+
+/* silly stgermain, I must define this */
+#define CURR_MODULE_NAME "UnderworldContext.c"
+
+typedef struct {
+	UnderworldContext* context;
+} ConstitutiveMatrixSuiteData;
+
+void ConstitutiveMatrixSuite_Setup( ConstitutiveMatrixSuiteData* data ) { 
+	Journal_Enable_AllTypedStream( False );
+}
+
+void ConstitutiveMatrixSuite_Teardown( ConstitutiveMatrixSuiteData* data ) {
+	Journal_Enable_AllTypedStream( True );
+}
+
+void SetMatrixWithSecondViscosity2( ConstitutiveMatrix* constitutiveMatrix, Element_LocalIndex lElement_I, Particle_InCellIndex cParticle_I, void* data ) {
+	XYZ director = { 1.0 , 2.0 , 3.0 };
+
+	StGermain_VectorNormalise( director, constitutiveMatrix->dim );
+
+	ConstitutiveMatrix_SetSecondViscosity( constitutiveMatrix, 2.0, director );
+}
+
+void testConstitutiveMatrix( FiniteElementContext* context ) {
+	Stream*					stream;
+	SymmetricTensor		stress;
+	SymmetricTensor		strainRate = {1, 2, 3, 4, 5, 6};
+	ConstitutiveMatrix*	constitutiveMatrix;
+
+	Journal_Enable_AllTypedStream( True );
+	stream = Journal_Register( Info_Type, (Name)"testConstitutiveMatrix" );
+ 
+	constitutiveMatrix = (ConstitutiveMatrix* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"constitutiveMatrix"  );
+
+	/* Create Constitutive Matrix */
+	Stream_RedirectFile_WithPrependedPath( stream, context->outputPath, "output.dat" );
+	
+	Journal_Printf( stream, "Constitutive Matrix after initialisation.\n" );
+	
+	Journal_Printf( stream, "Constitutive Matrix after func 'SetMatrixWithThrees'.\n" );
+	ConstitutiveMatrix_SetValueInAllEntries( constitutiveMatrix, 3.0 );
+	ConstitutiveMatrix_PrintContents( constitutiveMatrix, stream );
+	Journal_PrintBool( stream, constitutiveMatrix->isDiagonal );
+	
+	ConstitutiveMatrix_CalculateStress( constitutiveMatrix, strainRate, stress );
+	Journal_PrintSymmetricTensor( stream, strainRate, constitutiveMatrix->dim );
+	Journal_PrintSymmetricTensor( stream, stress, constitutiveMatrix->dim );
+	
+	Journal_Printf( stream, "Constitutive Matrix after func 'SetMatrixWithViscosity7'.\n" );
+	ConstitutiveMatrix_SetIsotropicViscosity( constitutiveMatrix, 7.0 );
+	ConstitutiveMatrix_PrintContents( constitutiveMatrix, stream );
+	Journal_PrintBool( stream, constitutiveMatrix->isDiagonal );
+
+	Journal_Printf( stream, "Viscosity = %4g\n", ConstitutiveMatrix_GetIsotropicViscosity( constitutiveMatrix ) );
+	ConstitutiveMatrix_CalculateStress( constitutiveMatrix, strainRate, stress );
+	Journal_PrintSymmetricTensor( stream, strainRate, constitutiveMatrix->dim );
+	Journal_PrintSymmetricTensor( stream, stress, constitutiveMatrix->dim );
+	constitutiveMatrix->isDiagonal = False;
+	ConstitutiveMatrix_CalculateStress( constitutiveMatrix, strainRate, stress );
+	Journal_PrintSymmetricTensor( stream, stress, constitutiveMatrix->dim );
+	
+	Journal_Printf( stream, "Constitutive Matrix after func 'SetMatrixWithSecondViscosity2'.\n" );
+	SetMatrixWithSecondViscosity2( constitutiveMatrix, 0, 0, NULL );
+	ConstitutiveMatrix_PrintContents( constitutiveMatrix, stream );
+	Journal_PrintBool( stream, constitutiveMatrix->isDiagonal );
+	
+	ConstitutiveMatrix_CalculateStress( constitutiveMatrix, strainRate, stress );
+	Journal_PrintSymmetricTensor( stream, strainRate, constitutiveMatrix->dim );
+	Journal_PrintSymmetricTensor( stream, stress, constitutiveMatrix->dim );
+
+	Journal_Enable_AllTypedStream( False );
+}
+
+
+void ConstitutiveMatrixSuite_CartesianMatrix2D( ConstitutiveMatrixSuiteData* data ) {
+	Dictionary*					dictionary;
+	UnderworldContext*		context;
+	Stg_ComponentFactory*	cf;
+	char							expected_file[PCU_PATH_MAX], output_file[PCU_PATH_MAX];
+	char							xml_input[PCU_PATH_MAX];
+	char							rFile[PCU_PATH_MAX];
+	int							err;
+
+	pcu_docstring( "This test creates a 2D cartesian constitutive matrix data structure and tests its functionality against an expected file" );
+
+	/* read in the xml input file */
+	pcu_filename_input( "testConstitutiveMatrix_Cartesian2D.xml", xml_input );
+	cf = stgMainInitFromXML( xml_input, MPI_COMM_WORLD, NULL );
+	context = (UnderworldContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context"  );
+	data->context = context;
+	dictionary = context->dictionary;
+
+	/* replace the Execute EP with the function to test the ConstitutiveMatrix */
+	ContextEP_ReplaceAll( context, AbstractContext_EP_Execute, testConstitutiveMatrix );
+
+	/* build and initialise all components */
+	stgMainBuildAndInitialise( cf );
+
+	/* now run the all EPs */
+	stgMainLoop( cf );
+
+	/* create the expected file string */
+	pcu_filename_expected( "testConstitutiveMatrix_Cartesian2D.expected", expected_file );
+
+	/* create the string for the output.dat */
+	strcpy( output_file, context->outputPath );
+	strcat( output_file, "/output.dat" );
+
+	/* check the output file against the expected output file */
+	pcu_check_fileEq( output_file, expected_file );
+
+	/* Now clean output path */
+	sprintf(rFile, "%s/output.dat", data->context->outputPath );
+	err = remove( rFile );
+	if( err == -1 ) printf("Error in %s, can't delete the input.xml\n", __func__);
+
+	/* end the run */
+	stgMainDestroy( cf );
+}
+
+void ConstitutiveMatrixSuite( pcu_suite_t* suite ) {
+   pcu_suite_setData( suite, ConstitutiveMatrixSuiteData );
+   pcu_suite_setFixtures( suite, ConstitutiveMatrixSuite_Setup, ConstitutiveMatrixSuite_Teardown );
+   pcu_suite_addTest( suite, ConstitutiveMatrixSuite_CartesianMatrix2D );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/tests/DirectorSuite.c
--- a/Rheology/tests/DirectorSuite.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,355 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the DirectorSuite
-**
-** $Id: testDirector.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 <Underworld/Underworld.h>
-#include "DirectorSuite.h"
-
-#define TOLERANCE 1e-10
-#define RANDOM_DIRECTOR_ERROR 1.0
-#define CURR_MODULE_NAME "DirectorSuite"
-
-typedef struct {
-} DirectorSuiteData;
-
-double dt( UnderworldContext* context ) { return 0.05; }
-
-void _Director_Intermediate_Replace( void* director, Index lParticle_I ) {}
-
-void test( UnderworldContext* context ) {
-	Director*			director = (Director*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"director" );
-	Particle_Index		lParticle_I;
-	GlobalParticle*	particle;
-	double				time = context->currentTime + context->dt;
-	Swarm*				swarm	= (Swarm* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialSwarm" );
-	XYZ					normal;
-	double				error = 0.0;
-   double				angle = 0.5 * M_PI - atan(1.0/(2.0*time) );
-   double				angleDirector;
-	double				gError;
-	int					particleGlobalCount;
-   int ierr;
-
-	for ( lParticle_I = 0 ; lParticle_I < swarm->particleLocalCount ; lParticle_I++ ) {
-		particle = (GlobalParticle* )Swarm_ParticleAt( swarm, lParticle_I );
-		SwarmVariable_ValueAt( director->directorSwarmVariable, lParticle_I, normal );
-      angleDirector = atan(-normal[1]/normal[0]);
-		error += fabs( angleDirector - angle );
-	}
-	ierr = MPI_Allreduce( &error, &gError, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
-	ierr = MPI_Allreduce( &swarm->particleLocalCount, &particleGlobalCount, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
-
-	//error /= (double) swarm->particleLocalCount;
-	//pcu_check_true( error < TOLERANCE );
-	gError /= particleGlobalCount;
-	pcu_check_true( gError < TOLERANCE );
-}
-
-void testRandom( UnderworldContext* context ) {
-	AlignmentSwarmVariable* alignment = (AlignmentSwarmVariable*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"alignment"  );
-	Director*               director;
-	Particle_Index          lParticle_I;
-	GlobalParticle*         particle;
-	Swarm*                  swarm;
-	XYZ                     normal;
-	int                     ii;
-	double                  dotProduct;
-	double                  angleBetween;
-	double                  circleAngle;
-	int                     circleAngleCounts[36] 	= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
-	Bool                    circleErrorFlag = False;
-	int                     circleAngleSum;
-	double                  circleAngleAverage;
-	double                  circleAngleStdDev;
-	int                     circleAngleLowerBound;
-	int                     circleAngleUpperBound;
-	double						gCircleAngleAverage;
-	int                     gCircleAngleCounts[36] 	= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
-   int ierr;
-
-	swarm = alignment->swarm;
-	director = alignment->director;
-
-	for ( lParticle_I = 0 ; lParticle_I < swarm->particleLocalCount ; lParticle_I++ ) {
-		particle = (GlobalParticle*)Swarm_ParticleAt( swarm, lParticle_I );
-		SwarmVariable_ValueAt( director->directorSwarmVariable, lParticle_I, normal );
-		/* Calculate dot product between normal and (0,1), then get an angle */
-
-		dotProduct = normal[0] * 0 + normal[1] * 1;
-
-		angleBetween = acos( dotProduct ) * 180 / M_PI; 
-		if ( normal[0] > 0 ) {
-			circleAngle = angleBetween;
-		}
-		else {
-			circleAngle = 360 - angleBetween;
-		}
-		circleAngleCounts[ (int)(circleAngle+0.5) / 10 ] += 1;
-	}
-	ierr = MPI_Allreduce( circleAngleCounts, gCircleAngleCounts, 36, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
-
-	circleAngleAverage = (double)swarm->particleLocalCount / 36;
-	ierr = MPI_Allreduce( &circleAngleAverage, &gCircleAngleAverage, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
-
-	/*NB. This definition is determined based on a set no. of particlesPerCell. Currently this value is = 20 */
-	#define TheoreticalStandardDeviation 13.64
-	circleAngleLowerBound = (int)(floor(/*circleAngleAverage*/gCircleAngleAverage - 3*TheoreticalStandardDeviation));
-	if (circleAngleLowerBound < 0 ) {
-		circleAngleLowerBound = 0;
-	}
-	circleAngleUpperBound = (int)(floor(/*circleAngleAverage*/gCircleAngleAverage + 3*TheoreticalStandardDeviation));
-	
-        circleAngleSum = 0;
-	for ( ii =0; ii < 36; ii++ ) {	
-		if (( gCircleAngleCounts[ii] < circleAngleLowerBound )|| (gCircleAngleCounts[ii] > circleAngleUpperBound)) {
-			circleErrorFlag = True;
-		}
-		//circleAngleSum = ((circleAngleAverage - circleAngleCounts[ii]) * 
-		//				(circleAngleAverage - circleAngleCounts[ii])) + circleAngleSum;
-		circleAngleSum = ((gCircleAngleAverage - gCircleAngleCounts[ii]) * 
-						(gCircleAngleAverage - gCircleAngleCounts[ii])) + circleAngleSum;
-	}
-	/* Calculate standard deviation */
-	circleAngleStdDev = sqrt(circleAngleSum / (36-1));
-
-	pcu_check_true( fabs( circleAngleStdDev - TheoreticalStandardDeviation ) < RANDOM_DIRECTOR_ERROR );
-	pcu_check_true( !circleErrorFlag );	
-}
-
-#define DIR_TEST_NUM_MAT 3
-#define DIR_X_AXIS 0
-#define DIR_Y_AXIS 1
-#define DIR_Z_AXIS 2
-#define ANGLE_ERROR 1e-7
-
-void testPerMaterial( UnderworldContext* context ) {
-	AlignmentSwarmVariable* alignment              = (AlignmentSwarmVariable*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"alignment" );
-	Materials_Register*     materials_Register     = context->materials_Register;
-	Director*               director;
-	Particle_Index          lParticle_I;
-	Swarm*                  swarm;
-	XYZ                     testVector;
-	Material_Index          materialsCount;
-	int                     material_I;
-	XYZ*                    matDirectionVectors;
-	double                  angle;
-	Bool			angleFailure		= False;
-	
-	swarm = alignment->swarm;
-	director = alignment->director;
-	materialsCount = Materials_Register_GetCount( materials_Register );
-	
-	/*  construct test for testDirectorPerMaterial.xml  */
-	/* assume a direction for each material and check that */
-	/* each particle has the same direction for it's material type. */
-	/* and that it's equal to the default value for each material. */
-	/* get materials and their initial directions */
-	
-	/* check that there are at least 3 materials */
-	/* check that the initialDirections are == certain defaults */
-	matDirectionVectors = Memory_Alloc_Array(XYZ, DIR_TEST_NUM_MAT, "materialDirectionVectors");
-
-	/* Define vectors */
-	matDirectionVectors[0][DIR_X_AXIS] = 1.0; matDirectionVectors[0][DIR_Y_AXIS] = 0.0; matDirectionVectors[0][DIR_Z_AXIS] = 0.0;
-	matDirectionVectors[1][DIR_X_AXIS] = 0.0; matDirectionVectors[1][DIR_Y_AXIS] = 1.0; matDirectionVectors[1][DIR_Z_AXIS] = 0.0;
-	matDirectionVectors[2][DIR_X_AXIS] = 1.0; matDirectionVectors[2][DIR_Y_AXIS] = 1.0; matDirectionVectors[2][DIR_Z_AXIS] = 0.0;
-	
-	for ( lParticle_I = 0 ; lParticle_I < swarm->particleLocalCount ; lParticle_I++ ) {
-		/* get particle's material type */
-		material_I = MaterialPointsSwarm_GetMaterialIndexAt( swarm, lParticle_I );
-
-		/* get particle's initialDirection */
-		SwarmVariable_ValueAt( director->directorSwarmVariable, lParticle_I, testVector );
-		/* check that angle is within error bar of correct value */
-		angle = StGermain_AngleBetweenVectors(matDirectionVectors[material_I],testVector, swarm->dim);
-	
-		if( fabs(angle) > ANGLE_ERROR )
-			angleFailure = True;
-	}
-
-	pcu_check_true( !angleFailure );
-}
-
-void testPerMaterial2( UnderworldContext* context ) {
-	AlignmentSwarmVariable* alignment              = (AlignmentSwarmVariable*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"alignment" );
-	Materials_Register*     materials_Register     = context->materials_Register;
-	Director*               director;
-	Particle_Index          lParticle_I;
-	Swarm*                  swarm;
-	XYZ                     testVector;
-	Material_Index          materialsCount;
-	int                     material_I;
-	XYZ*                    matDirectionVectors;
-	double                  angle;
-	Bool			angleFailure		= False;
-	
-	swarm = alignment->swarm;
-	director = alignment->director;
-	materialsCount = Materials_Register_GetCount( materials_Register );
-	
-	matDirectionVectors = Memory_Alloc_Array(XYZ, DIR_TEST_NUM_MAT, "materialDirectionVectors");
-
-	/* Define vectors */
-	matDirectionVectors[0][DIR_X_AXIS] = 1.0; matDirectionVectors[0][DIR_Y_AXIS] = 0.0; matDirectionVectors[0][DIR_Z_AXIS] = 0.0;
-	matDirectionVectors[1][DIR_X_AXIS] = 0.0; matDirectionVectors[1][DIR_Y_AXIS] = 1.0; matDirectionVectors[1][DIR_Z_AXIS] = 0.0;
-	matDirectionVectors[2][DIR_X_AXIS] = 1.0; matDirectionVectors[2][DIR_Y_AXIS] = 1.0; matDirectionVectors[2][DIR_Z_AXIS] = 0.0;
-	/* normalise the vectors */
-	matDirectionVectors[2][DIR_X_AXIS] /= pow( 2.0, 0.5 );
-	matDirectionVectors[2][DIR_Y_AXIS] /= pow( 2.0, 0.5 );
-	
-	for ( lParticle_I = 0 ; lParticle_I < swarm->particleLocalCount ; lParticle_I++ ) {
-		/* get particle's material type */
-		material_I = MaterialPointsSwarm_GetMaterialIndexAt( swarm, lParticle_I );
-
-		/* get particle's initialDirection */
-		SwarmVariable_ValueAt( director->directorSwarmVariable, lParticle_I, testVector );
-		/* check that angle is within error bar of correct value */
-		angle = StGermain_AngleBetweenVectors(matDirectionVectors[material_I],testVector, swarm->dim);
-	
-		/* the '1' material has a random normal vector, so the angle between this and the test vector should be non-zero */
-		if( material_I == 1 && fabs(angle) < ANGLE_ERROR )
-			angleFailure = True;
-
-		if( material_I != 1 && fabs(angle) > ANGLE_ERROR )
-			angleFailure = True;
-	}
-
-	pcu_check_true( !angleFailure );
-}
-
-void DirectorSuite_Setup( DirectorSuiteData* data ) {
-	Journal_Enable_AllTypedStream( False );
-}
-
-void DirectorSuite_Teardown( DirectorSuiteData* data ) {
-	Journal_Enable_AllTypedStream( True );
-}
-
-void DirectorSuite_Test( DirectorSuiteData* data ) {
-	UnderworldContext*		context;
-	Stg_ComponentFactory*	cf;
-	char							xml_input[PCU_PATH_MAX];
-   Director*					director;
-   /* this test checks that the director will eventually spin to point in the direction of maximum shear.
-      initially the director is set to point 90 degrees to this direction, so that the director routines should result in it 
-      spinning 90 degrees eventually.   the test checks how the angle evolves in time against the analytic result, where we have disabled 
-      the intermediate re-normalisation of the director vectors */
-	pcu_filename_input( "testDirector.xml", xml_input );
-	cf = stgMainInitFromXML( xml_input, MPI_COMM_WORLD, NULL );
-	context = (UnderworldContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context"  );
-	Stream_Enable( context->info, False );
-	Stream_Enable( context->verbose, False );
-	Stream_Enable( context->debug, False );
-
-	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, test );
-	EP_AppendClassHook( Context_GetEntryPoint( context, FiniteElementContext_EP_CalcDt ), dt, context );
-	stgMainBuildAndInitialise( cf );
-	director = (Director*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"director"  );
-	/* we disable the intermediate director step, which normalises the director.  this is done so that we can have an analytic solution, but a more inclusive test 
-	  would be a good idea */
-	director->_intermediate = _Director_Intermediate_Replace;
-	stgMainLoop( cf );
-	stgMainDestroy( cf );
-}
-
-void DirectorSuite_TestRandom( DirectorSuiteData* data ) {
-	UnderworldContext*		context;
-	Stg_ComponentFactory*	cf;
-	char							xml_input[PCU_PATH_MAX];
-
-	pcu_filename_input( "testDirectorRandom.xml", xml_input );
-	cf = stgMainInitFromXML( xml_input, MPI_COMM_WORLD, NULL );
-	context = (UnderworldContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context"  );
-	Stream_Enable( context->info, False );
-	Stream_Enable( context->verbose, False );
-	Stream_Enable( context->debug, False );
-	
-	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, testRandom );
-	stgMainBuildAndInitialise( cf );
-	stgMainLoop( cf );
-	stgMainDestroy( cf );
-}
-
-void DirectorSuite_TestPerMaterial( DirectorSuiteData* data ) {
-	UnderworldContext*		context;
-	Stg_ComponentFactory*	cf;
-	char							xml_input[PCU_PATH_MAX];
-
-	pcu_filename_input( "testDirectorPerMaterial.xml", xml_input );
-	cf = stgMainInitFromXML( xml_input, MPI_COMM_WORLD, NULL );
-	context = (UnderworldContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context"  );
-	Stream_Enable( context->info, False );
-	Stream_Enable( context->verbose, False );
-	Stream_Enable( context->debug, False );
-
-	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, testPerMaterial );
-	stgMainBuildAndInitialise( cf );
-	stgMainLoop( cf );
-	stgMainDestroy( cf );
-}
-
-void DirectorSuite_TestPerMaterial2( DirectorSuiteData* data ) {
-	UnderworldContext*		context;
-	Stg_ComponentFactory*	cf;
-	char							xml_input[PCU_PATH_MAX];
-
-	pcu_filename_input( "testDirectorPerMaterial2.xml", xml_input );
-	cf = stgMainInitFromXML( xml_input, MPI_COMM_WORLD, NULL );
-	context = (UnderworldContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context"  );
-	Stream_Enable( context->info, False );
-	Stream_Enable( context->verbose, False );
-	Stream_Enable( context->debug, False );
-
-	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, testPerMaterial2 );
-	stgMainBuildAndInitialise( cf );
-	stgMainLoop( cf );
-	stgMainDestroy( cf );
-}
-
-void DirectorSuite( pcu_suite_t* suite ) {
-   pcu_suite_setData( suite, DirectorSuiteData );
-   pcu_suite_setFixtures( suite, DirectorSuite_Setup, DirectorSuite_Teardown );
-   pcu_suite_addTest( suite, DirectorSuite_Test ); /* parallel bug */
-   pcu_suite_addTest( suite, DirectorSuite_TestRandom ); /* parallel bug */
-   pcu_suite_addTest( suite, DirectorSuite_TestPerMaterial );
-   pcu_suite_addTest( suite, DirectorSuite_TestPerMaterial2 );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/tests/DirectorSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/tests/DirectorSuite.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,355 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the DirectorSuite
+**
+** $Id: testDirector.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 <Underworld/Underworld.h>
+#include "DirectorSuite.h"
+
+#define TOLERANCE 1e-10
+#define RANDOM_DIRECTOR_ERROR 1.0
+#define CURR_MODULE_NAME "DirectorSuite"
+
+typedef struct {
+} DirectorSuiteData;
+
+double dt( UnderworldContext* context ) { return 0.05; }
+
+void _Director_Intermediate_Replace( void* director, Index lParticle_I ) {}
+
+void test( UnderworldContext* context ) {
+	Director*			director = (Director*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"director" );
+	Particle_Index		lParticle_I;
+	GlobalParticle*	particle;
+	double				time = context->currentTime + context->dt;
+	Swarm*				swarm	= (Swarm* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialSwarm" );
+	XYZ					normal;
+	double				error = 0.0;
+   double				angle = 0.5 * M_PI - atan(1.0/(2.0*time) );
+   double				angleDirector;
+	double				gError;
+	int					particleGlobalCount;
+   int ierr;
+
+	for ( lParticle_I = 0 ; lParticle_I < swarm->particleLocalCount ; lParticle_I++ ) {
+		particle = (GlobalParticle* )Swarm_ParticleAt( swarm, lParticle_I );
+		SwarmVariable_ValueAt( director->directorSwarmVariable, lParticle_I, normal );
+      angleDirector = atan(-normal[1]/normal[0]);
+		error += fabs( angleDirector - angle );
+	}
+	ierr = MPI_Allreduce( &error, &gError, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
+	ierr = MPI_Allreduce( &swarm->particleLocalCount, &particleGlobalCount, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
+
+	//error /= (double) swarm->particleLocalCount;
+	//pcu_check_true( error < TOLERANCE );
+	gError /= particleGlobalCount;
+	pcu_check_true( gError < TOLERANCE );
+}
+
+void testRandom( UnderworldContext* context ) {
+	AlignmentSwarmVariable* alignment = (AlignmentSwarmVariable*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"alignment"  );
+	Director*               director;
+	Particle_Index          lParticle_I;
+	GlobalParticle*         particle;
+	Swarm*                  swarm;
+	XYZ                     normal;
+	int                     ii;
+	double                  dotProduct;
+	double                  angleBetween;
+	double                  circleAngle;
+	int                     circleAngleCounts[36] 	= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+	Bool                    circleErrorFlag = False;
+	int                     circleAngleSum;
+	double                  circleAngleAverage;
+	double                  circleAngleStdDev;
+	int                     circleAngleLowerBound;
+	int                     circleAngleUpperBound;
+	double						gCircleAngleAverage;
+	int                     gCircleAngleCounts[36] 	= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+   int ierr;
+
+	swarm = alignment->swarm;
+	director = alignment->director;
+
+	for ( lParticle_I = 0 ; lParticle_I < swarm->particleLocalCount ; lParticle_I++ ) {
+		particle = (GlobalParticle*)Swarm_ParticleAt( swarm, lParticle_I );
+		SwarmVariable_ValueAt( director->directorSwarmVariable, lParticle_I, normal );
+		/* Calculate dot product between normal and (0,1), then get an angle */
+
+		dotProduct = normal[0] * 0 + normal[1] * 1;
+
+		angleBetween = acos( dotProduct ) * 180 / M_PI; 
+		if ( normal[0] > 0 ) {
+			circleAngle = angleBetween;
+		}
+		else {
+			circleAngle = 360 - angleBetween;
+		}
+		circleAngleCounts[ (int)(circleAngle+0.5) / 10 ] += 1;
+	}
+	ierr = MPI_Allreduce( circleAngleCounts, gCircleAngleCounts, 36, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
+
+	circleAngleAverage = (double)swarm->particleLocalCount / 36;
+	ierr = MPI_Allreduce( &circleAngleAverage, &gCircleAngleAverage, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
+
+	/*NB. This definition is determined based on a set no. of particlesPerCell. Currently this value is = 20 */
+	#define TheoreticalStandardDeviation 13.64
+	circleAngleLowerBound = (int)(floor(/*circleAngleAverage*/gCircleAngleAverage - 3*TheoreticalStandardDeviation));
+	if (circleAngleLowerBound < 0 ) {
+		circleAngleLowerBound = 0;
+	}
+	circleAngleUpperBound = (int)(floor(/*circleAngleAverage*/gCircleAngleAverage + 3*TheoreticalStandardDeviation));
+	
+        circleAngleSum = 0;
+	for ( ii =0; ii < 36; ii++ ) {	
+		if (( gCircleAngleCounts[ii] < circleAngleLowerBound )|| (gCircleAngleCounts[ii] > circleAngleUpperBound)) {
+			circleErrorFlag = True;
+		}
+		//circleAngleSum = ((circleAngleAverage - circleAngleCounts[ii]) * 
+		//				(circleAngleAverage - circleAngleCounts[ii])) + circleAngleSum;
+		circleAngleSum = ((gCircleAngleAverage - gCircleAngleCounts[ii]) * 
+						(gCircleAngleAverage - gCircleAngleCounts[ii])) + circleAngleSum;
+	}
+	/* Calculate standard deviation */
+	circleAngleStdDev = sqrt(circleAngleSum / (36-1));
+
+	pcu_check_true( fabs( circleAngleStdDev - TheoreticalStandardDeviation ) < RANDOM_DIRECTOR_ERROR );
+	pcu_check_true( !circleErrorFlag );	
+}
+
+#define DIR_TEST_NUM_MAT 3
+#define DIR_X_AXIS 0
+#define DIR_Y_AXIS 1
+#define DIR_Z_AXIS 2
+#define ANGLE_ERROR 1e-7
+
+void testPerMaterial( UnderworldContext* context ) {
+	AlignmentSwarmVariable* alignment              = (AlignmentSwarmVariable*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"alignment" );
+	Materials_Register*     materials_Register     = context->materials_Register;
+	Director*               director;
+	Particle_Index          lParticle_I;
+	Swarm*                  swarm;
+	XYZ                     testVector;
+	Material_Index          materialsCount;
+	int                     material_I;
+	XYZ*                    matDirectionVectors;
+	double                  angle;
+	Bool			angleFailure		= False;
+	
+	swarm = alignment->swarm;
+	director = alignment->director;
+	materialsCount = Materials_Register_GetCount( materials_Register );
+	
+	/*  construct test for testDirectorPerMaterial.xml  */
+	/* assume a direction for each material and check that */
+	/* each particle has the same direction for it's material type. */
+	/* and that it's equal to the default value for each material. */
+	/* get materials and their initial directions */
+	
+	/* check that there are at least 3 materials */
+	/* check that the initialDirections are == certain defaults */
+	matDirectionVectors = Memory_Alloc_Array(XYZ, DIR_TEST_NUM_MAT, "materialDirectionVectors");
+
+	/* Define vectors */
+	matDirectionVectors[0][DIR_X_AXIS] = 1.0; matDirectionVectors[0][DIR_Y_AXIS] = 0.0; matDirectionVectors[0][DIR_Z_AXIS] = 0.0;
+	matDirectionVectors[1][DIR_X_AXIS] = 0.0; matDirectionVectors[1][DIR_Y_AXIS] = 1.0; matDirectionVectors[1][DIR_Z_AXIS] = 0.0;
+	matDirectionVectors[2][DIR_X_AXIS] = 1.0; matDirectionVectors[2][DIR_Y_AXIS] = 1.0; matDirectionVectors[2][DIR_Z_AXIS] = 0.0;
+	
+	for ( lParticle_I = 0 ; lParticle_I < swarm->particleLocalCount ; lParticle_I++ ) {
+		/* get particle's material type */
+		material_I = MaterialPointsSwarm_GetMaterialIndexAt( swarm, lParticle_I );
+
+		/* get particle's initialDirection */
+		SwarmVariable_ValueAt( director->directorSwarmVariable, lParticle_I, testVector );
+		/* check that angle is within error bar of correct value */
+		angle = StGermain_AngleBetweenVectors(matDirectionVectors[material_I],testVector, swarm->dim);
+	
+		if( fabs(angle) > ANGLE_ERROR )
+			angleFailure = True;
+	}
+
+	pcu_check_true( !angleFailure );
+}
+
+void testPerMaterial2( UnderworldContext* context ) {
+	AlignmentSwarmVariable* alignment              = (AlignmentSwarmVariable*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"alignment" );
+	Materials_Register*     materials_Register     = context->materials_Register;
+	Director*               director;
+	Particle_Index          lParticle_I;
+	Swarm*                  swarm;
+	XYZ                     testVector;
+	Material_Index          materialsCount;
+	int                     material_I;
+	XYZ*                    matDirectionVectors;
+	double                  angle;
+	Bool			angleFailure		= False;
+	
+	swarm = alignment->swarm;
+	director = alignment->director;
+	materialsCount = Materials_Register_GetCount( materials_Register );
+	
+	matDirectionVectors = Memory_Alloc_Array(XYZ, DIR_TEST_NUM_MAT, "materialDirectionVectors");
+
+	/* Define vectors */
+	matDirectionVectors[0][DIR_X_AXIS] = 1.0; matDirectionVectors[0][DIR_Y_AXIS] = 0.0; matDirectionVectors[0][DIR_Z_AXIS] = 0.0;
+	matDirectionVectors[1][DIR_X_AXIS] = 0.0; matDirectionVectors[1][DIR_Y_AXIS] = 1.0; matDirectionVectors[1][DIR_Z_AXIS] = 0.0;
+	matDirectionVectors[2][DIR_X_AXIS] = 1.0; matDirectionVectors[2][DIR_Y_AXIS] = 1.0; matDirectionVectors[2][DIR_Z_AXIS] = 0.0;
+	/* normalise the vectors */
+	matDirectionVectors[2][DIR_X_AXIS] /= pow( 2.0, 0.5 );
+	matDirectionVectors[2][DIR_Y_AXIS] /= pow( 2.0, 0.5 );
+	
+	for ( lParticle_I = 0 ; lParticle_I < swarm->particleLocalCount ; lParticle_I++ ) {
+		/* get particle's material type */
+		material_I = MaterialPointsSwarm_GetMaterialIndexAt( swarm, lParticle_I );
+
+		/* get particle's initialDirection */
+		SwarmVariable_ValueAt( director->directorSwarmVariable, lParticle_I, testVector );
+		/* check that angle is within error bar of correct value */
+		angle = StGermain_AngleBetweenVectors(matDirectionVectors[material_I],testVector, swarm->dim);
+	
+		/* the '1' material has a random normal vector, so the angle between this and the test vector should be non-zero */
+		if( material_I == 1 && fabs(angle) < ANGLE_ERROR )
+			angleFailure = True;
+
+		if( material_I != 1 && fabs(angle) > ANGLE_ERROR )
+			angleFailure = True;
+	}
+
+	pcu_check_true( !angleFailure );
+}
+
+void DirectorSuite_Setup( DirectorSuiteData* data ) {
+	Journal_Enable_AllTypedStream( False );
+}
+
+void DirectorSuite_Teardown( DirectorSuiteData* data ) {
+	Journal_Enable_AllTypedStream( True );
+}
+
+void DirectorSuite_Test( DirectorSuiteData* data ) {
+	UnderworldContext*		context;
+	Stg_ComponentFactory*	cf;
+	char							xml_input[PCU_PATH_MAX];
+   Director*					director;
+   /* this test checks that the director will eventually spin to point in the direction of maximum shear.
+      initially the director is set to point 90 degrees to this direction, so that the director routines should result in it 
+      spinning 90 degrees eventually.   the test checks how the angle evolves in time against the analytic result, where we have disabled 
+      the intermediate re-normalisation of the director vectors */
+	pcu_filename_input( "testDirector.xml", xml_input );
+	cf = stgMainInitFromXML( xml_input, MPI_COMM_WORLD, NULL );
+	context = (UnderworldContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context"  );
+	Stream_Enable( context->info, False );
+	Stream_Enable( context->verbose, False );
+	Stream_Enable( context->debug, False );
+
+	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, test );
+	EP_AppendClassHook( Context_GetEntryPoint( context, FiniteElementContext_EP_CalcDt ), dt, context );
+	stgMainBuildAndInitialise( cf );
+	director = (Director*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"director"  );
+	/* we disable the intermediate director step, which normalises the director.  this is done so that we can have an analytic solution, but a more inclusive test 
+	  would be a good idea */
+	director->_intermediate = _Director_Intermediate_Replace;
+	stgMainLoop( cf );
+	stgMainDestroy( cf );
+}
+
+void DirectorSuite_TestRandom( DirectorSuiteData* data ) {
+	UnderworldContext*		context;
+	Stg_ComponentFactory*	cf;
+	char							xml_input[PCU_PATH_MAX];
+
+	pcu_filename_input( "testDirectorRandom.xml", xml_input );
+	cf = stgMainInitFromXML( xml_input, MPI_COMM_WORLD, NULL );
+	context = (UnderworldContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context"  );
+	Stream_Enable( context->info, False );
+	Stream_Enable( context->verbose, False );
+	Stream_Enable( context->debug, False );
+	
+	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, testRandom );
+	stgMainBuildAndInitialise( cf );
+	stgMainLoop( cf );
+	stgMainDestroy( cf );
+}
+
+void DirectorSuite_TestPerMaterial( DirectorSuiteData* data ) {
+	UnderworldContext*		context;
+	Stg_ComponentFactory*	cf;
+	char							xml_input[PCU_PATH_MAX];
+
+	pcu_filename_input( "testDirectorPerMaterial.xml", xml_input );
+	cf = stgMainInitFromXML( xml_input, MPI_COMM_WORLD, NULL );
+	context = (UnderworldContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context"  );
+	Stream_Enable( context->info, False );
+	Stream_Enable( context->verbose, False );
+	Stream_Enable( context->debug, False );
+
+	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, testPerMaterial );
+	stgMainBuildAndInitialise( cf );
+	stgMainLoop( cf );
+	stgMainDestroy( cf );
+}
+
+void DirectorSuite_TestPerMaterial2( DirectorSuiteData* data ) {
+	UnderworldContext*		context;
+	Stg_ComponentFactory*	cf;
+	char							xml_input[PCU_PATH_MAX];
+
+	pcu_filename_input( "testDirectorPerMaterial2.xml", xml_input );
+	cf = stgMainInitFromXML( xml_input, MPI_COMM_WORLD, NULL );
+	context = (UnderworldContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context"  );
+	Stream_Enable( context->info, False );
+	Stream_Enable( context->verbose, False );
+	Stream_Enable( context->debug, False );
+
+	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, testPerMaterial2 );
+	stgMainBuildAndInitialise( cf );
+	stgMainLoop( cf );
+	stgMainDestroy( cf );
+}
+
+void DirectorSuite( pcu_suite_t* suite ) {
+   pcu_suite_setData( suite, DirectorSuiteData );
+   pcu_suite_setFixtures( suite, DirectorSuite_Setup, DirectorSuite_Teardown );
+   pcu_suite_addTest( suite, DirectorSuite_Test ); /* parallel bug */
+   pcu_suite_addTest( suite, DirectorSuite_TestRandom ); /* parallel bug */
+   pcu_suite_addTest( suite, DirectorSuite_TestPerMaterial );
+   pcu_suite_addTest( suite, DirectorSuite_TestPerMaterial2 );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/tests/LateralViscosityAnalytic/LateralViscosityAnalytic.c
--- a/Rheology/tests/LateralViscosityAnalytic/LateralViscosityAnalytic.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,460 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: LateralViscosityAnalytic.c 628 2007-11-14 03:59:03Z RobertTurnbull $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Rheology/Rheology.h>
-
-#include <assert.h>
-
-#define SMALL 1.0e-5
-#define IS_ODD(A)   ( (A) % 2 == 1 )
-
-const Type LateralViscosityAnalytic_Type = "LateralViscosityAnalytic";
-
-typedef struct {
-	__AnalyticSolution
-	double                  beta;
-	int                     wavenumberX;
-	int                     wavenumberY;
-	FeVariable*		velocityField;
-} LateralViscosityAnalytic;
-
-/** Analytic Solution taken from 
- *  Shijie Zhong. Analytic solutions for Stokes' flow with lateral variations in viscosity. Geophys. J. Int., 124:18-28, 1996.
- *  All equations refer to this paper */
-
-void LateralViscosityAnalytic_TemperatureIC( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
-	DomainContext*  context            = (DomainContext*)_context;
-	FeVariable*             temperatureField   = (FeVariable*) FieldVariable_Register_GetByName( context->fieldVariable_Register, "TemperatureField" );
-	FeMesh* 		mesh               = temperatureField->feMesh;
-	double*                 result             = (double*) _result;
-	Dictionary*             dictionary         = context->dictionary;
-	double*                 coord;
-	double                  x; 
-	double                  y;
-	double                  kx;
-	double                  ky;
-	int                     wavenumberX;
-	int                     wavenumberY;
-	Coord			min, max;
-	double                  L;
-	
-	/* Find coordinate of node */
-	coord = Mesh_GetVertex( mesh, node_lI );
-
-	/* Make sure that the box has right dimensions */
-	Mesh_GetGlobalCoordRange( mesh, min, max );
-	assert( ( max[ J_AXIS ] - min[ J_AXIS ] - 1.0 ) < SMALL );
-	L = max[ I_AXIS ] - min[ I_AXIS ];
-
-	x = coord[ I_AXIS ] - min[ I_AXIS ];
-	y = coord[ J_AXIS ] - min[ J_AXIS ];
-
-	wavenumberX = Dictionary_GetInt_WithDefault( dictionary, (Dictionary_Entry_Key)"wavenumberX", 1  );
-	wavenumberY = Dictionary_GetInt_WithDefault( dictionary, (Dictionary_Entry_Key)"wavenumberY", 1 );
-
-	kx = wavenumberX * M_PI/ L;
-	ky = wavenumberY * M_PI;
-
-	*result = sin( ky * y ) * cos( kx * x  );
-}
-
-void _LateralViscosityAnalytic_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
-	LateralViscosityAnalytic*         self               = (LateralViscosityAnalytic*)analyticSolution;
-	FeMesh*			mesh = analyticFeVariable->feMesh;
-	Coord			min, max;
-	Cmplx                   N                  = {0,0};
-	double                  chi1;
-	double                  chi2;
-	Cmplx                   sumX;
-	Cmplx                   sumY;
-	Cmplx                   m[5];                       /* CRAPPY FORTRAN ARRAYS */
-	Cmplx                   mSquared[5];
-	Cmplx                   mExp[5];
-	Cmplx                   N1;
-	Cmplx                   N2;
-	Cmplx                   N3;
-	Cmplx                   N4;
-	double                  beta2_4kn;
-	Cmplx                   lambda1;
-	Cmplx                   lambda2;
-	Cmplx                   n1;
-	Cmplx                   n2;
-	Cmplx                   n1_minus_beta;
-	Cmplx                   n2_minus_beta;
-	Cmplx                   M;
-	Cmplx                   oneOnM;
-	Cmplx                   tmp;
-	double                  beta;
-	double                  kn;
-	Index                   index;
-	Index                   i;
-	Index                   j;
-	Index                   h;
-	Index                   k;
-	double                  L;
-	double                  kx;
-	double                  ky;
-	Cmplx                   A1;
-	Cmplx                   A2;
-	Cmplx                   A3;
-	Cmplx                   A4;
-	Cmplx                   exp_n1x;
-	Cmplx                   exp_n2x;
-	Cmplx                   a1End;
-	Cmplx                   a2End;
-	double                  x;
-	double                  y;
-	double                  factorA;
-	double                  factorB;
-	int                     wavenumberX;
-	int                     wavenumberY;
-	double                  sqRootValue;
-
-	Mesh_GetGlobalCoordRange( mesh, min, max );
-	x = coord[ I_AXIS ] - min[ I_AXIS ];
-	y = coord[ J_AXIS ] - min[ J_AXIS ];
-
-	beta = self->beta;
-	wavenumberX = self->wavenumberX;
-	wavenumberY = self->wavenumberY;
-	
-	L    = max[ I_AXIS ] - min[ I_AXIS ];
-	kx   = wavenumberX * M_PI/ L;
-	ky   = wavenumberY * M_PI;
-	kn   = ky; 
-
-	beta2_4kn = beta * beta + 4.0 * kn * kn;
-	sqRootValue = beta2_4kn * beta2_4kn + 16.0 * beta * beta * kn * kn;
-	sqRootValue = sqrt( sqRootValue );
-	chi1 = sqrt( 0.5 * (  beta2_4kn + sqRootValue ) );
-	chi2 = sqrt( 0.5 * ( -beta2_4kn + sqRootValue ) );
-
-	n1[ REAL_PART ] = 0.5 * (beta + chi1);
-	n1[ IMAG_PART ] = 0.5 * (chi2);
-	
-	n2[ REAL_PART ] = 0.5 * (beta - chi1);
-	n2[ IMAG_PART ] = 0.5 * (-chi2);
-
-	Cmplx_Copy( n1, m[1] );
-	Cmplx_Conjugate( n1, m[2] );
-	Cmplx_Copy( n2, m[3] );
-	Cmplx_Conjugate( n2, m[4] );
-			
-	for ( index = 1 ; index <= 4 ; index++ ) {
-		Cmplx_Multiply( m[index], m[index], mSquared[index] );
-		Cmplx_RealMultiply( m[ index ], -L, tmp );
-		Cmplx_Exp( tmp, mExp[ index ] );
-	}
-
-	/* Calculate M - Equation A7 */
-	Cmplx_Subtract( m[2], m[1], oneOnM );
-	Cmplx_Subtract( m[3], m[1], tmp );
-	Cmplx_Multiply( oneOnM, tmp, oneOnM );
-	Cmplx_Subtract( m[4], m[1], tmp );
-	Cmplx_Multiply( oneOnM, tmp, oneOnM );
-	Cmplx_RealDivideByCmplx( oneOnM, 1.0, M );
-
-	/* Calculate N - Equation A8 */
-	for ( j = 1 ; j <= 3 ; j++ ) {
-		for ( i = j+1 ; i <= 4 ; i++ ) {
-			Cmplx product = {0,0};
-			
-			/* Get h */
-			for ( h = 1 ; h <= 4 ; h++ ) {
-				if ( h != i && h != j )
-					break; /* Found h */
-			}
-
-			/* Get k */
-			for ( k = h+1 ; k <= 4 ; k++ ) {
-				if ( k != i && k != j )
-					break; /* Found k */
-			}			
-
-			product[ REAL_PART ] = IS_ODD( i + j ) ? 1.0 : -1.0;
-			
-			Cmplx_Multiply( product, mExp[ i ], product );
-			Cmplx_Multiply( product, mExp[ j ], product );
-
-			Cmplx_Subtract( mSquared[ k ], mSquared[ h ], tmp );
-			Cmplx_Multiply( product, tmp, product );
-
-			Cmplx_Subtract( mSquared[ i ], mSquared[ j ], tmp );
-			Cmplx_Multiply( product, tmp, product );
-
-			Cmplx_Add( N, product, N );
-		}
-	}
-
-	/* Build N1 - Equation A9 */
-	Cmplx_Subtract( mSquared[4], mSquared[3], tmp );
-	Cmplx_Multiply( tmp, mSquared[2], tmp );
-	Cmplx_Multiply( tmp, mExp[2], N1 ); 
-
-	Cmplx_Subtract( mSquared[4], mSquared[2], tmp );
-	Cmplx_Multiply( tmp, mSquared[3], tmp );
-	Cmplx_Multiply( tmp, mExp[3], tmp );
-	Cmplx_Subtract( N1, tmp, N1 );
-	
-	Cmplx_Subtract( mSquared[3], mSquared[2], tmp );
-	Cmplx_Multiply( tmp, mSquared[4], tmp );
-	Cmplx_Multiply( tmp, mExp[4], tmp );
-	Cmplx_Add( N1, tmp, N1 );
-	
-	/* Build N2 - Equation A10 */
-	Cmplx_Subtract( mSquared[4], mSquared[2], tmp );
-	Cmplx_Multiply( tmp, mSquared[1], tmp );
-	Cmplx_Multiply( tmp, mExp[1], N2 );
-
-	Cmplx_Subtract( mSquared[4], mSquared[1], tmp );
-	Cmplx_Multiply( tmp, mSquared[2], tmp );
-	Cmplx_Multiply( tmp, mExp[2], tmp );
-	Cmplx_Subtract( N2, tmp, N2 );
-
-	Cmplx_Subtract( mSquared[2], mSquared[1], tmp );
-	Cmplx_Multiply( tmp, mSquared[4], tmp );
-	Cmplx_Multiply( tmp, mExp[4], tmp );
-	Cmplx_Add( N2, tmp, N2 );
-
-	/* Build N3 - Equation A11 */
-	Cmplx_Subtract( mSquared[3], mSquared[4], tmp );
-	Cmplx_Multiply( tmp, mExp[2], N3 );
-
-	Cmplx_Subtract( mSquared[4], mSquared[2], tmp );
-	Cmplx_Multiply( tmp, mExp[3], tmp );
-	Cmplx_Add( N3, tmp, N3 );
-
-	Cmplx_Subtract( mSquared[2], mSquared[3], tmp );
-	Cmplx_Multiply( tmp, mExp[4], tmp );
-	Cmplx_Add( N3, tmp, N3 );
-
-	/* Build N4 - Equation A12 */
-	Cmplx_Subtract( mSquared[2], mSquared[4], tmp );
-	Cmplx_Multiply( tmp, mExp[1], N4 );
-
-	Cmplx_Subtract( mSquared[4], mSquared[1], tmp );
-	Cmplx_Multiply( tmp, mExp[2], tmp );
-	Cmplx_Add( N4, tmp, N4 );
-
-	Cmplx_Subtract( mSquared[1], mSquared[2], tmp );
-	Cmplx_Multiply( tmp, mExp[4], tmp );
-	Cmplx_Add( N4, tmp, N4 );
-
-
-    /* Build lambda1 - Equation B8 */
-	Cmplx_AddReal( n1, - beta, n1_minus_beta );
-    Cmplx_RealMultiply( n1_minus_beta,L, tmp );
-	Cmplx_Exp( tmp, tmp );
-    Cmplx_RealMultiply(tmp, cos( kx * L ), tmp );
-	Cmplx_RealMinusCmplx( tmp, 1.0, tmp );
-    Cmplx_RealMultiply(tmp, -kx, tmp );
-	Cmplx_Multiply( M, tmp, lambda1 );
-	
-	Cmplx_Multiply( n1_minus_beta, n1_minus_beta, tmp );
-	Cmplx_AddReal( tmp, kx * kx, tmp );
-
-	Cmplx_Division( lambda1, tmp, lambda1 );
-	
-	/* Build lambda2 - Equation B9 */
-	Cmplx_AddReal( n2, - beta, n2_minus_beta );
-	Cmplx_RealMultiply( n2_minus_beta,L, tmp );
-	Cmplx_Exp( tmp, tmp );
-	Cmplx_RealMultiply(tmp, cos( kx * L ), tmp );
-	Cmplx_RealMinusCmplx( tmp, 1.0, tmp );
-	Cmplx_RealMultiply(tmp, kx, tmp );
-	Cmplx_Multiply( M, tmp, lambda2 );
-	
-	Cmplx_Multiply( n2_minus_beta, n2_minus_beta, tmp );
-	Cmplx_AddReal( tmp, kx * kx, tmp );
-
-	Cmplx_Division( lambda2, tmp, lambda2 );
-
-
-
-	/* Build A1 - Equation B4 */
-	Cmplx_Multiply( mExp[1], lambda1, tmp );
-	factorA = tmp[ REAL_PART ];
-	Cmplx_Multiply( mExp[3], lambda2, tmp );
-	factorA += tmp[ REAL_PART ];
-	Cmplx_Division( N1, N, tmp );
-	Cmplx_RealMultiply( tmp, 2.0 * factorA, A1 );
-
-	Cmplx_Multiply( mExp[1], lambda1, tmp );
-	Cmplx_Multiply( tmp, mSquared[1], tmp );
-	factorB = tmp[ REAL_PART ];
-	Cmplx_Multiply( mExp[3], lambda2, tmp );
-	Cmplx_Multiply( tmp, mSquared[3], tmp );
-	factorB += tmp[ REAL_PART ];
-	Cmplx_Division( N3, N, tmp );
-	Cmplx_RealMultiply( tmp, 2.0 * factorB, tmp );
-	Cmplx_Add( A1, tmp, A1 );
-
-	Cmplx_Multiply( n1_minus_beta, n1_minus_beta, a1End );
-	Cmplx_AddReal( a1End, kx*kx, a1End );
-	Cmplx_RealDivideByCmplx( a1End, kx, a1End );
-	Cmplx_Multiply( a1End, M, a1End );
-	Cmplx_Add( A1, a1End, A1 );
-
-	/* Build A2 - Equation B5 */
-	Cmplx_Division( N2, N, tmp );
-	Cmplx_RealMultiply( tmp, 2.0 * factorA, A2 );
-
-	Cmplx_Division( N4, N, tmp );
-	Cmplx_RealMultiply( tmp, 2.0 * factorB, tmp );
-	Cmplx_Add( A2, tmp, A2 );
-
-	Cmplx_Multiply( n2_minus_beta, n2_minus_beta, a2End );
-	Cmplx_AddReal( a2End, kx*kx, a2End );
-	Cmplx_RealDivideByCmplx( a2End, kx, a2End );
-	Cmplx_Multiply( a2End, M, a2End );
-	Cmplx_Subtract( A2, a2End, A2 );	
-
-	/* Build A3 - Equation B6 */
-	Cmplx_Subtract( a2End, a1End, A3 );
-
-	/* Build A4 - Equation B7 */
-	Cmplx_Multiply( n1_minus_beta, n1_minus_beta, tmp );
-	Cmplx_AddReal( tmp, kx*kx, tmp );
-	Cmplx_Division( n1_minus_beta, tmp, tmp );
-	Cmplx_Multiply( tmp, M, A4 );
-
-	Cmplx_Multiply( n2_minus_beta, n2_minus_beta, tmp );
-	Cmplx_AddReal( tmp, kx*kx, tmp );
-	Cmplx_Division( n2_minus_beta, tmp, tmp );
-	Cmplx_Multiply( tmp, M, tmp );
-	Cmplx_Subtract( A4, tmp, A4 );
-	
-	/*************************************** Get Velocities - Eqn B10 - B11 *****************************************/
-	
-	/* Get First Term in Sums */
-	Cmplx_RealMultiply( n1, -x, tmp );
-	Cmplx_Exp( tmp, exp_n1x );
-	Cmplx_Multiply( A1, exp_n1x, sumX );
-
-	Cmplx_Copy( sumX, sumY );
-	Cmplx_Multiply( sumY, n1, sumY );
-	Cmplx_RealMultiply( sumY, -1.0, sumY );
-
-	/* Add second term in sum */
-	Cmplx_RealMultiply( n2, -x, tmp );
-	Cmplx_Exp( tmp, exp_n2x );
-	Cmplx_Multiply( A2, exp_n2x, tmp );
-	Cmplx_Add( sumX, tmp, sumX );
-
-	Cmplx_Multiply( tmp, n2, tmp );
-	Cmplx_RealMultiply( tmp, -1.0, tmp );
-	Cmplx_Add( sumY, tmp, sumY );
-	
-	/* Add third term in sum */
-	sumX[ REAL_PART ] += (A3[ REAL_PART ] * cos( kx*x ) + A4[ REAL_PART ] * sin( kx * x ) ) * exp( -beta*x );
-	sumY[ REAL_PART ] += exp( -beta * x ) * (
-		(kx * A4[REAL_PART] - beta * A3[ REAL_PART ]) * cos( kx * x ) - 
-		(kx * A3[REAL_PART] + beta * A4[ REAL_PART ]) * sin( kx * x ) );
-
-	velocity[ I_AXIS ] = -2.0 * kx * ky * cos( ky * y ) * sumX[ REAL_PART ]; 
-	velocity[ J_AXIS ] = 2.0 * kx * sin( ky * y ) * sumY[ REAL_PART ]; 
-
-}
-
-void _LateralViscosityAnalytic_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
-	LateralViscosityAnalytic*         self           = (LateralViscosityAnalytic*)analyticSolution;
-	AbstractContext*        context;
-	ConditionFunction*      condFunc;
-	
-	/* Construct Parent */
-	_AnalyticSolution_AssignFromXML( self, cf, data );
-
-	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  ); 
-	
-	/* Add temperature initial condition */
-	condFunc = ConditionFunction_New( LateralViscosityAnalytic_TemperatureIC, (Name)"LateralViscosityAnalytic_TemperatureIC"  );
-	ConditionFunction_Register_Add( context->condFunc_Register, condFunc );
-	
-	/* Create Analytic Fields */
-	self->velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  ); 
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, self->velocityField, _LateralViscosityAnalytic_VelocityFunction );
-
-	self->beta = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"beta", 0.0  );
-	self->wavenumberX = Stg_ComponentFactory_GetRootDictInt( cf, "wavenumberX", 1 );
-	self->wavenumberY = Stg_ComponentFactory_GetRootDictInt( cf, "wavenumberY", 1 );
-}
-
-void _LateralViscosityAnalytic_Build( void* analyticSolution, void* data ) {
-	LateralViscosityAnalytic*         self = (LateralViscosityAnalytic*)analyticSolution;
-
-	_AnalyticSolution_Build( self, data );
-}
-
-
-void* _LateralViscosityAnalytic_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(LateralViscosityAnalytic);
-	Type                                                      type = LateralViscosityAnalytic_Type;
-	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
-	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
-	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _LateralViscosityAnalytic_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _LateralViscosityAnalytic_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _LateralViscosityAnalytic_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 Underworld_LateralViscosityAnalytic_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, LateralViscosityAnalytic_Type, (Name)"0", _LateralViscosityAnalytic_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/tests/LateralViscosityAnalytic/LateralViscosityAnalytic.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/tests/LateralViscosityAnalytic/LateralViscosityAnalytic.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,460 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: LateralViscosityAnalytic.c 628 2007-11-14 03:59:03Z RobertTurnbull $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Rheology/Rheology.h>
+
+#include <assert.h>
+
+#define SMALL 1.0e-5
+#define IS_ODD(A)   ( (A) % 2 == 1 )
+
+const Type LateralViscosityAnalytic_Type = "LateralViscosityAnalytic";
+
+typedef struct {
+	__AnalyticSolution
+	double                  beta;
+	int                     wavenumberX;
+	int                     wavenumberY;
+	FeVariable*		velocityField;
+} LateralViscosityAnalytic;
+
+/** Analytic Solution taken from 
+ *  Shijie Zhong. Analytic solutions for Stokes' flow with lateral variations in viscosity. Geophys. J. Int., 124:18-28, 1996.
+ *  All equations refer to this paper */
+
+void LateralViscosityAnalytic_TemperatureIC( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
+	DomainContext*  context            = (DomainContext*)_context;
+	FeVariable*             temperatureField   = (FeVariable*) FieldVariable_Register_GetByName( context->fieldVariable_Register, "TemperatureField" );
+	FeMesh* 		mesh               = temperatureField->feMesh;
+	double*                 result             = (double*) _result;
+	Dictionary*             dictionary         = context->dictionary;
+	double*                 coord;
+	double                  x; 
+	double                  y;
+	double                  kx;
+	double                  ky;
+	int                     wavenumberX;
+	int                     wavenumberY;
+	Coord			min, max;
+	double                  L;
+	
+	/* Find coordinate of node */
+	coord = Mesh_GetVertex( mesh, node_lI );
+
+	/* Make sure that the box has right dimensions */
+	Mesh_GetGlobalCoordRange( mesh, min, max );
+	assert( ( max[ J_AXIS ] - min[ J_AXIS ] - 1.0 ) < SMALL );
+	L = max[ I_AXIS ] - min[ I_AXIS ];
+
+	x = coord[ I_AXIS ] - min[ I_AXIS ];
+	y = coord[ J_AXIS ] - min[ J_AXIS ];
+
+	wavenumberX = Dictionary_GetInt_WithDefault( dictionary, (Dictionary_Entry_Key)"wavenumberX", 1  );
+	wavenumberY = Dictionary_GetInt_WithDefault( dictionary, (Dictionary_Entry_Key)"wavenumberY", 1 );
+
+	kx = wavenumberX * M_PI/ L;
+	ky = wavenumberY * M_PI;
+
+	*result = sin( ky * y ) * cos( kx * x  );
+}
+
+void _LateralViscosityAnalytic_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
+	LateralViscosityAnalytic*         self               = (LateralViscosityAnalytic*)analyticSolution;
+	FeMesh*			mesh = analyticFeVariable->feMesh;
+	Coord			min, max;
+	Cmplx                   N                  = {0,0};
+	double                  chi1;
+	double                  chi2;
+	Cmplx                   sumX;
+	Cmplx                   sumY;
+	Cmplx                   m[5];                       /* CRAPPY FORTRAN ARRAYS */
+	Cmplx                   mSquared[5];
+	Cmplx                   mExp[5];
+	Cmplx                   N1;
+	Cmplx                   N2;
+	Cmplx                   N3;
+	Cmplx                   N4;
+	double                  beta2_4kn;
+	Cmplx                   lambda1;
+	Cmplx                   lambda2;
+	Cmplx                   n1;
+	Cmplx                   n2;
+	Cmplx                   n1_minus_beta;
+	Cmplx                   n2_minus_beta;
+	Cmplx                   M;
+	Cmplx                   oneOnM;
+	Cmplx                   tmp;
+	double                  beta;
+	double                  kn;
+	Index                   index;
+	Index                   i;
+	Index                   j;
+	Index                   h;
+	Index                   k;
+	double                  L;
+	double                  kx;
+	double                  ky;
+	Cmplx                   A1;
+	Cmplx                   A2;
+	Cmplx                   A3;
+	Cmplx                   A4;
+	Cmplx                   exp_n1x;
+	Cmplx                   exp_n2x;
+	Cmplx                   a1End;
+	Cmplx                   a2End;
+	double                  x;
+	double                  y;
+	double                  factorA;
+	double                  factorB;
+	int                     wavenumberX;
+	int                     wavenumberY;
+	double                  sqRootValue;
+
+	Mesh_GetGlobalCoordRange( mesh, min, max );
+	x = coord[ I_AXIS ] - min[ I_AXIS ];
+	y = coord[ J_AXIS ] - min[ J_AXIS ];
+
+	beta = self->beta;
+	wavenumberX = self->wavenumberX;
+	wavenumberY = self->wavenumberY;
+	
+	L    = max[ I_AXIS ] - min[ I_AXIS ];
+	kx   = wavenumberX * M_PI/ L;
+	ky   = wavenumberY * M_PI;
+	kn   = ky; 
+
+	beta2_4kn = beta * beta + 4.0 * kn * kn;
+	sqRootValue = beta2_4kn * beta2_4kn + 16.0 * beta * beta * kn * kn;
+	sqRootValue = sqrt( sqRootValue );
+	chi1 = sqrt( 0.5 * (  beta2_4kn + sqRootValue ) );
+	chi2 = sqrt( 0.5 * ( -beta2_4kn + sqRootValue ) );
+
+	n1[ REAL_PART ] = 0.5 * (beta + chi1);
+	n1[ IMAG_PART ] = 0.5 * (chi2);
+	
+	n2[ REAL_PART ] = 0.5 * (beta - chi1);
+	n2[ IMAG_PART ] = 0.5 * (-chi2);
+
+	Cmplx_Copy( n1, m[1] );
+	Cmplx_Conjugate( n1, m[2] );
+	Cmplx_Copy( n2, m[3] );
+	Cmplx_Conjugate( n2, m[4] );
+			
+	for ( index = 1 ; index <= 4 ; index++ ) {
+		Cmplx_Multiply( m[index], m[index], mSquared[index] );
+		Cmplx_RealMultiply( m[ index ], -L, tmp );
+		Cmplx_Exp( tmp, mExp[ index ] );
+	}
+
+	/* Calculate M - Equation A7 */
+	Cmplx_Subtract( m[2], m[1], oneOnM );
+	Cmplx_Subtract( m[3], m[1], tmp );
+	Cmplx_Multiply( oneOnM, tmp, oneOnM );
+	Cmplx_Subtract( m[4], m[1], tmp );
+	Cmplx_Multiply( oneOnM, tmp, oneOnM );
+	Cmplx_RealDivideByCmplx( oneOnM, 1.0, M );
+
+	/* Calculate N - Equation A8 */
+	for ( j = 1 ; j <= 3 ; j++ ) {
+		for ( i = j+1 ; i <= 4 ; i++ ) {
+			Cmplx product = {0,0};
+			
+			/* Get h */
+			for ( h = 1 ; h <= 4 ; h++ ) {
+				if ( h != i && h != j )
+					break; /* Found h */
+			}
+
+			/* Get k */
+			for ( k = h+1 ; k <= 4 ; k++ ) {
+				if ( k != i && k != j )
+					break; /* Found k */
+			}			
+
+			product[ REAL_PART ] = IS_ODD( i + j ) ? 1.0 : -1.0;
+			
+			Cmplx_Multiply( product, mExp[ i ], product );
+			Cmplx_Multiply( product, mExp[ j ], product );
+
+			Cmplx_Subtract( mSquared[ k ], mSquared[ h ], tmp );
+			Cmplx_Multiply( product, tmp, product );
+
+			Cmplx_Subtract( mSquared[ i ], mSquared[ j ], tmp );
+			Cmplx_Multiply( product, tmp, product );
+
+			Cmplx_Add( N, product, N );
+		}
+	}
+
+	/* Build N1 - Equation A9 */
+	Cmplx_Subtract( mSquared[4], mSquared[3], tmp );
+	Cmplx_Multiply( tmp, mSquared[2], tmp );
+	Cmplx_Multiply( tmp, mExp[2], N1 ); 
+
+	Cmplx_Subtract( mSquared[4], mSquared[2], tmp );
+	Cmplx_Multiply( tmp, mSquared[3], tmp );
+	Cmplx_Multiply( tmp, mExp[3], tmp );
+	Cmplx_Subtract( N1, tmp, N1 );
+	
+	Cmplx_Subtract( mSquared[3], mSquared[2], tmp );
+	Cmplx_Multiply( tmp, mSquared[4], tmp );
+	Cmplx_Multiply( tmp, mExp[4], tmp );
+	Cmplx_Add( N1, tmp, N1 );
+	
+	/* Build N2 - Equation A10 */
+	Cmplx_Subtract( mSquared[4], mSquared[2], tmp );
+	Cmplx_Multiply( tmp, mSquared[1], tmp );
+	Cmplx_Multiply( tmp, mExp[1], N2 );
+
+	Cmplx_Subtract( mSquared[4], mSquared[1], tmp );
+	Cmplx_Multiply( tmp, mSquared[2], tmp );
+	Cmplx_Multiply( tmp, mExp[2], tmp );
+	Cmplx_Subtract( N2, tmp, N2 );
+
+	Cmplx_Subtract( mSquared[2], mSquared[1], tmp );
+	Cmplx_Multiply( tmp, mSquared[4], tmp );
+	Cmplx_Multiply( tmp, mExp[4], tmp );
+	Cmplx_Add( N2, tmp, N2 );
+
+	/* Build N3 - Equation A11 */
+	Cmplx_Subtract( mSquared[3], mSquared[4], tmp );
+	Cmplx_Multiply( tmp, mExp[2], N3 );
+
+	Cmplx_Subtract( mSquared[4], mSquared[2], tmp );
+	Cmplx_Multiply( tmp, mExp[3], tmp );
+	Cmplx_Add( N3, tmp, N3 );
+
+	Cmplx_Subtract( mSquared[2], mSquared[3], tmp );
+	Cmplx_Multiply( tmp, mExp[4], tmp );
+	Cmplx_Add( N3, tmp, N3 );
+
+	/* Build N4 - Equation A12 */
+	Cmplx_Subtract( mSquared[2], mSquared[4], tmp );
+	Cmplx_Multiply( tmp, mExp[1], N4 );
+
+	Cmplx_Subtract( mSquared[4], mSquared[1], tmp );
+	Cmplx_Multiply( tmp, mExp[2], tmp );
+	Cmplx_Add( N4, tmp, N4 );
+
+	Cmplx_Subtract( mSquared[1], mSquared[2], tmp );
+	Cmplx_Multiply( tmp, mExp[4], tmp );
+	Cmplx_Add( N4, tmp, N4 );
+
+
+    /* Build lambda1 - Equation B8 */
+	Cmplx_AddReal( n1, - beta, n1_minus_beta );
+    Cmplx_RealMultiply( n1_minus_beta,L, tmp );
+	Cmplx_Exp( tmp, tmp );
+    Cmplx_RealMultiply(tmp, cos( kx * L ), tmp );
+	Cmplx_RealMinusCmplx( tmp, 1.0, tmp );
+    Cmplx_RealMultiply(tmp, -kx, tmp );
+	Cmplx_Multiply( M, tmp, lambda1 );
+	
+	Cmplx_Multiply( n1_minus_beta, n1_minus_beta, tmp );
+	Cmplx_AddReal( tmp, kx * kx, tmp );
+
+	Cmplx_Division( lambda1, tmp, lambda1 );
+	
+	/* Build lambda2 - Equation B9 */
+	Cmplx_AddReal( n2, - beta, n2_minus_beta );
+	Cmplx_RealMultiply( n2_minus_beta,L, tmp );
+	Cmplx_Exp( tmp, tmp );
+	Cmplx_RealMultiply(tmp, cos( kx * L ), tmp );
+	Cmplx_RealMinusCmplx( tmp, 1.0, tmp );
+	Cmplx_RealMultiply(tmp, kx, tmp );
+	Cmplx_Multiply( M, tmp, lambda2 );
+	
+	Cmplx_Multiply( n2_minus_beta, n2_minus_beta, tmp );
+	Cmplx_AddReal( tmp, kx * kx, tmp );
+
+	Cmplx_Division( lambda2, tmp, lambda2 );
+
+
+
+	/* Build A1 - Equation B4 */
+	Cmplx_Multiply( mExp[1], lambda1, tmp );
+	factorA = tmp[ REAL_PART ];
+	Cmplx_Multiply( mExp[3], lambda2, tmp );
+	factorA += tmp[ REAL_PART ];
+	Cmplx_Division( N1, N, tmp );
+	Cmplx_RealMultiply( tmp, 2.0 * factorA, A1 );
+
+	Cmplx_Multiply( mExp[1], lambda1, tmp );
+	Cmplx_Multiply( tmp, mSquared[1], tmp );
+	factorB = tmp[ REAL_PART ];
+	Cmplx_Multiply( mExp[3], lambda2, tmp );
+	Cmplx_Multiply( tmp, mSquared[3], tmp );
+	factorB += tmp[ REAL_PART ];
+	Cmplx_Division( N3, N, tmp );
+	Cmplx_RealMultiply( tmp, 2.0 * factorB, tmp );
+	Cmplx_Add( A1, tmp, A1 );
+
+	Cmplx_Multiply( n1_minus_beta, n1_minus_beta, a1End );
+	Cmplx_AddReal( a1End, kx*kx, a1End );
+	Cmplx_RealDivideByCmplx( a1End, kx, a1End );
+	Cmplx_Multiply( a1End, M, a1End );
+	Cmplx_Add( A1, a1End, A1 );
+
+	/* Build A2 - Equation B5 */
+	Cmplx_Division( N2, N, tmp );
+	Cmplx_RealMultiply( tmp, 2.0 * factorA, A2 );
+
+	Cmplx_Division( N4, N, tmp );
+	Cmplx_RealMultiply( tmp, 2.0 * factorB, tmp );
+	Cmplx_Add( A2, tmp, A2 );
+
+	Cmplx_Multiply( n2_minus_beta, n2_minus_beta, a2End );
+	Cmplx_AddReal( a2End, kx*kx, a2End );
+	Cmplx_RealDivideByCmplx( a2End, kx, a2End );
+	Cmplx_Multiply( a2End, M, a2End );
+	Cmplx_Subtract( A2, a2End, A2 );	
+
+	/* Build A3 - Equation B6 */
+	Cmplx_Subtract( a2End, a1End, A3 );
+
+	/* Build A4 - Equation B7 */
+	Cmplx_Multiply( n1_minus_beta, n1_minus_beta, tmp );
+	Cmplx_AddReal( tmp, kx*kx, tmp );
+	Cmplx_Division( n1_minus_beta, tmp, tmp );
+	Cmplx_Multiply( tmp, M, A4 );
+
+	Cmplx_Multiply( n2_minus_beta, n2_minus_beta, tmp );
+	Cmplx_AddReal( tmp, kx*kx, tmp );
+	Cmplx_Division( n2_minus_beta, tmp, tmp );
+	Cmplx_Multiply( tmp, M, tmp );
+	Cmplx_Subtract( A4, tmp, A4 );
+	
+	/*************************************** Get Velocities - Eqn B10 - B11 *****************************************/
+	
+	/* Get First Term in Sums */
+	Cmplx_RealMultiply( n1, -x, tmp );
+	Cmplx_Exp( tmp, exp_n1x );
+	Cmplx_Multiply( A1, exp_n1x, sumX );
+
+	Cmplx_Copy( sumX, sumY );
+	Cmplx_Multiply( sumY, n1, sumY );
+	Cmplx_RealMultiply( sumY, -1.0, sumY );
+
+	/* Add second term in sum */
+	Cmplx_RealMultiply( n2, -x, tmp );
+	Cmplx_Exp( tmp, exp_n2x );
+	Cmplx_Multiply( A2, exp_n2x, tmp );
+	Cmplx_Add( sumX, tmp, sumX );
+
+	Cmplx_Multiply( tmp, n2, tmp );
+	Cmplx_RealMultiply( tmp, -1.0, tmp );
+	Cmplx_Add( sumY, tmp, sumY );
+	
+	/* Add third term in sum */
+	sumX[ REAL_PART ] += (A3[ REAL_PART ] * cos( kx*x ) + A4[ REAL_PART ] * sin( kx * x ) ) * exp( -beta*x );
+	sumY[ REAL_PART ] += exp( -beta * x ) * (
+		(kx * A4[REAL_PART] - beta * A3[ REAL_PART ]) * cos( kx * x ) - 
+		(kx * A3[REAL_PART] + beta * A4[ REAL_PART ]) * sin( kx * x ) );
+
+	velocity[ I_AXIS ] = -2.0 * kx * ky * cos( ky * y ) * sumX[ REAL_PART ]; 
+	velocity[ J_AXIS ] = 2.0 * kx * sin( ky * y ) * sumY[ REAL_PART ]; 
+
+}
+
+void _LateralViscosityAnalytic_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
+	LateralViscosityAnalytic*         self           = (LateralViscosityAnalytic*)analyticSolution;
+	AbstractContext*        context;
+	ConditionFunction*      condFunc;
+	
+	/* Construct Parent */
+	_AnalyticSolution_AssignFromXML( self, cf, data );
+
+	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  ); 
+	
+	/* Add temperature initial condition */
+	condFunc = ConditionFunction_New( LateralViscosityAnalytic_TemperatureIC, (Name)"LateralViscosityAnalytic_TemperatureIC"  );
+	ConditionFunction_Register_Add( context->condFunc_Register, condFunc );
+	
+	/* Create Analytic Fields */
+	self->velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  ); 
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, self->velocityField, _LateralViscosityAnalytic_VelocityFunction );
+
+	self->beta = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"beta", 0.0  );
+	self->wavenumberX = Stg_ComponentFactory_GetRootDictInt( cf, "wavenumberX", 1 );
+	self->wavenumberY = Stg_ComponentFactory_GetRootDictInt( cf, "wavenumberY", 1 );
+}
+
+void _LateralViscosityAnalytic_Build( void* analyticSolution, void* data ) {
+	LateralViscosityAnalytic*         self = (LateralViscosityAnalytic*)analyticSolution;
+
+	_AnalyticSolution_Build( self, data );
+}
+
+
+void* _LateralViscosityAnalytic_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(LateralViscosityAnalytic);
+	Type                                                      type = LateralViscosityAnalytic_Type;
+	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
+	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
+	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _LateralViscosityAnalytic_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _LateralViscosityAnalytic_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _LateralViscosityAnalytic_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 Underworld_LateralViscosityAnalytic_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, LateralViscosityAnalytic_Type, (Name)"0", _LateralViscosityAnalytic_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/tests/NonNewtonianShearSolution/NonNewtonianShearSolution.c
--- a/Rheology/tests/NonNewtonianShearSolution/NonNewtonianShearSolution.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,178 +0,0 @@
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Rheology/Rheology.h>
-
-#include <assert.h>
-
-typedef struct {
-	__AnalyticSolution
-	MaterialViscosity*               materialViscosity;
-	Mesh*				 mesh;
-	NonNewtonian*                    nonNewtonianRheology;
-	double                           velocityTopOfBox;
-	FeVariable*			 velocityField;
-	FeVariable*			 strainRateField;
-	FeVariable*			 stressField;
-	FeVariable*			 viscosityField;
-} NonNewtonianShearSolution;
-
-const Type NonNewtonianShearSolution_Type = "NonNewtonianShearSolution";
-
-void NonNewtonianShearSolution_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
-	NonNewtonianShearSolution*   self = (NonNewtonianShearSolution*)analyticSolution;
-	double                       height;
-	double			     min[3], max[3];
-	
-	/* Get Parameters */
-	Mesh_GetGlobalCoordRange( self->mesh, min, max );
-	height = max[J_AXIS] - min[J_AXIS];
-
-	velocity[ I_AXIS ] = coord[J_AXIS] / height * self->velocityTopOfBox;
-	velocity[ J_AXIS ] = 0.0;
-}
-
-void NonNewtonianShearSolution_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
-	NonNewtonianShearSolution*   self = (NonNewtonianShearSolution*)analyticSolution;
-	double                       height;
-	double			     min[3], max[3];
-	
-	/* Get Parameters */
-	Mesh_GetGlobalCoordRange( self->mesh, min, max );
-	height = max[J_AXIS] - min[J_AXIS];
-
-	strainRate[ 0 ] = 0.0;
-	strainRate[ 1 ] = 0.0;
-	strainRate[ 2 ] = 0.5 * self->velocityTopOfBox / height;
-}
-
-void NonNewtonianShearSolution_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
-	NonNewtonianShearSolution*   self = (NonNewtonianShearSolution*)analyticSolution;
-	double                         eta;
-	double                         height;
-	double                         tau;
-	double                         n;
-	double			     min[3], max[3];
-	
-	/* Get Parameters */
-	Mesh_GetGlobalCoordRange( self->mesh, min, max );
-	eta = self->materialViscosity->eta0;
-	n = self->nonNewtonianRheology->stressExponent;
-	height = max[J_AXIS] - min[J_AXIS];
-
-	/* Calculate stress - without considering cohesion */
-	tau = pow( eta * self->velocityTopOfBox / height, 1/n);
-
-	/* Calculate Analytic Solution for the stress */
-	stress[0] = 0.0;
-	stress[1] = 0.0;
-	stress[2] = tau;
-}
-
-
-void NonNewtonianShearSolution_ViscosityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* viscosity ) {
-	NonNewtonianShearSolution*     self = (NonNewtonianShearSolution*)analyticSolution;
-	double                         eta0;
-	double                         height;
-	double                         n;
-	double			     min[3], max[3];
-	
-	/* Get Parameters */
-	eta0 = self->materialViscosity->eta0;
-	n = self->nonNewtonianRheology->stressExponent;
-	Mesh_GetGlobalCoordRange( self->mesh, min, max );
-	height = max[J_AXIS] - min[J_AXIS];
-
-	/* Calculate stress - without considering cohesion */
-	*viscosity = eta0 * pow( eta0 * self->velocityTopOfBox / height, 1/n-1.0);
-}
-
-void NonNewtonianShearSolution_UpdateVelocityBC( NonNewtonianShearSolution* self, FiniteElementContext* context ) {
-	self->velocityTopOfBox += context->dt;
-}
-
-void NonNewtonianShearSolution_VelocityBC( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
-	FiniteElementContext *	         context       = (FiniteElementContext*)_context;
-	NonNewtonianShearSolution*   self          = (NonNewtonianShearSolution*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)NonNewtonianShearSolution_Type );
-	double*                          result        = (double* ) _result;
-
-	*result = self->velocityTopOfBox;
-}
-
-void _NonNewtonianShearSolution_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
-	NonNewtonianShearSolution* self = (NonNewtonianShearSolution*)analyticSolution;
-	FiniteElementContext*          context;
-
-	/* Construct parent */
-	_AnalyticSolution_AssignFromXML( self, cf, data );
-	context = Stg_CheckType( self->context, FiniteElementContext );
-	
-	ConditionFunction_Register_Add( context->condFunc_Register, 
-			ConditionFunction_New( NonNewtonianShearSolution_VelocityBC, (Name)"ShearTrigger")  );	
-
-	/* Create Analytic Velocity Field */
-	self->velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, self->velocityField, NonNewtonianShearSolution_VelocityFunction );
-
-	/* Create Analytic Strain Rate Field */
-	self->strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, self->strainRateField, NonNewtonianShearSolution_StrainRateFunction );
-
-	/* Create Analytic Stress Field */
-	self->stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, self->stressField, NonNewtonianShearSolution_StressFunction );
-
-	/* Create Analytic Viscosity Field */
-	self->viscosityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"ViscosityField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, self->viscosityField, NonNewtonianShearSolution_ViscosityFunction );
-
-	self->materialViscosity = Stg_ComponentFactory_ConstructByName( cf, (Name)"layerViscosity", MaterialViscosity, True, data  );
-	self->nonNewtonianRheology = 
-		Stg_ComponentFactory_ConstructByName( cf, (Name)"nonNewtonianRheology", NonNewtonian, True, data  );
-	self->mesh = Stg_ComponentFactory_ConstructByName( cf, (Name)"linearMesh", Mesh, True, data  );
-
-	/* Set Velocity Stuff */
-	EP_AppendClassHook( Context_GetEntryPoint( context, AbstractContext_EP_UpdateClass ),
-			    NonNewtonianShearSolution_UpdateVelocityBC, self );
-	self->velocityTopOfBox = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"velocityTopOfBox", 0.5  );
-}
-
-void _NonNewtonianShearSolution_Build( void* analyticSolution, void* data ) {
-	NonNewtonianShearSolution* self = (NonNewtonianShearSolution*)analyticSolution;
-
-	_AnalyticSolution_Build( self, data );
-}
-
-
-/* This function will provide StGermain the abilty to instantiate (create) this codelet on demand. */
-void* _NonNewtonianShearSolution_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(NonNewtonianShearSolution);
-	Type                                                      type = NonNewtonianShearSolution_Type;
-	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
-	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
-	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _NonNewtonianShearSolution_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _NonNewtonianShearSolution_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _NonNewtonianShearSolution_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  );	
-}
-	
-/* This function is automatically run by StGermain when this plugin is loaded. The name must be "<plugin-name>_Register". */
-Index Underworld_NonNewtonianShearSolution_Register( PluginsManager* pluginsManager ) {
-	/* A plugin is only properly registered once it returns the handle provided when submitting a codelet to StGermain. */
-	return PluginsManager_Submit( pluginsManager, NonNewtonianShearSolution_Type, (Name)"0", _NonNewtonianShearSolution_DefaultNew  );
-}
-
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/tests/NonNewtonianShearSolution/NonNewtonianShearSolution.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/tests/NonNewtonianShearSolution/NonNewtonianShearSolution.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,178 @@
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Rheology/Rheology.h>
+
+#include <assert.h>
+
+typedef struct {
+	__AnalyticSolution
+	MaterialViscosity*               materialViscosity;
+	Mesh*				 mesh;
+	NonNewtonian*                    nonNewtonianRheology;
+	double                           velocityTopOfBox;
+	FeVariable*			 velocityField;
+	FeVariable*			 strainRateField;
+	FeVariable*			 stressField;
+	FeVariable*			 viscosityField;
+} NonNewtonianShearSolution;
+
+const Type NonNewtonianShearSolution_Type = "NonNewtonianShearSolution";
+
+void NonNewtonianShearSolution_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
+	NonNewtonianShearSolution*   self = (NonNewtonianShearSolution*)analyticSolution;
+	double                       height;
+	double			     min[3], max[3];
+	
+	/* Get Parameters */
+	Mesh_GetGlobalCoordRange( self->mesh, min, max );
+	height = max[J_AXIS] - min[J_AXIS];
+
+	velocity[ I_AXIS ] = coord[J_AXIS] / height * self->velocityTopOfBox;
+	velocity[ J_AXIS ] = 0.0;
+}
+
+void NonNewtonianShearSolution_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
+	NonNewtonianShearSolution*   self = (NonNewtonianShearSolution*)analyticSolution;
+	double                       height;
+	double			     min[3], max[3];
+	
+	/* Get Parameters */
+	Mesh_GetGlobalCoordRange( self->mesh, min, max );
+	height = max[J_AXIS] - min[J_AXIS];
+
+	strainRate[ 0 ] = 0.0;
+	strainRate[ 1 ] = 0.0;
+	strainRate[ 2 ] = 0.5 * self->velocityTopOfBox / height;
+}
+
+void NonNewtonianShearSolution_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
+	NonNewtonianShearSolution*   self = (NonNewtonianShearSolution*)analyticSolution;
+	double                         eta;
+	double                         height;
+	double                         tau;
+	double                         n;
+	double			     min[3], max[3];
+	
+	/* Get Parameters */
+	Mesh_GetGlobalCoordRange( self->mesh, min, max );
+	eta = self->materialViscosity->eta0;
+	n = self->nonNewtonianRheology->stressExponent;
+	height = max[J_AXIS] - min[J_AXIS];
+
+	/* Calculate stress - without considering cohesion */
+	tau = pow( eta * self->velocityTopOfBox / height, 1/n);
+
+	/* Calculate Analytic Solution for the stress */
+	stress[0] = 0.0;
+	stress[1] = 0.0;
+	stress[2] = tau;
+}
+
+
+void NonNewtonianShearSolution_ViscosityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* viscosity ) {
+	NonNewtonianShearSolution*     self = (NonNewtonianShearSolution*)analyticSolution;
+	double                         eta0;
+	double                         height;
+	double                         n;
+	double			     min[3], max[3];
+	
+	/* Get Parameters */
+	eta0 = self->materialViscosity->eta0;
+	n = self->nonNewtonianRheology->stressExponent;
+	Mesh_GetGlobalCoordRange( self->mesh, min, max );
+	height = max[J_AXIS] - min[J_AXIS];
+
+	/* Calculate stress - without considering cohesion */
+	*viscosity = eta0 * pow( eta0 * self->velocityTopOfBox / height, 1/n-1.0);
+}
+
+void NonNewtonianShearSolution_UpdateVelocityBC( NonNewtonianShearSolution* self, FiniteElementContext* context ) {
+	self->velocityTopOfBox += context->dt;
+}
+
+void NonNewtonianShearSolution_VelocityBC( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
+	FiniteElementContext *	         context       = (FiniteElementContext*)_context;
+	NonNewtonianShearSolution*   self          = (NonNewtonianShearSolution*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)NonNewtonianShearSolution_Type );
+	double*                          result        = (double* ) _result;
+
+	*result = self->velocityTopOfBox;
+}
+
+void _NonNewtonianShearSolution_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
+	NonNewtonianShearSolution* self = (NonNewtonianShearSolution*)analyticSolution;
+	FiniteElementContext*          context;
+
+	/* Construct parent */
+	_AnalyticSolution_AssignFromXML( self, cf, data );
+	context = Stg_CheckType( self->context, FiniteElementContext );
+	
+	ConditionFunction_Register_Add( context->condFunc_Register, 
+			ConditionFunction_New( NonNewtonianShearSolution_VelocityBC, (Name)"ShearTrigger")  );	
+
+	/* Create Analytic Velocity Field */
+	self->velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, self->velocityField, NonNewtonianShearSolution_VelocityFunction );
+
+	/* Create Analytic Strain Rate Field */
+	self->strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, self->strainRateField, NonNewtonianShearSolution_StrainRateFunction );
+
+	/* Create Analytic Stress Field */
+	self->stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, self->stressField, NonNewtonianShearSolution_StressFunction );
+
+	/* Create Analytic Viscosity Field */
+	self->viscosityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"ViscosityField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, self->viscosityField, NonNewtonianShearSolution_ViscosityFunction );
+
+	self->materialViscosity = Stg_ComponentFactory_ConstructByName( cf, (Name)"layerViscosity", MaterialViscosity, True, data  );
+	self->nonNewtonianRheology = 
+		Stg_ComponentFactory_ConstructByName( cf, (Name)"nonNewtonianRheology", NonNewtonian, True, data  );
+	self->mesh = Stg_ComponentFactory_ConstructByName( cf, (Name)"linearMesh", Mesh, True, data  );
+
+	/* Set Velocity Stuff */
+	EP_AppendClassHook( Context_GetEntryPoint( context, AbstractContext_EP_UpdateClass ),
+			    NonNewtonianShearSolution_UpdateVelocityBC, self );
+	self->velocityTopOfBox = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"velocityTopOfBox", 0.5  );
+}
+
+void _NonNewtonianShearSolution_Build( void* analyticSolution, void* data ) {
+	NonNewtonianShearSolution* self = (NonNewtonianShearSolution*)analyticSolution;
+
+	_AnalyticSolution_Build( self, data );
+}
+
+
+/* This function will provide StGermain the abilty to instantiate (create) this codelet on demand. */
+void* _NonNewtonianShearSolution_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(NonNewtonianShearSolution);
+	Type                                                      type = NonNewtonianShearSolution_Type;
+	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
+	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
+	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _NonNewtonianShearSolution_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _NonNewtonianShearSolution_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _NonNewtonianShearSolution_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  );	
+}
+	
+/* This function is automatically run by StGermain when this plugin is loaded. The name must be "<plugin-name>_Register". */
+Index Underworld_NonNewtonianShearSolution_Register( PluginsManager* pluginsManager ) {
+	/* A plugin is only properly registered once it returns the handle provided when submitting a codelet to StGermain. */
+	return PluginsManager_Submit( pluginsManager, NonNewtonianShearSolution_Type, (Name)"0", _NonNewtonianShearSolution_DefaultNew  );
+}
+
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/tests/ViscousSuite.c
--- a/Rheology/tests/ViscousSuite.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,446 +0,0 @@
-#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 "Underworld/Underworld.h"
-
-/* silly stgermain, I must define this */
-#define CURR_MODULE_NAME "UnderworldContext.c"
-
-typedef struct {
-	UnderworldContext* context;
-} ViscousSuiteData;
-
-void ViscousSuite_Setup( ViscousSuiteData* data ) { 
-	data->context=NULL;
-}
-
-void ViscousSuite_Teardown( ViscousSuiteData* data ) {
-}
-
-void ViscousSuite_ArrheniusStiffnessMatrix2D( ViscousSuiteData* data ) {
-	StiffnessMatrix*			stiffnessMatrix;
-	SystemLinearEquations*	sle;
-	Dictionary*					dictionary;
-	UnderworldContext*		context;
-	Stg_ComponentFactory*	cf;
-	PetscViewer					expViewer;
-	PetscReal					matrixNorm, errorNorm, test;
-	Mat							expected;
-	char							expected_file[PCU_PATH_MAX];
-	char							*filename;
-	double						tolerance;
-	char							xml_input[PCU_PATH_MAX];
-	char							rFile[PCU_PATH_MAX];
-	int							err;
-
-
-	pcu_docstring( "This test compares a Stiffness matrix against a previously generated stiffness matrix"
-		"The stiffness matrix is generated from a 2D FEM model for a flow with an Arrhenius rheology."
-		"See testArrhenius2D.xml for the actual xml used"	);
-
-	/* read in the xml input file */
-	pcu_filename_input( "testArrhenius2D.xml", xml_input );
-	cf = stgMainInitFromXML( xml_input, MPI_COMM_WORLD, NULL );
-	context = (UnderworldContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context" );
-	data->context = context;
-	dictionary = context->dictionary;
-
-	stgMainBuildAndInitialise( cf );
-
-	/* Assemble */
-	stiffnessMatrix = (StiffnessMatrix* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"k_matrix" );
-	sle = (SystemLinearEquations* )       LiveComponentRegister_Get( context->CF->LCRegister, (Name)"stokesEqn" );
-	assert( stiffnessMatrix  );
-	StiffnessMatrix_Assemble( stiffnessMatrix, False, sle, context );
-	stiffnessMatrix = stiffnessMatrix;
-
-	/* Test is to check the relative error between an
-		 1) expected stiffness matrix, (made years ago)
-		 2) the current stiffness matrix.
-
-		 both matricies are built using only an Arrhenius rheology 
-	 */
-
-	filename = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"StiffnessMatrixCompareFilename"  );
-	tolerance = Dictionary_GetDouble_WithDefault( dictionary, (Dictionary_Entry_Key)"StiffnessMatrixCompareTolerance", 1e-4  );
-
-	pcu_filename_expected( filename, expected_file );
-	PetscViewerBinaryOpen( context->communicator, expected_file, FILE_MODE_READ, &expViewer );
-
-	MatLoad( expViewer, MATAIJ, &expected );
-
-	/* 
-		 To view the expected and computed matricies uncomment this
-	PetscViewerASCIIOpen(context->communicator, "numerical.dat",&currViewer);
-	PetscViewerASCIIOpen(context->communicator, "expected.dat",&parallelViewer);
-	MatView( stiffnessMatrix->matrix, currViewer ); //PETSC_VIEWER_STDOUT_WORLD );
-	MatView( expected, parallelViewer ); //PETSC_VIEWER_STDOUT_WORLD );
-	PetscViewerDestroy(currViewer);
-	PetscViewerDestroy(parallelViewer);
-	*/
-
-	MatNorm( expected, NORM_FROBENIUS, &matrixNorm );
-	assert( matrixNorm != 0 );
-
-	MatAXPY( expected, -1, (stiffnessMatrix->matrix) , DIFFERENT_NONZERO_PATTERN );
-	MatNorm( expected, NORM_FROBENIUS, &errorNorm );
-	test = errorNorm / matrixNorm;
-
-	pcu_check_lt( test, tolerance );
-
-	if( data->context->rank == 0 ) {
-		/* Now clean output path */
-		sprintf(rFile, "%s/input.xml", data->context->outputPath );
-		err = remove( rFile );
-		if( err == -1 ) printf("Error in %s, can't delete the input.xml\n", __func__);
-	}
-
-   PetscViewerDestroy( expViewer );
-   MatDestroy( expected);
-	stgMainDestroy( cf );
-}
-
-void ViscousSuite_FrankKamenetskiiStiffnessMatrix2D( ViscousSuiteData* data ) {
-	StiffnessMatrix*			stiffnessMatrix;
-	SystemLinearEquations*	sle;
-	Dictionary*					dictionary;
-	UnderworldContext*		context;
-	Stg_ComponentFactory*	cf;
-	PetscViewer					expViewer;
-	PetscReal					matrixNorm, errorNorm, test;
-	Mat							expected;
-	char							expected_file[PCU_PATH_MAX];
-	char							*filename;
-	double						tolerance;
-	char							xml_input[PCU_PATH_MAX];
-	char							rFile[PCU_PATH_MAX];
-	int							err;
-
-	pcu_docstring( "This test compares a Stiffness matrix against a previously generated stiffness matrix"
-		"The stiffness matrix is generated from a 2D FEM model for a flow with an FrankKamenetskii rheology."
-		"See testFrankKamenetskii2D.xml for the actual xml used"	);
-
-	/* read in the xml input file */
-	pcu_filename_input( "testFrankKamenetskii2D.xml", xml_input );
-	cf = stgMainInitFromXML( xml_input, MPI_COMM_WORLD, NULL );
-	context = (UnderworldContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context" );
-	data->context = context;
-	dictionary = context->dictionary;
-
-	stgMainBuildAndInitialise( cf );
-
-	/* Assemble */
-	stiffnessMatrix = (StiffnessMatrix* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"k_matrix" );
-	sle = (SystemLinearEquations* )       LiveComponentRegister_Get( context->CF->LCRegister, (Name)"stokesEqn" );
-	assert( stiffnessMatrix  );
-	StiffnessMatrix_Assemble( stiffnessMatrix, False, sle, context );
-	stiffnessMatrix = stiffnessMatrix;
-
-	/* Test is to check the relative error between an
-		 1) expected stiffness matrix, (made years ago)
-		 2) the current stiffness matrix.
-
-		 both matricies are built using only an Arrhenius rheology 
-	 */
-
-	filename = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"StiffnessMatrixCompareFilename"  );
-	tolerance = Dictionary_GetDouble_WithDefault( dictionary, (Dictionary_Entry_Key)"StiffnessMatrixCompareTolerance", 1e-4  );
-
-	pcu_filename_expected( filename, expected_file );
-	PetscViewerBinaryOpen( context->communicator, expected_file, FILE_MODE_READ, &expViewer );
-
-	MatLoad( expViewer, MATAIJ, &expected );
-
-	/* 
-		 To view the expected and computed matricies uncomment this
-	PetscViewerASCIIOpen(context->communicator, "numerical.dat",&currViewer);
-	PetscViewerASCIIOpen(context->communicator, "expected.dat",&parallelViewer);
-	MatView( stiffnessMatrix->matrix, currViewer ); //PETSC_VIEWER_STDOUT_WORLD );
-	MatView( expected, parallelViewer ); //PETSC_VIEWER_STDOUT_WORLD );
-	PetscViewerDestroy(currViewer);
-	PetscViewerDestroy(parallelViewer);
-	*/
-
-	MatNorm( expected, NORM_FROBENIUS, &matrixNorm );
-	assert( matrixNorm != 0 );
-
-	MatAXPY( expected, -1, (stiffnessMatrix->matrix) , DIFFERENT_NONZERO_PATTERN );
-	MatNorm( expected, NORM_FROBENIUS, &errorNorm );
-	test = errorNorm / matrixNorm;
-
-	pcu_check_lt( test, tolerance );
-
-	if( data->context->rank == 0 ) {
-		/* Now clean output path */
-		sprintf(rFile, "%s/input.xml", data->context->outputPath );
-		err = remove( rFile );
-		if( err == -1 ) printf("Error in %s, can't delete the input.xml\n", __func__);
-	}
-
-   PetscViewerDestroy( expViewer );
-   MatDestroy( expected);
-	stgMainDestroy( cf );
-}
-
-void ViscousSuite_MaterialViscosityStiffnessMatrix2D( ViscousSuiteData* data ) {
-	StiffnessMatrix*			stiffnessMatrix;
-	SystemLinearEquations*	sle;
-	Dictionary*					dictionary;
-	UnderworldContext*		context;
-	Stg_ComponentFactory*	cf;
-	PetscViewer					expViewer/*, parallelViewer, currViewer*/;
-	PetscReal					matrixNorm, errorNorm, test;
-	Mat							expected;
-	char							expected_file[PCU_PATH_MAX];
-	char							*filename;
-	double						tolerance;
-	char							xml_input[PCU_PATH_MAX];
-	char							rFile[PCU_PATH_MAX];
-	int							err;
-
-	pcu_docstring( "This test compares a Stiffness matrix against a previously generated stiffness matrix"
-		"The stiffness matrix is generated from a 2D FEM model for a flow with an constant isoviscous rheology."
-		"See testMaterialViscosity2D.xml for the actual xml used"	);
-
-	/* read in the xml input file */
-	pcu_filename_input( "testMaterialViscosity2D.xml", xml_input );
-	cf = stgMainInitFromXML( xml_input, MPI_COMM_WORLD, NULL );
-	context = (UnderworldContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context" );
-	data->context = context;
-	dictionary = context->dictionary;
-
-	stgMainBuildAndInitialise( cf );
-
-	/* Assemble */
-	stiffnessMatrix = (StiffnessMatrix* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"k_matrix" );
-	sle = (SystemLinearEquations* )       LiveComponentRegister_Get( context->CF->LCRegister, (Name)"stokesEqn" );
-	assert( stiffnessMatrix  );
-	StiffnessMatrix_Assemble( stiffnessMatrix, False, sle, context );
-	stiffnessMatrix = stiffnessMatrix;
-
-/* Test is to check the relative error between an
-	 1) expected stiffness matrix, (made years ago)
-	 2) the current stiffness matrix.
-
-	 both matricies are built using only an Arrhenius rheology 
- */
-
-	filename = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"StiffnessMatrixCompareFilename"  );
-	tolerance = Dictionary_GetDouble_WithDefault( dictionary, (Dictionary_Entry_Key)"StiffnessMatrixCompareTolerance", 1e-4  );
-
-	pcu_filename_expected( filename, expected_file );
-	PetscViewerBinaryOpen( context->communicator, expected_file, FILE_MODE_READ, &expViewer );
-
-	MatLoad( expViewer, MATAIJ, &expected );
-	/* 
-		 To view the expected and computed matricies uncomment this
-	PetscViewerASCIIOpen(context->communicator, "numerical.dat",&currViewer);
-	PetscViewerASCIIOpen(context->communicator, "expected.dat",&parallelViewer);
-	MatView( stiffnessMatrix->matrix, currViewer ); //PETSC_VIEWER_STDOUT_WORLD );
-	MatView( expected, parallelViewer ); //PETSC_VIEWER_STDOUT_WORLD );
-	PetscViewerDestroy(currViewer);
-	PetscViewerDestroy(parallelViewer);
-	*/
-
-	MatNorm( expected, NORM_FROBENIUS, &matrixNorm );
-	assert( matrixNorm != 0 );
-
-	MatAXPY( expected, -1, (stiffnessMatrix->matrix) , DIFFERENT_NONZERO_PATTERN );
-	MatNorm( expected, NORM_FROBENIUS, &errorNorm );
-	test = errorNorm / matrixNorm;
-
-	pcu_check_lt( test, tolerance );
-
-	if( data->context->rank == 0 ) {
-		/* Now clean output path */
-		sprintf(rFile, "%s/input.xml", data->context->outputPath );
-		err = remove( rFile );
-		if( err == -1 ) printf("Error in %s, can't delete the input.xml\n", __func__);
-	}
-
-   PetscViewerDestroy( expViewer );
-   MatDestroy( expected);
-	stgMainDestroy( cf );
-}
-
-void ViscousSuite_ArrheniusStiffnessMatrix2D_DualMesh( ViscousSuiteData* data ) {
-	StiffnessMatrix*			stiffnessMatrix;
-	SystemLinearEquations*	sle;
-	Dictionary*					dictionary;
-	UnderworldContext*		context;
-	Stg_ComponentFactory*	cf;
-	PetscViewer					expViewer;
-	PetscReal					matrixNorm, errorNorm, test;
-	Mat							expected;
-	char							expected_file[PCU_PATH_MAX];
-	char							*filename;
-	double						tolerance;
-	char							xml_input[PCU_PATH_MAX];
-	char							rFile[PCU_PATH_MAX];
-	int							err;
-
-	pcu_docstring( "This test compares a Stiffness matrix against a previously generated stiffness matrix"
-		"The stiffness matrix is generated from a 2D FEM model for a flow with an FrankKamenetskii rheology."
-		"See testFrankKamenetskii2D.xml for the actual xml used"	);
-
-	/* read in the xml input file */
-	pcu_filename_input( "testArrhenius2D-DualMesh.xml", xml_input );
-	cf = stgMainInitFromXML( xml_input, MPI_COMM_WORLD, NULL );
-	context = (UnderworldContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context" );
-	data->context = context;
-	dictionary = context->dictionary;
-
-	stgMainBuildAndInitialise( cf );
-
-	/* Assemble */
-	stiffnessMatrix = (StiffnessMatrix* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"k_matrix" );
-	sle = (SystemLinearEquations* )       LiveComponentRegister_Get( context->CF->LCRegister, (Name)"stokesEqn" );
-	assert( stiffnessMatrix  );
-	StiffnessMatrix_Assemble( stiffnessMatrix, False, sle, context );
-	stiffnessMatrix = stiffnessMatrix;
-
-	/* Test is to check the relative error between an
-		 1) expected stiffness matrix, (made years ago)
-		 2) the current stiffness matrix.
-
-		 both matricies are built using only an Arrhenius rheology 
-	 */
-
-	filename = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"StiffnessMatrixCompareFilename"  );
-	tolerance = Dictionary_GetDouble_WithDefault( dictionary, (Dictionary_Entry_Key)"StiffnessMatrixCompareTolerance", 1e-4  );
-
-	pcu_filename_expected( filename, expected_file );
-	PetscViewerBinaryOpen( context->communicator, expected_file, FILE_MODE_READ, &expViewer );
-
-	MatLoad( expViewer, MATAIJ, &expected );
-
-	/* 
-		 To view the expected and computed matricies uncomment this
-	PetscViewerASCIIOpen(context->communicator, "numerical.dat",&currViewer);
-	PetscViewerASCIIOpen(context->communicator, "expected.dat",&parallelViewer);
-	MatView( stiffnessMatrix->matrix, currViewer ); //PETSC_VIEWER_STDOUT_WORLD );
-	MatView( expected, parallelViewer ); //PETSC_VIEWER_STDOUT_WORLD );
-	PetscViewerDestroy(currViewer);
-	PetscViewerDestroy(parallelViewer);
-	*/
-
-	MatNorm( expected, NORM_FROBENIUS, &matrixNorm );
-	assert( matrixNorm != 0 );
-
-	MatAXPY( expected, -1, (stiffnessMatrix->matrix) , DIFFERENT_NONZERO_PATTERN );
-	MatNorm( expected, NORM_FROBENIUS, &errorNorm );
-	test = errorNorm / matrixNorm;
-
-	pcu_check_lt( test, tolerance );
-
-	if( data->context->rank == 0 ) {
-		/* Now clean output path */
-		sprintf(rFile, "%s/input.xml", data->context->outputPath );
-		err = remove( rFile );
-		if( err == -1 ) printf("Error in %s, can't delete the input.xml\n", __func__);
-	}
-
-   PetscViewerDestroy( expViewer );
-   MatDestroy( expected);
-	stgMainDestroy( cf );
-}
-
-void ViscousSuite_FrankKamenetskiiStiffnessMatrix2D_DualMesh( ViscousSuiteData* data ) {
-	StiffnessMatrix*			stiffnessMatrix;
-	SystemLinearEquations*	sle;
-	Dictionary*					dictionary;
-	UnderworldContext*		context;
-	Stg_ComponentFactory*	cf;
-	PetscViewer					expViewer;
-	PetscReal					matrixNorm, errorNorm, test;
-	Mat							expected;
-	char							expected_file[PCU_PATH_MAX];
-	char							*filename;
-	double						tolerance;
-	char							xml_input[PCU_PATH_MAX];
-	char							rFile[PCU_PATH_MAX];
-	int							err;
-
-	pcu_docstring( "This test compares a Stiffness matrix against a previously generated stiffness matrix"
-		"The stiffness matrix is generated from a 2D FEM model for a flow with an FrankKamenetskii rheology."
-		"See testFrankKamenetskii2D.xml for the actual xml used"	);
-
-	/* read in the xml input file */
-	pcu_filename_input( "testFrankKamenetskii2D-DualMesh.xml", xml_input );
-	cf = stgMainInitFromXML( xml_input, MPI_COMM_WORLD, NULL );
-	context = (UnderworldContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context" );
-	data->context = context;
-	dictionary = context->dictionary;
-
-	stgMainBuildAndInitialise( cf );
-
-	/* Assemble */
-	stiffnessMatrix = (StiffnessMatrix* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"k_matrix" );
-	sle = (SystemLinearEquations* )       LiveComponentRegister_Get( context->CF->LCRegister, (Name)"stokesEqn" );
-	assert( stiffnessMatrix  );
-	StiffnessMatrix_Assemble( stiffnessMatrix, False, sle, context );
-	stiffnessMatrix = stiffnessMatrix;
-
-	/* Test is to check the relative error between an
-		 1) expected stiffness matrix, (made years ago)
-		 2) the current stiffness matrix.
-
-		 both matricies are built using only an Arrhenius rheology 
-	 */
-
-	filename = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"StiffnessMatrixCompareFilename"  );
-	tolerance = Dictionary_GetDouble_WithDefault( dictionary, (Dictionary_Entry_Key)"StiffnessMatrixCompareTolerance", 1e-4  );
-
-	pcu_filename_expected( filename, expected_file );
-	PetscViewerBinaryOpen( context->communicator, expected_file, FILE_MODE_READ, &expViewer );
-
-	MatLoad( expViewer, MATAIJ, &expected );
-
-	/* 
-		 To view the expected and computed matricies uncomment this
-	PetscViewerASCIIOpen(context->communicator, "numerical.dat",&currViewer);
-	PetscViewerASCIIOpen(context->communicator, "expected.dat",&parallelViewer);
-	MatView( stiffnessMatrix->matrix, currViewer ); //PETSC_VIEWER_STDOUT_WORLD );
-	MatView( expected, parallelViewer ); //PETSC_VIEWER_STDOUT_WORLD );
-	PetscViewerDestroy(currViewer);
-	PetscViewerDestroy(parallelViewer);
-	*/
-
-	MatNorm( expected, NORM_FROBENIUS, &matrixNorm );
-	assert( matrixNorm != 0 );
-
-	MatAXPY( expected, -1, (stiffnessMatrix->matrix) , DIFFERENT_NONZERO_PATTERN );
-	MatNorm( expected, NORM_FROBENIUS, &errorNorm );
-	test = errorNorm / matrixNorm;
-
-	pcu_check_lt( test, tolerance );
-
-	if( data->context->rank == 0 ) {
-		/* Now clean output path */
-		sprintf(rFile, "%s/input.xml", data->context->outputPath );
-		err = remove( rFile );
-		if( err == -1 ) printf("Error in %s, can't delete the input.xml\n", __func__);
-	}
-
-   PetscViewerDestroy( expViewer );
-   MatDestroy( expected);
-	stgMainDestroy( cf );
-}
-
-void ViscousSuite( pcu_suite_t* suite ) {
-   pcu_suite_setData( suite, ViscousSuiteData );
-   pcu_suite_setFixtures( suite, ViscousSuite_Setup, ViscousSuite_Teardown );
-   pcu_suite_addTest( suite, ViscousSuite_ArrheniusStiffnessMatrix2D );
-   pcu_suite_addTest( suite, ViscousSuite_FrankKamenetskiiStiffnessMatrix2D );
-   pcu_suite_addTest( suite, ViscousSuite_MaterialViscosityStiffnessMatrix2D );
-   pcu_suite_addTest( suite, ViscousSuite_ArrheniusStiffnessMatrix2D_DualMesh );
-   pcu_suite_addTest( suite, ViscousSuite_FrankKamenetskiiStiffnessMatrix2D_DualMesh );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/tests/ViscousSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/tests/ViscousSuite.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,446 @@
+#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 "Underworld/Underworld.h"
+
+/* silly stgermain, I must define this */
+#define CURR_MODULE_NAME "UnderworldContext.c"
+
+typedef struct {
+	UnderworldContext* context;
+} ViscousSuiteData;
+
+void ViscousSuite_Setup( ViscousSuiteData* data ) { 
+	data->context=NULL;
+}
+
+void ViscousSuite_Teardown( ViscousSuiteData* data ) {
+}
+
+void ViscousSuite_ArrheniusStiffnessMatrix2D( ViscousSuiteData* data ) {
+	StiffnessMatrix*			stiffnessMatrix;
+	SystemLinearEquations*	sle;
+	Dictionary*					dictionary;
+	UnderworldContext*		context;
+	Stg_ComponentFactory*	cf;
+	PetscViewer					expViewer;
+	PetscReal					matrixNorm, errorNorm, test;
+	Mat							expected;
+	char							expected_file[PCU_PATH_MAX];
+	char							*filename;
+	double						tolerance;
+	char							xml_input[PCU_PATH_MAX];
+	char							rFile[PCU_PATH_MAX];
+	int							err;
+
+
+	pcu_docstring( "This test compares a Stiffness matrix against a previously generated stiffness matrix"
+		"The stiffness matrix is generated from a 2D FEM model for a flow with an Arrhenius rheology."
+		"See testArrhenius2D.xml for the actual xml used"	);
+
+	/* read in the xml input file */
+	pcu_filename_input( "testArrhenius2D.xml", xml_input );
+	cf = stgMainInitFromXML( xml_input, MPI_COMM_WORLD, NULL );
+	context = (UnderworldContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context" );
+	data->context = context;
+	dictionary = context->dictionary;
+
+	stgMainBuildAndInitialise( cf );
+
+	/* Assemble */
+	stiffnessMatrix = (StiffnessMatrix* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"k_matrix" );
+	sle = (SystemLinearEquations* )       LiveComponentRegister_Get( context->CF->LCRegister, (Name)"stokesEqn" );
+	assert( stiffnessMatrix  );
+	StiffnessMatrix_Assemble( stiffnessMatrix, False, sle, context );
+	stiffnessMatrix = stiffnessMatrix;
+
+	/* Test is to check the relative error between an
+		 1) expected stiffness matrix, (made years ago)
+		 2) the current stiffness matrix.
+
+		 both matricies are built using only an Arrhenius rheology 
+	 */
+
+	filename = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"StiffnessMatrixCompareFilename"  );
+	tolerance = Dictionary_GetDouble_WithDefault( dictionary, (Dictionary_Entry_Key)"StiffnessMatrixCompareTolerance", 1e-4  );
+
+	pcu_filename_expected( filename, expected_file );
+	PetscViewerBinaryOpen( context->communicator, expected_file, FILE_MODE_READ, &expViewer );
+
+	MatLoad( expViewer, MATAIJ, &expected );
+
+	/* 
+		 To view the expected and computed matricies uncomment this
+	PetscViewerASCIIOpen(context->communicator, "numerical.dat",&currViewer);
+	PetscViewerASCIIOpen(context->communicator, "expected.dat",&parallelViewer);
+	MatView( stiffnessMatrix->matrix, currViewer ); //PETSC_VIEWER_STDOUT_WORLD );
+	MatView( expected, parallelViewer ); //PETSC_VIEWER_STDOUT_WORLD );
+	PetscViewerDestroy(currViewer);
+	PetscViewerDestroy(parallelViewer);
+	*/
+
+	MatNorm( expected, NORM_FROBENIUS, &matrixNorm );
+	assert( matrixNorm != 0 );
+
+	MatAXPY( expected, -1, (stiffnessMatrix->matrix) , DIFFERENT_NONZERO_PATTERN );
+	MatNorm( expected, NORM_FROBENIUS, &errorNorm );
+	test = errorNorm / matrixNorm;
+
+	pcu_check_lt( test, tolerance );
+
+	if( data->context->rank == 0 ) {
+		/* Now clean output path */
+		sprintf(rFile, "%s/input.xml", data->context->outputPath );
+		err = remove( rFile );
+		if( err == -1 ) printf("Error in %s, can't delete the input.xml\n", __func__);
+	}
+
+   PetscViewerDestroy( expViewer );
+   MatDestroy( expected);
+	stgMainDestroy( cf );
+}
+
+void ViscousSuite_FrankKamenetskiiStiffnessMatrix2D( ViscousSuiteData* data ) {
+	StiffnessMatrix*			stiffnessMatrix;
+	SystemLinearEquations*	sle;
+	Dictionary*					dictionary;
+	UnderworldContext*		context;
+	Stg_ComponentFactory*	cf;
+	PetscViewer					expViewer;
+	PetscReal					matrixNorm, errorNorm, test;
+	Mat							expected;
+	char							expected_file[PCU_PATH_MAX];
+	char							*filename;
+	double						tolerance;
+	char							xml_input[PCU_PATH_MAX];
+	char							rFile[PCU_PATH_MAX];
+	int							err;
+
+	pcu_docstring( "This test compares a Stiffness matrix against a previously generated stiffness matrix"
+		"The stiffness matrix is generated from a 2D FEM model for a flow with an FrankKamenetskii rheology."
+		"See testFrankKamenetskii2D.xml for the actual xml used"	);
+
+	/* read in the xml input file */
+	pcu_filename_input( "testFrankKamenetskii2D.xml", xml_input );
+	cf = stgMainInitFromXML( xml_input, MPI_COMM_WORLD, NULL );
+	context = (UnderworldContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context" );
+	data->context = context;
+	dictionary = context->dictionary;
+
+	stgMainBuildAndInitialise( cf );
+
+	/* Assemble */
+	stiffnessMatrix = (StiffnessMatrix* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"k_matrix" );
+	sle = (SystemLinearEquations* )       LiveComponentRegister_Get( context->CF->LCRegister, (Name)"stokesEqn" );
+	assert( stiffnessMatrix  );
+	StiffnessMatrix_Assemble( stiffnessMatrix, False, sle, context );
+	stiffnessMatrix = stiffnessMatrix;
+
+	/* Test is to check the relative error between an
+		 1) expected stiffness matrix, (made years ago)
+		 2) the current stiffness matrix.
+
+		 both matricies are built using only an Arrhenius rheology 
+	 */
+
+	filename = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"StiffnessMatrixCompareFilename"  );
+	tolerance = Dictionary_GetDouble_WithDefault( dictionary, (Dictionary_Entry_Key)"StiffnessMatrixCompareTolerance", 1e-4  );
+
+	pcu_filename_expected( filename, expected_file );
+	PetscViewerBinaryOpen( context->communicator, expected_file, FILE_MODE_READ, &expViewer );
+
+	MatLoad( expViewer, MATAIJ, &expected );
+
+	/* 
+		 To view the expected and computed matricies uncomment this
+	PetscViewerASCIIOpen(context->communicator, "numerical.dat",&currViewer);
+	PetscViewerASCIIOpen(context->communicator, "expected.dat",&parallelViewer);
+	MatView( stiffnessMatrix->matrix, currViewer ); //PETSC_VIEWER_STDOUT_WORLD );
+	MatView( expected, parallelViewer ); //PETSC_VIEWER_STDOUT_WORLD );
+	PetscViewerDestroy(currViewer);
+	PetscViewerDestroy(parallelViewer);
+	*/
+
+	MatNorm( expected, NORM_FROBENIUS, &matrixNorm );
+	assert( matrixNorm != 0 );
+
+	MatAXPY( expected, -1, (stiffnessMatrix->matrix) , DIFFERENT_NONZERO_PATTERN );
+	MatNorm( expected, NORM_FROBENIUS, &errorNorm );
+	test = errorNorm / matrixNorm;
+
+	pcu_check_lt( test, tolerance );
+
+	if( data->context->rank == 0 ) {
+		/* Now clean output path */
+		sprintf(rFile, "%s/input.xml", data->context->outputPath );
+		err = remove( rFile );
+		if( err == -1 ) printf("Error in %s, can't delete the input.xml\n", __func__);
+	}
+
+   PetscViewerDestroy( expViewer );
+   MatDestroy( expected);
+	stgMainDestroy( cf );
+}
+
+void ViscousSuite_MaterialViscosityStiffnessMatrix2D( ViscousSuiteData* data ) {
+	StiffnessMatrix*			stiffnessMatrix;
+	SystemLinearEquations*	sle;
+	Dictionary*					dictionary;
+	UnderworldContext*		context;
+	Stg_ComponentFactory*	cf;
+	PetscViewer					expViewer/*, parallelViewer, currViewer*/;
+	PetscReal					matrixNorm, errorNorm, test;
+	Mat							expected;
+	char							expected_file[PCU_PATH_MAX];
+	char							*filename;
+	double						tolerance;
+	char							xml_input[PCU_PATH_MAX];
+	char							rFile[PCU_PATH_MAX];
+	int							err;
+
+	pcu_docstring( "This test compares a Stiffness matrix against a previously generated stiffness matrix"
+		"The stiffness matrix is generated from a 2D FEM model for a flow with an constant isoviscous rheology."
+		"See testMaterialViscosity2D.xml for the actual xml used"	);
+
+	/* read in the xml input file */
+	pcu_filename_input( "testMaterialViscosity2D.xml", xml_input );
+	cf = stgMainInitFromXML( xml_input, MPI_COMM_WORLD, NULL );
+	context = (UnderworldContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context" );
+	data->context = context;
+	dictionary = context->dictionary;
+
+	stgMainBuildAndInitialise( cf );
+
+	/* Assemble */
+	stiffnessMatrix = (StiffnessMatrix* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"k_matrix" );
+	sle = (SystemLinearEquations* )       LiveComponentRegister_Get( context->CF->LCRegister, (Name)"stokesEqn" );
+	assert( stiffnessMatrix  );
+	StiffnessMatrix_Assemble( stiffnessMatrix, False, sle, context );
+	stiffnessMatrix = stiffnessMatrix;
+
+/* Test is to check the relative error between an
+	 1) expected stiffness matrix, (made years ago)
+	 2) the current stiffness matrix.
+
+	 both matricies are built using only an Arrhenius rheology 
+ */
+
+	filename = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"StiffnessMatrixCompareFilename"  );
+	tolerance = Dictionary_GetDouble_WithDefault( dictionary, (Dictionary_Entry_Key)"StiffnessMatrixCompareTolerance", 1e-4  );
+
+	pcu_filename_expected( filename, expected_file );
+	PetscViewerBinaryOpen( context->communicator, expected_file, FILE_MODE_READ, &expViewer );
+
+	MatLoad( expViewer, MATAIJ, &expected );
+	/* 
+		 To view the expected and computed matricies uncomment this
+	PetscViewerASCIIOpen(context->communicator, "numerical.dat",&currViewer);
+	PetscViewerASCIIOpen(context->communicator, "expected.dat",&parallelViewer);
+	MatView( stiffnessMatrix->matrix, currViewer ); //PETSC_VIEWER_STDOUT_WORLD );
+	MatView( expected, parallelViewer ); //PETSC_VIEWER_STDOUT_WORLD );
+	PetscViewerDestroy(currViewer);
+	PetscViewerDestroy(parallelViewer);
+	*/
+
+	MatNorm( expected, NORM_FROBENIUS, &matrixNorm );
+	assert( matrixNorm != 0 );
+
+	MatAXPY( expected, -1, (stiffnessMatrix->matrix) , DIFFERENT_NONZERO_PATTERN );
+	MatNorm( expected, NORM_FROBENIUS, &errorNorm );
+	test = errorNorm / matrixNorm;
+
+	pcu_check_lt( test, tolerance );
+
+	if( data->context->rank == 0 ) {
+		/* Now clean output path */
+		sprintf(rFile, "%s/input.xml", data->context->outputPath );
+		err = remove( rFile );
+		if( err == -1 ) printf("Error in %s, can't delete the input.xml\n", __func__);
+	}
+
+   PetscViewerDestroy( expViewer );
+   MatDestroy( expected);
+	stgMainDestroy( cf );
+}
+
+void ViscousSuite_ArrheniusStiffnessMatrix2D_DualMesh( ViscousSuiteData* data ) {
+	StiffnessMatrix*			stiffnessMatrix;
+	SystemLinearEquations*	sle;
+	Dictionary*					dictionary;
+	UnderworldContext*		context;
+	Stg_ComponentFactory*	cf;
+	PetscViewer					expViewer;
+	PetscReal					matrixNorm, errorNorm, test;
+	Mat							expected;
+	char							expected_file[PCU_PATH_MAX];
+	char							*filename;
+	double						tolerance;
+	char							xml_input[PCU_PATH_MAX];
+	char							rFile[PCU_PATH_MAX];
+	int							err;
+
+	pcu_docstring( "This test compares a Stiffness matrix against a previously generated stiffness matrix"
+		"The stiffness matrix is generated from a 2D FEM model for a flow with an FrankKamenetskii rheology."
+		"See testFrankKamenetskii2D.xml for the actual xml used"	);
+
+	/* read in the xml input file */
+	pcu_filename_input( "testArrhenius2D-DualMesh.xml", xml_input );
+	cf = stgMainInitFromXML( xml_input, MPI_COMM_WORLD, NULL );
+	context = (UnderworldContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context" );
+	data->context = context;
+	dictionary = context->dictionary;
+
+	stgMainBuildAndInitialise( cf );
+
+	/* Assemble */
+	stiffnessMatrix = (StiffnessMatrix* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"k_matrix" );
+	sle = (SystemLinearEquations* )       LiveComponentRegister_Get( context->CF->LCRegister, (Name)"stokesEqn" );
+	assert( stiffnessMatrix  );
+	StiffnessMatrix_Assemble( stiffnessMatrix, False, sle, context );
+	stiffnessMatrix = stiffnessMatrix;
+
+	/* Test is to check the relative error between an
+		 1) expected stiffness matrix, (made years ago)
+		 2) the current stiffness matrix.
+
+		 both matricies are built using only an Arrhenius rheology 
+	 */
+
+	filename = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"StiffnessMatrixCompareFilename"  );
+	tolerance = Dictionary_GetDouble_WithDefault( dictionary, (Dictionary_Entry_Key)"StiffnessMatrixCompareTolerance", 1e-4  );
+
+	pcu_filename_expected( filename, expected_file );
+	PetscViewerBinaryOpen( context->communicator, expected_file, FILE_MODE_READ, &expViewer );
+
+	MatLoad( expViewer, MATAIJ, &expected );
+
+	/* 
+		 To view the expected and computed matricies uncomment this
+	PetscViewerASCIIOpen(context->communicator, "numerical.dat",&currViewer);
+	PetscViewerASCIIOpen(context->communicator, "expected.dat",&parallelViewer);
+	MatView( stiffnessMatrix->matrix, currViewer ); //PETSC_VIEWER_STDOUT_WORLD );
+	MatView( expected, parallelViewer ); //PETSC_VIEWER_STDOUT_WORLD );
+	PetscViewerDestroy(currViewer);
+	PetscViewerDestroy(parallelViewer);
+	*/
+
+	MatNorm( expected, NORM_FROBENIUS, &matrixNorm );
+	assert( matrixNorm != 0 );
+
+	MatAXPY( expected, -1, (stiffnessMatrix->matrix) , DIFFERENT_NONZERO_PATTERN );
+	MatNorm( expected, NORM_FROBENIUS, &errorNorm );
+	test = errorNorm / matrixNorm;
+
+	pcu_check_lt( test, tolerance );
+
+	if( data->context->rank == 0 ) {
+		/* Now clean output path */
+		sprintf(rFile, "%s/input.xml", data->context->outputPath );
+		err = remove( rFile );
+		if( err == -1 ) printf("Error in %s, can't delete the input.xml\n", __func__);
+	}
+
+   PetscViewerDestroy( expViewer );
+   MatDestroy( expected);
+	stgMainDestroy( cf );
+}
+
+void ViscousSuite_FrankKamenetskiiStiffnessMatrix2D_DualMesh( ViscousSuiteData* data ) {
+	StiffnessMatrix*			stiffnessMatrix;
+	SystemLinearEquations*	sle;
+	Dictionary*					dictionary;
+	UnderworldContext*		context;
+	Stg_ComponentFactory*	cf;
+	PetscViewer					expViewer;
+	PetscReal					matrixNorm, errorNorm, test;
+	Mat							expected;
+	char							expected_file[PCU_PATH_MAX];
+	char							*filename;
+	double						tolerance;
+	char							xml_input[PCU_PATH_MAX];
+	char							rFile[PCU_PATH_MAX];
+	int							err;
+
+	pcu_docstring( "This test compares a Stiffness matrix against a previously generated stiffness matrix"
+		"The stiffness matrix is generated from a 2D FEM model for a flow with an FrankKamenetskii rheology."
+		"See testFrankKamenetskii2D.xml for the actual xml used"	);
+
+	/* read in the xml input file */
+	pcu_filename_input( "testFrankKamenetskii2D-DualMesh.xml", xml_input );
+	cf = stgMainInitFromXML( xml_input, MPI_COMM_WORLD, NULL );
+	context = (UnderworldContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context" );
+	data->context = context;
+	dictionary = context->dictionary;
+
+	stgMainBuildAndInitialise( cf );
+
+	/* Assemble */
+	stiffnessMatrix = (StiffnessMatrix* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"k_matrix" );
+	sle = (SystemLinearEquations* )       LiveComponentRegister_Get( context->CF->LCRegister, (Name)"stokesEqn" );
+	assert( stiffnessMatrix  );
+	StiffnessMatrix_Assemble( stiffnessMatrix, False, sle, context );
+	stiffnessMatrix = stiffnessMatrix;
+
+	/* Test is to check the relative error between an
+		 1) expected stiffness matrix, (made years ago)
+		 2) the current stiffness matrix.
+
+		 both matricies are built using only an Arrhenius rheology 
+	 */
+
+	filename = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"StiffnessMatrixCompareFilename"  );
+	tolerance = Dictionary_GetDouble_WithDefault( dictionary, (Dictionary_Entry_Key)"StiffnessMatrixCompareTolerance", 1e-4  );
+
+	pcu_filename_expected( filename, expected_file );
+	PetscViewerBinaryOpen( context->communicator, expected_file, FILE_MODE_READ, &expViewer );
+
+	MatLoad( expViewer, MATAIJ, &expected );
+
+	/* 
+		 To view the expected and computed matricies uncomment this
+	PetscViewerASCIIOpen(context->communicator, "numerical.dat",&currViewer);
+	PetscViewerASCIIOpen(context->communicator, "expected.dat",&parallelViewer);
+	MatView( stiffnessMatrix->matrix, currViewer ); //PETSC_VIEWER_STDOUT_WORLD );
+	MatView( expected, parallelViewer ); //PETSC_VIEWER_STDOUT_WORLD );
+	PetscViewerDestroy(currViewer);
+	PetscViewerDestroy(parallelViewer);
+	*/
+
+	MatNorm( expected, NORM_FROBENIUS, &matrixNorm );
+	assert( matrixNorm != 0 );
+
+	MatAXPY( expected, -1, (stiffnessMatrix->matrix) , DIFFERENT_NONZERO_PATTERN );
+	MatNorm( expected, NORM_FROBENIUS, &errorNorm );
+	test = errorNorm / matrixNorm;
+
+	pcu_check_lt( test, tolerance );
+
+	if( data->context->rank == 0 ) {
+		/* Now clean output path */
+		sprintf(rFile, "%s/input.xml", data->context->outputPath );
+		err = remove( rFile );
+		if( err == -1 ) printf("Error in %s, can't delete the input.xml\n", __func__);
+	}
+
+   PetscViewerDestroy( expViewer );
+   MatDestroy( expected);
+	stgMainDestroy( cf );
+}
+
+void ViscousSuite( pcu_suite_t* suite ) {
+   pcu_suite_setData( suite, ViscousSuiteData );
+   pcu_suite_setFixtures( suite, ViscousSuite_Setup, ViscousSuite_Teardown );
+   pcu_suite_addTest( suite, ViscousSuite_ArrheniusStiffnessMatrix2D );
+   pcu_suite_addTest( suite, ViscousSuite_FrankKamenetskiiStiffnessMatrix2D );
+   pcu_suite_addTest( suite, ViscousSuite_MaterialViscosityStiffnessMatrix2D );
+   pcu_suite_addTest( suite, ViscousSuite_ArrheniusStiffnessMatrix2D_DualMesh );
+   pcu_suite_addTest( suite, ViscousSuite_FrankKamenetskiiStiffnessMatrix2D_DualMesh );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/tests/VonMisesYieldingSuite.c
--- a/Rheology/tests/VonMisesYieldingSuite.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,189 +0,0 @@
-#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 "Underworld/Underworld.h"
-
-/* silly stgermain, I must define this */
-#define CURR_MODULE_NAME "UnderworldContext.c"
-
-const Type Underworld_testVonMisesYielding_Type = "Underworld_testVonMisesYielding";
-
-/* Define plugin structure */
-typedef struct {
-	__Codelet
-	YieldRheology_HasYieldedFunction* realHasYieldedFunction;
-	FeMesh* 		          mesh;
-	XYZ                   min;
-	XYZ                   max;
-	Bool                  hasYielded;
-} Underworld_testVonMisesYielding;
-
-/* define global vars .... that's very ugly, but it's only a pcu test */
-Underworld_testVonMisesYielding VMYS_globalSelf;
-
-typedef struct {
-} VonMisesYieldingSuiteData;
-
-void VonMisesYieldingSuite_Setup( VonMisesYieldingSuiteData* data ) { 
-}
-
-void VonMisesYieldingSuite_Teardown( VonMisesYieldingSuiteData* data ) {
-}
-
-double Underworld_testVonMisesYielding_dt( FiniteElementContext* context ) {
-	if ( context->currentTime >= 0.65 ) {
-		return 0.01;
-	}
-	return HUGE_VAL;
-}
-
-void testVonMisesYielding_HasYielded( 
-		void*                            yieldRheology,
-		ConstitutiveMatrix*              constitutiveMatrix,
-		MaterialPointsSwarm*             materialPointsSwarm,
-		Element_LocalIndex               lElement_I,
-		MaterialPoint*                   materialPoint,
-		double                           yieldCriterion,
-		double                           yieldIndicator ) 
-{
-	Dimension_Index dim_I;
-
-	/* Call real 'HasYielded' function */
-	VMYS_globalSelf.realHasYieldedFunction( 
-			yieldRheology, constitutiveMatrix, materialPointsSwarm, lElement_I, materialPoint, yieldCriterion, yieldIndicator );
-
-	/* Don't output information if this is the first non-linear iteration */
-	if ( constitutiveMatrix->sleNonLinearIteration_I == 0 ) {
-		return;
-	}
-
-	/* Store information */
-	VMYS_globalSelf.hasYielded = True;
-	for ( dim_I = 0 ; dim_I < constitutiveMatrix->dim ; dim_I++ ) {
-		if ( materialPoint->coord[ dim_I ] < VMYS_globalSelf.min[ dim_I ] )
-			VMYS_globalSelf.min[ dim_I ] = materialPoint->coord[ dim_I ];
-		if ( materialPoint->coord[ dim_I ] > VMYS_globalSelf.max[ dim_I ] )
-			VMYS_globalSelf.max[ dim_I ] = materialPoint->coord[ dim_I ];
-	}
-}
-
-
-void Underworld_testVonMisesYielding_Check( FiniteElementContext* context ) {
-	Stream* stream = Journal_Register( Dump_Type, (Name)Underworld_testVonMisesYielding_Type );
-
-   if(context->rank == 0){
-      /* Don't do anything if nothing has yielded yet */
-      if ( !VMYS_globalSelf.hasYielded ) {
-         return;
-      }
-   
-      /* Set the stream to point to our output file (so we can do a diff on it later ) */
-      Stream_Enable( stream, True );
-      Stream_RedirectFile_WithPrependedPath( stream, context->outputPath, "testVonMisesYielding.dat" );
-   
-      Journal_Printf( stream, "Material yielded at time %12.4g (step %u) within:\n", context->currentTime, context->timeStep ); 
-   
-      /* Output information */
-      Journal_Printf( stream, "\tx: %12.4g - %12.4g\n", VMYS_globalSelf.min[ I_AXIS ], VMYS_globalSelf.max[ I_AXIS ] );
-      Journal_Printf( stream, "\ty: %12.4g - %12.4g\n", VMYS_globalSelf.min[ J_AXIS ], VMYS_globalSelf.max[ J_AXIS ] );
-      if ( context->dim == 3 ) {
-         Journal_Printf( stream, "\tz: %12.4g - %12.4g\n", VMYS_globalSelf.min[ K_AXIS ], VMYS_globalSelf.max[ K_AXIS ] );
-      }
-      Stream_CloseAndFreeFile( stream );
-   }
-}
-
-void Underworld_testVonMisesYielding_Check_Sync( FiniteElementContext* context ) {
-   Coord mins;
-   Coord maxs;
-   
-   /* get true global max/min */
-
-   MPI_Allreduce( &VMYS_globalSelf.min[ I_AXIS ], &mins[I_AXIS], 1, MPI_DOUBLE, MPI_MIN, context->communicator );
-   MPI_Allreduce( &VMYS_globalSelf.min[ J_AXIS ], &mins[J_AXIS], 1, MPI_DOUBLE, MPI_MIN, context->communicator );
-   if ( context->dim == 3 )
-      MPI_Allreduce( &VMYS_globalSelf.min[ K_AXIS ], &mins[K_AXIS], 1, MPI_DOUBLE, MPI_MIN, context->communicator );
-
-   MPI_Allreduce( &VMYS_globalSelf.max[ I_AXIS ], &maxs[I_AXIS], 1, MPI_DOUBLE, MPI_MAX, context->communicator );
-   MPI_Allreduce( &VMYS_globalSelf.max[ J_AXIS ], &maxs[J_AXIS], 1, MPI_DOUBLE, MPI_MAX, context->communicator );
-   if ( context->dim == 3 )
-      MPI_Allreduce( &VMYS_globalSelf.max[ K_AXIS ], &maxs[K_AXIS], 1, MPI_DOUBLE, MPI_MAX, context->communicator );
-   
-   /* now set to these values */
-   VMYS_globalSelf.min[ I_AXIS ] = mins[ I_AXIS ];
-   VMYS_globalSelf.min[ J_AXIS ] = mins[ J_AXIS ];
-   if ( context->dim == 3 )
-      VMYS_globalSelf.min[ K_AXIS ] = mins[ K_AXIS ];
-   VMYS_globalSelf.max[ I_AXIS ] = maxs[ I_AXIS ];
-   VMYS_globalSelf.max[ J_AXIS ] = maxs[ J_AXIS ];
-   if ( context->dim == 3 )
-      VMYS_globalSelf.max[ K_AXIS ] = maxs[ K_AXIS ];
-}
-
-
-void VonMisesYieldingSuite_VonMises2D( VonMisesYieldingSuiteData* data ) {
-	UnderworldContext* context;
-	Dictionary*					dictionary;
-	YieldRheology*          yieldRheology;
-	Stg_ComponentFactory*	cf;
-	char							expected_file[PCU_PATH_MAX];
-	char							xml_input[PCU_PATH_MAX];
-
-	/* read in the xml input file */
-	pcu_filename_input( "testVonMisesYieldCriterion.xml", xml_input );
-	cf = stgMainInitFromXML( xml_input, MPI_COMM_WORLD, NULL );
-	context = (UnderworldContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context" );
-	dictionary = context->dictionary;
-
-	stgMainBuildAndInitialise( cf  );
-
-	/* get pointer to the mesh */
-	VMYS_globalSelf.mesh = Stg_ComponentFactory_ConstructByName( cf, (Name)"linearMesh", FeMesh, True, NULL ); 
-	
-	/* Get a pointer the yield rheology that we are trying to test */
-	yieldRheology = (YieldRheology* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"yieldRheology"  );
-	
-	/* Store the pointer to the original 'HasYielded' function */
-	VMYS_globalSelf.realHasYieldedFunction = yieldRheology->_hasYielded;
-
-	/* Reset this function pointer with our own */
-	yieldRheology->_hasYielded = testVonMisesYielding_HasYielded;
-
-   ContextEP_Append( context, AbstractContext_EP_Step, Underworld_testVonMisesYielding_Check_Sync );
-	ContextEP_Append( context, AbstractContext_EP_Step, Underworld_testVonMisesYielding_Check );
-	EP_AppendClassHook( Context_GetEntryPoint( context, FiniteElementContext_EP_CalcDt ), Underworld_testVonMisesYielding_dt, context );
-
-	VMYS_globalSelf.min[ I_AXIS ] =  HUGE_VAL;
-	VMYS_globalSelf.min[ J_AXIS ] =  HUGE_VAL;
-	VMYS_globalSelf.min[ K_AXIS ] =  HUGE_VAL;
-	VMYS_globalSelf.max[ I_AXIS ] = -HUGE_VAL;
-	VMYS_globalSelf.max[ J_AXIS ] = -HUGE_VAL;
-	VMYS_globalSelf.max[ K_AXIS ] = -HUGE_VAL;
-
-	stgMainLoop( cf );
-
-	MPI_Barrier( context->communicator );
-	pcu_filename_expected( "testVonMisesYieldCriterion.expected", expected_file );
-	pcu_check_fileEq( "output/testVonMisesYielding.dat", expected_file );
-
-	if(context->rank == 0){
-      remove("output/testVonMisesYielding.dat");
-      remove("output");
-   }
-
-	stgMainDestroy( cf );
-}
-
-void VonMisesYieldingSuite( pcu_suite_t* suite ) {
-   pcu_suite_setData( suite, VonMisesYieldingSuiteData );
-   pcu_suite_setFixtures( suite, VonMisesYieldingSuite_Setup, VonMisesYieldingSuite_Teardown );
-   pcu_suite_addTest( suite, VonMisesYieldingSuite_VonMises2D );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/tests/VonMisesYieldingSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/tests/VonMisesYieldingSuite.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,189 @@
+#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 "Underworld/Underworld.h"
+
+/* silly stgermain, I must define this */
+#define CURR_MODULE_NAME "UnderworldContext.c"
+
+const Type Underworld_testVonMisesYielding_Type = "Underworld_testVonMisesYielding";
+
+/* Define plugin structure */
+typedef struct {
+	__Codelet
+	YieldRheology_HasYieldedFunction* realHasYieldedFunction;
+	FeMesh* 		          mesh;
+	XYZ                   min;
+	XYZ                   max;
+	Bool                  hasYielded;
+} Underworld_testVonMisesYielding;
+
+/* define global vars .... that's very ugly, but it's only a pcu test */
+Underworld_testVonMisesYielding VMYS_globalSelf;
+
+typedef struct {
+} VonMisesYieldingSuiteData;
+
+void VonMisesYieldingSuite_Setup( VonMisesYieldingSuiteData* data ) { 
+}
+
+void VonMisesYieldingSuite_Teardown( VonMisesYieldingSuiteData* data ) {
+}
+
+double Underworld_testVonMisesYielding_dt( FiniteElementContext* context ) {
+	if ( context->currentTime >= 0.65 ) {
+		return 0.01;
+	}
+	return HUGE_VAL;
+}
+
+void testVonMisesYielding_HasYielded( 
+		void*                            yieldRheology,
+		ConstitutiveMatrix*              constitutiveMatrix,
+		MaterialPointsSwarm*             materialPointsSwarm,
+		Element_LocalIndex               lElement_I,
+		MaterialPoint*                   materialPoint,
+		double                           yieldCriterion,
+		double                           yieldIndicator ) 
+{
+	Dimension_Index dim_I;
+
+	/* Call real 'HasYielded' function */
+	VMYS_globalSelf.realHasYieldedFunction( 
+			yieldRheology, constitutiveMatrix, materialPointsSwarm, lElement_I, materialPoint, yieldCriterion, yieldIndicator );
+
+	/* Don't output information if this is the first non-linear iteration */
+	if ( constitutiveMatrix->sleNonLinearIteration_I == 0 ) {
+		return;
+	}
+
+	/* Store information */
+	VMYS_globalSelf.hasYielded = True;
+	for ( dim_I = 0 ; dim_I < constitutiveMatrix->dim ; dim_I++ ) {
+		if ( materialPoint->coord[ dim_I ] < VMYS_globalSelf.min[ dim_I ] )
+			VMYS_globalSelf.min[ dim_I ] = materialPoint->coord[ dim_I ];
+		if ( materialPoint->coord[ dim_I ] > VMYS_globalSelf.max[ dim_I ] )
+			VMYS_globalSelf.max[ dim_I ] = materialPoint->coord[ dim_I ];
+	}
+}
+
+
+void Underworld_testVonMisesYielding_Check( FiniteElementContext* context ) {
+	Stream* stream = Journal_Register( Dump_Type, (Name)Underworld_testVonMisesYielding_Type );
+
+   if(context->rank == 0){
+      /* Don't do anything if nothing has yielded yet */
+      if ( !VMYS_globalSelf.hasYielded ) {
+         return;
+      }
+   
+      /* Set the stream to point to our output file (so we can do a diff on it later ) */
+      Stream_Enable( stream, True );
+      Stream_RedirectFile_WithPrependedPath( stream, context->outputPath, "testVonMisesYielding.dat" );
+   
+      Journal_Printf( stream, "Material yielded at time %12.4g (step %u) within:\n", context->currentTime, context->timeStep ); 
+   
+      /* Output information */
+      Journal_Printf( stream, "\tx: %12.4g - %12.4g\n", VMYS_globalSelf.min[ I_AXIS ], VMYS_globalSelf.max[ I_AXIS ] );
+      Journal_Printf( stream, "\ty: %12.4g - %12.4g\n", VMYS_globalSelf.min[ J_AXIS ], VMYS_globalSelf.max[ J_AXIS ] );
+      if ( context->dim == 3 ) {
+         Journal_Printf( stream, "\tz: %12.4g - %12.4g\n", VMYS_globalSelf.min[ K_AXIS ], VMYS_globalSelf.max[ K_AXIS ] );
+      }
+      Stream_CloseAndFreeFile( stream );
+   }
+}
+
+void Underworld_testVonMisesYielding_Check_Sync( FiniteElementContext* context ) {
+   Coord mins;
+   Coord maxs;
+   
+   /* get true global max/min */
+
+   MPI_Allreduce( &VMYS_globalSelf.min[ I_AXIS ], &mins[I_AXIS], 1, MPI_DOUBLE, MPI_MIN, context->communicator );
+   MPI_Allreduce( &VMYS_globalSelf.min[ J_AXIS ], &mins[J_AXIS], 1, MPI_DOUBLE, MPI_MIN, context->communicator );
+   if ( context->dim == 3 )
+      MPI_Allreduce( &VMYS_globalSelf.min[ K_AXIS ], &mins[K_AXIS], 1, MPI_DOUBLE, MPI_MIN, context->communicator );
+
+   MPI_Allreduce( &VMYS_globalSelf.max[ I_AXIS ], &maxs[I_AXIS], 1, MPI_DOUBLE, MPI_MAX, context->communicator );
+   MPI_Allreduce( &VMYS_globalSelf.max[ J_AXIS ], &maxs[J_AXIS], 1, MPI_DOUBLE, MPI_MAX, context->communicator );
+   if ( context->dim == 3 )
+      MPI_Allreduce( &VMYS_globalSelf.max[ K_AXIS ], &maxs[K_AXIS], 1, MPI_DOUBLE, MPI_MAX, context->communicator );
+   
+   /* now set to these values */
+   VMYS_globalSelf.min[ I_AXIS ] = mins[ I_AXIS ];
+   VMYS_globalSelf.min[ J_AXIS ] = mins[ J_AXIS ];
+   if ( context->dim == 3 )
+      VMYS_globalSelf.min[ K_AXIS ] = mins[ K_AXIS ];
+   VMYS_globalSelf.max[ I_AXIS ] = maxs[ I_AXIS ];
+   VMYS_globalSelf.max[ J_AXIS ] = maxs[ J_AXIS ];
+   if ( context->dim == 3 )
+      VMYS_globalSelf.max[ K_AXIS ] = maxs[ K_AXIS ];
+}
+
+
+void VonMisesYieldingSuite_VonMises2D( VonMisesYieldingSuiteData* data ) {
+	UnderworldContext* context;
+	Dictionary*					dictionary;
+	YieldRheology*          yieldRheology;
+	Stg_ComponentFactory*	cf;
+	char							expected_file[PCU_PATH_MAX];
+	char							xml_input[PCU_PATH_MAX];
+
+	/* read in the xml input file */
+	pcu_filename_input( "testVonMisesYieldCriterion.xml", xml_input );
+	cf = stgMainInitFromXML( xml_input, MPI_COMM_WORLD, NULL );
+	context = (UnderworldContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context" );
+	dictionary = context->dictionary;
+
+	stgMainBuildAndInitialise( cf  );
+
+	/* get pointer to the mesh */
+	VMYS_globalSelf.mesh = Stg_ComponentFactory_ConstructByName( cf, (Name)"linearMesh", FeMesh, True, NULL ); 
+	
+	/* Get a pointer the yield rheology that we are trying to test */
+	yieldRheology = (YieldRheology* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"yieldRheology"  );
+	
+	/* Store the pointer to the original 'HasYielded' function */
+	VMYS_globalSelf.realHasYieldedFunction = yieldRheology->_hasYielded;
+
+	/* Reset this function pointer with our own */
+	yieldRheology->_hasYielded = testVonMisesYielding_HasYielded;
+
+   ContextEP_Append( context, AbstractContext_EP_Step, Underworld_testVonMisesYielding_Check_Sync );
+	ContextEP_Append( context, AbstractContext_EP_Step, Underworld_testVonMisesYielding_Check );
+	EP_AppendClassHook( Context_GetEntryPoint( context, FiniteElementContext_EP_CalcDt ), Underworld_testVonMisesYielding_dt, context );
+
+	VMYS_globalSelf.min[ I_AXIS ] =  HUGE_VAL;
+	VMYS_globalSelf.min[ J_AXIS ] =  HUGE_VAL;
+	VMYS_globalSelf.min[ K_AXIS ] =  HUGE_VAL;
+	VMYS_globalSelf.max[ I_AXIS ] = -HUGE_VAL;
+	VMYS_globalSelf.max[ J_AXIS ] = -HUGE_VAL;
+	VMYS_globalSelf.max[ K_AXIS ] = -HUGE_VAL;
+
+	stgMainLoop( cf );
+
+	MPI_Barrier( context->communicator );
+	pcu_filename_expected( "testVonMisesYieldCriterion.expected", expected_file );
+	pcu_check_fileEq( "output/testVonMisesYielding.dat", expected_file );
+
+	if(context->rank == 0){
+      remove("output/testVonMisesYielding.dat");
+      remove("output");
+   }
+
+	stgMainDestroy( cf );
+}
+
+void VonMisesYieldingSuite( pcu_suite_t* suite ) {
+   pcu_suite_setData( suite, VonMisesYieldingSuiteData );
+   pcu_suite_setFixtures( suite, VonMisesYieldingSuite_Setup, VonMisesYieldingSuite_Teardown );
+   pcu_suite_addTest( suite, VonMisesYieldingSuite_VonMises2D );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Rheology/tests/testYieldCriterion/testYieldCriterion.c
--- a/Rheology/tests/testYieldCriterion/testYieldCriterion.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,153 +0,0 @@
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Rheology/Rheology.h>
-
-#include <assert.h>
-
-const Type Underworld_testYieldCriterion_Type = "Underworld_testYieldCriterion";
-
-/* Define plugin structure */
-typedef struct {
-	__Codelet
-	YieldRheology_HasYieldedFunction* realHasYieldedFunction;
-	FeMesh* 		          mesh;
-	XYZ                               min;
-	XYZ                               max;
-	Bool                              hasYielded;
-} Underworld_testYieldCriterion;
-	
-FiniteElementContext*   context;
-
-void testYieldCriterion_HasYielded( 
-		void*                            yieldRheology,
-		ConstitutiveMatrix*              constitutiveMatrix,
-		MaterialPointsSwarm*             materialPointsSwarm,
-		Element_LocalIndex               lElement_I,
-		MaterialPoint*                   materialPoint,
-		double                           yieldCriterion,
-		double                           yieldIndicator ) 
-{
-	Underworld_testYieldCriterion* self;
-	Dimension_Index dim_I;
-
-	/* Get pointer to plugin struct */
-	self = (Underworld_testYieldCriterion*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_testYieldCriterion_Type  );
-
-	/* Call real 'HasYielded' function */
-	self->realHasYieldedFunction( 
-			yieldRheology, constitutiveMatrix, materialPointsSwarm, lElement_I, materialPoint, yieldCriterion, yieldIndicator );
-
-	/* Don't output information if this is the first non-linear iteration */
-	if ( constitutiveMatrix->sleNonLinearIteration_I == 0 ) {
-		return;
-	}
-
-	/* Store information */
-	self->hasYielded = True;
-	for ( dim_I = 0 ; dim_I < context->dim ; dim_I++ ) {
-		if ( materialPoint->coord[ dim_I ] < self->min[ dim_I ] )
-			self->min[ dim_I ] = materialPoint->coord[ dim_I ];
-		if ( materialPoint->coord[ dim_I ] > self->max[ dim_I ] )
-			self->max[ dim_I ] = materialPoint->coord[ dim_I ];
-	}
-}
-
-double Underworld_testYieldCriterion_dt( FiniteElementContext* context ) {
-	if ( context->currentTime >= 0.65 ) {
-		return 0.01;
-	}
-	return HUGE_VAL;
-}
-
-void Underworld_testYieldCriterion_Check( FiniteElementContext* context ) {
-	Stream* stream = Journal_Register( Dump_Type, (Name)Underworld_testYieldCriterion_Type );
-	Underworld_testYieldCriterion* self;
-
-	/* Get pointer to plugin struct */
-	self = (Underworld_testYieldCriterion* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_testYieldCriterion_Type );
-	assert( self );
-
-	/* Don't do anything if nothing has yielded yet */
-	if ( !self->hasYielded ) {
-		return;
-	}
-
-	/* Get Calculation to stop */
-	context->maxTimeSteps = context->timeStep;
-
-	/* Set the stream to point to our output file (so we can do a diff on it later ) */
-	Stream_Enable( stream, True );
-	Stream_RedirectFile_WithPrependedPath( stream, context->outputPath, "testYieldCriterion.dat" );
-
-	Journal_Printf( stream, "Material yielded at time %4g (step %u) within:\n", context->currentTime, context->timeStep ); 
-
-	/* Output information */
-	Journal_Printf( stream, "\tx: %12.4g - %12.4g\n", self->min[ I_AXIS ], self->max[ I_AXIS ] );
-	Journal_Printf( stream, "\ty: %12.4g - %12.4g\n", self->min[ J_AXIS ], self->max[ J_AXIS ] );
-	if ( context->dim == 3 ) {
-		Journal_Printf( stream, "\tz: %12.4g - %12.4g\n", self->min[ K_AXIS ], self->max[ K_AXIS ] );
-	}
-}
-
-void _Underworld_testYieldCriterion_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
-	YieldRheology*          yieldRheology;
-	Underworld_testYieldCriterion* self;
-
-	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", FiniteElementContext, True, data ); 
-
-	/* Get pointer to plugin struct */
-	self = (Underworld_testYieldCriterion* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_testYieldCriterion_Type  );
-
-	/* get pointer to the mesh */
-	self->mesh = Stg_ComponentFactory_ConstructByName( cf, (Name)"linearMesh", FeMesh, True, data ); 
-	
-	/* Get a pointer the yield rheology that we are trying to test */
-	yieldRheology = (YieldRheology* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"yieldRheology"  );
-	
-	/* Store the pointer to the original 'HasYielded' function */
-	self->realHasYieldedFunction = yieldRheology->_hasYielded;
-
-	/* Reset this function pointer with our own */
-	yieldRheology->_hasYielded = testYieldCriterion_HasYielded;
-
-	ContextEP_Append( context, AbstractContext_EP_Step, Underworld_testYieldCriterion_Check );
-	EP_AppendClassHook( Context_GetEntryPoint( context, FiniteElementContext_EP_CalcDt ), 
-			Underworld_testYieldCriterion_dt, context );
-
-	self->min[ I_AXIS ] = HUGE_VAL;
-	self->min[ J_AXIS ] = HUGE_VAL;
-	self->min[ K_AXIS ] = HUGE_VAL;
-	self->max[ I_AXIS ] = -HUGE_VAL;
-	self->max[ J_AXIS ] = -HUGE_VAL;
-	self->max[ K_AXIS ] = -HUGE_VAL;
-}
-
-void* _Underworld_testYieldCriterion_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof( Underworld_testYieldCriterion );
-	Type                                                      type = Underworld_testYieldCriterion_Type;
-	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
-	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
-	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_testYieldCriterion_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Underworld_testYieldCriterion_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 Underworld_testYieldCriterion_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Underworld_testYieldCriterion_Type, (Name)"0", _Underworld_testYieldCriterion_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Rheology/tests/testYieldCriterion/testYieldCriterion.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rheology/tests/testYieldCriterion/testYieldCriterion.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,153 @@
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Rheology/Rheology.h>
+
+#include <assert.h>
+
+const Type Underworld_testYieldCriterion_Type = "Underworld_testYieldCriterion";
+
+/* Define plugin structure */
+typedef struct {
+	__Codelet
+	YieldRheology_HasYieldedFunction* realHasYieldedFunction;
+	FeMesh* 		          mesh;
+	XYZ                               min;
+	XYZ                               max;
+	Bool                              hasYielded;
+} Underworld_testYieldCriterion;
+	
+FiniteElementContext*   context;
+
+void testYieldCriterion_HasYielded( 
+		void*                            yieldRheology,
+		ConstitutiveMatrix*              constitutiveMatrix,
+		MaterialPointsSwarm*             materialPointsSwarm,
+		Element_LocalIndex               lElement_I,
+		MaterialPoint*                   materialPoint,
+		double                           yieldCriterion,
+		double                           yieldIndicator ) 
+{
+	Underworld_testYieldCriterion* self;
+	Dimension_Index dim_I;
+
+	/* Get pointer to plugin struct */
+	self = (Underworld_testYieldCriterion*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_testYieldCriterion_Type  );
+
+	/* Call real 'HasYielded' function */
+	self->realHasYieldedFunction( 
+			yieldRheology, constitutiveMatrix, materialPointsSwarm, lElement_I, materialPoint, yieldCriterion, yieldIndicator );
+
+	/* Don't output information if this is the first non-linear iteration */
+	if ( constitutiveMatrix->sleNonLinearIteration_I == 0 ) {
+		return;
+	}
+
+	/* Store information */
+	self->hasYielded = True;
+	for ( dim_I = 0 ; dim_I < context->dim ; dim_I++ ) {
+		if ( materialPoint->coord[ dim_I ] < self->min[ dim_I ] )
+			self->min[ dim_I ] = materialPoint->coord[ dim_I ];
+		if ( materialPoint->coord[ dim_I ] > self->max[ dim_I ] )
+			self->max[ dim_I ] = materialPoint->coord[ dim_I ];
+	}
+}
+
+double Underworld_testYieldCriterion_dt( FiniteElementContext* context ) {
+	if ( context->currentTime >= 0.65 ) {
+		return 0.01;
+	}
+	return HUGE_VAL;
+}
+
+void Underworld_testYieldCriterion_Check( FiniteElementContext* context ) {
+	Stream* stream = Journal_Register( Dump_Type, (Name)Underworld_testYieldCriterion_Type );
+	Underworld_testYieldCriterion* self;
+
+	/* Get pointer to plugin struct */
+	self = (Underworld_testYieldCriterion* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_testYieldCriterion_Type );
+	assert( self );
+
+	/* Don't do anything if nothing has yielded yet */
+	if ( !self->hasYielded ) {
+		return;
+	}
+
+	/* Get Calculation to stop */
+	context->maxTimeSteps = context->timeStep;
+
+	/* Set the stream to point to our output file (so we can do a diff on it later ) */
+	Stream_Enable( stream, True );
+	Stream_RedirectFile_WithPrependedPath( stream, context->outputPath, "testYieldCriterion.dat" );
+
+	Journal_Printf( stream, "Material yielded at time %4g (step %u) within:\n", context->currentTime, context->timeStep ); 
+
+	/* Output information */
+	Journal_Printf( stream, "\tx: %12.4g - %12.4g\n", self->min[ I_AXIS ], self->max[ I_AXIS ] );
+	Journal_Printf( stream, "\ty: %12.4g - %12.4g\n", self->min[ J_AXIS ], self->max[ J_AXIS ] );
+	if ( context->dim == 3 ) {
+		Journal_Printf( stream, "\tz: %12.4g - %12.4g\n", self->min[ K_AXIS ], self->max[ K_AXIS ] );
+	}
+}
+
+void _Underworld_testYieldCriterion_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
+	YieldRheology*          yieldRheology;
+	Underworld_testYieldCriterion* self;
+
+	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", FiniteElementContext, True, data ); 
+
+	/* Get pointer to plugin struct */
+	self = (Underworld_testYieldCriterion* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_testYieldCriterion_Type  );
+
+	/* get pointer to the mesh */
+	self->mesh = Stg_ComponentFactory_ConstructByName( cf, (Name)"linearMesh", FeMesh, True, data ); 
+	
+	/* Get a pointer the yield rheology that we are trying to test */
+	yieldRheology = (YieldRheology* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"yieldRheology"  );
+	
+	/* Store the pointer to the original 'HasYielded' function */
+	self->realHasYieldedFunction = yieldRheology->_hasYielded;
+
+	/* Reset this function pointer with our own */
+	yieldRheology->_hasYielded = testYieldCriterion_HasYielded;
+
+	ContextEP_Append( context, AbstractContext_EP_Step, Underworld_testYieldCriterion_Check );
+	EP_AppendClassHook( Context_GetEntryPoint( context, FiniteElementContext_EP_CalcDt ), 
+			Underworld_testYieldCriterion_dt, context );
+
+	self->min[ I_AXIS ] = HUGE_VAL;
+	self->min[ J_AXIS ] = HUGE_VAL;
+	self->min[ K_AXIS ] = HUGE_VAL;
+	self->max[ I_AXIS ] = -HUGE_VAL;
+	self->max[ J_AXIS ] = -HUGE_VAL;
+	self->max[ K_AXIS ] = -HUGE_VAL;
+}
+
+void* _Underworld_testYieldCriterion_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof( Underworld_testYieldCriterion );
+	Type                                                      type = Underworld_testYieldCriterion_Type;
+	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
+	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
+	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_testYieldCriterion_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Underworld_testYieldCriterion_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 Underworld_testYieldCriterion_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Underworld_testYieldCriterion_Type, (Name)"0", _Underworld_testYieldCriterion_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SConscript
--- a/SConscript	Wed May 11 13:27:52 2011 -0700
+++ b/SConscript	Thu May 12 11:19:19 2011 -0700
@@ -54,8 +54,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.
@@ -67,7 +67,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 + '/*'))
@@ -119,8 +119,8 @@ for d in dirs:
 
     env.Install('include/Underworld/' + 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)
 
@@ -221,7 +221,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'], 'Underworld', 'underworld_static_modules.c')
+    reg_filename = os.path.join(env['build_dir'], 'Underworld', 'underworld_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')
@@ -230,12 +230,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, '   underworld_register_static_modules();\n')
     txt.insert(0, 'void underworld_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 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/DepthDependentAnalytic3D/DepthDependentAnalytic3D.c
--- a/SysTest/AnalyticPlugins/DepthDependentAnalytic3D/DepthDependentAnalytic3D.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,304 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: DepthDependentAnalytic3D.c 739 2008-06-12 06:05:14Z RobertTurnbull $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Rheology/Rheology.h>
-
-#include <assert.h>
-#include <string.h>
-
-const Type DepthDependentAnalytic3D_Type = "DepthDependentAnalytic3D";
-
-typedef struct {
-	__FieldTest
-	FieldTest_AnalyticSolutionFunc* viscosityFunc;
-	FieldTest_AnalyticSolutionFunc* viscosityDerivativeFunc;
-	FieldTest_AnalyticSolutionFunc* viscosity2ndDerivativeFunc;
-	double                          Ra;
-	double                          V0;
-} DepthDependentAnalytic3D;
-
-void DepthDependentAnalytic3D_ViscosityFunc_Isoviscous( void* analyticSolution, double* coord, double* eta ) {
-	*eta = 1.0;
-}
-void DepthDependentAnalytic3D_ViscosityDerivativeFunc_Isoviscous( void* analyticSolution, double* coord, double* d_eta_dy ) {
-	*d_eta_dy = 0.0;
-}
-void DepthDependentAnalytic3D_Viscosity2ndDerivativeFunc_Isoviscous( void* analyticSolution, double* coord, double* d2_eta_dy2 ) {
-	*d2_eta_dy2 = 0.0;
-}
-
-void DepthDependentAnalytic3D_ViscosityFunc_Linear( void* analyticSolution, double* coord, double* eta ) {
-	double y = coord[ J_AXIS ];
-	*eta = 2.0 - y;
-}
-void DepthDependentAnalytic3D_ViscosityDerivativeFunc_Linear( void* analyticSolution, double* coord, double* d_eta_dy ) {
-	*d_eta_dy = -1.0;
-}
-void DepthDependentAnalytic3D_Viscosity2ndDerivativeFunc_Linear( void* analyticSolution, double* coord, double* d2_eta_dy2 ) {
-	*d2_eta_dy2 = 0.0;
-}
-void DepthDependentAnalytic3D_ViscosityFunc_Exponential( void* analyticSolution, double* coord, double* eta ) {
-	double y = coord[ J_AXIS ];
-	*eta = exp( 1.0 - y );
-}
-void DepthDependentAnalytic3D_ViscosityDerivativeFunc_Exponential( void* analyticSolution, double* coord, double* d_eta_dy ) {
-	double y = coord[ J_AXIS ];
-	*d_eta_dy = - exp( 1.0 - y );
-}
-void DepthDependentAnalytic3D_Viscosity2ndDerivativeFunc_Exponential( void* analyticSolution, double* coord, double* d2_eta_dy2 ) {
-	double y = coord[ J_AXIS ];
-	*d2_eta_dy2 = exp( 1.0 - y );
-}
-void DepthDependentAnalytic3D_ViscosityFunc_Exponential2( void* analyticSolution, double* coord, double* eta ) {
-	double y = coord[ J_AXIS ];
-	double viscosityContrast = 1e6;
-	double gamma = log(viscosityContrast);
-	*eta = viscosityContrast * exp( - gamma *( 1.0 - y ) );
-}
-void DepthDependentAnalytic3D_ViscosityDerivativeFunc_Exponential2( void* analyticSolution, double* coord, double* d_eta_dy ) {
-	double y = coord[ J_AXIS ];
-	double viscosityContrast = 1e6;
-	double gamma = log(viscosityContrast);
-	*d_eta_dy = viscosityContrast * gamma * exp( - gamma *( 1.0 - y ) );
-}
-void DepthDependentAnalytic3D_Viscosity2ndDerivativeFunc_Exponential2( void* analyticSolution, double* coord, double* d2_eta_dy2 ) {
-	double y = coord[ J_AXIS ];
-	double viscosityContrast = 1e6;
-	double gamma = log(viscosityContrast);
-	*d2_eta_dy2 = viscosityContrast * gamma * gamma * exp( - gamma *( 1.0 - y ) );
-}
-
-
-void _DepthDependentAnalytic3D_TemperatureFunction( void* analyticSolution, double* coord, double* temperature ) {
-	DepthDependentAnalytic3D* self            = (DepthDependentAnalytic3D*)analyticSolution;
-	double                 x; 
-	double                 y;
-	double                 z;
-	double                 V0                 = self->V0;
-	double                 Ra                 = self->Ra;
-	double                 perturbation;
-	double                 eta, d_eta_dy, d2_eta_dy2;
-	
-	/* Find coordinate of node */
-	x = coord[ I_AXIS ];
-	y = coord[ J_AXIS ];
-	z = coord[ K_AXIS ];
-	
-	/* Get Viscositiy and derivatives */
-	self->viscosityFunc( self, coord, &eta );
-	self->viscosityDerivativeFunc( self, coord, &d_eta_dy );
-	self->viscosity2ndDerivativeFunc( self, coord, &d2_eta_dy2 );
-
-	perturbation = V0 / Ra * cos( M_PI * x ) * cos( M_PI * z ) * 
-		( 6.0 * M_PI * d_eta_dy * cos( M_PI * y ) - ( 9.0 * M_PI * M_PI * eta + d2_eta_dy2 ) * sin( M_PI * y ) );
-
-	*temperature = 1 - y + perturbation;
-}
-
-void _DepthDependentAnalytic3D_VelocityFunction( void* analyticSolution, double* coord, double* velocity ) {
-	DepthDependentAnalytic3D* self            = (DepthDependentAnalytic3D*)analyticSolution;
-	double                 V0                 = self->V0;
-	double                 x; 
-	double                 y;
-	double                 z;
-	XYZ                    min, max;
-
-	Mesh_GetGlobalCoordRange( self->elementMesh, min, max );
-	x = coord[ I_AXIS ] - min[ I_AXIS ];
-	y = coord[ J_AXIS ] - min[ J_AXIS ];
-	z = coord[ K_AXIS ] - min[ K_AXIS ];
-
-	velocity[ I_AXIS ] =          V0 * sin( M_PI * x ) * cos( M_PI * y ) * cos( M_PI * z ) ;
-	velocity[ J_AXIS ] =  - 2.0 * V0 * cos( M_PI * x ) * sin( M_PI * y ) * cos( M_PI * z ) ;
-	velocity[ K_AXIS ] =          V0 * cos( M_PI * x ) * cos( M_PI * y ) * sin( M_PI * z ) ;
-}
-
-void _DepthDependentAnalytic3D_ViscosityFunction( void* analyticSolution, double* coord, double* viscosity ) {
-	DepthDependentAnalytic3D* self            = (DepthDependentAnalytic3D*)analyticSolution;
-
-	self->viscosityFunc( self, coord, viscosity );
-}
-
-void _DepthDependentAnalytic3D_PressureFunction( void* analyticSolution, double* coord, double* pressure ) {
-	DepthDependentAnalytic3D* self            = (DepthDependentAnalytic3D*)analyticSolution;
-	double                 x; 
-	double                 y;
-	double                 z;
-	XYZ                    min, max;
-	double                 V0                 = self->V0;
-	double                 Ra                 = self->Ra;
-	double                 C                  = 0;
-	double                 f                  = 0;
-	double                 eta, d_eta_dy;
-
-	Mesh_GetGlobalCoordRange( self->elementMesh, min, max );
-	x = coord[ I_AXIS ] - min[ I_AXIS ];
-	y = coord[ J_AXIS ] - min[ J_AXIS ];
-	z = coord[ K_AXIS ] - min[ K_AXIS ];
-
-	f = - Ra*y*y*0.5 + Ra*y + C;
-	
-	/* Get Viscositiy and derivatives */
-	self->viscosityFunc( self, coord, &eta );
-	self->viscosityDerivativeFunc( self, coord, &d_eta_dy );
-
-	*pressure = V0 * cos( M_PI * x ) * cos( M_PI * z ) * ( 3.0 * eta * M_PI * cos( M_PI * y ) - d_eta_dy * sin( M_PI * y ) ) + f;
-}
-
-void DepthDependentAnalytic3D_TemperatureIC( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
-	DomainContext*         context            = (DomainContext*)_context;
-	FeVariable*            temperatureField   = (FeVariable*) FieldVariable_Register_GetByName( context->fieldVariable_Register, "TemperatureField" );
-	FeMesh*                mesh               = temperatureField->feMesh;
-	double*                temperature        = (double*) _result;
-	double*                coord;
-	DepthDependentAnalytic3D*  self           = Stg_ComponentFactory_ConstructByName( context->CF, (Name)DepthDependentAnalytic3D_Type, DepthDependentAnalytic3D, True, context  );
-	
-	/* Find coordinate of node */
-	coord = Mesh_GetVertex( mesh, node_lI );
-	
-	_DepthDependentAnalytic3D_TemperatureFunction( self, coord, temperature );
-}
-
-void DepthDependentAnalytic3D_PressureIC( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
-	DomainContext*         context            = (DomainContext*)_context;
-	FeVariable*            PressureField      = (FeVariable*) FieldVariable_Register_GetByName( context->fieldVariable_Register, "PressureField" );
-	FeMesh*                mesh               = PressureField->feMesh;
-	double*                pressure           = (double*) _result;
-	double*                coord;
-	DepthDependentAnalytic3D*  self           = Stg_ComponentFactory_ConstructByName( context->CF, (Name)DepthDependentAnalytic3D_Type, DepthDependentAnalytic3D, True, context  );
-	
-	/* Find coordinate of node */
-	coord = Mesh_GetVertex( mesh, node_lI );
-	
-	_DepthDependentAnalytic3D_PressureFunction( self, coord, pressure );
-}
-
-void _DepthDependentAnalytic3D_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
-	DepthDependentAnalytic3D*	self           = (DepthDependentAnalytic3D*)analyticSolution;
-	ConditionFunction*			condFunc;
-	char*								viscosityType;
-	
-	/* Construct Parent */
-	_FieldTest_AssignFromXML( self, cf, data );
-
-	/* Add temperature initial condition */
-	condFunc = ConditionFunction_New( DepthDependentAnalytic3D_TemperatureIC, (Name)"DepthDependentAnalytic3D_TemperatureIC"  );
-	ConditionFunction_Register_Add( condFunc_Register, condFunc );
-
-	/* Add pressure initial condition */
-	condFunc = ConditionFunction_New( DepthDependentAnalytic3D_PressureIC, (Name)"DepthDependentAnalytic3D_PressureIC"  );
-	ConditionFunction_Register_Add( condFunc_Register, condFunc );
-	
-	/* Create Analytic Fields */
-	self->_analyticSolutionList = Memory_Alloc_Array_Unnamed( FieldTest_AnalyticSolutionFunc*, 4 );
-	self->_analyticSolutionList[0] = _DepthDependentAnalytic3D_VelocityFunction;
-	self->_analyticSolutionList[1] = _DepthDependentAnalytic3D_PressureFunction;
-	self->_analyticSolutionList[2] = _DepthDependentAnalytic3D_TemperatureFunction;
-	self->_analyticSolutionList[3] = _DepthDependentAnalytic3D_ViscosityFunction;
-
-	/* Setup Viscosity Functions */
-	viscosityType = Stg_ComponentFactory_GetRootDictString( cf, (Dictionary_Entry_Key)"ViscosityType", "Isoviscous"  );
-	if ( strcasecmp( viscosityType, "Isoviscous" ) == 0 ) {
-		self->viscosityFunc              = DepthDependentAnalytic3D_ViscosityFunc_Isoviscous;
-		self->viscosityDerivativeFunc    = DepthDependentAnalytic3D_ViscosityDerivativeFunc_Isoviscous;
-		self->viscosity2ndDerivativeFunc = DepthDependentAnalytic3D_Viscosity2ndDerivativeFunc_Isoviscous;
-	}
-	else if ( strcasecmp( viscosityType, "Linear" ) == 0 ) {
-		self->viscosityFunc              = DepthDependentAnalytic3D_ViscosityFunc_Linear;
-		self->viscosityDerivativeFunc    = DepthDependentAnalytic3D_ViscosityDerivativeFunc_Linear;
-		self->viscosity2ndDerivativeFunc = DepthDependentAnalytic3D_Viscosity2ndDerivativeFunc_Linear;
-	}
-	else if ( strcasecmp( viscosityType, "Exponential" ) == 0 ) {
-		self->viscosityFunc              = DepthDependentAnalytic3D_ViscosityFunc_Exponential;
-		self->viscosityDerivativeFunc    = DepthDependentAnalytic3D_ViscosityDerivativeFunc_Exponential;
-		self->viscosity2ndDerivativeFunc = DepthDependentAnalytic3D_Viscosity2ndDerivativeFunc_Exponential;
-	}
-	else if ( strcasecmp( viscosityType, "Exponential2" ) == 0 ) {
-		self->viscosityFunc              = DepthDependentAnalytic3D_ViscosityFunc_Exponential2;
-		self->viscosityDerivativeFunc    = DepthDependentAnalytic3D_ViscosityDerivativeFunc_Exponential2;
-		self->viscosity2ndDerivativeFunc = DepthDependentAnalytic3D_Viscosity2ndDerivativeFunc_Exponential2;
-	}
-
-	self->Ra = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"Ra", 0.0  );
-	self->V0 = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"V0", 0.0  );
-}
-
-void _DepthDependentAnalytic3D_Build( void* analyticSolution, void* data ) {
-	DepthDependentAnalytic3D*         self = (DepthDependentAnalytic3D*)analyticSolution;
-
-	_FieldTest_Build( self, data );
-}
-
-
-void* _DepthDependentAnalytic3D_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(DepthDependentAnalytic3D);
-	Type                                                      type = DepthDependentAnalytic3D_Type;
-	Stg_Class_DeleteFunction*                              _delete = _FieldTest_Delete;
-	Stg_Class_PrintFunction*                                _print = _FieldTest_Print;
-	Stg_Class_CopyFunction*                                  _copy = _FieldTest_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _DepthDependentAnalytic3D_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _DepthDependentAnalytic3D_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _DepthDependentAnalytic3D_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 Underworld_DepthDependentAnalytic3D_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, DepthDependentAnalytic3D_Type, (Name)"0", _DepthDependentAnalytic3D_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/DepthDependentAnalytic3D/DepthDependentAnalytic3D.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/DepthDependentAnalytic3D/DepthDependentAnalytic3D.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,304 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: DepthDependentAnalytic3D.c 739 2008-06-12 06:05:14Z RobertTurnbull $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Rheology/Rheology.h>
+
+#include <assert.h>
+#include <string.h>
+
+const Type DepthDependentAnalytic3D_Type = "DepthDependentAnalytic3D";
+
+typedef struct {
+	__FieldTest
+	FieldTest_AnalyticSolutionFunc* viscosityFunc;
+	FieldTest_AnalyticSolutionFunc* viscosityDerivativeFunc;
+	FieldTest_AnalyticSolutionFunc* viscosity2ndDerivativeFunc;
+	double                          Ra;
+	double                          V0;
+} DepthDependentAnalytic3D;
+
+void DepthDependentAnalytic3D_ViscosityFunc_Isoviscous( void* analyticSolution, double* coord, double* eta ) {
+	*eta = 1.0;
+}
+void DepthDependentAnalytic3D_ViscosityDerivativeFunc_Isoviscous( void* analyticSolution, double* coord, double* d_eta_dy ) {
+	*d_eta_dy = 0.0;
+}
+void DepthDependentAnalytic3D_Viscosity2ndDerivativeFunc_Isoviscous( void* analyticSolution, double* coord, double* d2_eta_dy2 ) {
+	*d2_eta_dy2 = 0.0;
+}
+
+void DepthDependentAnalytic3D_ViscosityFunc_Linear( void* analyticSolution, double* coord, double* eta ) {
+	double y = coord[ J_AXIS ];
+	*eta = 2.0 - y;
+}
+void DepthDependentAnalytic3D_ViscosityDerivativeFunc_Linear( void* analyticSolution, double* coord, double* d_eta_dy ) {
+	*d_eta_dy = -1.0;
+}
+void DepthDependentAnalytic3D_Viscosity2ndDerivativeFunc_Linear( void* analyticSolution, double* coord, double* d2_eta_dy2 ) {
+	*d2_eta_dy2 = 0.0;
+}
+void DepthDependentAnalytic3D_ViscosityFunc_Exponential( void* analyticSolution, double* coord, double* eta ) {
+	double y = coord[ J_AXIS ];
+	*eta = exp( 1.0 - y );
+}
+void DepthDependentAnalytic3D_ViscosityDerivativeFunc_Exponential( void* analyticSolution, double* coord, double* d_eta_dy ) {
+	double y = coord[ J_AXIS ];
+	*d_eta_dy = - exp( 1.0 - y );
+}
+void DepthDependentAnalytic3D_Viscosity2ndDerivativeFunc_Exponential( void* analyticSolution, double* coord, double* d2_eta_dy2 ) {
+	double y = coord[ J_AXIS ];
+	*d2_eta_dy2 = exp( 1.0 - y );
+}
+void DepthDependentAnalytic3D_ViscosityFunc_Exponential2( void* analyticSolution, double* coord, double* eta ) {
+	double y = coord[ J_AXIS ];
+	double viscosityContrast = 1e6;
+	double gamma = log(viscosityContrast);
+	*eta = viscosityContrast * exp( - gamma *( 1.0 - y ) );
+}
+void DepthDependentAnalytic3D_ViscosityDerivativeFunc_Exponential2( void* analyticSolution, double* coord, double* d_eta_dy ) {
+	double y = coord[ J_AXIS ];
+	double viscosityContrast = 1e6;
+	double gamma = log(viscosityContrast);
+	*d_eta_dy = viscosityContrast * gamma * exp( - gamma *( 1.0 - y ) );
+}
+void DepthDependentAnalytic3D_Viscosity2ndDerivativeFunc_Exponential2( void* analyticSolution, double* coord, double* d2_eta_dy2 ) {
+	double y = coord[ J_AXIS ];
+	double viscosityContrast = 1e6;
+	double gamma = log(viscosityContrast);
+	*d2_eta_dy2 = viscosityContrast * gamma * gamma * exp( - gamma *( 1.0 - y ) );
+}
+
+
+void _DepthDependentAnalytic3D_TemperatureFunction( void* analyticSolution, double* coord, double* temperature ) {
+	DepthDependentAnalytic3D* self            = (DepthDependentAnalytic3D*)analyticSolution;
+	double                 x; 
+	double                 y;
+	double                 z;
+	double                 V0                 = self->V0;
+	double                 Ra                 = self->Ra;
+	double                 perturbation;
+	double                 eta, d_eta_dy, d2_eta_dy2;
+	
+	/* Find coordinate of node */
+	x = coord[ I_AXIS ];
+	y = coord[ J_AXIS ];
+	z = coord[ K_AXIS ];
+	
+	/* Get Viscositiy and derivatives */
+	self->viscosityFunc( self, coord, &eta );
+	self->viscosityDerivativeFunc( self, coord, &d_eta_dy );
+	self->viscosity2ndDerivativeFunc( self, coord, &d2_eta_dy2 );
+
+	perturbation = V0 / Ra * cos( M_PI * x ) * cos( M_PI * z ) * 
+		( 6.0 * M_PI * d_eta_dy * cos( M_PI * y ) - ( 9.0 * M_PI * M_PI * eta + d2_eta_dy2 ) * sin( M_PI * y ) );
+
+	*temperature = 1 - y + perturbation;
+}
+
+void _DepthDependentAnalytic3D_VelocityFunction( void* analyticSolution, double* coord, double* velocity ) {
+	DepthDependentAnalytic3D* self            = (DepthDependentAnalytic3D*)analyticSolution;
+	double                 V0                 = self->V0;
+	double                 x; 
+	double                 y;
+	double                 z;
+	XYZ                    min, max;
+
+	Mesh_GetGlobalCoordRange( self->elementMesh, min, max );
+	x = coord[ I_AXIS ] - min[ I_AXIS ];
+	y = coord[ J_AXIS ] - min[ J_AXIS ];
+	z = coord[ K_AXIS ] - min[ K_AXIS ];
+
+	velocity[ I_AXIS ] =          V0 * sin( M_PI * x ) * cos( M_PI * y ) * cos( M_PI * z ) ;
+	velocity[ J_AXIS ] =  - 2.0 * V0 * cos( M_PI * x ) * sin( M_PI * y ) * cos( M_PI * z ) ;
+	velocity[ K_AXIS ] =          V0 * cos( M_PI * x ) * cos( M_PI * y ) * sin( M_PI * z ) ;
+}
+
+void _DepthDependentAnalytic3D_ViscosityFunction( void* analyticSolution, double* coord, double* viscosity ) {
+	DepthDependentAnalytic3D* self            = (DepthDependentAnalytic3D*)analyticSolution;
+
+	self->viscosityFunc( self, coord, viscosity );
+}
+
+void _DepthDependentAnalytic3D_PressureFunction( void* analyticSolution, double* coord, double* pressure ) {
+	DepthDependentAnalytic3D* self            = (DepthDependentAnalytic3D*)analyticSolution;
+	double                 x; 
+	double                 y;
+	double                 z;
+	XYZ                    min, max;
+	double                 V0                 = self->V0;
+	double                 Ra                 = self->Ra;
+	double                 C                  = 0;
+	double                 f                  = 0;
+	double                 eta, d_eta_dy;
+
+	Mesh_GetGlobalCoordRange( self->elementMesh, min, max );
+	x = coord[ I_AXIS ] - min[ I_AXIS ];
+	y = coord[ J_AXIS ] - min[ J_AXIS ];
+	z = coord[ K_AXIS ] - min[ K_AXIS ];
+
+	f = - Ra*y*y*0.5 + Ra*y + C;
+	
+	/* Get Viscositiy and derivatives */
+	self->viscosityFunc( self, coord, &eta );
+	self->viscosityDerivativeFunc( self, coord, &d_eta_dy );
+
+	*pressure = V0 * cos( M_PI * x ) * cos( M_PI * z ) * ( 3.0 * eta * M_PI * cos( M_PI * y ) - d_eta_dy * sin( M_PI * y ) ) + f;
+}
+
+void DepthDependentAnalytic3D_TemperatureIC( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
+	DomainContext*         context            = (DomainContext*)_context;
+	FeVariable*            temperatureField   = (FeVariable*) FieldVariable_Register_GetByName( context->fieldVariable_Register, "TemperatureField" );
+	FeMesh*                mesh               = temperatureField->feMesh;
+	double*                temperature        = (double*) _result;
+	double*                coord;
+	DepthDependentAnalytic3D*  self           = Stg_ComponentFactory_ConstructByName( context->CF, (Name)DepthDependentAnalytic3D_Type, DepthDependentAnalytic3D, True, context  );
+	
+	/* Find coordinate of node */
+	coord = Mesh_GetVertex( mesh, node_lI );
+	
+	_DepthDependentAnalytic3D_TemperatureFunction( self, coord, temperature );
+}
+
+void DepthDependentAnalytic3D_PressureIC( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
+	DomainContext*         context            = (DomainContext*)_context;
+	FeVariable*            PressureField      = (FeVariable*) FieldVariable_Register_GetByName( context->fieldVariable_Register, "PressureField" );
+	FeMesh*                mesh               = PressureField->feMesh;
+	double*                pressure           = (double*) _result;
+	double*                coord;
+	DepthDependentAnalytic3D*  self           = Stg_ComponentFactory_ConstructByName( context->CF, (Name)DepthDependentAnalytic3D_Type, DepthDependentAnalytic3D, True, context  );
+	
+	/* Find coordinate of node */
+	coord = Mesh_GetVertex( mesh, node_lI );
+	
+	_DepthDependentAnalytic3D_PressureFunction( self, coord, pressure );
+}
+
+void _DepthDependentAnalytic3D_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
+	DepthDependentAnalytic3D*	self           = (DepthDependentAnalytic3D*)analyticSolution;
+	ConditionFunction*			condFunc;
+	char*								viscosityType;
+	
+	/* Construct Parent */
+	_FieldTest_AssignFromXML( self, cf, data );
+
+	/* Add temperature initial condition */
+	condFunc = ConditionFunction_New( DepthDependentAnalytic3D_TemperatureIC, (Name)"DepthDependentAnalytic3D_TemperatureIC"  );
+	ConditionFunction_Register_Add( condFunc_Register, condFunc );
+
+	/* Add pressure initial condition */
+	condFunc = ConditionFunction_New( DepthDependentAnalytic3D_PressureIC, (Name)"DepthDependentAnalytic3D_PressureIC"  );
+	ConditionFunction_Register_Add( condFunc_Register, condFunc );
+	
+	/* Create Analytic Fields */
+	self->_analyticSolutionList = Memory_Alloc_Array_Unnamed( FieldTest_AnalyticSolutionFunc*, 4 );
+	self->_analyticSolutionList[0] = _DepthDependentAnalytic3D_VelocityFunction;
+	self->_analyticSolutionList[1] = _DepthDependentAnalytic3D_PressureFunction;
+	self->_analyticSolutionList[2] = _DepthDependentAnalytic3D_TemperatureFunction;
+	self->_analyticSolutionList[3] = _DepthDependentAnalytic3D_ViscosityFunction;
+
+	/* Setup Viscosity Functions */
+	viscosityType = Stg_ComponentFactory_GetRootDictString( cf, (Dictionary_Entry_Key)"ViscosityType", "Isoviscous"  );
+	if ( strcasecmp( viscosityType, "Isoviscous" ) == 0 ) {
+		self->viscosityFunc              = DepthDependentAnalytic3D_ViscosityFunc_Isoviscous;
+		self->viscosityDerivativeFunc    = DepthDependentAnalytic3D_ViscosityDerivativeFunc_Isoviscous;
+		self->viscosity2ndDerivativeFunc = DepthDependentAnalytic3D_Viscosity2ndDerivativeFunc_Isoviscous;
+	}
+	else if ( strcasecmp( viscosityType, "Linear" ) == 0 ) {
+		self->viscosityFunc              = DepthDependentAnalytic3D_ViscosityFunc_Linear;
+		self->viscosityDerivativeFunc    = DepthDependentAnalytic3D_ViscosityDerivativeFunc_Linear;
+		self->viscosity2ndDerivativeFunc = DepthDependentAnalytic3D_Viscosity2ndDerivativeFunc_Linear;
+	}
+	else if ( strcasecmp( viscosityType, "Exponential" ) == 0 ) {
+		self->viscosityFunc              = DepthDependentAnalytic3D_ViscosityFunc_Exponential;
+		self->viscosityDerivativeFunc    = DepthDependentAnalytic3D_ViscosityDerivativeFunc_Exponential;
+		self->viscosity2ndDerivativeFunc = DepthDependentAnalytic3D_Viscosity2ndDerivativeFunc_Exponential;
+	}
+	else if ( strcasecmp( viscosityType, "Exponential2" ) == 0 ) {
+		self->viscosityFunc              = DepthDependentAnalytic3D_ViscosityFunc_Exponential2;
+		self->viscosityDerivativeFunc    = DepthDependentAnalytic3D_ViscosityDerivativeFunc_Exponential2;
+		self->viscosity2ndDerivativeFunc = DepthDependentAnalytic3D_Viscosity2ndDerivativeFunc_Exponential2;
+	}
+
+	self->Ra = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"Ra", 0.0  );
+	self->V0 = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"V0", 0.0  );
+}
+
+void _DepthDependentAnalytic3D_Build( void* analyticSolution, void* data ) {
+	DepthDependentAnalytic3D*         self = (DepthDependentAnalytic3D*)analyticSolution;
+
+	_FieldTest_Build( self, data );
+}
+
+
+void* _DepthDependentAnalytic3D_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(DepthDependentAnalytic3D);
+	Type                                                      type = DepthDependentAnalytic3D_Type;
+	Stg_Class_DeleteFunction*                              _delete = _FieldTest_Delete;
+	Stg_Class_PrintFunction*                                _print = _FieldTest_Print;
+	Stg_Class_CopyFunction*                                  _copy = _FieldTest_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _DepthDependentAnalytic3D_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _DepthDependentAnalytic3D_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _DepthDependentAnalytic3D_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 Underworld_DepthDependentAnalytic3D_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, DepthDependentAnalytic3D_Type, (Name)"0", _DepthDependentAnalytic3D_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/LateralViscosityAnalytic/LateralViscosityAnalytic.c
--- a/SysTest/AnalyticPlugins/LateralViscosityAnalytic/LateralViscosityAnalytic.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,470 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: LateralViscosityAnalytic.c 628 2007-11-14 03:59:03Z RobertTurnbull $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Rheology/Rheology.h>
-
-#include <assert.h>
-
-#define SMALL 1.0e-5
-#define IS_ODD(A)   ( (A) % 2 == 1 )
-
-const Type LateralViscosityAnalytic_Type = "LateralViscosityAnalytic";
-
-typedef struct {
-	__FieldTest
-	double                  beta;
-	int                     wavenumberX;
-	int                     wavenumberY;
-	FeVariable*		velocityField;
-} LateralViscosityAnalytic;
-
-/** Analytic Solution taken from 
- *  Shijie Zhong. Analytic solutions for Stokes' flow with lateral variations in viscosity. Geophys. J. Int., 124:18-28, 1996.
- *  All equations refer to this paper */
-
-void LateralViscosityAnalytic_TemperatureIC( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
-	DomainContext*  	context            = (DomainContext*)_context;
-	FeVariable*             temperatureField   = (FeVariable*) FieldVariable_Register_GetByName( context->fieldVariable_Register, "TemperatureField" );
-	FeMesh* 		mesh               = temperatureField->feMesh;
-	double*                 result             = (double*) _result;
-	Dictionary*             dictionary         = context->dictionary;
-	double*                 coord;
-	double                  x; 
-	double                  y;
-	double                  kx;
-	double                  ky;
-	int                     wavenumberX;
-	int                     wavenumberY;
-	Coord			min, max;
-	double                  L;
-	
-	/* Find coordinate of node */
-	coord = Mesh_GetVertex( mesh, node_lI );
-
-	/* Make sure that the box has right dimensions */
-	Mesh_GetGlobalCoordRange( mesh, min, max );
-	assert( ( max[ J_AXIS ] - min[ J_AXIS ] - 1.0 ) < SMALL );
-	L = max[ I_AXIS ] - min[ I_AXIS ];
-
-	x = coord[ I_AXIS ] - min[ I_AXIS ];
-	y = coord[ J_AXIS ] - min[ J_AXIS ];
-
-	wavenumberX = Dictionary_GetInt_WithDefault( dictionary, (Dictionary_Entry_Key)"wavenumberX", 1  );
-	wavenumberY = Dictionary_GetInt_WithDefault( dictionary, (Dictionary_Entry_Key)"wavenumberY", 1 );
-
-	kx = wavenumberX * M_PI/ L;
-	ky = wavenumberY * M_PI;
-
-	*result = sin( ky * y ) * cos( kx * x  );
-}
-
-void _LateralViscosityAnalytic_VelocityFunction( void* analyticSolution, double* coord, double* velocity ) {
-	LateralViscosityAnalytic*         self               = (LateralViscosityAnalytic*)analyticSolution;
-	FeMesh*			mesh = self->elementMesh;
-	Coord			min, max;
-	Cmplx                   N                  = {0,0};
-	double                  chi1;
-	double                  chi2;
-	Cmplx                   sumX;
-	Cmplx                   sumY;
-	Cmplx                   m[5];                       /* CRAPPY FORTRAN ARRAYS */
-	Cmplx                   mSquared[5];
-	Cmplx                   mExp[5];
-	Cmplx                   N1;
-	Cmplx                   N2;
-	Cmplx                   N3;
-	Cmplx                   N4;
-	double                  beta2_4kn;
-	Cmplx                   lambda1;
-	Cmplx                   lambda2;
-	Cmplx                   n1;
-	Cmplx                   n2;
-	Cmplx                   n1_minus_beta;
-	Cmplx                   n2_minus_beta;
-	Cmplx                   M;
-	Cmplx                   oneOnM;
-	Cmplx                   tmp;
-	double                  beta;
-	double                  kn;
-	Index                   index;
-	Index                   i;
-	Index                   j;
-	Index                   h;
-	Index                   k;
-	double                  L;
-	double                  kx;
-	double                  ky;
-	Cmplx                   A1;
-	Cmplx                   A2;
-	Cmplx                   A3;
-	Cmplx                   A4;
-	Cmplx                   exp_n1x;
-	Cmplx                   exp_n2x;
-	Cmplx                   a1End;
-	Cmplx                   a2End;
-	double                  x;
-	double                  y;
-	double                  factorA;
-	double                  factorB;
-	int                     wavenumberX;
-	int                     wavenumberY;
-	double                  sqRootValue;
-
-	Mesh_GetGlobalCoordRange( mesh, min, max );
-	x = coord[ I_AXIS ] - min[ I_AXIS ];
-	y = coord[ J_AXIS ] - min[ J_AXIS ];
-
-	beta = self->beta;
-	wavenumberX = self->wavenumberX;
-	wavenumberY = self->wavenumberY;
-	
-	L    = max[ I_AXIS ] - min[ I_AXIS ];
-	kx   = wavenumberX * M_PI/ L;
-	ky   = wavenumberY * M_PI;
-	kn   = ky; 
-
-	beta2_4kn = beta * beta + 4.0 * kn * kn;
-	sqRootValue = beta2_4kn * beta2_4kn + 16.0 * beta * beta * kn * kn;
-	sqRootValue = sqrt( sqRootValue );
-	chi1 = sqrt( 0.5 * (  beta2_4kn + sqRootValue ) );
-	chi2 = sqrt( 0.5 * ( -beta2_4kn + sqRootValue ) );
-
-	n1[ REAL_PART ] = 0.5 * (beta + chi1);
-	n1[ IMAG_PART ] = 0.5 * (chi2);
-	
-	n2[ REAL_PART ] = 0.5 * (beta - chi1);
-	n2[ IMAG_PART ] = 0.5 * (-chi2);
-
-	Cmplx_Copy( n1, m[1] );
-	Cmplx_Conjugate( n1, m[2] );
-	Cmplx_Copy( n2, m[3] );
-	Cmplx_Conjugate( n2, m[4] );
-			
-	for ( index = 1 ; index <= 4 ; index++ ) {
-		Cmplx_Multiply( m[index], m[index], mSquared[index] );
-		Cmplx_RealMultiply( m[ index ], -L, tmp );
-		Cmplx_Exp( tmp, mExp[ index ] );
-	}
-
-	/* Calculate M - Equation A7 */
-	Cmplx_Subtract( m[2], m[1], oneOnM );
-	Cmplx_Subtract( m[3], m[1], tmp );
-	Cmplx_Multiply( oneOnM, tmp, oneOnM );
-	Cmplx_Subtract( m[4], m[1], tmp );
-	Cmplx_Multiply( oneOnM, tmp, oneOnM );
-	Cmplx_RealDivideByCmplx( oneOnM, 1.0, M );
-
-	/* Calculate N - Equation A8 */
-	for ( j = 1 ; j <= 3 ; j++ ) {
-		for ( i = j+1 ; i <= 4 ; i++ ) {
-			Cmplx product = {0,0};
-			
-			/* Get h */
-			for ( h = 1 ; h <= 4 ; h++ ) {
-				if ( h != i && h != j )
-					break; /* Found h */
-			}
-
-			/* Get k */
-			for ( k = h+1 ; k <= 4 ; k++ ) {
-				if ( k != i && k != j )
-					break; /* Found k */
-			}			
-
-			product[ REAL_PART ] = IS_ODD( i + j ) ? 1.0 : -1.0;
-			
-			Cmplx_Multiply( product, mExp[ i ], product );
-			Cmplx_Multiply( product, mExp[ j ], product );
-
-			Cmplx_Subtract( mSquared[ k ], mSquared[ h ], tmp );
-			Cmplx_Multiply( product, tmp, product );
-
-			Cmplx_Subtract( mSquared[ i ], mSquared[ j ], tmp );
-			Cmplx_Multiply( product, tmp, product );
-
-			Cmplx_Add( N, product, N );
-		}
-	}
-
-	/* Build N1 - Equation A9 */
-	Cmplx_Subtract( mSquared[4], mSquared[3], tmp );
-	Cmplx_Multiply( tmp, mSquared[2], tmp );
-	Cmplx_Multiply( tmp, mExp[2], N1 ); 
-
-	Cmplx_Subtract( mSquared[4], mSquared[2], tmp );
-	Cmplx_Multiply( tmp, mSquared[3], tmp );
-	Cmplx_Multiply( tmp, mExp[3], tmp );
-	Cmplx_Subtract( N1, tmp, N1 );
-	
-	Cmplx_Subtract( mSquared[3], mSquared[2], tmp );
-	Cmplx_Multiply( tmp, mSquared[4], tmp );
-	Cmplx_Multiply( tmp, mExp[4], tmp );
-	Cmplx_Add( N1, tmp, N1 );
-	
-	/* Build N2 - Equation A10 */
-	Cmplx_Subtract( mSquared[4], mSquared[2], tmp );
-	Cmplx_Multiply( tmp, mSquared[1], tmp );
-	Cmplx_Multiply( tmp, mExp[1], N2 );
-
-	Cmplx_Subtract( mSquared[4], mSquared[1], tmp );
-	Cmplx_Multiply( tmp, mSquared[2], tmp );
-	Cmplx_Multiply( tmp, mExp[2], tmp );
-	Cmplx_Subtract( N2, tmp, N2 );
-
-	Cmplx_Subtract( mSquared[2], mSquared[1], tmp );
-	Cmplx_Multiply( tmp, mSquared[4], tmp );
-	Cmplx_Multiply( tmp, mExp[4], tmp );
-	Cmplx_Add( N2, tmp, N2 );
-
-	/* Build N3 - Equation A11 */
-	Cmplx_Subtract( mSquared[3], mSquared[4], tmp );
-	Cmplx_Multiply( tmp, mExp[2], N3 );
-
-	Cmplx_Subtract( mSquared[4], mSquared[2], tmp );
-	Cmplx_Multiply( tmp, mExp[3], tmp );
-	Cmplx_Add( N3, tmp, N3 );
-
-	Cmplx_Subtract( mSquared[2], mSquared[3], tmp );
-	Cmplx_Multiply( tmp, mExp[4], tmp );
-	Cmplx_Add( N3, tmp, N3 );
-
-	/* Build N4 - Equation A12 */
-	Cmplx_Subtract( mSquared[2], mSquared[4], tmp );
-	Cmplx_Multiply( tmp, mExp[1], N4 );
-
-	Cmplx_Subtract( mSquared[4], mSquared[1], tmp );
-	Cmplx_Multiply( tmp, mExp[2], tmp );
-	Cmplx_Add( N4, tmp, N4 );
-
-	Cmplx_Subtract( mSquared[1], mSquared[2], tmp );
-	Cmplx_Multiply( tmp, mExp[4], tmp );
-	Cmplx_Add( N4, tmp, N4 );
-
-    	/* Build lambda1 - Equation B8 */
-	Cmplx_AddReal( n1, - beta, n1_minus_beta );
-    	Cmplx_RealMultiply( n1_minus_beta,L, tmp );
-	Cmplx_Exp( tmp, tmp );
-    	Cmplx_RealMultiply(tmp, cos( kx * L ), tmp );
-	Cmplx_RealMinusCmplx( tmp, 1.0, tmp );
-    	Cmplx_RealMultiply(tmp, -kx, tmp );
-	Cmplx_Multiply( M, tmp, lambda1 );
-	
-	Cmplx_Multiply( n1_minus_beta, n1_minus_beta, tmp );
-	Cmplx_AddReal( tmp, kx * kx, tmp );
-
-	Cmplx_Division( lambda1, tmp, lambda1 );
-	
-	/* Build lambda2 - Equation B9 */
-	Cmplx_AddReal( n2, - beta, n2_minus_beta );
-	Cmplx_RealMultiply( n2_minus_beta,L, tmp );
-	Cmplx_Exp( tmp, tmp );
-	Cmplx_RealMultiply(tmp, cos( kx * L ), tmp );
-	Cmplx_RealMinusCmplx( tmp, 1.0, tmp );
-	Cmplx_RealMultiply(tmp, kx, tmp );
-	Cmplx_Multiply( M, tmp, lambda2 );
-	
-	Cmplx_Multiply( n2_minus_beta, n2_minus_beta, tmp );
-	Cmplx_AddReal( tmp, kx * kx, tmp );
-
-	Cmplx_Division( lambda2, tmp, lambda2 );
-
-	/* Build A1 - Equation B4 */
-	Cmplx_Multiply( mExp[1], lambda1, tmp );
-	factorA = tmp[ REAL_PART ];
-	Cmplx_Multiply( mExp[3], lambda2, tmp );
-	factorA += tmp[ REAL_PART ];
-	Cmplx_Division( N1, N, tmp );
-	Cmplx_RealMultiply( tmp, 2.0 * factorA, A1 );
-
-	Cmplx_Multiply( mExp[1], lambda1, tmp );
-	Cmplx_Multiply( tmp, mSquared[1], tmp );
-	factorB = tmp[ REAL_PART ];
-	Cmplx_Multiply( mExp[3], lambda2, tmp );
-	Cmplx_Multiply( tmp, mSquared[3], tmp );
-	factorB += tmp[ REAL_PART ];
-	Cmplx_Division( N3, N, tmp );
-	Cmplx_RealMultiply( tmp, 2.0 * factorB, tmp );
-	Cmplx_Add( A1, tmp, A1 );
-
-	Cmplx_Multiply( n1_minus_beta, n1_minus_beta, a1End );
-	Cmplx_AddReal( a1End, kx*kx, a1End );
-	Cmplx_RealDivideByCmplx( a1End, kx, a1End );
-	Cmplx_Multiply( a1End, M, a1End );
-	Cmplx_Add( A1, a1End, A1 );
-
-	/* Build A2 - Equation B5 */
-	Cmplx_Division( N2, N, tmp );
-	Cmplx_RealMultiply( tmp, 2.0 * factorA, A2 );
-
-	Cmplx_Division( N4, N, tmp );
-	Cmplx_RealMultiply( tmp, 2.0 * factorB, tmp );
-	Cmplx_Add( A2, tmp, A2 );
-
-	Cmplx_Multiply( n2_minus_beta, n2_minus_beta, a2End );
-	Cmplx_AddReal( a2End, kx*kx, a2End );
-	Cmplx_RealDivideByCmplx( a2End, kx, a2End );
-	Cmplx_Multiply( a2End, M, a2End );
-	Cmplx_Subtract( A2, a2End, A2 );	
-
-	/* Build A3 - Equation B6 */
-	Cmplx_Subtract( a2End, a1End, A3 );
-
-	/* Build A4 - Equation B7 */
-	Cmplx_Multiply( n1_minus_beta, n1_minus_beta, tmp );
-	Cmplx_AddReal( tmp, kx*kx, tmp );
-	Cmplx_Division( n1_minus_beta, tmp, tmp );
-	Cmplx_Multiply( tmp, M, A4 );
-
-	Cmplx_Multiply( n2_minus_beta, n2_minus_beta, tmp );
-	Cmplx_AddReal( tmp, kx*kx, tmp );
-	Cmplx_Division( n2_minus_beta, tmp, tmp );
-	Cmplx_Multiply( tmp, M, tmp );
-	Cmplx_Subtract( A4, tmp, A4 );
-	
-	/*************************************** Get Velocities - Eqn B10 - B11 *****************************************/
-	
-	/* Get First Term in Sums */
-	Cmplx_RealMultiply( n1, -x, tmp );
-	Cmplx_Exp( tmp, exp_n1x );
-	Cmplx_Multiply( A1, exp_n1x, sumX );
-
-	Cmplx_Copy( sumX, sumY );
-	Cmplx_Multiply( sumY, n1, sumY );
-	Cmplx_RealMultiply( sumY, -1.0, sumY );
-
-	/* Add second term in sum */
-	Cmplx_RealMultiply( n2, -x, tmp );
-	Cmplx_Exp( tmp, exp_n2x );
-	Cmplx_Multiply( A2, exp_n2x, tmp );
-	Cmplx_Add( sumX, tmp, sumX );
-
-	Cmplx_Multiply( tmp, n2, tmp );
-	Cmplx_RealMultiply( tmp, -1.0, tmp );
-	Cmplx_Add( sumY, tmp, sumY );
-	
-	/* Add third term in sum */
-	sumX[ REAL_PART ] += (A3[ REAL_PART ] * cos( kx*x ) + A4[ REAL_PART ] * sin( kx * x ) ) * exp( -beta*x );
-	sumY[ REAL_PART ] += exp( -beta * x ) * (
-		(kx * A4[REAL_PART] - beta * A3[ REAL_PART ]) * cos( kx * x ) - 
-		(kx * A3[REAL_PART] + beta * A4[ REAL_PART ]) * sin( kx * x ) );
-
-	velocity[ I_AXIS ] = -2.0 * kx * ky * cos( ky * y ) * sumX[ REAL_PART ]; 
-	velocity[ J_AXIS ] = 2.0 * kx * sin( ky * y ) * sumY[ REAL_PART ]; 
-}
-
-void _LateralViscosityAnalytic_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
-	LateralViscosityAnalytic*         self           = (LateralViscosityAnalytic*)analyticSolution;
-	ConditionFunction*      condFunc;
-	
-	/* Construct Parent */
-	_FieldTest_AssignFromXML( self, cf, data );
-
-	/* Add temperature initial condition */
-	condFunc = ConditionFunction_New( LateralViscosityAnalytic_TemperatureIC, (Name)"LateralViscosityAnalytic_TemperatureIC"  );
-	ConditionFunction_Register_Add( condFunc_Register, condFunc );
-	
-	/* Create Analytic Fields */
-	self->velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  ); 
-
-	self->beta = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"beta", 0.0  );
-	self->wavenumberX = Stg_ComponentFactory_GetRootDictInt( cf, "wavenumberX", 1 );
-	self->wavenumberY = Stg_ComponentFactory_GetRootDictInt( cf, "wavenumberY", 1 );
-}
-
-void _LateralViscosityAnalytic_Build( void* analyticSolution, void* data ) {
-	LateralViscosityAnalytic*         self = (LateralViscosityAnalytic*)analyticSolution;
-
-   Stg_Component_Build( self->velocityField, data, False ); 
-	_FieldTest_Build( self, data );
-
-	self->_analyticSolutionList = Memory_Alloc_Array_Unnamed( FieldTest_AnalyticSolutionFunc*, 1 );
-	self->_analyticSolutionList[0] = _LateralViscosityAnalytic_VelocityFunction;
-}
-
-void _LateralViscosityAnalytic_Initialise( void* analyticSolution, void* data ) {
-	LateralViscosityAnalytic*         self = (LateralViscosityAnalytic*)analyticSolution;
-
-   Stg_Component_Initialise( self->velocityField, data, False ); 
-	_FieldTest_Initialise( self, data );
-}
-
-void _LateralViscosityAnalytic_Destroy( void* analyticSolution, void* data ) {
-	LateralViscosityAnalytic*         self = (LateralViscosityAnalytic*)analyticSolution;
-
-   _FieldTest_Destroy( self, data );
-   Stg_Component_Destroy( self->velocityField, data, False ); 
-}
-
-
-void* _LateralViscosityAnalytic_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(LateralViscosityAnalytic);
-	Type                                                      type = LateralViscosityAnalytic_Type;
-	Stg_Class_DeleteFunction*                              _delete = _FieldTest_Delete;
-	Stg_Class_PrintFunction*                                _print = _FieldTest_Print;
-	Stg_Class_CopyFunction*                                  _copy = _FieldTest_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _LateralViscosityAnalytic_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _LateralViscosityAnalytic_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _LateralViscosityAnalytic_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _LateralViscosityAnalytic_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _FieldTest_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _LateralViscosityAnalytic_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 Underworld_LateralViscosityAnalytic_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, LateralViscosityAnalytic_Type, (Name)"0", _LateralViscosityAnalytic_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/LateralViscosityAnalytic/LateralViscosityAnalytic.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/LateralViscosityAnalytic/LateralViscosityAnalytic.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,470 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: LateralViscosityAnalytic.c 628 2007-11-14 03:59:03Z RobertTurnbull $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Rheology/Rheology.h>
+
+#include <assert.h>
+
+#define SMALL 1.0e-5
+#define IS_ODD(A)   ( (A) % 2 == 1 )
+
+const Type LateralViscosityAnalytic_Type = "LateralViscosityAnalytic";
+
+typedef struct {
+	__FieldTest
+	double                  beta;
+	int                     wavenumberX;
+	int                     wavenumberY;
+	FeVariable*		velocityField;
+} LateralViscosityAnalytic;
+
+/** Analytic Solution taken from 
+ *  Shijie Zhong. Analytic solutions for Stokes' flow with lateral variations in viscosity. Geophys. J. Int., 124:18-28, 1996.
+ *  All equations refer to this paper */
+
+void LateralViscosityAnalytic_TemperatureIC( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
+	DomainContext*  	context            = (DomainContext*)_context;
+	FeVariable*             temperatureField   = (FeVariable*) FieldVariable_Register_GetByName( context->fieldVariable_Register, "TemperatureField" );
+	FeMesh* 		mesh               = temperatureField->feMesh;
+	double*                 result             = (double*) _result;
+	Dictionary*             dictionary         = context->dictionary;
+	double*                 coord;
+	double                  x; 
+	double                  y;
+	double                  kx;
+	double                  ky;
+	int                     wavenumberX;
+	int                     wavenumberY;
+	Coord			min, max;
+	double                  L;
+	
+	/* Find coordinate of node */
+	coord = Mesh_GetVertex( mesh, node_lI );
+
+	/* Make sure that the box has right dimensions */
+	Mesh_GetGlobalCoordRange( mesh, min, max );
+	assert( ( max[ J_AXIS ] - min[ J_AXIS ] - 1.0 ) < SMALL );
+	L = max[ I_AXIS ] - min[ I_AXIS ];
+
+	x = coord[ I_AXIS ] - min[ I_AXIS ];
+	y = coord[ J_AXIS ] - min[ J_AXIS ];
+
+	wavenumberX = Dictionary_GetInt_WithDefault( dictionary, (Dictionary_Entry_Key)"wavenumberX", 1  );
+	wavenumberY = Dictionary_GetInt_WithDefault( dictionary, (Dictionary_Entry_Key)"wavenumberY", 1 );
+
+	kx = wavenumberX * M_PI/ L;
+	ky = wavenumberY * M_PI;
+
+	*result = sin( ky * y ) * cos( kx * x  );
+}
+
+void _LateralViscosityAnalytic_VelocityFunction( void* analyticSolution, double* coord, double* velocity ) {
+	LateralViscosityAnalytic*         self               = (LateralViscosityAnalytic*)analyticSolution;
+	FeMesh*			mesh = self->elementMesh;
+	Coord			min, max;
+	Cmplx                   N                  = {0,0};
+	double                  chi1;
+	double                  chi2;
+	Cmplx                   sumX;
+	Cmplx                   sumY;
+	Cmplx                   m[5];                       /* CRAPPY FORTRAN ARRAYS */
+	Cmplx                   mSquared[5];
+	Cmplx                   mExp[5];
+	Cmplx                   N1;
+	Cmplx                   N2;
+	Cmplx                   N3;
+	Cmplx                   N4;
+	double                  beta2_4kn;
+	Cmplx                   lambda1;
+	Cmplx                   lambda2;
+	Cmplx                   n1;
+	Cmplx                   n2;
+	Cmplx                   n1_minus_beta;
+	Cmplx                   n2_minus_beta;
+	Cmplx                   M;
+	Cmplx                   oneOnM;
+	Cmplx                   tmp;
+	double                  beta;
+	double                  kn;
+	Index                   index;
+	Index                   i;
+	Index                   j;
+	Index                   h;
+	Index                   k;
+	double                  L;
+	double                  kx;
+	double                  ky;
+	Cmplx                   A1;
+	Cmplx                   A2;
+	Cmplx                   A3;
+	Cmplx                   A4;
+	Cmplx                   exp_n1x;
+	Cmplx                   exp_n2x;
+	Cmplx                   a1End;
+	Cmplx                   a2End;
+	double                  x;
+	double                  y;
+	double                  factorA;
+	double                  factorB;
+	int                     wavenumberX;
+	int                     wavenumberY;
+	double                  sqRootValue;
+
+	Mesh_GetGlobalCoordRange( mesh, min, max );
+	x = coord[ I_AXIS ] - min[ I_AXIS ];
+	y = coord[ J_AXIS ] - min[ J_AXIS ];
+
+	beta = self->beta;
+	wavenumberX = self->wavenumberX;
+	wavenumberY = self->wavenumberY;
+	
+	L    = max[ I_AXIS ] - min[ I_AXIS ];
+	kx   = wavenumberX * M_PI/ L;
+	ky   = wavenumberY * M_PI;
+	kn   = ky; 
+
+	beta2_4kn = beta * beta + 4.0 * kn * kn;
+	sqRootValue = beta2_4kn * beta2_4kn + 16.0 * beta * beta * kn * kn;
+	sqRootValue = sqrt( sqRootValue );
+	chi1 = sqrt( 0.5 * (  beta2_4kn + sqRootValue ) );
+	chi2 = sqrt( 0.5 * ( -beta2_4kn + sqRootValue ) );
+
+	n1[ REAL_PART ] = 0.5 * (beta + chi1);
+	n1[ IMAG_PART ] = 0.5 * (chi2);
+	
+	n2[ REAL_PART ] = 0.5 * (beta - chi1);
+	n2[ IMAG_PART ] = 0.5 * (-chi2);
+
+	Cmplx_Copy( n1, m[1] );
+	Cmplx_Conjugate( n1, m[2] );
+	Cmplx_Copy( n2, m[3] );
+	Cmplx_Conjugate( n2, m[4] );
+			
+	for ( index = 1 ; index <= 4 ; index++ ) {
+		Cmplx_Multiply( m[index], m[index], mSquared[index] );
+		Cmplx_RealMultiply( m[ index ], -L, tmp );
+		Cmplx_Exp( tmp, mExp[ index ] );
+	}
+
+	/* Calculate M - Equation A7 */
+	Cmplx_Subtract( m[2], m[1], oneOnM );
+	Cmplx_Subtract( m[3], m[1], tmp );
+	Cmplx_Multiply( oneOnM, tmp, oneOnM );
+	Cmplx_Subtract( m[4], m[1], tmp );
+	Cmplx_Multiply( oneOnM, tmp, oneOnM );
+	Cmplx_RealDivideByCmplx( oneOnM, 1.0, M );
+
+	/* Calculate N - Equation A8 */
+	for ( j = 1 ; j <= 3 ; j++ ) {
+		for ( i = j+1 ; i <= 4 ; i++ ) {
+			Cmplx product = {0,0};
+			
+			/* Get h */
+			for ( h = 1 ; h <= 4 ; h++ ) {
+				if ( h != i && h != j )
+					break; /* Found h */
+			}
+
+			/* Get k */
+			for ( k = h+1 ; k <= 4 ; k++ ) {
+				if ( k != i && k != j )
+					break; /* Found k */
+			}			
+
+			product[ REAL_PART ] = IS_ODD( i + j ) ? 1.0 : -1.0;
+			
+			Cmplx_Multiply( product, mExp[ i ], product );
+			Cmplx_Multiply( product, mExp[ j ], product );
+
+			Cmplx_Subtract( mSquared[ k ], mSquared[ h ], tmp );
+			Cmplx_Multiply( product, tmp, product );
+
+			Cmplx_Subtract( mSquared[ i ], mSquared[ j ], tmp );
+			Cmplx_Multiply( product, tmp, product );
+
+			Cmplx_Add( N, product, N );
+		}
+	}
+
+	/* Build N1 - Equation A9 */
+	Cmplx_Subtract( mSquared[4], mSquared[3], tmp );
+	Cmplx_Multiply( tmp, mSquared[2], tmp );
+	Cmplx_Multiply( tmp, mExp[2], N1 ); 
+
+	Cmplx_Subtract( mSquared[4], mSquared[2], tmp );
+	Cmplx_Multiply( tmp, mSquared[3], tmp );
+	Cmplx_Multiply( tmp, mExp[3], tmp );
+	Cmplx_Subtract( N1, tmp, N1 );
+	
+	Cmplx_Subtract( mSquared[3], mSquared[2], tmp );
+	Cmplx_Multiply( tmp, mSquared[4], tmp );
+	Cmplx_Multiply( tmp, mExp[4], tmp );
+	Cmplx_Add( N1, tmp, N1 );
+	
+	/* Build N2 - Equation A10 */
+	Cmplx_Subtract( mSquared[4], mSquared[2], tmp );
+	Cmplx_Multiply( tmp, mSquared[1], tmp );
+	Cmplx_Multiply( tmp, mExp[1], N2 );
+
+	Cmplx_Subtract( mSquared[4], mSquared[1], tmp );
+	Cmplx_Multiply( tmp, mSquared[2], tmp );
+	Cmplx_Multiply( tmp, mExp[2], tmp );
+	Cmplx_Subtract( N2, tmp, N2 );
+
+	Cmplx_Subtract( mSquared[2], mSquared[1], tmp );
+	Cmplx_Multiply( tmp, mSquared[4], tmp );
+	Cmplx_Multiply( tmp, mExp[4], tmp );
+	Cmplx_Add( N2, tmp, N2 );
+
+	/* Build N3 - Equation A11 */
+	Cmplx_Subtract( mSquared[3], mSquared[4], tmp );
+	Cmplx_Multiply( tmp, mExp[2], N3 );
+
+	Cmplx_Subtract( mSquared[4], mSquared[2], tmp );
+	Cmplx_Multiply( tmp, mExp[3], tmp );
+	Cmplx_Add( N3, tmp, N3 );
+
+	Cmplx_Subtract( mSquared[2], mSquared[3], tmp );
+	Cmplx_Multiply( tmp, mExp[4], tmp );
+	Cmplx_Add( N3, tmp, N3 );
+
+	/* Build N4 - Equation A12 */
+	Cmplx_Subtract( mSquared[2], mSquared[4], tmp );
+	Cmplx_Multiply( tmp, mExp[1], N4 );
+
+	Cmplx_Subtract( mSquared[4], mSquared[1], tmp );
+	Cmplx_Multiply( tmp, mExp[2], tmp );
+	Cmplx_Add( N4, tmp, N4 );
+
+	Cmplx_Subtract( mSquared[1], mSquared[2], tmp );
+	Cmplx_Multiply( tmp, mExp[4], tmp );
+	Cmplx_Add( N4, tmp, N4 );
+
+    	/* Build lambda1 - Equation B8 */
+	Cmplx_AddReal( n1, - beta, n1_minus_beta );
+    	Cmplx_RealMultiply( n1_minus_beta,L, tmp );
+	Cmplx_Exp( tmp, tmp );
+    	Cmplx_RealMultiply(tmp, cos( kx * L ), tmp );
+	Cmplx_RealMinusCmplx( tmp, 1.0, tmp );
+    	Cmplx_RealMultiply(tmp, -kx, tmp );
+	Cmplx_Multiply( M, tmp, lambda1 );
+	
+	Cmplx_Multiply( n1_minus_beta, n1_minus_beta, tmp );
+	Cmplx_AddReal( tmp, kx * kx, tmp );
+
+	Cmplx_Division( lambda1, tmp, lambda1 );
+	
+	/* Build lambda2 - Equation B9 */
+	Cmplx_AddReal( n2, - beta, n2_minus_beta );
+	Cmplx_RealMultiply( n2_minus_beta,L, tmp );
+	Cmplx_Exp( tmp, tmp );
+	Cmplx_RealMultiply(tmp, cos( kx * L ), tmp );
+	Cmplx_RealMinusCmplx( tmp, 1.0, tmp );
+	Cmplx_RealMultiply(tmp, kx, tmp );
+	Cmplx_Multiply( M, tmp, lambda2 );
+	
+	Cmplx_Multiply( n2_minus_beta, n2_minus_beta, tmp );
+	Cmplx_AddReal( tmp, kx * kx, tmp );
+
+	Cmplx_Division( lambda2, tmp, lambda2 );
+
+	/* Build A1 - Equation B4 */
+	Cmplx_Multiply( mExp[1], lambda1, tmp );
+	factorA = tmp[ REAL_PART ];
+	Cmplx_Multiply( mExp[3], lambda2, tmp );
+	factorA += tmp[ REAL_PART ];
+	Cmplx_Division( N1, N, tmp );
+	Cmplx_RealMultiply( tmp, 2.0 * factorA, A1 );
+
+	Cmplx_Multiply( mExp[1], lambda1, tmp );
+	Cmplx_Multiply( tmp, mSquared[1], tmp );
+	factorB = tmp[ REAL_PART ];
+	Cmplx_Multiply( mExp[3], lambda2, tmp );
+	Cmplx_Multiply( tmp, mSquared[3], tmp );
+	factorB += tmp[ REAL_PART ];
+	Cmplx_Division( N3, N, tmp );
+	Cmplx_RealMultiply( tmp, 2.0 * factorB, tmp );
+	Cmplx_Add( A1, tmp, A1 );
+
+	Cmplx_Multiply( n1_minus_beta, n1_minus_beta, a1End );
+	Cmplx_AddReal( a1End, kx*kx, a1End );
+	Cmplx_RealDivideByCmplx( a1End, kx, a1End );
+	Cmplx_Multiply( a1End, M, a1End );
+	Cmplx_Add( A1, a1End, A1 );
+
+	/* Build A2 - Equation B5 */
+	Cmplx_Division( N2, N, tmp );
+	Cmplx_RealMultiply( tmp, 2.0 * factorA, A2 );
+
+	Cmplx_Division( N4, N, tmp );
+	Cmplx_RealMultiply( tmp, 2.0 * factorB, tmp );
+	Cmplx_Add( A2, tmp, A2 );
+
+	Cmplx_Multiply( n2_minus_beta, n2_minus_beta, a2End );
+	Cmplx_AddReal( a2End, kx*kx, a2End );
+	Cmplx_RealDivideByCmplx( a2End, kx, a2End );
+	Cmplx_Multiply( a2End, M, a2End );
+	Cmplx_Subtract( A2, a2End, A2 );	
+
+	/* Build A3 - Equation B6 */
+	Cmplx_Subtract( a2End, a1End, A3 );
+
+	/* Build A4 - Equation B7 */
+	Cmplx_Multiply( n1_minus_beta, n1_minus_beta, tmp );
+	Cmplx_AddReal( tmp, kx*kx, tmp );
+	Cmplx_Division( n1_minus_beta, tmp, tmp );
+	Cmplx_Multiply( tmp, M, A4 );
+
+	Cmplx_Multiply( n2_minus_beta, n2_minus_beta, tmp );
+	Cmplx_AddReal( tmp, kx*kx, tmp );
+	Cmplx_Division( n2_minus_beta, tmp, tmp );
+	Cmplx_Multiply( tmp, M, tmp );
+	Cmplx_Subtract( A4, tmp, A4 );
+	
+	/*************************************** Get Velocities - Eqn B10 - B11 *****************************************/
+	
+	/* Get First Term in Sums */
+	Cmplx_RealMultiply( n1, -x, tmp );
+	Cmplx_Exp( tmp, exp_n1x );
+	Cmplx_Multiply( A1, exp_n1x, sumX );
+
+	Cmplx_Copy( sumX, sumY );
+	Cmplx_Multiply( sumY, n1, sumY );
+	Cmplx_RealMultiply( sumY, -1.0, sumY );
+
+	/* Add second term in sum */
+	Cmplx_RealMultiply( n2, -x, tmp );
+	Cmplx_Exp( tmp, exp_n2x );
+	Cmplx_Multiply( A2, exp_n2x, tmp );
+	Cmplx_Add( sumX, tmp, sumX );
+
+	Cmplx_Multiply( tmp, n2, tmp );
+	Cmplx_RealMultiply( tmp, -1.0, tmp );
+	Cmplx_Add( sumY, tmp, sumY );
+	
+	/* Add third term in sum */
+	sumX[ REAL_PART ] += (A3[ REAL_PART ] * cos( kx*x ) + A4[ REAL_PART ] * sin( kx * x ) ) * exp( -beta*x );
+	sumY[ REAL_PART ] += exp( -beta * x ) * (
+		(kx * A4[REAL_PART] - beta * A3[ REAL_PART ]) * cos( kx * x ) - 
+		(kx * A3[REAL_PART] + beta * A4[ REAL_PART ]) * sin( kx * x ) );
+
+	velocity[ I_AXIS ] = -2.0 * kx * ky * cos( ky * y ) * sumX[ REAL_PART ]; 
+	velocity[ J_AXIS ] = 2.0 * kx * sin( ky * y ) * sumY[ REAL_PART ]; 
+}
+
+void _LateralViscosityAnalytic_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
+	LateralViscosityAnalytic*         self           = (LateralViscosityAnalytic*)analyticSolution;
+	ConditionFunction*      condFunc;
+	
+	/* Construct Parent */
+	_FieldTest_AssignFromXML( self, cf, data );
+
+	/* Add temperature initial condition */
+	condFunc = ConditionFunction_New( LateralViscosityAnalytic_TemperatureIC, (Name)"LateralViscosityAnalytic_TemperatureIC"  );
+	ConditionFunction_Register_Add( condFunc_Register, condFunc );
+	
+	/* Create Analytic Fields */
+	self->velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  ); 
+
+	self->beta = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"beta", 0.0  );
+	self->wavenumberX = Stg_ComponentFactory_GetRootDictInt( cf, "wavenumberX", 1 );
+	self->wavenumberY = Stg_ComponentFactory_GetRootDictInt( cf, "wavenumberY", 1 );
+}
+
+void _LateralViscosityAnalytic_Build( void* analyticSolution, void* data ) {
+	LateralViscosityAnalytic*         self = (LateralViscosityAnalytic*)analyticSolution;
+
+   Stg_Component_Build( self->velocityField, data, False ); 
+	_FieldTest_Build( self, data );
+
+	self->_analyticSolutionList = Memory_Alloc_Array_Unnamed( FieldTest_AnalyticSolutionFunc*, 1 );
+	self->_analyticSolutionList[0] = _LateralViscosityAnalytic_VelocityFunction;
+}
+
+void _LateralViscosityAnalytic_Initialise( void* analyticSolution, void* data ) {
+	LateralViscosityAnalytic*         self = (LateralViscosityAnalytic*)analyticSolution;
+
+   Stg_Component_Initialise( self->velocityField, data, False ); 
+	_FieldTest_Initialise( self, data );
+}
+
+void _LateralViscosityAnalytic_Destroy( void* analyticSolution, void* data ) {
+	LateralViscosityAnalytic*         self = (LateralViscosityAnalytic*)analyticSolution;
+
+   _FieldTest_Destroy( self, data );
+   Stg_Component_Destroy( self->velocityField, data, False ); 
+}
+
+
+void* _LateralViscosityAnalytic_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(LateralViscosityAnalytic);
+	Type                                                      type = LateralViscosityAnalytic_Type;
+	Stg_Class_DeleteFunction*                              _delete = _FieldTest_Delete;
+	Stg_Class_PrintFunction*                                _print = _FieldTest_Print;
+	Stg_Class_CopyFunction*                                  _copy = _FieldTest_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _LateralViscosityAnalytic_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _LateralViscosityAnalytic_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _LateralViscosityAnalytic_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _LateralViscosityAnalytic_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _FieldTest_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _LateralViscosityAnalytic_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 Underworld_LateralViscosityAnalytic_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, LateralViscosityAnalytic_Type, (Name)"0", _LateralViscosityAnalytic_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/NonNewtonianShearSolution/NonNewtonianShearSolution.c
--- a/SysTest/AnalyticPlugins/NonNewtonianShearSolution/NonNewtonianShearSolution.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,210 +0,0 @@
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Rheology/Rheology.h>
-
-#include <assert.h>
-
-typedef struct {
-	__FieldTest
-	MaterialViscosity*               materialViscosity;
-	Mesh*				 mesh;
-	NonNewtonian*                    nonNewtonianRheology;
-	double                           velocityTopOfBox;
-	FeVariable*			 velocityField;
-	FeVariable*			 strainRateField;
-	FeVariable*			 stressField;
-	FeVariable*			 viscosityField;
-} NonNewtonianShearSolution;
-
-const Type NonNewtonianShearSolution_Type = "NonNewtonianShearSolution";
-
-double NonNewtonianShearSolution_Dt( FiniteElementContext* context ) { return 0.01; }
-
-void NonNewtonianShearSolution_VelocityFunction( void* analyticSolution, double* coord, double* velocity ) {
-	NonNewtonianShearSolution*   self = (NonNewtonianShearSolution*)analyticSolution;
-	double                       height;
-	double			     min[3], max[3];
-	
-	/* Get Parameters */
-	Mesh_GetGlobalCoordRange( self->mesh, min, max );
-	height = max[J_AXIS] - min[J_AXIS];
-
-	velocity[ I_AXIS ] = coord[J_AXIS] / height * self->velocityTopOfBox;
-	velocity[ J_AXIS ] = 0.0;
-}
-
-void NonNewtonianShearSolution_StrainRateFunction( void* analyticSolution, double* coord, double* strainRate ) {
-	NonNewtonianShearSolution*   self = (NonNewtonianShearSolution*)analyticSolution;
-	double                       height;
-	double			     min[3], max[3];
-	
-	/* Get Parameters */
-	Mesh_GetGlobalCoordRange( self->mesh, min, max );
-	height = max[J_AXIS] - min[J_AXIS];
-
-	strainRate[ 0 ] = 0.0;
-	strainRate[ 1 ] = 0.0;
-	strainRate[ 2 ] = 0.5 * self->velocityTopOfBox / height;
-}
-
-void NonNewtonianShearSolution_StressFunction( void* analyticSolution, double* coord, double* stress ) {
-	NonNewtonianShearSolution*   self = (NonNewtonianShearSolution*)analyticSolution;
-	double                         eta;
-	double                         height;
-	double                         tau;
-	double                         n;
-	double			     min[3], max[3];
-	
-	/* Get Parameters */
-	Mesh_GetGlobalCoordRange( self->mesh, min, max );
-	eta = self->materialViscosity->eta0;
-	n = self->nonNewtonianRheology->n;
-	height = max[J_AXIS] - min[J_AXIS];
-
-	/* Calculate stress - without considering cohesion */
-	tau = pow( eta * self->velocityTopOfBox / height, 1/n);
-
-	/* Calculate Analytic Solution for the stress */
-	stress[0] = 0.0;
-	stress[1] = 0.0;
-	stress[2] = tau;
-}
-
-
-void NonNewtonianShearSolution_ViscosityFunction( void* analyticSolution, double* coord, double* viscosity ) {
-	NonNewtonianShearSolution*     self = (NonNewtonianShearSolution*)analyticSolution;
-	double                         eta0;
-	double                         height;
-	double                         n;
-	double			     min[3], max[3];
-	
-	/* Get Parameters */
-	eta0 = self->materialViscosity->eta0;
-	n = self->nonNewtonianRheology->n;
-	Mesh_GetGlobalCoordRange( self->mesh, min, max );
-	height = max[J_AXIS] - min[J_AXIS];
-
-	/* Calculate stress - without considering cohesion */
-	*viscosity = eta0 * pow( eta0 * self->velocityTopOfBox / height, 1/n-1.0);
-}
-
-void NonNewtonianShearSolution_UpdateVelocityBC( NonNewtonianShearSolution* self, FiniteElementContext* context ) {
-	self->velocityTopOfBox += context->dt;
-}
-
-void NonNewtonianShearSolution_VelocityBC( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
-	FiniteElementContext*		context       = (FiniteElementContext*)_context;
-	NonNewtonianShearSolution*	self          = (NonNewtonianShearSolution*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)NonNewtonianShearSolution_Type );
-	double*				result        = (double* ) _result;
-
-	*result = self->velocityTopOfBox;
-}
-
-void _NonNewtonianShearSolution_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
-	NonNewtonianShearSolution* self = (NonNewtonianShearSolution*)analyticSolution;
-	FiniteElementContext*          context;
-
-	/* Construct parent */
-	_FieldTest_AssignFromXML( self, cf, data );
-	context = Stg_CheckType( self->context, FiniteElementContext );
-	
-	ConditionFunction_Register_Add( condFunc_Register, ConditionFunction_New( NonNewtonianShearSolution_VelocityBC, (Name)"ShearTrigger")  );	
-
-	/* Create Analytic Velocity Field */
-	self->velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
-	/* Create Analytic Strain Rate Field */
-	self->strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, True, data  );
-	/* Create Analytic Stress Field */
-	self->stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, True, data  );
-	/* Create Analytic Viscosity Field */
-	self->viscosityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"ViscosityField", FeVariable, True, data  );
-
-	self->materialViscosity = Stg_ComponentFactory_ConstructByName( cf, (Name)"layerViscosity", MaterialViscosity, True, data  );
-	self->nonNewtonianRheology = Stg_ComponentFactory_ConstructByName( cf, (Name)"nonNewtonianRheology", NonNewtonian, True, data  );
-	self->mesh = Stg_ComponentFactory_ConstructByName( cf, (Name)"linearMesh", Mesh, True, data  );
-
-	/* Set Velocity Stuff */
-	EP_AppendClassHook( Context_GetEntryPoint( context, AbstractContext_EP_UpdateClass ), NonNewtonianShearSolution_UpdateVelocityBC, self );
-	EP_AppendClassHook( Context_GetEntryPoint( context, FiniteElementContext_EP_CalcDt ), NonNewtonianShearSolution_Dt, context );
-	self->velocityTopOfBox = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"velocityTopOfBox", 0.5  );
-}
-
-void _NonNewtonianShearSolution_Build( void* analyticSolution, void* data ) {
-	NonNewtonianShearSolution* self = (NonNewtonianShearSolution*)analyticSolution;
-
-   Stg_Component_Build( self->strainRateField, data, False );
-   Stg_Component_Build( self->stressField, data, False );
-   Stg_Component_Build( self->viscosityField, data, False );
-   Stg_Component_Build( self->materialViscosity, data, False );
-   Stg_Component_Build( self->nonNewtonianRheology, data, False );
-   Stg_Component_Build( self->mesh, data, False );
-	self->_analyticSolutionList = Memory_Alloc_Array_Unnamed( FieldTest_AnalyticSolutionFunc*, 4 );
-	self->_analyticSolutionList[0] = NonNewtonianShearSolution_VelocityFunction;
-	self->_analyticSolutionList[1] = NonNewtonianShearSolution_StrainRateFunction;
-	self->_analyticSolutionList[2] = NonNewtonianShearSolution_StressFunction;
-	self->_analyticSolutionList[3] = NonNewtonianShearSolution_ViscosityFunction;
-   
-   _FieldTest_Build( self, data );
-
-}
-
-void _NonNewtonianShearSolution_Initialise( void* analyticSolution, void* data ) {
-	NonNewtonianShearSolution* self = (NonNewtonianShearSolution*)analyticSolution;
-
-   Stg_Component_Initialise( self->strainRateField, data, False );
-   Stg_Component_Initialise( self->stressField, data, False );
-   Stg_Component_Initialise( self->viscosityField, data, False );
-   Stg_Component_Initialise( self->materialViscosity, data, False );
-   Stg_Component_Initialise( self->nonNewtonianRheology, data, False );
-   Stg_Component_Initialise( self->mesh, data, False );
-   
-   _FieldTest_Initialise( self, data );
-}
-
-void _NonNewtonianShearSolution_Destroy( void* analyticSolution, void* data ) {
-	NonNewtonianShearSolution* self = (NonNewtonianShearSolution*)analyticSolution;
-
-	_FieldTest_Destroy( self, data );
-
-   Stg_Component_Destroy( self->strainRateField, data, False );
-   Stg_Component_Destroy( self->stressField, data, False );
-   Stg_Component_Destroy( self->viscosityField, data, False );
-   Stg_Component_Destroy( self->materialViscosity, data, False );
-   Stg_Component_Destroy( self->nonNewtonianRheology, data, False );
-   Stg_Component_Destroy( self->mesh, data, False );
-}
-
-
-/* This function will provide StGermain the abilty to instantiate (create) this codelet on demand. */
-void* _NonNewtonianShearSolution_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(NonNewtonianShearSolution);
-	Type                                                      type = NonNewtonianShearSolution_Type;
-	Stg_Class_DeleteFunction*                              _delete = _FieldTest_Delete;
-	Stg_Class_PrintFunction*                                _print = _FieldTest_Print;
-	Stg_Class_CopyFunction*                                  _copy = _FieldTest_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _NonNewtonianShearSolution_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _NonNewtonianShearSolution_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _NonNewtonianShearSolution_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _NonNewtonianShearSolution_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _FieldTest_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _NonNewtonianShearSolution_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  );	
-}
-	
-/* This function is automatically run by StGermain when this plugin is loaded. The name must be "<plugin-name>_Register". */
-Index Underworld_NonNewtonianShearSolution_Register( PluginsManager* pluginsManager ) {
-	/* A plugin is only properly registered once it returns the handle provided when submitting a codelet to StGermain. */
-	return PluginsManager_Submit( pluginsManager, NonNewtonianShearSolution_Type, (Name)"0", _NonNewtonianShearSolution_DefaultNew  );
-}
-
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/NonNewtonianShearSolution/NonNewtonianShearSolution.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/NonNewtonianShearSolution/NonNewtonianShearSolution.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,210 @@
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Rheology/Rheology.h>
+
+#include <assert.h>
+
+typedef struct {
+	__FieldTest
+	MaterialViscosity*               materialViscosity;
+	Mesh*				 mesh;
+	NonNewtonian*                    nonNewtonianRheology;
+	double                           velocityTopOfBox;
+	FeVariable*			 velocityField;
+	FeVariable*			 strainRateField;
+	FeVariable*			 stressField;
+	FeVariable*			 viscosityField;
+} NonNewtonianShearSolution;
+
+const Type NonNewtonianShearSolution_Type = "NonNewtonianShearSolution";
+
+double NonNewtonianShearSolution_Dt( FiniteElementContext* context ) { return 0.01; }
+
+void NonNewtonianShearSolution_VelocityFunction( void* analyticSolution, double* coord, double* velocity ) {
+	NonNewtonianShearSolution*   self = (NonNewtonianShearSolution*)analyticSolution;
+	double                       height;
+	double			     min[3], max[3];
+	
+	/* Get Parameters */
+	Mesh_GetGlobalCoordRange( self->mesh, min, max );
+	height = max[J_AXIS] - min[J_AXIS];
+
+	velocity[ I_AXIS ] = coord[J_AXIS] / height * self->velocityTopOfBox;
+	velocity[ J_AXIS ] = 0.0;
+}
+
+void NonNewtonianShearSolution_StrainRateFunction( void* analyticSolution, double* coord, double* strainRate ) {
+	NonNewtonianShearSolution*   self = (NonNewtonianShearSolution*)analyticSolution;
+	double                       height;
+	double			     min[3], max[3];
+	
+	/* Get Parameters */
+	Mesh_GetGlobalCoordRange( self->mesh, min, max );
+	height = max[J_AXIS] - min[J_AXIS];
+
+	strainRate[ 0 ] = 0.0;
+	strainRate[ 1 ] = 0.0;
+	strainRate[ 2 ] = 0.5 * self->velocityTopOfBox / height;
+}
+
+void NonNewtonianShearSolution_StressFunction( void* analyticSolution, double* coord, double* stress ) {
+	NonNewtonianShearSolution*   self = (NonNewtonianShearSolution*)analyticSolution;
+	double                         eta;
+	double                         height;
+	double                         tau;
+	double                         n;
+	double			     min[3], max[3];
+	
+	/* Get Parameters */
+	Mesh_GetGlobalCoordRange( self->mesh, min, max );
+	eta = self->materialViscosity->eta0;
+	n = self->nonNewtonianRheology->n;
+	height = max[J_AXIS] - min[J_AXIS];
+
+	/* Calculate stress - without considering cohesion */
+	tau = pow( eta * self->velocityTopOfBox / height, 1/n);
+
+	/* Calculate Analytic Solution for the stress */
+	stress[0] = 0.0;
+	stress[1] = 0.0;
+	stress[2] = tau;
+}
+
+
+void NonNewtonianShearSolution_ViscosityFunction( void* analyticSolution, double* coord, double* viscosity ) {
+	NonNewtonianShearSolution*     self = (NonNewtonianShearSolution*)analyticSolution;
+	double                         eta0;
+	double                         height;
+	double                         n;
+	double			     min[3], max[3];
+	
+	/* Get Parameters */
+	eta0 = self->materialViscosity->eta0;
+	n = self->nonNewtonianRheology->n;
+	Mesh_GetGlobalCoordRange( self->mesh, min, max );
+	height = max[J_AXIS] - min[J_AXIS];
+
+	/* Calculate stress - without considering cohesion */
+	*viscosity = eta0 * pow( eta0 * self->velocityTopOfBox / height, 1/n-1.0);
+}
+
+void NonNewtonianShearSolution_UpdateVelocityBC( NonNewtonianShearSolution* self, FiniteElementContext* context ) {
+	self->velocityTopOfBox += context->dt;
+}
+
+void NonNewtonianShearSolution_VelocityBC( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
+	FiniteElementContext*		context       = (FiniteElementContext*)_context;
+	NonNewtonianShearSolution*	self          = (NonNewtonianShearSolution*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)NonNewtonianShearSolution_Type );
+	double*				result        = (double* ) _result;
+
+	*result = self->velocityTopOfBox;
+}
+
+void _NonNewtonianShearSolution_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
+	NonNewtonianShearSolution* self = (NonNewtonianShearSolution*)analyticSolution;
+	FiniteElementContext*          context;
+
+	/* Construct parent */
+	_FieldTest_AssignFromXML( self, cf, data );
+	context = Stg_CheckType( self->context, FiniteElementContext );
+	
+	ConditionFunction_Register_Add( condFunc_Register, ConditionFunction_New( NonNewtonianShearSolution_VelocityBC, (Name)"ShearTrigger")  );	
+
+	/* Create Analytic Velocity Field */
+	self->velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
+	/* Create Analytic Strain Rate Field */
+	self->strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, True, data  );
+	/* Create Analytic Stress Field */
+	self->stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, True, data  );
+	/* Create Analytic Viscosity Field */
+	self->viscosityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"ViscosityField", FeVariable, True, data  );
+
+	self->materialViscosity = Stg_ComponentFactory_ConstructByName( cf, (Name)"layerViscosity", MaterialViscosity, True, data  );
+	self->nonNewtonianRheology = Stg_ComponentFactory_ConstructByName( cf, (Name)"nonNewtonianRheology", NonNewtonian, True, data  );
+	self->mesh = Stg_ComponentFactory_ConstructByName( cf, (Name)"linearMesh", Mesh, True, data  );
+
+	/* Set Velocity Stuff */
+	EP_AppendClassHook( Context_GetEntryPoint( context, AbstractContext_EP_UpdateClass ), NonNewtonianShearSolution_UpdateVelocityBC, self );
+	EP_AppendClassHook( Context_GetEntryPoint( context, FiniteElementContext_EP_CalcDt ), NonNewtonianShearSolution_Dt, context );
+	self->velocityTopOfBox = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"velocityTopOfBox", 0.5  );
+}
+
+void _NonNewtonianShearSolution_Build( void* analyticSolution, void* data ) {
+	NonNewtonianShearSolution* self = (NonNewtonianShearSolution*)analyticSolution;
+
+   Stg_Component_Build( self->strainRateField, data, False );
+   Stg_Component_Build( self->stressField, data, False );
+   Stg_Component_Build( self->viscosityField, data, False );
+   Stg_Component_Build( self->materialViscosity, data, False );
+   Stg_Component_Build( self->nonNewtonianRheology, data, False );
+   Stg_Component_Build( self->mesh, data, False );
+	self->_analyticSolutionList = Memory_Alloc_Array_Unnamed( FieldTest_AnalyticSolutionFunc*, 4 );
+	self->_analyticSolutionList[0] = NonNewtonianShearSolution_VelocityFunction;
+	self->_analyticSolutionList[1] = NonNewtonianShearSolution_StrainRateFunction;
+	self->_analyticSolutionList[2] = NonNewtonianShearSolution_StressFunction;
+	self->_analyticSolutionList[3] = NonNewtonianShearSolution_ViscosityFunction;
+   
+   _FieldTest_Build( self, data );
+
+}
+
+void _NonNewtonianShearSolution_Initialise( void* analyticSolution, void* data ) {
+	NonNewtonianShearSolution* self = (NonNewtonianShearSolution*)analyticSolution;
+
+   Stg_Component_Initialise( self->strainRateField, data, False );
+   Stg_Component_Initialise( self->stressField, data, False );
+   Stg_Component_Initialise( self->viscosityField, data, False );
+   Stg_Component_Initialise( self->materialViscosity, data, False );
+   Stg_Component_Initialise( self->nonNewtonianRheology, data, False );
+   Stg_Component_Initialise( self->mesh, data, False );
+   
+   _FieldTest_Initialise( self, data );
+}
+
+void _NonNewtonianShearSolution_Destroy( void* analyticSolution, void* data ) {
+	NonNewtonianShearSolution* self = (NonNewtonianShearSolution*)analyticSolution;
+
+	_FieldTest_Destroy( self, data );
+
+   Stg_Component_Destroy( self->strainRateField, data, False );
+   Stg_Component_Destroy( self->stressField, data, False );
+   Stg_Component_Destroy( self->viscosityField, data, False );
+   Stg_Component_Destroy( self->materialViscosity, data, False );
+   Stg_Component_Destroy( self->nonNewtonianRheology, data, False );
+   Stg_Component_Destroy( self->mesh, data, False );
+}
+
+
+/* This function will provide StGermain the abilty to instantiate (create) this codelet on demand. */
+void* _NonNewtonianShearSolution_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(NonNewtonianShearSolution);
+	Type                                                      type = NonNewtonianShearSolution_Type;
+	Stg_Class_DeleteFunction*                              _delete = _FieldTest_Delete;
+	Stg_Class_PrintFunction*                                _print = _FieldTest_Print;
+	Stg_Class_CopyFunction*                                  _copy = _FieldTest_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _NonNewtonianShearSolution_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _NonNewtonianShearSolution_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _NonNewtonianShearSolution_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _NonNewtonianShearSolution_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _FieldTest_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _NonNewtonianShearSolution_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  );	
+}
+	
+/* This function is automatically run by StGermain when this plugin is loaded. The name must be "<plugin-name>_Register". */
+Index Underworld_NonNewtonianShearSolution_Register( PluginsManager* pluginsManager ) {
+	/* A plugin is only properly registered once it returns the handle provided when submitting a codelet to StGermain. */
+	return PluginsManager_Submit( pluginsManager, NonNewtonianShearSolution_Type, (Name)"0", _NonNewtonianShearSolution_DefaultNew  );
+}
+
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Trubitsyn2006/Trubitsyn2006.c
--- a/SysTest/AnalyticPlugins/Trubitsyn2006/Trubitsyn2006.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,354 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: Trubitsyn2006.c 737 2008-05-23 06:08:42Z RobertTurnbull $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Rheology/Rheology.h>
-
-#include <assert.h>
-#include <string.h>
-
-#define SMALL 1.0e-5
-#define IS_ODD(A)   ( (A) % 2 == 1 )
-
-const Type Trubitsyn2006_Type = "Underworld_Trubitsyn2006";
-
-typedef struct {
-	__FieldTest
-	FieldTest_AnalyticSolutionFunc* viscosityFunc;
-	FieldTest_AnalyticSolutionFunc* viscosityDerivativeFunc;
-	FeVariable*                        velocityField;
-	FeVariable*                        pressureField;
-	double                             Ra;
-	double                             T0;
-	int                                wavenumberX;
-	int                                wavenumberY;
-} Trubitsyn2006;
-
-/** Analytic Solution taken from 
- * V. P. Trubitsyn, A. A. Baranov, A. N. Eyseev, and A. P. Trubitsyn. 
- * 	Exact analytical solutions of the stokes equation for testing the equations of mantle convection with a variable viscosity. 
- *	Izvestiya Physics of the Solid Earth, 42(7):537–545, 2006. 
- *  
- *  All equations refer to this paper */
-
-double Trubitsyn_G( double x, double x0, double a ) {
-	return 1/(1 + exp( -2.0 * a * ( x - x0 ) ) );
-}
-double Trubitsyn_GDeriv( double x, double x0, double a ) {
-	return 2.0 * a * pow( exp( a * ( x - x0 ) ) + exp( -a * ( x - x0 ) ), -2.0 );
-}
-
-void _Trubitsyn2006_ViscosityFunc_Isoviscous( void* analyticSolution, double* coord, double* eta ) {
-	*eta = 1.0;
-}
-void _Trubitsyn2006_ViscosityDerivativeFunc_Isoviscous( void* analyticSolution, double* coord, double* viscDeriv ) {
-	viscDeriv[0] = 0.0;
-	viscDeriv[1] = 0.0;
-}
-void _Trubitsyn2006_ViscosityFunc_Model1( void* analyticSolution, double* coord, double* eta ) {
-	*eta = 1.0 + 100.0 * coord[ I_AXIS ] * coord[ J_AXIS ];
-}
-void _Trubitsyn2006_ViscosityDerivativeFunc_Model1( void* analyticSolution, double* coord, double* viscDeriv ) {
-	viscDeriv[0] = 100.0 * coord[ J_AXIS ];
-	viscDeriv[1] = 100.0 * coord[ I_AXIS ];
-}
-void _Trubitsyn2006_ViscosityFunc_Model2( void* analyticSolution, double* coord, double* eta ) {
-//	*eta = 999.0 * ( 1.0 - Trubitsyn_G( coord[ I_AXIS ], 0.5, 50 ) ) + 1;
-	*eta = ( coord[ I_AXIS ] <= 0.5 ? 1000.0 : 1 );
-}
-void _Trubitsyn2006_ViscosityDerivativeFunc_Model2( void* analyticSolution, double* coord, double* viscDeriv ) {
-//	viscDeriv[0] = -999.0 * Trubitsyn_GDeriv( coord[ I_AXIS ], 0.5, 50 );
-	viscDeriv[0] = 0.0;
-	viscDeriv[1] = 0.0;
-}
-void _Trubitsyn2006_ViscosityFunc_Model3( void* analyticSolution, double* coord, double* eta ) {
-	//*eta = 999.0 * ( 1.0 - Trubitsyn_G( coord[ J_AXIS ], 0.5, 50 ) ) + 1;
-	*eta = ( coord[ J_AXIS ] <= 0.5 ? 1000.0 : 1 );
-}
-void _Trubitsyn2006_ViscosityDerivativeFunc_Model3( void* analyticSolution, double* coord, double* viscDeriv ) {
-	viscDeriv[0] = 0.0;
-	viscDeriv[1] = 0.0;
-//	viscDeriv[1] = -999.0 * Trubitsyn_GDeriv( coord[ J_AXIS ], 0.5, 50 );
-}
-
-
-double Trubitsyn2006_V0( void* analyticSolution ) {
-	Trubitsyn2006*         self               = (Trubitsyn2006*)analyticSolution;
-	double                 T0                 = self->T0;
-	double                 Ra                 = self->Ra;
-
-	/* NB - Paper Trubitsyn [2006] is in error for this substitution - they leave out the square on pi */
-	return 0.25 * Ra * T0 * M_1_PI * M_1_PI;
-}
-
-
-void _Trubitsyn2006_VelocityFunction( void* analyticSolution, double* coord, double* velocity ) {
-	Trubitsyn2006*         self               = (Trubitsyn2006*)analyticSolution;
-	double                 v0                 = Trubitsyn2006_V0( self );
-	double                 x; 
-	double                 y;
-	XYZ                    min, max;
-
-	Mesh_GetGlobalCoordRange( self->velocityField->feMesh, min, max );
-	x = coord[ I_AXIS ] - min[ I_AXIS ];
-	y = coord[ J_AXIS ] - min[ J_AXIS ];
-
-	velocity[ J_AXIS ] =   v0 * sin( M_PI * y ) * cos( M_PI * x );         /* Equation 31 */
-	velocity[ I_AXIS ] = - v0 * cos( M_PI * y ) * sin( M_PI * x );         /* Equation 32 */
-}
-
-void _Trubitsyn2006_ViscosityFunction( void* analyticSolution, double* coord, double* viscosity ) {
-	Trubitsyn2006*         self               = (Trubitsyn2006*)analyticSolution;
-
-	self->viscosityFunc( self, coord, viscosity );
-}
-
-void _Trubitsyn2006_PressureFunction( void* analyticSolution, double* coord, double* pressure ) {
-	Trubitsyn2006*         self               = (Trubitsyn2006*)analyticSolution;
-	double                 T0                 = self->T0;
-	double                 Ra                 = self->Ra;
-	double                 x; 
-	double                 y;
-	XYZ                    min, max;
-	double                 eta;
-	double                 eta01;
-	double                 upperLeftCorner[]  = { 0.0, 1.0, 0.0 };
-	
-	Mesh_GetGlobalCoordRange( self->velocityField->feMesh, min, max );
-	x = coord[ I_AXIS ] - min[ I_AXIS ];
-	y = coord[ J_AXIS ] - min[ J_AXIS ];
-
-	/* Get Viscosities */
-	self->viscosityFunc( self, coord, &eta );
-	self->viscosityFunc( self, upperLeftCorner, &eta01 );
-
-	*pressure = - Ra * ( ( y * y * 0.5 - y + 0.5 )
-			+ 0.5 * T0 / M_PI * ( eta * cos( M_PI * y ) * cos( M_PI * x ) + eta01 ) );        /* Equation 46 */
-	//printf("pressure from t0 = %g\n", *pressure );
-	//*pressure = - 2.0 * M_PI * v0 * ( eta * cos( M_PI * y ) * cos( M_PI * x ) + eta01 ) 
-	//		- Ra * ( y*y * 0.5 - y + 0.5 );
-	//printf("pressure from v0 = %g\n\n", *pressure );
-}
-
-void _Trubitsyn2006_StreamFunction( void* analyticSolution, double* coord, double* psi ) {
-	Trubitsyn2006*         self               = (Trubitsyn2006*)analyticSolution;
-	double                 v0                 = Trubitsyn2006_V0( self );
-	double                 x; 
-	double                 y;
-	XYZ                    min, max;
-
-	Mesh_GetGlobalCoordRange( self->velocityField->feMesh, min, max );
-	x = coord[ I_AXIS ] - min[ I_AXIS ];
-	y = coord[ J_AXIS ] - min[ J_AXIS ];
-
-	*psi = - v0 / M_PI * sin( M_PI * y ) * sin( M_PI * x ) ;                                          /* Equation 40 */
-}
-
-void Trubitsyn2006_TemperatureIC( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
-	DomainContext*         context            = (DomainContext*)_context;
-	FeVariable*            temperatureField   = (FeVariable*) FieldVariable_Register_GetByName( context->fieldVariable_Register, "TemperatureField" );
-	FeMesh*                mesh               = temperatureField->feMesh;
-	double*                temperature        = (double*) _result;
-	double*                coord;
-	double                 x; 
-	double                 y;
-	Trubitsyn2006*         self               = Stg_ComponentFactory_ConstructByName( context->CF, (Name)Trubitsyn2006_Type, Trubitsyn2006, True, context );
-	double                 T0                 = self->T0;
-	double                 Ra                 = self->Ra;
-	double                 v0                 = Trubitsyn2006_V0( self  );
-	XYZ                    min, max;
-	double                 eta;
-	double                 d_eta_dy;
-	XYZ                    viscDeriv;
-	
-	/* Find coordinate of node */
-	coord = Mesh_GetVertex( mesh, node_lI );
-	Mesh_GetGlobalCoordRange( mesh, min, max );
-	x = coord[ I_AXIS ] - min[ I_AXIS ];
-	y = coord[ J_AXIS ] - min[ J_AXIS ];
-
-	self->viscosityFunc( self, coord, &eta );
-	self->viscosityDerivativeFunc( self, coord, viscDeriv );
-	d_eta_dy = viscDeriv[ J_AXIS ];
-
-	*temperature = 1 - y + T0 * cos( M_PI * x ) * ( eta * sin( M_PI * y ) - d_eta_dy / M_PI * cos( M_PI * y ) ) ;    /* Equation 47 */ 
-	
-	*temperature = 1 - y + 4.0 * M_PI * v0 / Ra * cos( M_PI * x ) * 
-		( M_PI * eta * sin( M_PI * y ) - d_eta_dy * cos( M_PI * y ) ) ;    /* Equation 47 */ 
-
-}
-
-void Trubitsyn2006_PressureIC( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
-	DomainContext*         context            = (DomainContext*)_context;
-	FeVariable*            PressureField      = (FeVariable*) FieldVariable_Register_GetByName( context->fieldVariable_Register, "PressureField" );
-	FeMesh*                mesh               = PressureField->feMesh;
-	double*                pressure           = (double*) _result;
-	double*                coord;
-	Trubitsyn2006* self = Stg_ComponentFactory_ConstructByName( context->CF, (Name)Trubitsyn2006_Type, Trubitsyn2006, True, context  );
-	
-	/* Find coordinate of node */
-	coord = Mesh_GetVertex( mesh, node_lI );
-	
-	_Trubitsyn2006_PressureFunction( self,  coord,  pressure );
-}
-
-void _Trubitsyn2006_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
-	Trubitsyn2006*			self = (Trubitsyn2006*)analyticSolution;
-	ConditionFunction*	condFunc;
-	char*						viscosityType;
-	Dictionary*				pluginDict = Codelet_GetPluginDictionary(self, cf->rootDict);
-	
-	/* Construct Parent */
-	_FieldTest_AssignFromXML( self, cf, data );
-
-	self->velocityField = Stg_ComponentFactory_ConstructByName( cf, Dictionary_GetString( pluginDict, (Dictionary_Entry_Key)"VelocityField" ), FeVariable, True, data);
-	self->pressureField = Stg_ComponentFactory_ConstructByName( cf, Dictionary_GetString( pluginDict, (Dictionary_Entry_Key)"PressureField" ), FeVariable, True, data);
-
-	/* Add temperature initial condition */
-	condFunc = ConditionFunction_New( Trubitsyn2006_TemperatureIC, (Name)"Trubitsyn2006_TemperatureIC"  );
-	ConditionFunction_Register_Add( condFunc_Register, condFunc );
-
-  /* Add pressure initial condition */
-	condFunc = ConditionFunction_New( Trubitsyn2006_PressureIC, (Name)"Trubitsyn2006_PressureIC"  );
-	ConditionFunction_Register_Add( condFunc_Register, condFunc );
-	
-	/* Create Analytic Fields */
-/*
-	self->velocityField = FieldTest_RegisterFeVariableFromCF( self, "VelocityField",  _Trubitsyn2006_VelocityFunction, cf, True, data );
-	self->pressureField = FieldTest_RegisterFeVariableFromCF( self, "PressureField",  _Trubitsyn2006_PressureFunction, cf, True, data );
-	FieldTest_RegisterFeVariableFromCF( self, "ViscosityField", _Trubitsyn2006_ViscosityFunction, cf, False, data );
-*/
-
-	/* Setup Viscosity Functions */
-	viscosityType = Stg_ComponentFactory_GetRootDictString( cf, (Dictionary_Entry_Key)"ViscosityType", "Isoviscous"  );
-	if ( strcasecmp( viscosityType, "Isoviscous" ) == 0 ) {
-		self->viscosityFunc           = _Trubitsyn2006_ViscosityFunc_Isoviscous;
-		self->viscosityDerivativeFunc = _Trubitsyn2006_ViscosityDerivativeFunc_Isoviscous;
-	}
-	else if ( strcasecmp( viscosityType, "Model1" ) == 0 ) {
-		self->viscosityFunc           = _Trubitsyn2006_ViscosityFunc_Model1;
-		self->viscosityDerivativeFunc = _Trubitsyn2006_ViscosityDerivativeFunc_Model1;
-	}
-	else if ( strcasecmp( viscosityType, "Model2" ) == 0 ) {
-		self->viscosityFunc           = _Trubitsyn2006_ViscosityFunc_Model2;
-		self->viscosityDerivativeFunc = _Trubitsyn2006_ViscosityDerivativeFunc_Model2;
-	}
-	else if ( strcasecmp( viscosityType, "Model3" ) == 0 ) {
-		self->viscosityFunc           = _Trubitsyn2006_ViscosityFunc_Model3;
-		self->viscosityDerivativeFunc = _Trubitsyn2006_ViscosityDerivativeFunc_Model3;
-	}
-	else {
-		Journal_Printf( Journal_Register( Error_Type, (Name)self->type  ), "Cannot understand viscosity type = '%s'\n", viscosityType );
-		abort();
-	}
-
-	self->Ra = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"Ra", 0.0  );
-	self->T0 = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"T0", 0.0  );
-	self->wavenumberX = Stg_ComponentFactory_GetRootDictInt( cf, "wavenumberX", 1 );
-	self->wavenumberY = Stg_ComponentFactory_GetRootDictInt( cf, "wavenumberY", 1 );
-}
-
-void _Trubitsyn2006_Build( void* analyticSolution, void* data ) {
-	Trubitsyn2006*         self = (Trubitsyn2006*)analyticSolution;
-
-	Stg_Component_Build(self->velocityField, data, False);
-   Stg_Component_Build(self->pressureField, data, False);
-
-	_FieldTest_Build( self, data );
-
-	self->_analyticSolutionList = Memory_Alloc_Array_Unnamed( FieldTest_AnalyticSolutionFunc*, 3 );
-	self->_analyticSolutionList[0] = _Trubitsyn2006_VelocityFunction;
-	self->_analyticSolutionList[1] = _Trubitsyn2006_PressureFunction;
-	self->_analyticSolutionList[2] = _Trubitsyn2006_ViscosityFunction;
-}
-
-void _Trubitsyn2006_Initialise( void* analyticSolution, void* data ) {
-	Trubitsyn2006*         self = (Trubitsyn2006*)analyticSolution;
-
-	Stg_Component_Initialise(self->velocityField, data, False);
-	Stg_Component_Initialise(self->pressureField, data, False);
-
-	_FieldTest_Initialise( self, data );
-}
-
-void _Trubitsyn2006_Destroy( void* analyticSolution, void* data ) {
-	Trubitsyn2006*         self = (Trubitsyn2006*)analyticSolution;
-
-   _FieldTest_Destroy( self, data );
-   
-	Stg_Component_Destroy(self->velocityField, data, False);
-	Stg_Component_Destroy(self->pressureField, data, False);
-}
-
-
-void* _Trubitsyn2006_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Trubitsyn2006);
-	Type                                                      type = Trubitsyn2006_Type;
-	Stg_Class_DeleteFunction*                              _delete = _FieldTest_Delete;
-	Stg_Class_PrintFunction*                                _print = _FieldTest_Print;
-	Stg_Class_CopyFunction*                                  _copy = _FieldTest_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Trubitsyn2006_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Trubitsyn2006_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _Trubitsyn2006_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _Trubitsyn2006_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _FieldTest_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _Trubitsyn2006_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 Underworld_Trubitsyn2006_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Trubitsyn2006_Type, (Name)"0", _Trubitsyn2006_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Trubitsyn2006/Trubitsyn2006.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Trubitsyn2006/Trubitsyn2006.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,354 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: Trubitsyn2006.c 737 2008-05-23 06:08:42Z RobertTurnbull $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Rheology/Rheology.h>
+
+#include <assert.h>
+#include <string.h>
+
+#define SMALL 1.0e-5
+#define IS_ODD(A)   ( (A) % 2 == 1 )
+
+const Type Trubitsyn2006_Type = "Underworld_Trubitsyn2006";
+
+typedef struct {
+	__FieldTest
+	FieldTest_AnalyticSolutionFunc* viscosityFunc;
+	FieldTest_AnalyticSolutionFunc* viscosityDerivativeFunc;
+	FeVariable*                        velocityField;
+	FeVariable*                        pressureField;
+	double                             Ra;
+	double                             T0;
+	int                                wavenumberX;
+	int                                wavenumberY;
+} Trubitsyn2006;
+
+/** Analytic Solution taken from 
+ * V. P. Trubitsyn, A. A. Baranov, A. N. Eyseev, and A. P. Trubitsyn. 
+ * 	Exact analytical solutions of the stokes equation for testing the equations of mantle convection with a variable viscosity. 
+ *	Izvestiya Physics of the Solid Earth, 42(7):537–545, 2006. 
+ *  
+ *  All equations refer to this paper */
+
+double Trubitsyn_G( double x, double x0, double a ) {
+	return 1/(1 + exp( -2.0 * a * ( x - x0 ) ) );
+}
+double Trubitsyn_GDeriv( double x, double x0, double a ) {
+	return 2.0 * a * pow( exp( a * ( x - x0 ) ) + exp( -a * ( x - x0 ) ), -2.0 );
+}
+
+void _Trubitsyn2006_ViscosityFunc_Isoviscous( void* analyticSolution, double* coord, double* eta ) {
+	*eta = 1.0;
+}
+void _Trubitsyn2006_ViscosityDerivativeFunc_Isoviscous( void* analyticSolution, double* coord, double* viscDeriv ) {
+	viscDeriv[0] = 0.0;
+	viscDeriv[1] = 0.0;
+}
+void _Trubitsyn2006_ViscosityFunc_Model1( void* analyticSolution, double* coord, double* eta ) {
+	*eta = 1.0 + 100.0 * coord[ I_AXIS ] * coord[ J_AXIS ];
+}
+void _Trubitsyn2006_ViscosityDerivativeFunc_Model1( void* analyticSolution, double* coord, double* viscDeriv ) {
+	viscDeriv[0] = 100.0 * coord[ J_AXIS ];
+	viscDeriv[1] = 100.0 * coord[ I_AXIS ];
+}
+void _Trubitsyn2006_ViscosityFunc_Model2( void* analyticSolution, double* coord, double* eta ) {
+//	*eta = 999.0 * ( 1.0 - Trubitsyn_G( coord[ I_AXIS ], 0.5, 50 ) ) + 1;
+	*eta = ( coord[ I_AXIS ] <= 0.5 ? 1000.0 : 1 );
+}
+void _Trubitsyn2006_ViscosityDerivativeFunc_Model2( void* analyticSolution, double* coord, double* viscDeriv ) {
+//	viscDeriv[0] = -999.0 * Trubitsyn_GDeriv( coord[ I_AXIS ], 0.5, 50 );
+	viscDeriv[0] = 0.0;
+	viscDeriv[1] = 0.0;
+}
+void _Trubitsyn2006_ViscosityFunc_Model3( void* analyticSolution, double* coord, double* eta ) {
+	//*eta = 999.0 * ( 1.0 - Trubitsyn_G( coord[ J_AXIS ], 0.5, 50 ) ) + 1;
+	*eta = ( coord[ J_AXIS ] <= 0.5 ? 1000.0 : 1 );
+}
+void _Trubitsyn2006_ViscosityDerivativeFunc_Model3( void* analyticSolution, double* coord, double* viscDeriv ) {
+	viscDeriv[0] = 0.0;
+	viscDeriv[1] = 0.0;
+//	viscDeriv[1] = -999.0 * Trubitsyn_GDeriv( coord[ J_AXIS ], 0.5, 50 );
+}
+
+
+double Trubitsyn2006_V0( void* analyticSolution ) {
+	Trubitsyn2006*         self               = (Trubitsyn2006*)analyticSolution;
+	double                 T0                 = self->T0;
+	double                 Ra                 = self->Ra;
+
+	/* NB - Paper Trubitsyn [2006] is in error for this substitution - they leave out the square on pi */
+	return 0.25 * Ra * T0 * M_1_PI * M_1_PI;
+}
+
+
+void _Trubitsyn2006_VelocityFunction( void* analyticSolution, double* coord, double* velocity ) {
+	Trubitsyn2006*         self               = (Trubitsyn2006*)analyticSolution;
+	double                 v0                 = Trubitsyn2006_V0( self );
+	double                 x; 
+	double                 y;
+	XYZ                    min, max;
+
+	Mesh_GetGlobalCoordRange( self->velocityField->feMesh, min, max );
+	x = coord[ I_AXIS ] - min[ I_AXIS ];
+	y = coord[ J_AXIS ] - min[ J_AXIS ];
+
+	velocity[ J_AXIS ] =   v0 * sin( M_PI * y ) * cos( M_PI * x );         /* Equation 31 */
+	velocity[ I_AXIS ] = - v0 * cos( M_PI * y ) * sin( M_PI * x );         /* Equation 32 */
+}
+
+void _Trubitsyn2006_ViscosityFunction( void* analyticSolution, double* coord, double* viscosity ) {
+	Trubitsyn2006*         self               = (Trubitsyn2006*)analyticSolution;
+
+	self->viscosityFunc( self, coord, viscosity );
+}
+
+void _Trubitsyn2006_PressureFunction( void* analyticSolution, double* coord, double* pressure ) {
+	Trubitsyn2006*         self               = (Trubitsyn2006*)analyticSolution;
+	double                 T0                 = self->T0;
+	double                 Ra                 = self->Ra;
+	double                 x; 
+	double                 y;
+	XYZ                    min, max;
+	double                 eta;
+	double                 eta01;
+	double                 upperLeftCorner[]  = { 0.0, 1.0, 0.0 };
+	
+	Mesh_GetGlobalCoordRange( self->velocityField->feMesh, min, max );
+	x = coord[ I_AXIS ] - min[ I_AXIS ];
+	y = coord[ J_AXIS ] - min[ J_AXIS ];
+
+	/* Get Viscosities */
+	self->viscosityFunc( self, coord, &eta );
+	self->viscosityFunc( self, upperLeftCorner, &eta01 );
+
+	*pressure = - Ra * ( ( y * y * 0.5 - y + 0.5 )
+			+ 0.5 * T0 / M_PI * ( eta * cos( M_PI * y ) * cos( M_PI * x ) + eta01 ) );        /* Equation 46 */
+	//printf("pressure from t0 = %g\n", *pressure );
+	//*pressure = - 2.0 * M_PI * v0 * ( eta * cos( M_PI * y ) * cos( M_PI * x ) + eta01 ) 
+	//		- Ra * ( y*y * 0.5 - y + 0.5 );
+	//printf("pressure from v0 = %g\n\n", *pressure );
+}
+
+void _Trubitsyn2006_StreamFunction( void* analyticSolution, double* coord, double* psi ) {
+	Trubitsyn2006*         self               = (Trubitsyn2006*)analyticSolution;
+	double                 v0                 = Trubitsyn2006_V0( self );
+	double                 x; 
+	double                 y;
+	XYZ                    min, max;
+
+	Mesh_GetGlobalCoordRange( self->velocityField->feMesh, min, max );
+	x = coord[ I_AXIS ] - min[ I_AXIS ];
+	y = coord[ J_AXIS ] - min[ J_AXIS ];
+
+	*psi = - v0 / M_PI * sin( M_PI * y ) * sin( M_PI * x ) ;                                          /* Equation 40 */
+}
+
+void Trubitsyn2006_TemperatureIC( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
+	DomainContext*         context            = (DomainContext*)_context;
+	FeVariable*            temperatureField   = (FeVariable*) FieldVariable_Register_GetByName( context->fieldVariable_Register, "TemperatureField" );
+	FeMesh*                mesh               = temperatureField->feMesh;
+	double*                temperature        = (double*) _result;
+	double*                coord;
+	double                 x; 
+	double                 y;
+	Trubitsyn2006*         self               = Stg_ComponentFactory_ConstructByName( context->CF, (Name)Trubitsyn2006_Type, Trubitsyn2006, True, context );
+	double                 T0                 = self->T0;
+	double                 Ra                 = self->Ra;
+	double                 v0                 = Trubitsyn2006_V0( self  );
+	XYZ                    min, max;
+	double                 eta;
+	double                 d_eta_dy;
+	XYZ                    viscDeriv;
+	
+	/* Find coordinate of node */
+	coord = Mesh_GetVertex( mesh, node_lI );
+	Mesh_GetGlobalCoordRange( mesh, min, max );
+	x = coord[ I_AXIS ] - min[ I_AXIS ];
+	y = coord[ J_AXIS ] - min[ J_AXIS ];
+
+	self->viscosityFunc( self, coord, &eta );
+	self->viscosityDerivativeFunc( self, coord, viscDeriv );
+	d_eta_dy = viscDeriv[ J_AXIS ];
+
+	*temperature = 1 - y + T0 * cos( M_PI * x ) * ( eta * sin( M_PI * y ) - d_eta_dy / M_PI * cos( M_PI * y ) ) ;    /* Equation 47 */ 
+	
+	*temperature = 1 - y + 4.0 * M_PI * v0 / Ra * cos( M_PI * x ) * 
+		( M_PI * eta * sin( M_PI * y ) - d_eta_dy * cos( M_PI * y ) ) ;    /* Equation 47 */ 
+
+}
+
+void Trubitsyn2006_PressureIC( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
+	DomainContext*         context            = (DomainContext*)_context;
+	FeVariable*            PressureField      = (FeVariable*) FieldVariable_Register_GetByName( context->fieldVariable_Register, "PressureField" );
+	FeMesh*                mesh               = PressureField->feMesh;
+	double*                pressure           = (double*) _result;
+	double*                coord;
+	Trubitsyn2006* self = Stg_ComponentFactory_ConstructByName( context->CF, (Name)Trubitsyn2006_Type, Trubitsyn2006, True, context  );
+	
+	/* Find coordinate of node */
+	coord = Mesh_GetVertex( mesh, node_lI );
+	
+	_Trubitsyn2006_PressureFunction( self,  coord,  pressure );
+}
+
+void _Trubitsyn2006_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
+	Trubitsyn2006*			self = (Trubitsyn2006*)analyticSolution;
+	ConditionFunction*	condFunc;
+	char*						viscosityType;
+	Dictionary*				pluginDict = Codelet_GetPluginDictionary(self, cf->rootDict);
+	
+	/* Construct Parent */
+	_FieldTest_AssignFromXML( self, cf, data );
+
+	self->velocityField = Stg_ComponentFactory_ConstructByName( cf, Dictionary_GetString( pluginDict, (Dictionary_Entry_Key)"VelocityField" ), FeVariable, True, data);
+	self->pressureField = Stg_ComponentFactory_ConstructByName( cf, Dictionary_GetString( pluginDict, (Dictionary_Entry_Key)"PressureField" ), FeVariable, True, data);
+
+	/* Add temperature initial condition */
+	condFunc = ConditionFunction_New( Trubitsyn2006_TemperatureIC, (Name)"Trubitsyn2006_TemperatureIC"  );
+	ConditionFunction_Register_Add( condFunc_Register, condFunc );
+
+  /* Add pressure initial condition */
+	condFunc = ConditionFunction_New( Trubitsyn2006_PressureIC, (Name)"Trubitsyn2006_PressureIC"  );
+	ConditionFunction_Register_Add( condFunc_Register, condFunc );
+	
+	/* Create Analytic Fields */
+/*
+	self->velocityField = FieldTest_RegisterFeVariableFromCF( self, "VelocityField",  _Trubitsyn2006_VelocityFunction, cf, True, data );
+	self->pressureField = FieldTest_RegisterFeVariableFromCF( self, "PressureField",  _Trubitsyn2006_PressureFunction, cf, True, data );
+	FieldTest_RegisterFeVariableFromCF( self, "ViscosityField", _Trubitsyn2006_ViscosityFunction, cf, False, data );
+*/
+
+	/* Setup Viscosity Functions */
+	viscosityType = Stg_ComponentFactory_GetRootDictString( cf, (Dictionary_Entry_Key)"ViscosityType", "Isoviscous"  );
+	if ( strcasecmp( viscosityType, "Isoviscous" ) == 0 ) {
+		self->viscosityFunc           = _Trubitsyn2006_ViscosityFunc_Isoviscous;
+		self->viscosityDerivativeFunc = _Trubitsyn2006_ViscosityDerivativeFunc_Isoviscous;
+	}
+	else if ( strcasecmp( viscosityType, "Model1" ) == 0 ) {
+		self->viscosityFunc           = _Trubitsyn2006_ViscosityFunc_Model1;
+		self->viscosityDerivativeFunc = _Trubitsyn2006_ViscosityDerivativeFunc_Model1;
+	}
+	else if ( strcasecmp( viscosityType, "Model2" ) == 0 ) {
+		self->viscosityFunc           = _Trubitsyn2006_ViscosityFunc_Model2;
+		self->viscosityDerivativeFunc = _Trubitsyn2006_ViscosityDerivativeFunc_Model2;
+	}
+	else if ( strcasecmp( viscosityType, "Model3" ) == 0 ) {
+		self->viscosityFunc           = _Trubitsyn2006_ViscosityFunc_Model3;
+		self->viscosityDerivativeFunc = _Trubitsyn2006_ViscosityDerivativeFunc_Model3;
+	}
+	else {
+		Journal_Printf( Journal_Register( Error_Type, (Name)self->type  ), "Cannot understand viscosity type = '%s'\n", viscosityType );
+		abort();
+	}
+
+	self->Ra = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"Ra", 0.0  );
+	self->T0 = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"T0", 0.0  );
+	self->wavenumberX = Stg_ComponentFactory_GetRootDictInt( cf, "wavenumberX", 1 );
+	self->wavenumberY = Stg_ComponentFactory_GetRootDictInt( cf, "wavenumberY", 1 );
+}
+
+void _Trubitsyn2006_Build( void* analyticSolution, void* data ) {
+	Trubitsyn2006*         self = (Trubitsyn2006*)analyticSolution;
+
+	Stg_Component_Build(self->velocityField, data, False);
+   Stg_Component_Build(self->pressureField, data, False);
+
+	_FieldTest_Build( self, data );
+
+	self->_analyticSolutionList = Memory_Alloc_Array_Unnamed( FieldTest_AnalyticSolutionFunc*, 3 );
+	self->_analyticSolutionList[0] = _Trubitsyn2006_VelocityFunction;
+	self->_analyticSolutionList[1] = _Trubitsyn2006_PressureFunction;
+	self->_analyticSolutionList[2] = _Trubitsyn2006_ViscosityFunction;
+}
+
+void _Trubitsyn2006_Initialise( void* analyticSolution, void* data ) {
+	Trubitsyn2006*         self = (Trubitsyn2006*)analyticSolution;
+
+	Stg_Component_Initialise(self->velocityField, data, False);
+	Stg_Component_Initialise(self->pressureField, data, False);
+
+	_FieldTest_Initialise( self, data );
+}
+
+void _Trubitsyn2006_Destroy( void* analyticSolution, void* data ) {
+	Trubitsyn2006*         self = (Trubitsyn2006*)analyticSolution;
+
+   _FieldTest_Destroy( self, data );
+   
+	Stg_Component_Destroy(self->velocityField, data, False);
+	Stg_Component_Destroy(self->pressureField, data, False);
+}
+
+
+void* _Trubitsyn2006_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Trubitsyn2006);
+	Type                                                      type = Trubitsyn2006_Type;
+	Stg_Class_DeleteFunction*                              _delete = _FieldTest_Delete;
+	Stg_Class_PrintFunction*                                _print = _FieldTest_Print;
+	Stg_Class_CopyFunction*                                  _copy = _FieldTest_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Trubitsyn2006_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Trubitsyn2006_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _Trubitsyn2006_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _Trubitsyn2006_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _FieldTest_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _Trubitsyn2006_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 Underworld_Trubitsyn2006_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Trubitsyn2006_Type, (Name)"0", _Trubitsyn2006_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/VelicIC/VelicIC.c
--- a/SysTest/AnalyticPlugins/VelicIC/VelicIC.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,169 +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: VelicIC.c 610 2007-10-11 08:09:29Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <assert.h>
-#include "VelicIC.h"
-
-const Type Underworld_VelicIC_Type = "Underworld_VelicIC";
-
-#define SMALL 1.0e-5
-
-/* Works with SolA */
-void Underworld_VelicIC_Sinusoidal( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
-	DomainContext*  context            = (DomainContext*)_context;
-	FeVariable*             temperatureField   = (FeVariable*) FieldVariable_Register_GetByName( context->fieldVariable_Register, "TemperatureField" );
-	FeMesh*			feMesh             = temperatureField->feMesh;
-	Dictionary*             dictionary         = context->dictionary;
-	double*                 result             = (double*) _result;
-	double*                 coord;
-	double                  x; 
-	double                  y;
-	double                  kx;
-	double                  ky;
-	int                     wavenumberX;
-	double                  wavenumberY;
-	double                  sigma;
-	double                  Lx;
-	double			min[3], max[3];
-	
-	/* Find coordinate of node */
-	coord = Mesh_GetVertex( feMesh, node_lI );
-	Mesh_GetGlobalCoordRange( feMesh, min, max );
-
-	/* Make sure that the box has right dimensions */
-	assert( ( max[ J_AXIS ] - min[ J_AXIS ] - 1.0 ) < SMALL );
-	Lx = max[ I_AXIS ] - min[ I_AXIS ];
-
-	x = coord[ I_AXIS ] - min[ I_AXIS ];
-	y = coord[ J_AXIS ] - min[ J_AXIS ];
-
-	wavenumberX = Dictionary_GetInt_WithDefault( dictionary, (Dictionary_Entry_Key)"wavenumberX", 1  );
-	wavenumberY = Dictionary_GetDouble_WithDefault( dictionary, (Dictionary_Entry_Key)"wavenumberY", 1.0  );
-	sigma = Dictionary_GetDouble_WithDefault( dictionary, (Dictionary_Entry_Key)"sigma", 1.0 );
-	
-	assert( sigma > 0.0 );
-	assert( wavenumberY > 0.0 );
-	assert( wavenumberX > 0.0 );
-	
-	kx = (double)wavenumberX * M_PI / Lx;
-	ky = (double)wavenumberY * M_PI;
-
-	*result = sigma * sin( ky * y ) * cos( kx * x  );
-}
-
-/* Works with SolB */
-void Underworld_VelicIC_Hyperbolic( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
-	DomainContext*  context            = (DomainContext*)_context;
-	FeVariable*             temperatureField   = (FeVariable*) FieldVariable_Register_GetByName( context->fieldVariable_Register, "TemperatureField" );
-	FeMesh*			feMesh             = temperatureField->feMesh;
-	Dictionary*             dictionary         = context->dictionary;
-	double*                 result             = (double*) _result;
-	double*                 coord;
-	double                  x; 
-	double                  y;
-	double                  km; /*  for y-direction */
-	double                  kn; /*  for x-direction */
-	double                  wavenumberX;
-	double                  wavenumberY;
-	double                  L;
-	double                  sigma;
-	double			min[3], max[3];
-	
-	/* Find coordinate of node */
-	coord = Mesh_GetVertex( feMesh, node_lI );
-	Mesh_GetGlobalCoordRange( feMesh, min, max );
-
-	/* Make sure that the box has right dimensions */
-	assert( (max[ J_AXIS ] - min[ J_AXIS ] - 1.0 ) < SMALL );
-	L = max[ I_AXIS ] - min[ I_AXIS ];
-
-	x = coord[ I_AXIS ] - min[ I_AXIS ];
-	y = coord[ J_AXIS ] - min[ J_AXIS ];
-
-	wavenumberX = Dictionary_GetInt_WithDefault( dictionary, (Dictionary_Entry_Key)"wavenumberX", 1  );
-	wavenumberY = Dictionary_GetDouble_WithDefault( dictionary, (Dictionary_Entry_Key)"wavenumberY", 2.0 );
-	assert( wavenumberX != wavenumberY  );
-	sigma = Dictionary_GetDouble_WithDefault( dictionary, (Dictionary_Entry_Key)"sigma", 1.0 );
-
-	kn = wavenumberX * M_PI / L;
-/* 	 TODO: Re-write Mirko's code and/or Documentation so the input parameters for these ICs are less confusing */
-	km = wavenumberY / L;
-
-	*result = sigma * sinh( km * y ) * cos( kn * x  );
-}
-
-
-
-void _Underworld_VelicIC_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
-	AbstractContext*        context;
-	ConditionFunction*      condFunc;
-
-	context = (AbstractContext*)Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  ); 
-	
-	condFunc = ConditionFunction_New( Underworld_VelicIC_Sinusoidal, (Name)"VelicIC_Sinusoidal" );
-	ConditionFunction_Register_Add( condFunc_Register, condFunc );
-	condFunc = ConditionFunction_New( Underworld_VelicIC_Hyperbolic, (Name)"VelicIC_Hyperbolic" );
-	ConditionFunction_Register_Add( condFunc_Register, condFunc );
-}	
-
-void* _Underworld_VelicIC_DefaultNew( Name name ) {
-	return Codelet_New(
-		Underworld_VelicIC_Type,
-		_Underworld_VelicIC_DefaultNew,
-		_Underworld_VelicIC_AssignFromXML,
-		_Codelet_Build,
-		_Codelet_Initialise,
-		_Codelet_Execute,
-		_Codelet_Destroy,
-		name );
-}
-
-Index Underworld_VelicIC_Register( PluginsManager* pluginsManager ) {
-	Journal_DPrintf( StgFEM_Debug, "In: %s( void* )\n", __func__ );
-
-	return PluginsManager_Submit( pluginsManager, Underworld_VelicIC_Type, (Name)"0", _Underworld_VelicIC_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/VelicIC/VelicIC.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/VelicIC/VelicIC.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,169 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** 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: VelicIC.c 610 2007-10-11 08:09:29Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <assert.h>
+#include "VelicIC.h"
+
+const Type Underworld_VelicIC_Type = "Underworld_VelicIC";
+
+#define SMALL 1.0e-5
+
+/* Works with SolA */
+void Underworld_VelicIC_Sinusoidal( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
+	DomainContext*  context            = (DomainContext*)_context;
+	FeVariable*             temperatureField   = (FeVariable*) FieldVariable_Register_GetByName( context->fieldVariable_Register, "TemperatureField" );
+	FeMesh*			feMesh             = temperatureField->feMesh;
+	Dictionary*             dictionary         = context->dictionary;
+	double*                 result             = (double*) _result;
+	double*                 coord;
+	double                  x; 
+	double                  y;
+	double                  kx;
+	double                  ky;
+	int                     wavenumberX;
+	double                  wavenumberY;
+	double                  sigma;
+	double                  Lx;
+	double			min[3], max[3];
+	
+	/* Find coordinate of node */
+	coord = Mesh_GetVertex( feMesh, node_lI );
+	Mesh_GetGlobalCoordRange( feMesh, min, max );
+
+	/* Make sure that the box has right dimensions */
+	assert( ( max[ J_AXIS ] - min[ J_AXIS ] - 1.0 ) < SMALL );
+	Lx = max[ I_AXIS ] - min[ I_AXIS ];
+
+	x = coord[ I_AXIS ] - min[ I_AXIS ];
+	y = coord[ J_AXIS ] - min[ J_AXIS ];
+
+	wavenumberX = Dictionary_GetInt_WithDefault( dictionary, (Dictionary_Entry_Key)"wavenumberX", 1  );
+	wavenumberY = Dictionary_GetDouble_WithDefault( dictionary, (Dictionary_Entry_Key)"wavenumberY", 1.0  );
+	sigma = Dictionary_GetDouble_WithDefault( dictionary, (Dictionary_Entry_Key)"sigma", 1.0 );
+	
+	assert( sigma > 0.0 );
+	assert( wavenumberY > 0.0 );
+	assert( wavenumberX > 0.0 );
+	
+	kx = (double)wavenumberX * M_PI / Lx;
+	ky = (double)wavenumberY * M_PI;
+
+	*result = sigma * sin( ky * y ) * cos( kx * x  );
+}
+
+/* Works with SolB */
+void Underworld_VelicIC_Hyperbolic( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
+	DomainContext*  context            = (DomainContext*)_context;
+	FeVariable*             temperatureField   = (FeVariable*) FieldVariable_Register_GetByName( context->fieldVariable_Register, "TemperatureField" );
+	FeMesh*			feMesh             = temperatureField->feMesh;
+	Dictionary*             dictionary         = context->dictionary;
+	double*                 result             = (double*) _result;
+	double*                 coord;
+	double                  x; 
+	double                  y;
+	double                  km; /*  for y-direction */
+	double                  kn; /*  for x-direction */
+	double                  wavenumberX;
+	double                  wavenumberY;
+	double                  L;
+	double                  sigma;
+	double			min[3], max[3];
+	
+	/* Find coordinate of node */
+	coord = Mesh_GetVertex( feMesh, node_lI );
+	Mesh_GetGlobalCoordRange( feMesh, min, max );
+
+	/* Make sure that the box has right dimensions */
+	assert( (max[ J_AXIS ] - min[ J_AXIS ] - 1.0 ) < SMALL );
+	L = max[ I_AXIS ] - min[ I_AXIS ];
+
+	x = coord[ I_AXIS ] - min[ I_AXIS ];
+	y = coord[ J_AXIS ] - min[ J_AXIS ];
+
+	wavenumberX = Dictionary_GetInt_WithDefault( dictionary, (Dictionary_Entry_Key)"wavenumberX", 1  );
+	wavenumberY = Dictionary_GetDouble_WithDefault( dictionary, (Dictionary_Entry_Key)"wavenumberY", 2.0 );
+	assert( wavenumberX != wavenumberY  );
+	sigma = Dictionary_GetDouble_WithDefault( dictionary, (Dictionary_Entry_Key)"sigma", 1.0 );
+
+	kn = wavenumberX * M_PI / L;
+/* 	 TODO: Re-write Mirko's code and/or Documentation so the input parameters for these ICs are less confusing */
+	km = wavenumberY / L;
+
+	*result = sigma * sinh( km * y ) * cos( kn * x  );
+}
+
+
+
+void _Underworld_VelicIC_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
+	AbstractContext*        context;
+	ConditionFunction*      condFunc;
+
+	context = (AbstractContext*)Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  ); 
+	
+	condFunc = ConditionFunction_New( Underworld_VelicIC_Sinusoidal, (Name)"VelicIC_Sinusoidal" );
+	ConditionFunction_Register_Add( condFunc_Register, condFunc );
+	condFunc = ConditionFunction_New( Underworld_VelicIC_Hyperbolic, (Name)"VelicIC_Hyperbolic" );
+	ConditionFunction_Register_Add( condFunc_Register, condFunc );
+}	
+
+void* _Underworld_VelicIC_DefaultNew( Name name ) {
+	return Codelet_New(
+		Underworld_VelicIC_Type,
+		_Underworld_VelicIC_DefaultNew,
+		_Underworld_VelicIC_AssignFromXML,
+		_Codelet_Build,
+		_Codelet_Initialise,
+		_Codelet_Execute,
+		_Codelet_Destroy,
+		name );
+}
+
+Index Underworld_VelicIC_Register( PluginsManager* pluginsManager ) {
+	Journal_DPrintf( StgFEM_Debug, "In: %s( void* )\n", __func__ );
+
+	return PluginsManager_Submit( pluginsManager, Underworld_VelicIC_Type, (Name)"0", _Underworld_VelicIC_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solA/Analytic_solA.c
--- a/SysTest/AnalyticPlugins/Velic_solA/Analytic_solA.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,151 +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:
-*+		Mirko Velic
-*+		Julian Giordani
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Patrick Sunter
-** $Id: solA.c 636 2006-09-08 03:07:06Z JulianGiordani $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include "Analytic_solA.h"
-
-const Type Underworld_solA_Type = "Underworld_Velic_solA";
-
-void _Velic_solutionA( double* pos, 
-		double sigma, double Z, int n, double km,
-                       double* velocity, double* pressure, double* Tstress, double* strainRate );
-
-void Underworld_solA_PressureFunction( void* analyticSolution, double* coord, double* pressure ) {
-	Underworld_solA* self = (Underworld_solA*) analyticSolution;
-	
-	_Velic_solutionA( coord, self->sigma, self->Z, self->n, self->km, NULL, pressure, NULL, NULL );
-}
-
-void Underworld_solA_VelocityFunction( void* analyticSolution, double* coord, double* velocity ) {
-	Underworld_solA* self = (Underworld_solA*) analyticSolution;
-	
-	_Velic_solutionA( coord, self->sigma, self->Z, self->n, self->km, velocity, NULL, NULL, NULL );
-}
-
-void Underworld_solA_StressFunction( void* analyticSolution, double* coord, double* stress ) {
-	Underworld_solA* self = (Underworld_solA*) analyticSolution;
-	
-	_Velic_solutionA( coord, self->sigma, self->Z, self->n, self->km, NULL, NULL, stress, NULL );
-}
-
-
-void Underworld_solA_StrainRateFunction( void* analyticSolution, double* coord, double* strainRate ) {
-	Underworld_solA* self = (Underworld_solA*) analyticSolution;
-	
-	_Velic_solutionA( coord, self->sigma, self->Z, self->n, self->km, NULL, NULL, NULL, strainRate );
-}
-
-void _Underworld_solA_Init( Underworld_solA* self, double sigma, double Z, double wavenumberY, int n ) {
-	self->sigma = sigma;
-	self->Z     = Z;
-	self-> km   = M_PI * wavenumberY;
-	self->n     = n;	
-}
-
-void _Underworld_solA_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
-	Underworld_solA*	self = (Underworld_solA*) analyticSolution;
-	Bool					isCorrectInput = True;
-	double				sigma, Z, wavenumberY, n;
-	
-	/* Construct Parent */
-	_FieldTest_AssignFromXML( self, cf, data );
-
-	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solA_sigma", 1.0  );
-	Z = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solA_Z", 1.0  );
-	wavenumberY = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"wavenumberY", 1.5  );
-	n = Stg_ComponentFactory_GetRootDictInt( cf, "wavenumberX", 1 );
-	
-	_Underworld_solA_Init( self, sigma, Z, wavenumberY, n );
-
-	isCorrectInput = solA_checkInputParams( self );
-	Journal_Firewall( isCorrectInput , Journal_Register( Error_Type, (Name)"solA"  ),
-			"Error in function %s: Bad Input parameters, solution check valid values in .tex documentation\n",
-			__func__ );
-}
-
-void _Underworld_solA_Build( void* analyticSolution, void* data ) {
-	Underworld_solA* 		self = (Underworld_solA*) analyticSolution;
-
-	_FieldTest_Build( self, data );
-
-	/* here we assign the memory and the func ptr for analytic sols */
-	self->_analyticSolutionList = Memory_Alloc_Array_Unnamed( FieldTest_AnalyticSolutionFunc*, 4 );
-	/* this order MUST be consistent with the xml file definition */
-	self->_analyticSolutionList[0] = Underworld_solA_VelocityFunction;
-	self->_analyticSolutionList[1] = Underworld_solA_PressureFunction;
-	self->_analyticSolutionList[2] = Underworld_solA_StrainRateFunction;
-	self->_analyticSolutionList[3] = Underworld_solA_StressFunction;
-
-}
-
-Bool solA_checkInputParams( Underworld_solA* self ) {
-	return ( 
-		( self->sigma > 0.0 ) && ( self->Z > 0.0 ) &&
-		( self->km > 0.0 )    && ( self->n > 0 )  
-                 ) ? True : False;
-}
-
-void* _Underworld_solA_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Underworld_solA);
-	Type                                                      type = Underworld_solA_Type;
-	Stg_Class_DeleteFunction*                              _delete = _FieldTest_Delete;
-	Stg_Class_PrintFunction*                                _print = _FieldTest_Print;
-	Stg_Class_CopyFunction*                                  _copy = _FieldTest_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_solA_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Underworld_solA_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _Underworld_solA_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 Underworld_Velic_solA_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Underworld_solA_Type, (Name)"0", _Underworld_solA_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solA/Analytic_solA.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solA/Analytic_solA.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,151 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Mirko Velic
+*+		Julian Giordani
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Patrick Sunter
+** $Id: solA.c 636 2006-09-08 03:07:06Z JulianGiordani $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include "Analytic_solA.h"
+
+const Type Underworld_solA_Type = "Underworld_Velic_solA";
+
+void _Velic_solutionA( double* pos, 
+		double sigma, double Z, int n, double km,
+                       double* velocity, double* pressure, double* Tstress, double* strainRate );
+
+void Underworld_solA_PressureFunction( void* analyticSolution, double* coord, double* pressure ) {
+	Underworld_solA* self = (Underworld_solA*) analyticSolution;
+	
+	_Velic_solutionA( coord, self->sigma, self->Z, self->n, self->km, NULL, pressure, NULL, NULL );
+}
+
+void Underworld_solA_VelocityFunction( void* analyticSolution, double* coord, double* velocity ) {
+	Underworld_solA* self = (Underworld_solA*) analyticSolution;
+	
+	_Velic_solutionA( coord, self->sigma, self->Z, self->n, self->km, velocity, NULL, NULL, NULL );
+}
+
+void Underworld_solA_StressFunction( void* analyticSolution, double* coord, double* stress ) {
+	Underworld_solA* self = (Underworld_solA*) analyticSolution;
+	
+	_Velic_solutionA( coord, self->sigma, self->Z, self->n, self->km, NULL, NULL, stress, NULL );
+}
+
+
+void Underworld_solA_StrainRateFunction( void* analyticSolution, double* coord, double* strainRate ) {
+	Underworld_solA* self = (Underworld_solA*) analyticSolution;
+	
+	_Velic_solutionA( coord, self->sigma, self->Z, self->n, self->km, NULL, NULL, NULL, strainRate );
+}
+
+void _Underworld_solA_Init( Underworld_solA* self, double sigma, double Z, double wavenumberY, int n ) {
+	self->sigma = sigma;
+	self->Z     = Z;
+	self-> km   = M_PI * wavenumberY;
+	self->n     = n;	
+}
+
+void _Underworld_solA_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
+	Underworld_solA*	self = (Underworld_solA*) analyticSolution;
+	Bool					isCorrectInput = True;
+	double				sigma, Z, wavenumberY, n;
+	
+	/* Construct Parent */
+	_FieldTest_AssignFromXML( self, cf, data );
+
+	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solA_sigma", 1.0  );
+	Z = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solA_Z", 1.0  );
+	wavenumberY = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"wavenumberY", 1.5  );
+	n = Stg_ComponentFactory_GetRootDictInt( cf, "wavenumberX", 1 );
+	
+	_Underworld_solA_Init( self, sigma, Z, wavenumberY, n );
+
+	isCorrectInput = solA_checkInputParams( self );
+	Journal_Firewall( isCorrectInput , Journal_Register( Error_Type, (Name)"solA"  ),
+			"Error in function %s: Bad Input parameters, solution check valid values in .tex documentation\n",
+			__func__ );
+}
+
+void _Underworld_solA_Build( void* analyticSolution, void* data ) {
+	Underworld_solA* 		self = (Underworld_solA*) analyticSolution;
+
+	_FieldTest_Build( self, data );
+
+	/* here we assign the memory and the func ptr for analytic sols */
+	self->_analyticSolutionList = Memory_Alloc_Array_Unnamed( FieldTest_AnalyticSolutionFunc*, 4 );
+	/* this order MUST be consistent with the xml file definition */
+	self->_analyticSolutionList[0] = Underworld_solA_VelocityFunction;
+	self->_analyticSolutionList[1] = Underworld_solA_PressureFunction;
+	self->_analyticSolutionList[2] = Underworld_solA_StrainRateFunction;
+	self->_analyticSolutionList[3] = Underworld_solA_StressFunction;
+
+}
+
+Bool solA_checkInputParams( Underworld_solA* self ) {
+	return ( 
+		( self->sigma > 0.0 ) && ( self->Z > 0.0 ) &&
+		( self->km > 0.0 )    && ( self->n > 0 )  
+                 ) ? True : False;
+}
+
+void* _Underworld_solA_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Underworld_solA);
+	Type                                                      type = Underworld_solA_Type;
+	Stg_Class_DeleteFunction*                              _delete = _FieldTest_Delete;
+	Stg_Class_PrintFunction*                                _print = _FieldTest_Print;
+	Stg_Class_CopyFunction*                                  _copy = _FieldTest_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_solA_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Underworld_solA_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _Underworld_solA_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 Underworld_Velic_solA_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Underworld_solA_Type, (Name)"0", _Underworld_solA_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solA/solA.c
--- a/SysTest/AnalyticPlugins/Velic_solA/solA.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,193 +0,0 @@
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-
-void _Velic_solutionA( double* pos, 
-		double sigma, double Z, int n, double km,
-		double* velocity, double* pressure, double* Tstress, double* strainRate );
-
-#ifndef NOSHARED
-int main() {
-	double sigma = 1.0;
-	double Z = 1.0;
-	double km = M_PI;
-	int n = 1;
-	double pos[2], velocity[2], pressure, Tstress[3], strainRate[3],jp;
-	int i, j;	
-
-	for (i=0;i<101;i++){
-	      for(j=0;j<101;j++){
-		 pos[0] = i/100.0;
-		 pos[1] = j/100.0;
-
-		 _Velic_solutionA( pos,
-				sigma, Z, n, km,
-				velocity, &pressure,  Tstress, strainRate );
-
-		 printf("%.7g %.7g %.7g %.7g %.7g %.7g %.7g %.7g %.7g %.7g %.7g %.7g\n",
-				 pos[0], pos[1], velocity[0], velocity[1],
-				 pressure, jp, 
-				 strainRate[0], strainRate[1], strainRate[2],
-				 Tstress[0], Tstress[1], Tstress[2] );
-				 
-	      }
-	}
-
-	return 0;
-}
-#endif
-
-void _Velic_solutionA( double* pos, 
-		double sigma, double Z, int n, double km,
-		double* velocity, double* pressure,  double* Tstress, double* strainRate ) {
-	
-	double u1,u2,u3,u4,pp,txx;
-	double _C1,_C2,_C3,_C4;
-	double sum1,sum2,sum3,sum4,sum5,sum6,sum7,mag,x,z;
-	double ss,ss_z,ss_zz,ss_zzz,e_zz,e_xx,e_xz;
-	double t1,t3,t4,t5,t6,t7,t9,t10,t14,t15;
-	double t16,t17,t18,t19,t20,t21,t23,t24,t25,t26,t27,t29;
-	double kn;
-
-	kn = (double)n*M_PI;
-	x = pos[0];
-	z = pos[1];
-
-	sum1=0.0;
-	 sum2=0.0;
-	 sum3=0.0;
-	 sum4=0.0;
-	 sum5=0.0;
-	 sum6=0.0;
-	 sum7=0.0;
-
-	 t1 = sin(km);
-	 t3 = kn * kn;
-	 t4 = exp(-kn);
-	 t5 = t4 * t4;
-	 t10 = km * km;
-	 t17 = pow(t10 + t3, 0.2e1);
-	 t21 = pow(t4 - 0.1e1, 0.2e1);
-	 t24 = pow(t4 + 0.1e1, 0.2e1);
-	 _C1 = t1 * sigma * (t3 * t5 + t3 - 0.2e1 * kn * t5 + 0.2e1 * kn + t10 * t5 + t10) * t4 / Z / t17 / t21 / t24 / 0.2e1;
-
-	 t1 = sin(km);
-	 t3 = kn * kn;
-	 t4 = exp(-kn);
-	 t5 = t4 * t4;
-	 t10 = km * km;
-	 t16 = pow(t10 + t3, 0.2e1);
-	 t20 = pow(t4 - 0.1e1, 0.2e1);
-	 t23 = pow(t4 + 0.1e1, 0.2e1);
-	 _C2 = -t1 * sigma * (t3 * t5 + t3 - 0.2e1 * kn * t5 + 0.2e1 * kn + t10 * t5 + t10) / Z / t16 / t20 / t23 / 0.2e1;
-
-	 t1 = sin(km);
-	 t3 = exp(-kn);
-	 t6 = km * km;
-	 t7 = kn * kn;
-	 _C3 = -t1 * sigma * t3 / Z / (t6 + t7) / (t3 - 0.1e1) / (t3 + 0.1e1) / 0.2e1;
-
-	 t1 = sin(km);
-	 t5 = km * km;
-	 t6 = kn * kn;
-	 t9 = exp(-kn);
-	 _C4 = -t1 * sigma / Z / (t5 + t6) / (t9 - 0.1e1) / (t9 + 0.1e1) / 0.2e1;
-
-	 t4 = exp(-kn * z);
-	 t10 = exp(kn * (z - 0.1e1));
-	 t14 = sin(km * z);
-	 t15 = km * km;
-	 t16 = kn * kn;
-	 t18 = pow(t15 + t16, 0.2e1);
-	 ss = (_C1 + z * _C3) * t4 + (_C2 + z * _C4) * t10 + kn * sigma * t14 / t18 / Z;
-
-	 t6 = exp(-kn * z);
-	 t14 = exp(kn * (z - 0.1e1));
-	 t18 = cos(km * z);
-	 t20 = km * km;
-	 t21 = kn * kn;
-	 t23 = pow(t20 + t21, 0.2e1);
-	 ss_z = (-(_C1 + z * _C3) * kn + _C3) * t6 + (_C4 + (_C2 + z * _C4) * kn) * t14 + kn * sigma * t18 * km / t23 / Z;
-
-	 t3 = kn * kn;
-	 t9 = exp(-kn * z);
-	 t19 = exp(kn * (z - 0.1e1));
-	 t23 = sin(km * z);
-	 t25 = km * km;
-	 t27 = pow(t25 + t3, 0.2e1);
-	 ss_zz = ((_C1 + z * _C3) * t3 - 0.2e1 * _C3 * kn) * t9 + (0.2e1 * _C4 * kn + (_C2 + z * _C4) * t3) * t19 - kn * sigma * t23 * t25 / t27 / Z;
-
-	 t3 = kn * kn;
-	 t4 = t3 * kn;
-	 t10 = exp(-kn * z);
-	 t20 = exp(kn * (z - 0.1e1));
-	 t24 = cos(km * z);
-	 t26 = km * km;
-	 t29 = pow(t26 + t3, 0.2e1);
-	 ss_zzz = (-(_C1 + z * _C3) * t4 + 0.3e1 * _C3 * t3) * t10 + (0.3e1 * _C4 * t3 + (_C2 + z * _C4) * t4) * t20 - kn * sigma * t24 * t26 * km / t29 / Z;
-
-	 /* u1 = Vz, u2 = Vx, u3 = tzz, u4 = tzx, pp = pressure */
-
-	 u1 = kn*ss;
-	 u2 = -ss_z;
-	 pp = Z*(ss_zzz-kn*kn*ss_z)/kn;
-	 u3 = 2.0*kn*ss_z - pp;
-	 u4 = -Z*(ss_zz + kn*kn*ss);
-	 txx = -2.0*Z*kn*ss_z - pp;
-	 
-	 
-	 u1 *= cos(kn*x); /* z velocity */
-	 sum1 += u1;
-	 u2 *= sin(kn*x); /* x velocity */
-	 sum2 += u2;
-	 u3 *= cos(kn*x); /* zz stress */
-	 sum3 += u3;
-	 u4 *= sin(kn*x); /* zx stress */
-	 sum4 += u4;
-	 txx *= cos(kn*x); /* xx stress */
-	 sum6 += txx;
-	 pp *= cos(kn*x); /* pressure */
-	 sum5 += pp;
-
-	 e_zz = kn*ss_z*cos(kn*x);  /* zz rate of strain */
-	 e_xx = -e_zz;  /* xx rate of strain */
-	 e_xz = -0.5*(ss_zz+kn*kn*ss)*sin(kn*x); /* xz rate of strain */
-
-	 ss *= sin(kn*x); /* stream function */
-	 /* density/temp */
-	 sum7 += -sin(km*z)*cos(kn*x);
-	 mag=sqrt(sum1*sum1+sum2*sum2);
-
-//	 printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,e_zz,e_xx,e_xz,ss);
-
-	 if ( velocity != NULL ) {
-		 velocity[0] = sum2;
-		 velocity[1] = sum1;
-	 }
-	 if( pressure != NULL ) {
-		 *pressure = sum5;
-	 }
-	 if( Tstress != NULL ) {
-		 Tstress[0] = sum6;
-		 Tstress[1] = sum3;
-		 Tstress[2] = sum4; /*2*Z*e_xz;*/
-	 }
-	 if( strainRate != NULL ) {
-		 strainRate[0] = e_xx;
-		 strainRate[1] = e_zz;
-		 strainRate[2] = e_xz;
-	 }
-	 /*
-	 if ( fabs( sum3 - ( 2*Z*e_zz - sum5 ) ) > 1e-4 ) {
-		 printf("%g is not within tolerance 1e-4\n", sum3 - ( 2*Z*e_zz + sum5 ) );
-		 assert(0);
-	 }
-	 if( fabs( sum5 - ( -0.5*(sum6 + sum3) ) ) > 1e-4 ) {
-		 printf("error is %g, which is outside tolerance of 1e-4\n", fabs( sum5 - ( -0.5*(sum6 + sum3) )) );
-		 assert(0);
-	 }
-	 */
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solA/solA.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solA/solA.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,193 @@
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+
+void _Velic_solutionA( double* pos, 
+		double sigma, double Z, int n, double km,
+		double* velocity, double* pressure, double* Tstress, double* strainRate );
+
+#ifndef NOSHARED
+int main() {
+	double sigma = 1.0;
+	double Z = 1.0;
+	double km = M_PI;
+	int n = 1;
+	double pos[2], velocity[2], pressure, Tstress[3], strainRate[3],jp;
+	int i, j;	
+
+	for (i=0;i<101;i++){
+	      for(j=0;j<101;j++){
+		 pos[0] = i/100.0;
+		 pos[1] = j/100.0;
+
+		 _Velic_solutionA( pos,
+				sigma, Z, n, km,
+				velocity, &pressure,  Tstress, strainRate );
+
+		 printf("%.7g %.7g %.7g %.7g %.7g %.7g %.7g %.7g %.7g %.7g %.7g %.7g\n",
+				 pos[0], pos[1], velocity[0], velocity[1],
+				 pressure, jp, 
+				 strainRate[0], strainRate[1], strainRate[2],
+				 Tstress[0], Tstress[1], Tstress[2] );
+				 
+	      }
+	}
+
+	return 0;
+}
+#endif
+
+void _Velic_solutionA( double* pos, 
+		double sigma, double Z, int n, double km,
+		double* velocity, double* pressure,  double* Tstress, double* strainRate ) {
+	
+	double u1,u2,u3,u4,pp,txx;
+	double _C1,_C2,_C3,_C4;
+	double sum1,sum2,sum3,sum4,sum5,sum6,sum7,mag,x,z;
+	double ss,ss_z,ss_zz,ss_zzz,e_zz,e_xx,e_xz;
+	double t1,t3,t4,t5,t6,t7,t9,t10,t14,t15;
+	double t16,t17,t18,t19,t20,t21,t23,t24,t25,t26,t27,t29;
+	double kn;
+
+	kn = (double)n*M_PI;
+	x = pos[0];
+	z = pos[1];
+
+	sum1=0.0;
+	 sum2=0.0;
+	 sum3=0.0;
+	 sum4=0.0;
+	 sum5=0.0;
+	 sum6=0.0;
+	 sum7=0.0;
+
+	 t1 = sin(km);
+	 t3 = kn * kn;
+	 t4 = exp(-kn);
+	 t5 = t4 * t4;
+	 t10 = km * km;
+	 t17 = pow(t10 + t3, 0.2e1);
+	 t21 = pow(t4 - 0.1e1, 0.2e1);
+	 t24 = pow(t4 + 0.1e1, 0.2e1);
+	 _C1 = t1 * sigma * (t3 * t5 + t3 - 0.2e1 * kn * t5 + 0.2e1 * kn + t10 * t5 + t10) * t4 / Z / t17 / t21 / t24 / 0.2e1;
+
+	 t1 = sin(km);
+	 t3 = kn * kn;
+	 t4 = exp(-kn);
+	 t5 = t4 * t4;
+	 t10 = km * km;
+	 t16 = pow(t10 + t3, 0.2e1);
+	 t20 = pow(t4 - 0.1e1, 0.2e1);
+	 t23 = pow(t4 + 0.1e1, 0.2e1);
+	 _C2 = -t1 * sigma * (t3 * t5 + t3 - 0.2e1 * kn * t5 + 0.2e1 * kn + t10 * t5 + t10) / Z / t16 / t20 / t23 / 0.2e1;
+
+	 t1 = sin(km);
+	 t3 = exp(-kn);
+	 t6 = km * km;
+	 t7 = kn * kn;
+	 _C3 = -t1 * sigma * t3 / Z / (t6 + t7) / (t3 - 0.1e1) / (t3 + 0.1e1) / 0.2e1;
+
+	 t1 = sin(km);
+	 t5 = km * km;
+	 t6 = kn * kn;
+	 t9 = exp(-kn);
+	 _C4 = -t1 * sigma / Z / (t5 + t6) / (t9 - 0.1e1) / (t9 + 0.1e1) / 0.2e1;
+
+	 t4 = exp(-kn * z);
+	 t10 = exp(kn * (z - 0.1e1));
+	 t14 = sin(km * z);
+	 t15 = km * km;
+	 t16 = kn * kn;
+	 t18 = pow(t15 + t16, 0.2e1);
+	 ss = (_C1 + z * _C3) * t4 + (_C2 + z * _C4) * t10 + kn * sigma * t14 / t18 / Z;
+
+	 t6 = exp(-kn * z);
+	 t14 = exp(kn * (z - 0.1e1));
+	 t18 = cos(km * z);
+	 t20 = km * km;
+	 t21 = kn * kn;
+	 t23 = pow(t20 + t21, 0.2e1);
+	 ss_z = (-(_C1 + z * _C3) * kn + _C3) * t6 + (_C4 + (_C2 + z * _C4) * kn) * t14 + kn * sigma * t18 * km / t23 / Z;
+
+	 t3 = kn * kn;
+	 t9 = exp(-kn * z);
+	 t19 = exp(kn * (z - 0.1e1));
+	 t23 = sin(km * z);
+	 t25 = km * km;
+	 t27 = pow(t25 + t3, 0.2e1);
+	 ss_zz = ((_C1 + z * _C3) * t3 - 0.2e1 * _C3 * kn) * t9 + (0.2e1 * _C4 * kn + (_C2 + z * _C4) * t3) * t19 - kn * sigma * t23 * t25 / t27 / Z;
+
+	 t3 = kn * kn;
+	 t4 = t3 * kn;
+	 t10 = exp(-kn * z);
+	 t20 = exp(kn * (z - 0.1e1));
+	 t24 = cos(km * z);
+	 t26 = km * km;
+	 t29 = pow(t26 + t3, 0.2e1);
+	 ss_zzz = (-(_C1 + z * _C3) * t4 + 0.3e1 * _C3 * t3) * t10 + (0.3e1 * _C4 * t3 + (_C2 + z * _C4) * t4) * t20 - kn * sigma * t24 * t26 * km / t29 / Z;
+
+	 /* u1 = Vz, u2 = Vx, u3 = tzz, u4 = tzx, pp = pressure */
+
+	 u1 = kn*ss;
+	 u2 = -ss_z;
+	 pp = Z*(ss_zzz-kn*kn*ss_z)/kn;
+	 u3 = 2.0*kn*ss_z - pp;
+	 u4 = -Z*(ss_zz + kn*kn*ss);
+	 txx = -2.0*Z*kn*ss_z - pp;
+	 
+	 
+	 u1 *= cos(kn*x); /* z velocity */
+	 sum1 += u1;
+	 u2 *= sin(kn*x); /* x velocity */
+	 sum2 += u2;
+	 u3 *= cos(kn*x); /* zz stress */
+	 sum3 += u3;
+	 u4 *= sin(kn*x); /* zx stress */
+	 sum4 += u4;
+	 txx *= cos(kn*x); /* xx stress */
+	 sum6 += txx;
+	 pp *= cos(kn*x); /* pressure */
+	 sum5 += pp;
+
+	 e_zz = kn*ss_z*cos(kn*x);  /* zz rate of strain */
+	 e_xx = -e_zz;  /* xx rate of strain */
+	 e_xz = -0.5*(ss_zz+kn*kn*ss)*sin(kn*x); /* xz rate of strain */
+
+	 ss *= sin(kn*x); /* stream function */
+	 /* density/temp */
+	 sum7 += -sin(km*z)*cos(kn*x);
+	 mag=sqrt(sum1*sum1+sum2*sum2);
+
+//	 printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,e_zz,e_xx,e_xz,ss);
+
+	 if ( velocity != NULL ) {
+		 velocity[0] = sum2;
+		 velocity[1] = sum1;
+	 }
+	 if( pressure != NULL ) {
+		 *pressure = sum5;
+	 }
+	 if( Tstress != NULL ) {
+		 Tstress[0] = sum6;
+		 Tstress[1] = sum3;
+		 Tstress[2] = sum4; /*2*Z*e_xz;*/
+	 }
+	 if( strainRate != NULL ) {
+		 strainRate[0] = e_xx;
+		 strainRate[1] = e_zz;
+		 strainRate[2] = e_xz;
+	 }
+	 /*
+	 if ( fabs( sum3 - ( 2*Z*e_zz - sum5 ) ) > 1e-4 ) {
+		 printf("%g is not within tolerance 1e-4\n", sum3 - ( 2*Z*e_zz + sum5 ) );
+		 assert(0);
+	 }
+	 if( fabs( sum5 - ( -0.5*(sum6 + sum3) ) ) > 1e-4 ) {
+		 printf("error is %g, which is outside tolerance of 1e-4\n", fabs( sum5 - ( -0.5*(sum6 + sum3) )) );
+		 assert(0);
+	 }
+	 */
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solB/Analytic_solB.c
--- a/SysTest/AnalyticPlugins/Velic_solB/Analytic_solB.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,145 +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:
-*+		Mirko Velic
-*+		Julian Giordani
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Patrick Sunter
-** $Id: solB.c 636 2006-09-08 03:07:06Z JulianGiordani $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include "Analytic_solB.h"
-
-const Type Underworld_solB_Type = "Underworld_Velic_solB";
-
-void Underworld_solB_PressureFunction( void* analyticSolution, double* coord, double* pressure ) {
-	Underworld_solB* self = (Underworld_solB*) analyticSolution;
-	
-	_Velic_solB( coord, self->sigma, self->Z, self->n, self->km, NULL, pressure, NULL, NULL );
-}
-
-void Underworld_solB_VelocityFunction( void* analyticSolution, double* coord, double* velocity ) {
-	Underworld_solB* self = (Underworld_solB*) analyticSolution;
-	
-	_Velic_solB( coord, self->sigma, self->Z, self->n, self->km, velocity, NULL, NULL, NULL );
-}
-
-void Underworld_solB_StressFunction( void* analyticSolution, double* coord, double* stress ) {
-	Underworld_solB* self = (Underworld_solB*) analyticSolution;
-	
-	_Velic_solB( coord, self->sigma, self->Z, self->n, self->km, NULL, NULL, stress, NULL );
-}
-
-
-void Underworld_solB_StrainRateFunction( void* analyticSolution, double* coord, double* strainRate ) {
-	Underworld_solB* self = (Underworld_solB*) analyticSolution;
-	
-	_Velic_solB( coord, self->sigma, self->Z, self->n, self->km, NULL, NULL, NULL, strainRate );
-}
-
-void _Underworld_solB_Init( Underworld_solB* self, double sigma, double Z, double wavenumberY, int n ) {
-	self->sigma = sigma;
-	self->Z     = Z;
-	self-> km   = wavenumberY;
-	self->n     = n;	
-}
-
-void _Underworld_solB_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
-	Underworld_solB* 		self = (Underworld_solB*) analyticSolution;
-	Bool                     isCorrectInput = True;
-	double                   sigma, Z, wavenumberY, n;
-
-	/* Construct Parent */
-	_FieldTest_AssignFromXML( self, cf, data );
-
-	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solB_sigma", 1.0  );
-	Z = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solB_Z", 1.0  );
-	wavenumberY = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"wavenumberY", 1.0  );
-	n = Stg_ComponentFactory_GetRootDictInt( cf, "wavenumberX", 1 );
-	
-	_Underworld_solB_Init( self, sigma, Z, wavenumberY, n );
-
-	isCorrectInput = solB_checkInputParams( self );
-	Journal_Firewall( isCorrectInput , Journal_Register( Error_Type, (Name)"Analytic_solB"  ),
-			"Error in function %s: Bad Input parameters, solution check valid values in .tex documentation\n",
-			__func__ );
-}
-
-void _Underworld_solB_Build( void* analyticSolution, void* data ) {
-	Underworld_solB* 		self = (Underworld_solB*) analyticSolution;
-
-	_FieldTest_Build( self, data );
-
-	/* here we assign the memory and the func ptr for analytic sols */
-	self->_analyticSolutionList = Memory_Alloc_Array_Unnamed( FieldTest_AnalyticSolutionFunc*, 4 );
-	/* this order MUST be consistent with the xml file definition */
-	self->_analyticSolutionList[0] = Underworld_solB_VelocityFunction;
-	self->_analyticSolutionList[1] = Underworld_solB_PressureFunction;
-	self->_analyticSolutionList[2] = Underworld_solB_StrainRateFunction;
-	self->_analyticSolutionList[3] = Underworld_solB_StressFunction;
-}
-
-Bool solB_checkInputParams( Underworld_solB* self ) {
-	return ( 
-			( self->sigma > 0.0 ) && ( self->Z > 0.0 ) &&
-			( self->km > 0.0 )    && ( self->n > 0 )  
-                 ) ? True : False;
-}
-void* _Underworld_solB_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Underworld_solB);
-	Type                                                      type = Underworld_solB_Type;
-	Stg_Class_DeleteFunction*                              _delete = _FieldTest_Delete;
-	Stg_Class_PrintFunction*                                _print = _FieldTest_Print;
-	Stg_Class_CopyFunction*                                  _copy = _FieldTest_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_solB_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Underworld_solB_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _Underworld_solB_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 Underworld_Velic_solB_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Underworld_solB_Type, (Name)"0", _Underworld_solB_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solB/Analytic_solB.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solB/Analytic_solB.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,145 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Mirko Velic
+*+		Julian Giordani
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Patrick Sunter
+** $Id: solB.c 636 2006-09-08 03:07:06Z JulianGiordani $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include "Analytic_solB.h"
+
+const Type Underworld_solB_Type = "Underworld_Velic_solB";
+
+void Underworld_solB_PressureFunction( void* analyticSolution, double* coord, double* pressure ) {
+	Underworld_solB* self = (Underworld_solB*) analyticSolution;
+	
+	_Velic_solB( coord, self->sigma, self->Z, self->n, self->km, NULL, pressure, NULL, NULL );
+}
+
+void Underworld_solB_VelocityFunction( void* analyticSolution, double* coord, double* velocity ) {
+	Underworld_solB* self = (Underworld_solB*) analyticSolution;
+	
+	_Velic_solB( coord, self->sigma, self->Z, self->n, self->km, velocity, NULL, NULL, NULL );
+}
+
+void Underworld_solB_StressFunction( void* analyticSolution, double* coord, double* stress ) {
+	Underworld_solB* self = (Underworld_solB*) analyticSolution;
+	
+	_Velic_solB( coord, self->sigma, self->Z, self->n, self->km, NULL, NULL, stress, NULL );
+}
+
+
+void Underworld_solB_StrainRateFunction( void* analyticSolution, double* coord, double* strainRate ) {
+	Underworld_solB* self = (Underworld_solB*) analyticSolution;
+	
+	_Velic_solB( coord, self->sigma, self->Z, self->n, self->km, NULL, NULL, NULL, strainRate );
+}
+
+void _Underworld_solB_Init( Underworld_solB* self, double sigma, double Z, double wavenumberY, int n ) {
+	self->sigma = sigma;
+	self->Z     = Z;
+	self-> km   = wavenumberY;
+	self->n     = n;	
+}
+
+void _Underworld_solB_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
+	Underworld_solB* 		self = (Underworld_solB*) analyticSolution;
+	Bool                     isCorrectInput = True;
+	double                   sigma, Z, wavenumberY, n;
+
+	/* Construct Parent */
+	_FieldTest_AssignFromXML( self, cf, data );
+
+	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solB_sigma", 1.0  );
+	Z = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solB_Z", 1.0  );
+	wavenumberY = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"wavenumberY", 1.0  );
+	n = Stg_ComponentFactory_GetRootDictInt( cf, "wavenumberX", 1 );
+	
+	_Underworld_solB_Init( self, sigma, Z, wavenumberY, n );
+
+	isCorrectInput = solB_checkInputParams( self );
+	Journal_Firewall( isCorrectInput , Journal_Register( Error_Type, (Name)"Analytic_solB"  ),
+			"Error in function %s: Bad Input parameters, solution check valid values in .tex documentation\n",
+			__func__ );
+}
+
+void _Underworld_solB_Build( void* analyticSolution, void* data ) {
+	Underworld_solB* 		self = (Underworld_solB*) analyticSolution;
+
+	_FieldTest_Build( self, data );
+
+	/* here we assign the memory and the func ptr for analytic sols */
+	self->_analyticSolutionList = Memory_Alloc_Array_Unnamed( FieldTest_AnalyticSolutionFunc*, 4 );
+	/* this order MUST be consistent with the xml file definition */
+	self->_analyticSolutionList[0] = Underworld_solB_VelocityFunction;
+	self->_analyticSolutionList[1] = Underworld_solB_PressureFunction;
+	self->_analyticSolutionList[2] = Underworld_solB_StrainRateFunction;
+	self->_analyticSolutionList[3] = Underworld_solB_StressFunction;
+}
+
+Bool solB_checkInputParams( Underworld_solB* self ) {
+	return ( 
+			( self->sigma > 0.0 ) && ( self->Z > 0.0 ) &&
+			( self->km > 0.0 )    && ( self->n > 0 )  
+                 ) ? True : False;
+}
+void* _Underworld_solB_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Underworld_solB);
+	Type                                                      type = Underworld_solB_Type;
+	Stg_Class_DeleteFunction*                              _delete = _FieldTest_Delete;
+	Stg_Class_PrintFunction*                                _print = _FieldTest_Print;
+	Stg_Class_CopyFunction*                                  _copy = _FieldTest_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_solB_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Underworld_solB_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _Underworld_solB_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 Underworld_Velic_solB_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Underworld_solB_Type, (Name)"0", _Underworld_solB_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solB/solB.c
--- a/SysTest/AnalyticPlugins/Velic_solB/solB.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,191 +0,0 @@
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-
-void _Velic_solB( double* pos,
-		double sigma, double Z, int n, double km,
-		double* velocity, double* pressure, double* Tstress, double* strainRate );
-
-#ifndef NOSHARED
-int main() {
-	double sigma = 1.0;
-	double Z = 1.0;
-	int n = 1;
-	double km = 2*M_PI;
-	double pos[2], velocity[2], pressure, Tstress[3], strainRate[3];
-	int i,j;
-
-	for (i=0;i<33;i++){
-		for(j=0;j<33;j++){
-			pos[0] = i/32.0;
-			pos[1] = j/32.0;
-
-			_Velic_solB( pos,
-					sigma, Z, n, km,
-					velocity, &pressure, Tstress, strainRate );
-
-			printf("%.7g %.7g %.7g %.7g %.7g %.7g %.7g %.7g %.7g %.7g %.7g\n",
-				 pos[0], pos[1], velocity[0], velocity[1],
-				 pressure, 
-				 strainRate[0], strainRate[1], strainRate[2],
-				 Tstress[0], Tstress[1], Tstress[2] );
-		}
-	}
-	return 0;
-}
-#endif
-
-void _Velic_solB( double* pos,
-		double sigma, double Z, int n, double km,
-		double* velocity, double* pressure, double* Tstress, double* strainRate ) {
-
-   double u1,u2,u3,u4,pp,txx;
-   double _C1,_C2,_C3,_C4;
-   double sum1,sum2,sum3,sum4,sum5,sum6,sum7,mag,x,z;
-   double kn;
-   double ss,ss_z,ss_zz,ss_zzz,e_zz,e_xx,e_xz;
-   double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
-   double t11,t12,t14,t15,t16,t18,t19,t20,t21,t22;
-   double t23,t24,t25,t26,t27,t28,t29,t32,t33;
-
-   kn = (double)n*M_PI;
-
-   	 x = pos[0];
-	 z = pos[1];
-
-	 sum1=0.0;
-	 sum2=0.0;
-	 sum3=0.0;
-	 sum4=0.0;
-	 sum5=0.0;
-	 sum6=0.0;
-	 sum7=0.0;
-	 
-
-	 t1 = exp(km);
-	 t5 = kn * kn;
-	 t6 = exp(-kn);
-	 t7 = t6 * t6;
-	 t12 = km * km;
-	 t22 = pow(-0.1e1 + t6, 0.2e1);
-	 t26 = pow(t6 + 0.1e1, 0.2e1);
-	 t29 = pow(kn - km, 0.2e1);
-	 t33 = pow(kn + km, 0.2e1);
-	 _C1 = sigma * (-0.1e1 + t1) * (t1 + 0.1e1) * (t5 * t7 + t5 + 0.2e1 * kn - 0.2e1 * kn * t7 - t12 * t7 - t12) * t6 / Z / t1 / t22 / t26 / t29 / t33 / 0.4e1;
-
-	 t1 = kn * kn;
-	 t2 = exp(-kn);
-	 t3 = t2 * t2;
-	 t8 = km * km;
-	 t11 = exp(km);
-	 t21 = pow(-0.1e1 + t2, 0.2e1);
-	 t25 = pow(t2 + 0.1e1, 0.2e1);
-	 t28 = pow(kn - km, 0.2e1);
-	 t32 = pow(kn + km, 0.2e1);
-	 _C2 = -(t1 * t3 + t1 + 0.2e1 * kn - 0.2e1 * kn * t3 - t8 * t3 - t8) * (t11 + 0.1e1) * (-0.1e1 + t11) * sigma / Z / t11 / t21 / t25 / t28 / t32 / 0.4e1;
-
-	 t1 = exp(km);
-	 t5 = exp(-kn);
-	 _C3 = -sigma * (-0.1e1 + t1) * (t1 + 0.1e1) * t5 / Z / t1 / (-0.1e1 + t5) / (t5 + 0.1e1) / (kn - km) / (kn + km) / 0.4e1;
-
-	 t1 = exp(km);
-	 t9 = exp(-kn);
-	 _C4 = -(t1 + 0.1e1) * (-0.1e1 + t1) * sigma / Z / t1 / (-0.1e1 + t9) / (t9 + 0.1e1) / (kn - km) / (kn + km) / 0.4e1;
-
-	 t4 = exp(-kn * z);
-	 t10 = exp(kn * (z - 0.1e1));
-	 t14 = sinh(km * z);
-	 t15 = km * km;
-	 t16 = kn * kn;
-	 t18 = pow(t15 - t16, 0.2e1);
-	 ss = (_C1 + z * _C3) * t4 + (_C2 + z * _C4) * t10 + kn * sigma * t14 / t18 / Z;
-
-	 t6 = exp(-kn * z);
-	 t14 = exp(kn * (z - 0.1e1));
-	 t18 = cosh(km * z);
-	 t20 = km * km;
-	 t21 = kn * kn;
-	 t23 = pow(t20 - t21, 0.2e1);
-	 ss_z = (-(_C1 + z * _C3) * kn + _C3) * t6 + (_C4 + (_C2 + z * _C4) * kn) * t14 + kn * sigma * t18 * km / t23 / Z;
-
-	 t3 = kn * kn;
-	 t9 = exp(-kn * z);
-	 t19 = exp(kn * (z - 0.1e1));
-	 t23 = sinh(km * z);
-	 t25 = km * km;
-	 t27 = pow(t25 - t3, 0.2e1);
-	 ss_zz = ((_C1 + z * _C3) * t3 - 0.2e1 * _C3 * kn) * t9 + (0.2e1 * _C4 * kn + (_C2 + z * _C4) * t3) * t19 + kn * sigma * t23 * t25 / t27 / Z;
-
-	 t3 = kn * kn;
-	 t4 = t3 * kn;
-	 t10 = exp(-kn * z);
-	 t20 = exp(kn * (z - 0.1e1));
-	 t24 = cosh(km * z);
-	 t26 = km * km;
-	 t29 = pow(t26 - t3, 0.2e1);
-	 ss_zzz = (-(_C1 + z * _C3) * t4 + 0.3e1 * _C3 * t3) * t10 + (0.3e1 * _C4 * t3 + (_C2 + z * _C4) * t4) * t20 + kn * sigma * t24 * t26 * km / t29 / Z;
-
-	 /* u1 = Vz, u2 = Vx, u3 = tzz, u4 = tzx, pp = pressure */
-
-	 u1 = kn*ss;
-	 u2 = -ss_z;
-	 pp = Z*(ss_zzz-kn*kn*ss_z)/kn;
-	 u3 = 2.0*Z*kn*ss_z - pp;
-	 u4 = -Z*(ss_zz + kn*kn*ss);
-	 txx = -2.0*Z*kn*ss_z - pp;
-	 
-	 
-	 u1 *= cos(kn*x); /* z velocity */
-	 sum1 += u1;
-	 u2 *= sin(kn*x); /* x velocity */
-	 sum2 += u2;
-	 u3 *= cos(kn*x); /* zz stress */
-	 sum3 += u3;
-	 u4 *= sin(kn*x); /* zx stress */
-	 sum4 += u4;
-	 txx *= cos(kn*x); /* xx stress */
-	 sum6 += txx;
-	 pp *= cos(kn*x); /* pressure */
-	 sum5 += pp;
-
-	 e_zz = kn*ss_z*cos(kn*x);  /* zz rate of strain */
-	 e_xx = -e_zz;  /* xx rate of strain */
-	 e_xz = -0.5*(ss_zz+kn*kn*ss)*sin(kn*x); /* xz rate of strain */
-
-	 ss *= sin(kn*x); /* stream function */
-	 /* density/temp */
-	 sum7 += -sigma*sinh(km*z)*cos(kn*x);
-
-	 mag=sqrt(sum1*sum1+sum2*sum2);
-	// printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,e_zz,e_xx,e_xz,ss);	    
-	 if ( velocity != NULL ) {
-		 velocity[0] = sum2;
-		 velocity[1] = sum1;
-	 }
-	 if( pressure != NULL ) {
-		 *pressure = sum5;
-	 }
-	 if( Tstress != NULL ) {
-		 Tstress[0] = sum6;
-		 Tstress[1] = sum3;
-		 Tstress[2] = sum4;
-	 }
-	 if( strainRate != NULL ) {
-		 strainRate[0] = e_xx;
-		 strainRate[1] = e_zz;
-		 strainRate[2] = e_xz;
-	 }
-	 /* Value checks, could be cleaned up if needed. Julian Giordani 2-Oct-2006*/
-	 if( fabs( sum5 - ( -0.5*(sum6+sum3) ) ) > 1e-5 ) {
-		 assert(0);
-	 }
-	 if( fabs( sum6 - (2*Z*e_xx - sum5) ) > 1e-5 ) {
-		 assert(0);
-	 }
-	 if( fabs( sum3 - (2*Z*e_zz - sum5) ) > 1e-5 ) {
-		 assert(0);
-	 }
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solB/solB.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solB/solB.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,191 @@
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+
+void _Velic_solB( double* pos,
+		double sigma, double Z, int n, double km,
+		double* velocity, double* pressure, double* Tstress, double* strainRate );
+
+#ifndef NOSHARED
+int main() {
+	double sigma = 1.0;
+	double Z = 1.0;
+	int n = 1;
+	double km = 2*M_PI;
+	double pos[2], velocity[2], pressure, Tstress[3], strainRate[3];
+	int i,j;
+
+	for (i=0;i<33;i++){
+		for(j=0;j<33;j++){
+			pos[0] = i/32.0;
+			pos[1] = j/32.0;
+
+			_Velic_solB( pos,
+					sigma, Z, n, km,
+					velocity, &pressure, Tstress, strainRate );
+
+			printf("%.7g %.7g %.7g %.7g %.7g %.7g %.7g %.7g %.7g %.7g %.7g\n",
+				 pos[0], pos[1], velocity[0], velocity[1],
+				 pressure, 
+				 strainRate[0], strainRate[1], strainRate[2],
+				 Tstress[0], Tstress[1], Tstress[2] );
+		}
+	}
+	return 0;
+}
+#endif
+
+void _Velic_solB( double* pos,
+		double sigma, double Z, int n, double km,
+		double* velocity, double* pressure, double* Tstress, double* strainRate ) {
+
+   double u1,u2,u3,u4,pp,txx;
+   double _C1,_C2,_C3,_C4;
+   double sum1,sum2,sum3,sum4,sum5,sum6,sum7,mag,x,z;
+   double kn;
+   double ss,ss_z,ss_zz,ss_zzz,e_zz,e_xx,e_xz;
+   double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
+   double t11,t12,t14,t15,t16,t18,t19,t20,t21,t22;
+   double t23,t24,t25,t26,t27,t28,t29,t32,t33;
+
+   kn = (double)n*M_PI;
+
+   	 x = pos[0];
+	 z = pos[1];
+
+	 sum1=0.0;
+	 sum2=0.0;
+	 sum3=0.0;
+	 sum4=0.0;
+	 sum5=0.0;
+	 sum6=0.0;
+	 sum7=0.0;
+	 
+
+	 t1 = exp(km);
+	 t5 = kn * kn;
+	 t6 = exp(-kn);
+	 t7 = t6 * t6;
+	 t12 = km * km;
+	 t22 = pow(-0.1e1 + t6, 0.2e1);
+	 t26 = pow(t6 + 0.1e1, 0.2e1);
+	 t29 = pow(kn - km, 0.2e1);
+	 t33 = pow(kn + km, 0.2e1);
+	 _C1 = sigma * (-0.1e1 + t1) * (t1 + 0.1e1) * (t5 * t7 + t5 + 0.2e1 * kn - 0.2e1 * kn * t7 - t12 * t7 - t12) * t6 / Z / t1 / t22 / t26 / t29 / t33 / 0.4e1;
+
+	 t1 = kn * kn;
+	 t2 = exp(-kn);
+	 t3 = t2 * t2;
+	 t8 = km * km;
+	 t11 = exp(km);
+	 t21 = pow(-0.1e1 + t2, 0.2e1);
+	 t25 = pow(t2 + 0.1e1, 0.2e1);
+	 t28 = pow(kn - km, 0.2e1);
+	 t32 = pow(kn + km, 0.2e1);
+	 _C2 = -(t1 * t3 + t1 + 0.2e1 * kn - 0.2e1 * kn * t3 - t8 * t3 - t8) * (t11 + 0.1e1) * (-0.1e1 + t11) * sigma / Z / t11 / t21 / t25 / t28 / t32 / 0.4e1;
+
+	 t1 = exp(km);
+	 t5 = exp(-kn);
+	 _C3 = -sigma * (-0.1e1 + t1) * (t1 + 0.1e1) * t5 / Z / t1 / (-0.1e1 + t5) / (t5 + 0.1e1) / (kn - km) / (kn + km) / 0.4e1;
+
+	 t1 = exp(km);
+	 t9 = exp(-kn);
+	 _C4 = -(t1 + 0.1e1) * (-0.1e1 + t1) * sigma / Z / t1 / (-0.1e1 + t9) / (t9 + 0.1e1) / (kn - km) / (kn + km) / 0.4e1;
+
+	 t4 = exp(-kn * z);
+	 t10 = exp(kn * (z - 0.1e1));
+	 t14 = sinh(km * z);
+	 t15 = km * km;
+	 t16 = kn * kn;
+	 t18 = pow(t15 - t16, 0.2e1);
+	 ss = (_C1 + z * _C3) * t4 + (_C2 + z * _C4) * t10 + kn * sigma * t14 / t18 / Z;
+
+	 t6 = exp(-kn * z);
+	 t14 = exp(kn * (z - 0.1e1));
+	 t18 = cosh(km * z);
+	 t20 = km * km;
+	 t21 = kn * kn;
+	 t23 = pow(t20 - t21, 0.2e1);
+	 ss_z = (-(_C1 + z * _C3) * kn + _C3) * t6 + (_C4 + (_C2 + z * _C4) * kn) * t14 + kn * sigma * t18 * km / t23 / Z;
+
+	 t3 = kn * kn;
+	 t9 = exp(-kn * z);
+	 t19 = exp(kn * (z - 0.1e1));
+	 t23 = sinh(km * z);
+	 t25 = km * km;
+	 t27 = pow(t25 - t3, 0.2e1);
+	 ss_zz = ((_C1 + z * _C3) * t3 - 0.2e1 * _C3 * kn) * t9 + (0.2e1 * _C4 * kn + (_C2 + z * _C4) * t3) * t19 + kn * sigma * t23 * t25 / t27 / Z;
+
+	 t3 = kn * kn;
+	 t4 = t3 * kn;
+	 t10 = exp(-kn * z);
+	 t20 = exp(kn * (z - 0.1e1));
+	 t24 = cosh(km * z);
+	 t26 = km * km;
+	 t29 = pow(t26 - t3, 0.2e1);
+	 ss_zzz = (-(_C1 + z * _C3) * t4 + 0.3e1 * _C3 * t3) * t10 + (0.3e1 * _C4 * t3 + (_C2 + z * _C4) * t4) * t20 + kn * sigma * t24 * t26 * km / t29 / Z;
+
+	 /* u1 = Vz, u2 = Vx, u3 = tzz, u4 = tzx, pp = pressure */
+
+	 u1 = kn*ss;
+	 u2 = -ss_z;
+	 pp = Z*(ss_zzz-kn*kn*ss_z)/kn;
+	 u3 = 2.0*Z*kn*ss_z - pp;
+	 u4 = -Z*(ss_zz + kn*kn*ss);
+	 txx = -2.0*Z*kn*ss_z - pp;
+	 
+	 
+	 u1 *= cos(kn*x); /* z velocity */
+	 sum1 += u1;
+	 u2 *= sin(kn*x); /* x velocity */
+	 sum2 += u2;
+	 u3 *= cos(kn*x); /* zz stress */
+	 sum3 += u3;
+	 u4 *= sin(kn*x); /* zx stress */
+	 sum4 += u4;
+	 txx *= cos(kn*x); /* xx stress */
+	 sum6 += txx;
+	 pp *= cos(kn*x); /* pressure */
+	 sum5 += pp;
+
+	 e_zz = kn*ss_z*cos(kn*x);  /* zz rate of strain */
+	 e_xx = -e_zz;  /* xx rate of strain */
+	 e_xz = -0.5*(ss_zz+kn*kn*ss)*sin(kn*x); /* xz rate of strain */
+
+	 ss *= sin(kn*x); /* stream function */
+	 /* density/temp */
+	 sum7 += -sigma*sinh(km*z)*cos(kn*x);
+
+	 mag=sqrt(sum1*sum1+sum2*sum2);
+	// printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,e_zz,e_xx,e_xz,ss);	    
+	 if ( velocity != NULL ) {
+		 velocity[0] = sum2;
+		 velocity[1] = sum1;
+	 }
+	 if( pressure != NULL ) {
+		 *pressure = sum5;
+	 }
+	 if( Tstress != NULL ) {
+		 Tstress[0] = sum6;
+		 Tstress[1] = sum3;
+		 Tstress[2] = sum4;
+	 }
+	 if( strainRate != NULL ) {
+		 strainRate[0] = e_xx;
+		 strainRate[1] = e_zz;
+		 strainRate[2] = e_xz;
+	 }
+	 /* Value checks, could be cleaned up if needed. Julian Giordani 2-Oct-2006*/
+	 if( fabs( sum5 - ( -0.5*(sum6+sum3) ) ) > 1e-5 ) {
+		 assert(0);
+	 }
+	 if( fabs( sum6 - (2*Z*e_xx - sum5) ) > 1e-5 ) {
+		 assert(0);
+	 }
+	 if( fabs( sum3 - (2*Z*e_zz - sum5) ) > 1e-5 ) {
+		 assert(0);
+	 }
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solC/Analytic_solC.c
--- a/SysTest/AnalyticPlugins/Velic_solC/Analytic_solC.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,167 +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:
-*+		Mirko Velic
-*+		Julian Giordani
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Patrick Sunter
-** $Id: solC.c 636 2006-09-08 03:07:06Z JulianGiordani $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include "Analytic_solC.h"
-
-const Type Velic_solC_Type = "Underworld_Velic_solC";
-
-void Velic_solC_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
-	Velic_solC* self = (Velic_solC*) analyticSolution;
-	
-	_Velic_solC( coord, self->sigma, self->eta, self->x_c, NULL, pressure, NULL, NULL );
-}
-
-void Velic_solC_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
-	Velic_solC* self = (Velic_solC*) analyticSolution;
-	
-	_Velic_solC( coord, self->sigma, self->eta, self->x_c, velocity, NULL, NULL, NULL );
-}
-
-void Velic_solC_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
-	Velic_solC* self = (Velic_solC*) analyticSolution;
-	
-	_Velic_solC( coord, self->sigma, self->eta, self->x_c, NULL, NULL, stress, NULL );
-}
-
-
-void Velic_solC_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
-	Velic_solC* self = (Velic_solC*) analyticSolution;
-	
-	_Velic_solC( coord, self->sigma, self->eta, self->x_c, NULL, NULL, NULL, strainRate );
-}
-
-void _Velic_solC_Init( Velic_solC* self, double sigma, double eta, double x_c ) {
-	Bool                     isCorrectInput = True;
-
-	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
-        self->_getAnalyticVelocity    = Velic_solC_VelocityFunction;
-	self->_getAnalyticPressure    = Velic_solC_PressureFunction;
-	self->_getAnalyticTotalStress = Velic_solC_StressFunction;
-	self->_getAnalyticStrainRate  = Velic_solC_StrainRateFunction;
-
-	self->sigma = sigma;
-	self->eta = eta;
-	self->x_c = x_c;
-
-	isCorrectInput = _checkInputParams( self );
-	Journal_Firewall( isCorrectInput , Journal_Register( Error_Type, (Name)"Velic_solB"  ),
-			"Error in function %s: Bad Input parameters, solution check valid values in .tex documentation\n",
-			__func__ );
-}
-
-void _Velic_solC_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
-	Velic_solC* self = (Velic_solC*) analyticSolution;
-	FeVariable*              velocityField;
-	FeVariable*              pressureField;
-	FeVariable*              stressField;
-	FeVariable*              strainRateField;
-	FeVariable*              recoveredStrainRateField;
-	FeVariable*              recoveredStressField;
-	double                   sigma, eta, x_c;
-
-	/* Construct Parent */
-	_AnalyticSolution_AssignFromXML( self, cf, data );
-
-	/* Create Analytic Fields */
-	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solC_VelocityFunction );
-
-	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solC_PressureFunction );
-
-	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False, data );
-	if ( stressField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solC_StressFunction );
-
-	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
-	if ( strainRateField   ) {
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solC_StrainRateFunction );
-	}
-
-	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
-	if ( recoveredStrainRateField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solC_StrainRateFunction );
-
-	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
-	if ( recoveredStressField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solC_StressFunction );
-	
-	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solC_sigma", 1.0  );
-	eta = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solC_eta", 1.0  );
-	x_c = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solC_xc", 0.4  );
-
-	_Velic_solC_Init( self, sigma, eta, x_c );
-}
-
-Bool _checkInputParams( Velic_solC* self ) {
-	return ( 
-			( self->sigma > 0.0 ) && ( self->eta > 0.0 ) &&
-			( self->x_c >= 0.0 ) && (self->x_c <= 1.0 ) 
-		);
-}
-
-void* _Velic_solC_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Velic_solC);
-	Type                                                      type = Velic_solC_Type;
-	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
-	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
-	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solC_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Velic_solC_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _AnalyticSolution_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 Underworld_Velic_solC_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Velic_solC_Type, (Name)"0", _Velic_solC_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solC/Analytic_solC.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solC/Analytic_solC.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,167 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Mirko Velic
+*+		Julian Giordani
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Patrick Sunter
+** $Id: solC.c 636 2006-09-08 03:07:06Z JulianGiordani $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include "Analytic_solC.h"
+
+const Type Velic_solC_Type = "Underworld_Velic_solC";
+
+void Velic_solC_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
+	Velic_solC* self = (Velic_solC*) analyticSolution;
+	
+	_Velic_solC( coord, self->sigma, self->eta, self->x_c, NULL, pressure, NULL, NULL );
+}
+
+void Velic_solC_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
+	Velic_solC* self = (Velic_solC*) analyticSolution;
+	
+	_Velic_solC( coord, self->sigma, self->eta, self->x_c, velocity, NULL, NULL, NULL );
+}
+
+void Velic_solC_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
+	Velic_solC* self = (Velic_solC*) analyticSolution;
+	
+	_Velic_solC( coord, self->sigma, self->eta, self->x_c, NULL, NULL, stress, NULL );
+}
+
+
+void Velic_solC_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
+	Velic_solC* self = (Velic_solC*) analyticSolution;
+	
+	_Velic_solC( coord, self->sigma, self->eta, self->x_c, NULL, NULL, NULL, strainRate );
+}
+
+void _Velic_solC_Init( Velic_solC* self, double sigma, double eta, double x_c ) {
+	Bool                     isCorrectInput = True;
+
+	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
+        self->_getAnalyticVelocity    = Velic_solC_VelocityFunction;
+	self->_getAnalyticPressure    = Velic_solC_PressureFunction;
+	self->_getAnalyticTotalStress = Velic_solC_StressFunction;
+	self->_getAnalyticStrainRate  = Velic_solC_StrainRateFunction;
+
+	self->sigma = sigma;
+	self->eta = eta;
+	self->x_c = x_c;
+
+	isCorrectInput = _checkInputParams( self );
+	Journal_Firewall( isCorrectInput , Journal_Register( Error_Type, (Name)"Velic_solB"  ),
+			"Error in function %s: Bad Input parameters, solution check valid values in .tex documentation\n",
+			__func__ );
+}
+
+void _Velic_solC_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
+	Velic_solC* self = (Velic_solC*) analyticSolution;
+	FeVariable*              velocityField;
+	FeVariable*              pressureField;
+	FeVariable*              stressField;
+	FeVariable*              strainRateField;
+	FeVariable*              recoveredStrainRateField;
+	FeVariable*              recoveredStressField;
+	double                   sigma, eta, x_c;
+
+	/* Construct Parent */
+	_AnalyticSolution_AssignFromXML( self, cf, data );
+
+	/* Create Analytic Fields */
+	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solC_VelocityFunction );
+
+	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solC_PressureFunction );
+
+	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False, data );
+	if ( stressField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solC_StressFunction );
+
+	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
+	if ( strainRateField   ) {
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solC_StrainRateFunction );
+	}
+
+	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
+	if ( recoveredStrainRateField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solC_StrainRateFunction );
+
+	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
+	if ( recoveredStressField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solC_StressFunction );
+	
+	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solC_sigma", 1.0  );
+	eta = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solC_eta", 1.0  );
+	x_c = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solC_xc", 0.4  );
+
+	_Velic_solC_Init( self, sigma, eta, x_c );
+}
+
+Bool _checkInputParams( Velic_solC* self ) {
+	return ( 
+			( self->sigma > 0.0 ) && ( self->eta > 0.0 ) &&
+			( self->x_c >= 0.0 ) && (self->x_c <= 1.0 ) 
+		);
+}
+
+void* _Velic_solC_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Velic_solC);
+	Type                                                      type = Velic_solC_Type;
+	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
+	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
+	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solC_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Velic_solC_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _AnalyticSolution_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 Underworld_Velic_solC_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Velic_solC_Type, (Name)"0", _Velic_solC_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solC/solC.c
--- a/SysTest/AnalyticPlugins/Velic_solC/solC.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,187 +0,0 @@
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-
-#define PI 3.14159265358979323846264338328
-#define FOURIER_TERMS 150
-
-void _Velic_solC( 
-		double pos[], 
-		double sigma, double eta, double x_c,
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] );
-
-
-
-int main( int argc, char **argv )
-{
-	int i,j;
-	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
-	double x,z;
-	
-	for (i=0;i<101;i++){
-		for(j=0;j<101;j++){
-			x = i/100.0;
-			z = j/100.0;
-			
-			pos[0] = x;
-			pos[1] = z;
-			_Velic_solC( pos, 1.0, 1.0, 0.4, vel, &pressure, total_stress, strain_rate );
-			
-			printf("t_xz,e_xz look funny \n");
-			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
-					pos[0],pos[1],
-					vel[0],vel[1], pressure, 
-					total_stress[0], total_stress[1], total_stress[2], 
-					strain_rate[0], strain_rate[1], strain_rate[2] );
-		}
-		printf("\n");
-	}
-	
-	return 0;
-}
-
-
-
-
-void _Velic_solC( 
-		double pos[],									/* coordinates */
-		double _sigma, double _eta, double _x_c,		/* problem dependant inputs: density, viscosity, width of dense column */
-		double vel[], double* presssure, 				/* output: velocity, pressure */
-		double total_stress[], double strain_rate[] ) 	/* ouput: total stresss, strain rate */ 
-{
-	double Z,u1,u2,u3,u4,u5,u6;
-	double _C1,_C2,_C3,_C4;
-	double sum1,sum2,sum3,sum4,sum5,sum6,sum7,mag,x,z;
-	double sigma,del_rho,k,xc;
-	int n;
-	
-	double t1,t2,t3,t4,t5,t6,t7,t8,t10,t11;
-	double t12,t14,t16,t21;
-	
-	
-	/* del_rho = sigma for x < xc and 0 for x > xc */
-	sigma = _sigma;
-	Z = _eta;
-	xc = _x_c;
-	
-	x = pos[0];
-	z = pos[1];
-	
-	sum1=0.0;
-	sum2=0.0;
-	sum3=0.0;
-	sum4=0.0;
-	sum5=0.0;
-	sum6=0.0;
-	sum7=0.0;
-	
-	
-	
-	for(n=1;n<FOURIER_TERMS;n++){
-		
-		k = (double)n*M_PI;
-		del_rho = 2.0*sigma*sin(k*xc)/k;
-		
-		t1 = exp(-k);
-		t7 = k * k;
-		t12 = pow(t1 + 0.1e1, 0.2e1);
-		_C1 = -del_rho * (-0.2e1 + k * t1 - 0.2e1 * t1) / Z / t7 / k / t12 / 0.2e1;
-		
-		t1 = exp(-k);
-		t6 = k * k;
-		t11 = pow(t1 + 0.1e1, 0.2e1);
-		_C2 = del_rho * (k + 0.2e1 + 0.2e1 * t1) / Z / t6 / k / t11 / 0.2e1;
-		
-		t3 = k * k;
-		t5 = exp(-k);
-		_C3 = del_rho / Z / t3 / (t5 + 0.1e1) / 0.2e1;
-		
-		t3 = k * k;
-		t5 = exp(-k);
-		_C4 = -del_rho / Z / t3 / (t5 + 0.1e1) / 0.2e1;
-		
-		/* Vz */
-		t4 = exp(-k * z);
-		t10 = exp(k * (z - 0.1e1));
-		t14 = k * k;
-		u1 = k * ((_C1 + z * _C3) * t4 + (_C2 + z * _C4) * t10 - del_rho / Z / t14 / k);
-		/* Vx */
-		t7 = exp(k * (z - 0.1e1));
-		t14 = exp(-k * z);
-		u2 = (-_C4 - (_C2 + z * _C4) * k) * t7 + (-_C3 + (_C1 + z * _C3) * k) * t14;
-		/* tzz */
-		t1 = Z * k;
-		t8 = exp(k * (z - 0.1e1));
-		t16 = exp(-k * z);
-		u3 = 0.2e1 * t1 * (_C4 + (_C2 + z * _C4) * k) * t8 + 0.2e1 * t1 * (_C3 - (_C1 + z * _C3) * k) * t16;
-		/* txz */
-		t2 = k * k;
-		t11 = exp(k * (z - 0.1e1));
-		t21 = exp(-k * z);
-		u4 = -Z * (0.2e1 * _C4 * k + 0.2e1 * t2 * (_C2 + z * _C4)) * t11 - Z * (-0.2e1 * _C3 * k + 0.2e1 * t2 * (_C1 + z * _C3)) * t21 + 0.1e1 / k * del_rho;
-		/* txx */
-		t1 = Z * k;
-		t8 = exp(k * (z - 0.1e1));
-		t16 = exp(-k * z);
-		u6 = -0.2e1 * t1 * (_C4 + (_C2 + z * _C4) * k) * t8 - 0.2e1 * t1 * (_C3 - (_C1 + z * _C3) * k) * t16;
-		/* pressure */
-		t1 = Z * k;
-		t4 = exp(k * (z - 0.1e1));
-		t8 = exp(-k * z);
-		u5 = 0.2e1 * t1 * _C4 * t4 + 0.2e1 * t1 * _C3 * t8;
-		
-		
-		
-		
-		u5 *= cos(k*x); /* pressure */
-		u6 *= cos(k*x); /* xx stress */    
-		sum5 +=u5;
-		sum6 +=u6;
-
-		u1 *= cos(k*x); /* z velocity */
-		sum1 += u1;
-		u2 *= sin(k*x); /* x velocity */
-		sum2 += u2;
-		u3 *= cos(k*x); /* zz stress */
-		sum3 += u3;
-		u4 *= sin(k*x); /* zx stress */
-		sum4 += u4;
-		    /* density */
-		sum7 += del_rho*cos(k*x);
-
-	}/* n */
-	 /* n=0 term*/
-	sum7 += sigma*xc;
-	 /* pressure 0th term integration constant is arbitrarily chosen so that this term is 0 at z=0.5 */
-	sum5 +=  sigma*xc*(0.5-z); /* now have total pressure */
-	sum3 += -sum5; /* now have total zz stress */
-	sum6 += -sum5; /* now have total xx stress */
-	mag=sqrt(sum1*sum1+sum2*sum2);
-	/*printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7);*/
-
-
-	/* Output */
-	if( vel != NULL ) {
-		vel[0] = sum2;
-		vel[1] = sum1;
-	}
-	if( presssure != NULL ) {
-		(*presssure) = sum5;
-	}
-	if( total_stress != NULL ) {
-		total_stress[0] = sum6;
-		total_stress[1] = sum3;
-		total_stress[2] = sum4;
-	}
-	if( strain_rate != NULL ) {
-		strain_rate[0] = (sum6+sum5)/(2.0*Z);
-		strain_rate[1] = (sum3+sum5)/(2.0*Z);
-		strain_rate[2] = sum4/(2.0*Z);
-	}
-	
-	
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solC/solC.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solC/solC.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,187 @@
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+
+#define PI 3.14159265358979323846264338328
+#define FOURIER_TERMS 150
+
+void _Velic_solC( 
+		double pos[], 
+		double sigma, double eta, double x_c,
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] );
+
+
+
+int main( int argc, char **argv )
+{
+	int i,j;
+	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
+	double x,z;
+	
+	for (i=0;i<101;i++){
+		for(j=0;j<101;j++){
+			x = i/100.0;
+			z = j/100.0;
+			
+			pos[0] = x;
+			pos[1] = z;
+			_Velic_solC( pos, 1.0, 1.0, 0.4, vel, &pressure, total_stress, strain_rate );
+			
+			printf("t_xz,e_xz look funny \n");
+			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
+					pos[0],pos[1],
+					vel[0],vel[1], pressure, 
+					total_stress[0], total_stress[1], total_stress[2], 
+					strain_rate[0], strain_rate[1], strain_rate[2] );
+		}
+		printf("\n");
+	}
+	
+	return 0;
+}
+
+
+
+
+void _Velic_solC( 
+		double pos[],									/* coordinates */
+		double _sigma, double _eta, double _x_c,		/* problem dependant inputs: density, viscosity, width of dense column */
+		double vel[], double* presssure, 				/* output: velocity, pressure */
+		double total_stress[], double strain_rate[] ) 	/* ouput: total stresss, strain rate */ 
+{
+	double Z,u1,u2,u3,u4,u5,u6;
+	double _C1,_C2,_C3,_C4;
+	double sum1,sum2,sum3,sum4,sum5,sum6,sum7,mag,x,z;
+	double sigma,del_rho,k,xc;
+	int n;
+	
+	double t1,t2,t3,t4,t5,t6,t7,t8,t10,t11;
+	double t12,t14,t16,t21;
+	
+	
+	/* del_rho = sigma for x < xc and 0 for x > xc */
+	sigma = _sigma;
+	Z = _eta;
+	xc = _x_c;
+	
+	x = pos[0];
+	z = pos[1];
+	
+	sum1=0.0;
+	sum2=0.0;
+	sum3=0.0;
+	sum4=0.0;
+	sum5=0.0;
+	sum6=0.0;
+	sum7=0.0;
+	
+	
+	
+	for(n=1;n<FOURIER_TERMS;n++){
+		
+		k = (double)n*M_PI;
+		del_rho = 2.0*sigma*sin(k*xc)/k;
+		
+		t1 = exp(-k);
+		t7 = k * k;
+		t12 = pow(t1 + 0.1e1, 0.2e1);
+		_C1 = -del_rho * (-0.2e1 + k * t1 - 0.2e1 * t1) / Z / t7 / k / t12 / 0.2e1;
+		
+		t1 = exp(-k);
+		t6 = k * k;
+		t11 = pow(t1 + 0.1e1, 0.2e1);
+		_C2 = del_rho * (k + 0.2e1 + 0.2e1 * t1) / Z / t6 / k / t11 / 0.2e1;
+		
+		t3 = k * k;
+		t5 = exp(-k);
+		_C3 = del_rho / Z / t3 / (t5 + 0.1e1) / 0.2e1;
+		
+		t3 = k * k;
+		t5 = exp(-k);
+		_C4 = -del_rho / Z / t3 / (t5 + 0.1e1) / 0.2e1;
+		
+		/* Vz */
+		t4 = exp(-k * z);
+		t10 = exp(k * (z - 0.1e1));
+		t14 = k * k;
+		u1 = k * ((_C1 + z * _C3) * t4 + (_C2 + z * _C4) * t10 - del_rho / Z / t14 / k);
+		/* Vx */
+		t7 = exp(k * (z - 0.1e1));
+		t14 = exp(-k * z);
+		u2 = (-_C4 - (_C2 + z * _C4) * k) * t7 + (-_C3 + (_C1 + z * _C3) * k) * t14;
+		/* tzz */
+		t1 = Z * k;
+		t8 = exp(k * (z - 0.1e1));
+		t16 = exp(-k * z);
+		u3 = 0.2e1 * t1 * (_C4 + (_C2 + z * _C4) * k) * t8 + 0.2e1 * t1 * (_C3 - (_C1 + z * _C3) * k) * t16;
+		/* txz */
+		t2 = k * k;
+		t11 = exp(k * (z - 0.1e1));
+		t21 = exp(-k * z);
+		u4 = -Z * (0.2e1 * _C4 * k + 0.2e1 * t2 * (_C2 + z * _C4)) * t11 - Z * (-0.2e1 * _C3 * k + 0.2e1 * t2 * (_C1 + z * _C3)) * t21 + 0.1e1 / k * del_rho;
+		/* txx */
+		t1 = Z * k;
+		t8 = exp(k * (z - 0.1e1));
+		t16 = exp(-k * z);
+		u6 = -0.2e1 * t1 * (_C4 + (_C2 + z * _C4) * k) * t8 - 0.2e1 * t1 * (_C3 - (_C1 + z * _C3) * k) * t16;
+		/* pressure */
+		t1 = Z * k;
+		t4 = exp(k * (z - 0.1e1));
+		t8 = exp(-k * z);
+		u5 = 0.2e1 * t1 * _C4 * t4 + 0.2e1 * t1 * _C3 * t8;
+		
+		
+		
+		
+		u5 *= cos(k*x); /* pressure */
+		u6 *= cos(k*x); /* xx stress */    
+		sum5 +=u5;
+		sum6 +=u6;
+
+		u1 *= cos(k*x); /* z velocity */
+		sum1 += u1;
+		u2 *= sin(k*x); /* x velocity */
+		sum2 += u2;
+		u3 *= cos(k*x); /* zz stress */
+		sum3 += u3;
+		u4 *= sin(k*x); /* zx stress */
+		sum4 += u4;
+		    /* density */
+		sum7 += del_rho*cos(k*x);
+
+	}/* n */
+	 /* n=0 term*/
+	sum7 += sigma*xc;
+	 /* pressure 0th term integration constant is arbitrarily chosen so that this term is 0 at z=0.5 */
+	sum5 +=  sigma*xc*(0.5-z); /* now have total pressure */
+	sum3 += -sum5; /* now have total zz stress */
+	sum6 += -sum5; /* now have total xx stress */
+	mag=sqrt(sum1*sum1+sum2*sum2);
+	/*printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7);*/
+
+
+	/* Output */
+	if( vel != NULL ) {
+		vel[0] = sum2;
+		vel[1] = sum1;
+	}
+	if( presssure != NULL ) {
+		(*presssure) = sum5;
+	}
+	if( total_stress != NULL ) {
+		total_stress[0] = sum6;
+		total_stress[1] = sum3;
+		total_stress[2] = sum4;
+	}
+	if( strain_rate != NULL ) {
+		strain_rate[0] = (sum6+sum5)/(2.0*Z);
+		strain_rate[1] = (sum3+sum5)/(2.0*Z);
+		strain_rate[2] = sum4/(2.0*Z);
+	}
+	
+	
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solCA/Analytic_solCA.c
--- a/SysTest/AnalyticPlugins/Velic_solCA/Analytic_solCA.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,173 +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:
-*+		Mirko Velic
-*+		Julian Giordani
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Patrick Sunter
-** $Id: solCA.c 636 2006-09-08 03:07:06Z JulianGiordani $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include "Analytic_solCA.h"
-
-const Type Velic_solCA_Type = "Underworld_Velic_solCA";
-
-void Velic_solCA_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
-	Velic_solCA* self = (Velic_solCA*) analyticSolution;
-	
-	_Velic_solCA( coord, self->sigma, self->eta, self->dx, self->x0, NULL, pressure, NULL, NULL );
-}
-
-void Velic_solCA_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
-	Velic_solCA* self = (Velic_solCA*) analyticSolution;
-	
-	_Velic_solCA( coord, self->sigma, self->eta, self->dx, self->x0, velocity, NULL, NULL, NULL );
-}
-
-void Velic_solCA_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
-	Velic_solCA* self = (Velic_solCA*) analyticSolution;
-	
-	_Velic_solCA( coord, self->sigma, self->eta, self->dx, self->x0, NULL, NULL, stress, NULL );
-}
-
-
-void Velic_solCA_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
-	Velic_solCA* self = (Velic_solCA*) analyticSolution;
-	
-	_Velic_solCA( coord, self->sigma, self->eta, self->dx, self->x0, NULL, NULL, NULL, strainRate );
-}
-
-void _Velic_solCA_Init( Velic_solCA* self, double sigma, double eta, double dx, double x0 ) {
-	Bool                     isCorrectInput = True;
-	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
-        self->_getAnalyticVelocity    = Velic_solCA_VelocityFunction;
-	self->_getAnalyticPressure    = Velic_solCA_PressureFunction;
-	self->_getAnalyticTotalStress = Velic_solCA_StressFunction;
-	self->_getAnalyticStrainRate  = Velic_solCA_StrainRateFunction;
-
-	self->sigma = sigma;
-	self->eta   = eta;
-	self->dx    = dx;
-	self->x0    = x0;
-
-	isCorrectInput = _checkInputParams( self );
-	Journal_Firewall( isCorrectInput , Journal_Register( Error_Type, (Name)"Velic_solCA"  ),
-			"Error in function %s: Bad Input parameters, solution check valid values in .tex documentation\n",
-			__func__ );
-}
-
-void _Velic_solCA_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
-	Velic_solCA* self = (Velic_solCA*) analyticSolution;
-	FeVariable*              velocityField;
-	FeVariable*              pressureField;
-	FeVariable*              stressField;
-	FeVariable*              strainRateField;
-	FeVariable*              recoveredStrainRateField;
-	FeVariable*              recoveredStressField;
-	double                   sigma, eta, dx, x0, startX, endX;
-
-	/* Construct Parent */
-	_AnalyticSolution_AssignFromXML( self, cf, data );
-
-	/* Create Analytic Fields */
-	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solCA_VelocityFunction );
-
-	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solCA_PressureFunction );
-
-	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False, data );
-	if ( stressField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solCA_StressFunction );
-
-	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
-	if ( strainRateField   ) {
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solCA_StrainRateFunction );
-	}
-
-	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
-	if ( recoveredStrainRateField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solCA_StrainRateFunction );
-
-	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
-	if ( recoveredStressField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solCA_StressFunction );
-
-	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solCA_sigma", 1.0  );
-	eta = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solCA_eta", 1.0  );
-	startX = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solCA_startX", 0.4  );
-	endX   = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solCA_endX", 0.8 );
-
-	dx = endX - startX;
-	x0 = 0.5 * (endX + startX );
-	
-	_Velic_solCA_Init( self, sigma, eta, dx, x0 );
-
-}
-
-Bool _checkInputParams( Velic_solCA* self ) {
-	return ( 
-			( self->sigma > 0.0 ) && ( self->eta > 0.0 ) &&
-			( self->dx >= 0.0 )    && ( self->x0 > 0 ) &&
-			( self->dx < 1.0 )    && ( self->x0 < 1.0 )
-		);
-}
-
-void* _Velic_solCA_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Velic_solCA);
-	Type                                                      type = Velic_solCA_Type;
-	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
-	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
-	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solCA_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Velic_solCA_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _AnalyticSolution_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 Underworld_Velic_solCA_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Velic_solCA_Type, (Name)"0", _Velic_solCA_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solCA/Analytic_solCA.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solCA/Analytic_solCA.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,173 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Mirko Velic
+*+		Julian Giordani
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Patrick Sunter
+** $Id: solCA.c 636 2006-09-08 03:07:06Z JulianGiordani $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include "Analytic_solCA.h"
+
+const Type Velic_solCA_Type = "Underworld_Velic_solCA";
+
+void Velic_solCA_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
+	Velic_solCA* self = (Velic_solCA*) analyticSolution;
+	
+	_Velic_solCA( coord, self->sigma, self->eta, self->dx, self->x0, NULL, pressure, NULL, NULL );
+}
+
+void Velic_solCA_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
+	Velic_solCA* self = (Velic_solCA*) analyticSolution;
+	
+	_Velic_solCA( coord, self->sigma, self->eta, self->dx, self->x0, velocity, NULL, NULL, NULL );
+}
+
+void Velic_solCA_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
+	Velic_solCA* self = (Velic_solCA*) analyticSolution;
+	
+	_Velic_solCA( coord, self->sigma, self->eta, self->dx, self->x0, NULL, NULL, stress, NULL );
+}
+
+
+void Velic_solCA_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
+	Velic_solCA* self = (Velic_solCA*) analyticSolution;
+	
+	_Velic_solCA( coord, self->sigma, self->eta, self->dx, self->x0, NULL, NULL, NULL, strainRate );
+}
+
+void _Velic_solCA_Init( Velic_solCA* self, double sigma, double eta, double dx, double x0 ) {
+	Bool                     isCorrectInput = True;
+	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
+        self->_getAnalyticVelocity    = Velic_solCA_VelocityFunction;
+	self->_getAnalyticPressure    = Velic_solCA_PressureFunction;
+	self->_getAnalyticTotalStress = Velic_solCA_StressFunction;
+	self->_getAnalyticStrainRate  = Velic_solCA_StrainRateFunction;
+
+	self->sigma = sigma;
+	self->eta   = eta;
+	self->dx    = dx;
+	self->x0    = x0;
+
+	isCorrectInput = _checkInputParams( self );
+	Journal_Firewall( isCorrectInput , Journal_Register( Error_Type, (Name)"Velic_solCA"  ),
+			"Error in function %s: Bad Input parameters, solution check valid values in .tex documentation\n",
+			__func__ );
+}
+
+void _Velic_solCA_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
+	Velic_solCA* self = (Velic_solCA*) analyticSolution;
+	FeVariable*              velocityField;
+	FeVariable*              pressureField;
+	FeVariable*              stressField;
+	FeVariable*              strainRateField;
+	FeVariable*              recoveredStrainRateField;
+	FeVariable*              recoveredStressField;
+	double                   sigma, eta, dx, x0, startX, endX;
+
+	/* Construct Parent */
+	_AnalyticSolution_AssignFromXML( self, cf, data );
+
+	/* Create Analytic Fields */
+	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solCA_VelocityFunction );
+
+	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solCA_PressureFunction );
+
+	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False, data );
+	if ( stressField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solCA_StressFunction );
+
+	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
+	if ( strainRateField   ) {
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solCA_StrainRateFunction );
+	}
+
+	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
+	if ( recoveredStrainRateField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solCA_StrainRateFunction );
+
+	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
+	if ( recoveredStressField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solCA_StressFunction );
+
+	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solCA_sigma", 1.0  );
+	eta = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solCA_eta", 1.0  );
+	startX = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solCA_startX", 0.4  );
+	endX   = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solCA_endX", 0.8 );
+
+	dx = endX - startX;
+	x0 = 0.5 * (endX + startX );
+	
+	_Velic_solCA_Init( self, sigma, eta, dx, x0 );
+
+}
+
+Bool _checkInputParams( Velic_solCA* self ) {
+	return ( 
+			( self->sigma > 0.0 ) && ( self->eta > 0.0 ) &&
+			( self->dx >= 0.0 )    && ( self->x0 > 0 ) &&
+			( self->dx < 1.0 )    && ( self->x0 < 1.0 )
+		);
+}
+
+void* _Velic_solCA_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Velic_solCA);
+	Type                                                      type = Velic_solCA_Type;
+	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
+	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
+	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solCA_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Velic_solCA_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _AnalyticSolution_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 Underworld_Velic_solCA_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Velic_solCA_Type, (Name)"0", _Velic_solCA_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solCA/solCA.c
--- a/SysTest/AnalyticPlugins/Velic_solCA/solCA.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,190 +0,0 @@
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-
-#define PI 3.14159265358979323846264338328
-
-
-void _Velic_solCA( 
-		double pos[], 
-		double _sigma, double _eta, double _dx, double _x_0,
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] );
-
-
-/*
-int main( int argc, char **argv )
-{
-	int i,j;
-	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
-	double x,z;
-	
-	for (i=0;i<101;i++){
-		for(j=0;j<101;j++){
-			x = i/100.0;
-			z = j/100.0;
-			
-			pos[0] = x;
-			pos[1] = z;
-			_Velic_solCA( pos, 1.0, 1.0, 0.2, 0.4, 
-					vel, &pressure, total_stress, strain_rate );
-			
-			printf("t_xz, e_xz look funny \n");
-			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
-					pos[0],pos[1],
-					vel[0],vel[1], pressure, 
-					total_stress[0], total_stress[1], total_stress[2], 
-					strain_rate[0], strain_rate[1], strain_rate[2] );
-		}
-		printf("\n");
-	}
-	
-	return 0;
-}
-*/
-
-
-void _Velic_solCA(
-		double pos[], 
-		double _sigma, double _eta, 	/* Input parameters: density, viscosity */
-		double _dx, double _x_0, 		/* Input parameters: width of the dense column, centre of the dense column */
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] )
-{
-	double Z,u1,u2,u3,u4,u5,u6;
-	double _C1,_C2,_C3,_C4;
-	double sum1,sum2,sum3,sum4,sum5,sum6,sum7,mag,x,z;
-	double sigma,del_rho,k,x0,dx;
-	int n;
-	
-	double t1,t2,t3,t4,t5,t6,t7,t8,t10,t11;
-	double t12,t14,t16,t21;
-	
-	
-	/* del_rho = sigma for x-dx/2 < x < xc+dx/2 and 0 else */
-	sigma = _sigma;
-	Z = _eta;
-	x0 = _x_0;
-	dx = _dx;
-	
-	x = pos[0];
-	z = pos[1];
-	
-	sum1=0.0;
-	sum2=0.0;
-	sum3=0.0;
-	sum4=0.0;
-	sum5=0.0;
-	sum6=0.0;
-	sum7=0.0;
-	
-	
-	
-	for(n=1;n<155;n++){
-		
-		k = (double)n*M_PI;
-		del_rho = 4.0*sigma*cos(k*x0)*sin(k*dx/2.0)/k;
-		
-		t1 = exp(-k);
-		t7 = k * k;
-		t12 = pow(t1 + 0.1e1, 0.2e1);
-		_C1 = -del_rho * (-0.2e1 + k * t1 - 0.2e1 * t1) / Z / t7 / k / t12 / 0.2e1;
-		
-		t1 = exp(-k);
-		t6 = k * k;
-		t11 = pow(t1 + 0.1e1, 0.2e1);
-		_C2 = del_rho * (k + 0.2e1 + 0.2e1 * t1) / Z / t6 / k / t11 / 0.2e1;
-		
-		t3 = k * k;
-		t5 = exp(-k);
-		_C3 = del_rho / Z / t3 / (t5 + 0.1e1) / 0.2e1;
-		
-		t3 = k * k;
-		t5 = exp(-k);
-		_C4 = -del_rho / Z / t3 / (t5 + 0.1e1) / 0.2e1;
-		
-		/* Vz */
-		t4 = exp(-k * z);
-		t10 = exp(k * (z - 0.1e1));
-		t14 = k * k;
-		u1 = k * ((_C1 + z * _C3) * t4 + (_C2 + z * _C4) * t10 - del_rho / Z / t14 / k);
-		/* Vx */
-		t7 = exp(k * (z - 0.1e1));
-		t14 = exp(-k * z);
-		u2 = (-_C4 - (_C2 + z * _C4) * k) * t7 + (-_C3 + (_C1 + z * _C3) * k) * t14;
-		/* tzz */
-		t1 = Z * k;
-		t8 = exp(k * (z - 0.1e1));
-		t16 = exp(-k * z);
-		u3 = 0.2e1 * t1 * (_C4 + (_C2 + z * _C4) * k) * t8 + 0.2e1 * t1 * (_C3 - (_C1 + z * _C3) * k) * t16;
-		/* txz */
-		t2 = k * k;
-		t11 = exp(k * (z - 0.1e1));
-		t21 = exp(-k * z);
-		u4 = -Z * (0.2e1 * _C4 * k + 0.2e1 * t2 * (_C2 + z * _C4)) * t11 - Z * (-0.2e1 * _C3 * k + 0.2e1 * t2 * (_C1 + z * _C3)) * t21 + 0.1e1 / k * del_rho;
-		/* txx */
-		t1 = Z * k;
-		t8 = exp(k * (z - 0.1e1));
-		t16 = exp(-k * z);
-		u6 = -0.2e1 * t1 * (_C4 + (_C2 + z * _C4) * k) * t8 - 0.2e1 * t1 * (_C3 - (_C1 + z * _C3) * k) * t16;
-		/* pressure */
-		t1 = Z * k;
-		t4 = exp(k * (z - 0.1e1));
-		t8 = exp(-k * z);
-		u5 = 0.2e1 * t1 * _C4 * t4 + 0.2e1 * t1 * _C3 * t8;
-		
-		
-		
-
-	    u5 = u5*cos(k*x); /* pressure */
-	    u6 = u6*cos(k*x); /* xx stress */	    
-	    sum5 +=u5;
-	    sum6 +=u6;
-
-	    u1 *= cos(k*x); /* z velocity */
-	    sum1 += u1;
-	    u2 *= sin(k*x); /* x velocity */
-	    sum2 += u2;
-	    u3 *= cos(k*x); /* zz stress */
-	    sum3 += u3;
-	    u4 *= sin(k*x); /* zx stress */
-	    sum4 += u4;
-	    /* density */
-	    sum7 += del_rho*cos(k*x);
-
-	 }/* n */
-	 /* n=0 term*/
-	 sum7 += sigma*dx;
-	 /* pressure 0th term integration constant is arbitrarily chosen so that this term is 0 at z=0.5 */
-	 sum5 += sigma*dx*(0.5-z); /* now have total pressure */
-	 sum3 += -sum5; /* now have total zz stress */
-	 sum6 += -sum5; /* now have total xx stress */
-	 mag=sqrt(sum1*sum1+sum2*sum2);
-        /*printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7);*/
-
-		
-	
-	/* Output */
-	if( vel != NULL ) {
-		vel[0] = sum2;
-		vel[1] = sum1;
-	}
-	if( presssure != NULL ) {
-		(*presssure) = sum5;
-	}
-	if( total_stress != NULL ) {
-		total_stress[0] = sum6;
-		total_stress[1] = sum3;
-		total_stress[2] = sum4;
-	}
-	if( strain_rate != NULL ) {
-		strain_rate[0] = (sum6+sum5)/(2.0*Z);
-		strain_rate[1] = (sum3+sum5)/(2.0*Z);
-		strain_rate[2] = (sum4)/(2.0*Z);
-	}
-	
-	
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solCA/solCA.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solCA/solCA.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,190 @@
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+
+#define PI 3.14159265358979323846264338328
+
+
+void _Velic_solCA( 
+		double pos[], 
+		double _sigma, double _eta, double _dx, double _x_0,
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] );
+
+
+/*
+int main( int argc, char **argv )
+{
+	int i,j;
+	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
+	double x,z;
+	
+	for (i=0;i<101;i++){
+		for(j=0;j<101;j++){
+			x = i/100.0;
+			z = j/100.0;
+			
+			pos[0] = x;
+			pos[1] = z;
+			_Velic_solCA( pos, 1.0, 1.0, 0.2, 0.4, 
+					vel, &pressure, total_stress, strain_rate );
+			
+			printf("t_xz, e_xz look funny \n");
+			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
+					pos[0],pos[1],
+					vel[0],vel[1], pressure, 
+					total_stress[0], total_stress[1], total_stress[2], 
+					strain_rate[0], strain_rate[1], strain_rate[2] );
+		}
+		printf("\n");
+	}
+	
+	return 0;
+}
+*/
+
+
+void _Velic_solCA(
+		double pos[], 
+		double _sigma, double _eta, 	/* Input parameters: density, viscosity */
+		double _dx, double _x_0, 		/* Input parameters: width of the dense column, centre of the dense column */
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] )
+{
+	double Z,u1,u2,u3,u4,u5,u6;
+	double _C1,_C2,_C3,_C4;
+	double sum1,sum2,sum3,sum4,sum5,sum6,sum7,mag,x,z;
+	double sigma,del_rho,k,x0,dx;
+	int n;
+	
+	double t1,t2,t3,t4,t5,t6,t7,t8,t10,t11;
+	double t12,t14,t16,t21;
+	
+	
+	/* del_rho = sigma for x-dx/2 < x < xc+dx/2 and 0 else */
+	sigma = _sigma;
+	Z = _eta;
+	x0 = _x_0;
+	dx = _dx;
+	
+	x = pos[0];
+	z = pos[1];
+	
+	sum1=0.0;
+	sum2=0.0;
+	sum3=0.0;
+	sum4=0.0;
+	sum5=0.0;
+	sum6=0.0;
+	sum7=0.0;
+	
+	
+	
+	for(n=1;n<155;n++){
+		
+		k = (double)n*M_PI;
+		del_rho = 4.0*sigma*cos(k*x0)*sin(k*dx/2.0)/k;
+		
+		t1 = exp(-k);
+		t7 = k * k;
+		t12 = pow(t1 + 0.1e1, 0.2e1);
+		_C1 = -del_rho * (-0.2e1 + k * t1 - 0.2e1 * t1) / Z / t7 / k / t12 / 0.2e1;
+		
+		t1 = exp(-k);
+		t6 = k * k;
+		t11 = pow(t1 + 0.1e1, 0.2e1);
+		_C2 = del_rho * (k + 0.2e1 + 0.2e1 * t1) / Z / t6 / k / t11 / 0.2e1;
+		
+		t3 = k * k;
+		t5 = exp(-k);
+		_C3 = del_rho / Z / t3 / (t5 + 0.1e1) / 0.2e1;
+		
+		t3 = k * k;
+		t5 = exp(-k);
+		_C4 = -del_rho / Z / t3 / (t5 + 0.1e1) / 0.2e1;
+		
+		/* Vz */
+		t4 = exp(-k * z);
+		t10 = exp(k * (z - 0.1e1));
+		t14 = k * k;
+		u1 = k * ((_C1 + z * _C3) * t4 + (_C2 + z * _C4) * t10 - del_rho / Z / t14 / k);
+		/* Vx */
+		t7 = exp(k * (z - 0.1e1));
+		t14 = exp(-k * z);
+		u2 = (-_C4 - (_C2 + z * _C4) * k) * t7 + (-_C3 + (_C1 + z * _C3) * k) * t14;
+		/* tzz */
+		t1 = Z * k;
+		t8 = exp(k * (z - 0.1e1));
+		t16 = exp(-k * z);
+		u3 = 0.2e1 * t1 * (_C4 + (_C2 + z * _C4) * k) * t8 + 0.2e1 * t1 * (_C3 - (_C1 + z * _C3) * k) * t16;
+		/* txz */
+		t2 = k * k;
+		t11 = exp(k * (z - 0.1e1));
+		t21 = exp(-k * z);
+		u4 = -Z * (0.2e1 * _C4 * k + 0.2e1 * t2 * (_C2 + z * _C4)) * t11 - Z * (-0.2e1 * _C3 * k + 0.2e1 * t2 * (_C1 + z * _C3)) * t21 + 0.1e1 / k * del_rho;
+		/* txx */
+		t1 = Z * k;
+		t8 = exp(k * (z - 0.1e1));
+		t16 = exp(-k * z);
+		u6 = -0.2e1 * t1 * (_C4 + (_C2 + z * _C4) * k) * t8 - 0.2e1 * t1 * (_C3 - (_C1 + z * _C3) * k) * t16;
+		/* pressure */
+		t1 = Z * k;
+		t4 = exp(k * (z - 0.1e1));
+		t8 = exp(-k * z);
+		u5 = 0.2e1 * t1 * _C4 * t4 + 0.2e1 * t1 * _C3 * t8;
+		
+		
+		
+
+	    u5 = u5*cos(k*x); /* pressure */
+	    u6 = u6*cos(k*x); /* xx stress */	    
+	    sum5 +=u5;
+	    sum6 +=u6;
+
+	    u1 *= cos(k*x); /* z velocity */
+	    sum1 += u1;
+	    u2 *= sin(k*x); /* x velocity */
+	    sum2 += u2;
+	    u3 *= cos(k*x); /* zz stress */
+	    sum3 += u3;
+	    u4 *= sin(k*x); /* zx stress */
+	    sum4 += u4;
+	    /* density */
+	    sum7 += del_rho*cos(k*x);
+
+	 }/* n */
+	 /* n=0 term*/
+	 sum7 += sigma*dx;
+	 /* pressure 0th term integration constant is arbitrarily chosen so that this term is 0 at z=0.5 */
+	 sum5 += sigma*dx*(0.5-z); /* now have total pressure */
+	 sum3 += -sum5; /* now have total zz stress */
+	 sum6 += -sum5; /* now have total xx stress */
+	 mag=sqrt(sum1*sum1+sum2*sum2);
+        /*printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7);*/
+
+		
+	
+	/* Output */
+	if( vel != NULL ) {
+		vel[0] = sum2;
+		vel[1] = sum1;
+	}
+	if( presssure != NULL ) {
+		(*presssure) = sum5;
+	}
+	if( total_stress != NULL ) {
+		total_stress[0] = sum6;
+		total_stress[1] = sum3;
+		total_stress[2] = sum4;
+	}
+	if( strain_rate != NULL ) {
+		strain_rate[0] = (sum6+sum5)/(2.0*Z);
+		strain_rate[1] = (sum3+sum5)/(2.0*Z);
+		strain_rate[2] = (sum4)/(2.0*Z);
+	}
+	
+	
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solCx/Analytic_solCx.c
--- a/SysTest/AnalyticPlugins/Velic_solCx/Analytic_solCx.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,154 +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:
-*+		Mirko Velic
-*+		Julian Giordani
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Patrick Sunter
-** $Id: solCx.c 636 2006-09-08 03:07:06Z JulianGiordani $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-#include<mpi.h>
-#include<stdio.h>
-#include<string.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include<StgFEM/StgFEM.h>
-
-#include "Analytic_solCx.h"
-
-const Type Underworld_solCx_Type = "Underworld_Velic_solCx";
-
-void Velic_solCx_PressureFunction( void* analyticSolution, double* coord, double* pressure ) {
-	Velic_solCx* self = (Velic_solCx*) analyticSolution;
-	
-	_Velic_solCx( coord, self->etaA, self->etaB, self->xc, self->n, NULL, pressure, NULL, NULL );
-}
-
-void Velic_solCx_VelocityFunction( void* analyticSolution, double* coord, double* velocity ) {
-	Velic_solCx* self = (Velic_solCx*) analyticSolution;
-	
-	_Velic_solCx( coord, self->etaA, self->etaB, self->xc, self->n, velocity, NULL, NULL, NULL );
-}
-
-void Velic_solCx_StressFunction( void* analyticSolution, double* coord, double* stress ) {
-	Velic_solCx* self = (Velic_solCx*) analyticSolution;
-	
-	_Velic_solCx( coord, self->etaA, self->etaB, self->xc, self->n, NULL, NULL, stress, NULL );
-}
-
-
-void Velic_solCx_StrainRateFunction( void* analyticSolution, double* coord, double* strainRate ) {
-	Velic_solCx* self = (Velic_solCx*) analyticSolution;
-	
-	_Velic_solCx( coord, self->etaA, self->etaB, self->xc, self->n, NULL, NULL, NULL, strainRate );
-}
-
-void Velic_solCx_ViscosityFunction( void* analyticSolution, double* coord, double* viscosity ) {
-	Velic_solCx* self = (Velic_solCx*) analyticSolution;
-	
-	*viscosity = ( coord[ I_AXIS ] < self->xc ) ? self->etaA : self->etaB;
-}
-
-void _Velic_solCx_Init( Velic_solCx* self, double etaA, double etaB, double xc, int n ) {
-	Bool                     correctInput = True;
-
-	self->etaA = etaA;
-	self->etaB = etaB;
-	self->xc   = xc;
-	self->n    = n;
-
-	if( (self->xc < 0.0) || self->xc > 1.0 ) 
-	      correctInput = False;	
-
-	Journal_Firewall( correctInput,  Journal_Register( Error_Type, (Name)"solCx_ErrorStream" ) ,
-			"Error: In func %s. The input parameters you supplied to the analytic Solution are incorrect.\nValid range of xc values is [0,1]. Currently it is %f\n", __func__, self->xc );
-}
-
-void _Underworld_solCx_Build( void* analyticSolution, void* data ) {
-	Velic_solCx* self = (Velic_solCx*) analyticSolution;
-
-		_FieldTest_Build( self, data );
-
-	/* here we assign the memory and the func ptr for analytic sols */
-	self->_analyticSolutionList = Memory_Alloc_Array_Unnamed( FieldTest_AnalyticSolutionFunc*, 4 );
-	/* this order MUST be consistent with the xml file definition */
-	self->_analyticSolutionList[0] = Velic_solCx_VelocityFunction;
-	self->_analyticSolutionList[1] = Velic_solCx_PressureFunction;
-	self->_analyticSolutionList[2] = Velic_solCx_StrainRateFunction;
-	self->_analyticSolutionList[3] = Velic_solCx_StressFunction;
-}
-
-void _Underworld_solCx_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
-	Velic_solCx* self = (Velic_solCx*) analyticSolution;
-	double etaA, etaB, xc;
-	int n;
-
-	/* Construct Parent */
-	_FieldTest_AssignFromXML( self, cf, data );
-
-	etaA = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solCx_etaA", 1.0  );
-	etaB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solCx_etaB", 2.0  );
-	xc   = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solCx_xc", 0.25  );
-	n    = Stg_ComponentFactory_GetRootDictInt( cf, "solCx_n", 1 );
-
-	_Velic_solCx_Init( self,  etaA,  etaB,  xc, n);
-}
-
-void* _Underworld_solCx_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Velic_solCx);
-	Type                                                      type = Underworld_solCx_Type;
-	Stg_Class_DeleteFunction*                              _delete = _FieldTest_Delete;
-	Stg_Class_PrintFunction*                                _print = _FieldTest_Print;
-	Stg_Class_CopyFunction*                                  _copy = _FieldTest_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_solCx_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Underworld_solCx_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _Underworld_solCx_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 Underworld_Velic_solCx_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Underworld_solCx_Type, (Name)"0", _Underworld_solCx_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solCx/Analytic_solCx.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solCx/Analytic_solCx.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,154 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Mirko Velic
+*+		Julian Giordani
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Patrick Sunter
+** $Id: solCx.c 636 2006-09-08 03:07:06Z JulianGiordani $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+#include<mpi.h>
+#include<stdio.h>
+#include<string.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include<StgFEM/StgFEM.h>
+
+#include "Analytic_solCx.h"
+
+const Type Underworld_solCx_Type = "Underworld_Velic_solCx";
+
+void Velic_solCx_PressureFunction( void* analyticSolution, double* coord, double* pressure ) {
+	Velic_solCx* self = (Velic_solCx*) analyticSolution;
+	
+	_Velic_solCx( coord, self->etaA, self->etaB, self->xc, self->n, NULL, pressure, NULL, NULL );
+}
+
+void Velic_solCx_VelocityFunction( void* analyticSolution, double* coord, double* velocity ) {
+	Velic_solCx* self = (Velic_solCx*) analyticSolution;
+	
+	_Velic_solCx( coord, self->etaA, self->etaB, self->xc, self->n, velocity, NULL, NULL, NULL );
+}
+
+void Velic_solCx_StressFunction( void* analyticSolution, double* coord, double* stress ) {
+	Velic_solCx* self = (Velic_solCx*) analyticSolution;
+	
+	_Velic_solCx( coord, self->etaA, self->etaB, self->xc, self->n, NULL, NULL, stress, NULL );
+}
+
+
+void Velic_solCx_StrainRateFunction( void* analyticSolution, double* coord, double* strainRate ) {
+	Velic_solCx* self = (Velic_solCx*) analyticSolution;
+	
+	_Velic_solCx( coord, self->etaA, self->etaB, self->xc, self->n, NULL, NULL, NULL, strainRate );
+}
+
+void Velic_solCx_ViscosityFunction( void* analyticSolution, double* coord, double* viscosity ) {
+	Velic_solCx* self = (Velic_solCx*) analyticSolution;
+	
+	*viscosity = ( coord[ I_AXIS ] < self->xc ) ? self->etaA : self->etaB;
+}
+
+void _Velic_solCx_Init( Velic_solCx* self, double etaA, double etaB, double xc, int n ) {
+	Bool                     correctInput = True;
+
+	self->etaA = etaA;
+	self->etaB = etaB;
+	self->xc   = xc;
+	self->n    = n;
+
+	if( (self->xc < 0.0) || self->xc > 1.0 ) 
+	      correctInput = False;	
+
+	Journal_Firewall( correctInput,  Journal_Register( Error_Type, (Name)"solCx_ErrorStream" ) ,
+			"Error: In func %s. The input parameters you supplied to the analytic Solution are incorrect.\nValid range of xc values is [0,1]. Currently it is %f\n", __func__, self->xc );
+}
+
+void _Underworld_solCx_Build( void* analyticSolution, void* data ) {
+	Velic_solCx* self = (Velic_solCx*) analyticSolution;
+
+		_FieldTest_Build( self, data );
+
+	/* here we assign the memory and the func ptr for analytic sols */
+	self->_analyticSolutionList = Memory_Alloc_Array_Unnamed( FieldTest_AnalyticSolutionFunc*, 4 );
+	/* this order MUST be consistent with the xml file definition */
+	self->_analyticSolutionList[0] = Velic_solCx_VelocityFunction;
+	self->_analyticSolutionList[1] = Velic_solCx_PressureFunction;
+	self->_analyticSolutionList[2] = Velic_solCx_StrainRateFunction;
+	self->_analyticSolutionList[3] = Velic_solCx_StressFunction;
+}
+
+void _Underworld_solCx_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
+	Velic_solCx* self = (Velic_solCx*) analyticSolution;
+	double etaA, etaB, xc;
+	int n;
+
+	/* Construct Parent */
+	_FieldTest_AssignFromXML( self, cf, data );
+
+	etaA = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solCx_etaA", 1.0  );
+	etaB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solCx_etaB", 2.0  );
+	xc   = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solCx_xc", 0.25  );
+	n    = Stg_ComponentFactory_GetRootDictInt( cf, "solCx_n", 1 );
+
+	_Velic_solCx_Init( self,  etaA,  etaB,  xc, n);
+}
+
+void* _Underworld_solCx_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Velic_solCx);
+	Type                                                      type = Underworld_solCx_Type;
+	Stg_Class_DeleteFunction*                              _delete = _FieldTest_Delete;
+	Stg_Class_PrintFunction*                                _print = _FieldTest_Print;
+	Stg_Class_CopyFunction*                                  _copy = _FieldTest_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_solCx_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Underworld_solCx_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _Underworld_solCx_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 Underworld_Velic_solCx_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Underworld_solCx_Type, (Name)"0", _Underworld_solCx_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solCx/solCx.c
--- a/SysTest/AnalyticPlugins/Velic_solCx/solCx.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2333 +0,0 @@
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-
-#define PI 3.14159265358979323846264338328
-
-
-void _Velic_solCx( 
-		double pos[], 
-		double _eta_A, double _eta_B, 
-		double _x_c, int _n,
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] );
-
-/*
-int main( int argc, char **argv )
-{
-	int i,j;
-	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
-	double x,z;
-	
-	for (i=0;i<101;i++){
-		for(j=0;j<101;j++){
-			x = i/100.0;
-			z = j/100.0;
-			
-			pos[0] = x;
-			pos[1] = z;
-			solCx( 
-					pos, 
-					1.0, 1.0,
-					0.5, 1,
-					vel, &pressure, total_stress, strain_rate );
-			
-			printf("t_xx, t_xz fucked !! \n");
-			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
-					pos[0],pos[1],
-					vel[0],vel[1], pressure, 
-					total_stress[0], total_stress[1], total_stress[2], 
-					strain_rate[0], strain_rate[1], strain_rate[2] );
-		}
-		printf("\n");
-	}
-	
-	return 0;
-}
-*/
-
-void _Velic_solCx(
-		double pos[], 
-		double _eta_A, double _eta_B, 	/* Input parameters: density, viscosity A, viscosity B */
-		double _x_c, int _n, 			/* Input parameters: viscosity jump location, wavenumber in x */
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] )
-{
-	double Z,u1,u2,u3,u4,u5,u6,ZA,ZB;
-	double sum1,sum2,sum3,sum4,sum5,sum6,mag,x,z,xc;
-	double _C1A,_C2A,_C3A,_C4A,_C1B,_C2B,_C3B,_C4B,_C1,_C2,_C3,_C4;
-	int n,nx;
-	
-	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,t43,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,t80;
-	double t81,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,t115,t116,t117,t118,t119,t120;
-	double t121,t122,t123,t124,t125,t126,t127,t128,t129,t130,t131,t132,t133,t134,t135,t136,t137,t138,t139,t140,t141,t142,t143,t144,t145,t146,t147,t148,t149,t150,t151,t152,t153,t154,t155,t156,t157,t158,t159,t160;
-	double t161,t162,t163,t164,t165,t166,t167,t168,t169,t170,t171,t172,t173,t174,t175,t176,t177,t178,t179,t180,t181,t182,t183,t184,t186,t187,t188,t189,t190,t191,t192,t193,t194,t195,t196,t197,t198,t199;
-	double t201,t202,t203,t204,t206,t207,t208,t209,t210,t211,t212,t213,t215,t216,t217,t218,t219,t220,t221,t222,t223,t224,t225,t226,t227,t228,t229,t230,t231,t232,t233,t234,t235,t236,t237,t238,t239,t240;
-	double t241,t242,t243,t244,t245,t246,t247,t248,t249,t250,t251,t252,t253,t254,t255,t256,t257,t258,t259,t260,t261,t262,t263,t264,t265,t267,t268,t269,t270,t272,t273,t274,t275,t276,t277,t278,t279,t280;
-	double t281,t282,t283,t284,t285,t286,t288,t289,t290,t291,t292,t295,t296,t297,t298,t299,t300,t301,t303,t304,t305,t307,t308,t310,t311,t312,t313,t314,t315,t316,t317,t318,t319,t320;
-	double t321,t322,t323,t324,t325,t326,t327,t328,t329,t330,t331,t332,t334,t335,t336,t337,t338,t339,t340,t341,t342,t344,t345,t346,t347,t348,t349,t350,t351,t352,t353,t354,t355,t356,t358,t359,t360;
-	double t361,t362,t363,t364,t365,t366,t367,t368,t369,t370,t371,t372,t373,t374,t375,t376,t377,t378,t379,t380,t381,t382,t383,t384,t385,t386,t387,t389,t390,t391,t393,t394,t395,t396,t397,t398;
-	double t401,t402,t403,t404,t405,t406,t407,t408,t409,t410,t411,t412,t413,t414,t415,t416,t417,t418,t419,t421,t422,t423,t424,t425,t426,t427,t428,t429,t430,t431,t432,t433,t434,t436,t437,t438,t439,t440;
-	double t441,t442,t443,t444,t445,t446,t447,t448,t450,t451,t453,t454,t455,t456,t457,t458,t459,t461,t462,t463,t464,t465,t466,t468,t469,t470,t471,t474,t475,t478,t480;
-	double t482,t483,t484,t485,t488,t489,t490,t492,t493,t495,t497,t498,t499,t501,t502,t503,t504,t505,t507,t508,t509,t510,t511,t512,t513,t515,t518,t520;
-	double t522,t525,t527,t528,t529,t530,t532,t533,t534,t535,t536,t538,t539,t541,t542,t544,t545,t546,t547,t548,t549,t550,t551,t552,t553,t554,t555,t556,t557,t560;
-	double t561,t562,t563,t564,t567,t568,t571,t573,t575,t576,t578,t579,t583,t590,t591,t594,t595,t596,t597,t598,t600;
-	double t601,t602,t604,t606,t607,t608,t611,t613,t615,t616,t617,t619,t621,t623,t624,t625,t626,t627,t629,t630,t632,t633,t634,t638,t639,t640;
-	double t641,t642,t643,t644,t645,t647,t648,t649,t650,t651,t652,t653,t654,t655,t656,t657,t658,t659,t660,t662,t663,t665,t666,t667,t668,t670,t671,t672,t673,t674,t675,t676,t679,t680;
-	double t682,t683,t684,t685,t686,t688,t689,t690,t691,t693,t694,t695,t696,t697,t698,t699,t700,t701,t702,t704,t705,t708,t709,t711,t712,t713,t714,t717,t718,t719;
-	double t721,t722,t723,t726,t727,t728,t730,t733,t734,t735,t736,t737,t738,t739,t740,t741,t744,t745,t746,t749,t750,t752,t753,t754,t755,t757,t758,t759,t760;
-	double t761,t762,t763,t764,t766,t767,t768,t770,t771,t772,t773,t774,t775,t776,t777,t778,t780,t781,t782,t785,t786,t789,t790,t791,t792,t793,t794,t795,t796,t797,t798,t800;
-	double t801,t806,t807,t808,t809,t811,t812,t817,t818,t819,t821,t822,t824,t827,t828,t830,t834,t835,t837,t840;
-	double t842,t843,t844,t845,t846,t849,t850,t853,t854,t855,t857,t858,t859,t860,t863,t864,t867,t868,t869,t873,t874,t877,t878,t879,t880;
-	double t884,t888,t891,t894,t900,t901,t903,t904,t907,t908,t909,t911,t914,t915,t916,t919,t920;
-	double t923,t924,t925,t926,t927,t929,t932,t935,t937,t939,t942,t943,t944,t945,t947,t948,t949,t950,t952,t953,t954,t955,t956,t957;
-	double t961,t964,t965,t966,t967,t968,t969,t971,t972,t974,t977,t978,t981,t983,t987,t988,t992,t993,t994,t997,t998;
-	double t1001,t1003,t1005,t1006,t1009,t1010,t1012,t1013,t1015,t1016,t1017,t1018,t1020,t1021,t1029,t1031,t1032,t1033,t1040;
-	double t1041,t1042,t1044,t1047,t1050,t1054,t1055,t1057,t1058,t1063,t1068,t1069,t1070,t1079,t1080;
-	double t1088,t1089,t1091,t1092,t1094,t1096,t1101,t1102,t1103,t1104,t1105,t1108,t1112,t1113,t1118,t1119,t1120;
-	double t1121,t1122,t1123,t1124,t1125,t1126,t1127,t1128,t1129,t1130,t1132,t1133,t1134,t1135,t1138,t1139,t1140,t1141,t1142,t1145,t1146,t1148,t1149,t1150,t1153,t1154,t1156,t1157,t1158,t1159;
-	double t1161,t1162,t1165,t1166,t1170,t1171,t1172,t1173,t1175,t1176,t1178,t1180,t1181,t1182,t1185,t1189,t1192,t1193,t1195,t1196,t1199;
-	double t1201,t1203,t1209,t1210,t1211,t1213,t1214,t1218,t1221,t1224,t1225,t1226,t1228,t1233,t1234,t1235,t1236,t1237,t1240;
-	double t1241,t1242,t1243,t1244,t1245,t1248,t1251,t1252,t1257,t1258,t1259,t1260,t1263,t1268,t1269,t1272,t1280;
-	double t1282,t1283,t1284,t1285,t1287,t1288,t1289,t1292,t1293,t1296,t1297,t1300,t1304,t1307,t1310,t1311,t1312,t1316,t1317,t1320;
-	double t1321,t1323,t1328,t1330,t1331,t1332,t1333,t1336,t1338,t1343,t1344,t1346,t1349,t1350,t1354;
-	double t1366,t1369,t1370,t1371,t1376,t1378,t1380,t1383,t1386,t1387,t1388,t1391,t1393,t1399;
-	double t1411,t1412,t1420,t1427;
-	double t1450,t1456,t1468,t1472,t1474,t1478;
-	double t1504,t1511;
-	double t1545;
-	double t1564,t1583;
-	
-	
-	/* del_rho = sin(n*Pi*z)*cos(nx*Pi*x)  n=nx gives only non-zero terms*/
-	n = _n; /* only one n in Fourier series because  del_rho has cos term */
-	nx = 1; /* can set these two to whatever we like */
-	
-	ZA=_eta_A; /* left column viscosity */
-	ZB=_eta_B; /* right column viscosity */
-	xc = _x_c;
-	
-	x = pos[0];
-	z = pos[1];
-	
-	sum1=0.0;
-	sum2=0.0;
-	sum3=0.0;
-	sum4=0.0;
-	sum5=0.0;
-	sum6=0.0;
-	
-	// Note that there is no Fourier sum here.
-	/****************************************************************************************/
-	_C1A = 0;
-	/****************************************************************************************/
-	t1 = nx * 0.3141592654e1;
-	t2 = sin(t1);
-	t3 = nx * t2;
-	t4 = n * n;
-	t5 = t4 * t4;
-	t6 = 0.3141592654e1 * 0.3141592654e1;
-	t8 = t3 * t5 * t6;
-	t9 = ZA * xc;
-	t12 = exp(xc * n * 0.3141592654e1);
-	t13 = t12 * t12;
-	t15 = n * 0.3141592654e1;
-	t16 = exp(t15);
-	t17 = t16 * t16;
-	t18 = t17 * t16;
-	t19 = ZB * t13 * t18;
-	t20 = t9 * t19;
-	t23 = ZA * ZA;
-	t24 = nx * nx;
-	t25 = t24 * nx;
-	t26 = t23 * t25;
-	t28 = t13 * t13;
-	t29 = t28 * t13;
-	t33 = nx * ZB;
-	t34 = t1 * xc;
-	t35 = sin(t34);
-	t36 = t4 * n;
-	t37 = t35 * t36;
-	t38 = t33 * t37;
-	t39 = 0.3141592654e1 * ZA;
-	t40 = t13 * t12;
-	t41 = t17 * t40;
-	t45 = ZB * ZB;
-	t46 = t45 * t24;
-	t47 = t46 * t4;
-	t48 = 0.3141592654e1 * xc;
-	t49 = t13 * t17;
-	t53 = xc * xc;
-	t54 = t36 * t53;
-	t56 = t54 * t6 * t45;
-	t57 = cos(t34);
-	t58 = t57 * t24;
-	t59 = t28 * t12;
-	t60 = t17 * t59;
-	t61 = t58 * t60;
-	t64 = t25 * t2;
-	t65 = t64 * t15;
-	t72 = nx * t23;
-	t74 = t72 * t2 * t5;
-	t75 = t6 * t53;
-	t76 = t16 * t29;
-	t80 = t23 * n;
-	t81 = t80 * 0.3141592654e1;
-	t82 = t18 * t28;
-	t86 = nx * t5;
-	t87 = t23 * t6;
-	t89 = xc * t2;
-	t90 = t13 * t18;
-	t91 = t89 * t90;
-	t94 = t28 * t28;
-	t96 = t24 * n;
-	t98 = t4 * t45;
-	t99 = t98 * 0.3141592654e1;
-	t100 = t58 * t41;
-	t104 = 0.3141592654e1 * t25;
-	t105 = ZA * n * t104;
-	t106 = t2 * ZB;
-	t110 = t17 * t17;
-	t111 = ZA * t110;
-	t116 = n * t28;
-	t122 = t64 * t4 * t6;
-	t126 = t23 * t29 * t4;
-	t128 = t24 * xc;
-	t132 = t36 * t23;
-	t133 = t6 * t57;
-	t135 = t128 * t41;
-	t138 = t6 * xc;
-	t142 = t72 * t2;
-	t147 = 0.4e1 * t8 * t20 - 0.2e1 * t26 * t2 * t16 * t29 - 0.8e1 * t38 * t39 * t41 + 0.4e1 * t47 * t48 * t49 - 0.8e1 * t56 * t61 - 0.4e1 * t65 * t20 + 0.2e1 * t26 * t2 * t18 * t28 - 0.4e1 * t74 * t75 * t76 - 0.2e1 * t81 * t64 * t82 - 0.4e1 * t86 * t87 * t91 - t23 * t94 * t96 + 0.8e1 * t99 * t100 - 0.2e1 * t105 * t106 * t82 - 0.4e1 * t38 * t48 * t111 * t12 + 0.2e1 * t116 * ZB * t111 * t24 + 0.4e1 * t122 * t20 + 0.4e1 * t126 * 0.3141592654e1 * t17 * t128 + 0.8e1 * t132 * t133 * t135 + 0.4e1 * t74 * t138 * t76 - 0.2e1 * t142 * t4 * t18 * t28;
-	t149 = ZA * t25 * t2;
-	t150 = ZB * t28;
-	t154 = t35 * t5;
-	t155 = t72 * t154;
-	t156 = t75 * t41;
-	t159 = nx * ZA;
-	t160 = t2 * t36;
-	t161 = t159 * t160;
-	t162 = 0.3141592654e1 * ZB;
-	t163 = t28 * t16;
-	t167 = t23 * t57;
-	t168 = t167 * t24;
-	t169 = n * t110;
-	t170 = t169 * t40;
-	t173 = ZA * ZB;
-	t174 = t173 * t90;
-	t177 = t36 * 0.3141592654e1;
-	t181 = t80 * t104;
-	t184 = n * t17;
-	t188 = t17 * t29;
-	t190 = t4 * 0.3141592654e1;
-	t191 = t190 * t24;
-	t206 = t138 * t60;
-	t209 = t23 * t4;
-	t211 = t209 * t6 * t25;
-	t212 = t89 * t76;
-	t216 = ZB * t16 * t29;
-	t217 = t9 * t216;
-	t220 = ZB * t110;
-	t221 = ZA * t24;
-	t222 = t221 * n;
-	t225 = t132 * t75;
-	t232 = t45 * t28;
-	t233 = t110 * t24;
-	t234 = t233 * n;
-	t236 = t209 * 0.3141592654e1;
-	t237 = t17 * xc;
-	t239 = t237 * t13 * t24;
-	t242 = -0.2e1 * t149 * t150 * t16 - 0.8e1 * t155 * t156 - 0.2e1 * t161 * t162 * t163 + 0.2e1 * t168 * t170 + 0.2e1 * t65 * t174 - 0.2e1 * t142 * t177 * t76 + 0.4e1 * t181 * t91 - 0.4e1 * t168 * t184 * t59 - 0.4e1 * t188 * t23 * t191 + 0.4e1 * t38 * t48 * ZA * t17 * t40 + 0.4e1 * t49 * t23 * t191 + 0.2e1 * t26 * t2 * t13 * t18 - 0.8e1 * t155 * t206 + 0.4e1 * t211 * t212 - 0.4e1 * t8 * t217 + 0.2e1 * t220 * t222 - 0.8e1 * t225 * t100 + 0.2e1 * t142 * t4 * t16 * t29 + t232 * t234 - 0.4e1 * t236 * t239;
-	t244 = nx * t45;
-	t245 = t244 * t37;
-	t246 = t110 * t40;
-	t251 = t237 * t59;
-	t256 = t64 * t90;
-	t260 = t36 * t45 * t133;
-	t263 = t45 * t57;
-	t264 = t263 * t24;
-	t265 = t169 * t12;
-	t269 = t6 * t36;
-	t270 = t17 * t24;
-	t274 = t110 * t13;
-	t276 = t190 * t128;
-	t279 = nx * t36;
-	t281 = t28 * t40;
-	t282 = t281 * t35;
-	t286 = t138 * t41;
-	t289 = t75 * t60;
-	t296 = t190 * t173;
-	t305 = t86 * t45 * t35;
-	t312 = t33 * t154;
-	t313 = t6 * ZA;
-	t324 = t232 * t270;
-	t327 = -0.2e1 * t245 * t48 * t246 + 0.4e1 * t159 * t37 * t162 * t251 + 0.4e1 * t209 * t75 * t256 + 0.8e1 * t260 * t135 + 0.2e1 * t264 * t265 + 0.32e2 * t9 * t150 * t269 * t270 + 0.4e1 * t274 * t23 * t276 + 0.2e1 * t279 * t45 * t282 * t48 + 0.8e1 * t155 * t286 + 0.8e1 * t155 * t289 - 0.8e1 * t150 * ZA * t96 * t17 + 0.8e1 * t296 * t61 - 0.2e1 * t105 * t106 * t163 - 0.2e1 * t81 * t256 - 0.8e1 * t305 * t156 - 0.4e1 * t33 * t282 * t177 * t9 - 0.16e2 * t312 * t313 * t237 * t40 - 0.4e1 * t168 * t184 * t40 + 0.2e1 * t168 * t265 + 0.16e2 * t269 * t53 * t324;
-	t328 = t3 * t4;
-	t331 = t72 * t37;
-	t332 = t48 * t60;
-	t335 = n * t94;
-	t345 = t72 * t35;
-	t349 = t173 * t57;
-	t355 = t53 * t17;
-	t364 = t54 * t6 * ZB;
-	t365 = t28 * t17;
-	t369 = xc * ZB;
-	t370 = t269 * t369;
-	t371 = ZA * t57;
-	t373 = t371 * t270 * t40;
-	t385 = nx * t35;
-	t396 = t4 * xc;
-	t397 = t396 * t162;
-	t415 = t37 * t48;
-	t418 = -0.32e2 * t364 * t365 * t221 - 0.16e2 * t370 * t373 - 0.4e1 * t331 * t48 * t41 + 0.4e1 * t86 * t23 * t53 * t6 * t2 * t90 + 0.2e1 * t385 * t177 * t23 * xc * t246 + 0.16e2 * t132 * t53 * t6 * t28 * t270 - 0.4e1 * t397 * t371 * t233 * t12 - 0.12e2 * t173 * t58 * t190 * t251 + 0.2e1 * t385 * t36 * 0.3141592654e1 * t23 * xc * t59 - 0.8e1 * t99 * t61 - 0.2e1 * t244 * t59 * t415;
-	t427 = t371 * t270 * t59;
-	t439 = t209 * t48;
-	t440 = t110 * t12;
-	t441 = t58 * t440;
-	t447 = t36 * xc;
-	t455 = t48 * t440;
-	t471 = ZB * t17;
-	t492 = 0.12e2 * t397 * t373 - 0.4e1 * t122 * t217 + 0.16e2 * t364 * t427 + 0.16e2 * t312 * t313 * t355 * t40 - 0.8e1 * t279 * t39 * t35 * ZB * t60 + 0.2e1 * t439 * t441 - 0.2e1 * t81 * t64 * t163 + 0.8e1 * t447 * t87 * t61 + 0.2e1 * t23 * t59 * t57 * t276 + 0.2e1 * t245 * t455 - 0.4e1 * t349 * t96 * t440 - 0.16e2 * t370 * t427 + 0.4e1 * t181 * t212 - 0.16e2 * t365 * t23 * t269 * t128 + 0.16e2 * t86 * t138 * ZA * t35 * t471 * t59 + 0.8e1 * t305 * t289 - 0.4e1 * t439 * t100 + 0.2e1 * ZB * t25 * t2 * ZA * t18 * t28 + 0.2e1 * t142 * t4 * t28 * t16 - 0.8e1 * t56 * t100;
-	t499 = ZA * t53 * t19;
-	t505 = t396 * 0.3141592654e1;
-	t518 = t173 * t53 * t16 * t29;
-	t533 = t23 * t28;
-	t535 = t188 * t45;
-	t538 = t24 * t4;
-	t545 = t3 * t177;
-	t546 = t173 * t76;
-	t555 = t45 * t110;
-	t557 = t72 * t160;
-	t561 = -0.8e1 * t225 * t61 - 0.2e1 * t161 * t162 * t82 + t533 * t234 + 0.4e1 * t535 * t191 + 0.4e1 * t167 * t538 * t332 + 0.4e1 * t349 * t96 * t60 + 0.2e1 * t545 * t546 - 0.2e1 * t264 * t170 + 0.4e1 * t397 * t281 * ZA * t58 - t555 * t96 - 0.4e1 * t557 * t48 * t76;
-	t567 = t396 * 0.3141592654e1 * t45;
-	t568 = t58 * t246;
-	t597 = t58 * n;
-	t615 = t13 * t45;
-	t616 = t615 * t233;
-	t619 = t94 * t45;
-	t621 = t45 * t59;
-	t625 = 0.2e1 * t149 * t216 + 0.2e1 * t567 * t568 - 0.16e2 * t269 * xc * t324 - 0.2e1 * t236 * xc * t281 * t58 - 0.2e1 * t142 * t177 * t90 - 0.8e1 * t567 * t100 + 0.2e1 * t65 * t546 - 0.8e1 * t305 * t206 + 0.2e1 * n * t45 * t281 * t57 * t24 - t23 * t110 * t96 - 0.8e1 * t296 * t100 + 0.2e1 * t23 * t281 * t597 + 0.4e1 * t545 * t20 + 0.2e1 * t159 * t2 * t4 * ZB * t163 - 0.4e1 * t557 * t48 * t90 + 0.4e1 * t122 * t518 + 0.8e1 * t263 * t538 * t332 - 0.4e1 * t505 * t616 - t619 * t96 - 0.2e1 * t621 * t57 * t276;
-	t626 = t49 * t45;
-	t660 = t29 * t45;
-	t685 = 0.2e1 * t545 * t174 - 0.4e1 * t126 * 0.3141592654e1 * t24 * xc - 0.4e1 * t47 * t48 * t188 + 0.4e1 * t505 * t660 * t24 - 0.2e1 * t142 * t177 * t163 - 0.2e1 * t142 * t4 * t13 * t18 + 0.8e1 * t260 * t128 * t60 - 0.2e1 * t328 * t546 - 0.2e1 * t26 * t2 * t28 * t16 + 0.4e1 * t545 * t217 - 0.4e1 * t209 * t138 * t256;
-	t690 = t6 * 0.3141592654e1;
-	t691 = ZA * t690;
-	t693 = t24 * t24;
-	t694 = t693 * xc;
-	t695 = t188 * t694;
-	t698 = t23 * ZA;
-	t699 = t698 * t690;
-	t700 = t699 * t5;
-	t704 = t5 * t4;
-	t705 = t691 * t704;
-	t709 = t691 * t5;
-	t713 = t5 * n;
-	t714 = t713 * ZB;
-	t718 = t698 * t6;
-	t719 = t713 * t28;
-	t722 = t699 * t704;
-	t726 = t713 * t94;
-	t733 = t713 * t45;
-	t736 = t87 * t36;
-	t740 = -0.4e1 * t691 * t98 * t695 + 0.8e1 * t700 * t270 * t13 + 0.4e1 * t705 * t660 * xc + 0.8e1 * t709 * t660 * t128 + 0.2e1 * t87 * t714 * t110 + t718 * t719 * t110 - 0.4e1 * t722 * t237 * t13 - t313 * t726 * t45 - 0.4e1 * t699 * t704 * xc * t29 + t313 * t733 * t28 + 0.4e1 * t736 * t150 * t233;
-	t746 = t313 * t36;
-	t752 = t6 * t6;
-	t753 = t23 * t752;
-	t759 = t698 * t752;
-	t760 = t759 * t36;
-	t761 = t17 * t693;
-	t762 = xc * t28;
-	t763 = t761 * t762;
-	t766 = t87 * t713;
-	t773 = t699 * t4;
-	t774 = t110 * t693;
-	t775 = xc * t13;
-	t785 = t704 * t17;
-	t789 = -0.16e2 * t736 * t150 * t270 + t718 * t116 * t693 - 0.2e1 * t746 * t555 * t24 + 0.4e1 * t705 * t535 + 0.64e2 * t753 * t713 * t17 * t150 * t128 - 0.16e2 * t760 * t763 + 0.2e1 * t766 * t150 * t110 + 0.4e1 * t722 * t274 * xc + 0.4e1 * t773 * t774 * t775 - 0.8e1 * t766 * t150 * t17 + 0.8e1 * t700 * t233 * t775 + 0.4e1 * t699 * t785 * t13;
-	t791 = t691 * t4;
-	t792 = t45 * t693;
-	t793 = t49 * t792;
-	t796 = t759 * t713;
-	t797 = t53 * t28;
-	t798 = t270 * t797;
-	t801 = t87 * n;
-	t818 = t5 * t36;
-	t819 = t753 * t818;
-	t827 = t753 * t36 * ZB;
-	t830 = xc * t45;
-	t834 = -0.4e1 * t791 * t793 + 0.32e2 * t796 * t798 + 0.2e1 * t801 * ZB * t693 * t110 + 0.2e1 * t718 * t36 * t28 * t24 - 0.8e1 * t700 * t128 * t29 - 0.8e1 * t700 * t239 - 0.8e1 * t801 * t150 * t761 + 0.32e2 * t819 * t365 * t369 - 0.64e2 * t753 * t714 * t798 + 0.32e2 * t827 * t763 + 0.4e1 * t705 * t830 * t49;
-	t842 = xc * t29;
-	t843 = t270 * t842;
-	t849 = t759 * t818;
-	t853 = t691 * t396;
-	t857 = t691 * t5 * t45;
-	t869 = t313 * n;
-	t874 = -0.2e1 * t718 * t36 * t94 * t24 - 0.4e1 * t773 * t761 * t29 + 0.8e1 * t700 * t843 + 0.2e1 * t87 * t726 * ZB + 0.16e2 * t849 * t797 * t17 + 0.4e1 * t853 * t793 + 0.8e1 * t857 * t239 + 0.2e1 * t801 * t150 * t693 - 0.8e1 * t700 * t270 * t29 - 0.8e1 * t709 * t49 * t46 - t869 * t619 * t693 + t869 * t232 * t693;
-	t877 = ZA * t752;
-	t878 = t877 * t818;
-	t911 = 0.16e2 * t878 * t53 * t45 * t365 - 0.4e1 * t699 * t785 * t29 - 0.4e1 * t705 * t188 * t830 + 0.2e1 * t801 * t94 * t693 * ZB - 0.8e1 * t857 * t843 - t718 * t726 + 0.4e1 * t773 * t761 * t13 - 0.4e1 * t705 * t775 * t555 + 0.2e1 * t746 * t232 * t233 - 0.16e2 * t878 * t830 * t365 - 0.2e1 * t746 * t619 * t24;
-	t916 = t110 * t28;
-	t945 = t28 * t693 * t45 * t17;
-	t948 = 0.32e2 * t877 * t733 * t798 + 0.2e1 * t718 * t36 * t916 * t24 - 0.4e1 * t705 * t626 + t718 * n * t916 * t693 - t869 * t792 * t110 - 0.4e1 * t773 * t761 * t775 + t718 * t719 + 0.2e1 * t746 * t232 * t24 - 0.16e2 * t849 * t365 * xc - t718 * t713 * t110 - 0.4e1 * t773 * t694 * t29 + 0.16e2 * t877 * t54 * t945;
-	t974 = t761 * t797;
-	t987 = 0.4e1 * t773 * t695 + 0.4e1 * t736 * t150 * t24 + 0.4e1 * t722 * t842 * t17 - 0.16e2 * t877 * t447 * t945 + 0.2e1 * t87 * t714 * t28 + t313 * t713 * t916 * t45 - 0.4e1 * t853 * t615 * t774 - 0.32e2 * t877 * t713 * xc * t324 + 0.16e2 * t760 * t974 + 0.4e1 * t736 * t94 * t24 * ZB + t869 * t792 * t916 - 0.8e1 * t691 * t5 * xc * t616;
-	t1021 = -t718 * t169 * t693 - 0.32e2 * t827 * t974 + 0.2e1 * t801 * t150 * t774 + 0.4e1 * t791 * t188 * t792 + 0.4e1 * t736 * t220 * t24 + 0.4e1 * t791 * t842 * t792 + 0.8e1 * t709 * t660 * t270 - t718 * t335 * t693 - 0.2e1 * t718 * t36 * t110 * t24 - 0.32e2 * t819 * t797 * t471 - t313 * t733 * t110 - 0.32e2 * t796 * t270 * t762;
-	
-	_C2A = (t147 - 0.4e1 * t65 * t217 + t418 + 0.2e1 * t150 * t222 + t327 - 0.2e1 * t149 * t19 + 0.2e1 * t335 * ZB * t24 * ZA - 0.16e2 * t312 * t313 * t355 * t59 - 0.4e1 * t281 * ZB * ZA * t597 - 0.2e1 * t505 * t45 * t281 * t58 - 0.4e1 * t211 * t2 * t53 * t76 + 0.8e1 * t305 * t286 - 0.4e1 * t122 * t499 - 0.4e1 * t331 * t332 + 0.8e1 * t345 * t177 * t60 - 0.2e1 * t142 * t177 * t82 + 0.2e1 * t72 * t281 * t415 + 0.4e1 * t349 * t96 * t41 - 0.2e1 * t81 * t64 * t76 + 0.2e1 * t58 * t80 * t59 + 0.8e1 * t345 * t177 * t41 - 0.4e1 * t8 * t499 + t242 + 0.4e1 * t8 * t518 + t625 + t685 + 0.2e1 * t328 * t174 + 0.2e1 * t331 * t455 - 0.2e1 * t33 * t2 * t4 * ZA * t82 - 0.4e1 * t626 * t191 + 0.16e2 * t364 * t373 - 0.2e1 * t621 * t597 - 0.2e1 * t439 * t568 + t492 + t533 * t96 + t232 * t96 + 0.2e1 * t567 * t441 + t561) / (t740 + t789 + t834 + t874 + t911 + t948 + t987 + t1021);
-	/****************************************************************************************/
-	t1 = n * n;
-	t2 = t1 * n;
-	t3 = t2 * 0.3141592654e1;
-	t4 = t3 * xc;
-	t5 = ZB * ZB;
-	t7 = exp(n * 0.3141592654e1);
-	t8 = t7 * t7;
-	t9 = t5 * t8;
-	t12 = exp(xc * n * 0.3141592654e1);
-	t13 = t12 * t12;
-	t14 = t13 * t13;
-	t15 = t14 * t13;
-	t19 = nx * nx;
-	t21 = nx * 0.3141592654e1;
-	t22 = sin(t21);
-	t23 = t19 * nx * t22;
-	t24 = t23 * 0.3141592654e1;
-	t25 = ZA * ZB;
-	t26 = t7 * t15;
-	t27 = t25 * t26;
-	t30 = t21 * xc;
-	t31 = sin(t30);
-	t32 = t31 * nx;
-	t33 = t32 * n;
-	t34 = ZA * ZA;
-	t35 = t8 * t8;
-	t36 = t34 * t35;
-	t40 = t2 * t34;
-	t41 = 0.3141592654e1 * t8;
-	t42 = t41 * t15;
-	t45 = t1 * t5;
-	t46 = t14 * t14;
-	t49 = t19 * t5;
-	t51 = t19 * t46;
-	t53 = t19 * t34;
-	t55 = t8 * t7;
-	t56 = t13 * t55;
-	t57 = t25 * t56;
-	t60 = t2 * nx;
-	t61 = 0.3141592654e1 * 0.3141592654e1;
-	t63 = t60 * t31 * t61;
-	t64 = xc * xc;
-	t65 = ZA * t64;
-	t66 = ZB * t8;
-	t67 = t14 * t12;
-	t68 = t66 * t67;
-	t69 = t65 * t68;
-	t72 = -0.4e1 * t4 * t9 * t15 + 0.4e1 * t24 * t27 + 0.4e1 * t33 * t36 * t12 - 0.4e1 * t40 * t42 - t45 * t46 + t45 * t14 - t49 * t14 + t51 * t5 - t53 * t14 + 0.4e1 * t24 * t57 + 0.32e2 * t63 * t69;
-	t73 = t1 * nx;
-	t75 = t73 * t31 * 0.3141592654e1;
-	t76 = t8 * t67;
-	t77 = t25 * t76;
-	t80 = t1 * t1;
-	t81 = t80 * t34;
-	t83 = t61 * t14;
-	t87 = t1 * t19;
-	t88 = cos(t30);
-	t90 = t87 * t88 * t61;
-	t91 = t5 * t64;
-	t92 = t13 * t12;
-	t93 = t8 * t92;
-	t94 = t91 * t93;
-	t100 = ZB * t64 * ZA * t8 * t92;
-	t103 = n * t19;
-	t105 = t103 * t88 * 0.3141592654e1;
-	t106 = ZA * xc;
-	t107 = ZB * t35;
-	t109 = t106 * t107 * t12;
-	t112 = t34 * xc;
-	t113 = t112 * t93;
-	t116 = t35 * t14;
-	t118 = t1 * ZA;
-	t119 = ZB * t14;
-	t122 = t1 * t46;
-	t125 = t19 * ZB;
-	t126 = t35 * ZA;
-	t127 = t125 * t126;
-	t129 = t1 * ZB;
-	t132 = -0.16e2 * t75 * t77 + 0.16e2 * t81 * t64 * t83 * t8 + 0.16e2 * t90 * t94 - 0.32e2 * t90 * t100 + 0.8e1 * t105 * t109 - 0.8e1 * t75 * t113 + t45 * t116 + 0.2e1 * t118 * t119 + 0.2e1 * t122 * t25 - 0.2e1 * t127 + 0.2e1 * t129 * t126;
-	t134 = t1 * t34;
-	t136 = t34 * t64;
-	t137 = t136 * t76;
-	t141 = t91 * t76;
-	t145 = t103 * t34;
-	t146 = 0.3141592654e1 * xc;
-	t147 = t8 * t13;
-	t153 = t14 * ZA;
-	t156 = xc * t5;
-	t157 = t156 * t93;
-	t160 = t103 * t5;
-	t162 = t146 * t8 * t15;
-	t166 = t34 * t7 * t15;
-	t169 = t134 * t116 - 0.16e2 * t63 * t137 - t49 * t116 - 0.16e2 * t63 * t141 - t53 * t116 + 0.4e1 * t145 * t146 * t147 - 0.2e1 * t51 * t25 - 0.2e1 * t125 * t153 - 0.16e2 * t75 * t157 + 0.4e1 * t160 * t162 - 0.4e1 * t24 * t166;
-	t170 = t106 * t68;
-	t177 = t35 * t92;
-	t178 = t112 * t177;
-	t181 = t156 * t76;
-	t186 = t35 * t12;
-	t187 = t112 * t186;
-	t193 = t5 * 0.3141592654e1;
-	t206 = t34 * t14;
-	t207 = t206 * t7;
-	t210 = -0.32e2 * t63 * t170 + 0.32e2 * t90 * t170 + 0.8e1 * t75 * t109 + 0.4e1 * t105 * t178 - 0.16e2 * t75 * t181 - 0.16e2 * t90 * t113 - 0.4e1 * t75 * t187 + 0.16e2 * t90 * t141 - 0.4e1 * t103 * t15 * t193 * xc + 0.16e2 * t73 * t22 * t34 * t146 * t26 + 0.4e1 * t32 * n * t34 * t67 + 0.4e1 * t24 * t207;
-	t217 = t106 * t66 * t92;
-	t226 = t88 * t19 * n;
-	t227 = 0.3141592654e1 * t34;
-	t229 = t227 * xc * t67;
-	t232 = t73 * t31;
-	t234 = t146 * t5 * t67;
-	t238 = t61 * ZB;
-	t239 = t14 * t8;
-	t240 = t238 * t239;
-	t243 = t136 * t93;
-	t246 = -0.8e1 * t33 * t25 * t186 + 0.32e2 * t90 * t217 - t45 * t35 + t53 * t35 - t134 * t35 - t134 * t46 + t134 * t14 - 0.4e1 * t226 * t229 + 0.4e1 * t232 * t234 + 0.32e2 * t87 * t65 * t240 + 0.16e2 * t63 * t243;
-	t247 = t14 * t92;
-	t249 = t227 * t247 * xc;
-	t254 = t73 * t22;
-	t259 = t60 * t22 * t61;
-	t260 = t112 * t26;
-	t264 = t146 * t247 * t5;
-	t268 = xc * t14;
-	t274 = t5 * t14;
-	t275 = t274 * t8;
-	t280 = n * nx;
-	t281 = t280 * t22;
-	t282 = t55 * t14;
-	t283 = t25 * t282;
-	t290 = ZA * t247 * xc * ZB;
-	t295 = t22 * nx * t1 * 0.3141592654e1;
-	t298 = -0.4e1 * t232 * t249 + 0.8e1 * t105 * t217 - 0.4e1 * t254 * t227 * t26 - 0.8e1 * t259 * t260 - 0.4e1 * t232 * t264 - 0.16e2 * t81 * t61 * t268 * t8 + 0.16e2 * t80 * t64 * t61 * t275 - 0.4e1 * t232 * t229 + 0.8e1 * t281 * t283 - 0.4e1 * t105 * t187 + 0.8e1 * t75 * t290 + 0.4e1 * t295 * t27;
-	t301 = t61 * t5;
-	t307 = t87 * t34;
-	t312 = t61 * xc;
-	t313 = t312 * t239;
-	t317 = t34 * t55 * t14;
-	t329 = ZB * t13 * t55;
-	t330 = t65 * t329;
-	t337 = -0.16e2 * t87 * t64 * t301 * t239 - 0.32e2 * t90 * t69 - 0.16e2 * t307 * t64 * t61 * t239 + 0.16e2 * t307 * t313 + 0.4e1 * t24 * t317 + t53 * t46 + t49 * t35 - 0.32e2 * t63 * t100 - 0.4e1 * t280 * t31 * t34 * t247 + 0.8e1 * t259 * t330 - 0.4e1 * t280 * t31 * t247 * t5;
-	t340 = t5 * t35;
-	t344 = t25 * t93;
-	t356 = t41 * t13;
-	t360 = t23 * n * t61;
-	t363 = t25 * t64 * t7 * t15;
-	t366 = t156 * t177;
-	t369 = t14 * t7;
-	t370 = t25 * t369;
-	t373 = t156 * t186;
-	t378 = 0.4e1 * t24 * t283 + 0.4e1 * t33 * t340 * t12 - 0.16e2 * t75 * t344 - 0.4e1 * t280 * t31 * t5 * t67 + 0.8e1 * t33 * t25 * t247 + 0.32e2 * t63 * t217 + 0.4e1 * t40 * t356 - 0.8e1 * t360 * t363 + 0.4e1 * t75 * t366 + 0.4e1 * t295 * t370 - 0.4e1 * t75 * t373 - 0.4e1 * t105 * t366;
-	t382 = t112 * t76;
-	t387 = t80 * t61;
-	t391 = t136 * t26;
-	t409 = 0.16e2 * t63 * t382 + 0.4e1 * t226 * t234 - 0.16e2 * t387 * xc * t275 + 0.8e1 * t259 * t391 - 0.16e2 * t105 * t344 + 0.4e1 * t226 * t264 - 0.8e1 * t105 * t170 + 0.16e2 * t232 * t193 * t76 + 0.8e1 * t360 * t330 - 0.8e1 * t105 * t290 + 0.16e2 * t90 * t243;
-	t423 = t153 * t8;
-	t426 = t34 * t13;
-	t427 = t426 * t55;
-	t430 = t34 * t8;
-	t437 = t80 * ZA;
-	t441 = 0.4e1 * t145 * t42 - 0.16e2 * t90 * t157 + 0.24e2 * t75 * t217 + 0.4e1 * t226 * t249 + 0.4e1 * t254 * t227 * t282 + 0.4e1 * t160 * t356 - 0.8e1 * t129 * t423 - 0.8e1 * t281 * t427 - 0.8e1 * t33 * t430 * t67 + 0.8e1 * t33 * t430 * t92 + 0.32e2 * t437 * ZB * t313;
-	t453 = t106 * ZB * t7 * t15;
-	t456 = t2 * t5;
-	t459 = t112 * t56;
-	t462 = t126 * t14;
-	t474 = t40 * 0.3141592654e1;
-	t475 = xc * t8;
-	t480 = t146 * t13 * t35;
-	t483 = -0.4e1 * t103 * xc * t193 * t147 + 0.16e2 * t87 * t61 * t156 * t239 + 0.8e1 * t259 * t453 - 0.4e1 * t456 * t356 + 0.8e1 * t259 * t459 - 0.2e1 * t125 * t462 - 0.8e1 * t281 * t207 + 0.16e2 * t295 * t459 - 0.8e1 * t60 * t22 * ZA * t312 * t329 + 0.4e1 * t474 * t475 * t15 + 0.4e1 * t160 * t480;
-	t497 = t136 * t56;
-	t504 = t9 * t13;
-	t509 = t475 * t13;
-	t512 = -0.8e1 * t105 * t113 - 0.4e1 * t254 * t227 * t56 + 0.8e1 * t281 * t57 + 0.4e1 * t295 * t283 + 0.2e1 * t129 * t462 + 0.4e1 * t24 * t370 - 0.8e1 * t360 * t497 - 0.4e1 * t24 * t427 - 0.4e1 * t145 * t162 + 0.4e1 * t4 * t504 - 0.8e1 * t281 * t370 - 0.4e1 * t474 * t509;
-	t528 = t5 * t13;
-	t529 = t528 * t35;
-	t532 = t106 * t329;
-	t542 = -0.16e2 * t295 * t453 - 0.32e2 * t437 * t64 * t240 + 0.8e1 * t281 * t317 + 0.24e2 * t75 * t170 - 0.4e1 * t75 * t178 + 0.8e1 * t360 * t453 - 0.4e1 * t4 * t529 - 0.16e2 * t295 * t532 - 0.8e1 * t33 * t344 - 0.16e2 * t90 * t181 + 0.4e1 * t33 * t340 * t92;
-	t557 = t146 * t15;
-	t562 = xc * t15;
-	t563 = t562 * t5;
-	t573 = 0.16e2 * t232 * t193 * t93 - 0.8e1 * t259 * t363 - 0.8e1 * t259 * t497 + 0.8e1 * t33 * t77 + 0.8e1 * t360 * t391 + 0.4e1 * t254 * t227 * t369 + 0.4e1 * t145 * t557 + 0.8e1 * t281 * t166 + 0.4e1 * t3 * t563 + 0.8e1 * t105 * t382 - 0.4e1 * t145 * t480 - 0.4e1 * t33 * t36 * t92;
-	t600 = 0.4e1 * t456 * t42 - 0.8e1 * t360 * t260 - 0.4e1 * t40 * t557 - 0.4e1 * t105 * t373 + 0.16e2 * t226 * t227 * t93 - 0.16e2 * t90 * t382 - 0.4e1 * t145 * t356 - 0.16e2 * t63 * t157 - 0.32e2 * t87 * t25 * t313 - 0.16e2 * t226 * t227 * t76 - 0.16e2 * t63 * t113;
-	t623 = xc * t13;
-	t627 = 0.8e1 * t125 * t423 - 0.8e1 * t360 * t532 + 0.16e2 * t90 * t137 - 0.4e1 * t160 * t42 + 0.16e2 * t63 * t94 + 0.16e2 * t63 * t181 - 0.8e1 * t281 * t27 - 0.8e1 * t75 * t382 + 0.8e1 * t360 * t459 + 0.4e1 * t295 * t57 + 0.16e2 * t105 * t77 + 0.4e1 * t474 * t623 * t35;
-	t632 = t61 * 0.3141592654e1;
-	t633 = t632 * t8;
-	t634 = t80 * n;
-	t638 = t632 * t634;
-	t639 = t638 * xc;
-	t642 = t61 * t34;
-	t643 = t122 * t19;
-	t649 = t61 * t61;
-	t650 = t649 * t1;
-	t652 = t19 * t19;
-	t653 = t14 * t652;
-	t654 = t653 * t9;
-	t657 = t14 * t1;
-	t658 = t657 * t19;
-	t665 = t632 * t34;
-	t666 = t665 * t2;
-	t667 = t8 * t19;
-	t668 = t667 * t623;
-	t674 = t665 * n;
-	t675 = t652 * xc;
-	t682 = 0.8e1 * t633 * t426 * t634 - 0.8e1 * t639 * t529 - 0.4e1 * t642 * t643 + 0.2e1 * t642 * t116 * t80 + 0.32e2 * t650 * t64 * t654 + 0.4e1 * t301 * t658 + 0.4e1 * t387 * t46 * ZA * ZB - 0.16e2 * t666 * t668 - 0.16e2 * t666 * t667 * t15 - 0.8e1 * t674 * t675 * t15 + 0.4e1 * t238 * t153 * t80;
-	t683 = t46 * t652;
-	t686 = t633 * t15;
-	t691 = t35 * t80;
-	t698 = t35 * t652;
-	t705 = t14 * t80;
-	t708 = t61 * t35;
-	t717 = -0.2e1 * t642 * t683 - 0.8e1 * t686 * t5 * t634 * xc - 0.2e1 * t301 * t691 + 0.8e1 * t638 * t563 - 0.2e1 * t642 * t691 - 0.2e1 * t642 * t698 - 0.2e1 * t301 * t698 - 0.2e1 * t301 * t683 + 0.2e1 * t642 * t705 + 0.2e1 * t708 * t274 * t80 + 0.2e1 * t301 * t653 - 0.2e1 * t642 * t80 * t46;
-	t727 = t61 * t46;
-	t737 = t649 * t34;
-	t738 = t737 * t1;
-	t739 = t8 * t652;
-	t740 = t739 * t268;
-	t746 = t61 * ZA;
-	t754 = t632 * n * xc;
-	t758 = 0.2e1 * t301 * t705 + 0.2e1 * t642 * t653 - 0.8e1 * t665 * xc * t634 * t15 - 0.2e1 * t727 * t5 * t80 - 0.32e2 * t650 * xc * t654 + 0.2e1 * t301 * t698 * t14 - 0.32e2 * t738 * t740 + 0.8e1 * t674 * t739 * t562 + 0.4e1 * t746 * t119 * t652 + 0.8e1 * t674 * t698 * t623 - 0.8e1 * t754 * t528 * t698;
-	t762 = t633 * t13;
-	t764 = t5 * n * t652;
-	t767 = t80 * t1;
-	t768 = t649 * t767;
-	t772 = t649 * ZA;
-	t773 = t772 * t129;
-	t777 = t35 * t1 * t19;
-	t780 = t632 * t5;
-	t781 = t780 * t15;
-	t786 = t698 * ZA;
-	t790 = t64 * t14;
-	t800 = t649 * t8;
-	t809 = 0.4e1 * t238 * t126 * t80 - 0.8e1 * t762 * t764 - 0.32e2 * t768 * xc * t275 + 0.64e2 * t773 * t740 - 0.4e1 * t301 * t777 - 0.8e1 * t781 * n * t8 * t675 + 0.4e1 * t238 * t786 + 0.32e2 * t768 * t34 * t790 * t8 - 0.8e1 * t633 * t528 * t634 + 0.8e1 * t754 * t528 * t739 + 0.128e3 * t800 * t119 * t80 * t19 * t106 + 0.8e1 * t674 * t739 * t13;
-	t812 = t649 * t80;
-	t817 = t83 * ZB;
-	t824 = t746 * ZB;
-	t828 = t800 * t14;
-	t855 = -0.64e2 * t812 * xc * t274 * t667 + 0.4e1 * t817 * t786 + 0.4e1 * t727 * ZA * t652 * ZB - 0.32e2 * t824 * t657 * t667 - 0.32e2 * t828 * t34 * t767 * xc - 0.8e1 * t633 * t15 * t34 * t634 - 0.8e1 * t674 * t739 * t15 + 0.32e2 * t768 * t64 * t275 + 0.4e1 * t708 * t14 * t307 + 0.2e1 * t708 * t206 * t652 + 0.8e1 * t632 * t35 * t13 * t34 * t634 * xc;
-	t858 = t35 * t19;
-	t873 = t2 * t8;
-	t878 = t61 * t1;
-	t901 = -0.16e2 * t632 * t2 * xc * t528 * t858 + 0.8e1 * t824 * t658 + 0.4e1 * t301 * t14 * t777 - 0.8e1 * t665 * t634 * t509 - 0.8e1 * t674 * t739 * t623 - 0.16e2 * t781 * t873 * t19 * xc + 0.8e1 * t878 * t14 * t127 + 0.8e1 * t878 * ZA * t51 * ZB + 0.8e1 * t686 * t764 + 0.8e1 * t665 * xc * t634 * t15 * t8 + 0.8e1 * t633 * t15 * t5 * t634 + 0.4e1 * t387 * t14 * t107 * ZA;
-	t903 = t739 * t790;
-	t923 = t737 * t80;
-	t924 = t667 * t790;
-	t927 = t780 * t2;
-	t937 = t15 * t19 * xc;
-	t943 = 0.32e2 * t738 * t903 + 0.16e2 * t781 * t873 * t19 + 0.8e1 * t754 * t15 * t652 * t5 + 0.16e2 * t666 * t858 * t623 + 0.64e2 * t828 * t25 * t767 * xc - 0.16e2 * t762 * t456 * t19 + 0.64e2 * t923 * t924 + 0.16e2 * t927 * t668 - 0.64e2 * t768 * ZA * t790 * t66 - 0.64e2 * t773 * t903 + 0.16e2 * t927 * t937 + 0.16e2 * t666 * t667 * t562;
-	t977 = 0.64e2 * t812 * t5 * t924 + 0.8e1 * t639 * t504 + 0.8e1 * t238 * t35 * t118 * t19 + 0.4e1 * t642 * t658 - 0.16e2 * t817 * t437 * t8 - 0.128e3 * t772 * ZB * t80 * t924 + 0.16e2 * t666 * t667 * t13 - 0.4e1 * t301 * t643 - 0.16e2 * t824 * t653 * t8 - 0.4e1 * t642 * t777 - 0.64e2 * t923 * t667 * t268 - 0.16e2 * t666 * t937;
-	
-	_C3A = (t72 + t132 + t169 + t210 + t246 + t298 + t337 + t378 + t409 + t441 + t483 + t512 + t542 + t573 + t600 + t627) / (t682 + t717 + t758 + t809 + t855 + t901 + t943 + t977);
-	/****************************************************************************************/
-	_C4A = 0;
-	/****************************************************************************************/
-	t1 = nx * 0.3141592654e1;
-	t2 = t1 * xc;
-	t3 = cos(t2);
-	t4 = nx * nx;
-	t6 = n * 0.3141592654e1;
-	t7 = t3 * t4 * t6;
-	t8 = ZA * ZB;
-	t9 = exp(t6);
-	t10 = t9 * t9;
-	t11 = xc * n;
-	t13 = exp(t11 * 0.3141592654e1);
-	t14 = t13 * t13;
-	t15 = t14 * t13;
-	t16 = t14 * t14;
-	t17 = t16 * t15;
-	t18 = t10 * t17;
-	t19 = t8 * t18;
-	t22 = sin(t2);
-	t23 = nx * t22;
-	t24 = t23 * n;
-	t25 = ZB * ZB;
-	t30 = n * n;
-	t31 = t30 * n;
-	t32 = t31 * nx;
-	t33 = 0.3141592654e1 * 0.3141592654e1;
-	t35 = t32 * t22 * t33;
-	t36 = ZA * ZA;
-	t37 = t36 * xc;
-	t38 = t16 * t13;
-	t39 = t10 * t38;
-	t40 = t37 * t39;
-	t43 = sin(t1);
-	t44 = nx * t43;
-	t45 = t30 * 0.3141592654e1;
-	t46 = t44 * t45;
-	t47 = ZA * xc;
-	t49 = ZB * t16 * t9;
-	t54 = t4 * nx * t43;
-	t55 = xc * xc;
-	t57 = t54 * t30 * t55;
-	t58 = t33 * 0.3141592654e1;
-	t59 = t58 * t25;
-	t60 = t16 * t9;
-	t61 = t59 * t60;
-	t64 = xc * t25;
-	t65 = t14 * t9;
-	t66 = t64 * t65;
-	t70 = t44 * t31 * t33;
-	t71 = t37 * t65;
-	t74 = t10 * t15;
-	t75 = t64 * t74;
-	t78 = t25 * t10;
-	t83 = t54 * n * t33;
-	t84 = t55 * t25;
-	t85 = t10 * t9;
-	t86 = t14 * t85;
-	t87 = t84 * t86;
-	t90 = t30 * t30;
-	t92 = t44 * t90 * t58;
-	t93 = t55 * xc;
-	t94 = t93 * t25;
-	t95 = t85 * t16;
-	t96 = t94 * t95;
-	t102 = t23 * t45;
-	t103 = t10 * t10;
-	t104 = ZB * t103;
-	t106 = t47 * t104 * t15;
-	t111 = t54 * 0.3141592654e1;
-	t112 = t25 * t85;
-	t113 = t112 * t16;
-	t115 = t8 * t39;
-	t118 = t16 * t14;
-	t119 = t85 * t118;
-	t120 = t37 * t119;
-	t123 = t16 * t16;
-	t124 = t36 * t123;
-	t125 = t124 * t9;
-	t127 = -0.8e1 * t7 * t19 + 0.2e1 * t24 * t25 * t13 * t10 - 0.16e2 * t35 * t40 - 0.16e2 * t46 * t47 * t49 - 0.8e1 * t57 * t61 + 0.4e1 * t46 * t66 + 0.2e1 * t70 * t71 - 0.16e2 * t35 * t75 + 0.6e1 * t24 * t78 * t38 - 0.2e1 * t83 * t87 - 0.8e1 * t92 * t96 - 0.8e1 * t46 * t37 * t95 - 0.12e2 * t102 * t106 + 0.2e1 * t83 * t71 + t111 * t113 + 0.8e1 * t7 * t115 + 0.2e1 * t83 * t120 + t111 * t125;
-	t128 = t37 * t74;
-	t131 = t44 * n;
-	t133 = t25 * t9 * t118;
-	t136 = t36 * t14;
-	t137 = t136 * t9;
-	t140 = t30 * t4;
-	t142 = t140 * t3 * t33;
-	t143 = t64 * t39;
-	t147 = t30 * nx * t43;
-	t148 = 0.3141592654e1 * t36;
-	t149 = t9 * t118;
-	t153 = t44 * t31 * ZA;
-	t154 = t33 * xc;
-	t155 = t154 * t49;
-	t160 = ZA * t17 * xc * ZB;
-	t163 = t103 * t13;
-	t164 = t64 * t163;
-	t170 = t44 * t90 * t55;
-	t171 = t58 * ZB;
-	t172 = ZA * t16;
-	t174 = t171 * t172 * t9;
-	t177 = t36 * t55;
-	t178 = t177 * t149;
-	t181 = t54 * t11;
-	t182 = t33 * t25;
-	t186 = t25 * t14;
-	t187 = t186 * t9;
-	t193 = t186 * t85;
-	t198 = ZB * t55;
-	t199 = ZA * t103;
-	t201 = t198 * t199 * t15;
-	t204 = 0.2e1 * t7 * t128 - 0.2e1 * t131 * t133 - 0.2e1 * t131 * t137 + 0.16e2 * t142 * t143 - t147 * t148 * t149 + 0.8e1 * t153 * t155 - 0.4e1 * t7 * t160 + 0.2e1 * t7 * t164 + 0.10e2 * t102 * t40 + 0.16e2 * t170 * t174 + 0.2e1 * t83 * t178 - 0.2e1 * t181 * t182 * t65 - t111 * t187 - 0.2e1 * t70 * t87 + 0.4e1 * t102 * t160 - 0.2e1 * t131 * t193 - 0.16e2 * t142 * t75 + 0.16e2 * t35 * t201;
-	t210 = t32 * t22;
-	t211 = t33 * t55;
-	t212 = t25 * t38;
-	t213 = t211 * t212;
-	t216 = n * nx;
-	t217 = t22 * t25;
-	t222 = ZB * t85 * t16;
-	t226 = t23 * t30;
-	t227 = t13 * t10;
-	t228 = t148 * t227;
-	t233 = t37 * t163;
-	t237 = n * t4 * t3;
-	t238 = t148 * t74;
-	t241 = t64 * t86;
-	t245 = t148 * xc * t15;
-	t248 = t112 * t118;
-	t250 = t22 * t36;
-	t256 = 0.3141592654e1 * t25;
-	t257 = t256 * t39;
-	t262 = t38 * t103;
-	t263 = t37 * t262;
-	t267 = t148 * t17 * xc;
-	t270 = -0.6e1 * t7 * t143 - 0.4e1 * t24 * t19 - 0.8e1 * t210 * t213 - 0.2e1 * t216 * t217 * t15 - 0.32e2 * t153 * t211 * t222 + 0.4e1 * t226 * t228 + 0.16e2 * t142 * t201 + 0.2e1 * t7 * t233 - 0.4e1 * t237 * t238 - 0.2e1 * t83 * t241 - 0.2e1 * t237 * t245 + t111 * t248 + 0.2e1 * t216 * t250 * t15 - 0.2e1 * t131 * t125 - 0.4e1 * t226 * t257 + t147 * t148 * t95 - 0.2e1 * t102 * t263 + 0.2e1 * t237 * t267;
-	t273 = t37 * t149;
-	t277 = t47 * t104 * t13;
-	t285 = t31 * t36;
-	t286 = t44 * t285;
-	t291 = t25 * t123 * t9;
-	t304 = 0.3141592654e1 * xc;
-	t305 = t304 * t212;
-	t312 = t256 * t18;
-	t315 = t8 * t60;
-	t319 = t54 * t30 * t58;
-	t323 = t90 * t36;
-	t324 = t44 * t323;
-	t325 = t55 * t58;
-	t326 = t325 * t60;
-	t329 = 0.2e1 * t102 * t164 + 0.2e1 * t83 * t273 - 0.4e1 * t102 * t277 - 0.2e1 * t7 * t263 + 0.4e1 * t24 * t8 * t17 - 0.4e1 * t286 * t154 * t60 - 0.2e1 * t131 * t291 - t147 * t148 * t119 + 0.2e1 * t24 * t78 * t17 + 0.2e1 * t54 * t85 * 0.3141592654e1 * ZA * ZB - 0.4e1 * t226 * t305 - 0.2e1 * t70 * t66 + t147 * t256 * t95 + 0.4e1 * t237 * t312 + 0.2e1 * t111 * t315 - 0.8e1 * t319 * t96 - t111 * t193 - 0.8e1 * t324 * t326;
-	t332 = t8 * t95;
-	t335 = t136 * t85;
-	t337 = t256 * t227;
-	t340 = t177 * t119;
-	t346 = t37 * t86;
-	t351 = t103 * t15;
-	t352 = t177 * t351;
-	t355 = t64 * t119;
-	t358 = t8 * t227;
-	t361 = t85 * 0.3141592654e1;
-	t365 = t84 * t39;
-	t372 = ZB * t10;
-	t373 = t372 * t38;
-	t374 = t47 * t373;
-	t379 = t177 * t39;
-	t384 = -0.2e1 * t46 * t332 + t111 * t335 + 0.4e1 * t237 * t337 - 0.2e1 * t83 * t340 + 0.16e2 * t286 * t211 * t95 + 0.2e1 * t70 * t346 - 0.8e1 * t170 * t61 - 0.8e1 * t142 * t352 - 0.2e1 * t83 * t355 - 0.4e1 * t24 * t358 + 0.2e1 * t147 * t361 * t8 + 0.8e1 * t35 * t365 - 0.2e1 * t226 * t267 + 0.8e1 * t102 * t115 - 0.12e2 * t102 * t374 + 0.16e2 * t142 * t40 - 0.8e1 * t142 * t379 + 0.4e1 * t237 * t228;
-	t386 = t54 * t30 * t93;
-	t387 = ZA * t85;
-	t389 = t171 * t387 * t16;
-	t394 = t64 * t60;
-	t398 = t304 * t25 * t15;
-	t401 = t361 * t25;
-	t405 = t84 * t65;
-	t410 = t148 * t18;
-	t414 = t25 * t16 * t9;
-	t417 = t84 * t74;
-	t422 = t177 * t86;
-	t428 = ZB * t38;
-	t429 = t47 * t428;
-	t432 = t148 * t39;
-	t439 = 0.16e2 * t386 * t389 - 0.16e2 * t386 * t174 + 0.8e1 * t46 * t394 + 0.2e1 * t237 * t398 - t147 * t401 + 0.4e1 * t7 * t374 + 0.2e1 * t83 * t405 - 0.4e1 * t46 * t241 - 0.4e1 * t226 * t410 + 0.2e1 * t131 * t414 + 0.8e1 * t35 * t417 - 0.8e1 * t142 * t365 + 0.2e1 * t70 * t422 - 0.4e1 * t181 * t182 * t60 + 0.12e2 * t102 * t429 - 0.4e1 * t226 * t432 + 0.32e2 * t35 * t374 - 0.4e1 * t7 * t106;
-	t442 = t36 * t9 * t118;
-	t444 = t123 * t9;
-	t445 = t8 * t444;
-	t448 = t361 * t36;
-	t451 = t47 * t372 * t17;
-	t454 = t94 * t60;
-	t457 = t25 * t103;
-	t465 = t47 * t372 * t15;
-	t468 = t36 * t85;
-	t469 = t468 * t16;
-	t474 = t43 * t85;
-	t478 = t8 * t74;
-	t484 = t256 * t74;
-	t489 = t198 * ZA * t10 * t15;
-	t501 = -t111 * t442 + 0.4e1 * t131 * t445 - t147 * t448 + 0.4e1 * t7 * t451 + 0.8e1 * t92 * t454 - 0.2e1 * t24 * t457 * t13 - 0.2e1 * t286 * t211 * t65 + 0.4e1 * t7 * t465 + t111 * t469 - 0.2e1 * t216 * t250 * t17 - 0.2e1 * t216 * t474 * t25 - 0.4e1 * t24 * t478 + 0.4e1 * t24 * t8 * t38 + 0.4e1 * t226 * t484 - 0.16e2 * t142 * t489 - 0.2e1 * t24 * t212 * t103 - 0.2e1 * t216 * t22 * t17 * t25 + 0.2e1 * t70 * t120;
-	t504 = t33 * t36 * t55 * t38;
-	t507 = t37 * t18;
-	t512 = t47 * ZB * t13 * t10;
-	t518 = t59 * t95;
-	t530 = t84 * t351;
-	t534 = t37 * t227;
-	t549 = -0.8e1 * t210 * t504 + 0.2e1 * t102 * t507 + 0.4e1 * t7 * t512 + t111 * t133 - 0.16e2 * t35 * t489 + 0.8e1 * t170 * t518 + 0.2e1 * t24 * t36 * t13 * t10 + 0.4e1 * t131 * t387 * ZB + 0.12e2 * t102 * t465 - 0.8e1 * t142 * t530 + t111 * t291 - 0.2e1 * t102 * t534 - 0.4e1 * t70 * t394 - 0.10e2 * t102 * t128 + 0.4e1 * t237 * t305 + 0.8e1 * t102 * t19 + 0.2e1 * t83 * t346 - 0.16e2 * t35 * t128;
-	t557 = t468 * t118;
-	t562 = t93 * t58;
-	t563 = t562 * t60;
-	t567 = t44 * t90 * t93;
-	t575 = ZA * t55;
-	t576 = t575 * t428;
-	t583 = t37 * t60;
-	t590 = t140 * t3;
-	t601 = -0.2e1 * t226 * t398 - 0.2e1 * t70 * t340 - 0.2e1 * t131 * t557 - 0.4e1 * t24 * t115 + 0.8e1 * t324 * t563 + 0.16e2 * t567 * t389 + 0.16e2 * t70 * t84 * t95 + 0.2e1 * t70 * t178 - 0.16e2 * t142 * t576 - 0.4e1 * t237 * t257 - 0.4e1 * t226 * t312 + 0.8e1 * t46 * t583 + 0.2e1 * t24 * t36 * t38 * t103 + 0.8e1 * t590 * t213 + 0.2e1 * t102 * t143 - 0.16e2 * t35 * t143 + 0.2e1 * t131 * t248 + 0.4e1 * t46 * t346;
-	t604 = n * t36;
-	t606 = t154 * t95;
-	t625 = t36 * t103;
-	t640 = t30 * t36;
-	t641 = t54 * t640;
-	t642 = t325 * t95;
-	t647 = -0.4e1 * t131 * t315 - 0.4e1 * t54 * t604 * t606 - t147 * t148 * t60 + 0.16e2 * t35 * t576 - 0.8e1 * t102 * t478 + 0.32e2 * t142 * t465 - 0.4e1 * t237 * t484 - 0.2e1 * t70 * t355 + 0.2e1 * t70 * t273 + 0.2e1 * t102 * t233 - 0.2e1 * t24 * t625 * t13 - 0.8e1 * t7 * t358 - 0.2e1 * t111 * t445 - 0.4e1 * t7 * t429 + 0.16e2 * t46 * t47 * t222 + 0.2e1 * t131 * t113 + 0.8e1 * t641 * t642 - 0.2e1 * t7 * t534;
-	t652 = t36 * t16;
-	t653 = t652 * t9;
-	t655 = t64 * t227;
-	t658 = t182 * t95;
-	t663 = t562 * t95;
-	t684 = t64 * t351;
-	t689 = t36 * t10;
-	t695 = t154 * t222;
-	t698 = -0.4e1 * t216 * t217 * t38 - t111 * t653 - 0.2e1 * t7 * t655 - 0.4e1 * t181 * t658 + 0.2e1 * t131 * t469 - 0.8e1 * t641 * t663 - 0.4e1 * t83 * t583 - 0.2e1 * t83 * t177 * t65 - 0.4e1 * t24 * t457 * t15 + 0.16e2 * t70 * t84 * t60 + 0.8e1 * t57 * t518 - 0.32e2 * t142 * t374 + 0.4e1 * t24 * t8 * t351 + 0.4e1 * t102 * t684 - t147 * t256 * t86 - 0.2e1 * t24 * t689 * t15 - 0.2e1 * t70 * t241 + 0.8e1 * t153 * t695;
-	t711 = t575 * t373;
-	t717 = t304 * t17 * t25;
-	t736 = t177 * t74;
-	t739 = 0.2e1 * t226 * t245 - 0.8e1 * t102 * t358 - 0.16e2 * t57 * t389 - 0.2e1 * t102 * t655 + 0.8e1 * t590 * t504 - 0.8e1 * t641 * t326 - 0.16e2 * t35 * t711 - t111 * t557 + t111 * t137 - 0.2e1 * t226 * t717 + 0.8e1 * t102 * t37 * t351 + 0.2e1 * t131 * t335 - 0.4e1 * t131 * t332 - 0.2e1 * t216 * t474 * t36 - 0.2e1 * t111 * t332 + 0.16e2 * t142 * t711 - t147 * t256 * t60 + 0.8e1 * t142 * t736;
-	t750 = t64 * t262;
-	t763 = t44 * t640;
-	t770 = t84 * t119;
-	t782 = 0.4e1 * t102 * t512 + 0.8e1 * t142 * t417 + 0.8e1 * t641 * t563 - 0.2e1 * t7 * t507 + 0.2e1 * t7 * t750 - 0.8e1 * t35 * t352 + 0.4e1 * t237 * t410 + 0.4e1 * t7 * t684 - 0.2e1 * t46 * t445 + t147 * t148 * t65 + 0.4e1 * t763 * t304 * t119 + 0.16e2 * t70 * t177 * t60 + 0.2e1 * t70 * t770 - t111 * t414 - 0.16e2 * t567 * t174 - 0.4e1 * t46 * t71 - 0.4e1 * t46 * t355 - 0.4e1 * t7 * t277;
-	t797 = t64 * t149;
-	t821 = -t54 * t448 + 0.2e1 * t131 * t442 + 0.8e1 * t7 * t478 + 0.8e1 * t35 * t379 - 0.2e1 * t181 * t182 * t149 + 0.2e1 * t70 * t405 + 0.2e1 * t83 * t770 - 0.2e1 * t70 * t797 - 0.6e1 * t7 * t75 - 0.4e1 * t286 * t606 - 0.4e1 * t237 * t432 + t147 * t256 * t149 - 0.4e1 * t763 * t304 * t149 - 0.2e1 * t102 * t75 + 0.2e1 * t237 * t717 + 0.8e1 * t324 * t642 - 0.16e2 * t170 * t389 + 0.2e1 * t83 * t422;
-	t827 = t84 * t149;
-	t846 = t54 * n * ZA;
-	t854 = t64 * t18;
-	t867 = -0.16e2 * t142 * t128 + 0.32e2 * t35 * t465 - 0.2e1 * t83 * t827 + 0.2e1 * t46 * t315 + t147 * t148 * t86 - 0.4e1 * t102 * t451 - 0.8e1 * t226 * t148 * xc * t38 - 0.2e1 * t24 * t689 * t38 + 0.2e1 * t131 * t187 + 0.8e1 * t846 * t155 + 0.8e1 * t35 * t736 + 0.2e1 * t24 * t689 * t17 - 0.2e1 * t7 * t854 + t147 * t256 * t119 + 0.2e1 * t102 * t854 - 0.8e1 * t35 * t530 + 0.4e1 * t46 * t797 + 0.2e1 * t102 * t750;
-	t909 = -0.8e1 * t324 * t663 + t147 * t256 * t444 - t147 * t256 * t65 + 0.4e1 * t226 * t238 + 0.2e1 * t7 * t40 - t54 * t401 + 0.16e2 * t57 * t174 + 0.4e1 * t226 * t337 + 0.4e1 * t24 * t8 * t163 + 0.8e1 * t846 * t695 + 0.8e1 * t319 * t454 + 0.2e1 * t131 * t653 - 0.8e1 * t46 * t64 * t95 + 0.6e1 * t24 * t78 * t15 - 0.4e1 * t44 * t31 * xc * t658 - 0.32e2 * t153 * t211 * t49 - 0.2e1 * t70 * t827 + t147 * t148 * t444;
-	t914 = t25 * ZB;
-	t915 = t33 * t914;
-	t919 = t4 * t4;
-	t920 = t16 * t919;
-	t929 = t123 * t90;
-	t932 = t919 * t103;
-	t935 = t33 * ZB;
-	t939 = t652 * t919;
-	t942 = t16 * t30;
-	t943 = t942 * t4;
-	t949 = t103 * t16;
-	t950 = t949 * t90;
-	t953 = -0.2e1 * t915 * t103 * t90 + 0.2e1 * t915 * t920 - 0.2e1 * t915 * t123 * t919 + 0.2e1 * t915 * t16 * t90 - 0.2e1 * t915 * t929 - 0.2e1 * t915 * t932 - 0.2e1 * t935 * t323 * t123 + 0.2e1 * t935 * t939 + 0.4e1 * t915 * t943 + 0.4e1 * t182 * t172 * t90 + 0.2e1 * t915 * t950;
-	t954 = t171 * t36;
-	t955 = t90 * n;
-	t956 = xc * t955;
-	t957 = t118 * t10;
-	t964 = t33 * t33;
-	t965 = t964 * ZB;
-	t966 = t965 * t640;
-	t967 = t10 * t919;
-	t968 = t55 * t16;
-	t969 = t967 * t968;
-	t972 = t935 * t36;
-	t974 = t103 * t30 * t4;
-	t977 = xc * t16;
-	t978 = t967 * t977;
-	t981 = t90 * t30;
-	t983 = t16 * t10;
-	t987 = t182 * ZA;
-	t988 = t4 * t10;
-	t992 = t171 * t604;
-	t993 = xc * t14;
-	t994 = t932 * t993;
-	t997 = t182 * t30;
-	t1005 = t171 * t285;
-	t1006 = t988 * t993;
-	t1009 = t58 * t914;
-	t1010 = t1009 * t31;
-	t1013 = 0.8e1 * t954 * t956 * t957 + 0.2e1 * t915 * t932 * t16 + 0.32e2 * t966 * t969 - 0.4e1 * t972 * t974 - 0.32e2 * t966 * t978 + 0.32e2 * t965 * t981 * t177 * t983 - 0.32e2 * t987 * t942 * t988 + 0.8e1 * t992 * t994 + 0.8e1 * t997 * t949 * ZA * t4 - 0.2e1 * t935 * t124 * t919 - 0.16e2 * t1005 * t1006 + 0.16e2 * t1010 * t1006;
-	t1015 = t964 * t25;
-	t1016 = ZA * t30;
-	t1017 = t1015 * t1016;
-	t1020 = t967 * t993;
-	t1031 = t1009 * t118;
-	t1032 = t31 * t10;
-	t1040 = t964 * t914;
-	t1041 = t1040 * t90;
-	t1044 = t55 * t10 * t4 * t16;
-	t1047 = t1040 * t30;
-	t1050 = t123 * ZA;
-	t1054 = t977 * t988;
-	t1057 = 0.64e2 * t1017 * t978 - 0.8e1 * t992 * t1020 + 0.2e1 * t972 * t950 + 0.4e1 * t182 * t929 * ZA + 0.4e1 * t182 * t199 * t90 - 0.16e2 * t1031 * t1032 * t4 * xc + 0.4e1 * t182 * t172 * t919 + 0.64e2 * t1041 * t1044 + 0.32e2 * t1047 * t969 + 0.4e1 * t182 * t1050 * t919 - 0.64e2 * t1041 * t1054;
-	t1058 = t1009 * n;
-	t1063 = t932 * ZA;
-	t1069 = t123 * t30 * t4;
-	t1080 = t993 * t103 * t4;
-	t1088 = t935 * t103;
-	t1094 = -0.8e1 * t1058 * t994 - 0.32e2 * t1047 * t978 + 0.4e1 * t182 * t1063 - 0.4e1 * t915 * t974 - 0.4e1 * t915 * t1069 - 0.2e1 * t935 * t625 * t90 - 0.8e1 * t1009 * t10 * t14 * t955 - 0.16e2 * t1010 * t1080 - 0.2e1 * t935 * t625 * t919 - 0.64e2 * t1017 * t969 + 0.2e1 * t1088 * t939 + 0.8e1 * t1009 * t957 * t955;
-	t1113 = t955 * t118 * xc;
-	t1120 = t4 * t118;
-	t1125 = t981 * xc;
-	t1133 = n * t10;
-	t1140 = -0.8e1 * t954 * t955 * t10 * t993 + 0.2e1 * t935 * t652 * t90 - 0.64e2 * t1015 * t981 * t575 * t983 + 0.8e1 * t182 * t103 * t1016 * t4 + 0.8e1 * t1009 * t1113 + 0.16e2 * t954 * t1032 * t4 * t14 - 0.16e2 * t954 * t1032 * t1120 + 0.64e2 * t1015 * t10 * t172 * t1125 + 0.8e1 * t171 * t103 * t136 * t956 - 0.8e1 * t1031 * t1133 * t919 * xc + 0.8e1 * t1058 * t1020;
-	t1153 = xc * t118;
-	t1165 = t182 * t16;
-	t1170 = t171 * t10;
-	t1178 = ZA * t90;
-	t1182 = 0.4e1 * t1088 * t652 * t140 + 0.8e1 * t954 * t1133 * t919 * t14 + 0.4e1 * t972 * t943 - 0.4e1 * t972 * t1069 - 0.16e2 * t954 * t31 * t4 * t1153 - 0.8e1 * t954 * n * t919 * t1153 - 0.8e1 * t954 * t1133 * t919 * t118 + 0.4e1 * t1165 * t1063 + 0.16e2 * t1005 * t1080 - 0.8e1 * t1170 * t118 * t36 * t955 - 0.16e2 * t987 * t920 * t10 - 0.16e2 * t1165 * t1178 * t10;
-	t1195 = t1040 * t981;
-	t1199 = t1009 * t955;
-	t1203 = t1009 * t10;
-	t1211 = t965 * t323;
-	t1225 = -0.32e2 * t965 * t10 * t652 * t1125 + 0.4e1 * t915 * t16 * t974 + 0.4e1 * t182 * t90 * t949 * ZA + 0.32e2 * t1195 * t968 * t10 - 0.8e1 * t1199 * t993 * t103 + 0.8e1 * t1203 * t118 * n * t919 + 0.8e1 * t1170 * t136 * t955 + 0.64e2 * t1211 * t1044 + 0.16e2 * t1031 * t1032 * t4 + 0.8e1 * t987 * t943 + 0.8e1 * t1199 * t993 * t10 + 0.8e1 * t997 * t1050 * t4;
-	t1263 = -0.128e3 * t1015 * t1178 * t1044 + 0.16e2 * t1005 * t988 * t1153 + 0.8e1 * t1058 * t1153 * t919 + 0.16e2 * t1010 * t1120 * xc - 0.8e1 * t954 * t1113 - 0.8e1 * t1203 * t14 * n * t919 - 0.16e2 * t1203 * t14 * t31 * t4 - 0.8e1 * t1203 * t1113 - 0.32e2 * t1195 * t977 * t10 - 0.64e2 * t1211 * t1054 + 0.8e1 * t992 * t967 * t1153 + 0.128e3 * t1015 * t983 * t90 * t4 * t47;
-	
-	_C1B = (t127 + t204 + t270 + t329 + t384 + t439 + t501 + t549 + t601 + t647 + t698 + t739 + t782 + t821 + t867 + t909) / (t953 + t1013 + t1057 + t1094 + t1140 + t1182 + t1225 + t1263);
-	/****************************************************************************************/
-	t1 = n * n;
-	t2 = t1 * n;
-	t3 = nx * t2;
-	t4 = 0.3141592654e1 * ZA;
-	t5 = t3 * t4;
-	t6 = nx * 0.3141592654e1;
-	t7 = t6 * xc;
-	t8 = sin(t7);
-	t9 = t8 * ZB;
-	t10 = n * 0.3141592654e1;
-	t11 = exp(t10);
-	t12 = t11 * t11;
-	t15 = exp(xc * n * 0.3141592654e1);
-	t16 = t15 * t15;
-	t17 = t16 * t16;
-	t18 = t17 * t15;
-	t19 = t12 * t18;
-	t23 = t1 * t1;
-	t24 = nx * t23;
-	t25 = ZB * ZB;
-	t27 = t18 * t8;
-	t28 = 0.3141592654e1 * 0.3141592654e1;
-	t29 = xc * xc;
-	t30 = t28 * t29;
-	t34 = t1 * xc;
-	t35 = 0.3141592654e1 * ZB;
-	t36 = t34 * t35;
-	t37 = cos(t7);
-	t38 = ZA * t37;
-	t39 = nx * nx;
-	t40 = t39 * t12;
-	t41 = t16 * t15;
-	t43 = t38 * t40 * t41;
-	t46 = t25 * n;
-	t47 = t46 * 0.3141592654e1;
-	t48 = t39 * nx;
-	t49 = sin(t6);
-	t50 = t48 * t49;
-	t51 = t12 * t11;
-	t52 = t51 * t17;
-	t53 = t50 * t52;
-	t56 = t34 * 0.3141592654e1 * t25;
-	t57 = t37 * t39;
-	t58 = t17 * t41;
-	t59 = t12 * t58;
-	t60 = t57 * t59;
-	t63 = t25 * t18;
-	t64 = t57 * n;
-	t67 = ZA * ZA;
-	t68 = t67 * n;
-	t69 = 0.3141592654e1 * t48;
-	t70 = t68 * t69;
-	t71 = t49 * xc;
-	t72 = t17 * t16;
-	t73 = t11 * t72;
-	t74 = t71 * t73;
-	t77 = t1 * t67;
-	t78 = t77 * 0.3141592654e1;
-	t81 = nx * t25;
-	t82 = t81 * t49;
-	t83 = t17 * t17;
-	t85 = t1 * t83 * t11;
-	t87 = nx * ZB;
-	t88 = t8 * t2;
-	t89 = t87 * t88;
-	t90 = 0.3141592654e1 * xc;
-	t91 = t12 * t12;
-	t92 = ZA * t91;
-	t97 = ZB * ZA;
-	t98 = t97 * t37;
-	t99 = t39 * n;
-	t100 = t12 * t41;
-	t104 = 0.8e1 * t5 * t9 * t19 + 0.8e1 * t24 * t25 * t27 * t30 + 0.12e2 * t36 * t43 - t47 * t53 - 0.2e1 * t56 * t60 - 0.4e1 * t63 * t64 + 0.6e1 * t70 * t74 + 0.4e1 * t78 * t60 - t82 * t85 + 0.4e1 * t89 * t90 * t92 * t41 + 0.4e1 * t98 * t99 * t100;
-	t105 = t67 * t48;
-	t106 = t49 * t51;
-	t107 = t106 * t72;
-	t109 = t1 * 0.3141592654e1;
-	t110 = t109 * xc;
-	t115 = nx * t67;
-	t116 = t115 * t49;
-	t117 = t1 * t16;
-	t118 = t117 * t11;
-	t120 = t2 * t25;
-	t121 = t28 * 0.3141592654e1;
-	t122 = t121 * t29;
-	t123 = t120 * t122;
-	t129 = t1 * ZB;
-	t130 = t129 * t4;
-	t131 = t57 * t100;
-	t134 = t12 * t16;
-	t136 = t109 * t39;
-	t139 = ZB * t18;
-	t141 = t39 * t1;
-	t142 = t141 * t90;
-	t145 = t77 * t90;
-	t146 = t91 * t41;
-	t147 = t57 * t146;
-	t151 = t25 * t39 * t1;
-	t152 = t72 * t12;
-	t156 = t49 * t2;
-	t158 = t83 * t11;
-	t162 = -t105 * t107 + 0.8e1 * t110 * t72 * t25 * t39 - t116 * t118 + 0.8e1 * t123 * t53 + 0.8e1 * t5 * t9 * t59 - 0.8e1 * t130 * t131 - 0.8e1 * t134 * t25 * t136 - 0.12e2 * t139 * t38 * t142 - 0.8e1 * t145 * t147 - 0.8e1 * t151 * t90 * t152 - 0.2e1 * t87 * t156 * t4 * t158;
-	t164 = t115 * t88;
-	t165 = t90 * t19;
-	t168 = t25 * t48;
-	t169 = t49 * t16;
-	t170 = t169 * t11;
-	t174 = ZA * n * t69;
-	t175 = ZB * t51;
-	t176 = t175 * t17;
-	t177 = t71 * t176;
-	t180 = t1 * t29;
-	t181 = t28 * t25;
-	t182 = t180 * t181;
-	t183 = t50 * t73;
-	t186 = ZA * t1;
-	t187 = t28 * t48;
-	t188 = t186 * t187;
-	t189 = ZB * t17;
-	t190 = t189 * t11;
-	t191 = t71 * t190;
-	t194 = t50 * t158;
-	t196 = t115 * t156;
-	t197 = t90 * t73;
-	t201 = t49 * t17 * t11;
-	t204 = t88 * t90;
-	t207 = t68 * 0.3141592654e1;
-	t208 = t17 * t11;
-	t209 = t50 * t208;
-	t211 = -0.2e1 * t164 * t165 - t168 * t170 + t168 * t107 + 0.8e1 * t174 * t177 + 0.2e1 * t182 * t183 + 0.8e1 * t188 * t191 + t47 * t194 - 0.6e1 * t196 * t197 - t168 * t201 - 0.4e1 * t81 * t18 * t204 - t207 * t209;
-	t212 = t2 * 0.3141592654e1;
-	t213 = t212 * t52;
-	t215 = t81 * t8;
-	t216 = t212 * t59;
-	t219 = t3 * t90;
-	t220 = t25 * t8;
-	t221 = t18 * t91;
-	t225 = t71 * t52;
-	t231 = t16 * t51;
-	t232 = t50 * t231;
-	t237 = ZA * t12;
-	t243 = t67 * t28;
-	t244 = t24 * t243;
-	t245 = t71 * t231;
-	t249 = -t116 * t213 - 0.4e1 * t215 * t216 + 0.2e1 * t219 * t220 * t221 - 0.4e1 * t70 * t225 + 0.4e1 * t98 * t99 * t146 + t47 * t232 - 0.2e1 * t145 * t57 * t221 + 0.4e1 * t89 * t90 * t237 * t41 - t105 * t201 - 0.6e1 * t244 * t245 + t105 * t170;
-	t252 = t25 * t37;
-	t253 = t252 * t39;
-	t255 = n * t15 * t12;
-	t258 = t2 * t29;
-	t259 = ZB * t28;
-	t260 = t258 * t259;
-	t263 = t106 * t17;
-	t265 = xc * t25;
-	t269 = t25 * t49;
-	t270 = t269 * t52;
-	t273 = t1 * t25;
-	t274 = t273 * 0.3141592654e1;
-	t275 = t57 * t19;
-	t278 = t24 * t30;
-	t288 = t1 * t11 * t72;
-	t290 = t212 * t208;
-	t292 = t2 * xc;
-	t296 = 0.2e1 * t253 * t255 + 0.16e2 * t260 * t43 + t105 * t263 - 0.4e1 * t10 * t265 * t53 + 0.4e1 * t219 * t270 - 0.12e2 * t274 * t275 + 0.8e1 * t278 * t270 - 0.2e1 * ZB * n * t69 * t49 * ZA * t158 - t82 * t288 - t116 * t290 + 0.16e2 * t292 * t243 * t275;
-	t301 = t50 * t176;
-	t304 = t51 * t72;
-	t305 = t71 * t304;
-	t308 = t25 * t41;
-	t311 = ZA * t48;
-	t312 = t311 * t49;
-	t317 = t91 * t15;
-	t318 = t57 * t317;
-	t321 = t81 * t88;
-	t322 = t90 * t59;
-	t325 = t212 * t231;
-	t327 = t15 * t12;
-	t328 = t57 * t327;
-	t331 = t77 * t187;
-	t334 = t2 * ZA;
-	t335 = t334 * t122;
-	t336 = t50 * t190;
-	t339 = 0.8e1 * t151 * t90 * t134 + 0.16e2 * t186 * t30 * t301 - 0.2e1 * t70 * t305 + 0.2e1 * t308 * t64 - 0.2e1 * t312 * ZB * t83 * t11 + 0.2e1 * t56 * t318 + 0.2e1 * t321 * t322 - t116 * t325 - 0.4e1 * t274 * t328 + 0.2e1 * t331 * t305 - 0.16e2 * t335 * t336;
-	t341 = t169 * t51;
-	t344 = t49 * t11 * t72;
-	t346 = t77 * t30;
-	t347 = t50 * t304;
-	t350 = t25 * t51;
-	t352 = nx * ZA;
-	t353 = t49 * t23;
-	t354 = t352 * t353;
-	t355 = t28 * xc;
-	t362 = t25 * t91;
-	t365 = t23 * n;
-	t366 = nx * t365;
-	t367 = t366 * t122;
-	t368 = ZB * t49;
-	t369 = ZA * t51;
-	t370 = t369 * t17;
-	t371 = t368 * t370;
-	t374 = t115 * t353;
-	t375 = t355 * t73;
-	t381 = t105 * t341 - t105 * t344 - 0.2e1 * t346 * t347 - t350 * t50 - 0.8e1 * t354 * t355 * t176 - 0.4e1 * t98 * t99 * t317 - 0.2e1 * t362 * t99 - 0.16e2 * t367 * t371 + 0.6e1 * t374 * t375 - 0.8e1 * t182 * t53 - t82 * t290;
-	t382 = t71 * t208;
-	t394 = t2 * t67;
-	t395 = t394 * t122;
-	t398 = t352 * t156;
-	t402 = t17 * t12;
-	t403 = t39 * ZA;
-	t404 = t402 * t403;
-	t407 = t269 * t208;
-	t411 = t49 * t83 * t11;
-	t413 = t46 * t69;
-	t419 = -0.4e1 * t331 * t382 + 0.2e1 * t115 * t58 * t204 - 0.2e1 * t145 * t60 + 0.12e2 * t274 * t131 + 0.2e1 * t346 * t232 + 0.8e1 * t395 * t53 - 0.8e1 * t398 * t90 * t176 - 0.64e2 * t260 * t404 + 0.4e1 * t219 * t407 + t168 * t411 - 0.6e1 * t413 * t74 - 0.2e1 * t110 * t308 * t57;
-	t424 = t16 * t11;
-	t425 = t212 * t424;
-	t427 = t258 * t181;
-	t430 = t67 * t29;
-	t431 = t366 * t430;
-	t432 = t121 * t49;
-	t433 = t432 * t52;
-	t436 = n * t12;
-	t437 = t436 * t18;
-	t440 = t29 * xc;
-	t441 = t440 * t121;
-	t442 = t394 * t441;
-	t445 = t67 * t37;
-	t446 = t445 * t39;
-	t448 = n * t18 * t91;
-	t453 = t352 * t49;
-	t458 = t8 * t23;
-	t462 = t81 * t458;
-	t463 = t30 * t19;
-	t466 = -t47 * t209 + t116 * t425 - 0.8e1 * t427 * t275 + 0.8e1 * t431 * t433 - 0.2e1 * t253 * t437 - 0.8e1 * t442 * t53 - 0.2e1 * t446 * t448 + 0.2e1 * t175 * t312 + 0.6e1 * t453 * t129 * t208 + 0.8e1 * t115 * t18 * t458 * t30 + 0.8e1 * t462 * t463;
-	t470 = t436 * t58;
-	t475 = t2 * t121 * t440 * t25;
-	t485 = t212 * t73;
-	t488 = t67 * t72 * t1;
-	t490 = t39 * xc;
-	t501 = 0.4e1 * t374 * t355 * t52 + 0.2e1 * t446 * t470 - 0.8e1 * t475 * t53 - 0.2e1 * t446 * t437 - 0.4e1 * t36 * t38 * t39 * t15 * t12 - t116 * t485 + 0.8e1 * t488 * 0.3141592654e1 * t12 * t490 - t207 * t183 - 0.2e1 * t182 * t232 - 0.6e1 * t413 * t245 - 0.4e1 * t413 * t382;
-	t503 = t115 * t8;
-	t510 = t355 * t19;
-	t513 = t432 * t208;
-	t525 = t38 * t40 * t18;
-	t533 = -0.4e1 * t503 * t216 - 0.4e1 * t89 * t90 * t92 * t15 - 0.16e2 * t462 * t510 + 0.8e1 * t431 * t513 - 0.4e1 * t78 * t131 + t47 * t183 - 0.2e1 * t67 * t83 * t99 + 0.4e1 * t331 * t225 + 0.16e2 * t260 * t525 - 0.4e1 * t89 * t90 * t237 * t58 - t207 * t53;
-	t536 = t28 * t37;
-	t538 = t490 * t100;
-	t541 = t334 * t441;
-	t547 = t394 * t30;
-	t550 = t212 * t19;
-	t553 = t366 * t441;
-	t556 = n * t17;
-	t571 = -0.8e1 * t427 * t131 + 0.16e2 * t394 * t536 * t538 + 0.16e2 * t541 * t336 + 0.2e1 * t453 * t129 * t158 - 0.8e1 * t547 * t147 + 0.4e1 * t503 * t550 - 0.8e1 * t553 * t270 + 0.4e1 * t556 * ZB * t92 * t39 - 0.2e1 * t67 * t91 * t99 - t82 * t425 + 0.4e1 * t78 * t275 + 0.2e1 * t78 * xc * t41 * t57;
-	t583 = t90 * t317;
-	t594 = t212 * t158;
-	t596 = t152 * t67;
-	t602 = t67 * t17;
-	t607 = 0.8e1 * t367 * t407 - 0.4e1 * t98 * t99 * t59 + 0.16e2 * t260 * t18 * ZA * t57 + 0.2e1 * t321 * t583 - 0.6e1 * t174 * t368 * t52 - 0.4e1 * t89 * t90 * ZA * t15 * t12 + t116 * t594 - 0.8e1 * t596 * t136 - 0.4e1 * t98 * t99 * t327 + 0.2e1 * t602 * t99 + 0.2e1 * t164 * t583;
-	t613 = t83 * t25;
-	t616 = t81 * t156;
-	t627 = t90 * t231;
-	t630 = t91 * t16;
-	t638 = 0.4e1 * t196 * t90 * t208 - 0.8e1 * t130 * t60 - 0.2e1 * t613 * t99 + 0.6e1 * t616 * t197 - 0.8e1 * t547 * t131 + 0.8e1 * t67 * t18 * t37 * t142 + 0.2e1 * t145 * t328 - 0.6e1 * t196 * t627 + 0.8e1 * t630 * t67 * t142 - 0.8e1 * t547 * t275 + 0.8e1 * t395 * t209;
-	t643 = t77 * t355;
-	t648 = t115 * t458;
-	t651 = t134 * t67;
-	t657 = t30 * t304;
-	t660 = t30 * t146;
-	t665 = t25 * t17;
-	t668 = t50 * t424;
-	t671 = -0.4e1 * t321 * t90 * t146 - 0.6e1 * t643 * t232 + 0.8e1 * t182 * t209 - 0.16e2 * t648 * t510 + 0.8e1 * t651 * t136 + 0.8e1 * t89 * t4 * t100 - 0.2e1 * t374 * t657 - 0.8e1 * t648 * t660 + 0.8e1 * t130 * t328 + 0.2e1 * t665 * t99 + 0.2e1 * t346 * t668;
-	t672 = t90 * t424;
-	t676 = t120 * t536;
-	t680 = t436 * t41;
-	t688 = t366 * t67 * t440;
-	t696 = xc * t12;
-	t697 = t696 * t18;
-	t701 = t252 * t141;
-	t702 = t90 * t221;
-	t705 = 0.2e1 * t196 * t672 - t47 * t347 + 0.16e2 * t676 * t538 - t116 * t85 - 0.2e1 * t253 * t680 + t207 * t194 + 0.4e1 * t98 * t99 * t19 - 0.8e1 * t688 * t433 + 0.16e2 * t541 * t301 - 0.6e1 * t312 * t190 + 0.4e1 * t352 * t88 * t35 * t697 + 0.2e1 * t701 * t702;
-	t712 = t24 * t430;
-	t713 = t28 * t49;
-	t721 = t1 * t17 * t11;
-	t726 = ZB * xc;
-	t737 = n * t91;
-	t741 = 0.8e1 * t346 * t209 + 0.2e1 * t712 * t713 * t424 + 0.8e1 * t130 * t275 - t47 * t668 + t116 * t721 - 0.8e1 * t688 * t513 + 0.4e1 * t352 * t27 * t212 * t726 + 0.8e1 * t648 * t463 + 0.4e1 * t274 * t60 - 0.4e1 * t374 * t355 * t208 - 0.4e1 * t253 * t737 * t41;
-	t745 = t269 * t231;
-	t749 = t1 * t28 * t265;
-	t757 = t16 * t39;
-	t758 = t696 * t757;
-	t762 = t69 * t49;
-	t772 = t355 * t100;
-	t775 = t81 * t353;
-	t778 = -0.8e1 * t398 * t90 * t190 - 0.2e1 * t278 * t745 + 0.4e1 * t749 * t53 + 0.32e2 * t394 * t29 * t28 * t17 * t40 - 0.8e1 * t78 * t758 + t350 * n * t762 - 0.6e1 * t87 * t49 * t186 * t52 - 0.8e1 * t553 * t407 - 0.4e1 * t749 * t209 + 0.16e2 * t648 * t772 - 0.6e1 * t775 * t375;
-	t790 = t212 * t304;
-	t793 = t156 * 0.3141592654e1;
-	t795 = t355 * t304;
-	t800 = t91 * t39;
-	t801 = t800 * n;
-	t807 = t2 * t28;
-	t808 = t807 * t726;
-	t811 = -0.2e1 * t616 * t672 - 0.2e1 * t446 * t680 - 0.2e1 * t78 * xc * t58 * t57 + 0.8e1 * t367 * t270 - t82 * t790 + t115 * t51 * t793 - 0.2e1 * t775 * t795 + 0.8e1 * t123 * t209 + 0.2e1 * t665 * t801 - 0.2e1 * t67 * t41 * t64 - 0.32e2 * t808 * t43;
-	t812 = t117 * t51;
-	t821 = t24 * t355;
-	t827 = t90 * t304;
-	t840 = t800 * t41;
-	t844 = -t116 * t812 - 0.2e1 * t110 * t25 * t58 * t57 - 0.4e1 * t78 * t328 + t82 * t485 - 0.4e1 * t821 * t407 + 0.4e1 * t196 * t90 * t52 + 0.2e1 * t196 * t827 + t82 * t325 + 0.2e1 * t253 * t448 - 0.32e2 * t402 * t67 * t807 * t490 - t207 * t232 + 0.12e2 * t186 * t90 * ZB * t37 * t840;
-	t849 = t1 * t51;
-	t850 = t849 * t17;
-	t860 = t269 * t424;
-	t863 = t273 * t187;
-	t874 = 0.16e2 * t462 * t772 - t116 * t850 + 0.16e2 * t553 * t371 + t116 * t288 - 0.12e2 * t97 * t57 * t109 * t697 + t82 * t594 - 0.2e1 * t278 * t860 - 0.2e1 * t863 * t305 - 0.16e2 * t180 * t259 * t311 * t201 - 0.6e1 * t863 * t74 + 0.8e1 * t174 * t191;
-	t879 = xc * ZA;
-	t888 = t67 * t51;
-	t901 = ZA * t17;
-	t903 = t368 * t901 * t11;
-	t908 = -0.2e1 * t352 * t51 * t156 * t35 + 0.64e2 * t879 * t189 * t807 * t40 + 0.2e1 * t46 * t58 * t37 * t39 - t888 * t50 + t105 * t411 - 0.16e2 * t335 * t301 + 0.8e1 * t152 * t25 * t136 - 0.8e1 * t278 * t407 + 0.2e1 * t712 * t713 * t231 - 0.16e2 * t367 * t903 + 0.2e1 * t145 * t318;
-	t923 = t71 * t424;
-	t926 = t87 * t458;
-	t927 = t28 * ZA;
-	t944 = 0.8e1 * t354 * t355 * t190 - 0.8e1 * t110 * t16 * t25 * t800 - 0.2e1 * t374 * t30 * t73 - 0.16e2 * t354 * t30 * t176 - 0.2e1 * t244 * t923 - 0.32e2 * t926 * t927 * t696 * t41 - 0.32e2 * t808 * t525 + 0.6e1 * t749 * t232 - 0.8e1 * t188 * t177 + 0.4e1 * t36 * t58 * ZA * t57 + 0.4e1 * t821 * t270;
-	t948 = t90 * t327;
-	t961 = t30 * t100;
-	t964 = t29 * t49;
-	t981 = t106 * t1;
-	t983 = -0.2e1 * t219 * t220 * t100 + 0.2e1 * t321 * t948 - 0.16e2 * t189 * ZA * t99 * t12 - 0.2e1 * t369 * n * t69 * t368 + 0.2e1 * t374 * t795 - 0.8e1 * t462 * t961 - 0.8e1 * t244 * t964 * t208 + 0.2e1 * t413 * t923 + 0.4e1 * t36 * t38 * t40 * t58 - 0.2e1 * t87 * t51 * t49 * t1 * ZA + t888 * n * t762 + t115 * t981;
-	t1012 = 0.6e1 * t616 * t627 - t82 * t213 + 0.2e1 * t775 * t657 - 0.12e2 * t215 * t550 - 0.6e1 * t145 * t131 + 0.2e1 * t81 * t41 * t204 + 0.6e1 * ZB * t48 * t49 * t370 - 0.4e1 * t70 * t382 + 0.2e1 * t446 * t255 + 0.8e1 * t89 * t4 * t327 - 0.4e1 * t56 * t147;
-	t1018 = t212 * t100;
-	t1029 = t212 * t327;
-	t1040 = 0.6e1 * t70 * t245 + 0.2e1 * t56 * t328 + t207 * t668 + 0.4e1 * t503 * t1018 + 0.2e1 * t253 * t470 - 0.6e1 * t398 * t35 * t208 - 0.8e1 * t331 * t964 * t52 - 0.4e1 * t503 * t1029 + 0.6e1 * t821 * t745 + 0.4e1 * t63 * t37 * t142 + 0.16e2 * t260 * t38 * t840;
-	t1068 = t207 * t347 - 0.2e1 * t164 * t702 - 0.2e1 * t331 * t964 * t73 + 0.8e1 * t374 * t30 * t52 + 0.16e2 * t278 * t903 + 0.2e1 * t863 * t923 + 0.6e1 * t445 * t141 * t165 - 0.2e1 * t164 * t90 * t100 + 0.6e1 * t331 * t74 - 0.2e1 * t182 * t668 - 0.2e1 * t115 * t41 * t204;
-	t1079 = t58 * t8;
-	t1091 = t807 * t29;
-	t1092 = t665 * t40;
-	t1101 = ZB * t91;
-	t1102 = t403 * n;
-	t1105 = -0.4e1 * t58 * ZB * ZA * t64 - t82 * t850 + 0.2e1 * t821 * t860 + t81 * t51 * t793 + 0.2e1 * t3 * t25 * t1079 * t90 + t82 * t721 - 0.2e1 * t643 * t668 + 0.16e2 * t926 * t927 * t29 * t91 * t41 + 0.32e2 * t1091 * t1092 - 0.2e1 * t219 * t220 * t19 + 0.4e1 * t139 * ZA * t64 + 0.4e1 * t1101 * t1102;
-	t1108 = t849 * t72;
-	t1121 = t737 * t15;
-	t1124 = t29 * t12;
-	t1133 = t116 * t1108 - 0.8e1 * t475 * t209 - 0.32e2 * t807 * xc * t1092 + 0.2e1 * t278 * t269 * t73 + t82 * t812 - 0.6e1 * t56 * t131 + 0.2e1 * t253 * t1121 + 0.16e2 * t926 * t927 * t1124 * t41 + t168 * t263 - 0.2e1 * t616 * t827 + t81 * t981;
-	t1134 = t394 * t28;
-	t1159 = -0.8e1 * t1134 * t29 * t18 * t57 + t82 * t118 - 0.12e2 * t215 * t1018 + 0.2e1 * t602 * t801 - t168 * t341 + 0.2e1 * t67 * t58 * t64 + t168 * t344 - 0.6e1 * t174 * t368 * t208 + 0.16e2 * t553 * t903 + t116 * t790 - 0.4e1 * t36 * t38 * t800 * t15;
-	t1161 = n * t83;
-	t1173 = ZB * t12;
-	t1196 = 0.4e1 * t1161 * ZB * t39 * ZA - 0.4e1 * t215 * t1029 - 0.8e1 * t488 * 0.3141592654e1 * t39 * xc + 0.32e2 * t821 * ZA * t8 * t1173 * t18 - 0.8e1 * t427 * t147 + 0.6e1 * t701 * t165 - 0.16e2 * t926 * t927 * t1124 * t18 - 0.8e1 * t1091 * t63 * t57 - 0.8e1 * t442 * t209 - 0.8e1 * t462 * t660 - 0.6e1 * t398 * t35 * t52;
-	t1228 = 0.2e1 * t413 * t305 - 0.8e1 * t648 * t961 - 0.16e2 * t87 * t27 * t23 * t28 * ZA * t29 + 0.4e1 * t189 * t1102 - 0.4e1 * t87 * t1079 * t212 * t879 + 0.2e1 * t164 * t948 - 0.2e1 * t70 * t923 + 0.2e1 * t164 * t322 + 0.2e1 * t446 * t1121 + 0.2e1 * t863 * t964 * t304 - t82 * t1108 + 0.16e2 * t676 * t490 * t19;
-	t1234 = t25 * ZB;
-	t1235 = t1234 * t28;
-	t1236 = t365 * t91;
-	t1240 = ZB * t121;
-	t1241 = t1240 * t77;
-	t1242 = t39 * t39;
-	t1243 = t12 * t1242;
-	t1244 = xc * t72;
-	t1245 = t1243 * t1244;
-	t1248 = t365 * t25;
-	t1252 = t243 * n;
-	t1257 = t23 * t1;
-	t1258 = t1240 * t1257;
-	t1259 = t67 * t12;
-	t1260 = xc * t16;
-	t1268 = t1234 * t121;
-	t1269 = t1268 * t23;
-	t1272 = t1242 * t91;
-	t1280 = t67 * xc;
-	t1284 = t28 * t28;
-	t1285 = t67 * t1284;
-	t1287 = t1285 * t2 * ZB;
-	t1288 = t17 * xc;
-	t1289 = t1243 * t1288;
-	t1292 = 0.2e1 * t1235 * t1236 * t17 + 0.8e1 * t1241 * t1245 + 0.4e1 * t927 * t1248 * t91 - 0.2e1 * t1252 * ZB * t1242 * t91 - 0.8e1 * t1258 * t1259 * t1260 - 0.4e1 * t1235 * t2 * t83 * t39 + 0.16e2 * t1269 * t758 + 0.2e1 * t1252 * t189 * t1272 - 0.2e1 * t1252 * t83 * t1242 * ZB + 0.8e1 * t1258 * t630 * t1280 - 0.32e2 * t1287 * t1289;
-	t1293 = t365 * t83;
-	t1300 = ZA * t1284;
-	t1304 = t17 * t1242 * t25 * t12;
-	t1307 = t927 * t2;
-	t1311 = t23 * t2;
-	t1312 = t1300 * t1311;
-	t1316 = t1234 * t1284;
-	t1317 = t1316 * t1311;
-	t1321 = t1240 * t23;
-	t1331 = t1240 * t23 * t67;
-	t1332 = t40 * t1244;
-	t1338 = t1243 * t1260;
-	t1344 = -0.2e1 * t1235 * t1293 - 0.16e2 * t181 * t365 * t901 * t12 - 0.64e2 * t1300 * t258 * t1304 + 0.8e1 * t1307 * t613 * t39 + 0.64e2 * t1312 * t265 * t402 - 0.32e2 * t1317 * t1288 * t12 - 0.16e2 * t1321 * t67 * t39 * t1244 + 0.2e1 * t1235 * n * t1272 * t17 + 0.16e2 * t1331 * t1332 + 0.64e2 * t1300 * t292 * t1304 - 0.8e1 * t1241 * t1338 - 0.2e1 * t243 * t1293 * ZB;
-	t1346 = t1316 * t2;
-	t1349 = t927 * n;
-	t1350 = t25 * t1242;
-	t1354 = t1268 * t1257;
-	t1366 = t1268 * t1;
-	t1370 = t29 * t17;
-	t1371 = t1243 * t1370;
-	t1386 = -0.32e2 * t1346 * t1289 + 0.4e1 * t1349 * t1350 * t91 + 0.8e1 * t1354 * t1260 * t12 - 0.16e2 * t181 * n * t901 * t1243 - 0.4e1 * t1235 * t2 * t91 * t39 + 0.8e1 * t1366 * t152 * t1242 + 0.32e2 * t1287 * t1371 + 0.8e1 * t1258 * t1280 * t152 - 0.8e1 * t1354 * t1260 * t91 + 0.128e3 * t1300 * t365 * xc * t1092 + 0.8e1 * t1366 * t1338;
-	t1387 = t1257 * t12;
-	t1391 = t1240 * t1;
-	t1399 = t1272 * t1260;
-	t1412 = t1285 * t1311;
-	t1427 = -0.8e1 * t1268 * t1387 * t16 - 0.8e1 * t1391 * t67 * t1242 * t1244 - 0.4e1 * t1134 * t1101 * t39 + 0.8e1 * t1241 * t1399 - 0.8e1 * t1258 * t596 + 0.4e1 * t927 * t1293 * t25 - 0.16e2 * t1331 * t758 + 0.8e1 * t1307 * t665 * t39 + 0.32e2 * t1412 * t1370 * t1173 + 0.8e1 * t1307 * t665 * t800 + 0.8e1 * t1391 * t1259 * t1242 * t16 - 0.8e1 * t1391 * t1259 * t1242 * t72;
-	t1456 = t365 * ZB;
-	t1468 = 0.4e1 * t927 * t1248 * t17 - 0.2e1 * t1235 * n * t1242 * t91 + 0.8e1 * t1366 * t1244 * t1242 - 0.16e2 * t1269 * t134 * t39 + 0.8e1 * t1268 * t1257 * t72 * xc + 0.16e2 * t1321 * t1259 * t757 + 0.32e2 * t1317 * t1370 * t12 + 0.4e1 * t1349 * t613 * t1242 + 0.2e1 * t243 * t1456 * t17 - 0.64e2 * t1285 * t365 * t12 * t189 * t490 - 0.8e1 * t1354 * t152 * xc;
-	t1472 = t1316 * t365;
-	t1474 = t1124 * t39 * t17;
-	t1478 = t17 * t91;
-	t1504 = t72 * t39;
-	t1511 = 0.4e1 * t1134 * t189 * t800 + 0.64e2 * t1472 * t1474 + 0.4e1 * t1235 * t2 * t1478 * t39 + 0.4e1 * t1349 * t665 * t1242 - 0.8e1 * t1258 * t1280 * t72 + 0.2e1 * t1252 * t189 * t1242 + 0.2e1 * t243 * t365 * t189 * t91 + 0.4e1 * t927 * t365 * t1478 * t25 - 0.128e3 * t1300 * t1248 * t1474 - 0.2e1 * t1235 * t1236 + 0.16e2 * t1269 * t1504 * xc + 0.2e1 * t1235 * t365 * t17;
-	t1545 = -0.2e1 * t1235 * t1161 * t1242 + 0.4e1 * t1349 * t1350 * t1478 - 0.8e1 * t1366 * t1245 + 0.2e1 * t1235 * t556 * t1242 - 0.32e2 * t1412 * t402 * t726 - 0.8e1 * t1366 * t1399 + 0.8e1 * t1258 * t651 - 0.2e1 * t243 * t1456 * t91 + 0.8e1 * t1268 * t1387 * t72 - 0.16e2 * t1269 * t1332 + 0.4e1 * t1134 * t189 * t39 + 0.16e2 * t1269 * t152 * t39;
-	t1564 = t1260 * t800;
-	t1583 = 0.64e2 * t1285 * t1456 * t1474 - 0.64e2 * t1472 * t1288 * t40 - 0.8e1 * t1366 * t134 * t1242 + 0.8e1 * t1307 * t362 * t39 + 0.4e1 * t1235 * t2 * t17 * t39 + 0.32e2 * t1346 * t1371 - 0.16e2 * t1269 * t1564 - 0.16e2 * t1321 * t1259 * t1504 + 0.16e2 * t1331 * t1564 - 0.64e2 * t1312 * t29 * t25 * t402 - 0.4e1 * t1134 * t83 * t39 * ZB - 0.32e2 * t181 * t2 * t404;
-	
-	_C2B = (t1133 + t1196 + t1068 + t811 + t466 + t1012 + t381 + t162 + t249 + t533 + t844 + t104 + t1159 + t571 + t211 + t874 + t607 + t339 + t296 + t638 + t908 + t671 + t419 + t983 + t705 + t1105 + t501 + t778 + t1040 + t1228 + t741 + t944) / (t1292 + t1344 + t1386 + t1427 + t1468 + t1511 + t1545 + t1583);
-	/****************************************************************************************/
-	t1 = n * n;
-	t2 = t1 * n;
-	t3 = t2 * nx;
-	t4 = nx * 0.3141592654e1;
-	t5 = t4 * xc;
-	t6 = sin(t5);
-	t7 = 0.3141592654e1 * 0.3141592654e1;
-	t9 = t3 * t6 * t7;
-	t10 = xc * xc;
-	t11 = ZA * ZA;
-	t12 = t10 * t11;
-	t13 = n * 0.3141592654e1;
-	t14 = exp(t13);
-	t15 = t14 * t14;
-	t16 = xc * n;
-	t18 = exp(t16 * 0.3141592654e1);
-	t19 = t18 * t18;
-	t20 = t19 * t18;
-	t21 = t15 * t20;
-	t22 = t12 * t21;
-	t25 = nx * t6;
-	t26 = t1 * 0.3141592654e1;
-	t27 = t25 * t26;
-	t28 = ZA * ZB;
-	t29 = t18 * t15;
-	t30 = t28 * t29;
-	t33 = t25 * n;
-	t34 = t11 * t15;
-	t35 = t19 * t19;
-	t36 = t35 * t18;
-	t40 = t25 * t1;
-	t41 = 0.3141592654e1 * t11;
-	t42 = t15 * t36;
-	t43 = t41 * t42;
-	t46 = nx * nx;
-	t47 = t1 * t46;
-	t48 = t47 * t11;
-	t49 = t7 * xc;
-	t50 = t35 * t15;
-	t51 = t49 * t50;
-	t55 = sin(t4);
-	t56 = t46 * nx * t55;
-	t58 = t56 * n * t7;
-	t59 = ZB * ZB;
-	t60 = t10 * t59;
-	t61 = t15 * t14;
-	t62 = t19 * t61;
-	t63 = t60 * t62;
-	t66 = t19 * t14;
-	t67 = t60 * t66;
-	t70 = t28 * t42;
-	t73 = cos(t5);
-	t74 = t47 * t73;
-	t75 = t7 * t11;
-	t77 = t75 * t10 * t36;
-	t80 = t73 * t46;
-	t81 = t80 * n;
-	t82 = 0.3141592654e1 * t59;
-	t83 = t82 * t42;
-	t87 = xc * t11;
-	t88 = t87 * t62;
-	t91 = n * nx;
-	t92 = t55 * t61;
-	t96 = nx * t55;
-	t98 = t96 * t2 * t7;
-	t101 = xc * t59;
-	t102 = t101 * t62;
-	t108 = t1 * t1;
-	t109 = t108 * t7;
-	t111 = t59 * t35;
-	t112 = t111 * t15;
-	t115 = t35 * t20;
-	t123 = t1 * nx * t55;
-	t124 = t61 * t35;
-	t127 = t35 * t19;
-	t128 = t61 * t127;
-	t129 = t60 * t128;
-	t132 = t56 * t16;
-	t133 = t7 * t59;
-	t134 = t133 * t124;
-	t137 = 0.6e1 * t58 * t88 - 0.2e1 * t91 * t92 * t11 + 0.2e1 * t98 * t63 - 0.6e1 * t58 * t102 - 0.2e1 * t91 * t92 * t59 - 0.16e2 * t109 * xc * t112 - 0.2e1 * t91 * t6 * t115 * t59 + 0.12e2 * t40 * t83 + t123 * t41 * t124 - 0.2e1 * t58 * t129 + 0.4e1 * t132 * t134;
-	t139 = t56 * 0.3141592654e1;
-	t140 = t111 * t14;
-	t144 = t49 * t124;
-	t147 = t91 * t55;
-	t148 = t61 * ZA;
-	t154 = ZA * t115 * xc * ZB;
-	t157 = t7 * 0.3141592654e1;
-	t159 = t96 * t108 * t157;
-	t160 = t10 * xc;
-	t161 = t160 * t59;
-	t162 = t35 * t14;
-	t163 = t161 * t162;
-	t166 = t28 * t162;
-	t169 = t80 * t13;
-	t170 = t101 * t42;
-	t173 = t2 * t11;
-	t174 = t96 * t173;
-	t175 = t7 * t10;
-	t179 = t59 * t15;
-	t184 = t15 * t15;
-	t193 = t139 * t140 + 0.4e1 * t56 * n * t11 * t144 + 0.4e1 * t147 * t148 * ZB + 0.4e1 * t27 * t154 + 0.8e1 * t159 * t163 - 0.12e2 * t147 * t166 + 0.2e1 * t169 * t170 - 0.16e2 * t174 * t175 * t124 + 0.2e1 * t33 * t179 * t20 - 0.2e1 * t33 * t11 * t36 * t184 + 0.2e1 * t56 * t61 * 0.3141592654e1 * ZA * ZB;
-	t194 = t173 * 0.3141592654e1;
-	t195 = xc * t15;
-	t196 = t195 * t19;
-	t202 = t15 * t115;
-	t203 = t28 * t202;
-	t206 = t96 * t26;
-	t207 = t14 * t127;
-	t208 = t101 * t207;
-	t211 = t12 * t128;
-	t218 = t11 * t61;
-	t219 = t218 * t35;
-	t221 = t108 * ZA;
-	t223 = t7 * ZB;
-	t224 = t223 * t50;
-	t227 = ZA * xc;
-	t228 = ZB * t15;
-	t229 = t228 * t36;
-	t230 = t227 * t229;
-	t233 = t87 * t207;
-	t236 = t6 * t11;
-	t240 = -0.4e1 * t194 * t196 + 0.4e1 * t194 * t195 * t127 + 0.4e1 * t33 * t203 - 0.12e2 * t206 * t208 + 0.2e1 * t58 * t211 - 0.16e2 * t47 * t10 * t133 * t50 + t139 * t219 - 0.32e2 * t221 * t10 * t224 - 0.4e1 * t169 * t230 - 0.6e1 * t98 * t233 + 0.2e1 * t91 * t236 * t20;
-	t244 = t227 * t228 * t20;
-	t252 = t184 * t18;
-	t253 = t101 * t252;
-	t256 = t35 * t35;
-	t257 = t256 * t14;
-	t258 = t28 * t257;
-	t261 = t108 * t11;
-	t263 = t7 * t35;
-	t268 = ZB * t61 * t35;
-	t273 = t96 * t108 * t160;
-	t274 = t157 * ZB;
-	t276 = t274 * t148 * t35;
-	t279 = t101 * t21;
-	t282 = 0.3141592654e1 * xc;
-	t283 = t59 * t36;
-	t284 = t282 * t283;
-	t289 = 0.4e1 * t169 * t244 - 0.4e1 * t132 * t133 * t162 - 0.2e1 * t147 * t140 - 0.2e1 * t27 * t253 + 0.2e1 * t139 * t258 + 0.16e2 * t261 * t10 * t263 * t15 - 0.16e2 * t206 * t227 * t268 - 0.16e2 * t273 * t276 - 0.6e1 * t27 * t279 - 0.4e1 * t40 * t284 - 0.32e2 * t9 * t230;
-	t290 = t1 * t11;
-	t291 = t96 * t290;
-	t297 = t59 * t61;
-	t298 = t297 * t127;
-	t300 = ZB * t36;
-	t301 = t227 * t300;
-	t304 = t1 * t59;
-	t305 = t184 * t35;
-	t310 = t46 * ZB;
-	t311 = t184 * ZA;
-	t312 = t310 * t311;
-	t314 = t60 * t21;
-	t317 = t1 * ZA;
-	t318 = ZB * t35;
-	t321 = t1 * t256;
-	t324 = t96 * t261;
-	t325 = t10 * t157;
-	t326 = t325 * t124;
-	t329 = -0.4e1 * t291 * t282 * t128 + t123 * t82 * t62 - t139 * t298 + 0.12e2 * t27 * t301 + t304 * t305 - 0.2e1 * t58 * t12 * t66 - 0.2e1 * t312 + 0.8e1 * t9 * t314 + 0.2e1 * t317 * t318 + 0.2e1 * t321 * t28 - 0.8e1 * t324 * t326;
-	t331 = t28 * t124;
-	t334 = 0.3141592654e1 * t15;
-	t335 = t334 * t127;
-	t338 = t35 * ZA;
-	t341 = t46 * t256;
-	t344 = t46 * t11;
-	t346 = t46 * t59;
-	t348 = t297 * t35;
-	t351 = ZA * t10;
-	t352 = t351 * t300;
-	t355 = t1 * ZB;
-	t362 = 0.12e2 * t147 * t331 - 0.4e1 * t173 * t335 - 0.2e1 * t310 * t338 - 0.2e1 * t341 * t28 - t344 * t305 - t346 * t305 + 0.2e1 * t147 * t348 + 0.16e2 * t9 * t352 + 0.2e1 * t355 * t311 + t290 * t305 + 0.2e1 * t33 * t34 * t20;
-	t363 = t36 * t184;
-	t364 = t87 * t363;
-	t368 = t47 * t73 * t7;
-	t373 = t160 * t157;
-	t374 = t373 * t124;
-	t377 = t311 * t35;
-	t380 = t12 * t62;
-	t386 = ZB * t10 * ZA * t15 * t20;
-	t389 = t87 * t66;
-	t393 = t56 * t1 * t10;
-	t401 = 0.2e1 * t27 * t364 - 0.16e2 * t368 * t279 - t123 * t41 * t257 + 0.8e1 * t324 * t374 + 0.2e1 * t355 * t377 - 0.2e1 * t98 * t380 - 0.16e2 * t9 * t386 + 0.2e1 * t58 * t389 + 0.16e2 * t393 * t276 + t123 * t82 * t162 - 0.2e1 * t33 * t179 * t36;
-	t412 = t11 * t14 * t127;
-	t416 = t11 * t19;
-	t417 = t416 * t61;
-	t421 = t96 * t2 * ZA;
-	t426 = t56 * n * ZA;
-	t427 = t318 * t14;
-	t428 = t49 * t427;
-	t431 = t82 * t29;
-	t434 = t87 * t21;
-	t442 = 0.2e1 * t33 * t11 * t184 * t18 + 0.4e1 * t81 * t284 - t139 * t412 + 0.2e1 * t147 * t219 - 0.2e1 * t147 * t417 + 0.32e2 * t421 * t175 * t268 + 0.8e1 * t426 * t428 + 0.4e1 * t81 * t431 - 0.2e1 * t169 * t434 - 0.2e1 * t98 * t129 - 0.32e2 * t47 * t28 * t51;
-	t443 = t184 * t20;
-	t447 = t61 * 0.3141592654e1;
-	t448 = t447 * t11;
-	t450 = t49 * t268;
-	t453 = t60 * t42;
-	t456 = t41 * t202;
-	t463 = t101 * t443;
-	t469 = t41 * xc * t20;
-	t474 = -0.8e1 * t27 * t87 * t443 - t56 * t448 - 0.8e1 * t426 * t450 + 0.8e1 * t368 * t453 + 0.4e1 * t40 * t456 + 0.4e1 * t40 * t431 - 0.4e1 * t81 * t456 - 0.4e1 * t27 * t463 + 0.6e1 * t139 * t331 + 0.2e1 * t40 * t469 - 0.16e2 * t9 * t434;
-	t482 = t108 * t10;
-	t492 = n * t46;
-	t493 = t492 * t11;
-	t495 = t282 * t19 * t184;
-	t498 = t56 * t290;
-	t499 = t325 * t162;
-	t502 = t416 * t14;
-	t504 = t60 * t207;
-	t507 = -t123 * t82 * t257 - 0.4e1 * t169 * t301 + t123 * t41 * t162 + 0.16e2 * t482 * t7 * t112 - 0.12e2 * t206 * t102 - t123 * t82 * t66 - 0.4e1 * t147 * t258 - 0.4e1 * t493 * t495 - 0.8e1 * t498 * t499 + t139 * t502 - 0.2e1 * t98 * t504;
-	t508 = t101 * t162;
-	t512 = t41 * t115 * xc;
-	t515 = t87 * t42;
-	t520 = ZB * t184;
-	t522 = t227 * t520 * t18;
-	t525 = t492 * t59;
-	t528 = t6 * t59;
-	t532 = t520 * t20;
-	t533 = t351 * t532;
-	t539 = t447 * t59;
-	t544 = 0.8e1 * t206 * t508 - 0.2e1 * t40 * t512 - 0.16e2 * t368 * t515 + 0.12e2 * t206 * t88 + 0.4e1 * t27 * t522 + 0.4e1 * t525 * t495 - 0.4e1 * t91 * t528 * t36 - 0.16e2 * t368 * t533 - 0.16e2 * t206 * t227 * t427 - t56 * t539 - 0.2e1 * t132 * t133 * t66;
-	t551 = t87 * t162;
-	t554 = t351 * t229;
-	t560 = t59 * t19;
-	t561 = t560 * t14;
-	t564 = t101 * t202;
-	t567 = t87 * t252;
-	t573 = t227 * t228 * t115;
-	t578 = 0.4e1 * t33 * t70 + 0.4e1 * t493 * t335 - 0.4e1 * t58 * t551 + 0.16e2 * t9 * t554 - 0.4e1 * t33 * t28 * t252 + 0.2e1 * t147 * t561 + 0.2e1 * t169 * t564 - 0.2e1 * t27 * t567 - 0.8e1 * t324 * t499 - 0.4e1 * t169 * t573 + 0.12e2 * t27 * t244;
-	t579 = t82 * t202;
-	t591 = t282 * t115 * t59;
-	t598 = t101 * t66;
-	t606 = -0.4e1 * t81 * t579 - 0.2e1 * t169 * t567 - 0.6e1 * t27 * t170 + 0.8e1 * t169 * t203 + 0.2e1 * t98 * t67 + 0.2e1 * t81 * t591 + 0.32e2 * t368 * t244 - 0.2e1 * t27 * t564 + 0.4e1 * t206 * t598 + 0.16e2 * t9 * t170 + 0.2e1 * t33 * t283 * t184;
-	t608 = t373 * t162;
-	t611 = t59 * t184;
-	t617 = t101 * t29;
-	t624 = t227 * ZB * t18 * t15;
-	t629 = t157 * t59;
-	t630 = t629 * t124;
-	t633 = t3 * t6;
-	t634 = t175 * t283;
-	t644 = 0.8e1 * t498 * t608 + 0.2e1 * t33 * t611 * t18 - 0.4e1 * t206 * t389 - 0.2e1 * t27 * t617 - 0.4e1 * t169 * t154 + 0.4e1 * t27 * t624 + 0.12e2 * t27 * t230 - 0.8e1 * t393 * t630 - 0.8e1 * t633 * t634 + 0.16e2 * t47 * t7 * t101 * t50 + 0.2e1 * t123 * t447 * t28;
-	t645 = t41 * t29;
-	t648 = t2 * 0.3141592654e1;
-	t649 = t648 * xc;
-	t650 = t560 * t184;
-	t656 = t56 * t1 * t157;
-	t659 = t87 * t128;
-	t662 = t96 * t482;
-	t663 = t629 * t162;
-	t671 = t161 * t124;
-	t674 = t218 * t127;
-	t679 = 0.4e1 * t81 * t645 - 0.4e1 * t649 * t650 - 0.8e1 * t169 * t70 + 0.8e1 * t656 * t163 - 0.2e1 * t98 * t659 - 0.8e1 * t662 * t663 - 0.32e2 * t421 * t175 * t427 - 0.2e1 * t147 * t502 + 0.8e1 * t656 * t671 + 0.2e1 * t147 * t674 - 0.16e2 * t368 * t386;
-	t714 = t334 * t19;
-	t719 = t12 * t42;
-	t722 = t304 * t35 - t346 * t35 + t341 * t59 - t344 * t35 + t344 * t256 + t346 * t184 - 0.16e2 * t368 * t554 - 0.16e2 * t48 * t175 * t50 + 0.4e1 * t525 * t714 - 0.2e1 * t58 * t659 + 0.8e1 * t368 * t719;
-	t730 = xc * t19;
-	t735 = t59 * t256 * t14;
-	t752 = 0.4e1 * t173 * t714 - 0.6e1 * t27 * t515 - 0.16e2 * t9 * t279 + 0.4e1 * t194 * t730 * t184 - t139 * t735 - 0.4e1 * t492 * t127 * t82 * xc - 0.4e1 * t98 * t508 - t123 * t41 * t207 - 0.2e1 * t147 * t298 + 0.8e1 * t368 * t314 + 0.6e1 * t132 * t133 * t207;
-	t755 = t28 * t21;
-	t759 = t274 * t338 * t14;
-	t767 = t11 * t35;
-	t768 = t767 * t14;
-	t778 = t560 * t61;
-	t781 = -0.2e1 * t58 * t504 - 0.8e1 * t27 * t755 + 0.16e2 * t662 * t759 + 0.12e2 * t291 * t282 * t207 - 0.6e1 * t27 * t434 + t139 * t768 - 0.8e1 * t498 * t326 + 0.4e1 * t33 * t611 * t20 + 0.2e1 * t81 * t512 - t139 * t561 + 0.2e1 * t147 * t778;
-	t786 = t12 * t443;
-	t790 = t282 * t59 * t20;
-	t796 = t59 * t14 * t127;
-	t806 = t41 * t21;
-	t811 = -0.8e1 * t393 * t663 + 0.8e1 * t368 * t786 + 0.2e1 * t81 * t790 + 0.4e1 * t169 * t624 + t139 * t796 + 0.2e1 * t206 * t258 - 0.2e1 * t40 * t591 - 0.8e1 * t662 * t630 - 0.4e1 * t33 * t30 - 0.4e1 * t40 * t806 + 0.8e1 * t9 * t786;
-	t819 = t282 * t15 * t127;
-	t822 = t101 * t363;
-	t830 = t11 * t256 * t14;
-	t835 = t227 * t532;
-	t842 = 0.2e1 * t33 * t11 * t18 * t15 + t123 * t41 * t66 - 0.4e1 * t493 * t819 - 0.2e1 * t27 * t822 - 0.16e2 * t368 * t170 - 0.4e1 * t169 * t463 - t139 * t830 - 0.4e1 * t649 * t179 * t127 + 0.12e2 * t27 * t835 - 0.16e2 * t368 * t434 - 0.2e1 * t40 * t790;
-	t845 = t87 * t202;
-	t854 = t338 * t15;
-	t859 = t12 * t207;
-	t868 = t139 * t348 - 0.2e1 * t27 * t845 + 0.8e1 * t169 * t755 - 0.2e1 * t58 * t380 + 0.6e1 * t206 * t331 + 0.8e1 * t310 * t854 - 0.2e1 * t169 * t822 + 0.2e1 * t98 * t859 + 0.8e1 * t159 * t671 + 0.8e1 * t74 * t634 - 0.2e1 * t169 * t253;
-	t880 = t60 * t443;
-	t891 = t101 * t128;
-	t894 = -t123 * t539 - 0.2e1 * t147 * t796 + 0.32e2 * t368 * t230 + t139 * t674 - 0.16e2 * t98 * t60 * t124 + 0.32e2 * t9 * t244 + 0.8e1 * t368 * t880 - 0.8e1 * t40 * t41 * xc * t36 - t123 * t82 * t128 - 0.6e1 * t58 * t233 + 0.2e1 * t58 * t891;
-	t903 = t179 * t19;
-	t920 = t56 * t1 * t160;
-	t925 = -0.2e1 * t174 * t175 * t66 - 0.4e1 * t493 * t714 + 0.4e1 * t649 * t903 - 0.4e1 * t81 * t43 + t123 * t82 * t207 + 0.4e1 * t206 * t891 - 0.16e2 * t273 * t759 - 0.8e1 * t27 * t203 + 0.32e2 * t221 * ZB * t51 - 0.16e2 * t920 * t759 - 0.8e1 * t9 * t453;
-	t932 = t87 * t29;
-	t945 = t82 * t21;
-	t953 = -0.16e2 * t920 * t276 - 0.8e1 * t169 * t30 - 0.8e1 * t633 * t77 - 0.2e1 * t27 * t932 - 0.4e1 * t174 * t49 * t162 + 0.8e1 * t206 * t87 * t124 - 0.2e1 * t147 * t768 + 0.4e1 * t169 * t522 - 0.12e2 * t81 * t945 + 0.4e1 * t33 * t28 * t115 + 0.4e1 * t525 * t819;
-	t971 = t282 * t127;
-	t978 = -0.6e1 * t98 * t102 + 0.2e1 * t169 * t515 - 0.2e1 * t310 * t377 + 0.2e1 * t147 * t830 + 0.8e1 * t368 * t22 - 0.2e1 * t169 * t617 + 0.16e2 * t662 * t276 - 0.8e1 * t355 * t854 + 0.4e1 * t493 * t971 - 0.16e2 * t9 * t533 - 0.2e1 * t169 * t279;
-	t997 = xc * t127;
-	t998 = t997 * t59;
-	t1003 = 0.4e1 * t40 * t579 + 0.2e1 * t169 * t845 + 0.16e2 * t9 * t515 + 0.8e1 * t206 * t551 + t123 * t41 * t128 + 0.16e2 * t98 * t60 * t162 + 0.2e1 * t169 * t364 - 0.2e1 * t169 * t932 + t139 * t778 + 0.4e1 * t648 * t998 + 0.2e1 * t147 * t412;
-	t1006 = t2 * t59;
-	t1017 = xc * t35;
-	t1033 = 0.4e1 * t1006 * t335 + 0.4e1 * t81 * t806 - 0.2e1 * t33 * t34 * t115 + 0.8e1 * t498 * t374 - 0.16e2 * t261 * t7 * t1017 * t15 + 0.8e1 * t206 * t101 * t124 - t123 * t448 + 0.2e1 * t147 * t735 + 0.6e1 * t98 * t208 + 0.6e1 * t98 * t88 - 0.4e1 * t33 * t755;
-	t1055 = -0.4e1 * t173 * t971 + 0.2e1 * t98 * t891 + 0.8e1 * t9 * t880 + 0.4e1 * t169 * t835 - t304 * t184 + t344 * t184 - t123 * t41 * t62 - 0.2e1 * t98 * t598 + 0.2e1 * t58 * t859 + 0.32e2 * t47 * t351 * t224 + 0.2e1 * t98 * t389;
-	t1070 = t15 * t19;
-	t1089 = -0.16e2 * t368 * t352 - 0.8e1 * t9 * t719 + 0.4e1 * t96 * t2 * xc * t134 - 0.2e1 * t91 * t236 * t115 + 0.4e1 * t27 * t573 + 0.4e1 * t493 * t282 * t1070 + 0.2e1 * t33 * t59 * t18 * t15 + 0.12e2 * t40 * t945 - 0.4e1 * t492 * xc * t82 * t1070 - 0.2e1 * t91 * t528 * t20 + 0.8e1 * t324 * t608;
-	t1113 = t123 * t82 * t124 + 0.8e1 * t421 * t428 - t139 * t417 + 0.4e1 * t40 * t645 + 0.16e2 * t393 * t759 - 0.2e1 * t33 * t179 * t115 - 0.4e1 * t525 * t335 + 0.4e1 * t33 * t28 * t36 - 0.4e1 * t1006 * t714 + 0.6e1 * t206 * t166 - 0.8e1 * t421 * t450;
-	t1119 = t321 * t46;
-	t1122 = t157 * t11;
-	t1123 = t1122 * t2;
-	t1124 = t184 * t46;
-	t1128 = t108 * n;
-	t1132 = t7 * t7;
-	t1133 = t1132 * t11;
-	t1134 = t1133 * t108;
-	t1135 = t15 * t46;
-	t1139 = t7 * ZA;
-	t1140 = t1139 * ZB;
-	t1141 = t1 * t35;
-	t1145 = t629 * t2;
-	t1146 = t1135 * t730;
-	t1149 = t157 * t1128;
-	t1150 = t1149 * xc;
-	t1153 = t46 * xc;
-	t1154 = t1153 * t127;
-	t1158 = t184 * t1 * t46;
-	t1161 = t46 * t46;
-	t1162 = t35 * t1161;
-	t1166 = t7 * t1;
-	t1170 = -0.4e1 * t133 * t1119 + 0.16e2 * t1123 * t1124 * t730 - 0.8e1 * t1122 * t1128 * t196 - 0.64e2 * t1134 * t1135 * t1017 - 0.32e2 * t1140 * t1141 * t1135 + 0.16e2 * t1145 * t1146 - 0.8e1 * t1150 * t650 - 0.16e2 * t1123 * t1154 - 0.4e1 * t133 * t1158 - 0.16e2 * t1140 * t1162 * t15 + 0.8e1 * t1166 * t35 * t312;
-	t1171 = t1161 * t184;
-	t1175 = t1122 * n;
-	t1176 = t15 * t1161;
-	t1180 = t1132 * ZA;
-	t1181 = t1180 * t355;
-	t1182 = t1176 * t1017;
-	t1185 = t1161 * xc;
-	t1189 = t1133 * t1;
-	t1192 = t108 * t1;
-	t1193 = t1132 * t1192;
-	t1195 = t10 * t35;
-	t1199 = t157 * t15;
-	t1203 = t1141 * t46;
-	t1211 = t184 * t108;
-	t1218 = 0.2e1 * t133 * t1171 * t35 + 0.8e1 * t1175 * t1176 * t997 + 0.64e2 * t1181 * t1182 - 0.8e1 * t1175 * t1185 * t127 - 0.32e2 * t1189 * t1182 - 0.64e2 * t1193 * ZA * t1195 * t228 + 0.8e1 * t1199 * t416 * t1128 + 0.8e1 * t1140 * t1203 - 0.4e1 * t75 * t1158 - 0.8e1 * t1199 * t560 * t1128 - 0.2e1 * t133 * t1211 - 0.8e1 * t1199 * t127 * t11 * t1128;
-	t1221 = t256 * t1161;
-	t1224 = t35 * t108;
-	t1233 = t7 * t256;
-	t1236 = -t75 * t1211 - t75 * t1221 - t133 * t1221 + t75 * t1224 - t75 * t1171 - t133 * t1171 + t133 * t1224 + t75 * t1162 - t75 * t108 * t256 + t133 * t1162 - t1233 * t59 * t108;
-	t1240 = t1135 * t1195;
-	t1252 = t629 * t127;
-	t1263 = t1171 * ZA;
-	t1280 = -0.128e3 * t1180 * ZB * t108 * t1240 + 0.32e2 * t1193 * t10 * t112 + 0.4e1 * t133 * t1203 + 0.4e1 * t109 * t256 * ZA * ZB - 0.8e1 * t1252 * n * t15 * t1185 + 0.8e1 * t1175 * t1171 * t730 - 0.8e1 * t1175 * t1176 * t127 + 0.4e1 * t223 * t1263 - 0.8e1 * t1175 * t1176 * t730 + 0.8e1 * t1166 * ZA * t341 * ZB + 0.64e2 * t1134 * t1240 + 0.8e1 * t1122 * xc * t1128 * t127 * t15;
-	t1283 = t1199 * t19;
-	t1287 = t1199 * t127;
-	t1289 = t59 * n * t1161;
-	t1293 = t157 * n * xc;
-	t1304 = t1132 * t108;
-	t1310 = t263 * ZB;
-	t1316 = t2 * t15;
-	t1323 = -0.16e2 * t1283 * t1006 * t46 + 0.8e1 * t1287 * t1289 + 0.8e1 * t1293 * t127 * t1161 * t59 + 0.16e2 * t1123 * t1135 * t19 + 0.8e1 * t1293 * t560 * t1176 + 0.64e2 * t1304 * t59 * t1240 + 0.4e1 * t75 * t1203 + 0.4e1 * t1310 * t1263 + 0.4e1 * t223 * t338 * t108 - 0.16e2 * t1252 * t1316 * t1153 - 0.16e2 * t1310 * t221 * t15;
-	t1330 = t1132 * t15;
-	t1336 = t1132 * t1;
-	t1338 = t1162 * t179;
-	t1370 = 0.8e1 * t1175 * t1176 * t19 + 0.4e1 * t1139 * t318 * t1161 + 0.128e3 * t1330 * t318 * t108 * t46 * t227 - 0.32e2 * t1336 * xc * t1338 + 0.4e1 * t1233 * ZA * t1161 * ZB - 0.8e1 * t1287 * t59 * t1128 * xc + 0.2e1 * t75 * t305 * t108 + 0.8e1 * t1199 * t127 * t59 * t1128 - 0.8e1 * t1283 * t1289 - 0.8e1 * t1293 * t560 * t1171 + 0.4e1 * t133 * t35 * t1158 + 0.8e1 * t157 * t184 * t19 * t11 * t1128 * xc;
-	t1376 = t7 * t184;
-	t1380 = t1176 * t1195;
-	t1393 = t1330 * t35;
-	t1411 = 0.16e2 * t1145 * t1154 + 0.8e1 * t1149 * t998 + 0.4e1 * t1376 * t35 * t48 + 0.32e2 * t1189 * t1380 + 0.32e2 * t1193 * t11 * t1195 * t15 - 0.64e2 * t1304 * xc * t111 * t1135 - 0.16e2 * t1123 * t1146 + 0.64e2 * t1393 * t28 * t1192 * xc - 0.16e2 * t1123 * t1135 * t127 - 0.8e1 * t1122 * xc * t1128 * t127 - 0.32e2 * t1193 * xc * t112 + 0.16e2 * t1252 * t1316 * t46;
-	t1450 = 0.2e1 * t1376 * t767 * t1161 + 0.2e1 * t1376 * t111 * t108 + 0.4e1 * t223 * t311 * t108 + 0.4e1 * t109 * t35 * t520 * ZA + 0.16e2 * t1123 * t1135 * t997 - 0.64e2 * t1181 * t1380 + 0.8e1 * t1150 * t903 - 0.32e2 * t1393 * t11 * t1192 * xc - 0.16e2 * t157 * t2 * xc * t560 * t1124 + 0.8e1 * t223 * t184 * t317 * t46 + 0.32e2 * t1336 * t10 * t1338 - 0.4e1 * t75 * t1119;
-	_C3B = (t606 + t722 + t1089 + t781 + 0.16e2 * t48 * t51 + t978 + t868 + t507 - t304 * t256 + 0.8e1 * t9 * t22 + t752 + 0.4e1 * t174 * t144 - 0.2e1 * t81 * t469 + 0.6e1 * t139 * t166 + t362 + 0.2e1 * t98 * t211 + t925 + t137 - t290 * t184 + 0.12e2 * t81 * t83 + t842 + 0.8e1 * t74 * t77 + 0.16e2 * t98 * t12 * t162 - 0.4e1 * t33 * t28 * t443 - 0.8e1 * t27 * t70 - 0.2e1 * t33 * t34 * t36 - 0.8e1 * t27 * t30 + 0.2e1 * t58 * t67 - 0.4e1 * t40 * t43 + 0.2e1 * t58 * t63 + t1033 - t290 * t256 + t290 * t35 + t193 + t1113 + t578 + t442 + t474 + t544 + t329 + t679 + t401 + t953 + t811 + t644 + t894 + t289 + t240 + t1055 + t1003) / (t1170 + t1218 + 0.2e1 * t1236 + t1280 + t1323 + t1370 + t1411 + t1450);
-	/****************************************************************************************/
-	t1 = n * n;
-	t2 = t1 * xc;
-	t3 = ZB * ZB;
-	t5 = t2 * 0.3141592654e1 * t3;
-	t6 = nx * 0.3141592654e1;
-	t7 = t6 * xc;
-	t8 = cos(t7);
-	t9 = nx * nx;
-	t10 = t8 * t9;
-	t11 = n * 0.3141592654e1;
-	t12 = exp(t11);
-	t13 = t12 * t12;
-	t16 = exp(xc * n * 0.3141592654e1);
-	t17 = t16 * t16;
-	t18 = t17 * t16;
-	t19 = t17 * t17;
-	t20 = t19 * t18;
-	t21 = t13 * t20;
-	t22 = t10 * t21;
-	t25 = ZA * ZA;
-	t26 = t1 * t25;
-	t27 = xc * 0.3141592654e1;
-	t28 = t26 * t27;
-	t29 = t19 * t16;
-	t30 = t13 * t13;
-	t31 = t29 * t30;
-	t35 = t9 * nx;
-	t36 = t3 * t35;
-	t37 = sin(t6);
-	t38 = t13 * t12;
-	t39 = t37 * t38;
-	t40 = t39 * t19;
-	t42 = t1 * t1;
-	t43 = nx * t42;
-	t44 = xc * xc;
-	t45 = t25 * t44;
-	t46 = t43 * t45;
-	t47 = 0.3141592654e1 * 0.3141592654e1;
-	t48 = t47 * t37;
-	t49 = t17 * t38;
-	t54 = 0.3141592654e1 * t35;
-	t55 = ZA * n * t54;
-	t56 = t37 * ZB;
-	t57 = t19 * t12;
-	t61 = t25 * t8;
-	t62 = t61 * t9;
-	t63 = n * t30;
-	t64 = t63 * t16;
-	t67 = t1 * n;
-	t69 = t47 * ZB;
-	t70 = t67 * t44 * t69;
-	t75 = nx * t3;
-	t76 = t75 * t37;
-	t77 = t67 * 0.3141592654e1;
-	t78 = t19 * t19;
-	t79 = t78 * t12;
-	t80 = t77 * t79;
-	t82 = t3 * t38;
-	t84 = t54 * t37;
-	t87 = sin(t7);
-	t88 = t29 * t87;
-	t89 = t47 * t44;
-	t93 = nx * t25;
-	t94 = t87 * t42;
-	t95 = t93 * t94;
-	t96 = t47 * xc;
-	t97 = t13 * t29;
-	t98 = t96 * t97;
-	t101 = t87 * t67;
-	t102 = t93 * t101;
-	t103 = t13 * t18;
-	t107 = t47 * t35;
-	t108 = t26 * t107;
-	t109 = t37 * t44;
-	t110 = t19 * t17;
-	t111 = t12 * t110;
-	t116 = t37 * t19 * t12;
-	t118 = t37 * xc;
-	t119 = ZB * t19;
-	t120 = t119 * t12;
-	t121 = t118 * t120;
-	t125 = xc * t3;
-	t126 = t1 * t47 * t125;
-	t127 = t35 * t37;
-	t128 = t38 * t19;
-	t129 = t127 * t128;
-	t132 = t26 * 0.3141592654e1;
-	t133 = t16 * t13;
-	t134 = t10 * t133;
-	t137 = 0.3141592654e1 * ZB;
-	t138 = t2 * t137;
-	t139 = ZA * t8;
-	t140 = t9 * t13;
-	t145 = t30 * t18;
-	t146 = t10 * t145;
-	t149 = t3 * t8;
-	t150 = t149 * t9;
-	t153 = 0.2e1 * t5 * t22 + 0.2e1 * t28 * t10 * t31 + t36 * t40 - 0.2e1 * t46 * t48 * t49 - 0.2e1 * t55 * t56 * t57 - 0.2e1 * t62 * t64 + 0.16e2 * t70 * t29 * ZA * t10 - t76 * t80 + t82 * n * t84 + 0.8e1 * t43 * t3 * t88 * t89 + 0.16e2 * t95 * t98 + 0.2e1 * t102 * t27 * t103 - 0.2e1 * t108 * t109 * t111 + t36 * t116 + 0.8e1 * t55 * t121 - 0.4e1 * t126 * t129 - 0.4e1 * t132 * t134 - 0.4e1 * t138 * t139 * t140 * t20 + 0.8e1 * t28 * t146 - 0.2e1 * t150 * t64;
-	t154 = t42 * n;
-	t155 = nx * t154;
-	t156 = t44 * xc;
-	t157 = t47 * 0.3141592654e1;
-	t158 = t156 * t157;
-	t159 = t155 * t158;
-	t162 = t56 * ZA * t19 * t12;
-	t165 = t77 * t49;
-	t167 = t1 * t3;
-	t168 = t167 * t89;
-	t169 = t127 * t49;
-	t172 = t37 * t67;
-	t173 = t75 * t172;
-	t174 = t38 * t110;
-	t175 = t27 * t174;
-	t179 = t47 * t25;
-	t181 = t10 * t97;
-	t184 = t27 * t31;
-	t187 = t67 * t47;
-	t188 = t44 * t3;
-	t189 = t187 * t188;
-	t192 = t25 * t35;
-	t193 = t37 * t17;
-	t194 = t193 * t12;
-	t196 = nx * ZA;
-	t197 = t196 * t172;
-	t198 = ZB * t38;
-	t199 = t198 * t19;
-	t204 = t1 * t12 * t110;
-	t207 = nx * ZB;
-	t209 = t1 * ZA;
-	t215 = t67 * t3;
-	t216 = t47 * t8;
-	t217 = t215 * t216;
-	t218 = t9 * xc;
-	t222 = nx * t67;
-	t223 = t222 * t27;
-	t224 = t3 * t87;
-	t228 = t167 * t107;
-	t232 = t26 * t96;
-	t235 = t207 * t94;
-	t236 = t47 * ZA;
-	t243 = xc * t13;
-	t244 = t243 * t29;
-	t248 = t25 * n;
-	t249 = t248 * 0.3141592654e1;
-	t253 = ZB * ZA;
-	t254 = t253 * t8;
-	t255 = t9 * n;
-	t256 = t30 * t16;
-	t260 = 0.2e1 * t207 * t37 * t209 * t128 + 0.2e1 * t5 * t134 - 0.16e2 * t217 * t218 * t97 - 0.2e1 * t223 * t224 * t31 - 0.2e1 * t228 * t109 * t174 - 0.2e1 * t232 * t169 - 0.16e2 * t235 * t236 * t44 * t30 * t18 - 0.4e1 * t196 * t101 * t137 * t244 + t249 * t169 + 0.8e1 * t168 * t129 + 0.4e1 * t254 * t255 * t256;
-	t263 = t43 * t179;
-	t267 = t3 * n;
-	t268 = t267 * t54;
-	t269 = t118 * t57;
-	t272 = t39 * t1;
-	t274 = t67 * t25;
-	t275 = t274 * t158;
-	t278 = t75 * t87;
-	t279 = t77 * t103;
-	t282 = t25 * t38;
-	t285 = ZA * t38;
-	t290 = t267 * 0.3141592654e1;
-	t296 = t77 * t111;
-	t298 = t196 * t37;
-	t299 = t1 * ZB;
-	t303 = t37 * t42;
-	t304 = t196 * t303;
-	t308 = t77 * t57;
-	t310 = t26 * t89;
-	t313 = t77 * t128;
-	t316 = t101 * t27;
-	t319 = t93 * t87;
-	t320 = t77 * t97;
-	t323 = t127 * t57;
-	t326 = t10 * n;
-	t329 = t118 * t174;
-	t332 = -0.8e1 * t263 * t109 * t57 - 0.4e1 * t268 * t269 + t93 * t272 + 0.8e1 * t275 * t129 - 0.4e1 * t278 * t279 + t282 * n * t84 - 0.2e1 * t285 * n * t54 * t56 - t290 * t169 - 0.2e1 * t196 * t38 * t172 * t137 + t76 * t296 - 0.2e1 * t298 * t299 * t79 + 0.8e1 * t304 * t96 * t120 + t76 * t308 - 0.2e1 * t310 * t169 - t76 * t313 + 0.2e1 * t75 * t18 * t316 + 0.4e1 * t319 * t320 + t249 * t323 - 0.2e1 * t25 * t18 * t326 + 0.2e1 * t228 * t329;
-	t335 = t75 * t101;
-	t336 = t27 * t21;
-	t342 = t77 * t133;
-	t347 = t209 * t137;
-	t350 = t9 * t1;
-	t351 = t149 * t350;
-	t355 = t37 * t78 * t12;
-	t359 = t93 * t303;
-	t367 = t172 * 0.3141592654e1;
-	t369 = t96 * t103;
-	t376 = t209 * t107;
-	t379 = t10 * t103;
-	t383 = t207 * t101;
-	t389 = 0.3141592654e1 * ZA;
-	t390 = t222 * t389;
-	t391 = t87 * ZB;
-	t398 = -0.2e1 * t102 * t336 + t93 * t38 * t367 + 0.16e2 * t95 * t369 - t82 * t127 - 0.8e1 * t197 * t27 * t120 + 0.8e1 * t376 * t121 - 0.8e1 * t189 * t379 - t249 * t129 - 0.4e1 * t383 * t27 * ZA * t16 * t13 - 0.8e1 * t390 * t391 * t21 - 0.2e1 * t197 * t137 * t57;
-	t402 = t39 * t110;
-	t404 = t193 * t38;
-	t406 = t127 * t174;
-	t408 = t167 * 0.3141592654e1;
-	t411 = t44 * t157;
-	t412 = t155 * t411;
-	t413 = t285 * t19;
-	t414 = t56 * t413;
-	t417 = ZA * t30;
-	t424 = t93 * t37;
-	t426 = t248 * t54;
-	t427 = t17 * t12;
-	t428 = t118 * t427;
-	t431 = t77 * t21;
-	t438 = ZA * t13;
-	t443 = t93 * t172;
-	t444 = t27 * t427;
-	t448 = t1 * t78 * t12;
-	t455 = t274 * t89;
-	t461 = t118 * t111;
-	t464 = -t36 * t402 + t36 * t404 - t249 * t406 - 0.4e1 * t408 * t134 + 0.16e2 * t412 * t414 - 0.4e1 * t383 * t27 * t417 * t18 + 0.2e1 * t28 * t22 - t424 * t80 - 0.2e1 * t426 * t428 + 0.4e1 * t278 * t431 + 0.4e1 * t254 * t255 * t103 + t290 * t323 + 0.4e1 * t383 * t27 * t438 * t20 + 0.2e1 * t443 * t444 + t424 * t448 - t36 * t194 - 0.32e2 * t235 * t236 * t243 * t18 + 0.8e1 * t455 * t181 - 0.4e1 * t359 * t96 * t128 - 0.2e1 * t426 * t461;
-	t469 = n * t16 * t13;
-	t474 = t1 * t38;
-	t475 = t474 * t19;
-	t480 = t89 * t103;
-	t483 = t67 * ZA;
-	t484 = t483 * t411;
-	t485 = t127 * t120;
-	t488 = t127 * t111;
-	t497 = t77 * t427;
-	t502 = t27 * t97;
-	t508 = t1 * t19 * t12;
-	t511 = t155 * t25 * t156;
-	t512 = t157 * t37;
-	t513 = t512 * t128;
-	t527 = t1 * t17;
-	t528 = t527 * t38;
-	t530 = -t76 * t497 - 0.4e1 * t254 * t255 * t97 - 0.2e1 * t102 * t502 - 0.4e1 * t108 * t269 - t76 * t508 + 0.8e1 * t511 * t513 + 0.4e1 * t150 * t63 * t18 + 0.4e1 * t383 * t27 * t438 * t18 + 0.4e1 * t132 * t379 + 0.2e1 * t168 * t488 - t76 * t528;
-	t535 = t44 * t13;
-	t542 = t527 * t12;
-	t544 = n * t13;
-	t545 = t544 * t20;
-	t548 = t75 * t303;
-	t549 = t96 * t111;
-	t552 = ZA * t35;
-	t553 = t552 * t37;
-	t562 = t43 * t96;
-	t563 = t3 * t37;
-	t564 = t563 * t128;
-	t579 = t474 * t110;
-	t590 = t9 * t30;
-	t591 = t590 * t18;
-	t595 = t127 * t427;
-	t598 = t77 * t174;
-	t600 = 0.4e1 * t5 * t146 + 0.16e2 * t235 * t236 * t535 * t18 + 0.8e1 * t455 * t146 + t76 * t542 - 0.2e1 * t150 * t545 + 0.2e1 * t548 * t549 - 0.2e1 * t553 * t120 + t290 * t488 - 0.8e1 * t274 * t47 * t44 * t29 * t10 - 0.4e1 * t562 * t564 - 0.2e1 * t132 * xc * t20 * t10 - 0.32e2 * t562 * ZA * t87 * ZB * t13 * t29 - 0.8e1 * t347 * t379 + t76 * t579 - 0.4e1 * t359 * t96 * t57 + 0.4e1 * t408 * t181 - 0.4e1 * t223 * t564 - 0.12e2 * t209 * t27 * ZB * t8 * t591 + 0.2e1 * t310 * t595 + t76 * t598;
-	t601 = t27 * t49;
-	t604 = t127 * t79;
-	t606 = ZB * t29;
-	t616 = t139 * t140 * t18;
-	t638 = t10 * t256;
-	t643 = t118 * t199;
-	t653 = t544 * t29;
-	t658 = t3 * t29;
-	t660 = t350 * t27;
-	t663 = -0.4e1 * t254 * t255 * t145 + 0.2e1 * t267 * t20 * t8 * t9 - 0.4e1 * t138 * t139 * t9 * t16 * t13 - 0.2e1 * t5 * t638 + 0.2e1 * t126 * t169 + 0.8e1 * t376 * t643 + 0.4e1 * t335 * t27 * t145 + 0.16e2 * t235 * t236 * t535 * t29 + 0.6e1 * t150 * t653 - 0.4e1 * t426 * t269 + 0.4e1 * t658 * t8 * t660;
-	t670 = t274 * t411;
-	t673 = t118 * t49;
-	t694 = t155 * t45;
-	t713 = n * t29 * t30;
-	t717 = t20 * t87;
-	t723 = t512 * t57;
-	t728 = -0.2e1 * t443 * t175 - 0.8e1 * t670 * t129 + 0.2e1 * t426 * t673 - 0.16e2 * t207 * t88 * t42 * t47 * ZA * t44 + 0.4e1 * t254 * t255 * t21 + t249 * t595 + 0.8e1 * t25 * t29 * t8 * t660 + 0.2e1 * t268 * t461 + 0.8e1 * t189 * t181 - 0.8e1 * t694 * t513 + 0.2e1 * t198 * t553 - 0.12e2 * t606 * t139 * t660 - 0.2e1 * t359 * t549 + 0.4e1 * t138 * t139 * t590 * t16 + 0.8e1 * t93 * t29 * t94 * t89 - 0.2e1 * t150 * t713 + 0.2e1 * t222 * t3 * t717 * t27 + 0.8e1 * t670 * t323 + 0.8e1 * t694 * t723 - 0.2e1 * t62 * t653;
-	t734 = t43 * t89;
-	t735 = t563 * t427;
-	t740 = t75 * t94;
-	t744 = ZB * xc;
-	t750 = t563 * t57;
-	t754 = t218 * t103;
-	t771 = t127 * t199;
-	t776 = t89 * t174;
-	t791 = -0.4e1 * t207 * t717 * t77 * xc * ZA + 0.4e1 * t443 * t27 * t57 + t192 * t40 - 0.8e1 * t55 * t643 - 0.16e2 * t209 * t89 * t771 - 0.8e1 * t275 * t323 + 0.2e1 * t359 * t776 + 0.16e2 * t304 * t89 * t199 + 0.4e1 * t278 * t320 + 0.2e1 * t207 * t172 * t389 * t79 - 0.8e1 * t390 * t391 * t97;
-	t794 = t483 * t158;
-	t801 = t2 * 0.3141592654e1;
-	t818 = t215 * t411;
-	t827 = t96 * t174;
-	t837 = t37 * t12 * t110;
-	t845 = 0.16e2 * t794 * t485 + 0.8e1 * t159 * t564 - 0.8e1 * t455 * t379 - 0.2e1 * t801 * t3 * t20 * t10 - 0.4e1 * t132 * t22 - 0.8e1 * t734 * t564 - 0.8e1 * t187 * t44 * t658 * t10 - 0.8e1 * t412 * t564 + 0.4e1 * t132 * t181 - 0.8e1 * t818 * t129 + 0.2e1 * t46 * t48 * t427 - 0.4e1 * t75 * t29 * t316 - 0.2e1 * t359 * t827 - t290 * t595 + 0.16e2 * t217 * t754 - t424 * t542 - 0.8e1 * t734 * t750 - t192 * t837 - 0.4e1 * t254 * t255 * t133 + 0.8e1 * t304 * t96 * t199;
-	t864 = t544 * t18;
-	t867 = t3 * t18;
-	t884 = t27 * t256;
-	t891 = t187 * t744;
-	t894 = t563 * t49;
-	t900 = -0.2e1 * t263 * t428 + 0.2e1 * t228 * t428 - 0.6e1 * t223 * t224 * t103 - t192 * t404 + 0.2e1 * t268 * t428 - 0.2e1 * t335 * t884 - t424 * t296 + 0.2e1 * t93 * t20 * t316 - 0.32e2 * t891 * t616 + 0.2e1 * t562 * t894 - 0.2e1 * t801 * t867 * t10;
-	t904 = t27 * t111;
-	t907 = t118 * t128;
-	t915 = t89 * t145;
-	t947 = t139 * t140 * t29;
-	t952 = -0.2e1 * t173 * t904 + 0.4e1 * t426 * t907 + 0.12e2 * t253 * t10 * t1 * 0.3141592654e1 * t244 + 0.8e1 * t95 * t915 - t36 * t355 - 0.16e2 * t794 * t771 - 0.8e1 * t511 * t723 + 0.16e2 * t734 * t162 + t36 * t837 + 0.2e1 * t298 * t299 * t57 - 0.2e1 * t28 * t638 - 0.2e1 * t62 * t545 + 0.2e1 * t310 * t406 + 0.12e2 * t138 * t616 + 0.4e1 * t223 * t750 + t424 * t497 + 0.2e1 * t734 * t894 + 0.2e1 * t132 * xc * t18 * t10 - 0.16e2 * t70 * t947 + 0.32e2 * t891 * t947;
-	t969 = t67 * t157 * t156 * t3;
-	t974 = t27 * t133;
-	t1001 = -0.8e1 * t159 * t750 - 0.16e2 * t412 * t162 - t290 * t129 + 0.8e1 * t310 * t323 - 0.4e1 * t319 * t342 + t75 * t272 + t192 * t402 - 0.8e1 * t359 * t89 * t128 - 0.10e2 * t61 * t350 * t502 + 0.8e1 * t818 * t323 - 0.4e1 * t108 * t907;
-	t1042 = t89 * t97;
-	t1055 = -0.2e1 * t168 * t595 + 0.16e2 * t484 * t771 + 0.4e1 * t11 * t125 * t129 - 0.2e1 * t173 * t444 + 0.2e1 * ZB * n * t54 * t37 * ZA * t79 - t424 * t475 + 0.2e1 * t562 * t735 - 0.2e1 * t548 * t776 + t424 * t204 + 0.2e1 * t25 * t20 * t326 + 0.8e1 * t383 * t389 * t133 + t75 * t38 * t367 + 0.2e1 * t62 * t469 + 0.2e1 * t197 * t137 * t128 - 0.2e1 * t102 * t884 - 0.2e1 * t5 * t379 - 0.8e1 * t740 * t1042 - 0.16e2 * t159 * t414 - 0.2e1 * ZB * t35 * t37 * t413 + 0.2e1 * t553 * ZB * t78 * t12;
-	t1096 = 0.2e1 * t443 * t904 - 0.2e1 * t268 * t329 - 0.2e1 * t443 * t601 + 0.2e1 * t102 * t974 - 0.2e1 * t263 * t673 + t424 * t165 + 0.2e1 * t62 * t713 + t424 * t308 - t424 * t313 + 0.8e1 * t347 * t22 - t424 * t598;
-	t1103 = t42 * t1 * t157;
-	t1104 = t1103 * t25;
-	t1108 = t3 * t19;
-	t1112 = n * t47;
-	t1113 = t9 * t9;
-	t1118 = t42 * t157;
-	t1119 = t1118 * t9;
-	t1120 = t25 * xc;
-	t1121 = t13 * t110;
-	t1122 = t1120 * t1121;
-	t1125 = t47 * t47;
-	t1126 = t67 * t1125;
-	t1127 = t1113 * ZA;
-	t1128 = t1126 * t1127;
-	t1129 = t19 * t13;
-	t1130 = t744 * t1129;
-	t1133 = t154 * t1125;
-	t1134 = t1133 * t9;
-	t1135 = t45 * t1129;
-	t1138 = t154 * t47;
-	t1139 = t25 * t30;
-	t1142 = t1126 * t1113;
-	t1145 = t125 * t1129;
-	t1148 = t1103 * xc;
-	t1149 = t3 * t13;
-	t1150 = t1149 * t17;
-	t1153 = t25 * t78;
-	t1156 = -0.8e1 * t1104 * t243 * t17 + 0.4e1 * t187 * t1108 * t9 - 0.2e1 * t1112 * t3 * t1113 * t30 + 0.16e2 * t1119 * t1122 + 0.64e2 * t1128 * t1130 + 0.64e2 * t1134 * t1135 - 0.2e1 * t1138 * t1139 + 0.32e2 * t1142 * t1135 - 0.32e2 * t1142 * t1145 + 0.8e1 * t1148 * t1150 - 0.2e1 * t1138 * t1153;
-	t1157 = t25 * t13;
-	t1158 = t1157 * t17;
-	t1161 = t13 * t17;
-	t1162 = t1120 * t1161;
-	t1165 = t3 * t78;
-	t1170 = t42 * t67 * t1125;
-	t1172 = t1108 * t13;
-	t1175 = t1 * t157;
-	t1176 = t1175 * t1113;
-	t1182 = t1120 * t1129;
-	t1189 = t110 * t9 * xc;
-	t1192 = t1149 * t110;
-	t1201 = 0.8e1 * t1103 * t1158 - 0.16e2 * t1119 * t1162 - 0.2e1 * t1112 * t1165 * t1113 + 0.32e2 * t1170 * t44 * t1172 - 0.8e1 * t1176 * t1162 + 0.8e1 * t1104 * t243 * t110 - 0.64e2 * t1134 * t1182 - 0.64e2 * t1134 * t1145 + 0.16e2 * t1118 * t3 * t1189 + 0.16e2 * t1119 * t1192 - 0.4e1 * t187 * t1165 * t9 - 0.4e1 * t187 * t1139 * t9;
-	t1209 = t17 * t30;
-	t1210 = t125 * t1209;
-	t1213 = t1138 * ZA;
-	t1214 = ZB * t30;
-	t1218 = t1157 * t110;
-	t1226 = t3 * t30;
-	t1237 = t1170 * t25;
-	t1242 = 0.4e1 * t1112 * ZA * t119 * t1113 - 0.16e2 * t1119 * t1150 - 0.8e1 * t1176 * t1210 + 0.4e1 * t1213 * t1214 * t19 - 0.16e2 * t1119 * t1218 - 0.32e2 * t1142 * t1182 - 0.8e1 * t1103 * t1120 * t110 - 0.4e1 * t187 * t1226 * t9 + 0.8e1 * t1103 * t1192 + 0.4e1 * t1112 * ZB * t1113 * t30 * ZA - 0.32e2 * t1237 * xc * t19 * t13;
-	t1251 = t125 * t1121;
-	t1260 = t1120 * t1209;
-	t1263 = t1139 * t19;
-	t1282 = 0.8e1 * t1103 * t110 * t3 * xc + 0.8e1 * t1104 * xc * t17 * t30 - 0.8e1 * t1176 * t1251 + 0.16e2 * t1119 * t1158 + 0.4e1 * t1112 * t78 * t1127 * ZB + 0.16e2 * t1119 * t1260 + 0.2e1 * t1138 * t1263 - 0.32e2 * t1170 * xc * t1172 - 0.16e2 * t1213 * t119 * t13 + 0.4e1 * t1138 * t1214 * ZA + 0.32e2 * t1237 * t44 * t19 * t13 - 0.16e2 * t1118 * t25 * t1189;
-	t1287 = t188 * t1129;
-	t1292 = t25 * t19;
-	t1296 = t187 * t9;
-	t1297 = t1226 * t19;
-	t1311 = t1112 * t1113;
-	t1317 = -0.8e1 * t1176 * t1150 + 0.32e2 * t1142 * t1287 - 0.8e1 * t1103 * t1150 + 0.2e1 * t1112 * t1292 * t1113 + 0.4e1 * t1296 * t1297 + 0.8e1 * t1176 * t1192 + 0.4e1 * t1296 * t1263 + 0.8e1 * t1176 * t1158 - 0.8e1 * t1175 * t25 * t1113 * xc * t110 + 0.2e1 * t1311 * t1297 + 0.2e1 * t1112 * t1108 * t1113;
-	t1320 = t253 * t1129;
-	t1328 = t253 * t30 * t19;
-	t1333 = t125 * t1161;
-	t1343 = ZB * t44 * t1129;
-	t1350 = -0.8e1 * t1176 * t1218 - 0.16e2 * t1311 * t1320 + 0.8e1 * t1176 * t1260 - 0.16e2 * t1119 * t1210 + 0.4e1 * t1311 * t1328 + 0.2e1 * t1311 * t1263 + 0.8e1 * t1176 * t1333 + 0.8e1 * t187 * ZB * t417 * t9 - 0.2e1 * t1138 * t1165 - 0.64e2 * t1128 * t1343 + 0.64e2 * t1134 * t1287 + 0.2e1 * t1138 * t1108;
-	t1369 = t1133 * t9 * ZA;
-	t1378 = t187 * ZA;
-	t1383 = t1170 * ZA;
-	t1388 = 0.2e1 * t1138 * t1297 - 0.8e1 * t1148 * t1192 + 0.2e1 * t1138 * t1292 - 0.16e2 * t1119 * t1251 + 0.8e1 * t1175 * xc * t110 * t1113 * t3 - 0.2e1 * t1112 * t1153 * t1113 + 0.128e3 * t1369 * t1130 + 0.16e2 * t1119 * t1333 + 0.4e1 * t1138 * t78 * ZA * ZB + 0.8e1 * t1378 * t78 * t9 * ZB - 0.64e2 * t1383 * t1343 + 0.64e2 * t1383 * t1130;
-	t1420 = 0.4e1 * t1138 * t119 * ZA - 0.128e3 * t1369 * t1343 - 0.4e1 * t187 * t1153 * t9 - 0.2e1 * t1138 * t1226 + 0.8e1 * t1296 * t1328 - 0.2e1 * t1112 * t1139 * t1113 - 0.8e1 * t1148 * t3 * t17 * t30 - 0.32e2 * t1296 * t1320 + 0.8e1 * t1176 * t1122 + 0.4e1 * t187 * t1292 * t9 + 0.8e1 * t1378 * t119 * t9 - 0.8e1 * t1103 * t1218;
-	
-	_C4B = (-t424 * t508 + 0.8e1 * t412 * t750 - 0.2e1 * t232 * t595 - 0.4e1 * t126 * t323 + t1096 - t76 * t204 + t728 + 0.2e1 * t548 * t827 + 0.2e1 * t150 * t469 + t398 + 0.8e1 * t189 * t146 + t260 - 0.2e1 * t351 * t184 - 0.2e1 * t268 * t673 - 0.4e1 * t319 * t279 + t464 - 0.2e1 * t108 * t461 + 0.16e2 * t740 * t369 + 0.16e2 * t274 * t216 * t754 - 0.16e2 * t70 * t139 * t591 + 0.2e1 * t55 * t56 * t128 - 0.2e1 * t359 * t89 * t111 + 0.2e1 * t734 * t563 * t111 + 0.6e1 * t223 * t224 * t97 + 0.8e1 * t383 * t389 * t103 + 0.4e1 * t606 * ZA * t326 - 0.2e1 * t93 * t18 * t316 - 0.4e1 * t443 * t27 * t128 + 0.8e1 * t197 * t27 * t199 + 0.8e1 * t108 * t109 * t128 - t249 * t604 + 0.16e2 * t70 * t616 - 0.8e1 * t969 * t323 + t845 - t424 * t579 + 0.16e2 * t159 * t162 + t290 * t406 - 0.6e1 * t150 * t864 + t192 * t116 + 0.2e1 * t867 * t326 - 0.4e1 * t658 * t326 - 0.2e1 * t351 * t502 - t76 * t165 + t900 + 0.8e1 * t168 * t323 + t791 + 0.8e1 * t740 * t915 - 0.4e1 * t562 * t750 - 0.4e1 * t278 * t342 + 0.4e1 * t319 * t431 + 0.2e1 * t173 * t175 + t424 * t528 + 0.8e1 * t969 * t129 - 0.8e1 * t347 * t181 + t332 + t530 - 0.2e1 * t108 * t329 - 0.2e1 * t207 * t38 * t37 * t1 * ZA + t1001 + 0.4e1 * t408 * t379 + t76 * t448 + 0.2e1 * t102 * t184 + 0.2e1 * t426 * t329 + 0.16e2 * t740 * t98 - t282 * t127 - 0.16e2 * t1 * t44 * t69 * t552 * t116 + 0.2e1 * t168 * t169 + 0.2e1 * t28 * t134 - t290 * t604 - 0.16e2 * t484 * t485 - 0.8e1 * t740 * t480 + 0.2e1 * t173 * t601 - 0.2e1 * t335 * t336 + t600 + 0.2e1 * t62 * t864 + t952 + 0.8e1 * t347 * t134 - t192 * t355 + t192 * t194 + 0.2e1 * t228 * t461 + t663 + 0.4e1 * t383 * t27 * t417 * t16 + 0.4e1 * t138 * t20 * ZA * t10 - 0.4e1 * t20 * ZB * ZA * t326 + 0.4e1 * t196 * t88 * t77 * t744 - 0.16e2 * t67 * xc * t179 * t181 - 0.8e1 * t95 * t480 - t249 * t488 - t76 * t475 + t1055 - 0.4e1 * t408 * t22 - 0.10e2 * t28 * t379 + 0.2e1 * t335 * t974 + t153 - 0.8e1 * t95 * t1042 - 0.2e1 * t734 * t735) / (t1156 + t1201 + t1242 + t1282 + t1317 + t1350 + t1388 + t1420);
-	/****************************************************************************************/
-	/****************************************************************************************/
-	
-	if(x>xc) {
-		_C1=_C1B; _C2=_C2B; _C3=_C3B; _C4=_C4B; Z=ZB;
-	}
-	else {
-		_C1=_C1A; _C2=_C2A; _C3=_C3A; _C4=_C4A; Z=ZA;
-	}
-	/****************************************************************************************/
-	/****************************************************************************************/
-	t1 = n * n;
-	t2 = t1 * t1;
-	t3 = t2 * n;
-	t4 = x * t3;
-	t5 = 0.3141592654e1 * 0.3141592654e1;
-	t6 = t5 * 0.3141592654e1;
-	t11 = _C3 * t6;
-	t12 = x * n;
-	t13 = nx * nx;
-	t14 = t13 * t13;
-	t15 = t12 * t14;
-	t19 = exp(t12 * 0.3141592654e1);
-	t20 = t19 * t19;
-	t21 = t4 * t20;
-	t24 = _C1 * t5;
-	t25 = Z * t20;
-	t29 = _C1 * t6;
-	t30 = t29 * Z;
-	t31 = t1 * n;
-	t32 = x * t31;
-	t33 = t32 * t13;
-	t36 = t11 * x;
-	t41 = n * t20;
-	t45 = t6 * _C4;
-	t49 = t20 * t1;
-	t51 = _C2 * Z;
-	t55 = -0.2e1 * t4 * t6 * _C2 * Z - 0.2e1 * t11 * t15 - 0.2e1 * t11 * t21 + 0.2e1 * t24 * t25 * t14 - t13 + 0.4e1 * t30 * t33 - 0.4e1 * t36 * t31 * t20 * t13 - 0.2e1 * t36 * t41 * t14 - 0.2e1 * t4 * t45 * t20 - t49 - 0.2e1 * t4 * t6 * t51 * t20;
-	t58 = t32 * t6;
-	t59 = _C4 * t20;
-	t63 = t20 * t13;
-	t67 = t12 * t6;
-	t68 = t20 * t14;
-	t87 = t49 * t13;
-	t90 = -0.4e1 * t11 * t33 - 0.4e1 * t58 * t59 * t13 - 0.4e1 * t58 * t51 * t63 - 0.2e1 * t67 * t51 * t68 + 0.4e1 * t32 * t45 * t13 - 0.2e1 * t67 * t59 * t14 - 0.2e1 * t30 * t21 + t1 + 0.2e1 * t24 * t25 * t2 + 0.2e1 * t12 * t45 * t14 + 0.4e1 * t24 * Z * t87;
-	t106 = _C3 * t5;
-	t120 = -0.4e1 * t30 * t32 * t63 + t63 + 0.4e1 * t24 * Z * t1 * t13 + 0.2e1 * t29 * Z * x * t3 - 0.4e1 * t58 * t51 * t13 - 0.2e1 * t106 * t2 + t32 * 0.3141592654e1 - 0.2e1 * t106 * t14 - 0.2e1 * t30 * t12 * t68 - 0.2e1 * t67 * t51 * t14 + 0.4e1 * t106 * t87;
-	t129 = sin(nx * 0.3141592654e1 * x);
-	t155 = 0.2e1 * t30 * t15 + x * 0.3141592654e1 * t41 * t13 - 0.4e1 * t19 * nx * t129 * n + t32 * 0.3141592654e1 * t20 + 0.2e1 * t106 * t68 + 0.2e1 * t106 * t20 * t2 - 0.4e1 * t106 * t1 * t13 - 0.2e1 * t11 * t4 + 0.2e1 * t4 * t45 + 0.2e1 * t24 * Z * t2 + 0.2e1 * t24 * Z * t14 + t12 * 0.3141592654e1 * t13;
-	t158 = t5 * Z;
-	
-	u1 = (t55 + t90 + t120 + t155) / (0.4e1 * t158 * t19 * t2 + 0.8e1 * t158 * t19 * t1 * t13 + 0.4e1 * t158 * t19 * t14);
-	/****************************************************************************************/
-	/****************************************************************************************/
-	t1 = n * n;
-	t2 = t1 * n;
-	t3 = x * t2;
-	t4 = 0.3141592654e1 * 0.3141592654e1;
-	t5 = t4 * 0.3141592654e1;
-	t6 = t3 * t5;
-	t7 = _C2 * Z;
-	t8 = nx * nx;
-	t12 = t1 * t1;
-	t13 = t12 * n;
-	t14 = x * t13;
-	t15 = t5 * _C4;
-	t16 = x * n;
-	t18 = exp(t16 * 0.3141592654e1);
-	t19 = t18 * t18;
-	t23 = t16 * t5;
-	t24 = t8 * t8;
-	t28 = _C3 * t5;
-	t29 = t14 * t19;
-	t32 = _C1 * t5;
-	t33 = t32 * Z;
-	t34 = t16 * t24;
-	t37 = _C4 * t19;
-	t45 = _C2 * t4;
-	t53 = t19 * t8;
-	t58 = _C4 * t4;
-	t60 = t1 * t19 * t8;
-	t63 = t19 * t24;
-	t67 = t3 * t8;
-	t73 = n * t19;
-	t86 = t28 * x;
-	t91 = 0.4e1 * t58 * t60 + 0.2e1 * t33 * t16 * t63 + 0.4e1 * t33 * t67 + 0.2e1 * t33 * t29 - x * 0.3141592654e1 * t73 * t8 - 0.2e1 * t53 + 0.2e1 * t32 * Z * x * t13 - 0.2e1 * t58 * t12 - 0.2e1 * t58 * t24 + t3 * 0.3141592654e1 + 0.4e1 * t86 * t2 * t19 * t8;
-	t94 = Z * t12;
-	t121 = -0.2e1 * t8 + 0.2e1 * t45 * t94 * t19 + 0.2e1 * t14 * t5 * t7 * t19 + 0.4e1 * t6 * t7 * t53 + 0.2e1 * t23 * t7 * t63 - 0.4e1 * t28 * t67 + 0.2e1 * t45 * t94 + 0.2e1 * t58 * t12 * t19 + t16 * 0.3141592654e1 * t8 + 0.2e1 * t14 * t15 - 0.2e1 * t28 * t14;
-	t146 = cos(nx * 0.3141592654e1 * x);
-	t156 = -t3 * 0.3141592654e1 * t19 + 0.2e1 * t58 * t63 - 0.4e1 * t58 * t1 * t8 + 0.4e1 * t45 * Z * t1 * t8 - 0.2e1 * t28 * t34 + 0.2e1 * t86 * t73 * t24 + 0.4e1 * t3 * t15 * t8 + 0.4e1 * t45 * Z * t60 + 0.4e1 * t18 * t146 * t8 + 0.2e1 * t45 * Z * t24 + 0.2e1 * t16 * t15 * t24;
-	t159 = t4 * Z;
-	
-	u2 = (-0.4e1 * t6 * t7 * t8 + 0.2e1 * t14 * t15 * t19 - 0.2e1 * t23 * t7 * t24 + 0.2e1 * t28 * t29 + 0.2e1 * t33 * t34 + 0.4e1 * t6 * t37 * t8 - 0.2e1 * t14 * t5 * _C2 * Z + 0.2e1 * t45 * Z * t19 * t24 + 0.2e1 * t23 * t37 * t24 + 0.4e1 * t33 * t3 * t53 + t91 + t121 + t156) / (0.4e1 * t159 * t18 * t12 + 0.8e1 * t159 * t18 * t1 * t8 + 0.4e1 * t159 * t18 * t24);
-	/****************************************************************************************/
-	/****************************************************************************************/
-	t1 = 0.3141592654e1 * 0.3141592654e1;
-	t2 = t1 * 0.3141592654e1;
-	t3 = _C1 * t2;
-	t4 = t3 * Z;
-	t5 = n * n;
-	t6 = t5 * t5;
-	t7 = t6 * n;
-	t8 = x * t7;
-	t9 = x * n;
-	t11 = exp(t9 * 0.3141592654e1);
-	t12 = t11 * t11;
-	t13 = t8 * t12;
-	t16 = t5 * n;
-	t17 = x * t16;
-	t18 = t17 * t2;
-	t19 = _C4 * t12;
-	t20 = nx * nx;
-	t24 = t2 * _C4;
-	t28 = _C3 * t2;
-	t29 = t28 * x;
-	t30 = t12 * n;
-	t31 = t20 * t20;
-	t40 = _C2 * Z;
-	t44 = t9 * t2;
-	t48 = t12 * t20;
-	t52 = t17 * t20;
-	t57 = -0.2e1 * t4 * t13 - 0.4e1 * t18 * t19 * t20 - 0.2e1 * t8 * t24 * t12 - 0.2e1 * t29 * t30 * t31 + 0.2e1 * t8 * t2 * _C2 * Z - 0.2e1 * t8 * t2 * t40 * t12 - 0.2e1 * t44 * t19 * t31 - 0.4e1 * t18 * t40 * t48 + t20 + 0.4e1 * t28 * t52 + t17 * 0.3141592654e1 * t12;
-	t58 = t9 * t31;
-	t61 = _C3 * t1;
-	t62 = t12 * t31;
-	t73 = t5 * t20;
-	t78 = _C1 * t1;
-	t90 = Z * t12;
-	t94 = 0.2e1 * t28 * t58 + 0.2e1 * t61 * t62 + 0.2e1 * t61 * t12 * t6 - 0.4e1 * t4 * t17 * t48 + 0.2e1 * t28 * t8 + 0.4e1 * t61 * t73 - 0.2e1 * t8 * t24 - 0.2e1 * t78 * Z * t6 - 0.2e1 * t44 * t40 * t62 - 0.2e1 * t78 * Z * t31 - t9 * 0.3141592654e1 * t20 + 0.2e1 * t78 * t90 * t6;
-	t101 = cos(nx * 0.3141592654e1 * x);
-	t102 = t11 * t101;
-	t109 = t12 * t5;
-	t110 = t109 * t20;
-	t128 = 0.2e1 * t61 * t6 - t17 * 0.3141592654e1 + 0.2e1 * t102 * t5 - 0.4e1 * t17 * t24 * t20 + 0.4e1 * t78 * Z * t110 - 0.2e1 * t9 * t24 * t31 - 0.4e1 * t4 * t52 - 0.2e1 * t4 * t9 * t62 + x * 0.3141592654e1 * t30 * t20 - t5 - 0.4e1 * t78 * Z * t5 * t20;
-	t156 = 0.2e1 * t78 * t90 * t31 - 0.2e1 * t3 * Z * x * t7 + t48 + 0.4e1 * t61 * t110 + 0.4e1 * t18 * t40 * t20 - 0.2e1 * t102 * t20 + 0.2e1 * t61 * t31 + 0.2e1 * t44 * t40 * t31 - t109 - 0.2e1 * t4 * t58 - 0.2e1 * t28 * t13 - 0.4e1 * t29 * t16 * t12 * t20;
-	t159 = t1 * t11;
-	
-	u3 = (t57 + t94 + t128 + t156) / (0.4e1 * t159 * t6 + 0.8e1 * t159 * t73 + 0.4e1 * t159 * t31);
-	/****************************************************************************************/
-	/****************************************************************************************/
-	t1 = _C2 * Z;
-	t2 = 0.3141592654e1 * 0.3141592654e1;
-	t3 = t2 * 0.3141592654e1;
-	t4 = n * n;
-	t5 = t4 * t4;
-	t6 = t5 * t4;
-	t8 = t3 * t6 * x;
-	t11 = x * t4;
-	t12 = t11 * t3;
-	t15 = exp(x * n * 0.3141592654e1);
-	t16 = t15 * t15;
-	t17 = _C3 * t16;
-	t18 = nx * nx;
-	t19 = t18 * t18;
-	t23 = t5 * n;
-	t24 = t2 * t23;
-	t28 = t1 * t3;
-	t29 = t6 * x;
-	t30 = t29 * t16;
-	t33 = _C4 * t3;
-	t34 = t5 * x;
-	t35 = t34 * t18;
-	t41 = sin(nx * 0.3141592654e1 * x);
-	t47 = t11 * t19;
-	t54 = t3 * _C3;
-	t57 = 0.2e1 * t1 * t8 + 0.2e1 * t12 * t17 * t19 + 0.2e1 * t1 * t24 * t16 + 0.2e1 * t28 * t30 - 0.4e1 * t33 * t35 + 0.2e1 * t15 * nx * t41 * t4 + 0.4e1 * t28 * t35 - 0.2e1 * t33 * t47 - 0.2e1 * t1 * t24 - 0.2e1 * t33 * t29 + 0.2e1 * t29 * t54;
-	t58 = 0.3141592654e1 * t16;
-	t60 = t2 * _C4;
-	t69 = t4 * n;
-	t73 = t1 * t2;
-	t75 = t69 * t16 * t18;
-	t79 = x * t16;
-	t83 = n * t16;
-	t84 = t83 * t19;
-	t95 = -t34 * t58 + 0.2e1 * t60 * t23 * t16 + 0.2e1 * t60 * n * t19 - t11 * 0.3141592654e1 * t18 + 0.4e1 * t60 * t69 * t18 + 0.4e1 * t73 * t75 + 0.4e1 * t33 * t5 * t79 * t18 + 0.2e1 * t73 * t84 + 0.2e1 * t60 * t84 + 0.2e1 * t33 * t4 * t79 * t19 + 0.4e1 * t60 * t75;
-	t97 = t34 * t3;
-	t101 = Z * _C1;
-	t102 = t16 * t19;
-	t106 = t16 * t18;
-	t127 = t2 * t69;
-	t131 = t2 * n;
-	t135 = 0.4e1 * t97 * t17 * t18 + 0.2e1 * t12 * t101 * t102 + 0.4e1 * t28 * t34 * t106 + 0.2e1 * t28 * t11 * t102 - 0.2e1 * t29 * t3 * Z * _C1 - 0.4e1 * t97 * t101 * t18 - 0.2e1 * t12 * t101 * t19 + 0.2e1 * t60 * t23 - 0.2e1 * t83 * t18 - 0.4e1 * t1 * t127 * t18 - 0.2e1 * t1 * t131 * t19;
-	t164 = 0.2e1 * t28 * t47 + 0.2e1 * t11 * t54 * t19 + 0.2e1 * t8 * t101 * t16 + 0.2e1 * t33 * t30 - t11 * t58 * t18 + 0.2e1 * t29 * t54 * t16 + 0.4e1 * t34 * t54 * t18 + 0.4e1 * t97 * t101 * t106 - 0.2e1 * t15 * t18 * nx * t41 - t34 * 0.3141592654e1 + 0.2e1 * n * t18;
-	
-	u4 = (t57 + t95 + t135 + t164) / (0.4e1 * t24 * t15 + 0.8e1 * t127 * t15 * t18 + 0.4e1 * t131 * t15 * t19);
-	
-	
-	/****************************************************************************************/
-	/****************************************************************************************/
-	
-	
-	u5 = (double)(-2*Z*n*PI*u2-u3*2*n*PI)*cos(n*PI*z); /* pressure */
-	
-	u6 = (double)(u3*2*n*PI + 4*Z*n*PI*u2)*cos(n*PI*z); /* zz stress */	    
-	sum5 +=u5;
-	sum6 +=u6;
-	
-	u1 *= cos(n*PI*z); /* x velocity */
-	sum1 += u1;
-	u2 *= sin(n*PI*z); /* z velocity */
-	sum2 += u2;
-	u3 *= 2*n*PI*cos(n*PI*z); /* xx stress */
-	sum3 += u3;
-	u4 *= 2*n*PI*sin(n*PI*z); /* zx stress */
-	sum4 += u4;
-	
-	
-	mag=sqrt(sum1*sum1+sum2*sum2);
-	/*printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag);*/
-	
-	
-	/* Output */
-	if( vel != NULL ) {
-		vel[0] = sum1;
-		vel[1] = sum2;
-	}
-	if( presssure != NULL ) {
-		(*presssure) = sum5;
-	}
-	if( total_stress != NULL ) {
-		total_stress[0] = sum3;
-		total_stress[1] = sum6; 
-		total_stress[2] = sum4;
-	}
-	if( strain_rate != NULL ) {
-		if( x>xc ) {
-			Z = ZB;
-		}
-		else {
-			Z = ZA;
-		}
-		strain_rate[0] = (sum3+sum5)/(2.0*Z);
-		strain_rate[1] = (sum6+sum5)/(2.0*Z);
-		strain_rate[2] = (sum4)/(2.0*Z);
-	}
-	/* Value checks, could be cleaned up if needed. Julian Giordani 2-Oct-2006*/
-	if( fabs( sum5 - ( -0.5*(sum6+sum3) ) ) > 1e-5 ) {
-		assert(0);
-	}
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solCx/solCx.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solCx/solCx.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,2333 @@
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+
+#define PI 3.14159265358979323846264338328
+
+
+void _Velic_solCx( 
+		double pos[], 
+		double _eta_A, double _eta_B, 
+		double _x_c, int _n,
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] );
+
+/*
+int main( int argc, char **argv )
+{
+	int i,j;
+	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
+	double x,z;
+	
+	for (i=0;i<101;i++){
+		for(j=0;j<101;j++){
+			x = i/100.0;
+			z = j/100.0;
+			
+			pos[0] = x;
+			pos[1] = z;
+			solCx( 
+					pos, 
+					1.0, 1.0,
+					0.5, 1,
+					vel, &pressure, total_stress, strain_rate );
+			
+			printf("t_xx, t_xz fucked !! \n");
+			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
+					pos[0],pos[1],
+					vel[0],vel[1], pressure, 
+					total_stress[0], total_stress[1], total_stress[2], 
+					strain_rate[0], strain_rate[1], strain_rate[2] );
+		}
+		printf("\n");
+	}
+	
+	return 0;
+}
+*/
+
+void _Velic_solCx(
+		double pos[], 
+		double _eta_A, double _eta_B, 	/* Input parameters: density, viscosity A, viscosity B */
+		double _x_c, int _n, 			/* Input parameters: viscosity jump location, wavenumber in x */
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] )
+{
+	double Z,u1,u2,u3,u4,u5,u6,ZA,ZB;
+	double sum1,sum2,sum3,sum4,sum5,sum6,mag,x,z,xc;
+	double _C1A,_C2A,_C3A,_C4A,_C1B,_C2B,_C3B,_C4B,_C1,_C2,_C3,_C4;
+	int n,nx;
+	
+	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,t43,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,t80;
+	double t81,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,t115,t116,t117,t118,t119,t120;
+	double t121,t122,t123,t124,t125,t126,t127,t128,t129,t130,t131,t132,t133,t134,t135,t136,t137,t138,t139,t140,t141,t142,t143,t144,t145,t146,t147,t148,t149,t150,t151,t152,t153,t154,t155,t156,t157,t158,t159,t160;
+	double t161,t162,t163,t164,t165,t166,t167,t168,t169,t170,t171,t172,t173,t174,t175,t176,t177,t178,t179,t180,t181,t182,t183,t184,t186,t187,t188,t189,t190,t191,t192,t193,t194,t195,t196,t197,t198,t199;
+	double t201,t202,t203,t204,t206,t207,t208,t209,t210,t211,t212,t213,t215,t216,t217,t218,t219,t220,t221,t222,t223,t224,t225,t226,t227,t228,t229,t230,t231,t232,t233,t234,t235,t236,t237,t238,t239,t240;
+	double t241,t242,t243,t244,t245,t246,t247,t248,t249,t250,t251,t252,t253,t254,t255,t256,t257,t258,t259,t260,t261,t262,t263,t264,t265,t267,t268,t269,t270,t272,t273,t274,t275,t276,t277,t278,t279,t280;
+	double t281,t282,t283,t284,t285,t286,t288,t289,t290,t291,t292,t295,t296,t297,t298,t299,t300,t301,t303,t304,t305,t307,t308,t310,t311,t312,t313,t314,t315,t316,t317,t318,t319,t320;
+	double t321,t322,t323,t324,t325,t326,t327,t328,t329,t330,t331,t332,t334,t335,t336,t337,t338,t339,t340,t341,t342,t344,t345,t346,t347,t348,t349,t350,t351,t352,t353,t354,t355,t356,t358,t359,t360;
+	double t361,t362,t363,t364,t365,t366,t367,t368,t369,t370,t371,t372,t373,t374,t375,t376,t377,t378,t379,t380,t381,t382,t383,t384,t385,t386,t387,t389,t390,t391,t393,t394,t395,t396,t397,t398;
+	double t401,t402,t403,t404,t405,t406,t407,t408,t409,t410,t411,t412,t413,t414,t415,t416,t417,t418,t419,t421,t422,t423,t424,t425,t426,t427,t428,t429,t430,t431,t432,t433,t434,t436,t437,t438,t439,t440;
+	double t441,t442,t443,t444,t445,t446,t447,t448,t450,t451,t453,t454,t455,t456,t457,t458,t459,t461,t462,t463,t464,t465,t466,t468,t469,t470,t471,t474,t475,t478,t480;
+	double t482,t483,t484,t485,t488,t489,t490,t492,t493,t495,t497,t498,t499,t501,t502,t503,t504,t505,t507,t508,t509,t510,t511,t512,t513,t515,t518,t520;
+	double t522,t525,t527,t528,t529,t530,t532,t533,t534,t535,t536,t538,t539,t541,t542,t544,t545,t546,t547,t548,t549,t550,t551,t552,t553,t554,t555,t556,t557,t560;
+	double t561,t562,t563,t564,t567,t568,t571,t573,t575,t576,t578,t579,t583,t590,t591,t594,t595,t596,t597,t598,t600;
+	double t601,t602,t604,t606,t607,t608,t611,t613,t615,t616,t617,t619,t621,t623,t624,t625,t626,t627,t629,t630,t632,t633,t634,t638,t639,t640;
+	double t641,t642,t643,t644,t645,t647,t648,t649,t650,t651,t652,t653,t654,t655,t656,t657,t658,t659,t660,t662,t663,t665,t666,t667,t668,t670,t671,t672,t673,t674,t675,t676,t679,t680;
+	double t682,t683,t684,t685,t686,t688,t689,t690,t691,t693,t694,t695,t696,t697,t698,t699,t700,t701,t702,t704,t705,t708,t709,t711,t712,t713,t714,t717,t718,t719;
+	double t721,t722,t723,t726,t727,t728,t730,t733,t734,t735,t736,t737,t738,t739,t740,t741,t744,t745,t746,t749,t750,t752,t753,t754,t755,t757,t758,t759,t760;
+	double t761,t762,t763,t764,t766,t767,t768,t770,t771,t772,t773,t774,t775,t776,t777,t778,t780,t781,t782,t785,t786,t789,t790,t791,t792,t793,t794,t795,t796,t797,t798,t800;
+	double t801,t806,t807,t808,t809,t811,t812,t817,t818,t819,t821,t822,t824,t827,t828,t830,t834,t835,t837,t840;
+	double t842,t843,t844,t845,t846,t849,t850,t853,t854,t855,t857,t858,t859,t860,t863,t864,t867,t868,t869,t873,t874,t877,t878,t879,t880;
+	double t884,t888,t891,t894,t900,t901,t903,t904,t907,t908,t909,t911,t914,t915,t916,t919,t920;
+	double t923,t924,t925,t926,t927,t929,t932,t935,t937,t939,t942,t943,t944,t945,t947,t948,t949,t950,t952,t953,t954,t955,t956,t957;
+	double t961,t964,t965,t966,t967,t968,t969,t971,t972,t974,t977,t978,t981,t983,t987,t988,t992,t993,t994,t997,t998;
+	double t1001,t1003,t1005,t1006,t1009,t1010,t1012,t1013,t1015,t1016,t1017,t1018,t1020,t1021,t1029,t1031,t1032,t1033,t1040;
+	double t1041,t1042,t1044,t1047,t1050,t1054,t1055,t1057,t1058,t1063,t1068,t1069,t1070,t1079,t1080;
+	double t1088,t1089,t1091,t1092,t1094,t1096,t1101,t1102,t1103,t1104,t1105,t1108,t1112,t1113,t1118,t1119,t1120;
+	double t1121,t1122,t1123,t1124,t1125,t1126,t1127,t1128,t1129,t1130,t1132,t1133,t1134,t1135,t1138,t1139,t1140,t1141,t1142,t1145,t1146,t1148,t1149,t1150,t1153,t1154,t1156,t1157,t1158,t1159;
+	double t1161,t1162,t1165,t1166,t1170,t1171,t1172,t1173,t1175,t1176,t1178,t1180,t1181,t1182,t1185,t1189,t1192,t1193,t1195,t1196,t1199;
+	double t1201,t1203,t1209,t1210,t1211,t1213,t1214,t1218,t1221,t1224,t1225,t1226,t1228,t1233,t1234,t1235,t1236,t1237,t1240;
+	double t1241,t1242,t1243,t1244,t1245,t1248,t1251,t1252,t1257,t1258,t1259,t1260,t1263,t1268,t1269,t1272,t1280;
+	double t1282,t1283,t1284,t1285,t1287,t1288,t1289,t1292,t1293,t1296,t1297,t1300,t1304,t1307,t1310,t1311,t1312,t1316,t1317,t1320;
+	double t1321,t1323,t1328,t1330,t1331,t1332,t1333,t1336,t1338,t1343,t1344,t1346,t1349,t1350,t1354;
+	double t1366,t1369,t1370,t1371,t1376,t1378,t1380,t1383,t1386,t1387,t1388,t1391,t1393,t1399;
+	double t1411,t1412,t1420,t1427;
+	double t1450,t1456,t1468,t1472,t1474,t1478;
+	double t1504,t1511;
+	double t1545;
+	double t1564,t1583;
+	
+	
+	/* del_rho = sin(n*Pi*z)*cos(nx*Pi*x)  n=nx gives only non-zero terms*/
+	n = _n; /* only one n in Fourier series because  del_rho has cos term */
+	nx = 1; /* can set these two to whatever we like */
+	
+	ZA=_eta_A; /* left column viscosity */
+	ZB=_eta_B; /* right column viscosity */
+	xc = _x_c;
+	
+	x = pos[0];
+	z = pos[1];
+	
+	sum1=0.0;
+	sum2=0.0;
+	sum3=0.0;
+	sum4=0.0;
+	sum5=0.0;
+	sum6=0.0;
+	
+	// Note that there is no Fourier sum here.
+	/****************************************************************************************/
+	_C1A = 0;
+	/****************************************************************************************/
+	t1 = nx * 0.3141592654e1;
+	t2 = sin(t1);
+	t3 = nx * t2;
+	t4 = n * n;
+	t5 = t4 * t4;
+	t6 = 0.3141592654e1 * 0.3141592654e1;
+	t8 = t3 * t5 * t6;
+	t9 = ZA * xc;
+	t12 = exp(xc * n * 0.3141592654e1);
+	t13 = t12 * t12;
+	t15 = n * 0.3141592654e1;
+	t16 = exp(t15);
+	t17 = t16 * t16;
+	t18 = t17 * t16;
+	t19 = ZB * t13 * t18;
+	t20 = t9 * t19;
+	t23 = ZA * ZA;
+	t24 = nx * nx;
+	t25 = t24 * nx;
+	t26 = t23 * t25;
+	t28 = t13 * t13;
+	t29 = t28 * t13;
+	t33 = nx * ZB;
+	t34 = t1 * xc;
+	t35 = sin(t34);
+	t36 = t4 * n;
+	t37 = t35 * t36;
+	t38 = t33 * t37;
+	t39 = 0.3141592654e1 * ZA;
+	t40 = t13 * t12;
+	t41 = t17 * t40;
+	t45 = ZB * ZB;
+	t46 = t45 * t24;
+	t47 = t46 * t4;
+	t48 = 0.3141592654e1 * xc;
+	t49 = t13 * t17;
+	t53 = xc * xc;
+	t54 = t36 * t53;
+	t56 = t54 * t6 * t45;
+	t57 = cos(t34);
+	t58 = t57 * t24;
+	t59 = t28 * t12;
+	t60 = t17 * t59;
+	t61 = t58 * t60;
+	t64 = t25 * t2;
+	t65 = t64 * t15;
+	t72 = nx * t23;
+	t74 = t72 * t2 * t5;
+	t75 = t6 * t53;
+	t76 = t16 * t29;
+	t80 = t23 * n;
+	t81 = t80 * 0.3141592654e1;
+	t82 = t18 * t28;
+	t86 = nx * t5;
+	t87 = t23 * t6;
+	t89 = xc * t2;
+	t90 = t13 * t18;
+	t91 = t89 * t90;
+	t94 = t28 * t28;
+	t96 = t24 * n;
+	t98 = t4 * t45;
+	t99 = t98 * 0.3141592654e1;
+	t100 = t58 * t41;
+	t104 = 0.3141592654e1 * t25;
+	t105 = ZA * n * t104;
+	t106 = t2 * ZB;
+	t110 = t17 * t17;
+	t111 = ZA * t110;
+	t116 = n * t28;
+	t122 = t64 * t4 * t6;
+	t126 = t23 * t29 * t4;
+	t128 = t24 * xc;
+	t132 = t36 * t23;
+	t133 = t6 * t57;
+	t135 = t128 * t41;
+	t138 = t6 * xc;
+	t142 = t72 * t2;
+	t147 = 0.4e1 * t8 * t20 - 0.2e1 * t26 * t2 * t16 * t29 - 0.8e1 * t38 * t39 * t41 + 0.4e1 * t47 * t48 * t49 - 0.8e1 * t56 * t61 - 0.4e1 * t65 * t20 + 0.2e1 * t26 * t2 * t18 * t28 - 0.4e1 * t74 * t75 * t76 - 0.2e1 * t81 * t64 * t82 - 0.4e1 * t86 * t87 * t91 - t23 * t94 * t96 + 0.8e1 * t99 * t100 - 0.2e1 * t105 * t106 * t82 - 0.4e1 * t38 * t48 * t111 * t12 + 0.2e1 * t116 * ZB * t111 * t24 + 0.4e1 * t122 * t20 + 0.4e1 * t126 * 0.3141592654e1 * t17 * t128 + 0.8e1 * t132 * t133 * t135 + 0.4e1 * t74 * t138 * t76 - 0.2e1 * t142 * t4 * t18 * t28;
+	t149 = ZA * t25 * t2;
+	t150 = ZB * t28;
+	t154 = t35 * t5;
+	t155 = t72 * t154;
+	t156 = t75 * t41;
+	t159 = nx * ZA;
+	t160 = t2 * t36;
+	t161 = t159 * t160;
+	t162 = 0.3141592654e1 * ZB;
+	t163 = t28 * t16;
+	t167 = t23 * t57;
+	t168 = t167 * t24;
+	t169 = n * t110;
+	t170 = t169 * t40;
+	t173 = ZA * ZB;
+	t174 = t173 * t90;
+	t177 = t36 * 0.3141592654e1;
+	t181 = t80 * t104;
+	t184 = n * t17;
+	t188 = t17 * t29;
+	t190 = t4 * 0.3141592654e1;
+	t191 = t190 * t24;
+	t206 = t138 * t60;
+	t209 = t23 * t4;
+	t211 = t209 * t6 * t25;
+	t212 = t89 * t76;
+	t216 = ZB * t16 * t29;
+	t217 = t9 * t216;
+	t220 = ZB * t110;
+	t221 = ZA * t24;
+	t222 = t221 * n;
+	t225 = t132 * t75;
+	t232 = t45 * t28;
+	t233 = t110 * t24;
+	t234 = t233 * n;
+	t236 = t209 * 0.3141592654e1;
+	t237 = t17 * xc;
+	t239 = t237 * t13 * t24;
+	t242 = -0.2e1 * t149 * t150 * t16 - 0.8e1 * t155 * t156 - 0.2e1 * t161 * t162 * t163 + 0.2e1 * t168 * t170 + 0.2e1 * t65 * t174 - 0.2e1 * t142 * t177 * t76 + 0.4e1 * t181 * t91 - 0.4e1 * t168 * t184 * t59 - 0.4e1 * t188 * t23 * t191 + 0.4e1 * t38 * t48 * ZA * t17 * t40 + 0.4e1 * t49 * t23 * t191 + 0.2e1 * t26 * t2 * t13 * t18 - 0.8e1 * t155 * t206 + 0.4e1 * t211 * t212 - 0.4e1 * t8 * t217 + 0.2e1 * t220 * t222 - 0.8e1 * t225 * t100 + 0.2e1 * t142 * t4 * t16 * t29 + t232 * t234 - 0.4e1 * t236 * t239;
+	t244 = nx * t45;
+	t245 = t244 * t37;
+	t246 = t110 * t40;
+	t251 = t237 * t59;
+	t256 = t64 * t90;
+	t260 = t36 * t45 * t133;
+	t263 = t45 * t57;
+	t264 = t263 * t24;
+	t265 = t169 * t12;
+	t269 = t6 * t36;
+	t270 = t17 * t24;
+	t274 = t110 * t13;
+	t276 = t190 * t128;
+	t279 = nx * t36;
+	t281 = t28 * t40;
+	t282 = t281 * t35;
+	t286 = t138 * t41;
+	t289 = t75 * t60;
+	t296 = t190 * t173;
+	t305 = t86 * t45 * t35;
+	t312 = t33 * t154;
+	t313 = t6 * ZA;
+	t324 = t232 * t270;
+	t327 = -0.2e1 * t245 * t48 * t246 + 0.4e1 * t159 * t37 * t162 * t251 + 0.4e1 * t209 * t75 * t256 + 0.8e1 * t260 * t135 + 0.2e1 * t264 * t265 + 0.32e2 * t9 * t150 * t269 * t270 + 0.4e1 * t274 * t23 * t276 + 0.2e1 * t279 * t45 * t282 * t48 + 0.8e1 * t155 * t286 + 0.8e1 * t155 * t289 - 0.8e1 * t150 * ZA * t96 * t17 + 0.8e1 * t296 * t61 - 0.2e1 * t105 * t106 * t163 - 0.2e1 * t81 * t256 - 0.8e1 * t305 * t156 - 0.4e1 * t33 * t282 * t177 * t9 - 0.16e2 * t312 * t313 * t237 * t40 - 0.4e1 * t168 * t184 * t40 + 0.2e1 * t168 * t265 + 0.16e2 * t269 * t53 * t324;
+	t328 = t3 * t4;
+	t331 = t72 * t37;
+	t332 = t48 * t60;
+	t335 = n * t94;
+	t345 = t72 * t35;
+	t349 = t173 * t57;
+	t355 = t53 * t17;
+	t364 = t54 * t6 * ZB;
+	t365 = t28 * t17;
+	t369 = xc * ZB;
+	t370 = t269 * t369;
+	t371 = ZA * t57;
+	t373 = t371 * t270 * t40;
+	t385 = nx * t35;
+	t396 = t4 * xc;
+	t397 = t396 * t162;
+	t415 = t37 * t48;
+	t418 = -0.32e2 * t364 * t365 * t221 - 0.16e2 * t370 * t373 - 0.4e1 * t331 * t48 * t41 + 0.4e1 * t86 * t23 * t53 * t6 * t2 * t90 + 0.2e1 * t385 * t177 * t23 * xc * t246 + 0.16e2 * t132 * t53 * t6 * t28 * t270 - 0.4e1 * t397 * t371 * t233 * t12 - 0.12e2 * t173 * t58 * t190 * t251 + 0.2e1 * t385 * t36 * 0.3141592654e1 * t23 * xc * t59 - 0.8e1 * t99 * t61 - 0.2e1 * t244 * t59 * t415;
+	t427 = t371 * t270 * t59;
+	t439 = t209 * t48;
+	t440 = t110 * t12;
+	t441 = t58 * t440;
+	t447 = t36 * xc;
+	t455 = t48 * t440;
+	t471 = ZB * t17;
+	t492 = 0.12e2 * t397 * t373 - 0.4e1 * t122 * t217 + 0.16e2 * t364 * t427 + 0.16e2 * t312 * t313 * t355 * t40 - 0.8e1 * t279 * t39 * t35 * ZB * t60 + 0.2e1 * t439 * t441 - 0.2e1 * t81 * t64 * t163 + 0.8e1 * t447 * t87 * t61 + 0.2e1 * t23 * t59 * t57 * t276 + 0.2e1 * t245 * t455 - 0.4e1 * t349 * t96 * t440 - 0.16e2 * t370 * t427 + 0.4e1 * t181 * t212 - 0.16e2 * t365 * t23 * t269 * t128 + 0.16e2 * t86 * t138 * ZA * t35 * t471 * t59 + 0.8e1 * t305 * t289 - 0.4e1 * t439 * t100 + 0.2e1 * ZB * t25 * t2 * ZA * t18 * t28 + 0.2e1 * t142 * t4 * t28 * t16 - 0.8e1 * t56 * t100;
+	t499 = ZA * t53 * t19;
+	t505 = t396 * 0.3141592654e1;
+	t518 = t173 * t53 * t16 * t29;
+	t533 = t23 * t28;
+	t535 = t188 * t45;
+	t538 = t24 * t4;
+	t545 = t3 * t177;
+	t546 = t173 * t76;
+	t555 = t45 * t110;
+	t557 = t72 * t160;
+	t561 = -0.8e1 * t225 * t61 - 0.2e1 * t161 * t162 * t82 + t533 * t234 + 0.4e1 * t535 * t191 + 0.4e1 * t167 * t538 * t332 + 0.4e1 * t349 * t96 * t60 + 0.2e1 * t545 * t546 - 0.2e1 * t264 * t170 + 0.4e1 * t397 * t281 * ZA * t58 - t555 * t96 - 0.4e1 * t557 * t48 * t76;
+	t567 = t396 * 0.3141592654e1 * t45;
+	t568 = t58 * t246;
+	t597 = t58 * n;
+	t615 = t13 * t45;
+	t616 = t615 * t233;
+	t619 = t94 * t45;
+	t621 = t45 * t59;
+	t625 = 0.2e1 * t149 * t216 + 0.2e1 * t567 * t568 - 0.16e2 * t269 * xc * t324 - 0.2e1 * t236 * xc * t281 * t58 - 0.2e1 * t142 * t177 * t90 - 0.8e1 * t567 * t100 + 0.2e1 * t65 * t546 - 0.8e1 * t305 * t206 + 0.2e1 * n * t45 * t281 * t57 * t24 - t23 * t110 * t96 - 0.8e1 * t296 * t100 + 0.2e1 * t23 * t281 * t597 + 0.4e1 * t545 * t20 + 0.2e1 * t159 * t2 * t4 * ZB * t163 - 0.4e1 * t557 * t48 * t90 + 0.4e1 * t122 * t518 + 0.8e1 * t263 * t538 * t332 - 0.4e1 * t505 * t616 - t619 * t96 - 0.2e1 * t621 * t57 * t276;
+	t626 = t49 * t45;
+	t660 = t29 * t45;
+	t685 = 0.2e1 * t545 * t174 - 0.4e1 * t126 * 0.3141592654e1 * t24 * xc - 0.4e1 * t47 * t48 * t188 + 0.4e1 * t505 * t660 * t24 - 0.2e1 * t142 * t177 * t163 - 0.2e1 * t142 * t4 * t13 * t18 + 0.8e1 * t260 * t128 * t60 - 0.2e1 * t328 * t546 - 0.2e1 * t26 * t2 * t28 * t16 + 0.4e1 * t545 * t217 - 0.4e1 * t209 * t138 * t256;
+	t690 = t6 * 0.3141592654e1;
+	t691 = ZA * t690;
+	t693 = t24 * t24;
+	t694 = t693 * xc;
+	t695 = t188 * t694;
+	t698 = t23 * ZA;
+	t699 = t698 * t690;
+	t700 = t699 * t5;
+	t704 = t5 * t4;
+	t705 = t691 * t704;
+	t709 = t691 * t5;
+	t713 = t5 * n;
+	t714 = t713 * ZB;
+	t718 = t698 * t6;
+	t719 = t713 * t28;
+	t722 = t699 * t704;
+	t726 = t713 * t94;
+	t733 = t713 * t45;
+	t736 = t87 * t36;
+	t740 = -0.4e1 * t691 * t98 * t695 + 0.8e1 * t700 * t270 * t13 + 0.4e1 * t705 * t660 * xc + 0.8e1 * t709 * t660 * t128 + 0.2e1 * t87 * t714 * t110 + t718 * t719 * t110 - 0.4e1 * t722 * t237 * t13 - t313 * t726 * t45 - 0.4e1 * t699 * t704 * xc * t29 + t313 * t733 * t28 + 0.4e1 * t736 * t150 * t233;
+	t746 = t313 * t36;
+	t752 = t6 * t6;
+	t753 = t23 * t752;
+	t759 = t698 * t752;
+	t760 = t759 * t36;
+	t761 = t17 * t693;
+	t762 = xc * t28;
+	t763 = t761 * t762;
+	t766 = t87 * t713;
+	t773 = t699 * t4;
+	t774 = t110 * t693;
+	t775 = xc * t13;
+	t785 = t704 * t17;
+	t789 = -0.16e2 * t736 * t150 * t270 + t718 * t116 * t693 - 0.2e1 * t746 * t555 * t24 + 0.4e1 * t705 * t535 + 0.64e2 * t753 * t713 * t17 * t150 * t128 - 0.16e2 * t760 * t763 + 0.2e1 * t766 * t150 * t110 + 0.4e1 * t722 * t274 * xc + 0.4e1 * t773 * t774 * t775 - 0.8e1 * t766 * t150 * t17 + 0.8e1 * t700 * t233 * t775 + 0.4e1 * t699 * t785 * t13;
+	t791 = t691 * t4;
+	t792 = t45 * t693;
+	t793 = t49 * t792;
+	t796 = t759 * t713;
+	t797 = t53 * t28;
+	t798 = t270 * t797;
+	t801 = t87 * n;
+	t818 = t5 * t36;
+	t819 = t753 * t818;
+	t827 = t753 * t36 * ZB;
+	t830 = xc * t45;
+	t834 = -0.4e1 * t791 * t793 + 0.32e2 * t796 * t798 + 0.2e1 * t801 * ZB * t693 * t110 + 0.2e1 * t718 * t36 * t28 * t24 - 0.8e1 * t700 * t128 * t29 - 0.8e1 * t700 * t239 - 0.8e1 * t801 * t150 * t761 + 0.32e2 * t819 * t365 * t369 - 0.64e2 * t753 * t714 * t798 + 0.32e2 * t827 * t763 + 0.4e1 * t705 * t830 * t49;
+	t842 = xc * t29;
+	t843 = t270 * t842;
+	t849 = t759 * t818;
+	t853 = t691 * t396;
+	t857 = t691 * t5 * t45;
+	t869 = t313 * n;
+	t874 = -0.2e1 * t718 * t36 * t94 * t24 - 0.4e1 * t773 * t761 * t29 + 0.8e1 * t700 * t843 + 0.2e1 * t87 * t726 * ZB + 0.16e2 * t849 * t797 * t17 + 0.4e1 * t853 * t793 + 0.8e1 * t857 * t239 + 0.2e1 * t801 * t150 * t693 - 0.8e1 * t700 * t270 * t29 - 0.8e1 * t709 * t49 * t46 - t869 * t619 * t693 + t869 * t232 * t693;
+	t877 = ZA * t752;
+	t878 = t877 * t818;
+	t911 = 0.16e2 * t878 * t53 * t45 * t365 - 0.4e1 * t699 * t785 * t29 - 0.4e1 * t705 * t188 * t830 + 0.2e1 * t801 * t94 * t693 * ZB - 0.8e1 * t857 * t843 - t718 * t726 + 0.4e1 * t773 * t761 * t13 - 0.4e1 * t705 * t775 * t555 + 0.2e1 * t746 * t232 * t233 - 0.16e2 * t878 * t830 * t365 - 0.2e1 * t746 * t619 * t24;
+	t916 = t110 * t28;
+	t945 = t28 * t693 * t45 * t17;
+	t948 = 0.32e2 * t877 * t733 * t798 + 0.2e1 * t718 * t36 * t916 * t24 - 0.4e1 * t705 * t626 + t718 * n * t916 * t693 - t869 * t792 * t110 - 0.4e1 * t773 * t761 * t775 + t718 * t719 + 0.2e1 * t746 * t232 * t24 - 0.16e2 * t849 * t365 * xc - t718 * t713 * t110 - 0.4e1 * t773 * t694 * t29 + 0.16e2 * t877 * t54 * t945;
+	t974 = t761 * t797;
+	t987 = 0.4e1 * t773 * t695 + 0.4e1 * t736 * t150 * t24 + 0.4e1 * t722 * t842 * t17 - 0.16e2 * t877 * t447 * t945 + 0.2e1 * t87 * t714 * t28 + t313 * t713 * t916 * t45 - 0.4e1 * t853 * t615 * t774 - 0.32e2 * t877 * t713 * xc * t324 + 0.16e2 * t760 * t974 + 0.4e1 * t736 * t94 * t24 * ZB + t869 * t792 * t916 - 0.8e1 * t691 * t5 * xc * t616;
+	t1021 = -t718 * t169 * t693 - 0.32e2 * t827 * t974 + 0.2e1 * t801 * t150 * t774 + 0.4e1 * t791 * t188 * t792 + 0.4e1 * t736 * t220 * t24 + 0.4e1 * t791 * t842 * t792 + 0.8e1 * t709 * t660 * t270 - t718 * t335 * t693 - 0.2e1 * t718 * t36 * t110 * t24 - 0.32e2 * t819 * t797 * t471 - t313 * t733 * t110 - 0.32e2 * t796 * t270 * t762;
+	
+	_C2A = (t147 - 0.4e1 * t65 * t217 + t418 + 0.2e1 * t150 * t222 + t327 - 0.2e1 * t149 * t19 + 0.2e1 * t335 * ZB * t24 * ZA - 0.16e2 * t312 * t313 * t355 * t59 - 0.4e1 * t281 * ZB * ZA * t597 - 0.2e1 * t505 * t45 * t281 * t58 - 0.4e1 * t211 * t2 * t53 * t76 + 0.8e1 * t305 * t286 - 0.4e1 * t122 * t499 - 0.4e1 * t331 * t332 + 0.8e1 * t345 * t177 * t60 - 0.2e1 * t142 * t177 * t82 + 0.2e1 * t72 * t281 * t415 + 0.4e1 * t349 * t96 * t41 - 0.2e1 * t81 * t64 * t76 + 0.2e1 * t58 * t80 * t59 + 0.8e1 * t345 * t177 * t41 - 0.4e1 * t8 * t499 + t242 + 0.4e1 * t8 * t518 + t625 + t685 + 0.2e1 * t328 * t174 + 0.2e1 * t331 * t455 - 0.2e1 * t33 * t2 * t4 * ZA * t82 - 0.4e1 * t626 * t191 + 0.16e2 * t364 * t373 - 0.2e1 * t621 * t597 - 0.2e1 * t439 * t568 + t492 + t533 * t96 + t232 * t96 + 0.2e1 * t567 * t441 + t561) / (t740 + t789 + t834 + t874 + t911 + t948 + t987 + t1021);
+	/****************************************************************************************/
+	t1 = n * n;
+	t2 = t1 * n;
+	t3 = t2 * 0.3141592654e1;
+	t4 = t3 * xc;
+	t5 = ZB * ZB;
+	t7 = exp(n * 0.3141592654e1);
+	t8 = t7 * t7;
+	t9 = t5 * t8;
+	t12 = exp(xc * n * 0.3141592654e1);
+	t13 = t12 * t12;
+	t14 = t13 * t13;
+	t15 = t14 * t13;
+	t19 = nx * nx;
+	t21 = nx * 0.3141592654e1;
+	t22 = sin(t21);
+	t23 = t19 * nx * t22;
+	t24 = t23 * 0.3141592654e1;
+	t25 = ZA * ZB;
+	t26 = t7 * t15;
+	t27 = t25 * t26;
+	t30 = t21 * xc;
+	t31 = sin(t30);
+	t32 = t31 * nx;
+	t33 = t32 * n;
+	t34 = ZA * ZA;
+	t35 = t8 * t8;
+	t36 = t34 * t35;
+	t40 = t2 * t34;
+	t41 = 0.3141592654e1 * t8;
+	t42 = t41 * t15;
+	t45 = t1 * t5;
+	t46 = t14 * t14;
+	t49 = t19 * t5;
+	t51 = t19 * t46;
+	t53 = t19 * t34;
+	t55 = t8 * t7;
+	t56 = t13 * t55;
+	t57 = t25 * t56;
+	t60 = t2 * nx;
+	t61 = 0.3141592654e1 * 0.3141592654e1;
+	t63 = t60 * t31 * t61;
+	t64 = xc * xc;
+	t65 = ZA * t64;
+	t66 = ZB * t8;
+	t67 = t14 * t12;
+	t68 = t66 * t67;
+	t69 = t65 * t68;
+	t72 = -0.4e1 * t4 * t9 * t15 + 0.4e1 * t24 * t27 + 0.4e1 * t33 * t36 * t12 - 0.4e1 * t40 * t42 - t45 * t46 + t45 * t14 - t49 * t14 + t51 * t5 - t53 * t14 + 0.4e1 * t24 * t57 + 0.32e2 * t63 * t69;
+	t73 = t1 * nx;
+	t75 = t73 * t31 * 0.3141592654e1;
+	t76 = t8 * t67;
+	t77 = t25 * t76;
+	t80 = t1 * t1;
+	t81 = t80 * t34;
+	t83 = t61 * t14;
+	t87 = t1 * t19;
+	t88 = cos(t30);
+	t90 = t87 * t88 * t61;
+	t91 = t5 * t64;
+	t92 = t13 * t12;
+	t93 = t8 * t92;
+	t94 = t91 * t93;
+	t100 = ZB * t64 * ZA * t8 * t92;
+	t103 = n * t19;
+	t105 = t103 * t88 * 0.3141592654e1;
+	t106 = ZA * xc;
+	t107 = ZB * t35;
+	t109 = t106 * t107 * t12;
+	t112 = t34 * xc;
+	t113 = t112 * t93;
+	t116 = t35 * t14;
+	t118 = t1 * ZA;
+	t119 = ZB * t14;
+	t122 = t1 * t46;
+	t125 = t19 * ZB;
+	t126 = t35 * ZA;
+	t127 = t125 * t126;
+	t129 = t1 * ZB;
+	t132 = -0.16e2 * t75 * t77 + 0.16e2 * t81 * t64 * t83 * t8 + 0.16e2 * t90 * t94 - 0.32e2 * t90 * t100 + 0.8e1 * t105 * t109 - 0.8e1 * t75 * t113 + t45 * t116 + 0.2e1 * t118 * t119 + 0.2e1 * t122 * t25 - 0.2e1 * t127 + 0.2e1 * t129 * t126;
+	t134 = t1 * t34;
+	t136 = t34 * t64;
+	t137 = t136 * t76;
+	t141 = t91 * t76;
+	t145 = t103 * t34;
+	t146 = 0.3141592654e1 * xc;
+	t147 = t8 * t13;
+	t153 = t14 * ZA;
+	t156 = xc * t5;
+	t157 = t156 * t93;
+	t160 = t103 * t5;
+	t162 = t146 * t8 * t15;
+	t166 = t34 * t7 * t15;
+	t169 = t134 * t116 - 0.16e2 * t63 * t137 - t49 * t116 - 0.16e2 * t63 * t141 - t53 * t116 + 0.4e1 * t145 * t146 * t147 - 0.2e1 * t51 * t25 - 0.2e1 * t125 * t153 - 0.16e2 * t75 * t157 + 0.4e1 * t160 * t162 - 0.4e1 * t24 * t166;
+	t170 = t106 * t68;
+	t177 = t35 * t92;
+	t178 = t112 * t177;
+	t181 = t156 * t76;
+	t186 = t35 * t12;
+	t187 = t112 * t186;
+	t193 = t5 * 0.3141592654e1;
+	t206 = t34 * t14;
+	t207 = t206 * t7;
+	t210 = -0.32e2 * t63 * t170 + 0.32e2 * t90 * t170 + 0.8e1 * t75 * t109 + 0.4e1 * t105 * t178 - 0.16e2 * t75 * t181 - 0.16e2 * t90 * t113 - 0.4e1 * t75 * t187 + 0.16e2 * t90 * t141 - 0.4e1 * t103 * t15 * t193 * xc + 0.16e2 * t73 * t22 * t34 * t146 * t26 + 0.4e1 * t32 * n * t34 * t67 + 0.4e1 * t24 * t207;
+	t217 = t106 * t66 * t92;
+	t226 = t88 * t19 * n;
+	t227 = 0.3141592654e1 * t34;
+	t229 = t227 * xc * t67;
+	t232 = t73 * t31;
+	t234 = t146 * t5 * t67;
+	t238 = t61 * ZB;
+	t239 = t14 * t8;
+	t240 = t238 * t239;
+	t243 = t136 * t93;
+	t246 = -0.8e1 * t33 * t25 * t186 + 0.32e2 * t90 * t217 - t45 * t35 + t53 * t35 - t134 * t35 - t134 * t46 + t134 * t14 - 0.4e1 * t226 * t229 + 0.4e1 * t232 * t234 + 0.32e2 * t87 * t65 * t240 + 0.16e2 * t63 * t243;
+	t247 = t14 * t92;
+	t249 = t227 * t247 * xc;
+	t254 = t73 * t22;
+	t259 = t60 * t22 * t61;
+	t260 = t112 * t26;
+	t264 = t146 * t247 * t5;
+	t268 = xc * t14;
+	t274 = t5 * t14;
+	t275 = t274 * t8;
+	t280 = n * nx;
+	t281 = t280 * t22;
+	t282 = t55 * t14;
+	t283 = t25 * t282;
+	t290 = ZA * t247 * xc * ZB;
+	t295 = t22 * nx * t1 * 0.3141592654e1;
+	t298 = -0.4e1 * t232 * t249 + 0.8e1 * t105 * t217 - 0.4e1 * t254 * t227 * t26 - 0.8e1 * t259 * t260 - 0.4e1 * t232 * t264 - 0.16e2 * t81 * t61 * t268 * t8 + 0.16e2 * t80 * t64 * t61 * t275 - 0.4e1 * t232 * t229 + 0.8e1 * t281 * t283 - 0.4e1 * t105 * t187 + 0.8e1 * t75 * t290 + 0.4e1 * t295 * t27;
+	t301 = t61 * t5;
+	t307 = t87 * t34;
+	t312 = t61 * xc;
+	t313 = t312 * t239;
+	t317 = t34 * t55 * t14;
+	t329 = ZB * t13 * t55;
+	t330 = t65 * t329;
+	t337 = -0.16e2 * t87 * t64 * t301 * t239 - 0.32e2 * t90 * t69 - 0.16e2 * t307 * t64 * t61 * t239 + 0.16e2 * t307 * t313 + 0.4e1 * t24 * t317 + t53 * t46 + t49 * t35 - 0.32e2 * t63 * t100 - 0.4e1 * t280 * t31 * t34 * t247 + 0.8e1 * t259 * t330 - 0.4e1 * t280 * t31 * t247 * t5;
+	t340 = t5 * t35;
+	t344 = t25 * t93;
+	t356 = t41 * t13;
+	t360 = t23 * n * t61;
+	t363 = t25 * t64 * t7 * t15;
+	t366 = t156 * t177;
+	t369 = t14 * t7;
+	t370 = t25 * t369;
+	t373 = t156 * t186;
+	t378 = 0.4e1 * t24 * t283 + 0.4e1 * t33 * t340 * t12 - 0.16e2 * t75 * t344 - 0.4e1 * t280 * t31 * t5 * t67 + 0.8e1 * t33 * t25 * t247 + 0.32e2 * t63 * t217 + 0.4e1 * t40 * t356 - 0.8e1 * t360 * t363 + 0.4e1 * t75 * t366 + 0.4e1 * t295 * t370 - 0.4e1 * t75 * t373 - 0.4e1 * t105 * t366;
+	t382 = t112 * t76;
+	t387 = t80 * t61;
+	t391 = t136 * t26;
+	t409 = 0.16e2 * t63 * t382 + 0.4e1 * t226 * t234 - 0.16e2 * t387 * xc * t275 + 0.8e1 * t259 * t391 - 0.16e2 * t105 * t344 + 0.4e1 * t226 * t264 - 0.8e1 * t105 * t170 + 0.16e2 * t232 * t193 * t76 + 0.8e1 * t360 * t330 - 0.8e1 * t105 * t290 + 0.16e2 * t90 * t243;
+	t423 = t153 * t8;
+	t426 = t34 * t13;
+	t427 = t426 * t55;
+	t430 = t34 * t8;
+	t437 = t80 * ZA;
+	t441 = 0.4e1 * t145 * t42 - 0.16e2 * t90 * t157 + 0.24e2 * t75 * t217 + 0.4e1 * t226 * t249 + 0.4e1 * t254 * t227 * t282 + 0.4e1 * t160 * t356 - 0.8e1 * t129 * t423 - 0.8e1 * t281 * t427 - 0.8e1 * t33 * t430 * t67 + 0.8e1 * t33 * t430 * t92 + 0.32e2 * t437 * ZB * t313;
+	t453 = t106 * ZB * t7 * t15;
+	t456 = t2 * t5;
+	t459 = t112 * t56;
+	t462 = t126 * t14;
+	t474 = t40 * 0.3141592654e1;
+	t475 = xc * t8;
+	t480 = t146 * t13 * t35;
+	t483 = -0.4e1 * t103 * xc * t193 * t147 + 0.16e2 * t87 * t61 * t156 * t239 + 0.8e1 * t259 * t453 - 0.4e1 * t456 * t356 + 0.8e1 * t259 * t459 - 0.2e1 * t125 * t462 - 0.8e1 * t281 * t207 + 0.16e2 * t295 * t459 - 0.8e1 * t60 * t22 * ZA * t312 * t329 + 0.4e1 * t474 * t475 * t15 + 0.4e1 * t160 * t480;
+	t497 = t136 * t56;
+	t504 = t9 * t13;
+	t509 = t475 * t13;
+	t512 = -0.8e1 * t105 * t113 - 0.4e1 * t254 * t227 * t56 + 0.8e1 * t281 * t57 + 0.4e1 * t295 * t283 + 0.2e1 * t129 * t462 + 0.4e1 * t24 * t370 - 0.8e1 * t360 * t497 - 0.4e1 * t24 * t427 - 0.4e1 * t145 * t162 + 0.4e1 * t4 * t504 - 0.8e1 * t281 * t370 - 0.4e1 * t474 * t509;
+	t528 = t5 * t13;
+	t529 = t528 * t35;
+	t532 = t106 * t329;
+	t542 = -0.16e2 * t295 * t453 - 0.32e2 * t437 * t64 * t240 + 0.8e1 * t281 * t317 + 0.24e2 * t75 * t170 - 0.4e1 * t75 * t178 + 0.8e1 * t360 * t453 - 0.4e1 * t4 * t529 - 0.16e2 * t295 * t532 - 0.8e1 * t33 * t344 - 0.16e2 * t90 * t181 + 0.4e1 * t33 * t340 * t92;
+	t557 = t146 * t15;
+	t562 = xc * t15;
+	t563 = t562 * t5;
+	t573 = 0.16e2 * t232 * t193 * t93 - 0.8e1 * t259 * t363 - 0.8e1 * t259 * t497 + 0.8e1 * t33 * t77 + 0.8e1 * t360 * t391 + 0.4e1 * t254 * t227 * t369 + 0.4e1 * t145 * t557 + 0.8e1 * t281 * t166 + 0.4e1 * t3 * t563 + 0.8e1 * t105 * t382 - 0.4e1 * t145 * t480 - 0.4e1 * t33 * t36 * t92;
+	t600 = 0.4e1 * t456 * t42 - 0.8e1 * t360 * t260 - 0.4e1 * t40 * t557 - 0.4e1 * t105 * t373 + 0.16e2 * t226 * t227 * t93 - 0.16e2 * t90 * t382 - 0.4e1 * t145 * t356 - 0.16e2 * t63 * t157 - 0.32e2 * t87 * t25 * t313 - 0.16e2 * t226 * t227 * t76 - 0.16e2 * t63 * t113;
+	t623 = xc * t13;
+	t627 = 0.8e1 * t125 * t423 - 0.8e1 * t360 * t532 + 0.16e2 * t90 * t137 - 0.4e1 * t160 * t42 + 0.16e2 * t63 * t94 + 0.16e2 * t63 * t181 - 0.8e1 * t281 * t27 - 0.8e1 * t75 * t382 + 0.8e1 * t360 * t459 + 0.4e1 * t295 * t57 + 0.16e2 * t105 * t77 + 0.4e1 * t474 * t623 * t35;
+	t632 = t61 * 0.3141592654e1;
+	t633 = t632 * t8;
+	t634 = t80 * n;
+	t638 = t632 * t634;
+	t639 = t638 * xc;
+	t642 = t61 * t34;
+	t643 = t122 * t19;
+	t649 = t61 * t61;
+	t650 = t649 * t1;
+	t652 = t19 * t19;
+	t653 = t14 * t652;
+	t654 = t653 * t9;
+	t657 = t14 * t1;
+	t658 = t657 * t19;
+	t665 = t632 * t34;
+	t666 = t665 * t2;
+	t667 = t8 * t19;
+	t668 = t667 * t623;
+	t674 = t665 * n;
+	t675 = t652 * xc;
+	t682 = 0.8e1 * t633 * t426 * t634 - 0.8e1 * t639 * t529 - 0.4e1 * t642 * t643 + 0.2e1 * t642 * t116 * t80 + 0.32e2 * t650 * t64 * t654 + 0.4e1 * t301 * t658 + 0.4e1 * t387 * t46 * ZA * ZB - 0.16e2 * t666 * t668 - 0.16e2 * t666 * t667 * t15 - 0.8e1 * t674 * t675 * t15 + 0.4e1 * t238 * t153 * t80;
+	t683 = t46 * t652;
+	t686 = t633 * t15;
+	t691 = t35 * t80;
+	t698 = t35 * t652;
+	t705 = t14 * t80;
+	t708 = t61 * t35;
+	t717 = -0.2e1 * t642 * t683 - 0.8e1 * t686 * t5 * t634 * xc - 0.2e1 * t301 * t691 + 0.8e1 * t638 * t563 - 0.2e1 * t642 * t691 - 0.2e1 * t642 * t698 - 0.2e1 * t301 * t698 - 0.2e1 * t301 * t683 + 0.2e1 * t642 * t705 + 0.2e1 * t708 * t274 * t80 + 0.2e1 * t301 * t653 - 0.2e1 * t642 * t80 * t46;
+	t727 = t61 * t46;
+	t737 = t649 * t34;
+	t738 = t737 * t1;
+	t739 = t8 * t652;
+	t740 = t739 * t268;
+	t746 = t61 * ZA;
+	t754 = t632 * n * xc;
+	t758 = 0.2e1 * t301 * t705 + 0.2e1 * t642 * t653 - 0.8e1 * t665 * xc * t634 * t15 - 0.2e1 * t727 * t5 * t80 - 0.32e2 * t650 * xc * t654 + 0.2e1 * t301 * t698 * t14 - 0.32e2 * t738 * t740 + 0.8e1 * t674 * t739 * t562 + 0.4e1 * t746 * t119 * t652 + 0.8e1 * t674 * t698 * t623 - 0.8e1 * t754 * t528 * t698;
+	t762 = t633 * t13;
+	t764 = t5 * n * t652;
+	t767 = t80 * t1;
+	t768 = t649 * t767;
+	t772 = t649 * ZA;
+	t773 = t772 * t129;
+	t777 = t35 * t1 * t19;
+	t780 = t632 * t5;
+	t781 = t780 * t15;
+	t786 = t698 * ZA;
+	t790 = t64 * t14;
+	t800 = t649 * t8;
+	t809 = 0.4e1 * t238 * t126 * t80 - 0.8e1 * t762 * t764 - 0.32e2 * t768 * xc * t275 + 0.64e2 * t773 * t740 - 0.4e1 * t301 * t777 - 0.8e1 * t781 * n * t8 * t675 + 0.4e1 * t238 * t786 + 0.32e2 * t768 * t34 * t790 * t8 - 0.8e1 * t633 * t528 * t634 + 0.8e1 * t754 * t528 * t739 + 0.128e3 * t800 * t119 * t80 * t19 * t106 + 0.8e1 * t674 * t739 * t13;
+	t812 = t649 * t80;
+	t817 = t83 * ZB;
+	t824 = t746 * ZB;
+	t828 = t800 * t14;
+	t855 = -0.64e2 * t812 * xc * t274 * t667 + 0.4e1 * t817 * t786 + 0.4e1 * t727 * ZA * t652 * ZB - 0.32e2 * t824 * t657 * t667 - 0.32e2 * t828 * t34 * t767 * xc - 0.8e1 * t633 * t15 * t34 * t634 - 0.8e1 * t674 * t739 * t15 + 0.32e2 * t768 * t64 * t275 + 0.4e1 * t708 * t14 * t307 + 0.2e1 * t708 * t206 * t652 + 0.8e1 * t632 * t35 * t13 * t34 * t634 * xc;
+	t858 = t35 * t19;
+	t873 = t2 * t8;
+	t878 = t61 * t1;
+	t901 = -0.16e2 * t632 * t2 * xc * t528 * t858 + 0.8e1 * t824 * t658 + 0.4e1 * t301 * t14 * t777 - 0.8e1 * t665 * t634 * t509 - 0.8e1 * t674 * t739 * t623 - 0.16e2 * t781 * t873 * t19 * xc + 0.8e1 * t878 * t14 * t127 + 0.8e1 * t878 * ZA * t51 * ZB + 0.8e1 * t686 * t764 + 0.8e1 * t665 * xc * t634 * t15 * t8 + 0.8e1 * t633 * t15 * t5 * t634 + 0.4e1 * t387 * t14 * t107 * ZA;
+	t903 = t739 * t790;
+	t923 = t737 * t80;
+	t924 = t667 * t790;
+	t927 = t780 * t2;
+	t937 = t15 * t19 * xc;
+	t943 = 0.32e2 * t738 * t903 + 0.16e2 * t781 * t873 * t19 + 0.8e1 * t754 * t15 * t652 * t5 + 0.16e2 * t666 * t858 * t623 + 0.64e2 * t828 * t25 * t767 * xc - 0.16e2 * t762 * t456 * t19 + 0.64e2 * t923 * t924 + 0.16e2 * t927 * t668 - 0.64e2 * t768 * ZA * t790 * t66 - 0.64e2 * t773 * t903 + 0.16e2 * t927 * t937 + 0.16e2 * t666 * t667 * t562;
+	t977 = 0.64e2 * t812 * t5 * t924 + 0.8e1 * t639 * t504 + 0.8e1 * t238 * t35 * t118 * t19 + 0.4e1 * t642 * t658 - 0.16e2 * t817 * t437 * t8 - 0.128e3 * t772 * ZB * t80 * t924 + 0.16e2 * t666 * t667 * t13 - 0.4e1 * t301 * t643 - 0.16e2 * t824 * t653 * t8 - 0.4e1 * t642 * t777 - 0.64e2 * t923 * t667 * t268 - 0.16e2 * t666 * t937;
+	
+	_C3A = (t72 + t132 + t169 + t210 + t246 + t298 + t337 + t378 + t409 + t441 + t483 + t512 + t542 + t573 + t600 + t627) / (t682 + t717 + t758 + t809 + t855 + t901 + t943 + t977);
+	/****************************************************************************************/
+	_C4A = 0;
+	/****************************************************************************************/
+	t1 = nx * 0.3141592654e1;
+	t2 = t1 * xc;
+	t3 = cos(t2);
+	t4 = nx * nx;
+	t6 = n * 0.3141592654e1;
+	t7 = t3 * t4 * t6;
+	t8 = ZA * ZB;
+	t9 = exp(t6);
+	t10 = t9 * t9;
+	t11 = xc * n;
+	t13 = exp(t11 * 0.3141592654e1);
+	t14 = t13 * t13;
+	t15 = t14 * t13;
+	t16 = t14 * t14;
+	t17 = t16 * t15;
+	t18 = t10 * t17;
+	t19 = t8 * t18;
+	t22 = sin(t2);
+	t23 = nx * t22;
+	t24 = t23 * n;
+	t25 = ZB * ZB;
+	t30 = n * n;
+	t31 = t30 * n;
+	t32 = t31 * nx;
+	t33 = 0.3141592654e1 * 0.3141592654e1;
+	t35 = t32 * t22 * t33;
+	t36 = ZA * ZA;
+	t37 = t36 * xc;
+	t38 = t16 * t13;
+	t39 = t10 * t38;
+	t40 = t37 * t39;
+	t43 = sin(t1);
+	t44 = nx * t43;
+	t45 = t30 * 0.3141592654e1;
+	t46 = t44 * t45;
+	t47 = ZA * xc;
+	t49 = ZB * t16 * t9;
+	t54 = t4 * nx * t43;
+	t55 = xc * xc;
+	t57 = t54 * t30 * t55;
+	t58 = t33 * 0.3141592654e1;
+	t59 = t58 * t25;
+	t60 = t16 * t9;
+	t61 = t59 * t60;
+	t64 = xc * t25;
+	t65 = t14 * t9;
+	t66 = t64 * t65;
+	t70 = t44 * t31 * t33;
+	t71 = t37 * t65;
+	t74 = t10 * t15;
+	t75 = t64 * t74;
+	t78 = t25 * t10;
+	t83 = t54 * n * t33;
+	t84 = t55 * t25;
+	t85 = t10 * t9;
+	t86 = t14 * t85;
+	t87 = t84 * t86;
+	t90 = t30 * t30;
+	t92 = t44 * t90 * t58;
+	t93 = t55 * xc;
+	t94 = t93 * t25;
+	t95 = t85 * t16;
+	t96 = t94 * t95;
+	t102 = t23 * t45;
+	t103 = t10 * t10;
+	t104 = ZB * t103;
+	t106 = t47 * t104 * t15;
+	t111 = t54 * 0.3141592654e1;
+	t112 = t25 * t85;
+	t113 = t112 * t16;
+	t115 = t8 * t39;
+	t118 = t16 * t14;
+	t119 = t85 * t118;
+	t120 = t37 * t119;
+	t123 = t16 * t16;
+	t124 = t36 * t123;
+	t125 = t124 * t9;
+	t127 = -0.8e1 * t7 * t19 + 0.2e1 * t24 * t25 * t13 * t10 - 0.16e2 * t35 * t40 - 0.16e2 * t46 * t47 * t49 - 0.8e1 * t57 * t61 + 0.4e1 * t46 * t66 + 0.2e1 * t70 * t71 - 0.16e2 * t35 * t75 + 0.6e1 * t24 * t78 * t38 - 0.2e1 * t83 * t87 - 0.8e1 * t92 * t96 - 0.8e1 * t46 * t37 * t95 - 0.12e2 * t102 * t106 + 0.2e1 * t83 * t71 + t111 * t113 + 0.8e1 * t7 * t115 + 0.2e1 * t83 * t120 + t111 * t125;
+	t128 = t37 * t74;
+	t131 = t44 * n;
+	t133 = t25 * t9 * t118;
+	t136 = t36 * t14;
+	t137 = t136 * t9;
+	t140 = t30 * t4;
+	t142 = t140 * t3 * t33;
+	t143 = t64 * t39;
+	t147 = t30 * nx * t43;
+	t148 = 0.3141592654e1 * t36;
+	t149 = t9 * t118;
+	t153 = t44 * t31 * ZA;
+	t154 = t33 * xc;
+	t155 = t154 * t49;
+	t160 = ZA * t17 * xc * ZB;
+	t163 = t103 * t13;
+	t164 = t64 * t163;
+	t170 = t44 * t90 * t55;
+	t171 = t58 * ZB;
+	t172 = ZA * t16;
+	t174 = t171 * t172 * t9;
+	t177 = t36 * t55;
+	t178 = t177 * t149;
+	t181 = t54 * t11;
+	t182 = t33 * t25;
+	t186 = t25 * t14;
+	t187 = t186 * t9;
+	t193 = t186 * t85;
+	t198 = ZB * t55;
+	t199 = ZA * t103;
+	t201 = t198 * t199 * t15;
+	t204 = 0.2e1 * t7 * t128 - 0.2e1 * t131 * t133 - 0.2e1 * t131 * t137 + 0.16e2 * t142 * t143 - t147 * t148 * t149 + 0.8e1 * t153 * t155 - 0.4e1 * t7 * t160 + 0.2e1 * t7 * t164 + 0.10e2 * t102 * t40 + 0.16e2 * t170 * t174 + 0.2e1 * t83 * t178 - 0.2e1 * t181 * t182 * t65 - t111 * t187 - 0.2e1 * t70 * t87 + 0.4e1 * t102 * t160 - 0.2e1 * t131 * t193 - 0.16e2 * t142 * t75 + 0.16e2 * t35 * t201;
+	t210 = t32 * t22;
+	t211 = t33 * t55;
+	t212 = t25 * t38;
+	t213 = t211 * t212;
+	t216 = n * nx;
+	t217 = t22 * t25;
+	t222 = ZB * t85 * t16;
+	t226 = t23 * t30;
+	t227 = t13 * t10;
+	t228 = t148 * t227;
+	t233 = t37 * t163;
+	t237 = n * t4 * t3;
+	t238 = t148 * t74;
+	t241 = t64 * t86;
+	t245 = t148 * xc * t15;
+	t248 = t112 * t118;
+	t250 = t22 * t36;
+	t256 = 0.3141592654e1 * t25;
+	t257 = t256 * t39;
+	t262 = t38 * t103;
+	t263 = t37 * t262;
+	t267 = t148 * t17 * xc;
+	t270 = -0.6e1 * t7 * t143 - 0.4e1 * t24 * t19 - 0.8e1 * t210 * t213 - 0.2e1 * t216 * t217 * t15 - 0.32e2 * t153 * t211 * t222 + 0.4e1 * t226 * t228 + 0.16e2 * t142 * t201 + 0.2e1 * t7 * t233 - 0.4e1 * t237 * t238 - 0.2e1 * t83 * t241 - 0.2e1 * t237 * t245 + t111 * t248 + 0.2e1 * t216 * t250 * t15 - 0.2e1 * t131 * t125 - 0.4e1 * t226 * t257 + t147 * t148 * t95 - 0.2e1 * t102 * t263 + 0.2e1 * t237 * t267;
+	t273 = t37 * t149;
+	t277 = t47 * t104 * t13;
+	t285 = t31 * t36;
+	t286 = t44 * t285;
+	t291 = t25 * t123 * t9;
+	t304 = 0.3141592654e1 * xc;
+	t305 = t304 * t212;
+	t312 = t256 * t18;
+	t315 = t8 * t60;
+	t319 = t54 * t30 * t58;
+	t323 = t90 * t36;
+	t324 = t44 * t323;
+	t325 = t55 * t58;
+	t326 = t325 * t60;
+	t329 = 0.2e1 * t102 * t164 + 0.2e1 * t83 * t273 - 0.4e1 * t102 * t277 - 0.2e1 * t7 * t263 + 0.4e1 * t24 * t8 * t17 - 0.4e1 * t286 * t154 * t60 - 0.2e1 * t131 * t291 - t147 * t148 * t119 + 0.2e1 * t24 * t78 * t17 + 0.2e1 * t54 * t85 * 0.3141592654e1 * ZA * ZB - 0.4e1 * t226 * t305 - 0.2e1 * t70 * t66 + t147 * t256 * t95 + 0.4e1 * t237 * t312 + 0.2e1 * t111 * t315 - 0.8e1 * t319 * t96 - t111 * t193 - 0.8e1 * t324 * t326;
+	t332 = t8 * t95;
+	t335 = t136 * t85;
+	t337 = t256 * t227;
+	t340 = t177 * t119;
+	t346 = t37 * t86;
+	t351 = t103 * t15;
+	t352 = t177 * t351;
+	t355 = t64 * t119;
+	t358 = t8 * t227;
+	t361 = t85 * 0.3141592654e1;
+	t365 = t84 * t39;
+	t372 = ZB * t10;
+	t373 = t372 * t38;
+	t374 = t47 * t373;
+	t379 = t177 * t39;
+	t384 = -0.2e1 * t46 * t332 + t111 * t335 + 0.4e1 * t237 * t337 - 0.2e1 * t83 * t340 + 0.16e2 * t286 * t211 * t95 + 0.2e1 * t70 * t346 - 0.8e1 * t170 * t61 - 0.8e1 * t142 * t352 - 0.2e1 * t83 * t355 - 0.4e1 * t24 * t358 + 0.2e1 * t147 * t361 * t8 + 0.8e1 * t35 * t365 - 0.2e1 * t226 * t267 + 0.8e1 * t102 * t115 - 0.12e2 * t102 * t374 + 0.16e2 * t142 * t40 - 0.8e1 * t142 * t379 + 0.4e1 * t237 * t228;
+	t386 = t54 * t30 * t93;
+	t387 = ZA * t85;
+	t389 = t171 * t387 * t16;
+	t394 = t64 * t60;
+	t398 = t304 * t25 * t15;
+	t401 = t361 * t25;
+	t405 = t84 * t65;
+	t410 = t148 * t18;
+	t414 = t25 * t16 * t9;
+	t417 = t84 * t74;
+	t422 = t177 * t86;
+	t428 = ZB * t38;
+	t429 = t47 * t428;
+	t432 = t148 * t39;
+	t439 = 0.16e2 * t386 * t389 - 0.16e2 * t386 * t174 + 0.8e1 * t46 * t394 + 0.2e1 * t237 * t398 - t147 * t401 + 0.4e1 * t7 * t374 + 0.2e1 * t83 * t405 - 0.4e1 * t46 * t241 - 0.4e1 * t226 * t410 + 0.2e1 * t131 * t414 + 0.8e1 * t35 * t417 - 0.8e1 * t142 * t365 + 0.2e1 * t70 * t422 - 0.4e1 * t181 * t182 * t60 + 0.12e2 * t102 * t429 - 0.4e1 * t226 * t432 + 0.32e2 * t35 * t374 - 0.4e1 * t7 * t106;
+	t442 = t36 * t9 * t118;
+	t444 = t123 * t9;
+	t445 = t8 * t444;
+	t448 = t361 * t36;
+	t451 = t47 * t372 * t17;
+	t454 = t94 * t60;
+	t457 = t25 * t103;
+	t465 = t47 * t372 * t15;
+	t468 = t36 * t85;
+	t469 = t468 * t16;
+	t474 = t43 * t85;
+	t478 = t8 * t74;
+	t484 = t256 * t74;
+	t489 = t198 * ZA * t10 * t15;
+	t501 = -t111 * t442 + 0.4e1 * t131 * t445 - t147 * t448 + 0.4e1 * t7 * t451 + 0.8e1 * t92 * t454 - 0.2e1 * t24 * t457 * t13 - 0.2e1 * t286 * t211 * t65 + 0.4e1 * t7 * t465 + t111 * t469 - 0.2e1 * t216 * t250 * t17 - 0.2e1 * t216 * t474 * t25 - 0.4e1 * t24 * t478 + 0.4e1 * t24 * t8 * t38 + 0.4e1 * t226 * t484 - 0.16e2 * t142 * t489 - 0.2e1 * t24 * t212 * t103 - 0.2e1 * t216 * t22 * t17 * t25 + 0.2e1 * t70 * t120;
+	t504 = t33 * t36 * t55 * t38;
+	t507 = t37 * t18;
+	t512 = t47 * ZB * t13 * t10;
+	t518 = t59 * t95;
+	t530 = t84 * t351;
+	t534 = t37 * t227;
+	t549 = -0.8e1 * t210 * t504 + 0.2e1 * t102 * t507 + 0.4e1 * t7 * t512 + t111 * t133 - 0.16e2 * t35 * t489 + 0.8e1 * t170 * t518 + 0.2e1 * t24 * t36 * t13 * t10 + 0.4e1 * t131 * t387 * ZB + 0.12e2 * t102 * t465 - 0.8e1 * t142 * t530 + t111 * t291 - 0.2e1 * t102 * t534 - 0.4e1 * t70 * t394 - 0.10e2 * t102 * t128 + 0.4e1 * t237 * t305 + 0.8e1 * t102 * t19 + 0.2e1 * t83 * t346 - 0.16e2 * t35 * t128;
+	t557 = t468 * t118;
+	t562 = t93 * t58;
+	t563 = t562 * t60;
+	t567 = t44 * t90 * t93;
+	t575 = ZA * t55;
+	t576 = t575 * t428;
+	t583 = t37 * t60;
+	t590 = t140 * t3;
+	t601 = -0.2e1 * t226 * t398 - 0.2e1 * t70 * t340 - 0.2e1 * t131 * t557 - 0.4e1 * t24 * t115 + 0.8e1 * t324 * t563 + 0.16e2 * t567 * t389 + 0.16e2 * t70 * t84 * t95 + 0.2e1 * t70 * t178 - 0.16e2 * t142 * t576 - 0.4e1 * t237 * t257 - 0.4e1 * t226 * t312 + 0.8e1 * t46 * t583 + 0.2e1 * t24 * t36 * t38 * t103 + 0.8e1 * t590 * t213 + 0.2e1 * t102 * t143 - 0.16e2 * t35 * t143 + 0.2e1 * t131 * t248 + 0.4e1 * t46 * t346;
+	t604 = n * t36;
+	t606 = t154 * t95;
+	t625 = t36 * t103;
+	t640 = t30 * t36;
+	t641 = t54 * t640;
+	t642 = t325 * t95;
+	t647 = -0.4e1 * t131 * t315 - 0.4e1 * t54 * t604 * t606 - t147 * t148 * t60 + 0.16e2 * t35 * t576 - 0.8e1 * t102 * t478 + 0.32e2 * t142 * t465 - 0.4e1 * t237 * t484 - 0.2e1 * t70 * t355 + 0.2e1 * t70 * t273 + 0.2e1 * t102 * t233 - 0.2e1 * t24 * t625 * t13 - 0.8e1 * t7 * t358 - 0.2e1 * t111 * t445 - 0.4e1 * t7 * t429 + 0.16e2 * t46 * t47 * t222 + 0.2e1 * t131 * t113 + 0.8e1 * t641 * t642 - 0.2e1 * t7 * t534;
+	t652 = t36 * t16;
+	t653 = t652 * t9;
+	t655 = t64 * t227;
+	t658 = t182 * t95;
+	t663 = t562 * t95;
+	t684 = t64 * t351;
+	t689 = t36 * t10;
+	t695 = t154 * t222;
+	t698 = -0.4e1 * t216 * t217 * t38 - t111 * t653 - 0.2e1 * t7 * t655 - 0.4e1 * t181 * t658 + 0.2e1 * t131 * t469 - 0.8e1 * t641 * t663 - 0.4e1 * t83 * t583 - 0.2e1 * t83 * t177 * t65 - 0.4e1 * t24 * t457 * t15 + 0.16e2 * t70 * t84 * t60 + 0.8e1 * t57 * t518 - 0.32e2 * t142 * t374 + 0.4e1 * t24 * t8 * t351 + 0.4e1 * t102 * t684 - t147 * t256 * t86 - 0.2e1 * t24 * t689 * t15 - 0.2e1 * t70 * t241 + 0.8e1 * t153 * t695;
+	t711 = t575 * t373;
+	t717 = t304 * t17 * t25;
+	t736 = t177 * t74;
+	t739 = 0.2e1 * t226 * t245 - 0.8e1 * t102 * t358 - 0.16e2 * t57 * t389 - 0.2e1 * t102 * t655 + 0.8e1 * t590 * t504 - 0.8e1 * t641 * t326 - 0.16e2 * t35 * t711 - t111 * t557 + t111 * t137 - 0.2e1 * t226 * t717 + 0.8e1 * t102 * t37 * t351 + 0.2e1 * t131 * t335 - 0.4e1 * t131 * t332 - 0.2e1 * t216 * t474 * t36 - 0.2e1 * t111 * t332 + 0.16e2 * t142 * t711 - t147 * t256 * t60 + 0.8e1 * t142 * t736;
+	t750 = t64 * t262;
+	t763 = t44 * t640;
+	t770 = t84 * t119;
+	t782 = 0.4e1 * t102 * t512 + 0.8e1 * t142 * t417 + 0.8e1 * t641 * t563 - 0.2e1 * t7 * t507 + 0.2e1 * t7 * t750 - 0.8e1 * t35 * t352 + 0.4e1 * t237 * t410 + 0.4e1 * t7 * t684 - 0.2e1 * t46 * t445 + t147 * t148 * t65 + 0.4e1 * t763 * t304 * t119 + 0.16e2 * t70 * t177 * t60 + 0.2e1 * t70 * t770 - t111 * t414 - 0.16e2 * t567 * t174 - 0.4e1 * t46 * t71 - 0.4e1 * t46 * t355 - 0.4e1 * t7 * t277;
+	t797 = t64 * t149;
+	t821 = -t54 * t448 + 0.2e1 * t131 * t442 + 0.8e1 * t7 * t478 + 0.8e1 * t35 * t379 - 0.2e1 * t181 * t182 * t149 + 0.2e1 * t70 * t405 + 0.2e1 * t83 * t770 - 0.2e1 * t70 * t797 - 0.6e1 * t7 * t75 - 0.4e1 * t286 * t606 - 0.4e1 * t237 * t432 + t147 * t256 * t149 - 0.4e1 * t763 * t304 * t149 - 0.2e1 * t102 * t75 + 0.2e1 * t237 * t717 + 0.8e1 * t324 * t642 - 0.16e2 * t170 * t389 + 0.2e1 * t83 * t422;
+	t827 = t84 * t149;
+	t846 = t54 * n * ZA;
+	t854 = t64 * t18;
+	t867 = -0.16e2 * t142 * t128 + 0.32e2 * t35 * t465 - 0.2e1 * t83 * t827 + 0.2e1 * t46 * t315 + t147 * t148 * t86 - 0.4e1 * t102 * t451 - 0.8e1 * t226 * t148 * xc * t38 - 0.2e1 * t24 * t689 * t38 + 0.2e1 * t131 * t187 + 0.8e1 * t846 * t155 + 0.8e1 * t35 * t736 + 0.2e1 * t24 * t689 * t17 - 0.2e1 * t7 * t854 + t147 * t256 * t119 + 0.2e1 * t102 * t854 - 0.8e1 * t35 * t530 + 0.4e1 * t46 * t797 + 0.2e1 * t102 * t750;
+	t909 = -0.8e1 * t324 * t663 + t147 * t256 * t444 - t147 * t256 * t65 + 0.4e1 * t226 * t238 + 0.2e1 * t7 * t40 - t54 * t401 + 0.16e2 * t57 * t174 + 0.4e1 * t226 * t337 + 0.4e1 * t24 * t8 * t163 + 0.8e1 * t846 * t695 + 0.8e1 * t319 * t454 + 0.2e1 * t131 * t653 - 0.8e1 * t46 * t64 * t95 + 0.6e1 * t24 * t78 * t15 - 0.4e1 * t44 * t31 * xc * t658 - 0.32e2 * t153 * t211 * t49 - 0.2e1 * t70 * t827 + t147 * t148 * t444;
+	t914 = t25 * ZB;
+	t915 = t33 * t914;
+	t919 = t4 * t4;
+	t920 = t16 * t919;
+	t929 = t123 * t90;
+	t932 = t919 * t103;
+	t935 = t33 * ZB;
+	t939 = t652 * t919;
+	t942 = t16 * t30;
+	t943 = t942 * t4;
+	t949 = t103 * t16;
+	t950 = t949 * t90;
+	t953 = -0.2e1 * t915 * t103 * t90 + 0.2e1 * t915 * t920 - 0.2e1 * t915 * t123 * t919 + 0.2e1 * t915 * t16 * t90 - 0.2e1 * t915 * t929 - 0.2e1 * t915 * t932 - 0.2e1 * t935 * t323 * t123 + 0.2e1 * t935 * t939 + 0.4e1 * t915 * t943 + 0.4e1 * t182 * t172 * t90 + 0.2e1 * t915 * t950;
+	t954 = t171 * t36;
+	t955 = t90 * n;
+	t956 = xc * t955;
+	t957 = t118 * t10;
+	t964 = t33 * t33;
+	t965 = t964 * ZB;
+	t966 = t965 * t640;
+	t967 = t10 * t919;
+	t968 = t55 * t16;
+	t969 = t967 * t968;
+	t972 = t935 * t36;
+	t974 = t103 * t30 * t4;
+	t977 = xc * t16;
+	t978 = t967 * t977;
+	t981 = t90 * t30;
+	t983 = t16 * t10;
+	t987 = t182 * ZA;
+	t988 = t4 * t10;
+	t992 = t171 * t604;
+	t993 = xc * t14;
+	t994 = t932 * t993;
+	t997 = t182 * t30;
+	t1005 = t171 * t285;
+	t1006 = t988 * t993;
+	t1009 = t58 * t914;
+	t1010 = t1009 * t31;
+	t1013 = 0.8e1 * t954 * t956 * t957 + 0.2e1 * t915 * t932 * t16 + 0.32e2 * t966 * t969 - 0.4e1 * t972 * t974 - 0.32e2 * t966 * t978 + 0.32e2 * t965 * t981 * t177 * t983 - 0.32e2 * t987 * t942 * t988 + 0.8e1 * t992 * t994 + 0.8e1 * t997 * t949 * ZA * t4 - 0.2e1 * t935 * t124 * t919 - 0.16e2 * t1005 * t1006 + 0.16e2 * t1010 * t1006;
+	t1015 = t964 * t25;
+	t1016 = ZA * t30;
+	t1017 = t1015 * t1016;
+	t1020 = t967 * t993;
+	t1031 = t1009 * t118;
+	t1032 = t31 * t10;
+	t1040 = t964 * t914;
+	t1041 = t1040 * t90;
+	t1044 = t55 * t10 * t4 * t16;
+	t1047 = t1040 * t30;
+	t1050 = t123 * ZA;
+	t1054 = t977 * t988;
+	t1057 = 0.64e2 * t1017 * t978 - 0.8e1 * t992 * t1020 + 0.2e1 * t972 * t950 + 0.4e1 * t182 * t929 * ZA + 0.4e1 * t182 * t199 * t90 - 0.16e2 * t1031 * t1032 * t4 * xc + 0.4e1 * t182 * t172 * t919 + 0.64e2 * t1041 * t1044 + 0.32e2 * t1047 * t969 + 0.4e1 * t182 * t1050 * t919 - 0.64e2 * t1041 * t1054;
+	t1058 = t1009 * n;
+	t1063 = t932 * ZA;
+	t1069 = t123 * t30 * t4;
+	t1080 = t993 * t103 * t4;
+	t1088 = t935 * t103;
+	t1094 = -0.8e1 * t1058 * t994 - 0.32e2 * t1047 * t978 + 0.4e1 * t182 * t1063 - 0.4e1 * t915 * t974 - 0.4e1 * t915 * t1069 - 0.2e1 * t935 * t625 * t90 - 0.8e1 * t1009 * t10 * t14 * t955 - 0.16e2 * t1010 * t1080 - 0.2e1 * t935 * t625 * t919 - 0.64e2 * t1017 * t969 + 0.2e1 * t1088 * t939 + 0.8e1 * t1009 * t957 * t955;
+	t1113 = t955 * t118 * xc;
+	t1120 = t4 * t118;
+	t1125 = t981 * xc;
+	t1133 = n * t10;
+	t1140 = -0.8e1 * t954 * t955 * t10 * t993 + 0.2e1 * t935 * t652 * t90 - 0.64e2 * t1015 * t981 * t575 * t983 + 0.8e1 * t182 * t103 * t1016 * t4 + 0.8e1 * t1009 * t1113 + 0.16e2 * t954 * t1032 * t4 * t14 - 0.16e2 * t954 * t1032 * t1120 + 0.64e2 * t1015 * t10 * t172 * t1125 + 0.8e1 * t171 * t103 * t136 * t956 - 0.8e1 * t1031 * t1133 * t919 * xc + 0.8e1 * t1058 * t1020;
+	t1153 = xc * t118;
+	t1165 = t182 * t16;
+	t1170 = t171 * t10;
+	t1178 = ZA * t90;
+	t1182 = 0.4e1 * t1088 * t652 * t140 + 0.8e1 * t954 * t1133 * t919 * t14 + 0.4e1 * t972 * t943 - 0.4e1 * t972 * t1069 - 0.16e2 * t954 * t31 * t4 * t1153 - 0.8e1 * t954 * n * t919 * t1153 - 0.8e1 * t954 * t1133 * t919 * t118 + 0.4e1 * t1165 * t1063 + 0.16e2 * t1005 * t1080 - 0.8e1 * t1170 * t118 * t36 * t955 - 0.16e2 * t987 * t920 * t10 - 0.16e2 * t1165 * t1178 * t10;
+	t1195 = t1040 * t981;
+	t1199 = t1009 * t955;
+	t1203 = t1009 * t10;
+	t1211 = t965 * t323;
+	t1225 = -0.32e2 * t965 * t10 * t652 * t1125 + 0.4e1 * t915 * t16 * t974 + 0.4e1 * t182 * t90 * t949 * ZA + 0.32e2 * t1195 * t968 * t10 - 0.8e1 * t1199 * t993 * t103 + 0.8e1 * t1203 * t118 * n * t919 + 0.8e1 * t1170 * t136 * t955 + 0.64e2 * t1211 * t1044 + 0.16e2 * t1031 * t1032 * t4 + 0.8e1 * t987 * t943 + 0.8e1 * t1199 * t993 * t10 + 0.8e1 * t997 * t1050 * t4;
+	t1263 = -0.128e3 * t1015 * t1178 * t1044 + 0.16e2 * t1005 * t988 * t1153 + 0.8e1 * t1058 * t1153 * t919 + 0.16e2 * t1010 * t1120 * xc - 0.8e1 * t954 * t1113 - 0.8e1 * t1203 * t14 * n * t919 - 0.16e2 * t1203 * t14 * t31 * t4 - 0.8e1 * t1203 * t1113 - 0.32e2 * t1195 * t977 * t10 - 0.64e2 * t1211 * t1054 + 0.8e1 * t992 * t967 * t1153 + 0.128e3 * t1015 * t983 * t90 * t4 * t47;
+	
+	_C1B = (t127 + t204 + t270 + t329 + t384 + t439 + t501 + t549 + t601 + t647 + t698 + t739 + t782 + t821 + t867 + t909) / (t953 + t1013 + t1057 + t1094 + t1140 + t1182 + t1225 + t1263);
+	/****************************************************************************************/
+	t1 = n * n;
+	t2 = t1 * n;
+	t3 = nx * t2;
+	t4 = 0.3141592654e1 * ZA;
+	t5 = t3 * t4;
+	t6 = nx * 0.3141592654e1;
+	t7 = t6 * xc;
+	t8 = sin(t7);
+	t9 = t8 * ZB;
+	t10 = n * 0.3141592654e1;
+	t11 = exp(t10);
+	t12 = t11 * t11;
+	t15 = exp(xc * n * 0.3141592654e1);
+	t16 = t15 * t15;
+	t17 = t16 * t16;
+	t18 = t17 * t15;
+	t19 = t12 * t18;
+	t23 = t1 * t1;
+	t24 = nx * t23;
+	t25 = ZB * ZB;
+	t27 = t18 * t8;
+	t28 = 0.3141592654e1 * 0.3141592654e1;
+	t29 = xc * xc;
+	t30 = t28 * t29;
+	t34 = t1 * xc;
+	t35 = 0.3141592654e1 * ZB;
+	t36 = t34 * t35;
+	t37 = cos(t7);
+	t38 = ZA * t37;
+	t39 = nx * nx;
+	t40 = t39 * t12;
+	t41 = t16 * t15;
+	t43 = t38 * t40 * t41;
+	t46 = t25 * n;
+	t47 = t46 * 0.3141592654e1;
+	t48 = t39 * nx;
+	t49 = sin(t6);
+	t50 = t48 * t49;
+	t51 = t12 * t11;
+	t52 = t51 * t17;
+	t53 = t50 * t52;
+	t56 = t34 * 0.3141592654e1 * t25;
+	t57 = t37 * t39;
+	t58 = t17 * t41;
+	t59 = t12 * t58;
+	t60 = t57 * t59;
+	t63 = t25 * t18;
+	t64 = t57 * n;
+	t67 = ZA * ZA;
+	t68 = t67 * n;
+	t69 = 0.3141592654e1 * t48;
+	t70 = t68 * t69;
+	t71 = t49 * xc;
+	t72 = t17 * t16;
+	t73 = t11 * t72;
+	t74 = t71 * t73;
+	t77 = t1 * t67;
+	t78 = t77 * 0.3141592654e1;
+	t81 = nx * t25;
+	t82 = t81 * t49;
+	t83 = t17 * t17;
+	t85 = t1 * t83 * t11;
+	t87 = nx * ZB;
+	t88 = t8 * t2;
+	t89 = t87 * t88;
+	t90 = 0.3141592654e1 * xc;
+	t91 = t12 * t12;
+	t92 = ZA * t91;
+	t97 = ZB * ZA;
+	t98 = t97 * t37;
+	t99 = t39 * n;
+	t100 = t12 * t41;
+	t104 = 0.8e1 * t5 * t9 * t19 + 0.8e1 * t24 * t25 * t27 * t30 + 0.12e2 * t36 * t43 - t47 * t53 - 0.2e1 * t56 * t60 - 0.4e1 * t63 * t64 + 0.6e1 * t70 * t74 + 0.4e1 * t78 * t60 - t82 * t85 + 0.4e1 * t89 * t90 * t92 * t41 + 0.4e1 * t98 * t99 * t100;
+	t105 = t67 * t48;
+	t106 = t49 * t51;
+	t107 = t106 * t72;
+	t109 = t1 * 0.3141592654e1;
+	t110 = t109 * xc;
+	t115 = nx * t67;
+	t116 = t115 * t49;
+	t117 = t1 * t16;
+	t118 = t117 * t11;
+	t120 = t2 * t25;
+	t121 = t28 * 0.3141592654e1;
+	t122 = t121 * t29;
+	t123 = t120 * t122;
+	t129 = t1 * ZB;
+	t130 = t129 * t4;
+	t131 = t57 * t100;
+	t134 = t12 * t16;
+	t136 = t109 * t39;
+	t139 = ZB * t18;
+	t141 = t39 * t1;
+	t142 = t141 * t90;
+	t145 = t77 * t90;
+	t146 = t91 * t41;
+	t147 = t57 * t146;
+	t151 = t25 * t39 * t1;
+	t152 = t72 * t12;
+	t156 = t49 * t2;
+	t158 = t83 * t11;
+	t162 = -t105 * t107 + 0.8e1 * t110 * t72 * t25 * t39 - t116 * t118 + 0.8e1 * t123 * t53 + 0.8e1 * t5 * t9 * t59 - 0.8e1 * t130 * t131 - 0.8e1 * t134 * t25 * t136 - 0.12e2 * t139 * t38 * t142 - 0.8e1 * t145 * t147 - 0.8e1 * t151 * t90 * t152 - 0.2e1 * t87 * t156 * t4 * t158;
+	t164 = t115 * t88;
+	t165 = t90 * t19;
+	t168 = t25 * t48;
+	t169 = t49 * t16;
+	t170 = t169 * t11;
+	t174 = ZA * n * t69;
+	t175 = ZB * t51;
+	t176 = t175 * t17;
+	t177 = t71 * t176;
+	t180 = t1 * t29;
+	t181 = t28 * t25;
+	t182 = t180 * t181;
+	t183 = t50 * t73;
+	t186 = ZA * t1;
+	t187 = t28 * t48;
+	t188 = t186 * t187;
+	t189 = ZB * t17;
+	t190 = t189 * t11;
+	t191 = t71 * t190;
+	t194 = t50 * t158;
+	t196 = t115 * t156;
+	t197 = t90 * t73;
+	t201 = t49 * t17 * t11;
+	t204 = t88 * t90;
+	t207 = t68 * 0.3141592654e1;
+	t208 = t17 * t11;
+	t209 = t50 * t208;
+	t211 = -0.2e1 * t164 * t165 - t168 * t170 + t168 * t107 + 0.8e1 * t174 * t177 + 0.2e1 * t182 * t183 + 0.8e1 * t188 * t191 + t47 * t194 - 0.6e1 * t196 * t197 - t168 * t201 - 0.4e1 * t81 * t18 * t204 - t207 * t209;
+	t212 = t2 * 0.3141592654e1;
+	t213 = t212 * t52;
+	t215 = t81 * t8;
+	t216 = t212 * t59;
+	t219 = t3 * t90;
+	t220 = t25 * t8;
+	t221 = t18 * t91;
+	t225 = t71 * t52;
+	t231 = t16 * t51;
+	t232 = t50 * t231;
+	t237 = ZA * t12;
+	t243 = t67 * t28;
+	t244 = t24 * t243;
+	t245 = t71 * t231;
+	t249 = -t116 * t213 - 0.4e1 * t215 * t216 + 0.2e1 * t219 * t220 * t221 - 0.4e1 * t70 * t225 + 0.4e1 * t98 * t99 * t146 + t47 * t232 - 0.2e1 * t145 * t57 * t221 + 0.4e1 * t89 * t90 * t237 * t41 - t105 * t201 - 0.6e1 * t244 * t245 + t105 * t170;
+	t252 = t25 * t37;
+	t253 = t252 * t39;
+	t255 = n * t15 * t12;
+	t258 = t2 * t29;
+	t259 = ZB * t28;
+	t260 = t258 * t259;
+	t263 = t106 * t17;
+	t265 = xc * t25;
+	t269 = t25 * t49;
+	t270 = t269 * t52;
+	t273 = t1 * t25;
+	t274 = t273 * 0.3141592654e1;
+	t275 = t57 * t19;
+	t278 = t24 * t30;
+	t288 = t1 * t11 * t72;
+	t290 = t212 * t208;
+	t292 = t2 * xc;
+	t296 = 0.2e1 * t253 * t255 + 0.16e2 * t260 * t43 + t105 * t263 - 0.4e1 * t10 * t265 * t53 + 0.4e1 * t219 * t270 - 0.12e2 * t274 * t275 + 0.8e1 * t278 * t270 - 0.2e1 * ZB * n * t69 * t49 * ZA * t158 - t82 * t288 - t116 * t290 + 0.16e2 * t292 * t243 * t275;
+	t301 = t50 * t176;
+	t304 = t51 * t72;
+	t305 = t71 * t304;
+	t308 = t25 * t41;
+	t311 = ZA * t48;
+	t312 = t311 * t49;
+	t317 = t91 * t15;
+	t318 = t57 * t317;
+	t321 = t81 * t88;
+	t322 = t90 * t59;
+	t325 = t212 * t231;
+	t327 = t15 * t12;
+	t328 = t57 * t327;
+	t331 = t77 * t187;
+	t334 = t2 * ZA;
+	t335 = t334 * t122;
+	t336 = t50 * t190;
+	t339 = 0.8e1 * t151 * t90 * t134 + 0.16e2 * t186 * t30 * t301 - 0.2e1 * t70 * t305 + 0.2e1 * t308 * t64 - 0.2e1 * t312 * ZB * t83 * t11 + 0.2e1 * t56 * t318 + 0.2e1 * t321 * t322 - t116 * t325 - 0.4e1 * t274 * t328 + 0.2e1 * t331 * t305 - 0.16e2 * t335 * t336;
+	t341 = t169 * t51;
+	t344 = t49 * t11 * t72;
+	t346 = t77 * t30;
+	t347 = t50 * t304;
+	t350 = t25 * t51;
+	t352 = nx * ZA;
+	t353 = t49 * t23;
+	t354 = t352 * t353;
+	t355 = t28 * xc;
+	t362 = t25 * t91;
+	t365 = t23 * n;
+	t366 = nx * t365;
+	t367 = t366 * t122;
+	t368 = ZB * t49;
+	t369 = ZA * t51;
+	t370 = t369 * t17;
+	t371 = t368 * t370;
+	t374 = t115 * t353;
+	t375 = t355 * t73;
+	t381 = t105 * t341 - t105 * t344 - 0.2e1 * t346 * t347 - t350 * t50 - 0.8e1 * t354 * t355 * t176 - 0.4e1 * t98 * t99 * t317 - 0.2e1 * t362 * t99 - 0.16e2 * t367 * t371 + 0.6e1 * t374 * t375 - 0.8e1 * t182 * t53 - t82 * t290;
+	t382 = t71 * t208;
+	t394 = t2 * t67;
+	t395 = t394 * t122;
+	t398 = t352 * t156;
+	t402 = t17 * t12;
+	t403 = t39 * ZA;
+	t404 = t402 * t403;
+	t407 = t269 * t208;
+	t411 = t49 * t83 * t11;
+	t413 = t46 * t69;
+	t419 = -0.4e1 * t331 * t382 + 0.2e1 * t115 * t58 * t204 - 0.2e1 * t145 * t60 + 0.12e2 * t274 * t131 + 0.2e1 * t346 * t232 + 0.8e1 * t395 * t53 - 0.8e1 * t398 * t90 * t176 - 0.64e2 * t260 * t404 + 0.4e1 * t219 * t407 + t168 * t411 - 0.6e1 * t413 * t74 - 0.2e1 * t110 * t308 * t57;
+	t424 = t16 * t11;
+	t425 = t212 * t424;
+	t427 = t258 * t181;
+	t430 = t67 * t29;
+	t431 = t366 * t430;
+	t432 = t121 * t49;
+	t433 = t432 * t52;
+	t436 = n * t12;
+	t437 = t436 * t18;
+	t440 = t29 * xc;
+	t441 = t440 * t121;
+	t442 = t394 * t441;
+	t445 = t67 * t37;
+	t446 = t445 * t39;
+	t448 = n * t18 * t91;
+	t453 = t352 * t49;
+	t458 = t8 * t23;
+	t462 = t81 * t458;
+	t463 = t30 * t19;
+	t466 = -t47 * t209 + t116 * t425 - 0.8e1 * t427 * t275 + 0.8e1 * t431 * t433 - 0.2e1 * t253 * t437 - 0.8e1 * t442 * t53 - 0.2e1 * t446 * t448 + 0.2e1 * t175 * t312 + 0.6e1 * t453 * t129 * t208 + 0.8e1 * t115 * t18 * t458 * t30 + 0.8e1 * t462 * t463;
+	t470 = t436 * t58;
+	t475 = t2 * t121 * t440 * t25;
+	t485 = t212 * t73;
+	t488 = t67 * t72 * t1;
+	t490 = t39 * xc;
+	t501 = 0.4e1 * t374 * t355 * t52 + 0.2e1 * t446 * t470 - 0.8e1 * t475 * t53 - 0.2e1 * t446 * t437 - 0.4e1 * t36 * t38 * t39 * t15 * t12 - t116 * t485 + 0.8e1 * t488 * 0.3141592654e1 * t12 * t490 - t207 * t183 - 0.2e1 * t182 * t232 - 0.6e1 * t413 * t245 - 0.4e1 * t413 * t382;
+	t503 = t115 * t8;
+	t510 = t355 * t19;
+	t513 = t432 * t208;
+	t525 = t38 * t40 * t18;
+	t533 = -0.4e1 * t503 * t216 - 0.4e1 * t89 * t90 * t92 * t15 - 0.16e2 * t462 * t510 + 0.8e1 * t431 * t513 - 0.4e1 * t78 * t131 + t47 * t183 - 0.2e1 * t67 * t83 * t99 + 0.4e1 * t331 * t225 + 0.16e2 * t260 * t525 - 0.4e1 * t89 * t90 * t237 * t58 - t207 * t53;
+	t536 = t28 * t37;
+	t538 = t490 * t100;
+	t541 = t334 * t441;
+	t547 = t394 * t30;
+	t550 = t212 * t19;
+	t553 = t366 * t441;
+	t556 = n * t17;
+	t571 = -0.8e1 * t427 * t131 + 0.16e2 * t394 * t536 * t538 + 0.16e2 * t541 * t336 + 0.2e1 * t453 * t129 * t158 - 0.8e1 * t547 * t147 + 0.4e1 * t503 * t550 - 0.8e1 * t553 * t270 + 0.4e1 * t556 * ZB * t92 * t39 - 0.2e1 * t67 * t91 * t99 - t82 * t425 + 0.4e1 * t78 * t275 + 0.2e1 * t78 * xc * t41 * t57;
+	t583 = t90 * t317;
+	t594 = t212 * t158;
+	t596 = t152 * t67;
+	t602 = t67 * t17;
+	t607 = 0.8e1 * t367 * t407 - 0.4e1 * t98 * t99 * t59 + 0.16e2 * t260 * t18 * ZA * t57 + 0.2e1 * t321 * t583 - 0.6e1 * t174 * t368 * t52 - 0.4e1 * t89 * t90 * ZA * t15 * t12 + t116 * t594 - 0.8e1 * t596 * t136 - 0.4e1 * t98 * t99 * t327 + 0.2e1 * t602 * t99 + 0.2e1 * t164 * t583;
+	t613 = t83 * t25;
+	t616 = t81 * t156;
+	t627 = t90 * t231;
+	t630 = t91 * t16;
+	t638 = 0.4e1 * t196 * t90 * t208 - 0.8e1 * t130 * t60 - 0.2e1 * t613 * t99 + 0.6e1 * t616 * t197 - 0.8e1 * t547 * t131 + 0.8e1 * t67 * t18 * t37 * t142 + 0.2e1 * t145 * t328 - 0.6e1 * t196 * t627 + 0.8e1 * t630 * t67 * t142 - 0.8e1 * t547 * t275 + 0.8e1 * t395 * t209;
+	t643 = t77 * t355;
+	t648 = t115 * t458;
+	t651 = t134 * t67;
+	t657 = t30 * t304;
+	t660 = t30 * t146;
+	t665 = t25 * t17;
+	t668 = t50 * t424;
+	t671 = -0.4e1 * t321 * t90 * t146 - 0.6e1 * t643 * t232 + 0.8e1 * t182 * t209 - 0.16e2 * t648 * t510 + 0.8e1 * t651 * t136 + 0.8e1 * t89 * t4 * t100 - 0.2e1 * t374 * t657 - 0.8e1 * t648 * t660 + 0.8e1 * t130 * t328 + 0.2e1 * t665 * t99 + 0.2e1 * t346 * t668;
+	t672 = t90 * t424;
+	t676 = t120 * t536;
+	t680 = t436 * t41;
+	t688 = t366 * t67 * t440;
+	t696 = xc * t12;
+	t697 = t696 * t18;
+	t701 = t252 * t141;
+	t702 = t90 * t221;
+	t705 = 0.2e1 * t196 * t672 - t47 * t347 + 0.16e2 * t676 * t538 - t116 * t85 - 0.2e1 * t253 * t680 + t207 * t194 + 0.4e1 * t98 * t99 * t19 - 0.8e1 * t688 * t433 + 0.16e2 * t541 * t301 - 0.6e1 * t312 * t190 + 0.4e1 * t352 * t88 * t35 * t697 + 0.2e1 * t701 * t702;
+	t712 = t24 * t430;
+	t713 = t28 * t49;
+	t721 = t1 * t17 * t11;
+	t726 = ZB * xc;
+	t737 = n * t91;
+	t741 = 0.8e1 * t346 * t209 + 0.2e1 * t712 * t713 * t424 + 0.8e1 * t130 * t275 - t47 * t668 + t116 * t721 - 0.8e1 * t688 * t513 + 0.4e1 * t352 * t27 * t212 * t726 + 0.8e1 * t648 * t463 + 0.4e1 * t274 * t60 - 0.4e1 * t374 * t355 * t208 - 0.4e1 * t253 * t737 * t41;
+	t745 = t269 * t231;
+	t749 = t1 * t28 * t265;
+	t757 = t16 * t39;
+	t758 = t696 * t757;
+	t762 = t69 * t49;
+	t772 = t355 * t100;
+	t775 = t81 * t353;
+	t778 = -0.8e1 * t398 * t90 * t190 - 0.2e1 * t278 * t745 + 0.4e1 * t749 * t53 + 0.32e2 * t394 * t29 * t28 * t17 * t40 - 0.8e1 * t78 * t758 + t350 * n * t762 - 0.6e1 * t87 * t49 * t186 * t52 - 0.8e1 * t553 * t407 - 0.4e1 * t749 * t209 + 0.16e2 * t648 * t772 - 0.6e1 * t775 * t375;
+	t790 = t212 * t304;
+	t793 = t156 * 0.3141592654e1;
+	t795 = t355 * t304;
+	t800 = t91 * t39;
+	t801 = t800 * n;
+	t807 = t2 * t28;
+	t808 = t807 * t726;
+	t811 = -0.2e1 * t616 * t672 - 0.2e1 * t446 * t680 - 0.2e1 * t78 * xc * t58 * t57 + 0.8e1 * t367 * t270 - t82 * t790 + t115 * t51 * t793 - 0.2e1 * t775 * t795 + 0.8e1 * t123 * t209 + 0.2e1 * t665 * t801 - 0.2e1 * t67 * t41 * t64 - 0.32e2 * t808 * t43;
+	t812 = t117 * t51;
+	t821 = t24 * t355;
+	t827 = t90 * t304;
+	t840 = t800 * t41;
+	t844 = -t116 * t812 - 0.2e1 * t110 * t25 * t58 * t57 - 0.4e1 * t78 * t328 + t82 * t485 - 0.4e1 * t821 * t407 + 0.4e1 * t196 * t90 * t52 + 0.2e1 * t196 * t827 + t82 * t325 + 0.2e1 * t253 * t448 - 0.32e2 * t402 * t67 * t807 * t490 - t207 * t232 + 0.12e2 * t186 * t90 * ZB * t37 * t840;
+	t849 = t1 * t51;
+	t850 = t849 * t17;
+	t860 = t269 * t424;
+	t863 = t273 * t187;
+	t874 = 0.16e2 * t462 * t772 - t116 * t850 + 0.16e2 * t553 * t371 + t116 * t288 - 0.12e2 * t97 * t57 * t109 * t697 + t82 * t594 - 0.2e1 * t278 * t860 - 0.2e1 * t863 * t305 - 0.16e2 * t180 * t259 * t311 * t201 - 0.6e1 * t863 * t74 + 0.8e1 * t174 * t191;
+	t879 = xc * ZA;
+	t888 = t67 * t51;
+	t901 = ZA * t17;
+	t903 = t368 * t901 * t11;
+	t908 = -0.2e1 * t352 * t51 * t156 * t35 + 0.64e2 * t879 * t189 * t807 * t40 + 0.2e1 * t46 * t58 * t37 * t39 - t888 * t50 + t105 * t411 - 0.16e2 * t335 * t301 + 0.8e1 * t152 * t25 * t136 - 0.8e1 * t278 * t407 + 0.2e1 * t712 * t713 * t231 - 0.16e2 * t367 * t903 + 0.2e1 * t145 * t318;
+	t923 = t71 * t424;
+	t926 = t87 * t458;
+	t927 = t28 * ZA;
+	t944 = 0.8e1 * t354 * t355 * t190 - 0.8e1 * t110 * t16 * t25 * t800 - 0.2e1 * t374 * t30 * t73 - 0.16e2 * t354 * t30 * t176 - 0.2e1 * t244 * t923 - 0.32e2 * t926 * t927 * t696 * t41 - 0.32e2 * t808 * t525 + 0.6e1 * t749 * t232 - 0.8e1 * t188 * t177 + 0.4e1 * t36 * t58 * ZA * t57 + 0.4e1 * t821 * t270;
+	t948 = t90 * t327;
+	t961 = t30 * t100;
+	t964 = t29 * t49;
+	t981 = t106 * t1;
+	t983 = -0.2e1 * t219 * t220 * t100 + 0.2e1 * t321 * t948 - 0.16e2 * t189 * ZA * t99 * t12 - 0.2e1 * t369 * n * t69 * t368 + 0.2e1 * t374 * t795 - 0.8e1 * t462 * t961 - 0.8e1 * t244 * t964 * t208 + 0.2e1 * t413 * t923 + 0.4e1 * t36 * t38 * t40 * t58 - 0.2e1 * t87 * t51 * t49 * t1 * ZA + t888 * n * t762 + t115 * t981;
+	t1012 = 0.6e1 * t616 * t627 - t82 * t213 + 0.2e1 * t775 * t657 - 0.12e2 * t215 * t550 - 0.6e1 * t145 * t131 + 0.2e1 * t81 * t41 * t204 + 0.6e1 * ZB * t48 * t49 * t370 - 0.4e1 * t70 * t382 + 0.2e1 * t446 * t255 + 0.8e1 * t89 * t4 * t327 - 0.4e1 * t56 * t147;
+	t1018 = t212 * t100;
+	t1029 = t212 * t327;
+	t1040 = 0.6e1 * t70 * t245 + 0.2e1 * t56 * t328 + t207 * t668 + 0.4e1 * t503 * t1018 + 0.2e1 * t253 * t470 - 0.6e1 * t398 * t35 * t208 - 0.8e1 * t331 * t964 * t52 - 0.4e1 * t503 * t1029 + 0.6e1 * t821 * t745 + 0.4e1 * t63 * t37 * t142 + 0.16e2 * t260 * t38 * t840;
+	t1068 = t207 * t347 - 0.2e1 * t164 * t702 - 0.2e1 * t331 * t964 * t73 + 0.8e1 * t374 * t30 * t52 + 0.16e2 * t278 * t903 + 0.2e1 * t863 * t923 + 0.6e1 * t445 * t141 * t165 - 0.2e1 * t164 * t90 * t100 + 0.6e1 * t331 * t74 - 0.2e1 * t182 * t668 - 0.2e1 * t115 * t41 * t204;
+	t1079 = t58 * t8;
+	t1091 = t807 * t29;
+	t1092 = t665 * t40;
+	t1101 = ZB * t91;
+	t1102 = t403 * n;
+	t1105 = -0.4e1 * t58 * ZB * ZA * t64 - t82 * t850 + 0.2e1 * t821 * t860 + t81 * t51 * t793 + 0.2e1 * t3 * t25 * t1079 * t90 + t82 * t721 - 0.2e1 * t643 * t668 + 0.16e2 * t926 * t927 * t29 * t91 * t41 + 0.32e2 * t1091 * t1092 - 0.2e1 * t219 * t220 * t19 + 0.4e1 * t139 * ZA * t64 + 0.4e1 * t1101 * t1102;
+	t1108 = t849 * t72;
+	t1121 = t737 * t15;
+	t1124 = t29 * t12;
+	t1133 = t116 * t1108 - 0.8e1 * t475 * t209 - 0.32e2 * t807 * xc * t1092 + 0.2e1 * t278 * t269 * t73 + t82 * t812 - 0.6e1 * t56 * t131 + 0.2e1 * t253 * t1121 + 0.16e2 * t926 * t927 * t1124 * t41 + t168 * t263 - 0.2e1 * t616 * t827 + t81 * t981;
+	t1134 = t394 * t28;
+	t1159 = -0.8e1 * t1134 * t29 * t18 * t57 + t82 * t118 - 0.12e2 * t215 * t1018 + 0.2e1 * t602 * t801 - t168 * t341 + 0.2e1 * t67 * t58 * t64 + t168 * t344 - 0.6e1 * t174 * t368 * t208 + 0.16e2 * t553 * t903 + t116 * t790 - 0.4e1 * t36 * t38 * t800 * t15;
+	t1161 = n * t83;
+	t1173 = ZB * t12;
+	t1196 = 0.4e1 * t1161 * ZB * t39 * ZA - 0.4e1 * t215 * t1029 - 0.8e1 * t488 * 0.3141592654e1 * t39 * xc + 0.32e2 * t821 * ZA * t8 * t1173 * t18 - 0.8e1 * t427 * t147 + 0.6e1 * t701 * t165 - 0.16e2 * t926 * t927 * t1124 * t18 - 0.8e1 * t1091 * t63 * t57 - 0.8e1 * t442 * t209 - 0.8e1 * t462 * t660 - 0.6e1 * t398 * t35 * t52;
+	t1228 = 0.2e1 * t413 * t305 - 0.8e1 * t648 * t961 - 0.16e2 * t87 * t27 * t23 * t28 * ZA * t29 + 0.4e1 * t189 * t1102 - 0.4e1 * t87 * t1079 * t212 * t879 + 0.2e1 * t164 * t948 - 0.2e1 * t70 * t923 + 0.2e1 * t164 * t322 + 0.2e1 * t446 * t1121 + 0.2e1 * t863 * t964 * t304 - t82 * t1108 + 0.16e2 * t676 * t490 * t19;
+	t1234 = t25 * ZB;
+	t1235 = t1234 * t28;
+	t1236 = t365 * t91;
+	t1240 = ZB * t121;
+	t1241 = t1240 * t77;
+	t1242 = t39 * t39;
+	t1243 = t12 * t1242;
+	t1244 = xc * t72;
+	t1245 = t1243 * t1244;
+	t1248 = t365 * t25;
+	t1252 = t243 * n;
+	t1257 = t23 * t1;
+	t1258 = t1240 * t1257;
+	t1259 = t67 * t12;
+	t1260 = xc * t16;
+	t1268 = t1234 * t121;
+	t1269 = t1268 * t23;
+	t1272 = t1242 * t91;
+	t1280 = t67 * xc;
+	t1284 = t28 * t28;
+	t1285 = t67 * t1284;
+	t1287 = t1285 * t2 * ZB;
+	t1288 = t17 * xc;
+	t1289 = t1243 * t1288;
+	t1292 = 0.2e1 * t1235 * t1236 * t17 + 0.8e1 * t1241 * t1245 + 0.4e1 * t927 * t1248 * t91 - 0.2e1 * t1252 * ZB * t1242 * t91 - 0.8e1 * t1258 * t1259 * t1260 - 0.4e1 * t1235 * t2 * t83 * t39 + 0.16e2 * t1269 * t758 + 0.2e1 * t1252 * t189 * t1272 - 0.2e1 * t1252 * t83 * t1242 * ZB + 0.8e1 * t1258 * t630 * t1280 - 0.32e2 * t1287 * t1289;
+	t1293 = t365 * t83;
+	t1300 = ZA * t1284;
+	t1304 = t17 * t1242 * t25 * t12;
+	t1307 = t927 * t2;
+	t1311 = t23 * t2;
+	t1312 = t1300 * t1311;
+	t1316 = t1234 * t1284;
+	t1317 = t1316 * t1311;
+	t1321 = t1240 * t23;
+	t1331 = t1240 * t23 * t67;
+	t1332 = t40 * t1244;
+	t1338 = t1243 * t1260;
+	t1344 = -0.2e1 * t1235 * t1293 - 0.16e2 * t181 * t365 * t901 * t12 - 0.64e2 * t1300 * t258 * t1304 + 0.8e1 * t1307 * t613 * t39 + 0.64e2 * t1312 * t265 * t402 - 0.32e2 * t1317 * t1288 * t12 - 0.16e2 * t1321 * t67 * t39 * t1244 + 0.2e1 * t1235 * n * t1272 * t17 + 0.16e2 * t1331 * t1332 + 0.64e2 * t1300 * t292 * t1304 - 0.8e1 * t1241 * t1338 - 0.2e1 * t243 * t1293 * ZB;
+	t1346 = t1316 * t2;
+	t1349 = t927 * n;
+	t1350 = t25 * t1242;
+	t1354 = t1268 * t1257;
+	t1366 = t1268 * t1;
+	t1370 = t29 * t17;
+	t1371 = t1243 * t1370;
+	t1386 = -0.32e2 * t1346 * t1289 + 0.4e1 * t1349 * t1350 * t91 + 0.8e1 * t1354 * t1260 * t12 - 0.16e2 * t181 * n * t901 * t1243 - 0.4e1 * t1235 * t2 * t91 * t39 + 0.8e1 * t1366 * t152 * t1242 + 0.32e2 * t1287 * t1371 + 0.8e1 * t1258 * t1280 * t152 - 0.8e1 * t1354 * t1260 * t91 + 0.128e3 * t1300 * t365 * xc * t1092 + 0.8e1 * t1366 * t1338;
+	t1387 = t1257 * t12;
+	t1391 = t1240 * t1;
+	t1399 = t1272 * t1260;
+	t1412 = t1285 * t1311;
+	t1427 = -0.8e1 * t1268 * t1387 * t16 - 0.8e1 * t1391 * t67 * t1242 * t1244 - 0.4e1 * t1134 * t1101 * t39 + 0.8e1 * t1241 * t1399 - 0.8e1 * t1258 * t596 + 0.4e1 * t927 * t1293 * t25 - 0.16e2 * t1331 * t758 + 0.8e1 * t1307 * t665 * t39 + 0.32e2 * t1412 * t1370 * t1173 + 0.8e1 * t1307 * t665 * t800 + 0.8e1 * t1391 * t1259 * t1242 * t16 - 0.8e1 * t1391 * t1259 * t1242 * t72;
+	t1456 = t365 * ZB;
+	t1468 = 0.4e1 * t927 * t1248 * t17 - 0.2e1 * t1235 * n * t1242 * t91 + 0.8e1 * t1366 * t1244 * t1242 - 0.16e2 * t1269 * t134 * t39 + 0.8e1 * t1268 * t1257 * t72 * xc + 0.16e2 * t1321 * t1259 * t757 + 0.32e2 * t1317 * t1370 * t12 + 0.4e1 * t1349 * t613 * t1242 + 0.2e1 * t243 * t1456 * t17 - 0.64e2 * t1285 * t365 * t12 * t189 * t490 - 0.8e1 * t1354 * t152 * xc;
+	t1472 = t1316 * t365;
+	t1474 = t1124 * t39 * t17;
+	t1478 = t17 * t91;
+	t1504 = t72 * t39;
+	t1511 = 0.4e1 * t1134 * t189 * t800 + 0.64e2 * t1472 * t1474 + 0.4e1 * t1235 * t2 * t1478 * t39 + 0.4e1 * t1349 * t665 * t1242 - 0.8e1 * t1258 * t1280 * t72 + 0.2e1 * t1252 * t189 * t1242 + 0.2e1 * t243 * t365 * t189 * t91 + 0.4e1 * t927 * t365 * t1478 * t25 - 0.128e3 * t1300 * t1248 * t1474 - 0.2e1 * t1235 * t1236 + 0.16e2 * t1269 * t1504 * xc + 0.2e1 * t1235 * t365 * t17;
+	t1545 = -0.2e1 * t1235 * t1161 * t1242 + 0.4e1 * t1349 * t1350 * t1478 - 0.8e1 * t1366 * t1245 + 0.2e1 * t1235 * t556 * t1242 - 0.32e2 * t1412 * t402 * t726 - 0.8e1 * t1366 * t1399 + 0.8e1 * t1258 * t651 - 0.2e1 * t243 * t1456 * t91 + 0.8e1 * t1268 * t1387 * t72 - 0.16e2 * t1269 * t1332 + 0.4e1 * t1134 * t189 * t39 + 0.16e2 * t1269 * t152 * t39;
+	t1564 = t1260 * t800;
+	t1583 = 0.64e2 * t1285 * t1456 * t1474 - 0.64e2 * t1472 * t1288 * t40 - 0.8e1 * t1366 * t134 * t1242 + 0.8e1 * t1307 * t362 * t39 + 0.4e1 * t1235 * t2 * t17 * t39 + 0.32e2 * t1346 * t1371 - 0.16e2 * t1269 * t1564 - 0.16e2 * t1321 * t1259 * t1504 + 0.16e2 * t1331 * t1564 - 0.64e2 * t1312 * t29 * t25 * t402 - 0.4e1 * t1134 * t83 * t39 * ZB - 0.32e2 * t181 * t2 * t404;
+	
+	_C2B = (t1133 + t1196 + t1068 + t811 + t466 + t1012 + t381 + t162 + t249 + t533 + t844 + t104 + t1159 + t571 + t211 + t874 + t607 + t339 + t296 + t638 + t908 + t671 + t419 + t983 + t705 + t1105 + t501 + t778 + t1040 + t1228 + t741 + t944) / (t1292 + t1344 + t1386 + t1427 + t1468 + t1511 + t1545 + t1583);
+	/****************************************************************************************/
+	t1 = n * n;
+	t2 = t1 * n;
+	t3 = t2 * nx;
+	t4 = nx * 0.3141592654e1;
+	t5 = t4 * xc;
+	t6 = sin(t5);
+	t7 = 0.3141592654e1 * 0.3141592654e1;
+	t9 = t3 * t6 * t7;
+	t10 = xc * xc;
+	t11 = ZA * ZA;
+	t12 = t10 * t11;
+	t13 = n * 0.3141592654e1;
+	t14 = exp(t13);
+	t15 = t14 * t14;
+	t16 = xc * n;
+	t18 = exp(t16 * 0.3141592654e1);
+	t19 = t18 * t18;
+	t20 = t19 * t18;
+	t21 = t15 * t20;
+	t22 = t12 * t21;
+	t25 = nx * t6;
+	t26 = t1 * 0.3141592654e1;
+	t27 = t25 * t26;
+	t28 = ZA * ZB;
+	t29 = t18 * t15;
+	t30 = t28 * t29;
+	t33 = t25 * n;
+	t34 = t11 * t15;
+	t35 = t19 * t19;
+	t36 = t35 * t18;
+	t40 = t25 * t1;
+	t41 = 0.3141592654e1 * t11;
+	t42 = t15 * t36;
+	t43 = t41 * t42;
+	t46 = nx * nx;
+	t47 = t1 * t46;
+	t48 = t47 * t11;
+	t49 = t7 * xc;
+	t50 = t35 * t15;
+	t51 = t49 * t50;
+	t55 = sin(t4);
+	t56 = t46 * nx * t55;
+	t58 = t56 * n * t7;
+	t59 = ZB * ZB;
+	t60 = t10 * t59;
+	t61 = t15 * t14;
+	t62 = t19 * t61;
+	t63 = t60 * t62;
+	t66 = t19 * t14;
+	t67 = t60 * t66;
+	t70 = t28 * t42;
+	t73 = cos(t5);
+	t74 = t47 * t73;
+	t75 = t7 * t11;
+	t77 = t75 * t10 * t36;
+	t80 = t73 * t46;
+	t81 = t80 * n;
+	t82 = 0.3141592654e1 * t59;
+	t83 = t82 * t42;
+	t87 = xc * t11;
+	t88 = t87 * t62;
+	t91 = n * nx;
+	t92 = t55 * t61;
+	t96 = nx * t55;
+	t98 = t96 * t2 * t7;
+	t101 = xc * t59;
+	t102 = t101 * t62;
+	t108 = t1 * t1;
+	t109 = t108 * t7;
+	t111 = t59 * t35;
+	t112 = t111 * t15;
+	t115 = t35 * t20;
+	t123 = t1 * nx * t55;
+	t124 = t61 * t35;
+	t127 = t35 * t19;
+	t128 = t61 * t127;
+	t129 = t60 * t128;
+	t132 = t56 * t16;
+	t133 = t7 * t59;
+	t134 = t133 * t124;
+	t137 = 0.6e1 * t58 * t88 - 0.2e1 * t91 * t92 * t11 + 0.2e1 * t98 * t63 - 0.6e1 * t58 * t102 - 0.2e1 * t91 * t92 * t59 - 0.16e2 * t109 * xc * t112 - 0.2e1 * t91 * t6 * t115 * t59 + 0.12e2 * t40 * t83 + t123 * t41 * t124 - 0.2e1 * t58 * t129 + 0.4e1 * t132 * t134;
+	t139 = t56 * 0.3141592654e1;
+	t140 = t111 * t14;
+	t144 = t49 * t124;
+	t147 = t91 * t55;
+	t148 = t61 * ZA;
+	t154 = ZA * t115 * xc * ZB;
+	t157 = t7 * 0.3141592654e1;
+	t159 = t96 * t108 * t157;
+	t160 = t10 * xc;
+	t161 = t160 * t59;
+	t162 = t35 * t14;
+	t163 = t161 * t162;
+	t166 = t28 * t162;
+	t169 = t80 * t13;
+	t170 = t101 * t42;
+	t173 = t2 * t11;
+	t174 = t96 * t173;
+	t175 = t7 * t10;
+	t179 = t59 * t15;
+	t184 = t15 * t15;
+	t193 = t139 * t140 + 0.4e1 * t56 * n * t11 * t144 + 0.4e1 * t147 * t148 * ZB + 0.4e1 * t27 * t154 + 0.8e1 * t159 * t163 - 0.12e2 * t147 * t166 + 0.2e1 * t169 * t170 - 0.16e2 * t174 * t175 * t124 + 0.2e1 * t33 * t179 * t20 - 0.2e1 * t33 * t11 * t36 * t184 + 0.2e1 * t56 * t61 * 0.3141592654e1 * ZA * ZB;
+	t194 = t173 * 0.3141592654e1;
+	t195 = xc * t15;
+	t196 = t195 * t19;
+	t202 = t15 * t115;
+	t203 = t28 * t202;
+	t206 = t96 * t26;
+	t207 = t14 * t127;
+	t208 = t101 * t207;
+	t211 = t12 * t128;
+	t218 = t11 * t61;
+	t219 = t218 * t35;
+	t221 = t108 * ZA;
+	t223 = t7 * ZB;
+	t224 = t223 * t50;
+	t227 = ZA * xc;
+	t228 = ZB * t15;
+	t229 = t228 * t36;
+	t230 = t227 * t229;
+	t233 = t87 * t207;
+	t236 = t6 * t11;
+	t240 = -0.4e1 * t194 * t196 + 0.4e1 * t194 * t195 * t127 + 0.4e1 * t33 * t203 - 0.12e2 * t206 * t208 + 0.2e1 * t58 * t211 - 0.16e2 * t47 * t10 * t133 * t50 + t139 * t219 - 0.32e2 * t221 * t10 * t224 - 0.4e1 * t169 * t230 - 0.6e1 * t98 * t233 + 0.2e1 * t91 * t236 * t20;
+	t244 = t227 * t228 * t20;
+	t252 = t184 * t18;
+	t253 = t101 * t252;
+	t256 = t35 * t35;
+	t257 = t256 * t14;
+	t258 = t28 * t257;
+	t261 = t108 * t11;
+	t263 = t7 * t35;
+	t268 = ZB * t61 * t35;
+	t273 = t96 * t108 * t160;
+	t274 = t157 * ZB;
+	t276 = t274 * t148 * t35;
+	t279 = t101 * t21;
+	t282 = 0.3141592654e1 * xc;
+	t283 = t59 * t36;
+	t284 = t282 * t283;
+	t289 = 0.4e1 * t169 * t244 - 0.4e1 * t132 * t133 * t162 - 0.2e1 * t147 * t140 - 0.2e1 * t27 * t253 + 0.2e1 * t139 * t258 + 0.16e2 * t261 * t10 * t263 * t15 - 0.16e2 * t206 * t227 * t268 - 0.16e2 * t273 * t276 - 0.6e1 * t27 * t279 - 0.4e1 * t40 * t284 - 0.32e2 * t9 * t230;
+	t290 = t1 * t11;
+	t291 = t96 * t290;
+	t297 = t59 * t61;
+	t298 = t297 * t127;
+	t300 = ZB * t36;
+	t301 = t227 * t300;
+	t304 = t1 * t59;
+	t305 = t184 * t35;
+	t310 = t46 * ZB;
+	t311 = t184 * ZA;
+	t312 = t310 * t311;
+	t314 = t60 * t21;
+	t317 = t1 * ZA;
+	t318 = ZB * t35;
+	t321 = t1 * t256;
+	t324 = t96 * t261;
+	t325 = t10 * t157;
+	t326 = t325 * t124;
+	t329 = -0.4e1 * t291 * t282 * t128 + t123 * t82 * t62 - t139 * t298 + 0.12e2 * t27 * t301 + t304 * t305 - 0.2e1 * t58 * t12 * t66 - 0.2e1 * t312 + 0.8e1 * t9 * t314 + 0.2e1 * t317 * t318 + 0.2e1 * t321 * t28 - 0.8e1 * t324 * t326;
+	t331 = t28 * t124;
+	t334 = 0.3141592654e1 * t15;
+	t335 = t334 * t127;
+	t338 = t35 * ZA;
+	t341 = t46 * t256;
+	t344 = t46 * t11;
+	t346 = t46 * t59;
+	t348 = t297 * t35;
+	t351 = ZA * t10;
+	t352 = t351 * t300;
+	t355 = t1 * ZB;
+	t362 = 0.12e2 * t147 * t331 - 0.4e1 * t173 * t335 - 0.2e1 * t310 * t338 - 0.2e1 * t341 * t28 - t344 * t305 - t346 * t305 + 0.2e1 * t147 * t348 + 0.16e2 * t9 * t352 + 0.2e1 * t355 * t311 + t290 * t305 + 0.2e1 * t33 * t34 * t20;
+	t363 = t36 * t184;
+	t364 = t87 * t363;
+	t368 = t47 * t73 * t7;
+	t373 = t160 * t157;
+	t374 = t373 * t124;
+	t377 = t311 * t35;
+	t380 = t12 * t62;
+	t386 = ZB * t10 * ZA * t15 * t20;
+	t389 = t87 * t66;
+	t393 = t56 * t1 * t10;
+	t401 = 0.2e1 * t27 * t364 - 0.16e2 * t368 * t279 - t123 * t41 * t257 + 0.8e1 * t324 * t374 + 0.2e1 * t355 * t377 - 0.2e1 * t98 * t380 - 0.16e2 * t9 * t386 + 0.2e1 * t58 * t389 + 0.16e2 * t393 * t276 + t123 * t82 * t162 - 0.2e1 * t33 * t179 * t36;
+	t412 = t11 * t14 * t127;
+	t416 = t11 * t19;
+	t417 = t416 * t61;
+	t421 = t96 * t2 * ZA;
+	t426 = t56 * n * ZA;
+	t427 = t318 * t14;
+	t428 = t49 * t427;
+	t431 = t82 * t29;
+	t434 = t87 * t21;
+	t442 = 0.2e1 * t33 * t11 * t184 * t18 + 0.4e1 * t81 * t284 - t139 * t412 + 0.2e1 * t147 * t219 - 0.2e1 * t147 * t417 + 0.32e2 * t421 * t175 * t268 + 0.8e1 * t426 * t428 + 0.4e1 * t81 * t431 - 0.2e1 * t169 * t434 - 0.2e1 * t98 * t129 - 0.32e2 * t47 * t28 * t51;
+	t443 = t184 * t20;
+	t447 = t61 * 0.3141592654e1;
+	t448 = t447 * t11;
+	t450 = t49 * t268;
+	t453 = t60 * t42;
+	t456 = t41 * t202;
+	t463 = t101 * t443;
+	t469 = t41 * xc * t20;
+	t474 = -0.8e1 * t27 * t87 * t443 - t56 * t448 - 0.8e1 * t426 * t450 + 0.8e1 * t368 * t453 + 0.4e1 * t40 * t456 + 0.4e1 * t40 * t431 - 0.4e1 * t81 * t456 - 0.4e1 * t27 * t463 + 0.6e1 * t139 * t331 + 0.2e1 * t40 * t469 - 0.16e2 * t9 * t434;
+	t482 = t108 * t10;
+	t492 = n * t46;
+	t493 = t492 * t11;
+	t495 = t282 * t19 * t184;
+	t498 = t56 * t290;
+	t499 = t325 * t162;
+	t502 = t416 * t14;
+	t504 = t60 * t207;
+	t507 = -t123 * t82 * t257 - 0.4e1 * t169 * t301 + t123 * t41 * t162 + 0.16e2 * t482 * t7 * t112 - 0.12e2 * t206 * t102 - t123 * t82 * t66 - 0.4e1 * t147 * t258 - 0.4e1 * t493 * t495 - 0.8e1 * t498 * t499 + t139 * t502 - 0.2e1 * t98 * t504;
+	t508 = t101 * t162;
+	t512 = t41 * t115 * xc;
+	t515 = t87 * t42;
+	t520 = ZB * t184;
+	t522 = t227 * t520 * t18;
+	t525 = t492 * t59;
+	t528 = t6 * t59;
+	t532 = t520 * t20;
+	t533 = t351 * t532;
+	t539 = t447 * t59;
+	t544 = 0.8e1 * t206 * t508 - 0.2e1 * t40 * t512 - 0.16e2 * t368 * t515 + 0.12e2 * t206 * t88 + 0.4e1 * t27 * t522 + 0.4e1 * t525 * t495 - 0.4e1 * t91 * t528 * t36 - 0.16e2 * t368 * t533 - 0.16e2 * t206 * t227 * t427 - t56 * t539 - 0.2e1 * t132 * t133 * t66;
+	t551 = t87 * t162;
+	t554 = t351 * t229;
+	t560 = t59 * t19;
+	t561 = t560 * t14;
+	t564 = t101 * t202;
+	t567 = t87 * t252;
+	t573 = t227 * t228 * t115;
+	t578 = 0.4e1 * t33 * t70 + 0.4e1 * t493 * t335 - 0.4e1 * t58 * t551 + 0.16e2 * t9 * t554 - 0.4e1 * t33 * t28 * t252 + 0.2e1 * t147 * t561 + 0.2e1 * t169 * t564 - 0.2e1 * t27 * t567 - 0.8e1 * t324 * t499 - 0.4e1 * t169 * t573 + 0.12e2 * t27 * t244;
+	t579 = t82 * t202;
+	t591 = t282 * t115 * t59;
+	t598 = t101 * t66;
+	t606 = -0.4e1 * t81 * t579 - 0.2e1 * t169 * t567 - 0.6e1 * t27 * t170 + 0.8e1 * t169 * t203 + 0.2e1 * t98 * t67 + 0.2e1 * t81 * t591 + 0.32e2 * t368 * t244 - 0.2e1 * t27 * t564 + 0.4e1 * t206 * t598 + 0.16e2 * t9 * t170 + 0.2e1 * t33 * t283 * t184;
+	t608 = t373 * t162;
+	t611 = t59 * t184;
+	t617 = t101 * t29;
+	t624 = t227 * ZB * t18 * t15;
+	t629 = t157 * t59;
+	t630 = t629 * t124;
+	t633 = t3 * t6;
+	t634 = t175 * t283;
+	t644 = 0.8e1 * t498 * t608 + 0.2e1 * t33 * t611 * t18 - 0.4e1 * t206 * t389 - 0.2e1 * t27 * t617 - 0.4e1 * t169 * t154 + 0.4e1 * t27 * t624 + 0.12e2 * t27 * t230 - 0.8e1 * t393 * t630 - 0.8e1 * t633 * t634 + 0.16e2 * t47 * t7 * t101 * t50 + 0.2e1 * t123 * t447 * t28;
+	t645 = t41 * t29;
+	t648 = t2 * 0.3141592654e1;
+	t649 = t648 * xc;
+	t650 = t560 * t184;
+	t656 = t56 * t1 * t157;
+	t659 = t87 * t128;
+	t662 = t96 * t482;
+	t663 = t629 * t162;
+	t671 = t161 * t124;
+	t674 = t218 * t127;
+	t679 = 0.4e1 * t81 * t645 - 0.4e1 * t649 * t650 - 0.8e1 * t169 * t70 + 0.8e1 * t656 * t163 - 0.2e1 * t98 * t659 - 0.8e1 * t662 * t663 - 0.32e2 * t421 * t175 * t427 - 0.2e1 * t147 * t502 + 0.8e1 * t656 * t671 + 0.2e1 * t147 * t674 - 0.16e2 * t368 * t386;
+	t714 = t334 * t19;
+	t719 = t12 * t42;
+	t722 = t304 * t35 - t346 * t35 + t341 * t59 - t344 * t35 + t344 * t256 + t346 * t184 - 0.16e2 * t368 * t554 - 0.16e2 * t48 * t175 * t50 + 0.4e1 * t525 * t714 - 0.2e1 * t58 * t659 + 0.8e1 * t368 * t719;
+	t730 = xc * t19;
+	t735 = t59 * t256 * t14;
+	t752 = 0.4e1 * t173 * t714 - 0.6e1 * t27 * t515 - 0.16e2 * t9 * t279 + 0.4e1 * t194 * t730 * t184 - t139 * t735 - 0.4e1 * t492 * t127 * t82 * xc - 0.4e1 * t98 * t508 - t123 * t41 * t207 - 0.2e1 * t147 * t298 + 0.8e1 * t368 * t314 + 0.6e1 * t132 * t133 * t207;
+	t755 = t28 * t21;
+	t759 = t274 * t338 * t14;
+	t767 = t11 * t35;
+	t768 = t767 * t14;
+	t778 = t560 * t61;
+	t781 = -0.2e1 * t58 * t504 - 0.8e1 * t27 * t755 + 0.16e2 * t662 * t759 + 0.12e2 * t291 * t282 * t207 - 0.6e1 * t27 * t434 + t139 * t768 - 0.8e1 * t498 * t326 + 0.4e1 * t33 * t611 * t20 + 0.2e1 * t81 * t512 - t139 * t561 + 0.2e1 * t147 * t778;
+	t786 = t12 * t443;
+	t790 = t282 * t59 * t20;
+	t796 = t59 * t14 * t127;
+	t806 = t41 * t21;
+	t811 = -0.8e1 * t393 * t663 + 0.8e1 * t368 * t786 + 0.2e1 * t81 * t790 + 0.4e1 * t169 * t624 + t139 * t796 + 0.2e1 * t206 * t258 - 0.2e1 * t40 * t591 - 0.8e1 * t662 * t630 - 0.4e1 * t33 * t30 - 0.4e1 * t40 * t806 + 0.8e1 * t9 * t786;
+	t819 = t282 * t15 * t127;
+	t822 = t101 * t363;
+	t830 = t11 * t256 * t14;
+	t835 = t227 * t532;
+	t842 = 0.2e1 * t33 * t11 * t18 * t15 + t123 * t41 * t66 - 0.4e1 * t493 * t819 - 0.2e1 * t27 * t822 - 0.16e2 * t368 * t170 - 0.4e1 * t169 * t463 - t139 * t830 - 0.4e1 * t649 * t179 * t127 + 0.12e2 * t27 * t835 - 0.16e2 * t368 * t434 - 0.2e1 * t40 * t790;
+	t845 = t87 * t202;
+	t854 = t338 * t15;
+	t859 = t12 * t207;
+	t868 = t139 * t348 - 0.2e1 * t27 * t845 + 0.8e1 * t169 * t755 - 0.2e1 * t58 * t380 + 0.6e1 * t206 * t331 + 0.8e1 * t310 * t854 - 0.2e1 * t169 * t822 + 0.2e1 * t98 * t859 + 0.8e1 * t159 * t671 + 0.8e1 * t74 * t634 - 0.2e1 * t169 * t253;
+	t880 = t60 * t443;
+	t891 = t101 * t128;
+	t894 = -t123 * t539 - 0.2e1 * t147 * t796 + 0.32e2 * t368 * t230 + t139 * t674 - 0.16e2 * t98 * t60 * t124 + 0.32e2 * t9 * t244 + 0.8e1 * t368 * t880 - 0.8e1 * t40 * t41 * xc * t36 - t123 * t82 * t128 - 0.6e1 * t58 * t233 + 0.2e1 * t58 * t891;
+	t903 = t179 * t19;
+	t920 = t56 * t1 * t160;
+	t925 = -0.2e1 * t174 * t175 * t66 - 0.4e1 * t493 * t714 + 0.4e1 * t649 * t903 - 0.4e1 * t81 * t43 + t123 * t82 * t207 + 0.4e1 * t206 * t891 - 0.16e2 * t273 * t759 - 0.8e1 * t27 * t203 + 0.32e2 * t221 * ZB * t51 - 0.16e2 * t920 * t759 - 0.8e1 * t9 * t453;
+	t932 = t87 * t29;
+	t945 = t82 * t21;
+	t953 = -0.16e2 * t920 * t276 - 0.8e1 * t169 * t30 - 0.8e1 * t633 * t77 - 0.2e1 * t27 * t932 - 0.4e1 * t174 * t49 * t162 + 0.8e1 * t206 * t87 * t124 - 0.2e1 * t147 * t768 + 0.4e1 * t169 * t522 - 0.12e2 * t81 * t945 + 0.4e1 * t33 * t28 * t115 + 0.4e1 * t525 * t819;
+	t971 = t282 * t127;
+	t978 = -0.6e1 * t98 * t102 + 0.2e1 * t169 * t515 - 0.2e1 * t310 * t377 + 0.2e1 * t147 * t830 + 0.8e1 * t368 * t22 - 0.2e1 * t169 * t617 + 0.16e2 * t662 * t276 - 0.8e1 * t355 * t854 + 0.4e1 * t493 * t971 - 0.16e2 * t9 * t533 - 0.2e1 * t169 * t279;
+	t997 = xc * t127;
+	t998 = t997 * t59;
+	t1003 = 0.4e1 * t40 * t579 + 0.2e1 * t169 * t845 + 0.16e2 * t9 * t515 + 0.8e1 * t206 * t551 + t123 * t41 * t128 + 0.16e2 * t98 * t60 * t162 + 0.2e1 * t169 * t364 - 0.2e1 * t169 * t932 + t139 * t778 + 0.4e1 * t648 * t998 + 0.2e1 * t147 * t412;
+	t1006 = t2 * t59;
+	t1017 = xc * t35;
+	t1033 = 0.4e1 * t1006 * t335 + 0.4e1 * t81 * t806 - 0.2e1 * t33 * t34 * t115 + 0.8e1 * t498 * t374 - 0.16e2 * t261 * t7 * t1017 * t15 + 0.8e1 * t206 * t101 * t124 - t123 * t448 + 0.2e1 * t147 * t735 + 0.6e1 * t98 * t208 + 0.6e1 * t98 * t88 - 0.4e1 * t33 * t755;
+	t1055 = -0.4e1 * t173 * t971 + 0.2e1 * t98 * t891 + 0.8e1 * t9 * t880 + 0.4e1 * t169 * t835 - t304 * t184 + t344 * t184 - t123 * t41 * t62 - 0.2e1 * t98 * t598 + 0.2e1 * t58 * t859 + 0.32e2 * t47 * t351 * t224 + 0.2e1 * t98 * t389;
+	t1070 = t15 * t19;
+	t1089 = -0.16e2 * t368 * t352 - 0.8e1 * t9 * t719 + 0.4e1 * t96 * t2 * xc * t134 - 0.2e1 * t91 * t236 * t115 + 0.4e1 * t27 * t573 + 0.4e1 * t493 * t282 * t1070 + 0.2e1 * t33 * t59 * t18 * t15 + 0.12e2 * t40 * t945 - 0.4e1 * t492 * xc * t82 * t1070 - 0.2e1 * t91 * t528 * t20 + 0.8e1 * t324 * t608;
+	t1113 = t123 * t82 * t124 + 0.8e1 * t421 * t428 - t139 * t417 + 0.4e1 * t40 * t645 + 0.16e2 * t393 * t759 - 0.2e1 * t33 * t179 * t115 - 0.4e1 * t525 * t335 + 0.4e1 * t33 * t28 * t36 - 0.4e1 * t1006 * t714 + 0.6e1 * t206 * t166 - 0.8e1 * t421 * t450;
+	t1119 = t321 * t46;
+	t1122 = t157 * t11;
+	t1123 = t1122 * t2;
+	t1124 = t184 * t46;
+	t1128 = t108 * n;
+	t1132 = t7 * t7;
+	t1133 = t1132 * t11;
+	t1134 = t1133 * t108;
+	t1135 = t15 * t46;
+	t1139 = t7 * ZA;
+	t1140 = t1139 * ZB;
+	t1141 = t1 * t35;
+	t1145 = t629 * t2;
+	t1146 = t1135 * t730;
+	t1149 = t157 * t1128;
+	t1150 = t1149 * xc;
+	t1153 = t46 * xc;
+	t1154 = t1153 * t127;
+	t1158 = t184 * t1 * t46;
+	t1161 = t46 * t46;
+	t1162 = t35 * t1161;
+	t1166 = t7 * t1;
+	t1170 = -0.4e1 * t133 * t1119 + 0.16e2 * t1123 * t1124 * t730 - 0.8e1 * t1122 * t1128 * t196 - 0.64e2 * t1134 * t1135 * t1017 - 0.32e2 * t1140 * t1141 * t1135 + 0.16e2 * t1145 * t1146 - 0.8e1 * t1150 * t650 - 0.16e2 * t1123 * t1154 - 0.4e1 * t133 * t1158 - 0.16e2 * t1140 * t1162 * t15 + 0.8e1 * t1166 * t35 * t312;
+	t1171 = t1161 * t184;
+	t1175 = t1122 * n;
+	t1176 = t15 * t1161;
+	t1180 = t1132 * ZA;
+	t1181 = t1180 * t355;
+	t1182 = t1176 * t1017;
+	t1185 = t1161 * xc;
+	t1189 = t1133 * t1;
+	t1192 = t108 * t1;
+	t1193 = t1132 * t1192;
+	t1195 = t10 * t35;
+	t1199 = t157 * t15;
+	t1203 = t1141 * t46;
+	t1211 = t184 * t108;
+	t1218 = 0.2e1 * t133 * t1171 * t35 + 0.8e1 * t1175 * t1176 * t997 + 0.64e2 * t1181 * t1182 - 0.8e1 * t1175 * t1185 * t127 - 0.32e2 * t1189 * t1182 - 0.64e2 * t1193 * ZA * t1195 * t228 + 0.8e1 * t1199 * t416 * t1128 + 0.8e1 * t1140 * t1203 - 0.4e1 * t75 * t1158 - 0.8e1 * t1199 * t560 * t1128 - 0.2e1 * t133 * t1211 - 0.8e1 * t1199 * t127 * t11 * t1128;
+	t1221 = t256 * t1161;
+	t1224 = t35 * t108;
+	t1233 = t7 * t256;
+	t1236 = -t75 * t1211 - t75 * t1221 - t133 * t1221 + t75 * t1224 - t75 * t1171 - t133 * t1171 + t133 * t1224 + t75 * t1162 - t75 * t108 * t256 + t133 * t1162 - t1233 * t59 * t108;
+	t1240 = t1135 * t1195;
+	t1252 = t629 * t127;
+	t1263 = t1171 * ZA;
+	t1280 = -0.128e3 * t1180 * ZB * t108 * t1240 + 0.32e2 * t1193 * t10 * t112 + 0.4e1 * t133 * t1203 + 0.4e1 * t109 * t256 * ZA * ZB - 0.8e1 * t1252 * n * t15 * t1185 + 0.8e1 * t1175 * t1171 * t730 - 0.8e1 * t1175 * t1176 * t127 + 0.4e1 * t223 * t1263 - 0.8e1 * t1175 * t1176 * t730 + 0.8e1 * t1166 * ZA * t341 * ZB + 0.64e2 * t1134 * t1240 + 0.8e1 * t1122 * xc * t1128 * t127 * t15;
+	t1283 = t1199 * t19;
+	t1287 = t1199 * t127;
+	t1289 = t59 * n * t1161;
+	t1293 = t157 * n * xc;
+	t1304 = t1132 * t108;
+	t1310 = t263 * ZB;
+	t1316 = t2 * t15;
+	t1323 = -0.16e2 * t1283 * t1006 * t46 + 0.8e1 * t1287 * t1289 + 0.8e1 * t1293 * t127 * t1161 * t59 + 0.16e2 * t1123 * t1135 * t19 + 0.8e1 * t1293 * t560 * t1176 + 0.64e2 * t1304 * t59 * t1240 + 0.4e1 * t75 * t1203 + 0.4e1 * t1310 * t1263 + 0.4e1 * t223 * t338 * t108 - 0.16e2 * t1252 * t1316 * t1153 - 0.16e2 * t1310 * t221 * t15;
+	t1330 = t1132 * t15;
+	t1336 = t1132 * t1;
+	t1338 = t1162 * t179;
+	t1370 = 0.8e1 * t1175 * t1176 * t19 + 0.4e1 * t1139 * t318 * t1161 + 0.128e3 * t1330 * t318 * t108 * t46 * t227 - 0.32e2 * t1336 * xc * t1338 + 0.4e1 * t1233 * ZA * t1161 * ZB - 0.8e1 * t1287 * t59 * t1128 * xc + 0.2e1 * t75 * t305 * t108 + 0.8e1 * t1199 * t127 * t59 * t1128 - 0.8e1 * t1283 * t1289 - 0.8e1 * t1293 * t560 * t1171 + 0.4e1 * t133 * t35 * t1158 + 0.8e1 * t157 * t184 * t19 * t11 * t1128 * xc;
+	t1376 = t7 * t184;
+	t1380 = t1176 * t1195;
+	t1393 = t1330 * t35;
+	t1411 = 0.16e2 * t1145 * t1154 + 0.8e1 * t1149 * t998 + 0.4e1 * t1376 * t35 * t48 + 0.32e2 * t1189 * t1380 + 0.32e2 * t1193 * t11 * t1195 * t15 - 0.64e2 * t1304 * xc * t111 * t1135 - 0.16e2 * t1123 * t1146 + 0.64e2 * t1393 * t28 * t1192 * xc - 0.16e2 * t1123 * t1135 * t127 - 0.8e1 * t1122 * xc * t1128 * t127 - 0.32e2 * t1193 * xc * t112 + 0.16e2 * t1252 * t1316 * t46;
+	t1450 = 0.2e1 * t1376 * t767 * t1161 + 0.2e1 * t1376 * t111 * t108 + 0.4e1 * t223 * t311 * t108 + 0.4e1 * t109 * t35 * t520 * ZA + 0.16e2 * t1123 * t1135 * t997 - 0.64e2 * t1181 * t1380 + 0.8e1 * t1150 * t903 - 0.32e2 * t1393 * t11 * t1192 * xc - 0.16e2 * t157 * t2 * xc * t560 * t1124 + 0.8e1 * t223 * t184 * t317 * t46 + 0.32e2 * t1336 * t10 * t1338 - 0.4e1 * t75 * t1119;
+	_C3B = (t606 + t722 + t1089 + t781 + 0.16e2 * t48 * t51 + t978 + t868 + t507 - t304 * t256 + 0.8e1 * t9 * t22 + t752 + 0.4e1 * t174 * t144 - 0.2e1 * t81 * t469 + 0.6e1 * t139 * t166 + t362 + 0.2e1 * t98 * t211 + t925 + t137 - t290 * t184 + 0.12e2 * t81 * t83 + t842 + 0.8e1 * t74 * t77 + 0.16e2 * t98 * t12 * t162 - 0.4e1 * t33 * t28 * t443 - 0.8e1 * t27 * t70 - 0.2e1 * t33 * t34 * t36 - 0.8e1 * t27 * t30 + 0.2e1 * t58 * t67 - 0.4e1 * t40 * t43 + 0.2e1 * t58 * t63 + t1033 - t290 * t256 + t290 * t35 + t193 + t1113 + t578 + t442 + t474 + t544 + t329 + t679 + t401 + t953 + t811 + t644 + t894 + t289 + t240 + t1055 + t1003) / (t1170 + t1218 + 0.2e1 * t1236 + t1280 + t1323 + t1370 + t1411 + t1450);
+	/****************************************************************************************/
+	t1 = n * n;
+	t2 = t1 * xc;
+	t3 = ZB * ZB;
+	t5 = t2 * 0.3141592654e1 * t3;
+	t6 = nx * 0.3141592654e1;
+	t7 = t6 * xc;
+	t8 = cos(t7);
+	t9 = nx * nx;
+	t10 = t8 * t9;
+	t11 = n * 0.3141592654e1;
+	t12 = exp(t11);
+	t13 = t12 * t12;
+	t16 = exp(xc * n * 0.3141592654e1);
+	t17 = t16 * t16;
+	t18 = t17 * t16;
+	t19 = t17 * t17;
+	t20 = t19 * t18;
+	t21 = t13 * t20;
+	t22 = t10 * t21;
+	t25 = ZA * ZA;
+	t26 = t1 * t25;
+	t27 = xc * 0.3141592654e1;
+	t28 = t26 * t27;
+	t29 = t19 * t16;
+	t30 = t13 * t13;
+	t31 = t29 * t30;
+	t35 = t9 * nx;
+	t36 = t3 * t35;
+	t37 = sin(t6);
+	t38 = t13 * t12;
+	t39 = t37 * t38;
+	t40 = t39 * t19;
+	t42 = t1 * t1;
+	t43 = nx * t42;
+	t44 = xc * xc;
+	t45 = t25 * t44;
+	t46 = t43 * t45;
+	t47 = 0.3141592654e1 * 0.3141592654e1;
+	t48 = t47 * t37;
+	t49 = t17 * t38;
+	t54 = 0.3141592654e1 * t35;
+	t55 = ZA * n * t54;
+	t56 = t37 * ZB;
+	t57 = t19 * t12;
+	t61 = t25 * t8;
+	t62 = t61 * t9;
+	t63 = n * t30;
+	t64 = t63 * t16;
+	t67 = t1 * n;
+	t69 = t47 * ZB;
+	t70 = t67 * t44 * t69;
+	t75 = nx * t3;
+	t76 = t75 * t37;
+	t77 = t67 * 0.3141592654e1;
+	t78 = t19 * t19;
+	t79 = t78 * t12;
+	t80 = t77 * t79;
+	t82 = t3 * t38;
+	t84 = t54 * t37;
+	t87 = sin(t7);
+	t88 = t29 * t87;
+	t89 = t47 * t44;
+	t93 = nx * t25;
+	t94 = t87 * t42;
+	t95 = t93 * t94;
+	t96 = t47 * xc;
+	t97 = t13 * t29;
+	t98 = t96 * t97;
+	t101 = t87 * t67;
+	t102 = t93 * t101;
+	t103 = t13 * t18;
+	t107 = t47 * t35;
+	t108 = t26 * t107;
+	t109 = t37 * t44;
+	t110 = t19 * t17;
+	t111 = t12 * t110;
+	t116 = t37 * t19 * t12;
+	t118 = t37 * xc;
+	t119 = ZB * t19;
+	t120 = t119 * t12;
+	t121 = t118 * t120;
+	t125 = xc * t3;
+	t126 = t1 * t47 * t125;
+	t127 = t35 * t37;
+	t128 = t38 * t19;
+	t129 = t127 * t128;
+	t132 = t26 * 0.3141592654e1;
+	t133 = t16 * t13;
+	t134 = t10 * t133;
+	t137 = 0.3141592654e1 * ZB;
+	t138 = t2 * t137;
+	t139 = ZA * t8;
+	t140 = t9 * t13;
+	t145 = t30 * t18;
+	t146 = t10 * t145;
+	t149 = t3 * t8;
+	t150 = t149 * t9;
+	t153 = 0.2e1 * t5 * t22 + 0.2e1 * t28 * t10 * t31 + t36 * t40 - 0.2e1 * t46 * t48 * t49 - 0.2e1 * t55 * t56 * t57 - 0.2e1 * t62 * t64 + 0.16e2 * t70 * t29 * ZA * t10 - t76 * t80 + t82 * n * t84 + 0.8e1 * t43 * t3 * t88 * t89 + 0.16e2 * t95 * t98 + 0.2e1 * t102 * t27 * t103 - 0.2e1 * t108 * t109 * t111 + t36 * t116 + 0.8e1 * t55 * t121 - 0.4e1 * t126 * t129 - 0.4e1 * t132 * t134 - 0.4e1 * t138 * t139 * t140 * t20 + 0.8e1 * t28 * t146 - 0.2e1 * t150 * t64;
+	t154 = t42 * n;
+	t155 = nx * t154;
+	t156 = t44 * xc;
+	t157 = t47 * 0.3141592654e1;
+	t158 = t156 * t157;
+	t159 = t155 * t158;
+	t162 = t56 * ZA * t19 * t12;
+	t165 = t77 * t49;
+	t167 = t1 * t3;
+	t168 = t167 * t89;
+	t169 = t127 * t49;
+	t172 = t37 * t67;
+	t173 = t75 * t172;
+	t174 = t38 * t110;
+	t175 = t27 * t174;
+	t179 = t47 * t25;
+	t181 = t10 * t97;
+	t184 = t27 * t31;
+	t187 = t67 * t47;
+	t188 = t44 * t3;
+	t189 = t187 * t188;
+	t192 = t25 * t35;
+	t193 = t37 * t17;
+	t194 = t193 * t12;
+	t196 = nx * ZA;
+	t197 = t196 * t172;
+	t198 = ZB * t38;
+	t199 = t198 * t19;
+	t204 = t1 * t12 * t110;
+	t207 = nx * ZB;
+	t209 = t1 * ZA;
+	t215 = t67 * t3;
+	t216 = t47 * t8;
+	t217 = t215 * t216;
+	t218 = t9 * xc;
+	t222 = nx * t67;
+	t223 = t222 * t27;
+	t224 = t3 * t87;
+	t228 = t167 * t107;
+	t232 = t26 * t96;
+	t235 = t207 * t94;
+	t236 = t47 * ZA;
+	t243 = xc * t13;
+	t244 = t243 * t29;
+	t248 = t25 * n;
+	t249 = t248 * 0.3141592654e1;
+	t253 = ZB * ZA;
+	t254 = t253 * t8;
+	t255 = t9 * n;
+	t256 = t30 * t16;
+	t260 = 0.2e1 * t207 * t37 * t209 * t128 + 0.2e1 * t5 * t134 - 0.16e2 * t217 * t218 * t97 - 0.2e1 * t223 * t224 * t31 - 0.2e1 * t228 * t109 * t174 - 0.2e1 * t232 * t169 - 0.16e2 * t235 * t236 * t44 * t30 * t18 - 0.4e1 * t196 * t101 * t137 * t244 + t249 * t169 + 0.8e1 * t168 * t129 + 0.4e1 * t254 * t255 * t256;
+	t263 = t43 * t179;
+	t267 = t3 * n;
+	t268 = t267 * t54;
+	t269 = t118 * t57;
+	t272 = t39 * t1;
+	t274 = t67 * t25;
+	t275 = t274 * t158;
+	t278 = t75 * t87;
+	t279 = t77 * t103;
+	t282 = t25 * t38;
+	t285 = ZA * t38;
+	t290 = t267 * 0.3141592654e1;
+	t296 = t77 * t111;
+	t298 = t196 * t37;
+	t299 = t1 * ZB;
+	t303 = t37 * t42;
+	t304 = t196 * t303;
+	t308 = t77 * t57;
+	t310 = t26 * t89;
+	t313 = t77 * t128;
+	t316 = t101 * t27;
+	t319 = t93 * t87;
+	t320 = t77 * t97;
+	t323 = t127 * t57;
+	t326 = t10 * n;
+	t329 = t118 * t174;
+	t332 = -0.8e1 * t263 * t109 * t57 - 0.4e1 * t268 * t269 + t93 * t272 + 0.8e1 * t275 * t129 - 0.4e1 * t278 * t279 + t282 * n * t84 - 0.2e1 * t285 * n * t54 * t56 - t290 * t169 - 0.2e1 * t196 * t38 * t172 * t137 + t76 * t296 - 0.2e1 * t298 * t299 * t79 + 0.8e1 * t304 * t96 * t120 + t76 * t308 - 0.2e1 * t310 * t169 - t76 * t313 + 0.2e1 * t75 * t18 * t316 + 0.4e1 * t319 * t320 + t249 * t323 - 0.2e1 * t25 * t18 * t326 + 0.2e1 * t228 * t329;
+	t335 = t75 * t101;
+	t336 = t27 * t21;
+	t342 = t77 * t133;
+	t347 = t209 * t137;
+	t350 = t9 * t1;
+	t351 = t149 * t350;
+	t355 = t37 * t78 * t12;
+	t359 = t93 * t303;
+	t367 = t172 * 0.3141592654e1;
+	t369 = t96 * t103;
+	t376 = t209 * t107;
+	t379 = t10 * t103;
+	t383 = t207 * t101;
+	t389 = 0.3141592654e1 * ZA;
+	t390 = t222 * t389;
+	t391 = t87 * ZB;
+	t398 = -0.2e1 * t102 * t336 + t93 * t38 * t367 + 0.16e2 * t95 * t369 - t82 * t127 - 0.8e1 * t197 * t27 * t120 + 0.8e1 * t376 * t121 - 0.8e1 * t189 * t379 - t249 * t129 - 0.4e1 * t383 * t27 * ZA * t16 * t13 - 0.8e1 * t390 * t391 * t21 - 0.2e1 * t197 * t137 * t57;
+	t402 = t39 * t110;
+	t404 = t193 * t38;
+	t406 = t127 * t174;
+	t408 = t167 * 0.3141592654e1;
+	t411 = t44 * t157;
+	t412 = t155 * t411;
+	t413 = t285 * t19;
+	t414 = t56 * t413;
+	t417 = ZA * t30;
+	t424 = t93 * t37;
+	t426 = t248 * t54;
+	t427 = t17 * t12;
+	t428 = t118 * t427;
+	t431 = t77 * t21;
+	t438 = ZA * t13;
+	t443 = t93 * t172;
+	t444 = t27 * t427;
+	t448 = t1 * t78 * t12;
+	t455 = t274 * t89;
+	t461 = t118 * t111;
+	t464 = -t36 * t402 + t36 * t404 - t249 * t406 - 0.4e1 * t408 * t134 + 0.16e2 * t412 * t414 - 0.4e1 * t383 * t27 * t417 * t18 + 0.2e1 * t28 * t22 - t424 * t80 - 0.2e1 * t426 * t428 + 0.4e1 * t278 * t431 + 0.4e1 * t254 * t255 * t103 + t290 * t323 + 0.4e1 * t383 * t27 * t438 * t20 + 0.2e1 * t443 * t444 + t424 * t448 - t36 * t194 - 0.32e2 * t235 * t236 * t243 * t18 + 0.8e1 * t455 * t181 - 0.4e1 * t359 * t96 * t128 - 0.2e1 * t426 * t461;
+	t469 = n * t16 * t13;
+	t474 = t1 * t38;
+	t475 = t474 * t19;
+	t480 = t89 * t103;
+	t483 = t67 * ZA;
+	t484 = t483 * t411;
+	t485 = t127 * t120;
+	t488 = t127 * t111;
+	t497 = t77 * t427;
+	t502 = t27 * t97;
+	t508 = t1 * t19 * t12;
+	t511 = t155 * t25 * t156;
+	t512 = t157 * t37;
+	t513 = t512 * t128;
+	t527 = t1 * t17;
+	t528 = t527 * t38;
+	t530 = -t76 * t497 - 0.4e1 * t254 * t255 * t97 - 0.2e1 * t102 * t502 - 0.4e1 * t108 * t269 - t76 * t508 + 0.8e1 * t511 * t513 + 0.4e1 * t150 * t63 * t18 + 0.4e1 * t383 * t27 * t438 * t18 + 0.4e1 * t132 * t379 + 0.2e1 * t168 * t488 - t76 * t528;
+	t535 = t44 * t13;
+	t542 = t527 * t12;
+	t544 = n * t13;
+	t545 = t544 * t20;
+	t548 = t75 * t303;
+	t549 = t96 * t111;
+	t552 = ZA * t35;
+	t553 = t552 * t37;
+	t562 = t43 * t96;
+	t563 = t3 * t37;
+	t564 = t563 * t128;
+	t579 = t474 * t110;
+	t590 = t9 * t30;
+	t591 = t590 * t18;
+	t595 = t127 * t427;
+	t598 = t77 * t174;
+	t600 = 0.4e1 * t5 * t146 + 0.16e2 * t235 * t236 * t535 * t18 + 0.8e1 * t455 * t146 + t76 * t542 - 0.2e1 * t150 * t545 + 0.2e1 * t548 * t549 - 0.2e1 * t553 * t120 + t290 * t488 - 0.8e1 * t274 * t47 * t44 * t29 * t10 - 0.4e1 * t562 * t564 - 0.2e1 * t132 * xc * t20 * t10 - 0.32e2 * t562 * ZA * t87 * ZB * t13 * t29 - 0.8e1 * t347 * t379 + t76 * t579 - 0.4e1 * t359 * t96 * t57 + 0.4e1 * t408 * t181 - 0.4e1 * t223 * t564 - 0.12e2 * t209 * t27 * ZB * t8 * t591 + 0.2e1 * t310 * t595 + t76 * t598;
+	t601 = t27 * t49;
+	t604 = t127 * t79;
+	t606 = ZB * t29;
+	t616 = t139 * t140 * t18;
+	t638 = t10 * t256;
+	t643 = t118 * t199;
+	t653 = t544 * t29;
+	t658 = t3 * t29;
+	t660 = t350 * t27;
+	t663 = -0.4e1 * t254 * t255 * t145 + 0.2e1 * t267 * t20 * t8 * t9 - 0.4e1 * t138 * t139 * t9 * t16 * t13 - 0.2e1 * t5 * t638 + 0.2e1 * t126 * t169 + 0.8e1 * t376 * t643 + 0.4e1 * t335 * t27 * t145 + 0.16e2 * t235 * t236 * t535 * t29 + 0.6e1 * t150 * t653 - 0.4e1 * t426 * t269 + 0.4e1 * t658 * t8 * t660;
+	t670 = t274 * t411;
+	t673 = t118 * t49;
+	t694 = t155 * t45;
+	t713 = n * t29 * t30;
+	t717 = t20 * t87;
+	t723 = t512 * t57;
+	t728 = -0.2e1 * t443 * t175 - 0.8e1 * t670 * t129 + 0.2e1 * t426 * t673 - 0.16e2 * t207 * t88 * t42 * t47 * ZA * t44 + 0.4e1 * t254 * t255 * t21 + t249 * t595 + 0.8e1 * t25 * t29 * t8 * t660 + 0.2e1 * t268 * t461 + 0.8e1 * t189 * t181 - 0.8e1 * t694 * t513 + 0.2e1 * t198 * t553 - 0.12e2 * t606 * t139 * t660 - 0.2e1 * t359 * t549 + 0.4e1 * t138 * t139 * t590 * t16 + 0.8e1 * t93 * t29 * t94 * t89 - 0.2e1 * t150 * t713 + 0.2e1 * t222 * t3 * t717 * t27 + 0.8e1 * t670 * t323 + 0.8e1 * t694 * t723 - 0.2e1 * t62 * t653;
+	t734 = t43 * t89;
+	t735 = t563 * t427;
+	t740 = t75 * t94;
+	t744 = ZB * xc;
+	t750 = t563 * t57;
+	t754 = t218 * t103;
+	t771 = t127 * t199;
+	t776 = t89 * t174;
+	t791 = -0.4e1 * t207 * t717 * t77 * xc * ZA + 0.4e1 * t443 * t27 * t57 + t192 * t40 - 0.8e1 * t55 * t643 - 0.16e2 * t209 * t89 * t771 - 0.8e1 * t275 * t323 + 0.2e1 * t359 * t776 + 0.16e2 * t304 * t89 * t199 + 0.4e1 * t278 * t320 + 0.2e1 * t207 * t172 * t389 * t79 - 0.8e1 * t390 * t391 * t97;
+	t794 = t483 * t158;
+	t801 = t2 * 0.3141592654e1;
+	t818 = t215 * t411;
+	t827 = t96 * t174;
+	t837 = t37 * t12 * t110;
+	t845 = 0.16e2 * t794 * t485 + 0.8e1 * t159 * t564 - 0.8e1 * t455 * t379 - 0.2e1 * t801 * t3 * t20 * t10 - 0.4e1 * t132 * t22 - 0.8e1 * t734 * t564 - 0.8e1 * t187 * t44 * t658 * t10 - 0.8e1 * t412 * t564 + 0.4e1 * t132 * t181 - 0.8e1 * t818 * t129 + 0.2e1 * t46 * t48 * t427 - 0.4e1 * t75 * t29 * t316 - 0.2e1 * t359 * t827 - t290 * t595 + 0.16e2 * t217 * t754 - t424 * t542 - 0.8e1 * t734 * t750 - t192 * t837 - 0.4e1 * t254 * t255 * t133 + 0.8e1 * t304 * t96 * t199;
+	t864 = t544 * t18;
+	t867 = t3 * t18;
+	t884 = t27 * t256;
+	t891 = t187 * t744;
+	t894 = t563 * t49;
+	t900 = -0.2e1 * t263 * t428 + 0.2e1 * t228 * t428 - 0.6e1 * t223 * t224 * t103 - t192 * t404 + 0.2e1 * t268 * t428 - 0.2e1 * t335 * t884 - t424 * t296 + 0.2e1 * t93 * t20 * t316 - 0.32e2 * t891 * t616 + 0.2e1 * t562 * t894 - 0.2e1 * t801 * t867 * t10;
+	t904 = t27 * t111;
+	t907 = t118 * t128;
+	t915 = t89 * t145;
+	t947 = t139 * t140 * t29;
+	t952 = -0.2e1 * t173 * t904 + 0.4e1 * t426 * t907 + 0.12e2 * t253 * t10 * t1 * 0.3141592654e1 * t244 + 0.8e1 * t95 * t915 - t36 * t355 - 0.16e2 * t794 * t771 - 0.8e1 * t511 * t723 + 0.16e2 * t734 * t162 + t36 * t837 + 0.2e1 * t298 * t299 * t57 - 0.2e1 * t28 * t638 - 0.2e1 * t62 * t545 + 0.2e1 * t310 * t406 + 0.12e2 * t138 * t616 + 0.4e1 * t223 * t750 + t424 * t497 + 0.2e1 * t734 * t894 + 0.2e1 * t132 * xc * t18 * t10 - 0.16e2 * t70 * t947 + 0.32e2 * t891 * t947;
+	t969 = t67 * t157 * t156 * t3;
+	t974 = t27 * t133;
+	t1001 = -0.8e1 * t159 * t750 - 0.16e2 * t412 * t162 - t290 * t129 + 0.8e1 * t310 * t323 - 0.4e1 * t319 * t342 + t75 * t272 + t192 * t402 - 0.8e1 * t359 * t89 * t128 - 0.10e2 * t61 * t350 * t502 + 0.8e1 * t818 * t323 - 0.4e1 * t108 * t907;
+	t1042 = t89 * t97;
+	t1055 = -0.2e1 * t168 * t595 + 0.16e2 * t484 * t771 + 0.4e1 * t11 * t125 * t129 - 0.2e1 * t173 * t444 + 0.2e1 * ZB * n * t54 * t37 * ZA * t79 - t424 * t475 + 0.2e1 * t562 * t735 - 0.2e1 * t548 * t776 + t424 * t204 + 0.2e1 * t25 * t20 * t326 + 0.8e1 * t383 * t389 * t133 + t75 * t38 * t367 + 0.2e1 * t62 * t469 + 0.2e1 * t197 * t137 * t128 - 0.2e1 * t102 * t884 - 0.2e1 * t5 * t379 - 0.8e1 * t740 * t1042 - 0.16e2 * t159 * t414 - 0.2e1 * ZB * t35 * t37 * t413 + 0.2e1 * t553 * ZB * t78 * t12;
+	t1096 = 0.2e1 * t443 * t904 - 0.2e1 * t268 * t329 - 0.2e1 * t443 * t601 + 0.2e1 * t102 * t974 - 0.2e1 * t263 * t673 + t424 * t165 + 0.2e1 * t62 * t713 + t424 * t308 - t424 * t313 + 0.8e1 * t347 * t22 - t424 * t598;
+	t1103 = t42 * t1 * t157;
+	t1104 = t1103 * t25;
+	t1108 = t3 * t19;
+	t1112 = n * t47;
+	t1113 = t9 * t9;
+	t1118 = t42 * t157;
+	t1119 = t1118 * t9;
+	t1120 = t25 * xc;
+	t1121 = t13 * t110;
+	t1122 = t1120 * t1121;
+	t1125 = t47 * t47;
+	t1126 = t67 * t1125;
+	t1127 = t1113 * ZA;
+	t1128 = t1126 * t1127;
+	t1129 = t19 * t13;
+	t1130 = t744 * t1129;
+	t1133 = t154 * t1125;
+	t1134 = t1133 * t9;
+	t1135 = t45 * t1129;
+	t1138 = t154 * t47;
+	t1139 = t25 * t30;
+	t1142 = t1126 * t1113;
+	t1145 = t125 * t1129;
+	t1148 = t1103 * xc;
+	t1149 = t3 * t13;
+	t1150 = t1149 * t17;
+	t1153 = t25 * t78;
+	t1156 = -0.8e1 * t1104 * t243 * t17 + 0.4e1 * t187 * t1108 * t9 - 0.2e1 * t1112 * t3 * t1113 * t30 + 0.16e2 * t1119 * t1122 + 0.64e2 * t1128 * t1130 + 0.64e2 * t1134 * t1135 - 0.2e1 * t1138 * t1139 + 0.32e2 * t1142 * t1135 - 0.32e2 * t1142 * t1145 + 0.8e1 * t1148 * t1150 - 0.2e1 * t1138 * t1153;
+	t1157 = t25 * t13;
+	t1158 = t1157 * t17;
+	t1161 = t13 * t17;
+	t1162 = t1120 * t1161;
+	t1165 = t3 * t78;
+	t1170 = t42 * t67 * t1125;
+	t1172 = t1108 * t13;
+	t1175 = t1 * t157;
+	t1176 = t1175 * t1113;
+	t1182 = t1120 * t1129;
+	t1189 = t110 * t9 * xc;
+	t1192 = t1149 * t110;
+	t1201 = 0.8e1 * t1103 * t1158 - 0.16e2 * t1119 * t1162 - 0.2e1 * t1112 * t1165 * t1113 + 0.32e2 * t1170 * t44 * t1172 - 0.8e1 * t1176 * t1162 + 0.8e1 * t1104 * t243 * t110 - 0.64e2 * t1134 * t1182 - 0.64e2 * t1134 * t1145 + 0.16e2 * t1118 * t3 * t1189 + 0.16e2 * t1119 * t1192 - 0.4e1 * t187 * t1165 * t9 - 0.4e1 * t187 * t1139 * t9;
+	t1209 = t17 * t30;
+	t1210 = t125 * t1209;
+	t1213 = t1138 * ZA;
+	t1214 = ZB * t30;
+	t1218 = t1157 * t110;
+	t1226 = t3 * t30;
+	t1237 = t1170 * t25;
+	t1242 = 0.4e1 * t1112 * ZA * t119 * t1113 - 0.16e2 * t1119 * t1150 - 0.8e1 * t1176 * t1210 + 0.4e1 * t1213 * t1214 * t19 - 0.16e2 * t1119 * t1218 - 0.32e2 * t1142 * t1182 - 0.8e1 * t1103 * t1120 * t110 - 0.4e1 * t187 * t1226 * t9 + 0.8e1 * t1103 * t1192 + 0.4e1 * t1112 * ZB * t1113 * t30 * ZA - 0.32e2 * t1237 * xc * t19 * t13;
+	t1251 = t125 * t1121;
+	t1260 = t1120 * t1209;
+	t1263 = t1139 * t19;
+	t1282 = 0.8e1 * t1103 * t110 * t3 * xc + 0.8e1 * t1104 * xc * t17 * t30 - 0.8e1 * t1176 * t1251 + 0.16e2 * t1119 * t1158 + 0.4e1 * t1112 * t78 * t1127 * ZB + 0.16e2 * t1119 * t1260 + 0.2e1 * t1138 * t1263 - 0.32e2 * t1170 * xc * t1172 - 0.16e2 * t1213 * t119 * t13 + 0.4e1 * t1138 * t1214 * ZA + 0.32e2 * t1237 * t44 * t19 * t13 - 0.16e2 * t1118 * t25 * t1189;
+	t1287 = t188 * t1129;
+	t1292 = t25 * t19;
+	t1296 = t187 * t9;
+	t1297 = t1226 * t19;
+	t1311 = t1112 * t1113;
+	t1317 = -0.8e1 * t1176 * t1150 + 0.32e2 * t1142 * t1287 - 0.8e1 * t1103 * t1150 + 0.2e1 * t1112 * t1292 * t1113 + 0.4e1 * t1296 * t1297 + 0.8e1 * t1176 * t1192 + 0.4e1 * t1296 * t1263 + 0.8e1 * t1176 * t1158 - 0.8e1 * t1175 * t25 * t1113 * xc * t110 + 0.2e1 * t1311 * t1297 + 0.2e1 * t1112 * t1108 * t1113;
+	t1320 = t253 * t1129;
+	t1328 = t253 * t30 * t19;
+	t1333 = t125 * t1161;
+	t1343 = ZB * t44 * t1129;
+	t1350 = -0.8e1 * t1176 * t1218 - 0.16e2 * t1311 * t1320 + 0.8e1 * t1176 * t1260 - 0.16e2 * t1119 * t1210 + 0.4e1 * t1311 * t1328 + 0.2e1 * t1311 * t1263 + 0.8e1 * t1176 * t1333 + 0.8e1 * t187 * ZB * t417 * t9 - 0.2e1 * t1138 * t1165 - 0.64e2 * t1128 * t1343 + 0.64e2 * t1134 * t1287 + 0.2e1 * t1138 * t1108;
+	t1369 = t1133 * t9 * ZA;
+	t1378 = t187 * ZA;
+	t1383 = t1170 * ZA;
+	t1388 = 0.2e1 * t1138 * t1297 - 0.8e1 * t1148 * t1192 + 0.2e1 * t1138 * t1292 - 0.16e2 * t1119 * t1251 + 0.8e1 * t1175 * xc * t110 * t1113 * t3 - 0.2e1 * t1112 * t1153 * t1113 + 0.128e3 * t1369 * t1130 + 0.16e2 * t1119 * t1333 + 0.4e1 * t1138 * t78 * ZA * ZB + 0.8e1 * t1378 * t78 * t9 * ZB - 0.64e2 * t1383 * t1343 + 0.64e2 * t1383 * t1130;
+	t1420 = 0.4e1 * t1138 * t119 * ZA - 0.128e3 * t1369 * t1343 - 0.4e1 * t187 * t1153 * t9 - 0.2e1 * t1138 * t1226 + 0.8e1 * t1296 * t1328 - 0.2e1 * t1112 * t1139 * t1113 - 0.8e1 * t1148 * t3 * t17 * t30 - 0.32e2 * t1296 * t1320 + 0.8e1 * t1176 * t1122 + 0.4e1 * t187 * t1292 * t9 + 0.8e1 * t1378 * t119 * t9 - 0.8e1 * t1103 * t1218;
+	
+	_C4B = (-t424 * t508 + 0.8e1 * t412 * t750 - 0.2e1 * t232 * t595 - 0.4e1 * t126 * t323 + t1096 - t76 * t204 + t728 + 0.2e1 * t548 * t827 + 0.2e1 * t150 * t469 + t398 + 0.8e1 * t189 * t146 + t260 - 0.2e1 * t351 * t184 - 0.2e1 * t268 * t673 - 0.4e1 * t319 * t279 + t464 - 0.2e1 * t108 * t461 + 0.16e2 * t740 * t369 + 0.16e2 * t274 * t216 * t754 - 0.16e2 * t70 * t139 * t591 + 0.2e1 * t55 * t56 * t128 - 0.2e1 * t359 * t89 * t111 + 0.2e1 * t734 * t563 * t111 + 0.6e1 * t223 * t224 * t97 + 0.8e1 * t383 * t389 * t103 + 0.4e1 * t606 * ZA * t326 - 0.2e1 * t93 * t18 * t316 - 0.4e1 * t443 * t27 * t128 + 0.8e1 * t197 * t27 * t199 + 0.8e1 * t108 * t109 * t128 - t249 * t604 + 0.16e2 * t70 * t616 - 0.8e1 * t969 * t323 + t845 - t424 * t579 + 0.16e2 * t159 * t162 + t290 * t406 - 0.6e1 * t150 * t864 + t192 * t116 + 0.2e1 * t867 * t326 - 0.4e1 * t658 * t326 - 0.2e1 * t351 * t502 - t76 * t165 + t900 + 0.8e1 * t168 * t323 + t791 + 0.8e1 * t740 * t915 - 0.4e1 * t562 * t750 - 0.4e1 * t278 * t342 + 0.4e1 * t319 * t431 + 0.2e1 * t173 * t175 + t424 * t528 + 0.8e1 * t969 * t129 - 0.8e1 * t347 * t181 + t332 + t530 - 0.2e1 * t108 * t329 - 0.2e1 * t207 * t38 * t37 * t1 * ZA + t1001 + 0.4e1 * t408 * t379 + t76 * t448 + 0.2e1 * t102 * t184 + 0.2e1 * t426 * t329 + 0.16e2 * t740 * t98 - t282 * t127 - 0.16e2 * t1 * t44 * t69 * t552 * t116 + 0.2e1 * t168 * t169 + 0.2e1 * t28 * t134 - t290 * t604 - 0.16e2 * t484 * t485 - 0.8e1 * t740 * t480 + 0.2e1 * t173 * t601 - 0.2e1 * t335 * t336 + t600 + 0.2e1 * t62 * t864 + t952 + 0.8e1 * t347 * t134 - t192 * t355 + t192 * t194 + 0.2e1 * t228 * t461 + t663 + 0.4e1 * t383 * t27 * t417 * t16 + 0.4e1 * t138 * t20 * ZA * t10 - 0.4e1 * t20 * ZB * ZA * t326 + 0.4e1 * t196 * t88 * t77 * t744 - 0.16e2 * t67 * xc * t179 * t181 - 0.8e1 * t95 * t480 - t249 * t488 - t76 * t475 + t1055 - 0.4e1 * t408 * t22 - 0.10e2 * t28 * t379 + 0.2e1 * t335 * t974 + t153 - 0.8e1 * t95 * t1042 - 0.2e1 * t734 * t735) / (t1156 + t1201 + t1242 + t1282 + t1317 + t1350 + t1388 + t1420);
+	/****************************************************************************************/
+	/****************************************************************************************/
+	
+	if(x>xc) {
+		_C1=_C1B; _C2=_C2B; _C3=_C3B; _C4=_C4B; Z=ZB;
+	}
+	else {
+		_C1=_C1A; _C2=_C2A; _C3=_C3A; _C4=_C4A; Z=ZA;
+	}
+	/****************************************************************************************/
+	/****************************************************************************************/
+	t1 = n * n;
+	t2 = t1 * t1;
+	t3 = t2 * n;
+	t4 = x * t3;
+	t5 = 0.3141592654e1 * 0.3141592654e1;
+	t6 = t5 * 0.3141592654e1;
+	t11 = _C3 * t6;
+	t12 = x * n;
+	t13 = nx * nx;
+	t14 = t13 * t13;
+	t15 = t12 * t14;
+	t19 = exp(t12 * 0.3141592654e1);
+	t20 = t19 * t19;
+	t21 = t4 * t20;
+	t24 = _C1 * t5;
+	t25 = Z * t20;
+	t29 = _C1 * t6;
+	t30 = t29 * Z;
+	t31 = t1 * n;
+	t32 = x * t31;
+	t33 = t32 * t13;
+	t36 = t11 * x;
+	t41 = n * t20;
+	t45 = t6 * _C4;
+	t49 = t20 * t1;
+	t51 = _C2 * Z;
+	t55 = -0.2e1 * t4 * t6 * _C2 * Z - 0.2e1 * t11 * t15 - 0.2e1 * t11 * t21 + 0.2e1 * t24 * t25 * t14 - t13 + 0.4e1 * t30 * t33 - 0.4e1 * t36 * t31 * t20 * t13 - 0.2e1 * t36 * t41 * t14 - 0.2e1 * t4 * t45 * t20 - t49 - 0.2e1 * t4 * t6 * t51 * t20;
+	t58 = t32 * t6;
+	t59 = _C4 * t20;
+	t63 = t20 * t13;
+	t67 = t12 * t6;
+	t68 = t20 * t14;
+	t87 = t49 * t13;
+	t90 = -0.4e1 * t11 * t33 - 0.4e1 * t58 * t59 * t13 - 0.4e1 * t58 * t51 * t63 - 0.2e1 * t67 * t51 * t68 + 0.4e1 * t32 * t45 * t13 - 0.2e1 * t67 * t59 * t14 - 0.2e1 * t30 * t21 + t1 + 0.2e1 * t24 * t25 * t2 + 0.2e1 * t12 * t45 * t14 + 0.4e1 * t24 * Z * t87;
+	t106 = _C3 * t5;
+	t120 = -0.4e1 * t30 * t32 * t63 + t63 + 0.4e1 * t24 * Z * t1 * t13 + 0.2e1 * t29 * Z * x * t3 - 0.4e1 * t58 * t51 * t13 - 0.2e1 * t106 * t2 + t32 * 0.3141592654e1 - 0.2e1 * t106 * t14 - 0.2e1 * t30 * t12 * t68 - 0.2e1 * t67 * t51 * t14 + 0.4e1 * t106 * t87;
+	t129 = sin(nx * 0.3141592654e1 * x);
+	t155 = 0.2e1 * t30 * t15 + x * 0.3141592654e1 * t41 * t13 - 0.4e1 * t19 * nx * t129 * n + t32 * 0.3141592654e1 * t20 + 0.2e1 * t106 * t68 + 0.2e1 * t106 * t20 * t2 - 0.4e1 * t106 * t1 * t13 - 0.2e1 * t11 * t4 + 0.2e1 * t4 * t45 + 0.2e1 * t24 * Z * t2 + 0.2e1 * t24 * Z * t14 + t12 * 0.3141592654e1 * t13;
+	t158 = t5 * Z;
+	
+	u1 = (t55 + t90 + t120 + t155) / (0.4e1 * t158 * t19 * t2 + 0.8e1 * t158 * t19 * t1 * t13 + 0.4e1 * t158 * t19 * t14);
+	/****************************************************************************************/
+	/****************************************************************************************/
+	t1 = n * n;
+	t2 = t1 * n;
+	t3 = x * t2;
+	t4 = 0.3141592654e1 * 0.3141592654e1;
+	t5 = t4 * 0.3141592654e1;
+	t6 = t3 * t5;
+	t7 = _C2 * Z;
+	t8 = nx * nx;
+	t12 = t1 * t1;
+	t13 = t12 * n;
+	t14 = x * t13;
+	t15 = t5 * _C4;
+	t16 = x * n;
+	t18 = exp(t16 * 0.3141592654e1);
+	t19 = t18 * t18;
+	t23 = t16 * t5;
+	t24 = t8 * t8;
+	t28 = _C3 * t5;
+	t29 = t14 * t19;
+	t32 = _C1 * t5;
+	t33 = t32 * Z;
+	t34 = t16 * t24;
+	t37 = _C4 * t19;
+	t45 = _C2 * t4;
+	t53 = t19 * t8;
+	t58 = _C4 * t4;
+	t60 = t1 * t19 * t8;
+	t63 = t19 * t24;
+	t67 = t3 * t8;
+	t73 = n * t19;
+	t86 = t28 * x;
+	t91 = 0.4e1 * t58 * t60 + 0.2e1 * t33 * t16 * t63 + 0.4e1 * t33 * t67 + 0.2e1 * t33 * t29 - x * 0.3141592654e1 * t73 * t8 - 0.2e1 * t53 + 0.2e1 * t32 * Z * x * t13 - 0.2e1 * t58 * t12 - 0.2e1 * t58 * t24 + t3 * 0.3141592654e1 + 0.4e1 * t86 * t2 * t19 * t8;
+	t94 = Z * t12;
+	t121 = -0.2e1 * t8 + 0.2e1 * t45 * t94 * t19 + 0.2e1 * t14 * t5 * t7 * t19 + 0.4e1 * t6 * t7 * t53 + 0.2e1 * t23 * t7 * t63 - 0.4e1 * t28 * t67 + 0.2e1 * t45 * t94 + 0.2e1 * t58 * t12 * t19 + t16 * 0.3141592654e1 * t8 + 0.2e1 * t14 * t15 - 0.2e1 * t28 * t14;
+	t146 = cos(nx * 0.3141592654e1 * x);
+	t156 = -t3 * 0.3141592654e1 * t19 + 0.2e1 * t58 * t63 - 0.4e1 * t58 * t1 * t8 + 0.4e1 * t45 * Z * t1 * t8 - 0.2e1 * t28 * t34 + 0.2e1 * t86 * t73 * t24 + 0.4e1 * t3 * t15 * t8 + 0.4e1 * t45 * Z * t60 + 0.4e1 * t18 * t146 * t8 + 0.2e1 * t45 * Z * t24 + 0.2e1 * t16 * t15 * t24;
+	t159 = t4 * Z;
+	
+	u2 = (-0.4e1 * t6 * t7 * t8 + 0.2e1 * t14 * t15 * t19 - 0.2e1 * t23 * t7 * t24 + 0.2e1 * t28 * t29 + 0.2e1 * t33 * t34 + 0.4e1 * t6 * t37 * t8 - 0.2e1 * t14 * t5 * _C2 * Z + 0.2e1 * t45 * Z * t19 * t24 + 0.2e1 * t23 * t37 * t24 + 0.4e1 * t33 * t3 * t53 + t91 + t121 + t156) / (0.4e1 * t159 * t18 * t12 + 0.8e1 * t159 * t18 * t1 * t8 + 0.4e1 * t159 * t18 * t24);
+	/****************************************************************************************/
+	/****************************************************************************************/
+	t1 = 0.3141592654e1 * 0.3141592654e1;
+	t2 = t1 * 0.3141592654e1;
+	t3 = _C1 * t2;
+	t4 = t3 * Z;
+	t5 = n * n;
+	t6 = t5 * t5;
+	t7 = t6 * n;
+	t8 = x * t7;
+	t9 = x * n;
+	t11 = exp(t9 * 0.3141592654e1);
+	t12 = t11 * t11;
+	t13 = t8 * t12;
+	t16 = t5 * n;
+	t17 = x * t16;
+	t18 = t17 * t2;
+	t19 = _C4 * t12;
+	t20 = nx * nx;
+	t24 = t2 * _C4;
+	t28 = _C3 * t2;
+	t29 = t28 * x;
+	t30 = t12 * n;
+	t31 = t20 * t20;
+	t40 = _C2 * Z;
+	t44 = t9 * t2;
+	t48 = t12 * t20;
+	t52 = t17 * t20;
+	t57 = -0.2e1 * t4 * t13 - 0.4e1 * t18 * t19 * t20 - 0.2e1 * t8 * t24 * t12 - 0.2e1 * t29 * t30 * t31 + 0.2e1 * t8 * t2 * _C2 * Z - 0.2e1 * t8 * t2 * t40 * t12 - 0.2e1 * t44 * t19 * t31 - 0.4e1 * t18 * t40 * t48 + t20 + 0.4e1 * t28 * t52 + t17 * 0.3141592654e1 * t12;
+	t58 = t9 * t31;
+	t61 = _C3 * t1;
+	t62 = t12 * t31;
+	t73 = t5 * t20;
+	t78 = _C1 * t1;
+	t90 = Z * t12;
+	t94 = 0.2e1 * t28 * t58 + 0.2e1 * t61 * t62 + 0.2e1 * t61 * t12 * t6 - 0.4e1 * t4 * t17 * t48 + 0.2e1 * t28 * t8 + 0.4e1 * t61 * t73 - 0.2e1 * t8 * t24 - 0.2e1 * t78 * Z * t6 - 0.2e1 * t44 * t40 * t62 - 0.2e1 * t78 * Z * t31 - t9 * 0.3141592654e1 * t20 + 0.2e1 * t78 * t90 * t6;
+	t101 = cos(nx * 0.3141592654e1 * x);
+	t102 = t11 * t101;
+	t109 = t12 * t5;
+	t110 = t109 * t20;
+	t128 = 0.2e1 * t61 * t6 - t17 * 0.3141592654e1 + 0.2e1 * t102 * t5 - 0.4e1 * t17 * t24 * t20 + 0.4e1 * t78 * Z * t110 - 0.2e1 * t9 * t24 * t31 - 0.4e1 * t4 * t52 - 0.2e1 * t4 * t9 * t62 + x * 0.3141592654e1 * t30 * t20 - t5 - 0.4e1 * t78 * Z * t5 * t20;
+	t156 = 0.2e1 * t78 * t90 * t31 - 0.2e1 * t3 * Z * x * t7 + t48 + 0.4e1 * t61 * t110 + 0.4e1 * t18 * t40 * t20 - 0.2e1 * t102 * t20 + 0.2e1 * t61 * t31 + 0.2e1 * t44 * t40 * t31 - t109 - 0.2e1 * t4 * t58 - 0.2e1 * t28 * t13 - 0.4e1 * t29 * t16 * t12 * t20;
+	t159 = t1 * t11;
+	
+	u3 = (t57 + t94 + t128 + t156) / (0.4e1 * t159 * t6 + 0.8e1 * t159 * t73 + 0.4e1 * t159 * t31);
+	/****************************************************************************************/
+	/****************************************************************************************/
+	t1 = _C2 * Z;
+	t2 = 0.3141592654e1 * 0.3141592654e1;
+	t3 = t2 * 0.3141592654e1;
+	t4 = n * n;
+	t5 = t4 * t4;
+	t6 = t5 * t4;
+	t8 = t3 * t6 * x;
+	t11 = x * t4;
+	t12 = t11 * t3;
+	t15 = exp(x * n * 0.3141592654e1);
+	t16 = t15 * t15;
+	t17 = _C3 * t16;
+	t18 = nx * nx;
+	t19 = t18 * t18;
+	t23 = t5 * n;
+	t24 = t2 * t23;
+	t28 = t1 * t3;
+	t29 = t6 * x;
+	t30 = t29 * t16;
+	t33 = _C4 * t3;
+	t34 = t5 * x;
+	t35 = t34 * t18;
+	t41 = sin(nx * 0.3141592654e1 * x);
+	t47 = t11 * t19;
+	t54 = t3 * _C3;
+	t57 = 0.2e1 * t1 * t8 + 0.2e1 * t12 * t17 * t19 + 0.2e1 * t1 * t24 * t16 + 0.2e1 * t28 * t30 - 0.4e1 * t33 * t35 + 0.2e1 * t15 * nx * t41 * t4 + 0.4e1 * t28 * t35 - 0.2e1 * t33 * t47 - 0.2e1 * t1 * t24 - 0.2e1 * t33 * t29 + 0.2e1 * t29 * t54;
+	t58 = 0.3141592654e1 * t16;
+	t60 = t2 * _C4;
+	t69 = t4 * n;
+	t73 = t1 * t2;
+	t75 = t69 * t16 * t18;
+	t79 = x * t16;
+	t83 = n * t16;
+	t84 = t83 * t19;
+	t95 = -t34 * t58 + 0.2e1 * t60 * t23 * t16 + 0.2e1 * t60 * n * t19 - t11 * 0.3141592654e1 * t18 + 0.4e1 * t60 * t69 * t18 + 0.4e1 * t73 * t75 + 0.4e1 * t33 * t5 * t79 * t18 + 0.2e1 * t73 * t84 + 0.2e1 * t60 * t84 + 0.2e1 * t33 * t4 * t79 * t19 + 0.4e1 * t60 * t75;
+	t97 = t34 * t3;
+	t101 = Z * _C1;
+	t102 = t16 * t19;
+	t106 = t16 * t18;
+	t127 = t2 * t69;
+	t131 = t2 * n;
+	t135 = 0.4e1 * t97 * t17 * t18 + 0.2e1 * t12 * t101 * t102 + 0.4e1 * t28 * t34 * t106 + 0.2e1 * t28 * t11 * t102 - 0.2e1 * t29 * t3 * Z * _C1 - 0.4e1 * t97 * t101 * t18 - 0.2e1 * t12 * t101 * t19 + 0.2e1 * t60 * t23 - 0.2e1 * t83 * t18 - 0.4e1 * t1 * t127 * t18 - 0.2e1 * t1 * t131 * t19;
+	t164 = 0.2e1 * t28 * t47 + 0.2e1 * t11 * t54 * t19 + 0.2e1 * t8 * t101 * t16 + 0.2e1 * t33 * t30 - t11 * t58 * t18 + 0.2e1 * t29 * t54 * t16 + 0.4e1 * t34 * t54 * t18 + 0.4e1 * t97 * t101 * t106 - 0.2e1 * t15 * t18 * nx * t41 - t34 * 0.3141592654e1 + 0.2e1 * n * t18;
+	
+	u4 = (t57 + t95 + t135 + t164) / (0.4e1 * t24 * t15 + 0.8e1 * t127 * t15 * t18 + 0.4e1 * t131 * t15 * t19);
+	
+	
+	/****************************************************************************************/
+	/****************************************************************************************/
+	
+	
+	u5 = (double)(-2*Z*n*PI*u2-u3*2*n*PI)*cos(n*PI*z); /* pressure */
+	
+	u6 = (double)(u3*2*n*PI + 4*Z*n*PI*u2)*cos(n*PI*z); /* zz stress */	    
+	sum5 +=u5;
+	sum6 +=u6;
+	
+	u1 *= cos(n*PI*z); /* x velocity */
+	sum1 += u1;
+	u2 *= sin(n*PI*z); /* z velocity */
+	sum2 += u2;
+	u3 *= 2*n*PI*cos(n*PI*z); /* xx stress */
+	sum3 += u3;
+	u4 *= 2*n*PI*sin(n*PI*z); /* zx stress */
+	sum4 += u4;
+	
+	
+	mag=sqrt(sum1*sum1+sum2*sum2);
+	/*printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag);*/
+	
+	
+	/* Output */
+	if( vel != NULL ) {
+		vel[0] = sum1;
+		vel[1] = sum2;
+	}
+	if( presssure != NULL ) {
+		(*presssure) = sum5;
+	}
+	if( total_stress != NULL ) {
+		total_stress[0] = sum3;
+		total_stress[1] = sum6; 
+		total_stress[2] = sum4;
+	}
+	if( strain_rate != NULL ) {
+		if( x>xc ) {
+			Z = ZB;
+		}
+		else {
+			Z = ZA;
+		}
+		strain_rate[0] = (sum3+sum5)/(2.0*Z);
+		strain_rate[1] = (sum6+sum5)/(2.0*Z);
+		strain_rate[2] = (sum4)/(2.0*Z);
+	}
+	/* Value checks, could be cleaned up if needed. Julian Giordani 2-Oct-2006*/
+	if( fabs( sum5 - ( -0.5*(sum6+sum3) ) ) > 1e-5 ) {
+		assert(0);
+	}
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solDA/Analytic_solDA.c
--- a/SysTest/AnalyticPlugins/Velic_solDA/Analytic_solDA.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,169 +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:
-*+		Mirko Velic
-*+		Julian Giordani
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Patrick Sunter
-** $Id: solDA.c 636 2006-09-08 03:07:06Z JulianGiordani $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include "Analytic_solDA.h"
-
-const Type Velic_solDA_Type = "Underworld_Velic_solDA";
-
-void Velic_solDA_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
-	Velic_solDA* self = (Velic_solDA*) analyticSolution;
-	
-	_Velic_solDA( coord, self->sigma, self->etaA, self->etaB, self->zc, self->dx, self->x0,
-		       	NULL, pressure, NULL, NULL );
-}
-
-void Velic_solDA_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
-	Velic_solDA* self = (Velic_solDA*) analyticSolution;
-	
-	_Velic_solDA( coord, self->sigma, self->etaA, self->etaB, self->zc, self->dx, self->x0,
-		       	velocity, NULL, NULL, NULL );
-}
-
-void Velic_solDA_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
-	Velic_solDA* self = (Velic_solDA*) analyticSolution;
-	
-	_Velic_solDA( coord, self->sigma, self->etaA, self->etaB, self->zc, self->dx, self->x0,
-		       	NULL, NULL, stress, NULL );
-}
-
-
-void Velic_solDA_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
-	Velic_solDA* self = (Velic_solDA*) analyticSolution;
-	
-	_Velic_solDA( coord, self->sigma, self->etaA, self->etaB, self->zc, self->dx, self->x0,
-		       	NULL, NULL, NULL, strainRate );
-}
-
-void _Velic_solDA_Init( Velic_solDA* self, double sigma, double etaA, double etaB, double zc, double dx, double x0 ) {
-	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
-        self->_getAnalyticVelocity    = Velic_solDA_VelocityFunction;
-	self->_getAnalyticPressure    = Velic_solDA_PressureFunction;
-	self->_getAnalyticTotalStress = Velic_solDA_StressFunction;
-	self->_getAnalyticStrainRate  = Velic_solDA_StrainRateFunction;
-	
-	self->sigma = sigma;
-	self->etaA = etaA;
-	self->etaB = etaB;
-	self->zc = zc;
-	self->dx = dx;
-	self->x0 = x0;
-}
-
-void _Velic_solDA_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
-	Velic_solDA* self = (Velic_solDA*) analyticSolution;
-	FeVariable*              velocityField;
-	FeVariable*              pressureField;
-	FeVariable*              stressField;
-	FeVariable*              strainRateField;
-	FeVariable*              recoveredStrainRateField;
-	FeVariable*              recoveredStressField;
-	double                   sigma, etaA, etaB, zc, dx, x0;
-	double                   startX, endX;
-	
-	/* Construct Parent */
-	_AnalyticSolution_AssignFromXML( self, cf, data );
-
-	/* Create Analytic Fields */
-	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solDA_VelocityFunction );
-
-	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solDA_PressureFunction );
-
-	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False, data );
-	if ( stressField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solDA_StressFunction );
-
-	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
-	if ( strainRateField   ) {
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solDA_StrainRateFunction );
-	}
-
-	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
-	if ( recoveredStrainRateField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solDA_StrainRateFunction );
-
-	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
-	if ( recoveredStressField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solDA_StressFunction );
-
-	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solDA_sigma", 3.0  );
-	etaA = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solDA_etaA", 1.0  );
-	etaB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solDA_etaB", 2.0  );
-	zc = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solDA_zc", 0.8  );
-	startX = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solCA_startX", 0.4  );
-	endX   = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solCA_endX", 0.8 );
-
-	dx = endX - startX;
-	x0 = 0.5 * (endX + startX );
-	
-	_Velic_solDA_Init( self, sigma, etaA, etaB, zc, dx, x0 );
-	
-
-}
-
-void* _Velic_solDA_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Velic_solDA);
-	Type                                                      type = Velic_solDA_Type;
-	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
-	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
-	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solDA_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Velic_solDA_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _AnalyticSolution_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 Underworld_Velic_solDA_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Velic_solDA_Type, (Name)"0", _Velic_solDA_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solDA/Analytic_solDA.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solDA/Analytic_solDA.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,169 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Mirko Velic
+*+		Julian Giordani
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Patrick Sunter
+** $Id: solDA.c 636 2006-09-08 03:07:06Z JulianGiordani $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include "Analytic_solDA.h"
+
+const Type Velic_solDA_Type = "Underworld_Velic_solDA";
+
+void Velic_solDA_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
+	Velic_solDA* self = (Velic_solDA*) analyticSolution;
+	
+	_Velic_solDA( coord, self->sigma, self->etaA, self->etaB, self->zc, self->dx, self->x0,
+		       	NULL, pressure, NULL, NULL );
+}
+
+void Velic_solDA_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
+	Velic_solDA* self = (Velic_solDA*) analyticSolution;
+	
+	_Velic_solDA( coord, self->sigma, self->etaA, self->etaB, self->zc, self->dx, self->x0,
+		       	velocity, NULL, NULL, NULL );
+}
+
+void Velic_solDA_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
+	Velic_solDA* self = (Velic_solDA*) analyticSolution;
+	
+	_Velic_solDA( coord, self->sigma, self->etaA, self->etaB, self->zc, self->dx, self->x0,
+		       	NULL, NULL, stress, NULL );
+}
+
+
+void Velic_solDA_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
+	Velic_solDA* self = (Velic_solDA*) analyticSolution;
+	
+	_Velic_solDA( coord, self->sigma, self->etaA, self->etaB, self->zc, self->dx, self->x0,
+		       	NULL, NULL, NULL, strainRate );
+}
+
+void _Velic_solDA_Init( Velic_solDA* self, double sigma, double etaA, double etaB, double zc, double dx, double x0 ) {
+	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
+        self->_getAnalyticVelocity    = Velic_solDA_VelocityFunction;
+	self->_getAnalyticPressure    = Velic_solDA_PressureFunction;
+	self->_getAnalyticTotalStress = Velic_solDA_StressFunction;
+	self->_getAnalyticStrainRate  = Velic_solDA_StrainRateFunction;
+	
+	self->sigma = sigma;
+	self->etaA = etaA;
+	self->etaB = etaB;
+	self->zc = zc;
+	self->dx = dx;
+	self->x0 = x0;
+}
+
+void _Velic_solDA_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
+	Velic_solDA* self = (Velic_solDA*) analyticSolution;
+	FeVariable*              velocityField;
+	FeVariable*              pressureField;
+	FeVariable*              stressField;
+	FeVariable*              strainRateField;
+	FeVariable*              recoveredStrainRateField;
+	FeVariable*              recoveredStressField;
+	double                   sigma, etaA, etaB, zc, dx, x0;
+	double                   startX, endX;
+	
+	/* Construct Parent */
+	_AnalyticSolution_AssignFromXML( self, cf, data );
+
+	/* Create Analytic Fields */
+	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solDA_VelocityFunction );
+
+	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solDA_PressureFunction );
+
+	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False, data );
+	if ( stressField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solDA_StressFunction );
+
+	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
+	if ( strainRateField   ) {
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solDA_StrainRateFunction );
+	}
+
+	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
+	if ( recoveredStrainRateField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solDA_StrainRateFunction );
+
+	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
+	if ( recoveredStressField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solDA_StressFunction );
+
+	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solDA_sigma", 3.0  );
+	etaA = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solDA_etaA", 1.0  );
+	etaB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solDA_etaB", 2.0  );
+	zc = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solDA_zc", 0.8  );
+	startX = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solCA_startX", 0.4  );
+	endX   = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solCA_endX", 0.8 );
+
+	dx = endX - startX;
+	x0 = 0.5 * (endX + startX );
+	
+	_Velic_solDA_Init( self, sigma, etaA, etaB, zc, dx, x0 );
+	
+
+}
+
+void* _Velic_solDA_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Velic_solDA);
+	Type                                                      type = Velic_solDA_Type;
+	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
+	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
+	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solDA_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Velic_solDA_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _AnalyticSolution_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 Underworld_Velic_solDA_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Velic_solDA_Type, (Name)"0", _Velic_solDA_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solDA/solDA.c
--- a/SysTest/AnalyticPlugins/Velic_solDA/solDA.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,974 +0,0 @@
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-
-
-void _Velic_solDA( 
-		double pos[],
-		double _sigma,
-		double _eta_A, double _eta_B, 
-		double _z_c, double _dx, double _x_0,
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] );
-
-
-int main( int argc, char **argv )
-{
-	int i,j;
-	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
-	double x,z;
-	
-	for (i=0;i<101;i++){
-		for(j=0;j<101;j++){
-			x = i/100.0;
-			z = j/100.0;
-			
-			pos[0] = x;
-			pos[1] = z;
-			_Velic_solDA(
-					pos,
-					3.0,
-					1.0, 2.0,
-					0.8, 0.25, 0.45,
-					vel, &pressure, total_stress, strain_rate );
-			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
-					pos[0],pos[1],
-					vel[0],vel[1], pressure, 
-					total_stress[0], total_stress[1], total_stress[2], 
-					strain_rate[0], strain_rate[1], strain_rate[2] );
-		}
-		printf("\n");
-	}
-	
-	return 0;
-}
-
-
-
-
-void _Velic_solDA(		
-		double pos[],
-		double _sigma, /* density */
-		double _eta_A, double _eta_B, /* viscosity A, viscosity B */ 
-		double _z_c, double _dx, double _x_0, /* viscosity jump location, width of dense column, centre of dense column */
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] )
-{
-	double Z,ZA,ZB,u1,u2,u3,u4,pp,txx;
-	double u1a,u2a,u3a,u4a,u1b,u2b,u3b,u4b;
-	double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,x,z;
-	double sigma,dx;
-	double del_rhoA,del_rhoB,del_rho;
-	int n;
-	double kn;
-	double _C1A,_C2A,_C3A,_C4A,_C1B,_C2B,_C3B,_C4B;
-	double x0,rho,zc;
-	
-	double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
-	double t11,t12,t13,t14,t15,t16,t17,t18,t19,t20;
-	double t21,t22,t23,t24,t25,t26,t27,t28,t29,t30;
-	double t31,t32,t33,t34,t35,t36,t37,t38,t39,t40;
-	double t41,t42,t43,t44,t45,t46,t47,t48,t49,t50;
-	double t51,t52,t53,t54,t55,t56,t57,t58,t59,t60;
-	double t61,t62,t63,t64,t66,t67,t68,t69,t70,t71;
-	double t72,t73,t74,t75,t76,t77,t78,t79,t80,t81;
-	double t82,t83,t84,t85,t86,t87,t88,t89,t90,t91;
-	double t93,t94,t95,t96,t97,t98,t99,t100,t101,t102;
-	double t103,t104,t105,t106,t107,t108,t109,t110,t111,t112;
-	double t113,t114,t115,t116,t117,t118,t119,t120,t121,t122;
-	double t123,t124,t125,t126,t128,t129,t130,t131,t132,t133;
-	double t134,t135,t136,t137,t138,t139,t140,t141,t142,t143;
-	double t144,t145,t146,t147,t148,t149,t150,t151,t152,t153;
-	double t154,t155,t156,t157,t158,t159,t160,t161,t162,t163;
-	double t164,t165,t166,t167,t168,t169,t170,t171,t172,t173;
-	double t174,t175,t176,t178,t179,t180,t181,t183,t184,t185;
-	double t186,t187,t188,t189,t191,t193,t196,t197,t200,t202;
-	double t203,t206,t207,t210,t211,t215,t217,t218,t219,t221;
-	double t222,t223,t224,t225,t226,t227,t228,t229,t232,t233;
-	double t238,t239,t243,t244,t246,t248,t250,t251,t267,t273;
-	
-	
-	
-	
-	/*************************************************************************/
-	/*************************************************************************/
-	/*   We have a dense column of density sigma
-	ranging from x=x0-dx/2 to x= x0+dx/2:    */
-	x0 = _x_0;
-	dx = _dx;
-	sigma = _sigma; /* density parameter */
-	ZA = _eta_A;    /* viscosity for layer A */
-	ZB = _eta_B; /* viscosity for layer B */
-	zc = _z_c;
-	/*************************************************************************/
-	/*************************************************************************/
-	
-	x = pos[0];
-	z = pos[1];
-	
-	sum1=0.0;
-	sum2=0.0;
-	sum3=0.0;
-	sum4=0.0;
-	sum5=0.0;
-	sum6=0.0;
-	sum7=0.0;
-	/* convergence is good */
-	for(n=1;n<75;n++){
-		kn = (double) n*M_PI;
-		
-		/*******************************************/
-		/*            calculate del_rho            */
-		/*******************************************/
-		del_rho = 4.0*sigma*cos(n*M_PI*x0)*sin(n*M_PI*dx/2.0)/n/M_PI;
-		del_rhoB = del_rhoA = del_rho;
-		
-		/*******************************************/
-		/*         calculate the constants         */
-		/*******************************************/
-		
-		if (z < zc) {
-			t1 = -ZB + ZA;
-			t2 = ZA * kn;
-			t3 = t2 * zc;
-			t4 = 0.2e1 * ZB;
-			t5 = kn * zc;
-			t7 = 0.2e1 * t5 * ZB;
-			t11 = exp(-0.3e1 * t5);
-			t13 = ZA + ZB;
-			t14 = t1 * t13;
-			t16 = pow(-0.1e1 + t5, 0.2e1);
-			t18 = kn * (-0.2e1 + zc);
-			t20 = exp(0.2e1 * t18);
-			t25 = zc - 0.1e1;
-			t26 = t13 * t25;
-			t27 = kn * t25;
-			t29 = exp(0.2e1 * t27);
-			t30 = t26 * t29;
-			t33 = kn * kn;
-			t34 = t33 * kn;
-			t35 = ZA * ZA;
-			t37 = zc * zc;
-			t38 = t37 * zc;
-			t40 = t34 * t37;
-			t42 = ZB * ZB;
-			t43 = t33 * t42;
-			t44 = t43 * t37;
-			t45 = 0.2e1 * t44;
-			t46 = t33 * t35;
-			t48 = 0.2e1 * t46 * zc;
-			t51 = 0.2e1 * t46 * t37;
-			t52 = ZA * ZB;
-			t53 = t33 * ZA;
-			t55 = t53 * t37 * ZB;
-			t56 = 0.4e1 * t55;
-			t57 = kn * t42;
-			t58 = ZB * zc;
-			t59 = t53 * t58;
-			t60 = 0.4e1 * t59;
-			t61 = t43 * zc;
-			t62 = 0.2e1 * t61;
-			t63 = t34 * ZA;
-			t67 = kn * t35;
-			t73 = t2 * t58;
-			t75 = t57 * zc;
-			t76 = t2 * ZB;
-			t77 = t34 * t35 * t38 - t40 * t35 - t45 + t48 - t40 * t42 - t51 + t52 + t56 - t57 - t60 + t62 - 0.2e1 * t63 * ZB * t38 + t67 * zc + 0.2e1 * t40 * t52 + t34 * t42 * t38 - t67 - 0.2e1 * t73 + t75 + t76;
-			t79 = exp(-0.2e1 * kn);
-			t82 = 0.6e1 * t55;
-			t83 = 0.2e1 * t52;
-			t84 = 0.4e1 * t44;
-			t85 = 0.3e1 * t73;
-			t86 = 0.4e1 * t57;
-			t87 = 0.2e1 * t76;
-			t88 = 0.4e1 * t61;
-			t89 = 0.6e1 * t59;
-			t90 = 0.4e1 * t75;
-			t91 = -t82 - t83 + t84 + t51 + t85 + t86 - t87 - t88 + t89 - t48 - t90;
-			t94 = exp(-kn * (zc + 0.2e1));
-			t99 = exp(-t5);
-			t101 = -t82 + t51 + t90 - t86 + t87 - t85 + t84 + t89 - t88 - t83 - t48;
-			t102 = exp(t18);
-			t110 = exp(kn * (0.3e1 * zc - 0.4e1));
-			t113 = exp(-0.2e1 * t5);
-			t121 = exp(kn * (zc - 0.4e1));
-			t123 = t1 * t1;
-			t125 = exp(0.4e1 * t27);
-			t126 = t123 * t125;
-			t131 = t1 * (-t3 + t4 - t7) * t11 + 0.2e1 * t14 * t16 * t20 + 0.8e1 * kn * t1 * t30 - 0.8e1 * t77 * t79 - 0.2e1 * t91 * t94 + t13 * (t3 - t4 - t7) * t99 + 0.2e1 * t101 * t102 + t1 * (-t3 - t4 - t7) * t110 - 0.2e1 * t14 * t16 * t113 + t13 * (t3 + t4 - t7) * t121 - 0.2e1 * t126 + 0.2e1 * t35 + 0.4e1 * t52 + 0.2e1 * t42;
-			t133 = ZA * del_rhoB;
-			t137 = exp(-0.3e1 * kn);
-			t141 = t33 * zc;
-			t142 = 0.2e1 * t141;
-			t143 = 0.4e1 * t5;
-			t144 = t33 * t37;
-			t145 = 0.2e1 * t144;
-			t148 = 0.2e1 * zc;
-			t151 = exp(-kn * (t148 + 0.1e1));
-			t155 = t133 * t5;
-			t156 = 0.2e1 * t133;
-			t163 = 0.3e1 * t2 * zc * del_rhoB * ZB;
-			t164 = t35 * del_rhoB;
-			t166 = 0.2e1 * t144 * t164;
-			t167 = t133 * ZB;
-			t169 = 0.2e1 * t141 * t167;
-			t172 = 0.2e1 * t133 * kn * ZB;
-			t174 = 0.2e1 * t164 * t5;
-			t176 = 0.2e1 * t144 * t167;
-			t178 = 0.2e1 * t141 * t164;
-			t179 = 0.2e1 * t164;
-			t183 = 0.3e1 * t155;
-			t197 = exp(kn * (t148 - 0.3e1));
-			t203 = exp(-kn);
-			t210 = t131 * del_rhoA - 0.2e1 * t133 * (-0.2e1 + kn) * t13 * t137 + 0.2e1 * t133 * (0.2e1 - t142 - t143 + t145 + kn) * t1 * t151 + t13 * (t155 + t156) * t99 + 0.2e1 * (-t163 + t166 + t169 + t172 + t174 - t176 - t178 + t179) * t102 + t1 * (-t156 + t183) * t11 - 0.2e1 * (-t176 + t163 + t166 - t174 - t172 - t178 + t179 + t169) * t94 + t13 * (-t156 + t155) * t121 - 0.2e1 * t133 * (-t142 + t143 + t145 + 0.2e1 - kn) * t1 * t197 - 0.2e1 * t133 * (0.2e1 + kn) * t13 * t203 + t1 * (t183 + t156) * t110;
-			t211 = t63 * zc;
-			t215 = exp(-t143);
-			t222 = t63 * t1;
-			t225 = t13 * t13;
-			t227 = exp(-0.4e1 * kn);
-			t238 = exp(-0.2e1 * kn * (zc + 0.1e1));
-			t251 = -0.8e1 * t211 * t14 * t20 - 0.2e1 * t53 * t123 * t215 + 0.8e1 * t211 * t14 * t113 + 0.8e1 * t222 * t30 + 0.2e1 * t53 * t225 * t227 + 0.16e2 * t53 * (-t62 + t60 - t48 - t52 + t45 + t51 - t56) * t79 - 0.8e1 * t222 * t26 * t238 - 0.2e1 * t53 * t126 + 0.2e1 * t33 * t35 * ZA + 0.2e1 * t53 * t42 + 0.4e1 * t46 * ZB;
-			_C1A = t210 / t251;
-			
-			t1 = -ZB + ZA;
-			t2 = ZA * kn;
-			t3 = t2 * zc;
-			t4 = 0.2e1 * ZB;
-			t5 = kn * zc;
-			t7 = 0.2e1 * t5 * ZB;
-			t11 = exp(-0.2e1 * t5);
-			t13 = kn * kn;
-			t14 = t13 * ZA;
-			t15 = zc * zc;
-			t17 = t14 * t15 * ZB;
-			t18 = 0.6e1 * t17;
-			t19 = ZA * ZA;
-			t20 = t13 * t19;
-			t22 = 0.2e1 * t20 * t15;
-			t23 = ZB * ZB;
-			t24 = kn * t23;
-			t25 = t24 * zc;
-			t26 = 0.4e1 * t25;
-			t27 = 0.4e1 * t24;
-			t28 = t2 * ZB;
-			t29 = 0.2e1 * t28;
-			t30 = zc * ZB;
-			t31 = t2 * t30;
-			t32 = 0.3e1 * t31;
-			t33 = t13 * t23;
-			t34 = t33 * t15;
-			t35 = 0.4e1 * t34;
-			t36 = t14 * t30;
-			t37 = 0.6e1 * t36;
-			t38 = t33 * zc;
-			t39 = 0.4e1 * t38;
-			t40 = ZA * ZB;
-			t41 = 0.2e1 * t40;
-			t43 = 0.2e1 * t20 * zc;
-			t44 = -t18 + t22 + t26 - t27 + t29 - t32 + t35 + t37 - t39 - t41 - t43;
-			t45 = zc - 0.1e1;
-			t46 = kn * t45;
-			t48 = exp(0.2e1 * t46);
-			t51 = t13 * kn;
-			t53 = t15 * zc;
-			t55 = t51 * t15;
-			t59 = t51 * ZA;
-			t66 = 0.4e1 * t17;
-			t67 = 0.4e1 * t36;
-			t68 = 0.2e1 * t34;
-			t69 = 0.2e1 * t38;
-			t70 = kn * t19;
-			t71 = t70 * zc;
-			t73 = t51 * t19 * t53 - t55 * t19 + 0.2e1 * t55 * t40 - 0.2e1 * t59 * ZB * t53 + t51 * t23 * t53 - t55 * t23 + t22 - t43 - t66 + t67 + t68 - t69 + t71 - t70 + t28 - 0.2e1 * t31 + t25 - t24 - t40;
-			t75 = kn * (-0.2e1 + zc);
-			t76 = exp(t75);
-			t79 = ZA + ZB;
-			t80 = t79 * t79;
-			t83 = exp(kn * (zc - 0.4e1));
-			t87 = t79 * t45;
-			t90 = exp(-kn * (zc + 0.2e1));
-			t97 = exp(0.2e1 * t75);
-			t99 = t1 * t1;
-			t101 = exp(-0.3e1 * t5);
-			t107 = exp(0.4e1 * t46);
-			t110 = -t18 - t41 + t35 + t22 + t32 + t27 - t29 - t39 + t37 - t43 - t26;
-			t112 = exp(-0.2e1 * kn);
-			t116 = t1 * t79;
-			t118 = pow(0.1e1 + t5, 0.2e1);
-			t119 = exp(-t5);
-			t126 = exp(kn * (0.3e1 * zc - 0.4e1));
-			t130 = -t1 * (-t3 + t4 - t7) * t11 - 0.2e1 * t44 * t48 + 0.8e1 * t73 * t76 + 0.2e1 * t80 * t83 - 0.8e1 * kn * t1 * t87 * t90 - t79 * (t3 + t4 - t7) * t97 - 0.2e1 * t99 * t101 - t71 + t31 - t1 * (-t3 - t4 - t7) * t107 + 0.2e1 * t23 + t41 + 0.2e1 * t110 * t112 + 0.2e1 * t25 + 0.2e1 * t116 * t118 * t119 - 0.2e1 * t116 * t118 * t126;
-			t132 = ZA * del_rhoB;
-			t133 = 0.2e1 * t132;
-			t134 = t132 * t5;
-			t138 = t19 * del_rhoB;
-			t139 = 0.2e1 * t138;
-			t140 = t132 * ZB;
-			t142 = t13 * zc;
-			t143 = 0.2e1 * t142;
-			t144 = 0.4e1 * t5;
-			t145 = t13 * t15;
-			t146 = 0.2e1 * t145;
-			t150 = exp(0.3e1 * t46);
-			t154 = 0.3e1 * t134;
-			t161 = kn * (zc + 0.1e1);
-			t162 = exp(-t161);
-			t168 = exp(t46);
-			t175 = t138 * t5;
-			t178 = t2 * zc * del_rhoB * ZB;
-			t179 = 0.3e1 * t178;
-			t181 = 0.2e1 * t145 * t138;
-			t183 = 0.2e1 * t142 * t140;
-			t186 = 0.2e1 * t132 * kn * ZB;
-			t187 = 0.2e1 * t175;
-			t189 = 0.2e1 * t145 * t140;
-			t191 = 0.2e1 * t142 * t138;
-			t202 = exp(kn * (zc - 0.3e1));
-			t206 = t130 * del_rhoA - t79 * (-t133 + t134) * t97 - t139 - 0.2e1 * t140 + 0.2e1 * t132 * (-t143 + t144 + t146 + 0.2e1 - kn) * t1 * t150 - t1 * (t154 + t133) * t107 - 0.2e1 * t132 * (0.2e1 - t143 - t144 + t146 + kn) * t1 * t162 + 0.2e1 * t132 * (0.2e1 + kn) * t79 * t168 - t1 * (-t133 + t154) * t11 - t175 - 0.2e1 * (-t179 + t181 + t183 + t186 + t187 - t189 - t191 + t139) * t48 - t178 + 0.2e1 * (-t189 + t179 + t181 - t187 - t186 - t191 + t139 + t183) * t112 + 0.2e1 * t132 * (-0.2e1 + kn) * t79 * t202;
-			t207 = t59 * zc;
-			t211 = exp(-t144);
-			t218 = t59 * t1;
-			t223 = exp(-0.4e1 * kn);
-			t232 = exp(-0.2e1 * t161);
-			t246 = -0.8e1 * t207 * t116 * t97 - 0.2e1 * t14 * t99 * t211 + 0.8e1 * t207 * t116 * t11 + 0.8e1 * t218 * t87 * t48 + 0.2e1 * t14 * t80 * t223 + 0.16e2 * t14 * (-t69 + t67 - t43 - t40 + t68 + t22 - t66) * t112 - 0.8e1 * t218 * t87 * t232 - 0.2e1 * t14 * t99 * t107 + 0.2e1 * t13 * t19 * ZA + 0.2e1 * t14 * t23 + 0.4e1 * t20 * ZB;
-			_C2A = t206 / t246;
-			
-			t1 = -ZB + ZA;
-			t2 = 0.2e1 * ZB;
-			t4 = t1 * (-ZA - t2);
-			t5 = kn * zc;
-			t7 = exp(-0.3e1 * t5);
-			t10 = ZA + ZB;
-			t11 = zc - 0.1e1;
-			t12 = t10 * t11;
-			t13 = kn * t11;
-			t15 = exp(0.2e1 * t13);
-			t16 = t12 * t15;
-			t19 = kn * kn;
-			t20 = ZA * ZA;
-			t21 = t19 * t20;
-			t22 = zc * zc;
-			t24 = 0.2e1 * t21 * t22;
-			t26 = 0.2e1 * t21 * zc;
-			t27 = t19 * ZA;
-			t28 = zc * ZB;
-			t30 = 0.4e1 * t27 * t28;
-			t33 = 0.4e1 * t27 * t22 * ZB;
-			t34 = ZB * ZB;
-			t35 = t19 * t34;
-			t37 = 0.2e1 * t35 * t22;
-			t39 = 0.2e1 * t35 * zc;
-			t40 = kn * t20;
-			t42 = t40 * zc;
-			t44 = ZA * kn;
-			t46 = 0.6e1 * t44 * t28;
-			t48 = 0.6e1 * t44 * ZB;
-			t49 = kn * t34;
-			t51 = t49 * zc;
-			t53 = ZA * ZB;
-			t54 = t24 - t26 + t30 - t33 + t37 - t39 + 0.3e1 * t40 - 0.3e1 * t42 + t46 - t48 + 0.3e1 * t49 - 0.3e1 * t51 - t53;
-			t55 = 0.2e1 * kn;
-			t56 = exp(-t55);
-			t59 = t1 * t10;
-			t60 = 0.2e1 * t5;
-			t61 = t60 - 0.3e1;
-			t62 = exp(-t60);
-			t66 = t10 * (ZA - t2);
-			t67 = exp(-t5);
-			t70 = kn * (-0.2e1 + zc);
-			t72 = exp(0.2e1 * t70);
-			t78 = exp(kn * (0.3e1 * zc - 0.4e1));
-			t80 = 0.2e1 * t40;
-			t81 = 0.2e1 * t42;
-			t82 = 0.4e1 * t49;
-			t83 = 0.4e1 * t51;
-			t85 = exp(t70);
-			t90 = exp(kn * (zc - 0.4e1));
-			t95 = exp(-kn * (zc + 0.2e1));
-			t98 = t1 * t1;
-			t100 = exp(0.4e1 * t13);
-			t101 = t98 * t100;
-			t103 = -t4 * t7 + 0.4e1 * kn * t1 * t16 + 0.4e1 * t54 * t56 + t59 * t61 * t62 + t66 * t67 - t59 * t61 * t72 + t4 * t78 + 0.2e1 * (-t80 + t48 + t81 - t82 - t53 - t46 + t83) * t85 - t66 * t90 + 0.2e1 * (-t80 + t48 + t81 - t82 + t53 - t46 + t83) * t95 - t101 + t34 + t20 + 0.2e1 * t53;
-			t105 = ZA * del_rhoB;
-			t108 = 0.2e1 * zc;
-			t111 = exp(-kn * (t108 + 0.1e1));
-			t116 = exp(-0.3e1 * kn);
-			t120 = t1 * ZA;
-			t126 = 0.2e1 * del_rhoB * kn * t20;
-			t130 = 0.2e1 * t44 * zc * del_rhoB * ZB;
-			t133 = 0.2e1 * t105 * kn * ZB;
-			t134 = t20 * del_rhoB;
-			t136 = 0.2e1 * t134 * t5;
-			t137 = 0.2e1 * t134;
-			t138 = t105 * ZB;
-			t151 = exp(kn * (t108 - 0.3e1));
-			t160 = exp(-kn);
-			t164 = t103 * del_rhoA - 0.2e1 * t105 * t1 * (-0.3e1 - t55 + t60) * t111 + 0.2e1 * t105 * t10 * t116 + 0.3e1 * t120 * del_rhoB * t78 + 0.2e1 * (-t126 - t130 + t133 + t136 + t137 - t138) * t85 - t105 * t10 * t90 + 0.2e1 * (-t126 - t130 + t133 + t136 + t138 - t137) * t95 - 0.2e1 * t105 * t1 * (-t55 + 0.3e1 + t60) * t151 - 0.3e1 * t120 * del_rhoB * t7 + t105 * t10 * t67 - 0.2e1 * t105 * t10 * t160;
-			t165 = t27 * zc;
-			t169 = t27 * t1;
-			t173 = exp(-0.2e1 * kn * (zc + 0.1e1));
-			t178 = exp(-0.4e1 * t5);
-			t187 = t10 * t10;
-			t189 = exp(-0.4e1 * kn);
-			t206 = -0.8e1 * t165 * t59 * t72 - 0.8e1 * t169 * t12 * t173 - 0.2e1 * t44 * t98 * t178 + 0.8e1 * t165 * t59 * t62 + 0.8e1 * t169 * t16 + 0.2e1 * t44 * t187 * t189 + 0.16e2 * t44 * (-t39 + t30 - t26 - t53 + t37 + t24 - t33) * t56 - 0.2e1 * t44 * t101 + 0.4e1 * t40 * ZB + 0.2e1 * kn * t20 * ZA + 0.2e1 * t44 * t34;
-			_C3A = t164 / t206;
-			
-			t1 = ZB * ZB;
-			t2 = kn * t1;
-			t3 = t2 * zc;
-			t5 = ZA * ZA;
-			t6 = kn * t5;
-			t8 = kn * kn;
-			t9 = t8 * t1;
-			t11 = 0.2e1 * t9 * zc;
-			t12 = t8 * t5;
-			t13 = zc * zc;
-			t15 = 0.2e1 * t12 * t13;
-			t16 = ZA * ZB;
-			t18 = 0.2e1 * t12 * zc;
-			t19 = ZA * kn;
-			t21 = 0.6e1 * t19 * ZB;
-			t22 = t8 * ZA;
-			t25 = 0.4e1 * t22 * t13 * ZB;
-			t27 = 0.2e1 * t9 * t13;
-			t28 = zc * ZB;
-			t30 = 0.6e1 * t19 * t28;
-			t32 = t6 * zc;
-			t35 = 0.4e1 * t22 * t28;
-			t36 = 0.3e1 * t3 - 0.3e1 * t6 - t11 + t15 - t16 - t18 + t21 - t25 + t27 - t30 - 0.3e1 * t2 + 0.3e1 * t32 + t35;
-			t38 = kn * (-0.2e1 + zc);
-			t39 = exp(t38);
-			t42 = -ZB + ZA;
-			t43 = 0.2e1 * ZB;
-			t45 = t42 * (-ZA - t43);
-			t46 = kn * zc;
-			t47 = 0.2e1 * t46;
-			t48 = exp(-t47);
-			t50 = 0.2e1 * t6;
-			t51 = 0.2e1 * t32;
-			t52 = 0.4e1 * t2;
-			t53 = 0.4e1 * t3;
-			t55 = 0.2e1 * kn;
-			t56 = exp(-t55);
-			t59 = t42 * t42;
-			t61 = exp(-0.3e1 * t46);
-			t63 = ZA + ZB;
-			t67 = exp(0.2e1 * t38);
-			t69 = t42 * t63;
-			t70 = t47 + 0.3e1;
-			t71 = exp(-t46);
-			t74 = t63 * t63;
-			t77 = exp(kn * (zc - 0.4e1));
-			t82 = exp(kn * (0.3e1 * zc - 0.4e1));
-			t85 = zc - 0.1e1;
-			t86 = kn * t85;
-			t88 = exp(0.4e1 * t86);
-			t93 = exp(0.2e1 * t86);
-			t97 = t63 * t85;
-			t100 = exp(-kn * (zc + 0.2e1));
-			t104 = -0.4e1 * t36 * t39 - t45 * t48 + 0.2e1 * (-t50 + t21 + t51 - t52 + t16 - t30 + t53) * t56 + t59 * t61 - t63 * (ZA - t43) * t67 - t69 * t70 * t71 - t74 * t77 + t69 * t70 * t82 + t45 * t88 - t16 - 0.2e1 * t1 + t5 + 0.2e1 * (-t50 + t21 + t51 - t52 - t16 - t30 + t53) * t93 + 0.4e1 * kn * t42 * t97 * t100;
-			t106 = ZA * del_rhoB;
-			t110 = kn * (zc + 0.1e1);
-			t111 = exp(-t110);
-			t120 = exp(0.3e1 * t86);
-			t126 = exp(kn * (zc - 0.3e1));
-			t132 = 0.2e1 * del_rhoB * kn * t5;
-			t136 = 0.2e1 * t19 * zc * del_rhoB * ZB;
-			t139 = 0.2e1 * t106 * kn * ZB;
-			t140 = t5 * del_rhoB;
-			t142 = 0.2e1 * t140 * t46;
-			t143 = t106 * ZB;
-			t144 = 0.2e1 * t140;
-			t148 = exp(t86);
-			t152 = t42 * ZA;
-			t162 = t104 * del_rhoA - 0.2e1 * t106 * t42 * (-0.3e1 - t55 + t47) * t111 - t106 * t63 * t67 - 0.2e1 * t106 * t42 * (-t55 + 0.3e1 + t47) * t120 + 0.2e1 * t106 * t63 * t126 + 0.2e1 * (-t132 - t136 + t139 + t142 + t143 - t144) * t56 - 0.2e1 * t106 * t63 * t148 + t143 - 0.3e1 * t152 * del_rhoB * t48 + 0.2e1 * (-t132 - t136 + t139 + t142 + t144 - t143) * t93 + 0.3e1 * t152 * del_rhoB * t88 + t140;
-			t163 = t22 * zc;
-			t167 = t22 * t42;
-			t169 = exp(-0.2e1 * t110);
-			t174 = exp(-0.4e1 * t46);
-			t185 = exp(-0.4e1 * kn);
-			t203 = -0.8e1 * t163 * t69 * t67 - 0.8e1 * t167 * t97 * t169 - 0.2e1 * t19 * t59 * t174 + 0.8e1 * t163 * t69 * t48 + 0.8e1 * t167 * t97 * t93 + 0.2e1 * t19 * t74 * t185 + 0.16e2 * t19 * (-t11 + t35 - t18 - t16 + t27 + t15 - t25) * t56 - 0.2e1 * t19 * t59 * t88 + 0.4e1 * t6 * ZB + 0.2e1 * kn * t5 * ZA + 0.2e1 * t19 * t1;
-			_C4A = t162 / t203;
-		} else {
-			t1 = ZA * kn;
-			t2 = t1 * ZB;
-			t3 = zc * ZB;
-			t4 = t1 * t3;
-			t6 = kn * kn;
-			t7 = ZB * ZB;
-			t8 = t6 * t7;
-			t9 = zc * zc;
-			t10 = t8 * t9;
-			t12 = ZA * ZA;
-			t14 = kn * t12 * zc;
-			t15 = 0.2e1 * t14;
-			t16 = t8 * zc;
-			t17 = t6 * kn;
-			t18 = t17 * t9;
-			t21 = kn * t7;
-			t22 = t21 * zc;
-			t25 = t9 * zc;
-			t35 = t6 * ZA;
-			t36 = t9 * ZB;
-			t37 = t35 * t36;
-			t39 = t6 * t12;
-			t40 = t39 * zc;
-			t41 = t35 * t3;
-			t43 = t39 * t9;
-			t44 = 0.4e1 * t43;
-			t47 = ZA * ZB;
-			t48 = 0.2e1 * t47;
-			t51 = t2 - 0.4e1 * t4 - 0.4e1 * t10 + t15 + t16 - 0.2e1 * t18 * t12 + 0.2e1 * t22 + 0.2e1 * t17 * t7 * t25 - 0.4e1 * t17 * ZA * ZB * t25 + 0.2e1 * t17 * t12 * t25 + 0.8e1 * t37 + t40 - 0.2e1 * t41 - t44 - 0.2e1 * t18 * t7 + t48 + 0.4e1 * t18 * t47;
-			t53 = kn * (zc + 0.1e1);
-			t54 = exp(-t53);
-			t57 = 0.6e1 * t37;
-			t58 = 0.2e1 * t10;
-			t59 = 0.4e1 * t14;
-			t60 = 0.3e1 * t4;
-			t62 = kn * zc;
-			t63 = 0.2e1 * t62;
-			t64 = exp(-t63);
-			t67 = -ZB + ZA;
-			t69 = 0.2e1 * t1 * zc;
-			t70 = 0.4e1 * t1;
-			t71 = 0.2e1 * ZA;
-			t72 = t62 * ZB;
-			t73 = kn * ZB;
-			t74 = 0.2e1 * t73;
-			t77 = zc - 0.1e1;
-			t78 = kn * t77;
-			t80 = exp(0.2e1 * t78);
-			t82 = ZA + ZB;
-			t83 = t67 * t82;
-			t85 = 0.2e1 * t6 * zc;
-			t86 = 0.4e1 * t62;
-			t87 = t6 * t9;
-			t89 = 0.2e1 - t85 - t86 + 0.2e1 * t87 + kn;
-			t90 = exp(t78);
-			t93 = t82 * t82;
-			t94 = -0.2e1 + kn;
-			t98 = exp(-kn * (0.3e1 + zc));
-			t100 = t67 * t67;
-			t103 = exp(0.3e1 * t78);
-			t107 = exp(-t86);
-			t115 = exp(-0.2e1 * kn);
-			t122 = exp(-kn * (0.3e1 * zc + 0.1e1));
-			t128 = exp(-0.2e1 * t53);
-			t134 = exp(kn * (zc - 0.3e1));
-			t138 = -0.4e1 * t51 * t54 - 0.2e1 * (-t57 + t58 - t59 + t60 + t44 - t48) * t64 + t67 * (t69 - t70 + t71 + t72 - t74) * t80 - t83 * t89 * t90 - t93 * t94 * t98 + t100 * t94 * t103 + t67 * (-t71 + t69 + t72) * t107 + 0.2e1 * (0.12e2 * t41 - t48 - t57 - 0.4e1 * t16 + t59 - t60 + t58 + t44 + 0.2e1 * t2 - 0.8e1 * t40) * t115 - t15 - t4 + 0.2e1 * t12 + t22 + t48 + t83 * t89 * t122 - t82 * (-t70 + t71 + t69 + t74 - t72) * t128 + 0.4e1 * t62 * t67 * t82 * t94 * t134;
-			t141 = del_rhoA * kn * ZB;
-			t143 = del_rhoA * ZB;
-			t144 = 0.2e1 * t143;
-			t145 = t62 * t143;
-			t153 = kn * (-0.2e1 + zc);
-			t154 = exp(t153);
-			t159 = t6 * del_rhoA;
-			t162 = del_rhoA * ZA;
-			t165 = zc * del_rhoA;
-			t166 = t21 * t165;
-			t167 = 0.2e1 * t166;
-			t168 = t159 * ZA;
-			t170 = 0.2e1 * t36 * t168;
-			t171 = t7 * del_rhoA;
-			t172 = 0.2e1 * t171;
-			t178 = 0.2e1 * t87 * t171;
-			t180 = t1 * t165 * ZB;
-			t181 = 0.3e1 * t180;
-			t186 = pow(-0.1e1 + t62, 0.2e1);
-			t189 = exp(-0.3e1 * t62);
-			t196 = 0.3e1 * t145;
-			t200 = exp(-t62);
-			t210 = exp(-kn * (zc + 0.2e1));
-			t218 = t138 * del_rhoB - t82 * (0.2e1 * t141 - t144 - t145) * t128 + 0.4e1 * t143 * (0.1e1 - 0.3e1 * kn + t87 - t85 + t63) * t67 * t154 + 0.2e1 * (-0.4e1 * t7 * zc * t159 + 0.2e1 * t162 * t73 + t167 - t170 + t172 + 0.4e1 * t3 * t168 - 0.4e1 * t21 * del_rhoA + t178 - t181) * t115 - 0.4e1 * t143 * t186 * t67 * t189 - 0.2e1 * (t181 + t172 - t170 - t167 + t178) * t64 + t67 * (-t196 + t144) * t107 + 0.4e1 * t143 * t82 * t200 - 0.2e1 * t162 * ZB + 0.4e1 * t143 * (kn - 0.1e1) * t82 * t210 + t166 + t67 * (0.6e1 * t141 - t196 - t144) * t80 + t180 - t172;
-			t219 = t6 * ZB;
-			t221 = exp(0.4e1 * t78);
-			t225 = t17 * ZB;
-			t226 = t225 * zc;
-			t228 = exp(0.2e1 * t153);
-			t238 = t225 * t67;
-			t239 = t82 * t77;
-			t244 = exp(-0.4e1 * kn);
-			t267 = -0.2e1 * t219 * t100 * t221 - 0.8e1 * t226 * t83 * t228 - 0.2e1 * t219 * t100 * t107 + 0.8e1 * t226 * t83 * t64 + 0.8e1 * t238 * t239 * t80 + 0.2e1 * t219 * t93 * t244 - 0.8e1 * t238 * t239 * t128 + 0.16e2 * t219 * (-0.2e1 * t16 + 0.4e1 * t41 - 0.2e1 * t40 - t47 + t58 + 0.2e1 * t43 - 0.4e1 * t37) * t115 + 0.4e1 * t35 * t7 + 0.2e1 * t39 * ZB + 0.2e1 * t6 * t7 * ZB;
-			_C1B = t218 / t267;
-			
-			t1 = kn * kn;
-			t2 = ZA * ZA;
-			t3 = t1 * t2;
-			t4 = zc * zc;
-			t5 = t3 * t4;
-			t6 = 0.4e1 * t5;
-			t7 = t3 * zc;
-			t9 = t1 * ZA;
-			t10 = zc * ZB;
-			t11 = t9 * t10;
-			t13 = t4 * ZB;
-			t14 = t9 * t13;
-			t15 = 0.6e1 * t14;
-			t16 = ZB * ZB;
-			t17 = t1 * t16;
-			t18 = t17 * t4;
-			t19 = 0.2e1 * t18;
-			t20 = t17 * zc;
-			t22 = kn * t2;
-			t23 = t22 * zc;
-			t24 = 0.4e1 * t23;
-			t25 = ZA * kn;
-			t26 = t25 * ZB;
-			t27 = 0.2e1 * t26;
-			t28 = t25 * t10;
-			t29 = 0.3e1 * t28;
-			t30 = ZA * ZB;
-			t31 = 0.2e1 * t30;
-			t34 = kn * (zc + 0.1e1);
-			t35 = exp(-t34);
-			t38 = ZA + ZB;
-			t39 = 0.2e1 * ZA;
-			t41 = 0.2e1 * t25 * zc;
-			t42 = 0.4e1 * t25;
-			t43 = kn * ZB;
-			t44 = 0.2e1 * t43;
-			t45 = kn * zc;
-			t46 = t45 * ZB;
-			t49 = zc - 0.1e1;
-			t50 = kn * t49;
-			t51 = exp(t50);
-			t53 = -ZB + ZA;
-			t55 = 0.2e1 + kn;
-			t57 = 0.2e1 * t45;
-			t58 = exp(-t57);
-			t67 = exp(-kn * (0.3e1 * zc + 0.1e1));
-			t69 = t53 * t38;
-			t71 = 0.2e1 * t1 * zc;
-			t72 = 0.4e1 * t45;
-			t73 = t1 * t4;
-			t75 = -t71 + t72 + 0.2e1 * t73 + 0.2e1 - kn;
-			t77 = exp(-0.2e1 * t34);
-			t80 = t53 * t53;
-			t82 = exp(-t72);
-			t84 = t1 * kn;
-			t86 = t4 * zc;
-			t89 = t84 * t4;
-			t108 = kn * t16;
-			t111 = 0.2e1 * t84 * t2 * t86 - 0.2e1 * t89 * t2 + 0.4e1 * t89 * t30 - 0.4e1 * t84 * ZA * ZB * t86 + 0.2e1 * t84 * t16 * t86 - 0.2e1 * t89 * t16 - t7 + t6 + 0.2e1 * t11 - 0.8e1 * t14 - t20 + 0.4e1 * t18 + 0.2e1 * t23 + t26 - 0.4e1 * t28 + 0.2e1 * t108 * zc - t31;
-			t113 = exp(-0.2e1 * kn);
-			t117 = exp(0.2e1 * t50);
-			t124 = exp(-kn * (0.3e1 + zc));
-			t129 = exp(kn * (zc - 0.3e1));
-			t135 = exp(0.3e1 * t50);
-			t140 = 0.2e1 * (t6 - 0.8e1 * t7 + 0.12e2 * t11 - t15 + t19 - 0.4e1 * t20 - t24 - t27 + t29 - t31) * t35 + t38 * (-t39 + t41 - t42 + t44 - t46) * t51 + 0.4e1 * t45 * t53 * t38 * t55 * t58 - t53 * (-t39 - t42 + t41 - t44 + t46) * t67 - t69 * t75 * t77 - t80 * t55 * t82 + 0.4e1 * t111 * t113 + t69 * t75 * t117 + t38 * (t41 + t39 - t46) * t124 - 0.2e1 * (t6 + t19 - t15 - t29 + t24 - t31) * t129 - t53 * (t39 + t46 + t41) * t135 + t27 + 0.2e1 * t16 + t108 + t22 + 0.4e1 * t30 + 0.2e1 * t2;
-			t142 = del_rhoA * ZB;
-			t143 = 0.2e1 * t142;
-			t145 = del_rhoA * kn * ZB;
-			t147 = t45 * t142;
-			t148 = 0.3e1 * t147;
-			t152 = t16 * del_rhoA;
-			t154 = 0.2e1 * t73 * t152;
-			t155 = t1 * del_rhoA;
-			t156 = t155 * ZA;
-			t158 = 0.2e1 * t13 * t156;
-			t159 = zc * del_rhoA;
-			t161 = 0.2e1 * t108 * t159;
-			t164 = 0.3e1 * t25 * t159 * ZB;
-			t165 = 0.2e1 * t152;
-			t169 = 0.3e1 * kn;
-			t172 = 0.2e1 * zc;
-			t175 = exp(-kn * (t172 + 0.1e1));
-			t180 = pow(0.1e1 + t45, 0.2e1);
-			t184 = exp(kn * (t172 - 0.3e1));
-			t188 = exp(-t169);
-			t217 = exp(-kn);
-			t221 = t140 * del_rhoB - t53 * (t143 + 0.6e1 * t145 - t148) * t67 - 0.2e1 * (t154 - t158 + t161 - t164 + t165) * t129 + 0.4e1 * t142 * (t169 - t57 + t73 - t71 + 0.1e1) * t53 * t175 - 0.4e1 * t142 * t180 * t53 * t184 + 0.4e1 * t142 * t38 * t188 + t38 * (0.2e1 * t145 + t143 - t147) * t51 - t53 * (-t148 - t143) * t135 + 0.2e1 * (0.4e1 * t10 * t156 - t158 + t154 - 0.4e1 * t16 * zc * t155 - 0.2e1 * del_rhoA * ZA * t43 + t164 + 0.4e1 * t108 * del_rhoA - t161 + t165) * t35 + t38 * (-t147 - t143) * t124 - 0.4e1 * t142 * (kn + 0.1e1) * t38 * t217;
-			t222 = t1 * ZB;
-			t224 = exp(0.4e1 * t50);
-			t228 = t84 * ZB;
-			t229 = t228 * zc;
-			t233 = exp(0.2e1 * kn * (-0.2e1 + zc));
-			t243 = t228 * t53;
-			t244 = t38 * t49;
-			t248 = t38 * t38;
-			t250 = exp(-0.4e1 * kn);
-			t273 = -0.2e1 * t222 * t80 * t224 - 0.8e1 * t229 * t69 * t233 - 0.2e1 * t222 * t80 * t82 + 0.8e1 * t229 * t69 * t58 + 0.8e1 * t243 * t244 * t117 + 0.2e1 * t222 * t248 * t250 - 0.8e1 * t243 * t244 * t77 + 0.16e2 * t222 * (-0.2e1 * t20 + 0.4e1 * t11 - 0.2e1 * t7 - t30 + t19 + 0.2e1 * t5 - 0.4e1 * t14) * t113 + 0.4e1 * t9 * t16 + 0.2e1 * t3 * ZB + 0.2e1 * t1 * t16 * ZB;
-			_C2B = t221 / t273;
-			
-			t1 = kn * kn;
-			t2 = ZA * ZA;
-			t3 = t1 * t2;
-			t4 = zc * zc;
-			t6 = 0.2e1 * t3 * t4;
-			t8 = 0.2e1 * t3 * zc;
-			t9 = t1 * ZA;
-			t10 = zc * ZB;
-			t12 = 0.4e1 * t9 * t10;
-			t15 = 0.4e1 * t9 * t4 * ZB;
-			t16 = ZB * ZB;
-			t17 = t1 * t16;
-			t19 = 0.2e1 * t17 * t4;
-			t21 = 0.2e1 * t17 * zc;
-			t22 = kn * t16;
-			t23 = t22 * zc;
-			t25 = ZA * kn;
-			t27 = 0.6e1 * t25 * t10;
-			t28 = kn * t2;
-			t29 = t28 * zc;
-			t31 = ZA * ZB;
-			t34 = kn * (zc + 0.1e1);
-			t35 = exp(-t34);
-			t38 = -ZB + ZA;
-			t39 = 0.2e1 * ZA;
-			t41 = t38 * (t39 + ZB);
-			t42 = zc - 0.1e1;
-			t43 = kn * t42;
-			t45 = exp(0.2e1 * t43);
-			t47 = 0.4e1 * t29;
-			t48 = 0.2e1 * t23;
-			t50 = kn * zc;
-			t51 = 0.2e1 * t50;
-			t52 = exp(-t51);
-			t55 = ZA + ZB;
-			t59 = exp(-0.2e1 * t34);
-			t61 = t38 * t55;
-			t64 = exp(kn * (zc - 0.3e1));
-			t68 = 0.2e1 * kn;
-			t69 = -0.3e1 - t68 + t51;
-			t70 = exp(t43);
-			t76 = exp(-kn * (0.3e1 * zc + 0.1e1));
-			t79 = t38 * t38;
-			t81 = exp(0.3e1 * t43);
-			t84 = exp(-0.4e1 * t50);
-			t87 = exp(-t68);
-			t90 = t55 * t55;
-			t93 = exp(-kn * (0.3e1 + zc));
-			t96 = 0.4e1 * (t6 - t8 + t12 - t15 + t19 - t21 - 0.3e1 * t23 + t27 - 0.3e1 * t29 - t31) * t35 + t41 * t45 + 0.2e1 * (t47 - t27 + t48 + t31) * t52 - t55 * (t39 - ZB) * t59 - 0.4e1 * t50 * t61 * t64 + t61 * t69 * t70 - t61 * t69 * t76 - t79 * t81 - t41 * t84 + 0.2e1 * (t47 - t27 + t48 - t31) * t87 + t90 * t93 + 0.2e1 * t2 + t31 - t16;
-			t98 = del_rhoA * ZB;
-			t104 = kn * (-0.2e1 + zc);
-			t105 = exp(t104);
-			t109 = zc * del_rhoA;
-			t112 = 0.2e1 * t25 * t109 * ZB;
-			t114 = 0.2e1 * t22 * t109;
-			t115 = t16 * del_rhoA;
-			t116 = 0.2e1 * t115;
-			t118 = del_rhoA * ZA * ZB;
-			t125 = exp(-0.3e1 * t50);
-			t132 = t38 * del_rhoA;
-			t136 = exp(-t50);
-			t142 = exp(-kn * (zc + 0.2e1));
-			t149 = t96 * del_rhoB + t98 * t55 * t59 + 0.2e1 * t98 * t38 * (t51 + 0.3e1) * t105 + 0.2e1 * (-t112 + t114 + t116 - t118) * t87 + 0.2e1 * t98 * t38 * (t51 - 0.3e1) * t125 + 0.2e1 * (-t112 + t114 + t118 - t116) * t52 + 0.3e1 * t132 * ZB * t84 + 0.2e1 * t98 * t55 * t136 - 0.2e1 * t98 * t55 * t142 - t115 - 0.3e1 * t132 * ZB * t45 - t118;
-			t150 = t1 * ZB;
-			t151 = t150 * zc;
-			t153 = exp(0.2e1 * t104);
-			t157 = kn * ZB;
-			t159 = exp(0.4e1 * t43);
-			t169 = t150 * t38;
-			t170 = t55 * t42;
-			t175 = exp(-0.4e1 * kn);
-			t193 = -0.8e1 * t151 * t61 * t153 - 0.2e1 * t157 * t79 * t159 - 0.2e1 * t157 * t79 * t84 + 0.8e1 * t151 * t61 * t52 + 0.8e1 * t169 * t170 * t45 + 0.2e1 * t157 * t90 * t175 - 0.8e1 * t169 * t170 * t59 + 0.16e2 * t157 * (-t21 + t12 - t8 - t31 + t19 + t6 - t15) * t87 + 0.4e1 * t25 * t16 + 0.2e1 * kn * t16 * ZB + 0.2e1 * t28 * ZB;
-			_C3B = t149 / t193;
-			
-			t1 = -ZB + ZA;
-			t2 = t1 * t1;
-			t3 = kn * zc;
-			t5 = exp(-0.4e1 * t3);
-			t6 = t2 * t5;
-			t7 = ZA + ZB;
-			t8 = t1 * t7;
-			t9 = 0.2e1 * t3;
-			t10 = exp(-t9);
-			t11 = t8 * t10;
-			t14 = ZA * ZA;
-			t15 = kn * t14;
-			t16 = t15 * zc;
-			t17 = 0.4e1 * t16;
-			t18 = ZA * kn;
-			t19 = zc * ZB;
-			t21 = 0.6e1 * t18 * t19;
-			t22 = ZB * ZB;
-			t23 = kn * t22;
-			t24 = t23 * zc;
-			t25 = 0.2e1 * t24;
-			t26 = ZA * ZB;
-			t30 = exp(kn * (zc - 0.3e1));
-			t33 = 0.2e1 * kn;
-			t34 = -t33 + 0.3e1 + t9;
-			t36 = kn * (zc + 0.1e1);
-			t38 = exp(-0.2e1 * t36);
-			t42 = exp(-t36);
-			t45 = kn * kn;
-			t46 = t45 * ZA;
-			t48 = 0.4e1 * t46 * t19;
-			t49 = t45 * t22;
-			t50 = zc * zc;
-			t52 = 0.2e1 * t49 * t50;
-			t55 = 0.2e1 * t49 * zc;
-			t57 = t45 * t14;
-			t59 = 0.2e1 * t57 * t50;
-			t61 = 0.2e1 * t57 * zc;
-			t64 = 0.4e1 * t46 * t50 * ZB;
-			t66 = exp(-t33);
-			t69 = 0.2e1 * ZA;
-			t71 = t7 * (t69 - ZB);
-			t72 = zc - 0.1e1;
-			t73 = kn * t72;
-			t74 = exp(t73);
-			t78 = exp(-kn * (0.3e1 + zc));
-			t81 = t1 * (t69 + ZB);
-			t85 = exp(-kn * (0.3e1 * zc + 0.1e1));
-			t88 = exp(0.3e1 * t73);
-			t91 = exp(0.2e1 * t73);
-			t95 = t6 - 0.4e1 * t3 * t11 + 0.2e1 * (t17 - t21 + t25 - t26) * t30 + t8 * t34 * t38 + 0.2e1 * (t17 - t21 + t25 + t26) * t42 - 0.4e1 * (t48 + t52 + 0.3e1 * t24 - t55 + 0.3e1 * t16 - t21 + t59 - t61 - t26 - t64) * t66 + t71 * t74 - t71 * t78 - t81 * t85 + t81 * t88 - t8 * t34 * t91 - t22 - 0.2e1 * t26 - t14;
-			t97 = t1 * del_rhoA;
-			t101 = del_rhoA * ZB;
-			t102 = exp(-kn);
-			t107 = exp(-0.3e1 * kn);
-			t111 = zc * del_rhoA;
-			t114 = 0.2e1 * t18 * t111 * ZB;
-			t116 = 0.2e1 * t23 * t111;
-			t118 = 0.2e1 * t22 * del_rhoA;
-			t120 = del_rhoA * ZA * ZB;
-			t131 = 0.2e1 * zc;
-			t134 = exp(-kn * (t131 + 0.1e1));
-			t144 = exp(kn * (t131 - 0.3e1));
-			t151 = t95 * del_rhoB + 0.3e1 * t97 * ZB * t85 + 0.2e1 * t101 * t7 * t102 - 0.2e1 * t101 * t7 * t107 + 0.2e1 * (-t114 + t116 + t118 - t120) * t30 + t101 * t7 * t78 + 0.2e1 * (-t114 + t116 + t120 - t118) * t42 + 0.2e1 * t101 * t1 * (t9 - 0.3e1) * t134 - t101 * t7 * t74 + 0.2e1 * t101 * t1 * (t9 + 0.3e1) * t144 - 0.3e1 * t97 * ZB * t88;
-			t152 = t45 * ZB;
-			t153 = t152 * zc;
-			t157 = exp(0.2e1 * kn * (-0.2e1 + zc));
-			t161 = kn * ZB;
-			t163 = exp(0.4e1 * t73);
-			t171 = t152 * t1;
-			t172 = t7 * t72;
-			t176 = t7 * t7;
-			t178 = exp(-0.4e1 * kn);
-			t196 = -0.8e1 * t153 * t8 * t157 - 0.2e1 * t161 * t2 * t163 - 0.2e1 * t161 * t6 + 0.8e1 * t153 * t11 + 0.8e1 * t171 * t172 * t91 + 0.2e1 * t161 * t176 * t178 - 0.8e1 * t171 * t172 * t38 + 0.16e2 * t161 * (-t55 + t48 - t61 - t26 + t52 + t59 - t64) * t66 + 0.4e1 * t18 * t22 + 0.2e1 * kn * t22 * ZB + 0.2e1 * t15 * ZB;
-			_C4B = t151 / t196;
-			
-		}
-		
-		/*******************************************/
-		/*       calculate the velocities etc      */
-		/*******************************************/
-		
-		if (z < zc) { 
-			
-			t4 = exp(-kn * z);
-			t10 = exp(kn * (z - zc));
-			t14 = kn * kn;
-			u1 = u1a = (_C1A + z * _C3A) * t4 + (_C2A + z * _C4A) * t10 - del_rhoA / ZA / t14;
-			
-			t1 = kn * z;
-			t2 = exp(-t1);
-			t6 = exp(kn * (z - zc));
-			t10 = 0.1e1 / kn;
-			u2 = u2a = t2 * _C1A - t6 * _C2A + t2 * (-0.1e1 + t1) * _C3A * t10 - t6 * (0.1e1 + t1) * _C4A * t10;
-			
-			t1 = ZA * kn;
-			t3 = exp(-kn * z);
-			t8 = exp(kn * (z - zc));
-			u3 = u3a = -0.2e1 * t1 * t3 * _C1A + 0.2e1 * t1 * t8 * _C2A - 0.2e1 * t1 * t3 * z * _C3A + 0.2e1 * t1 * t8 * z * _C4A;
-			
-			t2 = kn * z;
-			t6 = exp(-t2);
-			t15 = exp(kn * (z - zc));
-			u4 = u4a = -0.2e1 * ZA * (-_C3A + kn * _C1A + t2 * _C3A) * t6 - 0.2e1 * ZA * (_C4A + kn * _C2A + t2 * _C4A) * t15 + 0.1e1 / kn * del_rhoA;
-			
-			Z = ZA;
-			
-		} else {
-			
-			t5 = exp(kn * (zc - z));
-			t11 = exp(kn * (z - 0.1e1));
-			t15 = kn * kn;
-			u1 = u1b = (_C1B + z * _C3B) * t5 + (_C2B + z * _C4B) * t11 - del_rhoB / ZB / t15;
-			
-			t3 = exp(kn * (zc - z));
-			t7 = exp(kn * (z - 0.1e1));
-			t9 = kn * z;
-			t12 = 0.1e1 / kn;
-			u2 = u2b = t3 * _C1B - t7 * _C2B + t3 * (-0.1e1 + t9) * _C3B * t12 - t7 * (0.1e1 + t9) * _C4B * t12;
-			
-			t1 = kn * ZB;
-			t4 = exp(kn * (zc - z));
-			t9 = exp(kn * (z - 0.1e1));
-			u3 = u3b = -0.2e1 * t1 * t4 * _C1B + 0.2e1 * t1 * t9 * _C2B - 0.2e1 * t1 * t4 * z * _C3B + 0.2e1 * t1 * t9 * z * _C4B;
-			
-			t2 = kn * z;
-			t8 = exp(kn * (zc - z));
-			t17 = exp(kn * (z - 0.1e1));
-			u4 = u4b = -0.2e1 * ZB * (-_C3B + kn * _C1B + t2 * _C3B) * t8 - 0.2e1 * ZB * (_C4B + kn * _C2B + t2 * _C4B) * t17 + 0.1e1 / kn * del_rhoB;
-			
-			
-			Z = ZB;
-		}
-		
-		
-		
-		pp = (double)-(u3 + 2.0*n*M_PI*Z*u2)*cos(n*M_PI*x); /* pressure */
-		
-		txx = (double)(u3 + 4*Z*n*M_PI*u2)*cos(n*M_PI*x); /* xx stress */
-		sum5 += pp;
-		sum6 += txx;
-		
-		u1 *= cos(n*M_PI*x); /* z velocity */
-		sum1 += u1;
-		u2 *= sin(n*M_PI*x); /* x velocity */
-		sum2 += u2;
-		u3 *= cos(n*M_PI*x); /* zz stress */
-		sum3 += u3;
-		u4 *= sin(n*M_PI*x); /* zx stress */
-		sum4 += u4;
-		
-		rho = del_rho* cos(n*M_PI*x); /* density */
-		sum7 += rho;
-	}/* n */
-	
-	/* include terms for n=0 now */
-	del_rho = sigma*dx;
-	rho = del_rho; /* density */
-	sum7 += rho;
-	u3 = del_rho*(z-zc); /* zz stress */
-	sum3 += u3;
-	
-	txx = u3; /* xx stress */
-	pp = -u3; /* pressure */
-	sum5 += pp;
-	sum6 += txx;
-	/* i.e. u3 for n=0 is arbitrarily set to zero at z=zc */
-	
-	
-	mag=sqrt(sum1*sum1+sum2*sum2);
-	//printf("%0.7g %0.7g %0.7g %0.7g %0.7g %0.7g\n",x,y,z,sum3,sum2,sum1);
-	//printf("%0.7g %0.7g %0.7g\n%0.7g %0.7g %0.7g\n\n\n",x,y,z,x+sum3,y+sum2,z+sum1);
-	/*printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7); */
-	
-	
-	/* Output */
-	if( vel != NULL ) {
-		vel[0] = sum2;
-		vel[1] = sum1;
-	}
-	if( presssure != NULL ) {
-		(*presssure) = sum5;
-	}
-	if( total_stress != NULL ) {
-		total_stress[0] = sum6;
-		total_stress[1] = sum3;
-		total_stress[2] = sum4;
-	}
-	if( strain_rate != NULL ) {
-		if( z<zc ) {
-			Z = ZA;
-		}
-		else {
-			Z = ZB;
-		}
-		strain_rate[0] = (sum6+sum5)/(2.0*Z);
-		strain_rate[1] = (sum3+sum5)/(2.0*Z);
-		strain_rate[2] = (sum4)/(2.0*Z);
-	}
-	/* Value checks, could be cleaned up if needed. Julian Giordani 9-Oct-2006*/
-        if( fabs( sum5 - ( -0.5*(sum6+sum3) ) ) > 1e-5 ) {
-                assert(0);
-        }
-	
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solDA/solDA.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solDA/solDA.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,974 @@
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+
+
+void _Velic_solDA( 
+		double pos[],
+		double _sigma,
+		double _eta_A, double _eta_B, 
+		double _z_c, double _dx, double _x_0,
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] );
+
+
+int main( int argc, char **argv )
+{
+	int i,j;
+	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
+	double x,z;
+	
+	for (i=0;i<101;i++){
+		for(j=0;j<101;j++){
+			x = i/100.0;
+			z = j/100.0;
+			
+			pos[0] = x;
+			pos[1] = z;
+			_Velic_solDA(
+					pos,
+					3.0,
+					1.0, 2.0,
+					0.8, 0.25, 0.45,
+					vel, &pressure, total_stress, strain_rate );
+			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
+					pos[0],pos[1],
+					vel[0],vel[1], pressure, 
+					total_stress[0], total_stress[1], total_stress[2], 
+					strain_rate[0], strain_rate[1], strain_rate[2] );
+		}
+		printf("\n");
+	}
+	
+	return 0;
+}
+
+
+
+
+void _Velic_solDA(		
+		double pos[],
+		double _sigma, /* density */
+		double _eta_A, double _eta_B, /* viscosity A, viscosity B */ 
+		double _z_c, double _dx, double _x_0, /* viscosity jump location, width of dense column, centre of dense column */
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] )
+{
+	double Z,ZA,ZB,u1,u2,u3,u4,pp,txx;
+	double u1a,u2a,u3a,u4a,u1b,u2b,u3b,u4b;
+	double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,x,z;
+	double sigma,dx;
+	double del_rhoA,del_rhoB,del_rho;
+	int n;
+	double kn;
+	double _C1A,_C2A,_C3A,_C4A,_C1B,_C2B,_C3B,_C4B;
+	double x0,rho,zc;
+	
+	double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
+	double t11,t12,t13,t14,t15,t16,t17,t18,t19,t20;
+	double t21,t22,t23,t24,t25,t26,t27,t28,t29,t30;
+	double t31,t32,t33,t34,t35,t36,t37,t38,t39,t40;
+	double t41,t42,t43,t44,t45,t46,t47,t48,t49,t50;
+	double t51,t52,t53,t54,t55,t56,t57,t58,t59,t60;
+	double t61,t62,t63,t64,t66,t67,t68,t69,t70,t71;
+	double t72,t73,t74,t75,t76,t77,t78,t79,t80,t81;
+	double t82,t83,t84,t85,t86,t87,t88,t89,t90,t91;
+	double t93,t94,t95,t96,t97,t98,t99,t100,t101,t102;
+	double t103,t104,t105,t106,t107,t108,t109,t110,t111,t112;
+	double t113,t114,t115,t116,t117,t118,t119,t120,t121,t122;
+	double t123,t124,t125,t126,t128,t129,t130,t131,t132,t133;
+	double t134,t135,t136,t137,t138,t139,t140,t141,t142,t143;
+	double t144,t145,t146,t147,t148,t149,t150,t151,t152,t153;
+	double t154,t155,t156,t157,t158,t159,t160,t161,t162,t163;
+	double t164,t165,t166,t167,t168,t169,t170,t171,t172,t173;
+	double t174,t175,t176,t178,t179,t180,t181,t183,t184,t185;
+	double t186,t187,t188,t189,t191,t193,t196,t197,t200,t202;
+	double t203,t206,t207,t210,t211,t215,t217,t218,t219,t221;
+	double t222,t223,t224,t225,t226,t227,t228,t229,t232,t233;
+	double t238,t239,t243,t244,t246,t248,t250,t251,t267,t273;
+	
+	
+	
+	
+	/*************************************************************************/
+	/*************************************************************************/
+	/*   We have a dense column of density sigma
+	ranging from x=x0-dx/2 to x= x0+dx/2:    */
+	x0 = _x_0;
+	dx = _dx;
+	sigma = _sigma; /* density parameter */
+	ZA = _eta_A;    /* viscosity for layer A */
+	ZB = _eta_B; /* viscosity for layer B */
+	zc = _z_c;
+	/*************************************************************************/
+	/*************************************************************************/
+	
+	x = pos[0];
+	z = pos[1];
+	
+	sum1=0.0;
+	sum2=0.0;
+	sum3=0.0;
+	sum4=0.0;
+	sum5=0.0;
+	sum6=0.0;
+	sum7=0.0;
+	/* convergence is good */
+	for(n=1;n<75;n++){
+		kn = (double) n*M_PI;
+		
+		/*******************************************/
+		/*            calculate del_rho            */
+		/*******************************************/
+		del_rho = 4.0*sigma*cos(n*M_PI*x0)*sin(n*M_PI*dx/2.0)/n/M_PI;
+		del_rhoB = del_rhoA = del_rho;
+		
+		/*******************************************/
+		/*         calculate the constants         */
+		/*******************************************/
+		
+		if (z < zc) {
+			t1 = -ZB + ZA;
+			t2 = ZA * kn;
+			t3 = t2 * zc;
+			t4 = 0.2e1 * ZB;
+			t5 = kn * zc;
+			t7 = 0.2e1 * t5 * ZB;
+			t11 = exp(-0.3e1 * t5);
+			t13 = ZA + ZB;
+			t14 = t1 * t13;
+			t16 = pow(-0.1e1 + t5, 0.2e1);
+			t18 = kn * (-0.2e1 + zc);
+			t20 = exp(0.2e1 * t18);
+			t25 = zc - 0.1e1;
+			t26 = t13 * t25;
+			t27 = kn * t25;
+			t29 = exp(0.2e1 * t27);
+			t30 = t26 * t29;
+			t33 = kn * kn;
+			t34 = t33 * kn;
+			t35 = ZA * ZA;
+			t37 = zc * zc;
+			t38 = t37 * zc;
+			t40 = t34 * t37;
+			t42 = ZB * ZB;
+			t43 = t33 * t42;
+			t44 = t43 * t37;
+			t45 = 0.2e1 * t44;
+			t46 = t33 * t35;
+			t48 = 0.2e1 * t46 * zc;
+			t51 = 0.2e1 * t46 * t37;
+			t52 = ZA * ZB;
+			t53 = t33 * ZA;
+			t55 = t53 * t37 * ZB;
+			t56 = 0.4e1 * t55;
+			t57 = kn * t42;
+			t58 = ZB * zc;
+			t59 = t53 * t58;
+			t60 = 0.4e1 * t59;
+			t61 = t43 * zc;
+			t62 = 0.2e1 * t61;
+			t63 = t34 * ZA;
+			t67 = kn * t35;
+			t73 = t2 * t58;
+			t75 = t57 * zc;
+			t76 = t2 * ZB;
+			t77 = t34 * t35 * t38 - t40 * t35 - t45 + t48 - t40 * t42 - t51 + t52 + t56 - t57 - t60 + t62 - 0.2e1 * t63 * ZB * t38 + t67 * zc + 0.2e1 * t40 * t52 + t34 * t42 * t38 - t67 - 0.2e1 * t73 + t75 + t76;
+			t79 = exp(-0.2e1 * kn);
+			t82 = 0.6e1 * t55;
+			t83 = 0.2e1 * t52;
+			t84 = 0.4e1 * t44;
+			t85 = 0.3e1 * t73;
+			t86 = 0.4e1 * t57;
+			t87 = 0.2e1 * t76;
+			t88 = 0.4e1 * t61;
+			t89 = 0.6e1 * t59;
+			t90 = 0.4e1 * t75;
+			t91 = -t82 - t83 + t84 + t51 + t85 + t86 - t87 - t88 + t89 - t48 - t90;
+			t94 = exp(-kn * (zc + 0.2e1));
+			t99 = exp(-t5);
+			t101 = -t82 + t51 + t90 - t86 + t87 - t85 + t84 + t89 - t88 - t83 - t48;
+			t102 = exp(t18);
+			t110 = exp(kn * (0.3e1 * zc - 0.4e1));
+			t113 = exp(-0.2e1 * t5);
+			t121 = exp(kn * (zc - 0.4e1));
+			t123 = t1 * t1;
+			t125 = exp(0.4e1 * t27);
+			t126 = t123 * t125;
+			t131 = t1 * (-t3 + t4 - t7) * t11 + 0.2e1 * t14 * t16 * t20 + 0.8e1 * kn * t1 * t30 - 0.8e1 * t77 * t79 - 0.2e1 * t91 * t94 + t13 * (t3 - t4 - t7) * t99 + 0.2e1 * t101 * t102 + t1 * (-t3 - t4 - t7) * t110 - 0.2e1 * t14 * t16 * t113 + t13 * (t3 + t4 - t7) * t121 - 0.2e1 * t126 + 0.2e1 * t35 + 0.4e1 * t52 + 0.2e1 * t42;
+			t133 = ZA * del_rhoB;
+			t137 = exp(-0.3e1 * kn);
+			t141 = t33 * zc;
+			t142 = 0.2e1 * t141;
+			t143 = 0.4e1 * t5;
+			t144 = t33 * t37;
+			t145 = 0.2e1 * t144;
+			t148 = 0.2e1 * zc;
+			t151 = exp(-kn * (t148 + 0.1e1));
+			t155 = t133 * t5;
+			t156 = 0.2e1 * t133;
+			t163 = 0.3e1 * t2 * zc * del_rhoB * ZB;
+			t164 = t35 * del_rhoB;
+			t166 = 0.2e1 * t144 * t164;
+			t167 = t133 * ZB;
+			t169 = 0.2e1 * t141 * t167;
+			t172 = 0.2e1 * t133 * kn * ZB;
+			t174 = 0.2e1 * t164 * t5;
+			t176 = 0.2e1 * t144 * t167;
+			t178 = 0.2e1 * t141 * t164;
+			t179 = 0.2e1 * t164;
+			t183 = 0.3e1 * t155;
+			t197 = exp(kn * (t148 - 0.3e1));
+			t203 = exp(-kn);
+			t210 = t131 * del_rhoA - 0.2e1 * t133 * (-0.2e1 + kn) * t13 * t137 + 0.2e1 * t133 * (0.2e1 - t142 - t143 + t145 + kn) * t1 * t151 + t13 * (t155 + t156) * t99 + 0.2e1 * (-t163 + t166 + t169 + t172 + t174 - t176 - t178 + t179) * t102 + t1 * (-t156 + t183) * t11 - 0.2e1 * (-t176 + t163 + t166 - t174 - t172 - t178 + t179 + t169) * t94 + t13 * (-t156 + t155) * t121 - 0.2e1 * t133 * (-t142 + t143 + t145 + 0.2e1 - kn) * t1 * t197 - 0.2e1 * t133 * (0.2e1 + kn) * t13 * t203 + t1 * (t183 + t156) * t110;
+			t211 = t63 * zc;
+			t215 = exp(-t143);
+			t222 = t63 * t1;
+			t225 = t13 * t13;
+			t227 = exp(-0.4e1 * kn);
+			t238 = exp(-0.2e1 * kn * (zc + 0.1e1));
+			t251 = -0.8e1 * t211 * t14 * t20 - 0.2e1 * t53 * t123 * t215 + 0.8e1 * t211 * t14 * t113 + 0.8e1 * t222 * t30 + 0.2e1 * t53 * t225 * t227 + 0.16e2 * t53 * (-t62 + t60 - t48 - t52 + t45 + t51 - t56) * t79 - 0.8e1 * t222 * t26 * t238 - 0.2e1 * t53 * t126 + 0.2e1 * t33 * t35 * ZA + 0.2e1 * t53 * t42 + 0.4e1 * t46 * ZB;
+			_C1A = t210 / t251;
+			
+			t1 = -ZB + ZA;
+			t2 = ZA * kn;
+			t3 = t2 * zc;
+			t4 = 0.2e1 * ZB;
+			t5 = kn * zc;
+			t7 = 0.2e1 * t5 * ZB;
+			t11 = exp(-0.2e1 * t5);
+			t13 = kn * kn;
+			t14 = t13 * ZA;
+			t15 = zc * zc;
+			t17 = t14 * t15 * ZB;
+			t18 = 0.6e1 * t17;
+			t19 = ZA * ZA;
+			t20 = t13 * t19;
+			t22 = 0.2e1 * t20 * t15;
+			t23 = ZB * ZB;
+			t24 = kn * t23;
+			t25 = t24 * zc;
+			t26 = 0.4e1 * t25;
+			t27 = 0.4e1 * t24;
+			t28 = t2 * ZB;
+			t29 = 0.2e1 * t28;
+			t30 = zc * ZB;
+			t31 = t2 * t30;
+			t32 = 0.3e1 * t31;
+			t33 = t13 * t23;
+			t34 = t33 * t15;
+			t35 = 0.4e1 * t34;
+			t36 = t14 * t30;
+			t37 = 0.6e1 * t36;
+			t38 = t33 * zc;
+			t39 = 0.4e1 * t38;
+			t40 = ZA * ZB;
+			t41 = 0.2e1 * t40;
+			t43 = 0.2e1 * t20 * zc;
+			t44 = -t18 + t22 + t26 - t27 + t29 - t32 + t35 + t37 - t39 - t41 - t43;
+			t45 = zc - 0.1e1;
+			t46 = kn * t45;
+			t48 = exp(0.2e1 * t46);
+			t51 = t13 * kn;
+			t53 = t15 * zc;
+			t55 = t51 * t15;
+			t59 = t51 * ZA;
+			t66 = 0.4e1 * t17;
+			t67 = 0.4e1 * t36;
+			t68 = 0.2e1 * t34;
+			t69 = 0.2e1 * t38;
+			t70 = kn * t19;
+			t71 = t70 * zc;
+			t73 = t51 * t19 * t53 - t55 * t19 + 0.2e1 * t55 * t40 - 0.2e1 * t59 * ZB * t53 + t51 * t23 * t53 - t55 * t23 + t22 - t43 - t66 + t67 + t68 - t69 + t71 - t70 + t28 - 0.2e1 * t31 + t25 - t24 - t40;
+			t75 = kn * (-0.2e1 + zc);
+			t76 = exp(t75);
+			t79 = ZA + ZB;
+			t80 = t79 * t79;
+			t83 = exp(kn * (zc - 0.4e1));
+			t87 = t79 * t45;
+			t90 = exp(-kn * (zc + 0.2e1));
+			t97 = exp(0.2e1 * t75);
+			t99 = t1 * t1;
+			t101 = exp(-0.3e1 * t5);
+			t107 = exp(0.4e1 * t46);
+			t110 = -t18 - t41 + t35 + t22 + t32 + t27 - t29 - t39 + t37 - t43 - t26;
+			t112 = exp(-0.2e1 * kn);
+			t116 = t1 * t79;
+			t118 = pow(0.1e1 + t5, 0.2e1);
+			t119 = exp(-t5);
+			t126 = exp(kn * (0.3e1 * zc - 0.4e1));
+			t130 = -t1 * (-t3 + t4 - t7) * t11 - 0.2e1 * t44 * t48 + 0.8e1 * t73 * t76 + 0.2e1 * t80 * t83 - 0.8e1 * kn * t1 * t87 * t90 - t79 * (t3 + t4 - t7) * t97 - 0.2e1 * t99 * t101 - t71 + t31 - t1 * (-t3 - t4 - t7) * t107 + 0.2e1 * t23 + t41 + 0.2e1 * t110 * t112 + 0.2e1 * t25 + 0.2e1 * t116 * t118 * t119 - 0.2e1 * t116 * t118 * t126;
+			t132 = ZA * del_rhoB;
+			t133 = 0.2e1 * t132;
+			t134 = t132 * t5;
+			t138 = t19 * del_rhoB;
+			t139 = 0.2e1 * t138;
+			t140 = t132 * ZB;
+			t142 = t13 * zc;
+			t143 = 0.2e1 * t142;
+			t144 = 0.4e1 * t5;
+			t145 = t13 * t15;
+			t146 = 0.2e1 * t145;
+			t150 = exp(0.3e1 * t46);
+			t154 = 0.3e1 * t134;
+			t161 = kn * (zc + 0.1e1);
+			t162 = exp(-t161);
+			t168 = exp(t46);
+			t175 = t138 * t5;
+			t178 = t2 * zc * del_rhoB * ZB;
+			t179 = 0.3e1 * t178;
+			t181 = 0.2e1 * t145 * t138;
+			t183 = 0.2e1 * t142 * t140;
+			t186 = 0.2e1 * t132 * kn * ZB;
+			t187 = 0.2e1 * t175;
+			t189 = 0.2e1 * t145 * t140;
+			t191 = 0.2e1 * t142 * t138;
+			t202 = exp(kn * (zc - 0.3e1));
+			t206 = t130 * del_rhoA - t79 * (-t133 + t134) * t97 - t139 - 0.2e1 * t140 + 0.2e1 * t132 * (-t143 + t144 + t146 + 0.2e1 - kn) * t1 * t150 - t1 * (t154 + t133) * t107 - 0.2e1 * t132 * (0.2e1 - t143 - t144 + t146 + kn) * t1 * t162 + 0.2e1 * t132 * (0.2e1 + kn) * t79 * t168 - t1 * (-t133 + t154) * t11 - t175 - 0.2e1 * (-t179 + t181 + t183 + t186 + t187 - t189 - t191 + t139) * t48 - t178 + 0.2e1 * (-t189 + t179 + t181 - t187 - t186 - t191 + t139 + t183) * t112 + 0.2e1 * t132 * (-0.2e1 + kn) * t79 * t202;
+			t207 = t59 * zc;
+			t211 = exp(-t144);
+			t218 = t59 * t1;
+			t223 = exp(-0.4e1 * kn);
+			t232 = exp(-0.2e1 * t161);
+			t246 = -0.8e1 * t207 * t116 * t97 - 0.2e1 * t14 * t99 * t211 + 0.8e1 * t207 * t116 * t11 + 0.8e1 * t218 * t87 * t48 + 0.2e1 * t14 * t80 * t223 + 0.16e2 * t14 * (-t69 + t67 - t43 - t40 + t68 + t22 - t66) * t112 - 0.8e1 * t218 * t87 * t232 - 0.2e1 * t14 * t99 * t107 + 0.2e1 * t13 * t19 * ZA + 0.2e1 * t14 * t23 + 0.4e1 * t20 * ZB;
+			_C2A = t206 / t246;
+			
+			t1 = -ZB + ZA;
+			t2 = 0.2e1 * ZB;
+			t4 = t1 * (-ZA - t2);
+			t5 = kn * zc;
+			t7 = exp(-0.3e1 * t5);
+			t10 = ZA + ZB;
+			t11 = zc - 0.1e1;
+			t12 = t10 * t11;
+			t13 = kn * t11;
+			t15 = exp(0.2e1 * t13);
+			t16 = t12 * t15;
+			t19 = kn * kn;
+			t20 = ZA * ZA;
+			t21 = t19 * t20;
+			t22 = zc * zc;
+			t24 = 0.2e1 * t21 * t22;
+			t26 = 0.2e1 * t21 * zc;
+			t27 = t19 * ZA;
+			t28 = zc * ZB;
+			t30 = 0.4e1 * t27 * t28;
+			t33 = 0.4e1 * t27 * t22 * ZB;
+			t34 = ZB * ZB;
+			t35 = t19 * t34;
+			t37 = 0.2e1 * t35 * t22;
+			t39 = 0.2e1 * t35 * zc;
+			t40 = kn * t20;
+			t42 = t40 * zc;
+			t44 = ZA * kn;
+			t46 = 0.6e1 * t44 * t28;
+			t48 = 0.6e1 * t44 * ZB;
+			t49 = kn * t34;
+			t51 = t49 * zc;
+			t53 = ZA * ZB;
+			t54 = t24 - t26 + t30 - t33 + t37 - t39 + 0.3e1 * t40 - 0.3e1 * t42 + t46 - t48 + 0.3e1 * t49 - 0.3e1 * t51 - t53;
+			t55 = 0.2e1 * kn;
+			t56 = exp(-t55);
+			t59 = t1 * t10;
+			t60 = 0.2e1 * t5;
+			t61 = t60 - 0.3e1;
+			t62 = exp(-t60);
+			t66 = t10 * (ZA - t2);
+			t67 = exp(-t5);
+			t70 = kn * (-0.2e1 + zc);
+			t72 = exp(0.2e1 * t70);
+			t78 = exp(kn * (0.3e1 * zc - 0.4e1));
+			t80 = 0.2e1 * t40;
+			t81 = 0.2e1 * t42;
+			t82 = 0.4e1 * t49;
+			t83 = 0.4e1 * t51;
+			t85 = exp(t70);
+			t90 = exp(kn * (zc - 0.4e1));
+			t95 = exp(-kn * (zc + 0.2e1));
+			t98 = t1 * t1;
+			t100 = exp(0.4e1 * t13);
+			t101 = t98 * t100;
+			t103 = -t4 * t7 + 0.4e1 * kn * t1 * t16 + 0.4e1 * t54 * t56 + t59 * t61 * t62 + t66 * t67 - t59 * t61 * t72 + t4 * t78 + 0.2e1 * (-t80 + t48 + t81 - t82 - t53 - t46 + t83) * t85 - t66 * t90 + 0.2e1 * (-t80 + t48 + t81 - t82 + t53 - t46 + t83) * t95 - t101 + t34 + t20 + 0.2e1 * t53;
+			t105 = ZA * del_rhoB;
+			t108 = 0.2e1 * zc;
+			t111 = exp(-kn * (t108 + 0.1e1));
+			t116 = exp(-0.3e1 * kn);
+			t120 = t1 * ZA;
+			t126 = 0.2e1 * del_rhoB * kn * t20;
+			t130 = 0.2e1 * t44 * zc * del_rhoB * ZB;
+			t133 = 0.2e1 * t105 * kn * ZB;
+			t134 = t20 * del_rhoB;
+			t136 = 0.2e1 * t134 * t5;
+			t137 = 0.2e1 * t134;
+			t138 = t105 * ZB;
+			t151 = exp(kn * (t108 - 0.3e1));
+			t160 = exp(-kn);
+			t164 = t103 * del_rhoA - 0.2e1 * t105 * t1 * (-0.3e1 - t55 + t60) * t111 + 0.2e1 * t105 * t10 * t116 + 0.3e1 * t120 * del_rhoB * t78 + 0.2e1 * (-t126 - t130 + t133 + t136 + t137 - t138) * t85 - t105 * t10 * t90 + 0.2e1 * (-t126 - t130 + t133 + t136 + t138 - t137) * t95 - 0.2e1 * t105 * t1 * (-t55 + 0.3e1 + t60) * t151 - 0.3e1 * t120 * del_rhoB * t7 + t105 * t10 * t67 - 0.2e1 * t105 * t10 * t160;
+			t165 = t27 * zc;
+			t169 = t27 * t1;
+			t173 = exp(-0.2e1 * kn * (zc + 0.1e1));
+			t178 = exp(-0.4e1 * t5);
+			t187 = t10 * t10;
+			t189 = exp(-0.4e1 * kn);
+			t206 = -0.8e1 * t165 * t59 * t72 - 0.8e1 * t169 * t12 * t173 - 0.2e1 * t44 * t98 * t178 + 0.8e1 * t165 * t59 * t62 + 0.8e1 * t169 * t16 + 0.2e1 * t44 * t187 * t189 + 0.16e2 * t44 * (-t39 + t30 - t26 - t53 + t37 + t24 - t33) * t56 - 0.2e1 * t44 * t101 + 0.4e1 * t40 * ZB + 0.2e1 * kn * t20 * ZA + 0.2e1 * t44 * t34;
+			_C3A = t164 / t206;
+			
+			t1 = ZB * ZB;
+			t2 = kn * t1;
+			t3 = t2 * zc;
+			t5 = ZA * ZA;
+			t6 = kn * t5;
+			t8 = kn * kn;
+			t9 = t8 * t1;
+			t11 = 0.2e1 * t9 * zc;
+			t12 = t8 * t5;
+			t13 = zc * zc;
+			t15 = 0.2e1 * t12 * t13;
+			t16 = ZA * ZB;
+			t18 = 0.2e1 * t12 * zc;
+			t19 = ZA * kn;
+			t21 = 0.6e1 * t19 * ZB;
+			t22 = t8 * ZA;
+			t25 = 0.4e1 * t22 * t13 * ZB;
+			t27 = 0.2e1 * t9 * t13;
+			t28 = zc * ZB;
+			t30 = 0.6e1 * t19 * t28;
+			t32 = t6 * zc;
+			t35 = 0.4e1 * t22 * t28;
+			t36 = 0.3e1 * t3 - 0.3e1 * t6 - t11 + t15 - t16 - t18 + t21 - t25 + t27 - t30 - 0.3e1 * t2 + 0.3e1 * t32 + t35;
+			t38 = kn * (-0.2e1 + zc);
+			t39 = exp(t38);
+			t42 = -ZB + ZA;
+			t43 = 0.2e1 * ZB;
+			t45 = t42 * (-ZA - t43);
+			t46 = kn * zc;
+			t47 = 0.2e1 * t46;
+			t48 = exp(-t47);
+			t50 = 0.2e1 * t6;
+			t51 = 0.2e1 * t32;
+			t52 = 0.4e1 * t2;
+			t53 = 0.4e1 * t3;
+			t55 = 0.2e1 * kn;
+			t56 = exp(-t55);
+			t59 = t42 * t42;
+			t61 = exp(-0.3e1 * t46);
+			t63 = ZA + ZB;
+			t67 = exp(0.2e1 * t38);
+			t69 = t42 * t63;
+			t70 = t47 + 0.3e1;
+			t71 = exp(-t46);
+			t74 = t63 * t63;
+			t77 = exp(kn * (zc - 0.4e1));
+			t82 = exp(kn * (0.3e1 * zc - 0.4e1));
+			t85 = zc - 0.1e1;
+			t86 = kn * t85;
+			t88 = exp(0.4e1 * t86);
+			t93 = exp(0.2e1 * t86);
+			t97 = t63 * t85;
+			t100 = exp(-kn * (zc + 0.2e1));
+			t104 = -0.4e1 * t36 * t39 - t45 * t48 + 0.2e1 * (-t50 + t21 + t51 - t52 + t16 - t30 + t53) * t56 + t59 * t61 - t63 * (ZA - t43) * t67 - t69 * t70 * t71 - t74 * t77 + t69 * t70 * t82 + t45 * t88 - t16 - 0.2e1 * t1 + t5 + 0.2e1 * (-t50 + t21 + t51 - t52 - t16 - t30 + t53) * t93 + 0.4e1 * kn * t42 * t97 * t100;
+			t106 = ZA * del_rhoB;
+			t110 = kn * (zc + 0.1e1);
+			t111 = exp(-t110);
+			t120 = exp(0.3e1 * t86);
+			t126 = exp(kn * (zc - 0.3e1));
+			t132 = 0.2e1 * del_rhoB * kn * t5;
+			t136 = 0.2e1 * t19 * zc * del_rhoB * ZB;
+			t139 = 0.2e1 * t106 * kn * ZB;
+			t140 = t5 * del_rhoB;
+			t142 = 0.2e1 * t140 * t46;
+			t143 = t106 * ZB;
+			t144 = 0.2e1 * t140;
+			t148 = exp(t86);
+			t152 = t42 * ZA;
+			t162 = t104 * del_rhoA - 0.2e1 * t106 * t42 * (-0.3e1 - t55 + t47) * t111 - t106 * t63 * t67 - 0.2e1 * t106 * t42 * (-t55 + 0.3e1 + t47) * t120 + 0.2e1 * t106 * t63 * t126 + 0.2e1 * (-t132 - t136 + t139 + t142 + t143 - t144) * t56 - 0.2e1 * t106 * t63 * t148 + t143 - 0.3e1 * t152 * del_rhoB * t48 + 0.2e1 * (-t132 - t136 + t139 + t142 + t144 - t143) * t93 + 0.3e1 * t152 * del_rhoB * t88 + t140;
+			t163 = t22 * zc;
+			t167 = t22 * t42;
+			t169 = exp(-0.2e1 * t110);
+			t174 = exp(-0.4e1 * t46);
+			t185 = exp(-0.4e1 * kn);
+			t203 = -0.8e1 * t163 * t69 * t67 - 0.8e1 * t167 * t97 * t169 - 0.2e1 * t19 * t59 * t174 + 0.8e1 * t163 * t69 * t48 + 0.8e1 * t167 * t97 * t93 + 0.2e1 * t19 * t74 * t185 + 0.16e2 * t19 * (-t11 + t35 - t18 - t16 + t27 + t15 - t25) * t56 - 0.2e1 * t19 * t59 * t88 + 0.4e1 * t6 * ZB + 0.2e1 * kn * t5 * ZA + 0.2e1 * t19 * t1;
+			_C4A = t162 / t203;
+		} else {
+			t1 = ZA * kn;
+			t2 = t1 * ZB;
+			t3 = zc * ZB;
+			t4 = t1 * t3;
+			t6 = kn * kn;
+			t7 = ZB * ZB;
+			t8 = t6 * t7;
+			t9 = zc * zc;
+			t10 = t8 * t9;
+			t12 = ZA * ZA;
+			t14 = kn * t12 * zc;
+			t15 = 0.2e1 * t14;
+			t16 = t8 * zc;
+			t17 = t6 * kn;
+			t18 = t17 * t9;
+			t21 = kn * t7;
+			t22 = t21 * zc;
+			t25 = t9 * zc;
+			t35 = t6 * ZA;
+			t36 = t9 * ZB;
+			t37 = t35 * t36;
+			t39 = t6 * t12;
+			t40 = t39 * zc;
+			t41 = t35 * t3;
+			t43 = t39 * t9;
+			t44 = 0.4e1 * t43;
+			t47 = ZA * ZB;
+			t48 = 0.2e1 * t47;
+			t51 = t2 - 0.4e1 * t4 - 0.4e1 * t10 + t15 + t16 - 0.2e1 * t18 * t12 + 0.2e1 * t22 + 0.2e1 * t17 * t7 * t25 - 0.4e1 * t17 * ZA * ZB * t25 + 0.2e1 * t17 * t12 * t25 + 0.8e1 * t37 + t40 - 0.2e1 * t41 - t44 - 0.2e1 * t18 * t7 + t48 + 0.4e1 * t18 * t47;
+			t53 = kn * (zc + 0.1e1);
+			t54 = exp(-t53);
+			t57 = 0.6e1 * t37;
+			t58 = 0.2e1 * t10;
+			t59 = 0.4e1 * t14;
+			t60 = 0.3e1 * t4;
+			t62 = kn * zc;
+			t63 = 0.2e1 * t62;
+			t64 = exp(-t63);
+			t67 = -ZB + ZA;
+			t69 = 0.2e1 * t1 * zc;
+			t70 = 0.4e1 * t1;
+			t71 = 0.2e1 * ZA;
+			t72 = t62 * ZB;
+			t73 = kn * ZB;
+			t74 = 0.2e1 * t73;
+			t77 = zc - 0.1e1;
+			t78 = kn * t77;
+			t80 = exp(0.2e1 * t78);
+			t82 = ZA + ZB;
+			t83 = t67 * t82;
+			t85 = 0.2e1 * t6 * zc;
+			t86 = 0.4e1 * t62;
+			t87 = t6 * t9;
+			t89 = 0.2e1 - t85 - t86 + 0.2e1 * t87 + kn;
+			t90 = exp(t78);
+			t93 = t82 * t82;
+			t94 = -0.2e1 + kn;
+			t98 = exp(-kn * (0.3e1 + zc));
+			t100 = t67 * t67;
+			t103 = exp(0.3e1 * t78);
+			t107 = exp(-t86);
+			t115 = exp(-0.2e1 * kn);
+			t122 = exp(-kn * (0.3e1 * zc + 0.1e1));
+			t128 = exp(-0.2e1 * t53);
+			t134 = exp(kn * (zc - 0.3e1));
+			t138 = -0.4e1 * t51 * t54 - 0.2e1 * (-t57 + t58 - t59 + t60 + t44 - t48) * t64 + t67 * (t69 - t70 + t71 + t72 - t74) * t80 - t83 * t89 * t90 - t93 * t94 * t98 + t100 * t94 * t103 + t67 * (-t71 + t69 + t72) * t107 + 0.2e1 * (0.12e2 * t41 - t48 - t57 - 0.4e1 * t16 + t59 - t60 + t58 + t44 + 0.2e1 * t2 - 0.8e1 * t40) * t115 - t15 - t4 + 0.2e1 * t12 + t22 + t48 + t83 * t89 * t122 - t82 * (-t70 + t71 + t69 + t74 - t72) * t128 + 0.4e1 * t62 * t67 * t82 * t94 * t134;
+			t141 = del_rhoA * kn * ZB;
+			t143 = del_rhoA * ZB;
+			t144 = 0.2e1 * t143;
+			t145 = t62 * t143;
+			t153 = kn * (-0.2e1 + zc);
+			t154 = exp(t153);
+			t159 = t6 * del_rhoA;
+			t162 = del_rhoA * ZA;
+			t165 = zc * del_rhoA;
+			t166 = t21 * t165;
+			t167 = 0.2e1 * t166;
+			t168 = t159 * ZA;
+			t170 = 0.2e1 * t36 * t168;
+			t171 = t7 * del_rhoA;
+			t172 = 0.2e1 * t171;
+			t178 = 0.2e1 * t87 * t171;
+			t180 = t1 * t165 * ZB;
+			t181 = 0.3e1 * t180;
+			t186 = pow(-0.1e1 + t62, 0.2e1);
+			t189 = exp(-0.3e1 * t62);
+			t196 = 0.3e1 * t145;
+			t200 = exp(-t62);
+			t210 = exp(-kn * (zc + 0.2e1));
+			t218 = t138 * del_rhoB - t82 * (0.2e1 * t141 - t144 - t145) * t128 + 0.4e1 * t143 * (0.1e1 - 0.3e1 * kn + t87 - t85 + t63) * t67 * t154 + 0.2e1 * (-0.4e1 * t7 * zc * t159 + 0.2e1 * t162 * t73 + t167 - t170 + t172 + 0.4e1 * t3 * t168 - 0.4e1 * t21 * del_rhoA + t178 - t181) * t115 - 0.4e1 * t143 * t186 * t67 * t189 - 0.2e1 * (t181 + t172 - t170 - t167 + t178) * t64 + t67 * (-t196 + t144) * t107 + 0.4e1 * t143 * t82 * t200 - 0.2e1 * t162 * ZB + 0.4e1 * t143 * (kn - 0.1e1) * t82 * t210 + t166 + t67 * (0.6e1 * t141 - t196 - t144) * t80 + t180 - t172;
+			t219 = t6 * ZB;
+			t221 = exp(0.4e1 * t78);
+			t225 = t17 * ZB;
+			t226 = t225 * zc;
+			t228 = exp(0.2e1 * t153);
+			t238 = t225 * t67;
+			t239 = t82 * t77;
+			t244 = exp(-0.4e1 * kn);
+			t267 = -0.2e1 * t219 * t100 * t221 - 0.8e1 * t226 * t83 * t228 - 0.2e1 * t219 * t100 * t107 + 0.8e1 * t226 * t83 * t64 + 0.8e1 * t238 * t239 * t80 + 0.2e1 * t219 * t93 * t244 - 0.8e1 * t238 * t239 * t128 + 0.16e2 * t219 * (-0.2e1 * t16 + 0.4e1 * t41 - 0.2e1 * t40 - t47 + t58 + 0.2e1 * t43 - 0.4e1 * t37) * t115 + 0.4e1 * t35 * t7 + 0.2e1 * t39 * ZB + 0.2e1 * t6 * t7 * ZB;
+			_C1B = t218 / t267;
+			
+			t1 = kn * kn;
+			t2 = ZA * ZA;
+			t3 = t1 * t2;
+			t4 = zc * zc;
+			t5 = t3 * t4;
+			t6 = 0.4e1 * t5;
+			t7 = t3 * zc;
+			t9 = t1 * ZA;
+			t10 = zc * ZB;
+			t11 = t9 * t10;
+			t13 = t4 * ZB;
+			t14 = t9 * t13;
+			t15 = 0.6e1 * t14;
+			t16 = ZB * ZB;
+			t17 = t1 * t16;
+			t18 = t17 * t4;
+			t19 = 0.2e1 * t18;
+			t20 = t17 * zc;
+			t22 = kn * t2;
+			t23 = t22 * zc;
+			t24 = 0.4e1 * t23;
+			t25 = ZA * kn;
+			t26 = t25 * ZB;
+			t27 = 0.2e1 * t26;
+			t28 = t25 * t10;
+			t29 = 0.3e1 * t28;
+			t30 = ZA * ZB;
+			t31 = 0.2e1 * t30;
+			t34 = kn * (zc + 0.1e1);
+			t35 = exp(-t34);
+			t38 = ZA + ZB;
+			t39 = 0.2e1 * ZA;
+			t41 = 0.2e1 * t25 * zc;
+			t42 = 0.4e1 * t25;
+			t43 = kn * ZB;
+			t44 = 0.2e1 * t43;
+			t45 = kn * zc;
+			t46 = t45 * ZB;
+			t49 = zc - 0.1e1;
+			t50 = kn * t49;
+			t51 = exp(t50);
+			t53 = -ZB + ZA;
+			t55 = 0.2e1 + kn;
+			t57 = 0.2e1 * t45;
+			t58 = exp(-t57);
+			t67 = exp(-kn * (0.3e1 * zc + 0.1e1));
+			t69 = t53 * t38;
+			t71 = 0.2e1 * t1 * zc;
+			t72 = 0.4e1 * t45;
+			t73 = t1 * t4;
+			t75 = -t71 + t72 + 0.2e1 * t73 + 0.2e1 - kn;
+			t77 = exp(-0.2e1 * t34);
+			t80 = t53 * t53;
+			t82 = exp(-t72);
+			t84 = t1 * kn;
+			t86 = t4 * zc;
+			t89 = t84 * t4;
+			t108 = kn * t16;
+			t111 = 0.2e1 * t84 * t2 * t86 - 0.2e1 * t89 * t2 + 0.4e1 * t89 * t30 - 0.4e1 * t84 * ZA * ZB * t86 + 0.2e1 * t84 * t16 * t86 - 0.2e1 * t89 * t16 - t7 + t6 + 0.2e1 * t11 - 0.8e1 * t14 - t20 + 0.4e1 * t18 + 0.2e1 * t23 + t26 - 0.4e1 * t28 + 0.2e1 * t108 * zc - t31;
+			t113 = exp(-0.2e1 * kn);
+			t117 = exp(0.2e1 * t50);
+			t124 = exp(-kn * (0.3e1 + zc));
+			t129 = exp(kn * (zc - 0.3e1));
+			t135 = exp(0.3e1 * t50);
+			t140 = 0.2e1 * (t6 - 0.8e1 * t7 + 0.12e2 * t11 - t15 + t19 - 0.4e1 * t20 - t24 - t27 + t29 - t31) * t35 + t38 * (-t39 + t41 - t42 + t44 - t46) * t51 + 0.4e1 * t45 * t53 * t38 * t55 * t58 - t53 * (-t39 - t42 + t41 - t44 + t46) * t67 - t69 * t75 * t77 - t80 * t55 * t82 + 0.4e1 * t111 * t113 + t69 * t75 * t117 + t38 * (t41 + t39 - t46) * t124 - 0.2e1 * (t6 + t19 - t15 - t29 + t24 - t31) * t129 - t53 * (t39 + t46 + t41) * t135 + t27 + 0.2e1 * t16 + t108 + t22 + 0.4e1 * t30 + 0.2e1 * t2;
+			t142 = del_rhoA * ZB;
+			t143 = 0.2e1 * t142;
+			t145 = del_rhoA * kn * ZB;
+			t147 = t45 * t142;
+			t148 = 0.3e1 * t147;
+			t152 = t16 * del_rhoA;
+			t154 = 0.2e1 * t73 * t152;
+			t155 = t1 * del_rhoA;
+			t156 = t155 * ZA;
+			t158 = 0.2e1 * t13 * t156;
+			t159 = zc * del_rhoA;
+			t161 = 0.2e1 * t108 * t159;
+			t164 = 0.3e1 * t25 * t159 * ZB;
+			t165 = 0.2e1 * t152;
+			t169 = 0.3e1 * kn;
+			t172 = 0.2e1 * zc;
+			t175 = exp(-kn * (t172 + 0.1e1));
+			t180 = pow(0.1e1 + t45, 0.2e1);
+			t184 = exp(kn * (t172 - 0.3e1));
+			t188 = exp(-t169);
+			t217 = exp(-kn);
+			t221 = t140 * del_rhoB - t53 * (t143 + 0.6e1 * t145 - t148) * t67 - 0.2e1 * (t154 - t158 + t161 - t164 + t165) * t129 + 0.4e1 * t142 * (t169 - t57 + t73 - t71 + 0.1e1) * t53 * t175 - 0.4e1 * t142 * t180 * t53 * t184 + 0.4e1 * t142 * t38 * t188 + t38 * (0.2e1 * t145 + t143 - t147) * t51 - t53 * (-t148 - t143) * t135 + 0.2e1 * (0.4e1 * t10 * t156 - t158 + t154 - 0.4e1 * t16 * zc * t155 - 0.2e1 * del_rhoA * ZA * t43 + t164 + 0.4e1 * t108 * del_rhoA - t161 + t165) * t35 + t38 * (-t147 - t143) * t124 - 0.4e1 * t142 * (kn + 0.1e1) * t38 * t217;
+			t222 = t1 * ZB;
+			t224 = exp(0.4e1 * t50);
+			t228 = t84 * ZB;
+			t229 = t228 * zc;
+			t233 = exp(0.2e1 * kn * (-0.2e1 + zc));
+			t243 = t228 * t53;
+			t244 = t38 * t49;
+			t248 = t38 * t38;
+			t250 = exp(-0.4e1 * kn);
+			t273 = -0.2e1 * t222 * t80 * t224 - 0.8e1 * t229 * t69 * t233 - 0.2e1 * t222 * t80 * t82 + 0.8e1 * t229 * t69 * t58 + 0.8e1 * t243 * t244 * t117 + 0.2e1 * t222 * t248 * t250 - 0.8e1 * t243 * t244 * t77 + 0.16e2 * t222 * (-0.2e1 * t20 + 0.4e1 * t11 - 0.2e1 * t7 - t30 + t19 + 0.2e1 * t5 - 0.4e1 * t14) * t113 + 0.4e1 * t9 * t16 + 0.2e1 * t3 * ZB + 0.2e1 * t1 * t16 * ZB;
+			_C2B = t221 / t273;
+			
+			t1 = kn * kn;
+			t2 = ZA * ZA;
+			t3 = t1 * t2;
+			t4 = zc * zc;
+			t6 = 0.2e1 * t3 * t4;
+			t8 = 0.2e1 * t3 * zc;
+			t9 = t1 * ZA;
+			t10 = zc * ZB;
+			t12 = 0.4e1 * t9 * t10;
+			t15 = 0.4e1 * t9 * t4 * ZB;
+			t16 = ZB * ZB;
+			t17 = t1 * t16;
+			t19 = 0.2e1 * t17 * t4;
+			t21 = 0.2e1 * t17 * zc;
+			t22 = kn * t16;
+			t23 = t22 * zc;
+			t25 = ZA * kn;
+			t27 = 0.6e1 * t25 * t10;
+			t28 = kn * t2;
+			t29 = t28 * zc;
+			t31 = ZA * ZB;
+			t34 = kn * (zc + 0.1e1);
+			t35 = exp(-t34);
+			t38 = -ZB + ZA;
+			t39 = 0.2e1 * ZA;
+			t41 = t38 * (t39 + ZB);
+			t42 = zc - 0.1e1;
+			t43 = kn * t42;
+			t45 = exp(0.2e1 * t43);
+			t47 = 0.4e1 * t29;
+			t48 = 0.2e1 * t23;
+			t50 = kn * zc;
+			t51 = 0.2e1 * t50;
+			t52 = exp(-t51);
+			t55 = ZA + ZB;
+			t59 = exp(-0.2e1 * t34);
+			t61 = t38 * t55;
+			t64 = exp(kn * (zc - 0.3e1));
+			t68 = 0.2e1 * kn;
+			t69 = -0.3e1 - t68 + t51;
+			t70 = exp(t43);
+			t76 = exp(-kn * (0.3e1 * zc + 0.1e1));
+			t79 = t38 * t38;
+			t81 = exp(0.3e1 * t43);
+			t84 = exp(-0.4e1 * t50);
+			t87 = exp(-t68);
+			t90 = t55 * t55;
+			t93 = exp(-kn * (0.3e1 + zc));
+			t96 = 0.4e1 * (t6 - t8 + t12 - t15 + t19 - t21 - 0.3e1 * t23 + t27 - 0.3e1 * t29 - t31) * t35 + t41 * t45 + 0.2e1 * (t47 - t27 + t48 + t31) * t52 - t55 * (t39 - ZB) * t59 - 0.4e1 * t50 * t61 * t64 + t61 * t69 * t70 - t61 * t69 * t76 - t79 * t81 - t41 * t84 + 0.2e1 * (t47 - t27 + t48 - t31) * t87 + t90 * t93 + 0.2e1 * t2 + t31 - t16;
+			t98 = del_rhoA * ZB;
+			t104 = kn * (-0.2e1 + zc);
+			t105 = exp(t104);
+			t109 = zc * del_rhoA;
+			t112 = 0.2e1 * t25 * t109 * ZB;
+			t114 = 0.2e1 * t22 * t109;
+			t115 = t16 * del_rhoA;
+			t116 = 0.2e1 * t115;
+			t118 = del_rhoA * ZA * ZB;
+			t125 = exp(-0.3e1 * t50);
+			t132 = t38 * del_rhoA;
+			t136 = exp(-t50);
+			t142 = exp(-kn * (zc + 0.2e1));
+			t149 = t96 * del_rhoB + t98 * t55 * t59 + 0.2e1 * t98 * t38 * (t51 + 0.3e1) * t105 + 0.2e1 * (-t112 + t114 + t116 - t118) * t87 + 0.2e1 * t98 * t38 * (t51 - 0.3e1) * t125 + 0.2e1 * (-t112 + t114 + t118 - t116) * t52 + 0.3e1 * t132 * ZB * t84 + 0.2e1 * t98 * t55 * t136 - 0.2e1 * t98 * t55 * t142 - t115 - 0.3e1 * t132 * ZB * t45 - t118;
+			t150 = t1 * ZB;
+			t151 = t150 * zc;
+			t153 = exp(0.2e1 * t104);
+			t157 = kn * ZB;
+			t159 = exp(0.4e1 * t43);
+			t169 = t150 * t38;
+			t170 = t55 * t42;
+			t175 = exp(-0.4e1 * kn);
+			t193 = -0.8e1 * t151 * t61 * t153 - 0.2e1 * t157 * t79 * t159 - 0.2e1 * t157 * t79 * t84 + 0.8e1 * t151 * t61 * t52 + 0.8e1 * t169 * t170 * t45 + 0.2e1 * t157 * t90 * t175 - 0.8e1 * t169 * t170 * t59 + 0.16e2 * t157 * (-t21 + t12 - t8 - t31 + t19 + t6 - t15) * t87 + 0.4e1 * t25 * t16 + 0.2e1 * kn * t16 * ZB + 0.2e1 * t28 * ZB;
+			_C3B = t149 / t193;
+			
+			t1 = -ZB + ZA;
+			t2 = t1 * t1;
+			t3 = kn * zc;
+			t5 = exp(-0.4e1 * t3);
+			t6 = t2 * t5;
+			t7 = ZA + ZB;
+			t8 = t1 * t7;
+			t9 = 0.2e1 * t3;
+			t10 = exp(-t9);
+			t11 = t8 * t10;
+			t14 = ZA * ZA;
+			t15 = kn * t14;
+			t16 = t15 * zc;
+			t17 = 0.4e1 * t16;
+			t18 = ZA * kn;
+			t19 = zc * ZB;
+			t21 = 0.6e1 * t18 * t19;
+			t22 = ZB * ZB;
+			t23 = kn * t22;
+			t24 = t23 * zc;
+			t25 = 0.2e1 * t24;
+			t26 = ZA * ZB;
+			t30 = exp(kn * (zc - 0.3e1));
+			t33 = 0.2e1 * kn;
+			t34 = -t33 + 0.3e1 + t9;
+			t36 = kn * (zc + 0.1e1);
+			t38 = exp(-0.2e1 * t36);
+			t42 = exp(-t36);
+			t45 = kn * kn;
+			t46 = t45 * ZA;
+			t48 = 0.4e1 * t46 * t19;
+			t49 = t45 * t22;
+			t50 = zc * zc;
+			t52 = 0.2e1 * t49 * t50;
+			t55 = 0.2e1 * t49 * zc;
+			t57 = t45 * t14;
+			t59 = 0.2e1 * t57 * t50;
+			t61 = 0.2e1 * t57 * zc;
+			t64 = 0.4e1 * t46 * t50 * ZB;
+			t66 = exp(-t33);
+			t69 = 0.2e1 * ZA;
+			t71 = t7 * (t69 - ZB);
+			t72 = zc - 0.1e1;
+			t73 = kn * t72;
+			t74 = exp(t73);
+			t78 = exp(-kn * (0.3e1 + zc));
+			t81 = t1 * (t69 + ZB);
+			t85 = exp(-kn * (0.3e1 * zc + 0.1e1));
+			t88 = exp(0.3e1 * t73);
+			t91 = exp(0.2e1 * t73);
+			t95 = t6 - 0.4e1 * t3 * t11 + 0.2e1 * (t17 - t21 + t25 - t26) * t30 + t8 * t34 * t38 + 0.2e1 * (t17 - t21 + t25 + t26) * t42 - 0.4e1 * (t48 + t52 + 0.3e1 * t24 - t55 + 0.3e1 * t16 - t21 + t59 - t61 - t26 - t64) * t66 + t71 * t74 - t71 * t78 - t81 * t85 + t81 * t88 - t8 * t34 * t91 - t22 - 0.2e1 * t26 - t14;
+			t97 = t1 * del_rhoA;
+			t101 = del_rhoA * ZB;
+			t102 = exp(-kn);
+			t107 = exp(-0.3e1 * kn);
+			t111 = zc * del_rhoA;
+			t114 = 0.2e1 * t18 * t111 * ZB;
+			t116 = 0.2e1 * t23 * t111;
+			t118 = 0.2e1 * t22 * del_rhoA;
+			t120 = del_rhoA * ZA * ZB;
+			t131 = 0.2e1 * zc;
+			t134 = exp(-kn * (t131 + 0.1e1));
+			t144 = exp(kn * (t131 - 0.3e1));
+			t151 = t95 * del_rhoB + 0.3e1 * t97 * ZB * t85 + 0.2e1 * t101 * t7 * t102 - 0.2e1 * t101 * t7 * t107 + 0.2e1 * (-t114 + t116 + t118 - t120) * t30 + t101 * t7 * t78 + 0.2e1 * (-t114 + t116 + t120 - t118) * t42 + 0.2e1 * t101 * t1 * (t9 - 0.3e1) * t134 - t101 * t7 * t74 + 0.2e1 * t101 * t1 * (t9 + 0.3e1) * t144 - 0.3e1 * t97 * ZB * t88;
+			t152 = t45 * ZB;
+			t153 = t152 * zc;
+			t157 = exp(0.2e1 * kn * (-0.2e1 + zc));
+			t161 = kn * ZB;
+			t163 = exp(0.4e1 * t73);
+			t171 = t152 * t1;
+			t172 = t7 * t72;
+			t176 = t7 * t7;
+			t178 = exp(-0.4e1 * kn);
+			t196 = -0.8e1 * t153 * t8 * t157 - 0.2e1 * t161 * t2 * t163 - 0.2e1 * t161 * t6 + 0.8e1 * t153 * t11 + 0.8e1 * t171 * t172 * t91 + 0.2e1 * t161 * t176 * t178 - 0.8e1 * t171 * t172 * t38 + 0.16e2 * t161 * (-t55 + t48 - t61 - t26 + t52 + t59 - t64) * t66 + 0.4e1 * t18 * t22 + 0.2e1 * kn * t22 * ZB + 0.2e1 * t15 * ZB;
+			_C4B = t151 / t196;
+			
+		}
+		
+		/*******************************************/
+		/*       calculate the velocities etc      */
+		/*******************************************/
+		
+		if (z < zc) { 
+			
+			t4 = exp(-kn * z);
+			t10 = exp(kn * (z - zc));
+			t14 = kn * kn;
+			u1 = u1a = (_C1A + z * _C3A) * t4 + (_C2A + z * _C4A) * t10 - del_rhoA / ZA / t14;
+			
+			t1 = kn * z;
+			t2 = exp(-t1);
+			t6 = exp(kn * (z - zc));
+			t10 = 0.1e1 / kn;
+			u2 = u2a = t2 * _C1A - t6 * _C2A + t2 * (-0.1e1 + t1) * _C3A * t10 - t6 * (0.1e1 + t1) * _C4A * t10;
+			
+			t1 = ZA * kn;
+			t3 = exp(-kn * z);
+			t8 = exp(kn * (z - zc));
+			u3 = u3a = -0.2e1 * t1 * t3 * _C1A + 0.2e1 * t1 * t8 * _C2A - 0.2e1 * t1 * t3 * z * _C3A + 0.2e1 * t1 * t8 * z * _C4A;
+			
+			t2 = kn * z;
+			t6 = exp(-t2);
+			t15 = exp(kn * (z - zc));
+			u4 = u4a = -0.2e1 * ZA * (-_C3A + kn * _C1A + t2 * _C3A) * t6 - 0.2e1 * ZA * (_C4A + kn * _C2A + t2 * _C4A) * t15 + 0.1e1 / kn * del_rhoA;
+			
+			Z = ZA;
+			
+		} else {
+			
+			t5 = exp(kn * (zc - z));
+			t11 = exp(kn * (z - 0.1e1));
+			t15 = kn * kn;
+			u1 = u1b = (_C1B + z * _C3B) * t5 + (_C2B + z * _C4B) * t11 - del_rhoB / ZB / t15;
+			
+			t3 = exp(kn * (zc - z));
+			t7 = exp(kn * (z - 0.1e1));
+			t9 = kn * z;
+			t12 = 0.1e1 / kn;
+			u2 = u2b = t3 * _C1B - t7 * _C2B + t3 * (-0.1e1 + t9) * _C3B * t12 - t7 * (0.1e1 + t9) * _C4B * t12;
+			
+			t1 = kn * ZB;
+			t4 = exp(kn * (zc - z));
+			t9 = exp(kn * (z - 0.1e1));
+			u3 = u3b = -0.2e1 * t1 * t4 * _C1B + 0.2e1 * t1 * t9 * _C2B - 0.2e1 * t1 * t4 * z * _C3B + 0.2e1 * t1 * t9 * z * _C4B;
+			
+			t2 = kn * z;
+			t8 = exp(kn * (zc - z));
+			t17 = exp(kn * (z - 0.1e1));
+			u4 = u4b = -0.2e1 * ZB * (-_C3B + kn * _C1B + t2 * _C3B) * t8 - 0.2e1 * ZB * (_C4B + kn * _C2B + t2 * _C4B) * t17 + 0.1e1 / kn * del_rhoB;
+			
+			
+			Z = ZB;
+		}
+		
+		
+		
+		pp = (double)-(u3 + 2.0*n*M_PI*Z*u2)*cos(n*M_PI*x); /* pressure */
+		
+		txx = (double)(u3 + 4*Z*n*M_PI*u2)*cos(n*M_PI*x); /* xx stress */
+		sum5 += pp;
+		sum6 += txx;
+		
+		u1 *= cos(n*M_PI*x); /* z velocity */
+		sum1 += u1;
+		u2 *= sin(n*M_PI*x); /* x velocity */
+		sum2 += u2;
+		u3 *= cos(n*M_PI*x); /* zz stress */
+		sum3 += u3;
+		u4 *= sin(n*M_PI*x); /* zx stress */
+		sum4 += u4;
+		
+		rho = del_rho* cos(n*M_PI*x); /* density */
+		sum7 += rho;
+	}/* n */
+	
+	/* include terms for n=0 now */
+	del_rho = sigma*dx;
+	rho = del_rho; /* density */
+	sum7 += rho;
+	u3 = del_rho*(z-zc); /* zz stress */
+	sum3 += u3;
+	
+	txx = u3; /* xx stress */
+	pp = -u3; /* pressure */
+	sum5 += pp;
+	sum6 += txx;
+	/* i.e. u3 for n=0 is arbitrarily set to zero at z=zc */
+	
+	
+	mag=sqrt(sum1*sum1+sum2*sum2);
+	//printf("%0.7g %0.7g %0.7g %0.7g %0.7g %0.7g\n",x,y,z,sum3,sum2,sum1);
+	//printf("%0.7g %0.7g %0.7g\n%0.7g %0.7g %0.7g\n\n\n",x,y,z,x+sum3,y+sum2,z+sum1);
+	/*printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7); */
+	
+	
+	/* Output */
+	if( vel != NULL ) {
+		vel[0] = sum2;
+		vel[1] = sum1;
+	}
+	if( presssure != NULL ) {
+		(*presssure) = sum5;
+	}
+	if( total_stress != NULL ) {
+		total_stress[0] = sum6;
+		total_stress[1] = sum3;
+		total_stress[2] = sum4;
+	}
+	if( strain_rate != NULL ) {
+		if( z<zc ) {
+			Z = ZA;
+		}
+		else {
+			Z = ZB;
+		}
+		strain_rate[0] = (sum6+sum5)/(2.0*Z);
+		strain_rate[1] = (sum3+sum5)/(2.0*Z);
+		strain_rate[2] = (sum4)/(2.0*Z);
+	}
+	/* Value checks, could be cleaned up if needed. Julian Giordani 9-Oct-2006*/
+        if( fabs( sum5 - ( -0.5*(sum6+sum3) ) ) > 1e-5 ) {
+                assert(0);
+        }
+	
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solE/Analytic_solE.c
--- a/SysTest/AnalyticPlugins/Velic_solE/Analytic_solE.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,166 +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:
-*+		Mirko Velic
-*+		Julian Giordani
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Patrick Sunter
-** $Id: solE.c 636 2006-09-08 03:07:06Z JulianGiordani $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include "Analytic_solE.h"
-
-const Type Velic_solE_Type = "Underworld_Velic_solE";
-
-void Velic_solE_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
-	Velic_solE* self = (Velic_solE*) analyticSolution;
-	
-	_Velic_solE( coord, self->sigma, self->etaA, self->etaB, self->zc, self->km, self->n,
-		       	NULL, pressure, NULL, NULL );
-}
-
-void Velic_solE_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
-	Velic_solE* self = (Velic_solE*) analyticSolution;
-	
-	_Velic_solE( coord, self->sigma, self->etaA, self->etaB, self->zc, self->km, self->n,
-		       	velocity, NULL, NULL, NULL );
-}
-
-void Velic_solE_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
-	Velic_solE* self = (Velic_solE*) analyticSolution;
-	
-	_Velic_solE( coord, self->sigma, self->etaA, self->etaB, self->zc, self->km, self->n,
-		       	NULL, NULL, stress, NULL );
-}
-
-
-void Velic_solE_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
-	Velic_solE* self = (Velic_solE*) analyticSolution;
-	
-	_Velic_solE( coord, self->sigma, self->etaA, self->etaB, self->zc, self->km, self->n,
-		       	NULL, NULL, NULL, strainRate );
-}
-
-void _Velic_solE_Init( Velic_solE* self, double sigma, double etaA, double etaB, double zc, double km, double n ) {
-// TODO	Bool                     correctInput = True;
-	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
-        self->_getAnalyticVelocity    = Velic_solE_VelocityFunction;
-	self->_getAnalyticPressure    = Velic_solE_PressureFunction;
-	self->_getAnalyticTotalStress = Velic_solE_StressFunction;
-	self->_getAnalyticStrainRate  = Velic_solE_StrainRateFunction;
-
-	self->sigma = sigma;
-	self->etaA = etaA;
-	self->etaB = etaB;
-	self->zc = zc;
-	self->km = km;
-	self->n = n;
-}
-
-void _Velic_solE_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
-	Velic_solE* self = (Velic_solE*) analyticSolution;
-	FeVariable*              velocityField;
-	FeVariable*              pressureField;
-	FeVariable*              stressField;
-	FeVariable*              strainRateField;
-	FeVariable*              recoveredStrainRateField;
-	FeVariable*              recoveredStressField;
-	double                   sigma, etaA, etaB, zc, km;
-        int                      n;
-
-	/* Construct Parent */
-	_AnalyticSolution_AssignFromXML( self, cf, data );
-
-	/* Create Analytic Fields */
-	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solE_VelocityFunction );
-
-	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solE_PressureFunction );
-
-	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False , data);
-	if ( stressField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solE_StressFunction );
-
-	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
-	if ( strainRateField   ) {
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solE_StrainRateFunction );
-	}
-
-	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
-	if ( recoveredStrainRateField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solE_StrainRateFunction );
-
-	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
-	if ( recoveredStressField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solE_StressFunction );
-	
-
-	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solE_sigma", 1.0  );
-	etaA = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solE_etaA", 100.0  );
-	etaB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solE_etaB", 1.0  );
-	zc = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solE_zc", 0.8  );
-	km = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solE_km", M_PI  );
-	n = Stg_ComponentFactory_GetRootDictInt( cf, "solE_n", 1 );
-
-	_Velic_solE_Init( self, sigma, etaA, etaB, zc, km, n );
-}
-
-void* _Velic_solE_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Velic_solE);
-	Type                                                      type = Velic_solE_Type;
-	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
-	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
-	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solE_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Velic_solE_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _AnalyticSolution_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 Underworld_Velic_solE_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Velic_solE_Type, (Name)"0", _Velic_solE_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solE/Analytic_solE.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solE/Analytic_solE.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,166 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Mirko Velic
+*+		Julian Giordani
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Patrick Sunter
+** $Id: solE.c 636 2006-09-08 03:07:06Z JulianGiordani $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include "Analytic_solE.h"
+
+const Type Velic_solE_Type = "Underworld_Velic_solE";
+
+void Velic_solE_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
+	Velic_solE* self = (Velic_solE*) analyticSolution;
+	
+	_Velic_solE( coord, self->sigma, self->etaA, self->etaB, self->zc, self->km, self->n,
+		       	NULL, pressure, NULL, NULL );
+}
+
+void Velic_solE_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
+	Velic_solE* self = (Velic_solE*) analyticSolution;
+	
+	_Velic_solE( coord, self->sigma, self->etaA, self->etaB, self->zc, self->km, self->n,
+		       	velocity, NULL, NULL, NULL );
+}
+
+void Velic_solE_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
+	Velic_solE* self = (Velic_solE*) analyticSolution;
+	
+	_Velic_solE( coord, self->sigma, self->etaA, self->etaB, self->zc, self->km, self->n,
+		       	NULL, NULL, stress, NULL );
+}
+
+
+void Velic_solE_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
+	Velic_solE* self = (Velic_solE*) analyticSolution;
+	
+	_Velic_solE( coord, self->sigma, self->etaA, self->etaB, self->zc, self->km, self->n,
+		       	NULL, NULL, NULL, strainRate );
+}
+
+void _Velic_solE_Init( Velic_solE* self, double sigma, double etaA, double etaB, double zc, double km, double n ) {
+// TODO	Bool                     correctInput = True;
+	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
+        self->_getAnalyticVelocity    = Velic_solE_VelocityFunction;
+	self->_getAnalyticPressure    = Velic_solE_PressureFunction;
+	self->_getAnalyticTotalStress = Velic_solE_StressFunction;
+	self->_getAnalyticStrainRate  = Velic_solE_StrainRateFunction;
+
+	self->sigma = sigma;
+	self->etaA = etaA;
+	self->etaB = etaB;
+	self->zc = zc;
+	self->km = km;
+	self->n = n;
+}
+
+void _Velic_solE_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
+	Velic_solE* self = (Velic_solE*) analyticSolution;
+	FeVariable*              velocityField;
+	FeVariable*              pressureField;
+	FeVariable*              stressField;
+	FeVariable*              strainRateField;
+	FeVariable*              recoveredStrainRateField;
+	FeVariable*              recoveredStressField;
+	double                   sigma, etaA, etaB, zc, km;
+        int                      n;
+
+	/* Construct Parent */
+	_AnalyticSolution_AssignFromXML( self, cf, data );
+
+	/* Create Analytic Fields */
+	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solE_VelocityFunction );
+
+	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solE_PressureFunction );
+
+	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False , data);
+	if ( stressField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solE_StressFunction );
+
+	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
+	if ( strainRateField   ) {
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solE_StrainRateFunction );
+	}
+
+	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
+	if ( recoveredStrainRateField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solE_StrainRateFunction );
+
+	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
+	if ( recoveredStressField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solE_StressFunction );
+	
+
+	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solE_sigma", 1.0  );
+	etaA = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solE_etaA", 100.0  );
+	etaB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solE_etaB", 1.0  );
+	zc = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solE_zc", 0.8  );
+	km = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solE_km", M_PI  );
+	n = Stg_ComponentFactory_GetRootDictInt( cf, "solE_n", 1 );
+
+	_Velic_solE_Init( self, sigma, etaA, etaB, zc, km, n );
+}
+
+void* _Velic_solE_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Velic_solE);
+	Type                                                      type = Velic_solE_Type;
+	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
+	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
+	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solE_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Velic_solE_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _AnalyticSolution_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 Underworld_Velic_solE_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Velic_solE_Type, (Name)"0", _Velic_solE_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solE/solE.c
--- a/SysTest/AnalyticPlugins/Velic_solE/solE.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,839 +0,0 @@
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-
-
-void _Velic_solE( 
-		double pos[],
-		double _sigma,
-		double _eta_A, double _eta_B, 
-		double _z_c, double _km, int _n,
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] );
-
-
-int main( int argc, char **argv )
-{
-	int i,j;
-	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
-	double x,z;
-	
-	for (i=0;i<101;i++){
-		for(j=0;j<101;j++){
-			x = i/100.0;
-			z = j/100.0;
-			
-			pos[0] = x;
-			pos[1] = z;
-			_Velic_solE(
-					pos,
-					1.0,
-					100.0, 1.0,
-					0.8, (double)M_PI, 1,
-					vel, &pressure, total_stress, strain_rate );
-//			printf("pressure is fucked !! \n");
-			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
-					pos[0],pos[1],
-					vel[0],vel[1], pressure, 
-					total_stress[0], total_stress[1], total_stress[2], 
-					strain_rate[0], strain_rate[1], strain_rate[2] );
-		}
-		printf("\n");
-	}
-	
-	return 0;
-}
-
-
-
-void _Velic_solE(
-		double pos[],
-		double _sigma,
-		double _eta_A, double _eta_B, 
-		double _z_c, double _km, int _n,
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] )
-{
-	double Z,ZA,ZB,u1,u2,u3,u4,pp,txx;
-	double u1a,u2a,u3a,u4a,u1b,u2b,u3b,u4b;
-	double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,x,z;
-	double sigma;
-	int n;
-	double kn,km;
-	double _C1A,_C2A,_C3A,_C4A,_C1B,_C2B,_C3B,_C4B;
-	double rho,zc;
-	
-	double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
-	double t11,t12,t13,t14,t15,t16,t17,t18,t19,t20;
-	double t21,t22,t23,t24,t25,t26,t27,t28,t29,t30;
-	double t31,t32,t33,t34,t35,t36,t37,t38,t39,t40;
-	double t41,t42,t43,t44,t45,t46,t47,t48,t49,t50;
-	double t51,t52,t53,t54,t55,t56,t57,t58,t59,t60;
-	double t61,t62,t63,t64,t65,t66,t67,t68,t69,t70;
-	double t71,t72,t73,t74,t76,t77,t78,t79,t80,t81;
-	double t82,t83,t84,t85,t86,t87,t88,t89,t90,t91;
-	double t92,t93,t94,t95,t96,t97,t98,t99,t100,t101;
-	double t102,t103,t104,t105,t106,t109,t111,t112,t113,t114;
-	double t115,t116,t117,t118,t119,t120,t121,t123,t124,t126;
-	double t127,t128,t130,t131,t132,t133,t134,t136,t137,t140;
-	double t141,t142,t143,t145,t146,t147,t148,t149,t151,t152;
-	double t155,t156,t157,t158,t160,t162,t163,t164,t165,t166;
-	double t167,t169,t170,t171,t172,t173,t174,t176,t178,t179;
-	double t180,t181,t184,t186,t187,t188,t189,t191,t192,t193;
-	double t195,t196,t197,t198,t199,t200,t201,t203,t204,t205;
-	double t237,t241,t245,t247,t250,t251,t252,t253,t256,t261;
-	double t262,t263,t265,t266,t268,t269,t271,t272,t275,t276;
-	double t279,t282,t286;
-	
-	
-	/*************************************************************************/
-	/*************************************************************************/
-	/*
-	
-	rho = -sigma*sin(km*z)*cos(kn*x)
-	
-	The viscosity of layer B is ZB:
-	The viscosity of layer A is ZA:
-	
-	*/
-	/*************************************************************************/
-	/*************************************************************************/
-	
-	/*************************************************************************/
-	/*************************************************************************/
-	sigma = _sigma; /* density parameter for layer B */
-	ZA = _eta_A;    /* viscosity for layer A */
-	ZB = _eta_B; /* viscosity for layer B */
-	zc = _z_c;  /* dividing line between region B and region A */
-	
-	n = _n;
-	kn = (double)n*M_PI;
-	km = _km;
-	/*************************************************************************/
-	/*************************************************************************/
-	
-	x = pos[0];
-	z = pos[1];
-	
-	sum1=0.0;
-	sum2=0.0;
-	sum3=0.0;
-	sum4=0.0;
-	sum5=0.0;
-	sum6=0.0;
-	sum7=0.0;
-	
-	
-	/*******************************************/
-	/*         calculate the constants         */
-	/*******************************************/
-	
-	if ( z < zc ) {
-		t3 = exp(-kn * (zc + 0.2e1));
-		t4 = kn * kn;
-		t5 = t4 * t4;
-		t6 = t3 * t5;
-		t7 = ZA * zc;
-		t8 = km * zc;
-		t9 = sin(t8);
-		t10 = t7 * t9;
-		t13 = sin(km);
-		t14 = kn * t13;
-		t15 = km * km;
-		t16 = ZA * t15;
-		t17 = 0.2e1 * zc;
-		t20 = exp(-kn * (t17 + 0.3e1));
-		t26 = exp(-kn * (0.4e1 * zc + 0.1e1));
-		t27 = t26 * ZA;
-		t28 = t27 * t4;
-		t29 = zc * zc;
-		t31 = t29 * t15 * t13;
-		t33 = t4 * kn;
-		t34 = t3 * t33;
-		t35 = t34 * ZA;
-		t36 = cos(t8);
-		t38 = t29 * t36 * km;
-		t43 = exp(-kn * (zc + 0.4e1));
-		t47 = t36 * km * zc;
-		t51 = kn * (t17 + 0.1e1);
-		t52 = exp(-t51);
-		t53 = t52 * ZA;
-		t54 = t53 * t4;
-		t56 = kn * t36;
-		t57 = ZA * km;
-		t58 = kn * zc;
-		t60 = exp(-0.3e1 * t58);
-		t65 = t7 * t13;
-		t70 = exp(-kn * (0.3e1 * zc + 0.2e1));
-		t71 = t70 * t33;
-		t74 = km * ZB * zc;
-		t77 = t71 * ZA;
-		t81 = exp(-0.3e1 * kn);
-		t83 = t81 * t4 * ZA;
-		t84 = t13 * t15;
-		t85 = t84 * zc;
-		t88 = t29 * ZA * t9;
-		t91 = ZA * t33;
-		t92 = zc * t13;
-		t96 = kn * ZA;
-		t97 = t96 * t13;
-		t98 = t15 * zc;
-		t105 = t4 * ZA * t36;
-		t111 = 0.4e1 * t6 * t10 - t14 * t16 * t20 - t28 * t31 + 0.4e1 * t35 * t38 - 0.2e1 * t43 * t4 * ZA * t47 + t54 * t31 + 0.2e1 * t56 * t57 * t60 + t20 * t5 * t65 + 0.4e1 * t71 * t36 * t74 - 0.4e1 * t77 * t47 - t83 * t85 - 0.4e1 * t6 * t88 + 0.2e1 * t91 * t92 * t81 + 0.2e1 * t97 * t98 * t52 - t14 * t16 * t26 + 0.2e1 * t105 * t8 * t3 - 0.4e1 * t35 * t47;
-		t112 = t33 * zc;
-		t113 = ZB * t9;
-		t117 = t4 * t36;
-		t118 = t57 * t70;
-		t121 = t81 * ZA;
-		t123 = t5 * t13 * t29;
-		t128 = t29 * ZB * t9;
-		t140 = t70 * t5;
-		t143 = t57 * t3;
-		t147 = ZA * t9;
-		t151 = t4 * t13;
-		t156 = t20 * t4 * ZA;
-		t162 = t20 * ZA;
-		t164 = 0.4e1 * t112 * t113 * t70 + 0.4e1 * t117 * t118 + t121 * t123 + 0.4e1 * t77 * t38 + 0.4e1 * t6 * t128 + 0.2e1 * t91 * t92 * t26 + 0.2e1 * t56 * t57 * t43 - 0.4e1 * t34 * ZB * t38 - 0.4e1 * t140 * t128 - 0.2e1 * t56 * t143 + t53 * t123 - 0.4e1 * t112 * t147 * t3 - t151 * t53 - t27 * t123 - t54 * t85 + t156 * t85 + 0.2e1 * t60 * t4 * ZA * t47 - t162 * t123;
-		t172 = t33 * t13;
-		t176 = t33 * t9;
-		t187 = ZB * zc;
-		t188 = t187 * t9;
-		t200 = 0.4e1 * t34 * t36 * t74 - 0.2e1 * t105 * t8 * t70 - t172 * t162 + t84 * t27 - t172 * t53 - 0.4e1 * t176 * ZB * t70 + 0.4e1 * t176 * ZA * t70 - 0.4e1 * t176 * ZB * t3 + t151 * t162 - 0.4e1 * t6 * t188 - t151 * t27 + t151 * t121 - t172 * t121 + t84 * t53 + 0.4e1 * t176 * ZA * t3 - t172 * t27 - t84 * t121;
-		t237 = -t84 * t162 - t81 * t5 * t65 + t83 * t31 - 0.4e1 * t117 * t143 - 0.4e1 * t140 * t10 - 0.4e1 * t112 * t147 * t70 + 0.4e1 * t112 * t113 * t3 + t28 * t85 - t52 * t5 * t65 - t14 * t16 * t52 + t26 * t5 * t65 + 0.2e1 * t97 * t98 * t20 - 0.2e1 * t56 * t118 + 0.4e1 * t140 * t188 - 0.4e1 * t71 * ZB * t38 + 0.4e1 * t140 * t88 - t14 * t16 * t81 - t156 * t31;
-		t245 = pow(t15 + t4, 0.2e1);
-		t251 = exp(-0.2e1 * kn * (zc + 0.1e1));
-		t252 = ZB * t251;
-		t265 = exp(-0.2e1 * kn);
-		t268 = exp(-0.2e1 * t51);
-		t271 = exp(-0.4e1 * t58);
-		t275 = exp(-0.4e1 * kn);
-		_C1A = -sigma * (t111 + t164 + t200 + t237) / ZA / kn / t245 / (-0.4e1 * t58 * t252 - 0.4e1 * t96 * t29 * t251 + 0.4e1 * kn * t29 * t252 + 0.4e1 * t96 * zc * t251 - t187 * t265 - ZB * t268 - t7 * t271 + ZB * t265 + t7 * t275 + t187 * t268) / 0.4e1;
-		
-		t1 = 0.2e1 * zc;
-		t4 = exp(-kn * (t1 + 0.3e1));
-		t5 = kn * kn;
-		t7 = t4 * t5 * ZA;
-		t8 = sin(km);
-		t9 = km * km;
-		t10 = t8 * t9;
-		t11 = t10 * zc;
-		t14 = kn * (t1 + 0.1e1);
-		t15 = exp(-t14);
-		t16 = t5 * t5;
-		t18 = ZA * zc;
-		t19 = t18 * t8;
-		t21 = kn * t8;
-		t22 = ZA * t9;
-		t28 = exp(-kn * (0.3e1 * zc + 0.2e1));
-		t29 = t5 * kn;
-		t30 = t28 * t29;
-		t31 = t30 * ZA;
-		t32 = km * zc;
-		t33 = cos(t32);
-		t35 = t33 * km * zc;
-		t39 = exp(-0.3e1 * kn);
-		t41 = t39 * t5 * ZA;
-		t43 = t5 * t8;
-		t47 = exp(-kn * (0.4e1 * zc + 0.1e1));
-		t48 = ZA * t47;
-		t50 = t29 * t8;
-		t51 = ZA * t4;
-		t54 = ZA * t15;
-		t56 = sin(t32);
-		t57 = t29 * t56;
-		t66 = exp(-kn * (zc + 0.2e1));
-		t73 = ZA * t39;
-		t76 = -t7 * t11 + t15 * t16 * t19 + t21 * t22 * t15 + 0.4e1 * t31 * t35 + t41 * t11 + t43 * t48 + t50 * t51 - t10 * t48 + t50 * t54 + 0.4e1 * t57 * ZB * t28 - 0.4e1 * t57 * ZA * t28 + 0.4e1 * t57 * ZB * t66 + t43 * t54 + t10 * t51 - t43 * t51 + t50 * t73 - t10 * t54;
-		t83 = zc * zc;
-		t84 = t16 * t8 * t83;
-		t86 = t66 * t29;
-		t87 = t86 * ZA;
-		t89 = t83 * t33 * km;
-		t92 = t66 * t16;
-		t94 = t83 * ZB * t56;
-		t97 = ZA * t29;
-		t98 = zc * t8;
-		t102 = kn * ZA;
-		t103 = t102 * t8;
-		t104 = t9 * zc;
-		t109 = t83 * t9 * t8;
-		t113 = exp(-kn * (zc + 0.4e1));
-		t121 = t83 * ZA * t56;
-		t127 = t54 * t5;
-		t132 = t5 * t33;
-		t133 = ZA * km;
-		t134 = t133 * t66;
-		t140 = -0.4e1 * t57 * ZA * t66 + t50 * t48 + t10 * t73 + t51 * t84 - 0.4e1 * t87 * t89 - 0.4e1 * t92 * t94 - 0.2e1 * t97 * t98 * t47 - 0.2e1 * t103 * t104 * t15 - t41 * t109 + 0.2e1 * t113 * t5 * ZA * t35 - t47 * t16 * t19 + 0.4e1 * t92 * t121 - 0.2e1 * t103 * t104 * t4 - t127 * t109 + 0.4e1 * t86 * ZB * t89 + 0.4e1 * t132 * t134 + t7 * t109 + t21 * t22 * t47;
-		t142 = kn * t33;
-		t143 = kn * zc;
-		t145 = exp(-0.3e1 * t143);
-		t149 = t18 * t56;
-		t156 = t29 * zc;
-		t157 = ZB * t56;
-		t162 = t28 * t16;
-		t163 = zc * ZB;
-		t164 = t163 * t56;
-		t171 = t5 * ZA * t33;
-		t178 = t133 * t28;
-		t181 = ZA * t56;
-		t192 = km * ZB * zc;
-		t197 = -0.2e1 * t142 * t133 * t145 - 0.4e1 * t92 * t149 - t4 * t16 * t19 + 0.2e1 * t142 * t134 - 0.4e1 * t156 * t157 * t28 + t48 * t84 - 0.4e1 * t162 * t164 - 0.4e1 * t156 * t157 * t66 - 0.2e1 * t171 * t32 * t66 + 0.4e1 * t162 * t94 + t127 * t11 + 0.2e1 * t142 * t178 + 0.4e1 * t156 * t181 * t66 + t21 * t22 * t39 - 0.2e1 * t97 * t98 * t39 - 0.4e1 * t86 * t33 * t192 - 0.4e1 * t132 * t178;
-		t205 = t48 * t5;
-		t237 = -t54 * t84 - 0.2e1 * t145 * t5 * ZA * t35 + 0.4e1 * t92 * t164 + t205 * t109 - 0.4e1 * t31 * t89 + t21 * t22 * t4 - t73 * t84 + 0.4e1 * t156 * t181 * t28 - 0.2e1 * t142 * t133 * t113 + 0.4e1 * t162 * t149 - t205 * t11 + 0.4e1 * t87 * t35 - 0.4e1 * t162 * t121 + 0.4e1 * t30 * ZB * t89 + 0.2e1 * t171 * t32 * t28 + t39 * t16 * t19 - 0.4e1 * t30 * t33 * t192 - t43 * t73;
-		t241 = exp(t143);
-		t247 = pow(t9 + t5, 0.2e1);
-		t252 = exp(-0.2e1 * kn * (zc + 0.1e1));
-		t253 = ZB * t252;
-		t266 = exp(-0.2e1 * kn);
-		t269 = exp(-0.2e1 * t14);
-		t272 = exp(-0.4e1 * t143);
-		t276 = exp(-0.4e1 * kn);
-		_C2A = -sigma * (t76 + t140 + t197 + t237) * t241 / ZA / kn / t247 / (-0.4e1 * t143 * t253 - 0.4e1 * t102 * t83 * t252 + 0.4e1 * kn * t83 * t253 + 0.4e1 * t102 * zc * t252 - t163 * t266 - ZB * t269 - t18 * t272 + ZB * t266 + t18 * t276 + t163 * t269) / 0.4e1;
-		
-		t1 = kn * kn;
-		t2 = t1 * kn;
-		t3 = ZA * t2;
-		t4 = sin(km);
-		t5 = zc * t4;
-		t7 = exp(-0.3e1 * kn);
-		t10 = kn * t4;
-		t11 = km * km;
-		t12 = ZA * t11;
-		t16 = exp(-kn * (0.4e1 * zc + 0.1e1));
-		t19 = t1 * t4;
-		t20 = 0.2e1 * zc;
-		t22 = kn * (t20 + 0.1e1);
-		t23 = exp(-t22);
-		t24 = ZA * t23;
-		t26 = km * zc;
-		t27 = sin(t26);
-		t28 = t2 * t27;
-		t31 = exp(-kn * (zc + 0.2e1));
-		t32 = ZB * t31;
-		t36 = cos(t26);
-		t37 = t1 * ZA * t36;
-		t44 = exp(-kn * (0.3e1 * zc + 0.2e1));
-		t48 = t1 * t36;
-		t49 = ZA * km;
-		t50 = t49 * t44;
-		t56 = t7 * ZA;
-		t58 = t4 * t11;
-		t59 = t58 * zc;
-		t61 = ZB * t44;
-		t66 = exp(-kn * (t20 + 0.3e1));
-		t67 = ZA * t66;
-		t69 = -t3 * t5 * t7 + t10 * t12 * t16 + t19 * t24 + 0.4e1 * t28 * t32 - 0.4e1 * t37 * t26 * t31 - 0.4e1 * t28 * ZA * t44 - 0.4e1 * t50 * t48 + 0.4e1 * t37 * t26 * t44 - t56 * kn * t59 + 0.4e1 * t28 * t61 - t19 * t67;
-		t70 = ZA * t16;
-		t72 = t2 * t4;
-		t87 = km * ZB * zc;
-		t90 = t19 * t70 + t72 * t67 - t58 * t70 + t72 * t24 + t72 * t56 - t58 * t24 - 0.4e1 * t28 * ZA * t31 + t72 * t70 + t58 * t56 + t58 * t67 - 0.4e1 * t44 * t1 * t36 * t87;
-		t93 = t49 * t31;
-		t96 = t48 * km;
-		t101 = t2 * zc;
-		t102 = ZA * t27;
-		t106 = kn * t36;
-		t109 = exp(-kn * (zc + 0.4e1));
-		t113 = ZB * t27;
-		t119 = kn * ZA;
-		t120 = t119 * t4;
-		t121 = t11 * zc;
-		t126 = kn * zc;
-		t128 = exp(-0.3e1 * t126);
-		t132 = -t19 * t56 + 0.4e1 * t48 * t93 - 0.4e1 * t32 * t96 - t3 * t5 * t16 + 0.4e1 * t101 * t102 * t44 - 0.2e1 * t106 * t49 * t109 - 0.4e1 * t101 * t113 * t31 + t10 * t12 * t23 - t120 * t121 * t66 + 0.2e1 * t106 * t50 - 0.2e1 * t106 * t49 * t128;
-		t149 = t101 * t4;
-		t158 = -0.4e1 * t101 * t113 * t44 - t70 * kn * t59 + 0.4e1 * t101 * t102 * t31 - t120 * t121 * t23 + t10 * t12 * t7 + 0.4e1 * t61 * t96 + 0.2e1 * t106 * t93 - t24 * t149 - t67 * t149 + t10 * t12 * t66 + 0.4e1 * t31 * t1 * t36 * t87;
-		t164 = pow(t11 + t1, 0.2e1);
-		t170 = exp(-0.2e1 * kn * (zc + 0.1e1));
-		t171 = ZB * t170;
-		t174 = zc * zc;
-		t184 = zc * ZB;
-		t186 = exp(-0.2e1 * kn);
-		t189 = exp(-0.2e1 * t22);
-		t191 = ZA * zc;
-		t193 = exp(-0.4e1 * t126);
-		t197 = exp(-0.4e1 * kn);
-		_C3A = -sigma * (t69 + t90 + t132 + t158) / ZA / t164 / (0.4e1 * t126 * t171 + 0.4e1 * t119 * t174 * t170 - 0.4e1 * kn * t174 * t171 - 0.4e1 * t119 * zc * t170 + t184 * t186 + ZB * t189 + t191 * t193 - ZB * t186 - t191 * t197 - t184 * t189) / 0.4e1;
-		
-		t1 = 0.2e1 * zc;
-		t4 = exp(-kn * (t1 + 0.3e1));
-		t5 = t4 * ZA;
-		t6 = kn * kn;
-		t7 = t6 * kn;
-		t8 = t7 * zc;
-		t9 = sin(km);
-		t10 = t8 * t9;
-		t12 = kn * t9;
-		t13 = km * km;
-		t14 = ZA * t13;
-		t17 = km * zc;
-		t18 = sin(t17);
-		t19 = ZA * t18;
-		t22 = exp(-kn * (zc + 0.2e1));
-		t27 = exp(-0.3e1 * kn);
-		t31 = cos(t17);
-		t32 = t6 * ZA * t31;
-		t36 = exp(-kn * (0.3e1 * zc + 0.2e1));
-		t40 = t6 * t9;
-		t42 = kn * (t1 + 0.1e1);
-		t43 = exp(-t42);
-		t44 = ZA * t43;
-		t46 = t7 * t18;
-		t47 = ZB * t36;
-		t53 = ZB * t22;
-		t56 = t7 * t9;
-		t59 = t5 * t10 - t12 * t14 * t4 - 0.4e1 * t8 * t19 * t22 - t12 * t14 * t27 - 0.4e1 * t32 * t17 * t36 - t40 * t44 - 0.4e1 * t46 * t47 + 0.4e1 * t46 * ZA * t36 - 0.4e1 * t46 * t53 - t56 * t44 - t56 * t5;
-		t60 = t13 * t9;
-		t64 = exp(-kn * (0.4e1 * zc + 0.1e1));
-		t65 = ZA * t64;
-		t70 = km * ZB * zc;
-		t73 = t7 * ZA;
-		t74 = zc * t9;
-		t77 = kn * ZA;
-		t78 = t77 * t9;
-		t79 = t13 * zc;
-		t82 = t6 * t31;
-		t83 = ZA * km;
-		t84 = t83 * t22;
-		t94 = ZA * t27;
-		t97 = t60 * t65 - 0.4e1 * t22 * t6 * t31 * t70 + t73 * t74 * t27 + t78 * t79 * t43 - 0.4e1 * t82 * t84 - t12 * t14 * t64 - t40 * t65 + 0.4e1 * t46 * ZA * t22 - t56 * t65 - t60 * t94 - t60 * t5;
-		t106 = t83 * t36;
-		t113 = t60 * zc;
-		t115 = kn * t31;
-		t118 = ZB * t18;
-		t126 = t40 * t5 + t40 * t94 - t56 * t94 + t60 * t44 + 0.4e1 * t32 * t17 * t22 + 0.4e1 * t82 * t106 - 0.4e1 * t8 * t19 * t36 + t94 * kn * t113 - 0.2e1 * t115 * t106 + 0.4e1 * t8 * t118 * t22 + 0.4e1 * t36 * t6 * t31 * t70;
-		t127 = t82 * km;
-		t136 = exp(-kn * (zc + 0.4e1));
-		t147 = kn * zc;
-		t149 = exp(-0.3e1 * t147);
-		t158 = 0.4e1 * t53 * t127 + t73 * t74 * t64 - t12 * t14 * t43 + 0.2e1 * t115 * t83 * t136 - 0.4e1 * t47 * t127 - 0.2e1 * t115 * t84 + t44 * t10 + t78 * t79 * t4 + 0.2e1 * t115 * t83 * t149 + 0.4e1 * t8 * t118 * t36 + t65 * kn * t113;
-		t162 = exp(t147);
-		t166 = pow(t13 + t6, 0.2e1);
-		t172 = exp(-0.2e1 * kn * (zc + 0.1e1));
-		t173 = ZB * t172;
-		t176 = zc * zc;
-		t186 = zc * ZB;
-		t188 = exp(-0.2e1 * kn);
-		t191 = exp(-0.2e1 * t42);
-		t193 = ZA * zc;
-		t195 = exp(-0.4e1 * t147);
-		t199 = exp(-0.4e1 * kn);
-		_C4A = -sigma * (t59 + t97 + t126 + t158) * t162 / ZA / t166 / (-0.4e1 * t147 * t173 - 0.4e1 * t77 * t176 * t172 + 0.4e1 * kn * t176 * t173 + 0.4e1 * t77 * zc * t172 - t186 * t188 - ZB * t191 - t193 * t195 + ZB * t188 + t193 * t199 + t186 * t191) / 0.4e1;
-		
-		
-		
-	} else { 
-		t3 = kn * (0.2e1 * zc + 0.1e1);
-		t4 = exp(-t3);
-		t5 = t4 * ZB;
-		t6 = kn * kn;
-		t8 = sin(km);
-		t9 = km * km;
-		t10 = t8 * t9;
-		t11 = t10 * zc;
-		t14 = exp(-kn);
-		t15 = t14 * ZB;
-		t16 = t15 * t6;
-		t18 = zc * zc;
-		t20 = t18 * t9 * t8;
-		t23 = t10 * ZB;
-		t27 = exp(-kn * (zc + 0.2e1));
-		t29 = km * zc;
-		t30 = cos(t29);
-		t31 = t30 * km;
-		t32 = t31 * ZB;
-		t35 = kn * zc;
-		t37 = exp(-0.3e1 * t35);
-		t38 = t6 * kn;
-		t39 = t37 * t38;
-		t40 = ZA * zc;
-		t41 = sin(t29);
-		t42 = t40 * t41;
-		t45 = t4 * ZA;
-		t46 = t6 * t6;
-		t48 = t46 * t8 * t18;
-		t51 = t38 * zc;
-		t59 = km * ZB * zc;
-		t62 = zc * ZB;
-		t63 = t62 * t41;
-		t72 = exp(-kn * (0.4e1 * zc + 0.1e1));
-		t73 = t72 * t38;
-		t74 = t62 * t8;
-		t78 = t40 * t8;
-		t82 = t9 * ZB;
-		t84 = t6 * t8;
-		t88 = -0.4e1 * t5 * t6 * t11 - t16 * t11 + t16 * t20 + t14 * kn * t23 + 0.2e1 * t27 * kn * t32 - 0.4e1 * t39 * t42 - 0.8e1 * t45 * t48 + 0.4e1 * t51 * ZB * t41 * t27 + 0.2e1 * t37 * t6 * t30 * t59 + 0.4e1 * t39 * t63 + 0.4e1 * t45 * t51 * t8 + 0.2e1 * t73 * t74 + 0.2e1 * t4 * t46 * t78 - t14 * t8 * t82 + t15 * t84 + t72 * t8 * t82;
-		t89 = ZB * t8;
-		t91 = t4 * t38;
-		t92 = t91 * ZB;
-		t93 = t18 * zc;
-		t95 = t93 * t9 * t8;
-		t98 = t14 * t38;
-		t100 = t72 * ZB;
-		t102 = t91 * ZA;
-		t106 = t4 * t46 * kn;
-		t112 = t46 * zc * t8;
-		t127 = t27 * t38;
-		t130 = t18 * t30 * km;
-		t141 = -t73 * t89 - 0.4e1 * t92 * t95 + t98 * t89 - t100 * t84 - 0.4e1 * t102 * t20 - 0.4e1 * t106 * ZA * t8 * t18 - 0.4e1 * t5 * t112 - t15 * t112 + 0.4e1 * t4 * kn * zc * t23 + t15 * t48 - t72 * kn * t23 - 0.4e1 * t51 * ZA * t41 * t27 - 0.4e1 * t127 * ZB * t130 + 0.4e1 * t106 * t89 * t18 - 0.4e1 * t91 * t74 + 0.2e1 * t37 * kn * t32;
-		t147 = exp(-t35);
-		t152 = exp(-0.3e1 * kn);
-		t169 = t100 * t6;
-		t172 = t37 * t46;
-		t174 = t18 * ZA * t41;
-		t180 = exp(-kn * (0.3e1 * zc + 0.2e1));
-		t188 = t6 * t30 * km;
-		t191 = t27 * t46;
-		t193 = t18 * ZB * t41;
-		t198 = t127 * ZA;
-		t204 = -0.2e1 * t27 * t6 * t30 * t59 - 0.2e1 * t147 * kn * t32 - 0.2e1 * t152 * t6 * ZA * t11 - 0.4e1 * t39 * ZB * t130 - 0.4e1 * t106 * ZB * t93 * t8 + 0.4e1 * ZA * t38 * zc * t8 * t152 + t169 * t11 - t100 * t48 + 0.4e1 * t172 * t174 - 0.2e1 * t180 * t6 * t30 * t59 + t100 * t112 - 0.4e1 * t27 * ZB * t188 + 0.4e1 * t191 * t193 - 0.2e1 * t98 * t74 + 0.4e1 * t198 * t130 + 0.4e1 * t180 * ZB * t188;
-		t247 = -0.8e1 * t191 * t63 - 0.4e1 * t191 * t174 - 0.8e1 * t198 * t31 * zc - t169 * t20 - 0.4e1 * t172 * t193 + 0.2e1 * t4 * t6 * ZA * t11 + 0.4e1 * t102 * t95 + 0.8e1 * t127 * t30 * t59 - 0.2e1 * t152 * t46 * t78 + 0.4e1 * t106 * ZA * t93 * t8 + 0.8e1 * t5 * t48 + 0.4e1 * t92 * t20 + 0.8e1 * t191 * t42 + 0.2e1 * t147 * t6 * t30 * t59 - 0.2e1 * t180 * kn * t32 + 0.4e1 * t39 * ZA * t130;
-		t256 = pow(t9 + t6, 0.2e1);
-		t261 = exp(-0.2e1 * kn * (zc + 0.1e1));
-		t262 = ZB * t261;
-		t265 = kn * ZA;
-		t276 = exp(-0.2e1 * kn);
-		t279 = exp(-0.2e1 * t3);
-		t282 = exp(-0.4e1 * t35);
-		t286 = exp(-0.4e1 * kn);
-		_C1B = sigma * (t88 + t141 + t204 + t247) * t147 / ZB / kn / t256 / (0.4e1 * t35 * t262 + 0.4e1 * t265 * t18 * t261 - 0.4e1 * kn * t18 * t262 - 0.4e1 * t265 * zc * t261 + t62 * t276 + ZB * t279 + t40 * t282 - ZB * t276 - t40 * t286 - t62 * t279) / 0.4e1;
-		
-		t2 = exp(-0.2e1 * kn);
-		t3 = t2 * ZB;
-		t4 = kn * kn;
-		t5 = t3 * t4;
-		t6 = zc * zc;
-		t7 = km * km;
-		t9 = sin(km);
-		t10 = t6 * t7 * t9;
-		t13 = kn * (zc + 0.1e1);
-		t15 = exp(-0.2e1 * t13);
-		t16 = t4 * t4;
-		t18 = t15 * t16 * kn;
-		t19 = t9 * ZB;
-		t27 = exp(-0.2e1 * kn * (0.2e1 * zc + 0.1e1));
-		t28 = ZB * t27;
-		t30 = t16 * zc * t9;
-		t32 = t9 * t7;
-		t33 = t32 * zc;
-		t38 = exp(-kn * (0.3e1 * zc + 0.1e1));
-		t39 = t4 * kn;
-		t40 = t38 * t39;
-		t41 = t40 * ZA;
-		t42 = km * zc;
-		t43 = cos(t42);
-		t44 = t43 * km;
-		t45 = t44 * zc;
-		t49 = exp(-0.3e1 * t13);
-		t53 = km * ZB * zc;
-		t57 = t44 * ZB;
-		t60 = exp(-t13);
-		t64 = t15 * ZB;
-		t68 = t6 * zc;
-		t74 = t7 * ZB;
-		t78 = t4 * t9;
-		t84 = t2 * t39;
-		t86 = t27 * t39;
-		t88 = t5 * t10 + 0.4e1 * t18 * t19 * t6 + t28 * t30 - t5 * t33 - 0.8e1 * t41 * t45 - 0.2e1 * t49 * t4 * t43 * t53 + 0.2e1 * t38 * kn * t57 - 0.2e1 * t60 * kn * t57 + 0.4e1 * t64 * t4 * t33 - 0.4e1 * t18 * ZB * t68 * t9 - t2 * t9 * t74 + t27 * t9 * t74 + t3 * t78 + 0.4e1 * t18 * ZA * t68 * t9 - t84 * t19 + t86 * t19;
-		t90 = t40 * ZB;
-		t93 = t38 * t16;
-		t95 = sin(t42);
-		t96 = ZB * t6 * t95;
-		t99 = zc * ZB;
-		t100 = t99 * t95;
-		t105 = exp(-kn * (zc + 0.3e1));
-		t111 = t16 * t9 * t6;
-		t113 = t15 * t39;
-		t114 = t113 * ZB;
-		t116 = t68 * t7 * t9;
-		t120 = t6 * t43 * km;
-		t124 = ZA * t6 * t95;
-		t127 = t105 * t39;
-		t131 = t28 * t4;
-		t134 = t99 * t9;
-		t140 = ZA * zc;
-		t141 = t140 * t95;
-		t146 = t32 * ZB;
-		t149 = -t28 * t78 + 0.8e1 * t90 * t45 - 0.4e1 * t93 * t96 + 0.8e1 * t93 * t100 - 0.2e1 * t105 * t4 * t43 * t53 + t3 * t111 - 0.4e1 * t114 * t116 + 0.4e1 * t41 * t120 + 0.4e1 * t93 * t124 - 0.4e1 * t127 * ZB * t120 + t131 * t33 - t28 * t111 + 0.2e1 * t84 * t134 + 0.2e1 * t105 * kn * t57 - 0.4e1 * t40 * t141 + 0.4e1 * t15 * kn * zc * t146;
-		t151 = t113 * ZA;
-		t156 = t4 * t43 * km;
-		t165 = t15 * ZA;
-		t169 = t105 * t16;
-		t188 = t39 * zc * t9;
-		t197 = 0.4e1 * t151 * t116 + 0.4e1 * t38 * ZB * t156 - 0.2e1 * t86 * t134 - 0.4e1 * t151 * t10 - t2 * kn * t146 - 0.2e1 * t165 * t4 * t33 - 0.4e1 * t169 * t124 - t3 * t30 - 0.4e1 * t113 * t134 + 0.4e1 * t127 * ZA * t120 + 0.2e1 * t38 * t4 * t43 * t53 + 0.4e1 * t169 * t96 - 0.4e1 * t60 * ZB * t156 + 0.4e1 * t165 * t188 + 0.2e1 * t60 * t4 * t43 * t53 - 0.8e1 * t93 * t141;
-		t198 = kn * zc;
-		t200 = exp(-0.4e1 * t198);
-		t201 = t200 * ZA;
-		t237 = 0.2e1 * t201 * t30 + 0.4e1 * t114 * t10 - 0.4e1 * t127 * t141 + 0.4e1 * t64 * t30 + 0.4e1 * t127 * t100 - 0.2e1 * t49 * kn * t57 + 0.4e1 * t40 * t100 + t27 * kn * t146 - t131 * t10 - 0.2e1 * t165 * t30 - 0.4e1 * t90 * t120 + 0.8e1 * t165 * t111 - 0.4e1 * t18 * ZA * t9 * t6 - 0.8e1 * t64 * t111 + 0.4e1 * t201 * t188 + 0.2e1 * t201 * t4 * t33;
-		t245 = pow(t7 + t4, 0.2e1);
-		t250 = kn * ZA;
-		t263 = exp(-0.4e1 * kn);
-		_C2B = -sigma * (t88 + t149 + t197 + t237) / kn / ZB / t245 / (0.4e1 * t198 * t64 + 0.4e1 * t250 * t6 * t15 - 0.4e1 * kn * t6 * t64 - 0.4e1 * t250 * zc * t15 + t99 * t2 + t28 + t140 * t200 - t3 - t140 * t263 - t99 * t27) / 0.4e1;
-		
-		t4 = exp(-kn * (0.4e1 * zc + 0.1e1));
-		t5 = t4 * ZB;
-		t7 = sin(km);
-		t8 = km * km;
-		t9 = t7 * t8;
-		t10 = t9 * zc;
-		t12 = exp(-kn);
-		t14 = t9 * ZB;
-		t18 = kn * (0.2e1 * zc + 0.1e1);
-		t19 = exp(-t18);
-		t20 = kn * kn;
-		t21 = t20 * kn;
-		t23 = zc * ZB;
-		t24 = t23 * t7;
-		t27 = kn * zc;
-		t29 = exp(-0.3e1 * t27);
-		t31 = km * zc;
-		t32 = cos(t31);
-		t33 = t32 * km;
-		t34 = t33 * ZB;
-		t41 = exp(-kn * (zc + 0.2e1));
-		t45 = t29 * t21;
-		t46 = sin(t31);
-		t50 = t19 * ZA;
-		t51 = t21 * zc;
-		t56 = exp(-0.3e1 * kn);
-		t61 = kn * ZA;
-		t67 = t19 * ZB;
-		t68 = t20 * t20;
-		t70 = zc * zc;
-		t71 = t68 * t7 * t70;
-		t77 = km * ZB * zc;
-		t80 = t19 * t20;
-		t81 = t80 * ZB;
-		t83 = t70 * t8 * t7;
-		t86 = t4 * t21;
-		t88 = t80 * ZA;
-		t91 = t20 * t7;
-		t93 = t12 * ZB;
-		t96 = t8 * ZB;
-		t100 = t7 * ZB;
-		t102 = -t5 * kn * t10 - t12 * kn * t14 + 0.4e1 * t19 * t21 * t24 - 0.2e1 * t29 * kn * t34 - 0.4e1 * t20 * ZA * t32 * t31 * t41 - 0.4e1 * t45 * t23 * t46 - 0.6e1 * t50 * t51 * t7 - 0.2e1 * t56 * ZA * kn * t10 + 0.2e1 * t61 * t7 * t8 * zc * t19 - 0.4e1 * t67 * t71 + 0.4e1 * t41 * t20 * t32 * t77 - 0.4e1 * t81 * t83 - t86 * t24 - 0.4e1 * t88 * t10 + t5 * t91 - t93 * t91 + t12 * t7 * t96 - t4 * t7 * t96 + t86 * t100;
-		t103 = t12 * t21;
-		t105 = t29 * t20;
-		t120 = ZA * zc;
-		t158 = exp(-kn * (0.3e1 * zc + 0.2e1));
-		t162 = exp(-t27);
-		t167 = -t103 * t100 + 0.4e1 * t105 * ZA * t33 * zc + t93 * kn * t10 - 0.2e1 * t41 * kn * t34 - 0.4e1 * t51 * ZB * t46 * t41 - 0.4e1 * t19 * t68 * t120 * t7 + 0.4e1 * t67 * t68 * zc * t7 + t4 * kn * t14 + 0.4e1 * t88 * t83 + 0.4e1 * t50 * t71 + 0.4e1 * t45 * t120 * t46 - 0.2e1 * ZA * t21 * zc * t7 * t56 - 0.4e1 * t19 * kn * zc * t14 + 0.4e1 * t81 * t10 + 0.4e1 * t51 * ZA * t46 * t41 - 0.4e1 * t105 * t32 * t77 + 0.2e1 * t158 * kn * t34 + 0.2e1 * t162 * kn * t34 + t103 * t24;
-		t173 = pow(t8 + t20, 0.2e1);
-		t179 = exp(-0.2e1 * kn * (zc + 0.1e1));
-		t180 = ZB * t179;
-		t193 = exp(-0.2e1 * kn);
-		t196 = exp(-0.2e1 * t18);
-		t199 = exp(-0.4e1 * t27);
-		t203 = exp(-0.4e1 * kn);
-		_C3B = -sigma * (t102 + t167) * t162 / ZB / t173 / (0.4e1 * t27 * t180 + 0.4e1 * t61 * t70 * t179 - 0.4e1 * kn * t70 * t180 - 0.4e1 * t61 * zc * t179 + t23 * t193 + ZB * t196 + t120 * t199 - ZB * t193 - t120 * t203 - t23 * t196) / 0.4e1;
-		
-		t2 = kn * (zc + 0.1e1);
-		t4 = exp(-0.2e1 * t2);
-		t5 = t4 * ZA;
-		t6 = kn * kn;
-		t7 = t6 * kn;
-		t9 = sin(km);
-		t10 = t7 * zc * t9;
-		t17 = exp(-0.2e1 * kn * (0.2e1 * zc + 0.1e1));
-		t19 = km * km;
-		t20 = t9 * t19;
-		t21 = t20 * ZB;
-		t25 = exp(-kn * (zc + 0.3e1));
-		t26 = t25 * t7;
-		t27 = zc * ZB;
-		t28 = km * zc;
-		t29 = sin(t28);
-		t30 = t27 * t29;
-		t33 = kn * zc;
-		t35 = exp(-0.4e1 * t33);
-		t36 = t35 * ZA;
-		t39 = t4 * ZB;
-		t40 = t6 * t6;
-		t42 = t40 * zc * t9;
-		t47 = t17 * ZB;
-		t49 = t20 * zc;
-		t52 = exp(-0.3e1 * t2);
-		t54 = cos(t28);
-		t55 = t54 * km;
-		t56 = t55 * ZB;
-		t62 = exp(-kn * (0.3e1 * zc + 0.1e1));
-		t66 = t5 * t6;
-		t70 = exp(-0.2e1 * kn);
-		t72 = t19 * ZB;
-		t74 = t6 * t9;
-		t76 = t17 * t7;
-		t77 = t9 * ZB;
-		t79 = t70 * t7;
-		t81 = ZB * t70;
-		t85 = t62 * t6;
-		t88 = km * ZB * zc;
-		t91 = t39 * t6;
-		t94 = t27 * t9;
-		t96 = 0.6e1 * t5 * t10 + t17 * kn * t21 + 0.4e1 * t26 * t30 + 0.2e1 * t36 * t10 + 0.4e1 * t39 * t42 - 0.4e1 * t5 * t42 - t47 * kn * t49 - 0.2e1 * t52 * kn * t56 + 0.2e1 * t62 * kn * t56 - 0.4e1 * t66 * t49 - t70 * t9 * t72 - t47 * t74 + t76 * t77 - t79 * t77 + t81 * t74 + t17 * t9 * t72 + 0.4e1 * t85 * t54 * t88 + 0.4e1 * t91 * t49 + t79 * t94;
-		t98 = t55 * zc;
-		t105 = zc * zc;
-		t106 = t40 * t9 * t105;
-		t112 = ZA * zc;
-		t113 = t112 * t29;
-		t116 = t25 * t6;
-		t121 = t105 * t19 * t9;
-		t137 = t62 * t7;
-		t148 = exp(-t2);
-		t155 = -0.4e1 * t85 * ZA * t98 + 0.2e1 * t36 * kn * t49 + 0.4e1 * t5 * t106 + 0.2e1 * t25 * kn * t56 - 0.4e1 * t26 * t113 + 0.4e1 * t116 * ZA * t98 + 0.4e1 * t66 * t121 - 0.4e1 * t39 * t106 + t81 * kn * t49 - 0.4e1 * t4 * t7 * t94 - 0.4e1 * t116 * t54 * t88 - 0.2e1 * t5 * kn * t49 - 0.4e1 * t137 * t113 + 0.4e1 * t4 * kn * zc * t21 - 0.4e1 * t91 * t121 - t70 * kn * t21 - 0.2e1 * t148 * kn * t56 + 0.4e1 * t137 * t30 - t76 * t94;
-		t160 = pow(t19 + t6, 0.2e1);
-		t165 = kn * ZA;
-		t178 = exp(-0.4e1 * kn);
-		_C4B = -sigma * (t96 + t155) / ZB / t160 / (-0.4e1 * t33 * t39 - 0.4e1 * t165 * t105 * t4 + 0.4e1 * kn * t105 * t39 + 0.4e1 * t165 * zc * t4 - t27 * t70 - t47 - t112 * t35 + t81 + t112 * t178 + t27 * t17) / 0.4e1;
-		
-	}
-	
-	/*******************************************/
-	/*       calculate the velocities etc      */
-	/*******************************************/
-	
-	if ( z < zc ) {
-		t4 = exp(-kn * z);
-		t10 = exp(kn * (z - zc));
-		t12 = kn * kn;
-		t15 = sin(km * z);
-		t18 = km * km;
-		t20 = pow(t18 + t12, 0.2e1);
-		u1=u1a = kn * ((_C1A + z * _C3A) * t4 + (_C2A + z * _C4A) * t10 + sigma * t12 * t15 / ZA / t20);
-		
-		t6 = exp(-kn * z);
-		t14 = exp(kn * (z - zc));
-		t16 = kn * kn;
-		t19 = cos(km * z);
-		t23 = km * km;
-		t25 = pow(t23 + t16, 0.2e1);
-		u2=u2a = ((_C1A + z * _C3A) * kn - _C3A) * t6 + (-_C4A - (_C2A + z * _C4A) * kn) * t14 - sigma * t16 * t19 * km / ZA / t25;
-		
-		t1 = kn * ZA;
-		t7 = exp(-kn * z);
-		t16 = exp(kn * (z - zc));
-		t19 = kn * kn;
-		t23 = cos(km * z);
-		t25 = km * km;
-		t27 = pow(t25 + t19, 0.2e1);
-		u3=u3a = 0.2e1 * t1 * (-(_C1A + z * _C3A) * kn + _C3A) * t7 + 0.2e1 * t1 * (_C4A + (_C2A + z * _C4A) * kn) * t16 + 0.2e1 * t19 * kn * sigma * t23 * km / t27;
-		
-		t2 = kn * kn;
-		t10 = exp(-kn * z);
-		t21 = exp(kn * (z - zc));
-		t25 = sin(km * z);
-		t27 = km * km;
-		t28 = 0.1e1 / ZA;
-		t31 = pow(t27 + t2, 0.2e1);
-		t32 = 0.1e1 / t31;
-		t35 = t2 * t2;
-		u4=u4a = -ZA * (-0.2e1 * _C3A * kn + 0.2e1 * t2 * (_C1A + z * _C3A)) * t10 - ZA * (0.2e1 * t2 * (_C2A + z * _C4A) + 0.2e1 * _C4A * kn) * t21 - ZA * (-sigma * t2 * t25 * t27 * t28 * t32 + t35 * sigma * t25 * t28 * t32);
-		
-		
-		Z=ZA;
-		
-		
-	} else {
-		
-		t5 = exp(kn * (zc - z));
-		t11 = exp(kn * (z - 0.1e1));
-		t13 = kn * kn;
-		t16 = sin(km * z);
-		t19 = km * km;
-		t21 = pow(t19 + t13, 0.2e1);
-		u1=u1b = kn * ((_C1B + z * _C3B) * t5 + (_C2B + z * _C4B) * t11 + sigma * t13 * t16 / ZB / t21);
-		
-		t7 = exp(kn * (zc - z));
-		t15 = exp(kn * (z - 0.1e1));
-		t17 = kn * kn;
-		t20 = cos(km * z);
-		t24 = km * km;
-		t26 = pow(t24 + t17, 0.2e1);
-		u2=u2b = ((_C1B + z * _C3B) * kn - _C3B) * t7 + (-_C4B - (_C2B + z * _C4B) * kn) * t15 - sigma * t17 * t20 * km / ZB / t26;
-		
-		t1 = ZB * kn;
-		t8 = exp(kn * (zc - z));
-		t17 = exp(kn * (z - 0.1e1));
-		t20 = kn * kn;
-		t24 = cos(km * z);
-		t26 = km * km;
-		t28 = pow(t26 + t20, 0.2e1);
-		u3=u3b = 0.2e1 * t1 * (-(_C1B + z * _C3B) * kn + _C3B) * t8 + 0.2e1 * t1 * (_C4B + (_C2B + z * _C4B) * kn) * t17 + 0.2e1 * t20 * kn * sigma * t24 * km / t28;
-		
-		t2 = kn * kn;
-		t11 = exp(kn * (zc - z));
-		t22 = exp(kn * (z - 0.1e1));
-		t26 = sin(km * z);
-		t28 = km * km;
-		t29 = 0.1e1 / ZB;
-		t32 = pow(t28 + t2, 0.2e1);
-		t33 = 0.1e1 / t32;
-		t36 = t2 * t2;
-		u4=u4b = -ZB * (-0.2e1 * _C3B * kn + 0.2e1 * t2 * (_C1B + z * _C3B)) * t11 - ZB * (0.2e1 * t2 * (_C2B + z * _C4B) + 0.2e1 * _C4B * kn) * t22 - ZB * (-sigma * t2 * t26 * t28 * t29 * t33 + t36 * sigma * t26 * t29 * t33);
-		
-		Z=ZB;
-	}
-	
-	
-	
-	pp = (double)-(u3 + 2.0*n*M_PI*Z*u2)*cos(n*M_PI*x); /* pressure */
-	
-	txx = (double)(u3 + 4*Z*n*M_PI*u2)*cos(n*M_PI*x); /* xx stress */
-	//printf( "() = %g\n", (u3 + 2.0*n*M_PI*Z*u2) );
-	//printf( "cos = %g\n", cos(n*M_PI*x) );
-	//printf( "pp = %g\n", pp );
-	sum5 += pp;
-	sum6 += txx;
-	
-	u1 *= cos(n*M_PI*x); /* z velocity */
-	sum1 += u1;
-	u2 *= sin(n*M_PI*x); /* x velocity */
-	sum2 += u2;
-	u3 *= cos(n*M_PI*x); /* zz stress */
-	sum3 += u3;
-	u4 *= sin(n*M_PI*x); /* zx stress */
-	sum4 += u4;
-	
-	rho = -sigma*sin(km*z)*cos(n*M_PI*x); /* density */
-	sum7 += rho;
-	
-	mag=sqrt(sum1*sum1+sum2*sum2);
-	/****************************************************/
-	/****************************************************/
-//	printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7);
-	
-	
-	/* Output */
-	if( vel != NULL ) {
-		vel[0] = sum2;
-		vel[1] = sum1;
-	}
-	if( presssure != NULL ) {
-		//printf( "pressure = %g\n", *presssure );
-		(*presssure) = sum5;
-	}
-	if( total_stress != NULL ) {
-		total_stress[0] = sum6;
-		total_stress[1] = sum3;
-		total_stress[2] = sum4;
-	}
-	if( strain_rate != NULL ) {
-		if( z<zc ) {
-			Z = ZA;
-		}
-		else {
-			Z = ZB;
-		}
-		strain_rate[0] = (sum6+sum5)/(2.0*Z);
-		strain_rate[1] = (sum3+sum5)/(2.0*Z);
-		strain_rate[2] = (sum4)/(2.0*Z);
-	}
-	/* Value checks, could be cleaned up if needed. Julian Giordani 9-Oct-2006*/
-        if( fabs( sum5 - ( -0.5*(sum6+sum3) ) ) > 1e-5 ) {
-                assert(0);
-        }
-	
-	
-	
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solE/solE.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solE/solE.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,839 @@
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+
+
+void _Velic_solE( 
+		double pos[],
+		double _sigma,
+		double _eta_A, double _eta_B, 
+		double _z_c, double _km, int _n,
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] );
+
+
+int main( int argc, char **argv )
+{
+	int i,j;
+	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
+	double x,z;
+	
+	for (i=0;i<101;i++){
+		for(j=0;j<101;j++){
+			x = i/100.0;
+			z = j/100.0;
+			
+			pos[0] = x;
+			pos[1] = z;
+			_Velic_solE(
+					pos,
+					1.0,
+					100.0, 1.0,
+					0.8, (double)M_PI, 1,
+					vel, &pressure, total_stress, strain_rate );
+//			printf("pressure is fucked !! \n");
+			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
+					pos[0],pos[1],
+					vel[0],vel[1], pressure, 
+					total_stress[0], total_stress[1], total_stress[2], 
+					strain_rate[0], strain_rate[1], strain_rate[2] );
+		}
+		printf("\n");
+	}
+	
+	return 0;
+}
+
+
+
+void _Velic_solE(
+		double pos[],
+		double _sigma,
+		double _eta_A, double _eta_B, 
+		double _z_c, double _km, int _n,
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] )
+{
+	double Z,ZA,ZB,u1,u2,u3,u4,pp,txx;
+	double u1a,u2a,u3a,u4a,u1b,u2b,u3b,u4b;
+	double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,x,z;
+	double sigma;
+	int n;
+	double kn,km;
+	double _C1A,_C2A,_C3A,_C4A,_C1B,_C2B,_C3B,_C4B;
+	double rho,zc;
+	
+	double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
+	double t11,t12,t13,t14,t15,t16,t17,t18,t19,t20;
+	double t21,t22,t23,t24,t25,t26,t27,t28,t29,t30;
+	double t31,t32,t33,t34,t35,t36,t37,t38,t39,t40;
+	double t41,t42,t43,t44,t45,t46,t47,t48,t49,t50;
+	double t51,t52,t53,t54,t55,t56,t57,t58,t59,t60;
+	double t61,t62,t63,t64,t65,t66,t67,t68,t69,t70;
+	double t71,t72,t73,t74,t76,t77,t78,t79,t80,t81;
+	double t82,t83,t84,t85,t86,t87,t88,t89,t90,t91;
+	double t92,t93,t94,t95,t96,t97,t98,t99,t100,t101;
+	double t102,t103,t104,t105,t106,t109,t111,t112,t113,t114;
+	double t115,t116,t117,t118,t119,t120,t121,t123,t124,t126;
+	double t127,t128,t130,t131,t132,t133,t134,t136,t137,t140;
+	double t141,t142,t143,t145,t146,t147,t148,t149,t151,t152;
+	double t155,t156,t157,t158,t160,t162,t163,t164,t165,t166;
+	double t167,t169,t170,t171,t172,t173,t174,t176,t178,t179;
+	double t180,t181,t184,t186,t187,t188,t189,t191,t192,t193;
+	double t195,t196,t197,t198,t199,t200,t201,t203,t204,t205;
+	double t237,t241,t245,t247,t250,t251,t252,t253,t256,t261;
+	double t262,t263,t265,t266,t268,t269,t271,t272,t275,t276;
+	double t279,t282,t286;
+	
+	
+	/*************************************************************************/
+	/*************************************************************************/
+	/*
+	
+	rho = -sigma*sin(km*z)*cos(kn*x)
+	
+	The viscosity of layer B is ZB:
+	The viscosity of layer A is ZA:
+	
+	*/
+	/*************************************************************************/
+	/*************************************************************************/
+	
+	/*************************************************************************/
+	/*************************************************************************/
+	sigma = _sigma; /* density parameter for layer B */
+	ZA = _eta_A;    /* viscosity for layer A */
+	ZB = _eta_B; /* viscosity for layer B */
+	zc = _z_c;  /* dividing line between region B and region A */
+	
+	n = _n;
+	kn = (double)n*M_PI;
+	km = _km;
+	/*************************************************************************/
+	/*************************************************************************/
+	
+	x = pos[0];
+	z = pos[1];
+	
+	sum1=0.0;
+	sum2=0.0;
+	sum3=0.0;
+	sum4=0.0;
+	sum5=0.0;
+	sum6=0.0;
+	sum7=0.0;
+	
+	
+	/*******************************************/
+	/*         calculate the constants         */
+	/*******************************************/
+	
+	if ( z < zc ) {
+		t3 = exp(-kn * (zc + 0.2e1));
+		t4 = kn * kn;
+		t5 = t4 * t4;
+		t6 = t3 * t5;
+		t7 = ZA * zc;
+		t8 = km * zc;
+		t9 = sin(t8);
+		t10 = t7 * t9;
+		t13 = sin(km);
+		t14 = kn * t13;
+		t15 = km * km;
+		t16 = ZA * t15;
+		t17 = 0.2e1 * zc;
+		t20 = exp(-kn * (t17 + 0.3e1));
+		t26 = exp(-kn * (0.4e1 * zc + 0.1e1));
+		t27 = t26 * ZA;
+		t28 = t27 * t4;
+		t29 = zc * zc;
+		t31 = t29 * t15 * t13;
+		t33 = t4 * kn;
+		t34 = t3 * t33;
+		t35 = t34 * ZA;
+		t36 = cos(t8);
+		t38 = t29 * t36 * km;
+		t43 = exp(-kn * (zc + 0.4e1));
+		t47 = t36 * km * zc;
+		t51 = kn * (t17 + 0.1e1);
+		t52 = exp(-t51);
+		t53 = t52 * ZA;
+		t54 = t53 * t4;
+		t56 = kn * t36;
+		t57 = ZA * km;
+		t58 = kn * zc;
+		t60 = exp(-0.3e1 * t58);
+		t65 = t7 * t13;
+		t70 = exp(-kn * (0.3e1 * zc + 0.2e1));
+		t71 = t70 * t33;
+		t74 = km * ZB * zc;
+		t77 = t71 * ZA;
+		t81 = exp(-0.3e1 * kn);
+		t83 = t81 * t4 * ZA;
+		t84 = t13 * t15;
+		t85 = t84 * zc;
+		t88 = t29 * ZA * t9;
+		t91 = ZA * t33;
+		t92 = zc * t13;
+		t96 = kn * ZA;
+		t97 = t96 * t13;
+		t98 = t15 * zc;
+		t105 = t4 * ZA * t36;
+		t111 = 0.4e1 * t6 * t10 - t14 * t16 * t20 - t28 * t31 + 0.4e1 * t35 * t38 - 0.2e1 * t43 * t4 * ZA * t47 + t54 * t31 + 0.2e1 * t56 * t57 * t60 + t20 * t5 * t65 + 0.4e1 * t71 * t36 * t74 - 0.4e1 * t77 * t47 - t83 * t85 - 0.4e1 * t6 * t88 + 0.2e1 * t91 * t92 * t81 + 0.2e1 * t97 * t98 * t52 - t14 * t16 * t26 + 0.2e1 * t105 * t8 * t3 - 0.4e1 * t35 * t47;
+		t112 = t33 * zc;
+		t113 = ZB * t9;
+		t117 = t4 * t36;
+		t118 = t57 * t70;
+		t121 = t81 * ZA;
+		t123 = t5 * t13 * t29;
+		t128 = t29 * ZB * t9;
+		t140 = t70 * t5;
+		t143 = t57 * t3;
+		t147 = ZA * t9;
+		t151 = t4 * t13;
+		t156 = t20 * t4 * ZA;
+		t162 = t20 * ZA;
+		t164 = 0.4e1 * t112 * t113 * t70 + 0.4e1 * t117 * t118 + t121 * t123 + 0.4e1 * t77 * t38 + 0.4e1 * t6 * t128 + 0.2e1 * t91 * t92 * t26 + 0.2e1 * t56 * t57 * t43 - 0.4e1 * t34 * ZB * t38 - 0.4e1 * t140 * t128 - 0.2e1 * t56 * t143 + t53 * t123 - 0.4e1 * t112 * t147 * t3 - t151 * t53 - t27 * t123 - t54 * t85 + t156 * t85 + 0.2e1 * t60 * t4 * ZA * t47 - t162 * t123;
+		t172 = t33 * t13;
+		t176 = t33 * t9;
+		t187 = ZB * zc;
+		t188 = t187 * t9;
+		t200 = 0.4e1 * t34 * t36 * t74 - 0.2e1 * t105 * t8 * t70 - t172 * t162 + t84 * t27 - t172 * t53 - 0.4e1 * t176 * ZB * t70 + 0.4e1 * t176 * ZA * t70 - 0.4e1 * t176 * ZB * t3 + t151 * t162 - 0.4e1 * t6 * t188 - t151 * t27 + t151 * t121 - t172 * t121 + t84 * t53 + 0.4e1 * t176 * ZA * t3 - t172 * t27 - t84 * t121;
+		t237 = -t84 * t162 - t81 * t5 * t65 + t83 * t31 - 0.4e1 * t117 * t143 - 0.4e1 * t140 * t10 - 0.4e1 * t112 * t147 * t70 + 0.4e1 * t112 * t113 * t3 + t28 * t85 - t52 * t5 * t65 - t14 * t16 * t52 + t26 * t5 * t65 + 0.2e1 * t97 * t98 * t20 - 0.2e1 * t56 * t118 + 0.4e1 * t140 * t188 - 0.4e1 * t71 * ZB * t38 + 0.4e1 * t140 * t88 - t14 * t16 * t81 - t156 * t31;
+		t245 = pow(t15 + t4, 0.2e1);
+		t251 = exp(-0.2e1 * kn * (zc + 0.1e1));
+		t252 = ZB * t251;
+		t265 = exp(-0.2e1 * kn);
+		t268 = exp(-0.2e1 * t51);
+		t271 = exp(-0.4e1 * t58);
+		t275 = exp(-0.4e1 * kn);
+		_C1A = -sigma * (t111 + t164 + t200 + t237) / ZA / kn / t245 / (-0.4e1 * t58 * t252 - 0.4e1 * t96 * t29 * t251 + 0.4e1 * kn * t29 * t252 + 0.4e1 * t96 * zc * t251 - t187 * t265 - ZB * t268 - t7 * t271 + ZB * t265 + t7 * t275 + t187 * t268) / 0.4e1;
+		
+		t1 = 0.2e1 * zc;
+		t4 = exp(-kn * (t1 + 0.3e1));
+		t5 = kn * kn;
+		t7 = t4 * t5 * ZA;
+		t8 = sin(km);
+		t9 = km * km;
+		t10 = t8 * t9;
+		t11 = t10 * zc;
+		t14 = kn * (t1 + 0.1e1);
+		t15 = exp(-t14);
+		t16 = t5 * t5;
+		t18 = ZA * zc;
+		t19 = t18 * t8;
+		t21 = kn * t8;
+		t22 = ZA * t9;
+		t28 = exp(-kn * (0.3e1 * zc + 0.2e1));
+		t29 = t5 * kn;
+		t30 = t28 * t29;
+		t31 = t30 * ZA;
+		t32 = km * zc;
+		t33 = cos(t32);
+		t35 = t33 * km * zc;
+		t39 = exp(-0.3e1 * kn);
+		t41 = t39 * t5 * ZA;
+		t43 = t5 * t8;
+		t47 = exp(-kn * (0.4e1 * zc + 0.1e1));
+		t48 = ZA * t47;
+		t50 = t29 * t8;
+		t51 = ZA * t4;
+		t54 = ZA * t15;
+		t56 = sin(t32);
+		t57 = t29 * t56;
+		t66 = exp(-kn * (zc + 0.2e1));
+		t73 = ZA * t39;
+		t76 = -t7 * t11 + t15 * t16 * t19 + t21 * t22 * t15 + 0.4e1 * t31 * t35 + t41 * t11 + t43 * t48 + t50 * t51 - t10 * t48 + t50 * t54 + 0.4e1 * t57 * ZB * t28 - 0.4e1 * t57 * ZA * t28 + 0.4e1 * t57 * ZB * t66 + t43 * t54 + t10 * t51 - t43 * t51 + t50 * t73 - t10 * t54;
+		t83 = zc * zc;
+		t84 = t16 * t8 * t83;
+		t86 = t66 * t29;
+		t87 = t86 * ZA;
+		t89 = t83 * t33 * km;
+		t92 = t66 * t16;
+		t94 = t83 * ZB * t56;
+		t97 = ZA * t29;
+		t98 = zc * t8;
+		t102 = kn * ZA;
+		t103 = t102 * t8;
+		t104 = t9 * zc;
+		t109 = t83 * t9 * t8;
+		t113 = exp(-kn * (zc + 0.4e1));
+		t121 = t83 * ZA * t56;
+		t127 = t54 * t5;
+		t132 = t5 * t33;
+		t133 = ZA * km;
+		t134 = t133 * t66;
+		t140 = -0.4e1 * t57 * ZA * t66 + t50 * t48 + t10 * t73 + t51 * t84 - 0.4e1 * t87 * t89 - 0.4e1 * t92 * t94 - 0.2e1 * t97 * t98 * t47 - 0.2e1 * t103 * t104 * t15 - t41 * t109 + 0.2e1 * t113 * t5 * ZA * t35 - t47 * t16 * t19 + 0.4e1 * t92 * t121 - 0.2e1 * t103 * t104 * t4 - t127 * t109 + 0.4e1 * t86 * ZB * t89 + 0.4e1 * t132 * t134 + t7 * t109 + t21 * t22 * t47;
+		t142 = kn * t33;
+		t143 = kn * zc;
+		t145 = exp(-0.3e1 * t143);
+		t149 = t18 * t56;
+		t156 = t29 * zc;
+		t157 = ZB * t56;
+		t162 = t28 * t16;
+		t163 = zc * ZB;
+		t164 = t163 * t56;
+		t171 = t5 * ZA * t33;
+		t178 = t133 * t28;
+		t181 = ZA * t56;
+		t192 = km * ZB * zc;
+		t197 = -0.2e1 * t142 * t133 * t145 - 0.4e1 * t92 * t149 - t4 * t16 * t19 + 0.2e1 * t142 * t134 - 0.4e1 * t156 * t157 * t28 + t48 * t84 - 0.4e1 * t162 * t164 - 0.4e1 * t156 * t157 * t66 - 0.2e1 * t171 * t32 * t66 + 0.4e1 * t162 * t94 + t127 * t11 + 0.2e1 * t142 * t178 + 0.4e1 * t156 * t181 * t66 + t21 * t22 * t39 - 0.2e1 * t97 * t98 * t39 - 0.4e1 * t86 * t33 * t192 - 0.4e1 * t132 * t178;
+		t205 = t48 * t5;
+		t237 = -t54 * t84 - 0.2e1 * t145 * t5 * ZA * t35 + 0.4e1 * t92 * t164 + t205 * t109 - 0.4e1 * t31 * t89 + t21 * t22 * t4 - t73 * t84 + 0.4e1 * t156 * t181 * t28 - 0.2e1 * t142 * t133 * t113 + 0.4e1 * t162 * t149 - t205 * t11 + 0.4e1 * t87 * t35 - 0.4e1 * t162 * t121 + 0.4e1 * t30 * ZB * t89 + 0.2e1 * t171 * t32 * t28 + t39 * t16 * t19 - 0.4e1 * t30 * t33 * t192 - t43 * t73;
+		t241 = exp(t143);
+		t247 = pow(t9 + t5, 0.2e1);
+		t252 = exp(-0.2e1 * kn * (zc + 0.1e1));
+		t253 = ZB * t252;
+		t266 = exp(-0.2e1 * kn);
+		t269 = exp(-0.2e1 * t14);
+		t272 = exp(-0.4e1 * t143);
+		t276 = exp(-0.4e1 * kn);
+		_C2A = -sigma * (t76 + t140 + t197 + t237) * t241 / ZA / kn / t247 / (-0.4e1 * t143 * t253 - 0.4e1 * t102 * t83 * t252 + 0.4e1 * kn * t83 * t253 + 0.4e1 * t102 * zc * t252 - t163 * t266 - ZB * t269 - t18 * t272 + ZB * t266 + t18 * t276 + t163 * t269) / 0.4e1;
+		
+		t1 = kn * kn;
+		t2 = t1 * kn;
+		t3 = ZA * t2;
+		t4 = sin(km);
+		t5 = zc * t4;
+		t7 = exp(-0.3e1 * kn);
+		t10 = kn * t4;
+		t11 = km * km;
+		t12 = ZA * t11;
+		t16 = exp(-kn * (0.4e1 * zc + 0.1e1));
+		t19 = t1 * t4;
+		t20 = 0.2e1 * zc;
+		t22 = kn * (t20 + 0.1e1);
+		t23 = exp(-t22);
+		t24 = ZA * t23;
+		t26 = km * zc;
+		t27 = sin(t26);
+		t28 = t2 * t27;
+		t31 = exp(-kn * (zc + 0.2e1));
+		t32 = ZB * t31;
+		t36 = cos(t26);
+		t37 = t1 * ZA * t36;
+		t44 = exp(-kn * (0.3e1 * zc + 0.2e1));
+		t48 = t1 * t36;
+		t49 = ZA * km;
+		t50 = t49 * t44;
+		t56 = t7 * ZA;
+		t58 = t4 * t11;
+		t59 = t58 * zc;
+		t61 = ZB * t44;
+		t66 = exp(-kn * (t20 + 0.3e1));
+		t67 = ZA * t66;
+		t69 = -t3 * t5 * t7 + t10 * t12 * t16 + t19 * t24 + 0.4e1 * t28 * t32 - 0.4e1 * t37 * t26 * t31 - 0.4e1 * t28 * ZA * t44 - 0.4e1 * t50 * t48 + 0.4e1 * t37 * t26 * t44 - t56 * kn * t59 + 0.4e1 * t28 * t61 - t19 * t67;
+		t70 = ZA * t16;
+		t72 = t2 * t4;
+		t87 = km * ZB * zc;
+		t90 = t19 * t70 + t72 * t67 - t58 * t70 + t72 * t24 + t72 * t56 - t58 * t24 - 0.4e1 * t28 * ZA * t31 + t72 * t70 + t58 * t56 + t58 * t67 - 0.4e1 * t44 * t1 * t36 * t87;
+		t93 = t49 * t31;
+		t96 = t48 * km;
+		t101 = t2 * zc;
+		t102 = ZA * t27;
+		t106 = kn * t36;
+		t109 = exp(-kn * (zc + 0.4e1));
+		t113 = ZB * t27;
+		t119 = kn * ZA;
+		t120 = t119 * t4;
+		t121 = t11 * zc;
+		t126 = kn * zc;
+		t128 = exp(-0.3e1 * t126);
+		t132 = -t19 * t56 + 0.4e1 * t48 * t93 - 0.4e1 * t32 * t96 - t3 * t5 * t16 + 0.4e1 * t101 * t102 * t44 - 0.2e1 * t106 * t49 * t109 - 0.4e1 * t101 * t113 * t31 + t10 * t12 * t23 - t120 * t121 * t66 + 0.2e1 * t106 * t50 - 0.2e1 * t106 * t49 * t128;
+		t149 = t101 * t4;
+		t158 = -0.4e1 * t101 * t113 * t44 - t70 * kn * t59 + 0.4e1 * t101 * t102 * t31 - t120 * t121 * t23 + t10 * t12 * t7 + 0.4e1 * t61 * t96 + 0.2e1 * t106 * t93 - t24 * t149 - t67 * t149 + t10 * t12 * t66 + 0.4e1 * t31 * t1 * t36 * t87;
+		t164 = pow(t11 + t1, 0.2e1);
+		t170 = exp(-0.2e1 * kn * (zc + 0.1e1));
+		t171 = ZB * t170;
+		t174 = zc * zc;
+		t184 = zc * ZB;
+		t186 = exp(-0.2e1 * kn);
+		t189 = exp(-0.2e1 * t22);
+		t191 = ZA * zc;
+		t193 = exp(-0.4e1 * t126);
+		t197 = exp(-0.4e1 * kn);
+		_C3A = -sigma * (t69 + t90 + t132 + t158) / ZA / t164 / (0.4e1 * t126 * t171 + 0.4e1 * t119 * t174 * t170 - 0.4e1 * kn * t174 * t171 - 0.4e1 * t119 * zc * t170 + t184 * t186 + ZB * t189 + t191 * t193 - ZB * t186 - t191 * t197 - t184 * t189) / 0.4e1;
+		
+		t1 = 0.2e1 * zc;
+		t4 = exp(-kn * (t1 + 0.3e1));
+		t5 = t4 * ZA;
+		t6 = kn * kn;
+		t7 = t6 * kn;
+		t8 = t7 * zc;
+		t9 = sin(km);
+		t10 = t8 * t9;
+		t12 = kn * t9;
+		t13 = km * km;
+		t14 = ZA * t13;
+		t17 = km * zc;
+		t18 = sin(t17);
+		t19 = ZA * t18;
+		t22 = exp(-kn * (zc + 0.2e1));
+		t27 = exp(-0.3e1 * kn);
+		t31 = cos(t17);
+		t32 = t6 * ZA * t31;
+		t36 = exp(-kn * (0.3e1 * zc + 0.2e1));
+		t40 = t6 * t9;
+		t42 = kn * (t1 + 0.1e1);
+		t43 = exp(-t42);
+		t44 = ZA * t43;
+		t46 = t7 * t18;
+		t47 = ZB * t36;
+		t53 = ZB * t22;
+		t56 = t7 * t9;
+		t59 = t5 * t10 - t12 * t14 * t4 - 0.4e1 * t8 * t19 * t22 - t12 * t14 * t27 - 0.4e1 * t32 * t17 * t36 - t40 * t44 - 0.4e1 * t46 * t47 + 0.4e1 * t46 * ZA * t36 - 0.4e1 * t46 * t53 - t56 * t44 - t56 * t5;
+		t60 = t13 * t9;
+		t64 = exp(-kn * (0.4e1 * zc + 0.1e1));
+		t65 = ZA * t64;
+		t70 = km * ZB * zc;
+		t73 = t7 * ZA;
+		t74 = zc * t9;
+		t77 = kn * ZA;
+		t78 = t77 * t9;
+		t79 = t13 * zc;
+		t82 = t6 * t31;
+		t83 = ZA * km;
+		t84 = t83 * t22;
+		t94 = ZA * t27;
+		t97 = t60 * t65 - 0.4e1 * t22 * t6 * t31 * t70 + t73 * t74 * t27 + t78 * t79 * t43 - 0.4e1 * t82 * t84 - t12 * t14 * t64 - t40 * t65 + 0.4e1 * t46 * ZA * t22 - t56 * t65 - t60 * t94 - t60 * t5;
+		t106 = t83 * t36;
+		t113 = t60 * zc;
+		t115 = kn * t31;
+		t118 = ZB * t18;
+		t126 = t40 * t5 + t40 * t94 - t56 * t94 + t60 * t44 + 0.4e1 * t32 * t17 * t22 + 0.4e1 * t82 * t106 - 0.4e1 * t8 * t19 * t36 + t94 * kn * t113 - 0.2e1 * t115 * t106 + 0.4e1 * t8 * t118 * t22 + 0.4e1 * t36 * t6 * t31 * t70;
+		t127 = t82 * km;
+		t136 = exp(-kn * (zc + 0.4e1));
+		t147 = kn * zc;
+		t149 = exp(-0.3e1 * t147);
+		t158 = 0.4e1 * t53 * t127 + t73 * t74 * t64 - t12 * t14 * t43 + 0.2e1 * t115 * t83 * t136 - 0.4e1 * t47 * t127 - 0.2e1 * t115 * t84 + t44 * t10 + t78 * t79 * t4 + 0.2e1 * t115 * t83 * t149 + 0.4e1 * t8 * t118 * t36 + t65 * kn * t113;
+		t162 = exp(t147);
+		t166 = pow(t13 + t6, 0.2e1);
+		t172 = exp(-0.2e1 * kn * (zc + 0.1e1));
+		t173 = ZB * t172;
+		t176 = zc * zc;
+		t186 = zc * ZB;
+		t188 = exp(-0.2e1 * kn);
+		t191 = exp(-0.2e1 * t42);
+		t193 = ZA * zc;
+		t195 = exp(-0.4e1 * t147);
+		t199 = exp(-0.4e1 * kn);
+		_C4A = -sigma * (t59 + t97 + t126 + t158) * t162 / ZA / t166 / (-0.4e1 * t147 * t173 - 0.4e1 * t77 * t176 * t172 + 0.4e1 * kn * t176 * t173 + 0.4e1 * t77 * zc * t172 - t186 * t188 - ZB * t191 - t193 * t195 + ZB * t188 + t193 * t199 + t186 * t191) / 0.4e1;
+		
+		
+		
+	} else { 
+		t3 = kn * (0.2e1 * zc + 0.1e1);
+		t4 = exp(-t3);
+		t5 = t4 * ZB;
+		t6 = kn * kn;
+		t8 = sin(km);
+		t9 = km * km;
+		t10 = t8 * t9;
+		t11 = t10 * zc;
+		t14 = exp(-kn);
+		t15 = t14 * ZB;
+		t16 = t15 * t6;
+		t18 = zc * zc;
+		t20 = t18 * t9 * t8;
+		t23 = t10 * ZB;
+		t27 = exp(-kn * (zc + 0.2e1));
+		t29 = km * zc;
+		t30 = cos(t29);
+		t31 = t30 * km;
+		t32 = t31 * ZB;
+		t35 = kn * zc;
+		t37 = exp(-0.3e1 * t35);
+		t38 = t6 * kn;
+		t39 = t37 * t38;
+		t40 = ZA * zc;
+		t41 = sin(t29);
+		t42 = t40 * t41;
+		t45 = t4 * ZA;
+		t46 = t6 * t6;
+		t48 = t46 * t8 * t18;
+		t51 = t38 * zc;
+		t59 = km * ZB * zc;
+		t62 = zc * ZB;
+		t63 = t62 * t41;
+		t72 = exp(-kn * (0.4e1 * zc + 0.1e1));
+		t73 = t72 * t38;
+		t74 = t62 * t8;
+		t78 = t40 * t8;
+		t82 = t9 * ZB;
+		t84 = t6 * t8;
+		t88 = -0.4e1 * t5 * t6 * t11 - t16 * t11 + t16 * t20 + t14 * kn * t23 + 0.2e1 * t27 * kn * t32 - 0.4e1 * t39 * t42 - 0.8e1 * t45 * t48 + 0.4e1 * t51 * ZB * t41 * t27 + 0.2e1 * t37 * t6 * t30 * t59 + 0.4e1 * t39 * t63 + 0.4e1 * t45 * t51 * t8 + 0.2e1 * t73 * t74 + 0.2e1 * t4 * t46 * t78 - t14 * t8 * t82 + t15 * t84 + t72 * t8 * t82;
+		t89 = ZB * t8;
+		t91 = t4 * t38;
+		t92 = t91 * ZB;
+		t93 = t18 * zc;
+		t95 = t93 * t9 * t8;
+		t98 = t14 * t38;
+		t100 = t72 * ZB;
+		t102 = t91 * ZA;
+		t106 = t4 * t46 * kn;
+		t112 = t46 * zc * t8;
+		t127 = t27 * t38;
+		t130 = t18 * t30 * km;
+		t141 = -t73 * t89 - 0.4e1 * t92 * t95 + t98 * t89 - t100 * t84 - 0.4e1 * t102 * t20 - 0.4e1 * t106 * ZA * t8 * t18 - 0.4e1 * t5 * t112 - t15 * t112 + 0.4e1 * t4 * kn * zc * t23 + t15 * t48 - t72 * kn * t23 - 0.4e1 * t51 * ZA * t41 * t27 - 0.4e1 * t127 * ZB * t130 + 0.4e1 * t106 * t89 * t18 - 0.4e1 * t91 * t74 + 0.2e1 * t37 * kn * t32;
+		t147 = exp(-t35);
+		t152 = exp(-0.3e1 * kn);
+		t169 = t100 * t6;
+		t172 = t37 * t46;
+		t174 = t18 * ZA * t41;
+		t180 = exp(-kn * (0.3e1 * zc + 0.2e1));
+		t188 = t6 * t30 * km;
+		t191 = t27 * t46;
+		t193 = t18 * ZB * t41;
+		t198 = t127 * ZA;
+		t204 = -0.2e1 * t27 * t6 * t30 * t59 - 0.2e1 * t147 * kn * t32 - 0.2e1 * t152 * t6 * ZA * t11 - 0.4e1 * t39 * ZB * t130 - 0.4e1 * t106 * ZB * t93 * t8 + 0.4e1 * ZA * t38 * zc * t8 * t152 + t169 * t11 - t100 * t48 + 0.4e1 * t172 * t174 - 0.2e1 * t180 * t6 * t30 * t59 + t100 * t112 - 0.4e1 * t27 * ZB * t188 + 0.4e1 * t191 * t193 - 0.2e1 * t98 * t74 + 0.4e1 * t198 * t130 + 0.4e1 * t180 * ZB * t188;
+		t247 = -0.8e1 * t191 * t63 - 0.4e1 * t191 * t174 - 0.8e1 * t198 * t31 * zc - t169 * t20 - 0.4e1 * t172 * t193 + 0.2e1 * t4 * t6 * ZA * t11 + 0.4e1 * t102 * t95 + 0.8e1 * t127 * t30 * t59 - 0.2e1 * t152 * t46 * t78 + 0.4e1 * t106 * ZA * t93 * t8 + 0.8e1 * t5 * t48 + 0.4e1 * t92 * t20 + 0.8e1 * t191 * t42 + 0.2e1 * t147 * t6 * t30 * t59 - 0.2e1 * t180 * kn * t32 + 0.4e1 * t39 * ZA * t130;
+		t256 = pow(t9 + t6, 0.2e1);
+		t261 = exp(-0.2e1 * kn * (zc + 0.1e1));
+		t262 = ZB * t261;
+		t265 = kn * ZA;
+		t276 = exp(-0.2e1 * kn);
+		t279 = exp(-0.2e1 * t3);
+		t282 = exp(-0.4e1 * t35);
+		t286 = exp(-0.4e1 * kn);
+		_C1B = sigma * (t88 + t141 + t204 + t247) * t147 / ZB / kn / t256 / (0.4e1 * t35 * t262 + 0.4e1 * t265 * t18 * t261 - 0.4e1 * kn * t18 * t262 - 0.4e1 * t265 * zc * t261 + t62 * t276 + ZB * t279 + t40 * t282 - ZB * t276 - t40 * t286 - t62 * t279) / 0.4e1;
+		
+		t2 = exp(-0.2e1 * kn);
+		t3 = t2 * ZB;
+		t4 = kn * kn;
+		t5 = t3 * t4;
+		t6 = zc * zc;
+		t7 = km * km;
+		t9 = sin(km);
+		t10 = t6 * t7 * t9;
+		t13 = kn * (zc + 0.1e1);
+		t15 = exp(-0.2e1 * t13);
+		t16 = t4 * t4;
+		t18 = t15 * t16 * kn;
+		t19 = t9 * ZB;
+		t27 = exp(-0.2e1 * kn * (0.2e1 * zc + 0.1e1));
+		t28 = ZB * t27;
+		t30 = t16 * zc * t9;
+		t32 = t9 * t7;
+		t33 = t32 * zc;
+		t38 = exp(-kn * (0.3e1 * zc + 0.1e1));
+		t39 = t4 * kn;
+		t40 = t38 * t39;
+		t41 = t40 * ZA;
+		t42 = km * zc;
+		t43 = cos(t42);
+		t44 = t43 * km;
+		t45 = t44 * zc;
+		t49 = exp(-0.3e1 * t13);
+		t53 = km * ZB * zc;
+		t57 = t44 * ZB;
+		t60 = exp(-t13);
+		t64 = t15 * ZB;
+		t68 = t6 * zc;
+		t74 = t7 * ZB;
+		t78 = t4 * t9;
+		t84 = t2 * t39;
+		t86 = t27 * t39;
+		t88 = t5 * t10 + 0.4e1 * t18 * t19 * t6 + t28 * t30 - t5 * t33 - 0.8e1 * t41 * t45 - 0.2e1 * t49 * t4 * t43 * t53 + 0.2e1 * t38 * kn * t57 - 0.2e1 * t60 * kn * t57 + 0.4e1 * t64 * t4 * t33 - 0.4e1 * t18 * ZB * t68 * t9 - t2 * t9 * t74 + t27 * t9 * t74 + t3 * t78 + 0.4e1 * t18 * ZA * t68 * t9 - t84 * t19 + t86 * t19;
+		t90 = t40 * ZB;
+		t93 = t38 * t16;
+		t95 = sin(t42);
+		t96 = ZB * t6 * t95;
+		t99 = zc * ZB;
+		t100 = t99 * t95;
+		t105 = exp(-kn * (zc + 0.3e1));
+		t111 = t16 * t9 * t6;
+		t113 = t15 * t39;
+		t114 = t113 * ZB;
+		t116 = t68 * t7 * t9;
+		t120 = t6 * t43 * km;
+		t124 = ZA * t6 * t95;
+		t127 = t105 * t39;
+		t131 = t28 * t4;
+		t134 = t99 * t9;
+		t140 = ZA * zc;
+		t141 = t140 * t95;
+		t146 = t32 * ZB;
+		t149 = -t28 * t78 + 0.8e1 * t90 * t45 - 0.4e1 * t93 * t96 + 0.8e1 * t93 * t100 - 0.2e1 * t105 * t4 * t43 * t53 + t3 * t111 - 0.4e1 * t114 * t116 + 0.4e1 * t41 * t120 + 0.4e1 * t93 * t124 - 0.4e1 * t127 * ZB * t120 + t131 * t33 - t28 * t111 + 0.2e1 * t84 * t134 + 0.2e1 * t105 * kn * t57 - 0.4e1 * t40 * t141 + 0.4e1 * t15 * kn * zc * t146;
+		t151 = t113 * ZA;
+		t156 = t4 * t43 * km;
+		t165 = t15 * ZA;
+		t169 = t105 * t16;
+		t188 = t39 * zc * t9;
+		t197 = 0.4e1 * t151 * t116 + 0.4e1 * t38 * ZB * t156 - 0.2e1 * t86 * t134 - 0.4e1 * t151 * t10 - t2 * kn * t146 - 0.2e1 * t165 * t4 * t33 - 0.4e1 * t169 * t124 - t3 * t30 - 0.4e1 * t113 * t134 + 0.4e1 * t127 * ZA * t120 + 0.2e1 * t38 * t4 * t43 * t53 + 0.4e1 * t169 * t96 - 0.4e1 * t60 * ZB * t156 + 0.4e1 * t165 * t188 + 0.2e1 * t60 * t4 * t43 * t53 - 0.8e1 * t93 * t141;
+		t198 = kn * zc;
+		t200 = exp(-0.4e1 * t198);
+		t201 = t200 * ZA;
+		t237 = 0.2e1 * t201 * t30 + 0.4e1 * t114 * t10 - 0.4e1 * t127 * t141 + 0.4e1 * t64 * t30 + 0.4e1 * t127 * t100 - 0.2e1 * t49 * kn * t57 + 0.4e1 * t40 * t100 + t27 * kn * t146 - t131 * t10 - 0.2e1 * t165 * t30 - 0.4e1 * t90 * t120 + 0.8e1 * t165 * t111 - 0.4e1 * t18 * ZA * t9 * t6 - 0.8e1 * t64 * t111 + 0.4e1 * t201 * t188 + 0.2e1 * t201 * t4 * t33;
+		t245 = pow(t7 + t4, 0.2e1);
+		t250 = kn * ZA;
+		t263 = exp(-0.4e1 * kn);
+		_C2B = -sigma * (t88 + t149 + t197 + t237) / kn / ZB / t245 / (0.4e1 * t198 * t64 + 0.4e1 * t250 * t6 * t15 - 0.4e1 * kn * t6 * t64 - 0.4e1 * t250 * zc * t15 + t99 * t2 + t28 + t140 * t200 - t3 - t140 * t263 - t99 * t27) / 0.4e1;
+		
+		t4 = exp(-kn * (0.4e1 * zc + 0.1e1));
+		t5 = t4 * ZB;
+		t7 = sin(km);
+		t8 = km * km;
+		t9 = t7 * t8;
+		t10 = t9 * zc;
+		t12 = exp(-kn);
+		t14 = t9 * ZB;
+		t18 = kn * (0.2e1 * zc + 0.1e1);
+		t19 = exp(-t18);
+		t20 = kn * kn;
+		t21 = t20 * kn;
+		t23 = zc * ZB;
+		t24 = t23 * t7;
+		t27 = kn * zc;
+		t29 = exp(-0.3e1 * t27);
+		t31 = km * zc;
+		t32 = cos(t31);
+		t33 = t32 * km;
+		t34 = t33 * ZB;
+		t41 = exp(-kn * (zc + 0.2e1));
+		t45 = t29 * t21;
+		t46 = sin(t31);
+		t50 = t19 * ZA;
+		t51 = t21 * zc;
+		t56 = exp(-0.3e1 * kn);
+		t61 = kn * ZA;
+		t67 = t19 * ZB;
+		t68 = t20 * t20;
+		t70 = zc * zc;
+		t71 = t68 * t7 * t70;
+		t77 = km * ZB * zc;
+		t80 = t19 * t20;
+		t81 = t80 * ZB;
+		t83 = t70 * t8 * t7;
+		t86 = t4 * t21;
+		t88 = t80 * ZA;
+		t91 = t20 * t7;
+		t93 = t12 * ZB;
+		t96 = t8 * ZB;
+		t100 = t7 * ZB;
+		t102 = -t5 * kn * t10 - t12 * kn * t14 + 0.4e1 * t19 * t21 * t24 - 0.2e1 * t29 * kn * t34 - 0.4e1 * t20 * ZA * t32 * t31 * t41 - 0.4e1 * t45 * t23 * t46 - 0.6e1 * t50 * t51 * t7 - 0.2e1 * t56 * ZA * kn * t10 + 0.2e1 * t61 * t7 * t8 * zc * t19 - 0.4e1 * t67 * t71 + 0.4e1 * t41 * t20 * t32 * t77 - 0.4e1 * t81 * t83 - t86 * t24 - 0.4e1 * t88 * t10 + t5 * t91 - t93 * t91 + t12 * t7 * t96 - t4 * t7 * t96 + t86 * t100;
+		t103 = t12 * t21;
+		t105 = t29 * t20;
+		t120 = ZA * zc;
+		t158 = exp(-kn * (0.3e1 * zc + 0.2e1));
+		t162 = exp(-t27);
+		t167 = -t103 * t100 + 0.4e1 * t105 * ZA * t33 * zc + t93 * kn * t10 - 0.2e1 * t41 * kn * t34 - 0.4e1 * t51 * ZB * t46 * t41 - 0.4e1 * t19 * t68 * t120 * t7 + 0.4e1 * t67 * t68 * zc * t7 + t4 * kn * t14 + 0.4e1 * t88 * t83 + 0.4e1 * t50 * t71 + 0.4e1 * t45 * t120 * t46 - 0.2e1 * ZA * t21 * zc * t7 * t56 - 0.4e1 * t19 * kn * zc * t14 + 0.4e1 * t81 * t10 + 0.4e1 * t51 * ZA * t46 * t41 - 0.4e1 * t105 * t32 * t77 + 0.2e1 * t158 * kn * t34 + 0.2e1 * t162 * kn * t34 + t103 * t24;
+		t173 = pow(t8 + t20, 0.2e1);
+		t179 = exp(-0.2e1 * kn * (zc + 0.1e1));
+		t180 = ZB * t179;
+		t193 = exp(-0.2e1 * kn);
+		t196 = exp(-0.2e1 * t18);
+		t199 = exp(-0.4e1 * t27);
+		t203 = exp(-0.4e1 * kn);
+		_C3B = -sigma * (t102 + t167) * t162 / ZB / t173 / (0.4e1 * t27 * t180 + 0.4e1 * t61 * t70 * t179 - 0.4e1 * kn * t70 * t180 - 0.4e1 * t61 * zc * t179 + t23 * t193 + ZB * t196 + t120 * t199 - ZB * t193 - t120 * t203 - t23 * t196) / 0.4e1;
+		
+		t2 = kn * (zc + 0.1e1);
+		t4 = exp(-0.2e1 * t2);
+		t5 = t4 * ZA;
+		t6 = kn * kn;
+		t7 = t6 * kn;
+		t9 = sin(km);
+		t10 = t7 * zc * t9;
+		t17 = exp(-0.2e1 * kn * (0.2e1 * zc + 0.1e1));
+		t19 = km * km;
+		t20 = t9 * t19;
+		t21 = t20 * ZB;
+		t25 = exp(-kn * (zc + 0.3e1));
+		t26 = t25 * t7;
+		t27 = zc * ZB;
+		t28 = km * zc;
+		t29 = sin(t28);
+		t30 = t27 * t29;
+		t33 = kn * zc;
+		t35 = exp(-0.4e1 * t33);
+		t36 = t35 * ZA;
+		t39 = t4 * ZB;
+		t40 = t6 * t6;
+		t42 = t40 * zc * t9;
+		t47 = t17 * ZB;
+		t49 = t20 * zc;
+		t52 = exp(-0.3e1 * t2);
+		t54 = cos(t28);
+		t55 = t54 * km;
+		t56 = t55 * ZB;
+		t62 = exp(-kn * (0.3e1 * zc + 0.1e1));
+		t66 = t5 * t6;
+		t70 = exp(-0.2e1 * kn);
+		t72 = t19 * ZB;
+		t74 = t6 * t9;
+		t76 = t17 * t7;
+		t77 = t9 * ZB;
+		t79 = t70 * t7;
+		t81 = ZB * t70;
+		t85 = t62 * t6;
+		t88 = km * ZB * zc;
+		t91 = t39 * t6;
+		t94 = t27 * t9;
+		t96 = 0.6e1 * t5 * t10 + t17 * kn * t21 + 0.4e1 * t26 * t30 + 0.2e1 * t36 * t10 + 0.4e1 * t39 * t42 - 0.4e1 * t5 * t42 - t47 * kn * t49 - 0.2e1 * t52 * kn * t56 + 0.2e1 * t62 * kn * t56 - 0.4e1 * t66 * t49 - t70 * t9 * t72 - t47 * t74 + t76 * t77 - t79 * t77 + t81 * t74 + t17 * t9 * t72 + 0.4e1 * t85 * t54 * t88 + 0.4e1 * t91 * t49 + t79 * t94;
+		t98 = t55 * zc;
+		t105 = zc * zc;
+		t106 = t40 * t9 * t105;
+		t112 = ZA * zc;
+		t113 = t112 * t29;
+		t116 = t25 * t6;
+		t121 = t105 * t19 * t9;
+		t137 = t62 * t7;
+		t148 = exp(-t2);
+		t155 = -0.4e1 * t85 * ZA * t98 + 0.2e1 * t36 * kn * t49 + 0.4e1 * t5 * t106 + 0.2e1 * t25 * kn * t56 - 0.4e1 * t26 * t113 + 0.4e1 * t116 * ZA * t98 + 0.4e1 * t66 * t121 - 0.4e1 * t39 * t106 + t81 * kn * t49 - 0.4e1 * t4 * t7 * t94 - 0.4e1 * t116 * t54 * t88 - 0.2e1 * t5 * kn * t49 - 0.4e1 * t137 * t113 + 0.4e1 * t4 * kn * zc * t21 - 0.4e1 * t91 * t121 - t70 * kn * t21 - 0.2e1 * t148 * kn * t56 + 0.4e1 * t137 * t30 - t76 * t94;
+		t160 = pow(t19 + t6, 0.2e1);
+		t165 = kn * ZA;
+		t178 = exp(-0.4e1 * kn);
+		_C4B = -sigma * (t96 + t155) / ZB / t160 / (-0.4e1 * t33 * t39 - 0.4e1 * t165 * t105 * t4 + 0.4e1 * kn * t105 * t39 + 0.4e1 * t165 * zc * t4 - t27 * t70 - t47 - t112 * t35 + t81 + t112 * t178 + t27 * t17) / 0.4e1;
+		
+	}
+	
+	/*******************************************/
+	/*       calculate the velocities etc      */
+	/*******************************************/
+	
+	if ( z < zc ) {
+		t4 = exp(-kn * z);
+		t10 = exp(kn * (z - zc));
+		t12 = kn * kn;
+		t15 = sin(km * z);
+		t18 = km * km;
+		t20 = pow(t18 + t12, 0.2e1);
+		u1=u1a = kn * ((_C1A + z * _C3A) * t4 + (_C2A + z * _C4A) * t10 + sigma * t12 * t15 / ZA / t20);
+		
+		t6 = exp(-kn * z);
+		t14 = exp(kn * (z - zc));
+		t16 = kn * kn;
+		t19 = cos(km * z);
+		t23 = km * km;
+		t25 = pow(t23 + t16, 0.2e1);
+		u2=u2a = ((_C1A + z * _C3A) * kn - _C3A) * t6 + (-_C4A - (_C2A + z * _C4A) * kn) * t14 - sigma * t16 * t19 * km / ZA / t25;
+		
+		t1 = kn * ZA;
+		t7 = exp(-kn * z);
+		t16 = exp(kn * (z - zc));
+		t19 = kn * kn;
+		t23 = cos(km * z);
+		t25 = km * km;
+		t27 = pow(t25 + t19, 0.2e1);
+		u3=u3a = 0.2e1 * t1 * (-(_C1A + z * _C3A) * kn + _C3A) * t7 + 0.2e1 * t1 * (_C4A + (_C2A + z * _C4A) * kn) * t16 + 0.2e1 * t19 * kn * sigma * t23 * km / t27;
+		
+		t2 = kn * kn;
+		t10 = exp(-kn * z);
+		t21 = exp(kn * (z - zc));
+		t25 = sin(km * z);
+		t27 = km * km;
+		t28 = 0.1e1 / ZA;
+		t31 = pow(t27 + t2, 0.2e1);
+		t32 = 0.1e1 / t31;
+		t35 = t2 * t2;
+		u4=u4a = -ZA * (-0.2e1 * _C3A * kn + 0.2e1 * t2 * (_C1A + z * _C3A)) * t10 - ZA * (0.2e1 * t2 * (_C2A + z * _C4A) + 0.2e1 * _C4A * kn) * t21 - ZA * (-sigma * t2 * t25 * t27 * t28 * t32 + t35 * sigma * t25 * t28 * t32);
+		
+		
+		Z=ZA;
+		
+		
+	} else {
+		
+		t5 = exp(kn * (zc - z));
+		t11 = exp(kn * (z - 0.1e1));
+		t13 = kn * kn;
+		t16 = sin(km * z);
+		t19 = km * km;
+		t21 = pow(t19 + t13, 0.2e1);
+		u1=u1b = kn * ((_C1B + z * _C3B) * t5 + (_C2B + z * _C4B) * t11 + sigma * t13 * t16 / ZB / t21);
+		
+		t7 = exp(kn * (zc - z));
+		t15 = exp(kn * (z - 0.1e1));
+		t17 = kn * kn;
+		t20 = cos(km * z);
+		t24 = km * km;
+		t26 = pow(t24 + t17, 0.2e1);
+		u2=u2b = ((_C1B + z * _C3B) * kn - _C3B) * t7 + (-_C4B - (_C2B + z * _C4B) * kn) * t15 - sigma * t17 * t20 * km / ZB / t26;
+		
+		t1 = ZB * kn;
+		t8 = exp(kn * (zc - z));
+		t17 = exp(kn * (z - 0.1e1));
+		t20 = kn * kn;
+		t24 = cos(km * z);
+		t26 = km * km;
+		t28 = pow(t26 + t20, 0.2e1);
+		u3=u3b = 0.2e1 * t1 * (-(_C1B + z * _C3B) * kn + _C3B) * t8 + 0.2e1 * t1 * (_C4B + (_C2B + z * _C4B) * kn) * t17 + 0.2e1 * t20 * kn * sigma * t24 * km / t28;
+		
+		t2 = kn * kn;
+		t11 = exp(kn * (zc - z));
+		t22 = exp(kn * (z - 0.1e1));
+		t26 = sin(km * z);
+		t28 = km * km;
+		t29 = 0.1e1 / ZB;
+		t32 = pow(t28 + t2, 0.2e1);
+		t33 = 0.1e1 / t32;
+		t36 = t2 * t2;
+		u4=u4b = -ZB * (-0.2e1 * _C3B * kn + 0.2e1 * t2 * (_C1B + z * _C3B)) * t11 - ZB * (0.2e1 * t2 * (_C2B + z * _C4B) + 0.2e1 * _C4B * kn) * t22 - ZB * (-sigma * t2 * t26 * t28 * t29 * t33 + t36 * sigma * t26 * t29 * t33);
+		
+		Z=ZB;
+	}
+	
+	
+	
+	pp = (double)-(u3 + 2.0*n*M_PI*Z*u2)*cos(n*M_PI*x); /* pressure */
+	
+	txx = (double)(u3 + 4*Z*n*M_PI*u2)*cos(n*M_PI*x); /* xx stress */
+	//printf( "() = %g\n", (u3 + 2.0*n*M_PI*Z*u2) );
+	//printf( "cos = %g\n", cos(n*M_PI*x) );
+	//printf( "pp = %g\n", pp );
+	sum5 += pp;
+	sum6 += txx;
+	
+	u1 *= cos(n*M_PI*x); /* z velocity */
+	sum1 += u1;
+	u2 *= sin(n*M_PI*x); /* x velocity */
+	sum2 += u2;
+	u3 *= cos(n*M_PI*x); /* zz stress */
+	sum3 += u3;
+	u4 *= sin(n*M_PI*x); /* zx stress */
+	sum4 += u4;
+	
+	rho = -sigma*sin(km*z)*cos(n*M_PI*x); /* density */
+	sum7 += rho;
+	
+	mag=sqrt(sum1*sum1+sum2*sum2);
+	/****************************************************/
+	/****************************************************/
+//	printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7);
+	
+	
+	/* Output */
+	if( vel != NULL ) {
+		vel[0] = sum2;
+		vel[1] = sum1;
+	}
+	if( presssure != NULL ) {
+		//printf( "pressure = %g\n", *presssure );
+		(*presssure) = sum5;
+	}
+	if( total_stress != NULL ) {
+		total_stress[0] = sum6;
+		total_stress[1] = sum3;
+		total_stress[2] = sum4;
+	}
+	if( strain_rate != NULL ) {
+		if( z<zc ) {
+			Z = ZA;
+		}
+		else {
+			Z = ZB;
+		}
+		strain_rate[0] = (sum6+sum5)/(2.0*Z);
+		strain_rate[1] = (sum3+sum5)/(2.0*Z);
+		strain_rate[2] = (sum4)/(2.0*Z);
+	}
+	/* Value checks, could be cleaned up if needed. Julian Giordani 9-Oct-2006*/
+        if( fabs( sum5 - ( -0.5*(sum6+sum3) ) ) > 1e-5 ) {
+                assert(0);
+        }
+	
+	
+	
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solF/Analytic_solF.c
--- a/SysTest/AnalyticPlugins/Velic_solF/Analytic_solF.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,164 +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:
-*+		Mirko Velic
-*+		Julian Giordani
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Patrick Sunter
-** $Id: solF.c 636 2006-09-08 03:07:06Z JulianGiordani $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include "Analytic_solF.h"
-
-const Type Velic_solF_Type = "Underworld_Velic_solF";
-
-void Velic_solF_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
-	Velic_solF* self = (Velic_solF*) analyticSolution;
-	
-	_Velic_solF( coord, self->sigma, self->etaA, self->etaB, self->xc, self->zc,
-		       	NULL, pressure, NULL, NULL );
-}
-
-void Velic_solF_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
-	Velic_solF* self = (Velic_solF*) analyticSolution;
-	
-	_Velic_solF( coord, self->sigma, self->etaA, self->etaB, self->xc, self->zc,
-		       	velocity, NULL, NULL, NULL );
-}
-
-void Velic_solF_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
-	Velic_solF* self = (Velic_solF*) analyticSolution;
-	
-	_Velic_solF( coord, self->sigma, self->etaA, self->etaB, self->xc, self->zc,
-		       	NULL, NULL, stress, NULL );
-}
-
-
-void Velic_solF_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
-	Velic_solF* self = (Velic_solF*) analyticSolution;
-	
-	_Velic_solF( coord, self->sigma, self->etaA, self->etaB, self->xc, self->zc,
-			NULL, NULL, NULL, strainRate );
-}
-
-void _Velic_solF_Init( Velic_solF* self, double sigma, double etaA, double etaB, double xc, double zc ) {
-	// TODO	Bool                     correctInput = True;
-	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
-        self->_getAnalyticVelocity    = Velic_solF_VelocityFunction;
-	self->_getAnalyticPressure    = Velic_solF_PressureFunction;
-	self->_getAnalyticTotalStress = Velic_solF_StressFunction;
-	self->_getAnalyticStrainRate  = Velic_solF_StrainRateFunction;
-
-	self->sigma = sigma;
-	self->etaA = etaA;
-	self->etaB = etaB;
-	self->xc = xc;
-	self->zc = zc;
-}
-
-void _Velic_solF_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
-	Velic_solF* self = (Velic_solF*) analyticSolution;
-	FeVariable*              velocityField;
-	FeVariable*              pressureField;
-	FeVariable*              stressField;
-	FeVariable*              strainRateField;
-	FeVariable*              recoveredStrainRateField;
-	FeVariable*              recoveredStressField;
- 	double                   sigma, etaA, etaB, xc, zc;
-
-	/* Construct Parent */
-	_AnalyticSolution_AssignFromXML( self, cf, data );
-
-	/* Create Analytic Fields */
-	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solF_VelocityFunction );
-
-	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solF_PressureFunction );
-
-	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False, data );
-	if ( stressField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solF_StressFunction );
-
-	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
-	if ( strainRateField   ) {
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solF_StrainRateFunction );
-	}
-
-	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
-	if ( recoveredStrainRateField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solF_StrainRateFunction );
-
-	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
-	if ( recoveredStressField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solF_StressFunction );
-
-	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solF_sigma", 1.0  );
-	etaA = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solF_etaA", 2.0  );
-	etaB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solF_etaB", 1.0  );
-	xc = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solF_xc", 0.25  );
-	zc = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solF_zc", 0.7  );
-
-	_Velic_solF_Init( self, sigma, etaA, etaB, xc, zc );
-	
-
-}
-
-void* _Velic_solF_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Velic_solF);
-	Type                                                      type = Velic_solF_Type;
-	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
-	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
-	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solF_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Velic_solF_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _AnalyticSolution_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 Underworld_Velic_solF_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Velic_solF_Type, (Name)"0", _Velic_solF_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solF/Analytic_solF.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solF/Analytic_solF.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,164 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Mirko Velic
+*+		Julian Giordani
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Patrick Sunter
+** $Id: solF.c 636 2006-09-08 03:07:06Z JulianGiordani $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include "Analytic_solF.h"
+
+const Type Velic_solF_Type = "Underworld_Velic_solF";
+
+void Velic_solF_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
+	Velic_solF* self = (Velic_solF*) analyticSolution;
+	
+	_Velic_solF( coord, self->sigma, self->etaA, self->etaB, self->xc, self->zc,
+		       	NULL, pressure, NULL, NULL );
+}
+
+void Velic_solF_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
+	Velic_solF* self = (Velic_solF*) analyticSolution;
+	
+	_Velic_solF( coord, self->sigma, self->etaA, self->etaB, self->xc, self->zc,
+		       	velocity, NULL, NULL, NULL );
+}
+
+void Velic_solF_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
+	Velic_solF* self = (Velic_solF*) analyticSolution;
+	
+	_Velic_solF( coord, self->sigma, self->etaA, self->etaB, self->xc, self->zc,
+		       	NULL, NULL, stress, NULL );
+}
+
+
+void Velic_solF_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
+	Velic_solF* self = (Velic_solF*) analyticSolution;
+	
+	_Velic_solF( coord, self->sigma, self->etaA, self->etaB, self->xc, self->zc,
+			NULL, NULL, NULL, strainRate );
+}
+
+void _Velic_solF_Init( Velic_solF* self, double sigma, double etaA, double etaB, double xc, double zc ) {
+	// TODO	Bool                     correctInput = True;
+	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
+        self->_getAnalyticVelocity    = Velic_solF_VelocityFunction;
+	self->_getAnalyticPressure    = Velic_solF_PressureFunction;
+	self->_getAnalyticTotalStress = Velic_solF_StressFunction;
+	self->_getAnalyticStrainRate  = Velic_solF_StrainRateFunction;
+
+	self->sigma = sigma;
+	self->etaA = etaA;
+	self->etaB = etaB;
+	self->xc = xc;
+	self->zc = zc;
+}
+
+void _Velic_solF_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
+	Velic_solF* self = (Velic_solF*) analyticSolution;
+	FeVariable*              velocityField;
+	FeVariable*              pressureField;
+	FeVariable*              stressField;
+	FeVariable*              strainRateField;
+	FeVariable*              recoveredStrainRateField;
+	FeVariable*              recoveredStressField;
+ 	double                   sigma, etaA, etaB, xc, zc;
+
+	/* Construct Parent */
+	_AnalyticSolution_AssignFromXML( self, cf, data );
+
+	/* Create Analytic Fields */
+	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solF_VelocityFunction );
+
+	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solF_PressureFunction );
+
+	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False, data );
+	if ( stressField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solF_StressFunction );
+
+	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
+	if ( strainRateField   ) {
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solF_StrainRateFunction );
+	}
+
+	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
+	if ( recoveredStrainRateField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solF_StrainRateFunction );
+
+	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
+	if ( recoveredStressField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solF_StressFunction );
+
+	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solF_sigma", 1.0  );
+	etaA = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solF_etaA", 2.0  );
+	etaB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solF_etaB", 1.0  );
+	xc = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solF_xc", 0.25  );
+	zc = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solF_zc", 0.7  );
+
+	_Velic_solF_Init( self, sigma, etaA, etaB, xc, zc );
+	
+
+}
+
+void* _Velic_solF_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Velic_solF);
+	Type                                                      type = Velic_solF_Type;
+	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
+	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
+	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solF_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Velic_solF_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _AnalyticSolution_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 Underworld_Velic_solF_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Velic_solF_Type, (Name)"0", _Velic_solF_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solF/solF.c
--- a/SysTest/AnalyticPlugins/Velic_solF/solF.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,717 +0,0 @@
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-
-
-void _Velic_solF( 
-		double pos[],
-		double _sigma,
-		double _eta_A, double _eta_B, 
-		double _x_c, double _z_c,
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] );
-
-
-
-int main( int argc, char **argv )
-{
-	int i,j;
-	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
-	double x,z;
-	
-	for (i=0;i<101;i++){
-		for(j=0;j<101;j++){
-			x = i/100.0;
-			z = j/100.0;
-			
-			pos[0] = x;
-			pos[1] = z;
-			_Velic_solF(
-					pos,
-					1.0,
-					2.0, 1.0,
-					0.25, 0.7,
-					vel, &pressure, total_stress, strain_rate );
-			
-			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
-					pos[0],pos[1],
-					vel[0],vel[1], pressure, 
-					total_stress[0], total_stress[1], total_stress[2], 
-					strain_rate[0], strain_rate[1], strain_rate[2] );
-		}
-		printf("\n");
-	}
-	
-	return 0;
-}
-
-
-
-void _Velic_solF(
-		double pos[],
-		double _sigma, /* density */
-		double _eta_A, double _eta_B, /* viscosity A, viscosity B */ 
-		double _x_c, double _z_c, /* width of dense block, bottom of dense block */
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] )
-{
-	double Z,ZA,ZB,u1,u2,u3,u4,pp,txx;
-	double u1a,u2a,u3a,u4a,u1b,u2b,u3b,u4b;
-	double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,x,z;
-	double sigma;
-	double del_rho;
-	int n;
-	double kn;
-	double _C1A,_C2A,_C3A,_C4A,_C1B,_C2B,_C3B,_C4B;
-	double xc,rho,zc;
-	
-	double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
-	double t11,t12,t13,t14,t15,t16,t17,t18,t19,t20;
-	double t21,t22,t23,t24,t25,t26,t27,t28,t29,t30;
-	double t31,t32,t33,t34,t35,t36,t37,t38,t39,t40;
-	double t41,t42,t43,t44,t45,t46,t47,t48,t49,t50;
-	double t51,t52,t53,t54,t55,t56,t57,t58,t59,t60;
-	double t61,t62,t63,t64,t65,t66,t67,t68,t69,t70;
-	double t71,t72,t73,t74,t75,t76,t77,t78,t79,t80;
-	double t81,t82,t83,t85,t86,t87,t88,t89,t90,t91;
-	double t92,t93,t94,t95,t96,t97,t98,t99,t100,t101;
-	double t102,t103,t104,t105,t106,t107,t108,t109,t111,t112;
-	double t113,t114,t115,t116,t117,t118,t120,t121,t122,t124;
-	double t125,t126,t127,t128,t129,t130,t131,t133,t134,t135;
-	double t136,t137,t139,t141,t143,t144,t145,t146,t147,t148;
-	double t151,t152,t153,t154,t156,t157,t158,t159,t162,t163;
-	double t165,t167,t168,t190,t195;
-	
-	/*************************************************************************/
-	/*************************************************************************/
-	/*
-	In layer B (the top layer) we have a dense column of density sigma
-	ranging from x=0 to x= xc:
-	The viscosity of layer B is ZB:
-	The viscosity of layer A is ZA:
-	
-	*/
-	/*************************************************************************/
-	/*************************************************************************/
-	
-	/*************************************************************************/
-	/*************************************************************************/
-	xc = _x_c;  /* */
-	sigma = _sigma; /* density parameter for layer B */
-	ZA = _eta_A;    /* viscosity for layer A */
-	ZB = _eta_B; /* viscosity for layer B */
-	zc = _z_c;  /* dividing line between region B and region A */
-	/*************************************************************************/
-	/*************************************************************************/
-	
-	x = pos[0];
-	z = pos[1];
-	
-	sum1=0.0;
-	sum2=0.0;
-	sum3=0.0;
-	sum4=0.0;
-	sum5=0.0;
-	sum6=0.0;
-	sum7=0.0;
-	/* this one blows up when n gets around 85 for some reason... if max n is set to 75 it is fine though */
-	/* fixed the convergence problem */
-	for(n=1;n<55;n++){
-		kn = (double) n*M_PI;
-		
-		/*******************************************/
-		/*            calculate del_rho            */
-		/*******************************************/
-		//del_rho = 4.0*sigma*cos(n*M_PI*x0)*sin(n*M_PI*dx/2.0)/n/M_PI;
-		del_rho = 2.0*sigma*sin(kn*xc)/kn;
-		
-		/*******************************************/
-		/*         calculate the constants         */
-		/*******************************************/
-		
-		if ( z < zc ) {
-			t1 = kn * zc;
-			t2 = 0.4e1 * t1;
-			t3 = kn * kn;
-			t5 = 0.2e1 * t3 * zc;
-			t6 = zc * zc;
-			t7 = t6 * t3;
-			t8 = 0.2e1 * t7;
-			t10 = ZA - ZB;
-			t12 = 0.2e1 * zc;
-			t15 = exp(-kn * (0.1e1 + t12));
-			t22 = exp(kn * (t12 - 0.3e1));
-			t26 = ZA + ZB;
-			t29 = exp(-0.3e1 * kn);
-			t34 = exp(-kn);
-			t37 = 0.3e1 * t1;
-			t40 = exp(-t37);
-			t44 = exp(-t1);
-			t50 = exp(kn * (zc - 0.4e1));
-			t54 = 0.2e1 * ZA * kn * zc;
-			t56 = 0.2e1 * ZB * kn;
-			t57 = 0.2e1 * ZA;
-			t58 = t3 * ZA;
-			t60 = 0.2e1 * t58 * zc;
-			t63 = 0.3e1 * ZB * zc * kn;
-			t64 = t3 * ZB;
-			t66 = 0.2e1 * t64 * zc;
-			t68 = 0.2e1 * t64 * t6;
-			t70 = 0.2e1 * t58 * t6;
-			t73 = kn * (zc - 0.2e1);
-			t74 = exp(t73);
-			t82 = exp(kn * (0.3e1 * zc - 0.4e1));
-			t87 = exp(-kn * (0.2e1 + zc));
-			t92 = t10 * t10;
-			t93 = t3 * t92;
-			t94 = exp(-t2);
-			t97 = t26 * t26;
-			t100 = exp(-0.4e1 * kn);
-			t103 = t3 * kn;
-			t104 = t103 * t10;
-			t105 = zc - 0.1e1;
-			t106 = t26 * t105;
-			t107 = kn * t105;
-			t109 = exp(0.2e1 * t107);
-			t114 = exp(0.4e1 * t107);
-			t117 = t103 * zc;
-			t118 = t10 * t26;
-			t120 = exp(0.2e1 * t73);
-			t124 = ZA * ZA;
-			t125 = t3 * t124;
-			t128 = ZB * ZB;
-			t136 = ZA * ZB;
-			t145 = exp(-0.2e1 * kn);
-			t151 = exp(-0.2e1 * kn * (0.1e1 + zc));
-			t156 = exp(-0.2e1 * t1);
-			t165 = -0.2e1 * t93 * t94 + 0.2e1 * t3 * t97 * t100 + 0.8e1 * t104 * t106 * t109 - 0.2e1 * t93 * t114 - 0.8e1 * t117 * t118 * t120 + 0.16e2 * t3 * (-0.2e1 * t125 * zc + 0.2e1 * t7 * t128 + 0.2e1 * t7 * t124 - 0.2e1 * t128 * zc * t3 - t136 - 0.4e1 * t7 * t136 + 0.4e1 * t64 * ZA * zc) * t145 - 0.8e1 * t104 * t106 * t151 + 0.8e1 * t117 * t118 * t156 + 0.4e1 * t64 * ZA + 0.2e1 * t3 * t128 + 0.2e1 * t125;
-			_C1A = (0.2e1 * (-t2 - t5 + t8 + 0.2e1 + kn) * t10 * t15 - 0.2e1 * (0.2e1 - t5 + t2 + t8 - kn) * t10 * t22 - 0.2e1 * (-0.2e1 + kn) * t26 * t29 - 0.2e1 * (kn + 0.2e1) * t26 * t34 + (t37 - 0.2e1) * t10 * t40 + (t1 + 0.2e1) * t26 * t44 + (t1 - 0.2e1) * t26 * t50 + 0.2e1 * (t54 + t56 + t57 - t60 - t63 + t66 - t68 + t70) * t74 + (t37 + 0.2e1) * t10 * t82 - 0.2e1 * (-t68 + t63 - t60 + t70 - t56 + t57 - t54 + t66) * t87) * del_rho / t165;
-			
-			t1 = kn * kn;
-			t3 = 0.2e1 * t1 * zc;
-			t4 = kn * zc;
-			t5 = 0.4e1 * t4;
-			t6 = zc * zc;
-			t7 = t6 * t1;
-			t8 = 0.2e1 * t7;
-			t10 = ZA - ZB;
-			t12 = zc - 0.1e1;
-			t13 = kn * t12;
-			t15 = exp(0.3e1 * t13);
-			t19 = ZA + ZB;
-			t24 = exp(0.2e1 * kn * (zc - 0.2e1));
-			t26 = t1 * ZB;
-			t28 = 0.2e1 * t26 * t6;
-			t30 = ZB * zc * kn;
-			t31 = 0.3e1 * t30;
-			t32 = t1 * ZA;
-			t34 = 0.2e1 * t32 * zc;
-			t36 = 0.2e1 * t32 * t6;
-			t38 = 0.2e1 * ZB * kn;
-			t39 = 0.2e1 * ZA;
-			t41 = ZA * kn * zc;
-			t42 = 0.2e1 * t41;
-			t44 = 0.2e1 * t26 * zc;
-			t47 = exp(-0.2e1 * kn);
-			t52 = exp(t13);
-			t57 = exp(0.2e1 * t13);
-			t64 = exp(kn * (zc - 0.3e1));
-			t67 = 0.3e1 * t4;
-			t71 = exp(-0.2e1 * t4);
-			t76 = kn * (0.1e1 + zc);
-			t77 = exp(-t76);
-			t83 = exp(0.4e1 * t13);
-			t86 = 0.2e1 * (0.2e1 - t3 + t5 + t8 - kn) * t10 * t15 - (t4 - 0.2e1) * t19 * t24 + 0.2e1 * (-t28 + t31 - t34 + t36 - t38 + t39 - t42 + t44) * t47 + 0.2e1 * (kn + 0.2e1) * t19 * t52 - 0.2e1 * (t42 + t38 + t39 - t34 - t31 + t44 - t28 + t36) * t57 + 0.2e1 * (-0.2e1 + kn) * t19 * t64 - (t67 - 0.2e1) * t10 * t71 - 0.2e1 * (-t5 - t3 + t8 + 0.2e1 + kn) * t10 * t77 - (t67 + 0.2e1) * t10 * t83 - 0.2e1 * ZB - t39 - t30 - t41;
-			t88 = t10 * t10;
-			t89 = t1 * t88;
-			t90 = exp(-t5);
-			t93 = t19 * t19;
-			t96 = exp(-0.4e1 * kn);
-			t99 = t1 * kn;
-			t100 = t99 * t10;
-			t101 = t19 * t12;
-			t107 = t99 * zc;
-			t108 = t10 * t19;
-			t112 = ZA * ZA;
-			t113 = t1 * t112;
-			t116 = ZB * ZB;
-			t124 = ZA * ZB;
-			t135 = exp(-0.2e1 * t76);
-			t147 = -0.2e1 * t89 * t90 + 0.2e1 * t1 * t93 * t96 + 0.8e1 * t100 * t101 * t57 - 0.2e1 * t89 * t83 - 0.8e1 * t107 * t108 * t24 + 0.16e2 * t1 * (-0.2e1 * t113 * zc + 0.2e1 * t7 * t116 + 0.2e1 * t7 * t112 - 0.2e1 * t116 * zc * t1 - t124 - 0.4e1 * t7 * t124 + 0.4e1 * t26 * ZA * zc) * t47 - 0.8e1 * t100 * t101 * t135 + 0.8e1 * t107 * t108 * t71 + 0.4e1 * t26 * ZA + 0.2e1 * t1 * t116 + 0.2e1 * t113;
-			_C2A = t86 * del_rho / t147;
-			
-			t1 = kn * zc;
-			t2 = 0.2e1 * t1;
-			t3 = 0.2e1 * kn;
-			t5 = ZA - ZB;
-			t7 = 0.2e1 * zc;
-			t10 = exp(-kn * (0.1e1 + t7));
-			t17 = exp(kn * (t7 - 0.3e1));
-			t20 = ZA + ZB;
-			t22 = exp(-0.3e1 * kn);
-			t25 = exp(-kn);
-			t29 = exp(-0.3e1 * t1);
-			t32 = exp(-t1);
-			t36 = exp(kn * (zc - 0.4e1));
-			t38 = ZA * kn;
-			t40 = 0.2e1 * t38 * zc;
-			t41 = 0.2e1 * t38;
-			t43 = 0.2e1 * ZB * kn;
-			t44 = 0.2e1 * ZA;
-			t47 = 0.2e1 * ZB * zc * kn;
-			t50 = kn * (zc - 0.2e1);
-			t51 = exp(t50);
-			t57 = exp(kn * (0.3e1 * zc - 0.4e1));
-			t63 = exp(-kn * (0.2e1 + zc));
-			t68 = t5 * t5;
-			t69 = kn * t68;
-			t71 = exp(-0.4e1 * t1);
-			t74 = t20 * t20;
-			t77 = exp(-0.4e1 * kn);
-			t80 = kn * kn;
-			t81 = t80 * t5;
-			t82 = zc - 0.1e1;
-			t83 = t20 * t82;
-			t87 = exp(-0.2e1 * kn * (0.1e1 + zc));
-			t91 = t80 * zc;
-			t92 = t5 * t20;
-			t94 = exp(0.2e1 * t50);
-			t98 = ZA * ZA;
-			t102 = zc * zc;
-			t103 = t102 * t80;
-			t104 = ZB * ZB;
-			t112 = ZA * ZB;
-			t121 = exp(-t3);
-			t124 = kn * t82;
-			t126 = exp(0.2e1 * t124);
-			t130 = exp(-t2);
-			t135 = exp(0.4e1 * t124);
-			t144 = -0.2e1 * t69 * t71 + 0.2e1 * t74 * kn * t77 - 0.8e1 * t81 * t83 * t87 - 0.8e1 * t91 * t92 * t94 + 0.16e2 * kn * (-0.2e1 * t80 * t98 * zc + 0.2e1 * t103 * t104 + 0.2e1 * t103 * t98 - 0.2e1 * t104 * zc * t80 - t112 - 0.4e1 * t103 * t112 + 0.4e1 * ZB * t80 * ZA * zc) * t121 + 0.8e1 * t81 * t83 * t126 + 0.8e1 * t91 * t92 * t130 - 0.2e1 * t69 * t135 + 0.2e1 * kn * t104 + 0.2e1 * t98 * kn + 0.4e1 * t112 * kn;
-			_C3A = (-0.2e1 * (t2 - 0.3e1 - t3) * t5 * t10 - 0.2e1 * (t2 + 0.3e1 - t3) * t5 * t17 + 0.2e1 * t20 * t22 - 0.2e1 * t20 * t25 - 0.3e1 * t5 * t29 + t20 * t32 - t20 * t36 + 0.2e1 * (t40 - t41 + t43 + t44 - ZB - t47) * t51 + 0.3e1 * t5 * t57 + 0.2e1 * (-t41 + t43 + ZB - t47 + t40 - t44) * t63) * del_rho / t144;
-			
-			t1 = ZA + ZB;
-			t5 = exp(0.2e1 * kn * (zc - 0.2e1));
-			t7 = ZA * kn;
-			t8 = 0.2e1 * t7;
-			t10 = 0.2e1 * ZB * kn;
-			t13 = 0.2e1 * ZB * zc * kn;
-			t15 = 0.2e1 * t7 * zc;
-			t16 = 0.2e1 * ZA;
-			t18 = 0.2e1 * kn;
-			t19 = exp(-t18);
-			t24 = exp(kn * (zc - 0.3e1));
-			t27 = kn * zc;
-			t28 = 0.2e1 * t27;
-			t30 = ZA - ZB;
-			t33 = kn * (0.1e1 + zc);
-			t34 = exp(-t33);
-			t38 = zc - 0.1e1;
-			t39 = kn * t38;
-			t41 = exp(0.2e1 * t39);
-			t47 = exp(0.3e1 * t39);
-			t50 = exp(-t28);
-			t53 = exp(t39);
-			t57 = exp(0.4e1 * t39);
-			t60 = -t1 * t5 + 0.2e1 * (-t8 + t10 + ZB - t13 + t15 - t16) * t19 + 0.2e1 * t1 * t24 - 0.2e1 * (t28 - 0.3e1 - t18) * t30 * t34 + 0.2e1 * (t15 - t8 + t10 + t16 - ZB - t13) * t41 - 0.2e1 * (t28 + 0.3e1 - t18) * t30 * t47 - 0.3e1 * t30 * t50 - 0.2e1 * t1 * t53 + 0.3e1 * t30 * t57 + ZA + ZB;
-			t62 = t30 * t30;
-			t63 = kn * t62;
-			t65 = exp(-0.4e1 * t27);
-			t68 = t1 * t1;
-			t71 = exp(-0.4e1 * kn);
-			t74 = kn * kn;
-			t75 = t74 * t30;
-			t76 = t1 * t38;
-			t78 = exp(-0.2e1 * t33);
-			t82 = t74 * zc;
-			t83 = t30 * t1;
-			t87 = ZA * ZA;
-			t91 = zc * zc;
-			t92 = t91 * t74;
-			t93 = ZB * ZB;
-			t101 = ZA * ZB;
-			t126 = -0.2e1 * t63 * t65 + 0.2e1 * t68 * kn * t71 - 0.8e1 * t75 * t76 * t78 - 0.8e1 * t82 * t83 * t5 + 0.16e2 * kn * (-0.2e1 * t74 * t87 * zc + 0.2e1 * t92 * t93 + 0.2e1 * t92 * t87 - 0.2e1 * t93 * zc * t74 - t101 - 0.4e1 * t92 * t101 + 0.4e1 * ZB * t74 * ZA * zc) * t19 + 0.8e1 * t75 * t76 * t41 + 0.8e1 * t82 * t83 * t50 - 0.2e1 * t63 * t57 + 0.2e1 * kn * t93 + 0.2e1 * t87 * kn + 0.4e1 * t101 * kn;
-			_C4A = t60 * del_rho / t126;
-		} else { 
-			t1 = ZA - ZB;
-			t2 = ZA * kn;
-			t4 = 0.2e1 * t2 * zc;
-			t5 = 0.2e1 * ZA;
-			t7 = ZB * zc * kn;
-			t10 = kn * zc;
-			t11 = 0.4e1 * t10;
-			t12 = exp(-t11);
-			t14 = ZA + ZB;
-			t15 = 0.4e1 * t2;
-			t17 = 0.2e1 * ZB * kn;
-			t21 = kn * (0.1e1 + zc);
-			t23 = exp(-0.2e1 * t21);
-			t25 = kn * kn;
-			t26 = ZA * ZA;
-			t28 = t25 * t26 * zc;
-			t30 = zc * zc;
-			t31 = t30 * t25;
-			t32 = t31 * t26;
-			t33 = 0.4e1 * t32;
-			t34 = ZB * t25;
-			t36 = t34 * ZA * zc;
-			t39 = t26 * zc * kn;
-			t40 = 0.4e1 * t39;
-			t41 = ZA * ZB;
-			t42 = t41 * kn;
-			t44 = ZB * ZB;
-			t45 = t44 * zc;
-			t46 = t45 * t25;
-			t48 = t41 * t10;
-			t49 = 0.3e1 * t48;
-			t50 = t31 * t44;
-			t51 = 0.2e1 * t50;
-			t52 = 0.2e1 * t41;
-			t53 = t31 * t41;
-			t54 = 0.6e1 * t53;
-			t57 = exp(-0.2e1 * kn);
-			t64 = (-t11 - 0.2e1 * t25 * zc + 0.2e1 * t31 + 0.2e1 + kn) * t1;
-			t68 = exp(-kn * (0.1e1 + 0.3e1 * zc));
-			t72 = -0.2e1 + kn;
-			t76 = exp(kn * (zc - 0.3e1));
-			t80 = t25 * kn;
-			t81 = t30 * t80;
-			t85 = t30 * zc;
-			t91 = t45 * kn;
-			t97 = 0.2e1 * t39;
-			t106 = -0.2e1 * t81 * t44 + 0.2e1 * t44 * t80 * t85 + 0.2e1 * t26 * t80 * t85 + t52 + t42 + 0.2e1 * t91 + 0.8e1 * t53 + 0.4e1 * t81 * t41 - 0.4e1 * t48 + t46 + t97 - 0.2e1 * t36 - t33 - 0.4e1 * t41 * t80 * t85 - 0.4e1 * t50 - 0.2e1 * t26 * t30 * t80 + t28;
-			t107 = exp(-t21);
-			t112 = zc - 0.1e1;
-			t113 = kn * t112;
-			t115 = exp(0.2e1 * t113);
-			t117 = t1 * t1;
-			t120 = exp(0.3e1 * t113);
-			t124 = exp(-0.2e1 * t10);
-			t127 = t14 * t14;
-			t131 = exp(-kn * (zc + 0.3e1));
-			t133 = exp(t113);
-			t137 = t1 * (t4 - t5 + t7) * t12 - t14 * (t5 + t4 - t15 - t7 + t17) * t23 + 0.2e1 * (-0.8e1 * t28 + t33 + 0.12e2 * t36 + t40 + 0.2e1 * t42 - 0.4e1 * t46 - t49 + t51 - t52 - t54) * t57 + t64 * t14 * t68 + 0.4e1 * t10 * t1 * t14 * t72 * t76 - 0.4e1 * t106 * t107 + t1 * (t5 + t4 - t15 + t7 - t17) * t115 + t117 * t72 * t120 - 0.2e1 * (t49 - t54 + t33 + t51 - t52 - t40) * t124 - t127 * t72 * t131 - t64 * t14 * t133 - t48 + 0.2e1 * t26 - t97 + t52 + t91;
-			t143 = exp(-0.4e1 * kn);
-			t148 = exp(0.4e1 * t113);
-			t152 = t80 * ZB;
-			t153 = t152 * zc;
-			t154 = t1 * t14;
-			t158 = exp(0.2e1 * kn * (zc - 0.2e1));
-			t162 = t152 * t1;
-			t163 = t14 * t112;
-			t190 = -0.2e1 * t34 * t117 * t12 + 0.2e1 * t34 * t127 * t143 - 0.2e1 * t34 * t117 * t148 - 0.8e1 * t153 * t154 * t158 - 0.8e1 * t162 * t163 * t23 + 0.16e2 * t34 * (-0.2e1 * t28 + t51 + 0.2e1 * t32 - 0.2e1 * t46 - t41 - 0.4e1 * t53 + 0.4e1 * t36) * t57 + 0.8e1 * t162 * t163 * t115 + 0.8e1 * t153 * t154 * t124 + 0.2e1 * t25 * t44 * ZB + 0.2e1 * t34 * t26 + 0.4e1 * t25 * t44 * ZA;
-			_C1B = t137 * del_rho / t190;
-			
-			t1 = ZA - ZB;
-			t2 = t1 * t1;
-			t3 = kn + 0.2e1;
-			t5 = kn * zc;
-			t6 = 0.4e1 * t5;
-			t7 = exp(-t6);
-			t9 = kn * kn;
-			t12 = zc * zc;
-			t13 = t12 * t9;
-			t16 = (0.2e1 - 0.2e1 * t9 * zc + t6 + 0.2e1 * t13 - kn) * t1;
-			t17 = ZA + ZB;
-			t19 = kn * (0.1e1 + zc);
-			t21 = exp(-0.2e1 * t19);
-			t24 = ZA * ZA;
-			t25 = t9 * kn;
-			t27 = t12 * zc;
-			t33 = ZA * ZB;
-			t37 = t12 * t25;
-			t40 = ZB * ZB;
-			t46 = t13 * t24;
-			t47 = 0.4e1 * t46;
-			t49 = t9 * t24 * zc;
-			t50 = t13 * t33;
-			t52 = ZB * t9;
-			t54 = t52 * ZA * zc;
-			t56 = t13 * t40;
-			t58 = t40 * zc;
-			t59 = t58 * t9;
-			t61 = t24 * zc * kn;
-			t63 = t33 * kn;
-			t64 = t33 * t5;
-			t68 = 0.2e1 * t33;
-			t69 = 0.2e1 * t24 * t25 * t27 - 0.2e1 * t24 * t12 * t25 - 0.4e1 * t33 * t25 * t27 + 0.4e1 * t37 * t33 + 0.2e1 * t40 * t25 * t27 - 0.2e1 * t37 * t40 + t47 - t49 - 0.8e1 * t50 + 0.2e1 * t54 + 0.4e1 * t56 - t59 + 0.2e1 * t61 + t63 - 0.4e1 * t64 + 0.2e1 * t58 * kn - t68;
-			t71 = exp(-0.2e1 * kn);
-			t74 = ZA * kn;
-			t75 = 0.4e1 * t74;
-			t77 = 0.2e1 * t74 * zc;
-			t78 = 0.2e1 * ZA;
-			t80 = ZB * zc * kn;
-			t82 = 0.2e1 * ZB * kn;
-			t88 = exp(-kn * (0.1e1 + 0.3e1 * zc));
-			t90 = 0.6e1 * t50;
-			t91 = 0.2e1 * t56;
-			t92 = 0.3e1 * t64;
-			t93 = 0.4e1 * t61;
-			t97 = exp(kn * (zc - 0.3e1));
-			t103 = 0.2e1 * t63;
-			t105 = exp(-t19);
-			t108 = zc - 0.1e1;
-			t109 = kn * t108;
-			t111 = exp(0.2e1 * t109);
-			t117 = exp(0.3e1 * t109);
-			t122 = exp(-0.2e1 * t5);
-			t130 = exp(-kn * (zc + 0.3e1));
-			t134 = exp(t109);
-			t141 = -t2 * t3 * t7 - t16 * t17 * t21 + 0.4e1 * t69 * t71 - t1 * (-t75 + t77 - t78 + t80 - t82) * t88 - 0.2e1 * (-t90 + t91 + t47 - t92 + t93 - t68) * t97 + 0.2e1 * (t47 - 0.8e1 * t49 - t90 + 0.12e2 * t54 - 0.4e1 * t59 + t91 - t93 - t103 + t92 - t68) * t105 + t16 * t17 * t111 - t1 * (t77 + t78 + t80) * t117 + 0.4e1 * t5 * t1 * t17 * t3 * t122 + t17 * (t77 + t78 - t80) * t130 + t17 * (-t75 + t77 - t78 - t80 + t82) * t134 + kn * t40 + t103 + 0.2e1 * t40 + t24 * kn + 0.2e1 * t24 + 0.4e1 * t33;
-			t146 = t17 * t17;
-			t148 = exp(-0.4e1 * kn);
-			t153 = exp(0.4e1 * t109);
-			t157 = ZB * t25;
-			t158 = t157 * zc;
-			t159 = t1 * t17;
-			t163 = exp(0.2e1 * kn * (zc - 0.2e1));
-			t167 = t157 * t1;
-			t168 = t17 * t108;
-			t195 = -0.2e1 * t52 * t2 * t7 + 0.2e1 * t52 * t146 * t148 - 0.2e1 * t52 * t2 * t153 - 0.8e1 * t158 * t159 * t163 - 0.8e1 * t167 * t168 * t21 + 0.16e2 * t52 * (-0.2e1 * t49 + t91 + 0.2e1 * t46 - 0.2e1 * t59 - t33 - 0.4e1 * t50 + 0.4e1 * t54) * t71 + 0.8e1 * t167 * t168 * t111 + 0.8e1 * t158 * t159 * t122 + 0.2e1 * t9 * t40 * ZB + 0.2e1 * t52 * t24 + 0.4e1 * t9 * t40 * ZA;
-			_C2B = t141 * del_rho / t195;
-			
-			t1 = 0.2e1 * ZA;
-			t3 = ZA - ZB;
-			t4 = (t1 + ZB) * t3;
-			t5 = kn * zc;
-			t7 = exp(-0.4e1 * t5);
-			t9 = ZA + ZB;
-			t13 = kn * (0.1e1 + zc);
-			t15 = exp(-0.2e1 * t13);
-			t17 = ZA * ZB;
-			t19 = 0.6e1 * t17 * t5;
-			t20 = ZB * ZB;
-			t21 = zc * t20;
-			t22 = t21 * kn;
-			t23 = 0.2e1 * t22;
-			t24 = ZA * ZA;
-			t26 = t24 * zc * kn;
-			t27 = 0.4e1 * t26;
-			t29 = 0.2e1 * kn;
-			t30 = exp(-t29);
-			t33 = t3 * t9;
-			t34 = 0.2e1 * t5;
-			t35 = t34 - 0.3e1 - t29;
-			t39 = exp(-kn * (0.1e1 + 0.3e1 * zc));
-			t44 = exp(kn * (zc - 0.3e1));
-			t48 = kn * kn;
-			t51 = 0.2e1 * t48 * t24 * zc;
-			t52 = zc * zc;
-			t53 = t52 * t48;
-			t55 = 0.2e1 * t53 * t24;
-			t56 = ZB * t48;
-			t59 = 0.4e1 * t56 * ZA * zc;
-			t61 = 0.4e1 * t53 * t17;
-			t63 = 0.2e1 * t21 * t48;
-			t65 = 0.2e1 * t53 * t20;
-			t69 = exp(-t13);
-			t72 = zc - 0.1e1;
-			t73 = kn * t72;
-			t75 = exp(0.2e1 * t73);
-			t77 = t3 * t3;
-			t79 = exp(0.3e1 * t73);
-			t82 = exp(-t34);
-			t85 = t9 * t9;
-			t88 = exp(-kn * (zc + 0.3e1));
-			t90 = exp(t73);
-			t94 = -t4 * t7 - t9 * (t1 - ZB) * t15 + 0.2e1 * (-t19 + t23 + t27 - t17) * t30 - t33 * t35 * t39 - 0.4e1 * t5 * t33 * t44 + 0.4e1 * (-t51 + t55 + t59 - t61 - t63 + t65 - 0.3e1 * t26 - 0.3e1 * t22 + t19 - t17) * t69 + t4 * t75 - t77 * t79 + 0.2e1 * (-t19 + t23 + t27 + t17) * t82 + t85 * t88 + t33 * t35 * t90 + 0.2e1 * t24 - t20 + t17;
-			t96 = ZB * kn;
-			t101 = exp(-0.4e1 * kn);
-			t105 = t56 * t3;
-			t106 = t9 * t72;
-			t117 = t56 * zc;
-			t121 = exp(0.2e1 * kn * (zc - 0.2e1));
-			t129 = exp(0.4e1 * t73);
-			t141 = -0.2e1 * t96 * t77 * t7 + 0.2e1 * t96 * t85 * t101 - 0.8e1 * t105 * t106 * t15 + 0.16e2 * t96 * (-t51 + t65 + t55 - t63 - t17 - t61 + t59) * t30 + 0.8e1 * t105 * t106 * t75 - 0.8e1 * t117 * t33 * t121 + 0.8e1 * t117 * t33 * t82 - 0.2e1 * t96 * t77 * t129 + 0.2e1 * t96 * t24 + 0.2e1 * t20 * ZB * kn + 0.4e1 * t20 * kn * ZA;
-			_C3B = t94 * del_rho / t141;
-			
-			t1 = ZA - ZB;
-			t2 = t1 * t1;
-			t3 = kn * zc;
-			t5 = exp(-0.4e1 * t3);
-			t6 = t2 * t5;
-			t7 = ZA + ZB;
-			t8 = t1 * t7;
-			t9 = 0.2e1 * t3;
-			t10 = 0.2e1 * kn;
-			t11 = t9 + 0.3e1 - t10;
-			t13 = kn * (0.1e1 + zc);
-			t15 = exp(-0.2e1 * t13);
-			t18 = ZA * ZB;
-			t20 = 0.6e1 * t18 * t3;
-			t21 = kn * kn;
-			t22 = ZB * t21;
-			t25 = 0.4e1 * t22 * ZA * zc;
-			t26 = ZB * ZB;
-			t27 = t26 * zc;
-			t29 = 0.2e1 * t27 * t21;
-			t30 = ZA * ZA;
-			t32 = t30 * zc * kn;
-			t34 = zc * zc;
-			t35 = t34 * t21;
-			t37 = 0.2e1 * t35 * t30;
-			t39 = 0.2e1 * t35 * t26;
-			t41 = 0.4e1 * t35 * t18;
-			t44 = 0.2e1 * t21 * t30 * zc;
-			t45 = t27 * kn;
-			t48 = exp(-t10);
-			t51 = 0.2e1 * ZA;
-			t53 = (t51 + ZB) * t1;
-			t57 = exp(-kn * (0.1e1 + 0.3e1 * zc));
-			t59 = 0.2e1 * t45;
-			t60 = 0.4e1 * t32;
-			t64 = exp(kn * (zc - 0.3e1));
-			t68 = exp(-t13);
-			t71 = zc - 0.1e1;
-			t72 = kn * t71;
-			t74 = exp(0.2e1 * t72);
-			t78 = exp(0.3e1 * t72);
-			t80 = exp(-t9);
-			t81 = t8 * t80;
-			t85 = t7 * (t51 - ZB);
-			t88 = exp(-kn * (zc + 0.3e1));
-			t90 = exp(t72);
-			t93 = t6 + t8 * t11 * t15 - 0.4e1 * (-t18 - t20 + t25 - t29 + 0.3e1 * t32 + t37 + t39 - t41 - t44 + 0.3e1 * t45) * t48 - t53 * t57 + 0.2e1 * (-t20 + t59 + t60 - t18) * t64 + 0.2e1 * (-t20 + t59 + t60 + t18) * t68 - t8 * t11 * t74 + t53 * t78 - 0.4e1 * t3 * t81 - t85 * t88 + t85 * t90 - 0.2e1 * t18 - t26 - t30;
-			t95 = ZB * kn;
-			t98 = t7 * t7;
-			t100 = exp(-0.4e1 * kn);
-			t104 = t22 * t1;
-			t105 = t7 * t71;
-			t116 = t22 * zc;
-			t120 = exp(0.2e1 * kn * (zc - 0.2e1));
-			t127 = exp(0.4e1 * t72);
-			t139 = -0.2e1 * t95 * t6 + 0.2e1 * t95 * t98 * t100 - 0.8e1 * t104 * t105 * t15 + 0.16e2 * t95 * (-t44 + t39 + t37 - t29 - t18 - t41 + t25) * t48 + 0.8e1 * t104 * t105 * t74 - 0.8e1 * t116 * t8 * t120 + 0.8e1 * t116 * t81 - 0.2e1 * t95 * t2 * t127 + 0.2e1 * t95 * t30 + 0.2e1 * t26 * ZB * kn + 0.4e1 * t26 * kn * ZA;
-			_C4B = t93 * del_rho / t139;
-			
-			
-		}
-		
-		/*******************************************/
-		/*       calculate the velocities etc      */
-		/*******************************************/
-		
-		if ( z < zc ) {
-			t4 = exp(-kn * z);
-			t10 = exp(kn * (z - zc));
-			u1=u1a = (_C1A + z * _C3A) * t4 + (_C2A + z * _C4A) * t10;
-			
-			t1 = kn * z;
-			t2 = exp(-t1);
-			t6 = exp(kn * (z - zc));
-			t10 = 0.1e1 / kn;
-			u2=u2a = t2 * _C1A - t6 * _C2A + t2 * (-0.1e1 + t1) * _C3A * t10 - t6 * (0.1e1 + t1) * _C4A * t10;
-			
-			t1 = ZA * kn;
-			t3 = exp(-kn * z);
-			t8 = exp(kn * (z - zc));
-			u3=u3a = -0.2e1 * t1 * t3 * _C1A + 0.2e1 * t1 * t8 * _C2A - 0.2e1 * t1 * t3 * z * _C3A + 0.2e1 * t1 * t8 * z * _C4A;
-			
-			t2 = kn * z;
-			t6 = exp(-t2);
-			t14 = exp(kn * (z - zc));
-			u4=u4a = -0.2e1 * ZA * (-_C3A + kn * _C1A + t2 * _C3A) * t6 - 0.2e1 * ZA * (_C4A + kn * _C2A + t2 * _C4A) * t14;
-			
-			Z=ZA;
-			del_rho = 0.0;
-			
-		} else {
-			t5 = exp(kn * (zc - z));
-			t11 = exp(kn * (z - 0.1e1));
-			t15 = kn * kn;
-			u1=u1b = (_C1B + z * _C3B) * t5 + (_C2B + z * _C4B) * t11 - del_rho / ZB / t15;
-			
-			t3 = exp(kn * (zc - z));
-			t7 = exp(kn * (z - 0.1e1));
-			t9 = kn * z;
-			t12 = 0.1e1 / kn;
-			u2=u2b = t3 * _C1B - t7 * _C2B + t3 * (-0.1e1 + t9) * _C3B * t12 - t7 * (0.1e1 + t9) * _C4B * t12;
-			
-			t1 = ZB * kn;
-			t4 = exp(kn * (zc - z));
-			t9 = exp(kn * (z - 0.1e1));
-			u3=u3b = -0.2e1 * t1 * t4 * _C1B + 0.2e1 * t1 * t9 * _C2B - 0.2e1 * t1 * t4 * z * _C3B + 0.2e1 * t1 * t9 * z * _C4B;
-			
-			t2 = kn * z;
-			t8 = exp(kn * (zc - z));
-			t17 = exp(kn * (z - 0.1e1));
-			u4=u4b = -0.2e1 * ZB * (-_C3B + kn * _C1B + t2 * _C3B) * t8 - 0.2e1 * ZB * (_C4B + kn * _C2B + t2 * _C4B) * t17 + 0.1e1 / kn * del_rho;
-			
-			Z=ZB;
-		}
-		
-		
-		
-		pp = (double)-(u3 + 2.0*n*M_PI*Z*u2)*cos(n*M_PI*x); /* pressure */
-		
-		txx = (double)(u3 + 4*Z*n*M_PI*u2)*cos(n*M_PI*x); /* xx stress */
-		sum5 += pp;
-		sum6 += txx;
-		
-		u1 *= cos(n*M_PI*x); /* z velocity */
-		sum1 += u1;
-		u2 *= sin(n*M_PI*x); /* x velocity */
-		sum2 += u2;
-		u3 *= cos(n*M_PI*x); /* zz stress */
-		sum3 += u3;
-		u4 *= sin(n*M_PI*x); /* zx stress */
-		sum4 += u4;
-		
-		rho = del_rho* cos(n*M_PI*x); /* density */
-		sum7 += rho;
-	}/* n */
-	
-	/* include terms for n=0 now */
-	if( z >= zc ){
-		del_rho = sigma*xc;
-		rho = del_rho; /* density */
-		sum7 += rho;
-		u3 = del_rho*(z-zc); /* zz stress */
-		sum3 += u3;
-		
-		txx = u3; /* xx stress */
-		pp = -u3; /* pressure */
-		sum5 += pp;
-		sum6 += txx;
-		
-	}
-	
-	mag=sqrt(sum1*sum1+sum2*sum2);
-	//printf("%0.7g %0.7g %0.7g %0.7g %0.7g %0.7g\n",x,y,z,sum3,sum2,sum1);
-	//printf("%0.7g %0.7g %0.7g\n%0.7g %0.7g %0.7g\n\n\n",x,y,z,x+sum3,y+sum2,z+sum1);
-	/*printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7);*/
-	
-	
-	/* Output */
-	if( vel != NULL ) {
-		vel[0] = sum2;
-		vel[1] = sum1;
-	}
-	if( presssure != NULL ) {
-		(*presssure) = sum5;
-	}
-	if( total_stress != NULL ) {
-		total_stress[0] = sum6;
-		total_stress[1] = sum3;
-		total_stress[2] = sum4;
-	}
-	if( strain_rate != NULL ) {
-		if( z<zc ) {
-			Z = ZA;
-		}
-		else {
-			Z = ZB;
-		}
-		strain_rate[0] = (sum6+sum5)/(2.0*Z);
-		strain_rate[1] = (sum3+sum5)/(2.0*Z);
-		strain_rate[2] = (sum4)/(2.0*Z);
-	}
-	/* Value checks, could be cleaned up if needed. Julian Giordani 9-Oct-2006*/
-        if( fabs( sum5 - ( -0.5*(sum6+sum3) ) ) > 1e-5 ) {
-                assert(0);
-        }
-	
-	
-	
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solF/solF.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solF/solF.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,717 @@
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+
+
+void _Velic_solF( 
+		double pos[],
+		double _sigma,
+		double _eta_A, double _eta_B, 
+		double _x_c, double _z_c,
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] );
+
+
+
+int main( int argc, char **argv )
+{
+	int i,j;
+	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
+	double x,z;
+	
+	for (i=0;i<101;i++){
+		for(j=0;j<101;j++){
+			x = i/100.0;
+			z = j/100.0;
+			
+			pos[0] = x;
+			pos[1] = z;
+			_Velic_solF(
+					pos,
+					1.0,
+					2.0, 1.0,
+					0.25, 0.7,
+					vel, &pressure, total_stress, strain_rate );
+			
+			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
+					pos[0],pos[1],
+					vel[0],vel[1], pressure, 
+					total_stress[0], total_stress[1], total_stress[2], 
+					strain_rate[0], strain_rate[1], strain_rate[2] );
+		}
+		printf("\n");
+	}
+	
+	return 0;
+}
+
+
+
+void _Velic_solF(
+		double pos[],
+		double _sigma, /* density */
+		double _eta_A, double _eta_B, /* viscosity A, viscosity B */ 
+		double _x_c, double _z_c, /* width of dense block, bottom of dense block */
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] )
+{
+	double Z,ZA,ZB,u1,u2,u3,u4,pp,txx;
+	double u1a,u2a,u3a,u4a,u1b,u2b,u3b,u4b;
+	double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,x,z;
+	double sigma;
+	double del_rho;
+	int n;
+	double kn;
+	double _C1A,_C2A,_C3A,_C4A,_C1B,_C2B,_C3B,_C4B;
+	double xc,rho,zc;
+	
+	double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
+	double t11,t12,t13,t14,t15,t16,t17,t18,t19,t20;
+	double t21,t22,t23,t24,t25,t26,t27,t28,t29,t30;
+	double t31,t32,t33,t34,t35,t36,t37,t38,t39,t40;
+	double t41,t42,t43,t44,t45,t46,t47,t48,t49,t50;
+	double t51,t52,t53,t54,t55,t56,t57,t58,t59,t60;
+	double t61,t62,t63,t64,t65,t66,t67,t68,t69,t70;
+	double t71,t72,t73,t74,t75,t76,t77,t78,t79,t80;
+	double t81,t82,t83,t85,t86,t87,t88,t89,t90,t91;
+	double t92,t93,t94,t95,t96,t97,t98,t99,t100,t101;
+	double t102,t103,t104,t105,t106,t107,t108,t109,t111,t112;
+	double t113,t114,t115,t116,t117,t118,t120,t121,t122,t124;
+	double t125,t126,t127,t128,t129,t130,t131,t133,t134,t135;
+	double t136,t137,t139,t141,t143,t144,t145,t146,t147,t148;
+	double t151,t152,t153,t154,t156,t157,t158,t159,t162,t163;
+	double t165,t167,t168,t190,t195;
+	
+	/*************************************************************************/
+	/*************************************************************************/
+	/*
+	In layer B (the top layer) we have a dense column of density sigma
+	ranging from x=0 to x= xc:
+	The viscosity of layer B is ZB:
+	The viscosity of layer A is ZA:
+	
+	*/
+	/*************************************************************************/
+	/*************************************************************************/
+	
+	/*************************************************************************/
+	/*************************************************************************/
+	xc = _x_c;  /* */
+	sigma = _sigma; /* density parameter for layer B */
+	ZA = _eta_A;    /* viscosity for layer A */
+	ZB = _eta_B; /* viscosity for layer B */
+	zc = _z_c;  /* dividing line between region B and region A */
+	/*************************************************************************/
+	/*************************************************************************/
+	
+	x = pos[0];
+	z = pos[1];
+	
+	sum1=0.0;
+	sum2=0.0;
+	sum3=0.0;
+	sum4=0.0;
+	sum5=0.0;
+	sum6=0.0;
+	sum7=0.0;
+	/* this one blows up when n gets around 85 for some reason... if max n is set to 75 it is fine though */
+	/* fixed the convergence problem */
+	for(n=1;n<55;n++){
+		kn = (double) n*M_PI;
+		
+		/*******************************************/
+		/*            calculate del_rho            */
+		/*******************************************/
+		//del_rho = 4.0*sigma*cos(n*M_PI*x0)*sin(n*M_PI*dx/2.0)/n/M_PI;
+		del_rho = 2.0*sigma*sin(kn*xc)/kn;
+		
+		/*******************************************/
+		/*         calculate the constants         */
+		/*******************************************/
+		
+		if ( z < zc ) {
+			t1 = kn * zc;
+			t2 = 0.4e1 * t1;
+			t3 = kn * kn;
+			t5 = 0.2e1 * t3 * zc;
+			t6 = zc * zc;
+			t7 = t6 * t3;
+			t8 = 0.2e1 * t7;
+			t10 = ZA - ZB;
+			t12 = 0.2e1 * zc;
+			t15 = exp(-kn * (0.1e1 + t12));
+			t22 = exp(kn * (t12 - 0.3e1));
+			t26 = ZA + ZB;
+			t29 = exp(-0.3e1 * kn);
+			t34 = exp(-kn);
+			t37 = 0.3e1 * t1;
+			t40 = exp(-t37);
+			t44 = exp(-t1);
+			t50 = exp(kn * (zc - 0.4e1));
+			t54 = 0.2e1 * ZA * kn * zc;
+			t56 = 0.2e1 * ZB * kn;
+			t57 = 0.2e1 * ZA;
+			t58 = t3 * ZA;
+			t60 = 0.2e1 * t58 * zc;
+			t63 = 0.3e1 * ZB * zc * kn;
+			t64 = t3 * ZB;
+			t66 = 0.2e1 * t64 * zc;
+			t68 = 0.2e1 * t64 * t6;
+			t70 = 0.2e1 * t58 * t6;
+			t73 = kn * (zc - 0.2e1);
+			t74 = exp(t73);
+			t82 = exp(kn * (0.3e1 * zc - 0.4e1));
+			t87 = exp(-kn * (0.2e1 + zc));
+			t92 = t10 * t10;
+			t93 = t3 * t92;
+			t94 = exp(-t2);
+			t97 = t26 * t26;
+			t100 = exp(-0.4e1 * kn);
+			t103 = t3 * kn;
+			t104 = t103 * t10;
+			t105 = zc - 0.1e1;
+			t106 = t26 * t105;
+			t107 = kn * t105;
+			t109 = exp(0.2e1 * t107);
+			t114 = exp(0.4e1 * t107);
+			t117 = t103 * zc;
+			t118 = t10 * t26;
+			t120 = exp(0.2e1 * t73);
+			t124 = ZA * ZA;
+			t125 = t3 * t124;
+			t128 = ZB * ZB;
+			t136 = ZA * ZB;
+			t145 = exp(-0.2e1 * kn);
+			t151 = exp(-0.2e1 * kn * (0.1e1 + zc));
+			t156 = exp(-0.2e1 * t1);
+			t165 = -0.2e1 * t93 * t94 + 0.2e1 * t3 * t97 * t100 + 0.8e1 * t104 * t106 * t109 - 0.2e1 * t93 * t114 - 0.8e1 * t117 * t118 * t120 + 0.16e2 * t3 * (-0.2e1 * t125 * zc + 0.2e1 * t7 * t128 + 0.2e1 * t7 * t124 - 0.2e1 * t128 * zc * t3 - t136 - 0.4e1 * t7 * t136 + 0.4e1 * t64 * ZA * zc) * t145 - 0.8e1 * t104 * t106 * t151 + 0.8e1 * t117 * t118 * t156 + 0.4e1 * t64 * ZA + 0.2e1 * t3 * t128 + 0.2e1 * t125;
+			_C1A = (0.2e1 * (-t2 - t5 + t8 + 0.2e1 + kn) * t10 * t15 - 0.2e1 * (0.2e1 - t5 + t2 + t8 - kn) * t10 * t22 - 0.2e1 * (-0.2e1 + kn) * t26 * t29 - 0.2e1 * (kn + 0.2e1) * t26 * t34 + (t37 - 0.2e1) * t10 * t40 + (t1 + 0.2e1) * t26 * t44 + (t1 - 0.2e1) * t26 * t50 + 0.2e1 * (t54 + t56 + t57 - t60 - t63 + t66 - t68 + t70) * t74 + (t37 + 0.2e1) * t10 * t82 - 0.2e1 * (-t68 + t63 - t60 + t70 - t56 + t57 - t54 + t66) * t87) * del_rho / t165;
+			
+			t1 = kn * kn;
+			t3 = 0.2e1 * t1 * zc;
+			t4 = kn * zc;
+			t5 = 0.4e1 * t4;
+			t6 = zc * zc;
+			t7 = t6 * t1;
+			t8 = 0.2e1 * t7;
+			t10 = ZA - ZB;
+			t12 = zc - 0.1e1;
+			t13 = kn * t12;
+			t15 = exp(0.3e1 * t13);
+			t19 = ZA + ZB;
+			t24 = exp(0.2e1 * kn * (zc - 0.2e1));
+			t26 = t1 * ZB;
+			t28 = 0.2e1 * t26 * t6;
+			t30 = ZB * zc * kn;
+			t31 = 0.3e1 * t30;
+			t32 = t1 * ZA;
+			t34 = 0.2e1 * t32 * zc;
+			t36 = 0.2e1 * t32 * t6;
+			t38 = 0.2e1 * ZB * kn;
+			t39 = 0.2e1 * ZA;
+			t41 = ZA * kn * zc;
+			t42 = 0.2e1 * t41;
+			t44 = 0.2e1 * t26 * zc;
+			t47 = exp(-0.2e1 * kn);
+			t52 = exp(t13);
+			t57 = exp(0.2e1 * t13);
+			t64 = exp(kn * (zc - 0.3e1));
+			t67 = 0.3e1 * t4;
+			t71 = exp(-0.2e1 * t4);
+			t76 = kn * (0.1e1 + zc);
+			t77 = exp(-t76);
+			t83 = exp(0.4e1 * t13);
+			t86 = 0.2e1 * (0.2e1 - t3 + t5 + t8 - kn) * t10 * t15 - (t4 - 0.2e1) * t19 * t24 + 0.2e1 * (-t28 + t31 - t34 + t36 - t38 + t39 - t42 + t44) * t47 + 0.2e1 * (kn + 0.2e1) * t19 * t52 - 0.2e1 * (t42 + t38 + t39 - t34 - t31 + t44 - t28 + t36) * t57 + 0.2e1 * (-0.2e1 + kn) * t19 * t64 - (t67 - 0.2e1) * t10 * t71 - 0.2e1 * (-t5 - t3 + t8 + 0.2e1 + kn) * t10 * t77 - (t67 + 0.2e1) * t10 * t83 - 0.2e1 * ZB - t39 - t30 - t41;
+			t88 = t10 * t10;
+			t89 = t1 * t88;
+			t90 = exp(-t5);
+			t93 = t19 * t19;
+			t96 = exp(-0.4e1 * kn);
+			t99 = t1 * kn;
+			t100 = t99 * t10;
+			t101 = t19 * t12;
+			t107 = t99 * zc;
+			t108 = t10 * t19;
+			t112 = ZA * ZA;
+			t113 = t1 * t112;
+			t116 = ZB * ZB;
+			t124 = ZA * ZB;
+			t135 = exp(-0.2e1 * t76);
+			t147 = -0.2e1 * t89 * t90 + 0.2e1 * t1 * t93 * t96 + 0.8e1 * t100 * t101 * t57 - 0.2e1 * t89 * t83 - 0.8e1 * t107 * t108 * t24 + 0.16e2 * t1 * (-0.2e1 * t113 * zc + 0.2e1 * t7 * t116 + 0.2e1 * t7 * t112 - 0.2e1 * t116 * zc * t1 - t124 - 0.4e1 * t7 * t124 + 0.4e1 * t26 * ZA * zc) * t47 - 0.8e1 * t100 * t101 * t135 + 0.8e1 * t107 * t108 * t71 + 0.4e1 * t26 * ZA + 0.2e1 * t1 * t116 + 0.2e1 * t113;
+			_C2A = t86 * del_rho / t147;
+			
+			t1 = kn * zc;
+			t2 = 0.2e1 * t1;
+			t3 = 0.2e1 * kn;
+			t5 = ZA - ZB;
+			t7 = 0.2e1 * zc;
+			t10 = exp(-kn * (0.1e1 + t7));
+			t17 = exp(kn * (t7 - 0.3e1));
+			t20 = ZA + ZB;
+			t22 = exp(-0.3e1 * kn);
+			t25 = exp(-kn);
+			t29 = exp(-0.3e1 * t1);
+			t32 = exp(-t1);
+			t36 = exp(kn * (zc - 0.4e1));
+			t38 = ZA * kn;
+			t40 = 0.2e1 * t38 * zc;
+			t41 = 0.2e1 * t38;
+			t43 = 0.2e1 * ZB * kn;
+			t44 = 0.2e1 * ZA;
+			t47 = 0.2e1 * ZB * zc * kn;
+			t50 = kn * (zc - 0.2e1);
+			t51 = exp(t50);
+			t57 = exp(kn * (0.3e1 * zc - 0.4e1));
+			t63 = exp(-kn * (0.2e1 + zc));
+			t68 = t5 * t5;
+			t69 = kn * t68;
+			t71 = exp(-0.4e1 * t1);
+			t74 = t20 * t20;
+			t77 = exp(-0.4e1 * kn);
+			t80 = kn * kn;
+			t81 = t80 * t5;
+			t82 = zc - 0.1e1;
+			t83 = t20 * t82;
+			t87 = exp(-0.2e1 * kn * (0.1e1 + zc));
+			t91 = t80 * zc;
+			t92 = t5 * t20;
+			t94 = exp(0.2e1 * t50);
+			t98 = ZA * ZA;
+			t102 = zc * zc;
+			t103 = t102 * t80;
+			t104 = ZB * ZB;
+			t112 = ZA * ZB;
+			t121 = exp(-t3);
+			t124 = kn * t82;
+			t126 = exp(0.2e1 * t124);
+			t130 = exp(-t2);
+			t135 = exp(0.4e1 * t124);
+			t144 = -0.2e1 * t69 * t71 + 0.2e1 * t74 * kn * t77 - 0.8e1 * t81 * t83 * t87 - 0.8e1 * t91 * t92 * t94 + 0.16e2 * kn * (-0.2e1 * t80 * t98 * zc + 0.2e1 * t103 * t104 + 0.2e1 * t103 * t98 - 0.2e1 * t104 * zc * t80 - t112 - 0.4e1 * t103 * t112 + 0.4e1 * ZB * t80 * ZA * zc) * t121 + 0.8e1 * t81 * t83 * t126 + 0.8e1 * t91 * t92 * t130 - 0.2e1 * t69 * t135 + 0.2e1 * kn * t104 + 0.2e1 * t98 * kn + 0.4e1 * t112 * kn;
+			_C3A = (-0.2e1 * (t2 - 0.3e1 - t3) * t5 * t10 - 0.2e1 * (t2 + 0.3e1 - t3) * t5 * t17 + 0.2e1 * t20 * t22 - 0.2e1 * t20 * t25 - 0.3e1 * t5 * t29 + t20 * t32 - t20 * t36 + 0.2e1 * (t40 - t41 + t43 + t44 - ZB - t47) * t51 + 0.3e1 * t5 * t57 + 0.2e1 * (-t41 + t43 + ZB - t47 + t40 - t44) * t63) * del_rho / t144;
+			
+			t1 = ZA + ZB;
+			t5 = exp(0.2e1 * kn * (zc - 0.2e1));
+			t7 = ZA * kn;
+			t8 = 0.2e1 * t7;
+			t10 = 0.2e1 * ZB * kn;
+			t13 = 0.2e1 * ZB * zc * kn;
+			t15 = 0.2e1 * t7 * zc;
+			t16 = 0.2e1 * ZA;
+			t18 = 0.2e1 * kn;
+			t19 = exp(-t18);
+			t24 = exp(kn * (zc - 0.3e1));
+			t27 = kn * zc;
+			t28 = 0.2e1 * t27;
+			t30 = ZA - ZB;
+			t33 = kn * (0.1e1 + zc);
+			t34 = exp(-t33);
+			t38 = zc - 0.1e1;
+			t39 = kn * t38;
+			t41 = exp(0.2e1 * t39);
+			t47 = exp(0.3e1 * t39);
+			t50 = exp(-t28);
+			t53 = exp(t39);
+			t57 = exp(0.4e1 * t39);
+			t60 = -t1 * t5 + 0.2e1 * (-t8 + t10 + ZB - t13 + t15 - t16) * t19 + 0.2e1 * t1 * t24 - 0.2e1 * (t28 - 0.3e1 - t18) * t30 * t34 + 0.2e1 * (t15 - t8 + t10 + t16 - ZB - t13) * t41 - 0.2e1 * (t28 + 0.3e1 - t18) * t30 * t47 - 0.3e1 * t30 * t50 - 0.2e1 * t1 * t53 + 0.3e1 * t30 * t57 + ZA + ZB;
+			t62 = t30 * t30;
+			t63 = kn * t62;
+			t65 = exp(-0.4e1 * t27);
+			t68 = t1 * t1;
+			t71 = exp(-0.4e1 * kn);
+			t74 = kn * kn;
+			t75 = t74 * t30;
+			t76 = t1 * t38;
+			t78 = exp(-0.2e1 * t33);
+			t82 = t74 * zc;
+			t83 = t30 * t1;
+			t87 = ZA * ZA;
+			t91 = zc * zc;
+			t92 = t91 * t74;
+			t93 = ZB * ZB;
+			t101 = ZA * ZB;
+			t126 = -0.2e1 * t63 * t65 + 0.2e1 * t68 * kn * t71 - 0.8e1 * t75 * t76 * t78 - 0.8e1 * t82 * t83 * t5 + 0.16e2 * kn * (-0.2e1 * t74 * t87 * zc + 0.2e1 * t92 * t93 + 0.2e1 * t92 * t87 - 0.2e1 * t93 * zc * t74 - t101 - 0.4e1 * t92 * t101 + 0.4e1 * ZB * t74 * ZA * zc) * t19 + 0.8e1 * t75 * t76 * t41 + 0.8e1 * t82 * t83 * t50 - 0.2e1 * t63 * t57 + 0.2e1 * kn * t93 + 0.2e1 * t87 * kn + 0.4e1 * t101 * kn;
+			_C4A = t60 * del_rho / t126;
+		} else { 
+			t1 = ZA - ZB;
+			t2 = ZA * kn;
+			t4 = 0.2e1 * t2 * zc;
+			t5 = 0.2e1 * ZA;
+			t7 = ZB * zc * kn;
+			t10 = kn * zc;
+			t11 = 0.4e1 * t10;
+			t12 = exp(-t11);
+			t14 = ZA + ZB;
+			t15 = 0.4e1 * t2;
+			t17 = 0.2e1 * ZB * kn;
+			t21 = kn * (0.1e1 + zc);
+			t23 = exp(-0.2e1 * t21);
+			t25 = kn * kn;
+			t26 = ZA * ZA;
+			t28 = t25 * t26 * zc;
+			t30 = zc * zc;
+			t31 = t30 * t25;
+			t32 = t31 * t26;
+			t33 = 0.4e1 * t32;
+			t34 = ZB * t25;
+			t36 = t34 * ZA * zc;
+			t39 = t26 * zc * kn;
+			t40 = 0.4e1 * t39;
+			t41 = ZA * ZB;
+			t42 = t41 * kn;
+			t44 = ZB * ZB;
+			t45 = t44 * zc;
+			t46 = t45 * t25;
+			t48 = t41 * t10;
+			t49 = 0.3e1 * t48;
+			t50 = t31 * t44;
+			t51 = 0.2e1 * t50;
+			t52 = 0.2e1 * t41;
+			t53 = t31 * t41;
+			t54 = 0.6e1 * t53;
+			t57 = exp(-0.2e1 * kn);
+			t64 = (-t11 - 0.2e1 * t25 * zc + 0.2e1 * t31 + 0.2e1 + kn) * t1;
+			t68 = exp(-kn * (0.1e1 + 0.3e1 * zc));
+			t72 = -0.2e1 + kn;
+			t76 = exp(kn * (zc - 0.3e1));
+			t80 = t25 * kn;
+			t81 = t30 * t80;
+			t85 = t30 * zc;
+			t91 = t45 * kn;
+			t97 = 0.2e1 * t39;
+			t106 = -0.2e1 * t81 * t44 + 0.2e1 * t44 * t80 * t85 + 0.2e1 * t26 * t80 * t85 + t52 + t42 + 0.2e1 * t91 + 0.8e1 * t53 + 0.4e1 * t81 * t41 - 0.4e1 * t48 + t46 + t97 - 0.2e1 * t36 - t33 - 0.4e1 * t41 * t80 * t85 - 0.4e1 * t50 - 0.2e1 * t26 * t30 * t80 + t28;
+			t107 = exp(-t21);
+			t112 = zc - 0.1e1;
+			t113 = kn * t112;
+			t115 = exp(0.2e1 * t113);
+			t117 = t1 * t1;
+			t120 = exp(0.3e1 * t113);
+			t124 = exp(-0.2e1 * t10);
+			t127 = t14 * t14;
+			t131 = exp(-kn * (zc + 0.3e1));
+			t133 = exp(t113);
+			t137 = t1 * (t4 - t5 + t7) * t12 - t14 * (t5 + t4 - t15 - t7 + t17) * t23 + 0.2e1 * (-0.8e1 * t28 + t33 + 0.12e2 * t36 + t40 + 0.2e1 * t42 - 0.4e1 * t46 - t49 + t51 - t52 - t54) * t57 + t64 * t14 * t68 + 0.4e1 * t10 * t1 * t14 * t72 * t76 - 0.4e1 * t106 * t107 + t1 * (t5 + t4 - t15 + t7 - t17) * t115 + t117 * t72 * t120 - 0.2e1 * (t49 - t54 + t33 + t51 - t52 - t40) * t124 - t127 * t72 * t131 - t64 * t14 * t133 - t48 + 0.2e1 * t26 - t97 + t52 + t91;
+			t143 = exp(-0.4e1 * kn);
+			t148 = exp(0.4e1 * t113);
+			t152 = t80 * ZB;
+			t153 = t152 * zc;
+			t154 = t1 * t14;
+			t158 = exp(0.2e1 * kn * (zc - 0.2e1));
+			t162 = t152 * t1;
+			t163 = t14 * t112;
+			t190 = -0.2e1 * t34 * t117 * t12 + 0.2e1 * t34 * t127 * t143 - 0.2e1 * t34 * t117 * t148 - 0.8e1 * t153 * t154 * t158 - 0.8e1 * t162 * t163 * t23 + 0.16e2 * t34 * (-0.2e1 * t28 + t51 + 0.2e1 * t32 - 0.2e1 * t46 - t41 - 0.4e1 * t53 + 0.4e1 * t36) * t57 + 0.8e1 * t162 * t163 * t115 + 0.8e1 * t153 * t154 * t124 + 0.2e1 * t25 * t44 * ZB + 0.2e1 * t34 * t26 + 0.4e1 * t25 * t44 * ZA;
+			_C1B = t137 * del_rho / t190;
+			
+			t1 = ZA - ZB;
+			t2 = t1 * t1;
+			t3 = kn + 0.2e1;
+			t5 = kn * zc;
+			t6 = 0.4e1 * t5;
+			t7 = exp(-t6);
+			t9 = kn * kn;
+			t12 = zc * zc;
+			t13 = t12 * t9;
+			t16 = (0.2e1 - 0.2e1 * t9 * zc + t6 + 0.2e1 * t13 - kn) * t1;
+			t17 = ZA + ZB;
+			t19 = kn * (0.1e1 + zc);
+			t21 = exp(-0.2e1 * t19);
+			t24 = ZA * ZA;
+			t25 = t9 * kn;
+			t27 = t12 * zc;
+			t33 = ZA * ZB;
+			t37 = t12 * t25;
+			t40 = ZB * ZB;
+			t46 = t13 * t24;
+			t47 = 0.4e1 * t46;
+			t49 = t9 * t24 * zc;
+			t50 = t13 * t33;
+			t52 = ZB * t9;
+			t54 = t52 * ZA * zc;
+			t56 = t13 * t40;
+			t58 = t40 * zc;
+			t59 = t58 * t9;
+			t61 = t24 * zc * kn;
+			t63 = t33 * kn;
+			t64 = t33 * t5;
+			t68 = 0.2e1 * t33;
+			t69 = 0.2e1 * t24 * t25 * t27 - 0.2e1 * t24 * t12 * t25 - 0.4e1 * t33 * t25 * t27 + 0.4e1 * t37 * t33 + 0.2e1 * t40 * t25 * t27 - 0.2e1 * t37 * t40 + t47 - t49 - 0.8e1 * t50 + 0.2e1 * t54 + 0.4e1 * t56 - t59 + 0.2e1 * t61 + t63 - 0.4e1 * t64 + 0.2e1 * t58 * kn - t68;
+			t71 = exp(-0.2e1 * kn);
+			t74 = ZA * kn;
+			t75 = 0.4e1 * t74;
+			t77 = 0.2e1 * t74 * zc;
+			t78 = 0.2e1 * ZA;
+			t80 = ZB * zc * kn;
+			t82 = 0.2e1 * ZB * kn;
+			t88 = exp(-kn * (0.1e1 + 0.3e1 * zc));
+			t90 = 0.6e1 * t50;
+			t91 = 0.2e1 * t56;
+			t92 = 0.3e1 * t64;
+			t93 = 0.4e1 * t61;
+			t97 = exp(kn * (zc - 0.3e1));
+			t103 = 0.2e1 * t63;
+			t105 = exp(-t19);
+			t108 = zc - 0.1e1;
+			t109 = kn * t108;
+			t111 = exp(0.2e1 * t109);
+			t117 = exp(0.3e1 * t109);
+			t122 = exp(-0.2e1 * t5);
+			t130 = exp(-kn * (zc + 0.3e1));
+			t134 = exp(t109);
+			t141 = -t2 * t3 * t7 - t16 * t17 * t21 + 0.4e1 * t69 * t71 - t1 * (-t75 + t77 - t78 + t80 - t82) * t88 - 0.2e1 * (-t90 + t91 + t47 - t92 + t93 - t68) * t97 + 0.2e1 * (t47 - 0.8e1 * t49 - t90 + 0.12e2 * t54 - 0.4e1 * t59 + t91 - t93 - t103 + t92 - t68) * t105 + t16 * t17 * t111 - t1 * (t77 + t78 + t80) * t117 + 0.4e1 * t5 * t1 * t17 * t3 * t122 + t17 * (t77 + t78 - t80) * t130 + t17 * (-t75 + t77 - t78 - t80 + t82) * t134 + kn * t40 + t103 + 0.2e1 * t40 + t24 * kn + 0.2e1 * t24 + 0.4e1 * t33;
+			t146 = t17 * t17;
+			t148 = exp(-0.4e1 * kn);
+			t153 = exp(0.4e1 * t109);
+			t157 = ZB * t25;
+			t158 = t157 * zc;
+			t159 = t1 * t17;
+			t163 = exp(0.2e1 * kn * (zc - 0.2e1));
+			t167 = t157 * t1;
+			t168 = t17 * t108;
+			t195 = -0.2e1 * t52 * t2 * t7 + 0.2e1 * t52 * t146 * t148 - 0.2e1 * t52 * t2 * t153 - 0.8e1 * t158 * t159 * t163 - 0.8e1 * t167 * t168 * t21 + 0.16e2 * t52 * (-0.2e1 * t49 + t91 + 0.2e1 * t46 - 0.2e1 * t59 - t33 - 0.4e1 * t50 + 0.4e1 * t54) * t71 + 0.8e1 * t167 * t168 * t111 + 0.8e1 * t158 * t159 * t122 + 0.2e1 * t9 * t40 * ZB + 0.2e1 * t52 * t24 + 0.4e1 * t9 * t40 * ZA;
+			_C2B = t141 * del_rho / t195;
+			
+			t1 = 0.2e1 * ZA;
+			t3 = ZA - ZB;
+			t4 = (t1 + ZB) * t3;
+			t5 = kn * zc;
+			t7 = exp(-0.4e1 * t5);
+			t9 = ZA + ZB;
+			t13 = kn * (0.1e1 + zc);
+			t15 = exp(-0.2e1 * t13);
+			t17 = ZA * ZB;
+			t19 = 0.6e1 * t17 * t5;
+			t20 = ZB * ZB;
+			t21 = zc * t20;
+			t22 = t21 * kn;
+			t23 = 0.2e1 * t22;
+			t24 = ZA * ZA;
+			t26 = t24 * zc * kn;
+			t27 = 0.4e1 * t26;
+			t29 = 0.2e1 * kn;
+			t30 = exp(-t29);
+			t33 = t3 * t9;
+			t34 = 0.2e1 * t5;
+			t35 = t34 - 0.3e1 - t29;
+			t39 = exp(-kn * (0.1e1 + 0.3e1 * zc));
+			t44 = exp(kn * (zc - 0.3e1));
+			t48 = kn * kn;
+			t51 = 0.2e1 * t48 * t24 * zc;
+			t52 = zc * zc;
+			t53 = t52 * t48;
+			t55 = 0.2e1 * t53 * t24;
+			t56 = ZB * t48;
+			t59 = 0.4e1 * t56 * ZA * zc;
+			t61 = 0.4e1 * t53 * t17;
+			t63 = 0.2e1 * t21 * t48;
+			t65 = 0.2e1 * t53 * t20;
+			t69 = exp(-t13);
+			t72 = zc - 0.1e1;
+			t73 = kn * t72;
+			t75 = exp(0.2e1 * t73);
+			t77 = t3 * t3;
+			t79 = exp(0.3e1 * t73);
+			t82 = exp(-t34);
+			t85 = t9 * t9;
+			t88 = exp(-kn * (zc + 0.3e1));
+			t90 = exp(t73);
+			t94 = -t4 * t7 - t9 * (t1 - ZB) * t15 + 0.2e1 * (-t19 + t23 + t27 - t17) * t30 - t33 * t35 * t39 - 0.4e1 * t5 * t33 * t44 + 0.4e1 * (-t51 + t55 + t59 - t61 - t63 + t65 - 0.3e1 * t26 - 0.3e1 * t22 + t19 - t17) * t69 + t4 * t75 - t77 * t79 + 0.2e1 * (-t19 + t23 + t27 + t17) * t82 + t85 * t88 + t33 * t35 * t90 + 0.2e1 * t24 - t20 + t17;
+			t96 = ZB * kn;
+			t101 = exp(-0.4e1 * kn);
+			t105 = t56 * t3;
+			t106 = t9 * t72;
+			t117 = t56 * zc;
+			t121 = exp(0.2e1 * kn * (zc - 0.2e1));
+			t129 = exp(0.4e1 * t73);
+			t141 = -0.2e1 * t96 * t77 * t7 + 0.2e1 * t96 * t85 * t101 - 0.8e1 * t105 * t106 * t15 + 0.16e2 * t96 * (-t51 + t65 + t55 - t63 - t17 - t61 + t59) * t30 + 0.8e1 * t105 * t106 * t75 - 0.8e1 * t117 * t33 * t121 + 0.8e1 * t117 * t33 * t82 - 0.2e1 * t96 * t77 * t129 + 0.2e1 * t96 * t24 + 0.2e1 * t20 * ZB * kn + 0.4e1 * t20 * kn * ZA;
+			_C3B = t94 * del_rho / t141;
+			
+			t1 = ZA - ZB;
+			t2 = t1 * t1;
+			t3 = kn * zc;
+			t5 = exp(-0.4e1 * t3);
+			t6 = t2 * t5;
+			t7 = ZA + ZB;
+			t8 = t1 * t7;
+			t9 = 0.2e1 * t3;
+			t10 = 0.2e1 * kn;
+			t11 = t9 + 0.3e1 - t10;
+			t13 = kn * (0.1e1 + zc);
+			t15 = exp(-0.2e1 * t13);
+			t18 = ZA * ZB;
+			t20 = 0.6e1 * t18 * t3;
+			t21 = kn * kn;
+			t22 = ZB * t21;
+			t25 = 0.4e1 * t22 * ZA * zc;
+			t26 = ZB * ZB;
+			t27 = t26 * zc;
+			t29 = 0.2e1 * t27 * t21;
+			t30 = ZA * ZA;
+			t32 = t30 * zc * kn;
+			t34 = zc * zc;
+			t35 = t34 * t21;
+			t37 = 0.2e1 * t35 * t30;
+			t39 = 0.2e1 * t35 * t26;
+			t41 = 0.4e1 * t35 * t18;
+			t44 = 0.2e1 * t21 * t30 * zc;
+			t45 = t27 * kn;
+			t48 = exp(-t10);
+			t51 = 0.2e1 * ZA;
+			t53 = (t51 + ZB) * t1;
+			t57 = exp(-kn * (0.1e1 + 0.3e1 * zc));
+			t59 = 0.2e1 * t45;
+			t60 = 0.4e1 * t32;
+			t64 = exp(kn * (zc - 0.3e1));
+			t68 = exp(-t13);
+			t71 = zc - 0.1e1;
+			t72 = kn * t71;
+			t74 = exp(0.2e1 * t72);
+			t78 = exp(0.3e1 * t72);
+			t80 = exp(-t9);
+			t81 = t8 * t80;
+			t85 = t7 * (t51 - ZB);
+			t88 = exp(-kn * (zc + 0.3e1));
+			t90 = exp(t72);
+			t93 = t6 + t8 * t11 * t15 - 0.4e1 * (-t18 - t20 + t25 - t29 + 0.3e1 * t32 + t37 + t39 - t41 - t44 + 0.3e1 * t45) * t48 - t53 * t57 + 0.2e1 * (-t20 + t59 + t60 - t18) * t64 + 0.2e1 * (-t20 + t59 + t60 + t18) * t68 - t8 * t11 * t74 + t53 * t78 - 0.4e1 * t3 * t81 - t85 * t88 + t85 * t90 - 0.2e1 * t18 - t26 - t30;
+			t95 = ZB * kn;
+			t98 = t7 * t7;
+			t100 = exp(-0.4e1 * kn);
+			t104 = t22 * t1;
+			t105 = t7 * t71;
+			t116 = t22 * zc;
+			t120 = exp(0.2e1 * kn * (zc - 0.2e1));
+			t127 = exp(0.4e1 * t72);
+			t139 = -0.2e1 * t95 * t6 + 0.2e1 * t95 * t98 * t100 - 0.8e1 * t104 * t105 * t15 + 0.16e2 * t95 * (-t44 + t39 + t37 - t29 - t18 - t41 + t25) * t48 + 0.8e1 * t104 * t105 * t74 - 0.8e1 * t116 * t8 * t120 + 0.8e1 * t116 * t81 - 0.2e1 * t95 * t2 * t127 + 0.2e1 * t95 * t30 + 0.2e1 * t26 * ZB * kn + 0.4e1 * t26 * kn * ZA;
+			_C4B = t93 * del_rho / t139;
+			
+			
+		}
+		
+		/*******************************************/
+		/*       calculate the velocities etc      */
+		/*******************************************/
+		
+		if ( z < zc ) {
+			t4 = exp(-kn * z);
+			t10 = exp(kn * (z - zc));
+			u1=u1a = (_C1A + z * _C3A) * t4 + (_C2A + z * _C4A) * t10;
+			
+			t1 = kn * z;
+			t2 = exp(-t1);
+			t6 = exp(kn * (z - zc));
+			t10 = 0.1e1 / kn;
+			u2=u2a = t2 * _C1A - t6 * _C2A + t2 * (-0.1e1 + t1) * _C3A * t10 - t6 * (0.1e1 + t1) * _C4A * t10;
+			
+			t1 = ZA * kn;
+			t3 = exp(-kn * z);
+			t8 = exp(kn * (z - zc));
+			u3=u3a = -0.2e1 * t1 * t3 * _C1A + 0.2e1 * t1 * t8 * _C2A - 0.2e1 * t1 * t3 * z * _C3A + 0.2e1 * t1 * t8 * z * _C4A;
+			
+			t2 = kn * z;
+			t6 = exp(-t2);
+			t14 = exp(kn * (z - zc));
+			u4=u4a = -0.2e1 * ZA * (-_C3A + kn * _C1A + t2 * _C3A) * t6 - 0.2e1 * ZA * (_C4A + kn * _C2A + t2 * _C4A) * t14;
+			
+			Z=ZA;
+			del_rho = 0.0;
+			
+		} else {
+			t5 = exp(kn * (zc - z));
+			t11 = exp(kn * (z - 0.1e1));
+			t15 = kn * kn;
+			u1=u1b = (_C1B + z * _C3B) * t5 + (_C2B + z * _C4B) * t11 - del_rho / ZB / t15;
+			
+			t3 = exp(kn * (zc - z));
+			t7 = exp(kn * (z - 0.1e1));
+			t9 = kn * z;
+			t12 = 0.1e1 / kn;
+			u2=u2b = t3 * _C1B - t7 * _C2B + t3 * (-0.1e1 + t9) * _C3B * t12 - t7 * (0.1e1 + t9) * _C4B * t12;
+			
+			t1 = ZB * kn;
+			t4 = exp(kn * (zc - z));
+			t9 = exp(kn * (z - 0.1e1));
+			u3=u3b = -0.2e1 * t1 * t4 * _C1B + 0.2e1 * t1 * t9 * _C2B - 0.2e1 * t1 * t4 * z * _C3B + 0.2e1 * t1 * t9 * z * _C4B;
+			
+			t2 = kn * z;
+			t8 = exp(kn * (zc - z));
+			t17 = exp(kn * (z - 0.1e1));
+			u4=u4b = -0.2e1 * ZB * (-_C3B + kn * _C1B + t2 * _C3B) * t8 - 0.2e1 * ZB * (_C4B + kn * _C2B + t2 * _C4B) * t17 + 0.1e1 / kn * del_rho;
+			
+			Z=ZB;
+		}
+		
+		
+		
+		pp = (double)-(u3 + 2.0*n*M_PI*Z*u2)*cos(n*M_PI*x); /* pressure */
+		
+		txx = (double)(u3 + 4*Z*n*M_PI*u2)*cos(n*M_PI*x); /* xx stress */
+		sum5 += pp;
+		sum6 += txx;
+		
+		u1 *= cos(n*M_PI*x); /* z velocity */
+		sum1 += u1;
+		u2 *= sin(n*M_PI*x); /* x velocity */
+		sum2 += u2;
+		u3 *= cos(n*M_PI*x); /* zz stress */
+		sum3 += u3;
+		u4 *= sin(n*M_PI*x); /* zx stress */
+		sum4 += u4;
+		
+		rho = del_rho* cos(n*M_PI*x); /* density */
+		sum7 += rho;
+	}/* n */
+	
+	/* include terms for n=0 now */
+	if( z >= zc ){
+		del_rho = sigma*xc;
+		rho = del_rho; /* density */
+		sum7 += rho;
+		u3 = del_rho*(z-zc); /* zz stress */
+		sum3 += u3;
+		
+		txx = u3; /* xx stress */
+		pp = -u3; /* pressure */
+		sum5 += pp;
+		sum6 += txx;
+		
+	}
+	
+	mag=sqrt(sum1*sum1+sum2*sum2);
+	//printf("%0.7g %0.7g %0.7g %0.7g %0.7g %0.7g\n",x,y,z,sum3,sum2,sum1);
+	//printf("%0.7g %0.7g %0.7g\n%0.7g %0.7g %0.7g\n\n\n",x,y,z,x+sum3,y+sum2,z+sum1);
+	/*printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7);*/
+	
+	
+	/* Output */
+	if( vel != NULL ) {
+		vel[0] = sum2;
+		vel[1] = sum1;
+	}
+	if( presssure != NULL ) {
+		(*presssure) = sum5;
+	}
+	if( total_stress != NULL ) {
+		total_stress[0] = sum6;
+		total_stress[1] = sum3;
+		total_stress[2] = sum4;
+	}
+	if( strain_rate != NULL ) {
+		if( z<zc ) {
+			Z = ZA;
+		}
+		else {
+			Z = ZB;
+		}
+		strain_rate[0] = (sum6+sum5)/(2.0*Z);
+		strain_rate[1] = (sum3+sum5)/(2.0*Z);
+		strain_rate[2] = (sum4)/(2.0*Z);
+	}
+	/* Value checks, could be cleaned up if needed. Julian Giordani 9-Oct-2006*/
+        if( fabs( sum5 - ( -0.5*(sum6+sum3) ) ) > 1e-5 ) {
+                assert(0);
+        }
+	
+	
+	
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solG/Analytic_solG.c
--- a/SysTest/AnalyticPlugins/Velic_solG/Analytic_solG.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,169 +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:
-*+		Mirko Velic
-*+		Julian Giordani
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Patrick Sunter
-** $Id: solG.c 636 2006-09-08 03:07:06Z JulianGiordani $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include "Analytic_solG.h"
-
-const Type Velic_solG_Type = "Underworld_Velic_solG";
-
-void Velic_solG_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
-	Velic_solG* self = (Velic_solG*) analyticSolution;
-	
-	_Velic_solG( coord, self->sigma, self->etaA, self->etaB, self->dx, self->x0, self->zc,
-		       	NULL, pressure, NULL, NULL );
-}
-
-void Velic_solG_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
-	Velic_solG* self = (Velic_solG*) analyticSolution;
-	
-	_Velic_solG( coord, self->sigma, self->etaA, self->etaB, self->dx, self->x0, self->zc,
-		       	velocity, NULL, NULL, NULL );
-}
-
-void Velic_solG_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
-	Velic_solG* self = (Velic_solG*) analyticSolution;
-	
-	_Velic_solG( coord, self->sigma, self->etaA, self->etaB, self->dx, self->x0, self->zc,
-		       	NULL, NULL, stress, NULL );
-}
-
-
-void Velic_solG_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
-	Velic_solG* self = (Velic_solG*) analyticSolution;
-	
-	_Velic_solG( coord, self->sigma, self->etaA, self->etaB, self->dx, self->x0, self->zc,
-		       	NULL, NULL, NULL, strainRate );
-}
-
-void _Velic_solG_Init( Velic_solG* self, double sigma, double etaA, double etaB, double dx, double x0, double zc ) {
-	// TODO	Bool                     correctInput = True;
-	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
-        self->_getAnalyticVelocity    = Velic_solG_VelocityFunction;
-	self->_getAnalyticPressure    = Velic_solG_PressureFunction;
-	self->_getAnalyticTotalStress = Velic_solG_StressFunction;
-	self->_getAnalyticStrainRate  = Velic_solG_StrainRateFunction;
-
-	self->sigma = sigma;
-	self->etaA = etaA;
-	self->etaB = etaB;
-	self->dx = dx;
-	self->x0 = x0;
-	self->zc = zc;
-}
-
-void _Velic_solG_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
-	Velic_solG* self = (Velic_solG*) analyticSolution;
-	FeVariable*              velocityField;
-	FeVariable*              pressureField;
-	FeVariable*              stressField;
-	FeVariable*              strainRateField;
-	FeVariable*              recoveredStrainRateField;
-	FeVariable*              recoveredStressField;
-        double                   sigma, etaA, etaB, dx, x0, zc, startX, endX;
-
-	/* Construct Parent */
-	_AnalyticSolution_AssignFromXML( self, cf, data );
-
-	/* Create Analytic Fields */
-	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solG_VelocityFunction );
-
-	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solG_PressureFunction );
-
-	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False, data );
-	if ( stressField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solG_StressFunction );
-
-	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
-	if ( strainRateField   ) {
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solG_StrainRateFunction );
-	}
-
-	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
-	if ( recoveredStrainRateField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solG_StrainRateFunction );
-
-	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
-	if ( recoveredStressField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solG_StressFunction );
-	
-	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solG_sigma", 1.0  );
-	etaA = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solG_etaA", 10.0  );
-	etaB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solG_etaB", 1.0  );
-	zc = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solG_zc", 0.7  );
-	
-	startX = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solG_startX", 0.4  );
-	endX = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solG_endX", 0.55 );
-	dx = endX - startX;
-	x0 = 0.5 * (startX + endX );
-
-        _Velic_solG_Init( self, sigma, etaA, etaB, dx, x0, zc );
-
-
-}
-
-void* _Velic_solG_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Velic_solG);
-	Type                                                      type = Velic_solG_Type;
-	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
-	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
-	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solG_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Velic_solG_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _AnalyticSolution_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 Underworld_Velic_solG_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Velic_solG_Type, (Name)"0", _Velic_solG_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solG/Analytic_solG.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solG/Analytic_solG.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,169 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Mirko Velic
+*+		Julian Giordani
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Patrick Sunter
+** $Id: solG.c 636 2006-09-08 03:07:06Z JulianGiordani $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include "Analytic_solG.h"
+
+const Type Velic_solG_Type = "Underworld_Velic_solG";
+
+void Velic_solG_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
+	Velic_solG* self = (Velic_solG*) analyticSolution;
+	
+	_Velic_solG( coord, self->sigma, self->etaA, self->etaB, self->dx, self->x0, self->zc,
+		       	NULL, pressure, NULL, NULL );
+}
+
+void Velic_solG_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
+	Velic_solG* self = (Velic_solG*) analyticSolution;
+	
+	_Velic_solG( coord, self->sigma, self->etaA, self->etaB, self->dx, self->x0, self->zc,
+		       	velocity, NULL, NULL, NULL );
+}
+
+void Velic_solG_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
+	Velic_solG* self = (Velic_solG*) analyticSolution;
+	
+	_Velic_solG( coord, self->sigma, self->etaA, self->etaB, self->dx, self->x0, self->zc,
+		       	NULL, NULL, stress, NULL );
+}
+
+
+void Velic_solG_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
+	Velic_solG* self = (Velic_solG*) analyticSolution;
+	
+	_Velic_solG( coord, self->sigma, self->etaA, self->etaB, self->dx, self->x0, self->zc,
+		       	NULL, NULL, NULL, strainRate );
+}
+
+void _Velic_solG_Init( Velic_solG* self, double sigma, double etaA, double etaB, double dx, double x0, double zc ) {
+	// TODO	Bool                     correctInput = True;
+	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
+        self->_getAnalyticVelocity    = Velic_solG_VelocityFunction;
+	self->_getAnalyticPressure    = Velic_solG_PressureFunction;
+	self->_getAnalyticTotalStress = Velic_solG_StressFunction;
+	self->_getAnalyticStrainRate  = Velic_solG_StrainRateFunction;
+
+	self->sigma = sigma;
+	self->etaA = etaA;
+	self->etaB = etaB;
+	self->dx = dx;
+	self->x0 = x0;
+	self->zc = zc;
+}
+
+void _Velic_solG_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
+	Velic_solG* self = (Velic_solG*) analyticSolution;
+	FeVariable*              velocityField;
+	FeVariable*              pressureField;
+	FeVariable*              stressField;
+	FeVariable*              strainRateField;
+	FeVariable*              recoveredStrainRateField;
+	FeVariable*              recoveredStressField;
+        double                   sigma, etaA, etaB, dx, x0, zc, startX, endX;
+
+	/* Construct Parent */
+	_AnalyticSolution_AssignFromXML( self, cf, data );
+
+	/* Create Analytic Fields */
+	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solG_VelocityFunction );
+
+	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solG_PressureFunction );
+
+	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False, data );
+	if ( stressField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solG_StressFunction );
+
+	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
+	if ( strainRateField   ) {
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solG_StrainRateFunction );
+	}
+
+	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
+	if ( recoveredStrainRateField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solG_StrainRateFunction );
+
+	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
+	if ( recoveredStressField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solG_StressFunction );
+	
+	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solG_sigma", 1.0  );
+	etaA = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solG_etaA", 10.0  );
+	etaB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solG_etaB", 1.0  );
+	zc = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solG_zc", 0.7  );
+	
+	startX = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solG_startX", 0.4  );
+	endX = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solG_endX", 0.55 );
+	dx = endX - startX;
+	x0 = 0.5 * (startX + endX );
+
+        _Velic_solG_Init( self, sigma, etaA, etaB, dx, x0, zc );
+
+
+}
+
+void* _Velic_solG_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Velic_solG);
+	Type                                                      type = Velic_solG_Type;
+	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
+	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
+	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solG_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Velic_solG_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _AnalyticSolution_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 Underworld_Velic_solG_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Velic_solG_Type, (Name)"0", _Velic_solG_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solG/solG.c
--- a/SysTest/AnalyticPlugins/Velic_solG/solG.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,713 +0,0 @@
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-
-
-void _Velic_solG( 
-		double pos[],
-		double _sigma,
-		double _eta_A, double _eta_B, 
-		double _dx, double _x_0, double _z_c,
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] );
-
-
-int main( int argc, char **argv )
-{
-	int i,j;
-	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
-	double x,z;
-	
-	for (i=0;i<101;i++){
-		for(j=0;j<101;j++){
-			x = i/100.0;
-			z = j/100.0;
-			
-			pos[0] = x;
-			pos[1] = z;
-			_Velic_solG(
-					pos,
-					1.0,
-					10.0, 1.0,
-					0.4,0.55,0.7,
-					vel, &pressure, total_stress, strain_rate );
-			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
-					pos[0],pos[1],
-					vel[0],vel[1], pressure, 
-					total_stress[0], total_stress[1], total_stress[2], 
-					strain_rate[0], strain_rate[1], strain_rate[2] );
-		}
-		printf("\n");
-	}
-	
-	return 0;
-}
-
-
-
-void _Velic_solG(
-		double pos[],
-		double _sigma,
-		double _eta_A, double _eta_B, 
-		double _dx, double _x_0, double _z_c,
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] )
-{
-	double Z,ZA,ZB,u1,u2,u3,u4,pp,txx;
-	double u1a,u2a,u3a,u4a,u1b,u2b,u3b,u4b;
-	double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,x,z;
-	double sigma;
-	double del_rho;
-	int n;
-	double kn;
-	double _C1A,_C2A,_C3A,_C4A,_C1B,_C2B,_C3B,_C4B;
-	double x0,dx,rho,zc;
-	
-	double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
-	double t11,t12,t13,t14,t15,t16,t17,t18,t19,t20;
-	double t21,t22,t23,t24,t25,t26,t27,t28,t29,t30;
-	double t31,t32,t33,t34,t35,t36,t37,t38,t39,t40;
-	double t41,t42,t43,t44,t45,t46,t47,t48,t49,t50;
-	double t51,t52,t53,t54,t55,t56,t57,t58,t59,t60;
-	double t61,t62,t63,t64,t65,t66,t67,t68,t69,t70;
-	double t71,t72,t73,t74,t75,t76,t77,t78,t79,t80;
-	double t81,t82,t83,t85,t86,t87,t88,t89,t90,t91;
-	double t92,t93,t94,t95,t96,t97,t98,t99,t100,t101;
-	double t102,t103,t104,t105,t106,t107,t108,t109,t111,t112;
-	double t113,t114,t115,t116,t117,t118,t120,t121,t122,t124;
-	double t125,t126,t127,t128,t129,t130,t131,t133,t134,t135;
-	double t136,t137,t139,t141,t143,t144,t145,t146,t147,t148;
-	double t151,t152,t153,t154,t156,t157,t158,t159,t162,t163;
-	double t165,t167,t168,t190,t195;
-	
-	/*************************************************************************/
-	/*************************************************************************/
-	/*
-	In layer B (the top layer) we have a dense column of density sigma
-	ranging from x=0 to x= xc:
-	The viscosity of layer B is ZB:
-	The viscosity of layer A is ZA:
-	
-	*/
-	/*************************************************************************/
-	/*************************************************************************/
-	
-	/*************************************************************************/
-	/*************************************************************************/
-	x0 = _x_0;  /* centre of dense block in layer B */
-	dx =  _dx;  /* width of dense block in layer B */
-	sigma = _sigma; /* density parameter for layer B */
-	ZA = _eta_A;    /* viscosity for layer A */
-	ZB = _eta_B; /* viscosity for layer B */
-	zc = _z_c;  /* dividing line between region B and region A */
-	/*************************************************************************/
-	/*************************************************************************/
-	
-	x = pos[0];
-	z = pos[1];
-	
-	sum1=0.0;
-	sum2=0.0;
-	sum3=0.0;
-	sum4=0.0;
-	sum5=0.0;
-	sum6=0.0;
-	sum7=0.0;
-	/* this one blows up when n gets around 85 for some reason... if max n is set to 75 it is fine though */
-	/* fixed the convergence problem */
-	for(n=1;n<85;n++){
-		kn = (double) n*M_PI;
-		
-		/*******************************************/
-		/*            calculate del_rho            */
-		/*******************************************/
-		del_rho = 4.0*sigma*cos(n*M_PI*x0)*sin(n*M_PI*dx/2.0)/n/M_PI;
-		
-		/*******************************************/
-		/*         calculate the constants         */
-		/*******************************************/
-		
-		if ( z < zc ) {
-			t1 = kn * zc;
-			t2 = 0.4e1 * t1;
-			t3 = kn * kn;
-			t5 = 0.2e1 * t3 * zc;
-			t6 = zc * zc;
-			t7 = t6 * t3;
-			t8 = 0.2e1 * t7;
-			t10 = ZA - ZB;
-			t12 = 0.2e1 * zc;
-			t15 = exp(-kn * (0.1e1 + t12));
-			t22 = exp(kn * (t12 - 0.3e1));
-			t26 = ZA + ZB;
-			t29 = exp(-0.3e1 * kn);
-			t34 = exp(-kn);
-			t37 = 0.3e1 * t1;
-			t40 = exp(-t37);
-			t44 = exp(-t1);
-			t50 = exp(kn * (zc - 0.4e1));
-			t54 = 0.2e1 * ZA * kn * zc;
-			t56 = 0.2e1 * ZB * kn;
-			t57 = 0.2e1 * ZA;
-			t58 = t3 * ZA;
-			t60 = 0.2e1 * t58 * zc;
-			t63 = 0.3e1 * ZB * zc * kn;
-			t64 = t3 * ZB;
-			t66 = 0.2e1 * t64 * zc;
-			t68 = 0.2e1 * t64 * t6;
-			t70 = 0.2e1 * t58 * t6;
-			t73 = kn * (zc - 0.2e1);
-			t74 = exp(t73);
-			t82 = exp(kn * (0.3e1 * zc - 0.4e1));
-			t87 = exp(-kn * (0.2e1 + zc));
-			t92 = t10 * t10;
-			t93 = t3 * t92;
-			t94 = exp(-t2);
-			t97 = t26 * t26;
-			t100 = exp(-0.4e1 * kn);
-			t103 = t3 * kn;
-			t104 = t103 * t10;
-			t105 = zc - 0.1e1;
-			t106 = t26 * t105;
-			t107 = kn * t105;
-			t109 = exp(0.2e1 * t107);
-			t114 = exp(0.4e1 * t107);
-			t117 = t103 * zc;
-			t118 = t10 * t26;
-			t120 = exp(0.2e1 * t73);
-			t124 = ZA * ZA;
-			t125 = t3 * t124;
-			t128 = ZB * ZB;
-			t136 = ZA * ZB;
-			t145 = exp(-0.2e1 * kn);
-			t151 = exp(-0.2e1 * kn * (0.1e1 + zc));
-			t156 = exp(-0.2e1 * t1);
-			t165 = -0.2e1 * t93 * t94 + 0.2e1 * t3 * t97 * t100 + 0.8e1 * t104 * t106 * t109 - 0.2e1 * t93 * t114 - 0.8e1 * t117 * t118 * t120 + 0.16e2 * t3 * (-0.2e1 * t125 * zc + 0.2e1 * t7 * t128 + 0.2e1 * t7 * t124 - 0.2e1 * t128 * zc * t3 - t136 - 0.4e1 * t7 * t136 + 0.4e1 * t64 * ZA * zc) * t145 - 0.8e1 * t104 * t106 * t151 + 0.8e1 * t117 * t118 * t156 + 0.4e1 * t64 * ZA + 0.2e1 * t3 * t128 + 0.2e1 * t125;
-			_C1A = (0.2e1 * (-t2 - t5 + t8 + 0.2e1 + kn) * t10 * t15 - 0.2e1 * (0.2e1 - t5 + t2 + t8 - kn) * t10 * t22 - 0.2e1 * (-0.2e1 + kn) * t26 * t29 - 0.2e1 * (kn + 0.2e1) * t26 * t34 + (t37 - 0.2e1) * t10 * t40 + (t1 + 0.2e1) * t26 * t44 + (t1 - 0.2e1) * t26 * t50 + 0.2e1 * (t54 + t56 + t57 - t60 - t63 + t66 - t68 + t70) * t74 + (t37 + 0.2e1) * t10 * t82 - 0.2e1 * (-t68 + t63 - t60 + t70 - t56 + t57 - t54 + t66) * t87) * del_rho / t165;
-			
-			t1 = kn * kn;
-			t3 = 0.2e1 * t1 * zc;
-			t4 = kn * zc;
-			t5 = 0.4e1 * t4;
-			t6 = zc * zc;
-			t7 = t6 * t1;
-			t8 = 0.2e1 * t7;
-			t10 = ZA - ZB;
-			t12 = zc - 0.1e1;
-			t13 = kn * t12;
-			t15 = exp(0.3e1 * t13);
-			t19 = ZA + ZB;
-			t24 = exp(0.2e1 * kn * (zc - 0.2e1));
-			t26 = t1 * ZB;
-			t28 = 0.2e1 * t26 * t6;
-			t30 = ZB * zc * kn;
-			t31 = 0.3e1 * t30;
-			t32 = t1 * ZA;
-			t34 = 0.2e1 * t32 * zc;
-			t36 = 0.2e1 * t32 * t6;
-			t38 = 0.2e1 * ZB * kn;
-			t39 = 0.2e1 * ZA;
-			t41 = ZA * kn * zc;
-			t42 = 0.2e1 * t41;
-			t44 = 0.2e1 * t26 * zc;
-			t47 = exp(-0.2e1 * kn);
-			t52 = exp(t13);
-			t57 = exp(0.2e1 * t13);
-			t64 = exp(kn * (zc - 0.3e1));
-			t67 = 0.3e1 * t4;
-			t71 = exp(-0.2e1 * t4);
-			t76 = kn * (0.1e1 + zc);
-			t77 = exp(-t76);
-			t83 = exp(0.4e1 * t13);
-			t86 = 0.2e1 * (0.2e1 - t3 + t5 + t8 - kn) * t10 * t15 - (t4 - 0.2e1) * t19 * t24 + 0.2e1 * (-t28 + t31 - t34 + t36 - t38 + t39 - t42 + t44) * t47 + 0.2e1 * (kn + 0.2e1) * t19 * t52 - 0.2e1 * (t42 + t38 + t39 - t34 - t31 + t44 - t28 + t36) * t57 + 0.2e1 * (-0.2e1 + kn) * t19 * t64 - (t67 - 0.2e1) * t10 * t71 - 0.2e1 * (-t5 - t3 + t8 + 0.2e1 + kn) * t10 * t77 - (t67 + 0.2e1) * t10 * t83 - 0.2e1 * ZB - t39 - t30 - t41;
-			t88 = t10 * t10;
-			t89 = t1 * t88;
-			t90 = exp(-t5);
-			t93 = t19 * t19;
-			t96 = exp(-0.4e1 * kn);
-			t99 = t1 * kn;
-			t100 = t99 * t10;
-			t101 = t19 * t12;
-			t107 = t99 * zc;
-			t108 = t10 * t19;
-			t112 = ZA * ZA;
-			t113 = t1 * t112;
-			t116 = ZB * ZB;
-			t124 = ZA * ZB;
-			t135 = exp(-0.2e1 * t76);
-			t147 = -0.2e1 * t89 * t90 + 0.2e1 * t1 * t93 * t96 + 0.8e1 * t100 * t101 * t57 - 0.2e1 * t89 * t83 - 0.8e1 * t107 * t108 * t24 + 0.16e2 * t1 * (-0.2e1 * t113 * zc + 0.2e1 * t7 * t116 + 0.2e1 * t7 * t112 - 0.2e1 * t116 * zc * t1 - t124 - 0.4e1 * t7 * t124 + 0.4e1 * t26 * ZA * zc) * t47 - 0.8e1 * t100 * t101 * t135 + 0.8e1 * t107 * t108 * t71 + 0.4e1 * t26 * ZA + 0.2e1 * t1 * t116 + 0.2e1 * t113;
-			_C2A = t86 * del_rho / t147;
-			
-			t1 = kn * zc;
-			t2 = 0.2e1 * t1;
-			t3 = 0.2e1 * kn;
-			t5 = ZA - ZB;
-			t7 = 0.2e1 * zc;
-			t10 = exp(-kn * (0.1e1 + t7));
-			t17 = exp(kn * (t7 - 0.3e1));
-			t20 = ZA + ZB;
-			t22 = exp(-0.3e1 * kn);
-			t25 = exp(-kn);
-			t29 = exp(-0.3e1 * t1);
-			t32 = exp(-t1);
-			t36 = exp(kn * (zc - 0.4e1));
-			t38 = ZA * kn;
-			t40 = 0.2e1 * t38 * zc;
-			t41 = 0.2e1 * t38;
-			t43 = 0.2e1 * ZB * kn;
-			t44 = 0.2e1 * ZA;
-			t47 = 0.2e1 * ZB * zc * kn;
-			t50 = kn * (zc - 0.2e1);
-			t51 = exp(t50);
-			t57 = exp(kn * (0.3e1 * zc - 0.4e1));
-			t63 = exp(-kn * (0.2e1 + zc));
-			t68 = t5 * t5;
-			t69 = kn * t68;
-			t71 = exp(-0.4e1 * t1);
-			t74 = t20 * t20;
-			t77 = exp(-0.4e1 * kn);
-			t80 = kn * kn;
-			t81 = t80 * t5;
-			t82 = zc - 0.1e1;
-			t83 = t20 * t82;
-			t87 = exp(-0.2e1 * kn * (0.1e1 + zc));
-			t91 = t80 * zc;
-			t92 = t5 * t20;
-			t94 = exp(0.2e1 * t50);
-			t98 = ZA * ZA;
-			t102 = zc * zc;
-			t103 = t102 * t80;
-			t104 = ZB * ZB;
-			t112 = ZA * ZB;
-			t121 = exp(-t3);
-			t124 = kn * t82;
-			t126 = exp(0.2e1 * t124);
-			t130 = exp(-t2);
-			t135 = exp(0.4e1 * t124);
-			t144 = -0.2e1 * t69 * t71 + 0.2e1 * t74 * kn * t77 - 0.8e1 * t81 * t83 * t87 - 0.8e1 * t91 * t92 * t94 + 0.16e2 * kn * (-0.2e1 * t80 * t98 * zc + 0.2e1 * t103 * t104 + 0.2e1 * t103 * t98 - 0.2e1 * t104 * zc * t80 - t112 - 0.4e1 * t103 * t112 + 0.4e1 * ZB * t80 * ZA * zc) * t121 + 0.8e1 * t81 * t83 * t126 + 0.8e1 * t91 * t92 * t130 - 0.2e1 * t69 * t135 + 0.2e1 * kn * t104 + 0.2e1 * t98 * kn + 0.4e1 * t112 * kn;
-			_C3A = (-0.2e1 * (t2 - 0.3e1 - t3) * t5 * t10 - 0.2e1 * (t2 + 0.3e1 - t3) * t5 * t17 + 0.2e1 * t20 * t22 - 0.2e1 * t20 * t25 - 0.3e1 * t5 * t29 + t20 * t32 - t20 * t36 + 0.2e1 * (t40 - t41 + t43 + t44 - ZB - t47) * t51 + 0.3e1 * t5 * t57 + 0.2e1 * (-t41 + t43 + ZB - t47 + t40 - t44) * t63) * del_rho / t144;
-			
-			t1 = ZA + ZB;
-			t5 = exp(0.2e1 * kn * (zc - 0.2e1));
-			t7 = ZA * kn;
-			t8 = 0.2e1 * t7;
-			t10 = 0.2e1 * ZB * kn;
-			t13 = 0.2e1 * ZB * zc * kn;
-			t15 = 0.2e1 * t7 * zc;
-			t16 = 0.2e1 * ZA;
-			t18 = 0.2e1 * kn;
-			t19 = exp(-t18);
-			t24 = exp(kn * (zc - 0.3e1));
-			t27 = kn * zc;
-			t28 = 0.2e1 * t27;
-			t30 = ZA - ZB;
-			t33 = kn * (0.1e1 + zc);
-			t34 = exp(-t33);
-			t38 = zc - 0.1e1;
-			t39 = kn * t38;
-			t41 = exp(0.2e1 * t39);
-			t47 = exp(0.3e1 * t39);
-			t50 = exp(-t28);
-			t53 = exp(t39);
-			t57 = exp(0.4e1 * t39);
-			t60 = -t1 * t5 + 0.2e1 * (-t8 + t10 + ZB - t13 + t15 - t16) * t19 + 0.2e1 * t1 * t24 - 0.2e1 * (t28 - 0.3e1 - t18) * t30 * t34 + 0.2e1 * (t15 - t8 + t10 + t16 - ZB - t13) * t41 - 0.2e1 * (t28 + 0.3e1 - t18) * t30 * t47 - 0.3e1 * t30 * t50 - 0.2e1 * t1 * t53 + 0.3e1 * t30 * t57 + ZA + ZB;
-			t62 = t30 * t30;
-			t63 = kn * t62;
-			t65 = exp(-0.4e1 * t27);
-			t68 = t1 * t1;
-			t71 = exp(-0.4e1 * kn);
-			t74 = kn * kn;
-			t75 = t74 * t30;
-			t76 = t1 * t38;
-			t78 = exp(-0.2e1 * t33);
-			t82 = t74 * zc;
-			t83 = t30 * t1;
-			t87 = ZA * ZA;
-			t91 = zc * zc;
-			t92 = t91 * t74;
-			t93 = ZB * ZB;
-			t101 = ZA * ZB;
-			t126 = -0.2e1 * t63 * t65 + 0.2e1 * t68 * kn * t71 - 0.8e1 * t75 * t76 * t78 - 0.8e1 * t82 * t83 * t5 + 0.16e2 * kn * (-0.2e1 * t74 * t87 * zc + 0.2e1 * t92 * t93 + 0.2e1 * t92 * t87 - 0.2e1 * t93 * zc * t74 - t101 - 0.4e1 * t92 * t101 + 0.4e1 * ZB * t74 * ZA * zc) * t19 + 0.8e1 * t75 * t76 * t41 + 0.8e1 * t82 * t83 * t50 - 0.2e1 * t63 * t57 + 0.2e1 * kn * t93 + 0.2e1 * t87 * kn + 0.4e1 * t101 * kn;
-			_C4A = t60 * del_rho / t126;
-		} else { 
-			t1 = ZA - ZB;
-			t2 = ZA * kn;
-			t4 = 0.2e1 * t2 * zc;
-			t5 = 0.2e1 * ZA;
-			t7 = ZB * zc * kn;
-			t10 = kn * zc;
-			t11 = 0.4e1 * t10;
-			t12 = exp(-t11);
-			t14 = ZA + ZB;
-			t15 = 0.4e1 * t2;
-			t17 = 0.2e1 * ZB * kn;
-			t21 = kn * (0.1e1 + zc);
-			t23 = exp(-0.2e1 * t21);
-			t25 = kn * kn;
-			t26 = ZA * ZA;
-			t28 = t25 * t26 * zc;
-			t30 = zc * zc;
-			t31 = t30 * t25;
-			t32 = t31 * t26;
-			t33 = 0.4e1 * t32;
-			t34 = ZB * t25;
-			t36 = t34 * ZA * zc;
-			t39 = t26 * zc * kn;
-			t40 = 0.4e1 * t39;
-			t41 = ZA * ZB;
-			t42 = t41 * kn;
-			t44 = ZB * ZB;
-			t45 = t44 * zc;
-			t46 = t45 * t25;
-			t48 = t41 * t10;
-			t49 = 0.3e1 * t48;
-			t50 = t31 * t44;
-			t51 = 0.2e1 * t50;
-			t52 = 0.2e1 * t41;
-			t53 = t31 * t41;
-			t54 = 0.6e1 * t53;
-			t57 = exp(-0.2e1 * kn);
-			t64 = (-t11 - 0.2e1 * t25 * zc + 0.2e1 * t31 + 0.2e1 + kn) * t1;
-			t68 = exp(-kn * (0.1e1 + 0.3e1 * zc));
-			t72 = -0.2e1 + kn;
-			t76 = exp(kn * (zc - 0.3e1));
-			t80 = t25 * kn;
-			t81 = t30 * t80;
-			t85 = t30 * zc;
-			t91 = t45 * kn;
-			t97 = 0.2e1 * t39;
-			t106 = -0.2e1 * t81 * t44 + 0.2e1 * t44 * t80 * t85 + 0.2e1 * t26 * t80 * t85 + t52 + t42 + 0.2e1 * t91 + 0.8e1 * t53 + 0.4e1 * t81 * t41 - 0.4e1 * t48 + t46 + t97 - 0.2e1 * t36 - t33 - 0.4e1 * t41 * t80 * t85 - 0.4e1 * t50 - 0.2e1 * t26 * t30 * t80 + t28;
-			t107 = exp(-t21);
-			t112 = zc - 0.1e1;
-			t113 = kn * t112;
-			t115 = exp(0.2e1 * t113);
-			t117 = t1 * t1;
-			t120 = exp(0.3e1 * t113);
-			t124 = exp(-0.2e1 * t10);
-			t127 = t14 * t14;
-			t131 = exp(-kn * (zc + 0.3e1));
-			t133 = exp(t113);
-			t137 = t1 * (t4 - t5 + t7) * t12 - t14 * (t5 + t4 - t15 - t7 + t17) * t23 + 0.2e1 * (-0.8e1 * t28 + t33 + 0.12e2 * t36 + t40 + 0.2e1 * t42 - 0.4e1 * t46 - t49 + t51 - t52 - t54) * t57 + t64 * t14 * t68 + 0.4e1 * t10 * t1 * t14 * t72 * t76 - 0.4e1 * t106 * t107 + t1 * (t5 + t4 - t15 + t7 - t17) * t115 + t117 * t72 * t120 - 0.2e1 * (t49 - t54 + t33 + t51 - t52 - t40) * t124 - t127 * t72 * t131 - t64 * t14 * t133 - t48 + 0.2e1 * t26 - t97 + t52 + t91;
-			t143 = exp(-0.4e1 * kn);
-			t148 = exp(0.4e1 * t113);
-			t152 = t80 * ZB;
-			t153 = t152 * zc;
-			t154 = t1 * t14;
-			t158 = exp(0.2e1 * kn * (zc - 0.2e1));
-			t162 = t152 * t1;
-			t163 = t14 * t112;
-			t190 = -0.2e1 * t34 * t117 * t12 + 0.2e1 * t34 * t127 * t143 - 0.2e1 * t34 * t117 * t148 - 0.8e1 * t153 * t154 * t158 - 0.8e1 * t162 * t163 * t23 + 0.16e2 * t34 * (-0.2e1 * t28 + t51 + 0.2e1 * t32 - 0.2e1 * t46 - t41 - 0.4e1 * t53 + 0.4e1 * t36) * t57 + 0.8e1 * t162 * t163 * t115 + 0.8e1 * t153 * t154 * t124 + 0.2e1 * t25 * t44 * ZB + 0.2e1 * t34 * t26 + 0.4e1 * t25 * t44 * ZA;
-			_C1B = t137 * del_rho / t190;
-			
-			t1 = ZA - ZB;
-			t2 = t1 * t1;
-			t3 = kn + 0.2e1;
-			t5 = kn * zc;
-			t6 = 0.4e1 * t5;
-			t7 = exp(-t6);
-			t9 = kn * kn;
-			t12 = zc * zc;
-			t13 = t12 * t9;
-			t16 = (0.2e1 - 0.2e1 * t9 * zc + t6 + 0.2e1 * t13 - kn) * t1;
-			t17 = ZA + ZB;
-			t19 = kn * (0.1e1 + zc);
-			t21 = exp(-0.2e1 * t19);
-			t24 = ZA * ZA;
-			t25 = t9 * kn;
-			t27 = t12 * zc;
-			t33 = ZA * ZB;
-			t37 = t12 * t25;
-			t40 = ZB * ZB;
-			t46 = t13 * t24;
-			t47 = 0.4e1 * t46;
-			t49 = t9 * t24 * zc;
-			t50 = t13 * t33;
-			t52 = ZB * t9;
-			t54 = t52 * ZA * zc;
-			t56 = t13 * t40;
-			t58 = t40 * zc;
-			t59 = t58 * t9;
-			t61 = t24 * zc * kn;
-			t63 = t33 * kn;
-			t64 = t33 * t5;
-			t68 = 0.2e1 * t33;
-			t69 = 0.2e1 * t24 * t25 * t27 - 0.2e1 * t24 * t12 * t25 - 0.4e1 * t33 * t25 * t27 + 0.4e1 * t37 * t33 + 0.2e1 * t40 * t25 * t27 - 0.2e1 * t37 * t40 + t47 - t49 - 0.8e1 * t50 + 0.2e1 * t54 + 0.4e1 * t56 - t59 + 0.2e1 * t61 + t63 - 0.4e1 * t64 + 0.2e1 * t58 * kn - t68;
-			t71 = exp(-0.2e1 * kn);
-			t74 = ZA * kn;
-			t75 = 0.4e1 * t74;
-			t77 = 0.2e1 * t74 * zc;
-			t78 = 0.2e1 * ZA;
-			t80 = ZB * zc * kn;
-			t82 = 0.2e1 * ZB * kn;
-			t88 = exp(-kn * (0.1e1 + 0.3e1 * zc));
-			t90 = 0.6e1 * t50;
-			t91 = 0.2e1 * t56;
-			t92 = 0.3e1 * t64;
-			t93 = 0.4e1 * t61;
-			t97 = exp(kn * (zc - 0.3e1));
-			t103 = 0.2e1 * t63;
-			t105 = exp(-t19);
-			t108 = zc - 0.1e1;
-			t109 = kn * t108;
-			t111 = exp(0.2e1 * t109);
-			t117 = exp(0.3e1 * t109);
-			t122 = exp(-0.2e1 * t5);
-			t130 = exp(-kn * (zc + 0.3e1));
-			t134 = exp(t109);
-			t141 = -t2 * t3 * t7 - t16 * t17 * t21 + 0.4e1 * t69 * t71 - t1 * (-t75 + t77 - t78 + t80 - t82) * t88 - 0.2e1 * (-t90 + t91 + t47 - t92 + t93 - t68) * t97 + 0.2e1 * (t47 - 0.8e1 * t49 - t90 + 0.12e2 * t54 - 0.4e1 * t59 + t91 - t93 - t103 + t92 - t68) * t105 + t16 * t17 * t111 - t1 * (t77 + t78 + t80) * t117 + 0.4e1 * t5 * t1 * t17 * t3 * t122 + t17 * (t77 + t78 - t80) * t130 + t17 * (-t75 + t77 - t78 - t80 + t82) * t134 + kn * t40 + t103 + 0.2e1 * t40 + t24 * kn + 0.2e1 * t24 + 0.4e1 * t33;
-			t146 = t17 * t17;
-			t148 = exp(-0.4e1 * kn);
-			t153 = exp(0.4e1 * t109);
-			t157 = ZB * t25;
-			t158 = t157 * zc;
-			t159 = t1 * t17;
-			t163 = exp(0.2e1 * kn * (zc - 0.2e1));
-			t167 = t157 * t1;
-			t168 = t17 * t108;
-			t195 = -0.2e1 * t52 * t2 * t7 + 0.2e1 * t52 * t146 * t148 - 0.2e1 * t52 * t2 * t153 - 0.8e1 * t158 * t159 * t163 - 0.8e1 * t167 * t168 * t21 + 0.16e2 * t52 * (-0.2e1 * t49 + t91 + 0.2e1 * t46 - 0.2e1 * t59 - t33 - 0.4e1 * t50 + 0.4e1 * t54) * t71 + 0.8e1 * t167 * t168 * t111 + 0.8e1 * t158 * t159 * t122 + 0.2e1 * t9 * t40 * ZB + 0.2e1 * t52 * t24 + 0.4e1 * t9 * t40 * ZA;
-			_C2B = t141 * del_rho / t195;
-			
-			t1 = 0.2e1 * ZA;
-			t3 = ZA - ZB;
-			t4 = (t1 + ZB) * t3;
-			t5 = kn * zc;
-			t7 = exp(-0.4e1 * t5);
-			t9 = ZA + ZB;
-			t13 = kn * (0.1e1 + zc);
-			t15 = exp(-0.2e1 * t13);
-			t17 = ZA * ZB;
-			t19 = 0.6e1 * t17 * t5;
-			t20 = ZB * ZB;
-			t21 = zc * t20;
-			t22 = t21 * kn;
-			t23 = 0.2e1 * t22;
-			t24 = ZA * ZA;
-			t26 = t24 * zc * kn;
-			t27 = 0.4e1 * t26;
-			t29 = 0.2e1 * kn;
-			t30 = exp(-t29);
-			t33 = t3 * t9;
-			t34 = 0.2e1 * t5;
-			t35 = t34 - 0.3e1 - t29;
-			t39 = exp(-kn * (0.1e1 + 0.3e1 * zc));
-			t44 = exp(kn * (zc - 0.3e1));
-			t48 = kn * kn;
-			t51 = 0.2e1 * t48 * t24 * zc;
-			t52 = zc * zc;
-			t53 = t52 * t48;
-			t55 = 0.2e1 * t53 * t24;
-			t56 = ZB * t48;
-			t59 = 0.4e1 * t56 * ZA * zc;
-			t61 = 0.4e1 * t53 * t17;
-			t63 = 0.2e1 * t21 * t48;
-			t65 = 0.2e1 * t53 * t20;
-			t69 = exp(-t13);
-			t72 = zc - 0.1e1;
-			t73 = kn * t72;
-			t75 = exp(0.2e1 * t73);
-			t77 = t3 * t3;
-			t79 = exp(0.3e1 * t73);
-			t82 = exp(-t34);
-			t85 = t9 * t9;
-			t88 = exp(-kn * (zc + 0.3e1));
-			t90 = exp(t73);
-			t94 = -t4 * t7 - t9 * (t1 - ZB) * t15 + 0.2e1 * (-t19 + t23 + t27 - t17) * t30 - t33 * t35 * t39 - 0.4e1 * t5 * t33 * t44 + 0.4e1 * (-t51 + t55 + t59 - t61 - t63 + t65 - 0.3e1 * t26 - 0.3e1 * t22 + t19 - t17) * t69 + t4 * t75 - t77 * t79 + 0.2e1 * (-t19 + t23 + t27 + t17) * t82 + t85 * t88 + t33 * t35 * t90 + 0.2e1 * t24 - t20 + t17;
-			t96 = ZB * kn;
-			t101 = exp(-0.4e1 * kn);
-			t105 = t56 * t3;
-			t106 = t9 * t72;
-			t117 = t56 * zc;
-			t121 = exp(0.2e1 * kn * (zc - 0.2e1));
-			t129 = exp(0.4e1 * t73);
-			t141 = -0.2e1 * t96 * t77 * t7 + 0.2e1 * t96 * t85 * t101 - 0.8e1 * t105 * t106 * t15 + 0.16e2 * t96 * (-t51 + t65 + t55 - t63 - t17 - t61 + t59) * t30 + 0.8e1 * t105 * t106 * t75 - 0.8e1 * t117 * t33 * t121 + 0.8e1 * t117 * t33 * t82 - 0.2e1 * t96 * t77 * t129 + 0.2e1 * t96 * t24 + 0.2e1 * t20 * ZB * kn + 0.4e1 * t20 * kn * ZA;
-			_C3B = t94 * del_rho / t141;
-			
-			t1 = ZA - ZB;
-			t2 = t1 * t1;
-			t3 = kn * zc;
-			t5 = exp(-0.4e1 * t3);
-			t6 = t2 * t5;
-			t7 = ZA + ZB;
-			t8 = t1 * t7;
-			t9 = 0.2e1 * t3;
-			t10 = 0.2e1 * kn;
-			t11 = t9 + 0.3e1 - t10;
-			t13 = kn * (0.1e1 + zc);
-			t15 = exp(-0.2e1 * t13);
-			t18 = ZA * ZB;
-			t20 = 0.6e1 * t18 * t3;
-			t21 = kn * kn;
-			t22 = ZB * t21;
-			t25 = 0.4e1 * t22 * ZA * zc;
-			t26 = ZB * ZB;
-			t27 = t26 * zc;
-			t29 = 0.2e1 * t27 * t21;
-			t30 = ZA * ZA;
-			t32 = t30 * zc * kn;
-			t34 = zc * zc;
-			t35 = t34 * t21;
-			t37 = 0.2e1 * t35 * t30;
-			t39 = 0.2e1 * t35 * t26;
-			t41 = 0.4e1 * t35 * t18;
-			t44 = 0.2e1 * t21 * t30 * zc;
-			t45 = t27 * kn;
-			t48 = exp(-t10);
-			t51 = 0.2e1 * ZA;
-			t53 = (t51 + ZB) * t1;
-			t57 = exp(-kn * (0.1e1 + 0.3e1 * zc));
-			t59 = 0.2e1 * t45;
-			t60 = 0.4e1 * t32;
-			t64 = exp(kn * (zc - 0.3e1));
-			t68 = exp(-t13);
-			t71 = zc - 0.1e1;
-			t72 = kn * t71;
-			t74 = exp(0.2e1 * t72);
-			t78 = exp(0.3e1 * t72);
-			t80 = exp(-t9);
-			t81 = t8 * t80;
-			t85 = t7 * (t51 - ZB);
-			t88 = exp(-kn * (zc + 0.3e1));
-			t90 = exp(t72);
-			t93 = t6 + t8 * t11 * t15 - 0.4e1 * (-t18 - t20 + t25 - t29 + 0.3e1 * t32 + t37 + t39 - t41 - t44 + 0.3e1 * t45) * t48 - t53 * t57 + 0.2e1 * (-t20 + t59 + t60 - t18) * t64 + 0.2e1 * (-t20 + t59 + t60 + t18) * t68 - t8 * t11 * t74 + t53 * t78 - 0.4e1 * t3 * t81 - t85 * t88 + t85 * t90 - 0.2e1 * t18 - t26 - t30;
-			t95 = ZB * kn;
-			t98 = t7 * t7;
-			t100 = exp(-0.4e1 * kn);
-			t104 = t22 * t1;
-			t105 = t7 * t71;
-			t116 = t22 * zc;
-			t120 = exp(0.2e1 * kn * (zc - 0.2e1));
-			t127 = exp(0.4e1 * t72);
-			t139 = -0.2e1 * t95 * t6 + 0.2e1 * t95 * t98 * t100 - 0.8e1 * t104 * t105 * t15 + 0.16e2 * t95 * (-t44 + t39 + t37 - t29 - t18 - t41 + t25) * t48 + 0.8e1 * t104 * t105 * t74 - 0.8e1 * t116 * t8 * t120 + 0.8e1 * t116 * t81 - 0.2e1 * t95 * t2 * t127 + 0.2e1 * t95 * t30 + 0.2e1 * t26 * ZB * kn + 0.4e1 * t26 * kn * ZA;
-			_C4B = t93 * del_rho / t139;
-			
-			
-		}
-		
-		/*******************************************/
-		/*       calculate the velocities etc      */
-		/*******************************************/
-		
-		if ( z < zc ) {
-			t4 = exp(-kn * z);
-			t10 = exp(kn * (z - zc));
-			u1=u1a = (_C1A + z * _C3A) * t4 + (_C2A + z * _C4A) * t10;
-			
-			t1 = kn * z;
-			t2 = exp(-t1);
-			t6 = exp(kn * (z - zc));
-			t10 = 0.1e1 / kn;
-			u2=u2a = t2 * _C1A - t6 * _C2A + t2 * (-0.1e1 + t1) * _C3A * t10 - t6 * (0.1e1 + t1) * _C4A * t10;
-			
-			t1 = ZA * kn;
-			t3 = exp(-kn * z);
-			t8 = exp(kn * (z - zc));
-			u3=u3a = -0.2e1 * t1 * t3 * _C1A + 0.2e1 * t1 * t8 * _C2A - 0.2e1 * t1 * t3 * z * _C3A + 0.2e1 * t1 * t8 * z * _C4A;
-			
-			t2 = kn * z;
-			t6 = exp(-t2);
-			t14 = exp(kn * (z - zc));
-			u4=u4a = -0.2e1 * ZA * (-_C3A + kn * _C1A + t2 * _C3A) * t6 - 0.2e1 * ZA * (_C4A + kn * _C2A + t2 * _C4A) * t14;
-			
-			Z=ZA;
-			del_rho = 0.0;
-			
-		} else {
-			t5 = exp(kn * (zc - z));
-			t11 = exp(kn * (z - 0.1e1));
-			t15 = kn * kn;
-			u1=u1b = (_C1B + z * _C3B) * t5 + (_C2B + z * _C4B) * t11 - del_rho / ZB / t15;
-			
-			t3 = exp(kn * (zc - z));
-			t7 = exp(kn * (z - 0.1e1));
-			t9 = kn * z;
-			t12 = 0.1e1 / kn;
-			u2=u2b = t3 * _C1B - t7 * _C2B + t3 * (-0.1e1 + t9) * _C3B * t12 - t7 * (0.1e1 + t9) * _C4B * t12;
-			
-			t1 = ZB * kn;
-			t4 = exp(kn * (zc - z));
-			t9 = exp(kn * (z - 0.1e1));
-			u3=u3b = -0.2e1 * t1 * t4 * _C1B + 0.2e1 * t1 * t9 * _C2B - 0.2e1 * t1 * t4 * z * _C3B + 0.2e1 * t1 * t9 * z * _C4B;
-			
-			t2 = kn * z;
-			t8 = exp(kn * (zc - z));
-			t17 = exp(kn * (z - 0.1e1));
-			u4=u4b = -0.2e1 * ZB * (-_C3B + kn * _C1B + t2 * _C3B) * t8 - 0.2e1 * ZB * (_C4B + kn * _C2B + t2 * _C4B) * t17 + 0.1e1 / kn * del_rho;
-			
-			Z=ZB;
-		}
-		
-		
-		
-		pp = (double)-(u3 + 2.0*n*M_PI*Z*u2)*cos(n*M_PI*x); /* pressure */
-		
-		txx = (double)(u3 + 4*Z*n*M_PI*u2)*cos(n*M_PI*x); /* xx stress */
-		sum5 += pp;
-		sum6 += txx;
-		
-		u1 *= cos(n*M_PI*x); /* z velocity */
-		sum1 += u1;
-		u2 *= sin(n*M_PI*x); /* x velocity */
-		sum2 += u2;
-		u3 *= cos(n*M_PI*x); /* zz stress */
-		sum3 += u3;
-		u4 *= sin(n*M_PI*x); /* zx stress */
-		sum4 += u4;
-		
-		rho = del_rho* cos(n*M_PI*x); /* density */
-		sum7 += rho;
-	}/* n */
-	
-	/* include terms for n=0 now */
-	if( z >= zc ){
-		del_rho = sigma*dx;
-		rho = del_rho; /* density */
-		sum7 += rho;
-		u3 = del_rho*(z-zc); /* zz stress */
-		sum3 += u3;
-		
-		txx = u3; /* xx stress */
-		pp = -u3; /* pressure */
-		sum5 += pp;
-		sum6 += txx;
-		
-	}
-	
-	mag=sqrt(sum1*sum1+sum2*sum2);
-	//printf("%0.7g %0.7g %0.7g %0.7g %0.7g %0.7g\n",x,y,z,sum3,sum2,sum1);
-	//printf("%0.7g %0.7g %0.7g\n%0.7g %0.7g %0.7g\n\n\n",x,y,z,x+sum3,y+sum2,z+sum1);
-	/*printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7);*/
-	
-	/* Output */
-	if( vel != NULL ) {
-		vel[0] = sum2;
-		vel[1] = sum1;
-	}
-	if( presssure != NULL ) {
-		(*presssure) = sum5;
-	}
-	if( total_stress != NULL ) {
-		total_stress[0] = sum6;
-		total_stress[1] = sum3;
-		total_stress[2] = sum4;
-	}
-	if( strain_rate != NULL ) {
-		if( z<zc ) {
-			Z = ZA;
-		}
-		else {
-			Z = ZB;
-		}
-		strain_rate[0] = (sum6+sum5)/(2.0*Z);
-		strain_rate[1] = (sum3+sum5)/(2.0*Z);
-		strain_rate[2] = (sum4)/(2.0*Z);
-	}
-	/* Value checks, could be cleaned up if needed. Julian Giordani 9-Oct-2006*/
-        if( fabs( sum5 - ( -0.5*(sum6+sum3) ) ) > 1e-5 ) {
-                assert(0);
-        }
-	
-	
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solG/solG.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solG/solG.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,713 @@
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+
+
+void _Velic_solG( 
+		double pos[],
+		double _sigma,
+		double _eta_A, double _eta_B, 
+		double _dx, double _x_0, double _z_c,
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] );
+
+
+int main( int argc, char **argv )
+{
+	int i,j;
+	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
+	double x,z;
+	
+	for (i=0;i<101;i++){
+		for(j=0;j<101;j++){
+			x = i/100.0;
+			z = j/100.0;
+			
+			pos[0] = x;
+			pos[1] = z;
+			_Velic_solG(
+					pos,
+					1.0,
+					10.0, 1.0,
+					0.4,0.55,0.7,
+					vel, &pressure, total_stress, strain_rate );
+			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
+					pos[0],pos[1],
+					vel[0],vel[1], pressure, 
+					total_stress[0], total_stress[1], total_stress[2], 
+					strain_rate[0], strain_rate[1], strain_rate[2] );
+		}
+		printf("\n");
+	}
+	
+	return 0;
+}
+
+
+
+void _Velic_solG(
+		double pos[],
+		double _sigma,
+		double _eta_A, double _eta_B, 
+		double _dx, double _x_0, double _z_c,
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] )
+{
+	double Z,ZA,ZB,u1,u2,u3,u4,pp,txx;
+	double u1a,u2a,u3a,u4a,u1b,u2b,u3b,u4b;
+	double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,x,z;
+	double sigma;
+	double del_rho;
+	int n;
+	double kn;
+	double _C1A,_C2A,_C3A,_C4A,_C1B,_C2B,_C3B,_C4B;
+	double x0,dx,rho,zc;
+	
+	double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
+	double t11,t12,t13,t14,t15,t16,t17,t18,t19,t20;
+	double t21,t22,t23,t24,t25,t26,t27,t28,t29,t30;
+	double t31,t32,t33,t34,t35,t36,t37,t38,t39,t40;
+	double t41,t42,t43,t44,t45,t46,t47,t48,t49,t50;
+	double t51,t52,t53,t54,t55,t56,t57,t58,t59,t60;
+	double t61,t62,t63,t64,t65,t66,t67,t68,t69,t70;
+	double t71,t72,t73,t74,t75,t76,t77,t78,t79,t80;
+	double t81,t82,t83,t85,t86,t87,t88,t89,t90,t91;
+	double t92,t93,t94,t95,t96,t97,t98,t99,t100,t101;
+	double t102,t103,t104,t105,t106,t107,t108,t109,t111,t112;
+	double t113,t114,t115,t116,t117,t118,t120,t121,t122,t124;
+	double t125,t126,t127,t128,t129,t130,t131,t133,t134,t135;
+	double t136,t137,t139,t141,t143,t144,t145,t146,t147,t148;
+	double t151,t152,t153,t154,t156,t157,t158,t159,t162,t163;
+	double t165,t167,t168,t190,t195;
+	
+	/*************************************************************************/
+	/*************************************************************************/
+	/*
+	In layer B (the top layer) we have a dense column of density sigma
+	ranging from x=0 to x= xc:
+	The viscosity of layer B is ZB:
+	The viscosity of layer A is ZA:
+	
+	*/
+	/*************************************************************************/
+	/*************************************************************************/
+	
+	/*************************************************************************/
+	/*************************************************************************/
+	x0 = _x_0;  /* centre of dense block in layer B */
+	dx =  _dx;  /* width of dense block in layer B */
+	sigma = _sigma; /* density parameter for layer B */
+	ZA = _eta_A;    /* viscosity for layer A */
+	ZB = _eta_B; /* viscosity for layer B */
+	zc = _z_c;  /* dividing line between region B and region A */
+	/*************************************************************************/
+	/*************************************************************************/
+	
+	x = pos[0];
+	z = pos[1];
+	
+	sum1=0.0;
+	sum2=0.0;
+	sum3=0.0;
+	sum4=0.0;
+	sum5=0.0;
+	sum6=0.0;
+	sum7=0.0;
+	/* this one blows up when n gets around 85 for some reason... if max n is set to 75 it is fine though */
+	/* fixed the convergence problem */
+	for(n=1;n<85;n++){
+		kn = (double) n*M_PI;
+		
+		/*******************************************/
+		/*            calculate del_rho            */
+		/*******************************************/
+		del_rho = 4.0*sigma*cos(n*M_PI*x0)*sin(n*M_PI*dx/2.0)/n/M_PI;
+		
+		/*******************************************/
+		/*         calculate the constants         */
+		/*******************************************/
+		
+		if ( z < zc ) {
+			t1 = kn * zc;
+			t2 = 0.4e1 * t1;
+			t3 = kn * kn;
+			t5 = 0.2e1 * t3 * zc;
+			t6 = zc * zc;
+			t7 = t6 * t3;
+			t8 = 0.2e1 * t7;
+			t10 = ZA - ZB;
+			t12 = 0.2e1 * zc;
+			t15 = exp(-kn * (0.1e1 + t12));
+			t22 = exp(kn * (t12 - 0.3e1));
+			t26 = ZA + ZB;
+			t29 = exp(-0.3e1 * kn);
+			t34 = exp(-kn);
+			t37 = 0.3e1 * t1;
+			t40 = exp(-t37);
+			t44 = exp(-t1);
+			t50 = exp(kn * (zc - 0.4e1));
+			t54 = 0.2e1 * ZA * kn * zc;
+			t56 = 0.2e1 * ZB * kn;
+			t57 = 0.2e1 * ZA;
+			t58 = t3 * ZA;
+			t60 = 0.2e1 * t58 * zc;
+			t63 = 0.3e1 * ZB * zc * kn;
+			t64 = t3 * ZB;
+			t66 = 0.2e1 * t64 * zc;
+			t68 = 0.2e1 * t64 * t6;
+			t70 = 0.2e1 * t58 * t6;
+			t73 = kn * (zc - 0.2e1);
+			t74 = exp(t73);
+			t82 = exp(kn * (0.3e1 * zc - 0.4e1));
+			t87 = exp(-kn * (0.2e1 + zc));
+			t92 = t10 * t10;
+			t93 = t3 * t92;
+			t94 = exp(-t2);
+			t97 = t26 * t26;
+			t100 = exp(-0.4e1 * kn);
+			t103 = t3 * kn;
+			t104 = t103 * t10;
+			t105 = zc - 0.1e1;
+			t106 = t26 * t105;
+			t107 = kn * t105;
+			t109 = exp(0.2e1 * t107);
+			t114 = exp(0.4e1 * t107);
+			t117 = t103 * zc;
+			t118 = t10 * t26;
+			t120 = exp(0.2e1 * t73);
+			t124 = ZA * ZA;
+			t125 = t3 * t124;
+			t128 = ZB * ZB;
+			t136 = ZA * ZB;
+			t145 = exp(-0.2e1 * kn);
+			t151 = exp(-0.2e1 * kn * (0.1e1 + zc));
+			t156 = exp(-0.2e1 * t1);
+			t165 = -0.2e1 * t93 * t94 + 0.2e1 * t3 * t97 * t100 + 0.8e1 * t104 * t106 * t109 - 0.2e1 * t93 * t114 - 0.8e1 * t117 * t118 * t120 + 0.16e2 * t3 * (-0.2e1 * t125 * zc + 0.2e1 * t7 * t128 + 0.2e1 * t7 * t124 - 0.2e1 * t128 * zc * t3 - t136 - 0.4e1 * t7 * t136 + 0.4e1 * t64 * ZA * zc) * t145 - 0.8e1 * t104 * t106 * t151 + 0.8e1 * t117 * t118 * t156 + 0.4e1 * t64 * ZA + 0.2e1 * t3 * t128 + 0.2e1 * t125;
+			_C1A = (0.2e1 * (-t2 - t5 + t8 + 0.2e1 + kn) * t10 * t15 - 0.2e1 * (0.2e1 - t5 + t2 + t8 - kn) * t10 * t22 - 0.2e1 * (-0.2e1 + kn) * t26 * t29 - 0.2e1 * (kn + 0.2e1) * t26 * t34 + (t37 - 0.2e1) * t10 * t40 + (t1 + 0.2e1) * t26 * t44 + (t1 - 0.2e1) * t26 * t50 + 0.2e1 * (t54 + t56 + t57 - t60 - t63 + t66 - t68 + t70) * t74 + (t37 + 0.2e1) * t10 * t82 - 0.2e1 * (-t68 + t63 - t60 + t70 - t56 + t57 - t54 + t66) * t87) * del_rho / t165;
+			
+			t1 = kn * kn;
+			t3 = 0.2e1 * t1 * zc;
+			t4 = kn * zc;
+			t5 = 0.4e1 * t4;
+			t6 = zc * zc;
+			t7 = t6 * t1;
+			t8 = 0.2e1 * t7;
+			t10 = ZA - ZB;
+			t12 = zc - 0.1e1;
+			t13 = kn * t12;
+			t15 = exp(0.3e1 * t13);
+			t19 = ZA + ZB;
+			t24 = exp(0.2e1 * kn * (zc - 0.2e1));
+			t26 = t1 * ZB;
+			t28 = 0.2e1 * t26 * t6;
+			t30 = ZB * zc * kn;
+			t31 = 0.3e1 * t30;
+			t32 = t1 * ZA;
+			t34 = 0.2e1 * t32 * zc;
+			t36 = 0.2e1 * t32 * t6;
+			t38 = 0.2e1 * ZB * kn;
+			t39 = 0.2e1 * ZA;
+			t41 = ZA * kn * zc;
+			t42 = 0.2e1 * t41;
+			t44 = 0.2e1 * t26 * zc;
+			t47 = exp(-0.2e1 * kn);
+			t52 = exp(t13);
+			t57 = exp(0.2e1 * t13);
+			t64 = exp(kn * (zc - 0.3e1));
+			t67 = 0.3e1 * t4;
+			t71 = exp(-0.2e1 * t4);
+			t76 = kn * (0.1e1 + zc);
+			t77 = exp(-t76);
+			t83 = exp(0.4e1 * t13);
+			t86 = 0.2e1 * (0.2e1 - t3 + t5 + t8 - kn) * t10 * t15 - (t4 - 0.2e1) * t19 * t24 + 0.2e1 * (-t28 + t31 - t34 + t36 - t38 + t39 - t42 + t44) * t47 + 0.2e1 * (kn + 0.2e1) * t19 * t52 - 0.2e1 * (t42 + t38 + t39 - t34 - t31 + t44 - t28 + t36) * t57 + 0.2e1 * (-0.2e1 + kn) * t19 * t64 - (t67 - 0.2e1) * t10 * t71 - 0.2e1 * (-t5 - t3 + t8 + 0.2e1 + kn) * t10 * t77 - (t67 + 0.2e1) * t10 * t83 - 0.2e1 * ZB - t39 - t30 - t41;
+			t88 = t10 * t10;
+			t89 = t1 * t88;
+			t90 = exp(-t5);
+			t93 = t19 * t19;
+			t96 = exp(-0.4e1 * kn);
+			t99 = t1 * kn;
+			t100 = t99 * t10;
+			t101 = t19 * t12;
+			t107 = t99 * zc;
+			t108 = t10 * t19;
+			t112 = ZA * ZA;
+			t113 = t1 * t112;
+			t116 = ZB * ZB;
+			t124 = ZA * ZB;
+			t135 = exp(-0.2e1 * t76);
+			t147 = -0.2e1 * t89 * t90 + 0.2e1 * t1 * t93 * t96 + 0.8e1 * t100 * t101 * t57 - 0.2e1 * t89 * t83 - 0.8e1 * t107 * t108 * t24 + 0.16e2 * t1 * (-0.2e1 * t113 * zc + 0.2e1 * t7 * t116 + 0.2e1 * t7 * t112 - 0.2e1 * t116 * zc * t1 - t124 - 0.4e1 * t7 * t124 + 0.4e1 * t26 * ZA * zc) * t47 - 0.8e1 * t100 * t101 * t135 + 0.8e1 * t107 * t108 * t71 + 0.4e1 * t26 * ZA + 0.2e1 * t1 * t116 + 0.2e1 * t113;
+			_C2A = t86 * del_rho / t147;
+			
+			t1 = kn * zc;
+			t2 = 0.2e1 * t1;
+			t3 = 0.2e1 * kn;
+			t5 = ZA - ZB;
+			t7 = 0.2e1 * zc;
+			t10 = exp(-kn * (0.1e1 + t7));
+			t17 = exp(kn * (t7 - 0.3e1));
+			t20 = ZA + ZB;
+			t22 = exp(-0.3e1 * kn);
+			t25 = exp(-kn);
+			t29 = exp(-0.3e1 * t1);
+			t32 = exp(-t1);
+			t36 = exp(kn * (zc - 0.4e1));
+			t38 = ZA * kn;
+			t40 = 0.2e1 * t38 * zc;
+			t41 = 0.2e1 * t38;
+			t43 = 0.2e1 * ZB * kn;
+			t44 = 0.2e1 * ZA;
+			t47 = 0.2e1 * ZB * zc * kn;
+			t50 = kn * (zc - 0.2e1);
+			t51 = exp(t50);
+			t57 = exp(kn * (0.3e1 * zc - 0.4e1));
+			t63 = exp(-kn * (0.2e1 + zc));
+			t68 = t5 * t5;
+			t69 = kn * t68;
+			t71 = exp(-0.4e1 * t1);
+			t74 = t20 * t20;
+			t77 = exp(-0.4e1 * kn);
+			t80 = kn * kn;
+			t81 = t80 * t5;
+			t82 = zc - 0.1e1;
+			t83 = t20 * t82;
+			t87 = exp(-0.2e1 * kn * (0.1e1 + zc));
+			t91 = t80 * zc;
+			t92 = t5 * t20;
+			t94 = exp(0.2e1 * t50);
+			t98 = ZA * ZA;
+			t102 = zc * zc;
+			t103 = t102 * t80;
+			t104 = ZB * ZB;
+			t112 = ZA * ZB;
+			t121 = exp(-t3);
+			t124 = kn * t82;
+			t126 = exp(0.2e1 * t124);
+			t130 = exp(-t2);
+			t135 = exp(0.4e1 * t124);
+			t144 = -0.2e1 * t69 * t71 + 0.2e1 * t74 * kn * t77 - 0.8e1 * t81 * t83 * t87 - 0.8e1 * t91 * t92 * t94 + 0.16e2 * kn * (-0.2e1 * t80 * t98 * zc + 0.2e1 * t103 * t104 + 0.2e1 * t103 * t98 - 0.2e1 * t104 * zc * t80 - t112 - 0.4e1 * t103 * t112 + 0.4e1 * ZB * t80 * ZA * zc) * t121 + 0.8e1 * t81 * t83 * t126 + 0.8e1 * t91 * t92 * t130 - 0.2e1 * t69 * t135 + 0.2e1 * kn * t104 + 0.2e1 * t98 * kn + 0.4e1 * t112 * kn;
+			_C3A = (-0.2e1 * (t2 - 0.3e1 - t3) * t5 * t10 - 0.2e1 * (t2 + 0.3e1 - t3) * t5 * t17 + 0.2e1 * t20 * t22 - 0.2e1 * t20 * t25 - 0.3e1 * t5 * t29 + t20 * t32 - t20 * t36 + 0.2e1 * (t40 - t41 + t43 + t44 - ZB - t47) * t51 + 0.3e1 * t5 * t57 + 0.2e1 * (-t41 + t43 + ZB - t47 + t40 - t44) * t63) * del_rho / t144;
+			
+			t1 = ZA + ZB;
+			t5 = exp(0.2e1 * kn * (zc - 0.2e1));
+			t7 = ZA * kn;
+			t8 = 0.2e1 * t7;
+			t10 = 0.2e1 * ZB * kn;
+			t13 = 0.2e1 * ZB * zc * kn;
+			t15 = 0.2e1 * t7 * zc;
+			t16 = 0.2e1 * ZA;
+			t18 = 0.2e1 * kn;
+			t19 = exp(-t18);
+			t24 = exp(kn * (zc - 0.3e1));
+			t27 = kn * zc;
+			t28 = 0.2e1 * t27;
+			t30 = ZA - ZB;
+			t33 = kn * (0.1e1 + zc);
+			t34 = exp(-t33);
+			t38 = zc - 0.1e1;
+			t39 = kn * t38;
+			t41 = exp(0.2e1 * t39);
+			t47 = exp(0.3e1 * t39);
+			t50 = exp(-t28);
+			t53 = exp(t39);
+			t57 = exp(0.4e1 * t39);
+			t60 = -t1 * t5 + 0.2e1 * (-t8 + t10 + ZB - t13 + t15 - t16) * t19 + 0.2e1 * t1 * t24 - 0.2e1 * (t28 - 0.3e1 - t18) * t30 * t34 + 0.2e1 * (t15 - t8 + t10 + t16 - ZB - t13) * t41 - 0.2e1 * (t28 + 0.3e1 - t18) * t30 * t47 - 0.3e1 * t30 * t50 - 0.2e1 * t1 * t53 + 0.3e1 * t30 * t57 + ZA + ZB;
+			t62 = t30 * t30;
+			t63 = kn * t62;
+			t65 = exp(-0.4e1 * t27);
+			t68 = t1 * t1;
+			t71 = exp(-0.4e1 * kn);
+			t74 = kn * kn;
+			t75 = t74 * t30;
+			t76 = t1 * t38;
+			t78 = exp(-0.2e1 * t33);
+			t82 = t74 * zc;
+			t83 = t30 * t1;
+			t87 = ZA * ZA;
+			t91 = zc * zc;
+			t92 = t91 * t74;
+			t93 = ZB * ZB;
+			t101 = ZA * ZB;
+			t126 = -0.2e1 * t63 * t65 + 0.2e1 * t68 * kn * t71 - 0.8e1 * t75 * t76 * t78 - 0.8e1 * t82 * t83 * t5 + 0.16e2 * kn * (-0.2e1 * t74 * t87 * zc + 0.2e1 * t92 * t93 + 0.2e1 * t92 * t87 - 0.2e1 * t93 * zc * t74 - t101 - 0.4e1 * t92 * t101 + 0.4e1 * ZB * t74 * ZA * zc) * t19 + 0.8e1 * t75 * t76 * t41 + 0.8e1 * t82 * t83 * t50 - 0.2e1 * t63 * t57 + 0.2e1 * kn * t93 + 0.2e1 * t87 * kn + 0.4e1 * t101 * kn;
+			_C4A = t60 * del_rho / t126;
+		} else { 
+			t1 = ZA - ZB;
+			t2 = ZA * kn;
+			t4 = 0.2e1 * t2 * zc;
+			t5 = 0.2e1 * ZA;
+			t7 = ZB * zc * kn;
+			t10 = kn * zc;
+			t11 = 0.4e1 * t10;
+			t12 = exp(-t11);
+			t14 = ZA + ZB;
+			t15 = 0.4e1 * t2;
+			t17 = 0.2e1 * ZB * kn;
+			t21 = kn * (0.1e1 + zc);
+			t23 = exp(-0.2e1 * t21);
+			t25 = kn * kn;
+			t26 = ZA * ZA;
+			t28 = t25 * t26 * zc;
+			t30 = zc * zc;
+			t31 = t30 * t25;
+			t32 = t31 * t26;
+			t33 = 0.4e1 * t32;
+			t34 = ZB * t25;
+			t36 = t34 * ZA * zc;
+			t39 = t26 * zc * kn;
+			t40 = 0.4e1 * t39;
+			t41 = ZA * ZB;
+			t42 = t41 * kn;
+			t44 = ZB * ZB;
+			t45 = t44 * zc;
+			t46 = t45 * t25;
+			t48 = t41 * t10;
+			t49 = 0.3e1 * t48;
+			t50 = t31 * t44;
+			t51 = 0.2e1 * t50;
+			t52 = 0.2e1 * t41;
+			t53 = t31 * t41;
+			t54 = 0.6e1 * t53;
+			t57 = exp(-0.2e1 * kn);
+			t64 = (-t11 - 0.2e1 * t25 * zc + 0.2e1 * t31 + 0.2e1 + kn) * t1;
+			t68 = exp(-kn * (0.1e1 + 0.3e1 * zc));
+			t72 = -0.2e1 + kn;
+			t76 = exp(kn * (zc - 0.3e1));
+			t80 = t25 * kn;
+			t81 = t30 * t80;
+			t85 = t30 * zc;
+			t91 = t45 * kn;
+			t97 = 0.2e1 * t39;
+			t106 = -0.2e1 * t81 * t44 + 0.2e1 * t44 * t80 * t85 + 0.2e1 * t26 * t80 * t85 + t52 + t42 + 0.2e1 * t91 + 0.8e1 * t53 + 0.4e1 * t81 * t41 - 0.4e1 * t48 + t46 + t97 - 0.2e1 * t36 - t33 - 0.4e1 * t41 * t80 * t85 - 0.4e1 * t50 - 0.2e1 * t26 * t30 * t80 + t28;
+			t107 = exp(-t21);
+			t112 = zc - 0.1e1;
+			t113 = kn * t112;
+			t115 = exp(0.2e1 * t113);
+			t117 = t1 * t1;
+			t120 = exp(0.3e1 * t113);
+			t124 = exp(-0.2e1 * t10);
+			t127 = t14 * t14;
+			t131 = exp(-kn * (zc + 0.3e1));
+			t133 = exp(t113);
+			t137 = t1 * (t4 - t5 + t7) * t12 - t14 * (t5 + t4 - t15 - t7 + t17) * t23 + 0.2e1 * (-0.8e1 * t28 + t33 + 0.12e2 * t36 + t40 + 0.2e1 * t42 - 0.4e1 * t46 - t49 + t51 - t52 - t54) * t57 + t64 * t14 * t68 + 0.4e1 * t10 * t1 * t14 * t72 * t76 - 0.4e1 * t106 * t107 + t1 * (t5 + t4 - t15 + t7 - t17) * t115 + t117 * t72 * t120 - 0.2e1 * (t49 - t54 + t33 + t51 - t52 - t40) * t124 - t127 * t72 * t131 - t64 * t14 * t133 - t48 + 0.2e1 * t26 - t97 + t52 + t91;
+			t143 = exp(-0.4e1 * kn);
+			t148 = exp(0.4e1 * t113);
+			t152 = t80 * ZB;
+			t153 = t152 * zc;
+			t154 = t1 * t14;
+			t158 = exp(0.2e1 * kn * (zc - 0.2e1));
+			t162 = t152 * t1;
+			t163 = t14 * t112;
+			t190 = -0.2e1 * t34 * t117 * t12 + 0.2e1 * t34 * t127 * t143 - 0.2e1 * t34 * t117 * t148 - 0.8e1 * t153 * t154 * t158 - 0.8e1 * t162 * t163 * t23 + 0.16e2 * t34 * (-0.2e1 * t28 + t51 + 0.2e1 * t32 - 0.2e1 * t46 - t41 - 0.4e1 * t53 + 0.4e1 * t36) * t57 + 0.8e1 * t162 * t163 * t115 + 0.8e1 * t153 * t154 * t124 + 0.2e1 * t25 * t44 * ZB + 0.2e1 * t34 * t26 + 0.4e1 * t25 * t44 * ZA;
+			_C1B = t137 * del_rho / t190;
+			
+			t1 = ZA - ZB;
+			t2 = t1 * t1;
+			t3 = kn + 0.2e1;
+			t5 = kn * zc;
+			t6 = 0.4e1 * t5;
+			t7 = exp(-t6);
+			t9 = kn * kn;
+			t12 = zc * zc;
+			t13 = t12 * t9;
+			t16 = (0.2e1 - 0.2e1 * t9 * zc + t6 + 0.2e1 * t13 - kn) * t1;
+			t17 = ZA + ZB;
+			t19 = kn * (0.1e1 + zc);
+			t21 = exp(-0.2e1 * t19);
+			t24 = ZA * ZA;
+			t25 = t9 * kn;
+			t27 = t12 * zc;
+			t33 = ZA * ZB;
+			t37 = t12 * t25;
+			t40 = ZB * ZB;
+			t46 = t13 * t24;
+			t47 = 0.4e1 * t46;
+			t49 = t9 * t24 * zc;
+			t50 = t13 * t33;
+			t52 = ZB * t9;
+			t54 = t52 * ZA * zc;
+			t56 = t13 * t40;
+			t58 = t40 * zc;
+			t59 = t58 * t9;
+			t61 = t24 * zc * kn;
+			t63 = t33 * kn;
+			t64 = t33 * t5;
+			t68 = 0.2e1 * t33;
+			t69 = 0.2e1 * t24 * t25 * t27 - 0.2e1 * t24 * t12 * t25 - 0.4e1 * t33 * t25 * t27 + 0.4e1 * t37 * t33 + 0.2e1 * t40 * t25 * t27 - 0.2e1 * t37 * t40 + t47 - t49 - 0.8e1 * t50 + 0.2e1 * t54 + 0.4e1 * t56 - t59 + 0.2e1 * t61 + t63 - 0.4e1 * t64 + 0.2e1 * t58 * kn - t68;
+			t71 = exp(-0.2e1 * kn);
+			t74 = ZA * kn;
+			t75 = 0.4e1 * t74;
+			t77 = 0.2e1 * t74 * zc;
+			t78 = 0.2e1 * ZA;
+			t80 = ZB * zc * kn;
+			t82 = 0.2e1 * ZB * kn;
+			t88 = exp(-kn * (0.1e1 + 0.3e1 * zc));
+			t90 = 0.6e1 * t50;
+			t91 = 0.2e1 * t56;
+			t92 = 0.3e1 * t64;
+			t93 = 0.4e1 * t61;
+			t97 = exp(kn * (zc - 0.3e1));
+			t103 = 0.2e1 * t63;
+			t105 = exp(-t19);
+			t108 = zc - 0.1e1;
+			t109 = kn * t108;
+			t111 = exp(0.2e1 * t109);
+			t117 = exp(0.3e1 * t109);
+			t122 = exp(-0.2e1 * t5);
+			t130 = exp(-kn * (zc + 0.3e1));
+			t134 = exp(t109);
+			t141 = -t2 * t3 * t7 - t16 * t17 * t21 + 0.4e1 * t69 * t71 - t1 * (-t75 + t77 - t78 + t80 - t82) * t88 - 0.2e1 * (-t90 + t91 + t47 - t92 + t93 - t68) * t97 + 0.2e1 * (t47 - 0.8e1 * t49 - t90 + 0.12e2 * t54 - 0.4e1 * t59 + t91 - t93 - t103 + t92 - t68) * t105 + t16 * t17 * t111 - t1 * (t77 + t78 + t80) * t117 + 0.4e1 * t5 * t1 * t17 * t3 * t122 + t17 * (t77 + t78 - t80) * t130 + t17 * (-t75 + t77 - t78 - t80 + t82) * t134 + kn * t40 + t103 + 0.2e1 * t40 + t24 * kn + 0.2e1 * t24 + 0.4e1 * t33;
+			t146 = t17 * t17;
+			t148 = exp(-0.4e1 * kn);
+			t153 = exp(0.4e1 * t109);
+			t157 = ZB * t25;
+			t158 = t157 * zc;
+			t159 = t1 * t17;
+			t163 = exp(0.2e1 * kn * (zc - 0.2e1));
+			t167 = t157 * t1;
+			t168 = t17 * t108;
+			t195 = -0.2e1 * t52 * t2 * t7 + 0.2e1 * t52 * t146 * t148 - 0.2e1 * t52 * t2 * t153 - 0.8e1 * t158 * t159 * t163 - 0.8e1 * t167 * t168 * t21 + 0.16e2 * t52 * (-0.2e1 * t49 + t91 + 0.2e1 * t46 - 0.2e1 * t59 - t33 - 0.4e1 * t50 + 0.4e1 * t54) * t71 + 0.8e1 * t167 * t168 * t111 + 0.8e1 * t158 * t159 * t122 + 0.2e1 * t9 * t40 * ZB + 0.2e1 * t52 * t24 + 0.4e1 * t9 * t40 * ZA;
+			_C2B = t141 * del_rho / t195;
+			
+			t1 = 0.2e1 * ZA;
+			t3 = ZA - ZB;
+			t4 = (t1 + ZB) * t3;
+			t5 = kn * zc;
+			t7 = exp(-0.4e1 * t5);
+			t9 = ZA + ZB;
+			t13 = kn * (0.1e1 + zc);
+			t15 = exp(-0.2e1 * t13);
+			t17 = ZA * ZB;
+			t19 = 0.6e1 * t17 * t5;
+			t20 = ZB * ZB;
+			t21 = zc * t20;
+			t22 = t21 * kn;
+			t23 = 0.2e1 * t22;
+			t24 = ZA * ZA;
+			t26 = t24 * zc * kn;
+			t27 = 0.4e1 * t26;
+			t29 = 0.2e1 * kn;
+			t30 = exp(-t29);
+			t33 = t3 * t9;
+			t34 = 0.2e1 * t5;
+			t35 = t34 - 0.3e1 - t29;
+			t39 = exp(-kn * (0.1e1 + 0.3e1 * zc));
+			t44 = exp(kn * (zc - 0.3e1));
+			t48 = kn * kn;
+			t51 = 0.2e1 * t48 * t24 * zc;
+			t52 = zc * zc;
+			t53 = t52 * t48;
+			t55 = 0.2e1 * t53 * t24;
+			t56 = ZB * t48;
+			t59 = 0.4e1 * t56 * ZA * zc;
+			t61 = 0.4e1 * t53 * t17;
+			t63 = 0.2e1 * t21 * t48;
+			t65 = 0.2e1 * t53 * t20;
+			t69 = exp(-t13);
+			t72 = zc - 0.1e1;
+			t73 = kn * t72;
+			t75 = exp(0.2e1 * t73);
+			t77 = t3 * t3;
+			t79 = exp(0.3e1 * t73);
+			t82 = exp(-t34);
+			t85 = t9 * t9;
+			t88 = exp(-kn * (zc + 0.3e1));
+			t90 = exp(t73);
+			t94 = -t4 * t7 - t9 * (t1 - ZB) * t15 + 0.2e1 * (-t19 + t23 + t27 - t17) * t30 - t33 * t35 * t39 - 0.4e1 * t5 * t33 * t44 + 0.4e1 * (-t51 + t55 + t59 - t61 - t63 + t65 - 0.3e1 * t26 - 0.3e1 * t22 + t19 - t17) * t69 + t4 * t75 - t77 * t79 + 0.2e1 * (-t19 + t23 + t27 + t17) * t82 + t85 * t88 + t33 * t35 * t90 + 0.2e1 * t24 - t20 + t17;
+			t96 = ZB * kn;
+			t101 = exp(-0.4e1 * kn);
+			t105 = t56 * t3;
+			t106 = t9 * t72;
+			t117 = t56 * zc;
+			t121 = exp(0.2e1 * kn * (zc - 0.2e1));
+			t129 = exp(0.4e1 * t73);
+			t141 = -0.2e1 * t96 * t77 * t7 + 0.2e1 * t96 * t85 * t101 - 0.8e1 * t105 * t106 * t15 + 0.16e2 * t96 * (-t51 + t65 + t55 - t63 - t17 - t61 + t59) * t30 + 0.8e1 * t105 * t106 * t75 - 0.8e1 * t117 * t33 * t121 + 0.8e1 * t117 * t33 * t82 - 0.2e1 * t96 * t77 * t129 + 0.2e1 * t96 * t24 + 0.2e1 * t20 * ZB * kn + 0.4e1 * t20 * kn * ZA;
+			_C3B = t94 * del_rho / t141;
+			
+			t1 = ZA - ZB;
+			t2 = t1 * t1;
+			t3 = kn * zc;
+			t5 = exp(-0.4e1 * t3);
+			t6 = t2 * t5;
+			t7 = ZA + ZB;
+			t8 = t1 * t7;
+			t9 = 0.2e1 * t3;
+			t10 = 0.2e1 * kn;
+			t11 = t9 + 0.3e1 - t10;
+			t13 = kn * (0.1e1 + zc);
+			t15 = exp(-0.2e1 * t13);
+			t18 = ZA * ZB;
+			t20 = 0.6e1 * t18 * t3;
+			t21 = kn * kn;
+			t22 = ZB * t21;
+			t25 = 0.4e1 * t22 * ZA * zc;
+			t26 = ZB * ZB;
+			t27 = t26 * zc;
+			t29 = 0.2e1 * t27 * t21;
+			t30 = ZA * ZA;
+			t32 = t30 * zc * kn;
+			t34 = zc * zc;
+			t35 = t34 * t21;
+			t37 = 0.2e1 * t35 * t30;
+			t39 = 0.2e1 * t35 * t26;
+			t41 = 0.4e1 * t35 * t18;
+			t44 = 0.2e1 * t21 * t30 * zc;
+			t45 = t27 * kn;
+			t48 = exp(-t10);
+			t51 = 0.2e1 * ZA;
+			t53 = (t51 + ZB) * t1;
+			t57 = exp(-kn * (0.1e1 + 0.3e1 * zc));
+			t59 = 0.2e1 * t45;
+			t60 = 0.4e1 * t32;
+			t64 = exp(kn * (zc - 0.3e1));
+			t68 = exp(-t13);
+			t71 = zc - 0.1e1;
+			t72 = kn * t71;
+			t74 = exp(0.2e1 * t72);
+			t78 = exp(0.3e1 * t72);
+			t80 = exp(-t9);
+			t81 = t8 * t80;
+			t85 = t7 * (t51 - ZB);
+			t88 = exp(-kn * (zc + 0.3e1));
+			t90 = exp(t72);
+			t93 = t6 + t8 * t11 * t15 - 0.4e1 * (-t18 - t20 + t25 - t29 + 0.3e1 * t32 + t37 + t39 - t41 - t44 + 0.3e1 * t45) * t48 - t53 * t57 + 0.2e1 * (-t20 + t59 + t60 - t18) * t64 + 0.2e1 * (-t20 + t59 + t60 + t18) * t68 - t8 * t11 * t74 + t53 * t78 - 0.4e1 * t3 * t81 - t85 * t88 + t85 * t90 - 0.2e1 * t18 - t26 - t30;
+			t95 = ZB * kn;
+			t98 = t7 * t7;
+			t100 = exp(-0.4e1 * kn);
+			t104 = t22 * t1;
+			t105 = t7 * t71;
+			t116 = t22 * zc;
+			t120 = exp(0.2e1 * kn * (zc - 0.2e1));
+			t127 = exp(0.4e1 * t72);
+			t139 = -0.2e1 * t95 * t6 + 0.2e1 * t95 * t98 * t100 - 0.8e1 * t104 * t105 * t15 + 0.16e2 * t95 * (-t44 + t39 + t37 - t29 - t18 - t41 + t25) * t48 + 0.8e1 * t104 * t105 * t74 - 0.8e1 * t116 * t8 * t120 + 0.8e1 * t116 * t81 - 0.2e1 * t95 * t2 * t127 + 0.2e1 * t95 * t30 + 0.2e1 * t26 * ZB * kn + 0.4e1 * t26 * kn * ZA;
+			_C4B = t93 * del_rho / t139;
+			
+			
+		}
+		
+		/*******************************************/
+		/*       calculate the velocities etc      */
+		/*******************************************/
+		
+		if ( z < zc ) {
+			t4 = exp(-kn * z);
+			t10 = exp(kn * (z - zc));
+			u1=u1a = (_C1A + z * _C3A) * t4 + (_C2A + z * _C4A) * t10;
+			
+			t1 = kn * z;
+			t2 = exp(-t1);
+			t6 = exp(kn * (z - zc));
+			t10 = 0.1e1 / kn;
+			u2=u2a = t2 * _C1A - t6 * _C2A + t2 * (-0.1e1 + t1) * _C3A * t10 - t6 * (0.1e1 + t1) * _C4A * t10;
+			
+			t1 = ZA * kn;
+			t3 = exp(-kn * z);
+			t8 = exp(kn * (z - zc));
+			u3=u3a = -0.2e1 * t1 * t3 * _C1A + 0.2e1 * t1 * t8 * _C2A - 0.2e1 * t1 * t3 * z * _C3A + 0.2e1 * t1 * t8 * z * _C4A;
+			
+			t2 = kn * z;
+			t6 = exp(-t2);
+			t14 = exp(kn * (z - zc));
+			u4=u4a = -0.2e1 * ZA * (-_C3A + kn * _C1A + t2 * _C3A) * t6 - 0.2e1 * ZA * (_C4A + kn * _C2A + t2 * _C4A) * t14;
+			
+			Z=ZA;
+			del_rho = 0.0;
+			
+		} else {
+			t5 = exp(kn * (zc - z));
+			t11 = exp(kn * (z - 0.1e1));
+			t15 = kn * kn;
+			u1=u1b = (_C1B + z * _C3B) * t5 + (_C2B + z * _C4B) * t11 - del_rho / ZB / t15;
+			
+			t3 = exp(kn * (zc - z));
+			t7 = exp(kn * (z - 0.1e1));
+			t9 = kn * z;
+			t12 = 0.1e1 / kn;
+			u2=u2b = t3 * _C1B - t7 * _C2B + t3 * (-0.1e1 + t9) * _C3B * t12 - t7 * (0.1e1 + t9) * _C4B * t12;
+			
+			t1 = ZB * kn;
+			t4 = exp(kn * (zc - z));
+			t9 = exp(kn * (z - 0.1e1));
+			u3=u3b = -0.2e1 * t1 * t4 * _C1B + 0.2e1 * t1 * t9 * _C2B - 0.2e1 * t1 * t4 * z * _C3B + 0.2e1 * t1 * t9 * z * _C4B;
+			
+			t2 = kn * z;
+			t8 = exp(kn * (zc - z));
+			t17 = exp(kn * (z - 0.1e1));
+			u4=u4b = -0.2e1 * ZB * (-_C3B + kn * _C1B + t2 * _C3B) * t8 - 0.2e1 * ZB * (_C4B + kn * _C2B + t2 * _C4B) * t17 + 0.1e1 / kn * del_rho;
+			
+			Z=ZB;
+		}
+		
+		
+		
+		pp = (double)-(u3 + 2.0*n*M_PI*Z*u2)*cos(n*M_PI*x); /* pressure */
+		
+		txx = (double)(u3 + 4*Z*n*M_PI*u2)*cos(n*M_PI*x); /* xx stress */
+		sum5 += pp;
+		sum6 += txx;
+		
+		u1 *= cos(n*M_PI*x); /* z velocity */
+		sum1 += u1;
+		u2 *= sin(n*M_PI*x); /* x velocity */
+		sum2 += u2;
+		u3 *= cos(n*M_PI*x); /* zz stress */
+		sum3 += u3;
+		u4 *= sin(n*M_PI*x); /* zx stress */
+		sum4 += u4;
+		
+		rho = del_rho* cos(n*M_PI*x); /* density */
+		sum7 += rho;
+	}/* n */
+	
+	/* include terms for n=0 now */
+	if( z >= zc ){
+		del_rho = sigma*dx;
+		rho = del_rho; /* density */
+		sum7 += rho;
+		u3 = del_rho*(z-zc); /* zz stress */
+		sum3 += u3;
+		
+		txx = u3; /* xx stress */
+		pp = -u3; /* pressure */
+		sum5 += pp;
+		sum6 += txx;
+		
+	}
+	
+	mag=sqrt(sum1*sum1+sum2*sum2);
+	//printf("%0.7g %0.7g %0.7g %0.7g %0.7g %0.7g\n",x,y,z,sum3,sum2,sum1);
+	//printf("%0.7g %0.7g %0.7g\n%0.7g %0.7g %0.7g\n\n\n",x,y,z,x+sum3,y+sum2,z+sum1);
+	/*printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7);*/
+	
+	/* Output */
+	if( vel != NULL ) {
+		vel[0] = sum2;
+		vel[1] = sum1;
+	}
+	if( presssure != NULL ) {
+		(*presssure) = sum5;
+	}
+	if( total_stress != NULL ) {
+		total_stress[0] = sum6;
+		total_stress[1] = sum3;
+		total_stress[2] = sum4;
+	}
+	if( strain_rate != NULL ) {
+		if( z<zc ) {
+			Z = ZA;
+		}
+		else {
+			Z = ZB;
+		}
+		strain_rate[0] = (sum6+sum5)/(2.0*Z);
+		strain_rate[1] = (sum3+sum5)/(2.0*Z);
+		strain_rate[2] = (sum4)/(2.0*Z);
+	}
+	/* Value checks, could be cleaned up if needed. Julian Giordani 9-Oct-2006*/
+        if( fabs( sum5 - ( -0.5*(sum6+sum3) ) ) > 1e-5 ) {
+                assert(0);
+        }
+	
+	
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solH/Analytic_solH.c
--- a/SysTest/AnalyticPlugins/Velic_solH/Analytic_solH.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,158 +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:
-*+		Mirko Velic
-*+		Julian Giordani
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Patrick Sunter
-** $Id: solH.c 636 2006-09-08 03:07:06Z JulianGiordani $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include "Analytic_solH.h"
-
-const Type Velic_solH_Type = "Underworld_Velic_solH";
-
-void Velic_solH_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
-	Velic_solH* self = (Velic_solH*) analyticSolution;
-	
-	_Velic_solH( coord, self->sigma, self->eta, self->dx, self->dy, NULL, pressure, NULL, NULL );
-}
-
-void Velic_solH_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
-	Velic_solH* self = (Velic_solH*) analyticSolution;
-	
-	_Velic_solH( coord, self->sigma, self->eta, self->dx, self->dy, velocity, NULL, NULL, NULL );
-}
-
-void Velic_solH_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
-	Velic_solH* self = (Velic_solH*) analyticSolution;
-	
-	_Velic_solH( coord, self->sigma, self->eta, self->dx, self->dy, NULL, NULL, stress, NULL );
-}
-
-
-void Velic_solH_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
-	Velic_solH* self = (Velic_solH*) analyticSolution;
-	
-	_Velic_solH( coord, self->sigma, self->eta, self->dx, self->dy, NULL, NULL, NULL, strainRate );
-}
-
-void _Velic_solH_Init( Velic_solH* self, double sigma, double eta, double dx, double dy ) {
-	// TODO	Bool                     correctInput = True;
-	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
-        self->_getAnalyticVelocity    = Velic_solH_VelocityFunction;
-	self->_getAnalyticPressure    = Velic_solH_PressureFunction;
-	self->_getAnalyticTotalStress = Velic_solH_StressFunction;
-	self->_getAnalyticStrainRate  = Velic_solH_StrainRateFunction;
-
-	self->sigma = sigma;
-	self->eta = eta;
-	self->dx = dx;
-	self->dy = dy;
-}
-
-void _Velic_solH_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
-	Velic_solH* self = (Velic_solH*) analyticSolution;
-	FeVariable*              velocityField;
-	FeVariable*              pressureField;
-	FeVariable*              stressField;
-	FeVariable*              strainRateField;
-	FeVariable*              recoveredStrainRateField;
-	FeVariable*              recoveredStressField;
-	double                   sigma, eta, dx, dy;
-
-	/* Construct Parent */
-	_AnalyticSolution_AssignFromXML( self, cf, data );
-
-	/* Create Analytic Fields */
-	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solH_VelocityFunction );
-
-	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solH_PressureFunction );
-
-	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False, data );
-	if ( stressField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solH_StressFunction );
-
-	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
-	if ( strainRateField   ) {
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solH_StrainRateFunction );
-	}
-
-	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
-	if ( recoveredStrainRateField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solH_StrainRateFunction );
-
-	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
-	if ( recoveredStressField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solH_StressFunction );
-	
-
-	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solH_sigma", 1.0  );
-	eta = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solH_eta", 1.0  );
-	dx = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solH_dx", 0.4  );
-	dy = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solH_dy", 0.6  );
-
-	_Velic_solH_Init( self, sigma, eta, dx, dy );
-
-}
-
-void* _Velic_solH_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Velic_solH);
-	Type                                                      type = Velic_solH_Type;
-	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
-	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
-	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solH_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Velic_solH_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _AnalyticSolution_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 Underworld_Velic_solH_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Velic_solH_Type, (Name)"0", _Velic_solH_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solH/Analytic_solH.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solH/Analytic_solH.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,158 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Mirko Velic
+*+		Julian Giordani
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Patrick Sunter
+** $Id: solH.c 636 2006-09-08 03:07:06Z JulianGiordani $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include "Analytic_solH.h"
+
+const Type Velic_solH_Type = "Underworld_Velic_solH";
+
+void Velic_solH_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
+	Velic_solH* self = (Velic_solH*) analyticSolution;
+	
+	_Velic_solH( coord, self->sigma, self->eta, self->dx, self->dy, NULL, pressure, NULL, NULL );
+}
+
+void Velic_solH_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
+	Velic_solH* self = (Velic_solH*) analyticSolution;
+	
+	_Velic_solH( coord, self->sigma, self->eta, self->dx, self->dy, velocity, NULL, NULL, NULL );
+}
+
+void Velic_solH_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
+	Velic_solH* self = (Velic_solH*) analyticSolution;
+	
+	_Velic_solH( coord, self->sigma, self->eta, self->dx, self->dy, NULL, NULL, stress, NULL );
+}
+
+
+void Velic_solH_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
+	Velic_solH* self = (Velic_solH*) analyticSolution;
+	
+	_Velic_solH( coord, self->sigma, self->eta, self->dx, self->dy, NULL, NULL, NULL, strainRate );
+}
+
+void _Velic_solH_Init( Velic_solH* self, double sigma, double eta, double dx, double dy ) {
+	// TODO	Bool                     correctInput = True;
+	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
+        self->_getAnalyticVelocity    = Velic_solH_VelocityFunction;
+	self->_getAnalyticPressure    = Velic_solH_PressureFunction;
+	self->_getAnalyticTotalStress = Velic_solH_StressFunction;
+	self->_getAnalyticStrainRate  = Velic_solH_StrainRateFunction;
+
+	self->sigma = sigma;
+	self->eta = eta;
+	self->dx = dx;
+	self->dy = dy;
+}
+
+void _Velic_solH_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
+	Velic_solH* self = (Velic_solH*) analyticSolution;
+	FeVariable*              velocityField;
+	FeVariable*              pressureField;
+	FeVariable*              stressField;
+	FeVariable*              strainRateField;
+	FeVariable*              recoveredStrainRateField;
+	FeVariable*              recoveredStressField;
+	double                   sigma, eta, dx, dy;
+
+	/* Construct Parent */
+	_AnalyticSolution_AssignFromXML( self, cf, data );
+
+	/* Create Analytic Fields */
+	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solH_VelocityFunction );
+
+	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solH_PressureFunction );
+
+	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False, data );
+	if ( stressField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solH_StressFunction );
+
+	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
+	if ( strainRateField   ) {
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solH_StrainRateFunction );
+	}
+
+	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
+	if ( recoveredStrainRateField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solH_StrainRateFunction );
+
+	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
+	if ( recoveredStressField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solH_StressFunction );
+	
+
+	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solH_sigma", 1.0  );
+	eta = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solH_eta", 1.0  );
+	dx = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solH_dx", 0.4  );
+	dy = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solH_dy", 0.6  );
+
+	_Velic_solH_Init( self, sigma, eta, dx, dy );
+
+}
+
+void* _Velic_solH_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Velic_solH);
+	Type                                                      type = Velic_solH_Type;
+	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
+	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
+	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solH_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Velic_solH_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _AnalyticSolution_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 Underworld_Velic_solH_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Velic_solH_Type, (Name)"0", _Velic_solH_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solH/solH.c
--- a/SysTest/AnalyticPlugins/Velic_solH/solH.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,222 +0,0 @@
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-
-void _Velic_solH( 
-		double pos[],
-		double _sigma,
-		double _eta, 
-		double _dx, double _dy,
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] );
-
-
-int main( int argc, char **argv )
-{
-	int i,j;
-	double pos[3], vel[3], pressure, total_stress[6], strain_rate[6];
-	double x,y,z;
-	
-	for (i=0;i<101;i++){
-		for(j=0;j<101;j++){
-			x = i/100.0;
-			y = j/100.0;
-			
-			pos[0] = x;
-			pos[1] = y;
-			z = 0.2;
-			pos[2] = z;
-			_Velic_solH(
-					pos,
-					1.0,
-					1.0,
-					0.4,0.6,
-					vel, &pressure, total_stress, strain_rate );
-		}
-	}
-	
-	return 0;
-}
-
-
-
-
-void _Velic_solH(
-		double pos[],
-		double _sigma,
-		double _eta,
-		double _dx, double _dy,
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] )
-{
-	
-	double Z,u1,u2,u3,u4,u5,u6;
-	double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,sum8,sum9,sum10,sum11,x,y,z;
-	double sigma,dx,dy;
-	double del_rho;
-	int n,m;
-	double L1,kn,km;
-	double Am,Ap,Bm,Bp,C,D,E;
-	double pp,txx,tyy,tyx,rho;
-	
-	/*************************************************************************/
-	
-	dx = _dx; /* x width of block */
-	dy = _dy; /* y width of block */
-	sigma = _sigma; /* density of block */
-	Z = _eta; /* viscosity */
-	z=pos[2]; /* height of 2-d slice in x-y plane to view */
-	x = pos[0];
-	y = pos[1];
-	
-	sum1=0.0;
-	sum2=0.0;
-	sum3=0.0;
-	sum4=0.0;
-	sum5=0.0;
-	sum6=0.0;
-	sum7=0.0;
-	sum8=0.0;
-	sum9=0.0;
-	sum10=0.0;
-	sum11=0.0;
-	
-	for(n=0;n<45;n++){
-		for(m=0;m<45;m++){
-			
-			if ( n!=0 && m!=0 ){
-				del_rho = 4.0*sigma*sin((double)n*M_PI*dx)*sin((double)m*M_PI*dy)/(double)n/M_PI/(double)m/M_PI;
-			} else {
-				if ( n==0 && m !=0){
-					del_rho = 2.0*sigma*dx*sin((double)m*M_PI*dy)/(double)m/M_PI;
-				} else {
-					if ( n!=0 && m ==0){
-						del_rho = 2.0*sigma*dy*sin((double)n*M_PI*dx)/(double)n/M_PI;
-					} else {
-						del_rho = sigma*dx*dy;
-					}
-				}
-			}
-			kn = M_PI*(double)n;
-			km = M_PI*(double)m;
-			
-			L1 = M_PI*sqrt( (double)(n*n + m*m));
-			
-			Am = exp((z-2.0)*L1)-exp(-z*L1);
-			Ap = exp((z-2.0)*L1)+exp(-z*L1);
-			Bm = exp((z-1.0)*L1)-exp(-(z+1.0)*L1);
-			Bp = exp((z-1.0)*L1)+exp(-(z+1.0)*L1);
-			C = (exp(-z*L1)-1.0)*(exp((z-1.0)*L1)-1.0);
-			D = exp((z-1.0)*L1)-exp(-z*L1);
-			E = (1.0+exp(-L1));
-			
-			u1 = (n!=0 || m!=0) ? -( z*Am+(z-1.0)*Bm )*del_rho/( 2*Z*L1*E*E ) - C*del_rho/(Z*L1*L1*E) : 0.0;
-			if ( m !=0 ){
-				u2 =  ( z*Ap+(z-1.0)*Bp )*del_rho*km/( 2*Z*L1*L1*E*E ) - D*del_rho*km/(2*Z*L1*L1*L1*E);
-				u5 =  ( z*Am+(z-1.0)*Bm )*del_rho*km/( L1*E*E ) + C*del_rho*km/(L1*L1*E);
-			} else {
-				u2 = 0.0;
-				u5 = 0.0;
-			}
-			if ( n !=0 ){
-				u3 =  ( z*Ap+(z-1.0)*Bp )*del_rho*kn/( 2*Z*L1*L1*E*E ) - D*del_rho*kn/(2*Z*L1*L1*L1*E);
-				u6 =  ( z*Am+(z-1.0)*Bm )*del_rho*kn/( L1*E*E ) + C*del_rho*kn/(L1*L1*E);
-			} else {
-				u3 = 0.0;
-				u6 = 0.0;
-			}
-			u4 = (n==0 && m==0) ? del_rho*(z-0.5) :  -( z*Ap+(z-1.0)*Bp )*del_rho/( E*E ) + 2.0*D*del_rho/(L1*E) ;
-			pp = -u4-2.0*Z*(kn*u3+km*u2);
-			
-			txx = (-pp +2.0*Z*kn*u3)*cos(n*M_PI*x)*cos(m*M_PI*y);
-			tyy = (-pp +2.0*Z*km*u2)*cos(n*M_PI*x)*cos(m*M_PI*y);
-			tyx = -Z*(km*u3+kn*u2)*sin(n*M_PI*x)*sin(m*M_PI*y);
-			
-			//printf("u2 = %0.7g n=%d m=%d --> L2 = %0.7g  --> L1 = %0.7g\n",u2,n,m,L2,L1);
-			u1 *= cos(n*M_PI*x)*cos(m*M_PI*y); 
-			sum1 += u1;
-			u2 *= cos(n*M_PI*x)*sin(m*M_PI*y);
-			sum2 += u2;
-			u3 *= sin(n*M_PI*x)*cos(m*M_PI*y);
-			sum3 += u3;
-			u4 *= cos(n*M_PI*x)*cos(m*M_PI*y);
-			sum4 += u4;
-			u5 *= cos(n*M_PI*x)*sin(m*M_PI*y);
-			sum5 += u5;
-			u6 *= sin(n*M_PI*x)*cos(m*M_PI*y);
-			sum6 += u6;
-			
-			pp *= cos(n*M_PI*x)*cos(m*M_PI*y);
-			sum7 += pp; /* total pressure */
-			sum8 += txx;
-			sum9 += tyy;
-			sum10 += tyx;
-			
-			rho = del_rho*cos(n*M_PI*x)*cos(m*M_PI*y);
-			
-			sum11 += rho;
-			
-		}/* n */
-	}/* m */
-	mag=sqrt(sum1*sum1+sum2*sum2+sum3*sum3);
-	
-	//printf("%0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g\n",x,y,sum1,sum2,sum3,sum4,sum5,sum6,sum7,sum8,sum9,sum10,mag,sum11);
-	/************************************************************************************
-	Run this by doing
-	_Velic_solH > out
-	In gnuplot
-	set pm3d map
-	splot "out" u 1:2:N
-	where N = 3-14
-	N=3 is z velocity field (sum1)
-	4 is y velocity field (sum2)
-	5 is x velocity field (sum3)
-	6 = zz total stress field (sum4)
-	7 = zy total stress field (sum5)
-	8 = zx total stress field (sum6)
-	9 = total pressure field (sum7)
-	10 = xx total stress field (sum8)
-	11 = yy total stress field (sum9)
-	12 = yx total stress field (sum10)
-	13 = velocity magnitude (mag)
-	14 = density (mag11)
-	
-	if the set pm3d map thing doesn't work then you are probably using a version of
-	gnuplot that is too old --- seek medical assistance.
-	************************************************************************************/
-	
-	
-	/* Output */
-	if( vel != NULL ) {
-		vel[0] = sum3;
-		vel[1] = sum2;
-		vel[2] = sum1;
-	}
-	if( presssure != NULL ) {
-		(*presssure) = sum7;
-	}
-	if( total_stress != NULL ) {
-		/* xx,yy,zz,xy,xz,yz */
-		total_stress[0] = sum8;
-		total_stress[1] = sum9;
-		total_stress[2] = sum4;
-		total_stress[3] = sum10;
-		total_stress[4] = sum6;
-		total_stress[5] = sum5;
-	}
-	if( strain_rate != NULL ) {
-		strain_rate[0] = (sum8+sum7)/(2.0*Z);
-		strain_rate[1] = (sum9+sum7)/(2.0*Z);
-		strain_rate[2] = (sum4+sum7)/(2.0*Z);
-		strain_rate[3] = (sum10)/(2.0*Z);
-		strain_rate[4] = (sum6)/(2.0*Z);
-		strain_rate[5] = (sum5)/(2.0*Z);
-	}
-	/* Value checks, could be cleaned up if needed. Julian Giordani 9-Oct-2006*/
-	assert ( fabs( 3.0 * sum7 + sum8+sum9+sum4 ) <= 1e-5 );	
-	
-	
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solH/solH.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solH/solH.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,222 @@
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+
+void _Velic_solH( 
+		double pos[],
+		double _sigma,
+		double _eta, 
+		double _dx, double _dy,
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] );
+
+
+int main( int argc, char **argv )
+{
+	int i,j;
+	double pos[3], vel[3], pressure, total_stress[6], strain_rate[6];
+	double x,y,z;
+	
+	for (i=0;i<101;i++){
+		for(j=0;j<101;j++){
+			x = i/100.0;
+			y = j/100.0;
+			
+			pos[0] = x;
+			pos[1] = y;
+			z = 0.2;
+			pos[2] = z;
+			_Velic_solH(
+					pos,
+					1.0,
+					1.0,
+					0.4,0.6,
+					vel, &pressure, total_stress, strain_rate );
+		}
+	}
+	
+	return 0;
+}
+
+
+
+
+void _Velic_solH(
+		double pos[],
+		double _sigma,
+		double _eta,
+		double _dx, double _dy,
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] )
+{
+	
+	double Z,u1,u2,u3,u4,u5,u6;
+	double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,sum8,sum9,sum10,sum11,x,y,z;
+	double sigma,dx,dy;
+	double del_rho;
+	int n,m;
+	double L1,kn,km;
+	double Am,Ap,Bm,Bp,C,D,E;
+	double pp,txx,tyy,tyx,rho;
+	
+	/*************************************************************************/
+	
+	dx = _dx; /* x width of block */
+	dy = _dy; /* y width of block */
+	sigma = _sigma; /* density of block */
+	Z = _eta; /* viscosity */
+	z=pos[2]; /* height of 2-d slice in x-y plane to view */
+	x = pos[0];
+	y = pos[1];
+	
+	sum1=0.0;
+	sum2=0.0;
+	sum3=0.0;
+	sum4=0.0;
+	sum5=0.0;
+	sum6=0.0;
+	sum7=0.0;
+	sum8=0.0;
+	sum9=0.0;
+	sum10=0.0;
+	sum11=0.0;
+	
+	for(n=0;n<45;n++){
+		for(m=0;m<45;m++){
+			
+			if ( n!=0 && m!=0 ){
+				del_rho = 4.0*sigma*sin((double)n*M_PI*dx)*sin((double)m*M_PI*dy)/(double)n/M_PI/(double)m/M_PI;
+			} else {
+				if ( n==0 && m !=0){
+					del_rho = 2.0*sigma*dx*sin((double)m*M_PI*dy)/(double)m/M_PI;
+				} else {
+					if ( n!=0 && m ==0){
+						del_rho = 2.0*sigma*dy*sin((double)n*M_PI*dx)/(double)n/M_PI;
+					} else {
+						del_rho = sigma*dx*dy;
+					}
+				}
+			}
+			kn = M_PI*(double)n;
+			km = M_PI*(double)m;
+			
+			L1 = M_PI*sqrt( (double)(n*n + m*m));
+			
+			Am = exp((z-2.0)*L1)-exp(-z*L1);
+			Ap = exp((z-2.0)*L1)+exp(-z*L1);
+			Bm = exp((z-1.0)*L1)-exp(-(z+1.0)*L1);
+			Bp = exp((z-1.0)*L1)+exp(-(z+1.0)*L1);
+			C = (exp(-z*L1)-1.0)*(exp((z-1.0)*L1)-1.0);
+			D = exp((z-1.0)*L1)-exp(-z*L1);
+			E = (1.0+exp(-L1));
+			
+			u1 = (n!=0 || m!=0) ? -( z*Am+(z-1.0)*Bm )*del_rho/( 2*Z*L1*E*E ) - C*del_rho/(Z*L1*L1*E) : 0.0;
+			if ( m !=0 ){
+				u2 =  ( z*Ap+(z-1.0)*Bp )*del_rho*km/( 2*Z*L1*L1*E*E ) - D*del_rho*km/(2*Z*L1*L1*L1*E);
+				u5 =  ( z*Am+(z-1.0)*Bm )*del_rho*km/( L1*E*E ) + C*del_rho*km/(L1*L1*E);
+			} else {
+				u2 = 0.0;
+				u5 = 0.0;
+			}
+			if ( n !=0 ){
+				u3 =  ( z*Ap+(z-1.0)*Bp )*del_rho*kn/( 2*Z*L1*L1*E*E ) - D*del_rho*kn/(2*Z*L1*L1*L1*E);
+				u6 =  ( z*Am+(z-1.0)*Bm )*del_rho*kn/( L1*E*E ) + C*del_rho*kn/(L1*L1*E);
+			} else {
+				u3 = 0.0;
+				u6 = 0.0;
+			}
+			u4 = (n==0 && m==0) ? del_rho*(z-0.5) :  -( z*Ap+(z-1.0)*Bp )*del_rho/( E*E ) + 2.0*D*del_rho/(L1*E) ;
+			pp = -u4-2.0*Z*(kn*u3+km*u2);
+			
+			txx = (-pp +2.0*Z*kn*u3)*cos(n*M_PI*x)*cos(m*M_PI*y);
+			tyy = (-pp +2.0*Z*km*u2)*cos(n*M_PI*x)*cos(m*M_PI*y);
+			tyx = -Z*(km*u3+kn*u2)*sin(n*M_PI*x)*sin(m*M_PI*y);
+			
+			//printf("u2 = %0.7g n=%d m=%d --> L2 = %0.7g  --> L1 = %0.7g\n",u2,n,m,L2,L1);
+			u1 *= cos(n*M_PI*x)*cos(m*M_PI*y); 
+			sum1 += u1;
+			u2 *= cos(n*M_PI*x)*sin(m*M_PI*y);
+			sum2 += u2;
+			u3 *= sin(n*M_PI*x)*cos(m*M_PI*y);
+			sum3 += u3;
+			u4 *= cos(n*M_PI*x)*cos(m*M_PI*y);
+			sum4 += u4;
+			u5 *= cos(n*M_PI*x)*sin(m*M_PI*y);
+			sum5 += u5;
+			u6 *= sin(n*M_PI*x)*cos(m*M_PI*y);
+			sum6 += u6;
+			
+			pp *= cos(n*M_PI*x)*cos(m*M_PI*y);
+			sum7 += pp; /* total pressure */
+			sum8 += txx;
+			sum9 += tyy;
+			sum10 += tyx;
+			
+			rho = del_rho*cos(n*M_PI*x)*cos(m*M_PI*y);
+			
+			sum11 += rho;
+			
+		}/* n */
+	}/* m */
+	mag=sqrt(sum1*sum1+sum2*sum2+sum3*sum3);
+	
+	//printf("%0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g\n",x,y,sum1,sum2,sum3,sum4,sum5,sum6,sum7,sum8,sum9,sum10,mag,sum11);
+	/************************************************************************************
+	Run this by doing
+	_Velic_solH > out
+	In gnuplot
+	set pm3d map
+	splot "out" u 1:2:N
+	where N = 3-14
+	N=3 is z velocity field (sum1)
+	4 is y velocity field (sum2)
+	5 is x velocity field (sum3)
+	6 = zz total stress field (sum4)
+	7 = zy total stress field (sum5)
+	8 = zx total stress field (sum6)
+	9 = total pressure field (sum7)
+	10 = xx total stress field (sum8)
+	11 = yy total stress field (sum9)
+	12 = yx total stress field (sum10)
+	13 = velocity magnitude (mag)
+	14 = density (mag11)
+	
+	if the set pm3d map thing doesn't work then you are probably using a version of
+	gnuplot that is too old --- seek medical assistance.
+	************************************************************************************/
+	
+	
+	/* Output */
+	if( vel != NULL ) {
+		vel[0] = sum3;
+		vel[1] = sum2;
+		vel[2] = sum1;
+	}
+	if( presssure != NULL ) {
+		(*presssure) = sum7;
+	}
+	if( total_stress != NULL ) {
+		/* xx,yy,zz,xy,xz,yz */
+		total_stress[0] = sum8;
+		total_stress[1] = sum9;
+		total_stress[2] = sum4;
+		total_stress[3] = sum10;
+		total_stress[4] = sum6;
+		total_stress[5] = sum5;
+	}
+	if( strain_rate != NULL ) {
+		strain_rate[0] = (sum8+sum7)/(2.0*Z);
+		strain_rate[1] = (sum9+sum7)/(2.0*Z);
+		strain_rate[2] = (sum4+sum7)/(2.0*Z);
+		strain_rate[3] = (sum10)/(2.0*Z);
+		strain_rate[4] = (sum6)/(2.0*Z);
+		strain_rate[5] = (sum5)/(2.0*Z);
+	}
+	/* Value checks, could be cleaned up if needed. Julian Giordani 9-Oct-2006*/
+	assert ( fabs( 3.0 * sum7 + sum8+sum9+sum4 ) <= 1e-5 );	
+	
+	
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solHA/Analytic_solHA.c
--- a/SysTest/AnalyticPlugins/Velic_solHA/Analytic_solHA.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,152 +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:
-*+		Mirko Velic
-*+		Julian Giordani
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Patrick Sunter
-** $Id: solHA.c 636 2006-09-08 03:07:06Z JulianGiordani $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <stdio.h>
-#include <string.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include "Analytic_solHA.h"
-
-const Type Velic_solHA_Type = "Underworld_Velic_solHA";
-
-void Velic_solHA_PressureFunction( void* analyticSolution, double* coord, double* pressure ) {
-	Velic_solHA* self = (Velic_solHA*) analyticSolution;
-	
-	_Velic_solHA( coord, self->sigma, self->eta, self->dx, self->dy, self->x0, self->y0, NULL, pressure, NULL, NULL );
-}
-
-void Velic_solHA_VelocityFunction( void* analyticSolution, double* coord, double* velocity ) {
-	Velic_solHA* self = (Velic_solHA*) analyticSolution;
-	
-	_Velic_solHA( coord, self->sigma, self->eta, self->dx, self->dy, self->x0, self->y0, velocity, NULL, NULL, NULL );
-}
-
-void Velic_solHA_StressFunction( void* analyticSolution, double* coord, double* stress ) {
-	Velic_solHA* self = (Velic_solHA*) analyticSolution;
-	
-	_Velic_solHA( coord, self->sigma, self->eta, self->dx, self->dy, self->x0, self->y0, NULL, NULL, stress, NULL );
-}
-
-
-void Velic_solHA_StrainRateFunction( void* analyticSolution, double* coord, double* strainRate ) {
-	Velic_solHA* self = (Velic_solHA*) analyticSolution;
-	
-	_Velic_solHA( coord, self->sigma, self->eta, self->dx, self->dy, self->x0, self->y0, NULL, NULL, NULL, strainRate );
-}
-
-void _Velic_solHA_Init( Velic_solHA* self, double sigma, double eta, double dx, double dy, double x0, double y0 ) {
-	self->sigma = sigma;
-	self->eta = eta;
-	self->dx = dx;
-	self->dy = dy;
-	self->x0 = x0;
-	self->y0 = y0;
-}
-
-void _Velic_solHA_Build( void* analyticSolution, void* data ) {
-	Velic_solHA*          self  = (Velic_solHA*)analyticSolution;
-	
-	_FieldTest_Build( self, data );
-
-	/* here we assign the memory and the func ptr for analytic sols */
-	self->_analyticSolutionList = Memory_Alloc_Array_Unnamed( FieldTest_AnalyticSolutionFunc*, 4 );
-	/* this order MUST be consistent with the xml file definition */
-	self->_analyticSolutionList[0] = Velic_solHA_VelocityFunction;
-	self->_analyticSolutionList[1] = Velic_solHA_PressureFunction;
-	self->_analyticSolutionList[2] = Velic_solHA_StrainRateFunction;
-	self->_analyticSolutionList[3] = Velic_solHA_StressFunction;
-}
-
-void _Velic_solHA_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
-	Velic_solHA* self = (Velic_solHA*) analyticSolution;
-	double                   sigma, eta, dx, dy, x0, y0;
-	double                   startX, endX, startY, endY;
-
-	/* Construct Parent */
-	_FieldTest_AssignFromXML( self, cf, data );
-
-	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHA_sigma", 1.0  );
-	eta = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHA_eta", 1.0  );
-
-	startX = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHA_startX", 0.1  );
-	endX   = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHA_endX", 0.7  );
-
-	startY = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHA_startY", 0.2  );
-	endY   = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHA_endY", 0.6 );
-
-	dx = 0.5 * (startX + endX);
-	dy = 0.5 * (startY + endY );
-	x0 = endX - startX;
-	y0 = endY - startY;
-
-	_Velic_solHA_Init( self, sigma, eta, dx, dy, x0, y0 );
-
-}
-
-void* _Velic_solHA_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Velic_solHA);
-	Type                                                      type = Velic_solHA_Type;
-	Stg_Class_DeleteFunction*                              _delete = _FieldTest_Delete;
-	Stg_Class_PrintFunction*                                _print = _FieldTest_Print;
-	Stg_Class_CopyFunction*                                  _copy = _FieldTest_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solHA_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Velic_solHA_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _Velic_solHA_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 Underworld_Velic_solHA_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Velic_solHA_Type, (Name)"0", _Velic_solHA_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solHA/Analytic_solHA.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solHA/Analytic_solHA.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,152 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Mirko Velic
+*+		Julian Giordani
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Patrick Sunter
+** $Id: solHA.c 636 2006-09-08 03:07:06Z JulianGiordani $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <stdio.h>
+#include <string.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include "Analytic_solHA.h"
+
+const Type Velic_solHA_Type = "Underworld_Velic_solHA";
+
+void Velic_solHA_PressureFunction( void* analyticSolution, double* coord, double* pressure ) {
+	Velic_solHA* self = (Velic_solHA*) analyticSolution;
+	
+	_Velic_solHA( coord, self->sigma, self->eta, self->dx, self->dy, self->x0, self->y0, NULL, pressure, NULL, NULL );
+}
+
+void Velic_solHA_VelocityFunction( void* analyticSolution, double* coord, double* velocity ) {
+	Velic_solHA* self = (Velic_solHA*) analyticSolution;
+	
+	_Velic_solHA( coord, self->sigma, self->eta, self->dx, self->dy, self->x0, self->y0, velocity, NULL, NULL, NULL );
+}
+
+void Velic_solHA_StressFunction( void* analyticSolution, double* coord, double* stress ) {
+	Velic_solHA* self = (Velic_solHA*) analyticSolution;
+	
+	_Velic_solHA( coord, self->sigma, self->eta, self->dx, self->dy, self->x0, self->y0, NULL, NULL, stress, NULL );
+}
+
+
+void Velic_solHA_StrainRateFunction( void* analyticSolution, double* coord, double* strainRate ) {
+	Velic_solHA* self = (Velic_solHA*) analyticSolution;
+	
+	_Velic_solHA( coord, self->sigma, self->eta, self->dx, self->dy, self->x0, self->y0, NULL, NULL, NULL, strainRate );
+}
+
+void _Velic_solHA_Init( Velic_solHA* self, double sigma, double eta, double dx, double dy, double x0, double y0 ) {
+	self->sigma = sigma;
+	self->eta = eta;
+	self->dx = dx;
+	self->dy = dy;
+	self->x0 = x0;
+	self->y0 = y0;
+}
+
+void _Velic_solHA_Build( void* analyticSolution, void* data ) {
+	Velic_solHA*          self  = (Velic_solHA*)analyticSolution;
+	
+	_FieldTest_Build( self, data );
+
+	/* here we assign the memory and the func ptr for analytic sols */
+	self->_analyticSolutionList = Memory_Alloc_Array_Unnamed( FieldTest_AnalyticSolutionFunc*, 4 );
+	/* this order MUST be consistent with the xml file definition */
+	self->_analyticSolutionList[0] = Velic_solHA_VelocityFunction;
+	self->_analyticSolutionList[1] = Velic_solHA_PressureFunction;
+	self->_analyticSolutionList[2] = Velic_solHA_StrainRateFunction;
+	self->_analyticSolutionList[3] = Velic_solHA_StressFunction;
+}
+
+void _Velic_solHA_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
+	Velic_solHA* self = (Velic_solHA*) analyticSolution;
+	double                   sigma, eta, dx, dy, x0, y0;
+	double                   startX, endX, startY, endY;
+
+	/* Construct Parent */
+	_FieldTest_AssignFromXML( self, cf, data );
+
+	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHA_sigma", 1.0  );
+	eta = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHA_eta", 1.0  );
+
+	startX = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHA_startX", 0.1  );
+	endX   = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHA_endX", 0.7  );
+
+	startY = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHA_startY", 0.2  );
+	endY   = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHA_endY", 0.6 );
+
+	dx = 0.5 * (startX + endX);
+	dy = 0.5 * (startY + endY );
+	x0 = endX - startX;
+	y0 = endY - startY;
+
+	_Velic_solHA_Init( self, sigma, eta, dx, dy, x0, y0 );
+
+}
+
+void* _Velic_solHA_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Velic_solHA);
+	Type                                                      type = Velic_solHA_Type;
+	Stg_Class_DeleteFunction*                              _delete = _FieldTest_Delete;
+	Stg_Class_PrintFunction*                                _print = _FieldTest_Print;
+	Stg_Class_CopyFunction*                                  _copy = _FieldTest_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solHA_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Velic_solHA_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _Velic_solHA_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 Underworld_Velic_solHA_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Velic_solHA_Type, (Name)"0", _Velic_solHA_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solHA/solHA.c
--- a/SysTest/AnalyticPlugins/Velic_solHA/solHA.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,274 +0,0 @@
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-
-void _Velic_solHA( 
-		double pos[],
-		double _sigma, double _eta,
-		double _dx, double _dy,
-		double _x_0, double _y_0,
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] );
-
-#ifndef NOSHARED
-int main( int argc, char **argv )
-{
-	int i,j;
-	double pos[3], vel[3], pressure, total_stress[6], strain_rate[6];
-	double x,y,z;
-	
-	for (i=0;i<101;i++){
-		for(j=0;j<101;j++){
-			x = i/100.0;
-			y = j/100.0;
-			
-			pos[0] = x;
-			pos[1] = y;
-			z = 0.2;
-			pos[2] = z;
-			_Velic_solHA(
-					pos,
-					1.0, 1.0,
-					0.4, 0.35,
-					0.3, 0.6,
-					vel, &pressure, total_stress, strain_rate );
-		}
-	}
-	
-	return 0;
-}
-#endif
-
-
-
-/**********************************
-
-this solution is the same as solH
-but the density profile is changed
-to give a column of dense fluid
-in the interior of a box instead
-of in one corner.
-
-**********************************/
-
-void _Velic_solHA( 
-		double pos[],
-		double _sigma, double _eta,
-		double _dx, double _dy,
-		double _x_0, double _y_0,
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] )
-{
-	double Z,u1,u2,u3,u4,u5,u6;
-	double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,sum8,sum9,sum10,sum11,x,y,z;
-	double sigma,dx,dy,x0,y0;
-	double del_rho;
-	int n,m;
-	double L1,kn,km;
-	double Am,Ap,Bm,Bp,C,D,E;
-	double pp,txx,tyy,tyx,rho;
-
-	/* Do transformation from StGermain coord system ---> the coord system this analytic was written in
-	 * NOTE: This transformation is made here, into analytic system and then,
-	 * once the relevent quantites have been calculated, these quantites are transformed back 
-	 * StGermain cood sys		Analytic coord sys
-	 * 	x				y
-	 * 	y				z
-	 * 	z				x
-	 */
-	double _x,_y,_z;
-	_x = pos[0];
-	_y = pos[1];
-	_z = pos[2];
-
-	/*************************************************************************/
-	x0 = _x_0; /* x-centre of dense column */ 
-	y0 = _y_0; /* y-centre of dense column */ 
-	dx = _dx; /* x width of block */
-	dy = _dy; /* y width of block */
-	sigma = _sigma; /* density of column */
-	Z = _eta; /* viscosity */
-	
-	
-	/* Analytic = StGermain */
-	x = _z;
-	y = _x;
-	z = _y; /* height of 2-d slice in x-y plane to view */
-	
-	sum1=0.0;
-	sum2=0.0;
-	sum3=0.0;
-	sum4=0.0;
-	sum5=0.0;
-	sum6=0.0;
-	sum7=0.0;
-	sum8=0.0;
-	sum9=0.0;
-	sum10=0.0;
-	sum11=0.0;
-	
-	for(n=0;n<45;n++){
-		for(m=0;m<45;m++){
-			
-			if ( n!=0 && m!=0 ){
-				del_rho = 16.0*sigma*cos(n*M_PI*x0)*cos(m*M_PI*y0)*sin(n*M_PI*dx/2.0)*sin(m*M_PI*dy/2.0)/(n*m*M_PI*M_PI);
-			} else {
-				if ( n==0 && m !=0){
-					del_rho = 4.0*sigma*dx*cos(m*M_PI*y0)*sin(m*M_PI*dy/2.0)/(m*M_PI);
-				} else {
-					if ( n!=0 && m ==0){
-						del_rho = 4.0*sigma*dy*cos(n*M_PI*x0)*sin(n*M_PI*dx/2.0)/(n*M_PI);
-					} else {
-						del_rho = 2.0*sigma*dx*dy;
-					}
-				}
-			}
-			kn = M_PI*(double)n;
-			km = M_PI*(double)m;
-			
-			L1 = M_PI*sqrt( (double)(n*n + m*m));
-			
-			Am = exp((z-2.0)*L1)-exp(-z*L1);
-			Ap = exp((z-2.0)*L1)+exp(-z*L1);
-			Bm = exp((z-1.0)*L1)-exp(-(z+1.0)*L1);
-			Bp = exp((z-1.0)*L1)+exp(-(z+1.0)*L1);
-			C = (exp(-z*L1)-1.0)*(exp((z-1.0)*L1)-1.0);
-			D = exp((z-1.0)*L1)-exp(-z*L1);
-			E = (1.0+exp(-L1));
-			
-			u1 = (n!=0 || m!=0) ? -( z*Am+(z-1.0)*Bm )*del_rho/( 2*Z*L1*E*E ) - C*del_rho/(Z*L1*L1*E) : 0.0;
-			if ( m !=0 ){
-				u2 =  ( z*Ap+(z-1.0)*Bp )*del_rho*km/( 2*Z*L1*L1*E*E ) - D*del_rho*km/(2*Z*L1*L1*L1*E);
-				u5 =  ( z*Am+(z-1.0)*Bm )*del_rho*km/( L1*E*E ) + C*del_rho*km/(L1*L1*E);
-			} else {
-				u2 = 0.0;
-				u5 = 0.0;
-			}
-			if ( n !=0 ){
-				u3 =  ( z*Ap+(z-1.0)*Bp )*del_rho*kn/( 2*Z*L1*L1*E*E ) - D*del_rho*kn/(2*Z*L1*L1*L1*E);
-				u6 =  ( z*Am+(z-1.0)*Bm )*del_rho*kn/( L1*E*E ) + C*del_rho*kn/(L1*L1*E);
-			} else {
-				u3 = 0.0;
-				u6 = 0.0;
-			}
-			u4 = (n==0 && m==0) ? del_rho*(z-0.5) :  -( z*Ap+(z-1.0)*Bp )*del_rho/( E*E ) + 2.0*D*del_rho/(L1*E) ;
-			
-			pp = -u4-2.0*Z*(kn*u3+km*u2);
-			
-			txx = (-pp +2.0*Z*kn*u3)*cos(n*M_PI*x)*cos(m*M_PI*y);
-			tyy = (-pp +2.0*Z*km*u2)*cos(n*M_PI*x)*cos(m*M_PI*y);
-			tyx = -Z*(km*u3+kn*u2)*sin(n*M_PI*x)*sin(m*M_PI*y);
-			
-			pp *= cos(n*M_PI*x)*cos(m*M_PI*y);
-			//printf("u2 = %0.7g n=%d m=%d --> L2 = %0.7g  --> L1 = %0.7g\n",u2,n,m,L2,L1);
-			u1 *= cos(n*M_PI*x)*cos(m*M_PI*y); 
-			
-			sum1 += u1;
-			u2 *= cos(n*M_PI*x)*sin(m*M_PI*y);
-			sum2 += u2;
-			u3 *= sin(n*M_PI*x)*cos(m*M_PI*y);
-			sum3 += u3;
-			u4 *= cos(n*M_PI*x)*cos(m*M_PI*y);
-			sum4 += u4;
-			u5 *= cos(n*M_PI*x)*sin(m*M_PI*y);
-			sum5 += u5;
-			u6 *= sin(n*M_PI*x)*cos(m*M_PI*y);
-			sum6 += u6;
-			
-			sum7 += pp; /* total pressure */
-			sum8 += txx;
-			sum9 += tyy;
-			sum10 += tyx;
-			
-			rho = del_rho*cos(n*M_PI*x)*cos(m*M_PI*y);
-			
-			sum11 += rho;
-			
-			
-		}/* n */
-	}/* m */
-	
-	mag=sqrt(sum1*sum1+sum2*sum2+sum3*sum3);
-	
-	//printf("%0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g\n",x,y,sum1,sum2,sum3,sum4,sum5,sum6,sum7,sum8,sum9,sum10,mag,sum11);
-	
-	/************************************************************************************
-	Run this by doing
-	_Velic_solHA > out
-	In gnuplot
-	set pm3d map
-	splot "out" u 1:2:N
-	where N = 3-14
-	N=3 is z velocity field (sum1)
-	4 is y velocity field (sum2)
-	5 is x velocity field (sum3)
-	6 = zz total stress field (sum4)
-	7 = zy total stress field (sum5)
-	8 = zx total stress field (sum6)
-	9 = total pressure field (sum7)
-	10 = xx total stress field (sum8)
-	11 = yy total stress field (sum9)
-	12 = yx total stress field (sum10)
-	13 = velocity magnitude (mag)
-	14 = density (mag11)
-	
-	if the set pm3d map thing doesn't work then you are probably using a version of
-	gnuplot that is too old or using a mac --- check yourself into a mental hospital.
-	************************************************************************************/
-	
-	
-	/* Output */
-	if( vel != NULL ) {
-		/*
-		 * Mirko's coord sys
-		vel[0] = sum3;
-		vel[1] = sum2;
-		vel[2] = sum1;
-		*/
-		/* StGermain coord sys */
-		vel[0] = sum2;
-		vel[1] = sum1;
-		vel[2] = sum3;
-	}
-	if( presssure != NULL ) {
-		(*presssure) = sum7;
-	}
-	if( total_stress != NULL ) {
-		/* xx,yy,zz,xy,xz,yz */
-		/* Mirko's coord sys
-		total_stress[0] = sum8;
-		total_stress[1] = sum9;
-		total_stress[2] = sum4;
-		total_stress[3] = sum10;
-		total_stress[4] = sum6;
-		total_stress[5] = sum5;
-		*/
-		/* StGermain coord sys */
-		total_stress[0] = sum9;
-		total_stress[1] = sum4;
-		total_stress[2] = sum8;
-		total_stress[3] = sum5;
-		total_stress[4] = sum10;
-		total_stress[5] = sum6;
-	}
-	if( strain_rate != NULL ) {
-		strain_rate[0] = (sum9+sum7)/(2.0*Z);
-		strain_rate[1] = (sum4+sum7)/(2.0*Z);
-		strain_rate[2] = (sum8+sum7)/(2.0*Z);
-		strain_rate[3] = (sum5)/(2.0*Z);
-		strain_rate[4] = (sum10)/(2.0*Z);
-		strain_rate[5] = (sum6)/(2.0*Z);
-	}
-	/* TODO Enable the check below so it occurs on the first numerical timestep */
-	/* Value checks, could be cleaned up if needed. Julian Giordani 9-Oct-2006
-        if( fabs( sum7 - ( -0.5*(sum8+sum9+sum4) ) ) > 1e-5 ) {
-                //assert(0);
-        }
-	*/
-	
-	
-	
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solHA/solHA.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solHA/solHA.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,274 @@
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+
+void _Velic_solHA( 
+		double pos[],
+		double _sigma, double _eta,
+		double _dx, double _dy,
+		double _x_0, double _y_0,
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] );
+
+#ifndef NOSHARED
+int main( int argc, char **argv )
+{
+	int i,j;
+	double pos[3], vel[3], pressure, total_stress[6], strain_rate[6];
+	double x,y,z;
+	
+	for (i=0;i<101;i++){
+		for(j=0;j<101;j++){
+			x = i/100.0;
+			y = j/100.0;
+			
+			pos[0] = x;
+			pos[1] = y;
+			z = 0.2;
+			pos[2] = z;
+			_Velic_solHA(
+					pos,
+					1.0, 1.0,
+					0.4, 0.35,
+					0.3, 0.6,
+					vel, &pressure, total_stress, strain_rate );
+		}
+	}
+	
+	return 0;
+}
+#endif
+
+
+
+/**********************************
+
+this solution is the same as solH
+but the density profile is changed
+to give a column of dense fluid
+in the interior of a box instead
+of in one corner.
+
+**********************************/
+
+void _Velic_solHA( 
+		double pos[],
+		double _sigma, double _eta,
+		double _dx, double _dy,
+		double _x_0, double _y_0,
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] )
+{
+	double Z,u1,u2,u3,u4,u5,u6;
+	double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,sum8,sum9,sum10,sum11,x,y,z;
+	double sigma,dx,dy,x0,y0;
+	double del_rho;
+	int n,m;
+	double L1,kn,km;
+	double Am,Ap,Bm,Bp,C,D,E;
+	double pp,txx,tyy,tyx,rho;
+
+	/* Do transformation from StGermain coord system ---> the coord system this analytic was written in
+	 * NOTE: This transformation is made here, into analytic system and then,
+	 * once the relevent quantites have been calculated, these quantites are transformed back 
+	 * StGermain cood sys		Analytic coord sys
+	 * 	x				y
+	 * 	y				z
+	 * 	z				x
+	 */
+	double _x,_y,_z;
+	_x = pos[0];
+	_y = pos[1];
+	_z = pos[2];
+
+	/*************************************************************************/
+	x0 = _x_0; /* x-centre of dense column */ 
+	y0 = _y_0; /* y-centre of dense column */ 
+	dx = _dx; /* x width of block */
+	dy = _dy; /* y width of block */
+	sigma = _sigma; /* density of column */
+	Z = _eta; /* viscosity */
+	
+	
+	/* Analytic = StGermain */
+	x = _z;
+	y = _x;
+	z = _y; /* height of 2-d slice in x-y plane to view */
+	
+	sum1=0.0;
+	sum2=0.0;
+	sum3=0.0;
+	sum4=0.0;
+	sum5=0.0;
+	sum6=0.0;
+	sum7=0.0;
+	sum8=0.0;
+	sum9=0.0;
+	sum10=0.0;
+	sum11=0.0;
+	
+	for(n=0;n<45;n++){
+		for(m=0;m<45;m++){
+			
+			if ( n!=0 && m!=0 ){
+				del_rho = 16.0*sigma*cos(n*M_PI*x0)*cos(m*M_PI*y0)*sin(n*M_PI*dx/2.0)*sin(m*M_PI*dy/2.0)/(n*m*M_PI*M_PI);
+			} else {
+				if ( n==0 && m !=0){
+					del_rho = 4.0*sigma*dx*cos(m*M_PI*y0)*sin(m*M_PI*dy/2.0)/(m*M_PI);
+				} else {
+					if ( n!=0 && m ==0){
+						del_rho = 4.0*sigma*dy*cos(n*M_PI*x0)*sin(n*M_PI*dx/2.0)/(n*M_PI);
+					} else {
+						del_rho = 2.0*sigma*dx*dy;
+					}
+				}
+			}
+			kn = M_PI*(double)n;
+			km = M_PI*(double)m;
+			
+			L1 = M_PI*sqrt( (double)(n*n + m*m));
+			
+			Am = exp((z-2.0)*L1)-exp(-z*L1);
+			Ap = exp((z-2.0)*L1)+exp(-z*L1);
+			Bm = exp((z-1.0)*L1)-exp(-(z+1.0)*L1);
+			Bp = exp((z-1.0)*L1)+exp(-(z+1.0)*L1);
+			C = (exp(-z*L1)-1.0)*(exp((z-1.0)*L1)-1.0);
+			D = exp((z-1.0)*L1)-exp(-z*L1);
+			E = (1.0+exp(-L1));
+			
+			u1 = (n!=0 || m!=0) ? -( z*Am+(z-1.0)*Bm )*del_rho/( 2*Z*L1*E*E ) - C*del_rho/(Z*L1*L1*E) : 0.0;
+			if ( m !=0 ){
+				u2 =  ( z*Ap+(z-1.0)*Bp )*del_rho*km/( 2*Z*L1*L1*E*E ) - D*del_rho*km/(2*Z*L1*L1*L1*E);
+				u5 =  ( z*Am+(z-1.0)*Bm )*del_rho*km/( L1*E*E ) + C*del_rho*km/(L1*L1*E);
+			} else {
+				u2 = 0.0;
+				u5 = 0.0;
+			}
+			if ( n !=0 ){
+				u3 =  ( z*Ap+(z-1.0)*Bp )*del_rho*kn/( 2*Z*L1*L1*E*E ) - D*del_rho*kn/(2*Z*L1*L1*L1*E);
+				u6 =  ( z*Am+(z-1.0)*Bm )*del_rho*kn/( L1*E*E ) + C*del_rho*kn/(L1*L1*E);
+			} else {
+				u3 = 0.0;
+				u6 = 0.0;
+			}
+			u4 = (n==0 && m==0) ? del_rho*(z-0.5) :  -( z*Ap+(z-1.0)*Bp )*del_rho/( E*E ) + 2.0*D*del_rho/(L1*E) ;
+			
+			pp = -u4-2.0*Z*(kn*u3+km*u2);
+			
+			txx = (-pp +2.0*Z*kn*u3)*cos(n*M_PI*x)*cos(m*M_PI*y);
+			tyy = (-pp +2.0*Z*km*u2)*cos(n*M_PI*x)*cos(m*M_PI*y);
+			tyx = -Z*(km*u3+kn*u2)*sin(n*M_PI*x)*sin(m*M_PI*y);
+			
+			pp *= cos(n*M_PI*x)*cos(m*M_PI*y);
+			//printf("u2 = %0.7g n=%d m=%d --> L2 = %0.7g  --> L1 = %0.7g\n",u2,n,m,L2,L1);
+			u1 *= cos(n*M_PI*x)*cos(m*M_PI*y); 
+			
+			sum1 += u1;
+			u2 *= cos(n*M_PI*x)*sin(m*M_PI*y);
+			sum2 += u2;
+			u3 *= sin(n*M_PI*x)*cos(m*M_PI*y);
+			sum3 += u3;
+			u4 *= cos(n*M_PI*x)*cos(m*M_PI*y);
+			sum4 += u4;
+			u5 *= cos(n*M_PI*x)*sin(m*M_PI*y);
+			sum5 += u5;
+			u6 *= sin(n*M_PI*x)*cos(m*M_PI*y);
+			sum6 += u6;
+			
+			sum7 += pp; /* total pressure */
+			sum8 += txx;
+			sum9 += tyy;
+			sum10 += tyx;
+			
+			rho = del_rho*cos(n*M_PI*x)*cos(m*M_PI*y);
+			
+			sum11 += rho;
+			
+			
+		}/* n */
+	}/* m */
+	
+	mag=sqrt(sum1*sum1+sum2*sum2+sum3*sum3);
+	
+	//printf("%0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g\n",x,y,sum1,sum2,sum3,sum4,sum5,sum6,sum7,sum8,sum9,sum10,mag,sum11);
+	
+	/************************************************************************************
+	Run this by doing
+	_Velic_solHA > out
+	In gnuplot
+	set pm3d map
+	splot "out" u 1:2:N
+	where N = 3-14
+	N=3 is z velocity field (sum1)
+	4 is y velocity field (sum2)
+	5 is x velocity field (sum3)
+	6 = zz total stress field (sum4)
+	7 = zy total stress field (sum5)
+	8 = zx total stress field (sum6)
+	9 = total pressure field (sum7)
+	10 = xx total stress field (sum8)
+	11 = yy total stress field (sum9)
+	12 = yx total stress field (sum10)
+	13 = velocity magnitude (mag)
+	14 = density (mag11)
+	
+	if the set pm3d map thing doesn't work then you are probably using a version of
+	gnuplot that is too old or using a mac --- check yourself into a mental hospital.
+	************************************************************************************/
+	
+	
+	/* Output */
+	if( vel != NULL ) {
+		/*
+		 * Mirko's coord sys
+		vel[0] = sum3;
+		vel[1] = sum2;
+		vel[2] = sum1;
+		*/
+		/* StGermain coord sys */
+		vel[0] = sum2;
+		vel[1] = sum1;
+		vel[2] = sum3;
+	}
+	if( presssure != NULL ) {
+		(*presssure) = sum7;
+	}
+	if( total_stress != NULL ) {
+		/* xx,yy,zz,xy,xz,yz */
+		/* Mirko's coord sys
+		total_stress[0] = sum8;
+		total_stress[1] = sum9;
+		total_stress[2] = sum4;
+		total_stress[3] = sum10;
+		total_stress[4] = sum6;
+		total_stress[5] = sum5;
+		*/
+		/* StGermain coord sys */
+		total_stress[0] = sum9;
+		total_stress[1] = sum4;
+		total_stress[2] = sum8;
+		total_stress[3] = sum5;
+		total_stress[4] = sum10;
+		total_stress[5] = sum6;
+	}
+	if( strain_rate != NULL ) {
+		strain_rate[0] = (sum9+sum7)/(2.0*Z);
+		strain_rate[1] = (sum4+sum7)/(2.0*Z);
+		strain_rate[2] = (sum8+sum7)/(2.0*Z);
+		strain_rate[3] = (sum5)/(2.0*Z);
+		strain_rate[4] = (sum10)/(2.0*Z);
+		strain_rate[5] = (sum6)/(2.0*Z);
+	}
+	/* TODO Enable the check below so it occurs on the first numerical timestep */
+	/* Value checks, could be cleaned up if needed. Julian Giordani 9-Oct-2006
+        if( fabs( sum7 - ( -0.5*(sum8+sum9+sum4) ) ) > 1e-5 ) {
+                //assert(0);
+        }
+	*/
+	
+	
+	
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solHAy/Analytic_solHAy.c
--- a/SysTest/AnalyticPlugins/Velic_solHAy/Analytic_solHAy.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,160 +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:
-*+		Mirko Velic
-*+		Julian Giordani
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Patrick Sunter
-** $Id: solHAy.c 636 2006-09-08 03:07:06Z JulianGiordani $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include "Analytic_solHAy.h"
-
-const Type Velic_solHAy_Type = "Underworld_Velic_solHAy";
-
-void Velic_solHAy_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
-	Velic_solHAy* self = (Velic_solHAy*) analyticSolution;
-	
-	_Velic_solHAy( coord, self->sigma, self->eta, self->dx, self->dy, self->x0, self->y0, NULL, pressure, NULL, NULL );
-}
-
-void Velic_solHAy_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
-	Velic_solHAy* self = (Velic_solHAy*) analyticSolution;
-	
-	_Velic_solHAy( coord, self->sigma, self->eta, self->dx, self->dy, self->x0, self->y0, velocity, NULL, NULL, NULL );
-}
-
-void Velic_solHAy_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
-	Velic_solHAy* self = (Velic_solHAy*) analyticSolution;
-	
-	_Velic_solHAy( coord, self->sigma, self->eta, self->dx, self->dy, self->x0, self->y0, NULL, NULL, stress, NULL );
-}
-
-
-void Velic_solHAy_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
-	Velic_solHAy* self = (Velic_solHAy*) analyticSolution;
-	
-	_Velic_solHAy( coord, self->sigma, self->eta, self->dx, self->dy, self->x0, self->y0, NULL, NULL, NULL, strainRate );
-}
-
-void _Velic_solHAy_Init( Velic_solHAy* self, double sigma, double eta, double dx, double dy, double x0, double y0 ) {
-	// TODO	Bool                     correctInput = True;
-	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
-        self->_getAnalyticVelocity    = Velic_solHAy_VelocityFunction;
-	self->_getAnalyticPressure    = Velic_solHAy_PressureFunction;
-	self->_getAnalyticTotalStress = Velic_solHAy_StressFunction;
-	self->_getAnalyticStrainRate  = Velic_solHAy_StrainRateFunction;
-
-	self->sigma = sigma;
-	self->eta = eta;
-	self->dx = dx;
-	self->dy = dy;
-	self->x0 = x0;
-	self->y0 = y0;
-}
-
-void _Velic_solHAy_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
-	Velic_solHAy* self = (Velic_solHAy*) analyticSolution;
-	FeVariable*              velocityField;
-	FeVariable*              pressureField;
-	FeVariable*              stressField;
-	FeVariable*              strainRateField;
-	FeVariable*              recoveredStrainRateField;
-	FeVariable*              recoveredStressField;
-	double                   sigma, eta, dx, dy, x0, y0;
-
-	/* Construct Parent */
-	_AnalyticSolution_AssignFromXML( self, cf, data );
-
-	/* Create Analytic Fields */
-	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solHAy_VelocityFunction );
-
-	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solHAy_PressureFunction );
-
-	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False, data );
-	if ( stressField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solHAy_StressFunction );
-
-	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
-	if ( strainRateField   ) {
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solHAy_StrainRateFunction );
-	}
-
-	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
-	if ( recoveredStrainRateField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solHAy_StrainRateFunction );
-
-	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
-	if ( recoveredStressField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solHAy_StressFunction );
-
-	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHA_sigma", 1.0  );
-	eta = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHA_eta", 1.0  );
-	dx = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHA_dx", 0.4  );
-	dy = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHA_dy", 0.35  );
-	x0 = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHA_x0", 0.3  );
-	y0 = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHA_y0", 0.6  );
-
-	_Velic_solHAy_Init( self, sigma, eta, dx, dy, x0, y0 );
-}
-
-void* _Velic_solHAy_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Velic_solHAy);
-	Type                                                      type = Velic_solHAy_Type;
-	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
-	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
-	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solHAy_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Velic_solHAy_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _AnalyticSolution_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 Underworld_Velic_solHAy_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Velic_solHAy_Type, (Name)"0", _Velic_solHAy_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solHAy/Analytic_solHAy.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solHAy/Analytic_solHAy.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,160 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Mirko Velic
+*+		Julian Giordani
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Patrick Sunter
+** $Id: solHAy.c 636 2006-09-08 03:07:06Z JulianGiordani $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include "Analytic_solHAy.h"
+
+const Type Velic_solHAy_Type = "Underworld_Velic_solHAy";
+
+void Velic_solHAy_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
+	Velic_solHAy* self = (Velic_solHAy*) analyticSolution;
+	
+	_Velic_solHAy( coord, self->sigma, self->eta, self->dx, self->dy, self->x0, self->y0, NULL, pressure, NULL, NULL );
+}
+
+void Velic_solHAy_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
+	Velic_solHAy* self = (Velic_solHAy*) analyticSolution;
+	
+	_Velic_solHAy( coord, self->sigma, self->eta, self->dx, self->dy, self->x0, self->y0, velocity, NULL, NULL, NULL );
+}
+
+void Velic_solHAy_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
+	Velic_solHAy* self = (Velic_solHAy*) analyticSolution;
+	
+	_Velic_solHAy( coord, self->sigma, self->eta, self->dx, self->dy, self->x0, self->y0, NULL, NULL, stress, NULL );
+}
+
+
+void Velic_solHAy_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
+	Velic_solHAy* self = (Velic_solHAy*) analyticSolution;
+	
+	_Velic_solHAy( coord, self->sigma, self->eta, self->dx, self->dy, self->x0, self->y0, NULL, NULL, NULL, strainRate );
+}
+
+void _Velic_solHAy_Init( Velic_solHAy* self, double sigma, double eta, double dx, double dy, double x0, double y0 ) {
+	// TODO	Bool                     correctInput = True;
+	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
+        self->_getAnalyticVelocity    = Velic_solHAy_VelocityFunction;
+	self->_getAnalyticPressure    = Velic_solHAy_PressureFunction;
+	self->_getAnalyticTotalStress = Velic_solHAy_StressFunction;
+	self->_getAnalyticStrainRate  = Velic_solHAy_StrainRateFunction;
+
+	self->sigma = sigma;
+	self->eta = eta;
+	self->dx = dx;
+	self->dy = dy;
+	self->x0 = x0;
+	self->y0 = y0;
+}
+
+void _Velic_solHAy_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
+	Velic_solHAy* self = (Velic_solHAy*) analyticSolution;
+	FeVariable*              velocityField;
+	FeVariable*              pressureField;
+	FeVariable*              stressField;
+	FeVariable*              strainRateField;
+	FeVariable*              recoveredStrainRateField;
+	FeVariable*              recoveredStressField;
+	double                   sigma, eta, dx, dy, x0, y0;
+
+	/* Construct Parent */
+	_AnalyticSolution_AssignFromXML( self, cf, data );
+
+	/* Create Analytic Fields */
+	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solHAy_VelocityFunction );
+
+	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solHAy_PressureFunction );
+
+	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False, data );
+	if ( stressField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solHAy_StressFunction );
+
+	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
+	if ( strainRateField   ) {
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solHAy_StrainRateFunction );
+	}
+
+	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
+	if ( recoveredStrainRateField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solHAy_StrainRateFunction );
+
+	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
+	if ( recoveredStressField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solHAy_StressFunction );
+
+	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHA_sigma", 1.0  );
+	eta = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHA_eta", 1.0  );
+	dx = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHA_dx", 0.4  );
+	dy = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHA_dy", 0.35  );
+	x0 = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHA_x0", 0.3  );
+	y0 = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHA_y0", 0.6  );
+
+	_Velic_solHAy_Init( self, sigma, eta, dx, dy, x0, y0 );
+}
+
+void* _Velic_solHAy_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Velic_solHAy);
+	Type                                                      type = Velic_solHAy_Type;
+	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
+	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
+	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solHAy_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Velic_solHAy_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _AnalyticSolution_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 Underworld_Velic_solHAy_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Velic_solHAy_Type, (Name)"0", _Velic_solHAy_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solHAy/solHAy.c
--- a/SysTest/AnalyticPlugins/Velic_solHAy/solHAy.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,222 +0,0 @@
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-
-void _Velic_solHAy( 
-		double pos[],
-		double _sigma, double _eta,
-		double _dx, double _dy,
-		double _x_0, double _y_0,
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] );
-
-
-int main( int argc, char **argv )
-{
-	int i,j;
-	double pos[3], vel[3], pressure, total_stress[6], strain_rate[6];
-	double x,y,z;
-	
-	for (i=0;i<101;i++){
-		for(j=0;j<101;j++){
-			x = i/100.0;
-			z = j/100.0;
-			
-			pos[0] = x;
-			pos[1] = y;
-			y = 0.6;
-			pos[2] = y;
-			_Velic_solHAy(
-					pos,
-					1.0, 1.0,
-					0.4, 0.35,
-					0.3, 0.6,
-					vel, &pressure, total_stress, strain_rate );
-		}
-	}
-	
-	return 0;
-}
-
-
-
-void _Velic_solHAy( 
-		double pos[],
-		double _sigma, double _eta,
-		double _dx, double _dy,
-		double _x_0, double _y_0,
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] )
-{
-	double Z,u1,u2,u3,u4,u5,u6;
-	double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,sum8,sum9,sum10,x,y,z;
-	double sigma,dx,dy,x0,y0;
-	double del_rho;
-	int n,m;
-	double L1,kn,km;
-	double Am,Ap,Bm,Bp,C,D,E;
-	double pp,txx,tyy,tyx;
-	
-	/*************************************************************************/
-	//
-	x0 = _x_0;
-	y0 = _y_0;
-	dx = _dx;
-	dy = _dy;
-	sigma = _sigma;
-	Z = _eta;
-	//   zc = 0.6;
-	//
-	y=pos[2];
-	x = pos[0];
-	z = pos[1];
-	
-	sum1=0.0;
-	sum2=0.0;
-	sum3=0.0;
-	sum4=0.0;
-	sum5=0.0;
-	sum6=0.0;
-	sum7=0.0;
-	sum8=0.0;
-	sum9=0.0;
-	sum10=0.0;
-	
-	for(n=0;n<45;n++){
-		for(m=0;m<45;m++){
-			
-			if ( n!=0 && m!=0 ){
-				del_rho = 16.0*sigma*cos(n*M_PI*x0)*cos(m*M_PI*y0)*sin(n*M_PI*dx/2.0)*sin(m*M_PI*dy/2.0)/(n*m*M_PI*M_PI);
-			} else {
-				if ( n==0 && m !=0){
-					del_rho = 4.0*sigma*dx*cos(m*M_PI*y0)*sin(m*M_PI*dy/2.0)/(m*M_PI);
-				} else {
-					if ( n!=0 && m ==0){
-						del_rho = 4.0*sigma*dy*cos(n*M_PI*x0)*sin(n*M_PI*dx/2.0)/(n*M_PI);
-					} else {
-						del_rho = 2.0*sigma*dx*dy;
-					}
-				}
-			}
-			kn = M_PI*(double)n;
-			km = M_PI*(double)m;
-			
-			L1 = M_PI*sqrt( (double)(n*n + m*m));
-			
-			Am = exp((z-2.0)*L1)-exp(-z*L1);
-			Ap = exp((z-2.0)*L1)+exp(-z*L1);
-			Bm = exp((z-1.0)*L1)-exp(-(z+1.0)*L1);
-			Bp = exp((z-1.0)*L1)+exp(-(z+1.0)*L1);
-			C = (exp(-z*L1)-1.0)*(exp((z-1.0)*L1)-1.0);
-			D = exp((z-1.0)*L1)-exp(-z*L1);
-			E = (1.0+exp(-L1));
-			
-			u1 = (n!=0 || m!=0) ? -( z*Am+(z-1.0)*Bm )*del_rho/( 2*Z*L1*E*E ) - C*del_rho/(Z*L1*L1*E) : 0.0;
-			if ( m !=0 ){
-				u2 =  ( z*Ap+(z-1.0)*Bp )*del_rho*km/( 2*Z*L1*L1*E*E ) - D*del_rho*km/(2*Z*L1*L1*L1*E);
-				u5 =  ( z*Am+(z-1.0)*Bm )*del_rho*km/( L1*E*E ) + C*del_rho*km/(L1*L1*E);
-			} else {
-				u2 = 0.0;
-				u5 = 0.0;
-			}
-			if ( n !=0 ){
-				u3 =  ( z*Ap+(z-1.0)*Bp )*del_rho*kn/( 2*Z*L1*L1*E*E ) - D*del_rho*kn/(2*Z*L1*L1*L1*E);
-				u6 =  ( z*Am+(z-1.0)*Bm )*del_rho*kn/( L1*E*E ) + C*del_rho*kn/(L1*L1*E);
-			} else {
-				u3 = 0.0;
-				u6 = 0.0;
-			}
-			u4 = (n!=0 || m!=0) ? -( z*Ap+(z-1.0)*Bp )*del_rho/( E*E ) + 2.0*D*del_rho/(L1*E) : 0.0*del_rho*(z-0.5) ;
-			
-			pp = -u4-2.0*Z*(kn*u3+km*u2);
-			
-			txx = (-pp +2.0*Z*kn*u3)*cos(n*M_PI*x)*cos(m*M_PI*y);
-			tyy = (-pp +2.0*Z*km*u2)*cos(n*M_PI*x)*cos(m*M_PI*y);
-			tyx = -Z*(km*u3+kn*u2)*sin(n*M_PI*x)*sin(m*M_PI*y);
-			
-			pp *= cos(n*M_PI*x)*cos(m*M_PI*y);
-			//printf("u2 = %0.7g n=%d m=%d --> L2 = %0.7g  --> L1 = %0.7g\n",u2,n,m,L2,L1);
-			u1 *= cos(n*M_PI*x)*cos(m*M_PI*y); 
-			
-			sum1 += u1;
-			u2 *= cos(n*M_PI*x)*sin(m*M_PI*y);
-			sum2 += u2;
-			u3 *= sin(n*M_PI*x)*cos(m*M_PI*y);
-			sum3 += u3;
-			u4 *= cos(n*M_PI*x)*cos(m*M_PI*y);
-			sum4 += u4;
-			u5 *= cos(n*M_PI*x)*sin(m*M_PI*y);
-			sum5 += u5;
-			u6 *= sin(n*M_PI*x)*cos(m*M_PI*y);
-			sum6 += u6;
-			
-			sum7 += pp; /* total pressure */
-			sum8 += txx;
-			sum9 += tyy;
-			sum10 += tyx;
-			// u5 = (double)-2*n*M_PI*(Z*u2 + u3)*cos(n*M_PI*x); /* pressure */
-			
-			//u6 = (double)(u3*2*n*M_PI + 4*Z*n*M_PI*u2)*cos(n*M_PI*x); /* xx stress */	    
-			//sum5 +=u5;
-			//sum6 +=u6;
-			
-			//u1 *= cos(n*M_PI*x); /* z velocity */
-			//sum1 += u1;
-			//u2 *= sin(n*M_PI*x); /* x velocity */
-			//sum2 += u2;
-			//u3 *= 2*n*M_PI*cos(n*M_PI*x); /* zz stress */
-			//sum3 += u3;
-			//u4 *= 2*n*M_PI*sin(n*M_PI*x); /* zx stress */
-			//sum4 += u4;
-			
-		}/* n */
-	}/* m */
-	//if(z<zc){
-	//sum7 += sigma*dx; /* n=0 density term */
-	//sum5 += sigma*dx*(0.5-z); /* n=0 (hydrostatic) pressure term */
-	//sum3 += -sigma*dx*(0.5-z);/* n=0 (hydrostatic) tzz term */
-	//} else {
-	//sum5 += sigma*dx*(0.5-zc); /* n=0 (hydrostatic) pressure term */
-	//sum3 += -sigma*dx*(0.5-zc);/* n=0 (hydrostatic) tzz term */	    
-	//}
-	
-	mag=sqrt(sum1*sum1+sum2*sum2+sum3*sum3);
-	printf("%0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,sum7,sum8,sum9,sum10,mag);
-	
-	
-	/* Output */
-	if( vel != NULL ) {
-		vel[0] = sum3;
-		vel[1] = sum2;
-		vel[2] = sum1;
-	}
-	if( presssure != NULL ) {
-		(*presssure) = sum7;
-	}
-	if( total_stress != NULL ) {
-		/* xx,yy,zz,xy,xz,yz */
-		total_stress[0] = sum8;
-		total_stress[1] = sum9;
-		total_stress[2] = sum4;
-		total_stress[3] = sum10;
-		total_stress[4] = sum6;
-		total_stress[5] = sum5;
-	}
-	if( strain_rate != NULL ) {
-		strain_rate[0] = (sum8+sum7)/(2.0*Z);
-		strain_rate[1] = (sum9+sum7)/(2.0*Z);
-		strain_rate[2] = (sum4+sum7)/(2.0*Z);
-		strain_rate[3] = (sum10)/(2.0*Z);
-		strain_rate[4] = (sum6)/(2.0*Z);
-		strain_rate[5] = (sum5)/(2.0*Z);
-	}
-	/* Value checks, could be cleaned up if needed. Julian Giordani 9-Oct-2006*/
-        if( fabs( sum7 - ( -0.5*(sum8+sum9+sum4) ) ) > 1e-5 ) {
-                assert(0);
-        }
-	
-	
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solHAy/solHAy.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solHAy/solHAy.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,222 @@
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+
+void _Velic_solHAy( 
+		double pos[],
+		double _sigma, double _eta,
+		double _dx, double _dy,
+		double _x_0, double _y_0,
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] );
+
+
+int main( int argc, char **argv )
+{
+	int i,j;
+	double pos[3], vel[3], pressure, total_stress[6], strain_rate[6];
+	double x,y,z;
+	
+	for (i=0;i<101;i++){
+		for(j=0;j<101;j++){
+			x = i/100.0;
+			z = j/100.0;
+			
+			pos[0] = x;
+			pos[1] = y;
+			y = 0.6;
+			pos[2] = y;
+			_Velic_solHAy(
+					pos,
+					1.0, 1.0,
+					0.4, 0.35,
+					0.3, 0.6,
+					vel, &pressure, total_stress, strain_rate );
+		}
+	}
+	
+	return 0;
+}
+
+
+
+void _Velic_solHAy( 
+		double pos[],
+		double _sigma, double _eta,
+		double _dx, double _dy,
+		double _x_0, double _y_0,
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] )
+{
+	double Z,u1,u2,u3,u4,u5,u6;
+	double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,sum8,sum9,sum10,x,y,z;
+	double sigma,dx,dy,x0,y0;
+	double del_rho;
+	int n,m;
+	double L1,kn,km;
+	double Am,Ap,Bm,Bp,C,D,E;
+	double pp,txx,tyy,tyx;
+	
+	/*************************************************************************/
+	//
+	x0 = _x_0;
+	y0 = _y_0;
+	dx = _dx;
+	dy = _dy;
+	sigma = _sigma;
+	Z = _eta;
+	//   zc = 0.6;
+	//
+	y=pos[2];
+	x = pos[0];
+	z = pos[1];
+	
+	sum1=0.0;
+	sum2=0.0;
+	sum3=0.0;
+	sum4=0.0;
+	sum5=0.0;
+	sum6=0.0;
+	sum7=0.0;
+	sum8=0.0;
+	sum9=0.0;
+	sum10=0.0;
+	
+	for(n=0;n<45;n++){
+		for(m=0;m<45;m++){
+			
+			if ( n!=0 && m!=0 ){
+				del_rho = 16.0*sigma*cos(n*M_PI*x0)*cos(m*M_PI*y0)*sin(n*M_PI*dx/2.0)*sin(m*M_PI*dy/2.0)/(n*m*M_PI*M_PI);
+			} else {
+				if ( n==0 && m !=0){
+					del_rho = 4.0*sigma*dx*cos(m*M_PI*y0)*sin(m*M_PI*dy/2.0)/(m*M_PI);
+				} else {
+					if ( n!=0 && m ==0){
+						del_rho = 4.0*sigma*dy*cos(n*M_PI*x0)*sin(n*M_PI*dx/2.0)/(n*M_PI);
+					} else {
+						del_rho = 2.0*sigma*dx*dy;
+					}
+				}
+			}
+			kn = M_PI*(double)n;
+			km = M_PI*(double)m;
+			
+			L1 = M_PI*sqrt( (double)(n*n + m*m));
+			
+			Am = exp((z-2.0)*L1)-exp(-z*L1);
+			Ap = exp((z-2.0)*L1)+exp(-z*L1);
+			Bm = exp((z-1.0)*L1)-exp(-(z+1.0)*L1);
+			Bp = exp((z-1.0)*L1)+exp(-(z+1.0)*L1);
+			C = (exp(-z*L1)-1.0)*(exp((z-1.0)*L1)-1.0);
+			D = exp((z-1.0)*L1)-exp(-z*L1);
+			E = (1.0+exp(-L1));
+			
+			u1 = (n!=0 || m!=0) ? -( z*Am+(z-1.0)*Bm )*del_rho/( 2*Z*L1*E*E ) - C*del_rho/(Z*L1*L1*E) : 0.0;
+			if ( m !=0 ){
+				u2 =  ( z*Ap+(z-1.0)*Bp )*del_rho*km/( 2*Z*L1*L1*E*E ) - D*del_rho*km/(2*Z*L1*L1*L1*E);
+				u5 =  ( z*Am+(z-1.0)*Bm )*del_rho*km/( L1*E*E ) + C*del_rho*km/(L1*L1*E);
+			} else {
+				u2 = 0.0;
+				u5 = 0.0;
+			}
+			if ( n !=0 ){
+				u3 =  ( z*Ap+(z-1.0)*Bp )*del_rho*kn/( 2*Z*L1*L1*E*E ) - D*del_rho*kn/(2*Z*L1*L1*L1*E);
+				u6 =  ( z*Am+(z-1.0)*Bm )*del_rho*kn/( L1*E*E ) + C*del_rho*kn/(L1*L1*E);
+			} else {
+				u3 = 0.0;
+				u6 = 0.0;
+			}
+			u4 = (n!=0 || m!=0) ? -( z*Ap+(z-1.0)*Bp )*del_rho/( E*E ) + 2.0*D*del_rho/(L1*E) : 0.0*del_rho*(z-0.5) ;
+			
+			pp = -u4-2.0*Z*(kn*u3+km*u2);
+			
+			txx = (-pp +2.0*Z*kn*u3)*cos(n*M_PI*x)*cos(m*M_PI*y);
+			tyy = (-pp +2.0*Z*km*u2)*cos(n*M_PI*x)*cos(m*M_PI*y);
+			tyx = -Z*(km*u3+kn*u2)*sin(n*M_PI*x)*sin(m*M_PI*y);
+			
+			pp *= cos(n*M_PI*x)*cos(m*M_PI*y);
+			//printf("u2 = %0.7g n=%d m=%d --> L2 = %0.7g  --> L1 = %0.7g\n",u2,n,m,L2,L1);
+			u1 *= cos(n*M_PI*x)*cos(m*M_PI*y); 
+			
+			sum1 += u1;
+			u2 *= cos(n*M_PI*x)*sin(m*M_PI*y);
+			sum2 += u2;
+			u3 *= sin(n*M_PI*x)*cos(m*M_PI*y);
+			sum3 += u3;
+			u4 *= cos(n*M_PI*x)*cos(m*M_PI*y);
+			sum4 += u4;
+			u5 *= cos(n*M_PI*x)*sin(m*M_PI*y);
+			sum5 += u5;
+			u6 *= sin(n*M_PI*x)*cos(m*M_PI*y);
+			sum6 += u6;
+			
+			sum7 += pp; /* total pressure */
+			sum8 += txx;
+			sum9 += tyy;
+			sum10 += tyx;
+			// u5 = (double)-2*n*M_PI*(Z*u2 + u3)*cos(n*M_PI*x); /* pressure */
+			
+			//u6 = (double)(u3*2*n*M_PI + 4*Z*n*M_PI*u2)*cos(n*M_PI*x); /* xx stress */	    
+			//sum5 +=u5;
+			//sum6 +=u6;
+			
+			//u1 *= cos(n*M_PI*x); /* z velocity */
+			//sum1 += u1;
+			//u2 *= sin(n*M_PI*x); /* x velocity */
+			//sum2 += u2;
+			//u3 *= 2*n*M_PI*cos(n*M_PI*x); /* zz stress */
+			//sum3 += u3;
+			//u4 *= 2*n*M_PI*sin(n*M_PI*x); /* zx stress */
+			//sum4 += u4;
+			
+		}/* n */
+	}/* m */
+	//if(z<zc){
+	//sum7 += sigma*dx; /* n=0 density term */
+	//sum5 += sigma*dx*(0.5-z); /* n=0 (hydrostatic) pressure term */
+	//sum3 += -sigma*dx*(0.5-z);/* n=0 (hydrostatic) tzz term */
+	//} else {
+	//sum5 += sigma*dx*(0.5-zc); /* n=0 (hydrostatic) pressure term */
+	//sum3 += -sigma*dx*(0.5-zc);/* n=0 (hydrostatic) tzz term */	    
+	//}
+	
+	mag=sqrt(sum1*sum1+sum2*sum2+sum3*sum3);
+	printf("%0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,sum7,sum8,sum9,sum10,mag);
+	
+	
+	/* Output */
+	if( vel != NULL ) {
+		vel[0] = sum3;
+		vel[1] = sum2;
+		vel[2] = sum1;
+	}
+	if( presssure != NULL ) {
+		(*presssure) = sum7;
+	}
+	if( total_stress != NULL ) {
+		/* xx,yy,zz,xy,xz,yz */
+		total_stress[0] = sum8;
+		total_stress[1] = sum9;
+		total_stress[2] = sum4;
+		total_stress[3] = sum10;
+		total_stress[4] = sum6;
+		total_stress[5] = sum5;
+	}
+	if( strain_rate != NULL ) {
+		strain_rate[0] = (sum8+sum7)/(2.0*Z);
+		strain_rate[1] = (sum9+sum7)/(2.0*Z);
+		strain_rate[2] = (sum4+sum7)/(2.0*Z);
+		strain_rate[3] = (sum10)/(2.0*Z);
+		strain_rate[4] = (sum6)/(2.0*Z);
+		strain_rate[5] = (sum5)/(2.0*Z);
+	}
+	/* Value checks, could be cleaned up if needed. Julian Giordani 9-Oct-2006*/
+        if( fabs( sum7 - ( -0.5*(sum8+sum9+sum4) ) ) > 1e-5 ) {
+                assert(0);
+        }
+	
+	
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solHy/Analytic_solHy.c
--- a/SysTest/AnalyticPlugins/Velic_solHy/Analytic_solHy.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,164 +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:
-*+		Mirko Velic
-*+		Julian Giordani
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Patrick Sunter
-** $Id: solHy.c 636 2006-09-08 03:07:06Z JulianGiordani $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include "Analytic_solHy.h"
-
-const Type Velic_solHy_Type = "Underworld_Velic_solHy";
-
-void Velic_solHy_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
-	Velic_solHy* self = (Velic_solHy*) analyticSolution;
-	
-	_Velic_solHy( coord, self->etaA, self->etaB, self->xc, self->n, NULL, pressure, NULL, NULL );
-}
-
-void Velic_solHy_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
-	Velic_solHy* self = (Velic_solHy*) analyticSolution;
-	
-	_Velic_solHy( coord, self->etaA, self->etaB, self->xc, self->n, velocity, NULL, NULL, NULL );
-}
-
-void Velic_solHy_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
-	Velic_solHy* self = (Velic_solHy*) analyticSolution;
-	
-	_Velic_solHy( coord, self->etaA, self->etaB, self->xc, self->n, NULL, NULL, stress, NULL );
-}
-
-
-void Velic_solHy_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
-	Velic_solHy* self = (Velic_solHy*) analyticSolution;
-	
-	_Velic_solHy( coord, self->etaA, self->etaB, self->xc, self->n, NULL, NULL, NULL, strainRate );
-}
-
-void _Velic_solHy_Init( Velic_solHy* self, double etaA, double etaB, double xc, int n ) {
-	Bool                     correctInput = True;
-	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
-        self->_getAnalyticVelocity    = Velic_solHy_VelocityFunction;
-	self->_getAnalyticPressure    = Velic_solHy_PressureFunction;
-	self->_getAnalyticTotalStress = Velic_solHy_StressFunction;
-	self->_getAnalyticStrainRate  = Velic_solHy_StrainRateFunction;
-
-	self->etaA = etaA;
-	self->etaB = etaB;
-	self->xc = xc;
-	self->n = n;
-
-	if( (self->xc < 0.0) || self->xc > 1.0 ) 
-	      correctInput = False;	
-
-	Journal_Firewall( correctInput,  Journal_Register( Error_Type, (Name)"solHy_ErrorStream" ) ,
-			"Error: In func %s. The input parameters you supplied to the analytic Solution are incorrect.\nValid range of xc values is [0,1]. Currently it is %f\n", __func__, self->xc );
-}
-
-void _Velic_solHy_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
-	Velic_solHy* self = (Velic_solHy*) analyticSolution;
-	FeVariable*              velocityField;
-	FeVariable*              pressureField;
-	FeVariable*              stressField;
-	FeVariable*              strainRateField;
-	FeVariable*              recoveredStrainRateField;
-	FeVariable*              recoveredStressField;
-	double                   etaA, etaB, xc;
-	int                      n;
-
-	/* Construct Parent */
-	_AnalyticSolution_AssignFromXML( self, cf, data );
-
-	/* Create Analytic Fields */
-	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solHy_VelocityFunction );
-
-	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solHy_PressureFunction );
-
-	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False, data );
-	if ( stressField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solHy_StressFunction );
-
-	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
-	if ( strainRateField   ) {
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solHy_StrainRateFunction );
-	}
-
-	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
-	if ( recoveredStrainRateField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solHy_StrainRateFunction );
-
-	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
-	if ( recoveredStressField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solHy_StressFunction );
-	
-	etaA = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHy_etaA", 1.0  );
-	etaB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHy_etaB", 2.0  );
-	xc = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHy_xc", 0.25  );
-	n = Stg_ComponentFactory_GetRootDictInt( cf, "solHy_n", 1 );
-
-	_Velic_solHy_Init( self, etaA, etaB, xc, n );
-	
-}
-
-void* _Velic_solHy_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Velic_solHy);
-	Type                                                      type = Velic_solHy_Type;
-	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
-	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
-	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solHy_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Velic_solHy_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _AnalyticSolution_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 Underworld_Velic_solHy_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Velic_solHy_Type, (Name)"0", _Velic_solHy_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solHy/Analytic_solHy.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solHy/Analytic_solHy.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,164 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Mirko Velic
+*+		Julian Giordani
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Patrick Sunter
+** $Id: solHy.c 636 2006-09-08 03:07:06Z JulianGiordani $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include "Analytic_solHy.h"
+
+const Type Velic_solHy_Type = "Underworld_Velic_solHy";
+
+void Velic_solHy_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
+	Velic_solHy* self = (Velic_solHy*) analyticSolution;
+	
+	_Velic_solHy( coord, self->etaA, self->etaB, self->xc, self->n, NULL, pressure, NULL, NULL );
+}
+
+void Velic_solHy_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
+	Velic_solHy* self = (Velic_solHy*) analyticSolution;
+	
+	_Velic_solHy( coord, self->etaA, self->etaB, self->xc, self->n, velocity, NULL, NULL, NULL );
+}
+
+void Velic_solHy_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
+	Velic_solHy* self = (Velic_solHy*) analyticSolution;
+	
+	_Velic_solHy( coord, self->etaA, self->etaB, self->xc, self->n, NULL, NULL, stress, NULL );
+}
+
+
+void Velic_solHy_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
+	Velic_solHy* self = (Velic_solHy*) analyticSolution;
+	
+	_Velic_solHy( coord, self->etaA, self->etaB, self->xc, self->n, NULL, NULL, NULL, strainRate );
+}
+
+void _Velic_solHy_Init( Velic_solHy* self, double etaA, double etaB, double xc, int n ) {
+	Bool                     correctInput = True;
+	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
+        self->_getAnalyticVelocity    = Velic_solHy_VelocityFunction;
+	self->_getAnalyticPressure    = Velic_solHy_PressureFunction;
+	self->_getAnalyticTotalStress = Velic_solHy_StressFunction;
+	self->_getAnalyticStrainRate  = Velic_solHy_StrainRateFunction;
+
+	self->etaA = etaA;
+	self->etaB = etaB;
+	self->xc = xc;
+	self->n = n;
+
+	if( (self->xc < 0.0) || self->xc > 1.0 ) 
+	      correctInput = False;	
+
+	Journal_Firewall( correctInput,  Journal_Register( Error_Type, (Name)"solHy_ErrorStream" ) ,
+			"Error: In func %s. The input parameters you supplied to the analytic Solution are incorrect.\nValid range of xc values is [0,1]. Currently it is %f\n", __func__, self->xc );
+}
+
+void _Velic_solHy_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
+	Velic_solHy* self = (Velic_solHy*) analyticSolution;
+	FeVariable*              velocityField;
+	FeVariable*              pressureField;
+	FeVariable*              stressField;
+	FeVariable*              strainRateField;
+	FeVariable*              recoveredStrainRateField;
+	FeVariable*              recoveredStressField;
+	double                   etaA, etaB, xc;
+	int                      n;
+
+	/* Construct Parent */
+	_AnalyticSolution_AssignFromXML( self, cf, data );
+
+	/* Create Analytic Fields */
+	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solHy_VelocityFunction );
+
+	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solHy_PressureFunction );
+
+	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False, data );
+	if ( stressField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solHy_StressFunction );
+
+	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
+	if ( strainRateField   ) {
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solHy_StrainRateFunction );
+	}
+
+	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
+	if ( recoveredStrainRateField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solHy_StrainRateFunction );
+
+	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
+	if ( recoveredStressField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solHy_StressFunction );
+	
+	etaA = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHy_etaA", 1.0  );
+	etaB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHy_etaB", 2.0  );
+	xc = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solHy_xc", 0.25  );
+	n = Stg_ComponentFactory_GetRootDictInt( cf, "solHy_n", 1 );
+
+	_Velic_solHy_Init( self, etaA, etaB, xc, n );
+	
+}
+
+void* _Velic_solHy_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Velic_solHy);
+	Type                                                      type = Velic_solHy_Type;
+	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
+	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
+	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solHy_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Velic_solHy_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _AnalyticSolution_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 Underworld_Velic_solHy_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Velic_solHy_Type, (Name)"0", _Velic_solHy_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solHy/solHy.c
--- a/SysTest/AnalyticPlugins/Velic_solHy/solHy.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,149 +0,0 @@
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-
-int main (){
-   double Z,u1,u2,u3,u4,u5,u6;
-   double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,sum8,sum9,sum10,x,y,z;
-   double sigma,dx,dy;
-   double del_rho;
-   int i,j,n,m;
-   double L1,kn,km;
-   double Am,Ap,Bm,Bp,C,D,E;
-   double pp,txx,tyy,tyx;
-
-   /*************************************************************************/
-   //
-//   x0 = 0.3; 
-   dx = 0.7;
-   dy = 0.4;
-   sigma = 1.0;
-   Z = 1.0;
-//   zc = 0.6;
-   //
-   y=0.4;
-   for (i=0;i<101;i++){
-      for(j=0;j<101;j++){
-	 x = ((double)i)/100.0;
-	 z = ((double)j)/100.0;
-
-	 sum1=0.0;
-	 sum2=0.0;
-	 sum3=0.0;
-	 sum4=0.0;
-	 sum5=0.0;
-	 sum6=0.0;
-	 sum7=0.0;
-	 sum8=0.0;
-	 sum9=0.0;
-	 sum10=0.0;
-	 
-	 for(n=0;n<45;n++){
-	    for(m=0;m<45;m++){
-
-	       if ( n!=0 && m!=0 ){
-		  del_rho = 4.0*sigma*sin((double)n*M_PI*dx)*sin((double)m*M_PI*dy)/(double)n/M_PI/(double)m/M_PI;
-	       } else {
-		  if ( n==0 && m !=0){
-		     del_rho = 2.0*sigma*dx*sin((double)m*M_PI*dy)/(double)m/M_PI;
-		  } else {
-		     if ( n!=0 && m ==0){
-			del_rho = 2.0*sigma*dy*sin((double)n*M_PI*dx)/(double)n/M_PI;
-		     } else {
-			del_rho = sigma*dx*dy;
-		     }
-		  }
-	       }
-	       kn = M_PI*(double)n;
-	       km = M_PI*(double)m;
-
-	       L1 = M_PI*sqrt( (double)(n*n + m*m));
-
-	       Am = exp((z-2.0)*L1)-exp(-z*L1);
-	       Ap = exp((z-2.0)*L1)+exp(-z*L1);
-	       Bm = exp((z-1.0)*L1)-exp(-(z+1.0)*L1);
-	       Bp = exp((z-1.0)*L1)+exp(-(z+1.0)*L1);
-	       C = (exp(-z*L1)-1.0)*(exp((z-1.0)*L1)-1.0);
-	       D = exp((z-1.0)*L1)-exp(-z*L1);
-	       E = (1.0+exp(-L1));
-	       
-	       u1 = (n!=0 || m!=0) ? -( z*Am+(z-1.0)*Bm )*del_rho/( 2*Z*L1*E*E ) - C*del_rho/(Z*L1*L1*E) : 0.0;
-	       if ( m !=0 ){
-		  u2 =  ( z*Ap+(z-1.0)*Bp )*del_rho*km/( 2*Z*L1*L1*E*E ) - D*del_rho*km/(2*Z*L1*L1*L1*E);
-		  u5 =  ( z*Am+(z-1.0)*Bm )*del_rho*km/( L1*E*E ) + C*del_rho*km/(L1*L1*E);
-	       } else {
-		  u2 = 0.0;
-		  u5 = 0.0;
-	       }
-	       if ( n !=0 ){
-		  u3 =  ( z*Ap+(z-1.0)*Bp )*del_rho*kn/( 2*Z*L1*L1*E*E ) - D*del_rho*kn/(2*Z*L1*L1*L1*E);
-		  u6 =  ( z*Am+(z-1.0)*Bm )*del_rho*kn/( L1*E*E ) + C*del_rho*kn/(L1*L1*E);
-	       } else {
-		  u3 = 0.0;
-		  u6 = 0.0;
-	       }
-	       u4 = (n!=0 || m!=0) ? -( z*Ap+(z-1.0)*Bp )*del_rho/( E*E ) + 2.0*D*del_rho/(L1*E) : 0.0*del_rho*(z-0.5) ;
-
-	       pp = -u4-2.0*Z*(kn*u3+km*u2);
-	       
-	       txx = (-pp +2.0*Z*kn*u3)*cos(n*M_PI*x)*cos(m*M_PI*y);
-	       tyy = (-pp +2.0*Z*km*u2)*cos(n*M_PI*x)*cos(m*M_PI*y);
-	       tyx = -Z*(km*u3+kn*u2)*sin(n*M_PI*x)*sin(m*M_PI*y);
-	       
-	       pp *= cos(n*M_PI*x)*cos(m*M_PI*y);
-	       //printf("u2 = %0.7g n=%d m=%d --> L2 = %0.7g  --> L1 = %0.7g\n",u2,n,m,L2,L1);
-	       u1 *= cos(n*M_PI*x)*cos(m*M_PI*y); 
-		    
-	       sum1 += u1;
-	       u2 *= cos(n*M_PI*x)*sin(m*M_PI*y);
-	       sum2 += u2;
-	       u3 *= sin(n*M_PI*x)*cos(m*M_PI*y);
-	       sum3 += u3;
-	       u4 *= cos(n*M_PI*x)*cos(m*M_PI*y);
-	       sum4 += u4;
-	       u5 *= cos(n*M_PI*x)*sin(m*M_PI*y);
-	       sum5 += u5;
-	       u6 *= sin(n*M_PI*x)*cos(m*M_PI*y);
-	       sum6 += u6;
-
-	       sum7 += pp; /* total pressure */
-	       sum8 += txx;
-	       sum9 += tyy;
-	       sum10 += tyx;
-	       // u5 = (double)-2*n*M_PI*(Z*u2 + u3)*cos(n*M_PI*x); /* pressure */
-
-	       //u6 = (double)(u3*2*n*M_PI + 4*Z*n*M_PI*u2)*cos(n*M_PI*x); /* xx stress */	    
-	       //sum5 +=u5;
-	       //sum6 +=u6;
-
-	       //u1 *= cos(n*M_PI*x); /* z velocity */
-	       //sum1 += u1;
-	       //u2 *= sin(n*M_PI*x); /* x velocity */
-	       //sum2 += u2;
-	       //u3 *= 2*n*M_PI*cos(n*M_PI*x); /* zz stress */
-	       //sum3 += u3;
-	       //u4 *= 2*n*M_PI*sin(n*M_PI*x); /* zx stress */
-	       //sum4 += u4;
-
-	    }/* n */
-	 }/* m */
-	 //if(z<zc){
-	 //sum7 += sigma*dx; /* n=0 density term */
-	 //sum5 += sigma*dx*(0.5-z); /* n=0 (hydrostatic) pressure term */
-	 //sum3 += -sigma*dx*(0.5-z);/* n=0 (hydrostatic) tzz term */
-	 //} else {
-	 //sum5 += sigma*dx*(0.5-zc); /* n=0 (hydrostatic) pressure term */
-	 //sum3 += -sigma*dx*(0.5-zc);/* n=0 (hydrostatic) tzz term */	    
-	 //}
-	
-	 mag=sqrt(sum1*sum1+sum2*sum2+sum3*sum3);
-	 printf("%0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,sum7,sum8,sum9,sum10,mag);
-      }/* j */
-      // printf("%0.10g\n",exp(400.0));
-      printf("\n");
-   }/* i */
-   return 0;
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solHy/solHy.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solHy/solHy.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,149 @@
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+
+int main (){
+   double Z,u1,u2,u3,u4,u5,u6;
+   double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,sum8,sum9,sum10,x,y,z;
+   double sigma,dx,dy;
+   double del_rho;
+   int i,j,n,m;
+   double L1,kn,km;
+   double Am,Ap,Bm,Bp,C,D,E;
+   double pp,txx,tyy,tyx;
+
+   /*************************************************************************/
+   //
+//   x0 = 0.3; 
+   dx = 0.7;
+   dy = 0.4;
+   sigma = 1.0;
+   Z = 1.0;
+//   zc = 0.6;
+   //
+   y=0.4;
+   for (i=0;i<101;i++){
+      for(j=0;j<101;j++){
+	 x = ((double)i)/100.0;
+	 z = ((double)j)/100.0;
+
+	 sum1=0.0;
+	 sum2=0.0;
+	 sum3=0.0;
+	 sum4=0.0;
+	 sum5=0.0;
+	 sum6=0.0;
+	 sum7=0.0;
+	 sum8=0.0;
+	 sum9=0.0;
+	 sum10=0.0;
+	 
+	 for(n=0;n<45;n++){
+	    for(m=0;m<45;m++){
+
+	       if ( n!=0 && m!=0 ){
+		  del_rho = 4.0*sigma*sin((double)n*M_PI*dx)*sin((double)m*M_PI*dy)/(double)n/M_PI/(double)m/M_PI;
+	       } else {
+		  if ( n==0 && m !=0){
+		     del_rho = 2.0*sigma*dx*sin((double)m*M_PI*dy)/(double)m/M_PI;
+		  } else {
+		     if ( n!=0 && m ==0){
+			del_rho = 2.0*sigma*dy*sin((double)n*M_PI*dx)/(double)n/M_PI;
+		     } else {
+			del_rho = sigma*dx*dy;
+		     }
+		  }
+	       }
+	       kn = M_PI*(double)n;
+	       km = M_PI*(double)m;
+
+	       L1 = M_PI*sqrt( (double)(n*n + m*m));
+
+	       Am = exp((z-2.0)*L1)-exp(-z*L1);
+	       Ap = exp((z-2.0)*L1)+exp(-z*L1);
+	       Bm = exp((z-1.0)*L1)-exp(-(z+1.0)*L1);
+	       Bp = exp((z-1.0)*L1)+exp(-(z+1.0)*L1);
+	       C = (exp(-z*L1)-1.0)*(exp((z-1.0)*L1)-1.0);
+	       D = exp((z-1.0)*L1)-exp(-z*L1);
+	       E = (1.0+exp(-L1));
+	       
+	       u1 = (n!=0 || m!=0) ? -( z*Am+(z-1.0)*Bm )*del_rho/( 2*Z*L1*E*E ) - C*del_rho/(Z*L1*L1*E) : 0.0;
+	       if ( m !=0 ){
+		  u2 =  ( z*Ap+(z-1.0)*Bp )*del_rho*km/( 2*Z*L1*L1*E*E ) - D*del_rho*km/(2*Z*L1*L1*L1*E);
+		  u5 =  ( z*Am+(z-1.0)*Bm )*del_rho*km/( L1*E*E ) + C*del_rho*km/(L1*L1*E);
+	       } else {
+		  u2 = 0.0;
+		  u5 = 0.0;
+	       }
+	       if ( n !=0 ){
+		  u3 =  ( z*Ap+(z-1.0)*Bp )*del_rho*kn/( 2*Z*L1*L1*E*E ) - D*del_rho*kn/(2*Z*L1*L1*L1*E);
+		  u6 =  ( z*Am+(z-1.0)*Bm )*del_rho*kn/( L1*E*E ) + C*del_rho*kn/(L1*L1*E);
+	       } else {
+		  u3 = 0.0;
+		  u6 = 0.0;
+	       }
+	       u4 = (n!=0 || m!=0) ? -( z*Ap+(z-1.0)*Bp )*del_rho/( E*E ) + 2.0*D*del_rho/(L1*E) : 0.0*del_rho*(z-0.5) ;
+
+	       pp = -u4-2.0*Z*(kn*u3+km*u2);
+	       
+	       txx = (-pp +2.0*Z*kn*u3)*cos(n*M_PI*x)*cos(m*M_PI*y);
+	       tyy = (-pp +2.0*Z*km*u2)*cos(n*M_PI*x)*cos(m*M_PI*y);
+	       tyx = -Z*(km*u3+kn*u2)*sin(n*M_PI*x)*sin(m*M_PI*y);
+	       
+	       pp *= cos(n*M_PI*x)*cos(m*M_PI*y);
+	       //printf("u2 = %0.7g n=%d m=%d --> L2 = %0.7g  --> L1 = %0.7g\n",u2,n,m,L2,L1);
+	       u1 *= cos(n*M_PI*x)*cos(m*M_PI*y); 
+		    
+	       sum1 += u1;
+	       u2 *= cos(n*M_PI*x)*sin(m*M_PI*y);
+	       sum2 += u2;
+	       u3 *= sin(n*M_PI*x)*cos(m*M_PI*y);
+	       sum3 += u3;
+	       u4 *= cos(n*M_PI*x)*cos(m*M_PI*y);
+	       sum4 += u4;
+	       u5 *= cos(n*M_PI*x)*sin(m*M_PI*y);
+	       sum5 += u5;
+	       u6 *= sin(n*M_PI*x)*cos(m*M_PI*y);
+	       sum6 += u6;
+
+	       sum7 += pp; /* total pressure */
+	       sum8 += txx;
+	       sum9 += tyy;
+	       sum10 += tyx;
+	       // u5 = (double)-2*n*M_PI*(Z*u2 + u3)*cos(n*M_PI*x); /* pressure */
+
+	       //u6 = (double)(u3*2*n*M_PI + 4*Z*n*M_PI*u2)*cos(n*M_PI*x); /* xx stress */	    
+	       //sum5 +=u5;
+	       //sum6 +=u6;
+
+	       //u1 *= cos(n*M_PI*x); /* z velocity */
+	       //sum1 += u1;
+	       //u2 *= sin(n*M_PI*x); /* x velocity */
+	       //sum2 += u2;
+	       //u3 *= 2*n*M_PI*cos(n*M_PI*x); /* zz stress */
+	       //sum3 += u3;
+	       //u4 *= 2*n*M_PI*sin(n*M_PI*x); /* zx stress */
+	       //sum4 += u4;
+
+	    }/* n */
+	 }/* m */
+	 //if(z<zc){
+	 //sum7 += sigma*dx; /* n=0 density term */
+	 //sum5 += sigma*dx*(0.5-z); /* n=0 (hydrostatic) pressure term */
+	 //sum3 += -sigma*dx*(0.5-z);/* n=0 (hydrostatic) tzz term */
+	 //} else {
+	 //sum5 += sigma*dx*(0.5-zc); /* n=0 (hydrostatic) pressure term */
+	 //sum3 += -sigma*dx*(0.5-zc);/* n=0 (hydrostatic) tzz term */	    
+	 //}
+	
+	 mag=sqrt(sum1*sum1+sum2*sum2+sum3*sum3);
+	 printf("%0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g %0.7g\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,sum7,sum8,sum9,sum10,mag);
+      }/* j */
+      // printf("%0.10g\n",exp(400.0));
+      printf("\n");
+   }/* i */
+   return 0;
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solI/Analytic_solI.c
--- a/SysTest/AnalyticPlugins/Velic_solI/Analytic_solI.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,156 +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:
-*+		Mirko Velic
-*+		Julian Giordani
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Patrick Sunter
-** $Id: solI.c 636 2006-09-08 03:07:06Z JulianGiordani $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include "Analytic_solI.h"
-
-const Type Velic_solI_Type = "Underworld_Velic_solI";
-
-void Velic_solI_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
-	Velic_solI* self = (Velic_solI*) analyticSolution;
-	
-	_Velic_solI( coord, self->sigma, self->B, self->xc, NULL, pressure, NULL, NULL );
-}
-
-void Velic_solI_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
-	Velic_solI* self = (Velic_solI*) analyticSolution;
-	
-	_Velic_solI( coord, self->sigma, self->B, self->xc, velocity, NULL, NULL, NULL );
-}
-
-void Velic_solI_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
-	Velic_solI* self = (Velic_solI*) analyticSolution;
-	
-	_Velic_solI( coord, self->sigma, self->B, self->xc, NULL, NULL, stress, NULL );
-}
-
-
-void Velic_solI_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
-	Velic_solI* self = (Velic_solI*) analyticSolution;
-	
-	_Velic_solI( coord, self->sigma, self->B, self->xc, NULL, NULL, NULL, strainRate );
-}
-
-void _Velic_solI_Init( Velic_solI* self, double sigma, double B, double xc ) {
-	//	Bool                     correctInput = True;
-	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
-        self->_getAnalyticVelocity    = Velic_solI_VelocityFunction;
-	self->_getAnalyticPressure    = Velic_solI_PressureFunction;
-	self->_getAnalyticTotalStress = Velic_solI_StressFunction;
-	self->_getAnalyticStrainRate  = Velic_solI_StrainRateFunction;
-
-	self->sigma = sigma;
-	self->B = B;
-	self->xc = xc;
-}
-
-void _Velic_solI_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
-	Velic_solI* self = (Velic_solI*) analyticSolution;
-	FeVariable*              velocityField;
-	FeVariable*              pressureField;
-	FeVariable*              stressField;
-	FeVariable*              strainRateField;
-	FeVariable*              recoveredStrainRateField;
-	FeVariable*              recoveredStressField;
-	double                   sigma, B, xc, twiceB;
-
-	/* Construct Parent */
-	_AnalyticSolution_AssignFromXML( self, cf, data );
-
-	/* Create Analytic Fields */
-	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solI_VelocityFunction );
-
-	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solI_PressureFunction );
-
-	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False, data );
-	if ( stressField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solI_StressFunction );
-
-	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
-	if ( strainRateField   ) {
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solI_StrainRateFunction );
-	}
-
-	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
-	if ( recoveredStrainRateField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solI_StrainRateFunction );
-
-	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
-	if ( recoveredStressField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solI_StressFunction );
-	
-	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solI_sigma", 1.0  );
-	twiceB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solI_twiceB", 2.0  );
-	B = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solI_B", 0.5 * twiceB  );
-	xc = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solI_xc", 0.3  );
-
-	_Velic_solI_Init( self, sigma, B, xc );
-
-}
-
-void* _Velic_solI_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Velic_solI);
-	Type                                                      type = Velic_solI_Type;
-	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
-	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
-	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solI_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Velic_solI_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _AnalyticSolution_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 Underworld_Velic_solI_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Velic_solI_Type, (Name)"0", _Velic_solI_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solI/Analytic_solI.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solI/Analytic_solI.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,156 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Mirko Velic
+*+		Julian Giordani
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Patrick Sunter
+** $Id: solI.c 636 2006-09-08 03:07:06Z JulianGiordani $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include "Analytic_solI.h"
+
+const Type Velic_solI_Type = "Underworld_Velic_solI";
+
+void Velic_solI_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
+	Velic_solI* self = (Velic_solI*) analyticSolution;
+	
+	_Velic_solI( coord, self->sigma, self->B, self->xc, NULL, pressure, NULL, NULL );
+}
+
+void Velic_solI_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
+	Velic_solI* self = (Velic_solI*) analyticSolution;
+	
+	_Velic_solI( coord, self->sigma, self->B, self->xc, velocity, NULL, NULL, NULL );
+}
+
+void Velic_solI_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
+	Velic_solI* self = (Velic_solI*) analyticSolution;
+	
+	_Velic_solI( coord, self->sigma, self->B, self->xc, NULL, NULL, stress, NULL );
+}
+
+
+void Velic_solI_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
+	Velic_solI* self = (Velic_solI*) analyticSolution;
+	
+	_Velic_solI( coord, self->sigma, self->B, self->xc, NULL, NULL, NULL, strainRate );
+}
+
+void _Velic_solI_Init( Velic_solI* self, double sigma, double B, double xc ) {
+	//	Bool                     correctInput = True;
+	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
+        self->_getAnalyticVelocity    = Velic_solI_VelocityFunction;
+	self->_getAnalyticPressure    = Velic_solI_PressureFunction;
+	self->_getAnalyticTotalStress = Velic_solI_StressFunction;
+	self->_getAnalyticStrainRate  = Velic_solI_StrainRateFunction;
+
+	self->sigma = sigma;
+	self->B = B;
+	self->xc = xc;
+}
+
+void _Velic_solI_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
+	Velic_solI* self = (Velic_solI*) analyticSolution;
+	FeVariable*              velocityField;
+	FeVariable*              pressureField;
+	FeVariable*              stressField;
+	FeVariable*              strainRateField;
+	FeVariable*              recoveredStrainRateField;
+	FeVariable*              recoveredStressField;
+	double                   sigma, B, xc, twiceB;
+
+	/* Construct Parent */
+	_AnalyticSolution_AssignFromXML( self, cf, data );
+
+	/* Create Analytic Fields */
+	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solI_VelocityFunction );
+
+	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solI_PressureFunction );
+
+	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False, data );
+	if ( stressField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solI_StressFunction );
+
+	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
+	if ( strainRateField   ) {
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solI_StrainRateFunction );
+	}
+
+	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
+	if ( recoveredStrainRateField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solI_StrainRateFunction );
+
+	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
+	if ( recoveredStressField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solI_StressFunction );
+	
+	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solI_sigma", 1.0  );
+	twiceB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solI_twiceB", 2.0  );
+	B = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solI_B", 0.5 * twiceB  );
+	xc = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solI_xc", 0.3  );
+
+	_Velic_solI_Init( self, sigma, B, xc );
+
+}
+
+void* _Velic_solI_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Velic_solI);
+	Type                                                      type = Velic_solI_Type;
+	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
+	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
+	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solI_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Velic_solI_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _AnalyticSolution_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 Underworld_Velic_solI_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Velic_solI_Type, (Name)"0", _Velic_solI_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solI/solI.c
--- a/SysTest/AnalyticPlugins/Velic_solI/solI.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,433 +0,0 @@
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-
-void _Velic_solI( 
-		double pos[],
-		double _sigma,
-		double _B, double _x_c,
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] );
-
-
-int main( int argc, char **argv )
-{
-	int i,j;
-	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
-	double x,z;
-	
-	for (i=0;i<101;i++){
-		for(j=0;j<101;j++){
-			x = i/100.0;
-			z = j/100.0;
-			
-			pos[0] = x;
-			pos[1] = z;
-			_Velic_solI(
-					pos,
-					1.0,
-					1.5, 0.3,
-					vel, &pressure, total_stress, strain_rate );
-			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
-					pos[0],pos[1],
-					vel[0],vel[1], pressure, 
-					total_stress[0], total_stress[1], total_stress[2], 
-					strain_rate[0], strain_rate[1], strain_rate[2] );
-		}
-		printf("\n");
-	}
-	
-	return 0;
-}
-
-
-
-void _Velic_solI( 
-		double pos[],
-		double _sigma, /* density */
-		double _B, double _x_c, /* viscosity parameter, width of dense column */
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] )
-{
-	double Z;
-	double u1,u2,u3,u4,pp,txx;
-	double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,x,z;
-	double sigma,xc;
-	double del_rho;
-	int n;
-	double kn;
-	double _C1,_C2,_C3,_C4;
-	double B, Rp, R, U, VV;
-	double rho,a,b,r;
-	
-	double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
-	double t11,t12,t13,t14,t15,t16,t17,t18,t19,t20;
-	double t21,t22,t23,t24,t25,t26,t27,t28,t29,t30;
-	double t31,t32,t33,t34,t35,t36,t37,t38,t39,t40;
-	double t41,t42,t43,t44,t45,t46,t47,t48,t49,t50;
-	double t51,t52,t53,t57,t58,t59,t60,t61,t62,t63;
-	double t64,t65,t66,t67,t69,t70,t72,t73,t74,t75;
-	double t76,t77,t78,t81,t82,t84,t85,t88,t89,t91;
-	double t92,t95,t105,t106,t108,t109,t110,t111,t112,t116;
-	double t117,t119,t120,t121,t123,t126,t127,t128,t129,t130;
-	double t131,t134,t135,t137,t140,t143;
-	
-	
-	
-	/*************************************************************************/
-	/*************************************************************************/
-	/* "background" fluid has density of zero */
-	xc = _x_c;  /* centre of dense column */
-	sigma = _sigma; /* density parameter */
-	B = _B; /* viscosity parameter */
-	/* viscosity = exp(2.0*B*z) */
-	/*************************************************************************/
-	/*************************************************************************/
-	
-	x = pos[0];
-	z = pos[1];
-	
-	sum1=0.0;
-	sum2=0.0;
-	sum3=0.0;
-	sum4=0.0;
-	sum5=0.0;
-	sum6=0.0;
-	sum7=0.0;
-	
-	for(n=1;n<55;n++){
-		kn = (double) n*M_PI;
-		
-		a = B*B + kn*kn;
-		b = 2.0*kn*B;
-		r = sqrt(a*a + b*b);
-		Rp = sqrt( (r+a)/2.0 );
-		R  = sqrt( (r-a)/2.0 );
-		U  = Rp - B;
-		VV = Rp + B;
-		
-		/*******************************************/
-		/*            calculate del_rho            */
-		/*******************************************/
-		del_rho = 2.0*sigma*sin(kn*xc)/kn;
-		
-		/*******************************************/
-		/*         calculate the constants         */
-		/*******************************************/
-		
-		
-		t2 = sin(R);
-		t3 = t2 * R;
-		t4 = Rp * Rp;
-		t6 = (-(double) B - Rp);
-		t8 = exp((double) (2 * t6));
-		t11 = R * R;
-		t12 = t11 * Rp;
-		t13 = 0.2e1 * R;
-		t14 = cos(t13);
-		t16 = exp((double) t6);
-		t19 = (double) B * (double) B;
-		t25 = exp(-(double) (2 * B));
-		t26 = t25 * t2;
-		t31 = t11 * t19;
-		t34 = exp(-(double) B - 0.3e1 * Rp);
-		t37 = t19 * (double) B;
-		t38 = t37 * Rp;
-		t41 = t11 * t4;
-		t46 = t4 * Rp;
-		t47 = t46 * (double) B;
-		t49 = t19 * t4;
-		t53 = sin(t13);
-		t61 = cos(R);
-		t62 = t25 * t61;
-		t67 = t14 * t16;
-		t70 = -t3 * t4 * (double) B * t8 + t12 * (double) B * t14 * t16 + 0.5e1 * t3 * t19 * Rp * t8 + 0.5e1 * t26 * R * t19 * Rp + 0.2e1 * t31 * t34 + 0.3e1 * t38 * t16 - 0.2e1 * t41 * t34 - 0.2e1 * t31 * t16 - t47 * t16 - 0.2e1 * t49 * t16 - 0.5e1 * R * Rp * t19 * t53 * t16 + t26 * R * t4 * (double) B + 0.2e1 * t62 * t31 - t12 * (double) B * t16 - 0.3e1 * t38 * t67;
-		t72 = t11 * R;
-		t75 = t61 * t11;
-		t81 = t2 * t72;
-		t88 = R * t46;
-		t89 = t53 * t16;
-		t91 = t72 * Rp;
-		t109 = t47 * t67 + t26 * t72 * (double) B + 0.2e1 * t75 * t4 * t8 + 0.2e1 * t41 * t67 - t81 * (double) B * t8 + 0.2e1 * t49 * t67 + t81 * Rp * t8 + t88 * t89 + t26 * t91 - 0.2e1 * t75 * t19 * t8 - t91 * t89 + 0.3e1 * t25 * t37 * t3 - 0.3e1 * t37 * R * t2 * t8 - t3 * t46 * t8 - 0.2e1 * t62 * t41 - t26 * t88;
-		t111 = kn * kn;
-		t117 = exp(-0.4e1 * Rp);
-		t120 = exp(-0.2e1 * Rp);
-		t123 = t120 * t14;
-		_C1 = del_rho * kn * (t70 + t109) / (t111 + 0.4e1 * t19) / (t31 - t41 * t117 - 0.2e1 * t49 * t120 + 0.2e1 * t49 * t123 + 0.2e1 * t41 * t123 - t41 - 0.2e1 * t31 * t120 + t31 * t117) / 0.2e1;
-		
-		t3 = exp(-(double) (2 * B));
-		t4 = t3 * R;
-		t5 = cos(R);
-		t6 = t5 * Rp;
-		t7 = B * B;
-		t11 = Rp * Rp;
-		t12 = t11 * R;
-		t13 = -(double) B - Rp;
-		t14 = exp(t13);
-		t17 = t11 * Rp;
-		t19 = 0.2e1 * R;
-		t20 = sin(t19);
-		t21 = t20 * t14;
-		t23 = R * R;
-		t24 = t23 * R;
-		t25 = t24 * Rp;
-		t26 = cos(t19);
-		t27 = t26 * t14;
-		t29 = t24 * t5;
-		t31 = exp(0.2e1 * t13);
-		t32 = (double) B * t31;
-		t34 = sin(R);
-		t35 = t23 * t34;
-		t36 = t11 * t31;
-		t39 = t7 * B;
-		t45 = exp(-(double) B - 0.3e1 * Rp);
-		t51 = R * t5;
-		t57 = t34 * (double) t7;
-		t60 = t3 * t24;
-		t62 = t3 * t23;
-		t74 = Rp * t31;
-		t77 = -0.5e1 * t4 * t6 * (double) t7 + t12 * (double) B * t14 + t17 * (double) B * t21 + t25 * t27 + t29 * t32 - 0.2e1 * t35 * t36 - 0.3e1 * t4 * t5 * (double) t39 - t12 * (double) B * t45 - 0.2e1 * t35 * (double) t7 * t31 + 0.3e1 * t51 * (double) t39 * t31 - t51 * t17 * t31 - 0.4e1 * t57 * t36 - t60 * t6 - 0.2e1 * t62 * t34 * t11 - t60 * t5 * (double) B + 0.2e1 * t62 * t57 - 0.2e1 * t34 * t17 * t32 + 0.6e1 * t34 * (double) t39 * t74;
-		t78 = R * Rp;
-		t82 = (double) t7 * t11;
-		t85 = t23 * t11;
-		t106 = R * t17;
-		t108 = R * (double) t39;
-		t111 = t24 * (double) B;
-		t128 = -0.5e1 * t78 * (double) t7 * t45 + 0.2e1 * t82 * t21 + 0.2e1 * t85 * t21 - 0.3e1 * (double) t39 * Rp * t21 - t25 * t45 + t51 * t11 * (double) B * t31 + t23 * Rp * (double) B * t20 * t14 + 0.5e1 * t51 * Rp * (double) t7 * t31 + t4 * t5 * t17 + t29 * t74 - t106 * t27 - 0.3e1 * t108 * t45 + t111 * t14 + t106 * t45 - t111 * t45 + 0.3e1 * t108 * t14 + 0.5e1 * t78 * (double) t7 * t26 * t14 - t4 * t5 * t11 * (double) B - 0.2e1 * t35 * Rp * (double) B * t31;
-		t130 = (kn * kn);
-		t135 = t23 * (double) t7;
-		t137 = exp(-0.4e1 * Rp);
-		t140 = exp(-0.2e1 * Rp);
-		t143 = t140 * t26;
-		_C2 = del_rho * kn * (t77 + t128) / (double) (t130 + 4 * t7) / (t135 - t85 * t137 - 0.2e1 * t82 * t140 + 0.2e1 * t82 * t143 + 0.2e1 * t85 * t143 - t85 - 0.2e1 * t135 * t140 + t135 * t137) / 0.2e1;
-		
-		t2 = R * Rp;
-		t3 = B * B;
-		t4 = sin(R);
-		t7 = exp(-B - Rp);
-		t11 = t4 * R;
-		t15 = exp(-B - 0.3e1 * Rp);
-		t19 = Rp * Rp;
-		t20 = t19 * B;
-		t23 = R * R;
-		t24 = t3 * t23;
-		t26 = exp(-0.2e1 * Rp);
-		t28 = 0.2e1 * t24 * t26;
-		t29 = t26 * Rp;
-		t30 = t3 * B;
-		t33 = t19 * Rp;
-		t34 = t26 * t33;
-		t36 = t3 * t19;
-		t38 = 0.2e1 * t36 * t26;
-		t40 = t26 * t23;
-		t41 = Rp * B;
-		t42 = 0.2e1 * R;
-		t43 = cos(t42);
-		t49 = cos(R);
-		t50 = t49 * t23;
-		t58 = t4 * t7;
-		t60 = t23 * R;
-		t63 = t23 * t19;
-		t64 = t26 * t43;
-		t66 = 0.2e1 * t63 * t64;
-		t67 = 0.5e1 * t2 * t3 * t4 * t7 + 0.5e1 * t11 * t3 * Rp * t15 - t11 * t20 * t15 + t28 + 0.3e1 * t29 * t30 - t34 * B + t38 - 0.2e1 * t24 + t40 * t41 * t43 - 0.3e1 * t29 * t30 * t43 - 0.2e1 * t50 * t3 * t15 + 0.2e1 * t50 * t3 * t7 - R * t33 * t58 + t60 * Rp * t58 - t66;
-		t69 = 0.2e1 * t36 * t64;
-		t70 = t4 * t60;
-		t76 = sin(t42);
-		t108 = -t69 + t70 * B * t7 + t70 * Rp * t15 + t26 * R * t33 * t76 - t70 * B * t15 - t26 * t60 * Rp * t76 - t40 * t41 - t11 * t33 * t15 + t34 * B * t43 + 0.2e1 * t50 * t19 * t15 - 0.2e1 * t50 * t19 * t7 + 0.3e1 * t11 * t30 * t7 - 0.3e1 * t11 * t30 * t15 + t11 * t20 * t7 + 0.2e1 * t63 - 0.5e1 * t26 * t3 * t2 * t76;
-		t110 = kn * kn;
-		t116 = exp(-0.4e1 * Rp);
-		_C3 = -del_rho * kn * (t67 + t108) / (t110 + 0.4e1 * t3) / (t24 - t63 * t116 - t38 + t69 + t66 - t63 - t28 + t24 * t116) / 0.2e1;
-		
-		t2 = ((double) B * (double) B);
-		t3 = ((double) t2 * (double) B);
-		t6 = ((double) Rp * (double) Rp);
-		t10 = exp(-(double) (2 * Rp));
-		t11 = (double) R * (double) R;
-		t12 = t11 * (double) R;
-		t13 = t10 * t12;
-		t15 = R * Rp;
-		t18 = t10 * (double) R;
-		t19 = (double) t6 * (double) B;
-		t21 = cos((double) R);
-		t24 = exp((double) (-B - Rp));
-		t28 = t12 * (double) Rp;
-		t29 = t21 * t24;
-		t33 = t6 * Rp;
-		t34 = 2 * R;
-		t35 = cos((double) t34);
-		t38 = t12 * t21;
-		t41 = exp((double) (-B - 3 * Rp));
-		t44 = (double) B * t24;
-		t48 = (double) R * t21;
-		t52 = sin((double) t34);
-		t53 = (double) t6 * t52;
-		t59 = sin((double) R);
-		t60 = t11 * t59;
-		t70 = (double) (3 * t3 * R) + (double) (R * t6 * B) - t13 * (double) B - (double) (5 * t15 * t2) - t18 * t19 + 0.5e1 * (double) t15 * (double) t2 * t21 * t24 + t28 * t29 - 0.3e1 * t18 * (double) t3 - t18 * (double) t33 * t35 - t38 * (double) Rp * t41 - t38 * t44 + t38 * (double) B * t41 - t48 * t19 * t24 - 0.2e1 * t10 * (double) t2 * t53 - 0.3e1 * t48 * (double) t3 * t24 - 0.2e1 * t60 * (double) t2 * t41 - 0.2e1 * t59 * (double) t33 * t44 + 0.2e1 * t60 * (double) t2 * t24;
-		t84 = (double) t6 * t24;
-		t92 = t10 * t11;
-		t95 = R * t33;
-		t105 = Rp * t2;
-		t109 = Rp * B;
-		t119 = 0.2e1 * t60 * (double) t6 * t41 + 0.3e1 * t48 * (double) t3 * t41 - 0.3e1 * t10 * (double) t3 * (double) Rp * t52 + t13 * (double) Rp * t35 + 0.4e1 * (double) t2 * t59 * t84 + t48 * (double) t33 * t41 + t10 * (double) t33 * (double) B * t52 - 0.2e1 * t92 * t53 - (double) t95 * t29 + 0.2e1 * t60 * t84 + 0.6e1 * t59 * (double) t3 * (double) Rp * t24 + t48 * t19 * t41 + 0.5e1 * t18 * (double) t105 * t35 + t92 * (double) t109 * t52 - 0.5e1 * t48 * (double) t105 * t41 - 0.2e1 * t60 * (double) t109 * t24 + t12 * (double) B + (double) t95 - t28;
-		t121 = (kn * kn);
-		t126 = t11 * (double) t2;
-		t127 = t11 * (double) t6;
-		t129 = exp(-(double) (4 * Rp));
-		t131 = t2 * t6;
-		t134 = t10 * t35;
-		_C4 = -del_rho * kn * (t70 + t119) / (double) (t121 + 4 * t2) / (t126 - t127 * t129 - 0.2e1 * (double) t131 * t10 + 0.2e1 * (double) t131 * t134 + 0.2e1 * t127 * t134 - t127 - 0.2e1 * t126 * t10 + t126 * t129) / 0.2e1;
-		
-		/*******************************************/
-		/*       calculate the velocities etc      */
-		/*******************************************/
-		
-		
-		t1 = (kn * kn);
-		t2 = (B * B);
-		t8 = exp(B * z);
-		t9 = t8 * t8;
-		t14 = exp(U * (z - 0.1e1));
-		t15 = 0.1e1 / kn;
-		t17 = R * z;
-		t18 = cos(t17);
-		t20 = sin(t17);
-		t25 = exp(-VV * z);
-		u1 = -0.1e1 / (double) (t1 + 4 * t2) * del_rho / t9 + t14 * t15 * (_C1 * t18 + _C2 * t20) + t25 * t15 * (_C3 * t18 + _C4 * t20);
-		
-		t3 = exp((double) (U * (z - 1)));
-		t4 = R * z;
-		t5 = sin((double) t4);
-		t6 = t5 * (double) R;
-		t7 = cos((double) t4);
-		t11 = (kn * kn);
-		t12 = 0.1e1 / t11;
-		t16 = t7 * (double) R;
-		t22 = exp(-(double) (VV * z));
-		t33 = ((double) B * (double) B);
-		t39 = exp((double) (B * z));
-		t40 = t39 * t39;
-		u2 = -t3 * (-t6 + (double) U * t7) * _C1 * t12 - t3 * ((double) U * t5 + t16) * _C2 * t12 + t22 * (t6 + (double) VV * t7) * _C3 * t12 - t22 * (t16 - (double) VV * t5) * _C4 * t12 - 0.2e1 / (double) (t11 + 4 * t33) * del_rho / t40 * (double) B / kn;
-		
-		t5 = exp((double) (2 * B * z + U * z - U));
-		t6 = R * z;
-		t7 = sin((double) t6);
-		t8 = t7 * (double) R;
-		t9 = kn * kn;
-		t11 = 0.3e1 * t8 * t9;
-		t12 = cos((double) t6);
-		t13 = (double) U * t12;
-		t16 = U * U;
-		t17 = B * t16;
-		t20 = (double) B * t12;
-		t21 = R * R;
-		t23 = 0.2e1 * t20 * (double) t21;
-		t24 = B * U;
-		t28 = 0.2e1 * t20 * t9;
-		t29 = t16 * U;
-		t36 = t21 * R;
-		t37 = t7 * (double) t36;
-		t41 = 0.1e1 / t9 / kn;
-		t44 = (double) U * t7;
-		t47 = t12 * (double) R;
-		t49 = 0.3e1 * t47 * t9;
-		t50 = (double) B * t7;
-		t52 = 0.2e1 * t50 * (double) t21;
-		t58 = 0.2e1 * t50 * t9;
-		t65 = t12 * (double) t36;
-		t73 = exp((double) (z * (2 * B - VV)));
-		t74 = (double) VV * t12;
-		t77 = VV * VV;
-		t78 = B * t77;
-		t81 = B * VV;
-		t84 = t77 * VV;
-		t95 = (double) VV * t7;
-		t112 = B * B;
-		u3 = t5 * (-t11 + 0.3e1 * t13 * t9 - 0.2e1 * (double) t17 * t12 + t23 + 0.4e1 * (double) t24 * t8 - t28 - (double) t29 * t12 + 0.3e1 * t13 * (double) t21 + 0.3e1 * (double) t16 * t7 * (double) R - t37) * _C1 * t41 + t5 * (0.3e1 * t44 * t9 + t49 + t52 - 0.2e1 * (double) t17 * t7 - 0.4e1 * (double) t24 * t47 - t58 + 0.3e1 * t44 * (double) t21 - (double) t29 * t7 - 0.3e1 * (double) t16 * t12 * (double) R + t65) * _C2 * t41 + t73 * (-t11 - 0.3e1 * t74 * t9 - 0.2e1 * (double) t78 * t12 + t23 - 0.4e1 * (double) t81 * t8 - t28 + (double) t84 * t12 - 0.3e1 * t74 * (double) t21 + 0.3e1 * (double) t77 * t7 * (double) R - t37) * _C3 * t41 + t73 * (t49 - 0.3e1 * t95 * t9 - 0.2e1 * (double) t78 * t7 + t52 + 0.4e1 * (double) t81 * t47 - t58 + (double) t84 * t7 - 0.3e1 * t95 * (double) t21 - 0.3e1 * (double) t77 * t12 * (double) R + t65) * _C4 * t41 + 0.8e1 / (t9 + (double) (4 * t112)) * del_rho * (double) B;
-		
-		t5 = exp((double) (2 * B * z + U * z - U));
-		t6 = U * U;
-		t7 = R * z;
-		t8 = cos((double) t7);
-		t10 = R * R;
-		t11 = t8 * (double) t10;
-		t12 = sin((double) t7);
-		t16 = kn * kn;
-		t17 = t8 * t16;
-		t20 = 0.1e1 / t16;
-		t23 = t12 * (double) t10;
-		t28 = t12 * t16;
-		t36 = exp((double) (z * (2 * B - VV)));
-		t37 = VV * VV;
-		u4 = t5 * (-(double) t6 * t8 + t11 + 0.2e1 * (double) U * t12 * (double) R - t17) * _C1 * t20 - t5 * (-t23 + (double) t6 * t12 + 0.2e1 * (double) U * t8 * (double) R + t28) * _C2 * t20 + t36 * (-(double) t37 * t8 + t11 - 0.2e1 * (double) VV * t12 * (double) R - t17) * _C3 * t20 + t36 * (-(double) t37 * t12 + t23 + 0.2e1 * (double) VV * t8 * (double) R - t28) * _C4 * t20 + del_rho / kn;
-		
-		
-		
-		pp = (double)-(u3 + 2.0*n*M_PI*exp(2.0*B*z)*u2)*cos(n*M_PI*x); /* pressure */
-		
-		txx = (double)(u3 + 4*exp(2.0*B*z)*n*M_PI*u2)*cos(n*M_PI*x); /* xx stress */	    
-		sum5 += pp;
-		sum6 += txx;
-		
-		u1 *= cos(n*M_PI*x); /* z velocity */
-		sum1 += u1;
-		u2 *= sin(n*M_PI*x); /* x velocity */
-		sum2 += u2;
-		u3 *= cos(n*M_PI*x); /* zz stress */
-		sum3 += u3;
-		u4 *= sin(n*M_PI*x); /* zx stress */
-		sum4 += u4;
-		
-		rho = del_rho* cos(n*M_PI*x); /* density */
-		sum7 += rho;
-	}/* n */
-	
-	/* include terms for n=0 now */
-	del_rho = sigma*xc;
-	rho = del_rho; /* density */
-	sum7 += rho;
-	
-	u3 = del_rho*(z-0.5); /* zz stress */
-	sum3 += u3;
-	
-	txx = u3; /* xx stress */
-	pp = -u3; /* pressure */
-	sum5 += pp;
-	sum6 += txx;
-	
-	
-	mag=sqrt(sum1*sum1+sum2*sum2);
-	//printf("%0.7g %0.7g %0.7g %0.7g %0.7g %0.7g\n",x,y,z,sum3,sum2,sum1);
-	//printf("%0.7g %0.7g %0.7g\n%0.7g %0.7g %0.7g\n\n\n",x,y,z,x+sum3,y+sum2,z+sum1);
-	/*printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7);*/
-	
-	/* Output */
-	if( vel != NULL ) {
-		vel[0] = sum2;
-		vel[1] = sum1;
-	}
-	if( presssure != NULL ) {
-		(*presssure) = sum5;
-	}
-	if( total_stress != NULL ) {
-		total_stress[0] = sum6;
-		total_stress[1] = sum3;
-		total_stress[2] = sum4;
-	}
-	if( strain_rate != NULL ) {
-		/* sigma = tau - p, tau = sigma + p, tau[] = 2*eta*strain_rate[] */
-		Z = exp(2.0*B*z);
-		strain_rate[0] = (sum6+sum5)/(2.0*Z);
-		strain_rate[1] = (sum3+sum5)/(2.0*Z);
-		strain_rate[2] = (sum4)/(2.0*Z);
-	}
-	/* Value checks, could be cleaned up if needed. Julian Giordani 9-Oct-2006*/
-        if( fabs( sum5 - ( -0.5*(sum6+sum3) ) ) > 1e-5 ) {
-                assert(0);
-        }
-	
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solI/solI.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solI/solI.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,433 @@
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+
+void _Velic_solI( 
+		double pos[],
+		double _sigma,
+		double _B, double _x_c,
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] );
+
+
+int main( int argc, char **argv )
+{
+	int i,j;
+	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
+	double x,z;
+	
+	for (i=0;i<101;i++){
+		for(j=0;j<101;j++){
+			x = i/100.0;
+			z = j/100.0;
+			
+			pos[0] = x;
+			pos[1] = z;
+			_Velic_solI(
+					pos,
+					1.0,
+					1.5, 0.3,
+					vel, &pressure, total_stress, strain_rate );
+			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
+					pos[0],pos[1],
+					vel[0],vel[1], pressure, 
+					total_stress[0], total_stress[1], total_stress[2], 
+					strain_rate[0], strain_rate[1], strain_rate[2] );
+		}
+		printf("\n");
+	}
+	
+	return 0;
+}
+
+
+
+void _Velic_solI( 
+		double pos[],
+		double _sigma, /* density */
+		double _B, double _x_c, /* viscosity parameter, width of dense column */
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] )
+{
+	double Z;
+	double u1,u2,u3,u4,pp,txx;
+	double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,x,z;
+	double sigma,xc;
+	double del_rho;
+	int n;
+	double kn;
+	double _C1,_C2,_C3,_C4;
+	double B, Rp, R, U, VV;
+	double rho,a,b,r;
+	
+	double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
+	double t11,t12,t13,t14,t15,t16,t17,t18,t19,t20;
+	double t21,t22,t23,t24,t25,t26,t27,t28,t29,t30;
+	double t31,t32,t33,t34,t35,t36,t37,t38,t39,t40;
+	double t41,t42,t43,t44,t45,t46,t47,t48,t49,t50;
+	double t51,t52,t53,t57,t58,t59,t60,t61,t62,t63;
+	double t64,t65,t66,t67,t69,t70,t72,t73,t74,t75;
+	double t76,t77,t78,t81,t82,t84,t85,t88,t89,t91;
+	double t92,t95,t105,t106,t108,t109,t110,t111,t112,t116;
+	double t117,t119,t120,t121,t123,t126,t127,t128,t129,t130;
+	double t131,t134,t135,t137,t140,t143;
+	
+	
+	
+	/*************************************************************************/
+	/*************************************************************************/
+	/* "background" fluid has density of zero */
+	xc = _x_c;  /* centre of dense column */
+	sigma = _sigma; /* density parameter */
+	B = _B; /* viscosity parameter */
+	/* viscosity = exp(2.0*B*z) */
+	/*************************************************************************/
+	/*************************************************************************/
+	
+	x = pos[0];
+	z = pos[1];
+	
+	sum1=0.0;
+	sum2=0.0;
+	sum3=0.0;
+	sum4=0.0;
+	sum5=0.0;
+	sum6=0.0;
+	sum7=0.0;
+	
+	for(n=1;n<55;n++){
+		kn = (double) n*M_PI;
+		
+		a = B*B + kn*kn;
+		b = 2.0*kn*B;
+		r = sqrt(a*a + b*b);
+		Rp = sqrt( (r+a)/2.0 );
+		R  = sqrt( (r-a)/2.0 );
+		U  = Rp - B;
+		VV = Rp + B;
+		
+		/*******************************************/
+		/*            calculate del_rho            */
+		/*******************************************/
+		del_rho = 2.0*sigma*sin(kn*xc)/kn;
+		
+		/*******************************************/
+		/*         calculate the constants         */
+		/*******************************************/
+		
+		
+		t2 = sin(R);
+		t3 = t2 * R;
+		t4 = Rp * Rp;
+		t6 = (-(double) B - Rp);
+		t8 = exp((double) (2 * t6));
+		t11 = R * R;
+		t12 = t11 * Rp;
+		t13 = 0.2e1 * R;
+		t14 = cos(t13);
+		t16 = exp((double) t6);
+		t19 = (double) B * (double) B;
+		t25 = exp(-(double) (2 * B));
+		t26 = t25 * t2;
+		t31 = t11 * t19;
+		t34 = exp(-(double) B - 0.3e1 * Rp);
+		t37 = t19 * (double) B;
+		t38 = t37 * Rp;
+		t41 = t11 * t4;
+		t46 = t4 * Rp;
+		t47 = t46 * (double) B;
+		t49 = t19 * t4;
+		t53 = sin(t13);
+		t61 = cos(R);
+		t62 = t25 * t61;
+		t67 = t14 * t16;
+		t70 = -t3 * t4 * (double) B * t8 + t12 * (double) B * t14 * t16 + 0.5e1 * t3 * t19 * Rp * t8 + 0.5e1 * t26 * R * t19 * Rp + 0.2e1 * t31 * t34 + 0.3e1 * t38 * t16 - 0.2e1 * t41 * t34 - 0.2e1 * t31 * t16 - t47 * t16 - 0.2e1 * t49 * t16 - 0.5e1 * R * Rp * t19 * t53 * t16 + t26 * R * t4 * (double) B + 0.2e1 * t62 * t31 - t12 * (double) B * t16 - 0.3e1 * t38 * t67;
+		t72 = t11 * R;
+		t75 = t61 * t11;
+		t81 = t2 * t72;
+		t88 = R * t46;
+		t89 = t53 * t16;
+		t91 = t72 * Rp;
+		t109 = t47 * t67 + t26 * t72 * (double) B + 0.2e1 * t75 * t4 * t8 + 0.2e1 * t41 * t67 - t81 * (double) B * t8 + 0.2e1 * t49 * t67 + t81 * Rp * t8 + t88 * t89 + t26 * t91 - 0.2e1 * t75 * t19 * t8 - t91 * t89 + 0.3e1 * t25 * t37 * t3 - 0.3e1 * t37 * R * t2 * t8 - t3 * t46 * t8 - 0.2e1 * t62 * t41 - t26 * t88;
+		t111 = kn * kn;
+		t117 = exp(-0.4e1 * Rp);
+		t120 = exp(-0.2e1 * Rp);
+		t123 = t120 * t14;
+		_C1 = del_rho * kn * (t70 + t109) / (t111 + 0.4e1 * t19) / (t31 - t41 * t117 - 0.2e1 * t49 * t120 + 0.2e1 * t49 * t123 + 0.2e1 * t41 * t123 - t41 - 0.2e1 * t31 * t120 + t31 * t117) / 0.2e1;
+		
+		t3 = exp(-(double) (2 * B));
+		t4 = t3 * R;
+		t5 = cos(R);
+		t6 = t5 * Rp;
+		t7 = B * B;
+		t11 = Rp * Rp;
+		t12 = t11 * R;
+		t13 = -(double) B - Rp;
+		t14 = exp(t13);
+		t17 = t11 * Rp;
+		t19 = 0.2e1 * R;
+		t20 = sin(t19);
+		t21 = t20 * t14;
+		t23 = R * R;
+		t24 = t23 * R;
+		t25 = t24 * Rp;
+		t26 = cos(t19);
+		t27 = t26 * t14;
+		t29 = t24 * t5;
+		t31 = exp(0.2e1 * t13);
+		t32 = (double) B * t31;
+		t34 = sin(R);
+		t35 = t23 * t34;
+		t36 = t11 * t31;
+		t39 = t7 * B;
+		t45 = exp(-(double) B - 0.3e1 * Rp);
+		t51 = R * t5;
+		t57 = t34 * (double) t7;
+		t60 = t3 * t24;
+		t62 = t3 * t23;
+		t74 = Rp * t31;
+		t77 = -0.5e1 * t4 * t6 * (double) t7 + t12 * (double) B * t14 + t17 * (double) B * t21 + t25 * t27 + t29 * t32 - 0.2e1 * t35 * t36 - 0.3e1 * t4 * t5 * (double) t39 - t12 * (double) B * t45 - 0.2e1 * t35 * (double) t7 * t31 + 0.3e1 * t51 * (double) t39 * t31 - t51 * t17 * t31 - 0.4e1 * t57 * t36 - t60 * t6 - 0.2e1 * t62 * t34 * t11 - t60 * t5 * (double) B + 0.2e1 * t62 * t57 - 0.2e1 * t34 * t17 * t32 + 0.6e1 * t34 * (double) t39 * t74;
+		t78 = R * Rp;
+		t82 = (double) t7 * t11;
+		t85 = t23 * t11;
+		t106 = R * t17;
+		t108 = R * (double) t39;
+		t111 = t24 * (double) B;
+		t128 = -0.5e1 * t78 * (double) t7 * t45 + 0.2e1 * t82 * t21 + 0.2e1 * t85 * t21 - 0.3e1 * (double) t39 * Rp * t21 - t25 * t45 + t51 * t11 * (double) B * t31 + t23 * Rp * (double) B * t20 * t14 + 0.5e1 * t51 * Rp * (double) t7 * t31 + t4 * t5 * t17 + t29 * t74 - t106 * t27 - 0.3e1 * t108 * t45 + t111 * t14 + t106 * t45 - t111 * t45 + 0.3e1 * t108 * t14 + 0.5e1 * t78 * (double) t7 * t26 * t14 - t4 * t5 * t11 * (double) B - 0.2e1 * t35 * Rp * (double) B * t31;
+		t130 = (kn * kn);
+		t135 = t23 * (double) t7;
+		t137 = exp(-0.4e1 * Rp);
+		t140 = exp(-0.2e1 * Rp);
+		t143 = t140 * t26;
+		_C2 = del_rho * kn * (t77 + t128) / (double) (t130 + 4 * t7) / (t135 - t85 * t137 - 0.2e1 * t82 * t140 + 0.2e1 * t82 * t143 + 0.2e1 * t85 * t143 - t85 - 0.2e1 * t135 * t140 + t135 * t137) / 0.2e1;
+		
+		t2 = R * Rp;
+		t3 = B * B;
+		t4 = sin(R);
+		t7 = exp(-B - Rp);
+		t11 = t4 * R;
+		t15 = exp(-B - 0.3e1 * Rp);
+		t19 = Rp * Rp;
+		t20 = t19 * B;
+		t23 = R * R;
+		t24 = t3 * t23;
+		t26 = exp(-0.2e1 * Rp);
+		t28 = 0.2e1 * t24 * t26;
+		t29 = t26 * Rp;
+		t30 = t3 * B;
+		t33 = t19 * Rp;
+		t34 = t26 * t33;
+		t36 = t3 * t19;
+		t38 = 0.2e1 * t36 * t26;
+		t40 = t26 * t23;
+		t41 = Rp * B;
+		t42 = 0.2e1 * R;
+		t43 = cos(t42);
+		t49 = cos(R);
+		t50 = t49 * t23;
+		t58 = t4 * t7;
+		t60 = t23 * R;
+		t63 = t23 * t19;
+		t64 = t26 * t43;
+		t66 = 0.2e1 * t63 * t64;
+		t67 = 0.5e1 * t2 * t3 * t4 * t7 + 0.5e1 * t11 * t3 * Rp * t15 - t11 * t20 * t15 + t28 + 0.3e1 * t29 * t30 - t34 * B + t38 - 0.2e1 * t24 + t40 * t41 * t43 - 0.3e1 * t29 * t30 * t43 - 0.2e1 * t50 * t3 * t15 + 0.2e1 * t50 * t3 * t7 - R * t33 * t58 + t60 * Rp * t58 - t66;
+		t69 = 0.2e1 * t36 * t64;
+		t70 = t4 * t60;
+		t76 = sin(t42);
+		t108 = -t69 + t70 * B * t7 + t70 * Rp * t15 + t26 * R * t33 * t76 - t70 * B * t15 - t26 * t60 * Rp * t76 - t40 * t41 - t11 * t33 * t15 + t34 * B * t43 + 0.2e1 * t50 * t19 * t15 - 0.2e1 * t50 * t19 * t7 + 0.3e1 * t11 * t30 * t7 - 0.3e1 * t11 * t30 * t15 + t11 * t20 * t7 + 0.2e1 * t63 - 0.5e1 * t26 * t3 * t2 * t76;
+		t110 = kn * kn;
+		t116 = exp(-0.4e1 * Rp);
+		_C3 = -del_rho * kn * (t67 + t108) / (t110 + 0.4e1 * t3) / (t24 - t63 * t116 - t38 + t69 + t66 - t63 - t28 + t24 * t116) / 0.2e1;
+		
+		t2 = ((double) B * (double) B);
+		t3 = ((double) t2 * (double) B);
+		t6 = ((double) Rp * (double) Rp);
+		t10 = exp(-(double) (2 * Rp));
+		t11 = (double) R * (double) R;
+		t12 = t11 * (double) R;
+		t13 = t10 * t12;
+		t15 = R * Rp;
+		t18 = t10 * (double) R;
+		t19 = (double) t6 * (double) B;
+		t21 = cos((double) R);
+		t24 = exp((double) (-B - Rp));
+		t28 = t12 * (double) Rp;
+		t29 = t21 * t24;
+		t33 = t6 * Rp;
+		t34 = 2 * R;
+		t35 = cos((double) t34);
+		t38 = t12 * t21;
+		t41 = exp((double) (-B - 3 * Rp));
+		t44 = (double) B * t24;
+		t48 = (double) R * t21;
+		t52 = sin((double) t34);
+		t53 = (double) t6 * t52;
+		t59 = sin((double) R);
+		t60 = t11 * t59;
+		t70 = (double) (3 * t3 * R) + (double) (R * t6 * B) - t13 * (double) B - (double) (5 * t15 * t2) - t18 * t19 + 0.5e1 * (double) t15 * (double) t2 * t21 * t24 + t28 * t29 - 0.3e1 * t18 * (double) t3 - t18 * (double) t33 * t35 - t38 * (double) Rp * t41 - t38 * t44 + t38 * (double) B * t41 - t48 * t19 * t24 - 0.2e1 * t10 * (double) t2 * t53 - 0.3e1 * t48 * (double) t3 * t24 - 0.2e1 * t60 * (double) t2 * t41 - 0.2e1 * t59 * (double) t33 * t44 + 0.2e1 * t60 * (double) t2 * t24;
+		t84 = (double) t6 * t24;
+		t92 = t10 * t11;
+		t95 = R * t33;
+		t105 = Rp * t2;
+		t109 = Rp * B;
+		t119 = 0.2e1 * t60 * (double) t6 * t41 + 0.3e1 * t48 * (double) t3 * t41 - 0.3e1 * t10 * (double) t3 * (double) Rp * t52 + t13 * (double) Rp * t35 + 0.4e1 * (double) t2 * t59 * t84 + t48 * (double) t33 * t41 + t10 * (double) t33 * (double) B * t52 - 0.2e1 * t92 * t53 - (double) t95 * t29 + 0.2e1 * t60 * t84 + 0.6e1 * t59 * (double) t3 * (double) Rp * t24 + t48 * t19 * t41 + 0.5e1 * t18 * (double) t105 * t35 + t92 * (double) t109 * t52 - 0.5e1 * t48 * (double) t105 * t41 - 0.2e1 * t60 * (double) t109 * t24 + t12 * (double) B + (double) t95 - t28;
+		t121 = (kn * kn);
+		t126 = t11 * (double) t2;
+		t127 = t11 * (double) t6;
+		t129 = exp(-(double) (4 * Rp));
+		t131 = t2 * t6;
+		t134 = t10 * t35;
+		_C4 = -del_rho * kn * (t70 + t119) / (double) (t121 + 4 * t2) / (t126 - t127 * t129 - 0.2e1 * (double) t131 * t10 + 0.2e1 * (double) t131 * t134 + 0.2e1 * t127 * t134 - t127 - 0.2e1 * t126 * t10 + t126 * t129) / 0.2e1;
+		
+		/*******************************************/
+		/*       calculate the velocities etc      */
+		/*******************************************/
+		
+		
+		t1 = (kn * kn);
+		t2 = (B * B);
+		t8 = exp(B * z);
+		t9 = t8 * t8;
+		t14 = exp(U * (z - 0.1e1));
+		t15 = 0.1e1 / kn;
+		t17 = R * z;
+		t18 = cos(t17);
+		t20 = sin(t17);
+		t25 = exp(-VV * z);
+		u1 = -0.1e1 / (double) (t1 + 4 * t2) * del_rho / t9 + t14 * t15 * (_C1 * t18 + _C2 * t20) + t25 * t15 * (_C3 * t18 + _C4 * t20);
+		
+		t3 = exp((double) (U * (z - 1)));
+		t4 = R * z;
+		t5 = sin((double) t4);
+		t6 = t5 * (double) R;
+		t7 = cos((double) t4);
+		t11 = (kn * kn);
+		t12 = 0.1e1 / t11;
+		t16 = t7 * (double) R;
+		t22 = exp(-(double) (VV * z));
+		t33 = ((double) B * (double) B);
+		t39 = exp((double) (B * z));
+		t40 = t39 * t39;
+		u2 = -t3 * (-t6 + (double) U * t7) * _C1 * t12 - t3 * ((double) U * t5 + t16) * _C2 * t12 + t22 * (t6 + (double) VV * t7) * _C3 * t12 - t22 * (t16 - (double) VV * t5) * _C4 * t12 - 0.2e1 / (double) (t11 + 4 * t33) * del_rho / t40 * (double) B / kn;
+		
+		t5 = exp((double) (2 * B * z + U * z - U));
+		t6 = R * z;
+		t7 = sin((double) t6);
+		t8 = t7 * (double) R;
+		t9 = kn * kn;
+		t11 = 0.3e1 * t8 * t9;
+		t12 = cos((double) t6);
+		t13 = (double) U * t12;
+		t16 = U * U;
+		t17 = B * t16;
+		t20 = (double) B * t12;
+		t21 = R * R;
+		t23 = 0.2e1 * t20 * (double) t21;
+		t24 = B * U;
+		t28 = 0.2e1 * t20 * t9;
+		t29 = t16 * U;
+		t36 = t21 * R;
+		t37 = t7 * (double) t36;
+		t41 = 0.1e1 / t9 / kn;
+		t44 = (double) U * t7;
+		t47 = t12 * (double) R;
+		t49 = 0.3e1 * t47 * t9;
+		t50 = (double) B * t7;
+		t52 = 0.2e1 * t50 * (double) t21;
+		t58 = 0.2e1 * t50 * t9;
+		t65 = t12 * (double) t36;
+		t73 = exp((double) (z * (2 * B - VV)));
+		t74 = (double) VV * t12;
+		t77 = VV * VV;
+		t78 = B * t77;
+		t81 = B * VV;
+		t84 = t77 * VV;
+		t95 = (double) VV * t7;
+		t112 = B * B;
+		u3 = t5 * (-t11 + 0.3e1 * t13 * t9 - 0.2e1 * (double) t17 * t12 + t23 + 0.4e1 * (double) t24 * t8 - t28 - (double) t29 * t12 + 0.3e1 * t13 * (double) t21 + 0.3e1 * (double) t16 * t7 * (double) R - t37) * _C1 * t41 + t5 * (0.3e1 * t44 * t9 + t49 + t52 - 0.2e1 * (double) t17 * t7 - 0.4e1 * (double) t24 * t47 - t58 + 0.3e1 * t44 * (double) t21 - (double) t29 * t7 - 0.3e1 * (double) t16 * t12 * (double) R + t65) * _C2 * t41 + t73 * (-t11 - 0.3e1 * t74 * t9 - 0.2e1 * (double) t78 * t12 + t23 - 0.4e1 * (double) t81 * t8 - t28 + (double) t84 * t12 - 0.3e1 * t74 * (double) t21 + 0.3e1 * (double) t77 * t7 * (double) R - t37) * _C3 * t41 + t73 * (t49 - 0.3e1 * t95 * t9 - 0.2e1 * (double) t78 * t7 + t52 + 0.4e1 * (double) t81 * t47 - t58 + (double) t84 * t7 - 0.3e1 * t95 * (double) t21 - 0.3e1 * (double) t77 * t12 * (double) R + t65) * _C4 * t41 + 0.8e1 / (t9 + (double) (4 * t112)) * del_rho * (double) B;
+		
+		t5 = exp((double) (2 * B * z + U * z - U));
+		t6 = U * U;
+		t7 = R * z;
+		t8 = cos((double) t7);
+		t10 = R * R;
+		t11 = t8 * (double) t10;
+		t12 = sin((double) t7);
+		t16 = kn * kn;
+		t17 = t8 * t16;
+		t20 = 0.1e1 / t16;
+		t23 = t12 * (double) t10;
+		t28 = t12 * t16;
+		t36 = exp((double) (z * (2 * B - VV)));
+		t37 = VV * VV;
+		u4 = t5 * (-(double) t6 * t8 + t11 + 0.2e1 * (double) U * t12 * (double) R - t17) * _C1 * t20 - t5 * (-t23 + (double) t6 * t12 + 0.2e1 * (double) U * t8 * (double) R + t28) * _C2 * t20 + t36 * (-(double) t37 * t8 + t11 - 0.2e1 * (double) VV * t12 * (double) R - t17) * _C3 * t20 + t36 * (-(double) t37 * t12 + t23 + 0.2e1 * (double) VV * t8 * (double) R - t28) * _C4 * t20 + del_rho / kn;
+		
+		
+		
+		pp = (double)-(u3 + 2.0*n*M_PI*exp(2.0*B*z)*u2)*cos(n*M_PI*x); /* pressure */
+		
+		txx = (double)(u3 + 4*exp(2.0*B*z)*n*M_PI*u2)*cos(n*M_PI*x); /* xx stress */	    
+		sum5 += pp;
+		sum6 += txx;
+		
+		u1 *= cos(n*M_PI*x); /* z velocity */
+		sum1 += u1;
+		u2 *= sin(n*M_PI*x); /* x velocity */
+		sum2 += u2;
+		u3 *= cos(n*M_PI*x); /* zz stress */
+		sum3 += u3;
+		u4 *= sin(n*M_PI*x); /* zx stress */
+		sum4 += u4;
+		
+		rho = del_rho* cos(n*M_PI*x); /* density */
+		sum7 += rho;
+	}/* n */
+	
+	/* include terms for n=0 now */
+	del_rho = sigma*xc;
+	rho = del_rho; /* density */
+	sum7 += rho;
+	
+	u3 = del_rho*(z-0.5); /* zz stress */
+	sum3 += u3;
+	
+	txx = u3; /* xx stress */
+	pp = -u3; /* pressure */
+	sum5 += pp;
+	sum6 += txx;
+	
+	
+	mag=sqrt(sum1*sum1+sum2*sum2);
+	//printf("%0.7g %0.7g %0.7g %0.7g %0.7g %0.7g\n",x,y,z,sum3,sum2,sum1);
+	//printf("%0.7g %0.7g %0.7g\n%0.7g %0.7g %0.7g\n\n\n",x,y,z,x+sum3,y+sum2,z+sum1);
+	/*printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7);*/
+	
+	/* Output */
+	if( vel != NULL ) {
+		vel[0] = sum2;
+		vel[1] = sum1;
+	}
+	if( presssure != NULL ) {
+		(*presssure) = sum5;
+	}
+	if( total_stress != NULL ) {
+		total_stress[0] = sum6;
+		total_stress[1] = sum3;
+		total_stress[2] = sum4;
+	}
+	if( strain_rate != NULL ) {
+		/* sigma = tau - p, tau = sigma + p, tau[] = 2*eta*strain_rate[] */
+		Z = exp(2.0*B*z);
+		strain_rate[0] = (sum6+sum5)/(2.0*Z);
+		strain_rate[1] = (sum3+sum5)/(2.0*Z);
+		strain_rate[2] = (sum4)/(2.0*Z);
+	}
+	/* Value checks, could be cleaned up if needed. Julian Giordani 9-Oct-2006*/
+        if( fabs( sum5 - ( -0.5*(sum6+sum3) ) ) > 1e-5 ) {
+                assert(0);
+        }
+	
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solIA/Analytic_solIA.c
--- a/SysTest/AnalyticPlugins/Velic_solIA/Analytic_solIA.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,160 +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:
-*+		Mirko Velic
-*+		Julian Giordani
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Patrick Sunter
-** $Id: solIA.c 636 2006-09-08 03:07:06Z JulianGiordani $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include "Analytic_solIA.h"
-
-const Type Velic_solIA_Type = "Underworld_Velic_solIA";
-
-void Velic_solIA_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
-	Velic_solIA* self = (Velic_solIA*) analyticSolution;
-	
-	_Velic_solIA( coord, self->sigma, self->B, self->dx, self->x0, NULL, pressure, NULL, NULL );
-}
-
-void Velic_solIA_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
-	Velic_solIA* self = (Velic_solIA*) analyticSolution;
-	
-	_Velic_solIA( coord, self->sigma, self->B, self->dx, self->x0, velocity, NULL, NULL, NULL );
-}
-
-void Velic_solIA_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
-	Velic_solIA* self = (Velic_solIA*) analyticSolution;
-	
-	_Velic_solIA( coord, self->sigma, self->B, self->dx, self->x0, NULL, NULL, stress, NULL );
-}
-
-
-void Velic_solIA_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
-	Velic_solIA* self = (Velic_solIA*) analyticSolution;
-	
-	_Velic_solIA( coord, self->sigma, self->B, self->dx, self->x0, NULL, NULL, NULL, strainRate );
-}
-
-void _Velic_solIA_Init( Velic_solIA* self, double sigma, double B, double dx, double x0 ) {
-	//TODO	Bool                     correctInput = True;
-	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
-        self->_getAnalyticVelocity    = Velic_solIA_VelocityFunction;
-	self->_getAnalyticPressure    = Velic_solIA_PressureFunction;
-	self->_getAnalyticTotalStress = Velic_solIA_StressFunction;
-	self->_getAnalyticStrainRate  = Velic_solIA_StrainRateFunction;
-
-	self->sigma = sigma;
-	self->B = B;
-	self->dx = dx;
-	self->x0 = x0;
-}
-
-void _Velic_solIA_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
-	Velic_solIA* self = (Velic_solIA*) analyticSolution;
-	FeVariable*              velocityField;
-	FeVariable*              pressureField;
-	FeVariable*              stressField;
-	FeVariable*              strainRateField;
-	FeVariable*              recoveredStrainRateField;
-	FeVariable*              recoveredStressField;
-	double                   sigma, B, dx, x0, startX, endX, twiceB;
-
-	/* Construct Parent */
-	_AnalyticSolution_AssignFromXML( self, cf, data );
-
-	/* Create Analytic Fields */
-	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solIA_VelocityFunction );
-
-	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solIA_PressureFunction );
-
-	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False, data );
-	if ( stressField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solIA_StressFunction );
-
-	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
-	if ( strainRateField   ) {
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solIA_StrainRateFunction );
-	}
-
-	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
-	if ( recoveredStrainRateField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solIA_StrainRateFunction );
-
-	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
-	if ( recoveredStressField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solIA_StressFunction );
-	
-	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solIA_sigma", 1.0  );
-	twiceB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solIA_twiceB", 2.0  );
-	B = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solIA_B", 0.5 * twiceB  );
-
-	startX = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solIA_startX", 0.4  );
-	endX = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solIA_endX", 0.3 );
-	dx = endX - startX;
-	x0 = 0.5*(startX + endX );
-
-	_Velic_solIA_Init( self, sigma, B, dx, x0 );
-}
-
-void* _Velic_solIA_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Velic_solIA);
-	Type                                                      type = Velic_solIA_Type;
-	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
-	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
-	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solIA_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Velic_solIA_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _AnalyticSolution_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 Underworld_Velic_solIA_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Velic_solIA_Type, (Name)"0", _Velic_solIA_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solIA/Analytic_solIA.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solIA/Analytic_solIA.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,160 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Mirko Velic
+*+		Julian Giordani
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Patrick Sunter
+** $Id: solIA.c 636 2006-09-08 03:07:06Z JulianGiordani $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include "Analytic_solIA.h"
+
+const Type Velic_solIA_Type = "Underworld_Velic_solIA";
+
+void Velic_solIA_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
+	Velic_solIA* self = (Velic_solIA*) analyticSolution;
+	
+	_Velic_solIA( coord, self->sigma, self->B, self->dx, self->x0, NULL, pressure, NULL, NULL );
+}
+
+void Velic_solIA_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
+	Velic_solIA* self = (Velic_solIA*) analyticSolution;
+	
+	_Velic_solIA( coord, self->sigma, self->B, self->dx, self->x0, velocity, NULL, NULL, NULL );
+}
+
+void Velic_solIA_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
+	Velic_solIA* self = (Velic_solIA*) analyticSolution;
+	
+	_Velic_solIA( coord, self->sigma, self->B, self->dx, self->x0, NULL, NULL, stress, NULL );
+}
+
+
+void Velic_solIA_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
+	Velic_solIA* self = (Velic_solIA*) analyticSolution;
+	
+	_Velic_solIA( coord, self->sigma, self->B, self->dx, self->x0, NULL, NULL, NULL, strainRate );
+}
+
+void _Velic_solIA_Init( Velic_solIA* self, double sigma, double B, double dx, double x0 ) {
+	//TODO	Bool                     correctInput = True;
+	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
+        self->_getAnalyticVelocity    = Velic_solIA_VelocityFunction;
+	self->_getAnalyticPressure    = Velic_solIA_PressureFunction;
+	self->_getAnalyticTotalStress = Velic_solIA_StressFunction;
+	self->_getAnalyticStrainRate  = Velic_solIA_StrainRateFunction;
+
+	self->sigma = sigma;
+	self->B = B;
+	self->dx = dx;
+	self->x0 = x0;
+}
+
+void _Velic_solIA_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
+	Velic_solIA* self = (Velic_solIA*) analyticSolution;
+	FeVariable*              velocityField;
+	FeVariable*              pressureField;
+	FeVariable*              stressField;
+	FeVariable*              strainRateField;
+	FeVariable*              recoveredStrainRateField;
+	FeVariable*              recoveredStressField;
+	double                   sigma, B, dx, x0, startX, endX, twiceB;
+
+	/* Construct Parent */
+	_AnalyticSolution_AssignFromXML( self, cf, data );
+
+	/* Create Analytic Fields */
+	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solIA_VelocityFunction );
+
+	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solIA_PressureFunction );
+
+	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False, data );
+	if ( stressField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solIA_StressFunction );
+
+	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
+	if ( strainRateField   ) {
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solIA_StrainRateFunction );
+	}
+
+	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
+	if ( recoveredStrainRateField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solIA_StrainRateFunction );
+
+	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
+	if ( recoveredStressField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solIA_StressFunction );
+	
+	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solIA_sigma", 1.0  );
+	twiceB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solIA_twiceB", 2.0  );
+	B = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solIA_B", 0.5 * twiceB  );
+
+	startX = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solIA_startX", 0.4  );
+	endX = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solIA_endX", 0.3 );
+	dx = endX - startX;
+	x0 = 0.5*(startX + endX );
+
+	_Velic_solIA_Init( self, sigma, B, dx, x0 );
+}
+
+void* _Velic_solIA_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Velic_solIA);
+	Type                                                      type = Velic_solIA_Type;
+	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
+	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
+	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solIA_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Velic_solIA_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _AnalyticSolution_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 Underworld_Velic_solIA_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Velic_solIA_Type, (Name)"0", _Velic_solIA_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solIA/solIA.c
--- a/SysTest/AnalyticPlugins/Velic_solIA/solIA.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,436 +0,0 @@
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-
-void _Velic_solIA( 
-		double pos[],
-		double _sigma, double _B, 
-		double _dx, double _x_0,
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] );
-
-
-int main( int argc, char **argv )
-{
-	int i,j;
-	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
-	double x,z;
-	
-	for (i=0;i<101;i++){
-		for(j=0;j<101;j++){
-			x = i/100.0;
-			z = j/100.0;
-			
-			pos[0] = x;
-			pos[1] = z;
-			_Velic_solIA(
-					pos,
-					1.0, 1.0,
-					0.4, 0.3,
-					vel, &pressure, total_stress, strain_rate );
-			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
-					pos[0],pos[1],
-					vel[0],vel[1], pressure, 
-					total_stress[0], total_stress[1], total_stress[2], 
-					strain_rate[0], strain_rate[1], strain_rate[2] );
-		}
-		printf("\n");
-	}
-	
-	return 0;
-}
-
-
-void _Velic_solIA( 
-		double pos[],
-		double _sigma, double _B, /* density, viscosity parameter */
-		double _dx, double _x_0, /* width of dense column, centre of dense column */
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] )
-{
-	double Z;
-	double u1,u2,u3,u4,pp,txx;
-	double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,x,z;
-	double sigma,dx;
-	double del_rho;
-	int n;
-	double kn;
-	double _C1,_C2,_C3,_C4;
-	double B, Rp, R, U, VV;
-	double x0,rho,a,b,r;
-	
-	double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
-	double t11,t12,t13,t14,t15,t16,t17,t18,t19,t20;
-	double t21,t22,t23,t24,t25,t26,t27,t28,t29,t30;
-	double t31,t32,t33,t34,t35,t36,t37,t38,t39,t40;
-	double t41,t42,t43,t44,t45,t46,t47,t48,t49,t50;
-	double t51,t52,t53,t57,t58,t59,t60,t61,t62,t63;
-	double t64,t65,t66,t67,t69,t70,t72,t73,t74,t75;
-	double t76,t77,t78,t81,t82,t84,t85,t88,t89,t91;
-	double t92,t95,t105,t106,t108,t109,t110,t111,t112,t116;
-	double t117,t119,t120,t121,t123,t126,t127,t128,t129,t130;
-	double t131,t134,t135,t137,t140,t143;
-	
-	
-	
-	/*************************************************************************/
-	/*************************************************************************/
-	/* "background" fluid has density of zero */
-	x0 = _x_0;  /* centre of dense column */
-	dx = _dx;  /* total width of dense column */
-	sigma = _sigma; /* density parameter */
-	B = _B; /* viscosity parameter */
-	/* viscosity = exp(2.0*B*z) */
-	/*************************************************************************/
-	/*************************************************************************/
-	
-	x = pos[0];
-	z = pos[1];
-	
-	sum1=0.0;
-	sum2=0.0;
-	sum3=0.0;
-	sum4=0.0;
-	sum5=0.0;
-	sum6=0.0;
-	sum7=0.0;
-	
-	for(n=1;n<55;n++){
-		kn = (double) n*M_PI;
-		
-		a = B*B + kn*kn;
-		b = 2.0*kn*B;
-		r = sqrt(a*a + b*b);
-		Rp = sqrt( (r+a)/2.0 );
-		R  = sqrt( (r-a)/2.0 );
-		U  = Rp - B;
-		VV = Rp + B;
-		
-		/*******************************************/
-		/*            calculate del_rho            */
-		/*******************************************/
-		del_rho = 4.0*sigma*cos(n*M_PI*x0)*sin(n*M_PI*dx/2.0)/n/M_PI;
-		/* we can have any del_rho we like here as long as it is independent of z */
-		
-		
-		/*******************************************/
-		/*         calculate the constants         */
-		/*******************************************/
-		
-		
-		t2 = sin(R);
-		t3 = t2 * R;
-		t4 = Rp * Rp;
-		t6 = (-(double) B - Rp);
-		t8 = exp((double) (2 * t6));
-		t11 = R * R;
-		t12 = t11 * Rp;
-		t13 = 0.2e1 * R;
-		t14 = cos(t13);
-		t16 = exp((double) t6);
-		t19 = (double) B * (double) B;
-		t25 = exp(-(double) (2 * B));
-		t26 = t25 * t2;
-		t31 = t11 * t19;
-		t34 = exp(-(double) B - 0.3e1 * Rp);
-		t37 = t19 * (double) B;
-		t38 = t37 * Rp;
-		t41 = t11 * t4;
-		t46 = t4 * Rp;
-		t47 = t46 * (double) B;
-		t49 = t19 * t4;
-		t53 = sin(t13);
-		t61 = cos(R);
-		t62 = t25 * t61;
-		t67 = t14 * t16;
-		t70 = -t3 * t4 * (double) B * t8 + t12 * (double) B * t14 * t16 + 0.5e1 * t3 * t19 * Rp * t8 + 0.5e1 * t26 * R * t19 * Rp + 0.2e1 * t31 * t34 + 0.3e1 * t38 * t16 - 0.2e1 * t41 * t34 - 0.2e1 * t31 * t16 - t47 * t16 - 0.2e1 * t49 * t16 - 0.5e1 * R * Rp * t19 * t53 * t16 + t26 * R * t4 * (double) B + 0.2e1 * t62 * t31 - t12 * (double) B * t16 - 0.3e1 * t38 * t67;
-		t72 = t11 * R;
-		t75 = t61 * t11;
-		t81 = t2 * t72;
-		t88 = R * t46;
-		t89 = t53 * t16;
-		t91 = t72 * Rp;
-		t109 = t47 * t67 + t26 * t72 * (double) B + 0.2e1 * t75 * t4 * t8 + 0.2e1 * t41 * t67 - t81 * (double) B * t8 + 0.2e1 * t49 * t67 + t81 * Rp * t8 + t88 * t89 + t26 * t91 - 0.2e1 * t75 * t19 * t8 - t91 * t89 + 0.3e1 * t25 * t37 * t3 - 0.3e1 * t37 * R * t2 * t8 - t3 * t46 * t8 - 0.2e1 * t62 * t41 - t26 * t88;
-		t111 = kn * kn;
-		t117 = exp(-0.4e1 * Rp);
-		t120 = exp(-0.2e1 * Rp);
-		t123 = t120 * t14;
-		_C1 = del_rho * kn * (t70 + t109) / (t111 + 0.4e1 * t19) / (t31 - t41 * t117 - 0.2e1 * t49 * t120 + 0.2e1 * t49 * t123 + 0.2e1 * t41 * t123 - t41 - 0.2e1 * t31 * t120 + t31 * t117) / 0.2e1;
-		
-		t3 = exp(-(double) (2 * B));
-		t4 = t3 * R;
-		t5 = cos(R);
-		t6 = t5 * Rp;
-		t7 = B * B;
-		t11 = Rp * Rp;
-		t12 = t11 * R;
-		t13 = -(double) B - Rp;
-		t14 = exp(t13);
-		t17 = t11 * Rp;
-		t19 = 0.2e1 * R;
-		t20 = sin(t19);
-		t21 = t20 * t14;
-		t23 = R * R;
-		t24 = t23 * R;
-		t25 = t24 * Rp;
-		t26 = cos(t19);
-		t27 = t26 * t14;
-		t29 = t24 * t5;
-		t31 = exp(0.2e1 * t13);
-		t32 = (double) B * t31;
-		t34 = sin(R);
-		t35 = t23 * t34;
-		t36 = t11 * t31;
-		t39 = t7 * B;
-		t45 = exp(-(double) B - 0.3e1 * Rp);
-		t51 = R * t5;
-		t57 = t34 * (double) t7;
-		t60 = t3 * t24;
-		t62 = t3 * t23;
-		t74 = Rp * t31;
-		t77 = -0.5e1 * t4 * t6 * (double) t7 + t12 * (double) B * t14 + t17 * (double) B * t21 + t25 * t27 + t29 * t32 - 0.2e1 * t35 * t36 - 0.3e1 * t4 * t5 * (double) t39 - t12 * (double) B * t45 - 0.2e1 * t35 * (double) t7 * t31 + 0.3e1 * t51 * (double) t39 * t31 - t51 * t17 * t31 - 0.4e1 * t57 * t36 - t60 * t6 - 0.2e1 * t62 * t34 * t11 - t60 * t5 * (double) B + 0.2e1 * t62 * t57 - 0.2e1 * t34 * t17 * t32 + 0.6e1 * t34 * (double) t39 * t74;
-		t78 = R * Rp;
-		t82 = (double) t7 * t11;
-		t85 = t23 * t11;
-		t106 = R * t17;
-		t108 = R * (double) t39;
-		t111 = t24 * (double) B;
-		t128 = -0.5e1 * t78 * (double) t7 * t45 + 0.2e1 * t82 * t21 + 0.2e1 * t85 * t21 - 0.3e1 * (double) t39 * Rp * t21 - t25 * t45 + t51 * t11 * (double) B * t31 + t23 * Rp * (double) B * t20 * t14 + 0.5e1 * t51 * Rp * (double) t7 * t31 + t4 * t5 * t17 + t29 * t74 - t106 * t27 - 0.3e1 * t108 * t45 + t111 * t14 + t106 * t45 - t111 * t45 + 0.3e1 * t108 * t14 + 0.5e1 * t78 * (double) t7 * t26 * t14 - t4 * t5 * t11 * (double) B - 0.2e1 * t35 * Rp * (double) B * t31;
-		t130 = (kn * kn);
-		t135 = t23 * (double) t7;
-		t137 = exp(-0.4e1 * Rp);
-		t140 = exp(-0.2e1 * Rp);
-		t143 = t140 * t26;
-		_C2 = del_rho * kn * (t77 + t128) / (double) (t130 + 4 * t7) / (t135 - t85 * t137 - 0.2e1 * t82 * t140 + 0.2e1 * t82 * t143 + 0.2e1 * t85 * t143 - t85 - 0.2e1 * t135 * t140 + t135 * t137) / 0.2e1;
-		
-		t2 = R * Rp;
-		t3 = B * B;
-		t4 = sin(R);
-		t7 = exp(-B - Rp);
-		t11 = t4 * R;
-		t15 = exp(-B - 0.3e1 * Rp);
-		t19 = Rp * Rp;
-		t20 = t19 * B;
-		t23 = R * R;
-		t24 = t3 * t23;
-		t26 = exp(-0.2e1 * Rp);
-		t28 = 0.2e1 * t24 * t26;
-		t29 = t26 * Rp;
-		t30 = t3 * B;
-		t33 = t19 * Rp;
-		t34 = t26 * t33;
-		t36 = t3 * t19;
-		t38 = 0.2e1 * t36 * t26;
-		t40 = t26 * t23;
-		t41 = Rp * B;
-		t42 = 0.2e1 * R;
-		t43 = cos(t42);
-		t49 = cos(R);
-		t50 = t49 * t23;
-		t58 = t4 * t7;
-		t60 = t23 * R;
-		t63 = t23 * t19;
-		t64 = t26 * t43;
-		t66 = 0.2e1 * t63 * t64;
-		t67 = 0.5e1 * t2 * t3 * t4 * t7 + 0.5e1 * t11 * t3 * Rp * t15 - t11 * t20 * t15 + t28 + 0.3e1 * t29 * t30 - t34 * B + t38 - 0.2e1 * t24 + t40 * t41 * t43 - 0.3e1 * t29 * t30 * t43 - 0.2e1 * t50 * t3 * t15 + 0.2e1 * t50 * t3 * t7 - R * t33 * t58 + t60 * Rp * t58 - t66;
-		t69 = 0.2e1 * t36 * t64;
-		t70 = t4 * t60;
-		t76 = sin(t42);
-		t108 = -t69 + t70 * B * t7 + t70 * Rp * t15 + t26 * R * t33 * t76 - t70 * B * t15 - t26 * t60 * Rp * t76 - t40 * t41 - t11 * t33 * t15 + t34 * B * t43 + 0.2e1 * t50 * t19 * t15 - 0.2e1 * t50 * t19 * t7 + 0.3e1 * t11 * t30 * t7 - 0.3e1 * t11 * t30 * t15 + t11 * t20 * t7 + 0.2e1 * t63 - 0.5e1 * t26 * t3 * t2 * t76;
-		t110 = kn * kn;
-		t116 = exp(-0.4e1 * Rp);
-		_C3 = -del_rho * kn * (t67 + t108) / (t110 + 0.4e1 * t3) / (t24 - t63 * t116 - t38 + t69 + t66 - t63 - t28 + t24 * t116) / 0.2e1;
-		
-		t2 = ((double) B * (double) B);
-		t3 = ((double) t2 * (double) B);
-		t6 = ((double) Rp * (double) Rp);
-		t10 = exp(-(double) (2 * Rp));
-		t11 = (double) R * (double) R;
-		t12 = t11 * (double) R;
-		t13 = t10 * t12;
-		t15 = R * Rp;
-		t18 = t10 * (double) R;
-		t19 = (double) t6 * (double) B;
-		t21 = cos((double) R);
-		t24 = exp((double) (-B - Rp));
-		t28 = t12 * (double) Rp;
-		t29 = t21 * t24;
-		t33 = t6 * Rp;
-		t34 = 2 * R;
-		t35 = cos((double) t34);
-		t38 = t12 * t21;
-		t41 = exp((double) (-B - 3 * Rp));
-		t44 = (double) B * t24;
-		t48 = (double) R * t21;
-		t52 = sin((double) t34);
-		t53 = (double) t6 * t52;
-		t59 = sin((double) R);
-		t60 = t11 * t59;
-		t70 = (double) (3 * t3 * R) + (double) (R * t6 * B) - t13 * (double) B - (double) (5 * t15 * t2) - t18 * t19 + 0.5e1 * (double) t15 * (double) t2 * t21 * t24 + t28 * t29 - 0.3e1 * t18 * (double) t3 - t18 * (double) t33 * t35 - t38 * (double) Rp * t41 - t38 * t44 + t38 * (double) B * t41 - t48 * t19 * t24 - 0.2e1 * t10 * (double) t2 * t53 - 0.3e1 * t48 * (double) t3 * t24 - 0.2e1 * t60 * (double) t2 * t41 - 0.2e1 * t59 * (double) t33 * t44 + 0.2e1 * t60 * (double) t2 * t24;
-		t84 = (double) t6 * t24;
-		t92 = t10 * t11;
-		t95 = R * t33;
-		t105 = Rp * t2;
-		t109 = Rp * B;
-		t119 = 0.2e1 * t60 * (double) t6 * t41 + 0.3e1 * t48 * (double) t3 * t41 - 0.3e1 * t10 * (double) t3 * (double) Rp * t52 + t13 * (double) Rp * t35 + 0.4e1 * (double) t2 * t59 * t84 + t48 * (double) t33 * t41 + t10 * (double) t33 * (double) B * t52 - 0.2e1 * t92 * t53 - (double) t95 * t29 + 0.2e1 * t60 * t84 + 0.6e1 * t59 * (double) t3 * (double) Rp * t24 + t48 * t19 * t41 + 0.5e1 * t18 * (double) t105 * t35 + t92 * (double) t109 * t52 - 0.5e1 * t48 * (double) t105 * t41 - 0.2e1 * t60 * (double) t109 * t24 + t12 * (double) B + (double) t95 - t28;
-		t121 = (kn * kn);
-		t126 = t11 * (double) t2;
-		t127 = t11 * (double) t6;
-		t129 = exp(-(double) (4 * Rp));
-		t131 = t2 * t6;
-		t134 = t10 * t35;
-		_C4 = -del_rho * kn * (t70 + t119) / (double) (t121 + 4 * t2) / (t126 - t127 * t129 - 0.2e1 * (double) t131 * t10 + 0.2e1 * (double) t131 * t134 + 0.2e1 * t127 * t134 - t127 - 0.2e1 * t126 * t10 + t126 * t129) / 0.2e1;
-		
-		/*******************************************/
-		/*       calculate the velocities etc      */
-		/*******************************************/
-		
-		
-		t1 = (kn * kn);
-		t2 = (B * B);
-		t8 = exp(B * z);
-		t9 = t8 * t8;
-		t14 = exp(U * (z - 0.1e1));
-		t15 = 0.1e1 / kn;
-		t17 = R * z;
-		t18 = cos(t17);
-		t20 = sin(t17);
-		t25 = exp(-VV * z);
-		u1 = -0.1e1 / (double) (t1 + 4 * t2) * del_rho / t9 + t14 * t15 * (_C1 * t18 + _C2 * t20) + t25 * t15 * (_C3 * t18 + _C4 * t20);
-		
-		t3 = exp((double) (U * (z - 1)));
-		t4 = R * z;
-		t5 = sin((double) t4);
-		t6 = t5 * (double) R;
-		t7 = cos((double) t4);
-		t11 = (kn * kn);
-		t12 = 0.1e1 / t11;
-		t16 = t7 * (double) R;
-		t22 = exp(-(double) (VV * z));
-		t33 = ((double) B * (double) B);
-		t39 = exp((double) (B * z));
-		t40 = t39 * t39;
-		u2 = -t3 * (-t6 + (double) U * t7) * _C1 * t12 - t3 * ((double) U * t5 + t16) * _C2 * t12 + t22 * (t6 + (double) VV * t7) * _C3 * t12 - t22 * (t16 - (double) VV * t5) * _C4 * t12 - 0.2e1 / (double) (t11 + 4 * t33) * del_rho / t40 * (double) B / kn;
-		
-		t5 = exp((double) (2 * B * z + U * z - U));
-		t6 = R * z;
-		t7 = sin((double) t6);
-		t8 = t7 * (double) R;
-		t9 = kn * kn;
-		t11 = 0.3e1 * t8 * t9;
-		t12 = cos((double) t6);
-		t13 = (double) U * t12;
-		t16 = U * U;
-		t17 = B * t16;
-		t20 = (double) B * t12;
-		t21 = R * R;
-		t23 = 0.2e1 * t20 * (double) t21;
-		t24 = B * U;
-		t28 = 0.2e1 * t20 * t9;
-		t29 = t16 * U;
-		t36 = t21 * R;
-		t37 = t7 * (double) t36;
-		t41 = 0.1e1 / t9 / kn;
-		t44 = (double) U * t7;
-		t47 = t12 * (double) R;
-		t49 = 0.3e1 * t47 * t9;
-		t50 = (double) B * t7;
-		t52 = 0.2e1 * t50 * (double) t21;
-		t58 = 0.2e1 * t50 * t9;
-		t65 = t12 * (double) t36;
-		t73 = exp((double) (z * (2 * B - VV)));
-		t74 = (double) VV * t12;
-		t77 = VV * VV;
-		t78 = B * t77;
-		t81 = B * VV;
-		t84 = t77 * VV;
-		t95 = (double) VV * t7;
-		t112 = B * B;
-		u3 = t5 * (-t11 + 0.3e1 * t13 * t9 - 0.2e1 * (double) t17 * t12 + t23 + 0.4e1 * (double) t24 * t8 - t28 - (double) t29 * t12 + 0.3e1 * t13 * (double) t21 + 0.3e1 * (double) t16 * t7 * (double) R - t37) * _C1 * t41 + t5 * (0.3e1 * t44 * t9 + t49 + t52 - 0.2e1 * (double) t17 * t7 - 0.4e1 * (double) t24 * t47 - t58 + 0.3e1 * t44 * (double) t21 - (double) t29 * t7 - 0.3e1 * (double) t16 * t12 * (double) R + t65) * _C2 * t41 + t73 * (-t11 - 0.3e1 * t74 * t9 - 0.2e1 * (double) t78 * t12 + t23 - 0.4e1 * (double) t81 * t8 - t28 + (double) t84 * t12 - 0.3e1 * t74 * (double) t21 + 0.3e1 * (double) t77 * t7 * (double) R - t37) * _C3 * t41 + t73 * (t49 - 0.3e1 * t95 * t9 - 0.2e1 * (double) t78 * t7 + t52 + 0.4e1 * (double) t81 * t47 - t58 + (double) t84 * t7 - 0.3e1 * t95 * (double) t21 - 0.3e1 * (double) t77 * t12 * (double) R + t65) * _C4 * t41 + 0.8e1 / (t9 + (double) (4 * t112)) * del_rho * (double) B;
-		
-		t5 = exp((double) (2 * B * z + U * z - U));
-		t6 = U * U;
-		t7 = R * z;
-		t8 = cos((double) t7);
-		t10 = R * R;
-		t11 = t8 * (double) t10;
-		t12 = sin((double) t7);
-		t16 = kn * kn;
-		t17 = t8 * t16;
-		t20 = 0.1e1 / t16;
-		t23 = t12 * (double) t10;
-		t28 = t12 * t16;
-		t36 = exp((double) (z * (2 * B - VV)));
-		t37 = VV * VV;
-		u4 = t5 * (-(double) t6 * t8 + t11 + 0.2e1 * (double) U * t12 * (double) R - t17) * _C1 * t20 - t5 * (-t23 + (double) t6 * t12 + 0.2e1 * (double) U * t8 * (double) R + t28) * _C2 * t20 + t36 * (-(double) t37 * t8 + t11 - 0.2e1 * (double) VV * t12 * (double) R - t17) * _C3 * t20 + t36 * (-(double) t37 * t12 + t23 + 0.2e1 * (double) VV * t8 * (double) R - t28) * _C4 * t20 + del_rho / kn;
-		
-		
-		
-		pp = (double)-(u3 + 2.0*n*M_PI*exp(2.0*B*z)*u2)*cos(n*M_PI*x); /* pressure */
-		
-		txx = (double)(u3 + 4*exp(2.0*B*z)*n*M_PI*u2)*cos(n*M_PI*x); /* xx stress */	    
-		sum5 += pp;
-		sum6 += txx;
-		
-		u1 *= cos(n*M_PI*x); /* z velocity */
-		sum1 += u1;
-		u2 *= sin(n*M_PI*x); /* x velocity */
-		sum2 += u2;
-		u3 *= cos(n*M_PI*x); /* zz stress */
-		sum3 += u3;
-		u4 *= sin(n*M_PI*x); /* zx stress */
-		sum4 += u4;
-		
-		rho = del_rho* cos(n*M_PI*x); /* density */
-		sum7 += rho;
-	}/* n */
-	
-	/* include terms for n=0 now */
-	del_rho = sigma*dx;
-	rho = del_rho; /* density */
-	sum7 += rho;
-	
-	u3 = del_rho*(z-0.5); /* zz stress */
-	sum3 += u3;
-	
-	txx = u3; /* xx stress */
-	pp = -u3; /* pressure */
-	sum5 += pp;
-	sum6 += txx;
-	
-	
-	mag=sqrt(sum1*sum1+sum2*sum2);
-	//printf("%0.7g %0.7g %0.7g %0.7g %0.7g %0.7g\n",x,y,z,sum3,sum2,sum1);
-	//printf("%0.7g %0.7g %0.7g\n%0.7g %0.7g %0.7g\n\n\n",x,y,z,x+sum3,y+sum2,z+sum1);
-	/*printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7);*/
-	
-	
-	/* Output */
-	if( vel != NULL ) {
-		vel[0] = sum2;
-		vel[1] = sum1;
-	}
-	if( presssure != NULL ) {
-		(*presssure) = sum5;
-	}
-	if( total_stress != NULL ) {
-		total_stress[0] = sum6;
-		total_stress[1] = sum3;
-		total_stress[2] = sum4;
-	}
-	if( strain_rate != NULL ) {
-		/* sigma = tau - p, tau = sigma + p, tau[] = 2*eta*strain_rate[] */
-		Z = exp(2.0*B*z);
-		strain_rate[0] = (sum6+sum5)/(2.0*Z);
-		strain_rate[1] = (sum3+sum5)/(2.0*Z);
-		strain_rate[2] = (sum4)/(2.0*Z);
-	}
-	/* Value checks, could be cleaned up if needed. Julian Giordani 9-Oct-2006*/
-        if( fabs( sum5 - ( -0.5*(sum6+sum3) ) ) > 1e-5 ) {
-                assert(0);
-        }
-	
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solIA/solIA.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solIA/solIA.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,436 @@
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+
+void _Velic_solIA( 
+		double pos[],
+		double _sigma, double _B, 
+		double _dx, double _x_0,
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] );
+
+
+int main( int argc, char **argv )
+{
+	int i,j;
+	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
+	double x,z;
+	
+	for (i=0;i<101;i++){
+		for(j=0;j<101;j++){
+			x = i/100.0;
+			z = j/100.0;
+			
+			pos[0] = x;
+			pos[1] = z;
+			_Velic_solIA(
+					pos,
+					1.0, 1.0,
+					0.4, 0.3,
+					vel, &pressure, total_stress, strain_rate );
+			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
+					pos[0],pos[1],
+					vel[0],vel[1], pressure, 
+					total_stress[0], total_stress[1], total_stress[2], 
+					strain_rate[0], strain_rate[1], strain_rate[2] );
+		}
+		printf("\n");
+	}
+	
+	return 0;
+}
+
+
+void _Velic_solIA( 
+		double pos[],
+		double _sigma, double _B, /* density, viscosity parameter */
+		double _dx, double _x_0, /* width of dense column, centre of dense column */
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] )
+{
+	double Z;
+	double u1,u2,u3,u4,pp,txx;
+	double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,x,z;
+	double sigma,dx;
+	double del_rho;
+	int n;
+	double kn;
+	double _C1,_C2,_C3,_C4;
+	double B, Rp, R, U, VV;
+	double x0,rho,a,b,r;
+	
+	double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
+	double t11,t12,t13,t14,t15,t16,t17,t18,t19,t20;
+	double t21,t22,t23,t24,t25,t26,t27,t28,t29,t30;
+	double t31,t32,t33,t34,t35,t36,t37,t38,t39,t40;
+	double t41,t42,t43,t44,t45,t46,t47,t48,t49,t50;
+	double t51,t52,t53,t57,t58,t59,t60,t61,t62,t63;
+	double t64,t65,t66,t67,t69,t70,t72,t73,t74,t75;
+	double t76,t77,t78,t81,t82,t84,t85,t88,t89,t91;
+	double t92,t95,t105,t106,t108,t109,t110,t111,t112,t116;
+	double t117,t119,t120,t121,t123,t126,t127,t128,t129,t130;
+	double t131,t134,t135,t137,t140,t143;
+	
+	
+	
+	/*************************************************************************/
+	/*************************************************************************/
+	/* "background" fluid has density of zero */
+	x0 = _x_0;  /* centre of dense column */
+	dx = _dx;  /* total width of dense column */
+	sigma = _sigma; /* density parameter */
+	B = _B; /* viscosity parameter */
+	/* viscosity = exp(2.0*B*z) */
+	/*************************************************************************/
+	/*************************************************************************/
+	
+	x = pos[0];
+	z = pos[1];
+	
+	sum1=0.0;
+	sum2=0.0;
+	sum3=0.0;
+	sum4=0.0;
+	sum5=0.0;
+	sum6=0.0;
+	sum7=0.0;
+	
+	for(n=1;n<55;n++){
+		kn = (double) n*M_PI;
+		
+		a = B*B + kn*kn;
+		b = 2.0*kn*B;
+		r = sqrt(a*a + b*b);
+		Rp = sqrt( (r+a)/2.0 );
+		R  = sqrt( (r-a)/2.0 );
+		U  = Rp - B;
+		VV = Rp + B;
+		
+		/*******************************************/
+		/*            calculate del_rho            */
+		/*******************************************/
+		del_rho = 4.0*sigma*cos(n*M_PI*x0)*sin(n*M_PI*dx/2.0)/n/M_PI;
+		/* we can have any del_rho we like here as long as it is independent of z */
+		
+		
+		/*******************************************/
+		/*         calculate the constants         */
+		/*******************************************/
+		
+		
+		t2 = sin(R);
+		t3 = t2 * R;
+		t4 = Rp * Rp;
+		t6 = (-(double) B - Rp);
+		t8 = exp((double) (2 * t6));
+		t11 = R * R;
+		t12 = t11 * Rp;
+		t13 = 0.2e1 * R;
+		t14 = cos(t13);
+		t16 = exp((double) t6);
+		t19 = (double) B * (double) B;
+		t25 = exp(-(double) (2 * B));
+		t26 = t25 * t2;
+		t31 = t11 * t19;
+		t34 = exp(-(double) B - 0.3e1 * Rp);
+		t37 = t19 * (double) B;
+		t38 = t37 * Rp;
+		t41 = t11 * t4;
+		t46 = t4 * Rp;
+		t47 = t46 * (double) B;
+		t49 = t19 * t4;
+		t53 = sin(t13);
+		t61 = cos(R);
+		t62 = t25 * t61;
+		t67 = t14 * t16;
+		t70 = -t3 * t4 * (double) B * t8 + t12 * (double) B * t14 * t16 + 0.5e1 * t3 * t19 * Rp * t8 + 0.5e1 * t26 * R * t19 * Rp + 0.2e1 * t31 * t34 + 0.3e1 * t38 * t16 - 0.2e1 * t41 * t34 - 0.2e1 * t31 * t16 - t47 * t16 - 0.2e1 * t49 * t16 - 0.5e1 * R * Rp * t19 * t53 * t16 + t26 * R * t4 * (double) B + 0.2e1 * t62 * t31 - t12 * (double) B * t16 - 0.3e1 * t38 * t67;
+		t72 = t11 * R;
+		t75 = t61 * t11;
+		t81 = t2 * t72;
+		t88 = R * t46;
+		t89 = t53 * t16;
+		t91 = t72 * Rp;
+		t109 = t47 * t67 + t26 * t72 * (double) B + 0.2e1 * t75 * t4 * t8 + 0.2e1 * t41 * t67 - t81 * (double) B * t8 + 0.2e1 * t49 * t67 + t81 * Rp * t8 + t88 * t89 + t26 * t91 - 0.2e1 * t75 * t19 * t8 - t91 * t89 + 0.3e1 * t25 * t37 * t3 - 0.3e1 * t37 * R * t2 * t8 - t3 * t46 * t8 - 0.2e1 * t62 * t41 - t26 * t88;
+		t111 = kn * kn;
+		t117 = exp(-0.4e1 * Rp);
+		t120 = exp(-0.2e1 * Rp);
+		t123 = t120 * t14;
+		_C1 = del_rho * kn * (t70 + t109) / (t111 + 0.4e1 * t19) / (t31 - t41 * t117 - 0.2e1 * t49 * t120 + 0.2e1 * t49 * t123 + 0.2e1 * t41 * t123 - t41 - 0.2e1 * t31 * t120 + t31 * t117) / 0.2e1;
+		
+		t3 = exp(-(double) (2 * B));
+		t4 = t3 * R;
+		t5 = cos(R);
+		t6 = t5 * Rp;
+		t7 = B * B;
+		t11 = Rp * Rp;
+		t12 = t11 * R;
+		t13 = -(double) B - Rp;
+		t14 = exp(t13);
+		t17 = t11 * Rp;
+		t19 = 0.2e1 * R;
+		t20 = sin(t19);
+		t21 = t20 * t14;
+		t23 = R * R;
+		t24 = t23 * R;
+		t25 = t24 * Rp;
+		t26 = cos(t19);
+		t27 = t26 * t14;
+		t29 = t24 * t5;
+		t31 = exp(0.2e1 * t13);
+		t32 = (double) B * t31;
+		t34 = sin(R);
+		t35 = t23 * t34;
+		t36 = t11 * t31;
+		t39 = t7 * B;
+		t45 = exp(-(double) B - 0.3e1 * Rp);
+		t51 = R * t5;
+		t57 = t34 * (double) t7;
+		t60 = t3 * t24;
+		t62 = t3 * t23;
+		t74 = Rp * t31;
+		t77 = -0.5e1 * t4 * t6 * (double) t7 + t12 * (double) B * t14 + t17 * (double) B * t21 + t25 * t27 + t29 * t32 - 0.2e1 * t35 * t36 - 0.3e1 * t4 * t5 * (double) t39 - t12 * (double) B * t45 - 0.2e1 * t35 * (double) t7 * t31 + 0.3e1 * t51 * (double) t39 * t31 - t51 * t17 * t31 - 0.4e1 * t57 * t36 - t60 * t6 - 0.2e1 * t62 * t34 * t11 - t60 * t5 * (double) B + 0.2e1 * t62 * t57 - 0.2e1 * t34 * t17 * t32 + 0.6e1 * t34 * (double) t39 * t74;
+		t78 = R * Rp;
+		t82 = (double) t7 * t11;
+		t85 = t23 * t11;
+		t106 = R * t17;
+		t108 = R * (double) t39;
+		t111 = t24 * (double) B;
+		t128 = -0.5e1 * t78 * (double) t7 * t45 + 0.2e1 * t82 * t21 + 0.2e1 * t85 * t21 - 0.3e1 * (double) t39 * Rp * t21 - t25 * t45 + t51 * t11 * (double) B * t31 + t23 * Rp * (double) B * t20 * t14 + 0.5e1 * t51 * Rp * (double) t7 * t31 + t4 * t5 * t17 + t29 * t74 - t106 * t27 - 0.3e1 * t108 * t45 + t111 * t14 + t106 * t45 - t111 * t45 + 0.3e1 * t108 * t14 + 0.5e1 * t78 * (double) t7 * t26 * t14 - t4 * t5 * t11 * (double) B - 0.2e1 * t35 * Rp * (double) B * t31;
+		t130 = (kn * kn);
+		t135 = t23 * (double) t7;
+		t137 = exp(-0.4e1 * Rp);
+		t140 = exp(-0.2e1 * Rp);
+		t143 = t140 * t26;
+		_C2 = del_rho * kn * (t77 + t128) / (double) (t130 + 4 * t7) / (t135 - t85 * t137 - 0.2e1 * t82 * t140 + 0.2e1 * t82 * t143 + 0.2e1 * t85 * t143 - t85 - 0.2e1 * t135 * t140 + t135 * t137) / 0.2e1;
+		
+		t2 = R * Rp;
+		t3 = B * B;
+		t4 = sin(R);
+		t7 = exp(-B - Rp);
+		t11 = t4 * R;
+		t15 = exp(-B - 0.3e1 * Rp);
+		t19 = Rp * Rp;
+		t20 = t19 * B;
+		t23 = R * R;
+		t24 = t3 * t23;
+		t26 = exp(-0.2e1 * Rp);
+		t28 = 0.2e1 * t24 * t26;
+		t29 = t26 * Rp;
+		t30 = t3 * B;
+		t33 = t19 * Rp;
+		t34 = t26 * t33;
+		t36 = t3 * t19;
+		t38 = 0.2e1 * t36 * t26;
+		t40 = t26 * t23;
+		t41 = Rp * B;
+		t42 = 0.2e1 * R;
+		t43 = cos(t42);
+		t49 = cos(R);
+		t50 = t49 * t23;
+		t58 = t4 * t7;
+		t60 = t23 * R;
+		t63 = t23 * t19;
+		t64 = t26 * t43;
+		t66 = 0.2e1 * t63 * t64;
+		t67 = 0.5e1 * t2 * t3 * t4 * t7 + 0.5e1 * t11 * t3 * Rp * t15 - t11 * t20 * t15 + t28 + 0.3e1 * t29 * t30 - t34 * B + t38 - 0.2e1 * t24 + t40 * t41 * t43 - 0.3e1 * t29 * t30 * t43 - 0.2e1 * t50 * t3 * t15 + 0.2e1 * t50 * t3 * t7 - R * t33 * t58 + t60 * Rp * t58 - t66;
+		t69 = 0.2e1 * t36 * t64;
+		t70 = t4 * t60;
+		t76 = sin(t42);
+		t108 = -t69 + t70 * B * t7 + t70 * Rp * t15 + t26 * R * t33 * t76 - t70 * B * t15 - t26 * t60 * Rp * t76 - t40 * t41 - t11 * t33 * t15 + t34 * B * t43 + 0.2e1 * t50 * t19 * t15 - 0.2e1 * t50 * t19 * t7 + 0.3e1 * t11 * t30 * t7 - 0.3e1 * t11 * t30 * t15 + t11 * t20 * t7 + 0.2e1 * t63 - 0.5e1 * t26 * t3 * t2 * t76;
+		t110 = kn * kn;
+		t116 = exp(-0.4e1 * Rp);
+		_C3 = -del_rho * kn * (t67 + t108) / (t110 + 0.4e1 * t3) / (t24 - t63 * t116 - t38 + t69 + t66 - t63 - t28 + t24 * t116) / 0.2e1;
+		
+		t2 = ((double) B * (double) B);
+		t3 = ((double) t2 * (double) B);
+		t6 = ((double) Rp * (double) Rp);
+		t10 = exp(-(double) (2 * Rp));
+		t11 = (double) R * (double) R;
+		t12 = t11 * (double) R;
+		t13 = t10 * t12;
+		t15 = R * Rp;
+		t18 = t10 * (double) R;
+		t19 = (double) t6 * (double) B;
+		t21 = cos((double) R);
+		t24 = exp((double) (-B - Rp));
+		t28 = t12 * (double) Rp;
+		t29 = t21 * t24;
+		t33 = t6 * Rp;
+		t34 = 2 * R;
+		t35 = cos((double) t34);
+		t38 = t12 * t21;
+		t41 = exp((double) (-B - 3 * Rp));
+		t44 = (double) B * t24;
+		t48 = (double) R * t21;
+		t52 = sin((double) t34);
+		t53 = (double) t6 * t52;
+		t59 = sin((double) R);
+		t60 = t11 * t59;
+		t70 = (double) (3 * t3 * R) + (double) (R * t6 * B) - t13 * (double) B - (double) (5 * t15 * t2) - t18 * t19 + 0.5e1 * (double) t15 * (double) t2 * t21 * t24 + t28 * t29 - 0.3e1 * t18 * (double) t3 - t18 * (double) t33 * t35 - t38 * (double) Rp * t41 - t38 * t44 + t38 * (double) B * t41 - t48 * t19 * t24 - 0.2e1 * t10 * (double) t2 * t53 - 0.3e1 * t48 * (double) t3 * t24 - 0.2e1 * t60 * (double) t2 * t41 - 0.2e1 * t59 * (double) t33 * t44 + 0.2e1 * t60 * (double) t2 * t24;
+		t84 = (double) t6 * t24;
+		t92 = t10 * t11;
+		t95 = R * t33;
+		t105 = Rp * t2;
+		t109 = Rp * B;
+		t119 = 0.2e1 * t60 * (double) t6 * t41 + 0.3e1 * t48 * (double) t3 * t41 - 0.3e1 * t10 * (double) t3 * (double) Rp * t52 + t13 * (double) Rp * t35 + 0.4e1 * (double) t2 * t59 * t84 + t48 * (double) t33 * t41 + t10 * (double) t33 * (double) B * t52 - 0.2e1 * t92 * t53 - (double) t95 * t29 + 0.2e1 * t60 * t84 + 0.6e1 * t59 * (double) t3 * (double) Rp * t24 + t48 * t19 * t41 + 0.5e1 * t18 * (double) t105 * t35 + t92 * (double) t109 * t52 - 0.5e1 * t48 * (double) t105 * t41 - 0.2e1 * t60 * (double) t109 * t24 + t12 * (double) B + (double) t95 - t28;
+		t121 = (kn * kn);
+		t126 = t11 * (double) t2;
+		t127 = t11 * (double) t6;
+		t129 = exp(-(double) (4 * Rp));
+		t131 = t2 * t6;
+		t134 = t10 * t35;
+		_C4 = -del_rho * kn * (t70 + t119) / (double) (t121 + 4 * t2) / (t126 - t127 * t129 - 0.2e1 * (double) t131 * t10 + 0.2e1 * (double) t131 * t134 + 0.2e1 * t127 * t134 - t127 - 0.2e1 * t126 * t10 + t126 * t129) / 0.2e1;
+		
+		/*******************************************/
+		/*       calculate the velocities etc      */
+		/*******************************************/
+		
+		
+		t1 = (kn * kn);
+		t2 = (B * B);
+		t8 = exp(B * z);
+		t9 = t8 * t8;
+		t14 = exp(U * (z - 0.1e1));
+		t15 = 0.1e1 / kn;
+		t17 = R * z;
+		t18 = cos(t17);
+		t20 = sin(t17);
+		t25 = exp(-VV * z);
+		u1 = -0.1e1 / (double) (t1 + 4 * t2) * del_rho / t9 + t14 * t15 * (_C1 * t18 + _C2 * t20) + t25 * t15 * (_C3 * t18 + _C4 * t20);
+		
+		t3 = exp((double) (U * (z - 1)));
+		t4 = R * z;
+		t5 = sin((double) t4);
+		t6 = t5 * (double) R;
+		t7 = cos((double) t4);
+		t11 = (kn * kn);
+		t12 = 0.1e1 / t11;
+		t16 = t7 * (double) R;
+		t22 = exp(-(double) (VV * z));
+		t33 = ((double) B * (double) B);
+		t39 = exp((double) (B * z));
+		t40 = t39 * t39;
+		u2 = -t3 * (-t6 + (double) U * t7) * _C1 * t12 - t3 * ((double) U * t5 + t16) * _C2 * t12 + t22 * (t6 + (double) VV * t7) * _C3 * t12 - t22 * (t16 - (double) VV * t5) * _C4 * t12 - 0.2e1 / (double) (t11 + 4 * t33) * del_rho / t40 * (double) B / kn;
+		
+		t5 = exp((double) (2 * B * z + U * z - U));
+		t6 = R * z;
+		t7 = sin((double) t6);
+		t8 = t7 * (double) R;
+		t9 = kn * kn;
+		t11 = 0.3e1 * t8 * t9;
+		t12 = cos((double) t6);
+		t13 = (double) U * t12;
+		t16 = U * U;
+		t17 = B * t16;
+		t20 = (double) B * t12;
+		t21 = R * R;
+		t23 = 0.2e1 * t20 * (double) t21;
+		t24 = B * U;
+		t28 = 0.2e1 * t20 * t9;
+		t29 = t16 * U;
+		t36 = t21 * R;
+		t37 = t7 * (double) t36;
+		t41 = 0.1e1 / t9 / kn;
+		t44 = (double) U * t7;
+		t47 = t12 * (double) R;
+		t49 = 0.3e1 * t47 * t9;
+		t50 = (double) B * t7;
+		t52 = 0.2e1 * t50 * (double) t21;
+		t58 = 0.2e1 * t50 * t9;
+		t65 = t12 * (double) t36;
+		t73 = exp((double) (z * (2 * B - VV)));
+		t74 = (double) VV * t12;
+		t77 = VV * VV;
+		t78 = B * t77;
+		t81 = B * VV;
+		t84 = t77 * VV;
+		t95 = (double) VV * t7;
+		t112 = B * B;
+		u3 = t5 * (-t11 + 0.3e1 * t13 * t9 - 0.2e1 * (double) t17 * t12 + t23 + 0.4e1 * (double) t24 * t8 - t28 - (double) t29 * t12 + 0.3e1 * t13 * (double) t21 + 0.3e1 * (double) t16 * t7 * (double) R - t37) * _C1 * t41 + t5 * (0.3e1 * t44 * t9 + t49 + t52 - 0.2e1 * (double) t17 * t7 - 0.4e1 * (double) t24 * t47 - t58 + 0.3e1 * t44 * (double) t21 - (double) t29 * t7 - 0.3e1 * (double) t16 * t12 * (double) R + t65) * _C2 * t41 + t73 * (-t11 - 0.3e1 * t74 * t9 - 0.2e1 * (double) t78 * t12 + t23 - 0.4e1 * (double) t81 * t8 - t28 + (double) t84 * t12 - 0.3e1 * t74 * (double) t21 + 0.3e1 * (double) t77 * t7 * (double) R - t37) * _C3 * t41 + t73 * (t49 - 0.3e1 * t95 * t9 - 0.2e1 * (double) t78 * t7 + t52 + 0.4e1 * (double) t81 * t47 - t58 + (double) t84 * t7 - 0.3e1 * t95 * (double) t21 - 0.3e1 * (double) t77 * t12 * (double) R + t65) * _C4 * t41 + 0.8e1 / (t9 + (double) (4 * t112)) * del_rho * (double) B;
+		
+		t5 = exp((double) (2 * B * z + U * z - U));
+		t6 = U * U;
+		t7 = R * z;
+		t8 = cos((double) t7);
+		t10 = R * R;
+		t11 = t8 * (double) t10;
+		t12 = sin((double) t7);
+		t16 = kn * kn;
+		t17 = t8 * t16;
+		t20 = 0.1e1 / t16;
+		t23 = t12 * (double) t10;
+		t28 = t12 * t16;
+		t36 = exp((double) (z * (2 * B - VV)));
+		t37 = VV * VV;
+		u4 = t5 * (-(double) t6 * t8 + t11 + 0.2e1 * (double) U * t12 * (double) R - t17) * _C1 * t20 - t5 * (-t23 + (double) t6 * t12 + 0.2e1 * (double) U * t8 * (double) R + t28) * _C2 * t20 + t36 * (-(double) t37 * t8 + t11 - 0.2e1 * (double) VV * t12 * (double) R - t17) * _C3 * t20 + t36 * (-(double) t37 * t12 + t23 + 0.2e1 * (double) VV * t8 * (double) R - t28) * _C4 * t20 + del_rho / kn;
+		
+		
+		
+		pp = (double)-(u3 + 2.0*n*M_PI*exp(2.0*B*z)*u2)*cos(n*M_PI*x); /* pressure */
+		
+		txx = (double)(u3 + 4*exp(2.0*B*z)*n*M_PI*u2)*cos(n*M_PI*x); /* xx stress */	    
+		sum5 += pp;
+		sum6 += txx;
+		
+		u1 *= cos(n*M_PI*x); /* z velocity */
+		sum1 += u1;
+		u2 *= sin(n*M_PI*x); /* x velocity */
+		sum2 += u2;
+		u3 *= cos(n*M_PI*x); /* zz stress */
+		sum3 += u3;
+		u4 *= sin(n*M_PI*x); /* zx stress */
+		sum4 += u4;
+		
+		rho = del_rho* cos(n*M_PI*x); /* density */
+		sum7 += rho;
+	}/* n */
+	
+	/* include terms for n=0 now */
+	del_rho = sigma*dx;
+	rho = del_rho; /* density */
+	sum7 += rho;
+	
+	u3 = del_rho*(z-0.5); /* zz stress */
+	sum3 += u3;
+	
+	txx = u3; /* xx stress */
+	pp = -u3; /* pressure */
+	sum5 += pp;
+	sum6 += txx;
+	
+	
+	mag=sqrt(sum1*sum1+sum2*sum2);
+	//printf("%0.7g %0.7g %0.7g %0.7g %0.7g %0.7g\n",x,y,z,sum3,sum2,sum1);
+	//printf("%0.7g %0.7g %0.7g\n%0.7g %0.7g %0.7g\n\n\n",x,y,z,x+sum3,y+sum2,z+sum1);
+	/*printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7);*/
+	
+	
+	/* Output */
+	if( vel != NULL ) {
+		vel[0] = sum2;
+		vel[1] = sum1;
+	}
+	if( presssure != NULL ) {
+		(*presssure) = sum5;
+	}
+	if( total_stress != NULL ) {
+		total_stress[0] = sum6;
+		total_stress[1] = sum3;
+		total_stress[2] = sum4;
+	}
+	if( strain_rate != NULL ) {
+		/* sigma = tau - p, tau = sigma + p, tau[] = 2*eta*strain_rate[] */
+		Z = exp(2.0*B*z);
+		strain_rate[0] = (sum6+sum5)/(2.0*Z);
+		strain_rate[1] = (sum3+sum5)/(2.0*Z);
+		strain_rate[2] = (sum4)/(2.0*Z);
+	}
+	/* Value checks, could be cleaned up if needed. Julian Giordani 9-Oct-2006*/
+        if( fabs( sum5 - ( -0.5*(sum6+sum3) ) ) > 1e-5 ) {
+                assert(0);
+        }
+	
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solJ/Analytic_solJ.c
--- a/SysTest/AnalyticPlugins/Velic_solJ/Analytic_solJ.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,174 +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:
-*+		Mirko Velic
-*+		Julian Giordani
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Patrick Sunter
-** $Id: solJ.c 636 2006-09-08 03:07:06Z JulianGiordani $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include "Analytic_solJ.h"
-
-const Type Velic_solJ_Type = "Underworld_Velic_solJ";
-
-void Velic_solJ_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
-	Velic_solJ* self = (Velic_solJ*) analyticSolution;
-	
-	_Velic_solJ( coord, self->sigmaB, self->sigmaA, self->etaB, self->etaA, self->dxB, self->dxA,
-		       self->x0B, self->x0A, self->zc,
-	       	       NULL, pressure, NULL, NULL );
-}
-
-void Velic_solJ_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
-	Velic_solJ* self = (Velic_solJ*) analyticSolution;
-	
-	_Velic_solJ( coord, self->sigmaB, self->sigmaA, self->etaB, self->etaA, self->dxB, self->dxA,
-		       self->x0B, self->x0A, self->zc,
-	       	       velocity, NULL, NULL, NULL );
-}
-
-void Velic_solJ_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
-	Velic_solJ* self = (Velic_solJ*) analyticSolution;
-	
-	_Velic_solJ( coord, self->sigmaB, self->sigmaA, self->etaB, self->etaA, self->dxB, self->dxA,
-		       self->x0B, self->x0A, self->zc,
-	       	       NULL, NULL, stress, NULL );
-}
-
-
-void Velic_solJ_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
-	Velic_solJ* self = (Velic_solJ*) analyticSolution;
-	
-	_Velic_solJ( coord, self->sigmaB, self->sigmaA, self->etaB, self->etaA, self->dxB, self->dxA,
-		       self->x0B, self->x0A, self->zc,
-	       	       NULL, NULL, NULL, strainRate );
-}
-
-void _Velic_solJ_Init( Velic_solJ* self, double sigmaA, double sigmaB, double etaB, double etaA, double dxB, double dxA, double x0B, double x0A, double zc ) {
-// TODO	Bool                     correctInput = True;
-	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
-        self->_getAnalyticVelocity    = Velic_solJ_VelocityFunction;
-	self->_getAnalyticPressure    = Velic_solJ_PressureFunction;
-	self->_getAnalyticTotalStress = Velic_solJ_StressFunction;
-	self->_getAnalyticStrainRate  = Velic_solJ_StrainRateFunction;
-	
-	self->sigmaA = sigmaA;
-	self->sigmaB = sigmaB;
-	self->etaB = etaB;
-	self->etaA = etaA;
-	self->dxB = dxB;
-	self->dxA = dxA;
-	self->x0B = x0B;
-	self->x0A = x0A;
-	self->zc = zc;
-}
-
-void _Velic_solJ_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
-	Velic_solJ* self = (Velic_solJ*) analyticSolution;
-	FeVariable*              velocityField;
-	FeVariable*              pressureField;
-	FeVariable*              stressField;
-	FeVariable*              strainRateField;
-	FeVariable*              recoveredStrainRateField;
-	FeVariable*              recoveredStressField;
-	double                   sigmaA, sigmaB, etaB, etaA, dxB, dxA, x0B, x0A, zc;
-
-	/* Construct Parent */
-	_AnalyticSolution_AssignFromXML( self, cf, data );
-
-	/* Create Analytic Fields */
-	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solJ_VelocityFunction );
-
-	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solJ_PressureFunction );
-
-	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False, data );
-	if ( stressField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solJ_StressFunction );
-
-	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
-	if ( strainRateField   ) {
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solJ_StrainRateFunction );
-	}
-
-	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
-	if ( recoveredStrainRateField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solJ_StrainRateFunction );
-
-	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
-	if ( recoveredStressField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solJ_StressFunction );
-
-	sigmaA = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJ_sigmaA", 1.0  );
-	sigmaB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJ_sigmaB", 3.0  );
-	etaB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJ_etaB", 2.0  );
-	etaA = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJ_etaA", 1.0  );
-	dxB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJ_dxB", 0.4  );
-	dxA = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJ_dxA", 0.3  );
-	x0B = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJ_x0B", 0.3  );
-	x0A = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJ_x0A", 0.6  );
-	zc = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJ_zc", 0.8  );
-
-	_Velic_solJ_Init( self, sigmaA, sigmaB, etaB, etaA, dxB, dxA, x0B, x0A, zc );
-}
-
-void* _Velic_solJ_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Velic_solJ);
-	Type                                                      type = Velic_solJ_Type;
-	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
-	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
-	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solJ_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Velic_solJ_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _AnalyticSolution_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 Underworld_Velic_solJ_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Velic_solJ_Type, (Name)"0", _Velic_solJ_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solJ/Analytic_solJ.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solJ/Analytic_solJ.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,174 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Mirko Velic
+*+		Julian Giordani
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Patrick Sunter
+** $Id: solJ.c 636 2006-09-08 03:07:06Z JulianGiordani $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include "Analytic_solJ.h"
+
+const Type Velic_solJ_Type = "Underworld_Velic_solJ";
+
+void Velic_solJ_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
+	Velic_solJ* self = (Velic_solJ*) analyticSolution;
+	
+	_Velic_solJ( coord, self->sigmaB, self->sigmaA, self->etaB, self->etaA, self->dxB, self->dxA,
+		       self->x0B, self->x0A, self->zc,
+	       	       NULL, pressure, NULL, NULL );
+}
+
+void Velic_solJ_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
+	Velic_solJ* self = (Velic_solJ*) analyticSolution;
+	
+	_Velic_solJ( coord, self->sigmaB, self->sigmaA, self->etaB, self->etaA, self->dxB, self->dxA,
+		       self->x0B, self->x0A, self->zc,
+	       	       velocity, NULL, NULL, NULL );
+}
+
+void Velic_solJ_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
+	Velic_solJ* self = (Velic_solJ*) analyticSolution;
+	
+	_Velic_solJ( coord, self->sigmaB, self->sigmaA, self->etaB, self->etaA, self->dxB, self->dxA,
+		       self->x0B, self->x0A, self->zc,
+	       	       NULL, NULL, stress, NULL );
+}
+
+
+void Velic_solJ_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
+	Velic_solJ* self = (Velic_solJ*) analyticSolution;
+	
+	_Velic_solJ( coord, self->sigmaB, self->sigmaA, self->etaB, self->etaA, self->dxB, self->dxA,
+		       self->x0B, self->x0A, self->zc,
+	       	       NULL, NULL, NULL, strainRate );
+}
+
+void _Velic_solJ_Init( Velic_solJ* self, double sigmaA, double sigmaB, double etaB, double etaA, double dxB, double dxA, double x0B, double x0A, double zc ) {
+// TODO	Bool                     correctInput = True;
+	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
+        self->_getAnalyticVelocity    = Velic_solJ_VelocityFunction;
+	self->_getAnalyticPressure    = Velic_solJ_PressureFunction;
+	self->_getAnalyticTotalStress = Velic_solJ_StressFunction;
+	self->_getAnalyticStrainRate  = Velic_solJ_StrainRateFunction;
+	
+	self->sigmaA = sigmaA;
+	self->sigmaB = sigmaB;
+	self->etaB = etaB;
+	self->etaA = etaA;
+	self->dxB = dxB;
+	self->dxA = dxA;
+	self->x0B = x0B;
+	self->x0A = x0A;
+	self->zc = zc;
+}
+
+void _Velic_solJ_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
+	Velic_solJ* self = (Velic_solJ*) analyticSolution;
+	FeVariable*              velocityField;
+	FeVariable*              pressureField;
+	FeVariable*              stressField;
+	FeVariable*              strainRateField;
+	FeVariable*              recoveredStrainRateField;
+	FeVariable*              recoveredStressField;
+	double                   sigmaA, sigmaB, etaB, etaA, dxB, dxA, x0B, x0A, zc;
+
+	/* Construct Parent */
+	_AnalyticSolution_AssignFromXML( self, cf, data );
+
+	/* Create Analytic Fields */
+	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solJ_VelocityFunction );
+
+	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solJ_PressureFunction );
+
+	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False, data );
+	if ( stressField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solJ_StressFunction );
+
+	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
+	if ( strainRateField   ) {
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solJ_StrainRateFunction );
+	}
+
+	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
+	if ( recoveredStrainRateField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solJ_StrainRateFunction );
+
+	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
+	if ( recoveredStressField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solJ_StressFunction );
+
+	sigmaA = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJ_sigmaA", 1.0  );
+	sigmaB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJ_sigmaB", 3.0  );
+	etaB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJ_etaB", 2.0  );
+	etaA = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJ_etaA", 1.0  );
+	dxB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJ_dxB", 0.4  );
+	dxA = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJ_dxA", 0.3  );
+	x0B = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJ_x0B", 0.3  );
+	x0A = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJ_x0A", 0.6  );
+	zc = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJ_zc", 0.8  );
+
+	_Velic_solJ_Init( self, sigmaA, sigmaB, etaB, etaA, dxB, dxA, x0B, x0A, zc );
+}
+
+void* _Velic_solJ_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Velic_solJ);
+	Type                                                      type = Velic_solJ_Type;
+	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
+	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
+	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solJ_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Velic_solJ_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _AnalyticSolution_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 Underworld_Velic_solJ_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Velic_solJ_Type, (Name)"0", _Velic_solJ_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solJ/solJ.c
--- a/SysTest/AnalyticPlugins/Velic_solJ/solJ.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,992 +0,0 @@
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-
-void _Velic_solJ( 
-		double pos[],
-		double _sigma_B, double _sigma_A,
-		double _eta_B, double _eta_A, 
-		double _dx_B, double _dx_A,
-		double _x_0_B, double _x_0_A,
-		double _z_c,
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] );
-
-
-int main( int argc, char **argv )
-{
-	int i,j;
-	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
-	double x,z;
-	
-	for (i=0;i<101;i++){
-		for(j=0;j<101;j++){
-			x = i/100.0;
-			z = j/100.0;
-			
-			pos[0] = x;
-			pos[1] = z;
-			_Velic_solJ(
-					pos,
-					3.0, 1.0,
-					2.0, 1.0,
-					0.4, 0.3,
-					0.3, 0.6,
-					0.8,
-					vel, &pressure, total_stress, strain_rate );
-			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
-					pos[0],pos[1],
-					vel[0],vel[1], pressure, 
-					total_stress[0], total_stress[1], total_stress[2], 
-					strain_rate[0], strain_rate[1], strain_rate[2] );
-		}
-		printf("\n");
-	}
-	
-	return 0;
-}
-
-
-
-void _Velic_solJ( 
-		double pos[],
-		double _sigma_B ,double _sigma_A, /* density B, density A */
-		double _eta_B   ,double _eta_A  , /* viscosity B, viscosity A */
-		double _dx_B    ,double _dx_A   , /* width of the upper dense block, width of the lower dense block */
-		double _x_0_B   ,double _x_0_A  , /* centre of the upper dense block, centre of lower dense block */
-		double _z_c, /* bottom of the upper dense block */
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] )
-{
-	double Z,ZA,ZB,u1,u2,u3,u4,pp,txx;
-	double u1a,u2a,u3a,u4a,u1b,u2b,u3b,u4b;
-	double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,x,z;
-	double sigma,sigmaA,dx,dxA;
-	double del_rhoA,del_rhoB,del_rho;
-	int n;
-	double kn;
-	double _C1A,_C2A,_C3A,_C4A,_C1B,_C2B,_C3B,_C4B;
-	double x0,x0A,rho,zc,x0B,dxB,sigmaB;
-	
-	double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
-	double t11,t12,t13,t14,t15,t16,t17,t18,t19,t20;
-	double t21,t22,t23,t24,t25,t26,t27,t28,t29,t30;
-	double t31,t32,t33,t34,t35,t36,t37,t38,t39,t40;
-	double t41,t42,t43,t44,t45,t46,t47,t48,t49,t50;
-	double t51,t52,t53,t54,t55,t56,t57,t58,t59,t60;
-	double t61,t62,t63,t64,t66,t67,t68,t69,t70,t71;
-	double t72,t73,t74,t75,t76,t77,t78,t79,t80,t81;
-	double t82,t83,t84,t85,t86,t87,t88,t89,t90,t91;
-	double t93,t94,t95,t96,t97,t98,t99,t100,t101,t102;
-	double t103,t104,t105,t106,t107,t108,t109,t110,t111,t112;
-	double t113,t114,t115,t116,t117,t118,t119,t120,t121,t122;
-	double t123,t124,t125,t126,t128,t129,t130,t131,t132,t133;
-	double t134,t135,t136,t137,t138,t139,t140,t141,t142,t143;
-	double t144,t145,t146,t147,t148,t149,t150,t151,t152,t153;
-	double t154,t155,t156,t157,t158,t159,t160,t161,t162,t163;
-	double t164,t165,t166,t167,t168,t169,t170,t171,t172,t173;
-	double t174,t175,t176,t178,t179,t180,t181,t183,t184,t185;
-	double t186,t187,t188,t189,t191,t193,t196,t197,t200,t202;
-	double t203,t206,t207,t210,t211,t215,t217,t218,t219,t221;
-	double t222,t223,t224,t225,t226,t227,t228,t229,t232,t233;
-	double t238,t239,t243,t244,t246,t248,t250,t251,t267,t273;
-	
-	
-	
-	
-	/*************************************************************************/
-	/*************************************************************************/
-	x0 = x0B = _x_0_B;  /* centre of dense column for layer B */
-	dx = dxB = _dx_B;  /* total width of dense column  for layer B */
-	sigma = sigmaB = _sigma_B; /* density parameter for layer B (sigma_1 in _Velic_solJ.pdf) */
-	sigmaA = _sigma_A; /* density parameter for layer A (sigma_0 in _Velic_solJ.pdf) */
-	x0A = _x_0_A; /* centre of dense column for layer A */
-	dxA = _dx_A;  /* total width of dense column  for layer A (eta_0 in _Velic_solJ.pdf) */
-	ZA = _eta_A;    /* viscosity for layer A (eta_1 in _Velic_solJ.pdf) */
-	ZB = _eta_B; /* viscosity for layer B */
-	zc = _z_c;
-	/*************************************************************************/
-	/*************************************************************************/
-	
-	x = pos[0];
-	z = pos[1];
-	
-	sum1=0.0;
-	sum2=0.0;
-	sum3=0.0;
-	sum4=0.0;
-	sum5=0.0;
-	sum6=0.0;
-	sum7=0.0;
-	/* convergence is good */
-	for(n=1;n<155;n++){
-		kn = (double) n*M_PI;
-		
-		/*******************************************/
-		/*            calculate del_rho            */
-		/*******************************************/
-		del_rhoB = 4.0*sigma*cos(n*M_PI*x0)*sin(n*M_PI*dx/2.0)/n/M_PI;
-		del_rhoA = 4.0*sigmaA*cos(n*M_PI*x0A)*sin(n*M_PI*dxA/2.0)/n/M_PI;
-		
-		/*******************************************/
-		/*         calculate the constants         */
-		/*******************************************/
-		
-		if (z < zc) {
-			t1 = -ZB + ZA;
-			t2 = ZA * kn;
-			t3 = t2 * zc;
-			t4 = 0.2e1 * ZB;
-			t5 = kn * zc;
-			t7 = 0.2e1 * t5 * ZB;
-			t11 = exp(-0.3e1 * t5);
-			t13 = ZA + ZB;
-			t14 = t1 * t13;
-			t16 = pow(-0.1e1 + t5, 0.2e1);
-			t18 = kn * (-0.2e1 + zc);
-			t20 = exp(0.2e1 * t18);
-			t25 = zc - 0.1e1;
-			t26 = t13 * t25;
-			t27 = kn * t25;
-			t29 = exp(0.2e1 * t27);
-			t30 = t26 * t29;
-			t33 = kn * kn;
-			t34 = t33 * kn;
-			t35 = ZA * ZA;
-			t37 = zc * zc;
-			t38 = t37 * zc;
-			t40 = t34 * t37;
-			t42 = ZB * ZB;
-			t43 = t33 * t42;
-			t44 = t43 * t37;
-			t45 = 0.2e1 * t44;
-			t46 = t33 * t35;
-			t48 = 0.2e1 * t46 * zc;
-			t51 = 0.2e1 * t46 * t37;
-			t52 = ZA * ZB;
-			t53 = t33 * ZA;
-			t55 = t53 * t37 * ZB;
-			t56 = 0.4e1 * t55;
-			t57 = kn * t42;
-			t58 = ZB * zc;
-			t59 = t53 * t58;
-			t60 = 0.4e1 * t59;
-			t61 = t43 * zc;
-			t62 = 0.2e1 * t61;
-			t63 = t34 * ZA;
-			t67 = kn * t35;
-			t73 = t2 * t58;
-			t75 = t57 * zc;
-			t76 = t2 * ZB;
-			t77 = t34 * t35 * t38 - t40 * t35 - t45 + t48 - t40 * t42 - t51 + t52 + t56 - t57 - t60 + t62 - 0.2e1 * t63 * ZB * t38 + t67 * zc + 0.2e1 * t40 * t52 + t34 * t42 * t38 - t67 - 0.2e1 * t73 + t75 + t76;
-			t79 = exp(-0.2e1 * kn);
-			t82 = 0.6e1 * t55;
-			t83 = 0.2e1 * t52;
-			t84 = 0.4e1 * t44;
-			t85 = 0.3e1 * t73;
-			t86 = 0.4e1 * t57;
-			t87 = 0.2e1 * t76;
-			t88 = 0.4e1 * t61;
-			t89 = 0.6e1 * t59;
-			t90 = 0.4e1 * t75;
-			t91 = -t82 - t83 + t84 + t51 + t85 + t86 - t87 - t88 + t89 - t48 - t90;
-			t94 = exp(-kn * (zc + 0.2e1));
-			t99 = exp(-t5);
-			t101 = -t82 + t51 + t90 - t86 + t87 - t85 + t84 + t89 - t88 - t83 - t48;
-			t102 = exp(t18);
-			t110 = exp(kn * (0.3e1 * zc - 0.4e1));
-			t113 = exp(-0.2e1 * t5);
-			t121 = exp(kn * (zc - 0.4e1));
-			t123 = t1 * t1;
-			t125 = exp(0.4e1 * t27);
-			t126 = t123 * t125;
-			t131 = t1 * (-t3 + t4 - t7) * t11 + 0.2e1 * t14 * t16 * t20 + 0.8e1 * kn * t1 * t30 - 0.8e1 * t77 * t79 - 0.2e1 * t91 * t94 + t13 * (t3 - t4 - t7) * t99 + 0.2e1 * t101 * t102 + t1 * (-t3 - t4 - t7) * t110 - 0.2e1 * t14 * t16 * t113 + t13 * (t3 + t4 - t7) * t121 - 0.2e1 * t126 + 0.2e1 * t35 + 0.4e1 * t52 + 0.2e1 * t42;
-			t133 = ZA * del_rhoB;
-			t137 = exp(-0.3e1 * kn);
-			t141 = t33 * zc;
-			t142 = 0.2e1 * t141;
-			t143 = 0.4e1 * t5;
-			t144 = t33 * t37;
-			t145 = 0.2e1 * t144;
-			t148 = 0.2e1 * zc;
-			t151 = exp(-kn * (t148 + 0.1e1));
-			t155 = t133 * t5;
-			t156 = 0.2e1 * t133;
-			t163 = 0.3e1 * t2 * zc * del_rhoB * ZB;
-			t164 = t35 * del_rhoB;
-			t166 = 0.2e1 * t144 * t164;
-			t167 = t133 * ZB;
-			t169 = 0.2e1 * t141 * t167;
-			t172 = 0.2e1 * t133 * kn * ZB;
-			t174 = 0.2e1 * t164 * t5;
-			t176 = 0.2e1 * t144 * t167;
-			t178 = 0.2e1 * t141 * t164;
-			t179 = 0.2e1 * t164;
-			t183 = 0.3e1 * t155;
-			t197 = exp(kn * (t148 - 0.3e1));
-			t203 = exp(-kn);
-			t210 = t131 * del_rhoA - 0.2e1 * t133 * (-0.2e1 + kn) * t13 * t137 + 0.2e1 * t133 * (0.2e1 - t142 - t143 + t145 + kn) * t1 * t151 + t13 * (t155 + t156) * t99 + 0.2e1 * (-t163 + t166 + t169 + t172 + t174 - t176 - t178 + t179) * t102 + t1 * (-t156 + t183) * t11 - 0.2e1 * (-t176 + t163 + t166 - t174 - t172 - t178 + t179 + t169) * t94 + t13 * (-t156 + t155) * t121 - 0.2e1 * t133 * (-t142 + t143 + t145 + 0.2e1 - kn) * t1 * t197 - 0.2e1 * t133 * (0.2e1 + kn) * t13 * t203 + t1 * (t183 + t156) * t110;
-			t211 = t63 * zc;
-			t215 = exp(-t143);
-			t222 = t63 * t1;
-			t225 = t13 * t13;
-			t227 = exp(-0.4e1 * kn);
-			t238 = exp(-0.2e1 * kn * (zc + 0.1e1));
-			t251 = -0.8e1 * t211 * t14 * t20 - 0.2e1 * t53 * t123 * t215 + 0.8e1 * t211 * t14 * t113 + 0.8e1 * t222 * t30 + 0.2e1 * t53 * t225 * t227 + 0.16e2 * t53 * (-t62 + t60 - t48 - t52 + t45 + t51 - t56) * t79 - 0.8e1 * t222 * t26 * t238 - 0.2e1 * t53 * t126 + 0.2e1 * t33 * t35 * ZA + 0.2e1 * t53 * t42 + 0.4e1 * t46 * ZB;
-			_C1A = t210 / t251;
-			
-			t1 = -ZB + ZA;
-			t2 = ZA * kn;
-			t3 = t2 * zc;
-			t4 = 0.2e1 * ZB;
-			t5 = kn * zc;
-			t7 = 0.2e1 * t5 * ZB;
-			t11 = exp(-0.2e1 * t5);
-			t13 = kn * kn;
-			t14 = t13 * ZA;
-			t15 = zc * zc;
-			t17 = t14 * t15 * ZB;
-			t18 = 0.6e1 * t17;
-			t19 = ZA * ZA;
-			t20 = t13 * t19;
-			t22 = 0.2e1 * t20 * t15;
-			t23 = ZB * ZB;
-			t24 = kn * t23;
-			t25 = t24 * zc;
-			t26 = 0.4e1 * t25;
-			t27 = 0.4e1 * t24;
-			t28 = t2 * ZB;
-			t29 = 0.2e1 * t28;
-			t30 = zc * ZB;
-			t31 = t2 * t30;
-			t32 = 0.3e1 * t31;
-			t33 = t13 * t23;
-			t34 = t33 * t15;
-			t35 = 0.4e1 * t34;
-			t36 = t14 * t30;
-			t37 = 0.6e1 * t36;
-			t38 = t33 * zc;
-			t39 = 0.4e1 * t38;
-			t40 = ZA * ZB;
-			t41 = 0.2e1 * t40;
-			t43 = 0.2e1 * t20 * zc;
-			t44 = -t18 + t22 + t26 - t27 + t29 - t32 + t35 + t37 - t39 - t41 - t43;
-			t45 = zc - 0.1e1;
-			t46 = kn * t45;
-			t48 = exp(0.2e1 * t46);
-			t51 = t13 * kn;
-			t53 = t15 * zc;
-			t55 = t51 * t15;
-			t59 = t51 * ZA;
-			t66 = 0.4e1 * t17;
-			t67 = 0.4e1 * t36;
-			t68 = 0.2e1 * t34;
-			t69 = 0.2e1 * t38;
-			t70 = kn * t19;
-			t71 = t70 * zc;
-			t73 = t51 * t19 * t53 - t55 * t19 + 0.2e1 * t55 * t40 - 0.2e1 * t59 * ZB * t53 + t51 * t23 * t53 - t55 * t23 + t22 - t43 - t66 + t67 + t68 - t69 + t71 - t70 + t28 - 0.2e1 * t31 + t25 - t24 - t40;
-			t75 = kn * (-0.2e1 + zc);
-			t76 = exp(t75);
-			t79 = ZA + ZB;
-			t80 = t79 * t79;
-			t83 = exp(kn * (zc - 0.4e1));
-			t87 = t79 * t45;
-			t90 = exp(-kn * (zc + 0.2e1));
-			t97 = exp(0.2e1 * t75);
-			t99 = t1 * t1;
-			t101 = exp(-0.3e1 * t5);
-			t107 = exp(0.4e1 * t46);
-			t110 = -t18 - t41 + t35 + t22 + t32 + t27 - t29 - t39 + t37 - t43 - t26;
-			t112 = exp(-0.2e1 * kn);
-			t116 = t1 * t79;
-			t118 = pow(0.1e1 + t5, 0.2e1);
-			t119 = exp(-t5);
-			t126 = exp(kn * (0.3e1 * zc - 0.4e1));
-			t130 = -t1 * (-t3 + t4 - t7) * t11 - 0.2e1 * t44 * t48 + 0.8e1 * t73 * t76 + 0.2e1 * t80 * t83 - 0.8e1 * kn * t1 * t87 * t90 - t79 * (t3 + t4 - t7) * t97 - 0.2e1 * t99 * t101 - t71 + t31 - t1 * (-t3 - t4 - t7) * t107 + 0.2e1 * t23 + t41 + 0.2e1 * t110 * t112 + 0.2e1 * t25 + 0.2e1 * t116 * t118 * t119 - 0.2e1 * t116 * t118 * t126;
-			t132 = ZA * del_rhoB;
-			t133 = 0.2e1 * t132;
-			t134 = t132 * t5;
-			t138 = t19 * del_rhoB;
-			t139 = 0.2e1 * t138;
-			t140 = t132 * ZB;
-			t142 = t13 * zc;
-			t143 = 0.2e1 * t142;
-			t144 = 0.4e1 * t5;
-			t145 = t13 * t15;
-			t146 = 0.2e1 * t145;
-			t150 = exp(0.3e1 * t46);
-			t154 = 0.3e1 * t134;
-			t161 = kn * (zc + 0.1e1);
-			t162 = exp(-t161);
-			t168 = exp(t46);
-			t175 = t138 * t5;
-			t178 = t2 * zc * del_rhoB * ZB;
-			t179 = 0.3e1 * t178;
-			t181 = 0.2e1 * t145 * t138;
-			t183 = 0.2e1 * t142 * t140;
-			t186 = 0.2e1 * t132 * kn * ZB;
-			t187 = 0.2e1 * t175;
-			t189 = 0.2e1 * t145 * t140;
-			t191 = 0.2e1 * t142 * t138;
-			t202 = exp(kn * (zc - 0.3e1));
-			t206 = t130 * del_rhoA - t79 * (-t133 + t134) * t97 - t139 - 0.2e1 * t140 + 0.2e1 * t132 * (-t143 + t144 + t146 + 0.2e1 - kn) * t1 * t150 - t1 * (t154 + t133) * t107 - 0.2e1 * t132 * (0.2e1 - t143 - t144 + t146 + kn) * t1 * t162 + 0.2e1 * t132 * (0.2e1 + kn) * t79 * t168 - t1 * (-t133 + t154) * t11 - t175 - 0.2e1 * (-t179 + t181 + t183 + t186 + t187 - t189 - t191 + t139) * t48 - t178 + 0.2e1 * (-t189 + t179 + t181 - t187 - t186 - t191 + t139 + t183) * t112 + 0.2e1 * t132 * (-0.2e1 + kn) * t79 * t202;
-			t207 = t59 * zc;
-			t211 = exp(-t144);
-			t218 = t59 * t1;
-			t223 = exp(-0.4e1 * kn);
-			t232 = exp(-0.2e1 * t161);
-			t246 = -0.8e1 * t207 * t116 * t97 - 0.2e1 * t14 * t99 * t211 + 0.8e1 * t207 * t116 * t11 + 0.8e1 * t218 * t87 * t48 + 0.2e1 * t14 * t80 * t223 + 0.16e2 * t14 * (-t69 + t67 - t43 - t40 + t68 + t22 - t66) * t112 - 0.8e1 * t218 * t87 * t232 - 0.2e1 * t14 * t99 * t107 + 0.2e1 * t13 * t19 * ZA + 0.2e1 * t14 * t23 + 0.4e1 * t20 * ZB;
-			_C2A = t206 / t246;
-			
-			t1 = -ZB + ZA;
-			t2 = 0.2e1 * ZB;
-			t4 = t1 * (-ZA - t2);
-			t5 = kn * zc;
-			t7 = exp(-0.3e1 * t5);
-			t10 = ZA + ZB;
-			t11 = zc - 0.1e1;
-			t12 = t10 * t11;
-			t13 = kn * t11;
-			t15 = exp(0.2e1 * t13);
-			t16 = t12 * t15;
-			t19 = kn * kn;
-			t20 = ZA * ZA;
-			t21 = t19 * t20;
-			t22 = zc * zc;
-			t24 = 0.2e1 * t21 * t22;
-			t26 = 0.2e1 * t21 * zc;
-			t27 = t19 * ZA;
-			t28 = zc * ZB;
-			t30 = 0.4e1 * t27 * t28;
-			t33 = 0.4e1 * t27 * t22 * ZB;
-			t34 = ZB * ZB;
-			t35 = t19 * t34;
-			t37 = 0.2e1 * t35 * t22;
-			t39 = 0.2e1 * t35 * zc;
-			t40 = kn * t20;
-			t42 = t40 * zc;
-			t44 = ZA * kn;
-			t46 = 0.6e1 * t44 * t28;
-			t48 = 0.6e1 * t44 * ZB;
-			t49 = kn * t34;
-			t51 = t49 * zc;
-			t53 = ZA * ZB;
-			t54 = t24 - t26 + t30 - t33 + t37 - t39 + 0.3e1 * t40 - 0.3e1 * t42 + t46 - t48 + 0.3e1 * t49 - 0.3e1 * t51 - t53;
-			t55 = 0.2e1 * kn;
-			t56 = exp(-t55);
-			t59 = t1 * t10;
-			t60 = 0.2e1 * t5;
-			t61 = t60 - 0.3e1;
-			t62 = exp(-t60);
-			t66 = t10 * (ZA - t2);
-			t67 = exp(-t5);
-			t70 = kn * (-0.2e1 + zc);
-			t72 = exp(0.2e1 * t70);
-			t78 = exp(kn * (0.3e1 * zc - 0.4e1));
-			t80 = 0.2e1 * t40;
-			t81 = 0.2e1 * t42;
-			t82 = 0.4e1 * t49;
-			t83 = 0.4e1 * t51;
-			t85 = exp(t70);
-			t90 = exp(kn * (zc - 0.4e1));
-			t95 = exp(-kn * (zc + 0.2e1));
-			t98 = t1 * t1;
-			t100 = exp(0.4e1 * t13);
-			t101 = t98 * t100;
-			t103 = -t4 * t7 + 0.4e1 * kn * t1 * t16 + 0.4e1 * t54 * t56 + t59 * t61 * t62 + t66 * t67 - t59 * t61 * t72 + t4 * t78 + 0.2e1 * (-t80 + t48 + t81 - t82 - t53 - t46 + t83) * t85 - t66 * t90 + 0.2e1 * (-t80 + t48 + t81 - t82 + t53 - t46 + t83) * t95 - t101 + t34 + t20 + 0.2e1 * t53;
-			t105 = ZA * del_rhoB;
-			t108 = 0.2e1 * zc;
-			t111 = exp(-kn * (t108 + 0.1e1));
-			t116 = exp(-0.3e1 * kn);
-			t120 = t1 * ZA;
-			t126 = 0.2e1 * del_rhoB * kn * t20;
-			t130 = 0.2e1 * t44 * zc * del_rhoB * ZB;
-			t133 = 0.2e1 * t105 * kn * ZB;
-			t134 = t20 * del_rhoB;
-			t136 = 0.2e1 * t134 * t5;
-			t137 = 0.2e1 * t134;
-			t138 = t105 * ZB;
-			t151 = exp(kn * (t108 - 0.3e1));
-			t160 = exp(-kn);
-			t164 = t103 * del_rhoA - 0.2e1 * t105 * t1 * (-0.3e1 - t55 + t60) * t111 + 0.2e1 * t105 * t10 * t116 + 0.3e1 * t120 * del_rhoB * t78 + 0.2e1 * (-t126 - t130 + t133 + t136 + t137 - t138) * t85 - t105 * t10 * t90 + 0.2e1 * (-t126 - t130 + t133 + t136 + t138 - t137) * t95 - 0.2e1 * t105 * t1 * (-t55 + 0.3e1 + t60) * t151 - 0.3e1 * t120 * del_rhoB * t7 + t105 * t10 * t67 - 0.2e1 * t105 * t10 * t160;
-			t165 = t27 * zc;
-			t169 = t27 * t1;
-			t173 = exp(-0.2e1 * kn * (zc + 0.1e1));
-			t178 = exp(-0.4e1 * t5);
-			t187 = t10 * t10;
-			t189 = exp(-0.4e1 * kn);
-			t206 = -0.8e1 * t165 * t59 * t72 - 0.8e1 * t169 * t12 * t173 - 0.2e1 * t44 * t98 * t178 + 0.8e1 * t165 * t59 * t62 + 0.8e1 * t169 * t16 + 0.2e1 * t44 * t187 * t189 + 0.16e2 * t44 * (-t39 + t30 - t26 - t53 + t37 + t24 - t33) * t56 - 0.2e1 * t44 * t101 + 0.4e1 * t40 * ZB + 0.2e1 * kn * t20 * ZA + 0.2e1 * t44 * t34;
-			_C3A = t164 / t206;
-			
-			t1 = ZB * ZB;
-			t2 = kn * t1;
-			t3 = t2 * zc;
-			t5 = ZA * ZA;
-			t6 = kn * t5;
-			t8 = kn * kn;
-			t9 = t8 * t1;
-			t11 = 0.2e1 * t9 * zc;
-			t12 = t8 * t5;
-			t13 = zc * zc;
-			t15 = 0.2e1 * t12 * t13;
-			t16 = ZA * ZB;
-			t18 = 0.2e1 * t12 * zc;
-			t19 = ZA * kn;
-			t21 = 0.6e1 * t19 * ZB;
-			t22 = t8 * ZA;
-			t25 = 0.4e1 * t22 * t13 * ZB;
-			t27 = 0.2e1 * t9 * t13;
-			t28 = zc * ZB;
-			t30 = 0.6e1 * t19 * t28;
-			t32 = t6 * zc;
-			t35 = 0.4e1 * t22 * t28;
-			t36 = 0.3e1 * t3 - 0.3e1 * t6 - t11 + t15 - t16 - t18 + t21 - t25 + t27 - t30 - 0.3e1 * t2 + 0.3e1 * t32 + t35;
-			t38 = kn * (-0.2e1 + zc);
-			t39 = exp(t38);
-			t42 = -ZB + ZA;
-			t43 = 0.2e1 * ZB;
-			t45 = t42 * (-ZA - t43);
-			t46 = kn * zc;
-			t47 = 0.2e1 * t46;
-			t48 = exp(-t47);
-			t50 = 0.2e1 * t6;
-			t51 = 0.2e1 * t32;
-			t52 = 0.4e1 * t2;
-			t53 = 0.4e1 * t3;
-			t55 = 0.2e1 * kn;
-			t56 = exp(-t55);
-			t59 = t42 * t42;
-			t61 = exp(-0.3e1 * t46);
-			t63 = ZA + ZB;
-			t67 = exp(0.2e1 * t38);
-			t69 = t42 * t63;
-			t70 = t47 + 0.3e1;
-			t71 = exp(-t46);
-			t74 = t63 * t63;
-			t77 = exp(kn * (zc - 0.4e1));
-			t82 = exp(kn * (0.3e1 * zc - 0.4e1));
-			t85 = zc - 0.1e1;
-			t86 = kn * t85;
-			t88 = exp(0.4e1 * t86);
-			t93 = exp(0.2e1 * t86);
-			t97 = t63 * t85;
-			t100 = exp(-kn * (zc + 0.2e1));
-			t104 = -0.4e1 * t36 * t39 - t45 * t48 + 0.2e1 * (-t50 + t21 + t51 - t52 + t16 - t30 + t53) * t56 + t59 * t61 - t63 * (ZA - t43) * t67 - t69 * t70 * t71 - t74 * t77 + t69 * t70 * t82 + t45 * t88 - t16 - 0.2e1 * t1 + t5 + 0.2e1 * (-t50 + t21 + t51 - t52 - t16 - t30 + t53) * t93 + 0.4e1 * kn * t42 * t97 * t100;
-			t106 = ZA * del_rhoB;
-			t110 = kn * (zc + 0.1e1);
-			t111 = exp(-t110);
-			t120 = exp(0.3e1 * t86);
-			t126 = exp(kn * (zc - 0.3e1));
-			t132 = 0.2e1 * del_rhoB * kn * t5;
-			t136 = 0.2e1 * t19 * zc * del_rhoB * ZB;
-			t139 = 0.2e1 * t106 * kn * ZB;
-			t140 = t5 * del_rhoB;
-			t142 = 0.2e1 * t140 * t46;
-			t143 = t106 * ZB;
-			t144 = 0.2e1 * t140;
-			t148 = exp(t86);
-			t152 = t42 * ZA;
-			t162 = t104 * del_rhoA - 0.2e1 * t106 * t42 * (-0.3e1 - t55 + t47) * t111 - t106 * t63 * t67 - 0.2e1 * t106 * t42 * (-t55 + 0.3e1 + t47) * t120 + 0.2e1 * t106 * t63 * t126 + 0.2e1 * (-t132 - t136 + t139 + t142 + t143 - t144) * t56 - 0.2e1 * t106 * t63 * t148 + t143 - 0.3e1 * t152 * del_rhoB * t48 + 0.2e1 * (-t132 - t136 + t139 + t142 + t144 - t143) * t93 + 0.3e1 * t152 * del_rhoB * t88 + t140;
-			t163 = t22 * zc;
-			t167 = t22 * t42;
-			t169 = exp(-0.2e1 * t110);
-			t174 = exp(-0.4e1 * t46);
-			t185 = exp(-0.4e1 * kn);
-			t203 = -0.8e1 * t163 * t69 * t67 - 0.8e1 * t167 * t97 * t169 - 0.2e1 * t19 * t59 * t174 + 0.8e1 * t163 * t69 * t48 + 0.8e1 * t167 * t97 * t93 + 0.2e1 * t19 * t74 * t185 + 0.16e2 * t19 * (-t11 + t35 - t18 - t16 + t27 + t15 - t25) * t56 - 0.2e1 * t19 * t59 * t88 + 0.4e1 * t6 * ZB + 0.2e1 * kn * t5 * ZA + 0.2e1 * t19 * t1;
-			_C4A = t162 / t203;
-		} else {
-			t1 = ZA * kn;
-			t2 = t1 * ZB;
-			t3 = zc * ZB;
-			t4 = t1 * t3;
-			t6 = kn * kn;
-			t7 = ZB * ZB;
-			t8 = t6 * t7;
-			t9 = zc * zc;
-			t10 = t8 * t9;
-			t12 = ZA * ZA;
-			t14 = kn * t12 * zc;
-			t15 = 0.2e1 * t14;
-			t16 = t8 * zc;
-			t17 = t6 * kn;
-			t18 = t17 * t9;
-			t21 = kn * t7;
-			t22 = t21 * zc;
-			t25 = t9 * zc;
-			t35 = t6 * ZA;
-			t36 = t9 * ZB;
-			t37 = t35 * t36;
-			t39 = t6 * t12;
-			t40 = t39 * zc;
-			t41 = t35 * t3;
-			t43 = t39 * t9;
-			t44 = 0.4e1 * t43;
-			t47 = ZA * ZB;
-			t48 = 0.2e1 * t47;
-			t51 = t2 - 0.4e1 * t4 - 0.4e1 * t10 + t15 + t16 - 0.2e1 * t18 * t12 + 0.2e1 * t22 + 0.2e1 * t17 * t7 * t25 - 0.4e1 * t17 * ZA * ZB * t25 + 0.2e1 * t17 * t12 * t25 + 0.8e1 * t37 + t40 - 0.2e1 * t41 - t44 - 0.2e1 * t18 * t7 + t48 + 0.4e1 * t18 * t47;
-			t53 = kn * (zc + 0.1e1);
-			t54 = exp(-t53);
-			t57 = 0.6e1 * t37;
-			t58 = 0.2e1 * t10;
-			t59 = 0.4e1 * t14;
-			t60 = 0.3e1 * t4;
-			t62 = kn * zc;
-			t63 = 0.2e1 * t62;
-			t64 = exp(-t63);
-			t67 = -ZB + ZA;
-			t69 = 0.2e1 * t1 * zc;
-			t70 = 0.4e1 * t1;
-			t71 = 0.2e1 * ZA;
-			t72 = t62 * ZB;
-			t73 = kn * ZB;
-			t74 = 0.2e1 * t73;
-			t77 = zc - 0.1e1;
-			t78 = kn * t77;
-			t80 = exp(0.2e1 * t78);
-			t82 = ZA + ZB;
-			t83 = t67 * t82;
-			t85 = 0.2e1 * t6 * zc;
-			t86 = 0.4e1 * t62;
-			t87 = t6 * t9;
-			t89 = 0.2e1 - t85 - t86 + 0.2e1 * t87 + kn;
-			t90 = exp(t78);
-			t93 = t82 * t82;
-			t94 = -0.2e1 + kn;
-			t98 = exp(-kn * (0.3e1 + zc));
-			t100 = t67 * t67;
-			t103 = exp(0.3e1 * t78);
-			t107 = exp(-t86);
-			t115 = exp(-0.2e1 * kn);
-			t122 = exp(-kn * (0.3e1 * zc + 0.1e1));
-			t128 = exp(-0.2e1 * t53);
-			t134 = exp(kn * (zc - 0.3e1));
-			t138 = -0.4e1 * t51 * t54 - 0.2e1 * (-t57 + t58 - t59 + t60 + t44 - t48) * t64 + t67 * (t69 - t70 + t71 + t72 - t74) * t80 - t83 * t89 * t90 - t93 * t94 * t98 + t100 * t94 * t103 + t67 * (-t71 + t69 + t72) * t107 + 0.2e1 * (0.12e2 * t41 - t48 - t57 - 0.4e1 * t16 + t59 - t60 + t58 + t44 + 0.2e1 * t2 - 0.8e1 * t40) * t115 - t15 - t4 + 0.2e1 * t12 + t22 + t48 + t83 * t89 * t122 - t82 * (-t70 + t71 + t69 + t74 - t72) * t128 + 0.4e1 * t62 * t67 * t82 * t94 * t134;
-			t141 = del_rhoA * kn * ZB;
-			t143 = del_rhoA * ZB;
-			t144 = 0.2e1 * t143;
-			t145 = t62 * t143;
-			t153 = kn * (-0.2e1 + zc);
-			t154 = exp(t153);
-			t159 = t6 * del_rhoA;
-			t162 = del_rhoA * ZA;
-			t165 = zc * del_rhoA;
-			t166 = t21 * t165;
-			t167 = 0.2e1 * t166;
-			t168 = t159 * ZA;
-			t170 = 0.2e1 * t36 * t168;
-			t171 = t7 * del_rhoA;
-			t172 = 0.2e1 * t171;
-			t178 = 0.2e1 * t87 * t171;
-			t180 = t1 * t165 * ZB;
-			t181 = 0.3e1 * t180;
-			t186 = pow(-0.1e1 + t62, 0.2e1);
-			t189 = exp(-0.3e1 * t62);
-			t196 = 0.3e1 * t145;
-			t200 = exp(-t62);
-			t210 = exp(-kn * (zc + 0.2e1));
-			t218 = t138 * del_rhoB - t82 * (0.2e1 * t141 - t144 - t145) * t128 + 0.4e1 * t143 * (0.1e1 - 0.3e1 * kn + t87 - t85 + t63) * t67 * t154 + 0.2e1 * (-0.4e1 * t7 * zc * t159 + 0.2e1 * t162 * t73 + t167 - t170 + t172 + 0.4e1 * t3 * t168 - 0.4e1 * t21 * del_rhoA + t178 - t181) * t115 - 0.4e1 * t143 * t186 * t67 * t189 - 0.2e1 * (t181 + t172 - t170 - t167 + t178) * t64 + t67 * (-t196 + t144) * t107 + 0.4e1 * t143 * t82 * t200 - 0.2e1 * t162 * ZB + 0.4e1 * t143 * (kn - 0.1e1) * t82 * t210 + t166 + t67 * (0.6e1 * t141 - t196 - t144) * t80 + t180 - t172;
-			t219 = t6 * ZB;
-			t221 = exp(0.4e1 * t78);
-			t225 = t17 * ZB;
-			t226 = t225 * zc;
-			t228 = exp(0.2e1 * t153);
-			t238 = t225 * t67;
-			t239 = t82 * t77;
-			t244 = exp(-0.4e1 * kn);
-			t267 = -0.2e1 * t219 * t100 * t221 - 0.8e1 * t226 * t83 * t228 - 0.2e1 * t219 * t100 * t107 + 0.8e1 * t226 * t83 * t64 + 0.8e1 * t238 * t239 * t80 + 0.2e1 * t219 * t93 * t244 - 0.8e1 * t238 * t239 * t128 + 0.16e2 * t219 * (-0.2e1 * t16 + 0.4e1 * t41 - 0.2e1 * t40 - t47 + t58 + 0.2e1 * t43 - 0.4e1 * t37) * t115 + 0.4e1 * t35 * t7 + 0.2e1 * t39 * ZB + 0.2e1 * t6 * t7 * ZB;
-			_C1B = t218 / t267;
-			
-			t1 = kn * kn;
-			t2 = ZA * ZA;
-			t3 = t1 * t2;
-			t4 = zc * zc;
-			t5 = t3 * t4;
-			t6 = 0.4e1 * t5;
-			t7 = t3 * zc;
-			t9 = t1 * ZA;
-			t10 = zc * ZB;
-			t11 = t9 * t10;
-			t13 = t4 * ZB;
-			t14 = t9 * t13;
-			t15 = 0.6e1 * t14;
-			t16 = ZB * ZB;
-			t17 = t1 * t16;
-			t18 = t17 * t4;
-			t19 = 0.2e1 * t18;
-			t20 = t17 * zc;
-			t22 = kn * t2;
-			t23 = t22 * zc;
-			t24 = 0.4e1 * t23;
-			t25 = ZA * kn;
-			t26 = t25 * ZB;
-			t27 = 0.2e1 * t26;
-			t28 = t25 * t10;
-			t29 = 0.3e1 * t28;
-			t30 = ZA * ZB;
-			t31 = 0.2e1 * t30;
-			t34 = kn * (zc + 0.1e1);
-			t35 = exp(-t34);
-			t38 = ZA + ZB;
-			t39 = 0.2e1 * ZA;
-			t41 = 0.2e1 * t25 * zc;
-			t42 = 0.4e1 * t25;
-			t43 = kn * ZB;
-			t44 = 0.2e1 * t43;
-			t45 = kn * zc;
-			t46 = t45 * ZB;
-			t49 = zc - 0.1e1;
-			t50 = kn * t49;
-			t51 = exp(t50);
-			t53 = -ZB + ZA;
-			t55 = 0.2e1 + kn;
-			t57 = 0.2e1 * t45;
-			t58 = exp(-t57);
-			t67 = exp(-kn * (0.3e1 * zc + 0.1e1));
-			t69 = t53 * t38;
-			t71 = 0.2e1 * t1 * zc;
-			t72 = 0.4e1 * t45;
-			t73 = t1 * t4;
-			t75 = -t71 + t72 + 0.2e1 * t73 + 0.2e1 - kn;
-			t77 = exp(-0.2e1 * t34);
-			t80 = t53 * t53;
-			t82 = exp(-t72);
-			t84 = t1 * kn;
-			t86 = t4 * zc;
-			t89 = t84 * t4;
-			t108 = kn * t16;
-			t111 = 0.2e1 * t84 * t2 * t86 - 0.2e1 * t89 * t2 + 0.4e1 * t89 * t30 - 0.4e1 * t84 * ZA * ZB * t86 + 0.2e1 * t84 * t16 * t86 - 0.2e1 * t89 * t16 - t7 + t6 + 0.2e1 * t11 - 0.8e1 * t14 - t20 + 0.4e1 * t18 + 0.2e1 * t23 + t26 - 0.4e1 * t28 + 0.2e1 * t108 * zc - t31;
-			t113 = exp(-0.2e1 * kn);
-			t117 = exp(0.2e1 * t50);
-			t124 = exp(-kn * (0.3e1 + zc));
-			t129 = exp(kn * (zc - 0.3e1));
-			t135 = exp(0.3e1 * t50);
-			t140 = 0.2e1 * (t6 - 0.8e1 * t7 + 0.12e2 * t11 - t15 + t19 - 0.4e1 * t20 - t24 - t27 + t29 - t31) * t35 + t38 * (-t39 + t41 - t42 + t44 - t46) * t51 + 0.4e1 * t45 * t53 * t38 * t55 * t58 - t53 * (-t39 - t42 + t41 - t44 + t46) * t67 - t69 * t75 * t77 - t80 * t55 * t82 + 0.4e1 * t111 * t113 + t69 * t75 * t117 + t38 * (t41 + t39 - t46) * t124 - 0.2e1 * (t6 + t19 - t15 - t29 + t24 - t31) * t129 - t53 * (t39 + t46 + t41) * t135 + t27 + 0.2e1 * t16 + t108 + t22 + 0.4e1 * t30 + 0.2e1 * t2;
-			t142 = del_rhoA * ZB;
-			t143 = 0.2e1 * t142;
-			t145 = del_rhoA * kn * ZB;
-			t147 = t45 * t142;
-			t148 = 0.3e1 * t147;
-			t152 = t16 * del_rhoA;
-			t154 = 0.2e1 * t73 * t152;
-			t155 = t1 * del_rhoA;
-			t156 = t155 * ZA;
-			t158 = 0.2e1 * t13 * t156;
-			t159 = zc * del_rhoA;
-			t161 = 0.2e1 * t108 * t159;
-			t164 = 0.3e1 * t25 * t159 * ZB;
-			t165 = 0.2e1 * t152;
-			t169 = 0.3e1 * kn;
-			t172 = 0.2e1 * zc;
-			t175 = exp(-kn * (t172 + 0.1e1));
-			t180 = pow(0.1e1 + t45, 0.2e1);
-			t184 = exp(kn * (t172 - 0.3e1));
-			t188 = exp(-t169);
-			t217 = exp(-kn);
-			t221 = t140 * del_rhoB - t53 * (t143 + 0.6e1 * t145 - t148) * t67 - 0.2e1 * (t154 - t158 + t161 - t164 + t165) * t129 + 0.4e1 * t142 * (t169 - t57 + t73 - t71 + 0.1e1) * t53 * t175 - 0.4e1 * t142 * t180 * t53 * t184 + 0.4e1 * t142 * t38 * t188 + t38 * (0.2e1 * t145 + t143 - t147) * t51 - t53 * (-t148 - t143) * t135 + 0.2e1 * (0.4e1 * t10 * t156 - t158 + t154 - 0.4e1 * t16 * zc * t155 - 0.2e1 * del_rhoA * ZA * t43 + t164 + 0.4e1 * t108 * del_rhoA - t161 + t165) * t35 + t38 * (-t147 - t143) * t124 - 0.4e1 * t142 * (kn + 0.1e1) * t38 * t217;
-			t222 = t1 * ZB;
-			t224 = exp(0.4e1 * t50);
-			t228 = t84 * ZB;
-			t229 = t228 * zc;
-			t233 = exp(0.2e1 * kn * (-0.2e1 + zc));
-			t243 = t228 * t53;
-			t244 = t38 * t49;
-			t248 = t38 * t38;
-			t250 = exp(-0.4e1 * kn);
-			t273 = -0.2e1 * t222 * t80 * t224 - 0.8e1 * t229 * t69 * t233 - 0.2e1 * t222 * t80 * t82 + 0.8e1 * t229 * t69 * t58 + 0.8e1 * t243 * t244 * t117 + 0.2e1 * t222 * t248 * t250 - 0.8e1 * t243 * t244 * t77 + 0.16e2 * t222 * (-0.2e1 * t20 + 0.4e1 * t11 - 0.2e1 * t7 - t30 + t19 + 0.2e1 * t5 - 0.4e1 * t14) * t113 + 0.4e1 * t9 * t16 + 0.2e1 * t3 * ZB + 0.2e1 * t1 * t16 * ZB;
-			_C2B = t221 / t273;
-			
-			t1 = kn * kn;
-			t2 = ZA * ZA;
-			t3 = t1 * t2;
-			t4 = zc * zc;
-			t6 = 0.2e1 * t3 * t4;
-			t8 = 0.2e1 * t3 * zc;
-			t9 = t1 * ZA;
-			t10 = zc * ZB;
-			t12 = 0.4e1 * t9 * t10;
-			t15 = 0.4e1 * t9 * t4 * ZB;
-			t16 = ZB * ZB;
-			t17 = t1 * t16;
-			t19 = 0.2e1 * t17 * t4;
-			t21 = 0.2e1 * t17 * zc;
-			t22 = kn * t16;
-			t23 = t22 * zc;
-			t25 = ZA * kn;
-			t27 = 0.6e1 * t25 * t10;
-			t28 = kn * t2;
-			t29 = t28 * zc;
-			t31 = ZA * ZB;
-			t34 = kn * (zc + 0.1e1);
-			t35 = exp(-t34);
-			t38 = -ZB + ZA;
-			t39 = 0.2e1 * ZA;
-			t41 = t38 * (t39 + ZB);
-			t42 = zc - 0.1e1;
-			t43 = kn * t42;
-			t45 = exp(0.2e1 * t43);
-			t47 = 0.4e1 * t29;
-			t48 = 0.2e1 * t23;
-			t50 = kn * zc;
-			t51 = 0.2e1 * t50;
-			t52 = exp(-t51);
-			t55 = ZA + ZB;
-			t59 = exp(-0.2e1 * t34);
-			t61 = t38 * t55;
-			t64 = exp(kn * (zc - 0.3e1));
-			t68 = 0.2e1 * kn;
-			t69 = -0.3e1 - t68 + t51;
-			t70 = exp(t43);
-			t76 = exp(-kn * (0.3e1 * zc + 0.1e1));
-			t79 = t38 * t38;
-			t81 = exp(0.3e1 * t43);
-			t84 = exp(-0.4e1 * t50);
-			t87 = exp(-t68);
-			t90 = t55 * t55;
-			t93 = exp(-kn * (0.3e1 + zc));
-			t96 = 0.4e1 * (t6 - t8 + t12 - t15 + t19 - t21 - 0.3e1 * t23 + t27 - 0.3e1 * t29 - t31) * t35 + t41 * t45 + 0.2e1 * (t47 - t27 + t48 + t31) * t52 - t55 * (t39 - ZB) * t59 - 0.4e1 * t50 * t61 * t64 + t61 * t69 * t70 - t61 * t69 * t76 - t79 * t81 - t41 * t84 + 0.2e1 * (t47 - t27 + t48 - t31) * t87 + t90 * t93 + 0.2e1 * t2 + t31 - t16;
-			t98 = del_rhoA * ZB;
-			t104 = kn * (-0.2e1 + zc);
-			t105 = exp(t104);
-			t109 = zc * del_rhoA;
-			t112 = 0.2e1 * t25 * t109 * ZB;
-			t114 = 0.2e1 * t22 * t109;
-			t115 = t16 * del_rhoA;
-			t116 = 0.2e1 * t115;
-			t118 = del_rhoA * ZA * ZB;
-			t125 = exp(-0.3e1 * t50);
-			t132 = t38 * del_rhoA;
-			t136 = exp(-t50);
-			t142 = exp(-kn * (zc + 0.2e1));
-			t149 = t96 * del_rhoB + t98 * t55 * t59 + 0.2e1 * t98 * t38 * (t51 + 0.3e1) * t105 + 0.2e1 * (-t112 + t114 + t116 - t118) * t87 + 0.2e1 * t98 * t38 * (t51 - 0.3e1) * t125 + 0.2e1 * (-t112 + t114 + t118 - t116) * t52 + 0.3e1 * t132 * ZB * t84 + 0.2e1 * t98 * t55 * t136 - 0.2e1 * t98 * t55 * t142 - t115 - 0.3e1 * t132 * ZB * t45 - t118;
-			t150 = t1 * ZB;
-			t151 = t150 * zc;
-			t153 = exp(0.2e1 * t104);
-			t157 = kn * ZB;
-			t159 = exp(0.4e1 * t43);
-			t169 = t150 * t38;
-			t170 = t55 * t42;
-			t175 = exp(-0.4e1 * kn);
-			t193 = -0.8e1 * t151 * t61 * t153 - 0.2e1 * t157 * t79 * t159 - 0.2e1 * t157 * t79 * t84 + 0.8e1 * t151 * t61 * t52 + 0.8e1 * t169 * t170 * t45 + 0.2e1 * t157 * t90 * t175 - 0.8e1 * t169 * t170 * t59 + 0.16e2 * t157 * (-t21 + t12 - t8 - t31 + t19 + t6 - t15) * t87 + 0.4e1 * t25 * t16 + 0.2e1 * kn * t16 * ZB + 0.2e1 * t28 * ZB;
-			_C3B = t149 / t193;
-			
-			t1 = -ZB + ZA;
-			t2 = t1 * t1;
-			t3 = kn * zc;
-			t5 = exp(-0.4e1 * t3);
-			t6 = t2 * t5;
-			t7 = ZA + ZB;
-			t8 = t1 * t7;
-			t9 = 0.2e1 * t3;
-			t10 = exp(-t9);
-			t11 = t8 * t10;
-			t14 = ZA * ZA;
-			t15 = kn * t14;
-			t16 = t15 * zc;
-			t17 = 0.4e1 * t16;
-			t18 = ZA * kn;
-			t19 = zc * ZB;
-			t21 = 0.6e1 * t18 * t19;
-			t22 = ZB * ZB;
-			t23 = kn * t22;
-			t24 = t23 * zc;
-			t25 = 0.2e1 * t24;
-			t26 = ZA * ZB;
-			t30 = exp(kn * (zc - 0.3e1));
-			t33 = 0.2e1 * kn;
-			t34 = -t33 + 0.3e1 + t9;
-			t36 = kn * (zc + 0.1e1);
-			t38 = exp(-0.2e1 * t36);
-			t42 = exp(-t36);
-			t45 = kn * kn;
-			t46 = t45 * ZA;
-			t48 = 0.4e1 * t46 * t19;
-			t49 = t45 * t22;
-			t50 = zc * zc;
-			t52 = 0.2e1 * t49 * t50;
-			t55 = 0.2e1 * t49 * zc;
-			t57 = t45 * t14;
-			t59 = 0.2e1 * t57 * t50;
-			t61 = 0.2e1 * t57 * zc;
-			t64 = 0.4e1 * t46 * t50 * ZB;
-			t66 = exp(-t33);
-			t69 = 0.2e1 * ZA;
-			t71 = t7 * (t69 - ZB);
-			t72 = zc - 0.1e1;
-			t73 = kn * t72;
-			t74 = exp(t73);
-			t78 = exp(-kn * (0.3e1 + zc));
-			t81 = t1 * (t69 + ZB);
-			t85 = exp(-kn * (0.3e1 * zc + 0.1e1));
-			t88 = exp(0.3e1 * t73);
-			t91 = exp(0.2e1 * t73);
-			t95 = t6 - 0.4e1 * t3 * t11 + 0.2e1 * (t17 - t21 + t25 - t26) * t30 + t8 * t34 * t38 + 0.2e1 * (t17 - t21 + t25 + t26) * t42 - 0.4e1 * (t48 + t52 + 0.3e1 * t24 - t55 + 0.3e1 * t16 - t21 + t59 - t61 - t26 - t64) * t66 + t71 * t74 - t71 * t78 - t81 * t85 + t81 * t88 - t8 * t34 * t91 - t22 - 0.2e1 * t26 - t14;
-			t97 = t1 * del_rhoA;
-			t101 = del_rhoA * ZB;
-			t102 = exp(-kn);
-			t107 = exp(-0.3e1 * kn);
-			t111 = zc * del_rhoA;
-			t114 = 0.2e1 * t18 * t111 * ZB;
-			t116 = 0.2e1 * t23 * t111;
-			t118 = 0.2e1 * t22 * del_rhoA;
-			t120 = del_rhoA * ZA * ZB;
-			t131 = 0.2e1 * zc;
-			t134 = exp(-kn * (t131 + 0.1e1));
-			t144 = exp(kn * (t131 - 0.3e1));
-			t151 = t95 * del_rhoB + 0.3e1 * t97 * ZB * t85 + 0.2e1 * t101 * t7 * t102 - 0.2e1 * t101 * t7 * t107 + 0.2e1 * (-t114 + t116 + t118 - t120) * t30 + t101 * t7 * t78 + 0.2e1 * (-t114 + t116 + t120 - t118) * t42 + 0.2e1 * t101 * t1 * (t9 - 0.3e1) * t134 - t101 * t7 * t74 + 0.2e1 * t101 * t1 * (t9 + 0.3e1) * t144 - 0.3e1 * t97 * ZB * t88;
-			t152 = t45 * ZB;
-			t153 = t152 * zc;
-			t157 = exp(0.2e1 * kn * (-0.2e1 + zc));
-			t161 = kn * ZB;
-			t163 = exp(0.4e1 * t73);
-			t171 = t152 * t1;
-			t172 = t7 * t72;
-			t176 = t7 * t7;
-			t178 = exp(-0.4e1 * kn);
-			t196 = -0.8e1 * t153 * t8 * t157 - 0.2e1 * t161 * t2 * t163 - 0.2e1 * t161 * t6 + 0.8e1 * t153 * t11 + 0.8e1 * t171 * t172 * t91 + 0.2e1 * t161 * t176 * t178 - 0.8e1 * t171 * t172 * t38 + 0.16e2 * t161 * (-t55 + t48 - t61 - t26 + t52 + t59 - t64) * t66 + 0.4e1 * t18 * t22 + 0.2e1 * kn * t22 * ZB + 0.2e1 * t15 * ZB;
-			_C4B = t151 / t196;
-			
-		}
-		
-		/*******************************************/
-		/*       calculate the velocities etc      */
-		/*******************************************/
-		
-		if (z < zc) { 
-			
-			t4 = exp(-kn * z);
-			t10 = exp(kn * (z - zc));
-			t14 = kn * kn;
-			u1 = u1a = (_C1A + z * _C3A) * t4 + (_C2A + z * _C4A) * t10 - del_rhoA / ZA / t14;
-			
-			t1 = kn * z;
-			t2 = exp(-t1);
-			t6 = exp(kn * (z - zc));
-			t10 = 0.1e1 / kn;
-			u2 = u2a = t2 * _C1A - t6 * _C2A + t2 * (-0.1e1 + t1) * _C3A * t10 - t6 * (0.1e1 + t1) * _C4A * t10;
-			
-			t1 = ZA * kn;
-			t3 = exp(-kn * z);
-			t8 = exp(kn * (z - zc));
-			u3 = u3a = -0.2e1 * t1 * t3 * _C1A + 0.2e1 * t1 * t8 * _C2A - 0.2e1 * t1 * t3 * z * _C3A + 0.2e1 * t1 * t8 * z * _C4A;
-			
-			t2 = kn * z;
-			t6 = exp(-t2);
-			t15 = exp(kn * (z - zc));
-			u4 = u4a = -0.2e1 * ZA * (-_C3A + kn * _C1A + t2 * _C3A) * t6 - 0.2e1 * ZA * (_C4A + kn * _C2A + t2 * _C4A) * t15 + 0.1e1 / kn * del_rhoA;
-			
-			del_rho = del_rhoA;
-			Z = ZA;
-			
-		} else {
-			
-			t5 = exp(kn * (zc - z));
-			t11 = exp(kn * (z - 0.1e1));
-			t15 = kn * kn;
-			u1 = u1b = (_C1B + z * _C3B) * t5 + (_C2B + z * _C4B) * t11 - del_rhoB / ZB / t15;
-			
-			t3 = exp(kn * (zc - z));
-			t7 = exp(kn * (z - 0.1e1));
-			t9 = kn * z;
-			t12 = 0.1e1 / kn;
-			u2 = u2b = t3 * _C1B - t7 * _C2B + t3 * (-0.1e1 + t9) * _C3B * t12 - t7 * (0.1e1 + t9) * _C4B * t12;
-			
-			t1 = kn * ZB;
-			t4 = exp(kn * (zc - z));
-			t9 = exp(kn * (z - 0.1e1));
-			u3 = u3b = -0.2e1 * t1 * t4 * _C1B + 0.2e1 * t1 * t9 * _C2B - 0.2e1 * t1 * t4 * z * _C3B + 0.2e1 * t1 * t9 * z * _C4B;
-			
-			t2 = kn * z;
-			t8 = exp(kn * (zc - z));
-			t17 = exp(kn * (z - 0.1e1));
-			u4 = u4b = -0.2e1 * ZB * (-_C3B + kn * _C1B + t2 * _C3B) * t8 - 0.2e1 * ZB * (_C4B + kn * _C2B + t2 * _C4B) * t17 + 0.1e1 / kn * del_rhoB;
-			
-			
-			del_rho = del_rhoB;
-			Z = ZB;
-		}
-		
-		
-		
-		pp = (double)-(u3 + 2.0*n*M_PI*Z*u2)*cos(n*M_PI*x); /* pressure */
-		
-		txx = (double)(u3 + 4*Z*n*M_PI*u2)*cos(n*M_PI*x); /* xx stress */
-		sum5 += pp;
-		sum6 += txx;
-		
-		u1 *= cos(n*M_PI*x); /* z velocity */
-		sum1 += u1;
-		u2 *= sin(n*M_PI*x); /* x velocity */
-		sum2 += u2;
-		u3 *= cos(n*M_PI*x); /* zz stress */
-		sum3 += u3;
-		u4 *= sin(n*M_PI*x); /* zx stress */
-		sum4 += u4;
-		
-		rho = del_rho* cos(n*M_PI*x); /* density */
-		sum7 += rho;
-	}/* n */
-	
-	/* include terms for n=0 now */
-	if( z >= zc ){
-		del_rho = sigma*dx;
-		rho = del_rho; /* density */
-		sum7 += rho;
-		u3 = del_rho*(z-zc); /* zz stress */
-		sum3 += u3;
-		
-		txx = u3; /* xx stress */
-		pp = -u3; /* pressure */
-		sum5 += pp;
-		sum6 += txx;
-	} else {
-		del_rho = sigmaA*dxA;
-		rho = del_rho; /* density */
-		sum7 += rho;
-		u3 = del_rho*(z-zc); /* zz stress */
-		sum3 += u3;
-		
-		txx = u3; /* xx stress */
-		pp = -u3; /* pressure */
-		sum5 += pp;
-		sum6 += txx;
-		/* i.e. u3 for n=0 is arbitrarily set to zero at z=zc */
-	}
-	
-	mag=sqrt(sum1*sum1+sum2*sum2);
-	//printf("%0.7g %0.7g %0.7g %0.7g %0.7g %0.7g\n",x,y,z,sum3,sum2,sum1);
-	//printf("%0.7g %0.7g %0.7g\n%0.7g %0.7g %0.7g\n\n\n",x,y,z,x+sum3,y+sum2,z+sum1);
-	/*printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7);*/
-	
-	
-	/* Output */
-	if( vel != NULL ) {
-		vel[0] = sum2;
-		vel[1] = sum1;
-	}
-	if( presssure != NULL ) {
-		(*presssure) = sum5;
-	}
-	if( total_stress != NULL ) {
-		total_stress[0] = sum6;
-		total_stress[1] = sum3;
-		total_stress[2] = sum4;
-	}
-	if( strain_rate != NULL ) {
-		if( z<zc ) {
-			Z = ZA;
-		}
-		else {
-			Z = ZB;
-		}
-		strain_rate[0] = (sum6+sum5)/(2.0*Z);
-		strain_rate[1] = (sum3+sum5)/(2.0*Z);
-		strain_rate[2] = (sum4)/(2.0*Z);
-	}
-	/* Value checks, could be cleaned up if needed. Julian Giordani 9-Oct-2006*/
-        if( fabs( sum5 - ( -0.5*(sum6+sum3) ) ) > 1e-5 ) {
-                assert(0);
-        }
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solJ/solJ.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solJ/solJ.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,992 @@
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+
+void _Velic_solJ( 
+		double pos[],
+		double _sigma_B, double _sigma_A,
+		double _eta_B, double _eta_A, 
+		double _dx_B, double _dx_A,
+		double _x_0_B, double _x_0_A,
+		double _z_c,
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] );
+
+
+int main( int argc, char **argv )
+{
+	int i,j;
+	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
+	double x,z;
+	
+	for (i=0;i<101;i++){
+		for(j=0;j<101;j++){
+			x = i/100.0;
+			z = j/100.0;
+			
+			pos[0] = x;
+			pos[1] = z;
+			_Velic_solJ(
+					pos,
+					3.0, 1.0,
+					2.0, 1.0,
+					0.4, 0.3,
+					0.3, 0.6,
+					0.8,
+					vel, &pressure, total_stress, strain_rate );
+			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
+					pos[0],pos[1],
+					vel[0],vel[1], pressure, 
+					total_stress[0], total_stress[1], total_stress[2], 
+					strain_rate[0], strain_rate[1], strain_rate[2] );
+		}
+		printf("\n");
+	}
+	
+	return 0;
+}
+
+
+
+void _Velic_solJ( 
+		double pos[],
+		double _sigma_B ,double _sigma_A, /* density B, density A */
+		double _eta_B   ,double _eta_A  , /* viscosity B, viscosity A */
+		double _dx_B    ,double _dx_A   , /* width of the upper dense block, width of the lower dense block */
+		double _x_0_B   ,double _x_0_A  , /* centre of the upper dense block, centre of lower dense block */
+		double _z_c, /* bottom of the upper dense block */
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] )
+{
+	double Z,ZA,ZB,u1,u2,u3,u4,pp,txx;
+	double u1a,u2a,u3a,u4a,u1b,u2b,u3b,u4b;
+	double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,x,z;
+	double sigma,sigmaA,dx,dxA;
+	double del_rhoA,del_rhoB,del_rho;
+	int n;
+	double kn;
+	double _C1A,_C2A,_C3A,_C4A,_C1B,_C2B,_C3B,_C4B;
+	double x0,x0A,rho,zc,x0B,dxB,sigmaB;
+	
+	double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
+	double t11,t12,t13,t14,t15,t16,t17,t18,t19,t20;
+	double t21,t22,t23,t24,t25,t26,t27,t28,t29,t30;
+	double t31,t32,t33,t34,t35,t36,t37,t38,t39,t40;
+	double t41,t42,t43,t44,t45,t46,t47,t48,t49,t50;
+	double t51,t52,t53,t54,t55,t56,t57,t58,t59,t60;
+	double t61,t62,t63,t64,t66,t67,t68,t69,t70,t71;
+	double t72,t73,t74,t75,t76,t77,t78,t79,t80,t81;
+	double t82,t83,t84,t85,t86,t87,t88,t89,t90,t91;
+	double t93,t94,t95,t96,t97,t98,t99,t100,t101,t102;
+	double t103,t104,t105,t106,t107,t108,t109,t110,t111,t112;
+	double t113,t114,t115,t116,t117,t118,t119,t120,t121,t122;
+	double t123,t124,t125,t126,t128,t129,t130,t131,t132,t133;
+	double t134,t135,t136,t137,t138,t139,t140,t141,t142,t143;
+	double t144,t145,t146,t147,t148,t149,t150,t151,t152,t153;
+	double t154,t155,t156,t157,t158,t159,t160,t161,t162,t163;
+	double t164,t165,t166,t167,t168,t169,t170,t171,t172,t173;
+	double t174,t175,t176,t178,t179,t180,t181,t183,t184,t185;
+	double t186,t187,t188,t189,t191,t193,t196,t197,t200,t202;
+	double t203,t206,t207,t210,t211,t215,t217,t218,t219,t221;
+	double t222,t223,t224,t225,t226,t227,t228,t229,t232,t233;
+	double t238,t239,t243,t244,t246,t248,t250,t251,t267,t273;
+	
+	
+	
+	
+	/*************************************************************************/
+	/*************************************************************************/
+	x0 = x0B = _x_0_B;  /* centre of dense column for layer B */
+	dx = dxB = _dx_B;  /* total width of dense column  for layer B */
+	sigma = sigmaB = _sigma_B; /* density parameter for layer B (sigma_1 in _Velic_solJ.pdf) */
+	sigmaA = _sigma_A; /* density parameter for layer A (sigma_0 in _Velic_solJ.pdf) */
+	x0A = _x_0_A; /* centre of dense column for layer A */
+	dxA = _dx_A;  /* total width of dense column  for layer A (eta_0 in _Velic_solJ.pdf) */
+	ZA = _eta_A;    /* viscosity for layer A (eta_1 in _Velic_solJ.pdf) */
+	ZB = _eta_B; /* viscosity for layer B */
+	zc = _z_c;
+	/*************************************************************************/
+	/*************************************************************************/
+	
+	x = pos[0];
+	z = pos[1];
+	
+	sum1=0.0;
+	sum2=0.0;
+	sum3=0.0;
+	sum4=0.0;
+	sum5=0.0;
+	sum6=0.0;
+	sum7=0.0;
+	/* convergence is good */
+	for(n=1;n<155;n++){
+		kn = (double) n*M_PI;
+		
+		/*******************************************/
+		/*            calculate del_rho            */
+		/*******************************************/
+		del_rhoB = 4.0*sigma*cos(n*M_PI*x0)*sin(n*M_PI*dx/2.0)/n/M_PI;
+		del_rhoA = 4.0*sigmaA*cos(n*M_PI*x0A)*sin(n*M_PI*dxA/2.0)/n/M_PI;
+		
+		/*******************************************/
+		/*         calculate the constants         */
+		/*******************************************/
+		
+		if (z < zc) {
+			t1 = -ZB + ZA;
+			t2 = ZA * kn;
+			t3 = t2 * zc;
+			t4 = 0.2e1 * ZB;
+			t5 = kn * zc;
+			t7 = 0.2e1 * t5 * ZB;
+			t11 = exp(-0.3e1 * t5);
+			t13 = ZA + ZB;
+			t14 = t1 * t13;
+			t16 = pow(-0.1e1 + t5, 0.2e1);
+			t18 = kn * (-0.2e1 + zc);
+			t20 = exp(0.2e1 * t18);
+			t25 = zc - 0.1e1;
+			t26 = t13 * t25;
+			t27 = kn * t25;
+			t29 = exp(0.2e1 * t27);
+			t30 = t26 * t29;
+			t33 = kn * kn;
+			t34 = t33 * kn;
+			t35 = ZA * ZA;
+			t37 = zc * zc;
+			t38 = t37 * zc;
+			t40 = t34 * t37;
+			t42 = ZB * ZB;
+			t43 = t33 * t42;
+			t44 = t43 * t37;
+			t45 = 0.2e1 * t44;
+			t46 = t33 * t35;
+			t48 = 0.2e1 * t46 * zc;
+			t51 = 0.2e1 * t46 * t37;
+			t52 = ZA * ZB;
+			t53 = t33 * ZA;
+			t55 = t53 * t37 * ZB;
+			t56 = 0.4e1 * t55;
+			t57 = kn * t42;
+			t58 = ZB * zc;
+			t59 = t53 * t58;
+			t60 = 0.4e1 * t59;
+			t61 = t43 * zc;
+			t62 = 0.2e1 * t61;
+			t63 = t34 * ZA;
+			t67 = kn * t35;
+			t73 = t2 * t58;
+			t75 = t57 * zc;
+			t76 = t2 * ZB;
+			t77 = t34 * t35 * t38 - t40 * t35 - t45 + t48 - t40 * t42 - t51 + t52 + t56 - t57 - t60 + t62 - 0.2e1 * t63 * ZB * t38 + t67 * zc + 0.2e1 * t40 * t52 + t34 * t42 * t38 - t67 - 0.2e1 * t73 + t75 + t76;
+			t79 = exp(-0.2e1 * kn);
+			t82 = 0.6e1 * t55;
+			t83 = 0.2e1 * t52;
+			t84 = 0.4e1 * t44;
+			t85 = 0.3e1 * t73;
+			t86 = 0.4e1 * t57;
+			t87 = 0.2e1 * t76;
+			t88 = 0.4e1 * t61;
+			t89 = 0.6e1 * t59;
+			t90 = 0.4e1 * t75;
+			t91 = -t82 - t83 + t84 + t51 + t85 + t86 - t87 - t88 + t89 - t48 - t90;
+			t94 = exp(-kn * (zc + 0.2e1));
+			t99 = exp(-t5);
+			t101 = -t82 + t51 + t90 - t86 + t87 - t85 + t84 + t89 - t88 - t83 - t48;
+			t102 = exp(t18);
+			t110 = exp(kn * (0.3e1 * zc - 0.4e1));
+			t113 = exp(-0.2e1 * t5);
+			t121 = exp(kn * (zc - 0.4e1));
+			t123 = t1 * t1;
+			t125 = exp(0.4e1 * t27);
+			t126 = t123 * t125;
+			t131 = t1 * (-t3 + t4 - t7) * t11 + 0.2e1 * t14 * t16 * t20 + 0.8e1 * kn * t1 * t30 - 0.8e1 * t77 * t79 - 0.2e1 * t91 * t94 + t13 * (t3 - t4 - t7) * t99 + 0.2e1 * t101 * t102 + t1 * (-t3 - t4 - t7) * t110 - 0.2e1 * t14 * t16 * t113 + t13 * (t3 + t4 - t7) * t121 - 0.2e1 * t126 + 0.2e1 * t35 + 0.4e1 * t52 + 0.2e1 * t42;
+			t133 = ZA * del_rhoB;
+			t137 = exp(-0.3e1 * kn);
+			t141 = t33 * zc;
+			t142 = 0.2e1 * t141;
+			t143 = 0.4e1 * t5;
+			t144 = t33 * t37;
+			t145 = 0.2e1 * t144;
+			t148 = 0.2e1 * zc;
+			t151 = exp(-kn * (t148 + 0.1e1));
+			t155 = t133 * t5;
+			t156 = 0.2e1 * t133;
+			t163 = 0.3e1 * t2 * zc * del_rhoB * ZB;
+			t164 = t35 * del_rhoB;
+			t166 = 0.2e1 * t144 * t164;
+			t167 = t133 * ZB;
+			t169 = 0.2e1 * t141 * t167;
+			t172 = 0.2e1 * t133 * kn * ZB;
+			t174 = 0.2e1 * t164 * t5;
+			t176 = 0.2e1 * t144 * t167;
+			t178 = 0.2e1 * t141 * t164;
+			t179 = 0.2e1 * t164;
+			t183 = 0.3e1 * t155;
+			t197 = exp(kn * (t148 - 0.3e1));
+			t203 = exp(-kn);
+			t210 = t131 * del_rhoA - 0.2e1 * t133 * (-0.2e1 + kn) * t13 * t137 + 0.2e1 * t133 * (0.2e1 - t142 - t143 + t145 + kn) * t1 * t151 + t13 * (t155 + t156) * t99 + 0.2e1 * (-t163 + t166 + t169 + t172 + t174 - t176 - t178 + t179) * t102 + t1 * (-t156 + t183) * t11 - 0.2e1 * (-t176 + t163 + t166 - t174 - t172 - t178 + t179 + t169) * t94 + t13 * (-t156 + t155) * t121 - 0.2e1 * t133 * (-t142 + t143 + t145 + 0.2e1 - kn) * t1 * t197 - 0.2e1 * t133 * (0.2e1 + kn) * t13 * t203 + t1 * (t183 + t156) * t110;
+			t211 = t63 * zc;
+			t215 = exp(-t143);
+			t222 = t63 * t1;
+			t225 = t13 * t13;
+			t227 = exp(-0.4e1 * kn);
+			t238 = exp(-0.2e1 * kn * (zc + 0.1e1));
+			t251 = -0.8e1 * t211 * t14 * t20 - 0.2e1 * t53 * t123 * t215 + 0.8e1 * t211 * t14 * t113 + 0.8e1 * t222 * t30 + 0.2e1 * t53 * t225 * t227 + 0.16e2 * t53 * (-t62 + t60 - t48 - t52 + t45 + t51 - t56) * t79 - 0.8e1 * t222 * t26 * t238 - 0.2e1 * t53 * t126 + 0.2e1 * t33 * t35 * ZA + 0.2e1 * t53 * t42 + 0.4e1 * t46 * ZB;
+			_C1A = t210 / t251;
+			
+			t1 = -ZB + ZA;
+			t2 = ZA * kn;
+			t3 = t2 * zc;
+			t4 = 0.2e1 * ZB;
+			t5 = kn * zc;
+			t7 = 0.2e1 * t5 * ZB;
+			t11 = exp(-0.2e1 * t5);
+			t13 = kn * kn;
+			t14 = t13 * ZA;
+			t15 = zc * zc;
+			t17 = t14 * t15 * ZB;
+			t18 = 0.6e1 * t17;
+			t19 = ZA * ZA;
+			t20 = t13 * t19;
+			t22 = 0.2e1 * t20 * t15;
+			t23 = ZB * ZB;
+			t24 = kn * t23;
+			t25 = t24 * zc;
+			t26 = 0.4e1 * t25;
+			t27 = 0.4e1 * t24;
+			t28 = t2 * ZB;
+			t29 = 0.2e1 * t28;
+			t30 = zc * ZB;
+			t31 = t2 * t30;
+			t32 = 0.3e1 * t31;
+			t33 = t13 * t23;
+			t34 = t33 * t15;
+			t35 = 0.4e1 * t34;
+			t36 = t14 * t30;
+			t37 = 0.6e1 * t36;
+			t38 = t33 * zc;
+			t39 = 0.4e1 * t38;
+			t40 = ZA * ZB;
+			t41 = 0.2e1 * t40;
+			t43 = 0.2e1 * t20 * zc;
+			t44 = -t18 + t22 + t26 - t27 + t29 - t32 + t35 + t37 - t39 - t41 - t43;
+			t45 = zc - 0.1e1;
+			t46 = kn * t45;
+			t48 = exp(0.2e1 * t46);
+			t51 = t13 * kn;
+			t53 = t15 * zc;
+			t55 = t51 * t15;
+			t59 = t51 * ZA;
+			t66 = 0.4e1 * t17;
+			t67 = 0.4e1 * t36;
+			t68 = 0.2e1 * t34;
+			t69 = 0.2e1 * t38;
+			t70 = kn * t19;
+			t71 = t70 * zc;
+			t73 = t51 * t19 * t53 - t55 * t19 + 0.2e1 * t55 * t40 - 0.2e1 * t59 * ZB * t53 + t51 * t23 * t53 - t55 * t23 + t22 - t43 - t66 + t67 + t68 - t69 + t71 - t70 + t28 - 0.2e1 * t31 + t25 - t24 - t40;
+			t75 = kn * (-0.2e1 + zc);
+			t76 = exp(t75);
+			t79 = ZA + ZB;
+			t80 = t79 * t79;
+			t83 = exp(kn * (zc - 0.4e1));
+			t87 = t79 * t45;
+			t90 = exp(-kn * (zc + 0.2e1));
+			t97 = exp(0.2e1 * t75);
+			t99 = t1 * t1;
+			t101 = exp(-0.3e1 * t5);
+			t107 = exp(0.4e1 * t46);
+			t110 = -t18 - t41 + t35 + t22 + t32 + t27 - t29 - t39 + t37 - t43 - t26;
+			t112 = exp(-0.2e1 * kn);
+			t116 = t1 * t79;
+			t118 = pow(0.1e1 + t5, 0.2e1);
+			t119 = exp(-t5);
+			t126 = exp(kn * (0.3e1 * zc - 0.4e1));
+			t130 = -t1 * (-t3 + t4 - t7) * t11 - 0.2e1 * t44 * t48 + 0.8e1 * t73 * t76 + 0.2e1 * t80 * t83 - 0.8e1 * kn * t1 * t87 * t90 - t79 * (t3 + t4 - t7) * t97 - 0.2e1 * t99 * t101 - t71 + t31 - t1 * (-t3 - t4 - t7) * t107 + 0.2e1 * t23 + t41 + 0.2e1 * t110 * t112 + 0.2e1 * t25 + 0.2e1 * t116 * t118 * t119 - 0.2e1 * t116 * t118 * t126;
+			t132 = ZA * del_rhoB;
+			t133 = 0.2e1 * t132;
+			t134 = t132 * t5;
+			t138 = t19 * del_rhoB;
+			t139 = 0.2e1 * t138;
+			t140 = t132 * ZB;
+			t142 = t13 * zc;
+			t143 = 0.2e1 * t142;
+			t144 = 0.4e1 * t5;
+			t145 = t13 * t15;
+			t146 = 0.2e1 * t145;
+			t150 = exp(0.3e1 * t46);
+			t154 = 0.3e1 * t134;
+			t161 = kn * (zc + 0.1e1);
+			t162 = exp(-t161);
+			t168 = exp(t46);
+			t175 = t138 * t5;
+			t178 = t2 * zc * del_rhoB * ZB;
+			t179 = 0.3e1 * t178;
+			t181 = 0.2e1 * t145 * t138;
+			t183 = 0.2e1 * t142 * t140;
+			t186 = 0.2e1 * t132 * kn * ZB;
+			t187 = 0.2e1 * t175;
+			t189 = 0.2e1 * t145 * t140;
+			t191 = 0.2e1 * t142 * t138;
+			t202 = exp(kn * (zc - 0.3e1));
+			t206 = t130 * del_rhoA - t79 * (-t133 + t134) * t97 - t139 - 0.2e1 * t140 + 0.2e1 * t132 * (-t143 + t144 + t146 + 0.2e1 - kn) * t1 * t150 - t1 * (t154 + t133) * t107 - 0.2e1 * t132 * (0.2e1 - t143 - t144 + t146 + kn) * t1 * t162 + 0.2e1 * t132 * (0.2e1 + kn) * t79 * t168 - t1 * (-t133 + t154) * t11 - t175 - 0.2e1 * (-t179 + t181 + t183 + t186 + t187 - t189 - t191 + t139) * t48 - t178 + 0.2e1 * (-t189 + t179 + t181 - t187 - t186 - t191 + t139 + t183) * t112 + 0.2e1 * t132 * (-0.2e1 + kn) * t79 * t202;
+			t207 = t59 * zc;
+			t211 = exp(-t144);
+			t218 = t59 * t1;
+			t223 = exp(-0.4e1 * kn);
+			t232 = exp(-0.2e1 * t161);
+			t246 = -0.8e1 * t207 * t116 * t97 - 0.2e1 * t14 * t99 * t211 + 0.8e1 * t207 * t116 * t11 + 0.8e1 * t218 * t87 * t48 + 0.2e1 * t14 * t80 * t223 + 0.16e2 * t14 * (-t69 + t67 - t43 - t40 + t68 + t22 - t66) * t112 - 0.8e1 * t218 * t87 * t232 - 0.2e1 * t14 * t99 * t107 + 0.2e1 * t13 * t19 * ZA + 0.2e1 * t14 * t23 + 0.4e1 * t20 * ZB;
+			_C2A = t206 / t246;
+			
+			t1 = -ZB + ZA;
+			t2 = 0.2e1 * ZB;
+			t4 = t1 * (-ZA - t2);
+			t5 = kn * zc;
+			t7 = exp(-0.3e1 * t5);
+			t10 = ZA + ZB;
+			t11 = zc - 0.1e1;
+			t12 = t10 * t11;
+			t13 = kn * t11;
+			t15 = exp(0.2e1 * t13);
+			t16 = t12 * t15;
+			t19 = kn * kn;
+			t20 = ZA * ZA;
+			t21 = t19 * t20;
+			t22 = zc * zc;
+			t24 = 0.2e1 * t21 * t22;
+			t26 = 0.2e1 * t21 * zc;
+			t27 = t19 * ZA;
+			t28 = zc * ZB;
+			t30 = 0.4e1 * t27 * t28;
+			t33 = 0.4e1 * t27 * t22 * ZB;
+			t34 = ZB * ZB;
+			t35 = t19 * t34;
+			t37 = 0.2e1 * t35 * t22;
+			t39 = 0.2e1 * t35 * zc;
+			t40 = kn * t20;
+			t42 = t40 * zc;
+			t44 = ZA * kn;
+			t46 = 0.6e1 * t44 * t28;
+			t48 = 0.6e1 * t44 * ZB;
+			t49 = kn * t34;
+			t51 = t49 * zc;
+			t53 = ZA * ZB;
+			t54 = t24 - t26 + t30 - t33 + t37 - t39 + 0.3e1 * t40 - 0.3e1 * t42 + t46 - t48 + 0.3e1 * t49 - 0.3e1 * t51 - t53;
+			t55 = 0.2e1 * kn;
+			t56 = exp(-t55);
+			t59 = t1 * t10;
+			t60 = 0.2e1 * t5;
+			t61 = t60 - 0.3e1;
+			t62 = exp(-t60);
+			t66 = t10 * (ZA - t2);
+			t67 = exp(-t5);
+			t70 = kn * (-0.2e1 + zc);
+			t72 = exp(0.2e1 * t70);
+			t78 = exp(kn * (0.3e1 * zc - 0.4e1));
+			t80 = 0.2e1 * t40;
+			t81 = 0.2e1 * t42;
+			t82 = 0.4e1 * t49;
+			t83 = 0.4e1 * t51;
+			t85 = exp(t70);
+			t90 = exp(kn * (zc - 0.4e1));
+			t95 = exp(-kn * (zc + 0.2e1));
+			t98 = t1 * t1;
+			t100 = exp(0.4e1 * t13);
+			t101 = t98 * t100;
+			t103 = -t4 * t7 + 0.4e1 * kn * t1 * t16 + 0.4e1 * t54 * t56 + t59 * t61 * t62 + t66 * t67 - t59 * t61 * t72 + t4 * t78 + 0.2e1 * (-t80 + t48 + t81 - t82 - t53 - t46 + t83) * t85 - t66 * t90 + 0.2e1 * (-t80 + t48 + t81 - t82 + t53 - t46 + t83) * t95 - t101 + t34 + t20 + 0.2e1 * t53;
+			t105 = ZA * del_rhoB;
+			t108 = 0.2e1 * zc;
+			t111 = exp(-kn * (t108 + 0.1e1));
+			t116 = exp(-0.3e1 * kn);
+			t120 = t1 * ZA;
+			t126 = 0.2e1 * del_rhoB * kn * t20;
+			t130 = 0.2e1 * t44 * zc * del_rhoB * ZB;
+			t133 = 0.2e1 * t105 * kn * ZB;
+			t134 = t20 * del_rhoB;
+			t136 = 0.2e1 * t134 * t5;
+			t137 = 0.2e1 * t134;
+			t138 = t105 * ZB;
+			t151 = exp(kn * (t108 - 0.3e1));
+			t160 = exp(-kn);
+			t164 = t103 * del_rhoA - 0.2e1 * t105 * t1 * (-0.3e1 - t55 + t60) * t111 + 0.2e1 * t105 * t10 * t116 + 0.3e1 * t120 * del_rhoB * t78 + 0.2e1 * (-t126 - t130 + t133 + t136 + t137 - t138) * t85 - t105 * t10 * t90 + 0.2e1 * (-t126 - t130 + t133 + t136 + t138 - t137) * t95 - 0.2e1 * t105 * t1 * (-t55 + 0.3e1 + t60) * t151 - 0.3e1 * t120 * del_rhoB * t7 + t105 * t10 * t67 - 0.2e1 * t105 * t10 * t160;
+			t165 = t27 * zc;
+			t169 = t27 * t1;
+			t173 = exp(-0.2e1 * kn * (zc + 0.1e1));
+			t178 = exp(-0.4e1 * t5);
+			t187 = t10 * t10;
+			t189 = exp(-0.4e1 * kn);
+			t206 = -0.8e1 * t165 * t59 * t72 - 0.8e1 * t169 * t12 * t173 - 0.2e1 * t44 * t98 * t178 + 0.8e1 * t165 * t59 * t62 + 0.8e1 * t169 * t16 + 0.2e1 * t44 * t187 * t189 + 0.16e2 * t44 * (-t39 + t30 - t26 - t53 + t37 + t24 - t33) * t56 - 0.2e1 * t44 * t101 + 0.4e1 * t40 * ZB + 0.2e1 * kn * t20 * ZA + 0.2e1 * t44 * t34;
+			_C3A = t164 / t206;
+			
+			t1 = ZB * ZB;
+			t2 = kn * t1;
+			t3 = t2 * zc;
+			t5 = ZA * ZA;
+			t6 = kn * t5;
+			t8 = kn * kn;
+			t9 = t8 * t1;
+			t11 = 0.2e1 * t9 * zc;
+			t12 = t8 * t5;
+			t13 = zc * zc;
+			t15 = 0.2e1 * t12 * t13;
+			t16 = ZA * ZB;
+			t18 = 0.2e1 * t12 * zc;
+			t19 = ZA * kn;
+			t21 = 0.6e1 * t19 * ZB;
+			t22 = t8 * ZA;
+			t25 = 0.4e1 * t22 * t13 * ZB;
+			t27 = 0.2e1 * t9 * t13;
+			t28 = zc * ZB;
+			t30 = 0.6e1 * t19 * t28;
+			t32 = t6 * zc;
+			t35 = 0.4e1 * t22 * t28;
+			t36 = 0.3e1 * t3 - 0.3e1 * t6 - t11 + t15 - t16 - t18 + t21 - t25 + t27 - t30 - 0.3e1 * t2 + 0.3e1 * t32 + t35;
+			t38 = kn * (-0.2e1 + zc);
+			t39 = exp(t38);
+			t42 = -ZB + ZA;
+			t43 = 0.2e1 * ZB;
+			t45 = t42 * (-ZA - t43);
+			t46 = kn * zc;
+			t47 = 0.2e1 * t46;
+			t48 = exp(-t47);
+			t50 = 0.2e1 * t6;
+			t51 = 0.2e1 * t32;
+			t52 = 0.4e1 * t2;
+			t53 = 0.4e1 * t3;
+			t55 = 0.2e1 * kn;
+			t56 = exp(-t55);
+			t59 = t42 * t42;
+			t61 = exp(-0.3e1 * t46);
+			t63 = ZA + ZB;
+			t67 = exp(0.2e1 * t38);
+			t69 = t42 * t63;
+			t70 = t47 + 0.3e1;
+			t71 = exp(-t46);
+			t74 = t63 * t63;
+			t77 = exp(kn * (zc - 0.4e1));
+			t82 = exp(kn * (0.3e1 * zc - 0.4e1));
+			t85 = zc - 0.1e1;
+			t86 = kn * t85;
+			t88 = exp(0.4e1 * t86);
+			t93 = exp(0.2e1 * t86);
+			t97 = t63 * t85;
+			t100 = exp(-kn * (zc + 0.2e1));
+			t104 = -0.4e1 * t36 * t39 - t45 * t48 + 0.2e1 * (-t50 + t21 + t51 - t52 + t16 - t30 + t53) * t56 + t59 * t61 - t63 * (ZA - t43) * t67 - t69 * t70 * t71 - t74 * t77 + t69 * t70 * t82 + t45 * t88 - t16 - 0.2e1 * t1 + t5 + 0.2e1 * (-t50 + t21 + t51 - t52 - t16 - t30 + t53) * t93 + 0.4e1 * kn * t42 * t97 * t100;
+			t106 = ZA * del_rhoB;
+			t110 = kn * (zc + 0.1e1);
+			t111 = exp(-t110);
+			t120 = exp(0.3e1 * t86);
+			t126 = exp(kn * (zc - 0.3e1));
+			t132 = 0.2e1 * del_rhoB * kn * t5;
+			t136 = 0.2e1 * t19 * zc * del_rhoB * ZB;
+			t139 = 0.2e1 * t106 * kn * ZB;
+			t140 = t5 * del_rhoB;
+			t142 = 0.2e1 * t140 * t46;
+			t143 = t106 * ZB;
+			t144 = 0.2e1 * t140;
+			t148 = exp(t86);
+			t152 = t42 * ZA;
+			t162 = t104 * del_rhoA - 0.2e1 * t106 * t42 * (-0.3e1 - t55 + t47) * t111 - t106 * t63 * t67 - 0.2e1 * t106 * t42 * (-t55 + 0.3e1 + t47) * t120 + 0.2e1 * t106 * t63 * t126 + 0.2e1 * (-t132 - t136 + t139 + t142 + t143 - t144) * t56 - 0.2e1 * t106 * t63 * t148 + t143 - 0.3e1 * t152 * del_rhoB * t48 + 0.2e1 * (-t132 - t136 + t139 + t142 + t144 - t143) * t93 + 0.3e1 * t152 * del_rhoB * t88 + t140;
+			t163 = t22 * zc;
+			t167 = t22 * t42;
+			t169 = exp(-0.2e1 * t110);
+			t174 = exp(-0.4e1 * t46);
+			t185 = exp(-0.4e1 * kn);
+			t203 = -0.8e1 * t163 * t69 * t67 - 0.8e1 * t167 * t97 * t169 - 0.2e1 * t19 * t59 * t174 + 0.8e1 * t163 * t69 * t48 + 0.8e1 * t167 * t97 * t93 + 0.2e1 * t19 * t74 * t185 + 0.16e2 * t19 * (-t11 + t35 - t18 - t16 + t27 + t15 - t25) * t56 - 0.2e1 * t19 * t59 * t88 + 0.4e1 * t6 * ZB + 0.2e1 * kn * t5 * ZA + 0.2e1 * t19 * t1;
+			_C4A = t162 / t203;
+		} else {
+			t1 = ZA * kn;
+			t2 = t1 * ZB;
+			t3 = zc * ZB;
+			t4 = t1 * t3;
+			t6 = kn * kn;
+			t7 = ZB * ZB;
+			t8 = t6 * t7;
+			t9 = zc * zc;
+			t10 = t8 * t9;
+			t12 = ZA * ZA;
+			t14 = kn * t12 * zc;
+			t15 = 0.2e1 * t14;
+			t16 = t8 * zc;
+			t17 = t6 * kn;
+			t18 = t17 * t9;
+			t21 = kn * t7;
+			t22 = t21 * zc;
+			t25 = t9 * zc;
+			t35 = t6 * ZA;
+			t36 = t9 * ZB;
+			t37 = t35 * t36;
+			t39 = t6 * t12;
+			t40 = t39 * zc;
+			t41 = t35 * t3;
+			t43 = t39 * t9;
+			t44 = 0.4e1 * t43;
+			t47 = ZA * ZB;
+			t48 = 0.2e1 * t47;
+			t51 = t2 - 0.4e1 * t4 - 0.4e1 * t10 + t15 + t16 - 0.2e1 * t18 * t12 + 0.2e1 * t22 + 0.2e1 * t17 * t7 * t25 - 0.4e1 * t17 * ZA * ZB * t25 + 0.2e1 * t17 * t12 * t25 + 0.8e1 * t37 + t40 - 0.2e1 * t41 - t44 - 0.2e1 * t18 * t7 + t48 + 0.4e1 * t18 * t47;
+			t53 = kn * (zc + 0.1e1);
+			t54 = exp(-t53);
+			t57 = 0.6e1 * t37;
+			t58 = 0.2e1 * t10;
+			t59 = 0.4e1 * t14;
+			t60 = 0.3e1 * t4;
+			t62 = kn * zc;
+			t63 = 0.2e1 * t62;
+			t64 = exp(-t63);
+			t67 = -ZB + ZA;
+			t69 = 0.2e1 * t1 * zc;
+			t70 = 0.4e1 * t1;
+			t71 = 0.2e1 * ZA;
+			t72 = t62 * ZB;
+			t73 = kn * ZB;
+			t74 = 0.2e1 * t73;
+			t77 = zc - 0.1e1;
+			t78 = kn * t77;
+			t80 = exp(0.2e1 * t78);
+			t82 = ZA + ZB;
+			t83 = t67 * t82;
+			t85 = 0.2e1 * t6 * zc;
+			t86 = 0.4e1 * t62;
+			t87 = t6 * t9;
+			t89 = 0.2e1 - t85 - t86 + 0.2e1 * t87 + kn;
+			t90 = exp(t78);
+			t93 = t82 * t82;
+			t94 = -0.2e1 + kn;
+			t98 = exp(-kn * (0.3e1 + zc));
+			t100 = t67 * t67;
+			t103 = exp(0.3e1 * t78);
+			t107 = exp(-t86);
+			t115 = exp(-0.2e1 * kn);
+			t122 = exp(-kn * (0.3e1 * zc + 0.1e1));
+			t128 = exp(-0.2e1 * t53);
+			t134 = exp(kn * (zc - 0.3e1));
+			t138 = -0.4e1 * t51 * t54 - 0.2e1 * (-t57 + t58 - t59 + t60 + t44 - t48) * t64 + t67 * (t69 - t70 + t71 + t72 - t74) * t80 - t83 * t89 * t90 - t93 * t94 * t98 + t100 * t94 * t103 + t67 * (-t71 + t69 + t72) * t107 + 0.2e1 * (0.12e2 * t41 - t48 - t57 - 0.4e1 * t16 + t59 - t60 + t58 + t44 + 0.2e1 * t2 - 0.8e1 * t40) * t115 - t15 - t4 + 0.2e1 * t12 + t22 + t48 + t83 * t89 * t122 - t82 * (-t70 + t71 + t69 + t74 - t72) * t128 + 0.4e1 * t62 * t67 * t82 * t94 * t134;
+			t141 = del_rhoA * kn * ZB;
+			t143 = del_rhoA * ZB;
+			t144 = 0.2e1 * t143;
+			t145 = t62 * t143;
+			t153 = kn * (-0.2e1 + zc);
+			t154 = exp(t153);
+			t159 = t6 * del_rhoA;
+			t162 = del_rhoA * ZA;
+			t165 = zc * del_rhoA;
+			t166 = t21 * t165;
+			t167 = 0.2e1 * t166;
+			t168 = t159 * ZA;
+			t170 = 0.2e1 * t36 * t168;
+			t171 = t7 * del_rhoA;
+			t172 = 0.2e1 * t171;
+			t178 = 0.2e1 * t87 * t171;
+			t180 = t1 * t165 * ZB;
+			t181 = 0.3e1 * t180;
+			t186 = pow(-0.1e1 + t62, 0.2e1);
+			t189 = exp(-0.3e1 * t62);
+			t196 = 0.3e1 * t145;
+			t200 = exp(-t62);
+			t210 = exp(-kn * (zc + 0.2e1));
+			t218 = t138 * del_rhoB - t82 * (0.2e1 * t141 - t144 - t145) * t128 + 0.4e1 * t143 * (0.1e1 - 0.3e1 * kn + t87 - t85 + t63) * t67 * t154 + 0.2e1 * (-0.4e1 * t7 * zc * t159 + 0.2e1 * t162 * t73 + t167 - t170 + t172 + 0.4e1 * t3 * t168 - 0.4e1 * t21 * del_rhoA + t178 - t181) * t115 - 0.4e1 * t143 * t186 * t67 * t189 - 0.2e1 * (t181 + t172 - t170 - t167 + t178) * t64 + t67 * (-t196 + t144) * t107 + 0.4e1 * t143 * t82 * t200 - 0.2e1 * t162 * ZB + 0.4e1 * t143 * (kn - 0.1e1) * t82 * t210 + t166 + t67 * (0.6e1 * t141 - t196 - t144) * t80 + t180 - t172;
+			t219 = t6 * ZB;
+			t221 = exp(0.4e1 * t78);
+			t225 = t17 * ZB;
+			t226 = t225 * zc;
+			t228 = exp(0.2e1 * t153);
+			t238 = t225 * t67;
+			t239 = t82 * t77;
+			t244 = exp(-0.4e1 * kn);
+			t267 = -0.2e1 * t219 * t100 * t221 - 0.8e1 * t226 * t83 * t228 - 0.2e1 * t219 * t100 * t107 + 0.8e1 * t226 * t83 * t64 + 0.8e1 * t238 * t239 * t80 + 0.2e1 * t219 * t93 * t244 - 0.8e1 * t238 * t239 * t128 + 0.16e2 * t219 * (-0.2e1 * t16 + 0.4e1 * t41 - 0.2e1 * t40 - t47 + t58 + 0.2e1 * t43 - 0.4e1 * t37) * t115 + 0.4e1 * t35 * t7 + 0.2e1 * t39 * ZB + 0.2e1 * t6 * t7 * ZB;
+			_C1B = t218 / t267;
+			
+			t1 = kn * kn;
+			t2 = ZA * ZA;
+			t3 = t1 * t2;
+			t4 = zc * zc;
+			t5 = t3 * t4;
+			t6 = 0.4e1 * t5;
+			t7 = t3 * zc;
+			t9 = t1 * ZA;
+			t10 = zc * ZB;
+			t11 = t9 * t10;
+			t13 = t4 * ZB;
+			t14 = t9 * t13;
+			t15 = 0.6e1 * t14;
+			t16 = ZB * ZB;
+			t17 = t1 * t16;
+			t18 = t17 * t4;
+			t19 = 0.2e1 * t18;
+			t20 = t17 * zc;
+			t22 = kn * t2;
+			t23 = t22 * zc;
+			t24 = 0.4e1 * t23;
+			t25 = ZA * kn;
+			t26 = t25 * ZB;
+			t27 = 0.2e1 * t26;
+			t28 = t25 * t10;
+			t29 = 0.3e1 * t28;
+			t30 = ZA * ZB;
+			t31 = 0.2e1 * t30;
+			t34 = kn * (zc + 0.1e1);
+			t35 = exp(-t34);
+			t38 = ZA + ZB;
+			t39 = 0.2e1 * ZA;
+			t41 = 0.2e1 * t25 * zc;
+			t42 = 0.4e1 * t25;
+			t43 = kn * ZB;
+			t44 = 0.2e1 * t43;
+			t45 = kn * zc;
+			t46 = t45 * ZB;
+			t49 = zc - 0.1e1;
+			t50 = kn * t49;
+			t51 = exp(t50);
+			t53 = -ZB + ZA;
+			t55 = 0.2e1 + kn;
+			t57 = 0.2e1 * t45;
+			t58 = exp(-t57);
+			t67 = exp(-kn * (0.3e1 * zc + 0.1e1));
+			t69 = t53 * t38;
+			t71 = 0.2e1 * t1 * zc;
+			t72 = 0.4e1 * t45;
+			t73 = t1 * t4;
+			t75 = -t71 + t72 + 0.2e1 * t73 + 0.2e1 - kn;
+			t77 = exp(-0.2e1 * t34);
+			t80 = t53 * t53;
+			t82 = exp(-t72);
+			t84 = t1 * kn;
+			t86 = t4 * zc;
+			t89 = t84 * t4;
+			t108 = kn * t16;
+			t111 = 0.2e1 * t84 * t2 * t86 - 0.2e1 * t89 * t2 + 0.4e1 * t89 * t30 - 0.4e1 * t84 * ZA * ZB * t86 + 0.2e1 * t84 * t16 * t86 - 0.2e1 * t89 * t16 - t7 + t6 + 0.2e1 * t11 - 0.8e1 * t14 - t20 + 0.4e1 * t18 + 0.2e1 * t23 + t26 - 0.4e1 * t28 + 0.2e1 * t108 * zc - t31;
+			t113 = exp(-0.2e1 * kn);
+			t117 = exp(0.2e1 * t50);
+			t124 = exp(-kn * (0.3e1 + zc));
+			t129 = exp(kn * (zc - 0.3e1));
+			t135 = exp(0.3e1 * t50);
+			t140 = 0.2e1 * (t6 - 0.8e1 * t7 + 0.12e2 * t11 - t15 + t19 - 0.4e1 * t20 - t24 - t27 + t29 - t31) * t35 + t38 * (-t39 + t41 - t42 + t44 - t46) * t51 + 0.4e1 * t45 * t53 * t38 * t55 * t58 - t53 * (-t39 - t42 + t41 - t44 + t46) * t67 - t69 * t75 * t77 - t80 * t55 * t82 + 0.4e1 * t111 * t113 + t69 * t75 * t117 + t38 * (t41 + t39 - t46) * t124 - 0.2e1 * (t6 + t19 - t15 - t29 + t24 - t31) * t129 - t53 * (t39 + t46 + t41) * t135 + t27 + 0.2e1 * t16 + t108 + t22 + 0.4e1 * t30 + 0.2e1 * t2;
+			t142 = del_rhoA * ZB;
+			t143 = 0.2e1 * t142;
+			t145 = del_rhoA * kn * ZB;
+			t147 = t45 * t142;
+			t148 = 0.3e1 * t147;
+			t152 = t16 * del_rhoA;
+			t154 = 0.2e1 * t73 * t152;
+			t155 = t1 * del_rhoA;
+			t156 = t155 * ZA;
+			t158 = 0.2e1 * t13 * t156;
+			t159 = zc * del_rhoA;
+			t161 = 0.2e1 * t108 * t159;
+			t164 = 0.3e1 * t25 * t159 * ZB;
+			t165 = 0.2e1 * t152;
+			t169 = 0.3e1 * kn;
+			t172 = 0.2e1 * zc;
+			t175 = exp(-kn * (t172 + 0.1e1));
+			t180 = pow(0.1e1 + t45, 0.2e1);
+			t184 = exp(kn * (t172 - 0.3e1));
+			t188 = exp(-t169);
+			t217 = exp(-kn);
+			t221 = t140 * del_rhoB - t53 * (t143 + 0.6e1 * t145 - t148) * t67 - 0.2e1 * (t154 - t158 + t161 - t164 + t165) * t129 + 0.4e1 * t142 * (t169 - t57 + t73 - t71 + 0.1e1) * t53 * t175 - 0.4e1 * t142 * t180 * t53 * t184 + 0.4e1 * t142 * t38 * t188 + t38 * (0.2e1 * t145 + t143 - t147) * t51 - t53 * (-t148 - t143) * t135 + 0.2e1 * (0.4e1 * t10 * t156 - t158 + t154 - 0.4e1 * t16 * zc * t155 - 0.2e1 * del_rhoA * ZA * t43 + t164 + 0.4e1 * t108 * del_rhoA - t161 + t165) * t35 + t38 * (-t147 - t143) * t124 - 0.4e1 * t142 * (kn + 0.1e1) * t38 * t217;
+			t222 = t1 * ZB;
+			t224 = exp(0.4e1 * t50);
+			t228 = t84 * ZB;
+			t229 = t228 * zc;
+			t233 = exp(0.2e1 * kn * (-0.2e1 + zc));
+			t243 = t228 * t53;
+			t244 = t38 * t49;
+			t248 = t38 * t38;
+			t250 = exp(-0.4e1 * kn);
+			t273 = -0.2e1 * t222 * t80 * t224 - 0.8e1 * t229 * t69 * t233 - 0.2e1 * t222 * t80 * t82 + 0.8e1 * t229 * t69 * t58 + 0.8e1 * t243 * t244 * t117 + 0.2e1 * t222 * t248 * t250 - 0.8e1 * t243 * t244 * t77 + 0.16e2 * t222 * (-0.2e1 * t20 + 0.4e1 * t11 - 0.2e1 * t7 - t30 + t19 + 0.2e1 * t5 - 0.4e1 * t14) * t113 + 0.4e1 * t9 * t16 + 0.2e1 * t3 * ZB + 0.2e1 * t1 * t16 * ZB;
+			_C2B = t221 / t273;
+			
+			t1 = kn * kn;
+			t2 = ZA * ZA;
+			t3 = t1 * t2;
+			t4 = zc * zc;
+			t6 = 0.2e1 * t3 * t4;
+			t8 = 0.2e1 * t3 * zc;
+			t9 = t1 * ZA;
+			t10 = zc * ZB;
+			t12 = 0.4e1 * t9 * t10;
+			t15 = 0.4e1 * t9 * t4 * ZB;
+			t16 = ZB * ZB;
+			t17 = t1 * t16;
+			t19 = 0.2e1 * t17 * t4;
+			t21 = 0.2e1 * t17 * zc;
+			t22 = kn * t16;
+			t23 = t22 * zc;
+			t25 = ZA * kn;
+			t27 = 0.6e1 * t25 * t10;
+			t28 = kn * t2;
+			t29 = t28 * zc;
+			t31 = ZA * ZB;
+			t34 = kn * (zc + 0.1e1);
+			t35 = exp(-t34);
+			t38 = -ZB + ZA;
+			t39 = 0.2e1 * ZA;
+			t41 = t38 * (t39 + ZB);
+			t42 = zc - 0.1e1;
+			t43 = kn * t42;
+			t45 = exp(0.2e1 * t43);
+			t47 = 0.4e1 * t29;
+			t48 = 0.2e1 * t23;
+			t50 = kn * zc;
+			t51 = 0.2e1 * t50;
+			t52 = exp(-t51);
+			t55 = ZA + ZB;
+			t59 = exp(-0.2e1 * t34);
+			t61 = t38 * t55;
+			t64 = exp(kn * (zc - 0.3e1));
+			t68 = 0.2e1 * kn;
+			t69 = -0.3e1 - t68 + t51;
+			t70 = exp(t43);
+			t76 = exp(-kn * (0.3e1 * zc + 0.1e1));
+			t79 = t38 * t38;
+			t81 = exp(0.3e1 * t43);
+			t84 = exp(-0.4e1 * t50);
+			t87 = exp(-t68);
+			t90 = t55 * t55;
+			t93 = exp(-kn * (0.3e1 + zc));
+			t96 = 0.4e1 * (t6 - t8 + t12 - t15 + t19 - t21 - 0.3e1 * t23 + t27 - 0.3e1 * t29 - t31) * t35 + t41 * t45 + 0.2e1 * (t47 - t27 + t48 + t31) * t52 - t55 * (t39 - ZB) * t59 - 0.4e1 * t50 * t61 * t64 + t61 * t69 * t70 - t61 * t69 * t76 - t79 * t81 - t41 * t84 + 0.2e1 * (t47 - t27 + t48 - t31) * t87 + t90 * t93 + 0.2e1 * t2 + t31 - t16;
+			t98 = del_rhoA * ZB;
+			t104 = kn * (-0.2e1 + zc);
+			t105 = exp(t104);
+			t109 = zc * del_rhoA;
+			t112 = 0.2e1 * t25 * t109 * ZB;
+			t114 = 0.2e1 * t22 * t109;
+			t115 = t16 * del_rhoA;
+			t116 = 0.2e1 * t115;
+			t118 = del_rhoA * ZA * ZB;
+			t125 = exp(-0.3e1 * t50);
+			t132 = t38 * del_rhoA;
+			t136 = exp(-t50);
+			t142 = exp(-kn * (zc + 0.2e1));
+			t149 = t96 * del_rhoB + t98 * t55 * t59 + 0.2e1 * t98 * t38 * (t51 + 0.3e1) * t105 + 0.2e1 * (-t112 + t114 + t116 - t118) * t87 + 0.2e1 * t98 * t38 * (t51 - 0.3e1) * t125 + 0.2e1 * (-t112 + t114 + t118 - t116) * t52 + 0.3e1 * t132 * ZB * t84 + 0.2e1 * t98 * t55 * t136 - 0.2e1 * t98 * t55 * t142 - t115 - 0.3e1 * t132 * ZB * t45 - t118;
+			t150 = t1 * ZB;
+			t151 = t150 * zc;
+			t153 = exp(0.2e1 * t104);
+			t157 = kn * ZB;
+			t159 = exp(0.4e1 * t43);
+			t169 = t150 * t38;
+			t170 = t55 * t42;
+			t175 = exp(-0.4e1 * kn);
+			t193 = -0.8e1 * t151 * t61 * t153 - 0.2e1 * t157 * t79 * t159 - 0.2e1 * t157 * t79 * t84 + 0.8e1 * t151 * t61 * t52 + 0.8e1 * t169 * t170 * t45 + 0.2e1 * t157 * t90 * t175 - 0.8e1 * t169 * t170 * t59 + 0.16e2 * t157 * (-t21 + t12 - t8 - t31 + t19 + t6 - t15) * t87 + 0.4e1 * t25 * t16 + 0.2e1 * kn * t16 * ZB + 0.2e1 * t28 * ZB;
+			_C3B = t149 / t193;
+			
+			t1 = -ZB + ZA;
+			t2 = t1 * t1;
+			t3 = kn * zc;
+			t5 = exp(-0.4e1 * t3);
+			t6 = t2 * t5;
+			t7 = ZA + ZB;
+			t8 = t1 * t7;
+			t9 = 0.2e1 * t3;
+			t10 = exp(-t9);
+			t11 = t8 * t10;
+			t14 = ZA * ZA;
+			t15 = kn * t14;
+			t16 = t15 * zc;
+			t17 = 0.4e1 * t16;
+			t18 = ZA * kn;
+			t19 = zc * ZB;
+			t21 = 0.6e1 * t18 * t19;
+			t22 = ZB * ZB;
+			t23 = kn * t22;
+			t24 = t23 * zc;
+			t25 = 0.2e1 * t24;
+			t26 = ZA * ZB;
+			t30 = exp(kn * (zc - 0.3e1));
+			t33 = 0.2e1 * kn;
+			t34 = -t33 + 0.3e1 + t9;
+			t36 = kn * (zc + 0.1e1);
+			t38 = exp(-0.2e1 * t36);
+			t42 = exp(-t36);
+			t45 = kn * kn;
+			t46 = t45 * ZA;
+			t48 = 0.4e1 * t46 * t19;
+			t49 = t45 * t22;
+			t50 = zc * zc;
+			t52 = 0.2e1 * t49 * t50;
+			t55 = 0.2e1 * t49 * zc;
+			t57 = t45 * t14;
+			t59 = 0.2e1 * t57 * t50;
+			t61 = 0.2e1 * t57 * zc;
+			t64 = 0.4e1 * t46 * t50 * ZB;
+			t66 = exp(-t33);
+			t69 = 0.2e1 * ZA;
+			t71 = t7 * (t69 - ZB);
+			t72 = zc - 0.1e1;
+			t73 = kn * t72;
+			t74 = exp(t73);
+			t78 = exp(-kn * (0.3e1 + zc));
+			t81 = t1 * (t69 + ZB);
+			t85 = exp(-kn * (0.3e1 * zc + 0.1e1));
+			t88 = exp(0.3e1 * t73);
+			t91 = exp(0.2e1 * t73);
+			t95 = t6 - 0.4e1 * t3 * t11 + 0.2e1 * (t17 - t21 + t25 - t26) * t30 + t8 * t34 * t38 + 0.2e1 * (t17 - t21 + t25 + t26) * t42 - 0.4e1 * (t48 + t52 + 0.3e1 * t24 - t55 + 0.3e1 * t16 - t21 + t59 - t61 - t26 - t64) * t66 + t71 * t74 - t71 * t78 - t81 * t85 + t81 * t88 - t8 * t34 * t91 - t22 - 0.2e1 * t26 - t14;
+			t97 = t1 * del_rhoA;
+			t101 = del_rhoA * ZB;
+			t102 = exp(-kn);
+			t107 = exp(-0.3e1 * kn);
+			t111 = zc * del_rhoA;
+			t114 = 0.2e1 * t18 * t111 * ZB;
+			t116 = 0.2e1 * t23 * t111;
+			t118 = 0.2e1 * t22 * del_rhoA;
+			t120 = del_rhoA * ZA * ZB;
+			t131 = 0.2e1 * zc;
+			t134 = exp(-kn * (t131 + 0.1e1));
+			t144 = exp(kn * (t131 - 0.3e1));
+			t151 = t95 * del_rhoB + 0.3e1 * t97 * ZB * t85 + 0.2e1 * t101 * t7 * t102 - 0.2e1 * t101 * t7 * t107 + 0.2e1 * (-t114 + t116 + t118 - t120) * t30 + t101 * t7 * t78 + 0.2e1 * (-t114 + t116 + t120 - t118) * t42 + 0.2e1 * t101 * t1 * (t9 - 0.3e1) * t134 - t101 * t7 * t74 + 0.2e1 * t101 * t1 * (t9 + 0.3e1) * t144 - 0.3e1 * t97 * ZB * t88;
+			t152 = t45 * ZB;
+			t153 = t152 * zc;
+			t157 = exp(0.2e1 * kn * (-0.2e1 + zc));
+			t161 = kn * ZB;
+			t163 = exp(0.4e1 * t73);
+			t171 = t152 * t1;
+			t172 = t7 * t72;
+			t176 = t7 * t7;
+			t178 = exp(-0.4e1 * kn);
+			t196 = -0.8e1 * t153 * t8 * t157 - 0.2e1 * t161 * t2 * t163 - 0.2e1 * t161 * t6 + 0.8e1 * t153 * t11 + 0.8e1 * t171 * t172 * t91 + 0.2e1 * t161 * t176 * t178 - 0.8e1 * t171 * t172 * t38 + 0.16e2 * t161 * (-t55 + t48 - t61 - t26 + t52 + t59 - t64) * t66 + 0.4e1 * t18 * t22 + 0.2e1 * kn * t22 * ZB + 0.2e1 * t15 * ZB;
+			_C4B = t151 / t196;
+			
+		}
+		
+		/*******************************************/
+		/*       calculate the velocities etc      */
+		/*******************************************/
+		
+		if (z < zc) { 
+			
+			t4 = exp(-kn * z);
+			t10 = exp(kn * (z - zc));
+			t14 = kn * kn;
+			u1 = u1a = (_C1A + z * _C3A) * t4 + (_C2A + z * _C4A) * t10 - del_rhoA / ZA / t14;
+			
+			t1 = kn * z;
+			t2 = exp(-t1);
+			t6 = exp(kn * (z - zc));
+			t10 = 0.1e1 / kn;
+			u2 = u2a = t2 * _C1A - t6 * _C2A + t2 * (-0.1e1 + t1) * _C3A * t10 - t6 * (0.1e1 + t1) * _C4A * t10;
+			
+			t1 = ZA * kn;
+			t3 = exp(-kn * z);
+			t8 = exp(kn * (z - zc));
+			u3 = u3a = -0.2e1 * t1 * t3 * _C1A + 0.2e1 * t1 * t8 * _C2A - 0.2e1 * t1 * t3 * z * _C3A + 0.2e1 * t1 * t8 * z * _C4A;
+			
+			t2 = kn * z;
+			t6 = exp(-t2);
+			t15 = exp(kn * (z - zc));
+			u4 = u4a = -0.2e1 * ZA * (-_C3A + kn * _C1A + t2 * _C3A) * t6 - 0.2e1 * ZA * (_C4A + kn * _C2A + t2 * _C4A) * t15 + 0.1e1 / kn * del_rhoA;
+			
+			del_rho = del_rhoA;
+			Z = ZA;
+			
+		} else {
+			
+			t5 = exp(kn * (zc - z));
+			t11 = exp(kn * (z - 0.1e1));
+			t15 = kn * kn;
+			u1 = u1b = (_C1B + z * _C3B) * t5 + (_C2B + z * _C4B) * t11 - del_rhoB / ZB / t15;
+			
+			t3 = exp(kn * (zc - z));
+			t7 = exp(kn * (z - 0.1e1));
+			t9 = kn * z;
+			t12 = 0.1e1 / kn;
+			u2 = u2b = t3 * _C1B - t7 * _C2B + t3 * (-0.1e1 + t9) * _C3B * t12 - t7 * (0.1e1 + t9) * _C4B * t12;
+			
+			t1 = kn * ZB;
+			t4 = exp(kn * (zc - z));
+			t9 = exp(kn * (z - 0.1e1));
+			u3 = u3b = -0.2e1 * t1 * t4 * _C1B + 0.2e1 * t1 * t9 * _C2B - 0.2e1 * t1 * t4 * z * _C3B + 0.2e1 * t1 * t9 * z * _C4B;
+			
+			t2 = kn * z;
+			t8 = exp(kn * (zc - z));
+			t17 = exp(kn * (z - 0.1e1));
+			u4 = u4b = -0.2e1 * ZB * (-_C3B + kn * _C1B + t2 * _C3B) * t8 - 0.2e1 * ZB * (_C4B + kn * _C2B + t2 * _C4B) * t17 + 0.1e1 / kn * del_rhoB;
+			
+			
+			del_rho = del_rhoB;
+			Z = ZB;
+		}
+		
+		
+		
+		pp = (double)-(u3 + 2.0*n*M_PI*Z*u2)*cos(n*M_PI*x); /* pressure */
+		
+		txx = (double)(u3 + 4*Z*n*M_PI*u2)*cos(n*M_PI*x); /* xx stress */
+		sum5 += pp;
+		sum6 += txx;
+		
+		u1 *= cos(n*M_PI*x); /* z velocity */
+		sum1 += u1;
+		u2 *= sin(n*M_PI*x); /* x velocity */
+		sum2 += u2;
+		u3 *= cos(n*M_PI*x); /* zz stress */
+		sum3 += u3;
+		u4 *= sin(n*M_PI*x); /* zx stress */
+		sum4 += u4;
+		
+		rho = del_rho* cos(n*M_PI*x); /* density */
+		sum7 += rho;
+	}/* n */
+	
+	/* include terms for n=0 now */
+	if( z >= zc ){
+		del_rho = sigma*dx;
+		rho = del_rho; /* density */
+		sum7 += rho;
+		u3 = del_rho*(z-zc); /* zz stress */
+		sum3 += u3;
+		
+		txx = u3; /* xx stress */
+		pp = -u3; /* pressure */
+		sum5 += pp;
+		sum6 += txx;
+	} else {
+		del_rho = sigmaA*dxA;
+		rho = del_rho; /* density */
+		sum7 += rho;
+		u3 = del_rho*(z-zc); /* zz stress */
+		sum3 += u3;
+		
+		txx = u3; /* xx stress */
+		pp = -u3; /* pressure */
+		sum5 += pp;
+		sum6 += txx;
+		/* i.e. u3 for n=0 is arbitrarily set to zero at z=zc */
+	}
+	
+	mag=sqrt(sum1*sum1+sum2*sum2);
+	//printf("%0.7g %0.7g %0.7g %0.7g %0.7g %0.7g\n",x,y,z,sum3,sum2,sum1);
+	//printf("%0.7g %0.7g %0.7g\n%0.7g %0.7g %0.7g\n\n\n",x,y,z,x+sum3,y+sum2,z+sum1);
+	/*printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7);*/
+	
+	
+	/* Output */
+	if( vel != NULL ) {
+		vel[0] = sum2;
+		vel[1] = sum1;
+	}
+	if( presssure != NULL ) {
+		(*presssure) = sum5;
+	}
+	if( total_stress != NULL ) {
+		total_stress[0] = sum6;
+		total_stress[1] = sum3;
+		total_stress[2] = sum4;
+	}
+	if( strain_rate != NULL ) {
+		if( z<zc ) {
+			Z = ZA;
+		}
+		else {
+			Z = ZB;
+		}
+		strain_rate[0] = (sum6+sum5)/(2.0*Z);
+		strain_rate[1] = (sum3+sum5)/(2.0*Z);
+		strain_rate[2] = (sum4)/(2.0*Z);
+	}
+	/* Value checks, could be cleaned up if needed. Julian Giordani 9-Oct-2006*/
+        if( fabs( sum5 - ( -0.5*(sum6+sum3) ) ) > 1e-5 ) {
+                assert(0);
+        }
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solJA/Analytic_solJA.c
--- a/SysTest/AnalyticPlugins/Velic_solJA/Analytic_solJA.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,165 +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:
-*+		Mirko Velic
-*+		Julian Giordani
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Patrick Sunter
-** $Id: solJA.c 636 2006-09-08 03:07:06Z JulianGiordani $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include "Analytic_solJA.h"
-
-const Type Velic_solJA_Type = "Underworld_Velic_solJA";
-
-void Velic_solJA_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
-	Velic_solJA* self = (Velic_solJA*) analyticSolution;
-	
-	_Velic_solJA( coord, self->sigma, self->etaA, self->etaB, self->dx, self->x0, self->zc,
-		       	NULL, pressure, NULL, NULL );
-}
-
-void Velic_solJA_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
-	Velic_solJA* self = (Velic_solJA*) analyticSolution;
-	
-	_Velic_solJA( coord, self->sigma, self->etaA, self->etaB, self->dx, self->x0, self->zc,
-		       	velocity, NULL, NULL, NULL );
-}
-
-void Velic_solJA_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
-	Velic_solJA* self = (Velic_solJA*) analyticSolution;
-	
-	_Velic_solJA( coord, self->sigma, self->etaA, self->etaB, self->dx, self->x0, self->zc,
-		       	NULL, NULL, stress, NULL );
-}
-
-
-void Velic_solJA_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
-	Velic_solJA* self = (Velic_solJA*) analyticSolution;
-	
-	_Velic_solJA( coord, self->sigma, self->etaA, self->etaB, self->dx, self->x0, self->zc,
-		       	NULL, NULL, NULL, strainRate );
-}
-
-void _Velic_solJA_Init( Velic_solJA* self, double sigma, double etaA, double etaB, double dx, double x0, double zc ) {
-	// TODO	Bool                     correctInput = True;
-	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
-        self->_getAnalyticVelocity    = Velic_solJA_VelocityFunction;
-	self->_getAnalyticPressure    = Velic_solJA_PressureFunction;
-	self->_getAnalyticTotalStress = Velic_solJA_StressFunction;
-	self->_getAnalyticStrainRate  = Velic_solJA_StrainRateFunction;
-
-	self->sigma = sigma;
-	self->etaA = etaA;
-	self->etaB = etaB;
-	self->dx = dx;
-	self->x0 = x0;
-	self->zc = zc;
-}
-
-void _Velic_solJA_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
-	Velic_solJA* self = (Velic_solJA*) analyticSolution;
-	FeVariable*              velocityField;
-	FeVariable*              pressureField;
-	FeVariable*              stressField;
-	FeVariable*              strainRateField;
-	FeVariable*              recoveredStrainRateField;
-	FeVariable*              recoveredStressField;
-	double                   sigma, etaA, etaB, dx, x0, zc;
-
-	/* Construct Parent */
-	_AnalyticSolution_AssignFromXML( self, cf, data );
-
-	/* Create Analytic Fields */
-	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solJA_VelocityFunction );
-
-	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solJA_PressureFunction );
-
-	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False, data );
-	if ( stressField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solJA_StressFunction );
-
-	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
-	if ( strainRateField   ) {
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solJA_StrainRateFunction );
-	}
-
-	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
-	if ( recoveredStrainRateField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solJA_StrainRateFunction );
-
-	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
-	if ( recoveredStressField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solJA_StressFunction );
-	
-	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJA_sigma", 1.0  );
-	etaA = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJA_etaA", 100.0  );
-	etaB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJA_etaB", 1.0  );
-	dx = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJA_dx", 0.4  );
-	x0 = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJA_x0", 0.2  );
-	zc = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJA_zc", 0.8  );
-
-	_Velic_solJA_Init( self, sigma, etaA, etaB, dx, x0, zc );
-
-}
-
-void* _Velic_solJA_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Velic_solJA);
-	Type                                                      type = Velic_solJA_Type;
-	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
-	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
-	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solJA_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Velic_solJA_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _AnalyticSolution_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 Underworld_Velic_solJA_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Velic_solJA_Type, (Name)"0", _Velic_solJA_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solJA/Analytic_solJA.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solJA/Analytic_solJA.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,165 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Mirko Velic
+*+		Julian Giordani
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Patrick Sunter
+** $Id: solJA.c 636 2006-09-08 03:07:06Z JulianGiordani $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include "Analytic_solJA.h"
+
+const Type Velic_solJA_Type = "Underworld_Velic_solJA";
+
+void Velic_solJA_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
+	Velic_solJA* self = (Velic_solJA*) analyticSolution;
+	
+	_Velic_solJA( coord, self->sigma, self->etaA, self->etaB, self->dx, self->x0, self->zc,
+		       	NULL, pressure, NULL, NULL );
+}
+
+void Velic_solJA_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
+	Velic_solJA* self = (Velic_solJA*) analyticSolution;
+	
+	_Velic_solJA( coord, self->sigma, self->etaA, self->etaB, self->dx, self->x0, self->zc,
+		       	velocity, NULL, NULL, NULL );
+}
+
+void Velic_solJA_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
+	Velic_solJA* self = (Velic_solJA*) analyticSolution;
+	
+	_Velic_solJA( coord, self->sigma, self->etaA, self->etaB, self->dx, self->x0, self->zc,
+		       	NULL, NULL, stress, NULL );
+}
+
+
+void Velic_solJA_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
+	Velic_solJA* self = (Velic_solJA*) analyticSolution;
+	
+	_Velic_solJA( coord, self->sigma, self->etaA, self->etaB, self->dx, self->x0, self->zc,
+		       	NULL, NULL, NULL, strainRate );
+}
+
+void _Velic_solJA_Init( Velic_solJA* self, double sigma, double etaA, double etaB, double dx, double x0, double zc ) {
+	// TODO	Bool                     correctInput = True;
+	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
+        self->_getAnalyticVelocity    = Velic_solJA_VelocityFunction;
+	self->_getAnalyticPressure    = Velic_solJA_PressureFunction;
+	self->_getAnalyticTotalStress = Velic_solJA_StressFunction;
+	self->_getAnalyticStrainRate  = Velic_solJA_StrainRateFunction;
+
+	self->sigma = sigma;
+	self->etaA = etaA;
+	self->etaB = etaB;
+	self->dx = dx;
+	self->x0 = x0;
+	self->zc = zc;
+}
+
+void _Velic_solJA_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
+	Velic_solJA* self = (Velic_solJA*) analyticSolution;
+	FeVariable*              velocityField;
+	FeVariable*              pressureField;
+	FeVariable*              stressField;
+	FeVariable*              strainRateField;
+	FeVariable*              recoveredStrainRateField;
+	FeVariable*              recoveredStressField;
+	double                   sigma, etaA, etaB, dx, x0, zc;
+
+	/* Construct Parent */
+	_AnalyticSolution_AssignFromXML( self, cf, data );
+
+	/* Create Analytic Fields */
+	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solJA_VelocityFunction );
+
+	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solJA_PressureFunction );
+
+	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False, data );
+	if ( stressField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solJA_StressFunction );
+
+	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
+	if ( strainRateField   ) {
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solJA_StrainRateFunction );
+	}
+
+	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
+	if ( recoveredStrainRateField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solJA_StrainRateFunction );
+
+	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
+	if ( recoveredStressField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solJA_StressFunction );
+	
+	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJA_sigma", 1.0  );
+	etaA = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJA_etaA", 100.0  );
+	etaB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJA_etaB", 1.0  );
+	dx = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJA_dx", 0.4  );
+	x0 = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJA_x0", 0.2  );
+	zc = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solJA_zc", 0.8  );
+
+	_Velic_solJA_Init( self, sigma, etaA, etaB, dx, x0, zc );
+
+}
+
+void* _Velic_solJA_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Velic_solJA);
+	Type                                                      type = Velic_solJA_Type;
+	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
+	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
+	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solJA_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Velic_solJA_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _AnalyticSolution_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 Underworld_Velic_solJA_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Velic_solJA_Type, (Name)"0", _Velic_solJA_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solJA/solJA.c
--- a/SysTest/AnalyticPlugins/Velic_solJA/solJA.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,720 +0,0 @@
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-
-
-void _Velic_solJA( 
-		double pos[],
-		double _sigma,
-		double _eta_A, double _eta_B,
-		double _dx,
-		double _x_0, double _z_c,
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] );
-
-
-int main( int argc, char **argv )
-{
-	int i,j;
-	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
-	double x,z;
-	
-	for (i=0;i<101;i++){
-		for(j=0;j<101;j++){
-			x = i/100.0;
-			z = j/100.0;
-			
-			pos[0] = x;
-			pos[1] = z;
-			_Velic_solJA(
-					pos,
-					1.0,
-					100.0, 1.0,
-					0.4,
-					0.2, 0.8,
-					vel, &pressure, total_stress, strain_rate );
-			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
-					pos[0],pos[1],
-					vel[0],vel[1], pressure, 
-					total_stress[0], total_stress[1], total_stress[2], 
-					strain_rate[0], strain_rate[1], strain_rate[2] );
-		}
-		printf("\n");
-	}
-	
-	return 0;
-}
-
-
-
-
-void _Velic_solJA( 
-		double pos[],
-		double _sigma, /* density */
-		double _eta_A, double _eta_B, /* viscosity A, viscosity B */
-		double _dx, /* width of upper dense block */
-		double _x_0, double _z_c, /* centre of upper dense block, bottom of upper dense block */
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] )
-{
-	double Z,ZA,ZB,u1,u2,u3,u4,pp,txx;
-	double u1a,u2a,u3a,u4a,u1b,u2b,u3b,u4b;
-	double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,x,z;
-	double sigma,dx;
-	double del_rho;
-	int n;
-	double kn;
-	double _C1A,_C2A,_C3A,_C4A,_C1B,_C2B,_C3B,_C4B;
-	double x0,rho,zc;
-	
-	double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
-	double t11,t12,t13,t14,t15,t16,t17,t18,t19,t20;
-	double t21,t22,t23,t24,t25,t26,t27,t28,t29,t30;
-	double t31,t32,t33,t34,t35,t36,t37,t38,t39,t40;
-	double t41,t42,t43,t44,t45,t46,t47,t48,t49,t50;
-	double t51,t52,t53,t54,t55,t56,t57,t58,t59,t60;
-	double t61,t62,t63,t64,t65,t66,t67,t68,t69,t70;
-	double t71,t72,t73,t74,t75,t76,t77,t78,t79,t80;
-	double t81,t82,t83,t85,t86,t87,t88,t89,t90,t91;
-	double t92,t93,t94,t95,t96,t97,t98,t99,t100,t101;
-	double t102,t103,t104,t105,t106,t107,t108,t109,t111,t112;
-	double t113,t114,t115,t116,t117,t118,t120,t121,t122,t124;
-	double t125,t126,t127,t128,t129,t130,t131,t133,t134,t135;
-	double t136,t137,t139,t141,t143,t144,t145,t146,t147,t148;
-	double t151,t152,t153,t154,t156,t157,t158,t159,t162,t163;
-	double t165,t167,t168,t190,t195;
-	
-	/*************************************************************************/
-	/*************************************************************************/
-	/*
-	In layer B (the top layer) we have a dense column of density sigma
-	ranging from x=x0-dx/2 to x= x0+dx/2:
-	The viscosity of layer B is ZB:
-	The viscosity of layer A is ZA:
-	
-	If one wants a dense column from x=0 to x=dx then just set x0=dx/2
-	
-	*/
-	/*************************************************************************/
-	/*************************************************************************/
-	
-	/*************************************************************************/
-	/*************************************************************************/
-	x0 = _x_0;  /* centre of dense column for layer B */
-	dx = _dx;  /* total width of dense column  for layer B */
-	sigma = _sigma; /* density parameter for layer B */
-	ZA = _eta_A;    /* viscosity for layer A */
-	ZB = _eta_B; /* viscosity for layer B */
-	zc = _z_c;  /* dividing line between region B and region A */
-	/*************************************************************************/
-	/*************************************************************************/
-	
-	x = pos[0];
-	z = pos[1];
-	
-	sum1=0.0;
-	sum2=0.0;
-	sum3=0.0;
-	sum4=0.0;
-	sum5=0.0;
-	sum6=0.0;
-	sum7=0.0;
-	/* this one blows up when n gets around 85 for some reason... if max n is set to 75 it is fine though */
-	/* fixed the convergence problem */
-	for(n=1;n<55;n++){
-		kn = (double) n*M_PI;
-		
-		/*******************************************/
-		/*            calculate del_rho            */
-		/*******************************************/
-		del_rho = 4.0*sigma*cos(n*M_PI*x0)*sin(n*M_PI*dx/2.0)/n/M_PI;
-		/* we can have any del_rho we like here as long as it is independent of z */
-		
-		
-		/*******************************************/
-		/*         calculate the constants         */
-		/*******************************************/
-		
-		if ( z < zc ) {
-			t1 = kn * zc;
-			t2 = 0.4e1 * t1;
-			t3 = kn * kn;
-			t5 = 0.2e1 * t3 * zc;
-			t6 = zc * zc;
-			t7 = t6 * t3;
-			t8 = 0.2e1 * t7;
-			t10 = ZA - ZB;
-			t12 = 0.2e1 * zc;
-			t15 = exp(-kn * (0.1e1 + t12));
-			t22 = exp(kn * (t12 - 0.3e1));
-			t26 = ZA + ZB;
-			t29 = exp(-0.3e1 * kn);
-			t34 = exp(-kn);
-			t37 = 0.3e1 * t1;
-			t40 = exp(-t37);
-			t44 = exp(-t1);
-			t50 = exp(kn * (zc - 0.4e1));
-			t54 = 0.2e1 * ZA * kn * zc;
-			t56 = 0.2e1 * ZB * kn;
-			t57 = 0.2e1 * ZA;
-			t58 = t3 * ZA;
-			t60 = 0.2e1 * t58 * zc;
-			t63 = 0.3e1 * ZB * zc * kn;
-			t64 = t3 * ZB;
-			t66 = 0.2e1 * t64 * zc;
-			t68 = 0.2e1 * t64 * t6;
-			t70 = 0.2e1 * t58 * t6;
-			t73 = kn * (zc - 0.2e1);
-			t74 = exp(t73);
-			t82 = exp(kn * (0.3e1 * zc - 0.4e1));
-			t87 = exp(-kn * (0.2e1 + zc));
-			t92 = t10 * t10;
-			t93 = t3 * t92;
-			t94 = exp(-t2);
-			t97 = t26 * t26;
-			t100 = exp(-0.4e1 * kn);
-			t103 = t3 * kn;
-			t104 = t103 * t10;
-			t105 = zc - 0.1e1;
-			t106 = t26 * t105;
-			t107 = kn * t105;
-			t109 = exp(0.2e1 * t107);
-			t114 = exp(0.4e1 * t107);
-			t117 = t103 * zc;
-			t118 = t10 * t26;
-			t120 = exp(0.2e1 * t73);
-			t124 = ZA * ZA;
-			t125 = t3 * t124;
-			t128 = ZB * ZB;
-			t136 = ZA * ZB;
-			t145 = exp(-0.2e1 * kn);
-			t151 = exp(-0.2e1 * kn * (0.1e1 + zc));
-			t156 = exp(-0.2e1 * t1);
-			t165 = -0.2e1 * t93 * t94 + 0.2e1 * t3 * t97 * t100 + 0.8e1 * t104 * t106 * t109 - 0.2e1 * t93 * t114 - 0.8e1 * t117 * t118 * t120 + 0.16e2 * t3 * (-0.2e1 * t125 * zc + 0.2e1 * t7 * t128 + 0.2e1 * t7 * t124 - 0.2e1 * t128 * zc * t3 - t136 - 0.4e1 * t7 * t136 + 0.4e1 * t64 * ZA * zc) * t145 - 0.8e1 * t104 * t106 * t151 + 0.8e1 * t117 * t118 * t156 + 0.4e1 * t64 * ZA + 0.2e1 * t3 * t128 + 0.2e1 * t125;
-			_C1A = (0.2e1 * (-t2 - t5 + t8 + 0.2e1 + kn) * t10 * t15 - 0.2e1 * (0.2e1 - t5 + t2 + t8 - kn) * t10 * t22 - 0.2e1 * (-0.2e1 + kn) * t26 * t29 - 0.2e1 * (kn + 0.2e1) * t26 * t34 + (t37 - 0.2e1) * t10 * t40 + (t1 + 0.2e1) * t26 * t44 + (t1 - 0.2e1) * t26 * t50 + 0.2e1 * (t54 + t56 + t57 - t60 - t63 + t66 - t68 + t70) * t74 + (t37 + 0.2e1) * t10 * t82 - 0.2e1 * (-t68 + t63 - t60 + t70 - t56 + t57 - t54 + t66) * t87) * del_rho / t165;
-			
-			t1 = kn * kn;
-			t3 = 0.2e1 * t1 * zc;
-			t4 = kn * zc;
-			t5 = 0.4e1 * t4;
-			t6 = zc * zc;
-			t7 = t6 * t1;
-			t8 = 0.2e1 * t7;
-			t10 = ZA - ZB;
-			t12 = zc - 0.1e1;
-			t13 = kn * t12;
-			t15 = exp(0.3e1 * t13);
-			t19 = ZA + ZB;
-			t24 = exp(0.2e1 * kn * (zc - 0.2e1));
-			t26 = t1 * ZB;
-			t28 = 0.2e1 * t26 * t6;
-			t30 = ZB * zc * kn;
-			t31 = 0.3e1 * t30;
-			t32 = t1 * ZA;
-			t34 = 0.2e1 * t32 * zc;
-			t36 = 0.2e1 * t32 * t6;
-			t38 = 0.2e1 * ZB * kn;
-			t39 = 0.2e1 * ZA;
-			t41 = ZA * kn * zc;
-			t42 = 0.2e1 * t41;
-			t44 = 0.2e1 * t26 * zc;
-			t47 = exp(-0.2e1 * kn);
-			t52 = exp(t13);
-			t57 = exp(0.2e1 * t13);
-			t64 = exp(kn * (zc - 0.3e1));
-			t67 = 0.3e1 * t4;
-			t71 = exp(-0.2e1 * t4);
-			t76 = kn * (0.1e1 + zc);
-			t77 = exp(-t76);
-			t83 = exp(0.4e1 * t13);
-			t86 = 0.2e1 * (0.2e1 - t3 + t5 + t8 - kn) * t10 * t15 - (t4 - 0.2e1) * t19 * t24 + 0.2e1 * (-t28 + t31 - t34 + t36 - t38 + t39 - t42 + t44) * t47 + 0.2e1 * (kn + 0.2e1) * t19 * t52 - 0.2e1 * (t42 + t38 + t39 - t34 - t31 + t44 - t28 + t36) * t57 + 0.2e1 * (-0.2e1 + kn) * t19 * t64 - (t67 - 0.2e1) * t10 * t71 - 0.2e1 * (-t5 - t3 + t8 + 0.2e1 + kn) * t10 * t77 - (t67 + 0.2e1) * t10 * t83 - 0.2e1 * ZB - t39 - t30 - t41;
-			t88 = t10 * t10;
-			t89 = t1 * t88;
-			t90 = exp(-t5);
-			t93 = t19 * t19;
-			t96 = exp(-0.4e1 * kn);
-			t99 = t1 * kn;
-			t100 = t99 * t10;
-			t101 = t19 * t12;
-			t107 = t99 * zc;
-			t108 = t10 * t19;
-			t112 = ZA * ZA;
-			t113 = t1 * t112;
-			t116 = ZB * ZB;
-			t124 = ZA * ZB;
-			t135 = exp(-0.2e1 * t76);
-			t147 = -0.2e1 * t89 * t90 + 0.2e1 * t1 * t93 * t96 + 0.8e1 * t100 * t101 * t57 - 0.2e1 * t89 * t83 - 0.8e1 * t107 * t108 * t24 + 0.16e2 * t1 * (-0.2e1 * t113 * zc + 0.2e1 * t7 * t116 + 0.2e1 * t7 * t112 - 0.2e1 * t116 * zc * t1 - t124 - 0.4e1 * t7 * t124 + 0.4e1 * t26 * ZA * zc) * t47 - 0.8e1 * t100 * t101 * t135 + 0.8e1 * t107 * t108 * t71 + 0.4e1 * t26 * ZA + 0.2e1 * t1 * t116 + 0.2e1 * t113;
-			_C2A = t86 * del_rho / t147;
-			
-			t1 = kn * zc;
-			t2 = 0.2e1 * t1;
-			t3 = 0.2e1 * kn;
-			t5 = ZA - ZB;
-			t7 = 0.2e1 * zc;
-			t10 = exp(-kn * (0.1e1 + t7));
-			t17 = exp(kn * (t7 - 0.3e1));
-			t20 = ZA + ZB;
-			t22 = exp(-0.3e1 * kn);
-			t25 = exp(-kn);
-			t29 = exp(-0.3e1 * t1);
-			t32 = exp(-t1);
-			t36 = exp(kn * (zc - 0.4e1));
-			t38 = ZA * kn;
-			t40 = 0.2e1 * t38 * zc;
-			t41 = 0.2e1 * t38;
-			t43 = 0.2e1 * ZB * kn;
-			t44 = 0.2e1 * ZA;
-			t47 = 0.2e1 * ZB * zc * kn;
-			t50 = kn * (zc - 0.2e1);
-			t51 = exp(t50);
-			t57 = exp(kn * (0.3e1 * zc - 0.4e1));
-			t63 = exp(-kn * (0.2e1 + zc));
-			t68 = t5 * t5;
-			t69 = kn * t68;
-			t71 = exp(-0.4e1 * t1);
-			t74 = t20 * t20;
-			t77 = exp(-0.4e1 * kn);
-			t80 = kn * kn;
-			t81 = t80 * t5;
-			t82 = zc - 0.1e1;
-			t83 = t20 * t82;
-			t87 = exp(-0.2e1 * kn * (0.1e1 + zc));
-			t91 = t80 * zc;
-			t92 = t5 * t20;
-			t94 = exp(0.2e1 * t50);
-			t98 = ZA * ZA;
-			t102 = zc * zc;
-			t103 = t102 * t80;
-			t104 = ZB * ZB;
-			t112 = ZA * ZB;
-			t121 = exp(-t3);
-			t124 = kn * t82;
-			t126 = exp(0.2e1 * t124);
-			t130 = exp(-t2);
-			t135 = exp(0.4e1 * t124);
-			t144 = -0.2e1 * t69 * t71 + 0.2e1 * t74 * kn * t77 - 0.8e1 * t81 * t83 * t87 - 0.8e1 * t91 * t92 * t94 + 0.16e2 * kn * (-0.2e1 * t80 * t98 * zc + 0.2e1 * t103 * t104 + 0.2e1 * t103 * t98 - 0.2e1 * t104 * zc * t80 - t112 - 0.4e1 * t103 * t112 + 0.4e1 * ZB * t80 * ZA * zc) * t121 + 0.8e1 * t81 * t83 * t126 + 0.8e1 * t91 * t92 * t130 - 0.2e1 * t69 * t135 + 0.2e1 * kn * t104 + 0.2e1 * t98 * kn + 0.4e1 * t112 * kn;
-			_C3A = (-0.2e1 * (t2 - 0.3e1 - t3) * t5 * t10 - 0.2e1 * (t2 + 0.3e1 - t3) * t5 * t17 + 0.2e1 * t20 * t22 - 0.2e1 * t20 * t25 - 0.3e1 * t5 * t29 + t20 * t32 - t20 * t36 + 0.2e1 * (t40 - t41 + t43 + t44 - ZB - t47) * t51 + 0.3e1 * t5 * t57 + 0.2e1 * (-t41 + t43 + ZB - t47 + t40 - t44) * t63) * del_rho / t144;
-			
-			t1 = ZA + ZB;
-			t5 = exp(0.2e1 * kn * (zc - 0.2e1));
-			t7 = ZA * kn;
-			t8 = 0.2e1 * t7;
-			t10 = 0.2e1 * ZB * kn;
-			t13 = 0.2e1 * ZB * zc * kn;
-			t15 = 0.2e1 * t7 * zc;
-			t16 = 0.2e1 * ZA;
-			t18 = 0.2e1 * kn;
-			t19 = exp(-t18);
-			t24 = exp(kn * (zc - 0.3e1));
-			t27 = kn * zc;
-			t28 = 0.2e1 * t27;
-			t30 = ZA - ZB;
-			t33 = kn * (0.1e1 + zc);
-			t34 = exp(-t33);
-			t38 = zc - 0.1e1;
-			t39 = kn * t38;
-			t41 = exp(0.2e1 * t39);
-			t47 = exp(0.3e1 * t39);
-			t50 = exp(-t28);
-			t53 = exp(t39);
-			t57 = exp(0.4e1 * t39);
-			t60 = -t1 * t5 + 0.2e1 * (-t8 + t10 + ZB - t13 + t15 - t16) * t19 + 0.2e1 * t1 * t24 - 0.2e1 * (t28 - 0.3e1 - t18) * t30 * t34 + 0.2e1 * (t15 - t8 + t10 + t16 - ZB - t13) * t41 - 0.2e1 * (t28 + 0.3e1 - t18) * t30 * t47 - 0.3e1 * t30 * t50 - 0.2e1 * t1 * t53 + 0.3e1 * t30 * t57 + ZA + ZB;
-			t62 = t30 * t30;
-			t63 = kn * t62;
-			t65 = exp(-0.4e1 * t27);
-			t68 = t1 * t1;
-			t71 = exp(-0.4e1 * kn);
-			t74 = kn * kn;
-			t75 = t74 * t30;
-			t76 = t1 * t38;
-			t78 = exp(-0.2e1 * t33);
-			t82 = t74 * zc;
-			t83 = t30 * t1;
-			t87 = ZA * ZA;
-			t91 = zc * zc;
-			t92 = t91 * t74;
-			t93 = ZB * ZB;
-			t101 = ZA * ZB;
-			t126 = -0.2e1 * t63 * t65 + 0.2e1 * t68 * kn * t71 - 0.8e1 * t75 * t76 * t78 - 0.8e1 * t82 * t83 * t5 + 0.16e2 * kn * (-0.2e1 * t74 * t87 * zc + 0.2e1 * t92 * t93 + 0.2e1 * t92 * t87 - 0.2e1 * t93 * zc * t74 - t101 - 0.4e1 * t92 * t101 + 0.4e1 * ZB * t74 * ZA * zc) * t19 + 0.8e1 * t75 * t76 * t41 + 0.8e1 * t82 * t83 * t50 - 0.2e1 * t63 * t57 + 0.2e1 * kn * t93 + 0.2e1 * t87 * kn + 0.4e1 * t101 * kn;
-			_C4A = t60 * del_rho / t126;
-		} else { 
-			t1 = ZA - ZB;
-			t2 = ZA * kn;
-			t4 = 0.2e1 * t2 * zc;
-			t5 = 0.2e1 * ZA;
-			t7 = ZB * zc * kn;
-			t10 = kn * zc;
-			t11 = 0.4e1 * t10;
-			t12 = exp(-t11);
-			t14 = ZA + ZB;
-			t15 = 0.4e1 * t2;
-			t17 = 0.2e1 * ZB * kn;
-			t21 = kn * (0.1e1 + zc);
-			t23 = exp(-0.2e1 * t21);
-			t25 = kn * kn;
-			t26 = ZA * ZA;
-			t28 = t25 * t26 * zc;
-			t30 = zc * zc;
-			t31 = t30 * t25;
-			t32 = t31 * t26;
-			t33 = 0.4e1 * t32;
-			t34 = ZB * t25;
-			t36 = t34 * ZA * zc;
-			t39 = t26 * zc * kn;
-			t40 = 0.4e1 * t39;
-			t41 = ZA * ZB;
-			t42 = t41 * kn;
-			t44 = ZB * ZB;
-			t45 = t44 * zc;
-			t46 = t45 * t25;
-			t48 = t41 * t10;
-			t49 = 0.3e1 * t48;
-			t50 = t31 * t44;
-			t51 = 0.2e1 * t50;
-			t52 = 0.2e1 * t41;
-			t53 = t31 * t41;
-			t54 = 0.6e1 * t53;
-			t57 = exp(-0.2e1 * kn);
-			t64 = (-t11 - 0.2e1 * t25 * zc + 0.2e1 * t31 + 0.2e1 + kn) * t1;
-			t68 = exp(-kn * (0.1e1 + 0.3e1 * zc));
-			t72 = -0.2e1 + kn;
-			t76 = exp(kn * (zc - 0.3e1));
-			t80 = t25 * kn;
-			t81 = t30 * t80;
-			t85 = t30 * zc;
-			t91 = t45 * kn;
-			t97 = 0.2e1 * t39;
-			t106 = -0.2e1 * t81 * t44 + 0.2e1 * t44 * t80 * t85 + 0.2e1 * t26 * t80 * t85 + t52 + t42 + 0.2e1 * t91 + 0.8e1 * t53 + 0.4e1 * t81 * t41 - 0.4e1 * t48 + t46 + t97 - 0.2e1 * t36 - t33 - 0.4e1 * t41 * t80 * t85 - 0.4e1 * t50 - 0.2e1 * t26 * t30 * t80 + t28;
-			t107 = exp(-t21);
-			t112 = zc - 0.1e1;
-			t113 = kn * t112;
-			t115 = exp(0.2e1 * t113);
-			t117 = t1 * t1;
-			t120 = exp(0.3e1 * t113);
-			t124 = exp(-0.2e1 * t10);
-			t127 = t14 * t14;
-			t131 = exp(-kn * (zc + 0.3e1));
-			t133 = exp(t113);
-			t137 = t1 * (t4 - t5 + t7) * t12 - t14 * (t5 + t4 - t15 - t7 + t17) * t23 + 0.2e1 * (-0.8e1 * t28 + t33 + 0.12e2 * t36 + t40 + 0.2e1 * t42 - 0.4e1 * t46 - t49 + t51 - t52 - t54) * t57 + t64 * t14 * t68 + 0.4e1 * t10 * t1 * t14 * t72 * t76 - 0.4e1 * t106 * t107 + t1 * (t5 + t4 - t15 + t7 - t17) * t115 + t117 * t72 * t120 - 0.2e1 * (t49 - t54 + t33 + t51 - t52 - t40) * t124 - t127 * t72 * t131 - t64 * t14 * t133 - t48 + 0.2e1 * t26 - t97 + t52 + t91;
-			t143 = exp(-0.4e1 * kn);
-			t148 = exp(0.4e1 * t113);
-			t152 = t80 * ZB;
-			t153 = t152 * zc;
-			t154 = t1 * t14;
-			t158 = exp(0.2e1 * kn * (zc - 0.2e1));
-			t162 = t152 * t1;
-			t163 = t14 * t112;
-			t190 = -0.2e1 * t34 * t117 * t12 + 0.2e1 * t34 * t127 * t143 - 0.2e1 * t34 * t117 * t148 - 0.8e1 * t153 * t154 * t158 - 0.8e1 * t162 * t163 * t23 + 0.16e2 * t34 * (-0.2e1 * t28 + t51 + 0.2e1 * t32 - 0.2e1 * t46 - t41 - 0.4e1 * t53 + 0.4e1 * t36) * t57 + 0.8e1 * t162 * t163 * t115 + 0.8e1 * t153 * t154 * t124 + 0.2e1 * t25 * t44 * ZB + 0.2e1 * t34 * t26 + 0.4e1 * t25 * t44 * ZA;
-			_C1B = t137 * del_rho / t190;
-			
-			t1 = ZA - ZB;
-			t2 = t1 * t1;
-			t3 = kn + 0.2e1;
-			t5 = kn * zc;
-			t6 = 0.4e1 * t5;
-			t7 = exp(-t6);
-			t9 = kn * kn;
-			t12 = zc * zc;
-			t13 = t12 * t9;
-			t16 = (0.2e1 - 0.2e1 * t9 * zc + t6 + 0.2e1 * t13 - kn) * t1;
-			t17 = ZA + ZB;
-			t19 = kn * (0.1e1 + zc);
-			t21 = exp(-0.2e1 * t19);
-			t24 = ZA * ZA;
-			t25 = t9 * kn;
-			t27 = t12 * zc;
-			t33 = ZA * ZB;
-			t37 = t12 * t25;
-			t40 = ZB * ZB;
-			t46 = t13 * t24;
-			t47 = 0.4e1 * t46;
-			t49 = t9 * t24 * zc;
-			t50 = t13 * t33;
-			t52 = ZB * t9;
-			t54 = t52 * ZA * zc;
-			t56 = t13 * t40;
-			t58 = t40 * zc;
-			t59 = t58 * t9;
-			t61 = t24 * zc * kn;
-			t63 = t33 * kn;
-			t64 = t33 * t5;
-			t68 = 0.2e1 * t33;
-			t69 = 0.2e1 * t24 * t25 * t27 - 0.2e1 * t24 * t12 * t25 - 0.4e1 * t33 * t25 * t27 + 0.4e1 * t37 * t33 + 0.2e1 * t40 * t25 * t27 - 0.2e1 * t37 * t40 + t47 - t49 - 0.8e1 * t50 + 0.2e1 * t54 + 0.4e1 * t56 - t59 + 0.2e1 * t61 + t63 - 0.4e1 * t64 + 0.2e1 * t58 * kn - t68;
-			t71 = exp(-0.2e1 * kn);
-			t74 = ZA * kn;
-			t75 = 0.4e1 * t74;
-			t77 = 0.2e1 * t74 * zc;
-			t78 = 0.2e1 * ZA;
-			t80 = ZB * zc * kn;
-			t82 = 0.2e1 * ZB * kn;
-			t88 = exp(-kn * (0.1e1 + 0.3e1 * zc));
-			t90 = 0.6e1 * t50;
-			t91 = 0.2e1 * t56;
-			t92 = 0.3e1 * t64;
-			t93 = 0.4e1 * t61;
-			t97 = exp(kn * (zc - 0.3e1));
-			t103 = 0.2e1 * t63;
-			t105 = exp(-t19);
-			t108 = zc - 0.1e1;
-			t109 = kn * t108;
-			t111 = exp(0.2e1 * t109);
-			t117 = exp(0.3e1 * t109);
-			t122 = exp(-0.2e1 * t5);
-			t130 = exp(-kn * (zc + 0.3e1));
-			t134 = exp(t109);
-			t141 = -t2 * t3 * t7 - t16 * t17 * t21 + 0.4e1 * t69 * t71 - t1 * (-t75 + t77 - t78 + t80 - t82) * t88 - 0.2e1 * (-t90 + t91 + t47 - t92 + t93 - t68) * t97 + 0.2e1 * (t47 - 0.8e1 * t49 - t90 + 0.12e2 * t54 - 0.4e1 * t59 + t91 - t93 - t103 + t92 - t68) * t105 + t16 * t17 * t111 - t1 * (t77 + t78 + t80) * t117 + 0.4e1 * t5 * t1 * t17 * t3 * t122 + t17 * (t77 + t78 - t80) * t130 + t17 * (-t75 + t77 - t78 - t80 + t82) * t134 + kn * t40 + t103 + 0.2e1 * t40 + t24 * kn + 0.2e1 * t24 + 0.4e1 * t33;
-			t146 = t17 * t17;
-			t148 = exp(-0.4e1 * kn);
-			t153 = exp(0.4e1 * t109);
-			t157 = ZB * t25;
-			t158 = t157 * zc;
-			t159 = t1 * t17;
-			t163 = exp(0.2e1 * kn * (zc - 0.2e1));
-			t167 = t157 * t1;
-			t168 = t17 * t108;
-			t195 = -0.2e1 * t52 * t2 * t7 + 0.2e1 * t52 * t146 * t148 - 0.2e1 * t52 * t2 * t153 - 0.8e1 * t158 * t159 * t163 - 0.8e1 * t167 * t168 * t21 + 0.16e2 * t52 * (-0.2e1 * t49 + t91 + 0.2e1 * t46 - 0.2e1 * t59 - t33 - 0.4e1 * t50 + 0.4e1 * t54) * t71 + 0.8e1 * t167 * t168 * t111 + 0.8e1 * t158 * t159 * t122 + 0.2e1 * t9 * t40 * ZB + 0.2e1 * t52 * t24 + 0.4e1 * t9 * t40 * ZA;
-			_C2B = t141 * del_rho / t195;
-			
-			t1 = 0.2e1 * ZA;
-			t3 = ZA - ZB;
-			t4 = (t1 + ZB) * t3;
-			t5 = kn * zc;
-			t7 = exp(-0.4e1 * t5);
-			t9 = ZA + ZB;
-			t13 = kn * (0.1e1 + zc);
-			t15 = exp(-0.2e1 * t13);
-			t17 = ZA * ZB;
-			t19 = 0.6e1 * t17 * t5;
-			t20 = ZB * ZB;
-			t21 = zc * t20;
-			t22 = t21 * kn;
-			t23 = 0.2e1 * t22;
-			t24 = ZA * ZA;
-			t26 = t24 * zc * kn;
-			t27 = 0.4e1 * t26;
-			t29 = 0.2e1 * kn;
-			t30 = exp(-t29);
-			t33 = t3 * t9;
-			t34 = 0.2e1 * t5;
-			t35 = t34 - 0.3e1 - t29;
-			t39 = exp(-kn * (0.1e1 + 0.3e1 * zc));
-			t44 = exp(kn * (zc - 0.3e1));
-			t48 = kn * kn;
-			t51 = 0.2e1 * t48 * t24 * zc;
-			t52 = zc * zc;
-			t53 = t52 * t48;
-			t55 = 0.2e1 * t53 * t24;
-			t56 = ZB * t48;
-			t59 = 0.4e1 * t56 * ZA * zc;
-			t61 = 0.4e1 * t53 * t17;
-			t63 = 0.2e1 * t21 * t48;
-			t65 = 0.2e1 * t53 * t20;
-			t69 = exp(-t13);
-			t72 = zc - 0.1e1;
-			t73 = kn * t72;
-			t75 = exp(0.2e1 * t73);
-			t77 = t3 * t3;
-			t79 = exp(0.3e1 * t73);
-			t82 = exp(-t34);
-			t85 = t9 * t9;
-			t88 = exp(-kn * (zc + 0.3e1));
-			t90 = exp(t73);
-			t94 = -t4 * t7 - t9 * (t1 - ZB) * t15 + 0.2e1 * (-t19 + t23 + t27 - t17) * t30 - t33 * t35 * t39 - 0.4e1 * t5 * t33 * t44 + 0.4e1 * (-t51 + t55 + t59 - t61 - t63 + t65 - 0.3e1 * t26 - 0.3e1 * t22 + t19 - t17) * t69 + t4 * t75 - t77 * t79 + 0.2e1 * (-t19 + t23 + t27 + t17) * t82 + t85 * t88 + t33 * t35 * t90 + 0.2e1 * t24 - t20 + t17;
-			t96 = ZB * kn;
-			t101 = exp(-0.4e1 * kn);
-			t105 = t56 * t3;
-			t106 = t9 * t72;
-			t117 = t56 * zc;
-			t121 = exp(0.2e1 * kn * (zc - 0.2e1));
-			t129 = exp(0.4e1 * t73);
-			t141 = -0.2e1 * t96 * t77 * t7 + 0.2e1 * t96 * t85 * t101 - 0.8e1 * t105 * t106 * t15 + 0.16e2 * t96 * (-t51 + t65 + t55 - t63 - t17 - t61 + t59) * t30 + 0.8e1 * t105 * t106 * t75 - 0.8e1 * t117 * t33 * t121 + 0.8e1 * t117 * t33 * t82 - 0.2e1 * t96 * t77 * t129 + 0.2e1 * t96 * t24 + 0.2e1 * t20 * ZB * kn + 0.4e1 * t20 * kn * ZA;
-			_C3B = t94 * del_rho / t141;
-			
-			t1 = ZA - ZB;
-			t2 = t1 * t1;
-			t3 = kn * zc;
-			t5 = exp(-0.4e1 * t3);
-			t6 = t2 * t5;
-			t7 = ZA + ZB;
-			t8 = t1 * t7;
-			t9 = 0.2e1 * t3;
-			t10 = 0.2e1 * kn;
-			t11 = t9 + 0.3e1 - t10;
-			t13 = kn * (0.1e1 + zc);
-			t15 = exp(-0.2e1 * t13);
-			t18 = ZA * ZB;
-			t20 = 0.6e1 * t18 * t3;
-			t21 = kn * kn;
-			t22 = ZB * t21;
-			t25 = 0.4e1 * t22 * ZA * zc;
-			t26 = ZB * ZB;
-			t27 = t26 * zc;
-			t29 = 0.2e1 * t27 * t21;
-			t30 = ZA * ZA;
-			t32 = t30 * zc * kn;
-			t34 = zc * zc;
-			t35 = t34 * t21;
-			t37 = 0.2e1 * t35 * t30;
-			t39 = 0.2e1 * t35 * t26;
-			t41 = 0.4e1 * t35 * t18;
-			t44 = 0.2e1 * t21 * t30 * zc;
-			t45 = t27 * kn;
-			t48 = exp(-t10);
-			t51 = 0.2e1 * ZA;
-			t53 = (t51 + ZB) * t1;
-			t57 = exp(-kn * (0.1e1 + 0.3e1 * zc));
-			t59 = 0.2e1 * t45;
-			t60 = 0.4e1 * t32;
-			t64 = exp(kn * (zc - 0.3e1));
-			t68 = exp(-t13);
-			t71 = zc - 0.1e1;
-			t72 = kn * t71;
-			t74 = exp(0.2e1 * t72);
-			t78 = exp(0.3e1 * t72);
-			t80 = exp(-t9);
-			t81 = t8 * t80;
-			t85 = t7 * (t51 - ZB);
-			t88 = exp(-kn * (zc + 0.3e1));
-			t90 = exp(t72);
-			t93 = t6 + t8 * t11 * t15 - 0.4e1 * (-t18 - t20 + t25 - t29 + 0.3e1 * t32 + t37 + t39 - t41 - t44 + 0.3e1 * t45) * t48 - t53 * t57 + 0.2e1 * (-t20 + t59 + t60 - t18) * t64 + 0.2e1 * (-t20 + t59 + t60 + t18) * t68 - t8 * t11 * t74 + t53 * t78 - 0.4e1 * t3 * t81 - t85 * t88 + t85 * t90 - 0.2e1 * t18 - t26 - t30;
-			t95 = ZB * kn;
-			t98 = t7 * t7;
-			t100 = exp(-0.4e1 * kn);
-			t104 = t22 * t1;
-			t105 = t7 * t71;
-			t116 = t22 * zc;
-			t120 = exp(0.2e1 * kn * (zc - 0.2e1));
-			t127 = exp(0.4e1 * t72);
-			t139 = -0.2e1 * t95 * t6 + 0.2e1 * t95 * t98 * t100 - 0.8e1 * t104 * t105 * t15 + 0.16e2 * t95 * (-t44 + t39 + t37 - t29 - t18 - t41 + t25) * t48 + 0.8e1 * t104 * t105 * t74 - 0.8e1 * t116 * t8 * t120 + 0.8e1 * t116 * t81 - 0.2e1 * t95 * t2 * t127 + 0.2e1 * t95 * t30 + 0.2e1 * t26 * ZB * kn + 0.4e1 * t26 * kn * ZA;
-			_C4B = t93 * del_rho / t139;
-			
-			
-		}
-		
-		/*******************************************/
-		/*       calculate the velocities etc      */
-		/*******************************************/
-		
-		if ( z < zc ) {
-			t4 = exp(-kn * z);
-			t10 = exp(kn * (z - zc));
-			u1=u1a = (_C1A + z * _C3A) * t4 + (_C2A + z * _C4A) * t10;
-			
-			t1 = kn * z;
-			t2 = exp(-t1);
-			t6 = exp(kn * (z - zc));
-			t10 = 0.1e1 / kn;
-			u2=u2a = t2 * _C1A - t6 * _C2A + t2 * (-0.1e1 + t1) * _C3A * t10 - t6 * (0.1e1 + t1) * _C4A * t10;
-			
-			t1 = ZA * kn;
-			t3 = exp(-kn * z);
-			t8 = exp(kn * (z - zc));
-			u3=u3a = -0.2e1 * t1 * t3 * _C1A + 0.2e1 * t1 * t8 * _C2A - 0.2e1 * t1 * t3 * z * _C3A + 0.2e1 * t1 * t8 * z * _C4A;
-			
-			t2 = kn * z;
-			t6 = exp(-t2);
-			t14 = exp(kn * (z - zc));
-			u4=u4a = -0.2e1 * ZA * (-_C3A + kn * _C1A + t2 * _C3A) * t6 - 0.2e1 * ZA * (_C4A + kn * _C2A + t2 * _C4A) * t14;
-			
-			Z=ZA;
-			del_rho = 0.0;
-			
-		} else {
-			t5 = exp(kn * (zc - z));
-			t11 = exp(kn * (z - 0.1e1));
-			t15 = kn * kn;
-			u1=u1b = (_C1B + z * _C3B) * t5 + (_C2B + z * _C4B) * t11 - del_rho / ZB / t15;
-			
-			t3 = exp(kn * (zc - z));
-			t7 = exp(kn * (z - 0.1e1));
-			t9 = kn * z;
-			t12 = 0.1e1 / kn;
-			u2=u2b = t3 * _C1B - t7 * _C2B + t3 * (-0.1e1 + t9) * _C3B * t12 - t7 * (0.1e1 + t9) * _C4B * t12;
-			
-			t1 = ZB * kn;
-			t4 = exp(kn * (zc - z));
-			t9 = exp(kn * (z - 0.1e1));
-			u3=u3b = -0.2e1 * t1 * t4 * _C1B + 0.2e1 * t1 * t9 * _C2B - 0.2e1 * t1 * t4 * z * _C3B + 0.2e1 * t1 * t9 * z * _C4B;
-			
-			t2 = kn * z;
-			t8 = exp(kn * (zc - z));
-			t17 = exp(kn * (z - 0.1e1));
-			u4=u4b = -0.2e1 * ZB * (-_C3B + kn * _C1B + t2 * _C3B) * t8 - 0.2e1 * ZB * (_C4B + kn * _C2B + t2 * _C4B) * t17 + 0.1e1 / kn * del_rho;
-			
-			Z=ZB;
-		}
-		
-		
-		
-		pp = (double)-(u3 + 2.0*n*M_PI*Z*u2)*cos(n*M_PI*x); /* pressure */
-		
-		txx = (double)(u3 + 4*Z*n*M_PI*u2)*cos(n*M_PI*x); /* xx stress */
-		sum5 += pp;
-		sum6 += txx;
-		
-		u1 *= cos(n*M_PI*x); /* z velocity */
-		sum1 += u1;
-		u2 *= sin(n*M_PI*x); /* x velocity */
-		sum2 += u2;
-		u3 *= cos(n*M_PI*x); /* zz stress */
-		sum3 += u3;
-		u4 *= sin(n*M_PI*x); /* zx stress */
-		sum4 += u4;
-		
-		rho = del_rho* cos(n*M_PI*x); /* density */
-		sum7 += rho;
-	}/* n */
-	
-	/* include terms for n=0 now */
-	if( z >= zc ){
-		del_rho = sigma*dx;
-		rho = del_rho; /* density */
-		sum7 += rho;
-		u3 = del_rho*(z-zc); /* zz stress */
-		sum3 += u3;
-		
-		txx = u3; /* xx stress */
-		pp = -u3; /* pressure */
-		sum5 += pp;
-		sum6 += txx;
-		
-	}
-	
-	mag=sqrt(sum1*sum1+sum2*sum2);
-	//printf("%0.7g %0.7g %0.7g %0.7g %0.7g %0.7g\n",x,y,z,sum3,sum2,sum1);
-	//printf("%0.7g %0.7g %0.7g\n%0.7g %0.7g %0.7g\n\n\n",x,y,z,x+sum3,y+sum2,z+sum1);
-	/*printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7);*/
-	
-	
-	/* Output */
-	if( vel != NULL ) {
-		vel[0] = sum2;
-		vel[1] = sum1;
-	}
-	if( presssure != NULL ) {
-		(*presssure) = sum5;
-	}
-	if( total_stress != NULL ) {
-		total_stress[0] = sum6;
-		total_stress[1] = sum3;
-		total_stress[2] = sum4;
-	}
-	if( strain_rate != NULL ) {
-		if( z<zc ) {
-			Z = ZA;
-		}
-		else {
-			Z = ZB;
-		}
-		strain_rate[0] = (sum6+sum5)/(2.0*Z);
-		strain_rate[1] = (sum3+sum5)/(2.0*Z);
-		strain_rate[2] = (sum4)/(2.0*Z);
-	}
-	/* Value checks, could be cleaned up if needed. Julian Giordani 9-Oct-2006*/
-        if( fabs( sum5 - ( -0.5*(sum6+sum3) ) ) > 1e-5 ) {
-                assert(0);
-        }
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solJA/solJA.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solJA/solJA.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,720 @@
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+
+
+void _Velic_solJA( 
+		double pos[],
+		double _sigma,
+		double _eta_A, double _eta_B,
+		double _dx,
+		double _x_0, double _z_c,
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] );
+
+
+int main( int argc, char **argv )
+{
+	int i,j;
+	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
+	double x,z;
+	
+	for (i=0;i<101;i++){
+		for(j=0;j<101;j++){
+			x = i/100.0;
+			z = j/100.0;
+			
+			pos[0] = x;
+			pos[1] = z;
+			_Velic_solJA(
+					pos,
+					1.0,
+					100.0, 1.0,
+					0.4,
+					0.2, 0.8,
+					vel, &pressure, total_stress, strain_rate );
+			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
+					pos[0],pos[1],
+					vel[0],vel[1], pressure, 
+					total_stress[0], total_stress[1], total_stress[2], 
+					strain_rate[0], strain_rate[1], strain_rate[2] );
+		}
+		printf("\n");
+	}
+	
+	return 0;
+}
+
+
+
+
+void _Velic_solJA( 
+		double pos[],
+		double _sigma, /* density */
+		double _eta_A, double _eta_B, /* viscosity A, viscosity B */
+		double _dx, /* width of upper dense block */
+		double _x_0, double _z_c, /* centre of upper dense block, bottom of upper dense block */
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] )
+{
+	double Z,ZA,ZB,u1,u2,u3,u4,pp,txx;
+	double u1a,u2a,u3a,u4a,u1b,u2b,u3b,u4b;
+	double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,x,z;
+	double sigma,dx;
+	double del_rho;
+	int n;
+	double kn;
+	double _C1A,_C2A,_C3A,_C4A,_C1B,_C2B,_C3B,_C4B;
+	double x0,rho,zc;
+	
+	double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
+	double t11,t12,t13,t14,t15,t16,t17,t18,t19,t20;
+	double t21,t22,t23,t24,t25,t26,t27,t28,t29,t30;
+	double t31,t32,t33,t34,t35,t36,t37,t38,t39,t40;
+	double t41,t42,t43,t44,t45,t46,t47,t48,t49,t50;
+	double t51,t52,t53,t54,t55,t56,t57,t58,t59,t60;
+	double t61,t62,t63,t64,t65,t66,t67,t68,t69,t70;
+	double t71,t72,t73,t74,t75,t76,t77,t78,t79,t80;
+	double t81,t82,t83,t85,t86,t87,t88,t89,t90,t91;
+	double t92,t93,t94,t95,t96,t97,t98,t99,t100,t101;
+	double t102,t103,t104,t105,t106,t107,t108,t109,t111,t112;
+	double t113,t114,t115,t116,t117,t118,t120,t121,t122,t124;
+	double t125,t126,t127,t128,t129,t130,t131,t133,t134,t135;
+	double t136,t137,t139,t141,t143,t144,t145,t146,t147,t148;
+	double t151,t152,t153,t154,t156,t157,t158,t159,t162,t163;
+	double t165,t167,t168,t190,t195;
+	
+	/*************************************************************************/
+	/*************************************************************************/
+	/*
+	In layer B (the top layer) we have a dense column of density sigma
+	ranging from x=x0-dx/2 to x= x0+dx/2:
+	The viscosity of layer B is ZB:
+	The viscosity of layer A is ZA:
+	
+	If one wants a dense column from x=0 to x=dx then just set x0=dx/2
+	
+	*/
+	/*************************************************************************/
+	/*************************************************************************/
+	
+	/*************************************************************************/
+	/*************************************************************************/
+	x0 = _x_0;  /* centre of dense column for layer B */
+	dx = _dx;  /* total width of dense column  for layer B */
+	sigma = _sigma; /* density parameter for layer B */
+	ZA = _eta_A;    /* viscosity for layer A */
+	ZB = _eta_B; /* viscosity for layer B */
+	zc = _z_c;  /* dividing line between region B and region A */
+	/*************************************************************************/
+	/*************************************************************************/
+	
+	x = pos[0];
+	z = pos[1];
+	
+	sum1=0.0;
+	sum2=0.0;
+	sum3=0.0;
+	sum4=0.0;
+	sum5=0.0;
+	sum6=0.0;
+	sum7=0.0;
+	/* this one blows up when n gets around 85 for some reason... if max n is set to 75 it is fine though */
+	/* fixed the convergence problem */
+	for(n=1;n<55;n++){
+		kn = (double) n*M_PI;
+		
+		/*******************************************/
+		/*            calculate del_rho            */
+		/*******************************************/
+		del_rho = 4.0*sigma*cos(n*M_PI*x0)*sin(n*M_PI*dx/2.0)/n/M_PI;
+		/* we can have any del_rho we like here as long as it is independent of z */
+		
+		
+		/*******************************************/
+		/*         calculate the constants         */
+		/*******************************************/
+		
+		if ( z < zc ) {
+			t1 = kn * zc;
+			t2 = 0.4e1 * t1;
+			t3 = kn * kn;
+			t5 = 0.2e1 * t3 * zc;
+			t6 = zc * zc;
+			t7 = t6 * t3;
+			t8 = 0.2e1 * t7;
+			t10 = ZA - ZB;
+			t12 = 0.2e1 * zc;
+			t15 = exp(-kn * (0.1e1 + t12));
+			t22 = exp(kn * (t12 - 0.3e1));
+			t26 = ZA + ZB;
+			t29 = exp(-0.3e1 * kn);
+			t34 = exp(-kn);
+			t37 = 0.3e1 * t1;
+			t40 = exp(-t37);
+			t44 = exp(-t1);
+			t50 = exp(kn * (zc - 0.4e1));
+			t54 = 0.2e1 * ZA * kn * zc;
+			t56 = 0.2e1 * ZB * kn;
+			t57 = 0.2e1 * ZA;
+			t58 = t3 * ZA;
+			t60 = 0.2e1 * t58 * zc;
+			t63 = 0.3e1 * ZB * zc * kn;
+			t64 = t3 * ZB;
+			t66 = 0.2e1 * t64 * zc;
+			t68 = 0.2e1 * t64 * t6;
+			t70 = 0.2e1 * t58 * t6;
+			t73 = kn * (zc - 0.2e1);
+			t74 = exp(t73);
+			t82 = exp(kn * (0.3e1 * zc - 0.4e1));
+			t87 = exp(-kn * (0.2e1 + zc));
+			t92 = t10 * t10;
+			t93 = t3 * t92;
+			t94 = exp(-t2);
+			t97 = t26 * t26;
+			t100 = exp(-0.4e1 * kn);
+			t103 = t3 * kn;
+			t104 = t103 * t10;
+			t105 = zc - 0.1e1;
+			t106 = t26 * t105;
+			t107 = kn * t105;
+			t109 = exp(0.2e1 * t107);
+			t114 = exp(0.4e1 * t107);
+			t117 = t103 * zc;
+			t118 = t10 * t26;
+			t120 = exp(0.2e1 * t73);
+			t124 = ZA * ZA;
+			t125 = t3 * t124;
+			t128 = ZB * ZB;
+			t136 = ZA * ZB;
+			t145 = exp(-0.2e1 * kn);
+			t151 = exp(-0.2e1 * kn * (0.1e1 + zc));
+			t156 = exp(-0.2e1 * t1);
+			t165 = -0.2e1 * t93 * t94 + 0.2e1 * t3 * t97 * t100 + 0.8e1 * t104 * t106 * t109 - 0.2e1 * t93 * t114 - 0.8e1 * t117 * t118 * t120 + 0.16e2 * t3 * (-0.2e1 * t125 * zc + 0.2e1 * t7 * t128 + 0.2e1 * t7 * t124 - 0.2e1 * t128 * zc * t3 - t136 - 0.4e1 * t7 * t136 + 0.4e1 * t64 * ZA * zc) * t145 - 0.8e1 * t104 * t106 * t151 + 0.8e1 * t117 * t118 * t156 + 0.4e1 * t64 * ZA + 0.2e1 * t3 * t128 + 0.2e1 * t125;
+			_C1A = (0.2e1 * (-t2 - t5 + t8 + 0.2e1 + kn) * t10 * t15 - 0.2e1 * (0.2e1 - t5 + t2 + t8 - kn) * t10 * t22 - 0.2e1 * (-0.2e1 + kn) * t26 * t29 - 0.2e1 * (kn + 0.2e1) * t26 * t34 + (t37 - 0.2e1) * t10 * t40 + (t1 + 0.2e1) * t26 * t44 + (t1 - 0.2e1) * t26 * t50 + 0.2e1 * (t54 + t56 + t57 - t60 - t63 + t66 - t68 + t70) * t74 + (t37 + 0.2e1) * t10 * t82 - 0.2e1 * (-t68 + t63 - t60 + t70 - t56 + t57 - t54 + t66) * t87) * del_rho / t165;
+			
+			t1 = kn * kn;
+			t3 = 0.2e1 * t1 * zc;
+			t4 = kn * zc;
+			t5 = 0.4e1 * t4;
+			t6 = zc * zc;
+			t7 = t6 * t1;
+			t8 = 0.2e1 * t7;
+			t10 = ZA - ZB;
+			t12 = zc - 0.1e1;
+			t13 = kn * t12;
+			t15 = exp(0.3e1 * t13);
+			t19 = ZA + ZB;
+			t24 = exp(0.2e1 * kn * (zc - 0.2e1));
+			t26 = t1 * ZB;
+			t28 = 0.2e1 * t26 * t6;
+			t30 = ZB * zc * kn;
+			t31 = 0.3e1 * t30;
+			t32 = t1 * ZA;
+			t34 = 0.2e1 * t32 * zc;
+			t36 = 0.2e1 * t32 * t6;
+			t38 = 0.2e1 * ZB * kn;
+			t39 = 0.2e1 * ZA;
+			t41 = ZA * kn * zc;
+			t42 = 0.2e1 * t41;
+			t44 = 0.2e1 * t26 * zc;
+			t47 = exp(-0.2e1 * kn);
+			t52 = exp(t13);
+			t57 = exp(0.2e1 * t13);
+			t64 = exp(kn * (zc - 0.3e1));
+			t67 = 0.3e1 * t4;
+			t71 = exp(-0.2e1 * t4);
+			t76 = kn * (0.1e1 + zc);
+			t77 = exp(-t76);
+			t83 = exp(0.4e1 * t13);
+			t86 = 0.2e1 * (0.2e1 - t3 + t5 + t8 - kn) * t10 * t15 - (t4 - 0.2e1) * t19 * t24 + 0.2e1 * (-t28 + t31 - t34 + t36 - t38 + t39 - t42 + t44) * t47 + 0.2e1 * (kn + 0.2e1) * t19 * t52 - 0.2e1 * (t42 + t38 + t39 - t34 - t31 + t44 - t28 + t36) * t57 + 0.2e1 * (-0.2e1 + kn) * t19 * t64 - (t67 - 0.2e1) * t10 * t71 - 0.2e1 * (-t5 - t3 + t8 + 0.2e1 + kn) * t10 * t77 - (t67 + 0.2e1) * t10 * t83 - 0.2e1 * ZB - t39 - t30 - t41;
+			t88 = t10 * t10;
+			t89 = t1 * t88;
+			t90 = exp(-t5);
+			t93 = t19 * t19;
+			t96 = exp(-0.4e1 * kn);
+			t99 = t1 * kn;
+			t100 = t99 * t10;
+			t101 = t19 * t12;
+			t107 = t99 * zc;
+			t108 = t10 * t19;
+			t112 = ZA * ZA;
+			t113 = t1 * t112;
+			t116 = ZB * ZB;
+			t124 = ZA * ZB;
+			t135 = exp(-0.2e1 * t76);
+			t147 = -0.2e1 * t89 * t90 + 0.2e1 * t1 * t93 * t96 + 0.8e1 * t100 * t101 * t57 - 0.2e1 * t89 * t83 - 0.8e1 * t107 * t108 * t24 + 0.16e2 * t1 * (-0.2e1 * t113 * zc + 0.2e1 * t7 * t116 + 0.2e1 * t7 * t112 - 0.2e1 * t116 * zc * t1 - t124 - 0.4e1 * t7 * t124 + 0.4e1 * t26 * ZA * zc) * t47 - 0.8e1 * t100 * t101 * t135 + 0.8e1 * t107 * t108 * t71 + 0.4e1 * t26 * ZA + 0.2e1 * t1 * t116 + 0.2e1 * t113;
+			_C2A = t86 * del_rho / t147;
+			
+			t1 = kn * zc;
+			t2 = 0.2e1 * t1;
+			t3 = 0.2e1 * kn;
+			t5 = ZA - ZB;
+			t7 = 0.2e1 * zc;
+			t10 = exp(-kn * (0.1e1 + t7));
+			t17 = exp(kn * (t7 - 0.3e1));
+			t20 = ZA + ZB;
+			t22 = exp(-0.3e1 * kn);
+			t25 = exp(-kn);
+			t29 = exp(-0.3e1 * t1);
+			t32 = exp(-t1);
+			t36 = exp(kn * (zc - 0.4e1));
+			t38 = ZA * kn;
+			t40 = 0.2e1 * t38 * zc;
+			t41 = 0.2e1 * t38;
+			t43 = 0.2e1 * ZB * kn;
+			t44 = 0.2e1 * ZA;
+			t47 = 0.2e1 * ZB * zc * kn;
+			t50 = kn * (zc - 0.2e1);
+			t51 = exp(t50);
+			t57 = exp(kn * (0.3e1 * zc - 0.4e1));
+			t63 = exp(-kn * (0.2e1 + zc));
+			t68 = t5 * t5;
+			t69 = kn * t68;
+			t71 = exp(-0.4e1 * t1);
+			t74 = t20 * t20;
+			t77 = exp(-0.4e1 * kn);
+			t80 = kn * kn;
+			t81 = t80 * t5;
+			t82 = zc - 0.1e1;
+			t83 = t20 * t82;
+			t87 = exp(-0.2e1 * kn * (0.1e1 + zc));
+			t91 = t80 * zc;
+			t92 = t5 * t20;
+			t94 = exp(0.2e1 * t50);
+			t98 = ZA * ZA;
+			t102 = zc * zc;
+			t103 = t102 * t80;
+			t104 = ZB * ZB;
+			t112 = ZA * ZB;
+			t121 = exp(-t3);
+			t124 = kn * t82;
+			t126 = exp(0.2e1 * t124);
+			t130 = exp(-t2);
+			t135 = exp(0.4e1 * t124);
+			t144 = -0.2e1 * t69 * t71 + 0.2e1 * t74 * kn * t77 - 0.8e1 * t81 * t83 * t87 - 0.8e1 * t91 * t92 * t94 + 0.16e2 * kn * (-0.2e1 * t80 * t98 * zc + 0.2e1 * t103 * t104 + 0.2e1 * t103 * t98 - 0.2e1 * t104 * zc * t80 - t112 - 0.4e1 * t103 * t112 + 0.4e1 * ZB * t80 * ZA * zc) * t121 + 0.8e1 * t81 * t83 * t126 + 0.8e1 * t91 * t92 * t130 - 0.2e1 * t69 * t135 + 0.2e1 * kn * t104 + 0.2e1 * t98 * kn + 0.4e1 * t112 * kn;
+			_C3A = (-0.2e1 * (t2 - 0.3e1 - t3) * t5 * t10 - 0.2e1 * (t2 + 0.3e1 - t3) * t5 * t17 + 0.2e1 * t20 * t22 - 0.2e1 * t20 * t25 - 0.3e1 * t5 * t29 + t20 * t32 - t20 * t36 + 0.2e1 * (t40 - t41 + t43 + t44 - ZB - t47) * t51 + 0.3e1 * t5 * t57 + 0.2e1 * (-t41 + t43 + ZB - t47 + t40 - t44) * t63) * del_rho / t144;
+			
+			t1 = ZA + ZB;
+			t5 = exp(0.2e1 * kn * (zc - 0.2e1));
+			t7 = ZA * kn;
+			t8 = 0.2e1 * t7;
+			t10 = 0.2e1 * ZB * kn;
+			t13 = 0.2e1 * ZB * zc * kn;
+			t15 = 0.2e1 * t7 * zc;
+			t16 = 0.2e1 * ZA;
+			t18 = 0.2e1 * kn;
+			t19 = exp(-t18);
+			t24 = exp(kn * (zc - 0.3e1));
+			t27 = kn * zc;
+			t28 = 0.2e1 * t27;
+			t30 = ZA - ZB;
+			t33 = kn * (0.1e1 + zc);
+			t34 = exp(-t33);
+			t38 = zc - 0.1e1;
+			t39 = kn * t38;
+			t41 = exp(0.2e1 * t39);
+			t47 = exp(0.3e1 * t39);
+			t50 = exp(-t28);
+			t53 = exp(t39);
+			t57 = exp(0.4e1 * t39);
+			t60 = -t1 * t5 + 0.2e1 * (-t8 + t10 + ZB - t13 + t15 - t16) * t19 + 0.2e1 * t1 * t24 - 0.2e1 * (t28 - 0.3e1 - t18) * t30 * t34 + 0.2e1 * (t15 - t8 + t10 + t16 - ZB - t13) * t41 - 0.2e1 * (t28 + 0.3e1 - t18) * t30 * t47 - 0.3e1 * t30 * t50 - 0.2e1 * t1 * t53 + 0.3e1 * t30 * t57 + ZA + ZB;
+			t62 = t30 * t30;
+			t63 = kn * t62;
+			t65 = exp(-0.4e1 * t27);
+			t68 = t1 * t1;
+			t71 = exp(-0.4e1 * kn);
+			t74 = kn * kn;
+			t75 = t74 * t30;
+			t76 = t1 * t38;
+			t78 = exp(-0.2e1 * t33);
+			t82 = t74 * zc;
+			t83 = t30 * t1;
+			t87 = ZA * ZA;
+			t91 = zc * zc;
+			t92 = t91 * t74;
+			t93 = ZB * ZB;
+			t101 = ZA * ZB;
+			t126 = -0.2e1 * t63 * t65 + 0.2e1 * t68 * kn * t71 - 0.8e1 * t75 * t76 * t78 - 0.8e1 * t82 * t83 * t5 + 0.16e2 * kn * (-0.2e1 * t74 * t87 * zc + 0.2e1 * t92 * t93 + 0.2e1 * t92 * t87 - 0.2e1 * t93 * zc * t74 - t101 - 0.4e1 * t92 * t101 + 0.4e1 * ZB * t74 * ZA * zc) * t19 + 0.8e1 * t75 * t76 * t41 + 0.8e1 * t82 * t83 * t50 - 0.2e1 * t63 * t57 + 0.2e1 * kn * t93 + 0.2e1 * t87 * kn + 0.4e1 * t101 * kn;
+			_C4A = t60 * del_rho / t126;
+		} else { 
+			t1 = ZA - ZB;
+			t2 = ZA * kn;
+			t4 = 0.2e1 * t2 * zc;
+			t5 = 0.2e1 * ZA;
+			t7 = ZB * zc * kn;
+			t10 = kn * zc;
+			t11 = 0.4e1 * t10;
+			t12 = exp(-t11);
+			t14 = ZA + ZB;
+			t15 = 0.4e1 * t2;
+			t17 = 0.2e1 * ZB * kn;
+			t21 = kn * (0.1e1 + zc);
+			t23 = exp(-0.2e1 * t21);
+			t25 = kn * kn;
+			t26 = ZA * ZA;
+			t28 = t25 * t26 * zc;
+			t30 = zc * zc;
+			t31 = t30 * t25;
+			t32 = t31 * t26;
+			t33 = 0.4e1 * t32;
+			t34 = ZB * t25;
+			t36 = t34 * ZA * zc;
+			t39 = t26 * zc * kn;
+			t40 = 0.4e1 * t39;
+			t41 = ZA * ZB;
+			t42 = t41 * kn;
+			t44 = ZB * ZB;
+			t45 = t44 * zc;
+			t46 = t45 * t25;
+			t48 = t41 * t10;
+			t49 = 0.3e1 * t48;
+			t50 = t31 * t44;
+			t51 = 0.2e1 * t50;
+			t52 = 0.2e1 * t41;
+			t53 = t31 * t41;
+			t54 = 0.6e1 * t53;
+			t57 = exp(-0.2e1 * kn);
+			t64 = (-t11 - 0.2e1 * t25 * zc + 0.2e1 * t31 + 0.2e1 + kn) * t1;
+			t68 = exp(-kn * (0.1e1 + 0.3e1 * zc));
+			t72 = -0.2e1 + kn;
+			t76 = exp(kn * (zc - 0.3e1));
+			t80 = t25 * kn;
+			t81 = t30 * t80;
+			t85 = t30 * zc;
+			t91 = t45 * kn;
+			t97 = 0.2e1 * t39;
+			t106 = -0.2e1 * t81 * t44 + 0.2e1 * t44 * t80 * t85 + 0.2e1 * t26 * t80 * t85 + t52 + t42 + 0.2e1 * t91 + 0.8e1 * t53 + 0.4e1 * t81 * t41 - 0.4e1 * t48 + t46 + t97 - 0.2e1 * t36 - t33 - 0.4e1 * t41 * t80 * t85 - 0.4e1 * t50 - 0.2e1 * t26 * t30 * t80 + t28;
+			t107 = exp(-t21);
+			t112 = zc - 0.1e1;
+			t113 = kn * t112;
+			t115 = exp(0.2e1 * t113);
+			t117 = t1 * t1;
+			t120 = exp(0.3e1 * t113);
+			t124 = exp(-0.2e1 * t10);
+			t127 = t14 * t14;
+			t131 = exp(-kn * (zc + 0.3e1));
+			t133 = exp(t113);
+			t137 = t1 * (t4 - t5 + t7) * t12 - t14 * (t5 + t4 - t15 - t7 + t17) * t23 + 0.2e1 * (-0.8e1 * t28 + t33 + 0.12e2 * t36 + t40 + 0.2e1 * t42 - 0.4e1 * t46 - t49 + t51 - t52 - t54) * t57 + t64 * t14 * t68 + 0.4e1 * t10 * t1 * t14 * t72 * t76 - 0.4e1 * t106 * t107 + t1 * (t5 + t4 - t15 + t7 - t17) * t115 + t117 * t72 * t120 - 0.2e1 * (t49 - t54 + t33 + t51 - t52 - t40) * t124 - t127 * t72 * t131 - t64 * t14 * t133 - t48 + 0.2e1 * t26 - t97 + t52 + t91;
+			t143 = exp(-0.4e1 * kn);
+			t148 = exp(0.4e1 * t113);
+			t152 = t80 * ZB;
+			t153 = t152 * zc;
+			t154 = t1 * t14;
+			t158 = exp(0.2e1 * kn * (zc - 0.2e1));
+			t162 = t152 * t1;
+			t163 = t14 * t112;
+			t190 = -0.2e1 * t34 * t117 * t12 + 0.2e1 * t34 * t127 * t143 - 0.2e1 * t34 * t117 * t148 - 0.8e1 * t153 * t154 * t158 - 0.8e1 * t162 * t163 * t23 + 0.16e2 * t34 * (-0.2e1 * t28 + t51 + 0.2e1 * t32 - 0.2e1 * t46 - t41 - 0.4e1 * t53 + 0.4e1 * t36) * t57 + 0.8e1 * t162 * t163 * t115 + 0.8e1 * t153 * t154 * t124 + 0.2e1 * t25 * t44 * ZB + 0.2e1 * t34 * t26 + 0.4e1 * t25 * t44 * ZA;
+			_C1B = t137 * del_rho / t190;
+			
+			t1 = ZA - ZB;
+			t2 = t1 * t1;
+			t3 = kn + 0.2e1;
+			t5 = kn * zc;
+			t6 = 0.4e1 * t5;
+			t7 = exp(-t6);
+			t9 = kn * kn;
+			t12 = zc * zc;
+			t13 = t12 * t9;
+			t16 = (0.2e1 - 0.2e1 * t9 * zc + t6 + 0.2e1 * t13 - kn) * t1;
+			t17 = ZA + ZB;
+			t19 = kn * (0.1e1 + zc);
+			t21 = exp(-0.2e1 * t19);
+			t24 = ZA * ZA;
+			t25 = t9 * kn;
+			t27 = t12 * zc;
+			t33 = ZA * ZB;
+			t37 = t12 * t25;
+			t40 = ZB * ZB;
+			t46 = t13 * t24;
+			t47 = 0.4e1 * t46;
+			t49 = t9 * t24 * zc;
+			t50 = t13 * t33;
+			t52 = ZB * t9;
+			t54 = t52 * ZA * zc;
+			t56 = t13 * t40;
+			t58 = t40 * zc;
+			t59 = t58 * t9;
+			t61 = t24 * zc * kn;
+			t63 = t33 * kn;
+			t64 = t33 * t5;
+			t68 = 0.2e1 * t33;
+			t69 = 0.2e1 * t24 * t25 * t27 - 0.2e1 * t24 * t12 * t25 - 0.4e1 * t33 * t25 * t27 + 0.4e1 * t37 * t33 + 0.2e1 * t40 * t25 * t27 - 0.2e1 * t37 * t40 + t47 - t49 - 0.8e1 * t50 + 0.2e1 * t54 + 0.4e1 * t56 - t59 + 0.2e1 * t61 + t63 - 0.4e1 * t64 + 0.2e1 * t58 * kn - t68;
+			t71 = exp(-0.2e1 * kn);
+			t74 = ZA * kn;
+			t75 = 0.4e1 * t74;
+			t77 = 0.2e1 * t74 * zc;
+			t78 = 0.2e1 * ZA;
+			t80 = ZB * zc * kn;
+			t82 = 0.2e1 * ZB * kn;
+			t88 = exp(-kn * (0.1e1 + 0.3e1 * zc));
+			t90 = 0.6e1 * t50;
+			t91 = 0.2e1 * t56;
+			t92 = 0.3e1 * t64;
+			t93 = 0.4e1 * t61;
+			t97 = exp(kn * (zc - 0.3e1));
+			t103 = 0.2e1 * t63;
+			t105 = exp(-t19);
+			t108 = zc - 0.1e1;
+			t109 = kn * t108;
+			t111 = exp(0.2e1 * t109);
+			t117 = exp(0.3e1 * t109);
+			t122 = exp(-0.2e1 * t5);
+			t130 = exp(-kn * (zc + 0.3e1));
+			t134 = exp(t109);
+			t141 = -t2 * t3 * t7 - t16 * t17 * t21 + 0.4e1 * t69 * t71 - t1 * (-t75 + t77 - t78 + t80 - t82) * t88 - 0.2e1 * (-t90 + t91 + t47 - t92 + t93 - t68) * t97 + 0.2e1 * (t47 - 0.8e1 * t49 - t90 + 0.12e2 * t54 - 0.4e1 * t59 + t91 - t93 - t103 + t92 - t68) * t105 + t16 * t17 * t111 - t1 * (t77 + t78 + t80) * t117 + 0.4e1 * t5 * t1 * t17 * t3 * t122 + t17 * (t77 + t78 - t80) * t130 + t17 * (-t75 + t77 - t78 - t80 + t82) * t134 + kn * t40 + t103 + 0.2e1 * t40 + t24 * kn + 0.2e1 * t24 + 0.4e1 * t33;
+			t146 = t17 * t17;
+			t148 = exp(-0.4e1 * kn);
+			t153 = exp(0.4e1 * t109);
+			t157 = ZB * t25;
+			t158 = t157 * zc;
+			t159 = t1 * t17;
+			t163 = exp(0.2e1 * kn * (zc - 0.2e1));
+			t167 = t157 * t1;
+			t168 = t17 * t108;
+			t195 = -0.2e1 * t52 * t2 * t7 + 0.2e1 * t52 * t146 * t148 - 0.2e1 * t52 * t2 * t153 - 0.8e1 * t158 * t159 * t163 - 0.8e1 * t167 * t168 * t21 + 0.16e2 * t52 * (-0.2e1 * t49 + t91 + 0.2e1 * t46 - 0.2e1 * t59 - t33 - 0.4e1 * t50 + 0.4e1 * t54) * t71 + 0.8e1 * t167 * t168 * t111 + 0.8e1 * t158 * t159 * t122 + 0.2e1 * t9 * t40 * ZB + 0.2e1 * t52 * t24 + 0.4e1 * t9 * t40 * ZA;
+			_C2B = t141 * del_rho / t195;
+			
+			t1 = 0.2e1 * ZA;
+			t3 = ZA - ZB;
+			t4 = (t1 + ZB) * t3;
+			t5 = kn * zc;
+			t7 = exp(-0.4e1 * t5);
+			t9 = ZA + ZB;
+			t13 = kn * (0.1e1 + zc);
+			t15 = exp(-0.2e1 * t13);
+			t17 = ZA * ZB;
+			t19 = 0.6e1 * t17 * t5;
+			t20 = ZB * ZB;
+			t21 = zc * t20;
+			t22 = t21 * kn;
+			t23 = 0.2e1 * t22;
+			t24 = ZA * ZA;
+			t26 = t24 * zc * kn;
+			t27 = 0.4e1 * t26;
+			t29 = 0.2e1 * kn;
+			t30 = exp(-t29);
+			t33 = t3 * t9;
+			t34 = 0.2e1 * t5;
+			t35 = t34 - 0.3e1 - t29;
+			t39 = exp(-kn * (0.1e1 + 0.3e1 * zc));
+			t44 = exp(kn * (zc - 0.3e1));
+			t48 = kn * kn;
+			t51 = 0.2e1 * t48 * t24 * zc;
+			t52 = zc * zc;
+			t53 = t52 * t48;
+			t55 = 0.2e1 * t53 * t24;
+			t56 = ZB * t48;
+			t59 = 0.4e1 * t56 * ZA * zc;
+			t61 = 0.4e1 * t53 * t17;
+			t63 = 0.2e1 * t21 * t48;
+			t65 = 0.2e1 * t53 * t20;
+			t69 = exp(-t13);
+			t72 = zc - 0.1e1;
+			t73 = kn * t72;
+			t75 = exp(0.2e1 * t73);
+			t77 = t3 * t3;
+			t79 = exp(0.3e1 * t73);
+			t82 = exp(-t34);
+			t85 = t9 * t9;
+			t88 = exp(-kn * (zc + 0.3e1));
+			t90 = exp(t73);
+			t94 = -t4 * t7 - t9 * (t1 - ZB) * t15 + 0.2e1 * (-t19 + t23 + t27 - t17) * t30 - t33 * t35 * t39 - 0.4e1 * t5 * t33 * t44 + 0.4e1 * (-t51 + t55 + t59 - t61 - t63 + t65 - 0.3e1 * t26 - 0.3e1 * t22 + t19 - t17) * t69 + t4 * t75 - t77 * t79 + 0.2e1 * (-t19 + t23 + t27 + t17) * t82 + t85 * t88 + t33 * t35 * t90 + 0.2e1 * t24 - t20 + t17;
+			t96 = ZB * kn;
+			t101 = exp(-0.4e1 * kn);
+			t105 = t56 * t3;
+			t106 = t9 * t72;
+			t117 = t56 * zc;
+			t121 = exp(0.2e1 * kn * (zc - 0.2e1));
+			t129 = exp(0.4e1 * t73);
+			t141 = -0.2e1 * t96 * t77 * t7 + 0.2e1 * t96 * t85 * t101 - 0.8e1 * t105 * t106 * t15 + 0.16e2 * t96 * (-t51 + t65 + t55 - t63 - t17 - t61 + t59) * t30 + 0.8e1 * t105 * t106 * t75 - 0.8e1 * t117 * t33 * t121 + 0.8e1 * t117 * t33 * t82 - 0.2e1 * t96 * t77 * t129 + 0.2e1 * t96 * t24 + 0.2e1 * t20 * ZB * kn + 0.4e1 * t20 * kn * ZA;
+			_C3B = t94 * del_rho / t141;
+			
+			t1 = ZA - ZB;
+			t2 = t1 * t1;
+			t3 = kn * zc;
+			t5 = exp(-0.4e1 * t3);
+			t6 = t2 * t5;
+			t7 = ZA + ZB;
+			t8 = t1 * t7;
+			t9 = 0.2e1 * t3;
+			t10 = 0.2e1 * kn;
+			t11 = t9 + 0.3e1 - t10;
+			t13 = kn * (0.1e1 + zc);
+			t15 = exp(-0.2e1 * t13);
+			t18 = ZA * ZB;
+			t20 = 0.6e1 * t18 * t3;
+			t21 = kn * kn;
+			t22 = ZB * t21;
+			t25 = 0.4e1 * t22 * ZA * zc;
+			t26 = ZB * ZB;
+			t27 = t26 * zc;
+			t29 = 0.2e1 * t27 * t21;
+			t30 = ZA * ZA;
+			t32 = t30 * zc * kn;
+			t34 = zc * zc;
+			t35 = t34 * t21;
+			t37 = 0.2e1 * t35 * t30;
+			t39 = 0.2e1 * t35 * t26;
+			t41 = 0.4e1 * t35 * t18;
+			t44 = 0.2e1 * t21 * t30 * zc;
+			t45 = t27 * kn;
+			t48 = exp(-t10);
+			t51 = 0.2e1 * ZA;
+			t53 = (t51 + ZB) * t1;
+			t57 = exp(-kn * (0.1e1 + 0.3e1 * zc));
+			t59 = 0.2e1 * t45;
+			t60 = 0.4e1 * t32;
+			t64 = exp(kn * (zc - 0.3e1));
+			t68 = exp(-t13);
+			t71 = zc - 0.1e1;
+			t72 = kn * t71;
+			t74 = exp(0.2e1 * t72);
+			t78 = exp(0.3e1 * t72);
+			t80 = exp(-t9);
+			t81 = t8 * t80;
+			t85 = t7 * (t51 - ZB);
+			t88 = exp(-kn * (zc + 0.3e1));
+			t90 = exp(t72);
+			t93 = t6 + t8 * t11 * t15 - 0.4e1 * (-t18 - t20 + t25 - t29 + 0.3e1 * t32 + t37 + t39 - t41 - t44 + 0.3e1 * t45) * t48 - t53 * t57 + 0.2e1 * (-t20 + t59 + t60 - t18) * t64 + 0.2e1 * (-t20 + t59 + t60 + t18) * t68 - t8 * t11 * t74 + t53 * t78 - 0.4e1 * t3 * t81 - t85 * t88 + t85 * t90 - 0.2e1 * t18 - t26 - t30;
+			t95 = ZB * kn;
+			t98 = t7 * t7;
+			t100 = exp(-0.4e1 * kn);
+			t104 = t22 * t1;
+			t105 = t7 * t71;
+			t116 = t22 * zc;
+			t120 = exp(0.2e1 * kn * (zc - 0.2e1));
+			t127 = exp(0.4e1 * t72);
+			t139 = -0.2e1 * t95 * t6 + 0.2e1 * t95 * t98 * t100 - 0.8e1 * t104 * t105 * t15 + 0.16e2 * t95 * (-t44 + t39 + t37 - t29 - t18 - t41 + t25) * t48 + 0.8e1 * t104 * t105 * t74 - 0.8e1 * t116 * t8 * t120 + 0.8e1 * t116 * t81 - 0.2e1 * t95 * t2 * t127 + 0.2e1 * t95 * t30 + 0.2e1 * t26 * ZB * kn + 0.4e1 * t26 * kn * ZA;
+			_C4B = t93 * del_rho / t139;
+			
+			
+		}
+		
+		/*******************************************/
+		/*       calculate the velocities etc      */
+		/*******************************************/
+		
+		if ( z < zc ) {
+			t4 = exp(-kn * z);
+			t10 = exp(kn * (z - zc));
+			u1=u1a = (_C1A + z * _C3A) * t4 + (_C2A + z * _C4A) * t10;
+			
+			t1 = kn * z;
+			t2 = exp(-t1);
+			t6 = exp(kn * (z - zc));
+			t10 = 0.1e1 / kn;
+			u2=u2a = t2 * _C1A - t6 * _C2A + t2 * (-0.1e1 + t1) * _C3A * t10 - t6 * (0.1e1 + t1) * _C4A * t10;
+			
+			t1 = ZA * kn;
+			t3 = exp(-kn * z);
+			t8 = exp(kn * (z - zc));
+			u3=u3a = -0.2e1 * t1 * t3 * _C1A + 0.2e1 * t1 * t8 * _C2A - 0.2e1 * t1 * t3 * z * _C3A + 0.2e1 * t1 * t8 * z * _C4A;
+			
+			t2 = kn * z;
+			t6 = exp(-t2);
+			t14 = exp(kn * (z - zc));
+			u4=u4a = -0.2e1 * ZA * (-_C3A + kn * _C1A + t2 * _C3A) * t6 - 0.2e1 * ZA * (_C4A + kn * _C2A + t2 * _C4A) * t14;
+			
+			Z=ZA;
+			del_rho = 0.0;
+			
+		} else {
+			t5 = exp(kn * (zc - z));
+			t11 = exp(kn * (z - 0.1e1));
+			t15 = kn * kn;
+			u1=u1b = (_C1B + z * _C3B) * t5 + (_C2B + z * _C4B) * t11 - del_rho / ZB / t15;
+			
+			t3 = exp(kn * (zc - z));
+			t7 = exp(kn * (z - 0.1e1));
+			t9 = kn * z;
+			t12 = 0.1e1 / kn;
+			u2=u2b = t3 * _C1B - t7 * _C2B + t3 * (-0.1e1 + t9) * _C3B * t12 - t7 * (0.1e1 + t9) * _C4B * t12;
+			
+			t1 = ZB * kn;
+			t4 = exp(kn * (zc - z));
+			t9 = exp(kn * (z - 0.1e1));
+			u3=u3b = -0.2e1 * t1 * t4 * _C1B + 0.2e1 * t1 * t9 * _C2B - 0.2e1 * t1 * t4 * z * _C3B + 0.2e1 * t1 * t9 * z * _C4B;
+			
+			t2 = kn * z;
+			t8 = exp(kn * (zc - z));
+			t17 = exp(kn * (z - 0.1e1));
+			u4=u4b = -0.2e1 * ZB * (-_C3B + kn * _C1B + t2 * _C3B) * t8 - 0.2e1 * ZB * (_C4B + kn * _C2B + t2 * _C4B) * t17 + 0.1e1 / kn * del_rho;
+			
+			Z=ZB;
+		}
+		
+		
+		
+		pp = (double)-(u3 + 2.0*n*M_PI*Z*u2)*cos(n*M_PI*x); /* pressure */
+		
+		txx = (double)(u3 + 4*Z*n*M_PI*u2)*cos(n*M_PI*x); /* xx stress */
+		sum5 += pp;
+		sum6 += txx;
+		
+		u1 *= cos(n*M_PI*x); /* z velocity */
+		sum1 += u1;
+		u2 *= sin(n*M_PI*x); /* x velocity */
+		sum2 += u2;
+		u3 *= cos(n*M_PI*x); /* zz stress */
+		sum3 += u3;
+		u4 *= sin(n*M_PI*x); /* zx stress */
+		sum4 += u4;
+		
+		rho = del_rho* cos(n*M_PI*x); /* density */
+		sum7 += rho;
+	}/* n */
+	
+	/* include terms for n=0 now */
+	if( z >= zc ){
+		del_rho = sigma*dx;
+		rho = del_rho; /* density */
+		sum7 += rho;
+		u3 = del_rho*(z-zc); /* zz stress */
+		sum3 += u3;
+		
+		txx = u3; /* xx stress */
+		pp = -u3; /* pressure */
+		sum5 += pp;
+		sum6 += txx;
+		
+	}
+	
+	mag=sqrt(sum1*sum1+sum2*sum2);
+	//printf("%0.7g %0.7g %0.7g %0.7g %0.7g %0.7g\n",x,y,z,sum3,sum2,sum1);
+	//printf("%0.7g %0.7g %0.7g\n%0.7g %0.7g %0.7g\n\n\n",x,y,z,x+sum3,y+sum2,z+sum1);
+	/*printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7);*/
+	
+	
+	/* Output */
+	if( vel != NULL ) {
+		vel[0] = sum2;
+		vel[1] = sum1;
+	}
+	if( presssure != NULL ) {
+		(*presssure) = sum5;
+	}
+	if( total_stress != NULL ) {
+		total_stress[0] = sum6;
+		total_stress[1] = sum3;
+		total_stress[2] = sum4;
+	}
+	if( strain_rate != NULL ) {
+		if( z<zc ) {
+			Z = ZA;
+		}
+		else {
+			Z = ZB;
+		}
+		strain_rate[0] = (sum6+sum5)/(2.0*Z);
+		strain_rate[1] = (sum3+sum5)/(2.0*Z);
+		strain_rate[2] = (sum4)/(2.0*Z);
+	}
+	/* Value checks, could be cleaned up if needed. Julian Giordani 9-Oct-2006*/
+        if( fabs( sum5 - ( -0.5*(sum6+sum3) ) ) > 1e-5 ) {
+                assert(0);
+        }
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solKx/Analytic_solKx.c
--- a/SysTest/AnalyticPlugins/Velic_solKx/Analytic_solKx.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,187 +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:
-*+		Mirko Velic
-*+		Julian Giordani
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Patrick Sunter
-** $Id: solKx.c 636 2006-09-08 03:07:06Z JulianGiordani $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <stdio.h>
-#include <string.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include "Analytic_solKx.h"
-
-const Type Velic_solKx_Type = "Underworld_Velic_solKx";
-
-void Velic_solKx_ViscosityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* viscosity ) {
-	Velic_solKx* self = (Velic_solKx*) analyticSolution;
-	
-	_Velic_solKx( coord, self->sigma, self->_m, self->n, self->B, NULL, NULL, NULL, NULL, viscosity );
-}
-
-void Velic_solKx_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
-	Velic_solKx* self = (Velic_solKx*) analyticSolution;
-	
-	_Velic_solKx( coord, self->sigma, self->_m, self->n, self->B, NULL, pressure, NULL, NULL, NULL );
-}
-
-void Velic_solKx_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
-	Velic_solKx* self = (Velic_solKx*) analyticSolution;
-	
-	_Velic_solKx( coord, self->sigma, self->_m, self->n, self->B, velocity, NULL, NULL, NULL, NULL );
-}
-
-void Velic_solKx_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
-	Velic_solKx* self = (Velic_solKx*) analyticSolution;
-	
-	_Velic_solKx( coord, self->sigma, self->_m, self->n, self->B, NULL, NULL, stress, NULL, NULL );
-}
-
-
-void Velic_solKx_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
-	Velic_solKx* self = (Velic_solKx*) analyticSolution;
-	
-	_Velic_solKx( coord, self->sigma, self->_m, self->n, self->B, NULL, NULL, NULL, strainRate, NULL );
-}
-	
-void _Velic_solKx_Init( Velic_solKx* self, double sigma, double _m, double B, int n ) {
-	// TODO	Bool                     correctInput = True;
-	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
-        self->_getAnalyticVelocity    = Velic_solKx_VelocityFunction;
-	self->_getAnalyticPressure    = Velic_solKx_PressureFunction;
-	self->_getAnalyticTotalStress = Velic_solKx_StressFunction;
-	self->_getAnalyticStrainRate  = Velic_solKx_StrainRateFunction;
-
-	self->sigma = sigma;
-	self->_m = _m;
-	self->B = B;
-	self->n = n;
-}
-
-void _Velic_solKx_Build( void* analyticSolution, void* data ) {
-	Velic_solKx*          self  = (Velic_solKx*)analyticSolution;
-
-	_AnalyticSolution_Build( self, data );
-}
-
-void _Velic_solKx_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
-	Velic_solKx* self = (Velic_solKx*) analyticSolution;
-	FeVariable*              velocityField;
-	FeVariable*              pressureField;
-	FeVariable*              stressField;
-	FeVariable*              strainRateField;
-	FeVariable*              recoveredStrainRateField;
-	FeVariable*              viscosityField;
-	FeVariable*              recoveredStressField;
-	FeVariable*              recoveredPressureField;
-	double                   sigma, _m, B, twiceB;
-	int                      n;
-
-	/* Construct Parent */
-	_AnalyticSolution_AssignFromXML( self, cf, data );
-
-	/* Create Analytic Fields */
-	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solKx_VelocityFunction );
-
-	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solKx_PressureFunction );
-
-	viscosityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"ViscosityField", FeVariable, False, data );
-	if ( viscosityField  ) 
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, viscosityField, Velic_solKx_ViscosityFunction );
-
-	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False, data );
-	if ( stressField  ) 
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solKx_StressFunction );
-
-	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
-	if ( strainRateField   )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solKx_StrainRateFunction );
-
-	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
-	if ( recoveredStrainRateField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solKx_StrainRateFunction );
-
-	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
-	if ( recoveredStressField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solKx_StressFunction );
-
-	recoveredPressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredPressureField", FeVariable, False, data );
-	if ( recoveredPressureField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredPressureField, Velic_solKx_PressureFunction );
-
-
-	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solKx_sigma", 1.0  );
-	_m = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"wavenumberY", 1  );
-	n = Stg_ComponentFactory_GetRootDictInt( cf, "wavenumberX", 1 );
-	twiceB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solKx_twiceB", 2.0  );
-	B = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solKx_B", 0.5 * twiceB  );
-
-	_Velic_solKx_Init( self, sigma, _m, B, n );
-
-}
-
-void* _Velic_solKx_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Velic_solKx);
-	Type                                                      type = Velic_solKx_Type;
-	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
-	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
-	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solKx_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Velic_solKx_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _Velic_solKx_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 Underworld_Velic_solKx_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Velic_solKx_Type, (Name)"0", _Velic_solKx_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solKx/Analytic_solKx.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solKx/Analytic_solKx.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,187 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Mirko Velic
+*+		Julian Giordani
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Patrick Sunter
+** $Id: solKx.c 636 2006-09-08 03:07:06Z JulianGiordani $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <stdio.h>
+#include <string.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include "Analytic_solKx.h"
+
+const Type Velic_solKx_Type = "Underworld_Velic_solKx";
+
+void Velic_solKx_ViscosityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* viscosity ) {
+	Velic_solKx* self = (Velic_solKx*) analyticSolution;
+	
+	_Velic_solKx( coord, self->sigma, self->_m, self->n, self->B, NULL, NULL, NULL, NULL, viscosity );
+}
+
+void Velic_solKx_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
+	Velic_solKx* self = (Velic_solKx*) analyticSolution;
+	
+	_Velic_solKx( coord, self->sigma, self->_m, self->n, self->B, NULL, pressure, NULL, NULL, NULL );
+}
+
+void Velic_solKx_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
+	Velic_solKx* self = (Velic_solKx*) analyticSolution;
+	
+	_Velic_solKx( coord, self->sigma, self->_m, self->n, self->B, velocity, NULL, NULL, NULL, NULL );
+}
+
+void Velic_solKx_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
+	Velic_solKx* self = (Velic_solKx*) analyticSolution;
+	
+	_Velic_solKx( coord, self->sigma, self->_m, self->n, self->B, NULL, NULL, stress, NULL, NULL );
+}
+
+
+void Velic_solKx_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
+	Velic_solKx* self = (Velic_solKx*) analyticSolution;
+	
+	_Velic_solKx( coord, self->sigma, self->_m, self->n, self->B, NULL, NULL, NULL, strainRate, NULL );
+}
+	
+void _Velic_solKx_Init( Velic_solKx* self, double sigma, double _m, double B, int n ) {
+	// TODO	Bool                     correctInput = True;
+	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
+        self->_getAnalyticVelocity    = Velic_solKx_VelocityFunction;
+	self->_getAnalyticPressure    = Velic_solKx_PressureFunction;
+	self->_getAnalyticTotalStress = Velic_solKx_StressFunction;
+	self->_getAnalyticStrainRate  = Velic_solKx_StrainRateFunction;
+
+	self->sigma = sigma;
+	self->_m = _m;
+	self->B = B;
+	self->n = n;
+}
+
+void _Velic_solKx_Build( void* analyticSolution, void* data ) {
+	Velic_solKx*          self  = (Velic_solKx*)analyticSolution;
+
+	_AnalyticSolution_Build( self, data );
+}
+
+void _Velic_solKx_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
+	Velic_solKx* self = (Velic_solKx*) analyticSolution;
+	FeVariable*              velocityField;
+	FeVariable*              pressureField;
+	FeVariable*              stressField;
+	FeVariable*              strainRateField;
+	FeVariable*              recoveredStrainRateField;
+	FeVariable*              viscosityField;
+	FeVariable*              recoveredStressField;
+	FeVariable*              recoveredPressureField;
+	double                   sigma, _m, B, twiceB;
+	int                      n;
+
+	/* Construct Parent */
+	_AnalyticSolution_AssignFromXML( self, cf, data );
+
+	/* Create Analytic Fields */
+	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solKx_VelocityFunction );
+
+	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solKx_PressureFunction );
+
+	viscosityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"ViscosityField", FeVariable, False, data );
+	if ( viscosityField  ) 
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, viscosityField, Velic_solKx_ViscosityFunction );
+
+	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False, data );
+	if ( stressField  ) 
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solKx_StressFunction );
+
+	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
+	if ( strainRateField   )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solKx_StrainRateFunction );
+
+	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
+	if ( recoveredStrainRateField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solKx_StrainRateFunction );
+
+	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
+	if ( recoveredStressField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solKx_StressFunction );
+
+	recoveredPressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredPressureField", FeVariable, False, data );
+	if ( recoveredPressureField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredPressureField, Velic_solKx_PressureFunction );
+
+
+	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solKx_sigma", 1.0  );
+	_m = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"wavenumberY", 1  );
+	n = Stg_ComponentFactory_GetRootDictInt( cf, "wavenumberX", 1 );
+	twiceB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solKx_twiceB", 2.0  );
+	B = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solKx_B", 0.5 * twiceB  );
+
+	_Velic_solKx_Init( self, sigma, _m, B, n );
+
+}
+
+void* _Velic_solKx_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Velic_solKx);
+	Type                                                      type = Velic_solKx_Type;
+	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
+	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
+	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solKx_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Velic_solKx_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _Velic_solKx_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 Underworld_Velic_solKx_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Velic_solKx_Type, (Name)"0", _Velic_solKx_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solKx/solKx.c
--- a/SysTest/AnalyticPlugins/Velic_solKx/solKx.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,551 +0,0 @@
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-
-void _Velic_solKx( 
-		double pos[],
-		double _sigma,
-		double _m, int _n, 
-		double _B,
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[], double* viscosity );
-
-
-int main( int argc, char **argv )
-{
-	int i,j;
-	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
-	double x,z;
-	
-	for (i=0;i<101;i++){
-		for(j=0;j<101;j++){
-			x = i/100.0;
-			z = j/100.0;
-			
-			pos[0] = x;
-			pos[1] = z;
-			_Velic_solKx(
-					pos,
-					1.0,
-					(double)1, 1,
-					log(100.0)/2.0,
-					vel, &pressure, total_stress, strain_rate, NULL );
-			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
-					pos[0],pos[1],
-					vel[0],vel[1], pressure, 
-					total_stress[0], total_stress[1], total_stress[2], 
-					strain_rate[0], strain_rate[1], strain_rate[2] );
-		}
-		printf("\n");
-	}
-	
-	return 0;
-}
-
-
-
-
-/* this solution matches the stream function values in Zhong's paper for the few given viscosity constrasts */
-void _Velic_solKx( 
-		double pos[],
-		double _sigma, /* density */
-		double _m, int _n, /* wavelength in z, wavenumber in x */
-		double _B, /* viscosity parameter */
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[], double* viscosity )
-{
-	double Z;
-	double u1,u2,u3,u4,u5,u6;
-	double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,x,z;
-	double sigma;
-	int n;
-	double kn;
-	double _C1,_C2,_C3,_C4;
-	double B, Rp, UU, VV;
-	double rho,a,b,r,_aa,_bb,AA,BB,Rm,km,SS;
-	
-	double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
-	double t11,t12,t13,t14,t15,t16,t17,t18,t19,t20;
-	double t21,t22,t23,t24,t25,t26,t28,t30,t31,t32;
-	double t33,t34,t35,t36,t37,t38,t39,t41,t42,t43;
-	double t45,t46,t47,t48,t50,t52,t53,t54,t56,t57;
-	double t58,t59,t60,t61,t62,t63,t64,t65,t66,t67;
-	double t68,t69,t70,t71,t72,t73,t74,t75,t76,t77;
-	double t78,t79,t80,t81,t82,t83,t84,t85,t86,t87;
-	double t88,t90,t91,t92,t93,t95,t101,t102,t103,t104;
-	double t111,t112,t117,t120,t125,t126,t128,t130,t135,t137;
-	double t142,t143,t146,t147,t150,t151,t152,t160,t170;
-	
-	
-	
-	/*************************************************************************/
-	/*************************************************************************/
-	/* rho = -sin(km*z)*cos(kn*x) */ 
-	Z = exp( 2.0 * B * x );
-	B = _B; /* viscosity parameter must be non-zero*/
-	km = _m*M_PI; /* solution valid for km not zero -- should get trivial solution if km=0 */
-	n = _n; /* solution valid for n not zero */
-	kn = (double)_n*M_PI;
-	sigma = _sigma;
-	/*************************************************************************/
-	/*************************************************************************/
-	a = B*B + km*km;
-	b = 2.0*km*B;
-	r = sqrt(a*a + b*b);
-	Rp = sqrt( (r+a)/2.0 );
-	Rm  = sqrt( (r-a)/2.0 );
-	UU  = Rp - B;
-	VV = Rp + B;
-	
-	x = pos[0];
-	z = pos[1];
-	
-	sum1=0.0;
-	sum2=0.0;
-	sum3=0.0;
-	sum4=0.0;
-	sum5=0.0;
-	sum6=0.0;
-	sum7=0.0;
-	
-	
-	/*******************************************/
-	/*         calculate the constants         */
-	/*******************************************/
-	
-	
-	t1 = kn * kn;
-	t4 = km * km;
-	t6 = t4 * t4;
-	t7 = B * B;
-	t9 = 0.4e1 * t7 * t4;
-	t12 = 0.8e1 * t7 * kn * km;
-	t14 = 0.4e1 * t7 * t1;
-	t16 = 0.2e1 * t4 * t1;
-	t17 = t1 * t1;
-	_aa = -0.4e1 * B * t1 * sigma * (t4 + t1) / (t6 + t9 + t12 + t14 + t16 + t17) / (t6 + t9 - t12 + t14 + t16 + t17);
-	
-	t2 = kn * kn;
-	t3 = t2 * t2;
-	t4 = B * B;
-	t6 = 0.4e1 * t4 * t2;
-	t7 = km * km;
-	t9 = 0.4e1 * t7 * t4;
-	t10 = t7 * t7;
-	t12 = 0.2e1 * t7 * t2;
-	t16 = 0.8e1 * t4 * kn * km;
-	_bb = sigma * kn * (t3 - t6 + t9 + t10 + t12) / (t10 + t9 + t16 + t6 + t12 + t3) / (t10 + t9 - t16 + t6 + t12 + t3);
-	
-	AA = _aa;
-	BB = _bb;
-	
-	t1 = -B + Rp;
-	t2 = Rm * t1;
-	t3 = Rm * Rp;
-	t4 = Rm * B;
-	t6 = 0.2e1 * B * kn;
-	t7 = t3 + t4 + t6;
-	t11 = Rp * Rp;
-	t13 = 0.2e1 * B * Rp;
-	t14 = B * B;
-	t15 = 0.3e1 * t14;
-	t16 = kn * kn;
-	t17 = Rm * Rm;
-	t18 = t11 + t13 - t15 + t16 - t17;
-	t20 = t2 * t18 * BB;
-	t22 = -Rm + kn;
-	t23 = cos(t22);
-	t25 = t3 + t4 - t6;
-	t30 = Rm + kn;
-	t31 = cos(t30);
-	t34 = t2 * t18 * AA;
-	t39 = sin(t30);
-	t45 = sin(t22);
-	t50 = exp(-0.3e1 * Rp - B);
-	t52 = Rp + B;
-	t53 = Rm * t52;
-	t54 = t3 - t4 - t6;
-	t58 = t11 - t13 - t17 - t15 + t16;
-	t60 = t53 * t58 * BB;
-	t63 = t3 - t4 + t6;
-	t70 = t53 * t58 * AA;
-	t83 = exp(-t52);
-	t85 = t11 * B;
-	t86 = t14 * Rp;
-	t88 = t17 * Rp;
-	t93 = t17 * B;
-	t101 = 0.8e1 * t14 * BB * kn * Rp;
-	t103 = 0.2e1 * Rm;
-	t104 = cos(t103);
-	t117 = sin(t103);
-	t130 = exp(-0.2e1 * Rp);
-	t135 = exp(-0.4e1 * Rp);
-	t146 = t17 * t14;
-	t150 = t17 * t11;
-	_C1 = (((-0.2e1 * t2 * t7 * AA + t20) * t23 + (-0.2e1 * t2 * t25 * AA - t20) * t31 + (t34 - 0.2e1 * t2 * t25 * BB) * t39 + (-t34 - 0.2e1 * t2 * t7 * BB) * t45) * t50 + ((0.2e1 * t53 * t54 * AA + t60) * t23 + (0.2e1 * t53 * t63 * AA - t60) * t31 + (t70 + 0.2e1 * t53 * t63 * BB) * t39 + (-t70 + 0.2e1 * t53 * t54 * BB) * t45) * t83 + ((-0.2e1 * Rp * (t85 + 0.2e1 * t86 + 0.2e1 * t88 - 0.3e1 * t14 * B + t16 * B + t93) * AA - t101) * t104 + (-0.2e1 * t3 * (t11 - 0.5e1 * t14 + t16 - t17) * AA - 0.8e1 * B * BB * kn * Rm * Rp) * t117 + 0.2e1 * B * (t11 * Rp + 0.2e1 * t85 - 0.3e1 * t86 + t88 + t16 * Rp + 0.2e1 * t93) * AA + t101) * t130 + 0.4e1 * t17 * t1 * t52 * AA * t135) / (((0.8e1 * t14 + 0.8e1 * t17) * t11 * t104 - 0.8e1 * t11 * t14 - 0.8e1 * t146) * t130 + (-0.4e1 * t150 + 0.4e1 * t146) * t135 - 0.4e1 * t150 + 0.4e1 * t146);
-	
-	t1 = B * B;
-	t2 = t1 * kn;
-	t4 = 0.8e1 * t2 * Rp;
-	t5 = Rp * Rp;
-	t6 = t5 * Rp;
-	t7 = Rm * t6;
-	t8 = Rp * t1;
-	t10 = 0.5e1 * t8 * Rm;
-	t11 = kn * kn;
-	t12 = t11 * Rp;
-	t13 = t12 * Rm;
-	t14 = t11 * B;
-	t15 = t14 * Rm;
-	t16 = Rm * Rm;
-	t17 = t16 * Rm;
-	t18 = t17 * Rp;
-	t20 = Rm * t5 * B;
-	t21 = t17 * B;
-	t22 = t1 * B;
-	t24 = 0.3e1 * t22 * Rm;
-	t25 = -t4 + t7 - t10 + t13 + t15 - t18 - t20 - t21 - t24;
-	t28 = 0.3e1 * t22 * Rp;
-	t30 = 0.2e1 * t2 * Rm;
-	t31 = t16 * t1;
-	t32 = t16 * t5;
-	t33 = t6 * B;
-	t34 = t16 * Rp;
-	t35 = t34 * B;
-	t36 = t5 * t1;
-	t37 = 0.2e1 * t36;
-	t38 = B * kn;
-	t39 = Rm * Rp;
-	t41 = 0.2e1 * t38 * t39;
-	t42 = t12 * B;
-	t43 = -t28 + t30 + t31 + t32 + t33 + t35 + t37 + t41 + t42;
-	t47 = -Rm + kn;
-	t48 = cos(t47);
-	t50 = t13 + t15 - t18 - t24 - t20 - t21 + t7 - t10 + t4;
-	t52 = -t30 + t37 + t33 - t28 + t31 + t35 - t41 + t32 + t42;
-	t56 = Rm + kn;
-	t57 = cos(t56);
-	t63 = sin(t56);
-	t69 = sin(t47);
-	t74 = exp(-0.3e1 * Rp - B);
-	t76 = Rp + B;
-	t77 = Rm * t76;
-	t80 = 0.3e1 * t1;
-	t81 = t5 - 0.2e1 * B * Rp - t16 - t80 + t11;
-	t83 = t77 * t81 * AA;
-	t84 = Rm * B;
-	t85 = 0.2e1 * t38;
-	t86 = t39 - t84 - t85;
-	t92 = t39 - t84 + t85;
-	t102 = t77 * t81 * BB;
-	t112 = exp(-t76);
-	t120 = kn * Rm;
-	t125 = 0.2e1 * Rm;
-	t126 = cos(t125);
-	t137 = t1 * BB;
-	t142 = sin(t125);
-	t152 = exp(-0.2e1 * Rp);
-	t160 = exp(-0.4e1 * Rp);
-	_C2 = (((t25 * AA + 0.2e1 * t43 * BB) * t48 + (t50 * AA - 0.2e1 * t52 * BB) * t57 + (0.2e1 * t52 * AA + t50 * BB) * t63 + (-0.2e1 * t43 * AA + t25 * BB) * t69) * t74 + ((-t83 + 0.2e1 * t77 * t86 * BB) * t48 + (-t83 - 0.2e1 * t77 * t92 * BB) * t57 + (0.2e1 * t77 * t92 * AA - t102) * t63 + (-0.2e1 * t77 * t86 * AA - t102) * t69) * t112 + ((0.2e1 * t39 * (t5 - 0.5e1 * t1 + t11 - t16) * AA + 0.8e1 * B * BB * t120 * Rp) * t126 + (-0.2e1 * Rp * (t5 * B + 0.2e1 * t8 + 0.2e1 * t34 - 0.3e1 * t22 + t14 + t16 * B) * AA - 0.8e1 * t137 * kn * Rp) * t142 - 0.2e1 * t84 * (t5 + t80 + t16 - t11) * AA + 0.8e1 * t137 * t120) * t152 + (-0.2e1 * t83 - 0.8e1 * t38 * t77 * BB) * t160) / (((0.8e1 * t1 + 0.8e1 * t16) * t5 * t126 - 0.8e1 * t36 - 0.8e1 * t31) * t152 + (-0.4e1 * t32 + 0.4e1 * t31) * t160 - 0.4e1 * t32 + 0.4e1 * t31);
-	
-	t1 = -B + Rp;
-	t2 = Rm * t1;
-	t3 = Rm * Rp;
-	t4 = Rm * B;
-	t6 = 0.2e1 * B * kn;
-	t7 = t3 + t4 + t6;
-	t11 = Rp * Rp;
-	t13 = 0.2e1 * B * Rp;
-	t14 = B * B;
-	t15 = 0.3e1 * t14;
-	t16 = kn * kn;
-	t17 = Rm * Rm;
-	t18 = t11 + t13 - t15 + t16 - t17;
-	t20 = t2 * t18 * BB;
-	t22 = -Rm + kn;
-	t23 = cos(t22);
-	t25 = t3 + t4 - t6;
-	t30 = Rm + kn;
-	t31 = cos(t30);
-	t34 = t2 * t18 * AA;
-	t39 = sin(t30);
-	t45 = sin(t22);
-	t50 = exp(-0.3e1 * Rp - B);
-	t52 = Rp + B;
-	t53 = Rm * t52;
-	t54 = t3 - t4 - t6;
-	t58 = t11 - t13 - t17 - t15 + t16;
-	t60 = t53 * t58 * BB;
-	t63 = t3 - t4 + t6;
-	t70 = t53 * t58 * AA;
-	t83 = exp(-t52);
-	t85 = t17 * B;
-	t86 = t17 * Rp;
-	t91 = t11 * B;
-	t92 = t14 * Rp;
-	t101 = 0.8e1 * t14 * BB * kn * Rp;
-	t103 = 0.2e1 * Rm;
-	t104 = cos(t103);
-	t117 = sin(t103);
-	t130 = exp(-0.2e1 * Rp);
-	t143 = t17 * t14;
-	t147 = t17 * t11;
-	t151 = exp(-0.4e1 * Rp);
-	_C3 = (((0.2e1 * t2 * t7 * AA - t20) * t23 + (0.2e1 * t2 * t25 * AA + t20) * t31 + (-t34 + 0.2e1 * t2 * t25 * BB) * t39 + (t34 + 0.2e1 * t2 * t7 * BB) * t45) * t50 + ((-0.2e1 * t53 * t54 * AA - t60) * t23 + (-0.2e1 * t53 * t63 * AA + t60) * t31 + (-t70 - 0.2e1 * t53 * t63 * BB) * t39 + (t70 - 0.2e1 * t53 * t54 * BB) * t45) * t83 + ((0.2e1 * Rp * (t85 - 0.2e1 * t86 - 0.3e1 * t14 * B + t16 * B + t91 - 0.2e1 * t92) * AA + t101) * t104 + (0.2e1 * t3 * (t11 - 0.5e1 * t14 + t16 - t17) * AA + 0.8e1 * B * BB * kn * Rm * Rp) * t117 - 0.2e1 * B * (t11 * Rp - 0.2e1 * t91 - 0.3e1 * t92 + t86 + t16 * Rp - 0.2e1 * t85) * AA - t101) * t130 + 0.4e1 * t17 * t1 * t52 * AA) / (((0.8e1 * t14 + 0.8e1 * t17) * t11 * t104 - 0.8e1 * t11 * t14 - 0.8e1 * t143) * t130 + (-0.4e1 * t147 + 0.4e1 * t143) * t151 - 0.4e1 * t147 + 0.4e1 * t143);
-	
-	t2 = Rm * (-B + Rp);
-	t3 = Rp * Rp;
-	t6 = B * B;
-	t7 = 0.3e1 * t6;
-	t8 = kn * kn;
-	t9 = Rm * Rm;
-	t10 = t3 + 0.2e1 * B * Rp - t7 + t8 - t9;
-	t12 = t2 * t10 * AA;
-	t13 = Rm * Rp;
-	t14 = Rm * B;
-	t15 = B * kn;
-	t16 = 0.2e1 * t15;
-	t17 = t13 + t14 + t16;
-	t22 = -Rm + kn;
-	t23 = cos(t22);
-	t25 = t13 + t14 - t16;
-	t30 = Rm + kn;
-	t31 = cos(t30);
-	t37 = t2 * t10 * BB;
-	t39 = sin(t30);
-	t45 = sin(t22);
-	t50 = exp(-0.3e1 * Rp - B);
-	t52 = Rp * t6;
-	t54 = 0.5e1 * Rm * t52;
-	t56 = Rm * t3 * B;
-	t57 = t6 * B;
-	t59 = 0.3e1 * t57 * Rm;
-	t60 = t6 * kn;
-	t62 = 0.8e1 * t60 * Rp;
-	t63 = t9 * Rm;
-	t64 = Rp * t63;
-	t65 = B * t8;
-	t66 = t65 * Rm;
-	t67 = B * t63;
-	t68 = Rp * t8;
-	t69 = t68 * Rm;
-	t70 = t3 * Rp;
-	t71 = Rm * t70;
-	t72 = -t54 + t56 + t59 - t62 - t64 - t66 + t67 + t69 + t71;
-	t74 = t70 * B;
-	t75 = t9 * t3;
-	t76 = t3 * t6;
-	t77 = 0.2e1 * t76;
-	t79 = 0.3e1 * t57 * Rp;
-	t81 = 0.2e1 * t15 * t13;
-	t82 = t9 * Rp;
-	t83 = t82 * B;
-	t84 = t68 * B;
-	t85 = t9 * t6;
-	t87 = 0.2e1 * t60 * Rm;
-	t88 = t74 - t75 - t77 - t79 + t81 + t83 + t84 - t85 - t87;
-	t93 = -t66 + t69 - t64 + t59 - t54 + t62 + t56 + t71 + t67;
-	t95 = -t77 + t74 + t87 - t85 - t79 + t84 - t75 + t83 - t81;
-	t112 = exp(-Rp - B);
-	t120 = kn * Rm;
-	t125 = 0.2e1 * Rm;
-	t126 = cos(t125);
-	t137 = t6 * BB;
-	t142 = sin(t125);
-	t152 = exp(-0.2e1 * Rp);
-	t170 = exp(-0.4e1 * Rp);
-	_C4 = (((t12 + 0.2e1 * t2 * t17 * BB) * t23 + (t12 - 0.2e1 * t2 * t25 * BB) * t31 + (0.2e1 * t2 * t25 * AA + t37) * t39 + (-0.2e1 * t2 * t17 * AA + t37) * t45) * t50 + ((-t72 * AA - 0.2e1 * t88 * BB) * t23 + (-t93 * AA + 0.2e1 * t95 * BB) * t31 + (-0.2e1 * t95 * AA - t93 * BB) * t39 + (0.2e1 * t88 * AA - t72 * BB) * t45) * t112 + ((-0.2e1 * t13 * (t3 - 0.5e1 * t6 + t8 - t9) * AA - 0.8e1 * B * BB * t120 * Rp) * t126 + (0.2e1 * Rp * (t9 * B - 0.2e1 * t82 - 0.3e1 * t57 + t65 + t3 * B - 0.2e1 * t52) * AA + 0.8e1 * t137 * kn * Rp) * t142 - 0.2e1 * t14 * (t3 + t7 + t9 - t8) * AA + 0.8e1 * t137 * t120) * t152 + 0.2e1 * t12 + 0.8e1 * t15 * t2 * BB) / (((0.8e1 * t6 + 0.8e1 * t9) * t3 * t126 - 0.8e1 * t76 - 0.8e1 * t85) * t152 + (-0.4e1 * t75 + 0.4e1 * t85) * t170 - 0.4e1 * t75 + 0.4e1 * t85);
-	
-	
-	/*******************************************/
-	/*       calculate the velocities etc      */
-	/*******************************************/
-	
-	
-	t2 = exp(UU * x);
-	t3 = Rm * x;
-	t4 = cos(t3);
-	t6 = sin(t3);
-	t11 = exp(-VV * x);
-	t18 = exp(-0.2e1 * x * B);
-	t19 = kn * x;
-	t20 = cos(t19);
-	t22 = sin(t19);
-	u1 = -km * (t2 * (_C1 * t4 + _C2 * t6) + t11 * (_C3 * t4 + _C4 * t6) + t18 * (AA * t20 + BB * t22));
-	
-	t2 = exp(UU * x);
-	t4 = Rm * x;
-	t5 = cos(t4);
-	t7 = sin(t4);
-	t18 = exp(-VV * x);
-	t32 = exp(-0.2e1 * x * B);
-	t34 = kn * x;
-	t35 = cos(t34);
-	t37 = sin(t34);
-	u2 = UU * t2 * (_C1 * t5 + _C2 * t7) + t2 * (-_C1 * t7 * Rm + _C2 * t5 * Rm) - VV * t18 * (_C3 * t5 + _C4 * t7) + t18 * (-_C3 * t7 * Rm + _C4 * t5 * Rm) - 0.2e1 * B * t32 * (AA * t35 + BB * t37) + t32 * (-AA * t37 * kn + BB * t35 * kn);
-	
-	t2 = 0.2e1 * x * B;
-	t3 = exp(t2);
-	t6 = exp(UU * x);
-	t8 = Rm * x;
-	t9 = cos(t8);
-	t11 = sin(t8);
-	t22 = exp(-VV * x);
-	t34 = exp(-t2);
-	t36 = kn * x;
-	t37 = cos(t36);
-	t39 = sin(t36);
-	u3 = -0.2e1 * t3 * km * (UU * t6 * (_C1 * t9 + _C2 * t11) + t6 * (-_C1 * t11 * Rm + _C2 * t9 * Rm) - VV * t22 * (_C3 * t9 + _C4 * t11) + t22 * (-_C3 * t11 * Rm + _C4 * t9 * Rm) - 0.2e1 * B * t34 * (AA * t37 + BB * t39) + t34 * (-AA * t39 * kn + BB * t37 * kn));
-	
-	t2 = 0.2e1 * x * B;
-	t3 = exp(t2);
-	t4 = km * km;
-	t6 = exp(UU * x);
-	t7 = Rm * x;
-	t8 = cos(t7);
-	t9 = _C1 * t8;
-	t10 = sin(t7);
-	t11 = _C2 * t10;
-	t12 = t9 + t11;
-	t15 = exp(-VV * x);
-	t16 = _C3 * t8;
-	t17 = _C4 * t10;
-	t18 = t16 + t17;
-	t20 = exp(-t2);
-	t21 = kn * x;
-	t22 = cos(t21);
-	t23 = AA * t22;
-	t24 = sin(t21);
-	t25 = BB * t24;
-	t26 = t23 + t25;
-	t30 = UU * UU;
-	t41 = Rm * Rm;
-	t46 = VV * VV;
-	t61 = B * B;
-	t73 = kn * kn;
-	u4 = t3 * (t4 * (t6 * t12 + t15 * t18 + t20 * t26) + t30 * t6 * t12 + 0.2e1 * UU * t6 * (-_C1 * t10 * Rm + _C2 * t8 * Rm) + t6 * (-t9 * t41 - t11 * t41) + t46 * t15 * t18 - 0.2e1 * VV * t15 * (-_C3 * t10 * Rm + _C4 * t8 * Rm) + t15 * (-t16 * t41 - t17 * t41) + 0.4e1 * t61 * t20 * t26 - 0.4e1 * B * t20 * (-AA * t24 * kn + BB * t22 * kn) + t20 * (-t23 * t73 - t25 * t73));
-	
-	t2 = 0.2e1 * x * B;
-	t3 = exp(t2);
-	t4 = UU * UU;
-	t7 = exp(UU * x);
-	t9 = Rm * x;
-	t10 = cos(t9);
-	t11 = _C1 * t10;
-	t12 = sin(t9);
-	t13 = _C2 * t12;
-	t14 = t11 + t13;
-	t16 = t4 * t7;
-	t17 = _C1 * t12;
-	t19 = _C2 * t10;
-	t21 = -t17 * Rm + t19 * Rm;
-	t24 = UU * t7;
-	t25 = Rm * Rm;
-	t28 = -t11 * t25 - t13 * t25;
-	t31 = t25 * Rm;
-	t36 = VV * VV;
-	t39 = exp(-VV * x);
-	t41 = _C3 * t10;
-	t42 = _C4 * t12;
-	t43 = t41 + t42;
-	t45 = t36 * t39;
-	t46 = _C3 * t12;
-	t48 = _C4 * t10;
-	t50 = -t46 * Rm + t48 * Rm;
-	t53 = VV * t39;
-	t56 = -t41 * t25 - t42 * t25;
-	t63 = B * B;
-	t65 = exp(-t2);
-	t67 = kn * x;
-	t68 = cos(t67);
-	t69 = AA * t68;
-	t70 = sin(t67);
-	t71 = BB * t70;
-	t72 = t69 + t71;
-	t75 = t63 * t65;
-	t76 = AA * t70;
-	t78 = BB * t68;
-	t80 = -t76 * kn + t78 * kn;
-	t83 = B * t65;
-	t84 = kn * kn;
-	t87 = -t69 * t84 - t71 * t84;
-	t90 = t84 * kn;
-	t111 = km * km;
-	t128 = t4 * UU * t7 * t14 + 0.3e1 * t16 * t21 + 0.3e1 * t24 * t28 + t7 * (t17 * t31 - t19 * t31) - t36 * VV * t39 * t43 + 0.3e1 * t45 * t50 - 0.3e1 * t53 * t56 + t39 * (t46 * t31 - t48 * t31) - 0.8e1 * t63 * B * t65 * t72 + 0.12e2 * t75 * t80 - 0.6e1 * t83 * t87 + t65 * (t76 * t90 - t78 * t90) + 0.2e1 * B * (t16 * t14 + 0.2e1 * t24 * t21 + t7 * t28 + t45 * t43 - 0.2e1 * t53 * t50 + t39 * t56 + 0.4e1 * t75 * t72 - 0.4e1 * t83 * t80 + t65 * t87) - t111 * (t24 * t14 + t7 * t21 - t53 * t43 + t39 * t50 - 0.2e1 * t83 * t72 + t65 * t80) + 0.2e1 * B * t111 * (t7 * t14 + t39 * t43 + t65 * t72);
-	u5 = -t3 * t128 / km;
-	
-	t2 = 0.2e1 * x * B;
-	t3 = exp(t2);
-	t6 = exp(UU * x);
-	t8 = Rm * x;
-	t9 = cos(t8);
-	t11 = sin(t8);
-	t22 = exp(-VV * x);
-	t34 = exp(-t2);
-	t36 = kn * x;
-	t37 = cos(t36);
-	t39 = sin(t36);
-	u6 = 0.2e1 * t3 * km * (UU * t6 * (_C1 * t9 + _C2 * t11) + t6 * (-_C1 * t11 * Rm + _C2 * t9 * Rm) - VV * t22 * (_C3 * t9 + _C4 * t11) + t22 * (-_C3 * t11 * Rm + _C4 * t9 * Rm) - 0.2e1 * B * t34 * (AA * t37 + BB * t39) + t34 * (-AA * t39 * kn + BB * t37 * kn));
-	
-	
-	
-	
-	
-	SS = sin(km*z)*(exp(UU*x)*(_C1*cos(Rm*x)+_C2*sin(Rm*x)) + exp(-VV*x)*(_C3*cos(Rm*x)+_C4*sin(Rm*x)) + exp(-2*x*B)*(AA*cos(kn*x)+BB*sin(kn*x)));
-	
-	/* u1 = Vx, u2 = Vz, u3 = txx, u4 = tzx, u5 = pressure, u6 = tzz */
-	
-	
-	sum5 += u5*cos(km*z);  /* pressure */
-	u6 -= u5; /* get total stress */
-	sum6 += u6*cos(km*z);  /* xx stress */
-	
-	u1 *= cos(km*z); /* x velocity */
-	sum1 += u1;
-	u2 *= sin(km*z); /* z velocity */
-	sum2 += u2;
-	u3 -= u5; /* get total stress */
-	u3 *= cos(km*z); /* zz stress */
-	sum3 += u3;
-	u4 *= sin(km*z); /* zx stress */
-	sum4 += u4;
-	
-	rho = -sigma*sin(km*z)*cos(kn*x); /* density */
-	sum7 += rho;
-	
-	
-	mag=sqrt(u1*u1+u2*u2);
-	//printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,u1,u2,mag,SS);
-	/*printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,SS);*/
-	
-	if ( viscosity != NULL ) {
-		*viscosity = Z;
-	}
-	
-	/* Output */
-	if( vel != NULL ) {
-		vel[0] = sum2;
-		vel[1] = sum1;
-	}
-	if( presssure != NULL ) {
-		(*presssure) = sum5;
-	}
-	if( total_stress != NULL ) {
-		total_stress[0] = sum6;
-		total_stress[1] = sum3;
-		total_stress[2] = sum4;
-	}
-	if( strain_rate != NULL ) {
-		/* sigma = tau - p, tau = sigma + p, tau[] = 2*eta*strain_rate[] */
-		strain_rate[0] = (sum6+sum5)/(2.0*Z);
-		strain_rate[1] = (sum3+sum5)/(2.0*Z);
-		strain_rate[2] = (sum4)/(2.0*Z);
-	}
-	/* Value checks, could be cleaned up if needed. Julian Giordani 9-Oct-2006*/
-        if( fabs( sum5 - ( -0.5*(sum6+sum3) ) ) > 1e-5 ) {
-                assert(0);
-        }
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solKx/solKx.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solKx/solKx.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,551 @@
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+
+void _Velic_solKx( 
+		double pos[],
+		double _sigma,
+		double _m, int _n, 
+		double _B,
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[], double* viscosity );
+
+
+int main( int argc, char **argv )
+{
+	int i,j;
+	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
+	double x,z;
+	
+	for (i=0;i<101;i++){
+		for(j=0;j<101;j++){
+			x = i/100.0;
+			z = j/100.0;
+			
+			pos[0] = x;
+			pos[1] = z;
+			_Velic_solKx(
+					pos,
+					1.0,
+					(double)1, 1,
+					log(100.0)/2.0,
+					vel, &pressure, total_stress, strain_rate, NULL );
+			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
+					pos[0],pos[1],
+					vel[0],vel[1], pressure, 
+					total_stress[0], total_stress[1], total_stress[2], 
+					strain_rate[0], strain_rate[1], strain_rate[2] );
+		}
+		printf("\n");
+	}
+	
+	return 0;
+}
+
+
+
+
+/* this solution matches the stream function values in Zhong's paper for the few given viscosity constrasts */
+void _Velic_solKx( 
+		double pos[],
+		double _sigma, /* density */
+		double _m, int _n, /* wavelength in z, wavenumber in x */
+		double _B, /* viscosity parameter */
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[], double* viscosity )
+{
+	double Z;
+	double u1,u2,u3,u4,u5,u6;
+	double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,x,z;
+	double sigma;
+	int n;
+	double kn;
+	double _C1,_C2,_C3,_C4;
+	double B, Rp, UU, VV;
+	double rho,a,b,r,_aa,_bb,AA,BB,Rm,km,SS;
+	
+	double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
+	double t11,t12,t13,t14,t15,t16,t17,t18,t19,t20;
+	double t21,t22,t23,t24,t25,t26,t28,t30,t31,t32;
+	double t33,t34,t35,t36,t37,t38,t39,t41,t42,t43;
+	double t45,t46,t47,t48,t50,t52,t53,t54,t56,t57;
+	double t58,t59,t60,t61,t62,t63,t64,t65,t66,t67;
+	double t68,t69,t70,t71,t72,t73,t74,t75,t76,t77;
+	double t78,t79,t80,t81,t82,t83,t84,t85,t86,t87;
+	double t88,t90,t91,t92,t93,t95,t101,t102,t103,t104;
+	double t111,t112,t117,t120,t125,t126,t128,t130,t135,t137;
+	double t142,t143,t146,t147,t150,t151,t152,t160,t170;
+	
+	
+	
+	/*************************************************************************/
+	/*************************************************************************/
+	/* rho = -sin(km*z)*cos(kn*x) */ 
+	Z = exp( 2.0 * B * x );
+	B = _B; /* viscosity parameter must be non-zero*/
+	km = _m*M_PI; /* solution valid for km not zero -- should get trivial solution if km=0 */
+	n = _n; /* solution valid for n not zero */
+	kn = (double)_n*M_PI;
+	sigma = _sigma;
+	/*************************************************************************/
+	/*************************************************************************/
+	a = B*B + km*km;
+	b = 2.0*km*B;
+	r = sqrt(a*a + b*b);
+	Rp = sqrt( (r+a)/2.0 );
+	Rm  = sqrt( (r-a)/2.0 );
+	UU  = Rp - B;
+	VV = Rp + B;
+	
+	x = pos[0];
+	z = pos[1];
+	
+	sum1=0.0;
+	sum2=0.0;
+	sum3=0.0;
+	sum4=0.0;
+	sum5=0.0;
+	sum6=0.0;
+	sum7=0.0;
+	
+	
+	/*******************************************/
+	/*         calculate the constants         */
+	/*******************************************/
+	
+	
+	t1 = kn * kn;
+	t4 = km * km;
+	t6 = t4 * t4;
+	t7 = B * B;
+	t9 = 0.4e1 * t7 * t4;
+	t12 = 0.8e1 * t7 * kn * km;
+	t14 = 0.4e1 * t7 * t1;
+	t16 = 0.2e1 * t4 * t1;
+	t17 = t1 * t1;
+	_aa = -0.4e1 * B * t1 * sigma * (t4 + t1) / (t6 + t9 + t12 + t14 + t16 + t17) / (t6 + t9 - t12 + t14 + t16 + t17);
+	
+	t2 = kn * kn;
+	t3 = t2 * t2;
+	t4 = B * B;
+	t6 = 0.4e1 * t4 * t2;
+	t7 = km * km;
+	t9 = 0.4e1 * t7 * t4;
+	t10 = t7 * t7;
+	t12 = 0.2e1 * t7 * t2;
+	t16 = 0.8e1 * t4 * kn * km;
+	_bb = sigma * kn * (t3 - t6 + t9 + t10 + t12) / (t10 + t9 + t16 + t6 + t12 + t3) / (t10 + t9 - t16 + t6 + t12 + t3);
+	
+	AA = _aa;
+	BB = _bb;
+	
+	t1 = -B + Rp;
+	t2 = Rm * t1;
+	t3 = Rm * Rp;
+	t4 = Rm * B;
+	t6 = 0.2e1 * B * kn;
+	t7 = t3 + t4 + t6;
+	t11 = Rp * Rp;
+	t13 = 0.2e1 * B * Rp;
+	t14 = B * B;
+	t15 = 0.3e1 * t14;
+	t16 = kn * kn;
+	t17 = Rm * Rm;
+	t18 = t11 + t13 - t15 + t16 - t17;
+	t20 = t2 * t18 * BB;
+	t22 = -Rm + kn;
+	t23 = cos(t22);
+	t25 = t3 + t4 - t6;
+	t30 = Rm + kn;
+	t31 = cos(t30);
+	t34 = t2 * t18 * AA;
+	t39 = sin(t30);
+	t45 = sin(t22);
+	t50 = exp(-0.3e1 * Rp - B);
+	t52 = Rp + B;
+	t53 = Rm * t52;
+	t54 = t3 - t4 - t6;
+	t58 = t11 - t13 - t17 - t15 + t16;
+	t60 = t53 * t58 * BB;
+	t63 = t3 - t4 + t6;
+	t70 = t53 * t58 * AA;
+	t83 = exp(-t52);
+	t85 = t11 * B;
+	t86 = t14 * Rp;
+	t88 = t17 * Rp;
+	t93 = t17 * B;
+	t101 = 0.8e1 * t14 * BB * kn * Rp;
+	t103 = 0.2e1 * Rm;
+	t104 = cos(t103);
+	t117 = sin(t103);
+	t130 = exp(-0.2e1 * Rp);
+	t135 = exp(-0.4e1 * Rp);
+	t146 = t17 * t14;
+	t150 = t17 * t11;
+	_C1 = (((-0.2e1 * t2 * t7 * AA + t20) * t23 + (-0.2e1 * t2 * t25 * AA - t20) * t31 + (t34 - 0.2e1 * t2 * t25 * BB) * t39 + (-t34 - 0.2e1 * t2 * t7 * BB) * t45) * t50 + ((0.2e1 * t53 * t54 * AA + t60) * t23 + (0.2e1 * t53 * t63 * AA - t60) * t31 + (t70 + 0.2e1 * t53 * t63 * BB) * t39 + (-t70 + 0.2e1 * t53 * t54 * BB) * t45) * t83 + ((-0.2e1 * Rp * (t85 + 0.2e1 * t86 + 0.2e1 * t88 - 0.3e1 * t14 * B + t16 * B + t93) * AA - t101) * t104 + (-0.2e1 * t3 * (t11 - 0.5e1 * t14 + t16 - t17) * AA - 0.8e1 * B * BB * kn * Rm * Rp) * t117 + 0.2e1 * B * (t11 * Rp + 0.2e1 * t85 - 0.3e1 * t86 + t88 + t16 * Rp + 0.2e1 * t93) * AA + t101) * t130 + 0.4e1 * t17 * t1 * t52 * AA * t135) / (((0.8e1 * t14 + 0.8e1 * t17) * t11 * t104 - 0.8e1 * t11 * t14 - 0.8e1 * t146) * t130 + (-0.4e1 * t150 + 0.4e1 * t146) * t135 - 0.4e1 * t150 + 0.4e1 * t146);
+	
+	t1 = B * B;
+	t2 = t1 * kn;
+	t4 = 0.8e1 * t2 * Rp;
+	t5 = Rp * Rp;
+	t6 = t5 * Rp;
+	t7 = Rm * t6;
+	t8 = Rp * t1;
+	t10 = 0.5e1 * t8 * Rm;
+	t11 = kn * kn;
+	t12 = t11 * Rp;
+	t13 = t12 * Rm;
+	t14 = t11 * B;
+	t15 = t14 * Rm;
+	t16 = Rm * Rm;
+	t17 = t16 * Rm;
+	t18 = t17 * Rp;
+	t20 = Rm * t5 * B;
+	t21 = t17 * B;
+	t22 = t1 * B;
+	t24 = 0.3e1 * t22 * Rm;
+	t25 = -t4 + t7 - t10 + t13 + t15 - t18 - t20 - t21 - t24;
+	t28 = 0.3e1 * t22 * Rp;
+	t30 = 0.2e1 * t2 * Rm;
+	t31 = t16 * t1;
+	t32 = t16 * t5;
+	t33 = t6 * B;
+	t34 = t16 * Rp;
+	t35 = t34 * B;
+	t36 = t5 * t1;
+	t37 = 0.2e1 * t36;
+	t38 = B * kn;
+	t39 = Rm * Rp;
+	t41 = 0.2e1 * t38 * t39;
+	t42 = t12 * B;
+	t43 = -t28 + t30 + t31 + t32 + t33 + t35 + t37 + t41 + t42;
+	t47 = -Rm + kn;
+	t48 = cos(t47);
+	t50 = t13 + t15 - t18 - t24 - t20 - t21 + t7 - t10 + t4;
+	t52 = -t30 + t37 + t33 - t28 + t31 + t35 - t41 + t32 + t42;
+	t56 = Rm + kn;
+	t57 = cos(t56);
+	t63 = sin(t56);
+	t69 = sin(t47);
+	t74 = exp(-0.3e1 * Rp - B);
+	t76 = Rp + B;
+	t77 = Rm * t76;
+	t80 = 0.3e1 * t1;
+	t81 = t5 - 0.2e1 * B * Rp - t16 - t80 + t11;
+	t83 = t77 * t81 * AA;
+	t84 = Rm * B;
+	t85 = 0.2e1 * t38;
+	t86 = t39 - t84 - t85;
+	t92 = t39 - t84 + t85;
+	t102 = t77 * t81 * BB;
+	t112 = exp(-t76);
+	t120 = kn * Rm;
+	t125 = 0.2e1 * Rm;
+	t126 = cos(t125);
+	t137 = t1 * BB;
+	t142 = sin(t125);
+	t152 = exp(-0.2e1 * Rp);
+	t160 = exp(-0.4e1 * Rp);
+	_C2 = (((t25 * AA + 0.2e1 * t43 * BB) * t48 + (t50 * AA - 0.2e1 * t52 * BB) * t57 + (0.2e1 * t52 * AA + t50 * BB) * t63 + (-0.2e1 * t43 * AA + t25 * BB) * t69) * t74 + ((-t83 + 0.2e1 * t77 * t86 * BB) * t48 + (-t83 - 0.2e1 * t77 * t92 * BB) * t57 + (0.2e1 * t77 * t92 * AA - t102) * t63 + (-0.2e1 * t77 * t86 * AA - t102) * t69) * t112 + ((0.2e1 * t39 * (t5 - 0.5e1 * t1 + t11 - t16) * AA + 0.8e1 * B * BB * t120 * Rp) * t126 + (-0.2e1 * Rp * (t5 * B + 0.2e1 * t8 + 0.2e1 * t34 - 0.3e1 * t22 + t14 + t16 * B) * AA - 0.8e1 * t137 * kn * Rp) * t142 - 0.2e1 * t84 * (t5 + t80 + t16 - t11) * AA + 0.8e1 * t137 * t120) * t152 + (-0.2e1 * t83 - 0.8e1 * t38 * t77 * BB) * t160) / (((0.8e1 * t1 + 0.8e1 * t16) * t5 * t126 - 0.8e1 * t36 - 0.8e1 * t31) * t152 + (-0.4e1 * t32 + 0.4e1 * t31) * t160 - 0.4e1 * t32 + 0.4e1 * t31);
+	
+	t1 = -B + Rp;
+	t2 = Rm * t1;
+	t3 = Rm * Rp;
+	t4 = Rm * B;
+	t6 = 0.2e1 * B * kn;
+	t7 = t3 + t4 + t6;
+	t11 = Rp * Rp;
+	t13 = 0.2e1 * B * Rp;
+	t14 = B * B;
+	t15 = 0.3e1 * t14;
+	t16 = kn * kn;
+	t17 = Rm * Rm;
+	t18 = t11 + t13 - t15 + t16 - t17;
+	t20 = t2 * t18 * BB;
+	t22 = -Rm + kn;
+	t23 = cos(t22);
+	t25 = t3 + t4 - t6;
+	t30 = Rm + kn;
+	t31 = cos(t30);
+	t34 = t2 * t18 * AA;
+	t39 = sin(t30);
+	t45 = sin(t22);
+	t50 = exp(-0.3e1 * Rp - B);
+	t52 = Rp + B;
+	t53 = Rm * t52;
+	t54 = t3 - t4 - t6;
+	t58 = t11 - t13 - t17 - t15 + t16;
+	t60 = t53 * t58 * BB;
+	t63 = t3 - t4 + t6;
+	t70 = t53 * t58 * AA;
+	t83 = exp(-t52);
+	t85 = t17 * B;
+	t86 = t17 * Rp;
+	t91 = t11 * B;
+	t92 = t14 * Rp;
+	t101 = 0.8e1 * t14 * BB * kn * Rp;
+	t103 = 0.2e1 * Rm;
+	t104 = cos(t103);
+	t117 = sin(t103);
+	t130 = exp(-0.2e1 * Rp);
+	t143 = t17 * t14;
+	t147 = t17 * t11;
+	t151 = exp(-0.4e1 * Rp);
+	_C3 = (((0.2e1 * t2 * t7 * AA - t20) * t23 + (0.2e1 * t2 * t25 * AA + t20) * t31 + (-t34 + 0.2e1 * t2 * t25 * BB) * t39 + (t34 + 0.2e1 * t2 * t7 * BB) * t45) * t50 + ((-0.2e1 * t53 * t54 * AA - t60) * t23 + (-0.2e1 * t53 * t63 * AA + t60) * t31 + (-t70 - 0.2e1 * t53 * t63 * BB) * t39 + (t70 - 0.2e1 * t53 * t54 * BB) * t45) * t83 + ((0.2e1 * Rp * (t85 - 0.2e1 * t86 - 0.3e1 * t14 * B + t16 * B + t91 - 0.2e1 * t92) * AA + t101) * t104 + (0.2e1 * t3 * (t11 - 0.5e1 * t14 + t16 - t17) * AA + 0.8e1 * B * BB * kn * Rm * Rp) * t117 - 0.2e1 * B * (t11 * Rp - 0.2e1 * t91 - 0.3e1 * t92 + t86 + t16 * Rp - 0.2e1 * t85) * AA - t101) * t130 + 0.4e1 * t17 * t1 * t52 * AA) / (((0.8e1 * t14 + 0.8e1 * t17) * t11 * t104 - 0.8e1 * t11 * t14 - 0.8e1 * t143) * t130 + (-0.4e1 * t147 + 0.4e1 * t143) * t151 - 0.4e1 * t147 + 0.4e1 * t143);
+	
+	t2 = Rm * (-B + Rp);
+	t3 = Rp * Rp;
+	t6 = B * B;
+	t7 = 0.3e1 * t6;
+	t8 = kn * kn;
+	t9 = Rm * Rm;
+	t10 = t3 + 0.2e1 * B * Rp - t7 + t8 - t9;
+	t12 = t2 * t10 * AA;
+	t13 = Rm * Rp;
+	t14 = Rm * B;
+	t15 = B * kn;
+	t16 = 0.2e1 * t15;
+	t17 = t13 + t14 + t16;
+	t22 = -Rm + kn;
+	t23 = cos(t22);
+	t25 = t13 + t14 - t16;
+	t30 = Rm + kn;
+	t31 = cos(t30);
+	t37 = t2 * t10 * BB;
+	t39 = sin(t30);
+	t45 = sin(t22);
+	t50 = exp(-0.3e1 * Rp - B);
+	t52 = Rp * t6;
+	t54 = 0.5e1 * Rm * t52;
+	t56 = Rm * t3 * B;
+	t57 = t6 * B;
+	t59 = 0.3e1 * t57 * Rm;
+	t60 = t6 * kn;
+	t62 = 0.8e1 * t60 * Rp;
+	t63 = t9 * Rm;
+	t64 = Rp * t63;
+	t65 = B * t8;
+	t66 = t65 * Rm;
+	t67 = B * t63;
+	t68 = Rp * t8;
+	t69 = t68 * Rm;
+	t70 = t3 * Rp;
+	t71 = Rm * t70;
+	t72 = -t54 + t56 + t59 - t62 - t64 - t66 + t67 + t69 + t71;
+	t74 = t70 * B;
+	t75 = t9 * t3;
+	t76 = t3 * t6;
+	t77 = 0.2e1 * t76;
+	t79 = 0.3e1 * t57 * Rp;
+	t81 = 0.2e1 * t15 * t13;
+	t82 = t9 * Rp;
+	t83 = t82 * B;
+	t84 = t68 * B;
+	t85 = t9 * t6;
+	t87 = 0.2e1 * t60 * Rm;
+	t88 = t74 - t75 - t77 - t79 + t81 + t83 + t84 - t85 - t87;
+	t93 = -t66 + t69 - t64 + t59 - t54 + t62 + t56 + t71 + t67;
+	t95 = -t77 + t74 + t87 - t85 - t79 + t84 - t75 + t83 - t81;
+	t112 = exp(-Rp - B);
+	t120 = kn * Rm;
+	t125 = 0.2e1 * Rm;
+	t126 = cos(t125);
+	t137 = t6 * BB;
+	t142 = sin(t125);
+	t152 = exp(-0.2e1 * Rp);
+	t170 = exp(-0.4e1 * Rp);
+	_C4 = (((t12 + 0.2e1 * t2 * t17 * BB) * t23 + (t12 - 0.2e1 * t2 * t25 * BB) * t31 + (0.2e1 * t2 * t25 * AA + t37) * t39 + (-0.2e1 * t2 * t17 * AA + t37) * t45) * t50 + ((-t72 * AA - 0.2e1 * t88 * BB) * t23 + (-t93 * AA + 0.2e1 * t95 * BB) * t31 + (-0.2e1 * t95 * AA - t93 * BB) * t39 + (0.2e1 * t88 * AA - t72 * BB) * t45) * t112 + ((-0.2e1 * t13 * (t3 - 0.5e1 * t6 + t8 - t9) * AA - 0.8e1 * B * BB * t120 * Rp) * t126 + (0.2e1 * Rp * (t9 * B - 0.2e1 * t82 - 0.3e1 * t57 + t65 + t3 * B - 0.2e1 * t52) * AA + 0.8e1 * t137 * kn * Rp) * t142 - 0.2e1 * t14 * (t3 + t7 + t9 - t8) * AA + 0.8e1 * t137 * t120) * t152 + 0.2e1 * t12 + 0.8e1 * t15 * t2 * BB) / (((0.8e1 * t6 + 0.8e1 * t9) * t3 * t126 - 0.8e1 * t76 - 0.8e1 * t85) * t152 + (-0.4e1 * t75 + 0.4e1 * t85) * t170 - 0.4e1 * t75 + 0.4e1 * t85);
+	
+	
+	/*******************************************/
+	/*       calculate the velocities etc      */
+	/*******************************************/
+	
+	
+	t2 = exp(UU * x);
+	t3 = Rm * x;
+	t4 = cos(t3);
+	t6 = sin(t3);
+	t11 = exp(-VV * x);
+	t18 = exp(-0.2e1 * x * B);
+	t19 = kn * x;
+	t20 = cos(t19);
+	t22 = sin(t19);
+	u1 = -km * (t2 * (_C1 * t4 + _C2 * t6) + t11 * (_C3 * t4 + _C4 * t6) + t18 * (AA * t20 + BB * t22));
+	
+	t2 = exp(UU * x);
+	t4 = Rm * x;
+	t5 = cos(t4);
+	t7 = sin(t4);
+	t18 = exp(-VV * x);
+	t32 = exp(-0.2e1 * x * B);
+	t34 = kn * x;
+	t35 = cos(t34);
+	t37 = sin(t34);
+	u2 = UU * t2 * (_C1 * t5 + _C2 * t7) + t2 * (-_C1 * t7 * Rm + _C2 * t5 * Rm) - VV * t18 * (_C3 * t5 + _C4 * t7) + t18 * (-_C3 * t7 * Rm + _C4 * t5 * Rm) - 0.2e1 * B * t32 * (AA * t35 + BB * t37) + t32 * (-AA * t37 * kn + BB * t35 * kn);
+	
+	t2 = 0.2e1 * x * B;
+	t3 = exp(t2);
+	t6 = exp(UU * x);
+	t8 = Rm * x;
+	t9 = cos(t8);
+	t11 = sin(t8);
+	t22 = exp(-VV * x);
+	t34 = exp(-t2);
+	t36 = kn * x;
+	t37 = cos(t36);
+	t39 = sin(t36);
+	u3 = -0.2e1 * t3 * km * (UU * t6 * (_C1 * t9 + _C2 * t11) + t6 * (-_C1 * t11 * Rm + _C2 * t9 * Rm) - VV * t22 * (_C3 * t9 + _C4 * t11) + t22 * (-_C3 * t11 * Rm + _C4 * t9 * Rm) - 0.2e1 * B * t34 * (AA * t37 + BB * t39) + t34 * (-AA * t39 * kn + BB * t37 * kn));
+	
+	t2 = 0.2e1 * x * B;
+	t3 = exp(t2);
+	t4 = km * km;
+	t6 = exp(UU * x);
+	t7 = Rm * x;
+	t8 = cos(t7);
+	t9 = _C1 * t8;
+	t10 = sin(t7);
+	t11 = _C2 * t10;
+	t12 = t9 + t11;
+	t15 = exp(-VV * x);
+	t16 = _C3 * t8;
+	t17 = _C4 * t10;
+	t18 = t16 + t17;
+	t20 = exp(-t2);
+	t21 = kn * x;
+	t22 = cos(t21);
+	t23 = AA * t22;
+	t24 = sin(t21);
+	t25 = BB * t24;
+	t26 = t23 + t25;
+	t30 = UU * UU;
+	t41 = Rm * Rm;
+	t46 = VV * VV;
+	t61 = B * B;
+	t73 = kn * kn;
+	u4 = t3 * (t4 * (t6 * t12 + t15 * t18 + t20 * t26) + t30 * t6 * t12 + 0.2e1 * UU * t6 * (-_C1 * t10 * Rm + _C2 * t8 * Rm) + t6 * (-t9 * t41 - t11 * t41) + t46 * t15 * t18 - 0.2e1 * VV * t15 * (-_C3 * t10 * Rm + _C4 * t8 * Rm) + t15 * (-t16 * t41 - t17 * t41) + 0.4e1 * t61 * t20 * t26 - 0.4e1 * B * t20 * (-AA * t24 * kn + BB * t22 * kn) + t20 * (-t23 * t73 - t25 * t73));
+	
+	t2 = 0.2e1 * x * B;
+	t3 = exp(t2);
+	t4 = UU * UU;
+	t7 = exp(UU * x);
+	t9 = Rm * x;
+	t10 = cos(t9);
+	t11 = _C1 * t10;
+	t12 = sin(t9);
+	t13 = _C2 * t12;
+	t14 = t11 + t13;
+	t16 = t4 * t7;
+	t17 = _C1 * t12;
+	t19 = _C2 * t10;
+	t21 = -t17 * Rm + t19 * Rm;
+	t24 = UU * t7;
+	t25 = Rm * Rm;
+	t28 = -t11 * t25 - t13 * t25;
+	t31 = t25 * Rm;
+	t36 = VV * VV;
+	t39 = exp(-VV * x);
+	t41 = _C3 * t10;
+	t42 = _C4 * t12;
+	t43 = t41 + t42;
+	t45 = t36 * t39;
+	t46 = _C3 * t12;
+	t48 = _C4 * t10;
+	t50 = -t46 * Rm + t48 * Rm;
+	t53 = VV * t39;
+	t56 = -t41 * t25 - t42 * t25;
+	t63 = B * B;
+	t65 = exp(-t2);
+	t67 = kn * x;
+	t68 = cos(t67);
+	t69 = AA * t68;
+	t70 = sin(t67);
+	t71 = BB * t70;
+	t72 = t69 + t71;
+	t75 = t63 * t65;
+	t76 = AA * t70;
+	t78 = BB * t68;
+	t80 = -t76 * kn + t78 * kn;
+	t83 = B * t65;
+	t84 = kn * kn;
+	t87 = -t69 * t84 - t71 * t84;
+	t90 = t84 * kn;
+	t111 = km * km;
+	t128 = t4 * UU * t7 * t14 + 0.3e1 * t16 * t21 + 0.3e1 * t24 * t28 + t7 * (t17 * t31 - t19 * t31) - t36 * VV * t39 * t43 + 0.3e1 * t45 * t50 - 0.3e1 * t53 * t56 + t39 * (t46 * t31 - t48 * t31) - 0.8e1 * t63 * B * t65 * t72 + 0.12e2 * t75 * t80 - 0.6e1 * t83 * t87 + t65 * (t76 * t90 - t78 * t90) + 0.2e1 * B * (t16 * t14 + 0.2e1 * t24 * t21 + t7 * t28 + t45 * t43 - 0.2e1 * t53 * t50 + t39 * t56 + 0.4e1 * t75 * t72 - 0.4e1 * t83 * t80 + t65 * t87) - t111 * (t24 * t14 + t7 * t21 - t53 * t43 + t39 * t50 - 0.2e1 * t83 * t72 + t65 * t80) + 0.2e1 * B * t111 * (t7 * t14 + t39 * t43 + t65 * t72);
+	u5 = -t3 * t128 / km;
+	
+	t2 = 0.2e1 * x * B;
+	t3 = exp(t2);
+	t6 = exp(UU * x);
+	t8 = Rm * x;
+	t9 = cos(t8);
+	t11 = sin(t8);
+	t22 = exp(-VV * x);
+	t34 = exp(-t2);
+	t36 = kn * x;
+	t37 = cos(t36);
+	t39 = sin(t36);
+	u6 = 0.2e1 * t3 * km * (UU * t6 * (_C1 * t9 + _C2 * t11) + t6 * (-_C1 * t11 * Rm + _C2 * t9 * Rm) - VV * t22 * (_C3 * t9 + _C4 * t11) + t22 * (-_C3 * t11 * Rm + _C4 * t9 * Rm) - 0.2e1 * B * t34 * (AA * t37 + BB * t39) + t34 * (-AA * t39 * kn + BB * t37 * kn));
+	
+	
+	
+	
+	
+	SS = sin(km*z)*(exp(UU*x)*(_C1*cos(Rm*x)+_C2*sin(Rm*x)) + exp(-VV*x)*(_C3*cos(Rm*x)+_C4*sin(Rm*x)) + exp(-2*x*B)*(AA*cos(kn*x)+BB*sin(kn*x)));
+	
+	/* u1 = Vx, u2 = Vz, u3 = txx, u4 = tzx, u5 = pressure, u6 = tzz */
+	
+	
+	sum5 += u5*cos(km*z);  /* pressure */
+	u6 -= u5; /* get total stress */
+	sum6 += u6*cos(km*z);  /* xx stress */
+	
+	u1 *= cos(km*z); /* x velocity */
+	sum1 += u1;
+	u2 *= sin(km*z); /* z velocity */
+	sum2 += u2;
+	u3 -= u5; /* get total stress */
+	u3 *= cos(km*z); /* zz stress */
+	sum3 += u3;
+	u4 *= sin(km*z); /* zx stress */
+	sum4 += u4;
+	
+	rho = -sigma*sin(km*z)*cos(kn*x); /* density */
+	sum7 += rho;
+	
+	
+	mag=sqrt(u1*u1+u2*u2);
+	//printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,u1,u2,mag,SS);
+	/*printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,SS);*/
+	
+	if ( viscosity != NULL ) {
+		*viscosity = Z;
+	}
+	
+	/* Output */
+	if( vel != NULL ) {
+		vel[0] = sum2;
+		vel[1] = sum1;
+	}
+	if( presssure != NULL ) {
+		(*presssure) = sum5;
+	}
+	if( total_stress != NULL ) {
+		total_stress[0] = sum6;
+		total_stress[1] = sum3;
+		total_stress[2] = sum4;
+	}
+	if( strain_rate != NULL ) {
+		/* sigma = tau - p, tau = sigma + p, tau[] = 2*eta*strain_rate[] */
+		strain_rate[0] = (sum6+sum5)/(2.0*Z);
+		strain_rate[1] = (sum3+sum5)/(2.0*Z);
+		strain_rate[2] = (sum4)/(2.0*Z);
+	}
+	/* Value checks, could be cleaned up if needed. Julian Giordani 9-Oct-2006*/
+        if( fabs( sum5 - ( -0.5*(sum6+sum3) ) ) > 1e-5 ) {
+                assert(0);
+        }
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solKz/Analytic_solKz.c
--- a/SysTest/AnalyticPlugins/Velic_solKz/Analytic_solKz.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,149 +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:
-*+		Mirko Velic
-*+		Julian Giordani
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Patrick Sunter
-** $Id: solKz.c 636 2006-09-08 03:07:06Z JulianGiordani $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include "Analytic_solKz.h"
-
-const Type Velic_solKz_Type = "Underworld_Velic_solKz";
-
-void Velic_solKz_PressureFunction( void* analyticSolution, double* coord, double* pressure ) {
-	Velic_solKz* self = (Velic_solKz*) analyticSolution;
-	
-	_Velic_solKz( coord, self->sigma, self->km, self->n, self->B, NULL, pressure, NULL, NULL );
-}
-
-void Velic_solKz_VelocityFunction( void* analyticSolution, double* coord, double* velocity ) {
-	Velic_solKz* self = (Velic_solKz*) analyticSolution;
-	
-	_Velic_solKz( coord, self->sigma, self->km, self->n, self->B, velocity, NULL, NULL, NULL );
-}
-
-void Velic_solKz_StressFunction( void* analyticSolution, double* coord, double* stress ) {
-	Velic_solKz* self = (Velic_solKz*) analyticSolution;
-	
-	_Velic_solKz( coord, self->sigma, self->km, self->n, self->B, NULL, NULL, stress, NULL );
-}
-
-
-void Velic_solKz_StrainRateFunction( void* analyticSolution, double* coord, double* strainRate ) {
-	Velic_solKz* self = (Velic_solKz*) analyticSolution;
-	
-	_Velic_solKz( coord, self->sigma, self->km, self->n, self->B, NULL, NULL, NULL, strainRate );
-}
-
-void Velic_solKz_ViscosityFunction( void* analyticSolution, double* coord, double* viscosity ) {
-	Velic_solKz* self = (Velic_solKz*) analyticSolution;
-	
-	*viscosity = exp( 2.0 * self->B * coord[ J_AXIS ] );
-}
-
-	
-void _Velic_solKz_Init( Velic_solKz* self, double sigma, double km, double B, int n ) {
-	self->sigma = sigma;
-	self->km = km;
-	self->B = B;
-	self->n = n;
-}
-
-void _Velic_solKz_Build( void* analyticSolution, void* data ) {
-	Velic_solKz*          self  = (Velic_solKz*)analyticSolution;
-
-	_FieldTest_Build( self, data );
-
-	/* here we assign the memory and the func ptr for analytic sols */
-	self->_analyticSolutionList = Memory_Alloc_Array_Unnamed( FieldTest_AnalyticSolutionFunc*, 4 );
-	/* this order MUST be consistent with the xml file definition */
-	self->_analyticSolutionList[0] = Velic_solKz_VelocityFunction;
-	self->_analyticSolutionList[1] = Velic_solKz_PressureFunction;
-	self->_analyticSolutionList[2] = Velic_solKz_StrainRateFunction;
-	self->_analyticSolutionList[3] = Velic_solKz_StressFunction;
-}
-
-void _Velic_solKz_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
-	Velic_solKz* self = (Velic_solKz*) analyticSolution;
-	double                   sigma, m, B, twiceB, km;
-	int                      n;
-
-	/* Construct Parent */
-	_FieldTest_AssignFromXML( self, cf, data );
-
-	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solKz_sigma", 1.0  );
-	twiceB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solKz_twiceB", 2.0  );
-	B = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solKz_B", 0.5 * twiceB  );
-	m = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solKz_m", 1  );
-	n = Stg_ComponentFactory_GetRootDictInt( cf, "solKz_n", 1 );
-
-   km = M_PI * m;
-	
-  /* Note: in the _Velic_solKz function km and n must be supplied */
-	_Velic_solKz_Init( self, sigma, km, B, n );
-}
-
-void* _Velic_solKz_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Velic_solKz);
-	Type                                                      type = Velic_solKz_Type;
-	Stg_Class_DeleteFunction*                              _delete = _FieldTest_Delete;
-	Stg_Class_PrintFunction*                                _print = _FieldTest_Print;
-	Stg_Class_CopyFunction*                                  _copy = _FieldTest_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solKz_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Velic_solKz_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _Velic_solKz_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 Underworld_Velic_solKz_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Velic_solKz_Type, (Name)"0", _Velic_solKz_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solKz/Analytic_solKz.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solKz/Analytic_solKz.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,149 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Mirko Velic
+*+		Julian Giordani
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Patrick Sunter
+** $Id: solKz.c 636 2006-09-08 03:07:06Z JulianGiordani $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include "Analytic_solKz.h"
+
+const Type Velic_solKz_Type = "Underworld_Velic_solKz";
+
+void Velic_solKz_PressureFunction( void* analyticSolution, double* coord, double* pressure ) {
+	Velic_solKz* self = (Velic_solKz*) analyticSolution;
+	
+	_Velic_solKz( coord, self->sigma, self->km, self->n, self->B, NULL, pressure, NULL, NULL );
+}
+
+void Velic_solKz_VelocityFunction( void* analyticSolution, double* coord, double* velocity ) {
+	Velic_solKz* self = (Velic_solKz*) analyticSolution;
+	
+	_Velic_solKz( coord, self->sigma, self->km, self->n, self->B, velocity, NULL, NULL, NULL );
+}
+
+void Velic_solKz_StressFunction( void* analyticSolution, double* coord, double* stress ) {
+	Velic_solKz* self = (Velic_solKz*) analyticSolution;
+	
+	_Velic_solKz( coord, self->sigma, self->km, self->n, self->B, NULL, NULL, stress, NULL );
+}
+
+
+void Velic_solKz_StrainRateFunction( void* analyticSolution, double* coord, double* strainRate ) {
+	Velic_solKz* self = (Velic_solKz*) analyticSolution;
+	
+	_Velic_solKz( coord, self->sigma, self->km, self->n, self->B, NULL, NULL, NULL, strainRate );
+}
+
+void Velic_solKz_ViscosityFunction( void* analyticSolution, double* coord, double* viscosity ) {
+	Velic_solKz* self = (Velic_solKz*) analyticSolution;
+	
+	*viscosity = exp( 2.0 * self->B * coord[ J_AXIS ] );
+}
+
+	
+void _Velic_solKz_Init( Velic_solKz* self, double sigma, double km, double B, int n ) {
+	self->sigma = sigma;
+	self->km = km;
+	self->B = B;
+	self->n = n;
+}
+
+void _Velic_solKz_Build( void* analyticSolution, void* data ) {
+	Velic_solKz*          self  = (Velic_solKz*)analyticSolution;
+
+	_FieldTest_Build( self, data );
+
+	/* here we assign the memory and the func ptr for analytic sols */
+	self->_analyticSolutionList = Memory_Alloc_Array_Unnamed( FieldTest_AnalyticSolutionFunc*, 4 );
+	/* this order MUST be consistent with the xml file definition */
+	self->_analyticSolutionList[0] = Velic_solKz_VelocityFunction;
+	self->_analyticSolutionList[1] = Velic_solKz_PressureFunction;
+	self->_analyticSolutionList[2] = Velic_solKz_StrainRateFunction;
+	self->_analyticSolutionList[3] = Velic_solKz_StressFunction;
+}
+
+void _Velic_solKz_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
+	Velic_solKz* self = (Velic_solKz*) analyticSolution;
+	double                   sigma, m, B, twiceB, km;
+	int                      n;
+
+	/* Construct Parent */
+	_FieldTest_AssignFromXML( self, cf, data );
+
+	sigma = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solKz_sigma", 1.0  );
+	twiceB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solKz_twiceB", 2.0  );
+	B = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solKz_B", 0.5 * twiceB  );
+	m = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solKz_m", 1  );
+	n = Stg_ComponentFactory_GetRootDictInt( cf, "solKz_n", 1 );
+
+   km = M_PI * m;
+	
+  /* Note: in the _Velic_solKz function km and n must be supplied */
+	_Velic_solKz_Init( self, sigma, km, B, n );
+}
+
+void* _Velic_solKz_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Velic_solKz);
+	Type                                                      type = Velic_solKz_Type;
+	Stg_Class_DeleteFunction*                              _delete = _FieldTest_Delete;
+	Stg_Class_PrintFunction*                                _print = _FieldTest_Print;
+	Stg_Class_CopyFunction*                                  _copy = _FieldTest_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solKz_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Velic_solKz_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _Velic_solKz_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 Underworld_Velic_solKz_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Velic_solKz_Type, (Name)"0", _Velic_solKz_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solKz/solKz.c
--- a/SysTest/AnalyticPlugins/Velic_solKz/solKz.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,542 +0,0 @@
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-
-void _Velic_solKz( 
-		double pos[],
-		double _sigma,
-		double _km, int _n, 
-		double _B,
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] );
-
-#ifndef NOSHARED
-int main( int argc, char **argv )
-{
-	int i,j;
-	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
-	double x,z;
-	
-	for (i=0;i<101;i++){
-		for(j=0;j<101;j++){
-			x = i/100.0;
-			z = j/100.0;
-			
-			pos[0] = x;
-			pos[1] = z;
-			_Velic_solKz(
-					pos,
-					1.0,
-					(double)M_PI, 1,
-					2.5,
-					vel, &pressure, total_stress, strain_rate );
-			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
-					pos[0],pos[1],
-					vel[0],vel[1], pressure, 
-					total_stress[0], total_stress[1], total_stress[2], 
-					strain_rate[0], strain_rate[1], strain_rate[2] );
-		}
-		printf("\n");
-	}
-	
-	return 0;
-}
-#endif
-
-
-
-void _Velic_solKz( 
-		double pos[],
-		double _sigma, /* density */
-		double _km, int _n, /* wavelength in z, wavenumber in x */
-		double _B, /* viscosity parameter */
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] )
-{
-	double Z;
-	double u1,u2,u3,u4,u5,u6,SS;
-	double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,x,z;
-	double sigma;
-	int n;
-	double kn;
-	double _C1,_C2,_C3,_C4;
-	double B, Rp, UU, VV;
-	double rho,a,b,r,_aa,_bb,AA,BB,Rm,km;
-	
-	
-	double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
-	double t11,t12,t13,t14,t15,t16,t17,t18,t19,t20;
-	double t21,t22,t23,t24,t25,t26,t27,t28,t29,t31;
-	double t33,t34,t35,t37,t38,t40,t41,t42,t43,t45;
-	double t47,t51,t52,t53,t54,t55,t56,t57,t58,t59;
-	double t60,t61,t62,t64,t65,t66,t67,t68,t69,t70;
-	double t71,t72,t73,t74,t75,t76,t77,t78,t79,t80;
-	double t81,t82,t83,t84,t85,t86,t89,t90,t92,t94;
-	double t96,t97,t98,t99,t100,t101,t103,t104,t105,t106;
-	double t107,t108,t109,t110,t111,t112,t113,t114,t115,t116;
-	double t117,t118,t119,t120,t121,t122,t123,t124,t125,t126;
-	double t127,t130,t131,t132,t134,t135,t141,t144,t147,t148;
-	double t150,t151,t152,t161,t171;
-	
-	
-	
-	/*************************************************************************/
-	/*************************************************************************/
-	/* rho = -sigma*sin(km*z)*cos(kn*x) */ 
-	/* viscosity  Z= exp(2*B*z)  */
-	B = _B; /* viscosity parameter must be non-zero*/
-	km = _km; /* solution valid for km not zero -- should get trivial solution if km=0 */
-	n = _n; /* solution valid for n not zero */
-	sigma = _sigma;
-	/*************************************************************************/
-	/*************************************************************************/
-	kn = (double) _n*M_PI;
-	a = B*B + kn*kn;
-	b = 2.0*kn*B;
-	r = sqrt(a*a + b*b);
-	Rp = sqrt( (r+a)/2.0 );
-	Rm  = sqrt( (r-a)/2.0 );
-	UU  = Rp - B;
-	VV = Rp + B;
-	
-	
-	x = pos[0];
-	z = pos[1];
-	
-	sum1=0.0;
-	sum2=0.0;
-	sum3=0.0;
-	sum4=0.0;
-	sum5=0.0;
-	sum6=0.0;
-	sum7=0.0;
-	
-	
-	
-	
-	/*******************************************/
-	/*         calculate the constants         */
-	/*******************************************/
-	
-	t3 = kn * kn;
-	t4 = km * km;
-	t6 = B * B;
-	t8 = 0.4e1 * t3 * t6;
-	t10 = 0.4e1 * t4 * t6;
-	t13 = 0.8e1 * kn * t6 * km;
-	t14 = t4 * t4;
-	t16 = 0.2e1 * t3 * t4;
-	t17 = t3 * t3;
-	_aa = -0.4e1 * B * km * kn * (t3 + t4) / (t8 + t10 + t13 + t14 + t16 + t17) / (-t13 + t8 + t10 + t14 + t16 + t17);
-	
-	t1 = kn * kn;
-	t2 = t1 * t1;
-	t3 = B * B;
-	t5 = 0.4e1 * t1 * t3;
-	t6 = km * km;
-	t7 = t6 * t6;
-	t9 = 0.2e1 * t1 * t6;
-	t11 = 0.4e1 * t3 * t6;
-	t16 = 0.8e1 * kn * t3 * km;
-	_bb = kn * (t2 + t5 + t7 + t9 - t11) / (t5 + t11 + t16 + t7 + t9 + t2) / (-t16 + t5 + t11 + t7 + t9 + t2);
-	
-	AA = _aa;
-	BB = _bb;
-	
-	t1 = B * B;
-	t2 = t1 * Rp;
-	t4 = Rm * Rm;
-	t5 = t4 * Rp;
-	t7 = t4 * B;
-	t8 = km * km;
-	t12 = Rp * Rp;
-	t13 = B * t12;
-	t21 = 0.8e1 * t1 * km * BB * Rp;
-	t23 = 0.2e1 * Rm;
-	t24 = cos(t23);
-	t26 = Rm * Rp;
-	t38 = sin(t23);
-	t51 = exp(-0.2e1 * Rp);
-	t53 = B + Rp;
-	t54 = Rm * t53;
-	t55 = Rm * B;
-	t57 = 0.2e1 * B * km;
-	t58 = t55 + t57 - t26;
-	t62 = 0.3e1 * t1;
-	t64 = 0.2e1 * Rp * B;
-	t65 = t62 + t64 + t4 - t8 - t12;
-	t67 = t54 * t65 * BB;
-	t69 = Rm - km;
-	t70 = cos(t69);
-	t72 = -t57 + t55 - t26;
-	t77 = Rm + km;
-	t78 = cos(t77);
-	t81 = t54 * t65 * AA;
-	t86 = sin(t77);
-	t92 = sin(t69);
-	t96 = exp(-t53);
-	t98 = B - Rp;
-	t99 = Rm * t98;
-	t100 = t55 + t57 + t26;
-	t104 = t62 - t64 + t4 - t8 - t12;
-	t106 = t99 * t104 * BB;
-	t109 = -t57 + t55 + t26;
-	t116 = t99 * t104 * AA;
-	t130 = exp(-0.3e1 * Rp - B);
-	t135 = exp(-0.4e1 * Rp);
-	t144 = t4 * t1;
-	t150 = t4 * t12;
-	_C1 = (((0.2e1 * Rp * (0.2e1 * t2 + 0.2e1 * t5 + t7 + B * t8 - 0.3e1 * t1 * B + t13) * AA + t21) * t24 + (-0.2e1 * t26 * (t4 - t8 - t12 + 0.5e1 * t1) * AA + 0.8e1 * B * BB * km * Rm * Rp) * t38 - 0.2e1 * B * (0.2e1 * t13 + t12 * Rp - 0.3e1 * t2 + t5 + 0.2e1 * t7 + t8 * Rp) * AA - t21) * t51 + ((0.2e1 * t54 * t58 * AA + t67) * t70 + (0.2e1 * t54 * t72 * AA - t67) * t78 + (t81 + 0.2e1 * t54 * t72 * BB) * t86 + (t81 - 0.2e1 * t54 * t58 * BB) * t92) * t96 + ((-0.2e1 * t99 * t100 * AA - t106) * t70 + (-0.2e1 * t99 * t109 * AA + t106) * t78 + (-t116 - 0.2e1 * t99 * t109 * BB) * t86 + (-t116 + 0.2e1 * t99 * t100 * BB) * t92) * t130 + 0.4e1 * t4 * t98 * t53 * AA * t135) / (((-0.8e1 * t4 - 0.8e1 * t1) * t12 * t24 + 0.8e1 * t144 + 0.8e1 * t12 * t1) * t51 + (0.4e1 * t150 - 0.4e1 * t144) * t135 + 0.4e1 * t150 - 0.4e1 * t144);
-	
-	t1 = Rm * Rp;
-	t2 = Rm * Rm;
-	t3 = km * km;
-	t4 = Rp * Rp;
-	t5 = B * B;
-	t12 = km * Rm;
-	t17 = 0.2e1 * Rm;
-	t18 = cos(t17);
-	t22 = t2 * Rp;
-	t25 = B * t3;
-	t26 = t5 * B;
-	t33 = t5 * km;
-	t38 = sin(t17);
-	t40 = Rm * B;
-	t41 = 0.3e1 * t5;
-	t51 = exp(-0.2e1 * Rp);
-	t53 = B + Rp;
-	t54 = Rm * t53;
-	t57 = t41 + 0.2e1 * Rp * B + t2 - t3 - t4;
-	t59 = t54 * t57 * AA;
-	t60 = B * km;
-	t61 = 0.2e1 * t60;
-	t62 = t40 + t61 - t1;
-	t67 = Rm - km;
-	t68 = cos(t67);
-	t70 = -t61 + t40 - t1;
-	t75 = Rm + km;
-	t76 = cos(t75);
-	t82 = t54 * t57 * BB;
-	t84 = sin(t75);
-	t90 = sin(t67);
-	t94 = exp(-t53);
-	t97 = 0.3e1 * Rm * t26;
-	t98 = t2 * Rm;
-	t99 = t98 * B;
-	t100 = t3 * Rm;
-	t101 = t100 * Rp;
-	t103 = Rm * t4 * B;
-	t104 = t4 * Rp;
-	t105 = Rm * t104;
-	t107 = 0.8e1 * t33 * Rp;
-	t109 = 0.5e1 * t1 * t5;
-	t110 = t98 * Rp;
-	t111 = t100 * B;
-	t112 = t97 + t99 - t101 + t103 - t105 + t107 + t109 + t110 - t111;
-	t114 = t2 * t4;
-	t116 = 0.2e1 * t60 * t1;
-	t117 = t2 * t5;
-	t119 = 0.3e1 * t26 * Rp;
-	t120 = t104 * B;
-	t121 = t4 * t5;
-	t122 = 0.2e1 * t121;
-	t123 = t22 * B;
-	t125 = 0.2e1 * t33 * Rm;
-	t126 = t25 * Rp;
-	t127 = t114 + t116 + t117 - t119 + t120 + t122 + t123 + t125 + t126;
-	t132 = -t107 + t103 - t105 - t101 + t97 - t111 + t110 + t109 + t99;
-	t134 = t120 - t125 + t123 - t116 + t122 + t117 + t114 + t126 - t119;
-	t152 = exp(-0.3e1 * Rp - B);
-	t161 = exp(-0.4e1 * Rp);
-	_C2 = (((0.2e1 * t1 * (t2 - t3 - t4 + 0.5e1 * t5) * AA - 0.8e1 * B * BB * t12 * Rp) * t18 + (0.2e1 * Rp * (0.2e1 * t5 * Rp + 0.2e1 * t22 + t2 * B + t25 - 0.3e1 * t26 + B * t4) * AA + 0.8e1 * t33 * BB * Rp) * t38 + 0.2e1 * t40 * (t41 + t4 + t2 - t3) * AA - 0.8e1 * t5 * BB * t12) * t51 + ((-t59 + 0.2e1 * t54 * t62 * BB) * t68 + (-t59 - 0.2e1 * t54 * t70 * BB) * t76 + (0.2e1 * t54 * t70 * AA - t82) * t84 + (0.2e1 * t54 * t62 * AA + t82) * t90) * t94 + ((t112 * AA - 0.2e1 * t127 * BB) * t68 + (t132 * AA + 0.2e1 * t134 * BB) * t76 + (-0.2e1 * t134 * AA + t132 * BB) * t84 + (-0.2e1 * t127 * AA - t112 * BB) * t90) * t152 + (-0.2e1 * t59 + 0.8e1 * t40 * km * t53 * BB) * t161) / (((-0.8e1 * t2 - 0.8e1 * t5) * t4 * t18 + 0.8e1 * t117 + 0.8e1 * t121) * t51 + (0.4e1 * t114 - 0.4e1 * t117) * t161 + 0.4e1 * t114 - 0.4e1 * t117);
-	
-	t1 = B * B;
-	t2 = t1 * Rp;
-	t4 = Rm * Rm;
-	t5 = t4 * Rp;
-	t7 = Rp * Rp;
-	t8 = B * t7;
-	t11 = km * km;
-	t13 = t4 * B;
-	t21 = 0.8e1 * t1 * km * BB * Rp;
-	t23 = 0.2e1 * Rm;
-	t24 = cos(t23);
-	t26 = Rm * Rp;
-	t38 = sin(t23);
-	t51 = exp(-0.2e1 * Rp);
-	t53 = B + Rp;
-	t54 = Rm * t53;
-	t55 = Rm * B;
-	t57 = 0.2e1 * B * km;
-	t58 = t55 + t57 - t26;
-	t62 = 0.3e1 * t1;
-	t64 = 0.2e1 * Rp * B;
-	t65 = t62 + t64 + t4 - t11 - t7;
-	t67 = t54 * t65 * BB;
-	t69 = Rm - km;
-	t70 = cos(t69);
-	t72 = -t57 + t55 - t26;
-	t77 = Rm + km;
-	t78 = cos(t77);
-	t81 = t54 * t65 * AA;
-	t86 = sin(t77);
-	t92 = sin(t69);
-	t96 = exp(-t53);
-	t98 = B - Rp;
-	t99 = Rm * t98;
-	t100 = t55 + t57 + t26;
-	t104 = t62 - t64 + t4 - t11 - t7;
-	t106 = t99 * t104 * BB;
-	t109 = -t57 + t55 + t26;
-	t116 = t99 * t104 * AA;
-	t130 = exp(-0.3e1 * Rp - B);
-	t141 = t4 * t1;
-	t147 = t4 * t7;
-	t151 = exp(-0.4e1 * Rp);
-	_C3 = (((-0.2e1 * Rp * (-0.2e1 * t2 - 0.2e1 * t5 + t8 - 0.3e1 * t1 * B + B * t11 + t13) * AA - t21) * t24 + (0.2e1 * t26 * (t4 - t11 - t7 + 0.5e1 * t1) * AA - 0.8e1 * B * BB * km * Rm * Rp) * t38 - 0.2e1 * B * (0.2e1 * t8 + 0.2e1 * t13 + 0.3e1 * t2 - t7 * Rp - t5 - t11 * Rp) * AA + t21) * t51 + ((-0.2e1 * t54 * t58 * AA - t67) * t70 + (-0.2e1 * t54 * t72 * AA + t67) * t78 + (-t81 - 0.2e1 * t54 * t72 * BB) * t86 + (-t81 + 0.2e1 * t54 * t58 * BB) * t92) * t96 + ((0.2e1 * t99 * t100 * AA + t106) * t70 + (0.2e1 * t99 * t109 * AA - t106) * t78 + (t116 + 0.2e1 * t99 * t109 * BB) * t86 + (t116 - 0.2e1 * t99 * t100 * BB) * t92) * t130 + 0.4e1 * t4 * t98 * t53 * AA) / (((-0.8e1 * t4 - 0.8e1 * t1) * t7 * t24 + 0.8e1 * t141 + 0.8e1 * t7 * t1) * t51 + (0.4e1 * t147 - 0.4e1 * t141) * t151 + 0.4e1 * t147 - 0.4e1 * t141);
-	
-	t1 = Rm * Rp;
-	t2 = Rm * Rm;
-	t3 = km * km;
-	t4 = Rp * Rp;
-	t5 = B * B;
-	t12 = km * Rm;
-	t17 = 0.2e1 * Rm;
-	t18 = cos(t17);
-	t22 = t2 * Rp;
-	t25 = t5 * B;
-	t27 = B * t3;
-	t33 = t5 * km;
-	t38 = sin(t17);
-	t40 = Rm * B;
-	t41 = 0.3e1 * t5;
-	t51 = exp(-0.2e1 * Rp);
-	t53 = t2 * Rm;
-	t54 = t53 * B;
-	t56 = 0.5e1 * t1 * t5;
-	t58 = Rm * t4 * B;
-	t59 = t3 * Rm;
-	t60 = t59 * Rp;
-	t62 = 0.8e1 * t33 * Rp;
-	t64 = 0.3e1 * Rm * t25;
-	t65 = t53 * Rp;
-	t66 = t59 * B;
-	t67 = t4 * Rp;
-	t68 = Rm * t67;
-	t69 = t54 - t56 + t58 + t60 - t62 + t64 - t65 - t66 + t68;
-	t71 = t2 * t4;
-	t73 = 0.3e1 * t25 * Rp;
-	t74 = t2 * t5;
-	t75 = t27 * Rp;
-	t76 = B * km;
-	t78 = 0.2e1 * t76 * t1;
-	t80 = 0.2e1 * t33 * Rm;
-	t81 = t22 * B;
-	t82 = t4 * t5;
-	t83 = 0.2e1 * t82;
-	t84 = t67 * B;
-	t85 = t71 + t73 + t74 - t75 - t78 + t80 - t81 + t83 - t84;
-	t89 = Rm - km;
-	t90 = cos(t89);
-	t92 = t60 - t66 - t65 + t58 + t54 - t56 + t62 + t68 + t64;
-	t94 = t73 + t78 - t81 + t74 - t80 - t84 - t75 + t83 + t71;
-	t98 = Rm + km;
-	t99 = cos(t98);
-	t105 = sin(t98);
-	t111 = sin(t89);
-	t115 = exp(-Rp - B);
-	t117 = B - Rp;
-	t118 = Rm * t117;
-	t121 = t41 - 0.2e1 * Rp * B + t2 - t3 - t4;
-	t123 = t118 * t121 * AA;
-	t124 = 0.2e1 * t76;
-	t125 = t40 + t124 + t1;
-	t131 = -t124 + t40 + t1;
-	t141 = t118 * t121 * BB;
-	t152 = exp(-0.3e1 * Rp - B);
-	t171 = exp(-0.4e1 * Rp);
-	_C4 = (((-0.2e1 * t1 * (t2 - t3 - t4 + 0.5e1 * t5) * AA + 0.8e1 * B * BB * t12 * Rp) * t18 + (-0.2e1 * Rp * (-0.2e1 * t5 * Rp - 0.2e1 * t22 + t4 * B - 0.3e1 * t25 + t27 + t2 * B) * AA - 0.8e1 * t33 * BB * Rp) * t38 + 0.2e1 * t40 * (t41 + t4 + t2 - t3) * AA - 0.8e1 * t5 * BB * t12) * t51 + ((t69 * AA - 0.2e1 * t85 * BB) * t90 + (t92 * AA + 0.2e1 * t94 * BB) * t99 + (-0.2e1 * t94 * AA + t92 * BB) * t105 + (-0.2e1 * t85 * AA - t69 * BB) * t111) * t115 + ((-t123 + 0.2e1 * t118 * t125 * BB) * t90 + (-t123 - 0.2e1 * t118 * t131 * BB) * t99 + (0.2e1 * t118 * t131 * AA - t141) * t105 + (0.2e1 * t118 * t125 * AA + t141) * t111) * t152 - 0.2e1 * t123 + 0.8e1 * t40 * km * t117 * BB) / (((-0.8e1 * t2 - 0.8e1 * t5) * t4 * t18 + 0.8e1 * t74 + 0.8e1 * t82) * t51 + (0.4e1 * t71 - 0.4e1 * t74) * t171 + 0.4e1 * t71 - 0.4e1 * t74);
-	
-	/******************************************************************/
-	/******************************************************************/
-	
-	/*******************************************/
-	/*       calculate the velocities etc      */
-	/*******************************************/
-	
-	t2 = exp(UU * z);
-	t3 = Rm * z;
-	t4 = cos(t3);
-	t6 = sin(t3);
-	t11 = exp(-VV * z);
-	t18 = exp(-0.2e1 * z * B);
-	t19 = km * z;
-	t20 = cos(t19);
-	t22 = sin(t19);
-	u1 = kn * (t2 * (_C1 * t4 + _C2 * t6) + t11 * (_C3 * t4 + _C4 * t6) + t18 * (AA * t20 + BB * t22));
-	
-	t1 = Rm * z;
-	t2 = cos(t1);
-	t4 = sin(t1);
-	t14 = exp(UU * z);
-	t26 = exp(-VV * z);
-	t28 = km * z;
-	t29 = cos(t28);
-	t31 = sin(t28);
-	t43 = exp(-0.2e1 * z * B);
-	u2 = (-UU * (_C1 * t2 + _C2 * t4) + _C1 * t4 * Rm - _C2 * t2 * Rm) * t14 + (VV * (_C3 * t2 + _C4 * t4) + _C3 * t4 * Rm - _C4 * t2 * Rm) * t26 + (0.2e1 * B * (AA * t29 + BB * t31) + AA * t31 * km - BB * t29 * km) * t43;
-	
-	t2 = 0.2e1 * z * B;
-	t3 = exp(t2);
-	t4 = t3 * kn;
-	t5 = Rm * z;
-	t6 = cos(t5);
-	t8 = sin(t5);
-	t18 = exp(UU * z);
-	t31 = exp(-VV * z);
-	t34 = km * z;
-	t35 = cos(t34);
-	t37 = sin(t34);
-	t47 = exp(-t2);
-	u3 = 0.2e1 * t4 * (UU * (_C1 * t6 + _C2 * t8) - _C1 * t8 * Rm + _C2 * t6 * Rm) * t18 + 0.2e1 * t4 * (-VV * (_C3 * t6 + _C4 * t8) - _C3 * t8 * Rm + _C4 * t6 * Rm) * t31 + 0.2e1 * t4 * (-0.2e1 * B * (AA * t35 + BB * t37) - AA * t37 * km + BB * t35 * km) * t47;
-	
-	t1 = Rm * Rm;
-	t3 = UU * UU;
-	t8 = kn * kn;
-	t11 = Rm * z;
-	t12 = sin(t11);
-	t14 = cos(t11);
-	t20 = t14 * Rm;
-	t27 = 0.2e1 * z * B;
-	t28 = exp(t27);
-	t31 = exp(UU * z);
-	t38 = VV * VV;
-	t54 = exp(-VV * z);
-	t56 = km * km;
-	t59 = B * B;
-	t66 = km * z;
-	t67 = sin(t66);
-	t69 = cos(t66);
-	t83 = exp(-t27);
-	u4 = ((_C2 * t1 - t3 * _C2 + 0.2e1 * UU * _C1 * Rm - _C2 * t8) * t12 + _C1 * t14 * t1 - t3 * _C1 * t14 - 0.2e1 * UU * _C2 * t20 - t8 * _C1 * t14) * t28 * t31 + ((-0.2e1 * VV * _C3 * Rm + _C4 * t1 - _C4 * t8 - t38 * _C4) * t12 + 0.2e1 * VV * _C4 * t20 + _C3 * t14 * t1 - t8 * _C3 * t14 - t38 * _C3 * t14) * t28 * t54 + ((BB * t56 - t8 * BB - 0.4e1 * t59 * BB - 0.4e1 * B * AA * km) * t67 + AA * t69 * t56 - t8 * AA * t69 - 0.4e1 * t59 * AA * t69 + 0.4e1 * B * BB * t69 * km) * t28 * t83;
-	
-	
-	t1 = Rm * z;
-	t2 = sin(t1);
-	t3 = Rm * Rm;
-	t4 = t3 * Rm;
-	t5 = t2 * t4;
-	t6 = UU * UU;
-	t7 = t6 * UU;
-	t8 = cos(t1);
-	t15 = 0.2e1 * B * t8 * t3;
-	t19 = B * UU;
-	t20 = t2 * Rm;
-	t23 = kn * kn;
-	t24 = B * t23;
-	t26 = 0.2e1 * t24 * t8;
-	t27 = t23 * UU;
-	t29 = B * t6;
-	t33 = t23 * t2 * Rm;
-	t35 = 0.1e1 / kn;
-	t42 = 0.2e1 * B * t2 * t3;
-	t43 = t8 * t4;
-	t45 = 0.2e1 * t24 * t2;
-	t52 = t23 * t8 * Rm;
-	t53 = t8 * Rm;
-	t64 = 0.2e1 * z * B;
-	t65 = exp(t64);
-	t68 = exp(UU * z);
-	t70 = B * VV;
-	t76 = t23 * VV;
-	t78 = VV * VV;
-	t79 = t78 * VV;
-	t84 = B * t78;
-	t108 = exp(-VV * z);
-	t111 = km * z;
-	t112 = sin(t111);
-	t113 = km * km;
-	t118 = cos(t111);
-	t119 = t118 * km;
-	t121 = B * B;
-	t123 = t112 * km;
-	t130 = t113 * km;
-	t148 = exp(-t64);
-	u5 = (-(-t5 - t7 * t8 + 0.3e1 * UU * t8 * t3 + t15 + 0.3e1 * t6 * t2 * Rm + 0.4e1 * t19 * t20 - t26 + t27 * t8 - 0.2e1 * t29 * t8 - t33) * t35 * _C1 - (-t7 * t2 + t27 * t2 + t42 + t43 - t45 + 0.3e1 * UU * t2 * t3 - 0.2e1 * t29 * t2 + t52 - 0.4e1 * t19 * t53 - 0.3e1 * t6 * t8 * Rm) * t35 * _C2) * t65 * t68 + (-(t15 - 0.4e1 * t70 * t20 - t33 - 0.3e1 * VV * t8 * t3 - t76 * t8 + t79 * t8 + 0.3e1 * t78 * t2 * Rm - 0.2e1 * t84 * t8 - t26 - t5) * t35 * _C3 - (t52 - 0.3e1 * VV * t2 * t3 + t79 * t2 + 0.4e1 * t70 * t53 - 0.3e1 * t78 * t8 * Rm - 0.2e1 * t84 * t2 + t43 - t76 * t2 + t42 - t45) * t35 * _C4) * t65 * t108 - t65 * (-0.4e1 * B * BB * t112 * t113 + t23 * BB * t119 + 0.4e1 * t121 * AA * t123 - 0.4e1 * t121 * BB * t119 + BB * t118 * t130 - AA * t112 * t130 - 0.4e1 * B * AA * t118 * t113 - t23 * AA * t123 - 0.4e1 * t24 * AA * t118 - 0.4e1 * t24 * BB * t112) * t35 * t148;
-	
-	
-	
-	t2 = 0.2e1 * z * B;
-	t3 = exp(t2);
-	t4 = t3 * kn;
-	t5 = Rm * z;
-	t6 = cos(t5);
-	t8 = sin(t5);
-	t18 = exp(UU * z);
-	t31 = exp(-VV * z);
-	t34 = km * z;
-	t35 = cos(t34);
-	t37 = sin(t34);
-	t47 = exp(-t2);
-	u6 = -0.2e1 * t4 * (UU * (_C1 * t6 + _C2 * t8) - _C1 * t8 * Rm + _C2 * t6 * Rm) * t18 - 0.2e1 * t4 * (-VV * (_C3 * t6 + _C4 * t8) - _C3 * t8 * Rm + _C4 * t6 * Rm) * t31 - 0.2e1 * t4 * (-0.2e1 * B * (AA * t35 + BB * t37) - AA * t37 * km + BB * t35 * km) * t47;
-	
-	
-	
-	
-	/******************************************************************/
-	/******************************************************************/
-	
-	
-	
-	sum5 += u5*cos(n*M_PI*x);  /* pressure */
-	u6 -= u5; /* get total stress */
-	sum6 += u6*cos(n*M_PI*x);  /* xx stress */
-	
-	u1 *= cos(n*M_PI*x); /* z velocity */
-	sum1 += u1;
-	u2 *= sin(n*M_PI*x); /* x velocity */
-	sum2 += u2;
-	u3 -= u5; /* get total stress */
-	u3 *= cos(n*M_PI*x); /* zz stress */
-	sum3 += u3;
-	u4 *= sin(n*M_PI*x); /* zx stress */
-	sum4 += u4;
-	
-	rho = -sigma*sin(km*z)*cos(kn*x); /* density */
-	sum7 += rho;
-	
-	SS = exp(UU*z)*(_C1*cos(Rm*z)+_C2*sin(Rm*z)) +exp(-VV*z)*(_C3*cos(Rm*z)+_C4*sin(Rm*z)) + exp(-2*z*B)*(AA*cos(km*z)+BB*sin(km*z));
-	SS *= sin(kn*x); /* stream function */
-	
-	mag=sqrt(u1*u1+u2*u2);
-	/*printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,SS);*/
-	
-	
-	/* Output */
-	if( vel != NULL ) {
-		vel[0] = sum2;
-		vel[1] = sum1;
-	}
-	if( presssure != NULL ) {
-		(*presssure) = sum5;
-	}
-	if( total_stress != NULL ) {
-		total_stress[0] = sum6;
-		total_stress[1] = sum3;
-		total_stress[2] = sum4;
-	}
-	if( strain_rate != NULL ) {
-		/* sigma = tau - p, tau = sigma + p, tau[] = 2*eta*strain_rate[] */
-		Z = exp( 2.0 * B * z );
-		strain_rate[0] = (sum6+sum5)/(2.0*Z);
-		strain_rate[1] = (sum3+sum5)/(2.0*Z);
-		strain_rate[2] = (sum4)/(2.0*Z);
-	}
-	/* Value checks, could be cleaned up if needed. Julian Giordani 9-Oct-2006*/
-        if( fabs( sum5 - ( -0.5*(sum6+sum3) ) ) > 1e-5 ) {
-                assert(0);
-        }
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solKz/solKz.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solKz/solKz.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,542 @@
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+
+void _Velic_solKz( 
+		double pos[],
+		double _sigma,
+		double _km, int _n, 
+		double _B,
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] );
+
+#ifndef NOSHARED
+int main( int argc, char **argv )
+{
+	int i,j;
+	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
+	double x,z;
+	
+	for (i=0;i<101;i++){
+		for(j=0;j<101;j++){
+			x = i/100.0;
+			z = j/100.0;
+			
+			pos[0] = x;
+			pos[1] = z;
+			_Velic_solKz(
+					pos,
+					1.0,
+					(double)M_PI, 1,
+					2.5,
+					vel, &pressure, total_stress, strain_rate );
+			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
+					pos[0],pos[1],
+					vel[0],vel[1], pressure, 
+					total_stress[0], total_stress[1], total_stress[2], 
+					strain_rate[0], strain_rate[1], strain_rate[2] );
+		}
+		printf("\n");
+	}
+	
+	return 0;
+}
+#endif
+
+
+
+void _Velic_solKz( 
+		double pos[],
+		double _sigma, /* density */
+		double _km, int _n, /* wavelength in z, wavenumber in x */
+		double _B, /* viscosity parameter */
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] )
+{
+	double Z;
+	double u1,u2,u3,u4,u5,u6,SS;
+	double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,x,z;
+	double sigma;
+	int n;
+	double kn;
+	double _C1,_C2,_C3,_C4;
+	double B, Rp, UU, VV;
+	double rho,a,b,r,_aa,_bb,AA,BB,Rm,km;
+	
+	
+	double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
+	double t11,t12,t13,t14,t15,t16,t17,t18,t19,t20;
+	double t21,t22,t23,t24,t25,t26,t27,t28,t29,t31;
+	double t33,t34,t35,t37,t38,t40,t41,t42,t43,t45;
+	double t47,t51,t52,t53,t54,t55,t56,t57,t58,t59;
+	double t60,t61,t62,t64,t65,t66,t67,t68,t69,t70;
+	double t71,t72,t73,t74,t75,t76,t77,t78,t79,t80;
+	double t81,t82,t83,t84,t85,t86,t89,t90,t92,t94;
+	double t96,t97,t98,t99,t100,t101,t103,t104,t105,t106;
+	double t107,t108,t109,t110,t111,t112,t113,t114,t115,t116;
+	double t117,t118,t119,t120,t121,t122,t123,t124,t125,t126;
+	double t127,t130,t131,t132,t134,t135,t141,t144,t147,t148;
+	double t150,t151,t152,t161,t171;
+	
+	
+	
+	/*************************************************************************/
+	/*************************************************************************/
+	/* rho = -sigma*sin(km*z)*cos(kn*x) */ 
+	/* viscosity  Z= exp(2*B*z)  */
+	B = _B; /* viscosity parameter must be non-zero*/
+	km = _km; /* solution valid for km not zero -- should get trivial solution if km=0 */
+	n = _n; /* solution valid for n not zero */
+	sigma = _sigma;
+	/*************************************************************************/
+	/*************************************************************************/
+	kn = (double) _n*M_PI;
+	a = B*B + kn*kn;
+	b = 2.0*kn*B;
+	r = sqrt(a*a + b*b);
+	Rp = sqrt( (r+a)/2.0 );
+	Rm  = sqrt( (r-a)/2.0 );
+	UU  = Rp - B;
+	VV = Rp + B;
+	
+	
+	x = pos[0];
+	z = pos[1];
+	
+	sum1=0.0;
+	sum2=0.0;
+	sum3=0.0;
+	sum4=0.0;
+	sum5=0.0;
+	sum6=0.0;
+	sum7=0.0;
+	
+	
+	
+	
+	/*******************************************/
+	/*         calculate the constants         */
+	/*******************************************/
+	
+	t3 = kn * kn;
+	t4 = km * km;
+	t6 = B * B;
+	t8 = 0.4e1 * t3 * t6;
+	t10 = 0.4e1 * t4 * t6;
+	t13 = 0.8e1 * kn * t6 * km;
+	t14 = t4 * t4;
+	t16 = 0.2e1 * t3 * t4;
+	t17 = t3 * t3;
+	_aa = -0.4e1 * B * km * kn * (t3 + t4) / (t8 + t10 + t13 + t14 + t16 + t17) / (-t13 + t8 + t10 + t14 + t16 + t17);
+	
+	t1 = kn * kn;
+	t2 = t1 * t1;
+	t3 = B * B;
+	t5 = 0.4e1 * t1 * t3;
+	t6 = km * km;
+	t7 = t6 * t6;
+	t9 = 0.2e1 * t1 * t6;
+	t11 = 0.4e1 * t3 * t6;
+	t16 = 0.8e1 * kn * t3 * km;
+	_bb = kn * (t2 + t5 + t7 + t9 - t11) / (t5 + t11 + t16 + t7 + t9 + t2) / (-t16 + t5 + t11 + t7 + t9 + t2);
+	
+	AA = _aa;
+	BB = _bb;
+	
+	t1 = B * B;
+	t2 = t1 * Rp;
+	t4 = Rm * Rm;
+	t5 = t4 * Rp;
+	t7 = t4 * B;
+	t8 = km * km;
+	t12 = Rp * Rp;
+	t13 = B * t12;
+	t21 = 0.8e1 * t1 * km * BB * Rp;
+	t23 = 0.2e1 * Rm;
+	t24 = cos(t23);
+	t26 = Rm * Rp;
+	t38 = sin(t23);
+	t51 = exp(-0.2e1 * Rp);
+	t53 = B + Rp;
+	t54 = Rm * t53;
+	t55 = Rm * B;
+	t57 = 0.2e1 * B * km;
+	t58 = t55 + t57 - t26;
+	t62 = 0.3e1 * t1;
+	t64 = 0.2e1 * Rp * B;
+	t65 = t62 + t64 + t4 - t8 - t12;
+	t67 = t54 * t65 * BB;
+	t69 = Rm - km;
+	t70 = cos(t69);
+	t72 = -t57 + t55 - t26;
+	t77 = Rm + km;
+	t78 = cos(t77);
+	t81 = t54 * t65 * AA;
+	t86 = sin(t77);
+	t92 = sin(t69);
+	t96 = exp(-t53);
+	t98 = B - Rp;
+	t99 = Rm * t98;
+	t100 = t55 + t57 + t26;
+	t104 = t62 - t64 + t4 - t8 - t12;
+	t106 = t99 * t104 * BB;
+	t109 = -t57 + t55 + t26;
+	t116 = t99 * t104 * AA;
+	t130 = exp(-0.3e1 * Rp - B);
+	t135 = exp(-0.4e1 * Rp);
+	t144 = t4 * t1;
+	t150 = t4 * t12;
+	_C1 = (((0.2e1 * Rp * (0.2e1 * t2 + 0.2e1 * t5 + t7 + B * t8 - 0.3e1 * t1 * B + t13) * AA + t21) * t24 + (-0.2e1 * t26 * (t4 - t8 - t12 + 0.5e1 * t1) * AA + 0.8e1 * B * BB * km * Rm * Rp) * t38 - 0.2e1 * B * (0.2e1 * t13 + t12 * Rp - 0.3e1 * t2 + t5 + 0.2e1 * t7 + t8 * Rp) * AA - t21) * t51 + ((0.2e1 * t54 * t58 * AA + t67) * t70 + (0.2e1 * t54 * t72 * AA - t67) * t78 + (t81 + 0.2e1 * t54 * t72 * BB) * t86 + (t81 - 0.2e1 * t54 * t58 * BB) * t92) * t96 + ((-0.2e1 * t99 * t100 * AA - t106) * t70 + (-0.2e1 * t99 * t109 * AA + t106) * t78 + (-t116 - 0.2e1 * t99 * t109 * BB) * t86 + (-t116 + 0.2e1 * t99 * t100 * BB) * t92) * t130 + 0.4e1 * t4 * t98 * t53 * AA * t135) / (((-0.8e1 * t4 - 0.8e1 * t1) * t12 * t24 + 0.8e1 * t144 + 0.8e1 * t12 * t1) * t51 + (0.4e1 * t150 - 0.4e1 * t144) * t135 + 0.4e1 * t150 - 0.4e1 * t144);
+	
+	t1 = Rm * Rp;
+	t2 = Rm * Rm;
+	t3 = km * km;
+	t4 = Rp * Rp;
+	t5 = B * B;
+	t12 = km * Rm;
+	t17 = 0.2e1 * Rm;
+	t18 = cos(t17);
+	t22 = t2 * Rp;
+	t25 = B * t3;
+	t26 = t5 * B;
+	t33 = t5 * km;
+	t38 = sin(t17);
+	t40 = Rm * B;
+	t41 = 0.3e1 * t5;
+	t51 = exp(-0.2e1 * Rp);
+	t53 = B + Rp;
+	t54 = Rm * t53;
+	t57 = t41 + 0.2e1 * Rp * B + t2 - t3 - t4;
+	t59 = t54 * t57 * AA;
+	t60 = B * km;
+	t61 = 0.2e1 * t60;
+	t62 = t40 + t61 - t1;
+	t67 = Rm - km;
+	t68 = cos(t67);
+	t70 = -t61 + t40 - t1;
+	t75 = Rm + km;
+	t76 = cos(t75);
+	t82 = t54 * t57 * BB;
+	t84 = sin(t75);
+	t90 = sin(t67);
+	t94 = exp(-t53);
+	t97 = 0.3e1 * Rm * t26;
+	t98 = t2 * Rm;
+	t99 = t98 * B;
+	t100 = t3 * Rm;
+	t101 = t100 * Rp;
+	t103 = Rm * t4 * B;
+	t104 = t4 * Rp;
+	t105 = Rm * t104;
+	t107 = 0.8e1 * t33 * Rp;
+	t109 = 0.5e1 * t1 * t5;
+	t110 = t98 * Rp;
+	t111 = t100 * B;
+	t112 = t97 + t99 - t101 + t103 - t105 + t107 + t109 + t110 - t111;
+	t114 = t2 * t4;
+	t116 = 0.2e1 * t60 * t1;
+	t117 = t2 * t5;
+	t119 = 0.3e1 * t26 * Rp;
+	t120 = t104 * B;
+	t121 = t4 * t5;
+	t122 = 0.2e1 * t121;
+	t123 = t22 * B;
+	t125 = 0.2e1 * t33 * Rm;
+	t126 = t25 * Rp;
+	t127 = t114 + t116 + t117 - t119 + t120 + t122 + t123 + t125 + t126;
+	t132 = -t107 + t103 - t105 - t101 + t97 - t111 + t110 + t109 + t99;
+	t134 = t120 - t125 + t123 - t116 + t122 + t117 + t114 + t126 - t119;
+	t152 = exp(-0.3e1 * Rp - B);
+	t161 = exp(-0.4e1 * Rp);
+	_C2 = (((0.2e1 * t1 * (t2 - t3 - t4 + 0.5e1 * t5) * AA - 0.8e1 * B * BB * t12 * Rp) * t18 + (0.2e1 * Rp * (0.2e1 * t5 * Rp + 0.2e1 * t22 + t2 * B + t25 - 0.3e1 * t26 + B * t4) * AA + 0.8e1 * t33 * BB * Rp) * t38 + 0.2e1 * t40 * (t41 + t4 + t2 - t3) * AA - 0.8e1 * t5 * BB * t12) * t51 + ((-t59 + 0.2e1 * t54 * t62 * BB) * t68 + (-t59 - 0.2e1 * t54 * t70 * BB) * t76 + (0.2e1 * t54 * t70 * AA - t82) * t84 + (0.2e1 * t54 * t62 * AA + t82) * t90) * t94 + ((t112 * AA - 0.2e1 * t127 * BB) * t68 + (t132 * AA + 0.2e1 * t134 * BB) * t76 + (-0.2e1 * t134 * AA + t132 * BB) * t84 + (-0.2e1 * t127 * AA - t112 * BB) * t90) * t152 + (-0.2e1 * t59 + 0.8e1 * t40 * km * t53 * BB) * t161) / (((-0.8e1 * t2 - 0.8e1 * t5) * t4 * t18 + 0.8e1 * t117 + 0.8e1 * t121) * t51 + (0.4e1 * t114 - 0.4e1 * t117) * t161 + 0.4e1 * t114 - 0.4e1 * t117);
+	
+	t1 = B * B;
+	t2 = t1 * Rp;
+	t4 = Rm * Rm;
+	t5 = t4 * Rp;
+	t7 = Rp * Rp;
+	t8 = B * t7;
+	t11 = km * km;
+	t13 = t4 * B;
+	t21 = 0.8e1 * t1 * km * BB * Rp;
+	t23 = 0.2e1 * Rm;
+	t24 = cos(t23);
+	t26 = Rm * Rp;
+	t38 = sin(t23);
+	t51 = exp(-0.2e1 * Rp);
+	t53 = B + Rp;
+	t54 = Rm * t53;
+	t55 = Rm * B;
+	t57 = 0.2e1 * B * km;
+	t58 = t55 + t57 - t26;
+	t62 = 0.3e1 * t1;
+	t64 = 0.2e1 * Rp * B;
+	t65 = t62 + t64 + t4 - t11 - t7;
+	t67 = t54 * t65 * BB;
+	t69 = Rm - km;
+	t70 = cos(t69);
+	t72 = -t57 + t55 - t26;
+	t77 = Rm + km;
+	t78 = cos(t77);
+	t81 = t54 * t65 * AA;
+	t86 = sin(t77);
+	t92 = sin(t69);
+	t96 = exp(-t53);
+	t98 = B - Rp;
+	t99 = Rm * t98;
+	t100 = t55 + t57 + t26;
+	t104 = t62 - t64 + t4 - t11 - t7;
+	t106 = t99 * t104 * BB;
+	t109 = -t57 + t55 + t26;
+	t116 = t99 * t104 * AA;
+	t130 = exp(-0.3e1 * Rp - B);
+	t141 = t4 * t1;
+	t147 = t4 * t7;
+	t151 = exp(-0.4e1 * Rp);
+	_C3 = (((-0.2e1 * Rp * (-0.2e1 * t2 - 0.2e1 * t5 + t8 - 0.3e1 * t1 * B + B * t11 + t13) * AA - t21) * t24 + (0.2e1 * t26 * (t4 - t11 - t7 + 0.5e1 * t1) * AA - 0.8e1 * B * BB * km * Rm * Rp) * t38 - 0.2e1 * B * (0.2e1 * t8 + 0.2e1 * t13 + 0.3e1 * t2 - t7 * Rp - t5 - t11 * Rp) * AA + t21) * t51 + ((-0.2e1 * t54 * t58 * AA - t67) * t70 + (-0.2e1 * t54 * t72 * AA + t67) * t78 + (-t81 - 0.2e1 * t54 * t72 * BB) * t86 + (-t81 + 0.2e1 * t54 * t58 * BB) * t92) * t96 + ((0.2e1 * t99 * t100 * AA + t106) * t70 + (0.2e1 * t99 * t109 * AA - t106) * t78 + (t116 + 0.2e1 * t99 * t109 * BB) * t86 + (t116 - 0.2e1 * t99 * t100 * BB) * t92) * t130 + 0.4e1 * t4 * t98 * t53 * AA) / (((-0.8e1 * t4 - 0.8e1 * t1) * t7 * t24 + 0.8e1 * t141 + 0.8e1 * t7 * t1) * t51 + (0.4e1 * t147 - 0.4e1 * t141) * t151 + 0.4e1 * t147 - 0.4e1 * t141);
+	
+	t1 = Rm * Rp;
+	t2 = Rm * Rm;
+	t3 = km * km;
+	t4 = Rp * Rp;
+	t5 = B * B;
+	t12 = km * Rm;
+	t17 = 0.2e1 * Rm;
+	t18 = cos(t17);
+	t22 = t2 * Rp;
+	t25 = t5 * B;
+	t27 = B * t3;
+	t33 = t5 * km;
+	t38 = sin(t17);
+	t40 = Rm * B;
+	t41 = 0.3e1 * t5;
+	t51 = exp(-0.2e1 * Rp);
+	t53 = t2 * Rm;
+	t54 = t53 * B;
+	t56 = 0.5e1 * t1 * t5;
+	t58 = Rm * t4 * B;
+	t59 = t3 * Rm;
+	t60 = t59 * Rp;
+	t62 = 0.8e1 * t33 * Rp;
+	t64 = 0.3e1 * Rm * t25;
+	t65 = t53 * Rp;
+	t66 = t59 * B;
+	t67 = t4 * Rp;
+	t68 = Rm * t67;
+	t69 = t54 - t56 + t58 + t60 - t62 + t64 - t65 - t66 + t68;
+	t71 = t2 * t4;
+	t73 = 0.3e1 * t25 * Rp;
+	t74 = t2 * t5;
+	t75 = t27 * Rp;
+	t76 = B * km;
+	t78 = 0.2e1 * t76 * t1;
+	t80 = 0.2e1 * t33 * Rm;
+	t81 = t22 * B;
+	t82 = t4 * t5;
+	t83 = 0.2e1 * t82;
+	t84 = t67 * B;
+	t85 = t71 + t73 + t74 - t75 - t78 + t80 - t81 + t83 - t84;
+	t89 = Rm - km;
+	t90 = cos(t89);
+	t92 = t60 - t66 - t65 + t58 + t54 - t56 + t62 + t68 + t64;
+	t94 = t73 + t78 - t81 + t74 - t80 - t84 - t75 + t83 + t71;
+	t98 = Rm + km;
+	t99 = cos(t98);
+	t105 = sin(t98);
+	t111 = sin(t89);
+	t115 = exp(-Rp - B);
+	t117 = B - Rp;
+	t118 = Rm * t117;
+	t121 = t41 - 0.2e1 * Rp * B + t2 - t3 - t4;
+	t123 = t118 * t121 * AA;
+	t124 = 0.2e1 * t76;
+	t125 = t40 + t124 + t1;
+	t131 = -t124 + t40 + t1;
+	t141 = t118 * t121 * BB;
+	t152 = exp(-0.3e1 * Rp - B);
+	t171 = exp(-0.4e1 * Rp);
+	_C4 = (((-0.2e1 * t1 * (t2 - t3 - t4 + 0.5e1 * t5) * AA + 0.8e1 * B * BB * t12 * Rp) * t18 + (-0.2e1 * Rp * (-0.2e1 * t5 * Rp - 0.2e1 * t22 + t4 * B - 0.3e1 * t25 + t27 + t2 * B) * AA - 0.8e1 * t33 * BB * Rp) * t38 + 0.2e1 * t40 * (t41 + t4 + t2 - t3) * AA - 0.8e1 * t5 * BB * t12) * t51 + ((t69 * AA - 0.2e1 * t85 * BB) * t90 + (t92 * AA + 0.2e1 * t94 * BB) * t99 + (-0.2e1 * t94 * AA + t92 * BB) * t105 + (-0.2e1 * t85 * AA - t69 * BB) * t111) * t115 + ((-t123 + 0.2e1 * t118 * t125 * BB) * t90 + (-t123 - 0.2e1 * t118 * t131 * BB) * t99 + (0.2e1 * t118 * t131 * AA - t141) * t105 + (0.2e1 * t118 * t125 * AA + t141) * t111) * t152 - 0.2e1 * t123 + 0.8e1 * t40 * km * t117 * BB) / (((-0.8e1 * t2 - 0.8e1 * t5) * t4 * t18 + 0.8e1 * t74 + 0.8e1 * t82) * t51 + (0.4e1 * t71 - 0.4e1 * t74) * t171 + 0.4e1 * t71 - 0.4e1 * t74);
+	
+	/******************************************************************/
+	/******************************************************************/
+	
+	/*******************************************/
+	/*       calculate the velocities etc      */
+	/*******************************************/
+	
+	t2 = exp(UU * z);
+	t3 = Rm * z;
+	t4 = cos(t3);
+	t6 = sin(t3);
+	t11 = exp(-VV * z);
+	t18 = exp(-0.2e1 * z * B);
+	t19 = km * z;
+	t20 = cos(t19);
+	t22 = sin(t19);
+	u1 = kn * (t2 * (_C1 * t4 + _C2 * t6) + t11 * (_C3 * t4 + _C4 * t6) + t18 * (AA * t20 + BB * t22));
+	
+	t1 = Rm * z;
+	t2 = cos(t1);
+	t4 = sin(t1);
+	t14 = exp(UU * z);
+	t26 = exp(-VV * z);
+	t28 = km * z;
+	t29 = cos(t28);
+	t31 = sin(t28);
+	t43 = exp(-0.2e1 * z * B);
+	u2 = (-UU * (_C1 * t2 + _C2 * t4) + _C1 * t4 * Rm - _C2 * t2 * Rm) * t14 + (VV * (_C3 * t2 + _C4 * t4) + _C3 * t4 * Rm - _C4 * t2 * Rm) * t26 + (0.2e1 * B * (AA * t29 + BB * t31) + AA * t31 * km - BB * t29 * km) * t43;
+	
+	t2 = 0.2e1 * z * B;
+	t3 = exp(t2);
+	t4 = t3 * kn;
+	t5 = Rm * z;
+	t6 = cos(t5);
+	t8 = sin(t5);
+	t18 = exp(UU * z);
+	t31 = exp(-VV * z);
+	t34 = km * z;
+	t35 = cos(t34);
+	t37 = sin(t34);
+	t47 = exp(-t2);
+	u3 = 0.2e1 * t4 * (UU * (_C1 * t6 + _C2 * t8) - _C1 * t8 * Rm + _C2 * t6 * Rm) * t18 + 0.2e1 * t4 * (-VV * (_C3 * t6 + _C4 * t8) - _C3 * t8 * Rm + _C4 * t6 * Rm) * t31 + 0.2e1 * t4 * (-0.2e1 * B * (AA * t35 + BB * t37) - AA * t37 * km + BB * t35 * km) * t47;
+	
+	t1 = Rm * Rm;
+	t3 = UU * UU;
+	t8 = kn * kn;
+	t11 = Rm * z;
+	t12 = sin(t11);
+	t14 = cos(t11);
+	t20 = t14 * Rm;
+	t27 = 0.2e1 * z * B;
+	t28 = exp(t27);
+	t31 = exp(UU * z);
+	t38 = VV * VV;
+	t54 = exp(-VV * z);
+	t56 = km * km;
+	t59 = B * B;
+	t66 = km * z;
+	t67 = sin(t66);
+	t69 = cos(t66);
+	t83 = exp(-t27);
+	u4 = ((_C2 * t1 - t3 * _C2 + 0.2e1 * UU * _C1 * Rm - _C2 * t8) * t12 + _C1 * t14 * t1 - t3 * _C1 * t14 - 0.2e1 * UU * _C2 * t20 - t8 * _C1 * t14) * t28 * t31 + ((-0.2e1 * VV * _C3 * Rm + _C4 * t1 - _C4 * t8 - t38 * _C4) * t12 + 0.2e1 * VV * _C4 * t20 + _C3 * t14 * t1 - t8 * _C3 * t14 - t38 * _C3 * t14) * t28 * t54 + ((BB * t56 - t8 * BB - 0.4e1 * t59 * BB - 0.4e1 * B * AA * km) * t67 + AA * t69 * t56 - t8 * AA * t69 - 0.4e1 * t59 * AA * t69 + 0.4e1 * B * BB * t69 * km) * t28 * t83;
+	
+	
+	t1 = Rm * z;
+	t2 = sin(t1);
+	t3 = Rm * Rm;
+	t4 = t3 * Rm;
+	t5 = t2 * t4;
+	t6 = UU * UU;
+	t7 = t6 * UU;
+	t8 = cos(t1);
+	t15 = 0.2e1 * B * t8 * t3;
+	t19 = B * UU;
+	t20 = t2 * Rm;
+	t23 = kn * kn;
+	t24 = B * t23;
+	t26 = 0.2e1 * t24 * t8;
+	t27 = t23 * UU;
+	t29 = B * t6;
+	t33 = t23 * t2 * Rm;
+	t35 = 0.1e1 / kn;
+	t42 = 0.2e1 * B * t2 * t3;
+	t43 = t8 * t4;
+	t45 = 0.2e1 * t24 * t2;
+	t52 = t23 * t8 * Rm;
+	t53 = t8 * Rm;
+	t64 = 0.2e1 * z * B;
+	t65 = exp(t64);
+	t68 = exp(UU * z);
+	t70 = B * VV;
+	t76 = t23 * VV;
+	t78 = VV * VV;
+	t79 = t78 * VV;
+	t84 = B * t78;
+	t108 = exp(-VV * z);
+	t111 = km * z;
+	t112 = sin(t111);
+	t113 = km * km;
+	t118 = cos(t111);
+	t119 = t118 * km;
+	t121 = B * B;
+	t123 = t112 * km;
+	t130 = t113 * km;
+	t148 = exp(-t64);
+	u5 = (-(-t5 - t7 * t8 + 0.3e1 * UU * t8 * t3 + t15 + 0.3e1 * t6 * t2 * Rm + 0.4e1 * t19 * t20 - t26 + t27 * t8 - 0.2e1 * t29 * t8 - t33) * t35 * _C1 - (-t7 * t2 + t27 * t2 + t42 + t43 - t45 + 0.3e1 * UU * t2 * t3 - 0.2e1 * t29 * t2 + t52 - 0.4e1 * t19 * t53 - 0.3e1 * t6 * t8 * Rm) * t35 * _C2) * t65 * t68 + (-(t15 - 0.4e1 * t70 * t20 - t33 - 0.3e1 * VV * t8 * t3 - t76 * t8 + t79 * t8 + 0.3e1 * t78 * t2 * Rm - 0.2e1 * t84 * t8 - t26 - t5) * t35 * _C3 - (t52 - 0.3e1 * VV * t2 * t3 + t79 * t2 + 0.4e1 * t70 * t53 - 0.3e1 * t78 * t8 * Rm - 0.2e1 * t84 * t2 + t43 - t76 * t2 + t42 - t45) * t35 * _C4) * t65 * t108 - t65 * (-0.4e1 * B * BB * t112 * t113 + t23 * BB * t119 + 0.4e1 * t121 * AA * t123 - 0.4e1 * t121 * BB * t119 + BB * t118 * t130 - AA * t112 * t130 - 0.4e1 * B * AA * t118 * t113 - t23 * AA * t123 - 0.4e1 * t24 * AA * t118 - 0.4e1 * t24 * BB * t112) * t35 * t148;
+	
+	
+	
+	t2 = 0.2e1 * z * B;
+	t3 = exp(t2);
+	t4 = t3 * kn;
+	t5 = Rm * z;
+	t6 = cos(t5);
+	t8 = sin(t5);
+	t18 = exp(UU * z);
+	t31 = exp(-VV * z);
+	t34 = km * z;
+	t35 = cos(t34);
+	t37 = sin(t34);
+	t47 = exp(-t2);
+	u6 = -0.2e1 * t4 * (UU * (_C1 * t6 + _C2 * t8) - _C1 * t8 * Rm + _C2 * t6 * Rm) * t18 - 0.2e1 * t4 * (-VV * (_C3 * t6 + _C4 * t8) - _C3 * t8 * Rm + _C4 * t6 * Rm) * t31 - 0.2e1 * t4 * (-0.2e1 * B * (AA * t35 + BB * t37) - AA * t37 * km + BB * t35 * km) * t47;
+	
+	
+	
+	
+	/******************************************************************/
+	/******************************************************************/
+	
+	
+	
+	sum5 += u5*cos(n*M_PI*x);  /* pressure */
+	u6 -= u5; /* get total stress */
+	sum6 += u6*cos(n*M_PI*x);  /* xx stress */
+	
+	u1 *= cos(n*M_PI*x); /* z velocity */
+	sum1 += u1;
+	u2 *= sin(n*M_PI*x); /* x velocity */
+	sum2 += u2;
+	u3 -= u5; /* get total stress */
+	u3 *= cos(n*M_PI*x); /* zz stress */
+	sum3 += u3;
+	u4 *= sin(n*M_PI*x); /* zx stress */
+	sum4 += u4;
+	
+	rho = -sigma*sin(km*z)*cos(kn*x); /* density */
+	sum7 += rho;
+	
+	SS = exp(UU*z)*(_C1*cos(Rm*z)+_C2*sin(Rm*z)) +exp(-VV*z)*(_C3*cos(Rm*z)+_C4*sin(Rm*z)) + exp(-2*z*B)*(AA*cos(km*z)+BB*sin(km*z));
+	SS *= sin(kn*x); /* stream function */
+	
+	mag=sqrt(u1*u1+u2*u2);
+	/*printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,SS);*/
+	
+	
+	/* Output */
+	if( vel != NULL ) {
+		vel[0] = sum2;
+		vel[1] = sum1;
+	}
+	if( presssure != NULL ) {
+		(*presssure) = sum5;
+	}
+	if( total_stress != NULL ) {
+		total_stress[0] = sum6;
+		total_stress[1] = sum3;
+		total_stress[2] = sum4;
+	}
+	if( strain_rate != NULL ) {
+		/* sigma = tau - p, tau = sigma + p, tau[] = 2*eta*strain_rate[] */
+		Z = exp( 2.0 * B * z );
+		strain_rate[0] = (sum6+sum5)/(2.0*Z);
+		strain_rate[1] = (sum3+sum5)/(2.0*Z);
+		strain_rate[2] = (sum4)/(2.0*Z);
+	}
+	/* Value checks, could be cleaned up if needed. Julian Giordani 9-Oct-2006*/
+        if( fabs( sum5 - ( -0.5*(sum6+sum3) ) ) > 1e-5 ) {
+                assert(0);
+        }
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solL/Analytic_solL.c
--- a/SysTest/AnalyticPlugins/Velic_solL/Analytic_solL.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,154 +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:
-*+		Mirko Velic
-*+		Julian Giordani
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Patrick Sunter
-** $Id: solL.c 636 2006-09-08 03:07:06Z JulianGiordani $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include "Analytic_solL.h"
-
-const Type Velic_solL_Type = "Underworld_Velic_solL";
-
-void Velic_solL_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
-	Velic_solL* self = (Velic_solL*) analyticSolution;
-	
-	_Velic_solL( coord, self->sigmaB, self->sigmaA, self->eta, NULL, pressure, NULL, NULL );
-}
-
-void Velic_solL_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
-	Velic_solL* self = (Velic_solL*) analyticSolution;
-	
-	_Velic_solL( coord, self->sigmaB, self->sigmaA, self->eta, velocity, NULL, NULL, NULL );
-}
-
-void Velic_solL_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
-	Velic_solL* self = (Velic_solL*) analyticSolution;
-	
-	_Velic_solL( coord, self->sigmaB, self->sigmaA, self->eta, NULL, NULL, stress, NULL );
-}
-
-
-void Velic_solL_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
-	Velic_solL* self = (Velic_solL*) analyticSolution;
-	
-	_Velic_solL( coord, self->sigmaB, self->sigmaA, self->eta, NULL, NULL, NULL, strainRate );
-}
-
-void _Velic_solL_Init( Velic_solL* self, double sigmaB, double sigmaA, double eta ) {
-	// TODO	Bool                     correctInput = True;
-	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
-        self->_getAnalyticVelocity    = Velic_solL_VelocityFunction;
-	self->_getAnalyticPressure    = Velic_solL_PressureFunction;
-	self->_getAnalyticTotalStress = Velic_solL_StressFunction;
-	self->_getAnalyticStrainRate  = Velic_solL_StrainRateFunction;
-
-	self->sigmaB = sigmaB;
-	self->sigmaA = sigmaA;
-	self->eta = eta;
-}
-
-void _Velic_solL_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
-	Velic_solL* self = (Velic_solL*) analyticSolution;
-	FeVariable*              velocityField;
-	FeVariable*              pressureField;
-	FeVariable*              stressField;
-	FeVariable*              strainRateField;
-	FeVariable*              recoveredStrainRateField;
-	FeVariable*              recoveredStressField;
-	double                   sigmaB, sigmaA, eta;
-
-	/* Construct Parent */
-	_AnalyticSolution_AssignFromXML( self, cf, data );
-
-	/* Create Analytic Fields */
-	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solL_VelocityFunction );
-
-	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
-	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solL_PressureFunction );
-
-	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False, data );
-	if ( stressField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solL_StressFunction );
-
-	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
-	if ( strainRateField   ) {
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solL_StrainRateFunction );
-	}
-
-	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
-	if ( recoveredStrainRateField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solL_StrainRateFunction );
-
-	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
-	if ( recoveredStressField  )
-		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solL_StressFunction );
-
-	sigmaB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solL_sigmaB", 2.0  );
-	sigmaA = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solL_sigmaA", 1.0  );
-	eta = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solL_eta", 1.0  );
-
-	_Velic_solL_Init( self, sigmaB, sigmaA, eta );
-}
-
-void* _Velic_solL_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Velic_solL);
-	Type                                                      type = Velic_solL_Type;
-	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
-	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
-	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solL_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Velic_solL_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _AnalyticSolution_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 Underworld_Velic_solL_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Velic_solL_Type, (Name)"0", _Velic_solL_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solL/Analytic_solL.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solL/Analytic_solL.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,154 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Mirko Velic
+*+		Julian Giordani
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Patrick Sunter
+** $Id: solL.c 636 2006-09-08 03:07:06Z JulianGiordani $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include "Analytic_solL.h"
+
+const Type Velic_solL_Type = "Underworld_Velic_solL";
+
+void Velic_solL_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
+	Velic_solL* self = (Velic_solL*) analyticSolution;
+	
+	_Velic_solL( coord, self->sigmaB, self->sigmaA, self->eta, NULL, pressure, NULL, NULL );
+}
+
+void Velic_solL_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
+	Velic_solL* self = (Velic_solL*) analyticSolution;
+	
+	_Velic_solL( coord, self->sigmaB, self->sigmaA, self->eta, velocity, NULL, NULL, NULL );
+}
+
+void Velic_solL_StressFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* stress ) {
+	Velic_solL* self = (Velic_solL*) analyticSolution;
+	
+	_Velic_solL( coord, self->sigmaB, self->sigmaA, self->eta, NULL, NULL, stress, NULL );
+}
+
+
+void Velic_solL_StrainRateFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* strainRate ) {
+	Velic_solL* self = (Velic_solL*) analyticSolution;
+	
+	_Velic_solL( coord, self->sigmaB, self->sigmaA, self->eta, NULL, NULL, NULL, strainRate );
+}
+
+void _Velic_solL_Init( Velic_solL* self, double sigmaB, double sigmaA, double eta ) {
+	// TODO	Bool                     correctInput = True;
+	// Set the general AnalyticSolution (parent class) field function pointers to the specific analytic sols to use
+        self->_getAnalyticVelocity    = Velic_solL_VelocityFunction;
+	self->_getAnalyticPressure    = Velic_solL_PressureFunction;
+	self->_getAnalyticTotalStress = Velic_solL_StressFunction;
+	self->_getAnalyticStrainRate  = Velic_solL_StrainRateFunction;
+
+	self->sigmaB = sigmaB;
+	self->sigmaA = sigmaA;
+	self->eta = eta;
+}
+
+void _Velic_solL_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
+	Velic_solL* self = (Velic_solL*) analyticSolution;
+	FeVariable*              velocityField;
+	FeVariable*              pressureField;
+	FeVariable*              stressField;
+	FeVariable*              strainRateField;
+	FeVariable*              recoveredStrainRateField;
+	FeVariable*              recoveredStressField;
+	double                   sigmaB, sigmaA, eta;
+
+	/* Construct Parent */
+	_AnalyticSolution_AssignFromXML( self, cf, data );
+
+	/* Create Analytic Fields */
+	velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, velocityField, Velic_solL_VelocityFunction );
+
+	pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  );
+	AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, pressureField, Velic_solL_PressureFunction );
+
+	stressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StressField", FeVariable, False, data );
+	if ( stressField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, stressField, Velic_solL_StressFunction );
+
+	strainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"StrainRateField", FeVariable, False, data );
+	if ( strainRateField   ) {
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, strainRateField, Velic_solL_StrainRateFunction );
+	}
+
+	recoveredStrainRateField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStrainRateField", FeVariable, False, data );
+	if ( recoveredStrainRateField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStrainRateField, Velic_solL_StrainRateFunction );
+
+	recoveredStressField = Stg_ComponentFactory_ConstructByName( cf, (Name)"recoveredStressField", FeVariable, False, data );
+	if ( recoveredStressField  )
+		AnalyticSolution_RegisterFeVariableWithAnalyticFunction( self, recoveredStressField, Velic_solL_StressFunction );
+
+	sigmaB = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solL_sigmaB", 2.0  );
+	sigmaA = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solL_sigmaA", 1.0  );
+	eta = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solL_eta", 1.0  );
+
+	_Velic_solL_Init( self, sigmaB, sigmaA, eta );
+}
+
+void* _Velic_solL_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Velic_solL);
+	Type                                                      type = Velic_solL_Type;
+	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
+	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
+	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Velic_solL_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Velic_solL_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _AnalyticSolution_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 Underworld_Velic_solL_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Velic_solL_Type, (Name)"0", _Velic_solL_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solL/solL.c
--- a/SysTest/AnalyticPlugins/Velic_solL/solL.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,224 +0,0 @@
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-
-void _Velic_solL( 
-		double pos[],
-		double _sigma_B, double _sigma_A,
-		double _eta,
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] );
-
-
-int main( int argc, char **argv )
-{
-	int i,j;
-	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
-	double x,z;
-	
-	for (i=0;i<101;i++){
-		for(j=0;j<101;j++){
-			x = i/100.0;
-			z = j/100.0;
-			
-			pos[0] = x;
-			pos[1] = z;
-			_Velic_solL(
-					pos,
-					2.0, 1.0,
-					1.0,
-					vel, &pressure, total_stress, strain_rate );
-			printf("t_zx fucked !! \n");
-			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
-					pos[0],pos[1],
-					vel[0],vel[1], pressure, 
-					total_stress[0], total_stress[1], total_stress[2], 
-					strain_rate[0], strain_rate[1], strain_rate[2] );
-		}
-		printf("\n");
-	}
-	
-	return 0;
-}
-
-
-
-void _Velic_solL( 
-		double pos[],
-		double _sigma_B, double _sigma_A, /* density B, density A */
-		double _eta, /* viscosity */
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] )
-{
-	double u1,u2,u3,u4,pp,txx,Z;
-	double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,x,z;
-	double dsigma,sigma0,sigma1;
-	double del_rho;
-	int n;
-	double kn;
-	double _C1,_C2,_C3,_C4;
-	double rho;
-	
-	double t1,t2,t3,t4,t5,t6,t8,t9,t10,t12;
-	double t14,t16,t17,t20,t23;
-	
-	
-	
-	/*************************************************************************/
-	/*************************************************************************/
-	
-	sigma1 = _sigma_B; /* upper triangular density */
-	sigma0 = _sigma_A; /* lower triangular density */
-	
-	dsigma = sigma1-sigma0; /* density difference */
-	Z = _eta; /* viscosity */
-	
-	/*************************************************************************/
-	/*************************************************************************/
-	
-	x = pos[0];
-	z = pos[1];
-	
-	sum1=0.0;
-	sum2=0.0;
-	sum3=0.0;
-	sum4=0.0;
-	sum5=0.0;
-	sum6=0.0;
-	sum7=0.0;
-	
-	for(n=1;n<55;n++){
-		kn = (double) n*M_PI;
-		
-		
-		/*******************************************/
-		/*            calculate del_rho            */
-		/*******************************************/
-		del_rho =  2.0*dsigma*sin(kn*(z-1.0))/kn; /* density */
-		
-		/*******************************************/
-		/*         calculate the constants         */
-		/*******************************************/
-		t1 = sin(kn);
-		t3 = exp(-kn);
-		t4 = t3 * t3;
-		t9 = kn * kn;
-		t14 = pow(t3 - 0.1e1, 0.2e1);
-		t17 = pow(t3 + 0.1e1, 0.2e1);
-		_C1 = -dsigma * t1 * (0.2e1 * t4 * kn - t4 + 0.1e1) / t9 / Z / t14 / t17 / 0.4e1;
-		
-		t1 = sin(kn);
-		t3 = exp(-kn);
-		t4 = t3 * t3;
-		t9 = kn * kn;
-		t14 = pow(t3 - 0.1e1, 0.2e1);
-		t17 = pow(t3 + 0.1e1, 0.2e1);
-		_C2 = dsigma * t1 * t3 * (-t4 + 0.1e1 + 0.2e1 * kn) / t9 / Z / t14 / t17 / 0.4e1;
-		
-		t1 = sin(kn);
-		t6 = exp(-kn);
-		_C3 = t1 * dsigma / Z / kn / (t6 - 0.1e1) / (t6 + 0.1e1) / 0.4e1;
-		
-		t1 = exp(-kn);
-		t2 = sin(kn);
-		_C4 = t1 * t2 * dsigma / Z / kn / (t1 - 0.1e1) / (t1 + 0.1e1) / 0.4e1;
-		
-		/*******************************************/
-		/*       calculate the velocities etc      */
-		/*******************************************/
-		
-		
-		t3 = kn * z;
-		t4 = exp(-t3);
-		t10 = exp(kn * (z - 0.1e1));
-		t12 = kn * kn;
-		t16 = sin(t3 - kn);
-		u1 = (_C1 + z * _C3) * t4 + (_C2 + z * _C4) * t10 - dsigma / t12 * t16 / Z / 0.4e1;
-		
-		t1 = kn * z;
-		t2 = exp(-t1);
-		t5 = kn * (z - 0.1e1);
-		t6 = exp(t5);
-		t10 = 0.1e1 / kn;
-		t17 = kn * kn;
-		t20 = cos(t5);
-		u2 = t2 * _C1 - t6 * _C2 + t2 * (t1 - 0.1e1) * _C3 * t10 - t6 * (t1 + 0.1e1) * _C4 * t10 + dsigma / t17 * t20 / Z / 0.4e1;
-		
-		t1 = Z * kn;
-		t3 = exp(-kn * z);
-		t8 = kn * (z - 0.1e1);
-		t9 = exp(t8);
-		t23 = cos(t8);
-		u3 = -0.2e1 * t1 * t3 * _C1 + 0.2e1 * t1 * t9 * _C2 - 0.2e1 * t1 * t3 * z * _C3 + 0.2e1 * t1 * t9 * z * _C4 - 0.1e1 / kn * dsigma * t23;
-		
-		t2 = kn * z;
-		t8 = exp(kn * (z - 0.1e1));
-		t14 = exp(-t2);
-		u4 = -0.2e1 * Z * (_C4 + kn * _C2 + t2 * _C4) * t8 - 0.2e1 * Z * (-_C3 + kn * _C1 + t2 * _C3) * t14;
-		
-		
-		
-		pp = (double)-(u3 + 2.0*n*M_PI*Z*u2)*cos(n*M_PI*x); /* pressure */
-		
-		txx = (double)(u3 + 4*Z*n*M_PI*u2)*cos(n*M_PI*x); /* xx stress */	    
-		sum5 += pp;
-		sum6 += txx;
-		
-		u1 *= cos(n*M_PI*x); /* z velocity */
-		sum1 += u1;
-		u2 *= sin(n*M_PI*x); /* x velocity */
-		sum2 += u2;
-		u3 *= cos(n*M_PI*x); /* zz stress */
-		sum3 += u3;
-		u4 *= sin(n*M_PI*x); /* zx stress */
-		sum4 += u4;
-		
-		rho =  del_rho*cos(n*M_PI*x); /* density */
-		sum7 += rho;
-	}/* n */
-	
-	/* include terms for n=0 now */
-	sum7 += dsigma*z+sigma0; /* density term for n=0 */
-	
-	u3 = 0.5*dsigma*z*z + sigma0*z; /* zz stress for n=0 */
-	sum3 += u3;
-	
-	txx = u3; /* xx stress */
-	pp = -u3; /* pressure */
-	sum5 += pp;
-	sum6 += txx;
-	
-	
-	mag=sqrt(sum1*sum1+sum2*sum2);
-	//printf("%0.7g %0.7g %0.7g %0.7g %0.7g %0.7g\n",x,y,z,sum3,sum2,sum1);
-	//printf("%0.7g %0.7g %0.7g\n%0.7g %0.7g %0.7g\n\n\n",x,y,z,x+sum3,y+sum2,z+sum1);
-	/*printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7);*/
-	
-	
-	/* Output */
-	if( vel != NULL ) {
-		vel[0] = sum2;
-		vel[1] = sum1;
-	}
-	if( presssure != NULL ) {
-		(*presssure) = sum5;
-	}
-	if( total_stress != NULL ) {
-		total_stress[0] = sum6;
-		total_stress[1] = sum3;
-		total_stress[2] = sum4;
-	}
-	if( strain_rate != NULL ) {
-		/* sigma = tau - p, tau = sigma + p, tau[] = 2*eta*strain_rate[] */
-		strain_rate[0] = (sum6+sum5)/(2.0*Z);
-		strain_rate[1] = (sum3+sum5)/(2.0*Z);
-		strain_rate[2] = (sum4)/(2.0*Z);
-	}
-	/* Value checks, could be cleaned up if needed. Julian Giordani 9-Oct-2006*/
-        if( fabs( sum5 - ( -0.5*(sum6+sum3) ) ) > 1e-5 ) {
-                assert(0);
-        }
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solL/solL.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solL/solL.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,224 @@
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+
+void _Velic_solL( 
+		double pos[],
+		double _sigma_B, double _sigma_A,
+		double _eta,
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] );
+
+
+int main( int argc, char **argv )
+{
+	int i,j;
+	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
+	double x,z;
+	
+	for (i=0;i<101;i++){
+		for(j=0;j<101;j++){
+			x = i/100.0;
+			z = j/100.0;
+			
+			pos[0] = x;
+			pos[1] = z;
+			_Velic_solL(
+					pos,
+					2.0, 1.0,
+					1.0,
+					vel, &pressure, total_stress, strain_rate );
+			printf("t_zx fucked !! \n");
+			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
+					pos[0],pos[1],
+					vel[0],vel[1], pressure, 
+					total_stress[0], total_stress[1], total_stress[2], 
+					strain_rate[0], strain_rate[1], strain_rate[2] );
+		}
+		printf("\n");
+	}
+	
+	return 0;
+}
+
+
+
+void _Velic_solL( 
+		double pos[],
+		double _sigma_B, double _sigma_A, /* density B, density A */
+		double _eta, /* viscosity */
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] )
+{
+	double u1,u2,u3,u4,pp,txx,Z;
+	double sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7,x,z;
+	double dsigma,sigma0,sigma1;
+	double del_rho;
+	int n;
+	double kn;
+	double _C1,_C2,_C3,_C4;
+	double rho;
+	
+	double t1,t2,t3,t4,t5,t6,t8,t9,t10,t12;
+	double t14,t16,t17,t20,t23;
+	
+	
+	
+	/*************************************************************************/
+	/*************************************************************************/
+	
+	sigma1 = _sigma_B; /* upper triangular density */
+	sigma0 = _sigma_A; /* lower triangular density */
+	
+	dsigma = sigma1-sigma0; /* density difference */
+	Z = _eta; /* viscosity */
+	
+	/*************************************************************************/
+	/*************************************************************************/
+	
+	x = pos[0];
+	z = pos[1];
+	
+	sum1=0.0;
+	sum2=0.0;
+	sum3=0.0;
+	sum4=0.0;
+	sum5=0.0;
+	sum6=0.0;
+	sum7=0.0;
+	
+	for(n=1;n<55;n++){
+		kn = (double) n*M_PI;
+		
+		
+		/*******************************************/
+		/*            calculate del_rho            */
+		/*******************************************/
+		del_rho =  2.0*dsigma*sin(kn*(z-1.0))/kn; /* density */
+		
+		/*******************************************/
+		/*         calculate the constants         */
+		/*******************************************/
+		t1 = sin(kn);
+		t3 = exp(-kn);
+		t4 = t3 * t3;
+		t9 = kn * kn;
+		t14 = pow(t3 - 0.1e1, 0.2e1);
+		t17 = pow(t3 + 0.1e1, 0.2e1);
+		_C1 = -dsigma * t1 * (0.2e1 * t4 * kn - t4 + 0.1e1) / t9 / Z / t14 / t17 / 0.4e1;
+		
+		t1 = sin(kn);
+		t3 = exp(-kn);
+		t4 = t3 * t3;
+		t9 = kn * kn;
+		t14 = pow(t3 - 0.1e1, 0.2e1);
+		t17 = pow(t3 + 0.1e1, 0.2e1);
+		_C2 = dsigma * t1 * t3 * (-t4 + 0.1e1 + 0.2e1 * kn) / t9 / Z / t14 / t17 / 0.4e1;
+		
+		t1 = sin(kn);
+		t6 = exp(-kn);
+		_C3 = t1 * dsigma / Z / kn / (t6 - 0.1e1) / (t6 + 0.1e1) / 0.4e1;
+		
+		t1 = exp(-kn);
+		t2 = sin(kn);
+		_C4 = t1 * t2 * dsigma / Z / kn / (t1 - 0.1e1) / (t1 + 0.1e1) / 0.4e1;
+		
+		/*******************************************/
+		/*       calculate the velocities etc      */
+		/*******************************************/
+		
+		
+		t3 = kn * z;
+		t4 = exp(-t3);
+		t10 = exp(kn * (z - 0.1e1));
+		t12 = kn * kn;
+		t16 = sin(t3 - kn);
+		u1 = (_C1 + z * _C3) * t4 + (_C2 + z * _C4) * t10 - dsigma / t12 * t16 / Z / 0.4e1;
+		
+		t1 = kn * z;
+		t2 = exp(-t1);
+		t5 = kn * (z - 0.1e1);
+		t6 = exp(t5);
+		t10 = 0.1e1 / kn;
+		t17 = kn * kn;
+		t20 = cos(t5);
+		u2 = t2 * _C1 - t6 * _C2 + t2 * (t1 - 0.1e1) * _C3 * t10 - t6 * (t1 + 0.1e1) * _C4 * t10 + dsigma / t17 * t20 / Z / 0.4e1;
+		
+		t1 = Z * kn;
+		t3 = exp(-kn * z);
+		t8 = kn * (z - 0.1e1);
+		t9 = exp(t8);
+		t23 = cos(t8);
+		u3 = -0.2e1 * t1 * t3 * _C1 + 0.2e1 * t1 * t9 * _C2 - 0.2e1 * t1 * t3 * z * _C3 + 0.2e1 * t1 * t9 * z * _C4 - 0.1e1 / kn * dsigma * t23;
+		
+		t2 = kn * z;
+		t8 = exp(kn * (z - 0.1e1));
+		t14 = exp(-t2);
+		u4 = -0.2e1 * Z * (_C4 + kn * _C2 + t2 * _C4) * t8 - 0.2e1 * Z * (-_C3 + kn * _C1 + t2 * _C3) * t14;
+		
+		
+		
+		pp = (double)-(u3 + 2.0*n*M_PI*Z*u2)*cos(n*M_PI*x); /* pressure */
+		
+		txx = (double)(u3 + 4*Z*n*M_PI*u2)*cos(n*M_PI*x); /* xx stress */	    
+		sum5 += pp;
+		sum6 += txx;
+		
+		u1 *= cos(n*M_PI*x); /* z velocity */
+		sum1 += u1;
+		u2 *= sin(n*M_PI*x); /* x velocity */
+		sum2 += u2;
+		u3 *= cos(n*M_PI*x); /* zz stress */
+		sum3 += u3;
+		u4 *= sin(n*M_PI*x); /* zx stress */
+		sum4 += u4;
+		
+		rho =  del_rho*cos(n*M_PI*x); /* density */
+		sum7 += rho;
+	}/* n */
+	
+	/* include terms for n=0 now */
+	sum7 += dsigma*z+sigma0; /* density term for n=0 */
+	
+	u3 = 0.5*dsigma*z*z + sigma0*z; /* zz stress for n=0 */
+	sum3 += u3;
+	
+	txx = u3; /* xx stress */
+	pp = -u3; /* pressure */
+	sum5 += pp;
+	sum6 += txx;
+	
+	
+	mag=sqrt(sum1*sum1+sum2*sum2);
+	//printf("%0.7g %0.7g %0.7g %0.7g %0.7g %0.7g\n",x,y,z,sum3,sum2,sum1);
+	//printf("%0.7g %0.7g %0.7g\n%0.7g %0.7g %0.7g\n\n\n",x,y,z,x+sum3,y+sum2,z+sum1);
+	/*printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f\n",x,z,sum1,sum2,sum3,sum4,sum5,sum6,mag,sum7);*/
+	
+	
+	/* Output */
+	if( vel != NULL ) {
+		vel[0] = sum2;
+		vel[1] = sum1;
+	}
+	if( presssure != NULL ) {
+		(*presssure) = sum5;
+	}
+	if( total_stress != NULL ) {
+		total_stress[0] = sum6;
+		total_stress[1] = sum3;
+		total_stress[2] = sum4;
+	}
+	if( strain_rate != NULL ) {
+		/* sigma = tau - p, tau = sigma + p, tau[] = 2*eta*strain_rate[] */
+		strain_rate[0] = (sum6+sum5)/(2.0*Z);
+		strain_rate[1] = (sum3+sum5)/(2.0*Z);
+		strain_rate[2] = (sum4)/(2.0*Z);
+	}
+	/* Value checks, could be cleaned up if needed. Julian Giordani 9-Oct-2006*/
+        if( fabs( sum5 - ( -0.5*(sum6+sum3) ) ) > 1e-5 ) {
+                assert(0);
+        }
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solS/Analytic_solS.c
--- a/SysTest/AnalyticPlugins/Velic_solS/Analytic_solS.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,148 +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:
-*+		Mirko Velic
-*+		Julian Giordani
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Patrick Sunter
-** $Id: solS.c 636 2006-09-08 03:07:06Z JulianGiordani $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include "Analytic_solS.h"
-
-const Type Underworld_solS_Type = "Underworld_Velic_solS";
-
-void Underworld_solS_PressureFunction( void* analyticSolution, double* coord, double* pressure ) {
-	Underworld_solS* self = (Underworld_solS*) analyticSolution;
-	
-	_Velic_solS( coord, self->_n, self->_eta, NULL, pressure, NULL, NULL );
-}
-
-void Underworld_solS_VelocityFunction( void* analyticSolution, double* coord, double* velocity ) {
-	Underworld_solS* self = (Underworld_solS*) analyticSolution;
-	
-	_Velic_solS( coord, self->_n, self->_eta, velocity, NULL, NULL, NULL );
-}
-
-void Underworld_solS_StressFunction( void* analyticSolution, double* coord, double* stress ) {
-	Underworld_solS* self = (Underworld_solS*) analyticSolution;
-	
-	_Velic_solS( coord, self->_n, self->_eta, NULL, NULL, stress, NULL );
-}
-
-void Underworld_solS_StrainRateFunction( void* analyticSolution, double* coord, double* strainRate ) {
-	Underworld_solS* self = (Underworld_solS*) analyticSolution;
-	
-	_Velic_solS( coord, self->_n, self->_eta, NULL, NULL, NULL, strainRate );
-}
-
-void _Underworld_solS_Init( Underworld_solS* self, double _eta, int _n ) {
-	Bool isCorrectInput = True;
-
-	self->_eta = _eta;
-	self->_n = _n;
-	
-	isCorrectInput = _checkInputParams( self );
-	Journal_Firewall( isCorrectInput , Journal_Register( Error_Type, (Name)"Underworld_solS"  ),
-			"Error in function %s: Bad Input parameters, solution check valid values in .tex documentation\n",
-			__func__ );
-}
-
-void _Underworld_solS_Build( void* analyticSolution, void* data ) {
-	Underworld_solS* self = (Underworld_solS*)analyticSolution;
-	
-	_FieldTest_Build( self, data );
-
-	/* here we assign the memory and the func ptr for analytic sols */
-	self->_analyticSolutionList = Memory_Alloc_Array_Unnamed( FieldTest_AnalyticSolutionFunc*, 4 );
-	/* this order MUST be consistent with the xml file definition */
-	self->_analyticSolutionList[0] = Underworld_solS_VelocityFunction;
-	self->_analyticSolutionList[1] = Underworld_solS_PressureFunction;
-	self->_analyticSolutionList[2] = Underworld_solS_StrainRateFunction;
-	self->_analyticSolutionList[3] = Underworld_solS_StressFunction;
-}
-
-void _Underworld_solS_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
-	Underworld_solS*	self = (Underworld_solS*) analyticSolution;
-	Bool					isCorrectInput = True;
-	double				_eta;
-	int					_n;
-
-	/* Construct Parent */
-	_FieldTest_AssignFromXML( self, cf, data );
-	
-	_eta = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solS_eta", 1.0  );
-	_n = Stg_ComponentFactory_GetRootDictInt( cf, "sinusoidalLidWavenumber", 1 );
-
-	_Underworld_solS_Init( self, _eta, _n );
-
-	isCorrectInput = _checkInputParams( self );
-	Journal_Firewall( isCorrectInput , Journal_Register( Error_Type, (Name)"solS"  ),
-			"Error in function %s: Bad Input parameters, solution check valid values in .tex documentation\n",
-			__func__ );
-}
-
-Bool _checkInputParams( Underworld_solS* self ) {
-	return ( 
-		( self->_eta > 0.0 ) && ( self->_n > 0.0 )
-                 ) ? True : False;
-}
-
-void* _Underworld_solS_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Underworld_solS);
-	Type                                                      type = Underworld_solS_Type;
-	Stg_Class_DeleteFunction*                              _delete = _FieldTest_Delete;
-	Stg_Class_PrintFunction*                                _print = _FieldTest_Print;
-	Stg_Class_CopyFunction*                                  _copy = _FieldTest_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_solS_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Underworld_solS_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _Underworld_solS_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 Underworld_Velic_solS_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Underworld_solS_Type, (Name)"0", _Underworld_solS_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solS/Analytic_solS.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solS/Analytic_solS.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,148 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Mirko Velic
+*+		Julian Giordani
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Patrick Sunter
+** $Id: solS.c 636 2006-09-08 03:07:06Z JulianGiordani $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include "Analytic_solS.h"
+
+const Type Underworld_solS_Type = "Underworld_Velic_solS";
+
+void Underworld_solS_PressureFunction( void* analyticSolution, double* coord, double* pressure ) {
+	Underworld_solS* self = (Underworld_solS*) analyticSolution;
+	
+	_Velic_solS( coord, self->_n, self->_eta, NULL, pressure, NULL, NULL );
+}
+
+void Underworld_solS_VelocityFunction( void* analyticSolution, double* coord, double* velocity ) {
+	Underworld_solS* self = (Underworld_solS*) analyticSolution;
+	
+	_Velic_solS( coord, self->_n, self->_eta, velocity, NULL, NULL, NULL );
+}
+
+void Underworld_solS_StressFunction( void* analyticSolution, double* coord, double* stress ) {
+	Underworld_solS* self = (Underworld_solS*) analyticSolution;
+	
+	_Velic_solS( coord, self->_n, self->_eta, NULL, NULL, stress, NULL );
+}
+
+void Underworld_solS_StrainRateFunction( void* analyticSolution, double* coord, double* strainRate ) {
+	Underworld_solS* self = (Underworld_solS*) analyticSolution;
+	
+	_Velic_solS( coord, self->_n, self->_eta, NULL, NULL, NULL, strainRate );
+}
+
+void _Underworld_solS_Init( Underworld_solS* self, double _eta, int _n ) {
+	Bool isCorrectInput = True;
+
+	self->_eta = _eta;
+	self->_n = _n;
+	
+	isCorrectInput = _checkInputParams( self );
+	Journal_Firewall( isCorrectInput , Journal_Register( Error_Type, (Name)"Underworld_solS"  ),
+			"Error in function %s: Bad Input parameters, solution check valid values in .tex documentation\n",
+			__func__ );
+}
+
+void _Underworld_solS_Build( void* analyticSolution, void* data ) {
+	Underworld_solS* self = (Underworld_solS*)analyticSolution;
+	
+	_FieldTest_Build( self, data );
+
+	/* here we assign the memory and the func ptr for analytic sols */
+	self->_analyticSolutionList = Memory_Alloc_Array_Unnamed( FieldTest_AnalyticSolutionFunc*, 4 );
+	/* this order MUST be consistent with the xml file definition */
+	self->_analyticSolutionList[0] = Underworld_solS_VelocityFunction;
+	self->_analyticSolutionList[1] = Underworld_solS_PressureFunction;
+	self->_analyticSolutionList[2] = Underworld_solS_StrainRateFunction;
+	self->_analyticSolutionList[3] = Underworld_solS_StressFunction;
+}
+
+void _Underworld_solS_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
+	Underworld_solS*	self = (Underworld_solS*) analyticSolution;
+	Bool					isCorrectInput = True;
+	double				_eta;
+	int					_n;
+
+	/* Construct Parent */
+	_FieldTest_AssignFromXML( self, cf, data );
+	
+	_eta = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"solS_eta", 1.0  );
+	_n = Stg_ComponentFactory_GetRootDictInt( cf, "sinusoidalLidWavenumber", 1 );
+
+	_Underworld_solS_Init( self, _eta, _n );
+
+	isCorrectInput = _checkInputParams( self );
+	Journal_Firewall( isCorrectInput , Journal_Register( Error_Type, (Name)"solS"  ),
+			"Error in function %s: Bad Input parameters, solution check valid values in .tex documentation\n",
+			__func__ );
+}
+
+Bool _checkInputParams( Underworld_solS* self ) {
+	return ( 
+		( self->_eta > 0.0 ) && ( self->_n > 0.0 )
+                 ) ? True : False;
+}
+
+void* _Underworld_solS_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Underworld_solS);
+	Type                                                      type = Underworld_solS_Type;
+	Stg_Class_DeleteFunction*                              _delete = _FieldTest_Delete;
+	Stg_Class_PrintFunction*                                _print = _FieldTest_Print;
+	Stg_Class_CopyFunction*                                  _copy = _FieldTest_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_solS_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Underworld_solS_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _Underworld_solS_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 Underworld_Velic_solS_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Underworld_solS_Type, (Name)"0", _Underworld_solS_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solS/solS.c
--- a/SysTest/AnalyticPlugins/Velic_solS/solS.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,157 +0,0 @@
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-
-void _Velic_solS( 
-		double pos[],
-		int _n, double _eta,
-		double vel[], double* presssure, 
-		double total_stress[], double strain_rate[] );
-
-
-/*
-int main( int argc, char **argv )
-{
-	int i,j;
-	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
-	double x,z;
-	
-	for (i=0;i<129;i++){
-		for(j=0;j<129;j++){
-			x = i/128.0;
-			z = j/128.0;
-			
-			pos[0] = x;
-			pos[1] = z;
-			solS( pos, 1, 1.0, vel, &pressure, total_stress, strain_rate );
-			
-			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
-					pos[0],pos[1],	// 1, 2
-					vel[0],vel[1], 	// 3, 4
-					pressure, 		// 5
-					total_stress[0], total_stress[1], total_stress[2],	// 6,7,8
-			strain_rate[0], strain_rate[1], strain_rate[2] );	// 9,10,11
-			
-		}
-		printf("\n");
-	}
-	
-	return 0;
-}
-*/
-
-void _Velic_solS( 
-		double pos[],						/* coordinates */
-		int _n, double _eta,				/* wavenumber in x, viscosity */
-		double vel[], double* presssure, 				/* output: velocity, pressure */
-		double total_stress[], double strain_rate[] ) 	/* ouput: total stresss, strain rate */ 
-{
-	double Z;
-	double E;
-	double e_nPI;
-	double e_2nPI;
-	double e_4nPI;
-	double n;
-	double A,B,C,D;
-	double x,y,vx,vy;
-	double p;
-	double t_xx,t_yy,t_xy;
-	double e_xx,e_yy,e_xy;
-	double du_dx, dv_dy, du_dy, dv_dx;
-	
-	
-	Z = _eta;
-	n = _n;
-	
-	if( n == 0 ) {
-		printf("n must be non-zero \n" );
-		abort();
-	}
-	
-	
-	/* Constants */
-	e_nPI = exp( n * M_PI );
-	e_2nPI = e_nPI * e_nPI;
-	e_4nPI = e_2nPI * e_2nPI;
-	
-	E = (4.0 * n * n * M_PI * M_PI + 2.0 ) * e_2nPI - e_4nPI - 1.0;
-	
-	A = ( e_2nPI - 1.0 )* e_nPI / E;
-	B = - A;
-	
-	C =   ( 2.0 * n * M_PI - e_2nPI + 1.0 ) * e_nPI / E;
-	D = - ( 2.0 * n * M_PI * e_2nPI - e_2nPI + 1.0 ) * e_nPI / E;
-	
-	
-	x = pos[0];
-	y = pos[1];
-	
-	/* velocity */
-	vx = sin( n * M_PI * x ) * 
-		( ( A * n * M_PI + C + C * n * M_PI * y) * exp( n * M_PI * y ) 
-		- ( B * n * M_PI - D + D * n * M_PI * y ) * exp( - n * M_PI * y ) );
-	
-	vy = - n * M_PI * cos( n * M_PI * x ) * 
-		( ( A + C * y ) * exp( n * M_PI * y ) 
-		+ ( B + D * y ) * exp( - n * M_PI * y ) );
-	
-	/* pressure */
-	p = - 2.0 * n * M_PI * cos( n * M_PI * x ) * ( C * exp( n * M_PI * y ) + D * exp( - n * M_PI * y ) );
-	
-	/* strain rate */
-	du_dx = n*M_PI*cos(n*M_PI*x) * 
-		( ( A*n*M_PI + C + C*n*M_PI*y) * exp(n*M_PI*y) 
-		- ( B*n*M_PI - D + D*n*M_PI*y) * exp(-n*M_PI*y) );
-	
-	dv_dx = n*n*M_PI*M_PI*sin(n*M_PI*x) * 
-		( ( A + C*y ) * exp(n*M_PI*y) 
-		+ ( B + D*y ) * exp(-n*M_PI*y) );
-	
-	du_dy = sin(n*M_PI*x) * 
-		( ( A*n*n*M_PI*M_PI + 2.0*C*n*M_PI + C*n*n*M_PI*M_PI*y ) * exp(n*M_PI*y) 
-		+ ( B*n*n*M_PI*M_PI - 2.0*D*n*M_PI + D*n*n*M_PI*M_PI*y ) * exp(-n*M_PI*y) );
-	
-	dv_dy = - n*M_PI*cos(n*M_PI*x) * 
-		( ( A*n*M_PI + C + C*n*M_PI*y ) * exp(n*M_PI*y) 
-		+ ( -B*n*M_PI + D - D*n*M_PI*y ) * exp(-n*M_PI*y) );
-	
-	
-	e_xx = du_dx; /* du/dx */
-	e_yy = dv_dy; /* dv/dy */
-	e_xy = 0.5 * ( du_dy + dv_dx ); /* 0.5*(du/dy + dv/dx) */
-	
-	
-	
-	/* total stress */
-	t_xx = 2.0 * Z * e_xx - p;
-	t_yy = 2.0 * Z * e_yy - p;
-	t_xy = 2.0 * Z * e_xy;
-	
-	
-	
-	/* Output */
-	if( vel != NULL ) {
-		vel[0] = vx;
-		vel[1] = vy;
-	}
-	if( presssure != NULL ) {
-		(*presssure) = p;
-	}
-	if( total_stress != NULL ) {
-		total_stress[0] = t_xx;
-		total_stress[1] = t_yy;
-		total_stress[2] = t_xy;
-	}
-	if( strain_rate != NULL ) {
-		/* sigma = tau - p, tau = sigma + p, tau[] = 2*eta*strain_rate[] */
-		strain_rate[0] = e_xx;
-		strain_rate[1] = e_yy;
-		strain_rate[2] = e_xy;
-	}
-	
-	
-	
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d SysTest/AnalyticPlugins/Velic_solS/solS.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/Velic_solS/solS.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,157 @@
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+
+void _Velic_solS( 
+		double pos[],
+		int _n, double _eta,
+		double vel[], double* presssure, 
+		double total_stress[], double strain_rate[] );
+
+
+/*
+int main( int argc, char **argv )
+{
+	int i,j;
+	double pos[2], vel[2], pressure, total_stress[3], strain_rate[3];
+	double x,z;
+	
+	for (i=0;i<129;i++){
+		for(j=0;j<129;j++){
+			x = i/128.0;
+			z = j/128.0;
+			
+			pos[0] = x;
+			pos[1] = z;
+			solS( pos, 1, 1.0, vel, &pressure, total_stress, strain_rate );
+			
+			printf("%0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f %0.7f \n",
+					pos[0],pos[1],	// 1, 2
+					vel[0],vel[1], 	// 3, 4
+					pressure, 		// 5
+					total_stress[0], total_stress[1], total_stress[2],	// 6,7,8
+			strain_rate[0], strain_rate[1], strain_rate[2] );	// 9,10,11
+			
+		}
+		printf("\n");
+	}
+	
+	return 0;
+}
+*/
+
+void _Velic_solS( 
+		double pos[],						/* coordinates */
+		int _n, double _eta,				/* wavenumber in x, viscosity */
+		double vel[], double* presssure, 				/* output: velocity, pressure */
+		double total_stress[], double strain_rate[] ) 	/* ouput: total stresss, strain rate */ 
+{
+	double Z;
+	double E;
+	double e_nPI;
+	double e_2nPI;
+	double e_4nPI;
+	double n;
+	double A,B,C,D;
+	double x,y,vx,vy;
+	double p;
+	double t_xx,t_yy,t_xy;
+	double e_xx,e_yy,e_xy;
+	double du_dx, dv_dy, du_dy, dv_dx;
+	
+	
+	Z = _eta;
+	n = _n;
+	
+	if( n == 0 ) {
+		printf("n must be non-zero \n" );
+		abort();
+	}
+	
+	
+	/* Constants */
+	e_nPI = exp( n * M_PI );
+	e_2nPI = e_nPI * e_nPI;
+	e_4nPI = e_2nPI * e_2nPI;
+	
+	E = (4.0 * n * n * M_PI * M_PI + 2.0 ) * e_2nPI - e_4nPI - 1.0;
+	
+	A = ( e_2nPI - 1.0 )* e_nPI / E;
+	B = - A;
+	
+	C =   ( 2.0 * n * M_PI - e_2nPI + 1.0 ) * e_nPI / E;
+	D = - ( 2.0 * n * M_PI * e_2nPI - e_2nPI + 1.0 ) * e_nPI / E;
+	
+	
+	x = pos[0];
+	y = pos[1];
+	
+	/* velocity */
+	vx = sin( n * M_PI * x ) * 
+		( ( A * n * M_PI + C + C * n * M_PI * y) * exp( n * M_PI * y ) 
+		- ( B * n * M_PI - D + D * n * M_PI * y ) * exp( - n * M_PI * y ) );
+	
+	vy = - n * M_PI * cos( n * M_PI * x ) * 
+		( ( A + C * y ) * exp( n * M_PI * y ) 
+		+ ( B + D * y ) * exp( - n * M_PI * y ) );
+	
+	/* pressure */
+	p = - 2.0 * n * M_PI * cos( n * M_PI * x ) * ( C * exp( n * M_PI * y ) + D * exp( - n * M_PI * y ) );
+	
+	/* strain rate */
+	du_dx = n*M_PI*cos(n*M_PI*x) * 
+		( ( A*n*M_PI + C + C*n*M_PI*y) * exp(n*M_PI*y) 
+		- ( B*n*M_PI - D + D*n*M_PI*y) * exp(-n*M_PI*y) );
+	
+	dv_dx = n*n*M_PI*M_PI*sin(n*M_PI*x) * 
+		( ( A + C*y ) * exp(n*M_PI*y) 
+		+ ( B + D*y ) * exp(-n*M_PI*y) );
+	
+	du_dy = sin(n*M_PI*x) * 
+		( ( A*n*n*M_PI*M_PI + 2.0*C*n*M_PI + C*n*n*M_PI*M_PI*y ) * exp(n*M_PI*y) 
+		+ ( B*n*n*M_PI*M_PI - 2.0*D*n*M_PI + D*n*n*M_PI*M_PI*y ) * exp(-n*M_PI*y) );
+	
+	dv_dy = - n*M_PI*cos(n*M_PI*x) * 
+		( ( A*n*M_PI + C + C*n*M_PI*y ) * exp(n*M_PI*y) 
+		+ ( -B*n*M_PI + D - D*n*M_PI*y ) * exp(-n*M_PI*y) );
+	
+	
+	e_xx = du_dx; /* du/dx */
+	e_yy = dv_dy; /* dv/dy */
+	e_xy = 0.5 * ( du_dy + dv_dx ); /* 0.5*(du/dy + dv/dx) */
+	
+	
+	
+	/* total stress */
+	t_xx = 2.0 * Z * e_xx - p;
+	t_yy = 2.0 * Z * e_yy - p;
+	t_xy = 2.0 * Z * e_xy;
+	
+	
+	
+	/* Output */
+	if( vel != NULL ) {
+		vel[0] = vx;
+		vel[1] = vy;
+	}
+	if( presssure != NULL ) {
+		(*presssure) = p;
+	}
+	if( total_stress != NULL ) {
+		total_stress[0] = t_xx;
+		total_stress[1] = t_yy;
+		total_stress[2] = t_xy;
+	}
+	if( strain_rate != NULL ) {
+		/* sigma = tau - p, tau = sigma + p, tau[] = 2*eta*strain_rate[] */
+		strain_rate[0] = e_xx;
+		strain_rate[1] = e_yy;
+		strain_rate[2] = e_xy;
+	}
+	
+	
+	
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/BaseRecoveryFeVar.c
--- a/Utils/src/BaseRecoveryFeVar.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,514 +0,0 @@
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include "Underworld/Rheology/Rheology.h"
-
-#include "types.h"
-#include "BaseRecoveryFeVar.h"
-
-#include <math.h>
-#include <assert.h>
-#include <string.h>
-
-const Type BaseRecoveryFeVar_Type = "BaseRecoveryFeVar";
-
-void* _BaseRecoveryFeVar_DefaultNew( Name name ) {
-  /* this is an abstract call so this function should never be called */
-	assert(0);
-}
-BaseRecoveryFeVar* _BaseRecoveryFeVar_New(  BASERECOVERYFEVAR_DEFARGS  ) 
-{
-	BaseRecoveryFeVar* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(BaseRecoveryFeVar) );
-	/* 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;
-	_interpolateValueAt         = _FeVariable_InterpolateValueAt;
-	_getMinGlobalFieldMagnitude = _FeVariable_GetMinGlobalFieldMagnitude;
-	_getMaxGlobalFieldMagnitude = _FeVariable_GetMaxGlobalFieldMagnitude;
-	_getMinAndMaxLocalCoords    = _FeVariable_GetMinAndMaxLocalCoords;
-	_getMinAndMaxGlobalCoords   = _FeVariable_GetMinAndMaxGlobalCoords;
-	_interpolateWithinElement   = _FeVariable_InterpolateNodeValuesToElLocalCoord;
-	_getValueAtNode             = _FeVariable_GetValueAtNode;
-	_syncShadowValues           = _FeVariable_SyncShadowValues;
-
-	self = (BaseRecoveryFeVar*)
-		_FeVariable_New(  FEVARIABLE_PASSARGS  );
-
-	self->_getCoeffAtNode = _BaseRecoveryFeVar_GetCoeffAtNode;
-	self->_interpolateWithinElement = NULL;
-
-	return self;
-}
-
-void _BaseRecoveryFeVar_Delete( void* _self ) {
-	BaseRecoveryFeVar* self = (BaseRecoveryFeVar*)_self;
-
-	_FeVariable_Delete( self );
-}
-  
-void _BaseRecoveryFeVar_Destroy( void* _self, void* data ) { 
-	BaseRecoveryFeVar* self = (BaseRecoveryFeVar*)_self;
-	Memory_Free( self->pVec );
-	Memory_Free( self->bninfo );
-
-	Stg_Component_Destroy( self->dataVariable, data, False );
-	Stg_Component_Destroy( self->dofLayout, data, False );
-	Stg_Component_Destroy( self->rawField, data, False );
-
-	_FeVariable_Destroy( _self, data ); 
-} 
-
-void _BaseRecoveryFeVar_Execute( void* _self, void* data ) { _FeVariable_Execute( _self, data ); }
-
-void _BaseRecoveryFeVar_Init(
-	BaseRecoveryFeVar*	self, 
-	Variable_Register*	vr, 
-	FeVariable*				rawField, 
-	int						rawOrderOfInterpolation,
-	Bool						coeffInterpolation )
-{
-
-   self->inc = IArray_New(); /* Must call here because this component never calls _FeVariable_Init */
-   self->vr = vr;
-   self->rawField = rawField;
-
-   /* record the rawField that is required on the repRequired_RawField register */
-   if( (unsigned)-1 == Stg_ObjectList_GetIndex( repRequiredRawFields_Reg, rawField->name ) )
-      Stg_ObjectList_Append( repRequiredRawFields_Reg, rawField ); 
-
-  /* we save the rawOrderOfInterpolation here and allow the instances of this class
-   * to change their orderOfInterpolation values individually in there Init */
-  self->orderOfInterpolation = rawOrderOfInterpolation;
-
-  /* set this components mesh to equal the rawField's mesh */
-  self->feMesh = rawField->feMesh;
-
-	/* set polynomial length: linear only available because we only use
-	 * linear elements and patches containing immdeiately adjacent elements only */
-	if( self->dim == 2 ) {
-		self->orderOfInterpolation = 3;
-		self->_makePoly = _BaseRecoveryFeVar_pVec_2Dorder1;
-	} else {
-		self->orderOfInterpolation = 4;
-		self->_makePoly = _BaseRecoveryFeVar_pVec_3Dorder1;
-	}
-
-	/* override FeVariable functions here */
-	self->_getValueAtNode = _BaseRecoveryFeVar_GetValueAtNode;
-
-	/* select interpolation technique */
-	if( coeffInterpolation ) 
-		self->_interpolateWithinElement = _BaseRecoveryFeVar_GetValueInElementWithCoeffInterpolation;
-	else
-		self->_interpolateWithinElement = _BaseRecoveryFeVar_GetValueInElementWithStdInterpolation;
-}
-
-void _BaseRecoveryFeVar_AssignFromXML( void* _self, Stg_ComponentFactory* cf, void* data ) {
-  BaseRecoveryFeVar*	self = (BaseRecoveryFeVar*) _self;
-  FeVariable*			rawField = NULL;
-  int						rawOrderOfInterpolation;
-  Bool					coeffInterpolation;
-  Variable_Register*	vr;
-
-  /* Construct FieldVariable, NOT FeVariable parent */
-  _FieldVariable_AssignFromXML( self, cf, data );
-
-  vr = self->context->variable_Register;
-
-  /* get the initial field */
-  rawField = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"RawField", FeVariable, True, data  ); 
-
-  /* get the order of interpolation */
-  rawOrderOfInterpolation = Stg_ComponentFactory_GetInt( cf, self->name , (Dictionary_Entry_Key)"orderOfInterpolation", 1  );
-
-  coeffInterpolation = Stg_ComponentFactory_GetBool( cf, self->name , (Dictionary_Entry_Key)"coeffInterpolation", True );
-
-  Journal_Firewall( (rawOrderOfInterpolation < 2  ) ,
-      Journal_Register( Error_Type, (Name)"BadNews"  ),
-      "Error in %s, the orderOfInterpolation must be: 1, higher order coefficients haven't been implemented. Currently it's %d\n"
-      "The larger the number the orderOfInterpolation:\n"
-      " * the more accurate the recoveredField\n"
-      " * the longer an iteration will take\n\n", __func__, rawOrderOfInterpolation );
-
-  _BaseRecoveryFeVar_Init( self, vr, rawField, rawOrderOfInterpolation, coeffInterpolation );
-}
-void _BaseRecoveryFeVar_Build( void* _self, void* data ) {
-  BaseRecoveryFeVar* self = (BaseRecoveryFeVar*) _self;
-	Sync*	               sync;
-	int                  componentsCount = 0;
-	int                  variable_I, node_I;
-	int                  *nodeDomainCountPtr = NULL;
-	char                 **variableName, *tmpName;
-	Variable*            dataVariable;
-	Variable_Register*	 variable_Register = self->vr;
-
-	Stg_Component_Build( self->feMesh, data, False );
-	/**** Create FeVariable to store the recovered field ****/
-
-	/* 1st Make sure rawField is built */
-	Stg_Component_Build( self->rawField, data, False );
-
-	/* 2nd create vector to store the repField */ 
-	componentsCount = self->orderOfInterpolation * self->fieldComponentCount;
-  /* create an variable names - create an extra variableName for the dofLayout */
-	variableName = Memory_Alloc_Array( char*, componentsCount * sizeof(char*) + 1, "names");
-	tmpName = Stg_Object_AppendSuffix( self, (Name)self->name  );
-
-  /* setup the sync and the nodeDomainCount */
-	sync = Mesh_GetSync( self->feMesh, MT_VERTEX );
-	assert( Class_IsSuper( self->feMesh->topo, IGraph ) );
-	nodeDomainCountPtr = &((IGraph*)self->feMesh->topo)->remotes[MT_VERTEX]->nDomains;
-	assert( componentsCount <= 100 );
-
-	for ( variable_I = 0 ; variable_I < componentsCount ; variable_I++ ) {
-		Stg_asprintf( &variableName[ variable_I ], "%s_%s-%d", self->type, self->name, variable_I );
-	}
-	Stg_asprintf( &variableName[ componentsCount ], "%s-dofLayout", self->name );
-	dataVariable = Variable_NewVector2( tmpName,
-												(AbstractContext*)self->context,
-												Variable_DataType_Double, 
-												componentsCount,
-												(unsigned*)&sync->nDomains, 
-												NULL, 
-												(void**)NULL,
-												variable_Register,
-                                            (const char**)variableName );
-
-	for( variable_I = 0; variable_I < dataVariable->dataTypeCounts[0]; variable_I++ )
-		dataVariable->components[variable_I]->allocateSelf = True;
-
-	dataVariable->allocateSelf = True;
-
-	/* 3rd create the dofLayout */
-	self->dofLayout = DofLayout_New( variableName[componentsCount], self->context, variable_Register, *nodeDomainCountPtr, self->feMesh );
-	for ( variable_I = 0 ; variable_I < componentsCount ; variable_I++ ) {
-
-			/* We have to set the array ptr ptr for these guys manually - this should be fixed */
-			Variable* variable = Variable_Register_GetByName( variable_Register, variableName[ variable_I ] );
-			variable->arrayPtrPtr = &dataVariable->arrayPtr;
-
-			/* Assign variable to each node */
-			for( node_I = 0; node_I < *nodeDomainCountPtr; node_I++ ) {
-				DofLayout_AddDof_ByVarName( self->dofLayout, variableName[variable_I], node_I );
-			}
-			/* Free Name */
-			Memory_Free( variableName[ variable_I ] );
-		}
-	
-	Stg_Component_Build( self->dofLayout, NULL, False );
-	Stg_Component_Initialise( self->dofLayout, NULL, False );
-
-	LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*) dataVariable );
-	LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*) self->dofLayout );
-
-   self->dataVariable = dataVariable;
-	/**** END building repField ****/
-
-  self->bninfo = Memory_Alloc_Array( BoundaryNodesInfo, 
-						      FeMesh_GetNodeDomainSize( self->feMesh ),
-						      "BoundaryNodesInfo" );
-}
-void _BaseRecoveryFeVar_Initialise( void* _self, void* data ) {
-	BaseRecoveryFeVar*      self = (BaseRecoveryFeVar*) _self;
-
-	/* Initialise parent */
-	_FieldVariable_Initialise( self, data );
-
-	/* Initialise class specific stuff */
-	Stg_Component_Initialise( self->rawField, data, False );
-	Stg_Component_Initialise( self->dofLayout, data, False );
-
-	self->pVec = Memory_Alloc_Array( double, self->orderOfInterpolation, "position polynomial" );
-  
-	/* BaseUtils_PopulateBoundaryNodesInfo should be called each timestep if AMR is used.
-	 * Here it's assumed the domain is not REMESHED after the it's created */
-	BaseUtils_PopulateBoundaryNodesInfo( self->rawField->feMesh, self->bninfo );
-}
-
-void _BaseRecoveryFeVar_Boundaries( void* _self ) {
-	BaseRecoveryFeVar* self         = (BaseRecoveryFeVar*)_self;
-	FeMesh*             feMesh   = self->feMesh;
-  BoundaryNodesInfo*  bninfo = self->bninfo;
-	Index               coeffCount, nPatches, nLocalNodes, coeff_I, node_I, patch_I, nbrNodeID;
-  double *coord, *nbrCoord, distance, weight; 
-  double numerator[50], denominator[50], coeff[50], nbrCoeff[50];
-
-  coeffCount = self->orderOfInterpolation * self->fieldComponentCount;
-  nLocalNodes = FeMesh_GetNodeLocalSize( self->rawField->feMesh );
-
-  for( node_I = 0 ; node_I < nLocalNodes ; node_I++ ) {
-    if( !bninfo[node_I].onMeshBoundary )
-      continue;
-    memset( numerator, 0, sizeof(double)*50 );
-    memset( denominator, 0, sizeof(double)*50 );
-    coord =  Mesh_GetVertex( feMesh , node_I );
-    nPatches = bninfo[node_I].numOfPatches2use;
-    /* go through nodes with patches that will contribute to this boundary node */
-    for( patch_I = 0 ; patch_I < nPatches; patch_I++ ) {
-      nbrNodeID = bninfo[node_I].patchNodes[patch_I];
-      nbrCoord = Mesh_GetVertex( feMesh, nbrNodeID );
-
-      /* weight the coefficients to be interpolated */
-      distance = StGermain_DistanceBetweenPoints( nbrCoord, coord , (self->dim) );
-      weight = 1/(distance*distance);
-      _BaseRecoveryFeVar_GetCoeffAtNode( self, nbrNodeID, nbrCoeff );
-
-      for( coeff_I = 0 ; coeff_I < coeffCount ; coeff_I++ ) {
-        numerator[coeff_I] += weight*nbrCoeff[coeff_I];
-        denominator[coeff_I] += weight;
-      }
-    }
-
-    for( coeff_I = 0 ; coeff_I < coeffCount ; coeff_I++ ) 
-      coeff[coeff_I] = numerator[coeff_I]/denominator[coeff_I];
-
-    /* set value at boundary node */
-    FeVariable_SetValueAtNode( self, node_I , coeff );
-  }
-}
-
-void _BaseRecoveryFeVar_GetCoeffAtNode( void* feVariable, Node_DomainIndex dNode_I, double* coeff ) {
-	/**** Get Coefficients ****/
-	BaseRecoveryFeVar* self = (BaseRecoveryFeVar*) feVariable;
-	Variable*	currVariable = NULL;
-	Dof_Index	dofCountThisNode = 0;
-	Dof_Index	nodeLocalDof_I;
-
-	dofCountThisNode = self->dofLayout->dofCounts[dNode_I];
-	
-	for ( nodeLocalDof_I=0; nodeLocalDof_I < dofCountThisNode; nodeLocalDof_I++ ) {
-		currVariable = DofLayout_GetVariable( self->dofLayout, dNode_I, nodeLocalDof_I );
-		coeff[ nodeLocalDof_I ] = Variable_GetValueDouble( currVariable, dNode_I );
-	}
-}
-
-void _BaseRecoveryFeVar_GetValueAtNode( void* feVariable, Node_DomainIndex dNode_I, double* value ) {
-	BaseRecoveryFeVar* self = (BaseRecoveryFeVar*) feVariable;
-	int dof_I, order, dofThatExist;
-	double coeff[50];
-	double *ptr = coeff;
-	double *coord;
-
-	/**** Get Coefficients ****/
-	Variable*	currVariable = NULL;
-	Dof_Index	dofCountThisNode = 0;
-	Dof_Index	nodeLocalDof_I;
-
-	dofCountThisNode = self->dofLayout->dofCounts[dNode_I];
-	
-	for ( nodeLocalDof_I=0; nodeLocalDof_I < dofCountThisNode; nodeLocalDof_I++ ) {
-		currVariable = DofLayout_GetVariable( self->dofLayout, dNode_I, nodeLocalDof_I );
-		ptr[ nodeLocalDof_I ] = Variable_GetValueDouble( currVariable, dNode_I );
-	}
-
-	/**** Apply Coefficients ****/
-	order = self->orderOfInterpolation;
-	dofThatExist = self->fieldComponentCount;
-	coord = Mesh_GetVertex( self->feMesh , dNode_I );
-
-	for( dof_I = 0 ; dof_I < dofThatExist ; dof_I++ ) 
-			value[dof_I] = _BaseRecoveryFeVar_ApplyCoeff( self, &(coeff[dof_I*order]), coord, order, self->pVec );
-}
-
-void _BaseRecoveryFeVar_GetValueInElementWithStdInterpolation( void* feVariable, Element_Index lEl_I, double* xi, double* value ) {
-	BaseRecoveryFeVar  *self = (BaseRecoveryFeVar*) feVariable;
-	FeMesh             *mesh = self->feMesh;
-	ElementType        *elementType = NULL;
-	IArray*            inc  = self->inc;
-	double             valueAtNode[8][9];  /* TODO: make non static */
-	double             Ni[8]; 
-	int nNodes, *nodes, node_I, order, dof_I, dofThatExist;
-
-	order = self->orderOfInterpolation;
-	dofThatExist = self->fieldComponentCount;
-
-	/* Get nodes in element lEl_I */
-	FeMesh_GetElementNodes( mesh, lEl_I, self->inc );
-	nNodes = IArray_GetSize( inc );
-	nodes = IArray_GetPtr( inc );
-
-	/* Calculate shapefunction for interpolation */
-	elementType = FeMesh_GetElementType( mesh, lEl_I );
-	ElementType_EvaluateShapeFunctionsAt( elementType, xi, Ni );
-
-	/* zero the value vector */
-	memset( value, 0, sizeof(double)*dofThatExist );
-
-	/* Get value of self an the nodes and store in valueAtNode */ 
-	for( node_I = 0 ; node_I < nNodes ; node_I++ ) {
-		_BaseRecoveryFeVar_GetValueAtNode( self, nodes[ node_I ], valueAtNode[ node_I ] );
-		/* Interpolate valueAtNode to xi manually */
-		for( dof_I = 0 ; dof_I < dofThatExist ; dof_I++ ) {
-				value[dof_I] += Ni[node_I]*valueAtNode[node_I][dof_I];
-		}
-	}
-}
-
-void _BaseRecoveryFeVar_GetValueInElementWithCoeffInterpolation( void* feVariable, Element_Index lEl_I, double* xi, double* value ) {
-	BaseRecoveryFeVar* self = (BaseRecoveryFeVar*) feVariable;
-	FeMesh*              mesh = self->feMesh;
-	IArray*              inc  = self->inc;
-	double               globalCoord[3];
-	double               coeff[50]; 
-	int nNodes, *nodes, order, dof_I, dofThatExist;
-
-	order = self->orderOfInterpolation;
-	dofThatExist = self->fieldComponentCount;
-	FeMesh_CoordLocalToGlobal( mesh, lEl_I, xi, globalCoord );
-
-	/* Get nodes in element lEl_I */
-	FeMesh_GetElementNodes( mesh, lEl_I, self->inc );
-	nNodes = IArray_GetSize( inc );
-	nodes = IArray_GetPtr( inc );
-
-	/** Get the coeffieients of each node **/
-	_FeVariable_InterpolateNodeValuesToElLocalCoord( self, lEl_I, xi, coeff );
-
-	for( dof_I = 0 ; dof_I < dofThatExist ; dof_I++ ) 
-			value[dof_I] = _BaseRecoveryFeVar_ApplyCoeff( self, &(coeff[dof_I*order]), globalCoord, order, self->pVec );
-}
-
-double _BaseRecoveryFeVar_ApplyCoeff( BaseRecoveryFeVar* self, double* coeff, double* coord, int order, double* pVec ) {
-	double value = 0;
-	int order_I;
-
-	self->_makePoly( coord, pVec );
-	for( order_I = 0 ; order_I < order ; order_I++ ) 
-		value += coeff[order_I] * pVec[order_I];
-
-	return value;
-}
-
-void BaseUtils_Add2LmStruct( LmStruct* lmStruct, Index nodeID ) {
-	int count_I;
-	for( count_I = 0 ; count_I < lmStruct->numberOfNodes ; count_I++ ) {
-		/* To prevent duplication in the list*/
-		if( lmStruct->nodeIDList[count_I] == nodeID )
-			return;
-	}
-	lmStruct->nodeIDList[ lmStruct->numberOfNodes ] = nodeID;
-	lmStruct->numberOfNodes++;
-}
-
-void BaseUtils_PopulateBoundaryNodesInfo( FeMesh* mesh, BoundaryNodesInfo* bninfo ) {
-/* Function Description:
- * Populates a mesh-related data structure, called self->boundaryNodeInfo.
- * An array of size n, where n is the number of DOMAIN nodes. 
- * each element contain:
- * Bool onMeshBoundary   ... is node on the Mesh boundary
- * int  numOfPatches2use ... number of Patches which will contribute to node
- *  This will aid the patch algorithms, which needs to know if a node
- *  is on the domain boundary or not (i.e. does not have a full set of valid adjacent elements).
- *  Algorithm to assign onBoundary is
- *  To go through each node
- *  	set onBoundary = false
- *  	check if a single neighbour element is invalid (thus outside the domain)
- *  		if so, set onBoundary = true 
- * 
- */
-	Node_Index              dNodes_I, tmpNodeID, tmpNode_I;
-	Element_Index           nbrElementID, nbrElement_I;
-	int                     nEls, *els;
-	int                     nNodes, *nodes;
-	LmStruct                list;
-	Sync*                   sync;
-	int                     domainNodes;
-	int                     nLocalNodes;
-	int                     nVerts;
-  const int               *verts;
-	IArray*			            inc[2];
-
-	sync = Mesh_GetSync( mesh, MT_VERTEX );
-	IGraph_GetBoundaryElements( mesh->topo, MT_VERTEX, &nVerts, &verts );
-	nLocalNodes = FeMesh_GetNodeLocalSize( mesh );
-	domainNodes = FeMesh_GetNodeDomainSize( mesh );
-
-	assert( nVerts <= domainNodes );
-
-  /* initialise boundaryNodesInfo data structure:
-   * for all nodes
-   * onMeshBoundary = false,
-   * numOfPatches2use = 0
-   * patchNodes list = [-1,-1,-1,....,-1]
-   * */
-	for( dNodes_I = 0 ; dNodes_I < domainNodes ; dNodes_I++ ) {
-		bninfo[dNodes_I].onMeshBoundary = False;
-		bninfo[dNodes_I].numOfPatches2use = 0;
-		memset( bninfo[dNodes_I].patchNodes, -1, sizeof(int)*REP_MAXNODESPERPATCH );
-	}
-
-	/* First flag boundary nodes */
-	for( dNodes_I = 0 ; dNodes_I < nVerts ; dNodes_I++ )
-	       bninfo[verts[dNodes_I]].onMeshBoundary = True;
-
-	/* Update all other procs. */
-    /* Argument Describtion:
-     * 1) start of local address
-     * 2) size of chunk in array
-     * 3) location and size of local information in array
-     * 4) size of chunk to send???
-     * 5) size of chunk to receive??
-     */
-	Sync_SyncArray( sync, bninfo, sizeof(BoundaryNodesInfo), 
-			bninfo + nLocalNodes , sizeof(BoundaryNodesInfo), 
-			sizeof(BoundaryNodesInfo) );	
-
-	/* Now calculate the numOfPatches2use for each onMeshBoundary node
-	 * If node is on boundary, find how many patches will contribute to recovery at that location
-	 * 	 ONLY LOOP OVER LOCAL NODES HERE
-	 */
-	inc[0] = IArray_New();
-	inc[1] = IArray_New();
-	for( dNodes_I = 0 ; dNodes_I < FeMesh_GetNodeDomainSize( mesh ) ; dNodes_I++ ) {
-		if( !bninfo[dNodes_I].onMeshBoundary ) 
-			continue;
-
-		list.numberOfNodes = 0;
-				
-		/* Go through all neighbour elements */
-		FeMesh_GetNodeElements( mesh, dNodes_I, inc[0] );
-		nEls = IArray_GetSize( inc[0] );
-		els = IArray_GetPtr( inc[0] );
-
-		for( nbrElement_I = 0 ; nbrElement_I < nEls ; nbrElement_I++) {
-			nbrElementID = els[nbrElement_I];
-			/* Go through nodes on elements and see if they're valid patchs */
-			FeMesh_GetElementNodes( mesh, nbrElementID, inc[1] );
-			nNodes = IArray_GetSize( inc[1] );
-			nodes = IArray_GetPtr( inc[1] );
-
-			for( tmpNode_I = 0 ; tmpNode_I < nNodes ; tmpNode_I++ ) {
-				tmpNodeID = nodes[tmpNode_I];
-				if( !bninfo[tmpNodeID].onMeshBoundary ) 
-					BaseUtils_Add2LmStruct( &list, tmpNodeID );
-			}
-		}
-		bninfo[dNodes_I].numOfPatches2use = list.numberOfNodes;
-		assert( list.numberOfNodes < 20 ); /* TODO: not pretty */
-		memcpy( bninfo[dNodes_I].patchNodes, list.nodeIDList, list.numberOfNodes*sizeof(int) );
-	}
-	NewClass_Delete( inc[0] );
-	NewClass_Delete( inc[1] );
-}
-
-
-void _BaseRecoveryFeVar_pVec_2Dorder1( double *global, double *pVec ) {
-	pVec[0] = 1;
-	pVec[1] = global[0];
-	pVec[2] = global[1];
-}
-
-void _BaseRecoveryFeVar_pVec_3Dorder1( double *global, double *pVec ) {
-	pVec[0] = 1;
-	pVec[1] = global[0];
-	pVec[2] = global[1];
-	pVec[3] = global[2];
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/BaseRecoveryFeVar.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/BaseRecoveryFeVar.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,514 @@
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include "Underworld/Rheology/Rheology.h"
+
+#include "types.h"
+#include "BaseRecoveryFeVar.h"
+
+#include <math.h>
+#include <assert.h>
+#include <string.h>
+
+const Type BaseRecoveryFeVar_Type = "BaseRecoveryFeVar";
+
+void* _BaseRecoveryFeVar_DefaultNew( Name name ) {
+  /* this is an abstract call so this function should never be called */
+	assert(0);
+}
+BaseRecoveryFeVar* _BaseRecoveryFeVar_New(  BASERECOVERYFEVAR_DEFARGS  ) 
+{
+	BaseRecoveryFeVar* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(BaseRecoveryFeVar) );
+	/* 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;
+	_interpolateValueAt         = _FeVariable_InterpolateValueAt;
+	_getMinGlobalFieldMagnitude = _FeVariable_GetMinGlobalFieldMagnitude;
+	_getMaxGlobalFieldMagnitude = _FeVariable_GetMaxGlobalFieldMagnitude;
+	_getMinAndMaxLocalCoords    = _FeVariable_GetMinAndMaxLocalCoords;
+	_getMinAndMaxGlobalCoords   = _FeVariable_GetMinAndMaxGlobalCoords;
+	_interpolateWithinElement   = _FeVariable_InterpolateNodeValuesToElLocalCoord;
+	_getValueAtNode             = _FeVariable_GetValueAtNode;
+	_syncShadowValues           = _FeVariable_SyncShadowValues;
+
+	self = (BaseRecoveryFeVar*)
+		_FeVariable_New(  FEVARIABLE_PASSARGS  );
+
+	self->_getCoeffAtNode = _BaseRecoveryFeVar_GetCoeffAtNode;
+	self->_interpolateWithinElement = NULL;
+
+	return self;
+}
+
+void _BaseRecoveryFeVar_Delete( void* _self ) {
+	BaseRecoveryFeVar* self = (BaseRecoveryFeVar*)_self;
+
+	_FeVariable_Delete( self );
+}
+  
+void _BaseRecoveryFeVar_Destroy( void* _self, void* data ) { 
+	BaseRecoveryFeVar* self = (BaseRecoveryFeVar*)_self;
+	Memory_Free( self->pVec );
+	Memory_Free( self->bninfo );
+
+	Stg_Component_Destroy( self->dataVariable, data, False );
+	Stg_Component_Destroy( self->dofLayout, data, False );
+	Stg_Component_Destroy( self->rawField, data, False );
+
+	_FeVariable_Destroy( _self, data ); 
+} 
+
+void _BaseRecoveryFeVar_Execute( void* _self, void* data ) { _FeVariable_Execute( _self, data ); }
+
+void _BaseRecoveryFeVar_Init(
+	BaseRecoveryFeVar*	self, 
+	Variable_Register*	vr, 
+	FeVariable*				rawField, 
+	int						rawOrderOfInterpolation,
+	Bool						coeffInterpolation )
+{
+
+   self->inc = IArray_New(); /* Must call here because this component never calls _FeVariable_Init */
+   self->vr = vr;
+   self->rawField = rawField;
+
+   /* record the rawField that is required on the repRequired_RawField register */
+   if( (unsigned)-1 == Stg_ObjectList_GetIndex( repRequiredRawFields_Reg, rawField->name ) )
+      Stg_ObjectList_Append( repRequiredRawFields_Reg, rawField ); 
+
+  /* we save the rawOrderOfInterpolation here and allow the instances of this class
+   * to change their orderOfInterpolation values individually in there Init */
+  self->orderOfInterpolation = rawOrderOfInterpolation;
+
+  /* set this components mesh to equal the rawField's mesh */
+  self->feMesh = rawField->feMesh;
+
+	/* set polynomial length: linear only available because we only use
+	 * linear elements and patches containing immdeiately adjacent elements only */
+	if( self->dim == 2 ) {
+		self->orderOfInterpolation = 3;
+		self->_makePoly = _BaseRecoveryFeVar_pVec_2Dorder1;
+	} else {
+		self->orderOfInterpolation = 4;
+		self->_makePoly = _BaseRecoveryFeVar_pVec_3Dorder1;
+	}
+
+	/* override FeVariable functions here */
+	self->_getValueAtNode = _BaseRecoveryFeVar_GetValueAtNode;
+
+	/* select interpolation technique */
+	if( coeffInterpolation ) 
+		self->_interpolateWithinElement = _BaseRecoveryFeVar_GetValueInElementWithCoeffInterpolation;
+	else
+		self->_interpolateWithinElement = _BaseRecoveryFeVar_GetValueInElementWithStdInterpolation;
+}
+
+void _BaseRecoveryFeVar_AssignFromXML( void* _self, Stg_ComponentFactory* cf, void* data ) {
+  BaseRecoveryFeVar*	self = (BaseRecoveryFeVar*) _self;
+  FeVariable*			rawField = NULL;
+  int						rawOrderOfInterpolation;
+  Bool					coeffInterpolation;
+  Variable_Register*	vr;
+
+  /* Construct FieldVariable, NOT FeVariable parent */
+  _FieldVariable_AssignFromXML( self, cf, data );
+
+  vr = self->context->variable_Register;
+
+  /* get the initial field */
+  rawField = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"RawField", FeVariable, True, data  ); 
+
+  /* get the order of interpolation */
+  rawOrderOfInterpolation = Stg_ComponentFactory_GetInt( cf, self->name , (Dictionary_Entry_Key)"orderOfInterpolation", 1  );
+
+  coeffInterpolation = Stg_ComponentFactory_GetBool( cf, self->name , (Dictionary_Entry_Key)"coeffInterpolation", True );
+
+  Journal_Firewall( (rawOrderOfInterpolation < 2  ) ,
+      Journal_Register( Error_Type, (Name)"BadNews"  ),
+      "Error in %s, the orderOfInterpolation must be: 1, higher order coefficients haven't been implemented. Currently it's %d\n"
+      "The larger the number the orderOfInterpolation:\n"
+      " * the more accurate the recoveredField\n"
+      " * the longer an iteration will take\n\n", __func__, rawOrderOfInterpolation );
+
+  _BaseRecoveryFeVar_Init( self, vr, rawField, rawOrderOfInterpolation, coeffInterpolation );
+}
+void _BaseRecoveryFeVar_Build( void* _self, void* data ) {
+  BaseRecoveryFeVar* self = (BaseRecoveryFeVar*) _self;
+	Sync*	               sync;
+	int                  componentsCount = 0;
+	int                  variable_I, node_I;
+	int                  *nodeDomainCountPtr = NULL;
+	char                 **variableName, *tmpName;
+	Variable*            dataVariable;
+	Variable_Register*	 variable_Register = self->vr;
+
+	Stg_Component_Build( self->feMesh, data, False );
+	/**** Create FeVariable to store the recovered field ****/
+
+	/* 1st Make sure rawField is built */
+	Stg_Component_Build( self->rawField, data, False );
+
+	/* 2nd create vector to store the repField */ 
+	componentsCount = self->orderOfInterpolation * self->fieldComponentCount;
+  /* create an variable names - create an extra variableName for the dofLayout */
+	variableName = Memory_Alloc_Array( char*, componentsCount * sizeof(char*) + 1, "names");
+	tmpName = Stg_Object_AppendSuffix( self, (Name)self->name  );
+
+  /* setup the sync and the nodeDomainCount */
+	sync = Mesh_GetSync( self->feMesh, MT_VERTEX );
+	assert( Class_IsSuper( self->feMesh->topo, IGraph ) );
+	nodeDomainCountPtr = &((IGraph*)self->feMesh->topo)->remotes[MT_VERTEX]->nDomains;
+	assert( componentsCount <= 100 );
+
+	for ( variable_I = 0 ; variable_I < componentsCount ; variable_I++ ) {
+		Stg_asprintf( &variableName[ variable_I ], "%s_%s-%d", self->type, self->name, variable_I );
+	}
+	Stg_asprintf( &variableName[ componentsCount ], "%s-dofLayout", self->name );
+	dataVariable = Variable_NewVector2( tmpName,
+												(AbstractContext*)self->context,
+												Variable_DataType_Double, 
+												componentsCount,
+												(unsigned*)&sync->nDomains, 
+												NULL, 
+												(void**)NULL,
+												variable_Register,
+                                            (const char**)variableName );
+
+	for( variable_I = 0; variable_I < dataVariable->dataTypeCounts[0]; variable_I++ )
+		dataVariable->components[variable_I]->allocateSelf = True;
+
+	dataVariable->allocateSelf = True;
+
+	/* 3rd create the dofLayout */
+	self->dofLayout = DofLayout_New( variableName[componentsCount], self->context, variable_Register, *nodeDomainCountPtr, self->feMesh );
+	for ( variable_I = 0 ; variable_I < componentsCount ; variable_I++ ) {
+
+			/* We have to set the array ptr ptr for these guys manually - this should be fixed */
+			Variable* variable = Variable_Register_GetByName( variable_Register, variableName[ variable_I ] );
+			variable->arrayPtrPtr = &dataVariable->arrayPtr;
+
+			/* Assign variable to each node */
+			for( node_I = 0; node_I < *nodeDomainCountPtr; node_I++ ) {
+				DofLayout_AddDof_ByVarName( self->dofLayout, variableName[variable_I], node_I );
+			}
+			/* Free Name */
+			Memory_Free( variableName[ variable_I ] );
+		}
+	
+	Stg_Component_Build( self->dofLayout, NULL, False );
+	Stg_Component_Initialise( self->dofLayout, NULL, False );
+
+	LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*) dataVariable );
+	LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*) self->dofLayout );
+
+   self->dataVariable = dataVariable;
+	/**** END building repField ****/
+
+  self->bninfo = Memory_Alloc_Array( BoundaryNodesInfo, 
+						      FeMesh_GetNodeDomainSize( self->feMesh ),
+						      "BoundaryNodesInfo" );
+}
+void _BaseRecoveryFeVar_Initialise( void* _self, void* data ) {
+	BaseRecoveryFeVar*      self = (BaseRecoveryFeVar*) _self;
+
+	/* Initialise parent */
+	_FieldVariable_Initialise( self, data );
+
+	/* Initialise class specific stuff */
+	Stg_Component_Initialise( self->rawField, data, False );
+	Stg_Component_Initialise( self->dofLayout, data, False );
+
+	self->pVec = Memory_Alloc_Array( double, self->orderOfInterpolation, "position polynomial" );
+  
+	/* BaseUtils_PopulateBoundaryNodesInfo should be called each timestep if AMR is used.
+	 * Here it's assumed the domain is not REMESHED after the it's created */
+	BaseUtils_PopulateBoundaryNodesInfo( self->rawField->feMesh, self->bninfo );
+}
+
+void _BaseRecoveryFeVar_Boundaries( void* _self ) {
+	BaseRecoveryFeVar* self         = (BaseRecoveryFeVar*)_self;
+	FeMesh*             feMesh   = self->feMesh;
+  BoundaryNodesInfo*  bninfo = self->bninfo;
+	Index               coeffCount, nPatches, nLocalNodes, coeff_I, node_I, patch_I, nbrNodeID;
+  double *coord, *nbrCoord, distance, weight; 
+  double numerator[50], denominator[50], coeff[50], nbrCoeff[50];
+
+  coeffCount = self->orderOfInterpolation * self->fieldComponentCount;
+  nLocalNodes = FeMesh_GetNodeLocalSize( self->rawField->feMesh );
+
+  for( node_I = 0 ; node_I < nLocalNodes ; node_I++ ) {
+    if( !bninfo[node_I].onMeshBoundary )
+      continue;
+    memset( numerator, 0, sizeof(double)*50 );
+    memset( denominator, 0, sizeof(double)*50 );
+    coord =  Mesh_GetVertex( feMesh , node_I );
+    nPatches = bninfo[node_I].numOfPatches2use;
+    /* go through nodes with patches that will contribute to this boundary node */
+    for( patch_I = 0 ; patch_I < nPatches; patch_I++ ) {
+      nbrNodeID = bninfo[node_I].patchNodes[patch_I];
+      nbrCoord = Mesh_GetVertex( feMesh, nbrNodeID );
+
+      /* weight the coefficients to be interpolated */
+      distance = StGermain_DistanceBetweenPoints( nbrCoord, coord , (self->dim) );
+      weight = 1/(distance*distance);
+      _BaseRecoveryFeVar_GetCoeffAtNode( self, nbrNodeID, nbrCoeff );
+
+      for( coeff_I = 0 ; coeff_I < coeffCount ; coeff_I++ ) {
+        numerator[coeff_I] += weight*nbrCoeff[coeff_I];
+        denominator[coeff_I] += weight;
+      }
+    }
+
+    for( coeff_I = 0 ; coeff_I < coeffCount ; coeff_I++ ) 
+      coeff[coeff_I] = numerator[coeff_I]/denominator[coeff_I];
+
+    /* set value at boundary node */
+    FeVariable_SetValueAtNode( self, node_I , coeff );
+  }
+}
+
+void _BaseRecoveryFeVar_GetCoeffAtNode( void* feVariable, Node_DomainIndex dNode_I, double* coeff ) {
+	/**** Get Coefficients ****/
+	BaseRecoveryFeVar* self = (BaseRecoveryFeVar*) feVariable;
+	Variable*	currVariable = NULL;
+	Dof_Index	dofCountThisNode = 0;
+	Dof_Index	nodeLocalDof_I;
+
+	dofCountThisNode = self->dofLayout->dofCounts[dNode_I];
+	
+	for ( nodeLocalDof_I=0; nodeLocalDof_I < dofCountThisNode; nodeLocalDof_I++ ) {
+		currVariable = DofLayout_GetVariable( self->dofLayout, dNode_I, nodeLocalDof_I );
+		coeff[ nodeLocalDof_I ] = Variable_GetValueDouble( currVariable, dNode_I );
+	}
+}
+
+void _BaseRecoveryFeVar_GetValueAtNode( void* feVariable, Node_DomainIndex dNode_I, double* value ) {
+	BaseRecoveryFeVar* self = (BaseRecoveryFeVar*) feVariable;
+	int dof_I, order, dofThatExist;
+	double coeff[50];
+	double *ptr = coeff;
+	double *coord;
+
+	/**** Get Coefficients ****/
+	Variable*	currVariable = NULL;
+	Dof_Index	dofCountThisNode = 0;
+	Dof_Index	nodeLocalDof_I;
+
+	dofCountThisNode = self->dofLayout->dofCounts[dNode_I];
+	
+	for ( nodeLocalDof_I=0; nodeLocalDof_I < dofCountThisNode; nodeLocalDof_I++ ) {
+		currVariable = DofLayout_GetVariable( self->dofLayout, dNode_I, nodeLocalDof_I );
+		ptr[ nodeLocalDof_I ] = Variable_GetValueDouble( currVariable, dNode_I );
+	}
+
+	/**** Apply Coefficients ****/
+	order = self->orderOfInterpolation;
+	dofThatExist = self->fieldComponentCount;
+	coord = Mesh_GetVertex( self->feMesh , dNode_I );
+
+	for( dof_I = 0 ; dof_I < dofThatExist ; dof_I++ ) 
+			value[dof_I] = _BaseRecoveryFeVar_ApplyCoeff( self, &(coeff[dof_I*order]), coord, order, self->pVec );
+}
+
+void _BaseRecoveryFeVar_GetValueInElementWithStdInterpolation( void* feVariable, Element_Index lEl_I, double* xi, double* value ) {
+	BaseRecoveryFeVar  *self = (BaseRecoveryFeVar*) feVariable;
+	FeMesh             *mesh = self->feMesh;
+	ElementType        *elementType = NULL;
+	IArray*            inc  = self->inc;
+	double             valueAtNode[8][9];  /* TODO: make non static */
+	double             Ni[8]; 
+	int nNodes, *nodes, node_I, order, dof_I, dofThatExist;
+
+	order = self->orderOfInterpolation;
+	dofThatExist = self->fieldComponentCount;
+
+	/* Get nodes in element lEl_I */
+	FeMesh_GetElementNodes( mesh, lEl_I, self->inc );
+	nNodes = IArray_GetSize( inc );
+	nodes = IArray_GetPtr( inc );
+
+	/* Calculate shapefunction for interpolation */
+	elementType = FeMesh_GetElementType( mesh, lEl_I );
+	ElementType_EvaluateShapeFunctionsAt( elementType, xi, Ni );
+
+	/* zero the value vector */
+	memset( value, 0, sizeof(double)*dofThatExist );
+
+	/* Get value of self an the nodes and store in valueAtNode */ 
+	for( node_I = 0 ; node_I < nNodes ; node_I++ ) {
+		_BaseRecoveryFeVar_GetValueAtNode( self, nodes[ node_I ], valueAtNode[ node_I ] );
+		/* Interpolate valueAtNode to xi manually */
+		for( dof_I = 0 ; dof_I < dofThatExist ; dof_I++ ) {
+				value[dof_I] += Ni[node_I]*valueAtNode[node_I][dof_I];
+		}
+	}
+}
+
+void _BaseRecoveryFeVar_GetValueInElementWithCoeffInterpolation( void* feVariable, Element_Index lEl_I, double* xi, double* value ) {
+	BaseRecoveryFeVar* self = (BaseRecoveryFeVar*) feVariable;
+	FeMesh*              mesh = self->feMesh;
+	IArray*              inc  = self->inc;
+	double               globalCoord[3];
+	double               coeff[50]; 
+	int nNodes, *nodes, order, dof_I, dofThatExist;
+
+	order = self->orderOfInterpolation;
+	dofThatExist = self->fieldComponentCount;
+	FeMesh_CoordLocalToGlobal( mesh, lEl_I, xi, globalCoord );
+
+	/* Get nodes in element lEl_I */
+	FeMesh_GetElementNodes( mesh, lEl_I, self->inc );
+	nNodes = IArray_GetSize( inc );
+	nodes = IArray_GetPtr( inc );
+
+	/** Get the coeffieients of each node **/
+	_FeVariable_InterpolateNodeValuesToElLocalCoord( self, lEl_I, xi, coeff );
+
+	for( dof_I = 0 ; dof_I < dofThatExist ; dof_I++ ) 
+			value[dof_I] = _BaseRecoveryFeVar_ApplyCoeff( self, &(coeff[dof_I*order]), globalCoord, order, self->pVec );
+}
+
+double _BaseRecoveryFeVar_ApplyCoeff( BaseRecoveryFeVar* self, double* coeff, double* coord, int order, double* pVec ) {
+	double value = 0;
+	int order_I;
+
+	self->_makePoly( coord, pVec );
+	for( order_I = 0 ; order_I < order ; order_I++ ) 
+		value += coeff[order_I] * pVec[order_I];
+
+	return value;
+}
+
+void BaseUtils_Add2LmStruct( LmStruct* lmStruct, Index nodeID ) {
+	int count_I;
+	for( count_I = 0 ; count_I < lmStruct->numberOfNodes ; count_I++ ) {
+		/* To prevent duplication in the list*/
+		if( lmStruct->nodeIDList[count_I] == nodeID )
+			return;
+	}
+	lmStruct->nodeIDList[ lmStruct->numberOfNodes ] = nodeID;
+	lmStruct->numberOfNodes++;
+}
+
+void BaseUtils_PopulateBoundaryNodesInfo( FeMesh* mesh, BoundaryNodesInfo* bninfo ) {
+/* Function Description:
+ * Populates a mesh-related data structure, called self->boundaryNodeInfo.
+ * An array of size n, where n is the number of DOMAIN nodes. 
+ * each element contain:
+ * Bool onMeshBoundary   ... is node on the Mesh boundary
+ * int  numOfPatches2use ... number of Patches which will contribute to node
+ *  This will aid the patch algorithms, which needs to know if a node
+ *  is on the domain boundary or not (i.e. does not have a full set of valid adjacent elements).
+ *  Algorithm to assign onBoundary is
+ *  To go through each node
+ *  	set onBoundary = false
+ *  	check if a single neighbour element is invalid (thus outside the domain)
+ *  		if so, set onBoundary = true 
+ * 
+ */
+	Node_Index              dNodes_I, tmpNodeID, tmpNode_I;
+	Element_Index           nbrElementID, nbrElement_I;
+	int                     nEls, *els;
+	int                     nNodes, *nodes;
+	LmStruct                list;
+	Sync*                   sync;
+	int                     domainNodes;
+	int                     nLocalNodes;
+	int                     nVerts;
+  const int               *verts;
+	IArray*			            inc[2];
+
+	sync = Mesh_GetSync( mesh, MT_VERTEX );
+	IGraph_GetBoundaryElements( mesh->topo, MT_VERTEX, &nVerts, &verts );
+	nLocalNodes = FeMesh_GetNodeLocalSize( mesh );
+	domainNodes = FeMesh_GetNodeDomainSize( mesh );
+
+	assert( nVerts <= domainNodes );
+
+  /* initialise boundaryNodesInfo data structure:
+   * for all nodes
+   * onMeshBoundary = false,
+   * numOfPatches2use = 0
+   * patchNodes list = [-1,-1,-1,....,-1]
+   * */
+	for( dNodes_I = 0 ; dNodes_I < domainNodes ; dNodes_I++ ) {
+		bninfo[dNodes_I].onMeshBoundary = False;
+		bninfo[dNodes_I].numOfPatches2use = 0;
+		memset( bninfo[dNodes_I].patchNodes, -1, sizeof(int)*REP_MAXNODESPERPATCH );
+	}
+
+	/* First flag boundary nodes */
+	for( dNodes_I = 0 ; dNodes_I < nVerts ; dNodes_I++ )
+	       bninfo[verts[dNodes_I]].onMeshBoundary = True;
+
+	/* Update all other procs. */
+    /* Argument Describtion:
+     * 1) start of local address
+     * 2) size of chunk in array
+     * 3) location and size of local information in array
+     * 4) size of chunk to send???
+     * 5) size of chunk to receive??
+     */
+	Sync_SyncArray( sync, bninfo, sizeof(BoundaryNodesInfo), 
+			bninfo + nLocalNodes , sizeof(BoundaryNodesInfo), 
+			sizeof(BoundaryNodesInfo) );	
+
+	/* Now calculate the numOfPatches2use for each onMeshBoundary node
+	 * If node is on boundary, find how many patches will contribute to recovery at that location
+	 * 	 ONLY LOOP OVER LOCAL NODES HERE
+	 */
+	inc[0] = IArray_New();
+	inc[1] = IArray_New();
+	for( dNodes_I = 0 ; dNodes_I < FeMesh_GetNodeDomainSize( mesh ) ; dNodes_I++ ) {
+		if( !bninfo[dNodes_I].onMeshBoundary ) 
+			continue;
+
+		list.numberOfNodes = 0;
+				
+		/* Go through all neighbour elements */
+		FeMesh_GetNodeElements( mesh, dNodes_I, inc[0] );
+		nEls = IArray_GetSize( inc[0] );
+		els = IArray_GetPtr( inc[0] );
+
+		for( nbrElement_I = 0 ; nbrElement_I < nEls ; nbrElement_I++) {
+			nbrElementID = els[nbrElement_I];
+			/* Go through nodes on elements and see if they're valid patchs */
+			FeMesh_GetElementNodes( mesh, nbrElementID, inc[1] );
+			nNodes = IArray_GetSize( inc[1] );
+			nodes = IArray_GetPtr( inc[1] );
+
+			for( tmpNode_I = 0 ; tmpNode_I < nNodes ; tmpNode_I++ ) {
+				tmpNodeID = nodes[tmpNode_I];
+				if( !bninfo[tmpNodeID].onMeshBoundary ) 
+					BaseUtils_Add2LmStruct( &list, tmpNodeID );
+			}
+		}
+		bninfo[dNodes_I].numOfPatches2use = list.numberOfNodes;
+		assert( list.numberOfNodes < 20 ); /* TODO: not pretty */
+		memcpy( bninfo[dNodes_I].patchNodes, list.nodeIDList, list.numberOfNodes*sizeof(int) );
+	}
+	NewClass_Delete( inc[0] );
+	NewClass_Delete( inc[1] );
+}
+
+
+void _BaseRecoveryFeVar_pVec_2Dorder1( double *global, double *pVec ) {
+	pVec[0] = 1;
+	pVec[1] = global[0];
+	pVec[2] = global[1];
+}
+
+void _BaseRecoveryFeVar_pVec_3Dorder1( double *global, double *pVec ) {
+	pVec[0] = 1;
+	pVec[1] = global[0];
+	pVec[2] = global[1];
+	pVec[3] = global[2];
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/DensityField.c
--- a/Utils/src/DensityField.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,177 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Monash Cluster Computing, Australia
-** (C) 2003-2004 All Rights Reserved
-**
-** Primary Authors:
-** Robert Turnbull, MCC
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include <Underworld/Rheology/Rheology.h>
-
-#include "types.h"
-#include "DensityField.h"
-#include <assert.h>
-
-const Type DensityField_Type = "DensityField";
-
-DensityField* _DensityField_New(  DENSITYFIELD_DEFARGS  ) {
-	DensityField* self;
-	
-	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree.
-	At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-	assert( _sizeOfSelf >= sizeof(DensityField) );
-	self = (DensityField*) _ParticleFeVariable_New(  PARTICLEFEVARIABLE_PASSARGS  );
-	
-	return self;
-}
-
-void _DensityField_Init( DensityField* self, BuoyancyForceTerm* buoyancyForceTerm, Variable_Register* variable_Register ) {
-	/* Assign Pointers */
-	self->buoyancyForceTerm = buoyancyForceTerm;
-	self->variable_Register = variable_Register;
-	
-	/* Set pointers to swarm to be the same as the one on the constitutive matrix */
-	self->assemblyTerm->integrationSwarm = self->buoyancyForceTerm->integrationSwarm;
-	self->massMatrixForceTerm->integrationSwarm = self->buoyancyForceTerm->integrationSwarm;	
-}
-
-/* --- Virtual Function Implementations --- */
-void _DensityField_Delete( void* densityField ) {
-	DensityField* self = (DensityField*) densityField;
-
-	_ParticleFeVariable_Delete( self );
-}
-
-void _DensityField_Print( void* densityField, Stream* stream ) {
-	DensityField* self = (DensityField*) densityField;
-	
-	/* General info */
-	Journal_Printf( stream, "DensityField (ptr): %p\n", self );
-	
-	/* Print parent */
-	_FeVariable_Print( self, stream );
-	
-	/* DensityField info */
-	Journal_PrintPointer( stream, self->buoyancyForceTerm );
-}
-
-void* _DensityField_Copy( const void* feVariable, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	DensityField*	self = (DensityField*)feVariable;
-	DensityField*	newDensityField;
-	
-	newDensityField = (DensityField*) _FeVariable_Copy( feVariable, dest, deep, nameExt, ptrMap );
-
-	newDensityField->buoyancyForceTerm = self->buoyancyForceTerm;
-	
-	return (void*)newDensityField;
-}
-
-void* _DensityField_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                       _sizeOfSelf = sizeof(DensityField);
-	Type                                                               type = DensityField_Type;
-	Stg_Class_DeleteFunction*                                       _delete = _DensityField_Delete;
-	Stg_Class_PrintFunction*                                         _print = _DensityField_Print;
-	Stg_Class_CopyFunction*                                           _copy = _DensityField_Copy;
-	Stg_Component_DefaultConstructorFunction*           _defaultConstructor = _DensityField_DefaultNew;
-	Stg_Component_ConstructFunction*                             _construct = _DensityField_AssignFromXML;
-	Stg_Component_BuildFunction*                                     _build = _DensityField_Build;
-	Stg_Component_InitialiseFunction*                           _initialise = _DensityField_Initialise;
-	Stg_Component_ExecuteFunction*                                 _execute = _DensityField_Execute;
-	Stg_Component_DestroyFunction*                                 _destroy = _DensityField_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 = _DensityField_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 = ZERO;
-	FieldVariable_GetValueFunction*   _getMaxGlobalFieldMagnitude = ZERO;
-	FeVariable_SyncShadowValuesFunc*            _syncShadowValues = ZERO;
-
-	return (void*) _DensityField_New(  DENSITYFIELD_PASSARGS  );
-}
-
-void _DensityField_AssignFromXML( void* densityField, Stg_ComponentFactory* cf, void* data ){
-	DensityField*			self = (DensityField*) densityField;
-	BuoyancyForceTerm*	buoyancyForceTerm;
-	Variable_Register*	variable_Register;
-
-	_ParticleFeVariable_AssignFromXML( self, cf, data );
-
-	buoyancyForceTerm = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"BuoyancyForceTerm", BuoyancyForceTerm, True, data );
-	variable_Register = self->context->variable_Register; 
-	assert( variable_Register  );
-
-	_DensityField_Init( self, buoyancyForceTerm, variable_Register );
-}
-
-void _DensityField_Build( void* densityField, void* data ) {
-	DensityField*			self = (DensityField*) densityField;
-	Variable_Register*	variable_Register = (Variable_Register*) self->variable_Register;
-	char*						tmpName;
-
-	Stg_Component_Build( self->buoyancyForceTerm, data, False );
-
-  	/* Create Dof Layout */
-	assert( Class_IsSuper( self->feMesh->topo, IGraph ) );
-	tmpName = Stg_Object_AppendSuffix( self, (Name)"densityVariable"  );
-	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)"densityDOF"  );
-	self->dofLayout = DofLayout_New( tmpName, self->context, variable_Register, 0, self->feMesh );
-	self->dofLayout->_numItemsInLayout = FeMesh_GetNodeDomainSize( self->feMesh );
-	DofLayout_AddAllFromVariableArray( self->dofLayout, 1, &self->dataVariable );
-	Memory_Free( tmpName );
-	self->eqNum->dofLayout = self->dofLayout;
-
-	_ParticleFeVariable_Build( self, data );
-}
-void _DensityField_Initialise( void* densityField, void* data ) {
-	DensityField* self = (DensityField*) densityField;
-
-	Stg_Component_Initialise( self->buoyancyForceTerm, data, False );
-
-	_ParticleFeVariable_Initialise( self, data );
-}
-void _DensityField_Execute( void* densityField, void* data ) {
-	DensityField* self = (DensityField*) densityField;
-
-	_ParticleFeVariable_Execute( self, data );
-}
-void _DensityField_Destroy( void* densityField, void* data ) {
-	DensityField* self = (DensityField*) densityField;
-
-   Stg_Component_Destroy( self->buoyancyForceTerm, data, False );
-
-	_ParticleFeVariable_Destroy( self, data );
-}
-
-void _DensityField_ValueAtParticle( void* densityField, IntegrationPointsSwarm* swarm, Element_LocalIndex lElement_I, void* _particle, double* density ) {
-	DensityField*                    self = (DensityField*) densityField;
-	IntegrationPoint*                particle = (IntegrationPoint*) _particle;
-	Material*                        material = NULL;
-	BuoyancyForceTerm_MaterialExt*   materialExt;
-	
-	/* Calculate density from particle material */
-	material = IntegrationPointsSwarm_GetMaterialOn( (IntegrationPointsSwarm*)swarm, particle );
-	materialExt = (BuoyancyForceTerm_MaterialExt*)ExtensionManager_Get( material->extensionMgr, material, self->buoyancyForceTerm->materialExtHandle );
-	*density = materialExt->density;
-}
-
-
-
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/DensityField.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/DensityField.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,177 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Monash Cluster Computing, Australia
+** (C) 2003-2004 All Rights Reserved
+**
+** Primary Authors:
+** Robert Turnbull, MCC
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include <Underworld/Rheology/Rheology.h>
+
+#include "types.h"
+#include "DensityField.h"
+#include <assert.h>
+
+const Type DensityField_Type = "DensityField";
+
+DensityField* _DensityField_New(  DENSITYFIELD_DEFARGS  ) {
+	DensityField* self;
+	
+	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree.
+	At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+	assert( _sizeOfSelf >= sizeof(DensityField) );
+	self = (DensityField*) _ParticleFeVariable_New(  PARTICLEFEVARIABLE_PASSARGS  );
+	
+	return self;
+}
+
+void _DensityField_Init( DensityField* self, BuoyancyForceTerm* buoyancyForceTerm, Variable_Register* variable_Register ) {
+	/* Assign Pointers */
+	self->buoyancyForceTerm = buoyancyForceTerm;
+	self->variable_Register = variable_Register;
+	
+	/* Set pointers to swarm to be the same as the one on the constitutive matrix */
+	self->assemblyTerm->integrationSwarm = self->buoyancyForceTerm->integrationSwarm;
+	self->massMatrixForceTerm->integrationSwarm = self->buoyancyForceTerm->integrationSwarm;	
+}
+
+/* --- Virtual Function Implementations --- */
+void _DensityField_Delete( void* densityField ) {
+	DensityField* self = (DensityField*) densityField;
+
+	_ParticleFeVariable_Delete( self );
+}
+
+void _DensityField_Print( void* densityField, Stream* stream ) {
+	DensityField* self = (DensityField*) densityField;
+	
+	/* General info */
+	Journal_Printf( stream, "DensityField (ptr): %p\n", self );
+	
+	/* Print parent */
+	_FeVariable_Print( self, stream );
+	
+	/* DensityField info */
+	Journal_PrintPointer( stream, self->buoyancyForceTerm );
+}
+
+void* _DensityField_Copy( const void* feVariable, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	DensityField*	self = (DensityField*)feVariable;
+	DensityField*	newDensityField;
+	
+	newDensityField = (DensityField*) _FeVariable_Copy( feVariable, dest, deep, nameExt, ptrMap );
+
+	newDensityField->buoyancyForceTerm = self->buoyancyForceTerm;
+	
+	return (void*)newDensityField;
+}
+
+void* _DensityField_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                       _sizeOfSelf = sizeof(DensityField);
+	Type                                                               type = DensityField_Type;
+	Stg_Class_DeleteFunction*                                       _delete = _DensityField_Delete;
+	Stg_Class_PrintFunction*                                         _print = _DensityField_Print;
+	Stg_Class_CopyFunction*                                           _copy = _DensityField_Copy;
+	Stg_Component_DefaultConstructorFunction*           _defaultConstructor = _DensityField_DefaultNew;
+	Stg_Component_ConstructFunction*                             _construct = _DensityField_AssignFromXML;
+	Stg_Component_BuildFunction*                                     _build = _DensityField_Build;
+	Stg_Component_InitialiseFunction*                           _initialise = _DensityField_Initialise;
+	Stg_Component_ExecuteFunction*                                 _execute = _DensityField_Execute;
+	Stg_Component_DestroyFunction*                                 _destroy = _DensityField_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 = _DensityField_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 = ZERO;
+	FieldVariable_GetValueFunction*   _getMaxGlobalFieldMagnitude = ZERO;
+	FeVariable_SyncShadowValuesFunc*            _syncShadowValues = ZERO;
+
+	return (void*) _DensityField_New(  DENSITYFIELD_PASSARGS  );
+}
+
+void _DensityField_AssignFromXML( void* densityField, Stg_ComponentFactory* cf, void* data ){
+	DensityField*			self = (DensityField*) densityField;
+	BuoyancyForceTerm*	buoyancyForceTerm;
+	Variable_Register*	variable_Register;
+
+	_ParticleFeVariable_AssignFromXML( self, cf, data );
+
+	buoyancyForceTerm = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"BuoyancyForceTerm", BuoyancyForceTerm, True, data );
+	variable_Register = self->context->variable_Register; 
+	assert( variable_Register  );
+
+	_DensityField_Init( self, buoyancyForceTerm, variable_Register );
+}
+
+void _DensityField_Build( void* densityField, void* data ) {
+	DensityField*			self = (DensityField*) densityField;
+	Variable_Register*	variable_Register = (Variable_Register*) self->variable_Register;
+	char*						tmpName;
+
+	Stg_Component_Build( self->buoyancyForceTerm, data, False );
+
+  	/* Create Dof Layout */
+	assert( Class_IsSuper( self->feMesh->topo, IGraph ) );
+	tmpName = Stg_Object_AppendSuffix( self, (Name)"densityVariable"  );
+	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)"densityDOF"  );
+	self->dofLayout = DofLayout_New( tmpName, self->context, variable_Register, 0, self->feMesh );
+	self->dofLayout->_numItemsInLayout = FeMesh_GetNodeDomainSize( self->feMesh );
+	DofLayout_AddAllFromVariableArray( self->dofLayout, 1, &self->dataVariable );
+	Memory_Free( tmpName );
+	self->eqNum->dofLayout = self->dofLayout;
+
+	_ParticleFeVariable_Build( self, data );
+}
+void _DensityField_Initialise( void* densityField, void* data ) {
+	DensityField* self = (DensityField*) densityField;
+
+	Stg_Component_Initialise( self->buoyancyForceTerm, data, False );
+
+	_ParticleFeVariable_Initialise( self, data );
+}
+void _DensityField_Execute( void* densityField, void* data ) {
+	DensityField* self = (DensityField*) densityField;
+
+	_ParticleFeVariable_Execute( self, data );
+}
+void _DensityField_Destroy( void* densityField, void* data ) {
+	DensityField* self = (DensityField*) densityField;
+
+   Stg_Component_Destroy( self->buoyancyForceTerm, data, False );
+
+	_ParticleFeVariable_Destroy( self, data );
+}
+
+void _DensityField_ValueAtParticle( void* densityField, IntegrationPointsSwarm* swarm, Element_LocalIndex lElement_I, void* _particle, double* density ) {
+	DensityField*                    self = (DensityField*) densityField;
+	IntegrationPoint*                particle = (IntegrationPoint*) _particle;
+	Material*                        material = NULL;
+	BuoyancyForceTerm_MaterialExt*   materialExt;
+	
+	/* Calculate density from particle material */
+	material = IntegrationPointsSwarm_GetMaterialOn( (IntegrationPointsSwarm*)swarm, particle );
+	materialExt = (BuoyancyForceTerm_MaterialExt*)ExtensionManager_Get( material->extensionMgr, material, self->buoyancyForceTerm->materialExtHandle );
+	*density = materialExt->density;
+}
+
+
+
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/DivergenceForce.c
--- a/Utils/src/DivergenceForce.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,297 +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)
-**
-** Copyright (C) 2008, California Institute of Technology
-** Modified for DivergenceForce by Walter Landry
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License 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/Gale/Utils/src/DivergenceForce.c 1691 2007-03-13T18:13:42.248551Z boo  $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "DivergenceForce.h"
-
-#include <assert.h>
-#include <string.h>
-
-/* Textual name of this class */
-const Type DivergenceForce_Type = "DivergenceForce";
-
-DivergenceForce* DivergenceForce_New(Name name,
-                                     FiniteElementContext*	context,
-                                     ForceVector* forceVector,
-                                     Swarm* integrationSwarm,
-                                     Stg_Shape* domainShape,
-                                     FeMesh* geometryMesh,
-                                     StressBC_Entry force)
-{
-	DivergenceForce* self = (DivergenceForce*) _DivergenceForce_DefaultNew( name );
-
-	DivergenceForce_InitAll( 
-			self,
-                        context,
-			forceVector,
-			integrationSwarm,
-                        domainShape,
-                        geometryMesh,
-                        force);
-
-	return self;
-}
-
-/* Creation implementation / Virtual constructor */
-DivergenceForce* _DivergenceForce_New( DIVERGENCEFORCE_DEFARGS)
-{
-	DivergenceForce* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(DivergenceForce) );
-	self = (DivergenceForce*) _ForceTerm_New( FORCETERM_PASSARGS);
-	
-	return self;
-}
-
-void _DivergenceForce_Init(DivergenceForce* self,
-                           Stg_Shape* domainShape, FeMesh *geometryMesh,
-                           StressBC_Entry force)
-{
-  self->isConstructed    = True;
-
-  self->domainShape=domainShape;
-  self->geometryMesh=geometryMesh;
-  self->force=force;
-}
-
-void DivergenceForce_InitAll( 
-		void*                                               forceTerm,
-                FiniteElementContext*	context,
-		ForceVector*                                        forceVector,
-		Swarm*                                              integrationSwarm,
-                Stg_Shape* domainShape,
-                FeMesh* geometryMesh,
-                StressBC_Entry force)
-{
-	DivergenceForce* self = (DivergenceForce*) forceTerm;
-
-	_ForceTerm_Init( self, context, forceVector, integrationSwarm, NULL );
-	_DivergenceForce_Init( self, domainShape, geometryMesh, force);
-}
-
-void _DivergenceForce_Delete( void* forceTerm ) {
-	DivergenceForce* self = (DivergenceForce*)forceTerm;
-
-	_ForceTerm_Delete( self );
-}
-
-void _DivergenceForce_Print( void* forceTerm, Stream* stream ) {
-	DivergenceForce* self = (DivergenceForce*)forceTerm;
-	
-	_ForceTerm_Print( self, stream );
-
-	/* General info */
-}
-
-void* _DivergenceForce_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(DivergenceForce);
-	Type                                                      type = DivergenceForce_Type;
-	Stg_Class_DeleteFunction*                              _delete = _DivergenceForce_Delete;
-	Stg_Class_PrintFunction*                                _print = _DivergenceForce_Print;
-	Stg_Class_CopyFunction*                                  _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _DivergenceForce_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _DivergenceForce_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _DivergenceForce_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _DivergenceForce_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _DivergenceForce_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _DivergenceForce_Destroy;
-	ForceTerm_AssembleElementFunction*            _assembleElement = _DivergenceForce_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*)_DivergenceForce_New( DIVERGENCEFORCE_PASSARGS);
-}
-
-void _DivergenceForce_AssignFromXML( void* forceTerm, Stg_ComponentFactory* cf, void* data ) {
-	DivergenceForce*          self             = (DivergenceForce*)forceTerm;
-	Dictionary*		dict;
-        Stg_Shape* domainShape=NULL;
-        FeMesh* geometryMesh=NULL;
-        StressBC_Entry force;
-        char *type;
-
-	/* Construct Parent */
-	_ForceTerm_AssignFromXML( self, cf, data );
-
-	dict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( cf->componentDict, self->name ) );
-	domainShape =  Stg_ComponentFactory_ConstructByKey(  cf,  self->name,  "DomainShape", Stg_Shape,  True, data  ) ;
-        type = Stg_ComponentFactory_GetString( cf, self->name, "force_type", "");
-
-        if(!strcasecmp(type,"double") || !strcasecmp(type,"float"))
-          {
-            force.type = StressBC_Double;
-            force.DoubleValue =
-              Stg_ComponentFactory_GetDouble( cf, self->name, "force_value", 0.0);
-          }
-        else if(!strcasecmp(type,"func"))
-          {
-            char *funcName = Stg_ComponentFactory_GetString
-              ( cf, self->name, "force_value", "");
-            
-            Index cfIndex;
-            cfIndex = ConditionFunction_Register_GetIndex
-              ( condFunc_Register, funcName);
-            force.type = StressBC_ConditionFunction;
-            if ( cfIndex == (unsigned)-1 ) {	
-              Stream*	errorStr = Journal_Register( Error_Type, self->type );
-              
-              Journal_Printf( errorStr, "Error- in %s: While parsing "
-                              "definition of DivergenceForce, the cond. func. "
-                              " \"%s\" - wasn't found in the c.f. register.\n",
-                              __func__, funcName );
-              Journal_Printf( errorStr, "(Available functions in the C.F. register are: ");	
-              ConditionFunction_Register_PrintNameOfEachFunc
-                ( condFunc_Register, errorStr );
-              Journal_Printf( errorStr, ")\n");	
-              assert(0);
-            }
-            force.CFIndex = cfIndex;
-          }
-        else if(strlen(type)==0)
-          {
-            Stream* errorStr = Journal_Register( Error_Type, self->type );
-            Journal_Printf( errorStr, "Error- in %s: While parsing "
-                            "definition of DivergenceForce, force_type is not specified.\nSupported types are \"double\" and \"function\".\n",
-                            __func__);
-            assert(0);
-          }
-        else
-          {
-            Stream* errorStr = Journal_Register( Error_Type, self->type );
-            Journal_Printf( errorStr, "Error- in %s: While parsing "
-                            "definition of DivergenceForce, the type of condition \"%s\"\nis not supported.  Supported types are \"double\" and \"function\".\n",
-                            __func__, type );
-            assert(0);
-          }
-        
-        geometryMesh=Stg_ComponentFactory_ConstructByKey(  cf,  self->name,  "GeometryMesh", FeMesh,  True, data  ) ;
-        
-	_DivergenceForce_Init( self, domainShape, geometryMesh, force);
-}
-
-void _DivergenceForce_Build( void* forceTerm, void* data ) {
-	DivergenceForce*               self               = (DivergenceForce*)forceTerm;
-	_ForceTerm_Build( self, data );
-}
-
-void _DivergenceForce_Initialise( void* forceTerm, void* data ) {
-	DivergenceForce*             self             = (DivergenceForce*)forceTerm;
-	_ForceTerm_Initialise( self, data );
-}
-
-void _DivergenceForce_Execute( void* forceTerm, void* data ) {
-	_ForceTerm_Execute( forceTerm, data );
-}
-
-void _DivergenceForce_Destroy( void* forceTerm, void* data ) {
-	_ForceTerm_Destroy( forceTerm, data );
-}
-
-
-void _DivergenceForce_AssembleElement( void* forceTerm,
-                                       ForceVector* forceVector, 
-                                       Element_LocalIndex lElement_I, 
-                                       double* elForceVec ) {
-  DivergenceForce* self=(DivergenceForce*) forceTerm;
-  FeMesh* mesh=forceVector->feVariable->feMesh;
-  Node_ElementLocalIndex           eNode_I;
-  Element_NodeIndex                elementNodeCount;
-  Node_DomainIndex *elementNodes=NULL;
-
-  double xi[3], force, factor;
-  ElementType* geometryElementType;
-  
-  IArray *incidence;
-
-  xi[0]=0;
-  xi[1]=0;
-  xi[2]=0;
-  geometryElementType=FeMesh_GetElementType(self->geometryMesh,lElement_I);
-  factor=ElementType_JacobianDeterminant( geometryElementType,
-                                          self->geometryMesh,
-                                          lElement_I,
-                                          xi, forceVector->dim );
-  incidence=IArray_New();
-  Mesh_GetIncidence(mesh, Mesh_GetDimSize(mesh), lElement_I,
-                    MT_VERTEX,incidence);
-  elementNodeCount=IArray_GetSize(incidence);
-  elementNodes=(Node_DomainIndex*)IArray_GetPtr(incidence);
-  
-  for( eNode_I = 0 ; eNode_I < elementNodeCount; eNode_I++ ) {
-    if(Stg_Shape_IsCoordInside(self->domainShape,
-                               Mesh_GetVertex(mesh,elementNodes[eNode_I])))
-      {
-        switch(self->force.type)
-          {
-          case StressBC_Double:
-            force=self->force.DoubleValue;
-            break;
-          case StressBC_ConditionFunction:
-            
-            /* We use a variable number of zero "0", because
-               we don't use the variable number and that one
-               is always going to exist. */
-            ConditionFunction_Apply
-              (condFunc_Register->_cf[self->force.CFIndex],
-               elementNodes[eNode_I],0,self->context,&force);
-            break;
-          }
-        elForceVec[ eNode_I] += force*factor;
-      }
-  }
-  NewClass_Delete(incidence);
-}
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/DivergenceForce.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/DivergenceForce.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,297 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** 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)
+**
+** Copyright (C) 2008, California Institute of Technology
+** Modified for DivergenceForce by Walter Landry
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License 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/Gale/Utils/src/DivergenceForce.c 1691 2007-03-13T18:13:42.248551Z boo  $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "DivergenceForce.h"
+
+#include <assert.h>
+#include <string.h>
+
+/* Textual name of this class */
+const Type DivergenceForce_Type = "DivergenceForce";
+
+DivergenceForce* DivergenceForce_New(Name name,
+                                     FiniteElementContext*	context,
+                                     ForceVector* forceVector,
+                                     Swarm* integrationSwarm,
+                                     Stg_Shape* domainShape,
+                                     FeMesh* geometryMesh,
+                                     StressBC_Entry force)
+{
+	DivergenceForce* self = (DivergenceForce*) _DivergenceForce_DefaultNew( name );
+
+	DivergenceForce_InitAll( 
+			self,
+                        context,
+			forceVector,
+			integrationSwarm,
+                        domainShape,
+                        geometryMesh,
+                        force);
+
+	return self;
+}
+
+/* Creation implementation / Virtual constructor */
+DivergenceForce* _DivergenceForce_New( DIVERGENCEFORCE_DEFARGS)
+{
+	DivergenceForce* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(DivergenceForce) );
+	self = (DivergenceForce*) _ForceTerm_New( FORCETERM_PASSARGS);
+	
+	return self;
+}
+
+void _DivergenceForce_Init(DivergenceForce* self,
+                           Stg_Shape* domainShape, FeMesh *geometryMesh,
+                           StressBC_Entry force)
+{
+  self->isConstructed    = True;
+
+  self->domainShape=domainShape;
+  self->geometryMesh=geometryMesh;
+  self->force=force;
+}
+
+void DivergenceForce_InitAll( 
+		void*                                               forceTerm,
+                FiniteElementContext*	context,
+		ForceVector*                                        forceVector,
+		Swarm*                                              integrationSwarm,
+                Stg_Shape* domainShape,
+                FeMesh* geometryMesh,
+                StressBC_Entry force)
+{
+	DivergenceForce* self = (DivergenceForce*) forceTerm;
+
+	_ForceTerm_Init( self, context, forceVector, integrationSwarm, NULL );
+	_DivergenceForce_Init( self, domainShape, geometryMesh, force);
+}
+
+void _DivergenceForce_Delete( void* forceTerm ) {
+	DivergenceForce* self = (DivergenceForce*)forceTerm;
+
+	_ForceTerm_Delete( self );
+}
+
+void _DivergenceForce_Print( void* forceTerm, Stream* stream ) {
+	DivergenceForce* self = (DivergenceForce*)forceTerm;
+	
+	_ForceTerm_Print( self, stream );
+
+	/* General info */
+}
+
+void* _DivergenceForce_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(DivergenceForce);
+	Type                                                      type = DivergenceForce_Type;
+	Stg_Class_DeleteFunction*                              _delete = _DivergenceForce_Delete;
+	Stg_Class_PrintFunction*                                _print = _DivergenceForce_Print;
+	Stg_Class_CopyFunction*                                  _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _DivergenceForce_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _DivergenceForce_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _DivergenceForce_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _DivergenceForce_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _DivergenceForce_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _DivergenceForce_Destroy;
+	ForceTerm_AssembleElementFunction*            _assembleElement = _DivergenceForce_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*)_DivergenceForce_New( DIVERGENCEFORCE_PASSARGS);
+}
+
+void _DivergenceForce_AssignFromXML( void* forceTerm, Stg_ComponentFactory* cf, void* data ) {
+	DivergenceForce*          self             = (DivergenceForce*)forceTerm;
+	Dictionary*		dict;
+        Stg_Shape* domainShape=NULL;
+        FeMesh* geometryMesh=NULL;
+        StressBC_Entry force;
+        char *type;
+
+	/* Construct Parent */
+	_ForceTerm_AssignFromXML( self, cf, data );
+
+	dict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( cf->componentDict, self->name ) );
+	domainShape =  Stg_ComponentFactory_ConstructByKey(  cf,  self->name,  "DomainShape", Stg_Shape,  True, data  ) ;
+        type = Stg_ComponentFactory_GetString( cf, self->name, "force_type", "");
+
+        if(!strcasecmp(type,"double") || !strcasecmp(type,"float"))
+          {
+            force.type = StressBC_Double;
+            force.DoubleValue =
+              Stg_ComponentFactory_GetDouble( cf, self->name, "force_value", 0.0);
+          }
+        else if(!strcasecmp(type,"func"))
+          {
+            char *funcName = Stg_ComponentFactory_GetString
+              ( cf, self->name, "force_value", "");
+            
+            Index cfIndex;
+            cfIndex = ConditionFunction_Register_GetIndex
+              ( condFunc_Register, funcName);
+            force.type = StressBC_ConditionFunction;
+            if ( cfIndex == (unsigned)-1 ) {	
+              Stream*	errorStr = Journal_Register( Error_Type, self->type );
+              
+              Journal_Printf( errorStr, "Error- in %s: While parsing "
+                              "definition of DivergenceForce, the cond. func. "
+                              " \"%s\" - wasn't found in the c.f. register.\n",
+                              __func__, funcName );
+              Journal_Printf( errorStr, "(Available functions in the C.F. register are: ");	
+              ConditionFunction_Register_PrintNameOfEachFunc
+                ( condFunc_Register, errorStr );
+              Journal_Printf( errorStr, ")\n");	
+              assert(0);
+            }
+            force.CFIndex = cfIndex;
+          }
+        else if(strlen(type)==0)
+          {
+            Stream* errorStr = Journal_Register( Error_Type, self->type );
+            Journal_Printf( errorStr, "Error- in %s: While parsing "
+                            "definition of DivergenceForce, force_type is not specified.\nSupported types are \"double\" and \"function\".\n",
+                            __func__);
+            assert(0);
+          }
+        else
+          {
+            Stream* errorStr = Journal_Register( Error_Type, self->type );
+            Journal_Printf( errorStr, "Error- in %s: While parsing "
+                            "definition of DivergenceForce, the type of condition \"%s\"\nis not supported.  Supported types are \"double\" and \"function\".\n",
+                            __func__, type );
+            assert(0);
+          }
+        
+        geometryMesh=Stg_ComponentFactory_ConstructByKey(  cf,  self->name,  "GeometryMesh", FeMesh,  True, data  ) ;
+        
+	_DivergenceForce_Init( self, domainShape, geometryMesh, force);
+}
+
+void _DivergenceForce_Build( void* forceTerm, void* data ) {
+	DivergenceForce*               self               = (DivergenceForce*)forceTerm;
+	_ForceTerm_Build( self, data );
+}
+
+void _DivergenceForce_Initialise( void* forceTerm, void* data ) {
+	DivergenceForce*             self             = (DivergenceForce*)forceTerm;
+	_ForceTerm_Initialise( self, data );
+}
+
+void _DivergenceForce_Execute( void* forceTerm, void* data ) {
+	_ForceTerm_Execute( forceTerm, data );
+}
+
+void _DivergenceForce_Destroy( void* forceTerm, void* data ) {
+	_ForceTerm_Destroy( forceTerm, data );
+}
+
+
+void _DivergenceForce_AssembleElement( void* forceTerm,
+                                       ForceVector* forceVector, 
+                                       Element_LocalIndex lElement_I, 
+                                       double* elForceVec ) {
+  DivergenceForce* self=(DivergenceForce*) forceTerm;
+  FeMesh* mesh=forceVector->feVariable->feMesh;
+  Node_ElementLocalIndex           eNode_I;
+  Element_NodeIndex                elementNodeCount;
+  Node_DomainIndex *elementNodes=NULL;
+
+  double xi[3], force, factor;
+  ElementType* geometryElementType;
+  
+  IArray *incidence;
+
+  xi[0]=0;
+  xi[1]=0;
+  xi[2]=0;
+  geometryElementType=FeMesh_GetElementType(self->geometryMesh,lElement_I);
+  factor=ElementType_JacobianDeterminant( geometryElementType,
+                                          self->geometryMesh,
+                                          lElement_I,
+                                          xi, forceVector->dim );
+  incidence=IArray_New();
+  Mesh_GetIncidence(mesh, Mesh_GetDimSize(mesh), lElement_I,
+                    MT_VERTEX,incidence);
+  elementNodeCount=IArray_GetSize(incidence);
+  elementNodes=(Node_DomainIndex*)IArray_GetPtr(incidence);
+  
+  for( eNode_I = 0 ; eNode_I < elementNodeCount; eNode_I++ ) {
+    if(Stg_Shape_IsCoordInside(self->domainShape,
+                               Mesh_GetVertex(mesh,elementNodes[eNode_I])))
+      {
+        switch(self->force.type)
+          {
+          case StressBC_Double:
+            force=self->force.DoubleValue;
+            break;
+          case StressBC_ConditionFunction:
+            
+            /* We use a variable number of zero "0", because
+               we don't use the variable number and that one
+               is always going to exist. */
+            ConditionFunction_Apply
+              (condFunc_Register->_cf[self->force.CFIndex],
+               elementNodes[eNode_I],0,self->context,&force);
+            break;
+          }
+        elForceVec[ eNode_I] += force*factor;
+      }
+  }
+  NewClass_Delete(incidence);
+}
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/Finalise.c
--- a/Utils/src/Finalise.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,60 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: Finalise.c 610 2007-10-11 08:09:29Z SteveQuenette $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include "Finalise.h"
-
-#include <stdio.h>
-
-Bool Underworld_Utils_Finalise( void ) {
-	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
-   _Stg_ObjectList_Delete( repRequiredRawFields_Reg );
-	
-	return True;
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/Finalise.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/Finalise.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,60 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: Finalise.c 610 2007-10-11 08:09:29Z SteveQuenette $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include "Finalise.h"
+
+#include <stdio.h>
+
+Bool Underworld_Utils_Finalise( void ) {
+	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
+   _Stg_ObjectList_Delete( repRequiredRawFields_Reg );
+	
+	return True;
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/Init.c
--- a/Utils/src/Init.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,117 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: Init.c 765 2008-07-24 05:40:02Z LukeHodkinson $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-
-#include <PICellerator/PICellerator.h>
-#include <PICellerator/Weights/Weights.h>
-#include <PICellerator/Weights/WeightsCalculator.h>
-
-#include <Underworld/Rheology/Rheology.h>
-
-#include "Utils.h"
-
-Stg_ObjectList* repRequiredRawFields_Reg = NULL;
-
-#include <stdio.h>
-
-Bool Underworld_Utils_Init( int* argc, char** argv[] ) {
-	Stg_ComponentRegister* componentRegister = Stg_ComponentRegister_Get_ComponentRegister();
-
-   /* A register to keep track of fields needed to be initialise before the REP_Algorithm */
-   repRequiredRawFields_Reg = Stg_ObjectList_New();
-
-	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
-	
-	Stg_ComponentRegister_Add( componentRegister, UnderworldContext_Type, (Name)"0", _UnderworldContext_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, TracerOutput_Type, (Name)"0", _TracerOutput_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, Underworld_SwarmOutput_Type, (Name)"0", _Underworld_SwarmOutput_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, RadiogenicHeatingTerm_Type, (Name)"0", _RadiogenicHeatingTerm_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, StressField_Type , (Name)"0", _StressField_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, NodalPressureField_Type , (Name)"0", _NodalPressureField_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, SmoothVelGradField_Type , (Name)"0", _SmoothVelGradField_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, ViscosityField_Type , (Name)"0", _ViscosityField_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, DensityField_Type , (Name)"0", _DensityField_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, DivergenceForce_Type,
-                                   (Name)"0", _DivergenceForce_DefaultNew );
-	Stg_ComponentRegister_Add( componentRegister, MixedStabiliserTerm_Type,
-                                   (Name)"0", _MixedStabiliserTerm_DefaultNew );
-	Stg_ComponentRegister_Add( componentRegister, StressBC_Type,
-                                   (Name)"0", _StressBC_DefaultNew );
-
-	RegisterParent( UnderworldContext_Type,       	    PICelleratorContext_Type );
-	RegisterParent( TracerOutput_Type,     SwarmOutput_Type );
-	RegisterParent( Underworld_SwarmOutput_Type,        SwarmOutput_Type );
-	RegisterParent( RadiogenicHeatingTerm_Type,         ForceTerm_Type );
-	RegisterParent( StressField_Type,                   ParticleFeVariable_Type );
-	RegisterParent( NodalPressureField_Type,            ParticleFeVariable_Type );
-	RegisterParent( SmoothVelGradField_Type,            ParticleFeVariable_Type );
-	RegisterParent( ViscosityField_Type,                ParticleFeVariable_Type );
-	RegisterParent( DensityField_Type,                  ParticleFeVariable_Type );
-	RegisterParent( DivergenceForce_Type,                  ForceTerm_Type );
-	RegisterParent( MixedStabiliserTerm_Type, StiffnessMatrixTerm_Type );
-	RegisterParent( StressBC_Type, ForceTerm_Type );
-
-   /* Register the new BaseClass for recovery fields */
-   Stg_ComponentRegister_Add( componentRegister, BaseRecoveryFeVar_Type, (Name)"0", _BaseRecoveryFeVar_DefaultNew  );
-   RegisterParent( BaseRecoveryFeVar_Type, FeVariable_Type );
-
-   /* Register the SPR component */
-   Stg_ComponentRegister_Add( componentRegister, SPR_StrainRate_Type, (Name)"0", _SPR_StrainRate_DefaultNew  );
-   RegisterParent( SPR_StrainRate_Type, BaseRecoveryFeVar_Type );
-
-   Stg_ComponentRegister_Add( componentRegister, REP_Algorithm_Type, (Name)"0", _REP_Algorithm_DefaultNew  );
-   RegisterParent( REP_Algorithm_Type,           Stg_Component_Type );
-
-   Stg_ComponentRegister_Add( componentRegister, RecoveredFeVariable_Type, (Name)"0", _RecoveredFeVariable_DefaultNew  );
-   RegisterParent( RecoveredFeVariable_Type,     FeVariable_Type );
-
-	return True;
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/Init.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/Init.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,117 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: Init.c 765 2008-07-24 05:40:02Z LukeHodkinson $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+
+#include <PICellerator/PICellerator.h>
+#include <PICellerator/Weights/Weights.h>
+#include <PICellerator/Weights/WeightsCalculator.h>
+
+#include <Underworld/Rheology/Rheology.h>
+
+#include "Utils.h"
+
+Stg_ObjectList* repRequiredRawFields_Reg = NULL;
+
+#include <stdio.h>
+
+Bool Underworld_Utils_Init( int* argc, char** argv[] ) {
+	Stg_ComponentRegister* componentRegister = Stg_ComponentRegister_Get_ComponentRegister();
+
+   /* A register to keep track of fields needed to be initialise before the REP_Algorithm */
+   repRequiredRawFields_Reg = Stg_ObjectList_New();
+
+	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
+	
+	Stg_ComponentRegister_Add( componentRegister, UnderworldContext_Type, (Name)"0", _UnderworldContext_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, TracerOutput_Type, (Name)"0", _TracerOutput_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, Underworld_SwarmOutput_Type, (Name)"0", _Underworld_SwarmOutput_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, RadiogenicHeatingTerm_Type, (Name)"0", _RadiogenicHeatingTerm_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, StressField_Type , (Name)"0", _StressField_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, NodalPressureField_Type , (Name)"0", _NodalPressureField_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, SmoothVelGradField_Type , (Name)"0", _SmoothVelGradField_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, ViscosityField_Type , (Name)"0", _ViscosityField_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, DensityField_Type , (Name)"0", _DensityField_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, DivergenceForce_Type,
+                                   (Name)"0", _DivergenceForce_DefaultNew );
+	Stg_ComponentRegister_Add( componentRegister, MixedStabiliserTerm_Type,
+                                   (Name)"0", _MixedStabiliserTerm_DefaultNew );
+	Stg_ComponentRegister_Add( componentRegister, StressBC_Type,
+                                   (Name)"0", _StressBC_DefaultNew );
+
+	RegisterParent( UnderworldContext_Type,       	    PICelleratorContext_Type );
+	RegisterParent( TracerOutput_Type,     SwarmOutput_Type );
+	RegisterParent( Underworld_SwarmOutput_Type,        SwarmOutput_Type );
+	RegisterParent( RadiogenicHeatingTerm_Type,         ForceTerm_Type );
+	RegisterParent( StressField_Type,                   ParticleFeVariable_Type );
+	RegisterParent( NodalPressureField_Type,            ParticleFeVariable_Type );
+	RegisterParent( SmoothVelGradField_Type,            ParticleFeVariable_Type );
+	RegisterParent( ViscosityField_Type,                ParticleFeVariable_Type );
+	RegisterParent( DensityField_Type,                  ParticleFeVariable_Type );
+	RegisterParent( DivergenceForce_Type,                  ForceTerm_Type );
+	RegisterParent( MixedStabiliserTerm_Type, StiffnessMatrixTerm_Type );
+	RegisterParent( StressBC_Type, ForceTerm_Type );
+
+   /* Register the new BaseClass for recovery fields */
+   Stg_ComponentRegister_Add( componentRegister, BaseRecoveryFeVar_Type, (Name)"0", _BaseRecoveryFeVar_DefaultNew  );
+   RegisterParent( BaseRecoveryFeVar_Type, FeVariable_Type );
+
+   /* Register the SPR component */
+   Stg_ComponentRegister_Add( componentRegister, SPR_StrainRate_Type, (Name)"0", _SPR_StrainRate_DefaultNew  );
+   RegisterParent( SPR_StrainRate_Type, BaseRecoveryFeVar_Type );
+
+   Stg_ComponentRegister_Add( componentRegister, REP_Algorithm_Type, (Name)"0", _REP_Algorithm_DefaultNew  );
+   RegisterParent( REP_Algorithm_Type,           Stg_Component_Type );
+
+   Stg_ComponentRegister_Add( componentRegister, RecoveredFeVariable_Type, (Name)"0", _RecoveredFeVariable_DefaultNew  );
+   RegisterParent( RecoveredFeVariable_Type,     FeVariable_Type );
+
+	return True;
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/MixedStabiliserTerm.c
--- a/Utils/src/MixedStabiliserTerm.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,249 +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: MixedStabiliserTerm.c 2192 2004-10-15 02:45:38Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <string.h>
-#include <assert.h>
-#include <mpi.h>
-
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Underworld.h>
-
-#include "types.h"
-#include "MixedStabiliserTerm.h"
-
-
-const Type MixedStabiliserTerm_Type = "MixedStabiliserTerm";
-
-
-void* _MixedStabiliserTerm_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                 _sizeOfSelf = sizeof(MixedStabiliserTerm);
-	Type                                                         type = MixedStabiliserTerm_Type;
-	Stg_Class_DeleteFunction*                                 _delete = _MixedStabiliserTerm_Delete;
-	Stg_Class_PrintFunction*                                   _print = _StiffnessMatrixTerm_Print;
-	Stg_Class_CopyFunction*                                     _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*     _defaultConstructor = _MixedStabiliserTerm_DefaultNew;
-	Stg_Component_ConstructFunction*                       _construct = _MixedStabiliserTerm_AssignFromXML;
-	Stg_Component_BuildFunction*                               _build = _MixedStabiliserTerm_Build;
-	Stg_Component_InitialiseFunction*                     _initialise = _MixedStabiliserTerm_Initialise;
-	Stg_Component_ExecuteFunction*                           _execute = _MixedStabiliserTerm_Execute;
-	Stg_Component_DestroyFunction*                           _destroy = _MixedStabiliserTerm_Destroy;
-	StiffnessMatrixTerm_AssembleElementFunction*     _assembleElement = _MixedStabiliserTerm_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*)_MixedStabiliserTerm_New(  MIXEDSTABILISERTERM_PASSARGS  );
-}
-
-/* Creation implementation / Virtual constructor */
-MixedStabiliserTerm* _MixedStabiliserTerm_New(   MIXEDSTABILISERTERM_DEFARGS  )
-{
-	MixedStabiliserTerm* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(MixedStabiliserTerm) );
-	self = (MixedStabiliserTerm*) _StiffnessMatrixTerm_New(  STIFFNESSMATRIXTERM_PASSARGS  );
-
-   return self;
-}
-
-void _MixedStabiliserTerm_Init( MixedStabiliserTerm* self ) {
-   self->picSwarm = NULL;
-   self->storeVisc = NULL;
-   self->Ni = NULL;
-   self->elStiffMat = NULL;
-}
-
-void _MixedStabiliserTerm_Delete( void* _self ) {
-   MixedStabiliserTerm* self = (MixedStabiliserTerm*)_self;
-
-   if( self->Ni )
-      Memory_Free( self->Ni );
-   if( self->elStiffMat )
-      Memory_Free( self->elStiffMat );
-
-   _StiffnessMatrixTerm_Delete( self );
-}
-
-void _MixedStabiliserTerm_AssignFromXML( void* _self, Stg_ComponentFactory* cf, void* data ) {
-   MixedStabiliserTerm* self = (MixedStabiliserTerm*)_self;
-
-   _StiffnessMatrixTerm_AssignFromXML( self, cf, data );
-   _MixedStabiliserTerm_Init( self );
-
-   self->picSwarm = Stg_ComponentFactory_ConstructByKey(
-      cf, self->name, "picSwarm", IntegrationPointsSwarm,
-      True, data );
-   self->storeVisc =
-     Stg_ComponentFactory_ConstructByKey(cf, self->name, "storeVisc",
-                                         StoreVisc, True, data );
-}
-
-void _MixedStabiliserTerm_Build( void* _self, void* data ) {
-   MixedStabiliserTerm* self = (MixedStabiliserTerm*)_self;
-
-   _StiffnessMatrixTerm_Build( self, data );
-}
-
-void _MixedStabiliserTerm_Initialise( void* _self, void* data ) {
-   MixedStabiliserTerm* self = (MixedStabiliserTerm*)_self;
-   _StiffnessMatrixTerm_Initialise( self, data );
-}
-
-void _MixedStabiliserTerm_Execute( void* _self, void* data ) {
-   _StiffnessMatrixTerm_Execute( _self, data );
-}
-
-void _MixedStabiliserTerm_Destroy( void* _self, void* data ) {
-   _StiffnessMatrixTerm_Destroy( _self, data );
-}
-
-void _MixedStabiliserTerm_AssembleElement( void* _self,
-					  StiffnessMatrix* stiffMat,
-					  Element_LocalIndex elementIndex,
-					  SystemLinearEquations* _sle,
-					  FiniteElementContext* ctx,
-					  double** elStiffMat )
-{
-   MixedStabiliserTerm* self = (MixedStabiliserTerm*)_self;
-   Stokes_SLE* sle = Stg_DCheckType( _sle, Stokes_SLE );
-   StiffnessMatrix* gMatrix = sle->gStiffMat;
-   FeVariable* colVar  = gMatrix->columnVariable;
-   FeMesh* mesh = colVar->feMesh;
-   int nDims = Mesh_GetDimSize( mesh );
-   double *xi, weight, jacDet, weightJacDet, cellArea = 0.0;
-   double *Ni, **GNx, viscFac;
-   int nParticles, nElNodes, cellIndex;
-   ElementType* elementType;
-   IntegrationPointsSwarm* swarm;
-   IntegrationPoint* integrationPoint;
-   double geometric_factor;
-   double** localElStiffMat;
-   int ii, jj, kk;
-   double sumVisc = 0.0, visc;
-
-   /* Get the current element's type and cache the number
-      of nodes. */
-   elementType = FeMesh_GetElementType( mesh, elementIndex );
-   nElNodes = elementType->nodeCount;
-
-   /* If we don't already have arrays, allocate them now. */
-   if( !self->Ni && !self->GNx && !self->elStiffMat ) {
-      self->Ni = Memory_Alloc_Array( double, nElNodes, MixedStabiliserTerm_Type );
-      self->GNx = Memory_Alloc_2DArray( double, nDims, nElNodes, MixedStabiliserTerm_Type );
-      self->elStiffMat = Memory_Alloc_2DArray( double, nElNodes, nElNodes, MixedStabiliserTerm_Type );
-   }
-
-   /* Cache array pointers stored on the mesh. */
-   Ni = self->Ni;
-   GNx = self->GNx;
-   localElStiffMat = self->elStiffMat;
-
-   /* Zero the local element stiffness matrix. */
-   for( ii = 0; ii < nElNodes; ii++ )
-      memset( localElStiffMat[ii], 0, nElNodes * sizeof(double) );
-
-   /* Assemble the mass matrix portion. */
-   swarm = (IntegrationPointsSwarm*)(self->integrationSwarm);
-   cellIndex = CellLayout_MapElementIdToCellId( swarm->cellLayout,
-                                                elementIndex );
-   nParticles = swarm->cellParticleCountTbl[cellIndex];
-   for( ii = 0; ii < nParticles; ii++ ) {
-
-      /* Cache information from the current integration point. */
-      integrationPoint = (IntegrationPoint*)Swarm_ParticleInCellAt(
-         swarm, cellIndex, ii );
-      xi = integrationPoint->xi;
-      weight = integrationPoint->weight;
-      ElementType_EvaluateShapeFunctionsAt( elementType, xi, Ni );
-      ElementType_ShapeFunctionsGlobalDerivs(
-         elementType, mesh, elementIndex, xi, nDims, &jacDet, GNx );
-      weightJacDet = weight * jacDet;
-
-      /* Loop over element nodes. */
-      for( jj = 0 ; jj < nElNodes; jj++ ) {
-         for ( kk = 0 ; kk < nElNodes ; kk++ ) {
-            localElStiffMat[jj][kk] += weightJacDet * Ni[jj] * Ni[kk];
-         }
-      }
-   }
-
-   /* Calculate the cell's area and viscosity. */
-   swarm = self->picSwarm;
-   cellIndex = CellLayout_MapElementIdToCellId( swarm->cellLayout, elementIndex );
-   nParticles = swarm->cellParticleCountTbl[cellIndex];
-   for( ii = 0; ii < nParticles; ii++ ) {
-     StoreVisc_ParticleExt*            particleExt;
-     MaterialPointsSwarm*    mSwarm;
-     MaterialPoint*          materialparticle;
-
-      /* Cache information from the current integration point. */
-      integrationPoint = (IntegrationPoint*)Swarm_ParticleInCellAt(
-         swarm, cellIndex, ii );
-      ElementType_ShapeFunctionsGlobalDerivs(
-         elementType, mesh, elementIndex, integrationPoint->xi,
-         nDims, &jacDet, GNx );
-
-      /* Add this particle's value to the area. */
-      cellArea += integrationPoint->weight * jacDet;
-
-      materialparticle =
-        OneToOneMapper_GetMaterialPoint( swarm->mapper,
-                                         integrationPoint, &mSwarm );
-      particleExt=
-        (StoreVisc_ParticleExt*)ExtensionManager_Get( mSwarm->particleExtensionMgr,
-                              materialparticle,
-                              self->storeVisc->particleExtHandle );
-
-      visc=particleExt->effVisc;
-      sumVisc += visc*integrationPoint->weight * jacDet;
-   }
-
-   /* Normalize the viscosity factor by dividing by cell area. */
-   viscFac = cellArea / sumVisc;
-
-   /* Adjust the calculated mass matrix by the 'special operator'. The
-      nElNodes term comes from an averaging operator applied twice. */
-
-   for( ii = 0; ii < nElNodes; ii++ )
-      for( jj = 0; jj < nElNodes; jj++ )
-        localElStiffMat[ii][jj] -= cellArea/(nElNodes*nElNodes);
-
-   /* Apply the viscosity factor and negate the calculated value. */
-   for( ii = 0; ii < nElNodes; ii++ ) {
-      for( jj = 0; jj < nElNodes; jj++ )
-         elStiffMat[ii][jj] += -localElStiffMat[ii][jj] * viscFac;
-   }
-}
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/MixedStabiliserTerm.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/MixedStabiliserTerm.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,249 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd,
+** 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: MixedStabiliserTerm.c 2192 2004-10-15 02:45:38Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <string.h>
+#include <assert.h>
+#include <mpi.h>
+
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Underworld.h>
+
+#include "types.h"
+#include "MixedStabiliserTerm.h"
+
+
+const Type MixedStabiliserTerm_Type = "MixedStabiliserTerm";
+
+
+void* _MixedStabiliserTerm_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                 _sizeOfSelf = sizeof(MixedStabiliserTerm);
+	Type                                                         type = MixedStabiliserTerm_Type;
+	Stg_Class_DeleteFunction*                                 _delete = _MixedStabiliserTerm_Delete;
+	Stg_Class_PrintFunction*                                   _print = _StiffnessMatrixTerm_Print;
+	Stg_Class_CopyFunction*                                     _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*     _defaultConstructor = _MixedStabiliserTerm_DefaultNew;
+	Stg_Component_ConstructFunction*                       _construct = _MixedStabiliserTerm_AssignFromXML;
+	Stg_Component_BuildFunction*                               _build = _MixedStabiliserTerm_Build;
+	Stg_Component_InitialiseFunction*                     _initialise = _MixedStabiliserTerm_Initialise;
+	Stg_Component_ExecuteFunction*                           _execute = _MixedStabiliserTerm_Execute;
+	Stg_Component_DestroyFunction*                           _destroy = _MixedStabiliserTerm_Destroy;
+	StiffnessMatrixTerm_AssembleElementFunction*     _assembleElement = _MixedStabiliserTerm_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*)_MixedStabiliserTerm_New(  MIXEDSTABILISERTERM_PASSARGS  );
+}
+
+/* Creation implementation / Virtual constructor */
+MixedStabiliserTerm* _MixedStabiliserTerm_New(   MIXEDSTABILISERTERM_DEFARGS  )
+{
+	MixedStabiliserTerm* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(MixedStabiliserTerm) );
+	self = (MixedStabiliserTerm*) _StiffnessMatrixTerm_New(  STIFFNESSMATRIXTERM_PASSARGS  );
+
+   return self;
+}
+
+void _MixedStabiliserTerm_Init( MixedStabiliserTerm* self ) {
+   self->picSwarm = NULL;
+   self->storeVisc = NULL;
+   self->Ni = NULL;
+   self->elStiffMat = NULL;
+}
+
+void _MixedStabiliserTerm_Delete( void* _self ) {
+   MixedStabiliserTerm* self = (MixedStabiliserTerm*)_self;
+
+   if( self->Ni )
+      Memory_Free( self->Ni );
+   if( self->elStiffMat )
+      Memory_Free( self->elStiffMat );
+
+   _StiffnessMatrixTerm_Delete( self );
+}
+
+void _MixedStabiliserTerm_AssignFromXML( void* _self, Stg_ComponentFactory* cf, void* data ) {
+   MixedStabiliserTerm* self = (MixedStabiliserTerm*)_self;
+
+   _StiffnessMatrixTerm_AssignFromXML( self, cf, data );
+   _MixedStabiliserTerm_Init( self );
+
+   self->picSwarm = Stg_ComponentFactory_ConstructByKey(
+      cf, self->name, "picSwarm", IntegrationPointsSwarm,
+      True, data );
+   self->storeVisc =
+     Stg_ComponentFactory_ConstructByKey(cf, self->name, "storeVisc",
+                                         StoreVisc, True, data );
+}
+
+void _MixedStabiliserTerm_Build( void* _self, void* data ) {
+   MixedStabiliserTerm* self = (MixedStabiliserTerm*)_self;
+
+   _StiffnessMatrixTerm_Build( self, data );
+}
+
+void _MixedStabiliserTerm_Initialise( void* _self, void* data ) {
+   MixedStabiliserTerm* self = (MixedStabiliserTerm*)_self;
+   _StiffnessMatrixTerm_Initialise( self, data );
+}
+
+void _MixedStabiliserTerm_Execute( void* _self, void* data ) {
+   _StiffnessMatrixTerm_Execute( _self, data );
+}
+
+void _MixedStabiliserTerm_Destroy( void* _self, void* data ) {
+   _StiffnessMatrixTerm_Destroy( _self, data );
+}
+
+void _MixedStabiliserTerm_AssembleElement( void* _self,
+					  StiffnessMatrix* stiffMat,
+					  Element_LocalIndex elementIndex,
+					  SystemLinearEquations* _sle,
+					  FiniteElementContext* ctx,
+					  double** elStiffMat )
+{
+   MixedStabiliserTerm* self = (MixedStabiliserTerm*)_self;
+   Stokes_SLE* sle = Stg_DCheckType( _sle, Stokes_SLE );
+   StiffnessMatrix* gMatrix = sle->gStiffMat;
+   FeVariable* colVar  = gMatrix->columnVariable;
+   FeMesh* mesh = colVar->feMesh;
+   int nDims = Mesh_GetDimSize( mesh );
+   double *xi, weight, jacDet, weightJacDet, cellArea = 0.0;
+   double *Ni, **GNx, viscFac;
+   int nParticles, nElNodes, cellIndex;
+   ElementType* elementType;
+   IntegrationPointsSwarm* swarm;
+   IntegrationPoint* integrationPoint;
+   double geometric_factor;
+   double** localElStiffMat;
+   int ii, jj, kk;
+   double sumVisc = 0.0, visc;
+
+   /* Get the current element's type and cache the number
+      of nodes. */
+   elementType = FeMesh_GetElementType( mesh, elementIndex );
+   nElNodes = elementType->nodeCount;
+
+   /* If we don't already have arrays, allocate them now. */
+   if( !self->Ni && !self->GNx && !self->elStiffMat ) {
+      self->Ni = Memory_Alloc_Array( double, nElNodes, MixedStabiliserTerm_Type );
+      self->GNx = Memory_Alloc_2DArray( double, nDims, nElNodes, MixedStabiliserTerm_Type );
+      self->elStiffMat = Memory_Alloc_2DArray( double, nElNodes, nElNodes, MixedStabiliserTerm_Type );
+   }
+
+   /* Cache array pointers stored on the mesh. */
+   Ni = self->Ni;
+   GNx = self->GNx;
+   localElStiffMat = self->elStiffMat;
+
+   /* Zero the local element stiffness matrix. */
+   for( ii = 0; ii < nElNodes; ii++ )
+      memset( localElStiffMat[ii], 0, nElNodes * sizeof(double) );
+
+   /* Assemble the mass matrix portion. */
+   swarm = (IntegrationPointsSwarm*)(self->integrationSwarm);
+   cellIndex = CellLayout_MapElementIdToCellId( swarm->cellLayout,
+                                                elementIndex );
+   nParticles = swarm->cellParticleCountTbl[cellIndex];
+   for( ii = 0; ii < nParticles; ii++ ) {
+
+      /* Cache information from the current integration point. */
+      integrationPoint = (IntegrationPoint*)Swarm_ParticleInCellAt(
+         swarm, cellIndex, ii );
+      xi = integrationPoint->xi;
+      weight = integrationPoint->weight;
+      ElementType_EvaluateShapeFunctionsAt( elementType, xi, Ni );
+      ElementType_ShapeFunctionsGlobalDerivs(
+         elementType, mesh, elementIndex, xi, nDims, &jacDet, GNx );
+      weightJacDet = weight * jacDet;
+
+      /* Loop over element nodes. */
+      for( jj = 0 ; jj < nElNodes; jj++ ) {
+         for ( kk = 0 ; kk < nElNodes ; kk++ ) {
+            localElStiffMat[jj][kk] += weightJacDet * Ni[jj] * Ni[kk];
+         }
+      }
+   }
+
+   /* Calculate the cell's area and viscosity. */
+   swarm = self->picSwarm;
+   cellIndex = CellLayout_MapElementIdToCellId( swarm->cellLayout, elementIndex );
+   nParticles = swarm->cellParticleCountTbl[cellIndex];
+   for( ii = 0; ii < nParticles; ii++ ) {
+     StoreVisc_ParticleExt*            particleExt;
+     MaterialPointsSwarm*    mSwarm;
+     MaterialPoint*          materialparticle;
+
+      /* Cache information from the current integration point. */
+      integrationPoint = (IntegrationPoint*)Swarm_ParticleInCellAt(
+         swarm, cellIndex, ii );
+      ElementType_ShapeFunctionsGlobalDerivs(
+         elementType, mesh, elementIndex, integrationPoint->xi,
+         nDims, &jacDet, GNx );
+
+      /* Add this particle's value to the area. */
+      cellArea += integrationPoint->weight * jacDet;
+
+      materialparticle =
+        OneToOneMapper_GetMaterialPoint( swarm->mapper,
+                                         integrationPoint, &mSwarm );
+      particleExt=
+        (StoreVisc_ParticleExt*)ExtensionManager_Get( mSwarm->particleExtensionMgr,
+                              materialparticle,
+                              self->storeVisc->particleExtHandle );
+
+      visc=particleExt->effVisc;
+      sumVisc += visc*integrationPoint->weight * jacDet;
+   }
+
+   /* Normalize the viscosity factor by dividing by cell area. */
+   viscFac = cellArea / sumVisc;
+
+   /* Adjust the calculated mass matrix by the 'special operator'. The
+      nElNodes term comes from an averaging operator applied twice. */
+
+   for( ii = 0; ii < nElNodes; ii++ )
+      for( jj = 0; jj < nElNodes; jj++ )
+        localElStiffMat[ii][jj] -= cellArea/(nElNodes*nElNodes);
+
+   /* Apply the viscosity factor and negate the calculated value. */
+   for( ii = 0; ii < nElNodes; ii++ ) {
+      for( jj = 0; jj < nElNodes; jj++ )
+         elStiffMat[ii][jj] += -localElStiffMat[ii][jj] * viscFac;
+   }
+}
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/NodalPressureField.c
--- a/Utils/src/NodalPressureField.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,202 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Monash Cluster Computing, Australia
-** (C) 2003-2004 All Rights Reserved
-**
-** Primary Authors:
-** Luke Hodkinson
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#include <mpi.h>
-
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Rheology/Rheology.h>
-
-#include "types.h"
-#include "NodalPressureField.h"
-
-const Type NodalPressureField_Type = "NodalPressureField";
-
-/*
-** Constructors/Destructors.
-*/
-
-NodalPressureField* _NodalPressureField_New(  NODALPRESSUREFIELD_DEFARGS  ) {
-   NodalPressureField* self;
-
-   assert( _sizeOfSelf >= sizeof(NodalPressureField) );
-   self = (NodalPressureField*)_ParticleFeVariable_New(  PARTICLEFEVARIABLE_PASSARGS  );
-
-   return self;
-}
-
-void _NodalPressureField_Init( NodalPressureField* self, Variable_Register* variable_Register, FeVariable* pressureField, SystemLinearEquations* sle) {
-   self->variable_Register = variable_Register;
-   self->fieldComponentCount = 1;
-   self->pressureField = pressureField;
-   if( sle )
-      SystemLinearEquations_AddPostNonLinearEP( sle, NodalPressureField_Type, NodalPressureField_NonLinearUpdate );
-}
-
-void* _NodalPressureField_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                       _sizeOfSelf = sizeof(NodalPressureField);
-	Type                                                               type = NodalPressureField_Type;
-	Stg_Class_DeleteFunction*                                       _delete = _NodalPressureField_Delete;
-	Stg_Class_PrintFunction*                                         _print = _NodalPressureField_Print;
-	Stg_Class_CopyFunction*                                           _copy = _NodalPressureField_Copy;
-	Stg_Component_DefaultConstructorFunction*           _defaultConstructor = _NodalPressureField_DefaultNew;
-	Stg_Component_ConstructFunction*                             _construct = _NodalPressureField_AssignFromXML;
-	Stg_Component_BuildFunction*                                     _build = _NodalPressureField_Build;
-	Stg_Component_InitialiseFunction*                           _initialise = _NodalPressureField_Initialise;
-	Stg_Component_ExecuteFunction*                                 _execute = _NodalPressureField_Execute;
-	Stg_Component_DestroyFunction*                                 _destroy = _NodalPressureField_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 = _NodalPressureField_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 = ZERO;
-	FieldVariable_GetValueFunction*   _getMaxGlobalFieldMagnitude = ZERO;
-	FeVariable_SyncShadowValuesFunc*            _syncShadowValues = ZERO;
-
-   return (void*) _NodalPressureField_New(  NODALPRESSUREFIELD_PASSARGS  );
-}
-
-void _NodalPressureField_Delete( void* _self ) {
-   NodalPressureField* self = (NodalPressureField*) _self;
-
-   _ParticleFeVariable_Delete( self );
-}
-
-/*
-** Methods.
-*/
-
-void _NodalPressureField_Print( void* _self, Stream* stream ) {
-   NodalPressureField* self = (NodalPressureField*)_self;
-
-   /* General info */
-   Journal_Printf( stream, "NodalPressureField (ptr): %p\n", self );
-
-   /* Print parent */
-   _ParticleFeVariable_Print( self, stream );
-}
-
-void* _NodalPressureField_Copy( const void* _self, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-   abort();
-}
-
-void NodalPressureField_NonLinearUpdate( void* _sle, void* _ctx ) {
-   DomainContext*				ctx = (DomainContext*)_ctx;
-   FieldVariable_Register*	fieldVar_Register;
-   NodalPressureField*		preVar;
-
-   fieldVar_Register = ctx->fieldVariable_Register; 
-   preVar = (NodalPressureField*)FieldVariable_Register_GetByName( fieldVar_Register, "NodalPressureField" );
-   ParticleFeVariable_Update( preVar );
-}
-
-void _NodalPressureField_AssignFromXML( void* _self, Stg_ComponentFactory* cf, void* data ){
-   NodalPressureField*		self = (NodalPressureField*) _self;
-   Variable_Register*		variable_Register;
-   SystemLinearEquations*	sle;
-   FeVariable*					pressureField;
-
-   _ParticleFeVariable_AssignFromXML( self, cf, data );
-
-   variable_Register = self->variable_Register; 
-   assert( variable_Register );
-
-   pressureField = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"PressureField", FeVariable, True, data  );
-
-   /*
-   ** If we're using this field for non-linear feedback, we'll need to update it in between
-   ** non-linear iterations. */
-   sle = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"SLE", SystemLinearEquations, False, data  );
-
-   _NodalPressureField_Init( self, variable_Register, pressureField, sle );
-
-}
-
-void _NodalPressureField_Build( void* _self, void* data ) {
-   NodalPressureField* self = (NodalPressureField*) _self;
-   char *tmpName, *tmpName2;
-   Node_DomainIndex  node_I;
-
-   Stg_Component_Build( self->feMesh, data, False );
-
-   /* Create Variable to store data */
-   assert( Class_IsSuper( self->feMesh->topo, IGraph ) );
-   tmpName = Stg_Object_AppendSuffix( self, "DataVariable"  );
-   self->dataVariable = Variable_NewScalar( tmpName, (AbstractContext*)self->context, Variable_DataType_Double, (Index*)&((IGraph*)self->feMesh->topo)->remotes[MT_VERTEX]->nDomains, NULL, (void**)&self->data, self->variable_Register  );
-	
-   /* Create Dof Layout */
-   tmpName2 = Stg_Object_AppendSuffix( self, "DofLayout"  );
-   self->dofLayout = DofLayout_New( tmpName2, self->context, self->variable_Register, 0, self->feMesh );
-   self->dofLayout->_numItemsInLayout = FeMesh_GetNodeDomainSize( self->feMesh );
-   for( node_I = 0; node_I < FeMesh_GetNodeDomainSize( self->feMesh ); node_I++ ) {
-      DofLayout_AddDof_ByVarName( self->dofLayout, tmpName, node_I );
-   }
-   Memory_Free( tmpName );
-   Memory_Free( tmpName2 );
-   self->eqNum->dofLayout = self->dofLayout;
-
-   /* Build and Update all Variables that this component has created */
-   Stg_Component_Build( self->dataVariable, data, False); Variable_Update( self->dataVariable );
-   Stg_Component_Build( self->pressureField, data, False);
-
-   _ParticleFeVariable_Build( self, data );
-   /* Update again, just in case things were changed/reallocated when ICs loaded */
-   Variable_Update( self->dataVariable );
-}
-
-void _NodalPressureField_Initialise( void* _self, void* data ) {
-   NodalPressureField* self = (NodalPressureField*) _self;
-	
-   /* Initialise and Update all Variables that this component has created */
-   Stg_Component_Initialise( self->dataVariable, data, False); Variable_Update( self->dataVariable );
-   
-   Stg_Component_Initialise( self->pressureField, data, False);
-	
-   _ParticleFeVariable_Initialise( self, data );
-
-   /* Do a post-update just in case */
-   Variable_Update( self->dataVariable );
-
-}
-
-void _NodalPressureField_Execute( void* _self, void* data ) {
-   NodalPressureField* self = (NodalPressureField*) _self;
-
-   _ParticleFeVariable_Execute( self, data );
-}
-
-void _NodalPressureField_Destroy( void* _self, void* data ) {
-   NodalPressureField* self = (NodalPressureField*) _self;
-
-	Stg_Component_Destroy( self->pressureField, data, False);
-
-	_ParticleFeVariable_Destroy( self, data );
-}
-
-void _NodalPressureField_ValueAtParticle( void* _self, IntegrationPointsSwarm* swarm, Element_LocalIndex lElement_I, void* _particle, double* pressure ) {
-   NodalPressureField* self = (NodalPressureField*)_self;
-   IntegrationPoint* particle = (IntegrationPoint*)_particle;
-
-   FeVariable_InterpolateWithinElement( self->pressureField, lElement_I, particle->xi, pressure );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/NodalPressureField.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/NodalPressureField.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,202 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Monash Cluster Computing, Australia
+** (C) 2003-2004 All Rights Reserved
+**
+** Primary Authors:
+** Luke Hodkinson
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include <mpi.h>
+
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Rheology/Rheology.h>
+
+#include "types.h"
+#include "NodalPressureField.h"
+
+const Type NodalPressureField_Type = "NodalPressureField";
+
+/*
+** Constructors/Destructors.
+*/
+
+NodalPressureField* _NodalPressureField_New(  NODALPRESSUREFIELD_DEFARGS  ) {
+   NodalPressureField* self;
+
+   assert( _sizeOfSelf >= sizeof(NodalPressureField) );
+   self = (NodalPressureField*)_ParticleFeVariable_New(  PARTICLEFEVARIABLE_PASSARGS  );
+
+   return self;
+}
+
+void _NodalPressureField_Init( NodalPressureField* self, Variable_Register* variable_Register, FeVariable* pressureField, SystemLinearEquations* sle) {
+   self->variable_Register = variable_Register;
+   self->fieldComponentCount = 1;
+   self->pressureField = pressureField;
+   if( sle )
+      SystemLinearEquations_AddPostNonLinearEP( sle, NodalPressureField_Type, NodalPressureField_NonLinearUpdate );
+}
+
+void* _NodalPressureField_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                       _sizeOfSelf = sizeof(NodalPressureField);
+	Type                                                               type = NodalPressureField_Type;
+	Stg_Class_DeleteFunction*                                       _delete = _NodalPressureField_Delete;
+	Stg_Class_PrintFunction*                                         _print = _NodalPressureField_Print;
+	Stg_Class_CopyFunction*                                           _copy = _NodalPressureField_Copy;
+	Stg_Component_DefaultConstructorFunction*           _defaultConstructor = _NodalPressureField_DefaultNew;
+	Stg_Component_ConstructFunction*                             _construct = _NodalPressureField_AssignFromXML;
+	Stg_Component_BuildFunction*                                     _build = _NodalPressureField_Build;
+	Stg_Component_InitialiseFunction*                           _initialise = _NodalPressureField_Initialise;
+	Stg_Component_ExecuteFunction*                                 _execute = _NodalPressureField_Execute;
+	Stg_Component_DestroyFunction*                                 _destroy = _NodalPressureField_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 = _NodalPressureField_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 = ZERO;
+	FieldVariable_GetValueFunction*   _getMaxGlobalFieldMagnitude = ZERO;
+	FeVariable_SyncShadowValuesFunc*            _syncShadowValues = ZERO;
+
+   return (void*) _NodalPressureField_New(  NODALPRESSUREFIELD_PASSARGS  );
+}
+
+void _NodalPressureField_Delete( void* _self ) {
+   NodalPressureField* self = (NodalPressureField*) _self;
+
+   _ParticleFeVariable_Delete( self );
+}
+
+/*
+** Methods.
+*/
+
+void _NodalPressureField_Print( void* _self, Stream* stream ) {
+   NodalPressureField* self = (NodalPressureField*)_self;
+
+   /* General info */
+   Journal_Printf( stream, "NodalPressureField (ptr): %p\n", self );
+
+   /* Print parent */
+   _ParticleFeVariable_Print( self, stream );
+}
+
+void* _NodalPressureField_Copy( const void* _self, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+   abort();
+}
+
+void NodalPressureField_NonLinearUpdate( void* _sle, void* _ctx ) {
+   DomainContext*				ctx = (DomainContext*)_ctx;
+   FieldVariable_Register*	fieldVar_Register;
+   NodalPressureField*		preVar;
+
+   fieldVar_Register = ctx->fieldVariable_Register; 
+   preVar = (NodalPressureField*)FieldVariable_Register_GetByName( fieldVar_Register, "NodalPressureField" );
+   ParticleFeVariable_Update( preVar );
+}
+
+void _NodalPressureField_AssignFromXML( void* _self, Stg_ComponentFactory* cf, void* data ){
+   NodalPressureField*		self = (NodalPressureField*) _self;
+   Variable_Register*		variable_Register;
+   SystemLinearEquations*	sle;
+   FeVariable*					pressureField;
+
+   _ParticleFeVariable_AssignFromXML( self, cf, data );
+
+   variable_Register = self->variable_Register; 
+   assert( variable_Register );
+
+   pressureField = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"PressureField", FeVariable, True, data  );
+
+   /*
+   ** If we're using this field for non-linear feedback, we'll need to update it in between
+   ** non-linear iterations. */
+   sle = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"SLE", SystemLinearEquations, False, data  );
+
+   _NodalPressureField_Init( self, variable_Register, pressureField, sle );
+
+}
+
+void _NodalPressureField_Build( void* _self, void* data ) {
+   NodalPressureField* self = (NodalPressureField*) _self;
+   char *tmpName, *tmpName2;
+   Node_DomainIndex  node_I;
+
+   Stg_Component_Build( self->feMesh, data, False );
+
+   /* Create Variable to store data */
+   assert( Class_IsSuper( self->feMesh->topo, IGraph ) );
+   tmpName = Stg_Object_AppendSuffix( self, "DataVariable"  );
+   self->dataVariable = Variable_NewScalar( tmpName, (AbstractContext*)self->context, Variable_DataType_Double, (Index*)&((IGraph*)self->feMesh->topo)->remotes[MT_VERTEX]->nDomains, NULL, (void**)&self->data, self->variable_Register  );
+	
+   /* Create Dof Layout */
+   tmpName2 = Stg_Object_AppendSuffix( self, "DofLayout"  );
+   self->dofLayout = DofLayout_New( tmpName2, self->context, self->variable_Register, 0, self->feMesh );
+   self->dofLayout->_numItemsInLayout = FeMesh_GetNodeDomainSize( self->feMesh );
+   for( node_I = 0; node_I < FeMesh_GetNodeDomainSize( self->feMesh ); node_I++ ) {
+      DofLayout_AddDof_ByVarName( self->dofLayout, tmpName, node_I );
+   }
+   Memory_Free( tmpName );
+   Memory_Free( tmpName2 );
+   self->eqNum->dofLayout = self->dofLayout;
+
+   /* Build and Update all Variables that this component has created */
+   Stg_Component_Build( self->dataVariable, data, False); Variable_Update( self->dataVariable );
+   Stg_Component_Build( self->pressureField, data, False);
+
+   _ParticleFeVariable_Build( self, data );
+   /* Update again, just in case things were changed/reallocated when ICs loaded */
+   Variable_Update( self->dataVariable );
+}
+
+void _NodalPressureField_Initialise( void* _self, void* data ) {
+   NodalPressureField* self = (NodalPressureField*) _self;
+	
+   /* Initialise and Update all Variables that this component has created */
+   Stg_Component_Initialise( self->dataVariable, data, False); Variable_Update( self->dataVariable );
+   
+   Stg_Component_Initialise( self->pressureField, data, False);
+	
+   _ParticleFeVariable_Initialise( self, data );
+
+   /* Do a post-update just in case */
+   Variable_Update( self->dataVariable );
+
+}
+
+void _NodalPressureField_Execute( void* _self, void* data ) {
+   NodalPressureField* self = (NodalPressureField*) _self;
+
+   _ParticleFeVariable_Execute( self, data );
+}
+
+void _NodalPressureField_Destroy( void* _self, void* data ) {
+   NodalPressureField* self = (NodalPressureField*) _self;
+
+	Stg_Component_Destroy( self->pressureField, data, False);
+
+	_ParticleFeVariable_Destroy( self, data );
+}
+
+void _NodalPressureField_ValueAtParticle( void* _self, IntegrationPointsSwarm* swarm, Element_LocalIndex lElement_I, void* _particle, double* pressure ) {
+   NodalPressureField* self = (NodalPressureField*)_self;
+   IntegrationPoint* particle = (IntegrationPoint*)_particle;
+
+   FeVariable_InterpolateWithinElement( self->pressureField, lElement_I, particle->xi, pressure );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/REP_Algorithm.c
--- a/Utils/src/REP_Algorithm.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,532 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-** Copyright (c) 2007, 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:
-**		Julian Giordani - Julian.Giordani at sci.monash.edu.au
-**
-** Contributors:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+
-** $Id:  $
-** 
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-/*
- * The REP algorithm is desciped in the paper
- * 	B.Boroomand & O.C.Zienkiewicz, "An Improved REP Recovery and the Effectivity Robustness Test",
- * 	Int. J. for Numerical Methods in Engineering, vol. 40, pages 3247-3277, 1997.
- * 
- *
- * Phases of the REP_Algorithm in this code
- * 	1: Assemble element H and F
- * 	2: Communicate H and F elemental objects
- * 	3: Assemble patch matrix, A and rightside vector b
- * 	4: Solve Ax=b, where x is the patch Coefficients
- * 	5: Communicate proc boundary coefficient for completeness with respect to domain recoveries
- *  6: Perform a final sync of the node values at proc-boundary domain-edge nodes <br/>
- */ 
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Underworld.h>
-
-#include "types.h"
-#include "BaseRecoveryFeVar.h"
-#include "RecoveredFeVariable.h"
-#include "REP_Algorithm.h"
-
-#include <assert.h>
-#include <string.h>
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type REP_Algorithm_Type = "REP_Algorithm";
-char*  NameOfPatch;
-void* _REP_Algorithm_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(REP_Algorithm);
-	Type                                                      type = REP_Algorithm_Type;
-	Stg_Class_DeleteFunction*                              _delete = _REP_Algorithm_Delete;
-	Stg_Class_PrintFunction*                                _print = _REP_Algorithm_Print;
-	Stg_Class_CopyFunction*                                  _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _REP_Algorithm_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _REP_Algorithm_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _REP_Algorithm_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _REP_Algorithm_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _REP_Algorithm_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _REP_Algorithm_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*)_REP_Algorithm_New(  REP_ALGORITHM_PASSARGS  );
-}
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-REP_Algorithm* _REP_Algorithm_New(  REP_ALGORITHM_DEFARGS  )
-{
-	REP_Algorithm* self;
-	
-	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-	assert( _sizeOfSelf >= sizeof(REP_Algorithm) );
-	/* 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 = (REP_Algorithm*) _Stg_Component_New(  STG_COMPONENT_PASSARGS  );
-
-	return self;
-}
-
-
-void _REP_Algorithm_Delete( void* patchRecoveryFeVariable ) {
-}
-
-void _REP_Algorithm_Print( void* patchRecoveryFeVariable, Stream* stream ) {
-
-}
-
-void _REP_Algorithm_Init( void* rep, 
-			  UnderworldContext* context )
-{
-   REP_Algorithm* self = (REP_Algorithm*)rep;
-
-#if PATCH_DEBUG
-   char* filename;
-   self->myStream = Journal_Register( Info_Type, (Name)self->type  );
-   Stg_asprintf( &filename, "FieldRecovery-Output.%dof%d.dat", context->rank, context->nproc );
-   Stream_RedirectFile_WithPrependedPath( self->myStream, context->outputPath, filename );
-   Memory_Free( filename );
-#endif
-
-   self->context = context;
-   ContextEP_Append_AlwaysLast( context, "stokesEqn-execute", _REP_Algorithm_Execute );
-   NameOfPatch = self->name;
-
-   self->incArray = IArray_New();
-}
-
-
-void _REP_Algorithm_AssignFromXML( void* patchRecoveryFeVariable, Stg_ComponentFactory* cf, void* data ) {
-   REP_Algorithm*          self     = (REP_Algorithm*)patchRecoveryFeVariable;
-   UnderworldContext*      context = NULL;
-   Dictionary*             dictionary = Dictionary_GetDictionary( cf->componentDict, self->name );
-   Dictionary_Entry_Value* list;
-   char*                   varName;
-   Stream*                 errorStream = Journal_Register( Error_Type, (Name)"_REP_Algorithm_Construct"  );
-   int field_I, listCount;
-
-	self->IPswarm         = NULL;
-
-	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", UnderworldContext, False, data );
-	if( !context  )
-		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data  );
-
-  list = Dictionary_Get( dictionary, (Dictionary_Entry_Key)"RepFieldList"  );
-  Journal_Firewall(
-			list != NULL,
-			errorStream,
-			"Error in %s:\n"
-			"You must specify a list of RecoveredFeVariable in your xml.\nExample:\n"
-			"<list name=\"RepFieldList\">\n"
-				"\t<param>recoveredSigmaField</param>\n"
-			"</list>\n", __func__ );
-	
-	listCount = Dictionary_Entry_Value_GetCount( list );
-  Journal_Firewall(
-			listCount != 0,
-			errorStream,
-			"Error in %s:\n"
-			"You have no RecoveredFeVariable defined in the RepFieldList list. At least one RecoveredFeVariable must be included.\nExample:\n"
-			"<list name=\"RepFieldList\">\n"
-				"\t<param>recoveredSigmaField</param>\n"
-			"</list>\n", __func__ );
-	
-	/* Allocate the memory to store pointers */
-	self->repFieldList = Memory_Alloc_Array( RecoveredFeVariable*, listCount, "List RecoveredFeVariable" );
-
-	/* get all the rep fields from the dictionary */
-	for( field_I = 0 ; field_I < listCount ; field_I++ ) {
-		varName = Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetElement( list, field_I ) );
-		self->repFieldList[ field_I ] = Stg_ComponentFactory_ConstructByName( cf, (Name)varName, RecoveredFeVariable, True, data  );
-	}
-
-	self->constitutiveMatrix = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"ConstitutiveMatrix", ConstitutiveMatrix, True, data );
-
-	if(self->constitutiveMatrix ) { 
-    /* implicitly get from constitutiveMatrix dictionary */
-		self->IPswarm = Stg_ComponentFactory_ConstructByKey( cf, self->constitutiveMatrix->name, (Dictionary_Entry_Key)"Swarm", IntegrationPointsSwarm, True, data  );
-
-		/* check if any of the repFields require the storeConstitutiveMatrix, if so turnOn */
-		for( field_I = 0 ; field_I < listCount ; field_I++ ) {
-			if( self->repFieldList[field_I]->nonLinearProblem == True ) { 
-				self->constitutiveMatrix->storeConstitutiveMatrix = True;
-				ConstitutiveMatrixCartesian_SetupParticleStorage( (ConstitutiveMatrixCartesian*)self->constitutiveMatrix );
-				/* only need to do the above once if we need it */
-				break;
-			}
-		}
-	}
-	else {
-    /* explicitly get from component dictionary */
-		self->IPswarm = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"IntegrationPoints", IntegrationPointsSwarm, True, data  );
-	}
-
-  self->repFieldCount = listCount;
-
-	_REP_Algorithm_Init( self, context );
-}
-
-void _REP_Algorithm_Build( void* patchRecoveryFeVariable, void* data ) {
-   REP_Algorithm* self = (REP_Algorithm*)patchRecoveryFeVariable;
-   int xx;
-	
-   Stg_Component_Build( self->IPswarm, data, False );
-   Stg_Component_Build( self->constitutiveMatrix, data, False );
-   for( xx = 0 ; xx < self->repFieldCount ; xx++ )
-      Stg_Component_Build( self->repFieldList[xx], data, False );
-}
-
-void _REP_Algorithm_Initialise( void* patchRecoveryFeVariable, void* data ) {
-	REP_Algorithm* self = (REP_Algorithm*)patchRecoveryFeVariable;
-	int xx;
-	
-   Stg_Component_Initialise( self->IPswarm, data, False );
-   Stg_Component_Initialise( self->constitutiveMatrix, data, False );
-	for( xx = 0 ; xx < self->repFieldCount ; xx++ )
-		Stg_Component_Initialise( self->repFieldList[xx], data, False );
-}
-
-void _REP_Algorithm_Execute( void* patch, void* data ) {
-  /* Fuction Description: is the driver of the main algorithm
-   * All repFields associated with this component will be
-   * are executed in the below functions 
-   */
-	UnderworldContext* context = (UnderworldContext*)data;
-	REP_Algorithm* self = (REP_Algorithm*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)NameOfPatch );
-	double startTime;
-	int field_I;
-	assert( self );
-
-	/* TODO: Optimisation question. Is this a test and do function or a straigh do function */
-   for( field_I = 0 ; field_I < Stg_ObjectList_Count( repRequiredRawFields_Reg ); field_I++ )
-      FeVariable_SyncShadowValues( (FeVariable* )Stg_ObjectList_At( repRequiredRawFields_Reg, field_I ) );
-
-	MPI_Barrier(MPI_COMM_WORLD);
-
-	startTime = MPI_Wtime();
-	Journal_RPrintf( Journal_Register( Info_Type, (Name)"REP" ),
-			"Start Recovery Method\n" );
-		
-  /* Phases of the REP_Algorithm in this code */
-
-  /* 1: Assemble element H and F */
-    _REP_Algorithm_AssembleAllLocalElement( self );	
-  /* 2: Communicate H and F elemental objects */
-    _REP_Algorithm_Communicate( self );
-  /* 3: Assemble patch matrix, A and rightside vector b and solve for x*/
-    _REP_Algorithm_SolvePatches( self );
-  /* 4: Communicate proc boundary coefficient for completeness with respect to domain recoveries */
-    _REP_Algorithm_CommunicateBoundaries( self );
-  /* 5: Calculate the Boundary values */
-    _REP_Algorithm_Boundaries( self );
-  /* 6: Perform a final sync for new proc boundary domain edge nodes */
-    _REP_Algorithm_CommunicateBoundaries( self );
-
-		Journal_RPrintf( Journal_Register( Info_Type, (Name)"REP" ),
-				"Time Taken for Recovery Method %f\n", MPI_Wtime()-startTime);
-}
-
-void _REP_Algorithm_Destroy( void* rep, void* data ) {
-  REP_Algorithm* self = (REP_Algorithm*)rep;
-  int xx;
-
-   Stg_Component_Destroy( self->IPswarm, data, False );
-   Stg_Component_Destroy( self->constitutiveMatrix, data, False );
-	NewClass_Delete( self->incArray );
-	
-	for( xx = 0 ; xx < self->repFieldCount ; xx++ )
-		Stg_Component_Destroy( self->repFieldList[xx], data, False );
-
-	Memory_Free( self->repFieldList );
-}
-
-void _REP_Algorithm_CommunicateBoundaries( REP_Algorithm* self ) {
-	int field_I;
-	for( field_I = 0 ; field_I < self->repFieldCount ; field_I++ ) 
-		_FeVariable_SyncShadowValues( self->repFieldList[field_I] );
-}
-
-void _REP_Algorithm_Boundaries( REP_Algorithm* self ) {
-	int field_I;
-	for( field_I = 0 ; field_I < self->repFieldCount ; field_I++ ) 
-		_BaseRecoveryFeVar_Boundaries( self->repFieldList[field_I] );
-
-}
-
-void _REP_Algorithm_SolvePatches( REP_Algorithm* self ) {
-	int elList[20]/*TODO is maxNumberOfElementAroundApatch*/, nEl, node_I, nLocalNodes, field_I;
-	LmStruct lmStruct;
-
-	nLocalNodes = FeMesh_GetNodeLocalSize( self->repFieldList[0]->feMesh );
-
-	for( field_I = 0 ; field_I < self->repFieldCount ; field_I++ ) 
-		RecoveredFeVariable_SetupWorkSpace( self->repFieldList[field_I] );
-
-	for( node_I = 0 ; node_I < nLocalNodes ; node_I++ ) {
-		if( self->repFieldList[0]->bninfo[node_I].onMeshBoundary ) /*TODO: only uses 1st mesh*/
-			continue;
-		REP_Algorithm_MakeLM( self->repFieldList[0]->feMesh, node_I, elList, &nEl, &lmStruct );
-		/* for each recovered field */
-		for( field_I = 0 ; field_I < self->repFieldCount ; field_I++ )
-			RecoveredFeVariable_SolvePatch( self->repFieldList[field_I], node_I, elList, nEl, &lmStruct );
-	}
-	for( field_I = 0 ; field_I < self->repFieldCount ; field_I++ )
-		RecoveredFeVariable_RemoveWorkSpace( self->repFieldList[field_I] );
-}
-void _REP_Algorithm_Communicate( REP_Algorithm* self ) {
-	int field_I;
-	for( field_I = 0 ; field_I < self->repFieldCount ; field_I++ )
-		RecoveredFeVariable_CommunicateHF( self->repFieldList[field_I] );
-}
-
-void REP_Algorithm_MakeLM( FeMesh* mesh, int lPatchID, int *elList, int* nEl, LmStruct* lmStruct ) {
-	/* Fuction Description: populates the 
-	 * elList = the elements surrounding patchNode
-	 * nEl = the number of elements surrounding 
-	 * lm  = location matrix (ordering) needed of Sys Linear Eq. REP uses
-	 */
-	int   el_I, node_I, nodesPerEl, *nodeList;
-	Index dElID, dNodeID;
-	IArray *inc_E, *inc_N;
-
-	/* 1) Initialisation of Location Matrix datastructure */
-	lmStruct->numberOfNodes = 0;
-	memset( lmStruct->nodeIDList, -1, sizeof(int)*REP_MAXNODESPERPATCH );
-
-	inc_E = IArray_New();
-	inc_N = IArray_New();
-  /* 2) find the elements around the node and put in elList */
-	FeMesh_GetNodeElements( mesh, lPatchID, inc_E );
-	*nEl = IArray_GetSize( inc_E );
-	memcpy(elList, IArray_GetPtr( inc_E ), *nEl*sizeof(unsigned) );
-
-	/* 3) foreach element find each node which will form patch
-	 * and save in lmStruct */
-	for( el_I = 0 ; el_I < *nEl ; el_I++ ) {
-		dElID = elList[ el_I ];
-		FeMesh_GetElementNodes( mesh, dElID, inc_N );
-		nodesPerEl = IArray_GetSize( inc_N );
-		nodeList = IArray_GetPtr( inc_N );
-		for( node_I = 0 ; node_I < nodesPerEl ; node_I++ ) {
-			dNodeID = nodeList[node_I];
-			if( el_I == 0 ) {
-				/* This is just a speed-up condition for large meshes
-				 * it can be ignored altogether and you can just run the else condition,
-				 * but it's a poor search algorithm */
-				lmStruct->nodeIDList[ lmStruct->numberOfNodes ] = dNodeID;
-				lmStruct->numberOfNodes++;
-			} else {
-				/* if nodeID NOT in table
-					   then add nodeID to table
-				*/
-				if( _REP_Algorithm_locateInPatchListStruct( lmStruct, dNodeID ) == -1 ) {
-					lmStruct->nodeIDList[ lmStruct->numberOfNodes ] = dNodeID;
-					lmStruct->numberOfNodes++;
-				}
-			}
-		}	 
-	}
-	NewClass_Delete( inc_N );
-	NewClass_Delete( inc_E );
-}
-
-int _REP_Algorithm_locateInPatchListStruct( LmStruct* lmStruct, int nodeID ) {
-	/*TODO: This is a linear search, could take a while for 3-D meshes, especially if non-square elements are used 
-	 * should change it to quicker search */
-	int node_I;
-	for( node_I = 0 ; node_I < lmStruct->numberOfNodes ; node_I++ ){
-		if( lmStruct->nodeIDList[ node_I ] == nodeID ) 
-			return node_I;
-	}
-	return -1;
-}
-
-void _REP_Algorithm_ZeroHiFi( REP_Algorithm* self, double*** elHi_Mat, double*** elFi_Mat ) {
-  /* Function Describption: zeros the Hi and Fi memory spaces */
-	/* TODO: Can only do one repFieldList element now */
-	int components           = self->repFieldList[0]->fieldComponentCount;
-	int dim                  = self->repFieldList[0]->dim;
-	int order = self->repFieldList[0]->orderOfInterpolation;
-	int nodesPerEl           = self->repFieldList[0]->nodesPerEl;
-	int comp_I, dim_I, node_I;
-	
-	for( comp_I = 0 ; comp_I < components ; comp_I++ ) {
-		for( dim_I = 0 ; dim_I < dim; dim_I++ ) 
-			memset( elHi_Mat[comp_I][dim_I], 0, order*sizeof(double) );
-		for( node_I = 0 ; node_I < nodesPerEl; node_I++ ) 
-			memset( elFi_Mat[comp_I][node_I], 0, dim*sizeof(double) );
-	}
-}
-void _REP_Algorithm_AssembleAllLocalElement( REP_Algorithm* self ) {
-  /* Function Describption: assembles all local element H and F objects for each
-   * repField associated with this REP_Algorithm
-   */
-  double**** elHi_Mat;
-  double*** elFi_Mat;
-  double** p_pVec, **GNx;
-  int field_I, lElement_I, repFieldCount, numberLocalElements;
-
-  repFieldCount = self->repFieldCount;
-	elHi_Mat = Memory_Alloc_Array( double***, repFieldCount, "localElement_HiPerField" );
-	elFi_Mat = Memory_Alloc_Array( double**, repFieldCount, "localElement_FiPerField" );
-	p_pVec = Memory_Alloc_Array( double*, repFieldCount, "position polynomialPerField" );
-	/* Assume GNx this the same for all fields */
-	GNx = Memory_Alloc_2DArray( double, self->repFieldList[0]->dim, REP_MAXNODESPERPATCH, (Name)"GNx" );
-	numberLocalElements = FeMesh_GetElementLocalSize( self->repFieldList[0]->feMesh );
-
-	for( field_I = 0 ; field_I < self->repFieldCount ; field_I++  ) {
-		/* TODO assumes constant nodesPerEl across domain */
-		elHi_Mat[field_I] = Memory_Alloc_3DArray( double, self->repFieldList[field_I]->fieldComponentCount, self->repFieldList[field_I]->dim * self->repFieldList[field_I]->nodesPerEl, self->repFieldList[field_I]->orderOfInterpolation, (Name)"localElement_Hi"  );
-		elFi_Mat[field_I] = Memory_Alloc_2DArray( double, self->repFieldList[field_I]->fieldComponentCount, self->repFieldList[field_I]->dim * self->repFieldList[field_I]->nodesPerEl, (Name)"localElement_Fi" );
-		p_pVec[field_I] = Memory_Alloc_Array( double, self->repFieldList[field_I]->orderOfInterpolation, "position polynomial" );
-	}
-
-	/* go throught all local elements */
-	for( lElement_I = 0 ; lElement_I < numberLocalElements ; lElement_I++ ) {
-		/* Zero temp data structures */
-		for( field_I = 0 ; field_I < self->repFieldCount ; field_I++ )
-			_RecoveredFeVariable_ZeroHiFi( self->repFieldList[field_I], elHi_Mat[field_I], elFi_Mat[field_I] );
-
-		_REP_Algorithm_AssembleElement( self, lElement_I, elHi_Mat, elFi_Mat, p_pVec, GNx );
-
-		/* incorporate Hi_Mat and Fi_Mat into proc size arrays */
-		for( field_I = 0 ; field_I < self->repFieldCount ; field_I++ ) 
-			self->repFieldList[field_I]->_putElIntoProc( self->repFieldList[field_I], lElement_I, elHi_Mat[field_I], elFi_Mat[field_I] );
-	}
-
-	for( field_I = 0 ; field_I < self->repFieldCount ; field_I++ ) {
-		Memory_Free( elHi_Mat[field_I] );
-		Memory_Free( elFi_Mat[field_I] ); 
-		Memory_Free( p_pVec[field_I] );	
-	}
-	Memory_Free( elHi_Mat );
-	Memory_Free( elFi_Mat ); 
-	Memory_Free( p_pVec );
-	Memory_Free( GNx );
-}
-
-void _REP_Algorithm_AssembleElement( REP_Algorithm* self, int lElement_I, double**** Hi_Mat, double*** Fi_Mat, double** p_pVec, double** GNx ) {
-	IntegrationPointsSwarm* swarm = self->IPswarm;
-	FeMesh*                 mesh = self->repFieldList[0]->rawField->feMesh;
-	ElementType*            elementType;
-	IntegrationPoint*       particle;
- 	double globalCoord[3], detJac;
-	int cell_I, cellParticleCount, nodesPerEl, cParticle_I;
-	/* Only need one */
-	int dim = self->repFieldList[0]->dim;
-	int field_I;
-
-	/* Get the element type */
-	elementType = FeMesh_GetElementType( mesh, lElement_I );
-
-	/* Get the number of nodes per element */
-	FeMesh_GetElementNodes( mesh, lElement_I, self->incArray );
-	nodesPerEl = IArray_GetSize( self->incArray );
-
-	/* Get number of particles per element */
-	cell_I = CellLayout_MapElementIdToCellId( swarm->cellLayout, lElement_I );
-	cellParticleCount = swarm->cellParticleCountTbl[ cell_I ];
-
-	for( cParticle_I = 0 ; cParticle_I < cellParticleCount ; cParticle_I++ ) {
-		particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );	
-
-		/* calculate derivatives on particles */
-		ElementType_ShapeFunctionsGlobalDerivs( elementType, 
-							mesh, 
-							lElement_I,
-							particle->xi,
-							dim,
-							&detJac, GNx );
-		/* put particle co-ords into polynomial */
-		FeMesh_CoordLocalToGlobal( mesh, lElement_I, particle->xi, globalCoord );
-
-		for( field_I = 0 ; field_I < self->repFieldCount ; field_I++ )  {
-			_RecoveredFeVariable_AssembleAtParticle( self->repFieldList[field_I], self->constitutiveMatrix, 
-					self->constitutiveMatrix->currentParticleIndex, particle, lElement_I, 
-					globalCoord, (double**)GNx, detJac, Hi_Mat[field_I], Fi_Mat[field_I]);
-
-			/* could be a useful functionPtr later on, JG 12May09
-			self->repFieldList[field_I]->_assembleOnParticle( self->repFieldList[field_I], self->constitutiveMatrix, 
-					self->constitutiveMatrix->currentParticleIndex, particle, lElement_I, 
-					globalCoord, (double**)GNx, detJac, Hi_Mat[field_I], Fi_Mat[field_I]);
-					*/
-		}
-
-	}
-}
-
-void _REP_Algorithm_Solver(double **array, double* bVec, int n) {
-	/* Function Description: Calls the actual lapack function to solve the small dense linear system Ax=b */
-	int i,j, info, LDA, LDB, N, NRHS;
-	
-	int* IPIV = Memory_Alloc_Array( int, n, "IPIV" ); 
-	double* AT = Memory_Alloc_Array( double, n * n , "AT" ); 
-	assert( IPIV );
-	assert( AT );
-	/* must transform, because LAPACK uses Fortran 
-	 * transform AMatrix in A Column */
-	for( i = 0 ; i < n ; i++ ) {
-		for( j = 0 ; j < n ; j++ ) {
-			AT[ (i * n) + j ] = array[j][i];
-		}
-	}
-		
-	NRHS = 1;
-	N = LDA = LDB = n;
-	dgesv_( &N, &NRHS, AT, &LDA, IPIV, bVec, &LDB, &info);
-
-	Journal_Firewall( info == 0, Journal_Register( Error_Type, (Name)"error_REP"  ), "Error: In %s looks like the lapack solver (DGESV) died with the error code %d. Could be due to ill-conditioned matrix ... I advise that you manually print the results of the matrices that lapack uses or contact a developer.\n", __func__, info);
-	Memory_Free(IPIV);
-	Memory_Free(AT);
-}
-
-
-
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/REP_Algorithm.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/REP_Algorithm.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,532 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** Copyright (c) 2007, 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:
+**		Julian Giordani - Julian.Giordani at sci.monash.edu.au
+**
+** Contributors:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+
+** $Id:  $
+** 
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+/*
+ * The REP algorithm is desciped in the paper
+ * 	B.Boroomand & O.C.Zienkiewicz, "An Improved REP Recovery and the Effectivity Robustness Test",
+ * 	Int. J. for Numerical Methods in Engineering, vol. 40, pages 3247-3277, 1997.
+ * 
+ *
+ * Phases of the REP_Algorithm in this code
+ * 	1: Assemble element H and F
+ * 	2: Communicate H and F elemental objects
+ * 	3: Assemble patch matrix, A and rightside vector b
+ * 	4: Solve Ax=b, where x is the patch Coefficients
+ * 	5: Communicate proc boundary coefficient for completeness with respect to domain recoveries
+ *  6: Perform a final sync of the node values at proc-boundary domain-edge nodes <br/>
+ */ 
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Underworld.h>
+
+#include "types.h"
+#include "BaseRecoveryFeVar.h"
+#include "RecoveredFeVariable.h"
+#include "REP_Algorithm.h"
+
+#include <assert.h>
+#include <string.h>
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type REP_Algorithm_Type = "REP_Algorithm";
+char*  NameOfPatch;
+void* _REP_Algorithm_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(REP_Algorithm);
+	Type                                                      type = REP_Algorithm_Type;
+	Stg_Class_DeleteFunction*                              _delete = _REP_Algorithm_Delete;
+	Stg_Class_PrintFunction*                                _print = _REP_Algorithm_Print;
+	Stg_Class_CopyFunction*                                  _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _REP_Algorithm_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _REP_Algorithm_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _REP_Algorithm_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _REP_Algorithm_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _REP_Algorithm_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _REP_Algorithm_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*)_REP_Algorithm_New(  REP_ALGORITHM_PASSARGS  );
+}
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+REP_Algorithm* _REP_Algorithm_New(  REP_ALGORITHM_DEFARGS  )
+{
+	REP_Algorithm* self;
+	
+	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+	assert( _sizeOfSelf >= sizeof(REP_Algorithm) );
+	/* 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 = (REP_Algorithm*) _Stg_Component_New(  STG_COMPONENT_PASSARGS  );
+
+	return self;
+}
+
+
+void _REP_Algorithm_Delete( void* patchRecoveryFeVariable ) {
+}
+
+void _REP_Algorithm_Print( void* patchRecoveryFeVariable, Stream* stream ) {
+
+}
+
+void _REP_Algorithm_Init( void* rep, 
+			  UnderworldContext* context )
+{
+   REP_Algorithm* self = (REP_Algorithm*)rep;
+
+#if PATCH_DEBUG
+   char* filename;
+   self->myStream = Journal_Register( Info_Type, (Name)self->type  );
+   Stg_asprintf( &filename, "FieldRecovery-Output.%dof%d.dat", context->rank, context->nproc );
+   Stream_RedirectFile_WithPrependedPath( self->myStream, context->outputPath, filename );
+   Memory_Free( filename );
+#endif
+
+   self->context = context;
+   ContextEP_Append_AlwaysLast( context, "stokesEqn-execute", _REP_Algorithm_Execute );
+   NameOfPatch = self->name;
+
+   self->incArray = IArray_New();
+}
+
+
+void _REP_Algorithm_AssignFromXML( void* patchRecoveryFeVariable, Stg_ComponentFactory* cf, void* data ) {
+   REP_Algorithm*          self     = (REP_Algorithm*)patchRecoveryFeVariable;
+   UnderworldContext*      context = NULL;
+   Dictionary*             dictionary = Dictionary_GetDictionary( cf->componentDict, self->name );
+   Dictionary_Entry_Value* list;
+   char*                   varName;
+   Stream*                 errorStream = Journal_Register( Error_Type, (Name)"_REP_Algorithm_Construct"  );
+   int field_I, listCount;
+
+	self->IPswarm         = NULL;
+
+	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", UnderworldContext, False, data );
+	if( !context  )
+		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data  );
+
+  list = Dictionary_Get( dictionary, (Dictionary_Entry_Key)"RepFieldList"  );
+  Journal_Firewall(
+			list != NULL,
+			errorStream,
+			"Error in %s:\n"
+			"You must specify a list of RecoveredFeVariable in your xml.\nExample:\n"
+			"<list name=\"RepFieldList\">\n"
+				"\t<param>recoveredSigmaField</param>\n"
+			"</list>\n", __func__ );
+	
+	listCount = Dictionary_Entry_Value_GetCount( list );
+  Journal_Firewall(
+			listCount != 0,
+			errorStream,
+			"Error in %s:\n"
+			"You have no RecoveredFeVariable defined in the RepFieldList list. At least one RecoveredFeVariable must be included.\nExample:\n"
+			"<list name=\"RepFieldList\">\n"
+				"\t<param>recoveredSigmaField</param>\n"
+			"</list>\n", __func__ );
+	
+	/* Allocate the memory to store pointers */
+	self->repFieldList = Memory_Alloc_Array( RecoveredFeVariable*, listCount, "List RecoveredFeVariable" );
+
+	/* get all the rep fields from the dictionary */
+	for( field_I = 0 ; field_I < listCount ; field_I++ ) {
+		varName = Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetElement( list, field_I ) );
+		self->repFieldList[ field_I ] = Stg_ComponentFactory_ConstructByName( cf, (Name)varName, RecoveredFeVariable, True, data  );
+	}
+
+	self->constitutiveMatrix = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"ConstitutiveMatrix", ConstitutiveMatrix, True, data );
+
+	if(self->constitutiveMatrix ) { 
+    /* implicitly get from constitutiveMatrix dictionary */
+		self->IPswarm = Stg_ComponentFactory_ConstructByKey( cf, self->constitutiveMatrix->name, (Dictionary_Entry_Key)"Swarm", IntegrationPointsSwarm, True, data  );
+
+		/* check if any of the repFields require the storeConstitutiveMatrix, if so turnOn */
+		for( field_I = 0 ; field_I < listCount ; field_I++ ) {
+			if( self->repFieldList[field_I]->nonLinearProblem == True ) { 
+				self->constitutiveMatrix->storeConstitutiveMatrix = True;
+				ConstitutiveMatrixCartesian_SetupParticleStorage( (ConstitutiveMatrixCartesian*)self->constitutiveMatrix );
+				/* only need to do the above once if we need it */
+				break;
+			}
+		}
+	}
+	else {
+    /* explicitly get from component dictionary */
+		self->IPswarm = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"IntegrationPoints", IntegrationPointsSwarm, True, data  );
+	}
+
+  self->repFieldCount = listCount;
+
+	_REP_Algorithm_Init( self, context );
+}
+
+void _REP_Algorithm_Build( void* patchRecoveryFeVariable, void* data ) {
+   REP_Algorithm* self = (REP_Algorithm*)patchRecoveryFeVariable;
+   int xx;
+	
+   Stg_Component_Build( self->IPswarm, data, False );
+   Stg_Component_Build( self->constitutiveMatrix, data, False );
+   for( xx = 0 ; xx < self->repFieldCount ; xx++ )
+      Stg_Component_Build( self->repFieldList[xx], data, False );
+}
+
+void _REP_Algorithm_Initialise( void* patchRecoveryFeVariable, void* data ) {
+	REP_Algorithm* self = (REP_Algorithm*)patchRecoveryFeVariable;
+	int xx;
+	
+   Stg_Component_Initialise( self->IPswarm, data, False );
+   Stg_Component_Initialise( self->constitutiveMatrix, data, False );
+	for( xx = 0 ; xx < self->repFieldCount ; xx++ )
+		Stg_Component_Initialise( self->repFieldList[xx], data, False );
+}
+
+void _REP_Algorithm_Execute( void* patch, void* data ) {
+  /* Fuction Description: is the driver of the main algorithm
+   * All repFields associated with this component will be
+   * are executed in the below functions 
+   */
+	UnderworldContext* context = (UnderworldContext*)data;
+	REP_Algorithm* self = (REP_Algorithm*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)NameOfPatch );
+	double startTime;
+	int field_I;
+	assert( self );
+
+	/* TODO: Optimisation question. Is this a test and do function or a straigh do function */
+   for( field_I = 0 ; field_I < Stg_ObjectList_Count( repRequiredRawFields_Reg ); field_I++ )
+      FeVariable_SyncShadowValues( (FeVariable* )Stg_ObjectList_At( repRequiredRawFields_Reg, field_I ) );
+
+	MPI_Barrier(MPI_COMM_WORLD);
+
+	startTime = MPI_Wtime();
+	Journal_RPrintf( Journal_Register( Info_Type, (Name)"REP" ),
+			"Start Recovery Method\n" );
+		
+  /* Phases of the REP_Algorithm in this code */
+
+  /* 1: Assemble element H and F */
+    _REP_Algorithm_AssembleAllLocalElement( self );	
+  /* 2: Communicate H and F elemental objects */
+    _REP_Algorithm_Communicate( self );
+  /* 3: Assemble patch matrix, A and rightside vector b and solve for x*/
+    _REP_Algorithm_SolvePatches( self );
+  /* 4: Communicate proc boundary coefficient for completeness with respect to domain recoveries */
+    _REP_Algorithm_CommunicateBoundaries( self );
+  /* 5: Calculate the Boundary values */
+    _REP_Algorithm_Boundaries( self );
+  /* 6: Perform a final sync for new proc boundary domain edge nodes */
+    _REP_Algorithm_CommunicateBoundaries( self );
+
+		Journal_RPrintf( Journal_Register( Info_Type, (Name)"REP" ),
+				"Time Taken for Recovery Method %f\n", MPI_Wtime()-startTime);
+}
+
+void _REP_Algorithm_Destroy( void* rep, void* data ) {
+  REP_Algorithm* self = (REP_Algorithm*)rep;
+  int xx;
+
+   Stg_Component_Destroy( self->IPswarm, data, False );
+   Stg_Component_Destroy( self->constitutiveMatrix, data, False );
+	NewClass_Delete( self->incArray );
+	
+	for( xx = 0 ; xx < self->repFieldCount ; xx++ )
+		Stg_Component_Destroy( self->repFieldList[xx], data, False );
+
+	Memory_Free( self->repFieldList );
+}
+
+void _REP_Algorithm_CommunicateBoundaries( REP_Algorithm* self ) {
+	int field_I;
+	for( field_I = 0 ; field_I < self->repFieldCount ; field_I++ ) 
+		_FeVariable_SyncShadowValues( self->repFieldList[field_I] );
+}
+
+void _REP_Algorithm_Boundaries( REP_Algorithm* self ) {
+	int field_I;
+	for( field_I = 0 ; field_I < self->repFieldCount ; field_I++ ) 
+		_BaseRecoveryFeVar_Boundaries( self->repFieldList[field_I] );
+
+}
+
+void _REP_Algorithm_SolvePatches( REP_Algorithm* self ) {
+	int elList[20]/*TODO is maxNumberOfElementAroundApatch*/, nEl, node_I, nLocalNodes, field_I;
+	LmStruct lmStruct;
+
+	nLocalNodes = FeMesh_GetNodeLocalSize( self->repFieldList[0]->feMesh );
+
+	for( field_I = 0 ; field_I < self->repFieldCount ; field_I++ ) 
+		RecoveredFeVariable_SetupWorkSpace( self->repFieldList[field_I] );
+
+	for( node_I = 0 ; node_I < nLocalNodes ; node_I++ ) {
+		if( self->repFieldList[0]->bninfo[node_I].onMeshBoundary ) /*TODO: only uses 1st mesh*/
+			continue;
+		REP_Algorithm_MakeLM( self->repFieldList[0]->feMesh, node_I, elList, &nEl, &lmStruct );
+		/* for each recovered field */
+		for( field_I = 0 ; field_I < self->repFieldCount ; field_I++ )
+			RecoveredFeVariable_SolvePatch( self->repFieldList[field_I], node_I, elList, nEl, &lmStruct );
+	}
+	for( field_I = 0 ; field_I < self->repFieldCount ; field_I++ )
+		RecoveredFeVariable_RemoveWorkSpace( self->repFieldList[field_I] );
+}
+void _REP_Algorithm_Communicate( REP_Algorithm* self ) {
+	int field_I;
+	for( field_I = 0 ; field_I < self->repFieldCount ; field_I++ )
+		RecoveredFeVariable_CommunicateHF( self->repFieldList[field_I] );
+}
+
+void REP_Algorithm_MakeLM( FeMesh* mesh, int lPatchID, int *elList, int* nEl, LmStruct* lmStruct ) {
+	/* Fuction Description: populates the 
+	 * elList = the elements surrounding patchNode
+	 * nEl = the number of elements surrounding 
+	 * lm  = location matrix (ordering) needed of Sys Linear Eq. REP uses
+	 */
+	int   el_I, node_I, nodesPerEl, *nodeList;
+	Index dElID, dNodeID;
+	IArray *inc_E, *inc_N;
+
+	/* 1) Initialisation of Location Matrix datastructure */
+	lmStruct->numberOfNodes = 0;
+	memset( lmStruct->nodeIDList, -1, sizeof(int)*REP_MAXNODESPERPATCH );
+
+	inc_E = IArray_New();
+	inc_N = IArray_New();
+  /* 2) find the elements around the node and put in elList */
+	FeMesh_GetNodeElements( mesh, lPatchID, inc_E );
+	*nEl = IArray_GetSize( inc_E );
+	memcpy(elList, IArray_GetPtr( inc_E ), *nEl*sizeof(unsigned) );
+
+	/* 3) foreach element find each node which will form patch
+	 * and save in lmStruct */
+	for( el_I = 0 ; el_I < *nEl ; el_I++ ) {
+		dElID = elList[ el_I ];
+		FeMesh_GetElementNodes( mesh, dElID, inc_N );
+		nodesPerEl = IArray_GetSize( inc_N );
+		nodeList = IArray_GetPtr( inc_N );
+		for( node_I = 0 ; node_I < nodesPerEl ; node_I++ ) {
+			dNodeID = nodeList[node_I];
+			if( el_I == 0 ) {
+				/* This is just a speed-up condition for large meshes
+				 * it can be ignored altogether and you can just run the else condition,
+				 * but it's a poor search algorithm */
+				lmStruct->nodeIDList[ lmStruct->numberOfNodes ] = dNodeID;
+				lmStruct->numberOfNodes++;
+			} else {
+				/* if nodeID NOT in table
+					   then add nodeID to table
+				*/
+				if( _REP_Algorithm_locateInPatchListStruct( lmStruct, dNodeID ) == -1 ) {
+					lmStruct->nodeIDList[ lmStruct->numberOfNodes ] = dNodeID;
+					lmStruct->numberOfNodes++;
+				}
+			}
+		}	 
+	}
+	NewClass_Delete( inc_N );
+	NewClass_Delete( inc_E );
+}
+
+int _REP_Algorithm_locateInPatchListStruct( LmStruct* lmStruct, int nodeID ) {
+	/*TODO: This is a linear search, could take a while for 3-D meshes, especially if non-square elements are used 
+	 * should change it to quicker search */
+	int node_I;
+	for( node_I = 0 ; node_I < lmStruct->numberOfNodes ; node_I++ ){
+		if( lmStruct->nodeIDList[ node_I ] == nodeID ) 
+			return node_I;
+	}
+	return -1;
+}
+
+void _REP_Algorithm_ZeroHiFi( REP_Algorithm* self, double*** elHi_Mat, double*** elFi_Mat ) {
+  /* Function Describption: zeros the Hi and Fi memory spaces */
+	/* TODO: Can only do one repFieldList element now */
+	int components           = self->repFieldList[0]->fieldComponentCount;
+	int dim                  = self->repFieldList[0]->dim;
+	int order = self->repFieldList[0]->orderOfInterpolation;
+	int nodesPerEl           = self->repFieldList[0]->nodesPerEl;
+	int comp_I, dim_I, node_I;
+	
+	for( comp_I = 0 ; comp_I < components ; comp_I++ ) {
+		for( dim_I = 0 ; dim_I < dim; dim_I++ ) 
+			memset( elHi_Mat[comp_I][dim_I], 0, order*sizeof(double) );
+		for( node_I = 0 ; node_I < nodesPerEl; node_I++ ) 
+			memset( elFi_Mat[comp_I][node_I], 0, dim*sizeof(double) );
+	}
+}
+void _REP_Algorithm_AssembleAllLocalElement( REP_Algorithm* self ) {
+  /* Function Describption: assembles all local element H and F objects for each
+   * repField associated with this REP_Algorithm
+   */
+  double**** elHi_Mat;
+  double*** elFi_Mat;
+  double** p_pVec, **GNx;
+  int field_I, lElement_I, repFieldCount, numberLocalElements;
+
+  repFieldCount = self->repFieldCount;
+	elHi_Mat = Memory_Alloc_Array( double***, repFieldCount, "localElement_HiPerField" );
+	elFi_Mat = Memory_Alloc_Array( double**, repFieldCount, "localElement_FiPerField" );
+	p_pVec = Memory_Alloc_Array( double*, repFieldCount, "position polynomialPerField" );
+	/* Assume GNx this the same for all fields */
+	GNx = Memory_Alloc_2DArray( double, self->repFieldList[0]->dim, REP_MAXNODESPERPATCH, (Name)"GNx" );
+	numberLocalElements = FeMesh_GetElementLocalSize( self->repFieldList[0]->feMesh );
+
+	for( field_I = 0 ; field_I < self->repFieldCount ; field_I++  ) {
+		/* TODO assumes constant nodesPerEl across domain */
+		elHi_Mat[field_I] = Memory_Alloc_3DArray( double, self->repFieldList[field_I]->fieldComponentCount, self->repFieldList[field_I]->dim * self->repFieldList[field_I]->nodesPerEl, self->repFieldList[field_I]->orderOfInterpolation, (Name)"localElement_Hi"  );
+		elFi_Mat[field_I] = Memory_Alloc_2DArray( double, self->repFieldList[field_I]->fieldComponentCount, self->repFieldList[field_I]->dim * self->repFieldList[field_I]->nodesPerEl, (Name)"localElement_Fi" );
+		p_pVec[field_I] = Memory_Alloc_Array( double, self->repFieldList[field_I]->orderOfInterpolation, "position polynomial" );
+	}
+
+	/* go throught all local elements */
+	for( lElement_I = 0 ; lElement_I < numberLocalElements ; lElement_I++ ) {
+		/* Zero temp data structures */
+		for( field_I = 0 ; field_I < self->repFieldCount ; field_I++ )
+			_RecoveredFeVariable_ZeroHiFi( self->repFieldList[field_I], elHi_Mat[field_I], elFi_Mat[field_I] );
+
+		_REP_Algorithm_AssembleElement( self, lElement_I, elHi_Mat, elFi_Mat, p_pVec, GNx );
+
+		/* incorporate Hi_Mat and Fi_Mat into proc size arrays */
+		for( field_I = 0 ; field_I < self->repFieldCount ; field_I++ ) 
+			self->repFieldList[field_I]->_putElIntoProc( self->repFieldList[field_I], lElement_I, elHi_Mat[field_I], elFi_Mat[field_I] );
+	}
+
+	for( field_I = 0 ; field_I < self->repFieldCount ; field_I++ ) {
+		Memory_Free( elHi_Mat[field_I] );
+		Memory_Free( elFi_Mat[field_I] ); 
+		Memory_Free( p_pVec[field_I] );	
+	}
+	Memory_Free( elHi_Mat );
+	Memory_Free( elFi_Mat ); 
+	Memory_Free( p_pVec );
+	Memory_Free( GNx );
+}
+
+void _REP_Algorithm_AssembleElement( REP_Algorithm* self, int lElement_I, double**** Hi_Mat, double*** Fi_Mat, double** p_pVec, double** GNx ) {
+	IntegrationPointsSwarm* swarm = self->IPswarm;
+	FeMesh*                 mesh = self->repFieldList[0]->rawField->feMesh;
+	ElementType*            elementType;
+	IntegrationPoint*       particle;
+ 	double globalCoord[3], detJac;
+	int cell_I, cellParticleCount, nodesPerEl, cParticle_I;
+	/* Only need one */
+	int dim = self->repFieldList[0]->dim;
+	int field_I;
+
+	/* Get the element type */
+	elementType = FeMesh_GetElementType( mesh, lElement_I );
+
+	/* Get the number of nodes per element */
+	FeMesh_GetElementNodes( mesh, lElement_I, self->incArray );
+	nodesPerEl = IArray_GetSize( self->incArray );
+
+	/* Get number of particles per element */
+	cell_I = CellLayout_MapElementIdToCellId( swarm->cellLayout, lElement_I );
+	cellParticleCount = swarm->cellParticleCountTbl[ cell_I ];
+
+	for( cParticle_I = 0 ; cParticle_I < cellParticleCount ; cParticle_I++ ) {
+		particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );	
+
+		/* calculate derivatives on particles */
+		ElementType_ShapeFunctionsGlobalDerivs( elementType, 
+							mesh, 
+							lElement_I,
+							particle->xi,
+							dim,
+							&detJac, GNx );
+		/* put particle co-ords into polynomial */
+		FeMesh_CoordLocalToGlobal( mesh, lElement_I, particle->xi, globalCoord );
+
+		for( field_I = 0 ; field_I < self->repFieldCount ; field_I++ )  {
+			_RecoveredFeVariable_AssembleAtParticle( self->repFieldList[field_I], self->constitutiveMatrix, 
+					self->constitutiveMatrix->currentParticleIndex, particle, lElement_I, 
+					globalCoord, (double**)GNx, detJac, Hi_Mat[field_I], Fi_Mat[field_I]);
+
+			/* could be a useful functionPtr later on, JG 12May09
+			self->repFieldList[field_I]->_assembleOnParticle( self->repFieldList[field_I], self->constitutiveMatrix, 
+					self->constitutiveMatrix->currentParticleIndex, particle, lElement_I, 
+					globalCoord, (double**)GNx, detJac, Hi_Mat[field_I], Fi_Mat[field_I]);
+					*/
+		}
+
+	}
+}
+
+void _REP_Algorithm_Solver(double **array, double* bVec, int n) {
+	/* Function Description: Calls the actual lapack function to solve the small dense linear system Ax=b */
+	int i,j, info, LDA, LDB, N, NRHS;
+	
+	int* IPIV = Memory_Alloc_Array( int, n, "IPIV" ); 
+	double* AT = Memory_Alloc_Array( double, n * n , "AT" ); 
+	assert( IPIV );
+	assert( AT );
+	/* must transform, because LAPACK uses Fortran 
+	 * transform AMatrix in A Column */
+	for( i = 0 ; i < n ; i++ ) {
+		for( j = 0 ; j < n ; j++ ) {
+			AT[ (i * n) + j ] = array[j][i];
+		}
+	}
+		
+	NRHS = 1;
+	N = LDA = LDB = n;
+	dgesv_( &N, &NRHS, AT, &LDA, IPIV, bVec, &LDB, &info);
+
+	Journal_Firewall( info == 0, Journal_Register( Error_Type, (Name)"error_REP"  ), "Error: In %s looks like the lapack solver (DGESV) died with the error code %d. Could be due to ill-conditioned matrix ... I advise that you manually print the results of the matrices that lapack uses or contact a developer.\n", __func__, info);
+	Memory_Free(IPIV);
+	Memory_Free(AT);
+}
+
+
+
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/RadiogenicHeatingTerm.c
--- a/Utils/src/RadiogenicHeatingTerm.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,234 +0,0 @@
-
-
-#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/Utils/Utils.h>
-
-#include "types.h"
-#include "RadiogenicHeatingTerm.h"
-
-#include <assert.h>
-#include <string.h>
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type RadiogenicHeatingTerm_Type = "RadiogenicHeatingTerm";
-
-RadiogenicHeatingTerm* RadiogenicHeatingTerm_New( 
-	Name							name,
-	FiniteElementContext*	context,
-	ForceVector*				forceVector,
-	Swarm*						integrationSwarm,
-	Materials_Register*		materials_Register )
-{
-	RadiogenicHeatingTerm* self = (RadiogenicHeatingTerm*) _RadiogenicHeatingTerm_DefaultNew( name );
-
-	self->isConstructed = True;
-	_ForceTerm_Init( self, context, forceVector, integrationSwarm, NULL );
-	_RadiogenicHeatingTerm_Init( self, materials_Register );
-
-	return self;
-}
-
-/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
-RadiogenicHeatingTerm* _RadiogenicHeatingTerm_New(  RADIOGENICHEATINGTERM_DEFARGS  )
-{
-	RadiogenicHeatingTerm* self;
-	
-	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-	assert( _sizeOfSelf >= sizeof(RadiogenicHeatingTerm) );
-	/* 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 = (RadiogenicHeatingTerm*) _ForceTerm_New(  FORCETERM_PASSARGS  );
-	
-	/* Function pointers for this class that are not on the parent class should be set here */
-	
-	return self;
-}
-
-void _RadiogenicHeatingTerm_Init( void* forceTerm, Materials_Register* materials_Register ) {
-	RadiogenicHeatingTerm* self = (RadiogenicHeatingTerm*)forceTerm;
-
-	self->materials_Register = materials_Register;
-}
-
-void _RadiogenicHeatingTerm_Delete( void* forceTerm ) {
-	RadiogenicHeatingTerm* self = (RadiogenicHeatingTerm*)forceTerm;
-
-	_ForceTerm_Delete( self );
-}
-
-void _RadiogenicHeatingTerm_Print( void* forceTerm, Stream* stream ) {
-	RadiogenicHeatingTerm* self = (RadiogenicHeatingTerm*)forceTerm;
-	
-	_ForceTerm_Print( self, stream );
-
-	/* General info */
-	Journal_PrintPointer( stream, self->materials_Register );
-	Journal_PrintPointer( stream, self->context );
-}
-
-void* _RadiogenicHeatingTerm_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(RadiogenicHeatingTerm);
-	Type                                                      type = RadiogenicHeatingTerm_Type;
-	Stg_Class_DeleteFunction*                              _delete = _RadiogenicHeatingTerm_Delete;
-	Stg_Class_PrintFunction*                                _print = _RadiogenicHeatingTerm_Print;
-	Stg_Class_CopyFunction*                                  _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _RadiogenicHeatingTerm_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _RadiogenicHeatingTerm_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _RadiogenicHeatingTerm_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _RadiogenicHeatingTerm_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _RadiogenicHeatingTerm_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _RadiogenicHeatingTerm_Destroy;
-	ForceTerm_AssembleElementFunction*            _assembleElement = _RadiogenicHeatingTerm_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*)_RadiogenicHeatingTerm_New(  RADIOGENICHEATINGTERM_PASSARGS  );
-}
-
-void _RadiogenicHeatingTerm_AssignFromXML( void* forceTerm, Stg_ComponentFactory* cf, void* data ) {
-	RadiogenicHeatingTerm*	self = (RadiogenicHeatingTerm*)forceTerm;
-	Materials_Register*		materials_Register;
-
-	/* Construct Parent */
-	_ForceTerm_AssignFromXML( self, cf, data );
-
-	materials_Register = ((PICelleratorContext*)self->context)->materials_Register; 
-	assert( materials_Register );
-
-	_RadiogenicHeatingTerm_Init( self, materials_Register );
-}
-
-void _RadiogenicHeatingTerm_Build( void* forceTerm, void* data ) {
-	RadiogenicHeatingTerm*               self               = (RadiogenicHeatingTerm*)forceTerm;
-	RadiogenicHeatingTerm_MaterialExt*   materialExt;
-	Material_Index                       material_I;
-	Material*                            material;
-	HeatingElement*                      heatingElement;
-	Index                                heatingElement_I;
-	Index                                heatingElementCount;
-	Dictionary_Entry_Value*              list;
-	Dictionary_Entry_Value*              entry;
-	Materials_Register*                  materials_Register = self->materials_Register;
-	Stream*                              errorStream = Journal_Register( Error_Type, (Name)self->type  );
-
-	_ForceTerm_Build( self, data );
-
-	/* Sort out material extension stuff */
-	self->materialExtHandle = Materials_Register_AddMaterialExtension( self->materials_Register, self->type, sizeof(RadiogenicHeatingTerm_MaterialExt) );
-
-	for ( material_I = 0 ; material_I < Materials_Register_GetCount( materials_Register ) ; material_I++) {
-		material = Materials_Register_GetByIndex( materials_Register, material_I );
-		materialExt = (RadiogenicHeatingTerm_MaterialExt*)ExtensionManager_GetFunc( material->extensionMgr, material, self->materialExtHandle );
-
-		/* Get List of Heating Elements from material's dictionary */
-		list = Dictionary_Get( material->dictionary, (Dictionary_Entry_Key)"heatingElements" );
-                Journal_Firewall(list!=NULL,errorStream,"Every material must have a heatingElements term.\nThe material '%s' does not have one.",
-                                 material->name);
-  		heatingElementCount = Dictionary_Entry_Value_GetCount( list  );
-                materialExt->heatingElementList = Memory_Alloc_Array( HeatingElement, heatingElementCount, "Heating Element" );
-  		memset( materialExt->heatingElementList, 0, heatingElementCount * sizeof(HeatingElement) );
-  		materialExt->heatingElementCount = heatingElementCount;
-  	
-  		for ( heatingElement_I = 0 ; heatingElement_I < heatingElementCount ; heatingElement_I++) { 
-			heatingElement = &materialExt->heatingElementList[ heatingElement_I ];
-  			entry = Dictionary_Entry_Value_GetElement( list, heatingElement_I );
-	    	
-   		heatingElement->Q = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( entry, (Dictionary_Entry_Key)"Q") );
-   		heatingElement->lambda = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( entry, (Dictionary_Entry_Key)"lambda") );
-	   }
-	}
-}
-
-void _RadiogenicHeatingTerm_Initialise( void* forceTerm, void* data ) {
-	RadiogenicHeatingTerm* self = (RadiogenicHeatingTerm*)forceTerm;
-
-	_ForceTerm_Initialise( self, data );
-}
-
-void _RadiogenicHeatingTerm_Execute( void* forceTerm, void* data ) {
-	RadiogenicHeatingTerm* self = (RadiogenicHeatingTerm*)forceTerm;
-
-	_ForceTerm_Execute( self, data );
-}
-
-void _RadiogenicHeatingTerm_Destroy( void* forceTerm, void* data ) {
-	RadiogenicHeatingTerm* self = (RadiogenicHeatingTerm*)forceTerm;
-
-	_ForceTerm_Destroy( self, data );
-}
-
-
-void _RadiogenicHeatingTerm_AssembleElement( void* forceTerm, ForceVector* forceVector, Element_LocalIndex lElement_I, double* elForceVec ) {
-	RadiogenicHeatingTerm*               self               = (RadiogenicHeatingTerm*) forceTerm;
-	IntegrationPoint*                    particle;
-	RadiogenicHeatingTerm_MaterialExt*   materialExt;
-	Particle_InCellIndex                 cParticle_I;
-	Particle_InCellIndex                 cellParticleCount;
-	Element_NodeIndex                    elementNodeCount;
-	Dimension_Index                      dim                = forceVector->dim;
-	Swarm*                               swarm              = self->integrationSwarm;
-	FeMesh*       		             mesh               = forceVector->feVariable->feMesh;
-	Node_ElementLocalIndex               eNode_I;
-	Cell_Index                           cell_I;
-	ElementType*                         elementType;
-	double                               detJac             = 0.0;
-	double                               factor;
-	double                               Ni[27];
-	double                               radiogenicHeating;
-	double*                              xi;
-	Material*                            material;
-	double                               time               = self->context->currentTime;
-	HeatingElement*                      heatingElement;
-	Index                                heatingElementCount;
-	Index                                heatingElement_I;
-
-	elementType       = FeMesh_GetElementType( mesh, lElement_I );
-	elementNodeCount  = elementType->nodeCount;
-	cell_I            = CellLayout_MapElementIdToCellId( swarm->cellLayout, lElement_I );
-	cellParticleCount = swarm->cellParticleCountTbl[cell_I];
-
-	for( cParticle_I = 0 ; cParticle_I < cellParticleCount ; cParticle_I++ ) {
-		particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
-
-		/* Get parameters */
-		material = IntegrationPointsSwarm_GetMaterialOn( (IntegrationPointsSwarm*)swarm, particle );
-		materialExt = (RadiogenicHeatingTerm_MaterialExt*)ExtensionManager_Get( material->extensionMgr, material, self->materialExtHandle );
-		
-		/* Check if this material has heating term */
-		heatingElementCount = materialExt->heatingElementCount;
-		if ( heatingElementCount == 0 )
-			continue;
-
-		/* Calculate Radiogenic Heating */
-		radiogenicHeating = 0.0;
-        	for ( heatingElement_I = 0 ; heatingElement_I < heatingElementCount ; heatingElement_I++ ) {
-			heatingElement = &materialExt->heatingElementList[ heatingElement_I ];
-	        	radiogenicHeating += heatingElement->Q * exp(-heatingElement->lambda * (time));
-		}
-
-		/* Get Values to det integration */
-		xi  = particle->xi;
-		detJac = ElementType_JacobianDeterminant( elementType, mesh, lElement_I, xi, dim );
-		ElementType_EvaluateShapeFunctionsAt( elementType, xi, Ni );
-
-		/* Apply heating term */
-		factor = detJac * particle->weight * radiogenicHeating;
-		for( eNode_I = 0 ; eNode_I < elementNodeCount; eNode_I++ ) { 		
-			elForceVec[ eNode_I ] += factor * Ni[ eNode_I ] ;
-		}
-	}
-}
-
-
-
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/RadiogenicHeatingTerm.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/RadiogenicHeatingTerm.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,234 @@
+
+
+#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/Utils/Utils.h>
+
+#include "types.h"
+#include "RadiogenicHeatingTerm.h"
+
+#include <assert.h>
+#include <string.h>
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type RadiogenicHeatingTerm_Type = "RadiogenicHeatingTerm";
+
+RadiogenicHeatingTerm* RadiogenicHeatingTerm_New( 
+	Name							name,
+	FiniteElementContext*	context,
+	ForceVector*				forceVector,
+	Swarm*						integrationSwarm,
+	Materials_Register*		materials_Register )
+{
+	RadiogenicHeatingTerm* self = (RadiogenicHeatingTerm*) _RadiogenicHeatingTerm_DefaultNew( name );
+
+	self->isConstructed = True;
+	_ForceTerm_Init( self, context, forceVector, integrationSwarm, NULL );
+	_RadiogenicHeatingTerm_Init( self, materials_Register );
+
+	return self;
+}
+
+/* Private Constructor: This will accept all the virtual functions for this class as arguments. */
+RadiogenicHeatingTerm* _RadiogenicHeatingTerm_New(  RADIOGENICHEATINGTERM_DEFARGS  )
+{
+	RadiogenicHeatingTerm* self;
+	
+	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+	assert( _sizeOfSelf >= sizeof(RadiogenicHeatingTerm) );
+	/* 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 = (RadiogenicHeatingTerm*) _ForceTerm_New(  FORCETERM_PASSARGS  );
+	
+	/* Function pointers for this class that are not on the parent class should be set here */
+	
+	return self;
+}
+
+void _RadiogenicHeatingTerm_Init( void* forceTerm, Materials_Register* materials_Register ) {
+	RadiogenicHeatingTerm* self = (RadiogenicHeatingTerm*)forceTerm;
+
+	self->materials_Register = materials_Register;
+}
+
+void _RadiogenicHeatingTerm_Delete( void* forceTerm ) {
+	RadiogenicHeatingTerm* self = (RadiogenicHeatingTerm*)forceTerm;
+
+	_ForceTerm_Delete( self );
+}
+
+void _RadiogenicHeatingTerm_Print( void* forceTerm, Stream* stream ) {
+	RadiogenicHeatingTerm* self = (RadiogenicHeatingTerm*)forceTerm;
+	
+	_ForceTerm_Print( self, stream );
+
+	/* General info */
+	Journal_PrintPointer( stream, self->materials_Register );
+	Journal_PrintPointer( stream, self->context );
+}
+
+void* _RadiogenicHeatingTerm_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(RadiogenicHeatingTerm);
+	Type                                                      type = RadiogenicHeatingTerm_Type;
+	Stg_Class_DeleteFunction*                              _delete = _RadiogenicHeatingTerm_Delete;
+	Stg_Class_PrintFunction*                                _print = _RadiogenicHeatingTerm_Print;
+	Stg_Class_CopyFunction*                                  _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _RadiogenicHeatingTerm_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _RadiogenicHeatingTerm_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _RadiogenicHeatingTerm_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _RadiogenicHeatingTerm_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _RadiogenicHeatingTerm_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _RadiogenicHeatingTerm_Destroy;
+	ForceTerm_AssembleElementFunction*            _assembleElement = _RadiogenicHeatingTerm_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*)_RadiogenicHeatingTerm_New(  RADIOGENICHEATINGTERM_PASSARGS  );
+}
+
+void _RadiogenicHeatingTerm_AssignFromXML( void* forceTerm, Stg_ComponentFactory* cf, void* data ) {
+	RadiogenicHeatingTerm*	self = (RadiogenicHeatingTerm*)forceTerm;
+	Materials_Register*		materials_Register;
+
+	/* Construct Parent */
+	_ForceTerm_AssignFromXML( self, cf, data );
+
+	materials_Register = ((PICelleratorContext*)self->context)->materials_Register; 
+	assert( materials_Register );
+
+	_RadiogenicHeatingTerm_Init( self, materials_Register );
+}
+
+void _RadiogenicHeatingTerm_Build( void* forceTerm, void* data ) {
+	RadiogenicHeatingTerm*               self               = (RadiogenicHeatingTerm*)forceTerm;
+	RadiogenicHeatingTerm_MaterialExt*   materialExt;
+	Material_Index                       material_I;
+	Material*                            material;
+	HeatingElement*                      heatingElement;
+	Index                                heatingElement_I;
+	Index                                heatingElementCount;
+	Dictionary_Entry_Value*              list;
+	Dictionary_Entry_Value*              entry;
+	Materials_Register*                  materials_Register = self->materials_Register;
+	Stream*                              errorStream = Journal_Register( Error_Type, (Name)self->type  );
+
+	_ForceTerm_Build( self, data );
+
+	/* Sort out material extension stuff */
+	self->materialExtHandle = Materials_Register_AddMaterialExtension( self->materials_Register, self->type, sizeof(RadiogenicHeatingTerm_MaterialExt) );
+
+	for ( material_I = 0 ; material_I < Materials_Register_GetCount( materials_Register ) ; material_I++) {
+		material = Materials_Register_GetByIndex( materials_Register, material_I );
+		materialExt = (RadiogenicHeatingTerm_MaterialExt*)ExtensionManager_GetFunc( material->extensionMgr, material, self->materialExtHandle );
+
+		/* Get List of Heating Elements from material's dictionary */
+		list = Dictionary_Get( material->dictionary, (Dictionary_Entry_Key)"heatingElements" );
+                Journal_Firewall(list!=NULL,errorStream,"Every material must have a heatingElements term.\nThe material '%s' does not have one.",
+                                 material->name);
+  		heatingElementCount = Dictionary_Entry_Value_GetCount( list  );
+                materialExt->heatingElementList = Memory_Alloc_Array( HeatingElement, heatingElementCount, "Heating Element" );
+  		memset( materialExt->heatingElementList, 0, heatingElementCount * sizeof(HeatingElement) );
+  		materialExt->heatingElementCount = heatingElementCount;
+  	
+  		for ( heatingElement_I = 0 ; heatingElement_I < heatingElementCount ; heatingElement_I++) { 
+			heatingElement = &materialExt->heatingElementList[ heatingElement_I ];
+  			entry = Dictionary_Entry_Value_GetElement( list, heatingElement_I );
+	    	
+   		heatingElement->Q = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( entry, (Dictionary_Entry_Key)"Q") );
+   		heatingElement->lambda = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( entry, (Dictionary_Entry_Key)"lambda") );
+	   }
+	}
+}
+
+void _RadiogenicHeatingTerm_Initialise( void* forceTerm, void* data ) {
+	RadiogenicHeatingTerm* self = (RadiogenicHeatingTerm*)forceTerm;
+
+	_ForceTerm_Initialise( self, data );
+}
+
+void _RadiogenicHeatingTerm_Execute( void* forceTerm, void* data ) {
+	RadiogenicHeatingTerm* self = (RadiogenicHeatingTerm*)forceTerm;
+
+	_ForceTerm_Execute( self, data );
+}
+
+void _RadiogenicHeatingTerm_Destroy( void* forceTerm, void* data ) {
+	RadiogenicHeatingTerm* self = (RadiogenicHeatingTerm*)forceTerm;
+
+	_ForceTerm_Destroy( self, data );
+}
+
+
+void _RadiogenicHeatingTerm_AssembleElement( void* forceTerm, ForceVector* forceVector, Element_LocalIndex lElement_I, double* elForceVec ) {
+	RadiogenicHeatingTerm*               self               = (RadiogenicHeatingTerm*) forceTerm;
+	IntegrationPoint*                    particle;
+	RadiogenicHeatingTerm_MaterialExt*   materialExt;
+	Particle_InCellIndex                 cParticle_I;
+	Particle_InCellIndex                 cellParticleCount;
+	Element_NodeIndex                    elementNodeCount;
+	Dimension_Index                      dim                = forceVector->dim;
+	Swarm*                               swarm              = self->integrationSwarm;
+	FeMesh*       		             mesh               = forceVector->feVariable->feMesh;
+	Node_ElementLocalIndex               eNode_I;
+	Cell_Index                           cell_I;
+	ElementType*                         elementType;
+	double                               detJac             = 0.0;
+	double                               factor;
+	double                               Ni[27];
+	double                               radiogenicHeating;
+	double*                              xi;
+	Material*                            material;
+	double                               time               = self->context->currentTime;
+	HeatingElement*                      heatingElement;
+	Index                                heatingElementCount;
+	Index                                heatingElement_I;
+
+	elementType       = FeMesh_GetElementType( mesh, lElement_I );
+	elementNodeCount  = elementType->nodeCount;
+	cell_I            = CellLayout_MapElementIdToCellId( swarm->cellLayout, lElement_I );
+	cellParticleCount = swarm->cellParticleCountTbl[cell_I];
+
+	for( cParticle_I = 0 ; cParticle_I < cellParticleCount ; cParticle_I++ ) {
+		particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
+
+		/* Get parameters */
+		material = IntegrationPointsSwarm_GetMaterialOn( (IntegrationPointsSwarm*)swarm, particle );
+		materialExt = (RadiogenicHeatingTerm_MaterialExt*)ExtensionManager_Get( material->extensionMgr, material, self->materialExtHandle );
+		
+		/* Check if this material has heating term */
+		heatingElementCount = materialExt->heatingElementCount;
+		if ( heatingElementCount == 0 )
+			continue;
+
+		/* Calculate Radiogenic Heating */
+		radiogenicHeating = 0.0;
+        	for ( heatingElement_I = 0 ; heatingElement_I < heatingElementCount ; heatingElement_I++ ) {
+			heatingElement = &materialExt->heatingElementList[ heatingElement_I ];
+	        	radiogenicHeating += heatingElement->Q * exp(-heatingElement->lambda * (time));
+		}
+
+		/* Get Values to det integration */
+		xi  = particle->xi;
+		detJac = ElementType_JacobianDeterminant( elementType, mesh, lElement_I, xi, dim );
+		ElementType_EvaluateShapeFunctionsAt( elementType, xi, Ni );
+
+		/* Apply heating term */
+		factor = detJac * particle->weight * radiogenicHeating;
+		for( eNode_I = 0 ; eNode_I < elementNodeCount; eNode_I++ ) { 		
+			elForceVec[ eNode_I ] += factor * Ni[ eNode_I ] ;
+		}
+	}
+}
+
+
+
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/RecoveredFeVariable.c
--- a/Utils/src/RecoveredFeVariable.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,745 +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: RecoveredFeVariable.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 "Underworld/Rheology/Rheology.h"
-
-#include "types.h"
-#include "BaseRecoveryFeVar.h"
-#include "RecoveredFeVariable.h"
-#include "REP_Algorithm.h"
-
-#include <math.h>
-#include <assert.h>
-#include <string.h>
-
-const Type RecoveredFeVariable_Type = "RecoveredFeVariable";
-
-void* _RecoveredFeVariable_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(RecoveredFeVariable);
-	Type                                                      type = RecoveredFeVariable_Type;
-	Stg_Class_DeleteFunction*                              _delete = _RecoveredFeVariable_Delete;
-	Stg_Class_PrintFunction*                                _print = _RecoveredFeVariable_Print;
-	Stg_Class_CopyFunction*                                  _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _RecoveredFeVariable_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _RecoveredFeVariable_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _RecoveredFeVariable_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _RecoveredFeVariable_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _RecoveredFeVariable_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _RecoveredFeVariable_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 = (AllocationType)ZERO;
-	FieldVariable_InterpolateValueAtFunction*             _interpolateValueAt = ZERO;
-	FieldVariable_GetValueFunction*               _getMinGlobalFieldMagnitude = ZERO;
-	FieldVariable_GetValueFunction*               _getMaxGlobalFieldMagnitude = ZERO;
-	FieldVariable_GetCoordFunction*                  _getMinAndMaxLocalCoords = ZERO;
-	FieldVariable_GetCoordFunction*                 _getMinAndMaxGlobalCoords = ZERO;
-	FeVariable_InterpolateWithinElementFunction*    _interpolateWithinElement = ZERO;
-	FeVariable_GetValueAtNodeFunction*                        _getValueAtNode = ZERO;
-	FeVariable_SyncShadowValuesFunc*                        _syncShadowValues = ZERO;
-
-	return (void*)_RecoveredFeVariable_New(  RECOVEREDFEVARIABLE_PASSARGS  );
-}
-
-RecoveredFeVariable* _RecoveredFeVariable_New(  RECOVEREDFEVARIABLE_DEFARGS  )
-{
-	RecoveredFeVariable*		self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(RecoveredFeVariable) );
-	self = (RecoveredFeVariable*)
-		_BaseRecoveryFeVar_New(  BASERECOVERYFEVAR_PASSARGS  );
-
-	return self;
-}
-
-/* --- Virtual Function Implementations --- */
-void _RecoveredFeVariable_Delete( void* recFeVariable ) {
-	RecoveredFeVariable* self = (RecoveredFeVariable*) recFeVariable;
-	_BaseRecoveryFeVar_Delete( self );
-}
-
-void _RecoveredFeVariable_Print( void* recFeVariable, Stream* stream ) {
-	RecoveredFeVariable* self = (RecoveredFeVariable*) recFeVariable;
-	
-	/* General info */
-	Journal_Printf( stream, "RecoveredFeVariable (ptr): %p\n", self );
-	
-	/* Print parent */
-	_FeVariable_Print( self, stream );
-	
-	/* RecoveredFeVariable info */
-}
-
-void* _RecoveredFeVariable_Copy( const void* recFeVariable, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	abort();
-}
-
-void _RecoveredFeVariable_Init( RecoveredFeVariable* self, StiffnessMatrix* stiffnessMatrix, FeVariable* rawPressureField, FeVariable* velGradField, Bool refreshMeshConnectivity, Bool recoverStrain ) {
-	/* Setup basic pointers and functionPtrs that are specific to problem spec  */
-
-	self->rawPressureField = rawPressureField;
-	self->velGradField = velGradField;
-	self->refreshMeshConnectivity = refreshMeshConnectivity;
-	self->recoverStrain = recoverStrain;
-	self->fieldComponentCount = StGermain_nSymmetricTensorVectorComponents(self->dim);
-   self->nonLinearProblem = stiffnessMatrix->isNonLinear;
-
-	/* assign functionPtrs for 2D and 3D here */
-	if( self->dim == 2 ) {    
-		self->_calcHi = _RecoveredFeVariable_CalcHi2D;
-		self->_calcFi = _RecoveredFeVariable_CalcFi2D;
-		self->nodesInPatch = 9; /*TODO is static, should be dynamic later */
-	} else {
-		self->_calcHi =	_RecoveredFeVariable_CalcHi3D;
-		self->_calcFi =	_RecoveredFeVariable_CalcFi3D;
-		self->nodesInPatch = 27; /*TODO is static, should be dynamic later */
-	}
-
-	self->coeffCount = self->orderOfInterpolation * self->fieldComponentCount;
-}
-
-void _RecoveredFeVariable_AssignFromXML( void* recFeVariable, Stg_ComponentFactory* cf, void* data ) {
-   RecoveredFeVariable*  self        = (RecoveredFeVariable*) recFeVariable;
-   StiffnessMatrix*      stiffnessMatrix = NULL;
-   FeVariable*           rawPressureField = NULL;
-   FeVariable*           velGradField = NULL;
-   Bool                  refreshMeshConnectivity, recoverStrain, recoverPressure;
-
-   _BaseRecoveryFeVar_AssignFromXML( self, cf, data );
-
-   /* assume there this always a stiffness matrix called k_matrix */
-   stiffnessMatrix = Stg_ComponentFactory_ConstructByName( cf, (Name)"k_matrix", StiffnessMatrix, True, data  ); 
-
-   recoverPressure = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"recoverPressure", True ); 
-   if( recoverPressure == True  ) {
-      rawPressureField = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"RawPressureField", FeVariable, True, data );
-      /* record the rawField that is required on the repRequired_RawField register */
-      if( (unsigned )-1 == Stg_ObjectList_GetIndex( repRequiredRawFields_Reg, rawPressureField->name ) )
-         Stg_ObjectList_Append( repRequiredRawFields_Reg, rawPressureField );
-   }
-
-   velGradField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityGradientsField", FeVariable, False, data  );
-
-   refreshMeshConnectivity = Stg_ComponentFactory_GetBool( cf, self->name , (Dictionary_Entry_Key)"refreshMeshConnectivity", False  );
-   recoverStrain = Stg_ComponentFactory_GetBool( cf, self->name , (Dictionary_Entry_Key)"recoverStrain", False  );
-
-   _RecoveredFeVariable_Init( self, stiffnessMatrix, rawPressureField, velGradField, refreshMeshConnectivity, recoverStrain );
-}
-
-void _RecoveredFeVariable_Build( void* recFeVariable, void* data ) {
-	RecoveredFeVariable* self = (RecoveredFeVariable*) recFeVariable;
-
-	/* Build the parent class */
-	_BaseRecoveryFeVar_Build( self, data );
-
-	/* check and build for pressure field */
-	if( self->rawPressureField )
-		Stg_Component_Build( self->rawPressureField, data, False );
-
-   Stg_Component_Build( self->velGradField, data, False );
-	/* Make static, for current release of code.
-	 * When AMR comes this will need to be addressed */
-	self->nodesPerEl = (self->rawField->dim == 2) ? 4 : 8;
-	if( self->refreshMeshConnectivity == False ) {
-		self->elementRep_H = Memory_Alloc_Array( double, 
-						FeMesh_GetNodeDomainSize( self->feMesh )*
-						self->fieldComponentCount*
-						self->dim * self->nodesPerEl * self->orderOfInterpolation, 
-						"domain Element REP RHS");
-		self->elementRep_F = Memory_Alloc_Array( double, 
-						FeMesh_GetNodeDomainSize( self->feMesh )*
-						self->fieldComponentCount*
-						self->nodesPerEl * self->dim,
-						"domain Element REP LHS");
-	}
-}
-
-void _RecoveredFeVariable_Initialise( void* recFeVariable, void* data ) {
-   RecoveredFeVariable*      self = (RecoveredFeVariable*) recFeVariable;
-
-   /* Initialise parent */
-   _BaseRecoveryFeVar_Initialise( self, data );
-
-   /* Initialise class specific stuff */
-   if( self->rawPressureField ) 
-      Stg_Component_Initialise( self->rawPressureField, data, False );
-   Stg_Component_Initialise( self->dofLayout, data, False );
-   Stg_Component_Initialise( self->velGradField, data, False );
-
-   self->pMatrix = Memory_Alloc_2DArray( double, self->fieldComponentCount, self->orderOfInterpolation , (Name)"P_Matrix" );
-   self->CPmat = Memory_Alloc_2DArray( double, self->fieldComponentCount, self->orderOfInterpolation, "CP matrix, for strainRate only");
-   self->tmpC  = Memory_Alloc_2DArray( double, self->fieldComponentCount, self->fieldComponentCount, "tmp C matrix, for strainRate only");
-
-   /* this functionPtr could be useful later, JG, 12May09
-   * self->_assembleOnParticle = _RecoveredFeVariable_AssembleAtParticle;
-   */
-   self->_putElIntoProc = _RecoveredFeVariable_PutElIntoProc;
-}
-
-void _RecoveredFeVariable_Execute( void* recFeVariable, void* data ) {
-	RecoveredFeVariable* self = (RecoveredFeVariable*) recFeVariable; 
-
-	_BaseRecoveryFeVar_Execute( self, data );
-}
-
-void _RecoveredFeVariable_Destroy( void* recFeVariable, void* data ) {
-	RecoveredFeVariable* self = (RecoveredFeVariable*) recFeVariable;
-
-	Memory_Free( self->elementRep_H );
-	Memory_Free( self->elementRep_F );
-	Memory_Free( self->pMatrix );
-	Memory_Free( self->CPmat );
-	Memory_Free( self->tmpC );
-
-	Stg_Component_Destroy( self->velGradField, data, False );
-
-	if( self->rawPressureField )
-		Stg_Component_Destroy( self->rawPressureField, data, False );
-	
-	_BaseRecoveryFeVar_Destroy( self, data );
-}
-
-void _RecoveredFeVariable_AssembleAtParticle(
-   RecoveredFeVariable* self,
-   ConstitutiveMatrix*  constitutiveMatrix,
-   int                  particleIndex,
-   IntegrationPoint*    particle,
-   int                  lElement_I, 
-   double*              globalCoord,
-   double**             GNx,
-   double               detJac,
-   double***            Hi_Mat,
-   double**             Fi_Mat )
-{
-	SymmetricTensor p_StrainRate, p_Stress, theCopy;
-   RheologyMaterial* material = (RheologyMaterial*) IntegrationPointsSwarm_GetMaterialOn( (IntegrationPointsSwarm*)constitutiveMatrix->integrationSwarm, particle );
-	int dim  = self->dim;
-	int dofThatExist = self->fieldComponentCount;
-	int order = self->orderOfInterpolation;
-	int dof_I;
-	double pressure, factor;
-	double* pVec   = self->pVec;
-	double** pMatrix = self->pMatrix; 
-	double** tmpC = self->tmpC; 
-
-	/* integration factor */
-	factor = particle->weight * detJac;
-
-	self->_makePoly( globalCoord, pVec );
-
-	/* get raw field values on particles */
-	FeVariable_InterpolateWithinElement( self->rawField, lElement_I, particle->xi, p_StrainRate );
-
-   if( constitutiveMatrix ) {
-      if( self->nonLinearProblem ) {
-         /*use the stored constMatrix to match current velocity and pressure solution */
-         ConstitutiveMatrix_GetStoredMatrixOnParticle( constitutiveMatrix, particle, tmpC );
-      } else {
-         /* build total constitutive matrix - could diagree with current velcoity and pressure solution */
-         ConstitutiveMatrix_Assemble( constitutiveMatrix, lElement_I, particleIndex, particle ); 
-      }
-
-      if( !self->recoverStrain ) {
-         /* if not recovering strain rate we build p_Stress now */
-         if( self->nonLinearProblem ) {
-            /* perform stress calculation; note, this use the cumulative call because p_Stress */
-            if (dim == 2 ) _TmpConstMat2D_CalculateStress( tmpC, p_StrainRate, p_Stress, constitutiveMatrix->isDiagonal );
-            else _TmpConstMat3D_CalculateStress( tmpC, p_StrainRate, p_Stress, constitutiveMatrix->isDiagonal );
-
-         } else { ConstitutiveMatrix_CalculateStress( constitutiveMatrix, p_StrainRate, p_Stress ); }
-      }
-   } else {
-      /* if not consitutiveMatrix was given assume viscosity = 1 */
-      for( dof_I = 0 ; dof_I < dofThatExist ; dof_I++ ) 
-         p_Stress[ dof_I ] = 2 * p_StrainRate[ dof_I ]; 
-   }
-
-   if( material->compressible ) { 
-   /* Check if material is compressible, if so adjust direct stress components, here it's assumed the
-   compressible material has an isotropic viscosity */
-      double du_dx, dv_dy, dw_dz;
-      double compressibleBit;
-      TensorArray p_velGradField;
-      FeVariable_InterpolateWithinElement( self->velGradField, lElement_I, particle->xi, p_velGradField );
-      du_dx = p_velGradField[0];
-
-      if( dim == 2 ) {
-         dv_dy = p_velGradField[2];
-         compressibleBit = (-2/3)*constitutiveMatrix->matrixData[0][0]*(du_dx+dv_dy);
-         p_Stress[0] = p_Stress[0] + compressibleBit;
-         p_Stress[1] = p_Stress[1] + compressibleBit;
-      } else {
-         dv_dy = p_velGradField[4];
-         dw_dz = p_velGradField[8];
-         compressibleBit = (-2/3)*constitutiveMatrix->matrixData[0][0]*(du_dx+dv_dy+dw_dz);
-         p_Stress[0] = p_Stress[0] + compressibleBit;
-         p_Stress[1] = p_Stress[1] + compressibleBit;
-         p_Stress[2] = p_Stress[2] + compressibleBit;
-      }
-   }
-
-	/* If pressure exists, then recovered total pressure by taking the raw pressure field as input */
-	if ( self->rawPressureField != NULL ) {	
-		FeVariable_InterpolateWithinElement( self->rawPressureField, lElement_I, particle->xi, &pressure );
-		p_Stress[0] = p_Stress[0] - pressure; // xx 
-		p_Stress[1] = p_Stress[1] - pressure; // yy 
-		if( dim == 3 )
-			p_Stress[2] = p_Stress[2] - pressure; // zz
-	}
-
-#if DEBUG_REP
-	p_Stress[0] = 1;
-	p_Stress[1] = 1;
-	p_Stress[2] = 1;
-	p_Stress[3] = 1;
-	p_Stress[4] = 1;
-	p_Stress[5] = 1;
-#endif
-
-	if( self->recoverStrain )
-		memcpy( theCopy, p_StrainRate, dofThatExist*sizeof(double) );
-	else
-		memcpy( theCopy, p_Stress, dofThatExist*sizeof(double) );
-
-	for( dof_I = 0 ; dof_I < dofThatExist ; dof_I++ ) {
-    /* now assemble things per dof, see eq. 20 in 
-     * B.Boroomand & O.C.Zienkiewicz, 
-     * "An Improved REP Recovery and the Effectivity Robustness Test",
-     * Int. J. for Numerical Methods in Engineering, vol. 40, pages 3247-3277, 1997. */
-
-		if( self->recoverStrain ) {
-			memset( p_StrainRate, 0, dofThatExist*sizeof(double) );
-			p_StrainRate[dof_I] = theCopy[dof_I];
-		} else {
-			/* Setup raw stress tensor for RHS */
-			memset( p_Stress, 0, dofThatExist*sizeof(double) );
-			p_Stress[dof_I] = theCopy[dof_I];
-		}
-
-		/* Setup polynomial matrix for creating LHS */
-		ZeroMatrix( pMatrix, dofThatExist, order );
-		memcpy( pMatrix[dof_I], pVec, order*sizeof(double) );
-
-		if( self->recoverStrain ) {
-			Index ii;
-			if( !constitutiveMatrix ) {
-        /* if no consitutive matrix make it up - assume viscosity = 1 */
-				for( ii = 0 ; ii < dofThatExist; ii++ ) { memset( tmpC[ii], 0, dofThatExist*sizeof(double)); }
-				if (dim == 2) { tmpC[0][0] = tmpC[1][1] = tmpC[2][2] = 1; } 
-        else { tmpC[0][0] = tmpC[1][1] = tmpC[2][2] = tmpC[3][3] = tmpC[4][4] = tmpC[5][5] = 1; }
-
-			} else {
-				/* copy constitutive matrix */
-				for(ii = 0 ; ii < dofThatExist ; ii++)
-					memcpy( tmpC[ii], constitutiveMatrix->matrixData[ii], dofThatExist*sizeof(double) ); 
-			}
-      if( dim == 2 ){
-        /* modify stored constitutive matrix to account for symmetry (see CalculateStress routines)  */
-        tmpC[0][2] *= 2.0;
-        tmpC[1][2] *= 2.0;
-        tmpC[2][2] *= 2.0;
-      } else {
-        tmpC[0][3] *= 2.0;
-        tmpC[1][3] *= 2.0;
-        tmpC[2][3] *= 2.0;
-        tmpC[3][3] *= 2.0;
-        tmpC[4][3] *= 2.0;
-        tmpC[5][3] *= 2.0;
-        tmpC[0][4] *= 2.0;
-        tmpC[1][4] *= 2.0;
-        tmpC[2][4] *= 2.0;
-        tmpC[3][4] *= 2.0;
-        tmpC[4][4] *= 2.0;
-        tmpC[5][4] *= 2.0;
-        tmpC[0][5] *= 2.0;
-        tmpC[1][5] *= 2.0;
-        tmpC[2][5] *= 2.0;
-        tmpC[3][5] *= 2.0;
-        tmpC[4][5] *= 2.0;
-        tmpC[5][5] *= 2.0;
-      }
-			/* Multiply in tmpC so that we solve for strainrates */ 
-			NonSquareMatrix_MultiplicationByNonSquareMatrix(
-					tmpC, dofThatExist, dofThatExist, 
-					pMatrix, dofThatExist, order, 
-					self->CPmat);
-			ConstitutiveMatrix_CalculateStress( constitutiveMatrix, p_StrainRate, p_Stress );
-			self->_calcHi( self, GNx, self->CPmat, factor, Hi_Mat[dof_I] );
-		} else {
-			/* cal Hi, build lefthand Operator */
-			self->_calcHi( self, GNx, pMatrix, factor, Hi_Mat[dof_I] );
-		}
-		/* cal Fi, build righthand Operator */
-		self->_calcFi( self, GNx, p_Stress, factor, Fi_Mat[dof_I] );
-	}
-}
-
-void _RecoveredFeVariable_ZeroHiFi( RecoveredFeVariable* self, double*** elHi_Mat, double** elFi_Mat ) {
-	/* Function description:
-   * Zeros object Hi and Fi, probably a bit expensive */
-	int dim, order, nodesPerEl, dofThatExist, rowsInH, dof_I;
-	
-	dim = self->dim;
-	dofThatExist = self->fieldComponentCount;
-	nodesPerEl = self->nodesPerEl;
-	order = self->orderOfInterpolation;
-	rowsInH = nodesPerEl * dim;
-
-  ZeroMatrix( elFi_Mat, dofThatExist, rowsInH );
-	for( dof_I = 0 ; dof_I < dofThatExist ; dof_I++ ) 
-		ZeroMatrix( elHi_Mat[dof_I], rowsInH, order );
-}
-
-
-void _RecoveredFeVariable_CalcHi2D( RecoveredFeVariable* self, double** GNx, double** pMatrix, double factor, double** Hi ) {
-  /* See eq 24 in Boroomand and Zienk, 1997 */
-	int order, dim, row, order_I, node_I, nodesPerEl;
-	double d_dx, d_dy;
-
-	nodesPerEl = self->nodesPerEl;
-	dim = self->dim;
-	order = self->orderOfInterpolation;
-
-	for( node_I = 0 ; node_I < nodesPerEl ; node_I++ ) {
-		d_dx = GNx[0][node_I] * factor;
-		d_dy = GNx[1][node_I] * factor;
-		row  = dim*node_I;
-		for( order_I = 0 ; order_I < order ; order_I++ ) {
-			Hi[row][order_I]   += d_dx * pMatrix[0][order_I] + d_dy * pMatrix[2][order_I];
-			Hi[row+1][order_I] += d_dy * pMatrix[1][order_I] + d_dx * pMatrix[2][order_I];
-		}
-	}
-}
-
-void _RecoveredFeVariable_CalcHi3D( RecoveredFeVariable* self, double** GNx, double** pMatrix, double factor, double** Hi ) {
-  /* See eq 24 in Boroomand and Zienk, 1997 */
-	int order, dim, row, order_I, node_I, nodesPerEl;
-	double d_dx, d_dy, d_dz;
-
-	nodesPerEl = self->nodesPerEl;
-	dim = self->dim;
-	order = self->orderOfInterpolation;
-
-	for( order_I = 0 ; order_I < order ; order_I++ ) {
-		for( node_I = 0 ; node_I < nodesPerEl ; node_I++ ) {
-			d_dx = GNx[0][node_I] * factor;
-			d_dy = GNx[1][node_I] * factor;
-			d_dz = GNx[2][node_I] * factor;
-			row  = dim*node_I;
-			Hi[row][order_I]   += d_dx * pMatrix[0][order_I] + d_dy * pMatrix[3][order_I] + d_dz*pMatrix[4][order_I];
-			Hi[row+1][order_I] += d_dy * pMatrix[1][order_I] + d_dx * pMatrix[3][order_I] + d_dz*pMatrix[5][order_I];
-			Hi[row+2][order_I] += d_dz * pMatrix[2][order_I] + d_dx * pMatrix[4][order_I] + d_dy*pMatrix[5][order_I];
-		}
-	}
-}
-
-void _RecoveredFeVariable_CalcFi2D( RecoveredFeVariable* self, double** GNx, double* p_Stress, double factor, double* Fi ) {
-  /* See eq 25 in Boroomand and Zienk, 1997 */
-	int node_I, nodesPerEl, dim, row;
-	double d_dx, d_dy;
-
-	dim = self->dim;
-	nodesPerEl = self->nodesPerEl;
-
-	for( node_I = 0 ; node_I < nodesPerEl ; node_I ++ ) {
-		d_dx = GNx[0][node_I] * factor;
-		d_dy = GNx[1][node_I] * factor;
-		row  = dim*node_I;
-		/* TODO: Only in 2-D at present */
-		Fi[row]   += d_dx * p_Stress[0] + d_dy * p_Stress[2];
-		Fi[row+1] += d_dy * p_Stress[1] + d_dx * p_Stress[2];
-	}
-}
-
-void _RecoveredFeVariable_CalcFi3D( RecoveredFeVariable* self, double** GNx, double* p_Stress, double factor, double* Fi ) {
-  /* See eq 25 in Boroomand and Zienk, 1997 */
-	int node_I, nodesPerEl, dim, row;
-	double d_dx, d_dy, d_dz;
-
-	dim = self->dim;
-	nodesPerEl = self->nodesPerEl;
-
-	for( node_I = 0 ; node_I < nodesPerEl ; node_I ++ ) {
-		d_dx = GNx[0][node_I] * factor;
-		d_dy = GNx[1][node_I] * factor;
-		d_dz = GNx[2][node_I] * factor;
-		row  = dim*node_I;
-		Fi[row]   += d_dx * p_Stress[0] + d_dy * p_Stress[3] + d_dz*p_Stress[4];
-		Fi[row+1] += d_dy * p_Stress[1] + d_dx * p_Stress[3] + d_dz*p_Stress[5];
-		Fi[row+2] += d_dz * p_Stress[2] + d_dx * p_Stress[4] + d_dy*p_Stress[5];
-	}
-}
-
-void _RecoveredFeVariable_PutElIntoProc( RecoveredFeVariable* self, int lElement_I, double*** elHi_Mat, double** elFi_Mat ) {
-	int keyH, keyF, dof_I, row_I, order_I;
-	int dim, dofThatExist, order, nodesPerEl, rowsInH;
-	double* ptrH = self->elementRep_H;
-	double* ptrF = self->elementRep_F;
-
-	dim = self->dim;
-	nodesPerEl = self->nodesPerEl;
-	dofThatExist = self->fieldComponentCount;
-	order = self->orderOfInterpolation;
-	rowsInH = nodesPerEl * dim;
-	
-	for( dof_I = 0 ; dof_I < dofThatExist ; dof_I++ ) {  
-		keyH = (lElement_I*dofThatExist*rowsInH*order) + (dof_I*rowsInH*order);
-		keyF = (lElement_I*dofThatExist*rowsInH) + (dof_I*rowsInH);
-		for( row_I = 0 ; row_I < rowsInH ; row_I++ ) {
-			ptrF[ keyF + row_I ] =+ elFi_Mat[dof_I][row_I];
-
-			for( order_I = 0 ; order_I < order ; order_I++ )
-				/* lElement_I*dofThatExist*rowsInH*order + row_I*order + order_I */
-				ptrH[ (keyF + row_I)*order + order_I ] =+ elHi_Mat[dof_I][row_I][order_I];
-		}
-	}
-}
-
-void RecoveredFeVariable_CommunicateHF( RecoveredFeVariable* self ) {
-	/* Update all other procs. */
-	Sync* sync;
-	int chunkSize_H, chunkSize_F, nLocalEl;
-
-	if( self->dim ==2 ) sync = Mesh_GetSync( self->feMesh, MT_FACE );
-	else sync = Mesh_GetSync( self->feMesh, MT_VOLUME );
-
-	nLocalEl = FeMesh_GetElementLocalSize( self->feMesh );
-	chunkSize_H = self->fieldComponentCount * self->nodesPerEl * self->dim * self->orderOfInterpolation;
-	chunkSize_F = self->fieldComponentCount * self->nodesPerEl * self->dim;
-	/* Argument Describtion below:
-	 * 0) the sync object
-	 * 1) start of local address
-	 * 2) size of chunk in array
-	 * 3) location + size of local information in array
-	 * 4) size of chunk to send???
-	 * 5) size of chunk to receive??
-	 */
-	/* Sync of the elementRep_H */
-	Sync_SyncArray( sync, self->elementRep_H, chunkSize_H * sizeof(double), 
-			self->elementRep_H + nLocalEl * chunkSize_H, chunkSize_H * sizeof(double), 
-			chunkSize_H * sizeof(double) );
-
-	/* Sync of the elementRep_H */
-	Sync_SyncArray( sync, self->elementRep_F, chunkSize_F * sizeof(double), 
-			self->elementRep_F + nLocalEl * chunkSize_F, chunkSize_F * sizeof(double), 
-			chunkSize_F * sizeof(double) );
-}
-
-void RecoveredFeVariable_SetupWorkSpace( RecoveredFeVariable* self ) {
-	int dofThatExist, order, nodesPerEl, nodesInPatch, rowsInH;
-
-	nodesPerEl = self->nodesPerEl;
-	dofThatExist = self->fieldComponentCount;
-	order = self->orderOfInterpolation;
-	nodesInPatch = self->nodesInPatch;
-	rowsInH = nodesInPatch * self->dim;
-
-	/* will be useful if AMR begins, currently assumes a static mesh */
-	self->patch_H    = Memory_Alloc_3DArray( double, dofThatExist, rowsInH, order , (Name)"H_Matrix" );
-	self->patch_F    = Memory_Alloc_2DArray( double, dofThatExist, rowsInH, (Name)"F Vector" );
-	self->H_t        = Memory_Alloc_2DArray( double, order, rowsInH/*rowsInH, dofThatExist*/, " H transpose");
-	self->AMat       = Memory_Alloc_3DArray( double, dofThatExist, order, order , (Name)"AMatrix" );
-	self->bVec       = Memory_Alloc_2DArray( double, dofThatExist, order , (Name)"BVector" );
-	self->tmpEl_H    = Memory_Alloc_2DArray( double, rowsInH, order , (Name)"tmp Element H" );
-	self->tmpEl_F    = Memory_Alloc_Array( double, rowsInH, "tmp Element H");
-}
-
-void RecoveredFeVariable_RemoveWorkSpace( RecoveredFeVariable* self ) {
-	/* will be useful if AMR begins, currently assumes a static mesh */
-	Memory_Free( self->patch_H );
-	Memory_Free( self->patch_F );
-	Memory_Free( self->H_t );
-	Memory_Free( self->AMat );
-	Memory_Free( self->bVec );
-	Memory_Free( self->tmpEl_H );
-	Memory_Free( self->tmpEl_F );
-}
-
-void _RecoveredFeVariable_UnpackElement( double* ptrH, double* ptrF, int rowsInH, int order, double **el_H, double *el_F ) {
-	int row_I, order_I;
-		/* Unpack */
-		for( row_I = 0 ; row_I < rowsInH ; row_I++ ) {
-			for(order_I = 0 ; order_I < order ; order_I++ ) {
-				el_H[row_I][order_I] = ptrH[row_I*order + order_I];
-			}
-			el_F[row_I]= ptrF[row_I];
-		}
-}
-void RecoveredFeVariable_SolvePatch( RecoveredFeVariable* self, int pNodeID, int *elList, int nEl, LmStruct* lmStruct ) {
-	double **patch_H, *patch_F;
-	/* Used for unpacking */
-	double **el_H = self->tmpEl_H;
-	double *el_F = self->tmpEl_F;
-	double *ptrH, *ptrF;
-  double coeff[50];
-	IArray *inc;
-	double *coord;
-	int dim, dofThatExist, order, nodesPerEl, rowsInElH, rowsInPatchH, row, elID;
-	int dof_I, el_I, node_I, nodeID, indexOfEntry, order_I;
-	int *nodeList;
-	int chunkSize_H;
-	int chunkSize_F;
-
-	dim = self->dim;
-	nodesPerEl = self->nodesPerEl;
-	dofThatExist = self->fieldComponentCount;
-	order = self->orderOfInterpolation;
-	rowsInElH = nodesPerEl * self->dim;
-	rowsInPatchH = self->nodesInPatch * self->dim;
-
-	chunkSize_H =  self->nodesPerEl * self->dim * self->orderOfInterpolation;
-	chunkSize_F =  self->nodesPerEl * self->dim;
-
-	/* use the inc on the FeVariable */
-	inc = self->inc;
-
-	coord = Mesh_GetVertex( self->feMesh , pNodeID );
-
-	for( dof_I = 0 ; dof_I < dofThatExist ; dof_I++ ) {
-			ZeroMatrix( self->patch_H[dof_I], rowsInPatchH, order );
-	}
-	ZeroMatrix(self->patch_F, dofThatExist, rowsInPatchH );
-		
-	for( dof_I = 0 ; dof_I < dofThatExist ; dof_I++ ) {
-		patch_H = self->patch_H[dof_I];
-		patch_F = self->patch_F[dof_I];
-		for( el_I = 0 ; el_I < nEl ; el_I++ ) {
-			elID = elList[el_I];
-			ptrH = &(self->elementRep_H[ chunkSize_H * (elID*dofThatExist + dof_I) ]);
-			ptrF = &(self->elementRep_F[ chunkSize_F * (elID*dofThatExist + dof_I) ]);
-			_RecoveredFeVariable_UnpackElement( ptrH, ptrF, rowsInElH, order, el_H, el_F );
-			/* get nodes in element */
-			FeMesh_GetElementNodes( self->feMesh, elID, inc );
-			nodesPerEl = IArray_GetSize( inc );
-			nodeList = IArray_GetPtr( inc );
-			for( node_I = 0 ; node_I < nodesPerEl ; node_I++ ) {
-				nodeID = nodeList[node_I];	
-				indexOfEntry = _REP_Algorithm_locateInPatchListStruct( lmStruct, nodeID );	
-				assert( indexOfEntry != -1 );
-				row = indexOfEntry * dim;
-
-				for( order_I = 0 ; order_I < order ; order_I++ ) {
-					patch_H[row][order_I]   += el_H[node_I*dim][order_I]; 
-					patch_H[row+1][order_I] += el_H[node_I*dim+1][order_I]; 
-					if( dim == 3 )
-						patch_H[row+2][order_I] += el_H[node_I*dim+2][order_I]; 
-				}
-
-				patch_F[row] += el_F[node_I*dim];
-				patch_F[row+1] += el_F[node_I*dim+1];
-				if( dim == 3 ) 
-					patch_F[row+2] += el_F[node_I*dim+2];
-			}
-		}
-		/* Now the actual maths */
-		NonSquareMatrix_Transpose( patch_H, rowsInPatchH, order, self->H_t );
-	
-		/* 5) Construct A_Matrix = Ht_Matrix . H_Matrix */
-		NonSquareMatrix_MultiplicationByNonSquareMatrix( self->H_t, order, rowsInPatchH, 
-																patch_H, rowsInPatchH,  order, 
-																self->AMat[dof_I] );
-	
-		/* 6) Construct bMatrix = Ht_Matrix . F_Vector */
-		NonSquareMatrix_MatrixVectorMultiplication( self->H_t, order, rowsInPatchH,
-																patch_F, rowsInPatchH,
-																self->bVec[dof_I] );
-
-		_REP_Algorithm_Solver(self->AMat[dof_I], self->bVec[dof_I], order);
-		memcpy( &coeff[order*dof_I], self->bVec[dof_I], sizeof(double)*order );
-	}
-	FeVariable_SetValueAtNode( self, pNodeID , coeff );
-}
-
-void _TmpConstMat2D_CalculateStress( double** D, SymmetricTensor strainRate, SymmetricTensor stress, Bool isDiagonal ) {
-	if (isDiagonal) {
-		stress[0] = D[0][0] * strainRate[0];
-		stress[1] = D[1][1] * strainRate[1];
-		stress[2] = D[2][2] * 2.0 * strainRate[2];
-	} else {
-		stress[0] = D[0][0] * strainRate[0] + D[0][1] * strainRate[1] + D[0][2] * 2.0 * strainRate[2];
-		stress[1] = D[1][0] * strainRate[0] + D[1][1] * strainRate[1] + D[1][2] * 2.0 * strainRate[2];
-		stress[2] = D[2][0] * strainRate[0] + D[2][1] * strainRate[1] + D[2][2] * 2.0 * strainRate[2];
-	}
-}
-
-void _TmpConstMat3D_CalculateStress( double** D, SymmetricTensor strainRate, SymmetricTensor stress, Bool isDiagonal ) {
-	          	
-	if (isDiagonal) {
-		stress[0] = D[0][0] * strainRate[0];
-		stress[1] = D[1][1] * strainRate[1];
-		stress[2] = D[2][2] * strainRate[2];
-		stress[3] = D[3][3] * 2.0 * strainRate[3];
-		stress[4] = D[4][4] * 2.0 * strainRate[4];
-		stress[5] = D[5][5] * 2.0 * strainRate[5];
-	} else {
-		stress[0] = D[0][0] * strainRate[0] + D[0][1] * strainRate[1] + D[0][2] * strainRate[2] 
-			+ 2.0 * (D[0][3] * strainRate[3] + D[0][4] * strainRate[4] + D[0][5] * strainRate[5]);
-
-		stress[1] = D[1][0] * strainRate[0] + D[1][1] * strainRate[1] + D[1][2] * strainRate[2] 
-			+ 2.0 * (D[1][3] * strainRate[3] + D[1][4] * strainRate[4] + D[1][5] * strainRate[5]);
-
-		stress[2] = D[2][0] * strainRate[0] + D[2][1] * strainRate[1] + D[2][2] * strainRate[2] 
-			+ 2.0 * (D[2][3] * strainRate[3] + D[2][4] * strainRate[4] + D[2][5] * strainRate[5]);
-
-		stress[3] = D[3][0] * strainRate[0] + D[3][1] * strainRate[1] + D[3][2] * strainRate[2] 
-			+ 2.0 * (D[3][3] * strainRate[3] + D[3][4] * strainRate[4] + D[3][5] * strainRate[5]);
-
-		stress[4] = D[4][0] * strainRate[0] + D[4][1] * strainRate[1] + D[4][2] * strainRate[2] 
-			+ 2.0 * (D[4][3] * strainRate[3] + D[4][4] * strainRate[4] + D[4][5] * strainRate[5]);
-
-		stress[5] = D[5][0] * strainRate[0] + D[5][1] * strainRate[1] + D[5][2] * strainRate[2] 
-			+ 2.0 * (D[5][3] * strainRate[3] + D[5][4] * strainRate[4] + D[5][5] * strainRate[5]);
-	}
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/RecoveredFeVariable.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/RecoveredFeVariable.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,745 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+**
+** 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: RecoveredFeVariable.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 "Underworld/Rheology/Rheology.h"
+
+#include "types.h"
+#include "BaseRecoveryFeVar.h"
+#include "RecoveredFeVariable.h"
+#include "REP_Algorithm.h"
+
+#include <math.h>
+#include <assert.h>
+#include <string.h>
+
+const Type RecoveredFeVariable_Type = "RecoveredFeVariable";
+
+void* _RecoveredFeVariable_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(RecoveredFeVariable);
+	Type                                                      type = RecoveredFeVariable_Type;
+	Stg_Class_DeleteFunction*                              _delete = _RecoveredFeVariable_Delete;
+	Stg_Class_PrintFunction*                                _print = _RecoveredFeVariable_Print;
+	Stg_Class_CopyFunction*                                  _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _RecoveredFeVariable_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _RecoveredFeVariable_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _RecoveredFeVariable_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _RecoveredFeVariable_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _RecoveredFeVariable_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _RecoveredFeVariable_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 = (AllocationType)ZERO;
+	FieldVariable_InterpolateValueAtFunction*             _interpolateValueAt = ZERO;
+	FieldVariable_GetValueFunction*               _getMinGlobalFieldMagnitude = ZERO;
+	FieldVariable_GetValueFunction*               _getMaxGlobalFieldMagnitude = ZERO;
+	FieldVariable_GetCoordFunction*                  _getMinAndMaxLocalCoords = ZERO;
+	FieldVariable_GetCoordFunction*                 _getMinAndMaxGlobalCoords = ZERO;
+	FeVariable_InterpolateWithinElementFunction*    _interpolateWithinElement = ZERO;
+	FeVariable_GetValueAtNodeFunction*                        _getValueAtNode = ZERO;
+	FeVariable_SyncShadowValuesFunc*                        _syncShadowValues = ZERO;
+
+	return (void*)_RecoveredFeVariable_New(  RECOVEREDFEVARIABLE_PASSARGS  );
+}
+
+RecoveredFeVariable* _RecoveredFeVariable_New(  RECOVEREDFEVARIABLE_DEFARGS  )
+{
+	RecoveredFeVariable*		self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(RecoveredFeVariable) );
+	self = (RecoveredFeVariable*)
+		_BaseRecoveryFeVar_New(  BASERECOVERYFEVAR_PASSARGS  );
+
+	return self;
+}
+
+/* --- Virtual Function Implementations --- */
+void _RecoveredFeVariable_Delete( void* recFeVariable ) {
+	RecoveredFeVariable* self = (RecoveredFeVariable*) recFeVariable;
+	_BaseRecoveryFeVar_Delete( self );
+}
+
+void _RecoveredFeVariable_Print( void* recFeVariable, Stream* stream ) {
+	RecoveredFeVariable* self = (RecoveredFeVariable*) recFeVariable;
+	
+	/* General info */
+	Journal_Printf( stream, "RecoveredFeVariable (ptr): %p\n", self );
+	
+	/* Print parent */
+	_FeVariable_Print( self, stream );
+	
+	/* RecoveredFeVariable info */
+}
+
+void* _RecoveredFeVariable_Copy( const void* recFeVariable, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	abort();
+}
+
+void _RecoveredFeVariable_Init( RecoveredFeVariable* self, StiffnessMatrix* stiffnessMatrix, FeVariable* rawPressureField, FeVariable* velGradField, Bool refreshMeshConnectivity, Bool recoverStrain ) {
+	/* Setup basic pointers and functionPtrs that are specific to problem spec  */
+
+	self->rawPressureField = rawPressureField;
+	self->velGradField = velGradField;
+	self->refreshMeshConnectivity = refreshMeshConnectivity;
+	self->recoverStrain = recoverStrain;
+	self->fieldComponentCount = StGermain_nSymmetricTensorVectorComponents(self->dim);
+   self->nonLinearProblem = stiffnessMatrix->isNonLinear;
+
+	/* assign functionPtrs for 2D and 3D here */
+	if( self->dim == 2 ) {    
+		self->_calcHi = _RecoveredFeVariable_CalcHi2D;
+		self->_calcFi = _RecoveredFeVariable_CalcFi2D;
+		self->nodesInPatch = 9; /*TODO is static, should be dynamic later */
+	} else {
+		self->_calcHi =	_RecoveredFeVariable_CalcHi3D;
+		self->_calcFi =	_RecoveredFeVariable_CalcFi3D;
+		self->nodesInPatch = 27; /*TODO is static, should be dynamic later */
+	}
+
+	self->coeffCount = self->orderOfInterpolation * self->fieldComponentCount;
+}
+
+void _RecoveredFeVariable_AssignFromXML( void* recFeVariable, Stg_ComponentFactory* cf, void* data ) {
+   RecoveredFeVariable*  self        = (RecoveredFeVariable*) recFeVariable;
+   StiffnessMatrix*      stiffnessMatrix = NULL;
+   FeVariable*           rawPressureField = NULL;
+   FeVariable*           velGradField = NULL;
+   Bool                  refreshMeshConnectivity, recoverStrain, recoverPressure;
+
+   _BaseRecoveryFeVar_AssignFromXML( self, cf, data );
+
+   /* assume there this always a stiffness matrix called k_matrix */
+   stiffnessMatrix = Stg_ComponentFactory_ConstructByName( cf, (Name)"k_matrix", StiffnessMatrix, True, data  ); 
+
+   recoverPressure = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"recoverPressure", True ); 
+   if( recoverPressure == True  ) {
+      rawPressureField = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"RawPressureField", FeVariable, True, data );
+      /* record the rawField that is required on the repRequired_RawField register */
+      if( (unsigned )-1 == Stg_ObjectList_GetIndex( repRequiredRawFields_Reg, rawPressureField->name ) )
+         Stg_ObjectList_Append( repRequiredRawFields_Reg, rawPressureField );
+   }
+
+   velGradField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityGradientsField", FeVariable, False, data  );
+
+   refreshMeshConnectivity = Stg_ComponentFactory_GetBool( cf, self->name , (Dictionary_Entry_Key)"refreshMeshConnectivity", False  );
+   recoverStrain = Stg_ComponentFactory_GetBool( cf, self->name , (Dictionary_Entry_Key)"recoverStrain", False  );
+
+   _RecoveredFeVariable_Init( self, stiffnessMatrix, rawPressureField, velGradField, refreshMeshConnectivity, recoverStrain );
+}
+
+void _RecoveredFeVariable_Build( void* recFeVariable, void* data ) {
+	RecoveredFeVariable* self = (RecoveredFeVariable*) recFeVariable;
+
+	/* Build the parent class */
+	_BaseRecoveryFeVar_Build( self, data );
+
+	/* check and build for pressure field */
+	if( self->rawPressureField )
+		Stg_Component_Build( self->rawPressureField, data, False );
+
+   Stg_Component_Build( self->velGradField, data, False );
+	/* Make static, for current release of code.
+	 * When AMR comes this will need to be addressed */
+	self->nodesPerEl = (self->rawField->dim == 2) ? 4 : 8;
+	if( self->refreshMeshConnectivity == False ) {
+		self->elementRep_H = Memory_Alloc_Array( double, 
+						FeMesh_GetNodeDomainSize( self->feMesh )*
+						self->fieldComponentCount*
+						self->dim * self->nodesPerEl * self->orderOfInterpolation, 
+						"domain Element REP RHS");
+		self->elementRep_F = Memory_Alloc_Array( double, 
+						FeMesh_GetNodeDomainSize( self->feMesh )*
+						self->fieldComponentCount*
+						self->nodesPerEl * self->dim,
+						"domain Element REP LHS");
+	}
+}
+
+void _RecoveredFeVariable_Initialise( void* recFeVariable, void* data ) {
+   RecoveredFeVariable*      self = (RecoveredFeVariable*) recFeVariable;
+
+   /* Initialise parent */
+   _BaseRecoveryFeVar_Initialise( self, data );
+
+   /* Initialise class specific stuff */
+   if( self->rawPressureField ) 
+      Stg_Component_Initialise( self->rawPressureField, data, False );
+   Stg_Component_Initialise( self->dofLayout, data, False );
+   Stg_Component_Initialise( self->velGradField, data, False );
+
+   self->pMatrix = Memory_Alloc_2DArray( double, self->fieldComponentCount, self->orderOfInterpolation , (Name)"P_Matrix" );
+   self->CPmat = Memory_Alloc_2DArray( double, self->fieldComponentCount, self->orderOfInterpolation, "CP matrix, for strainRate only");
+   self->tmpC  = Memory_Alloc_2DArray( double, self->fieldComponentCount, self->fieldComponentCount, "tmp C matrix, for strainRate only");
+
+   /* this functionPtr could be useful later, JG, 12May09
+   * self->_assembleOnParticle = _RecoveredFeVariable_AssembleAtParticle;
+   */
+   self->_putElIntoProc = _RecoveredFeVariable_PutElIntoProc;
+}
+
+void _RecoveredFeVariable_Execute( void* recFeVariable, void* data ) {
+	RecoveredFeVariable* self = (RecoveredFeVariable*) recFeVariable; 
+
+	_BaseRecoveryFeVar_Execute( self, data );
+}
+
+void _RecoveredFeVariable_Destroy( void* recFeVariable, void* data ) {
+	RecoveredFeVariable* self = (RecoveredFeVariable*) recFeVariable;
+
+	Memory_Free( self->elementRep_H );
+	Memory_Free( self->elementRep_F );
+	Memory_Free( self->pMatrix );
+	Memory_Free( self->CPmat );
+	Memory_Free( self->tmpC );
+
+	Stg_Component_Destroy( self->velGradField, data, False );
+
+	if( self->rawPressureField )
+		Stg_Component_Destroy( self->rawPressureField, data, False );
+	
+	_BaseRecoveryFeVar_Destroy( self, data );
+}
+
+void _RecoveredFeVariable_AssembleAtParticle(
+   RecoveredFeVariable* self,
+   ConstitutiveMatrix*  constitutiveMatrix,
+   int                  particleIndex,
+   IntegrationPoint*    particle,
+   int                  lElement_I, 
+   double*              globalCoord,
+   double**             GNx,
+   double               detJac,
+   double***            Hi_Mat,
+   double**             Fi_Mat )
+{
+	SymmetricTensor p_StrainRate, p_Stress, theCopy;
+   RheologyMaterial* material = (RheologyMaterial*) IntegrationPointsSwarm_GetMaterialOn( (IntegrationPointsSwarm*)constitutiveMatrix->integrationSwarm, particle );
+	int dim  = self->dim;
+	int dofThatExist = self->fieldComponentCount;
+	int order = self->orderOfInterpolation;
+	int dof_I;
+	double pressure, factor;
+	double* pVec   = self->pVec;
+	double** pMatrix = self->pMatrix; 
+	double** tmpC = self->tmpC; 
+
+	/* integration factor */
+	factor = particle->weight * detJac;
+
+	self->_makePoly( globalCoord, pVec );
+
+	/* get raw field values on particles */
+	FeVariable_InterpolateWithinElement( self->rawField, lElement_I, particle->xi, p_StrainRate );
+
+   if( constitutiveMatrix ) {
+      if( self->nonLinearProblem ) {
+         /*use the stored constMatrix to match current velocity and pressure solution */
+         ConstitutiveMatrix_GetStoredMatrixOnParticle( constitutiveMatrix, particle, tmpC );
+      } else {
+         /* build total constitutive matrix - could diagree with current velcoity and pressure solution */
+         ConstitutiveMatrix_Assemble( constitutiveMatrix, lElement_I, particleIndex, particle ); 
+      }
+
+      if( !self->recoverStrain ) {
+         /* if not recovering strain rate we build p_Stress now */
+         if( self->nonLinearProblem ) {
+            /* perform stress calculation; note, this use the cumulative call because p_Stress */
+            if (dim == 2 ) _TmpConstMat2D_CalculateStress( tmpC, p_StrainRate, p_Stress, constitutiveMatrix->isDiagonal );
+            else _TmpConstMat3D_CalculateStress( tmpC, p_StrainRate, p_Stress, constitutiveMatrix->isDiagonal );
+
+         } else { ConstitutiveMatrix_CalculateStress( constitutiveMatrix, p_StrainRate, p_Stress ); }
+      }
+   } else {
+      /* if not consitutiveMatrix was given assume viscosity = 1 */
+      for( dof_I = 0 ; dof_I < dofThatExist ; dof_I++ ) 
+         p_Stress[ dof_I ] = 2 * p_StrainRate[ dof_I ]; 
+   }
+
+   if( material->compressible ) { 
+   /* Check if material is compressible, if so adjust direct stress components, here it's assumed the
+   compressible material has an isotropic viscosity */
+      double du_dx, dv_dy, dw_dz;
+      double compressibleBit;
+      TensorArray p_velGradField;
+      FeVariable_InterpolateWithinElement( self->velGradField, lElement_I, particle->xi, p_velGradField );
+      du_dx = p_velGradField[0];
+
+      if( dim == 2 ) {
+         dv_dy = p_velGradField[2];
+         compressibleBit = (-2/3)*constitutiveMatrix->matrixData[0][0]*(du_dx+dv_dy);
+         p_Stress[0] = p_Stress[0] + compressibleBit;
+         p_Stress[1] = p_Stress[1] + compressibleBit;
+      } else {
+         dv_dy = p_velGradField[4];
+         dw_dz = p_velGradField[8];
+         compressibleBit = (-2/3)*constitutiveMatrix->matrixData[0][0]*(du_dx+dv_dy+dw_dz);
+         p_Stress[0] = p_Stress[0] + compressibleBit;
+         p_Stress[1] = p_Stress[1] + compressibleBit;
+         p_Stress[2] = p_Stress[2] + compressibleBit;
+      }
+   }
+
+	/* If pressure exists, then recovered total pressure by taking the raw pressure field as input */
+	if ( self->rawPressureField != NULL ) {	
+		FeVariable_InterpolateWithinElement( self->rawPressureField, lElement_I, particle->xi, &pressure );
+		p_Stress[0] = p_Stress[0] - pressure; // xx 
+		p_Stress[1] = p_Stress[1] - pressure; // yy 
+		if( dim == 3 )
+			p_Stress[2] = p_Stress[2] - pressure; // zz
+	}
+
+#if DEBUG_REP
+	p_Stress[0] = 1;
+	p_Stress[1] = 1;
+	p_Stress[2] = 1;
+	p_Stress[3] = 1;
+	p_Stress[4] = 1;
+	p_Stress[5] = 1;
+#endif
+
+	if( self->recoverStrain )
+		memcpy( theCopy, p_StrainRate, dofThatExist*sizeof(double) );
+	else
+		memcpy( theCopy, p_Stress, dofThatExist*sizeof(double) );
+
+	for( dof_I = 0 ; dof_I < dofThatExist ; dof_I++ ) {
+    /* now assemble things per dof, see eq. 20 in 
+     * B.Boroomand & O.C.Zienkiewicz, 
+     * "An Improved REP Recovery and the Effectivity Robustness Test",
+     * Int. J. for Numerical Methods in Engineering, vol. 40, pages 3247-3277, 1997. */
+
+		if( self->recoverStrain ) {
+			memset( p_StrainRate, 0, dofThatExist*sizeof(double) );
+			p_StrainRate[dof_I] = theCopy[dof_I];
+		} else {
+			/* Setup raw stress tensor for RHS */
+			memset( p_Stress, 0, dofThatExist*sizeof(double) );
+			p_Stress[dof_I] = theCopy[dof_I];
+		}
+
+		/* Setup polynomial matrix for creating LHS */
+		ZeroMatrix( pMatrix, dofThatExist, order );
+		memcpy( pMatrix[dof_I], pVec, order*sizeof(double) );
+
+		if( self->recoverStrain ) {
+			Index ii;
+			if( !constitutiveMatrix ) {
+        /* if no consitutive matrix make it up - assume viscosity = 1 */
+				for( ii = 0 ; ii < dofThatExist; ii++ ) { memset( tmpC[ii], 0, dofThatExist*sizeof(double)); }
+				if (dim == 2) { tmpC[0][0] = tmpC[1][1] = tmpC[2][2] = 1; } 
+        else { tmpC[0][0] = tmpC[1][1] = tmpC[2][2] = tmpC[3][3] = tmpC[4][4] = tmpC[5][5] = 1; }
+
+			} else {
+				/* copy constitutive matrix */
+				for(ii = 0 ; ii < dofThatExist ; ii++)
+					memcpy( tmpC[ii], constitutiveMatrix->matrixData[ii], dofThatExist*sizeof(double) ); 
+			}
+      if( dim == 2 ){
+        /* modify stored constitutive matrix to account for symmetry (see CalculateStress routines)  */
+        tmpC[0][2] *= 2.0;
+        tmpC[1][2] *= 2.0;
+        tmpC[2][2] *= 2.0;
+      } else {
+        tmpC[0][3] *= 2.0;
+        tmpC[1][3] *= 2.0;
+        tmpC[2][3] *= 2.0;
+        tmpC[3][3] *= 2.0;
+        tmpC[4][3] *= 2.0;
+        tmpC[5][3] *= 2.0;
+        tmpC[0][4] *= 2.0;
+        tmpC[1][4] *= 2.0;
+        tmpC[2][4] *= 2.0;
+        tmpC[3][4] *= 2.0;
+        tmpC[4][4] *= 2.0;
+        tmpC[5][4] *= 2.0;
+        tmpC[0][5] *= 2.0;
+        tmpC[1][5] *= 2.0;
+        tmpC[2][5] *= 2.0;
+        tmpC[3][5] *= 2.0;
+        tmpC[4][5] *= 2.0;
+        tmpC[5][5] *= 2.0;
+      }
+			/* Multiply in tmpC so that we solve for strainrates */ 
+			NonSquareMatrix_MultiplicationByNonSquareMatrix(
+					tmpC, dofThatExist, dofThatExist, 
+					pMatrix, dofThatExist, order, 
+					self->CPmat);
+			ConstitutiveMatrix_CalculateStress( constitutiveMatrix, p_StrainRate, p_Stress );
+			self->_calcHi( self, GNx, self->CPmat, factor, Hi_Mat[dof_I] );
+		} else {
+			/* cal Hi, build lefthand Operator */
+			self->_calcHi( self, GNx, pMatrix, factor, Hi_Mat[dof_I] );
+		}
+		/* cal Fi, build righthand Operator */
+		self->_calcFi( self, GNx, p_Stress, factor, Fi_Mat[dof_I] );
+	}
+}
+
+void _RecoveredFeVariable_ZeroHiFi( RecoveredFeVariable* self, double*** elHi_Mat, double** elFi_Mat ) {
+	/* Function description:
+   * Zeros object Hi and Fi, probably a bit expensive */
+	int dim, order, nodesPerEl, dofThatExist, rowsInH, dof_I;
+	
+	dim = self->dim;
+	dofThatExist = self->fieldComponentCount;
+	nodesPerEl = self->nodesPerEl;
+	order = self->orderOfInterpolation;
+	rowsInH = nodesPerEl * dim;
+
+  ZeroMatrix( elFi_Mat, dofThatExist, rowsInH );
+	for( dof_I = 0 ; dof_I < dofThatExist ; dof_I++ ) 
+		ZeroMatrix( elHi_Mat[dof_I], rowsInH, order );
+}
+
+
+void _RecoveredFeVariable_CalcHi2D( RecoveredFeVariable* self, double** GNx, double** pMatrix, double factor, double** Hi ) {
+  /* See eq 24 in Boroomand and Zienk, 1997 */
+	int order, dim, row, order_I, node_I, nodesPerEl;
+	double d_dx, d_dy;
+
+	nodesPerEl = self->nodesPerEl;
+	dim = self->dim;
+	order = self->orderOfInterpolation;
+
+	for( node_I = 0 ; node_I < nodesPerEl ; node_I++ ) {
+		d_dx = GNx[0][node_I] * factor;
+		d_dy = GNx[1][node_I] * factor;
+		row  = dim*node_I;
+		for( order_I = 0 ; order_I < order ; order_I++ ) {
+			Hi[row][order_I]   += d_dx * pMatrix[0][order_I] + d_dy * pMatrix[2][order_I];
+			Hi[row+1][order_I] += d_dy * pMatrix[1][order_I] + d_dx * pMatrix[2][order_I];
+		}
+	}
+}
+
+void _RecoveredFeVariable_CalcHi3D( RecoveredFeVariable* self, double** GNx, double** pMatrix, double factor, double** Hi ) {
+  /* See eq 24 in Boroomand and Zienk, 1997 */
+	int order, dim, row, order_I, node_I, nodesPerEl;
+	double d_dx, d_dy, d_dz;
+
+	nodesPerEl = self->nodesPerEl;
+	dim = self->dim;
+	order = self->orderOfInterpolation;
+
+	for( order_I = 0 ; order_I < order ; order_I++ ) {
+		for( node_I = 0 ; node_I < nodesPerEl ; node_I++ ) {
+			d_dx = GNx[0][node_I] * factor;
+			d_dy = GNx[1][node_I] * factor;
+			d_dz = GNx[2][node_I] * factor;
+			row  = dim*node_I;
+			Hi[row][order_I]   += d_dx * pMatrix[0][order_I] + d_dy * pMatrix[3][order_I] + d_dz*pMatrix[4][order_I];
+			Hi[row+1][order_I] += d_dy * pMatrix[1][order_I] + d_dx * pMatrix[3][order_I] + d_dz*pMatrix[5][order_I];
+			Hi[row+2][order_I] += d_dz * pMatrix[2][order_I] + d_dx * pMatrix[4][order_I] + d_dy*pMatrix[5][order_I];
+		}
+	}
+}
+
+void _RecoveredFeVariable_CalcFi2D( RecoveredFeVariable* self, double** GNx, double* p_Stress, double factor, double* Fi ) {
+  /* See eq 25 in Boroomand and Zienk, 1997 */
+	int node_I, nodesPerEl, dim, row;
+	double d_dx, d_dy;
+
+	dim = self->dim;
+	nodesPerEl = self->nodesPerEl;
+
+	for( node_I = 0 ; node_I < nodesPerEl ; node_I ++ ) {
+		d_dx = GNx[0][node_I] * factor;
+		d_dy = GNx[1][node_I] * factor;
+		row  = dim*node_I;
+		/* TODO: Only in 2-D at present */
+		Fi[row]   += d_dx * p_Stress[0] + d_dy * p_Stress[2];
+		Fi[row+1] += d_dy * p_Stress[1] + d_dx * p_Stress[2];
+	}
+}
+
+void _RecoveredFeVariable_CalcFi3D( RecoveredFeVariable* self, double** GNx, double* p_Stress, double factor, double* Fi ) {
+  /* See eq 25 in Boroomand and Zienk, 1997 */
+	int node_I, nodesPerEl, dim, row;
+	double d_dx, d_dy, d_dz;
+
+	dim = self->dim;
+	nodesPerEl = self->nodesPerEl;
+
+	for( node_I = 0 ; node_I < nodesPerEl ; node_I ++ ) {
+		d_dx = GNx[0][node_I] * factor;
+		d_dy = GNx[1][node_I] * factor;
+		d_dz = GNx[2][node_I] * factor;
+		row  = dim*node_I;
+		Fi[row]   += d_dx * p_Stress[0] + d_dy * p_Stress[3] + d_dz*p_Stress[4];
+		Fi[row+1] += d_dy * p_Stress[1] + d_dx * p_Stress[3] + d_dz*p_Stress[5];
+		Fi[row+2] += d_dz * p_Stress[2] + d_dx * p_Stress[4] + d_dy*p_Stress[5];
+	}
+}
+
+void _RecoveredFeVariable_PutElIntoProc( RecoveredFeVariable* self, int lElement_I, double*** elHi_Mat, double** elFi_Mat ) {
+	int keyH, keyF, dof_I, row_I, order_I;
+	int dim, dofThatExist, order, nodesPerEl, rowsInH;
+	double* ptrH = self->elementRep_H;
+	double* ptrF = self->elementRep_F;
+
+	dim = self->dim;
+	nodesPerEl = self->nodesPerEl;
+	dofThatExist = self->fieldComponentCount;
+	order = self->orderOfInterpolation;
+	rowsInH = nodesPerEl * dim;
+	
+	for( dof_I = 0 ; dof_I < dofThatExist ; dof_I++ ) {  
+		keyH = (lElement_I*dofThatExist*rowsInH*order) + (dof_I*rowsInH*order);
+		keyF = (lElement_I*dofThatExist*rowsInH) + (dof_I*rowsInH);
+		for( row_I = 0 ; row_I < rowsInH ; row_I++ ) {
+			ptrF[ keyF + row_I ] =+ elFi_Mat[dof_I][row_I];
+
+			for( order_I = 0 ; order_I < order ; order_I++ )
+				/* lElement_I*dofThatExist*rowsInH*order + row_I*order + order_I */
+				ptrH[ (keyF + row_I)*order + order_I ] =+ elHi_Mat[dof_I][row_I][order_I];
+		}
+	}
+}
+
+void RecoveredFeVariable_CommunicateHF( RecoveredFeVariable* self ) {
+	/* Update all other procs. */
+	Sync* sync;
+	int chunkSize_H, chunkSize_F, nLocalEl;
+
+	if( self->dim ==2 ) sync = Mesh_GetSync( self->feMesh, MT_FACE );
+	else sync = Mesh_GetSync( self->feMesh, MT_VOLUME );
+
+	nLocalEl = FeMesh_GetElementLocalSize( self->feMesh );
+	chunkSize_H = self->fieldComponentCount * self->nodesPerEl * self->dim * self->orderOfInterpolation;
+	chunkSize_F = self->fieldComponentCount * self->nodesPerEl * self->dim;
+	/* Argument Describtion below:
+	 * 0) the sync object
+	 * 1) start of local address
+	 * 2) size of chunk in array
+	 * 3) location + size of local information in array
+	 * 4) size of chunk to send???
+	 * 5) size of chunk to receive??
+	 */
+	/* Sync of the elementRep_H */
+	Sync_SyncArray( sync, self->elementRep_H, chunkSize_H * sizeof(double), 
+			self->elementRep_H + nLocalEl * chunkSize_H, chunkSize_H * sizeof(double), 
+			chunkSize_H * sizeof(double) );
+
+	/* Sync of the elementRep_H */
+	Sync_SyncArray( sync, self->elementRep_F, chunkSize_F * sizeof(double), 
+			self->elementRep_F + nLocalEl * chunkSize_F, chunkSize_F * sizeof(double), 
+			chunkSize_F * sizeof(double) );
+}
+
+void RecoveredFeVariable_SetupWorkSpace( RecoveredFeVariable* self ) {
+	int dofThatExist, order, nodesPerEl, nodesInPatch, rowsInH;
+
+	nodesPerEl = self->nodesPerEl;
+	dofThatExist = self->fieldComponentCount;
+	order = self->orderOfInterpolation;
+	nodesInPatch = self->nodesInPatch;
+	rowsInH = nodesInPatch * self->dim;
+
+	/* will be useful if AMR begins, currently assumes a static mesh */
+	self->patch_H    = Memory_Alloc_3DArray( double, dofThatExist, rowsInH, order , (Name)"H_Matrix" );
+	self->patch_F    = Memory_Alloc_2DArray( double, dofThatExist, rowsInH, (Name)"F Vector" );
+	self->H_t        = Memory_Alloc_2DArray( double, order, rowsInH/*rowsInH, dofThatExist*/, " H transpose");
+	self->AMat       = Memory_Alloc_3DArray( double, dofThatExist, order, order , (Name)"AMatrix" );
+	self->bVec       = Memory_Alloc_2DArray( double, dofThatExist, order , (Name)"BVector" );
+	self->tmpEl_H    = Memory_Alloc_2DArray( double, rowsInH, order , (Name)"tmp Element H" );
+	self->tmpEl_F    = Memory_Alloc_Array( double, rowsInH, "tmp Element H");
+}
+
+void RecoveredFeVariable_RemoveWorkSpace( RecoveredFeVariable* self ) {
+	/* will be useful if AMR begins, currently assumes a static mesh */
+	Memory_Free( self->patch_H );
+	Memory_Free( self->patch_F );
+	Memory_Free( self->H_t );
+	Memory_Free( self->AMat );
+	Memory_Free( self->bVec );
+	Memory_Free( self->tmpEl_H );
+	Memory_Free( self->tmpEl_F );
+}
+
+void _RecoveredFeVariable_UnpackElement( double* ptrH, double* ptrF, int rowsInH, int order, double **el_H, double *el_F ) {
+	int row_I, order_I;
+		/* Unpack */
+		for( row_I = 0 ; row_I < rowsInH ; row_I++ ) {
+			for(order_I = 0 ; order_I < order ; order_I++ ) {
+				el_H[row_I][order_I] = ptrH[row_I*order + order_I];
+			}
+			el_F[row_I]= ptrF[row_I];
+		}
+}
+void RecoveredFeVariable_SolvePatch( RecoveredFeVariable* self, int pNodeID, int *elList, int nEl, LmStruct* lmStruct ) {
+	double **patch_H, *patch_F;
+	/* Used for unpacking */
+	double **el_H = self->tmpEl_H;
+	double *el_F = self->tmpEl_F;
+	double *ptrH, *ptrF;
+  double coeff[50];
+	IArray *inc;
+	double *coord;
+	int dim, dofThatExist, order, nodesPerEl, rowsInElH, rowsInPatchH, row, elID;
+	int dof_I, el_I, node_I, nodeID, indexOfEntry, order_I;
+	int *nodeList;
+	int chunkSize_H;
+	int chunkSize_F;
+
+	dim = self->dim;
+	nodesPerEl = self->nodesPerEl;
+	dofThatExist = self->fieldComponentCount;
+	order = self->orderOfInterpolation;
+	rowsInElH = nodesPerEl * self->dim;
+	rowsInPatchH = self->nodesInPatch * self->dim;
+
+	chunkSize_H =  self->nodesPerEl * self->dim * self->orderOfInterpolation;
+	chunkSize_F =  self->nodesPerEl * self->dim;
+
+	/* use the inc on the FeVariable */
+	inc = self->inc;
+
+	coord = Mesh_GetVertex( self->feMesh , pNodeID );
+
+	for( dof_I = 0 ; dof_I < dofThatExist ; dof_I++ ) {
+			ZeroMatrix( self->patch_H[dof_I], rowsInPatchH, order );
+	}
+	ZeroMatrix(self->patch_F, dofThatExist, rowsInPatchH );
+		
+	for( dof_I = 0 ; dof_I < dofThatExist ; dof_I++ ) {
+		patch_H = self->patch_H[dof_I];
+		patch_F = self->patch_F[dof_I];
+		for( el_I = 0 ; el_I < nEl ; el_I++ ) {
+			elID = elList[el_I];
+			ptrH = &(self->elementRep_H[ chunkSize_H * (elID*dofThatExist + dof_I) ]);
+			ptrF = &(self->elementRep_F[ chunkSize_F * (elID*dofThatExist + dof_I) ]);
+			_RecoveredFeVariable_UnpackElement( ptrH, ptrF, rowsInElH, order, el_H, el_F );
+			/* get nodes in element */
+			FeMesh_GetElementNodes( self->feMesh, elID, inc );
+			nodesPerEl = IArray_GetSize( inc );
+			nodeList = IArray_GetPtr( inc );
+			for( node_I = 0 ; node_I < nodesPerEl ; node_I++ ) {
+				nodeID = nodeList[node_I];	
+				indexOfEntry = _REP_Algorithm_locateInPatchListStruct( lmStruct, nodeID );	
+				assert( indexOfEntry != -1 );
+				row = indexOfEntry * dim;
+
+				for( order_I = 0 ; order_I < order ; order_I++ ) {
+					patch_H[row][order_I]   += el_H[node_I*dim][order_I]; 
+					patch_H[row+1][order_I] += el_H[node_I*dim+1][order_I]; 
+					if( dim == 3 )
+						patch_H[row+2][order_I] += el_H[node_I*dim+2][order_I]; 
+				}
+
+				patch_F[row] += el_F[node_I*dim];
+				patch_F[row+1] += el_F[node_I*dim+1];
+				if( dim == 3 ) 
+					patch_F[row+2] += el_F[node_I*dim+2];
+			}
+		}
+		/* Now the actual maths */
+		NonSquareMatrix_Transpose( patch_H, rowsInPatchH, order, self->H_t );
+	
+		/* 5) Construct A_Matrix = Ht_Matrix . H_Matrix */
+		NonSquareMatrix_MultiplicationByNonSquareMatrix( self->H_t, order, rowsInPatchH, 
+																patch_H, rowsInPatchH,  order, 
+																self->AMat[dof_I] );
+	
+		/* 6) Construct bMatrix = Ht_Matrix . F_Vector */
+		NonSquareMatrix_MatrixVectorMultiplication( self->H_t, order, rowsInPatchH,
+																patch_F, rowsInPatchH,
+																self->bVec[dof_I] );
+
+		_REP_Algorithm_Solver(self->AMat[dof_I], self->bVec[dof_I], order);
+		memcpy( &coeff[order*dof_I], self->bVec[dof_I], sizeof(double)*order );
+	}
+	FeVariable_SetValueAtNode( self, pNodeID , coeff );
+}
+
+void _TmpConstMat2D_CalculateStress( double** D, SymmetricTensor strainRate, SymmetricTensor stress, Bool isDiagonal ) {
+	if (isDiagonal) {
+		stress[0] = D[0][0] * strainRate[0];
+		stress[1] = D[1][1] * strainRate[1];
+		stress[2] = D[2][2] * 2.0 * strainRate[2];
+	} else {
+		stress[0] = D[0][0] * strainRate[0] + D[0][1] * strainRate[1] + D[0][2] * 2.0 * strainRate[2];
+		stress[1] = D[1][0] * strainRate[0] + D[1][1] * strainRate[1] + D[1][2] * 2.0 * strainRate[2];
+		stress[2] = D[2][0] * strainRate[0] + D[2][1] * strainRate[1] + D[2][2] * 2.0 * strainRate[2];
+	}
+}
+
+void _TmpConstMat3D_CalculateStress( double** D, SymmetricTensor strainRate, SymmetricTensor stress, Bool isDiagonal ) {
+	          	
+	if (isDiagonal) {
+		stress[0] = D[0][0] * strainRate[0];
+		stress[1] = D[1][1] * strainRate[1];
+		stress[2] = D[2][2] * strainRate[2];
+		stress[3] = D[3][3] * 2.0 * strainRate[3];
+		stress[4] = D[4][4] * 2.0 * strainRate[4];
+		stress[5] = D[5][5] * 2.0 * strainRate[5];
+	} else {
+		stress[0] = D[0][0] * strainRate[0] + D[0][1] * strainRate[1] + D[0][2] * strainRate[2] 
+			+ 2.0 * (D[0][3] * strainRate[3] + D[0][4] * strainRate[4] + D[0][5] * strainRate[5]);
+
+		stress[1] = D[1][0] * strainRate[0] + D[1][1] * strainRate[1] + D[1][2] * strainRate[2] 
+			+ 2.0 * (D[1][3] * strainRate[3] + D[1][4] * strainRate[4] + D[1][5] * strainRate[5]);
+
+		stress[2] = D[2][0] * strainRate[0] + D[2][1] * strainRate[1] + D[2][2] * strainRate[2] 
+			+ 2.0 * (D[2][3] * strainRate[3] + D[2][4] * strainRate[4] + D[2][5] * strainRate[5]);
+
+		stress[3] = D[3][0] * strainRate[0] + D[3][1] * strainRate[1] + D[3][2] * strainRate[2] 
+			+ 2.0 * (D[3][3] * strainRate[3] + D[3][4] * strainRate[4] + D[3][5] * strainRate[5]);
+
+		stress[4] = D[4][0] * strainRate[0] + D[4][1] * strainRate[1] + D[4][2] * strainRate[2] 
+			+ 2.0 * (D[4][3] * strainRate[3] + D[4][4] * strainRate[4] + D[4][5] * strainRate[5]);
+
+		stress[5] = D[5][0] * strainRate[0] + D[5][1] * strainRate[1] + D[5][2] * strainRate[2] 
+			+ 2.0 * (D[5][3] * strainRate[3] + D[5][4] * strainRate[4] + D[5][5] * strainRate[5]);
+	}
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/SPR_StrainRate.c
--- a/Utils/src/SPR_StrainRate.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,282 +0,0 @@
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Rheology/Rheology.h>
-
-#include "types.h"
-#include "BaseRecoveryFeVar.h"
-#include "SPR_StrainRate.h"
-#include "REP_Algorithm.h"
-
-#include <math.h>
-#include <assert.h>
-#include <string.h>
-
-const Type SPR_StrainRate_Type = "SPR_StrainRate";
-char*  SPR_NameOfPatch;
-
-
-SPR_StrainRate* SPR_StrainRate_New(
-	Name							name,
-	DomainContext*				context,
-	void*                   feMesh,
-   void*                   geometryMesh,
-	DofLayout*              dofLayout,                                                                                 
-   void*                   bcs,
-   void*                   ics,
-   void*                   linkedDofInfo,
-   void*                   templateFeVariable,    
-	Index							fieldComponentCount,
-	Dimension_Index			dim,
-	Bool                    isCheckpointedAndReloaded,                                                                 
-   Bool                    isReferenceSolution,                                                                       
-   Bool                    loadReferenceEachTimestep,    
- 	MPI_Comm						communicator,
-	FieldVariable_Register*	fV_Register,
-	Variable_Register*		vr, 
-	FeVariable*					rawField, 
-	int							rawOrderOfInterpolation,
-	Bool							coeffInterpolation )
-{
-  SPR_StrainRate* self = (SPR_StrainRate*)_SPR_StrainRate_DefaultNew( name );
-
-	self->isConstructed = True;
-   _FieldVariable_Init( (FieldVariable*)self, context, fieldComponentCount, dim, isCheckpointedAndReloaded, communicator, fV_Register );
-	_FeVariable_Init( (FeVariable*) self, feMesh, geometryMesh, dofLayout, bcs, ics, linkedDofInfo, templateFeVariable, isReferenceSolution, loadReferenceEachTimestep  );       
-   _BaseRecoveryFeVar_Init( (BaseRecoveryFeVar*)self, vr, rawField, rawOrderOfInterpolation, coeffInterpolation );
-   _SPR_StrainRate_Init( self );
-
-	return self;
-}
-
-void* _SPR_StrainRate_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(SPR_StrainRate);
-	Type                                                      type = SPR_StrainRate_Type;
-	Stg_Class_DeleteFunction*                              _delete = _SPR_StrainRate_Delete;
-	Stg_Class_PrintFunction*                                _print = _SPR_StrainRate_Print;
-	Stg_Class_CopyFunction*                                  _copy = _SPR_StrainRate_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _SPR_StrainRate_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _SPR_StrainRate_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _SPR_StrainRate_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _SPR_StrainRate_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _SPR_StrainRate_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _SPR_StrainRate_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 = (AllocationType)ZERO;
-	FieldVariable_InterpolateValueAtFunction*             _interpolateValueAt = ZERO;
-	FieldVariable_GetValueFunction*               _getMinGlobalFieldMagnitude = ZERO;
-	FieldVariable_GetValueFunction*               _getMaxGlobalFieldMagnitude = ZERO;
-	FieldVariable_GetCoordFunction*                  _getMinAndMaxLocalCoords = ZERO;
-	FieldVariable_GetCoordFunction*                 _getMinAndMaxGlobalCoords = ZERO;
-	FeVariable_InterpolateWithinElementFunction*    _interpolateWithinElement = ZERO;
-	FeVariable_GetValueAtNodeFunction*                        _getValueAtNode = ZERO;
-	FeVariable_SyncShadowValuesFunc*                        _syncShadowValues = ZERO;
-
-	return (void*)_SPR_StrainRate_New(  SPR_STRAINRATE_PASSARGS  );
-}
-
-SPR_StrainRate* _SPR_StrainRate_New(  SPR_STRAINRATE_DEFARGS  )
-{
-	SPR_StrainRate* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(SPR_StrainRate) );
-	self = (SPR_StrainRate*) _BaseRecoveryFeVar_New(  BASERECOVERYFEVAR_PASSARGS  );
-
-	return self;
-}
-
-void _SPR_StrainRate_Delete(  void* sprVar  ) {
-   _BaseRecoveryFeVar_Delete( sprVar );
-}
-
-/* --- Virtual Function Implementations --- */
-void _SPR_StrainRate_Destroy( void* sprVar, void *data ) {
-	_BaseRecoveryFeVar_Destroy( sprVar, data );
-}
-
-void _SPR_StrainRate_Print( void* sprVar, Stream* stream ) {
-	SPR_StrainRate* self = (SPR_StrainRate*) sprVar;
-	
-	/* General info */
-	Journal_Printf( stream, "SPR_StrainRate (ptr): %p\n", self );
-	
-	/* Print parent */
-	_FeVariable_Print( self, stream );
-}
-
-
-void* _SPR_StrainRate_Copy( const void* sprVar, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-   return NULL;
-}
-
-void _SPR_StrainRate_Init( SPR_StrainRate* self ) {
-   /* initialise the fieldComponent count here */
-   self->fieldComponentCount = StGermain_nSymmetricTensorVectorComponents(self->dim);
-
-	/* Setup basic pointers and functionPtrs that are specific to problem spec  */
-   ContextEP_Append_AlwaysLast( self->context, "stokesEqn-execute", _SPR_StrainRate_Execute );
-
-	SPR_NameOfPatch = self->name;
-}
-
-void _SPR_StrainRate_AssignFromXML( void* sprVar, Stg_ComponentFactory* cf, void* data ) {
-	SPR_StrainRate* self = (SPR_StrainRate*) sprVar;
-
-  /* Construct the parent */
-  _BaseRecoveryFeVar_AssignFromXML( self, cf, data );
-
-  _SPR_StrainRate_Init( self );
-}
-
-void _SPR_StrainRate_Build( void* sprVar, void* data ) {
-	_BaseRecoveryFeVar_Build( sprVar, data );	
-}
-
-void _SPR_StrainRate_Initialise( void* sprVar, void* data ) {
-	_BaseRecoveryFeVar_Initialise( sprVar, data );	
-}
-
-void _SPR_StrainRate_Execute( void* patch, void* data ) {
-  /* Fuction Description: is the driver of the main algorithm
-   * All repFields associated with this component will be
-   * are executed in the below functions 
-   */
-	PICelleratorContext* context = (PICelleratorContext*)data;
-	SPR_StrainRate* self = (SPR_StrainRate*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)SPR_NameOfPatch );
-	double startTime;
-	assert( self );
-
-	FeVariable_SyncShadowValues( self->rawField );
-	MPI_Barrier(MPI_COMM_WORLD);
-
-	startTime = MPI_Wtime( );
-	Journal_RPrintf( Journal_Register( Info_Type, (Name)"REP" ), "Start Recovery Method\n" );
-		
- 	/* Phases of the SPR_StrainRate in this code */
-
-	/* 1: Assemble A and b see eq. 14.31, REFERENCE and solve for [a] */
- 	_SPR_StrainRate_AssembleSolveLocalPatchs( self );	
- 	/* 2: Communicate [a]  */
-	FeVariable_SyncShadowValues( self );
- 	/* 3: Calculate the Boundary values */
-	_BaseRecoveryFeVar_Boundaries( self );
- 	/* 4: Perform a final sync for new proc boundary domain edge nodes */
-	FeVariable_SyncShadowValues( self );
-
-	Journal_RPrintf( Journal_Register( Info_Type, (Name)"REP" ), "Time Taken for Recovery Method %f\n", MPI_Wtime()-startTime);
-}
-
-
-void _SPR_StrainRate_AssembleSolveLocalPatchs( void* sprVar ) {
-	SPR_StrainRate*		self = (SPR_StrainRate*)sprVar;
-	FeVariable*				rawField = self->rawField;
- 	BoundaryNodesInfo*	bninfo = self->bninfo;
-	Index						dofThatExist = rawField->fieldComponentCount;
-	Index						orderOfInterpolation = self->orderOfInterpolation;
-	Index						dof_I, nLocalNodes, node_I;
-	double					**AMatrix;   /* holds the AMatrix */     
-	double					**bVector;   /* holds bVec for each dof */
-	double					*patchCoeff;
-	
-
-	/* Allocate memory to AMatrix and bVectors */
-	AMatrix = Memory_Alloc_2DArray( double, orderOfInterpolation, orderOfInterpolation, (Name)"A matrix"  );
-  /* multiple bVectors are needed for each dof */
-	bVector = Memory_Alloc_2DArray( double, dofThatExist, orderOfInterpolation, (Name)"b Vector * dof"  );
-	patchCoeff = Memory_Alloc_Array( double, orderOfInterpolation * dofThatExist, "tmp coefficient array" );
-	
-  nLocalNodes = FeMesh_GetNodeLocalSize( self->rawField->feMesh );
-
-  /* loop through patchable nodes assembling AMatrix and bVectors and solving for patch coefficients */
-  for( node_I = 0 ; node_I < nLocalNodes ; node_I++ ) {
-    if( bninfo[node_I].onMeshBoundary )
-      continue;
-    ZeroMatrix( AMatrix, orderOfInterpolation, orderOfInterpolation );
-    ZeroMatrix( bVector, dofThatExist, orderOfInterpolation );
-
-    _SPR_StrainRate_AssemblePatch( self, node_I, AMatrix, bVector);
-
-    for( dof_I = 0 ; dof_I < dofThatExist ; dof_I++ ) {
-      _REP_Algorithm_Solver( AMatrix, bVector[dof_I], orderOfInterpolation );
-      /* copy bVector into the corresponding patchCoeff array */
-      memcpy( &patchCoeff[dof_I*orderOfInterpolation], bVector[dof_I], orderOfInterpolation*sizeof(double) );
-    }
-    /* write all dof patch coefficients on the node */
-    FeVariable_SetValueAtNode( self, node_I , patchCoeff );
-  }
-
-	Memory_Free( AMatrix );
-	Memory_Free( bVector );
-	Memory_Free( patchCoeff );
-	
-}
-
-void _SPR_StrainRate_AssemblePatch( SPR_StrainRate* self, int node_I, double** AMatrix, double** bVector) {
-/* Functiona Details:
- * This assembles the AMatrix and the bVectors, see eq. 14.31, REFERENCE.
- * First the elements around the patch node are found, then for each element the
- * cooordinate and the strain rate at the super convergent locations are stored.
- */
-
-	FeVariable*			rawField = self->rawField;
-	FeMesh*				feMesh = (FeMesh*)rawField->feMesh;
-	Index					dofThatExist = rawField->fieldComponentCount;
-	Index					nbrEl_I, nbrElementID, nbrElCount;
-	Index					count_i, count_j, dof_I;
-	double				center[3] = {0.0,0.0,0.0};
-	int					orderOfInterpolation = self->orderOfInterpolation;
-	IArray*				inc = self->inc; 
-
-	SymmetricTensor	*scp_eps; 
-	double				**globalCoord;
-	double				**pVec;
-	int					*nbrElList;    
-
-	/* 1) find the elements around the node and point to them via the nbrElList*/
-	FeMesh_GetNodeElements( feMesh, node_I, inc );
-	nbrElCount = IArray_GetSize( inc );
-	nbrElList = IArray_GetPtr( inc );
-
-	/* 2) Memory Allocations + Initialisations */
-	scp_eps  = Memory_Alloc_Array( SymmetricTensor, nbrElCount, "StrainRate at superconvergent points" );
-
-	globalCoord = Memory_Alloc_2DArray( double, nbrElCount, self->dim, (Name)"Global Coords of superconvergent points"  );
-
-	pVec = Memory_Alloc_2DArray( double, nbrElCount, orderOfInterpolation, (Name)"Holds transformed global coord polynomials" );
-
-	/* 3 ) Now collect information, to go find each elements contribution to the patch 
-   * So find the p vectors and strain-rate pseudo vectors for the Ax=b equation
-   * */
-	for( nbrEl_I = 0 ; nbrEl_I < nbrElCount ; nbrEl_I++ ) {
-		nbrElementID = nbrElList[ nbrEl_I ];
-
-		FeMesh_CoordLocalToGlobal( feMesh, nbrElementID, center, globalCoord[nbrEl_I] );
-		self->_makePoly( globalCoord[nbrEl_I], pVec[nbrEl_I] );
-
-		FeVariable_InterpolateWithinElement( rawField , nbrElList[nbrEl_I], center, scp_eps[nbrEl_I] );
-	}
-
- 	/* Construct A Matrix (Geometric based) and b Vectors (tensor based) */
-	for( nbrEl_I = 0 ; nbrEl_I < nbrElCount ; nbrEl_I++ ) {
-		for( count_i = 0 ; count_i < orderOfInterpolation ; count_i++ ) {
-			for( count_j = 0; count_j < orderOfInterpolation ; count_j++ ) {
-				AMatrix[count_i][count_j] += ( pVec[nbrEl_I][count_i] * pVec[nbrEl_I][count_j] );
-			}
-		}
-		for(dof_I = 0 ; dof_I < dofThatExist ; dof_I++ ) {
-			for( count_i = 0 ; count_i < orderOfInterpolation ; count_i++ ) {
-				bVector[dof_I][ count_i ] += (scp_eps[nbrEl_I][dof_I] * pVec[nbrEl_I][count_i]);
-			}
- 		}
-	}
-	Memory_Free( scp_eps );
-	Memory_Free( globalCoord );
-	Memory_Free( pVec );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/SPR_StrainRate.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/SPR_StrainRate.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,282 @@
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Rheology/Rheology.h>
+
+#include "types.h"
+#include "BaseRecoveryFeVar.h"
+#include "SPR_StrainRate.h"
+#include "REP_Algorithm.h"
+
+#include <math.h>
+#include <assert.h>
+#include <string.h>
+
+const Type SPR_StrainRate_Type = "SPR_StrainRate";
+char*  SPR_NameOfPatch;
+
+
+SPR_StrainRate* SPR_StrainRate_New(
+	Name							name,
+	DomainContext*				context,
+	void*                   feMesh,
+   void*                   geometryMesh,
+	DofLayout*              dofLayout,                                                                                 
+   void*                   bcs,
+   void*                   ics,
+   void*                   linkedDofInfo,
+   void*                   templateFeVariable,    
+	Index							fieldComponentCount,
+	Dimension_Index			dim,
+	Bool                    isCheckpointedAndReloaded,                                                                 
+   Bool                    isReferenceSolution,                                                                       
+   Bool                    loadReferenceEachTimestep,    
+ 	MPI_Comm						communicator,
+	FieldVariable_Register*	fV_Register,
+	Variable_Register*		vr, 
+	FeVariable*					rawField, 
+	int							rawOrderOfInterpolation,
+	Bool							coeffInterpolation )
+{
+  SPR_StrainRate* self = (SPR_StrainRate*)_SPR_StrainRate_DefaultNew( name );
+
+	self->isConstructed = True;
+   _FieldVariable_Init( (FieldVariable*)self, context, fieldComponentCount, dim, isCheckpointedAndReloaded, communicator, fV_Register );
+	_FeVariable_Init( (FeVariable*) self, feMesh, geometryMesh, dofLayout, bcs, ics, linkedDofInfo, templateFeVariable, isReferenceSolution, loadReferenceEachTimestep  );       
+   _BaseRecoveryFeVar_Init( (BaseRecoveryFeVar*)self, vr, rawField, rawOrderOfInterpolation, coeffInterpolation );
+   _SPR_StrainRate_Init( self );
+
+	return self;
+}
+
+void* _SPR_StrainRate_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(SPR_StrainRate);
+	Type                                                      type = SPR_StrainRate_Type;
+	Stg_Class_DeleteFunction*                              _delete = _SPR_StrainRate_Delete;
+	Stg_Class_PrintFunction*                                _print = _SPR_StrainRate_Print;
+	Stg_Class_CopyFunction*                                  _copy = _SPR_StrainRate_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _SPR_StrainRate_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _SPR_StrainRate_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _SPR_StrainRate_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _SPR_StrainRate_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _SPR_StrainRate_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _SPR_StrainRate_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 = (AllocationType)ZERO;
+	FieldVariable_InterpolateValueAtFunction*             _interpolateValueAt = ZERO;
+	FieldVariable_GetValueFunction*               _getMinGlobalFieldMagnitude = ZERO;
+	FieldVariable_GetValueFunction*               _getMaxGlobalFieldMagnitude = ZERO;
+	FieldVariable_GetCoordFunction*                  _getMinAndMaxLocalCoords = ZERO;
+	FieldVariable_GetCoordFunction*                 _getMinAndMaxGlobalCoords = ZERO;
+	FeVariable_InterpolateWithinElementFunction*    _interpolateWithinElement = ZERO;
+	FeVariable_GetValueAtNodeFunction*                        _getValueAtNode = ZERO;
+	FeVariable_SyncShadowValuesFunc*                        _syncShadowValues = ZERO;
+
+	return (void*)_SPR_StrainRate_New(  SPR_STRAINRATE_PASSARGS  );
+}
+
+SPR_StrainRate* _SPR_StrainRate_New(  SPR_STRAINRATE_DEFARGS  )
+{
+	SPR_StrainRate* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(SPR_StrainRate) );
+	self = (SPR_StrainRate*) _BaseRecoveryFeVar_New(  BASERECOVERYFEVAR_PASSARGS  );
+
+	return self;
+}
+
+void _SPR_StrainRate_Delete(  void* sprVar  ) {
+   _BaseRecoveryFeVar_Delete( sprVar );
+}
+
+/* --- Virtual Function Implementations --- */
+void _SPR_StrainRate_Destroy( void* sprVar, void *data ) {
+	_BaseRecoveryFeVar_Destroy( sprVar, data );
+}
+
+void _SPR_StrainRate_Print( void* sprVar, Stream* stream ) {
+	SPR_StrainRate* self = (SPR_StrainRate*) sprVar;
+	
+	/* General info */
+	Journal_Printf( stream, "SPR_StrainRate (ptr): %p\n", self );
+	
+	/* Print parent */
+	_FeVariable_Print( self, stream );
+}
+
+
+void* _SPR_StrainRate_Copy( const void* sprVar, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+   return NULL;
+}
+
+void _SPR_StrainRate_Init( SPR_StrainRate* self ) {
+   /* initialise the fieldComponent count here */
+   self->fieldComponentCount = StGermain_nSymmetricTensorVectorComponents(self->dim);
+
+	/* Setup basic pointers and functionPtrs that are specific to problem spec  */
+   ContextEP_Append_AlwaysLast( self->context, "stokesEqn-execute", _SPR_StrainRate_Execute );
+
+	SPR_NameOfPatch = self->name;
+}
+
+void _SPR_StrainRate_AssignFromXML( void* sprVar, Stg_ComponentFactory* cf, void* data ) {
+	SPR_StrainRate* self = (SPR_StrainRate*) sprVar;
+
+  /* Construct the parent */
+  _BaseRecoveryFeVar_AssignFromXML( self, cf, data );
+
+  _SPR_StrainRate_Init( self );
+}
+
+void _SPR_StrainRate_Build( void* sprVar, void* data ) {
+	_BaseRecoveryFeVar_Build( sprVar, data );	
+}
+
+void _SPR_StrainRate_Initialise( void* sprVar, void* data ) {
+	_BaseRecoveryFeVar_Initialise( sprVar, data );	
+}
+
+void _SPR_StrainRate_Execute( void* patch, void* data ) {
+  /* Fuction Description: is the driver of the main algorithm
+   * All repFields associated with this component will be
+   * are executed in the below functions 
+   */
+	PICelleratorContext* context = (PICelleratorContext*)data;
+	SPR_StrainRate* self = (SPR_StrainRate*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)SPR_NameOfPatch );
+	double startTime;
+	assert( self );
+
+	FeVariable_SyncShadowValues( self->rawField );
+	MPI_Barrier(MPI_COMM_WORLD);
+
+	startTime = MPI_Wtime( );
+	Journal_RPrintf( Journal_Register( Info_Type, (Name)"REP" ), "Start Recovery Method\n" );
+		
+ 	/* Phases of the SPR_StrainRate in this code */
+
+	/* 1: Assemble A and b see eq. 14.31, REFERENCE and solve for [a] */
+ 	_SPR_StrainRate_AssembleSolveLocalPatchs( self );	
+ 	/* 2: Communicate [a]  */
+	FeVariable_SyncShadowValues( self );
+ 	/* 3: Calculate the Boundary values */
+	_BaseRecoveryFeVar_Boundaries( self );
+ 	/* 4: Perform a final sync for new proc boundary domain edge nodes */
+	FeVariable_SyncShadowValues( self );
+
+	Journal_RPrintf( Journal_Register( Info_Type, (Name)"REP" ), "Time Taken for Recovery Method %f\n", MPI_Wtime()-startTime);
+}
+
+
+void _SPR_StrainRate_AssembleSolveLocalPatchs( void* sprVar ) {
+	SPR_StrainRate*		self = (SPR_StrainRate*)sprVar;
+	FeVariable*				rawField = self->rawField;
+ 	BoundaryNodesInfo*	bninfo = self->bninfo;
+	Index						dofThatExist = rawField->fieldComponentCount;
+	Index						orderOfInterpolation = self->orderOfInterpolation;
+	Index						dof_I, nLocalNodes, node_I;
+	double					**AMatrix;   /* holds the AMatrix */     
+	double					**bVector;   /* holds bVec for each dof */
+	double					*patchCoeff;
+	
+
+	/* Allocate memory to AMatrix and bVectors */
+	AMatrix = Memory_Alloc_2DArray( double, orderOfInterpolation, orderOfInterpolation, (Name)"A matrix"  );
+  /* multiple bVectors are needed for each dof */
+	bVector = Memory_Alloc_2DArray( double, dofThatExist, orderOfInterpolation, (Name)"b Vector * dof"  );
+	patchCoeff = Memory_Alloc_Array( double, orderOfInterpolation * dofThatExist, "tmp coefficient array" );
+	
+  nLocalNodes = FeMesh_GetNodeLocalSize( self->rawField->feMesh );
+
+  /* loop through patchable nodes assembling AMatrix and bVectors and solving for patch coefficients */
+  for( node_I = 0 ; node_I < nLocalNodes ; node_I++ ) {
+    if( bninfo[node_I].onMeshBoundary )
+      continue;
+    ZeroMatrix( AMatrix, orderOfInterpolation, orderOfInterpolation );
+    ZeroMatrix( bVector, dofThatExist, orderOfInterpolation );
+
+    _SPR_StrainRate_AssemblePatch( self, node_I, AMatrix, bVector);
+
+    for( dof_I = 0 ; dof_I < dofThatExist ; dof_I++ ) {
+      _REP_Algorithm_Solver( AMatrix, bVector[dof_I], orderOfInterpolation );
+      /* copy bVector into the corresponding patchCoeff array */
+      memcpy( &patchCoeff[dof_I*orderOfInterpolation], bVector[dof_I], orderOfInterpolation*sizeof(double) );
+    }
+    /* write all dof patch coefficients on the node */
+    FeVariable_SetValueAtNode( self, node_I , patchCoeff );
+  }
+
+	Memory_Free( AMatrix );
+	Memory_Free( bVector );
+	Memory_Free( patchCoeff );
+	
+}
+
+void _SPR_StrainRate_AssemblePatch( SPR_StrainRate* self, int node_I, double** AMatrix, double** bVector) {
+/* Functiona Details:
+ * This assembles the AMatrix and the bVectors, see eq. 14.31, REFERENCE.
+ * First the elements around the patch node are found, then for each element the
+ * cooordinate and the strain rate at the super convergent locations are stored.
+ */
+
+	FeVariable*			rawField = self->rawField;
+	FeMesh*				feMesh = (FeMesh*)rawField->feMesh;
+	Index					dofThatExist = rawField->fieldComponentCount;
+	Index					nbrEl_I, nbrElementID, nbrElCount;
+	Index					count_i, count_j, dof_I;
+	double				center[3] = {0.0,0.0,0.0};
+	int					orderOfInterpolation = self->orderOfInterpolation;
+	IArray*				inc = self->inc; 
+
+	SymmetricTensor	*scp_eps; 
+	double				**globalCoord;
+	double				**pVec;
+	int					*nbrElList;    
+
+	/* 1) find the elements around the node and point to them via the nbrElList*/
+	FeMesh_GetNodeElements( feMesh, node_I, inc );
+	nbrElCount = IArray_GetSize( inc );
+	nbrElList = IArray_GetPtr( inc );
+
+	/* 2) Memory Allocations + Initialisations */
+	scp_eps  = Memory_Alloc_Array( SymmetricTensor, nbrElCount, "StrainRate at superconvergent points" );
+
+	globalCoord = Memory_Alloc_2DArray( double, nbrElCount, self->dim, (Name)"Global Coords of superconvergent points"  );
+
+	pVec = Memory_Alloc_2DArray( double, nbrElCount, orderOfInterpolation, (Name)"Holds transformed global coord polynomials" );
+
+	/* 3 ) Now collect information, to go find each elements contribution to the patch 
+   * So find the p vectors and strain-rate pseudo vectors for the Ax=b equation
+   * */
+	for( nbrEl_I = 0 ; nbrEl_I < nbrElCount ; nbrEl_I++ ) {
+		nbrElementID = nbrElList[ nbrEl_I ];
+
+		FeMesh_CoordLocalToGlobal( feMesh, nbrElementID, center, globalCoord[nbrEl_I] );
+		self->_makePoly( globalCoord[nbrEl_I], pVec[nbrEl_I] );
+
+		FeVariable_InterpolateWithinElement( rawField , nbrElList[nbrEl_I], center, scp_eps[nbrEl_I] );
+	}
+
+ 	/* Construct A Matrix (Geometric based) and b Vectors (tensor based) */
+	for( nbrEl_I = 0 ; nbrEl_I < nbrElCount ; nbrEl_I++ ) {
+		for( count_i = 0 ; count_i < orderOfInterpolation ; count_i++ ) {
+			for( count_j = 0; count_j < orderOfInterpolation ; count_j++ ) {
+				AMatrix[count_i][count_j] += ( pVec[nbrEl_I][count_i] * pVec[nbrEl_I][count_j] );
+			}
+		}
+		for(dof_I = 0 ; dof_I < dofThatExist ; dof_I++ ) {
+			for( count_i = 0 ; count_i < orderOfInterpolation ; count_i++ ) {
+				bVector[dof_I][ count_i ] += (scp_eps[nbrEl_I][dof_I] * pVec[nbrEl_I][count_i]);
+			}
+ 		}
+	}
+	Memory_Free( scp_eps );
+	Memory_Free( globalCoord );
+	Memory_Free( pVec );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/SmoothVelGradField.c
--- a/Utils/src/SmoothVelGradField.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,279 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Monash Cluster Computing, Australia
-** (C) 2003-2004 All Rights Reserved
-**
-** Primary Authors:
-** Luke Hodkinson
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#include <mpi.h>
-
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Rheology/Rheology.h>
-
-#include "types.h"
-#include "SmoothVelGradField.h"
-
-const Type SmoothVelGradField_Type = "SmoothVelGradField";
-
-/*
-** Constructors/Destructors.
-*/
-
-SmoothVelGradField* _SmoothVelGradField_New(  SMOOTHVELGRADFIELD_DEFARGS  ) {
-   SmoothVelGradField* self;
-
-   assert( _sizeOfSelf >= sizeof(SmoothVelGradField) );
-   self = (SmoothVelGradField*)_ParticleFeVariable_New(  PARTICLEFEVARIABLE_PASSARGS  );
-
-   return self;
-}
-
-void _SmoothVelGradField_Init(
-	SmoothVelGradField*		self,
-	Variable_Register*		variable_Register,
-	FeVariable*					velField,
-	SystemLinearEquations*	sle)
-{
-   self->variable_Register = variable_Register;
-   self->fieldComponentCount = 1;
-   self->useDeriv = True;
-   self->velField = velField;
-
-   if( sle )
-      SystemLinearEquations_AddPostNonLinearEP( sle, SmoothVelGradField_Type, SmoothVelGradField_NonLinearUpdate );
-}
-
-void* _SmoothVelGradField_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                       _sizeOfSelf = sizeof(SmoothVelGradField);
-	Type                                                               type = SmoothVelGradField_Type;
-	Stg_Class_DeleteFunction*                                       _delete = _SmoothVelGradField_Delete;
-	Stg_Class_PrintFunction*                                         _print = _SmoothVelGradField_Print;
-	Stg_Class_CopyFunction*                                           _copy = _SmoothVelGradField_Copy;
-	Stg_Component_DefaultConstructorFunction*           _defaultConstructor = _SmoothVelGradField_DefaultNew;
-	Stg_Component_ConstructFunction*                             _construct = _SmoothVelGradField_AssignFromXML;
-	Stg_Component_BuildFunction*                                     _build = _SmoothVelGradField_Build;
-	Stg_Component_InitialiseFunction*                           _initialise = _SmoothVelGradField_Initialise;
-	Stg_Component_ExecuteFunction*                                 _execute = _SmoothVelGradField_Execute;
-	Stg_Component_DestroyFunction*                                 _destroy = _SmoothVelGradField_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 = _SmoothVelGradField_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 = ZERO;
-	FieldVariable_GetValueFunction*   _getMaxGlobalFieldMagnitude = ZERO;
-	FeVariable_SyncShadowValuesFunc*            _syncShadowValues = ZERO;
-
-   return (void*) _SmoothVelGradField_New(  SMOOTHVELGRADFIELD_PASSARGS  );
-}
-
-void _SmoothVelGradField_Delete( void* _self ) {
-   SmoothVelGradField* self = (SmoothVelGradField*) _self;
-
-   _ParticleFeVariable_Delete( self );
-}
-
-/*
-** Methods.
-*/
-
-void _SmoothVelGradField_Print( void* _self, Stream* stream ) {
-   SmoothVelGradField* self = (SmoothVelGradField*)_self;
-
-   /* General info */
-   Journal_Printf( stream, "SmoothVelGradField (ptr): %p\n", self );
-
-   /* Print parent */
-   _ParticleFeVariable_Print( self, stream );
-}
-
-void* _SmoothVelGradField_Copy( const void* _self, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-   abort();
-}
-
-void SmoothVelGradField_NonLinearUpdate( void* _sle, void* _ctx ) {
-   SystemLinearEquations* sle;
-   DomainContext* ctx = (DomainContext*)_ctx;
-   FieldVariable_Register* fieldVar_Register;
-   SmoothVelGradField* preVar;
-
-	sle = (SystemLinearEquations*)_sle;
-   fieldVar_Register = ctx->fieldVariable_Register;
-   preVar = (SmoothVelGradField*)FieldVariable_Register_GetByName( fieldVar_Register, "VelocityGradientsField" );
-   ParticleFeVariable_Update( preVar );
-}
-
-void _SmoothVelGradField_AssignFromXML( void* _self, Stg_ComponentFactory* cf, void* data ){
-   SmoothVelGradField* self = (SmoothVelGradField*) _self;
-   Variable_Register* variable_Register;
-   SystemLinearEquations* sle;
-   FeVariable* velField;
-
-   /* Construct Parent */
-   _ParticleFeVariable_AssignFromXML( self, cf, data );
-
-   variable_Register = self->context->variable_Register;
-   assert( variable_Register );
-
-   velField = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"VelocityField", FeVariable, True, data  );
-
-	/*
-   ** If we're using this field for non-linear feedback, we'll need to update it in between
-   ** non-linear iterations. */
-   sle = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"SLE", SystemLinearEquations, False, data  );
-
-   _SmoothVelGradField_Init( self, variable_Register, velField, sle );
-}
-
-void _SmoothVelGradField_Build( void* _self, void* data ) {
-   SmoothVelGradField* self = (SmoothVelGradField*) _self;
-   char* tmpName;
-   char* variableName[9];
-   Variable_Index variable_I;
-   Node_DomainIndex  node_I;
-   int dim;
-
-   Stg_Component_Build( self->feMesh, data, False );
-   Stg_Component_Build( self->velField, data, False );
-   dim = Mesh_GetDimSize( self->feMesh );
-   self->fieldComponentCount = dim * dim;
-
-   /* Need some names for sub variables. */
-   if( dim == 2 ) {
-      variableName[0] = StG_Strdup( "vel_grad_xx" );
-      variableName[1] = StG_Strdup( "vel_grad_xy" );
-      variableName[2] = StG_Strdup( "vel_grad_yx" );
-      variableName[3] = StG_Strdup( "vel_grad_yy" );
-   }
-   else {
-      variableName[0] = StG_Strdup( "vel_grad_xx" );
-      variableName[1] = StG_Strdup( "vel_grad_xy" );
-      variableName[2] = StG_Strdup( "vel_grad_xz" );
-      variableName[3] = StG_Strdup( "vel_grad_yx" );
-      variableName[4] = StG_Strdup( "vel_grad_yy" );
-      variableName[5] = StG_Strdup( "vel_grad_yz" );
-      variableName[6] = StG_Strdup( "vel_grad_zx" );
-      variableName[7] = StG_Strdup( "vel_grad_zy" );
-      variableName[8] = StG_Strdup( "vel_grad_zz" );
-   }
-
-   /* Create Variable to store data */
-   assert( Class_IsSuper( self->feMesh->topo, IGraph ) );
-   tmpName = Stg_Object_AppendSuffix( self, (Name)"DataVariable"  );
-   self->dataVariable = Variable_NewVector(
-      tmpName,
-		(AbstractContext*)self->context,	
-      Variable_DataType_Double, 
-      self->fieldComponentCount,
-      (Index*)(&((IGraph*)self->feMesh->topo)->remotes[MT_VERTEX]->nDomains), 
-      NULL,
-      (void**)&self->data, 
-      self->variable_Register,
-      variableName[0],
-      variableName[1],
-      variableName[2],
-      variableName[3],
-      variableName[4],
-      variableName[5],
-      variableName[6],
-      variableName[7],
-      variableName[8] );
-   Memory_Free( tmpName );
-
-   /* Create Dof Layout */
-   tmpName = Stg_Object_AppendSuffix( self, (Name)"DofLayout"  );
-   self->dofLayout = DofLayout_New( tmpName, self->context, self->variable_Register, 0, self->feMesh );
-   self->dofLayout->_numItemsInLayout = FeMesh_GetNodeDomainSize( self->feMesh );
-   for( variable_I = 0; variable_I < self->fieldComponentCount ; variable_I++ ) {
-      self->dataVariableList[ variable_I ] = Variable_Register_GetByName( self->variable_Register, 
-									  variableName[ variable_I ] );
-      for( node_I = 0; node_I < FeMesh_GetNodeDomainSize( self->feMesh ); node_I++ )
-         DofLayout_AddDof_ByVarName( self->dofLayout, variableName[variable_I], node_I );
-		/* Free Name */
-		Memory_Free( variableName[ variable_I ] );
-   }
-   Memory_Free( tmpName );
-   self->eqNum->dofLayout = self->dofLayout;
-
-   /* Build and Update all Variables that this component has created */
-   Stg_Component_Build( self->dataVariable, data, False);
-   Variable_Update( self->dataVariable );
-   for( variable_I = 0; variable_I < self->fieldComponentCount ; variable_I++ ) {
-      Stg_Component_Build( self->dataVariableList[ variable_I ], data, False);
-      Variable_Update( self->dataVariableList[ variable_I ] );
-   }
-
-   _ParticleFeVariable_Build( self, data );
-
-   /* Update again, just in case things were changed/reallocated when ICs loaded */
-   Variable_Update( self->dataVariable );
-   for( variable_I = 0; variable_I < self->fieldComponentCount ; variable_I++ )
-      Variable_Update( self->dataVariableList[ variable_I ] );
-}
-
-void _SmoothVelGradField_Initialise( void* _self, void* data ) {
-   SmoothVelGradField* self = (SmoothVelGradField*) _self;
-   Variable_Index variable_I;
-
-   Stg_Component_Initialise( self->velField, data, False );
-
-   /* Initialise and Update all Variables that this component has created */
-   Stg_Component_Initialise( self->dataVariable, data, False); Variable_Update( self->dataVariable );
-   for( variable_I = 0; variable_I < self->fieldComponentCount ; variable_I++ ) {
-      Stg_Component_Initialise( self->dataVariableList[ variable_I ], data, False);
-      Variable_Update( self->dataVariableList[ variable_I ] );
-   }
-	
-   _ParticleFeVariable_Initialise( self, data );
-
-   /* Do a post-update just in case */
-   Variable_Update( self->dataVariable );
-   for( variable_I = 0; variable_I < self->fieldComponentCount ; variable_I++ )
-      Variable_Update( self->dataVariableList[ variable_I ] );
-}
-
-void _SmoothVelGradField_Execute( void* _self, void* data ) {
-   SmoothVelGradField* self = (SmoothVelGradField*) _self;
-
-   _ParticleFeVariable_Execute( self, data );
-}
-
-void _SmoothVelGradField_Destroy( void* _self, void* data ) {
-   SmoothVelGradField* self = (SmoothVelGradField*) _self;
-
-   Stg_Component_Destroy( self->velField, data, False );
-
-   _ParticleFeVariable_Destroy( self, data );
-}
-
-void _SmoothVelGradField_ValueAtParticle(
-	void*							_self,
-	IntegrationPointsSwarm*	swarm,
-	Element_LocalIndex		lElement_I,
-	void*							_particle,
-	double*						velGrad )
-{
-   SmoothVelGradField* self = (SmoothVelGradField*)_self;
-
-   assert( self->useDeriv );
-   assert( self->GNx );
-
-   FeVariable_InterpolateDerivatives_WithGNx( self->velField, lElement_I, self->GNx, velGrad );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/SmoothVelGradField.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/SmoothVelGradField.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,279 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Monash Cluster Computing, Australia
+** (C) 2003-2004 All Rights Reserved
+**
+** Primary Authors:
+** Luke Hodkinson
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include <mpi.h>
+
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Rheology/Rheology.h>
+
+#include "types.h"
+#include "SmoothVelGradField.h"
+
+const Type SmoothVelGradField_Type = "SmoothVelGradField";
+
+/*
+** Constructors/Destructors.
+*/
+
+SmoothVelGradField* _SmoothVelGradField_New(  SMOOTHVELGRADFIELD_DEFARGS  ) {
+   SmoothVelGradField* self;
+
+   assert( _sizeOfSelf >= sizeof(SmoothVelGradField) );
+   self = (SmoothVelGradField*)_ParticleFeVariable_New(  PARTICLEFEVARIABLE_PASSARGS  );
+
+   return self;
+}
+
+void _SmoothVelGradField_Init(
+	SmoothVelGradField*		self,
+	Variable_Register*		variable_Register,
+	FeVariable*					velField,
+	SystemLinearEquations*	sle)
+{
+   self->variable_Register = variable_Register;
+   self->fieldComponentCount = 1;
+   self->useDeriv = True;
+   self->velField = velField;
+
+   if( sle )
+      SystemLinearEquations_AddPostNonLinearEP( sle, SmoothVelGradField_Type, SmoothVelGradField_NonLinearUpdate );
+}
+
+void* _SmoothVelGradField_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                       _sizeOfSelf = sizeof(SmoothVelGradField);
+	Type                                                               type = SmoothVelGradField_Type;
+	Stg_Class_DeleteFunction*                                       _delete = _SmoothVelGradField_Delete;
+	Stg_Class_PrintFunction*                                         _print = _SmoothVelGradField_Print;
+	Stg_Class_CopyFunction*                                           _copy = _SmoothVelGradField_Copy;
+	Stg_Component_DefaultConstructorFunction*           _defaultConstructor = _SmoothVelGradField_DefaultNew;
+	Stg_Component_ConstructFunction*                             _construct = _SmoothVelGradField_AssignFromXML;
+	Stg_Component_BuildFunction*                                     _build = _SmoothVelGradField_Build;
+	Stg_Component_InitialiseFunction*                           _initialise = _SmoothVelGradField_Initialise;
+	Stg_Component_ExecuteFunction*                                 _execute = _SmoothVelGradField_Execute;
+	Stg_Component_DestroyFunction*                                 _destroy = _SmoothVelGradField_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 = _SmoothVelGradField_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 = ZERO;
+	FieldVariable_GetValueFunction*   _getMaxGlobalFieldMagnitude = ZERO;
+	FeVariable_SyncShadowValuesFunc*            _syncShadowValues = ZERO;
+
+   return (void*) _SmoothVelGradField_New(  SMOOTHVELGRADFIELD_PASSARGS  );
+}
+
+void _SmoothVelGradField_Delete( void* _self ) {
+   SmoothVelGradField* self = (SmoothVelGradField*) _self;
+
+   _ParticleFeVariable_Delete( self );
+}
+
+/*
+** Methods.
+*/
+
+void _SmoothVelGradField_Print( void* _self, Stream* stream ) {
+   SmoothVelGradField* self = (SmoothVelGradField*)_self;
+
+   /* General info */
+   Journal_Printf( stream, "SmoothVelGradField (ptr): %p\n", self );
+
+   /* Print parent */
+   _ParticleFeVariable_Print( self, stream );
+}
+
+void* _SmoothVelGradField_Copy( const void* _self, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+   abort();
+}
+
+void SmoothVelGradField_NonLinearUpdate( void* _sle, void* _ctx ) {
+   SystemLinearEquations* sle;
+   DomainContext* ctx = (DomainContext*)_ctx;
+   FieldVariable_Register* fieldVar_Register;
+   SmoothVelGradField* preVar;
+
+	sle = (SystemLinearEquations*)_sle;
+   fieldVar_Register = ctx->fieldVariable_Register;
+   preVar = (SmoothVelGradField*)FieldVariable_Register_GetByName( fieldVar_Register, "VelocityGradientsField" );
+   ParticleFeVariable_Update( preVar );
+}
+
+void _SmoothVelGradField_AssignFromXML( void* _self, Stg_ComponentFactory* cf, void* data ){
+   SmoothVelGradField* self = (SmoothVelGradField*) _self;
+   Variable_Register* variable_Register;
+   SystemLinearEquations* sle;
+   FeVariable* velField;
+
+   /* Construct Parent */
+   _ParticleFeVariable_AssignFromXML( self, cf, data );
+
+   variable_Register = self->context->variable_Register;
+   assert( variable_Register );
+
+   velField = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"VelocityField", FeVariable, True, data  );
+
+	/*
+   ** If we're using this field for non-linear feedback, we'll need to update it in between
+   ** non-linear iterations. */
+   sle = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"SLE", SystemLinearEquations, False, data  );
+
+   _SmoothVelGradField_Init( self, variable_Register, velField, sle );
+}
+
+void _SmoothVelGradField_Build( void* _self, void* data ) {
+   SmoothVelGradField* self = (SmoothVelGradField*) _self;
+   char* tmpName;
+   char* variableName[9];
+   Variable_Index variable_I;
+   Node_DomainIndex  node_I;
+   int dim;
+
+   Stg_Component_Build( self->feMesh, data, False );
+   Stg_Component_Build( self->velField, data, False );
+   dim = Mesh_GetDimSize( self->feMesh );
+   self->fieldComponentCount = dim * dim;
+
+   /* Need some names for sub variables. */
+   if( dim == 2 ) {
+      variableName[0] = StG_Strdup( "vel_grad_xx" );
+      variableName[1] = StG_Strdup( "vel_grad_xy" );
+      variableName[2] = StG_Strdup( "vel_grad_yx" );
+      variableName[3] = StG_Strdup( "vel_grad_yy" );
+   }
+   else {
+      variableName[0] = StG_Strdup( "vel_grad_xx" );
+      variableName[1] = StG_Strdup( "vel_grad_xy" );
+      variableName[2] = StG_Strdup( "vel_grad_xz" );
+      variableName[3] = StG_Strdup( "vel_grad_yx" );
+      variableName[4] = StG_Strdup( "vel_grad_yy" );
+      variableName[5] = StG_Strdup( "vel_grad_yz" );
+      variableName[6] = StG_Strdup( "vel_grad_zx" );
+      variableName[7] = StG_Strdup( "vel_grad_zy" );
+      variableName[8] = StG_Strdup( "vel_grad_zz" );
+   }
+
+   /* Create Variable to store data */
+   assert( Class_IsSuper( self->feMesh->topo, IGraph ) );
+   tmpName = Stg_Object_AppendSuffix( self, (Name)"DataVariable"  );
+   self->dataVariable = Variable_NewVector(
+      tmpName,
+		(AbstractContext*)self->context,	
+      Variable_DataType_Double, 
+      self->fieldComponentCount,
+      (Index*)(&((IGraph*)self->feMesh->topo)->remotes[MT_VERTEX]->nDomains), 
+      NULL,
+      (void**)&self->data, 
+      self->variable_Register,
+      variableName[0],
+      variableName[1],
+      variableName[2],
+      variableName[3],
+      variableName[4],
+      variableName[5],
+      variableName[6],
+      variableName[7],
+      variableName[8] );
+   Memory_Free( tmpName );
+
+   /* Create Dof Layout */
+   tmpName = Stg_Object_AppendSuffix( self, (Name)"DofLayout"  );
+   self->dofLayout = DofLayout_New( tmpName, self->context, self->variable_Register, 0, self->feMesh );
+   self->dofLayout->_numItemsInLayout = FeMesh_GetNodeDomainSize( self->feMesh );
+   for( variable_I = 0; variable_I < self->fieldComponentCount ; variable_I++ ) {
+      self->dataVariableList[ variable_I ] = Variable_Register_GetByName( self->variable_Register, 
+									  variableName[ variable_I ] );
+      for( node_I = 0; node_I < FeMesh_GetNodeDomainSize( self->feMesh ); node_I++ )
+         DofLayout_AddDof_ByVarName( self->dofLayout, variableName[variable_I], node_I );
+		/* Free Name */
+		Memory_Free( variableName[ variable_I ] );
+   }
+   Memory_Free( tmpName );
+   self->eqNum->dofLayout = self->dofLayout;
+
+   /* Build and Update all Variables that this component has created */
+   Stg_Component_Build( self->dataVariable, data, False);
+   Variable_Update( self->dataVariable );
+   for( variable_I = 0; variable_I < self->fieldComponentCount ; variable_I++ ) {
+      Stg_Component_Build( self->dataVariableList[ variable_I ], data, False);
+      Variable_Update( self->dataVariableList[ variable_I ] );
+   }
+
+   _ParticleFeVariable_Build( self, data );
+
+   /* Update again, just in case things were changed/reallocated when ICs loaded */
+   Variable_Update( self->dataVariable );
+   for( variable_I = 0; variable_I < self->fieldComponentCount ; variable_I++ )
+      Variable_Update( self->dataVariableList[ variable_I ] );
+}
+
+void _SmoothVelGradField_Initialise( void* _self, void* data ) {
+   SmoothVelGradField* self = (SmoothVelGradField*) _self;
+   Variable_Index variable_I;
+
+   Stg_Component_Initialise( self->velField, data, False );
+
+   /* Initialise and Update all Variables that this component has created */
+   Stg_Component_Initialise( self->dataVariable, data, False); Variable_Update( self->dataVariable );
+   for( variable_I = 0; variable_I < self->fieldComponentCount ; variable_I++ ) {
+      Stg_Component_Initialise( self->dataVariableList[ variable_I ], data, False);
+      Variable_Update( self->dataVariableList[ variable_I ] );
+   }
+	
+   _ParticleFeVariable_Initialise( self, data );
+
+   /* Do a post-update just in case */
+   Variable_Update( self->dataVariable );
+   for( variable_I = 0; variable_I < self->fieldComponentCount ; variable_I++ )
+      Variable_Update( self->dataVariableList[ variable_I ] );
+}
+
+void _SmoothVelGradField_Execute( void* _self, void* data ) {
+   SmoothVelGradField* self = (SmoothVelGradField*) _self;
+
+   _ParticleFeVariable_Execute( self, data );
+}
+
+void _SmoothVelGradField_Destroy( void* _self, void* data ) {
+   SmoothVelGradField* self = (SmoothVelGradField*) _self;
+
+   Stg_Component_Destroy( self->velField, data, False );
+
+   _ParticleFeVariable_Destroy( self, data );
+}
+
+void _SmoothVelGradField_ValueAtParticle(
+	void*							_self,
+	IntegrationPointsSwarm*	swarm,
+	Element_LocalIndex		lElement_I,
+	void*							_particle,
+	double*						velGrad )
+{
+   SmoothVelGradField* self = (SmoothVelGradField*)_self;
+
+   assert( self->useDeriv );
+   assert( self->GNx );
+
+   FeVariable_InterpolateDerivatives_WithGNx( self->velField, lElement_I, self->GNx, velGrad );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/StressBC.c
--- a/Utils/src/StressBC.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,604 +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)
-**
-**  Modified 2006-2010 by Walter Landry (California Institute of Technology)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License 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/PICellerator.h>
-#include <PICellerator/PopulationControl/PopulationControl.h>
-#include <PICellerator/Weights/Weights.h>
-#include <PICellerator/MaterialPoints/MaterialPoints.h>
-
-#include "PICellerator/Utils/types.h"
-#include "PICellerator/Utils/MaterialSwarmVariable.h"
-
-#include "types.h"
-#include "StressBC.h"
-
-#include <assert.h>
-#include <string.h>
-
-/* Textual name of this class */
-const Type StressBC_Type = "StressBC";
-
-extern Name WallEnumToStr[Wall_Size];
-
-StressBC* StressBC_New( 
-		Name                                      name,
-                FiniteElementContext*	context,
-		ForceVector*                              forceVector,
-		Swarm*                                    integrationSwarm,
-                ConditionFunction_Register*               conFunc_Register)
-{
-	StressBC* self = (StressBC*) _StressBC_DefaultNew( name );
-
-	StressBC_InitAll( 
-			self,
-                        context,
-			forceVector,
-			integrationSwarm,
-                        conFunc_Register);
-
-	return self;
-}
-
-/* Creation implementation / Virtual constructor */
-StressBC* _StressBC_New( STRESSBC_DEFARGS)
-{
-	StressBC* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(StressBC) );
-	self = (StressBC*) _ForceTerm_New( FORCETERM_PASSARGS);
-	
-        self->conFunc_Register=condFunc_Register;
-	
-	return self;
-}
-
-void _StressBC_Init( 
-		StressBC*                                  self, 
-                ConditionFunction_Register*		   conFunc_Register)
-{
-  self->isConstructed    = True;
-  self->numEntries        = 0;
-  self->conFunc_Register=conFunc_Register;
-}
-
-void StressBC_InitAll( 
-		void*                                               forceTerm,
-                FiniteElementContext*	context,
-		ForceVector*                                        forceVector,
-		Swarm*                                              integrationSwarm,
-                ConditionFunction_Register*			    conFunc_Register)
-{
-	StressBC* self = (StressBC*) forceTerm;
-
-	_ForceTerm_Init( self, context, forceVector, integrationSwarm, NULL );
-	_StressBC_Init( self, conFunc_Register );
-}
-
-void _StressBC_Delete( void* forceTerm ) {
-	StressBC* self = (StressBC*)forceTerm;
-
-	_ForceTerm_Delete( self );
-}
-
-void _StressBC_Print( void* forceTerm, Stream* stream ) {
-	StressBC* self = (StressBC*)forceTerm;
-	
-	_ForceTerm_Print( self, stream );
-}
-
-void* _StressBC_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(StressBC);
-	Type                                                      type = StressBC_Type;
-	Stg_Class_DeleteFunction*                              _delete = _StressBC_Delete;
-	Stg_Class_PrintFunction*                                _print = _StressBC_Print;
-	Stg_Class_CopyFunction*                                  _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _StressBC_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _StressBC_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _StressBC_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _StressBC_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _StressBC_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _StressBC_Destroy;
-	ForceTerm_AssembleElementFunction*            _assembleElement = _StressBC_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*)_StressBC_New( STRESSBC_PASSARGS);
-}
-
-void _StressBC_AssignFromXML( void* forceTerm, Stg_ComponentFactory* cf, void* data ) {
-	StressBC*          self             = (StressBC*)forceTerm;
-
-	/* Construct Parent */
-	_ForceTerm_AssignFromXML( self, cf, data );
-
-	_StressBC_Init( self, condFunc_Register );
-        {
-          char*	wallStr;
-		
-          /* Obtain which wall */
-          wallStr = Stg_ComponentFactory_GetString( cf, self->name,
-                                                    "wall", "");
-          if (!strcasecmp(wallStr, "back"))
-            self->_wall = Wall_Back;
-          else if (!strcasecmp(wallStr, "left"))
-            self->_wall = Wall_Left;
-          else if (!strcasecmp(wallStr, "bottom"))
-            self->_wall = Wall_Bottom;
-          else if (!strcasecmp(wallStr, "right"))
-            self->_wall = Wall_Right;
-          else if (!strcasecmp(wallStr, "top"))
-            self->_wall = Wall_Top;
-          else if (!strcasecmp(wallStr, "front"))
-            self->_wall = Wall_Front;
-          else {
-            assert( 0 );
-            self->_wall = Wall_Size; /* invalid entry */
-          }
-        }
-        _StressBC_GetValues(cf,self,"x",data);
-        _StressBC_GetValues(cf,self,"y",data);
-        _StressBC_GetValues(cf,self,"z",data);
-
-        self->bottom_density=
-          Stg_ComponentFactory_GetDouble(cf,self->name,"bottomDensity",0.0);
-}
-
-/* Gets the actual values used by the StressBC (e.g. a float or a function). */
-void _StressBC_GetValues(Stg_ComponentFactory* cf, void *stressBC,
-                         char *direction, void *data)
-{
-          StressBC*          self             = (StressBC*)stressBC;
-          char temp_str[20];
-          char *type;
-
-          switch(*direction)
-            {
-            case 'x':
-              self->_entryTbl[self->numEntries].axis=I_AXIS;
-              break;
-            case 'y':
-              self->_entryTbl[self->numEntries].axis=J_AXIS;
-              break;
-            case 'z':
-              self->_entryTbl[self->numEntries].axis=K_AXIS;
-              break;
-            }
-
-          strcat(strcpy(temp_str,direction),"_type");
-          type=Stg_ComponentFactory_GetString( cf, self->name, temp_str, "");
-          strcat(strcpy(temp_str,direction),"_value");
-
-          if(!strcasecmp(type,"double") || !strcasecmp(type,"float"))
-            {
-              self->_entryTbl[self->numEntries].type = StressBC_Double;
-              self->_entryTbl[self->numEntries].DoubleValue =
-                Stg_ComponentFactory_GetDouble( cf, self->name, temp_str, 0.0);
-              (self->numEntries)++;
-            }
-          else if(!strcasecmp(type,"func"))
-            {
-              char *funcName =
-                Stg_ComponentFactory_GetString( cf, self->name, temp_str, "");
-              Index	cfIndex;
-
-              cfIndex = ConditionFunction_Register_GetIndex
-                ( self->conFunc_Register, funcName);
-              self->_entryTbl[self->numEntries].type =
-                StressBC_ConditionFunction;
-              if ( cfIndex == (unsigned)-1 ) {	
-                Stream*	errorStr = Journal_Register( Error_Type, self->type );
-                
-                Journal_Printf( errorStr, "Error- in %s: While parsing "
-                                "definition of StressBC (applies to wall \"%s\"), the cond. func. applied to "
-                                "direction \"%s\" - \"%s\" - wasn't found in the c.f. register.\n",
-                                __func__, WallEnumToStr[self->_wall],
-                                direction, funcName );
-                Journal_Printf( errorStr, "(Available functions in the C.F. register are: ");	
-                ConditionFunction_Register_PrintNameOfEachFunc
-                  ( self->conFunc_Register, errorStr );
-                Journal_Printf( errorStr, ")\n");	
-                assert(0);
-              }	
-              self->_entryTbl[self->numEntries].CFIndex = cfIndex;
-              (self->numEntries)++;
-            }
-          else if(!strcasecmp(type,"HydrostaticTerm"))
-            {
-              self->_entryTbl[self->numEntries].type = StressBC_HydrostaticTerm;
-              self->_entryTbl[self->numEntries].hydrostaticTerm =
-                Stg_ComponentFactory_ConstructByKey( cf, self->name, temp_str,
-                                                     HydrostaticTerm, True,
-                                                     data ) ;
-              (self->numEntries)++;
-            }
-          else if(strlen(type)!=0)
-            {
-              Stream* errorStr = Journal_Register( Error_Type, self->type );
-              Journal_Printf( errorStr, "Error- in %s: While parsing "
-                              "definition of StressBC (applies to wall \"%s\"), the type of condition \"%s\"\nis not supported.  Supported types are \"double\" and \"function\".",
-                                __func__, WallEnumToStr[self->_wall],
-                                type );
-              assert(0);
-            }
-}
-
-void _StressBC_Build( void* forceTerm, void* data ) {
-	StressBC*               self               = (StressBC*)forceTerm;
-	Name                             name;
-
-	_ForceTerm_Build( self, data );
-}
-
-void _StressBC_Initialise( void* forceTerm, void* data ) {
-	StressBC*             self             = (StressBC*)forceTerm;
-	Index                          i;
-
-	_ForceTerm_Initialise( self, data );
-
-}
-
-void _StressBC_Execute( void* forceTerm, void* data ) {
-	_ForceTerm_Execute( forceTerm, data );
-}
-
-void _StressBC_Destroy( void* forceTerm, void* data ) {
-	_ForceTerm_Destroy( forceTerm, data );
-}
-
-void _StressBC_AssembleElement( void* forceTerm, ForceVector* forceVector, Element_LocalIndex lElement_I, double* elForceVec ) {
-  StressBC*               self               = (StressBC*) forceTerm;
-  Dimension_Index                  dim                = forceVector->dim;
-  FeMesh*              mesh               = forceVector->feVariable->feMesh;
-  Grid*		grid;
-  Node_ElementLocalIndex           eNode_I;
-  ElementType*                     elementType;
-  Dof_Index                        nodeDofCount;
-  double                           stress, area;
-  IJK			ijk;
-  int overcount;
-  IArray *incidence;
-  int elementNodeCount;
-  int *elementNodes;
-  double *coord;
-
-  FeVariable* velocityField = NULL;
-  velocityField = (FeVariable*)FieldVariable_Register_GetByName
-    ( self->context->fieldVariable_Register, "VelocityField" );
-
-  elementType       = FeMesh_GetElementType( mesh, lElement_I );
-  nodeDofCount      = dim;
-  
-  grid=*(Grid**)ExtensionManager_Get(mesh->info, mesh, 
-                                     ExtensionManager_GetHandle(mesh->info,
-                                                                "vertexGrid"));
-  
-  incidence=IArray_New();
-  area=StressBC_compute_face_area(self->_wall,mesh,lElement_I,dim,incidence);
-  elementNodeCount=IArray_GetSize(incidence);
-  elementNodes=IArray_GetPtr(incidence);
-
-  if(dim==2)
-    {
-      overcount=2;
-    }
-  else
-    {
-      overcount=4;
-    }
-  /* Apply the stress */
-  for( eNode_I = 0 ; eNode_I < elementNodeCount; eNode_I++ ) {
-    /* Make sure that we are on the boundary */
-    int condition, entry_I;
-    ConditionFunction* cf;
-    RegularMeshUtils_Node_1DTo3D
-      (mesh,Mesh_DomainToGlobal(mesh,MT_VERTEX,elementNodes[eNode_I]),ijk);
-    
-    switch(self->_wall)
-      {
-      case Wall_Left:
-        condition=(ijk[0] == 0);
-        break;
-      case Wall_Right:
-        condition=(ijk[0] == ( grid->sizes[0] - 1 ));
-        break;
-      case Wall_Bottom:
-        condition=(ijk[1] == 0);
-        break;
-      case Wall_Top:
-        condition=(ijk[1] == ( grid->sizes[1] - 1 ));
-        break;
-      case Wall_Front:
-        condition=(ijk[2] == 0);
-        break;
-      case Wall_Back:
-        condition=(ijk[2] == ( grid->sizes[2] - 1 ));
-        break;
-      }
-    
-    if(condition)
-      {
-        for(entry_I=0; entry_I<self->numEntries; ++entry_I)
-          {
-            switch(self->_entryTbl[entry_I].type)
-              {
-              case StressBC_Double:
-                stress=self->_entryTbl[entry_I].DoubleValue;
-                break;
-              case StressBC_ConditionFunction:
-                cf=self->conFunc_Register->
-                  _cf[self->_entryTbl[entry_I].CFIndex];
-                
-                /* We use a variable number of zero "0", because
-                   we don't use the variable number and that one
-                   is always going to exist. */
-                ConditionFunction_Apply(cf,elementNodes[eNode_I],
-                                        0,self->context,&stress);
-                break;
-              case StressBC_HydrostaticTerm:
-                if(self->_wall!=Wall_Top && self->_wall!=Wall_Bottom)
-                  {
-                    Stream* errorStr=Journal_Register( Error_Type, self->type );
-                    Journal_Firewall(0,errorStr,"You can only apply a HydrostaticTerm StressBC to the top or bottom wall.\nYou applied it to the %s wall",WallVC_WallEnumToStr[self->_wall]);
-                  }
-
-                coord=Mesh_GetVertex(mesh,elementNodes[eNode_I]);
-                stress=
-                  -HydrostaticTerm_Pressure(self->_entryTbl[entry_I].hydrostaticTerm,
-                                            coord);
-                /* For the bottom, we need to add in the effects of
-                   material outside the mesh. */
-
-                if(self->_wall==Wall_Bottom)
-                  {
-                    Coord bottom;
-                    double dy;
-                    bottom[0]=coord[0];
-                    bottom[1]=0;
-                    bottom[2]=coord[2];
-                    dy=bottom[1] - coord[1];
-                    stress+=HydrostaticTerm_Pressure(self->_entryTbl[entry_I].hydrostaticTerm,bottom);
-                    stress-=self->bottom_density
-                      * self->_entryTbl[entry_I].hydrostaticTerm->gravity
-                      * dy;
-                  }
-                    
-                if(dim==2)
-                  {
-                    double dx, dy, *coord0, *coord1;
-                    /* StGermain uses the ordering
-
-                       0:x,y
-                       1:x+,y
-                       2:x+,y+
-                       3:x,y+
-
-                       So the top two vertices are 2 and 3 */
-
-                    coord0=Mesh_GetVertex(mesh,elementNodes[3]);
-                    coord1=Mesh_GetVertex(mesh,elementNodes[2]);
-
-                    dx=coord1[0]-coord0[0];
-                    dy=-(coord1[1]-coord0[1]);
-
-                    elForceVec[eNode_I*nodeDofCount + I_AXIS]+=
-                      stress*dy/overcount;
-                    elForceVec[eNode_I*nodeDofCount + J_AXIS]+=
-                      stress*dx/overcount;
-                  }
-                else
-                  {
-                    double *coord0,*coord1,*coord2,*coord3,
-                      vector0[3],vector1[3],normal[3];
-                    
-                    /* Decompose the quadrilateral into two triangles.
-                       For each triangle, take the cross product and
-                       apply the force in that direction. */
-
-                    coord0=Mesh_GetVertex(mesh,elementNodes[2]);
-                    coord1=Mesh_GetVertex(mesh,elementNodes[3]);
-                    coord2=Mesh_GetVertex(mesh,elementNodes[7]);
-                    coord3=Mesh_GetVertex(mesh,elementNodes[6]);
-                    
-                    StGermain_VectorSubtraction( vector0, coord1, coord0, dim) ;
-                    StGermain_VectorSubtraction( vector1, coord2, coord1, dim) ;
-                    StGermain_VectorCrossProduct( normal, vector0, vector1 );
-
-                    elForceVec[eNode_I*nodeDofCount + I_AXIS]+=
-                      stress*normal[0]/(2*overcount);
-                    elForceVec[eNode_I*nodeDofCount + J_AXIS]+=
-                      stress*normal[1]/(2*overcount);
-                    elForceVec[eNode_I*nodeDofCount + K_AXIS]+=
-                      stress*normal[2]/(2*overcount);
-
-                    StGermain_VectorSubtraction( vector0, coord2, coord1, dim) ;
-                    StGermain_VectorSubtraction( vector1, coord3, coord2, dim) ;
-                    StGermain_VectorCrossProduct( normal, vector0, vector1 );
-
-                    elForceVec[eNode_I*nodeDofCount + I_AXIS]+=
-                      stress*normal[0]/(2*overcount);;
-                    elForceVec[eNode_I*nodeDofCount + J_AXIS]+=
-                      stress*normal[1]/(2*overcount);;
-                    elForceVec[eNode_I*nodeDofCount + K_AXIS]+=
-                      stress*normal[2]/(2*overcount);;
-                  }
-                break;
-              }
-            /* We have to divide by an overcount_factor, because
-               otherwise different elements will count the same node
-               more than once.  In 2D, nodes are counted twice, in 3D,
-               nodes are counted four times. */
-            if(self->_entryTbl[entry_I].type!=StressBC_HydrostaticTerm)
-              elForceVec[eNode_I*nodeDofCount + self->_entryTbl[entry_I].axis]+=
-                stress*area/overcount;
-          }
-      }
-  }
-  NewClass_Delete(incidence);
-}
-
-
-double StressBC_compute_face_area(Wall wall, FeMesh *mesh, Index lElement_I, 
-                                  Dimension_Index dim,
-                                  IArray *incidence)
-{
-  /* Compute the area of the face. */
-  if(dim==2)
-    {
-      double *coord1, *coord2;
-      int lower,upper,direction;
-      int *elementNodes;
-      switch(wall)
-        {
-        case Wall_Left:
-          lower=0;
-          upper=3;
-          direction=1;
-          break;
-        case Wall_Right:
-          lower=1;
-          upper=2;
-          direction=1;
-          break;
-        case Wall_Bottom:
-          lower=0;
-          upper=1;
-          direction=0;
-          break;
-        case Wall_Top:
-          lower=3;
-          upper=2;
-          direction=0;
-          break;
-        }
-
-      Mesh_GetIncidence(mesh, Mesh_GetDimSize(mesh), lElement_I,
-                        MT_VERTEX,incidence);
-      elementNodes=IArray_GetPtr(incidence);
-                              
-      coord1=Mesh_GetVertex(mesh,elementNodes[lower]);
-      coord2=Mesh_GetVertex(mesh,elementNodes[upper]);
-      return coord2[direction]-coord1[direction];
-    }
-  else
-    {
-      double *coord1, *coord2, *coord3, *coord4;
-      int first, second, third, fourth;
-      int *elementNodes;
-                              
-      /* StGermain uses the ordering
-         0: x,y,z
-         1: x+,y,z
-         2: x,y+,z
-         3: x+,y+,z
-         4: x,y,z+
-         5: x+,y,z+
-         6: x,y+,z+
-         7: x+,y+,z+
-      */
-
-      /* Get the indices for which wall we want to get the area of. */
-      switch(wall)
-        {
-        case Wall_Left:
-          first=0;
-          second=2;
-          third=6;
-          fourth=4;
-          break;
-        case Wall_Right:
-          first=1;
-          second=3;
-          third=7;
-          fourth=5;
-          break;
-        case Wall_Bottom:
-          first=0;
-          second=1;
-          third=5;
-          fourth=4;
-          break;
-        case Wall_Top:
-          first=2;
-          second=3;
-          third=7;
-          fourth=6;
-          break;
-        case Wall_Front:
-          first=0;
-          second=1;
-          third=4;
-          fourth=3;
-          break;
-        case Wall_Back:
-          first=4;
-          second=5;
-          third=7;
-          fourth=6;
-          break;
-        }
-
-      Mesh_GetIncidence(mesh, Mesh_GetDimSize(mesh), lElement_I,
-                        MT_VERTEX,incidence);
-      elementNodes=IArray_GetPtr(incidence);
-
-      coord1=Mesh_GetVertex(mesh,elementNodes[first]);
-      coord2=Mesh_GetVertex(mesh,elementNodes[second]);
-      coord3=Mesh_GetVertex(mesh,elementNodes[third]);
-      coord4=Mesh_GetVertex(mesh,elementNodes[fourth]);
-
-      return StGermain_ConvexQuadrilateralArea(coord1,coord2,coord3,coord4,
-                                               dim);
-    }
-}
-
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/StressBC.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/StressBC.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,604 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** 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)
+**
+**  Modified 2006-2010 by Walter Landry (California Institute of Technology)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License 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/PICellerator.h>
+#include <PICellerator/PopulationControl/PopulationControl.h>
+#include <PICellerator/Weights/Weights.h>
+#include <PICellerator/MaterialPoints/MaterialPoints.h>
+
+#include "PICellerator/Utils/types.h"
+#include "PICellerator/Utils/MaterialSwarmVariable.h"
+
+#include "types.h"
+#include "StressBC.h"
+
+#include <assert.h>
+#include <string.h>
+
+/* Textual name of this class */
+const Type StressBC_Type = "StressBC";
+
+extern Name WallEnumToStr[Wall_Size];
+
+StressBC* StressBC_New( 
+		Name                                      name,
+                FiniteElementContext*	context,
+		ForceVector*                              forceVector,
+		Swarm*                                    integrationSwarm,
+                ConditionFunction_Register*               conFunc_Register)
+{
+	StressBC* self = (StressBC*) _StressBC_DefaultNew( name );
+
+	StressBC_InitAll( 
+			self,
+                        context,
+			forceVector,
+			integrationSwarm,
+                        conFunc_Register);
+
+	return self;
+}
+
+/* Creation implementation / Virtual constructor */
+StressBC* _StressBC_New( STRESSBC_DEFARGS)
+{
+	StressBC* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(StressBC) );
+	self = (StressBC*) _ForceTerm_New( FORCETERM_PASSARGS);
+	
+        self->conFunc_Register=condFunc_Register;
+	
+	return self;
+}
+
+void _StressBC_Init( 
+		StressBC*                                  self, 
+                ConditionFunction_Register*		   conFunc_Register)
+{
+  self->isConstructed    = True;
+  self->numEntries        = 0;
+  self->conFunc_Register=conFunc_Register;
+}
+
+void StressBC_InitAll( 
+		void*                                               forceTerm,
+                FiniteElementContext*	context,
+		ForceVector*                                        forceVector,
+		Swarm*                                              integrationSwarm,
+                ConditionFunction_Register*			    conFunc_Register)
+{
+	StressBC* self = (StressBC*) forceTerm;
+
+	_ForceTerm_Init( self, context, forceVector, integrationSwarm, NULL );
+	_StressBC_Init( self, conFunc_Register );
+}
+
+void _StressBC_Delete( void* forceTerm ) {
+	StressBC* self = (StressBC*)forceTerm;
+
+	_ForceTerm_Delete( self );
+}
+
+void _StressBC_Print( void* forceTerm, Stream* stream ) {
+	StressBC* self = (StressBC*)forceTerm;
+	
+	_ForceTerm_Print( self, stream );
+}
+
+void* _StressBC_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(StressBC);
+	Type                                                      type = StressBC_Type;
+	Stg_Class_DeleteFunction*                              _delete = _StressBC_Delete;
+	Stg_Class_PrintFunction*                                _print = _StressBC_Print;
+	Stg_Class_CopyFunction*                                  _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _StressBC_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _StressBC_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _StressBC_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _StressBC_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _StressBC_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _StressBC_Destroy;
+	ForceTerm_AssembleElementFunction*            _assembleElement = _StressBC_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*)_StressBC_New( STRESSBC_PASSARGS);
+}
+
+void _StressBC_AssignFromXML( void* forceTerm, Stg_ComponentFactory* cf, void* data ) {
+	StressBC*          self             = (StressBC*)forceTerm;
+
+	/* Construct Parent */
+	_ForceTerm_AssignFromXML( self, cf, data );
+
+	_StressBC_Init( self, condFunc_Register );
+        {
+          char*	wallStr;
+		
+          /* Obtain which wall */
+          wallStr = Stg_ComponentFactory_GetString( cf, self->name,
+                                                    "wall", "");
+          if (!strcasecmp(wallStr, "back"))
+            self->_wall = Wall_Back;
+          else if (!strcasecmp(wallStr, "left"))
+            self->_wall = Wall_Left;
+          else if (!strcasecmp(wallStr, "bottom"))
+            self->_wall = Wall_Bottom;
+          else if (!strcasecmp(wallStr, "right"))
+            self->_wall = Wall_Right;
+          else if (!strcasecmp(wallStr, "top"))
+            self->_wall = Wall_Top;
+          else if (!strcasecmp(wallStr, "front"))
+            self->_wall = Wall_Front;
+          else {
+            assert( 0 );
+            self->_wall = Wall_Size; /* invalid entry */
+          }
+        }
+        _StressBC_GetValues(cf,self,"x",data);
+        _StressBC_GetValues(cf,self,"y",data);
+        _StressBC_GetValues(cf,self,"z",data);
+
+        self->bottom_density=
+          Stg_ComponentFactory_GetDouble(cf,self->name,"bottomDensity",0.0);
+}
+
+/* Gets the actual values used by the StressBC (e.g. a float or a function). */
+void _StressBC_GetValues(Stg_ComponentFactory* cf, void *stressBC,
+                         char *direction, void *data)
+{
+          StressBC*          self             = (StressBC*)stressBC;
+          char temp_str[20];
+          char *type;
+
+          switch(*direction)
+            {
+            case 'x':
+              self->_entryTbl[self->numEntries].axis=I_AXIS;
+              break;
+            case 'y':
+              self->_entryTbl[self->numEntries].axis=J_AXIS;
+              break;
+            case 'z':
+              self->_entryTbl[self->numEntries].axis=K_AXIS;
+              break;
+            }
+
+          strcat(strcpy(temp_str,direction),"_type");
+          type=Stg_ComponentFactory_GetString( cf, self->name, temp_str, "");
+          strcat(strcpy(temp_str,direction),"_value");
+
+          if(!strcasecmp(type,"double") || !strcasecmp(type,"float"))
+            {
+              self->_entryTbl[self->numEntries].type = StressBC_Double;
+              self->_entryTbl[self->numEntries].DoubleValue =
+                Stg_ComponentFactory_GetDouble( cf, self->name, temp_str, 0.0);
+              (self->numEntries)++;
+            }
+          else if(!strcasecmp(type,"func"))
+            {
+              char *funcName =
+                Stg_ComponentFactory_GetString( cf, self->name, temp_str, "");
+              Index	cfIndex;
+
+              cfIndex = ConditionFunction_Register_GetIndex
+                ( self->conFunc_Register, funcName);
+              self->_entryTbl[self->numEntries].type =
+                StressBC_ConditionFunction;
+              if ( cfIndex == (unsigned)-1 ) {	
+                Stream*	errorStr = Journal_Register( Error_Type, self->type );
+                
+                Journal_Printf( errorStr, "Error- in %s: While parsing "
+                                "definition of StressBC (applies to wall \"%s\"), the cond. func. applied to "
+                                "direction \"%s\" - \"%s\" - wasn't found in the c.f. register.\n",
+                                __func__, WallEnumToStr[self->_wall],
+                                direction, funcName );
+                Journal_Printf( errorStr, "(Available functions in the C.F. register are: ");	
+                ConditionFunction_Register_PrintNameOfEachFunc
+                  ( self->conFunc_Register, errorStr );
+                Journal_Printf( errorStr, ")\n");	
+                assert(0);
+              }	
+              self->_entryTbl[self->numEntries].CFIndex = cfIndex;
+              (self->numEntries)++;
+            }
+          else if(!strcasecmp(type,"HydrostaticTerm"))
+            {
+              self->_entryTbl[self->numEntries].type = StressBC_HydrostaticTerm;
+              self->_entryTbl[self->numEntries].hydrostaticTerm =
+                Stg_ComponentFactory_ConstructByKey( cf, self->name, temp_str,
+                                                     HydrostaticTerm, True,
+                                                     data ) ;
+              (self->numEntries)++;
+            }
+          else if(strlen(type)!=0)
+            {
+              Stream* errorStr = Journal_Register( Error_Type, self->type );
+              Journal_Printf( errorStr, "Error- in %s: While parsing "
+                              "definition of StressBC (applies to wall \"%s\"), the type of condition \"%s\"\nis not supported.  Supported types are \"double\" and \"function\".",
+                                __func__, WallEnumToStr[self->_wall],
+                                type );
+              assert(0);
+            }
+}
+
+void _StressBC_Build( void* forceTerm, void* data ) {
+	StressBC*               self               = (StressBC*)forceTerm;
+	Name                             name;
+
+	_ForceTerm_Build( self, data );
+}
+
+void _StressBC_Initialise( void* forceTerm, void* data ) {
+	StressBC*             self             = (StressBC*)forceTerm;
+	Index                          i;
+
+	_ForceTerm_Initialise( self, data );
+
+}
+
+void _StressBC_Execute( void* forceTerm, void* data ) {
+	_ForceTerm_Execute( forceTerm, data );
+}
+
+void _StressBC_Destroy( void* forceTerm, void* data ) {
+	_ForceTerm_Destroy( forceTerm, data );
+}
+
+void _StressBC_AssembleElement( void* forceTerm, ForceVector* forceVector, Element_LocalIndex lElement_I, double* elForceVec ) {
+  StressBC*               self               = (StressBC*) forceTerm;
+  Dimension_Index                  dim                = forceVector->dim;
+  FeMesh*              mesh               = forceVector->feVariable->feMesh;
+  Grid*		grid;
+  Node_ElementLocalIndex           eNode_I;
+  ElementType*                     elementType;
+  Dof_Index                        nodeDofCount;
+  double                           stress, area;
+  IJK			ijk;
+  int overcount;
+  IArray *incidence;
+  int elementNodeCount;
+  int *elementNodes;
+  double *coord;
+
+  FeVariable* velocityField = NULL;
+  velocityField = (FeVariable*)FieldVariable_Register_GetByName
+    ( self->context->fieldVariable_Register, "VelocityField" );
+
+  elementType       = FeMesh_GetElementType( mesh, lElement_I );
+  nodeDofCount      = dim;
+  
+  grid=*(Grid**)ExtensionManager_Get(mesh->info, mesh, 
+                                     ExtensionManager_GetHandle(mesh->info,
+                                                                "vertexGrid"));
+  
+  incidence=IArray_New();
+  area=StressBC_compute_face_area(self->_wall,mesh,lElement_I,dim,incidence);
+  elementNodeCount=IArray_GetSize(incidence);
+  elementNodes=IArray_GetPtr(incidence);
+
+  if(dim==2)
+    {
+      overcount=2;
+    }
+  else
+    {
+      overcount=4;
+    }
+  /* Apply the stress */
+  for( eNode_I = 0 ; eNode_I < elementNodeCount; eNode_I++ ) {
+    /* Make sure that we are on the boundary */
+    int condition, entry_I;
+    ConditionFunction* cf;
+    RegularMeshUtils_Node_1DTo3D
+      (mesh,Mesh_DomainToGlobal(mesh,MT_VERTEX,elementNodes[eNode_I]),ijk);
+    
+    switch(self->_wall)
+      {
+      case Wall_Left:
+        condition=(ijk[0] == 0);
+        break;
+      case Wall_Right:
+        condition=(ijk[0] == ( grid->sizes[0] - 1 ));
+        break;
+      case Wall_Bottom:
+        condition=(ijk[1] == 0);
+        break;
+      case Wall_Top:
+        condition=(ijk[1] == ( grid->sizes[1] - 1 ));
+        break;
+      case Wall_Front:
+        condition=(ijk[2] == 0);
+        break;
+      case Wall_Back:
+        condition=(ijk[2] == ( grid->sizes[2] - 1 ));
+        break;
+      }
+    
+    if(condition)
+      {
+        for(entry_I=0; entry_I<self->numEntries; ++entry_I)
+          {
+            switch(self->_entryTbl[entry_I].type)
+              {
+              case StressBC_Double:
+                stress=self->_entryTbl[entry_I].DoubleValue;
+                break;
+              case StressBC_ConditionFunction:
+                cf=self->conFunc_Register->
+                  _cf[self->_entryTbl[entry_I].CFIndex];
+                
+                /* We use a variable number of zero "0", because
+                   we don't use the variable number and that one
+                   is always going to exist. */
+                ConditionFunction_Apply(cf,elementNodes[eNode_I],
+                                        0,self->context,&stress);
+                break;
+              case StressBC_HydrostaticTerm:
+                if(self->_wall!=Wall_Top && self->_wall!=Wall_Bottom)
+                  {
+                    Stream* errorStr=Journal_Register( Error_Type, self->type );
+                    Journal_Firewall(0,errorStr,"You can only apply a HydrostaticTerm StressBC to the top or bottom wall.\nYou applied it to the %s wall",WallVC_WallEnumToStr[self->_wall]);
+                  }
+
+                coord=Mesh_GetVertex(mesh,elementNodes[eNode_I]);
+                stress=
+                  -HydrostaticTerm_Pressure(self->_entryTbl[entry_I].hydrostaticTerm,
+                                            coord);
+                /* For the bottom, we need to add in the effects of
+                   material outside the mesh. */
+
+                if(self->_wall==Wall_Bottom)
+                  {
+                    Coord bottom;
+                    double dy;
+                    bottom[0]=coord[0];
+                    bottom[1]=0;
+                    bottom[2]=coord[2];
+                    dy=bottom[1] - coord[1];
+                    stress+=HydrostaticTerm_Pressure(self->_entryTbl[entry_I].hydrostaticTerm,bottom);
+                    stress-=self->bottom_density
+                      * self->_entryTbl[entry_I].hydrostaticTerm->gravity
+                      * dy;
+                  }
+                    
+                if(dim==2)
+                  {
+                    double dx, dy, *coord0, *coord1;
+                    /* StGermain uses the ordering
+
+                       0:x,y
+                       1:x+,y
+                       2:x+,y+
+                       3:x,y+
+
+                       So the top two vertices are 2 and 3 */
+
+                    coord0=Mesh_GetVertex(mesh,elementNodes[3]);
+                    coord1=Mesh_GetVertex(mesh,elementNodes[2]);
+
+                    dx=coord1[0]-coord0[0];
+                    dy=-(coord1[1]-coord0[1]);
+
+                    elForceVec[eNode_I*nodeDofCount + I_AXIS]+=
+                      stress*dy/overcount;
+                    elForceVec[eNode_I*nodeDofCount + J_AXIS]+=
+                      stress*dx/overcount;
+                  }
+                else
+                  {
+                    double *coord0,*coord1,*coord2,*coord3,
+                      vector0[3],vector1[3],normal[3];
+                    
+                    /* Decompose the quadrilateral into two triangles.
+                       For each triangle, take the cross product and
+                       apply the force in that direction. */
+
+                    coord0=Mesh_GetVertex(mesh,elementNodes[2]);
+                    coord1=Mesh_GetVertex(mesh,elementNodes[3]);
+                    coord2=Mesh_GetVertex(mesh,elementNodes[7]);
+                    coord3=Mesh_GetVertex(mesh,elementNodes[6]);
+                    
+                    StGermain_VectorSubtraction( vector0, coord1, coord0, dim) ;
+                    StGermain_VectorSubtraction( vector1, coord2, coord1, dim) ;
+                    StGermain_VectorCrossProduct( normal, vector0, vector1 );
+
+                    elForceVec[eNode_I*nodeDofCount + I_AXIS]+=
+                      stress*normal[0]/(2*overcount);
+                    elForceVec[eNode_I*nodeDofCount + J_AXIS]+=
+                      stress*normal[1]/(2*overcount);
+                    elForceVec[eNode_I*nodeDofCount + K_AXIS]+=
+                      stress*normal[2]/(2*overcount);
+
+                    StGermain_VectorSubtraction( vector0, coord2, coord1, dim) ;
+                    StGermain_VectorSubtraction( vector1, coord3, coord2, dim) ;
+                    StGermain_VectorCrossProduct( normal, vector0, vector1 );
+
+                    elForceVec[eNode_I*nodeDofCount + I_AXIS]+=
+                      stress*normal[0]/(2*overcount);;
+                    elForceVec[eNode_I*nodeDofCount + J_AXIS]+=
+                      stress*normal[1]/(2*overcount);;
+                    elForceVec[eNode_I*nodeDofCount + K_AXIS]+=
+                      stress*normal[2]/(2*overcount);;
+                  }
+                break;
+              }
+            /* We have to divide by an overcount_factor, because
+               otherwise different elements will count the same node
+               more than once.  In 2D, nodes are counted twice, in 3D,
+               nodes are counted four times. */
+            if(self->_entryTbl[entry_I].type!=StressBC_HydrostaticTerm)
+              elForceVec[eNode_I*nodeDofCount + self->_entryTbl[entry_I].axis]+=
+                stress*area/overcount;
+          }
+      }
+  }
+  NewClass_Delete(incidence);
+}
+
+
+double StressBC_compute_face_area(Wall wall, FeMesh *mesh, Index lElement_I, 
+                                  Dimension_Index dim,
+                                  IArray *incidence)
+{
+  /* Compute the area of the face. */
+  if(dim==2)
+    {
+      double *coord1, *coord2;
+      int lower,upper,direction;
+      int *elementNodes;
+      switch(wall)
+        {
+        case Wall_Left:
+          lower=0;
+          upper=3;
+          direction=1;
+          break;
+        case Wall_Right:
+          lower=1;
+          upper=2;
+          direction=1;
+          break;
+        case Wall_Bottom:
+          lower=0;
+          upper=1;
+          direction=0;
+          break;
+        case Wall_Top:
+          lower=3;
+          upper=2;
+          direction=0;
+          break;
+        }
+
+      Mesh_GetIncidence(mesh, Mesh_GetDimSize(mesh), lElement_I,
+                        MT_VERTEX,incidence);
+      elementNodes=IArray_GetPtr(incidence);
+                              
+      coord1=Mesh_GetVertex(mesh,elementNodes[lower]);
+      coord2=Mesh_GetVertex(mesh,elementNodes[upper]);
+      return coord2[direction]-coord1[direction];
+    }
+  else
+    {
+      double *coord1, *coord2, *coord3, *coord4;
+      int first, second, third, fourth;
+      int *elementNodes;
+                              
+      /* StGermain uses the ordering
+         0: x,y,z
+         1: x+,y,z
+         2: x,y+,z
+         3: x+,y+,z
+         4: x,y,z+
+         5: x+,y,z+
+         6: x,y+,z+
+         7: x+,y+,z+
+      */
+
+      /* Get the indices for which wall we want to get the area of. */
+      switch(wall)
+        {
+        case Wall_Left:
+          first=0;
+          second=2;
+          third=6;
+          fourth=4;
+          break;
+        case Wall_Right:
+          first=1;
+          second=3;
+          third=7;
+          fourth=5;
+          break;
+        case Wall_Bottom:
+          first=0;
+          second=1;
+          third=5;
+          fourth=4;
+          break;
+        case Wall_Top:
+          first=2;
+          second=3;
+          third=7;
+          fourth=6;
+          break;
+        case Wall_Front:
+          first=0;
+          second=1;
+          third=4;
+          fourth=3;
+          break;
+        case Wall_Back:
+          first=4;
+          second=5;
+          third=7;
+          fourth=6;
+          break;
+        }
+
+      Mesh_GetIncidence(mesh, Mesh_GetDimSize(mesh), lElement_I,
+                        MT_VERTEX,incidence);
+      elementNodes=IArray_GetPtr(incidence);
+
+      coord1=Mesh_GetVertex(mesh,elementNodes[first]);
+      coord2=Mesh_GetVertex(mesh,elementNodes[second]);
+      coord3=Mesh_GetVertex(mesh,elementNodes[third]);
+      coord4=Mesh_GetVertex(mesh,elementNodes[fourth]);
+
+      return StGermain_ConvexQuadrilateralArea(coord1,coord2,coord3,coord4,
+                                               dim);
+    }
+}
+
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/StressField.c
--- a/Utils/src/StressField.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,316 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Monash Cluster Computing, Australia
-** (C) 2003-2004 All Rights Reserved
-**
-** Primary Authors:
-** Robert Turnbull, MCC
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include <Underworld/Rheology/Rheology.h>
-
-#include "types.h"
-#include "StressField.h"
-#include <assert.h>
-#include <string.h>
-
-const Type StressField_Type = "StressField";
-
-StressField* _StressField_New(  STRESSFIELD_DEFARGS  ) {
-	StressField* self;
-	
-	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree.
-		At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-	assert( _sizeOfSelf >= sizeof(StressField) );
-	self = (StressField*) _ParticleFeVariable_New(  PARTICLEFEVARIABLE_PASSARGS  );
-	
-	return self;
-}
-
-void _StressField_Init( 
-	StressField*				self,
-	FeVariable*					strainRateField,
-	ConstitutiveMatrix*		constitutiveMatrix,
-	Variable*					stressVariable,
-	Variable_Register*		variable_Register,
-	SystemLinearEquations*	sle)
-{
-	Dimension_Index dim = constitutiveMatrix->dim;
-
-	/* Assign Pointers */
-	self->strainRateField = strainRateField;
-	self->constitutiveMatrix = constitutiveMatrix;
-	self->variable_Register = variable_Register;
-
-	self->fieldComponentCount = StGermain_nSymmetricTensorVectorComponents( dim );
-
-	if ( stressVariable ) {
-		self->stressVariable = stressVariable;
-		self->_valueAtParticle = _StressField_ValueAtParticle_FromVariable;
-	}
-		
-	/* Set pointers to swarm to be the same as the one on the constitutive matrix */
-	self->assemblyTerm->integrationSwarm = self->constitutiveMatrix->integrationSwarm;
-	self->massMatrixForceTerm->integrationSwarm = self->constitutiveMatrix->integrationSwarm;
-
-	/*
-	** If we're using this field for non-linear feedback, we'll need to update it in between
-	** non-linear iterations. */
-	if( sle )
-		SystemLinearEquations_AddPostNonLinearEP( sle, StressField_Type, StressField_NonLinearUpdate );
-}
-
-/* --- Virtual Function Implementations --- */
-void _StressField_Delete( void* stressField ) {
-	StressField* self = (StressField*) stressField;
-
-	_FeVariable_Delete( self );
-}
-
-void _StressField_Print( void* stressField, Stream* stream ) {
-	StressField* self = (StressField*) stressField;
-	
-	/* General info */
-	Journal_Printf( stream, "StressField (ptr): %p\n", self );
-	
-	/* Print parent */
-	_FeVariable_Print( self, stream );
-	
-	/* StressField info */
-	Journal_PrintPointer( stream, self->strainRateField );
-	Journal_PrintPointer( stream, self->constitutiveMatrix );
-}
-
-void* _StressField_Copy( const void* feVariable, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	StressField*	self = (StressField*)feVariable;
-	StressField*	newStressField;
-	
-	newStressField = (StressField*) _FeVariable_Copy( feVariable, dest, deep, nameExt, ptrMap );
-
-	newStressField->strainRateField = self->strainRateField;
-	newStressField->constitutiveMatrix = self->constitutiveMatrix;
-	
-	return (void*)newStressField;
-}
-
-void* _StressField_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                       _sizeOfSelf = sizeof(StressField);
-	Type                                                               type = StressField_Type;
-	Stg_Class_DeleteFunction*                                       _delete = _StressField_Delete;
-	Stg_Class_PrintFunction*                                         _print = _StressField_Print;
-	Stg_Class_CopyFunction*                                           _copy = _StressField_Copy;
-	Stg_Component_DefaultConstructorFunction*           _defaultConstructor = _StressField_DefaultNew;
-	Stg_Component_ConstructFunction*                             _construct = _StressField_AssignFromXML;
-	Stg_Component_BuildFunction*                                     _build = _StressField_Build;
-	Stg_Component_InitialiseFunction*                           _initialise = _StressField_Initialise;
-	Stg_Component_ExecuteFunction*                                 _execute = _StressField_Execute;
-	Stg_Component_DestroyFunction*                                 _destroy = _StressField_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 = _StressField_ValueAtParticle_Recalculate;
-
-	/* 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 = ZERO;
-	FieldVariable_GetValueFunction*   _getMaxGlobalFieldMagnitude = ZERO;
-	FeVariable_SyncShadowValuesFunc*            _syncShadowValues = ZERO;
-
-	return (void*) _StressField_New(  STRESSFIELD_PASSARGS  );
-}
-
-void StressField_NonLinearUpdate( void* _sle, void* _ctx ) {
-   SystemLinearEquations* sle;
-   DomainContext* ctx = (DomainContext*)_ctx;
-   FieldVariable_Register* fieldVar_Register;
-   StressField* stressVar;
-
-	sle = (SystemLinearEquations*)_sle;
-   fieldVar_Register = ctx->fieldVariable_Register;
-   stressVar = (StressField*)FieldVariable_Register_GetByName( fieldVar_Register, "StressField" );
-   ParticleFeVariable_Update( stressVar );
-}
-
-void _StressField_AssignFromXML( void* stressField, Stg_ComponentFactory* cf, void* data ){
-	StressField*          self = (StressField*) stressField;
-	FeVariable*           strainRateField;
-	ConstitutiveMatrix*   constitutiveMatrix;
-	Variable_Register*    variable_Register;
-	Name                  stressVariableName;
-	Variable*             stressVariable;
-	SystemLinearEquations* sle;
-
-	/* Construct Parent */
-	_ParticleFeVariable_AssignFromXML( self, cf, data );
-
-	strainRateField =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"StrainRateField", FeVariable, True, data  );
-	constitutiveMatrix = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"ConstitutiveMatrix", ConstitutiveMatrix, True, data );
-	variable_Register = self->context->variable_Register; 
-	assert( variable_Register  );
-
-	stressVariableName = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"StressVariable", "Stress"  );
-	stressVariable = Variable_Register_GetByName( variable_Register, stressVariableName );
-
-   sle = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"SLE", SystemLinearEquations, False, data  );
-
-	_StressField_Init( self, strainRateField, constitutiveMatrix, stressVariable, variable_Register, sle );
-}
-
-void _StressField_Build( void* stressField, void* data ) {
-	StressField* self = (StressField*) stressField;
-	char*              tmpName;
-	char*              variableName[6];
-	Dimension_Index   dim = self->constitutiveMatrix->dim;
-	Variable_Index variable_I;
-	Node_DomainIndex  node_I;
-
-	Stg_Component_Build( self->feMesh, data, False );
-	Stg_Component_Build( self->strainRateField, data, False );
-	Stg_Component_Build( self->constitutiveMatrix, data, False );
-	if ( self->stressVariable ) Stg_Component_Build( self->stressVariable, data, False );
-
-	if ( dim == 2 ) {
-		variableName[0] = StG_Strdup( "tau_xx" );
-		variableName[1] = StG_Strdup( "tau_yy" );
-		variableName[2] = StG_Strdup( "tau_xy" );
-	}
-	else {
-		variableName[0] = StG_Strdup( "tau_xx" );
-		variableName[1] = StG_Strdup( "tau_yy" );
-		variableName[2] = StG_Strdup( "tau_zz" );
-		variableName[3] = StG_Strdup( "tau_xy" );
-		variableName[4] = StG_Strdup( "tau_xz" );
-		variableName[5] = StG_Strdup( "tau_yz" );
-	}
-
-	/* Create Variable to store data */
-	assert( Class_IsSuper( self->feMesh->topo, IGraph ) );
-	tmpName = Stg_Object_AppendSuffix( self, (Name)"DataVariable"  );
-	self->dataVariable = Variable_NewVector(
-		tmpName,
-		(AbstractContext*)self->context,
-		Variable_DataType_Double, 
-		self->fieldComponentCount,
-		(Index*)(&((IGraph*)self->feMesh->topo)->remotes[MT_VERTEX]->nDomains), 
-		NULL,
-		(void**)&self->data, 
-		self->variable_Register,
-		variableName[0],
-		variableName[1],
-		variableName[2],
-		variableName[3],
-		variableName[4],
-		variableName[5] );
-	Memory_Free( tmpName );
-	
-	/* Create Dof Layout */
-	tmpName = Stg_Object_AppendSuffix( self, (Name)"DofLayout"  );
-	self->dofLayout = DofLayout_New( tmpName, self->context, self->variable_Register, 0, self->feMesh );
-	self->dofLayout->_numItemsInLayout = FeMesh_GetNodeDomainSize( self->feMesh );
-	for( variable_I = 0; variable_I < self->fieldComponentCount ; variable_I++ ) {
-		self->dataVariableList[ variable_I ] = Variable_Register_GetByName( self->variable_Register, 
-                             variableName[ variable_I ] );
-		for( node_I = 0; node_I < FeMesh_GetNodeDomainSize( self->feMesh ); node_I++ )
-			DofLayout_AddDof_ByVarName( self->dofLayout, variableName[variable_I], node_I );
-		/* Free Name */
-		Memory_Free( variableName[ variable_I ] );
-	}
-	Memory_Free( tmpName );
-	self->eqNum->dofLayout = self->dofLayout;
-
-	/* Build and Update all Variables that this component has created */
-	Stg_Component_Build( self->dataVariable, data, False); Variable_Update( self->dataVariable );
-	for( variable_I = 0; variable_I < self->fieldComponentCount ; variable_I++ ) {
-		Stg_Component_Build( self->dataVariableList[ variable_I ], data, False); Variable_Update( self->dataVariableList[ variable_I ] );
-	}
-
-	_ParticleFeVariable_Build( self, data );
-	/* Update again, just in case things were changed/reallocated when ICs loaded */
-	Variable_Update( self->dataVariable );
-	for( variable_I = 0; variable_I < self->fieldComponentCount ; variable_I++ ) {
-		Variable_Update( self->dataVariableList[ variable_I ] );
-	}
-}
-
-void _StressField_Initialise( void* stressField, void* data ) {
-	StressField* self = (StressField*) stressField;
-	Variable_Index variable_I;
-
-	Stg_Component_Initialise( self->strainRateField, data, False );
-	Stg_Component_Initialise( self->constitutiveMatrix, data, False );
-	/* Initialise and Update all Variables that this component has created */
-	Stg_Component_Initialise( self->dataVariable, data, False); Variable_Update( self->dataVariable );
-	for( variable_I = 0; variable_I < self->fieldComponentCount ; variable_I++ ) {
-		Stg_Component_Initialise( self->dataVariableList[ variable_I ], data, False); Variable_Update( self->dataVariableList[ variable_I ] );
-	}
-	
-	_ParticleFeVariable_Initialise( self, data );
-
-	/* Do a post-update just in case */
-	Variable_Update( self->dataVariable );
-	for( variable_I = 0; variable_I < self->fieldComponentCount ; variable_I++ ) {
-		Variable_Update( self->dataVariableList[ variable_I ] );
-	}
-
-}
-
-void _StressField_Execute( void* stressField, void* data ) {
-	StressField* self = (StressField*) stressField;
-
-	_ParticleFeVariable_Execute( self, data );
-}
-
-void _StressField_Destroy( void* stressField, void* data ) {
-	StressField* self = (StressField*) stressField;
-
-	Stg_Component_Destroy( self->strainRateField, data, False );
-	Stg_Component_Destroy( self->constitutiveMatrix, data, False );
-	Stg_Component_Destroy( self->dataVariable, data, False);
-
-	_ParticleFeVariable_Destroy( self, data );
-}
-
-void _StressField_ValueAtParticle_Recalculate( void* stressField, IntegrationPointsSwarm* swarm, Element_LocalIndex lElement_I, void* _particle, double* stress ) {
-	StressField*      self         = (StressField*) stressField;
-	SymmetricTensor   strainRate;
-	IntegrationPoint* particle     = (IntegrationPoint*) _particle;
-	
-	/* Calculate stress from strain rate and constitutive matrix */
-	ConstitutiveMatrix_Assemble( self->constitutiveMatrix, lElement_I,
-                                     self->currentParticleIndex, particle );
-	FeVariable_InterpolateWithinElement( self->strainRateField, lElement_I, particle->xi, strainRate );
-	ConstitutiveMatrix_CalculateStress( self->constitutiveMatrix, strainRate, stress );
-
-	assert ( !isnan( stress[0] ) );
-	assert ( !isnan( stress[1] ) );
-	assert ( !isnan( stress[2] ) );
-	
-}
-
-void _StressField_ValueAtParticle_FromVariable( void* stressField, IntegrationPointsSwarm* swarm, Element_LocalIndex lElement_I, void* particle, double* stress ) {
-	StressField*      self         = (StressField*) stressField;
-	double*           stressParticleExt;
-	MaterialPointsSwarm* materialPointsSwarm;
-	void* materialPoint;
-	
-	/* Ok, we break any fancy mapper stuff here and assume the materialParticles correspond exactly to the
-	 * Integration ones: */
-	materialPoint = OneToOneMapper_GetMaterialPoint( swarm->mapper, particle, &materialPointsSwarm );	
-
-	/* Get pointer to stress using variable */
-	stressParticleExt = (double*) ((ArithPointer) materialPoint + (ArithPointer)self->stressVariable->offsets[0]);
-	memcpy( stress, stressParticleExt, sizeof(double)*self->fieldComponentCount );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/StressField.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/StressField.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,316 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Monash Cluster Computing, Australia
+** (C) 2003-2004 All Rights Reserved
+**
+** Primary Authors:
+** Robert Turnbull, MCC
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include <Underworld/Rheology/Rheology.h>
+
+#include "types.h"
+#include "StressField.h"
+#include <assert.h>
+#include <string.h>
+
+const Type StressField_Type = "StressField";
+
+StressField* _StressField_New(  STRESSFIELD_DEFARGS  ) {
+	StressField* self;
+	
+	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree.
+		At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+	assert( _sizeOfSelf >= sizeof(StressField) );
+	self = (StressField*) _ParticleFeVariable_New(  PARTICLEFEVARIABLE_PASSARGS  );
+	
+	return self;
+}
+
+void _StressField_Init( 
+	StressField*				self,
+	FeVariable*					strainRateField,
+	ConstitutiveMatrix*		constitutiveMatrix,
+	Variable*					stressVariable,
+	Variable_Register*		variable_Register,
+	SystemLinearEquations*	sle)
+{
+	Dimension_Index dim = constitutiveMatrix->dim;
+
+	/* Assign Pointers */
+	self->strainRateField = strainRateField;
+	self->constitutiveMatrix = constitutiveMatrix;
+	self->variable_Register = variable_Register;
+
+	self->fieldComponentCount = StGermain_nSymmetricTensorVectorComponents( dim );
+
+	if ( stressVariable ) {
+		self->stressVariable = stressVariable;
+		self->_valueAtParticle = _StressField_ValueAtParticle_FromVariable;
+	}
+		
+	/* Set pointers to swarm to be the same as the one on the constitutive matrix */
+	self->assemblyTerm->integrationSwarm = self->constitutiveMatrix->integrationSwarm;
+	self->massMatrixForceTerm->integrationSwarm = self->constitutiveMatrix->integrationSwarm;
+
+	/*
+	** If we're using this field for non-linear feedback, we'll need to update it in between
+	** non-linear iterations. */
+	if( sle )
+		SystemLinearEquations_AddPostNonLinearEP( sle, StressField_Type, StressField_NonLinearUpdate );
+}
+
+/* --- Virtual Function Implementations --- */
+void _StressField_Delete( void* stressField ) {
+	StressField* self = (StressField*) stressField;
+
+	_FeVariable_Delete( self );
+}
+
+void _StressField_Print( void* stressField, Stream* stream ) {
+	StressField* self = (StressField*) stressField;
+	
+	/* General info */
+	Journal_Printf( stream, "StressField (ptr): %p\n", self );
+	
+	/* Print parent */
+	_FeVariable_Print( self, stream );
+	
+	/* StressField info */
+	Journal_PrintPointer( stream, self->strainRateField );
+	Journal_PrintPointer( stream, self->constitutiveMatrix );
+}
+
+void* _StressField_Copy( const void* feVariable, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	StressField*	self = (StressField*)feVariable;
+	StressField*	newStressField;
+	
+	newStressField = (StressField*) _FeVariable_Copy( feVariable, dest, deep, nameExt, ptrMap );
+
+	newStressField->strainRateField = self->strainRateField;
+	newStressField->constitutiveMatrix = self->constitutiveMatrix;
+	
+	return (void*)newStressField;
+}
+
+void* _StressField_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                       _sizeOfSelf = sizeof(StressField);
+	Type                                                               type = StressField_Type;
+	Stg_Class_DeleteFunction*                                       _delete = _StressField_Delete;
+	Stg_Class_PrintFunction*                                         _print = _StressField_Print;
+	Stg_Class_CopyFunction*                                           _copy = _StressField_Copy;
+	Stg_Component_DefaultConstructorFunction*           _defaultConstructor = _StressField_DefaultNew;
+	Stg_Component_ConstructFunction*                             _construct = _StressField_AssignFromXML;
+	Stg_Component_BuildFunction*                                     _build = _StressField_Build;
+	Stg_Component_InitialiseFunction*                           _initialise = _StressField_Initialise;
+	Stg_Component_ExecuteFunction*                                 _execute = _StressField_Execute;
+	Stg_Component_DestroyFunction*                                 _destroy = _StressField_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 = _StressField_ValueAtParticle_Recalculate;
+
+	/* 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 = ZERO;
+	FieldVariable_GetValueFunction*   _getMaxGlobalFieldMagnitude = ZERO;
+	FeVariable_SyncShadowValuesFunc*            _syncShadowValues = ZERO;
+
+	return (void*) _StressField_New(  STRESSFIELD_PASSARGS  );
+}
+
+void StressField_NonLinearUpdate( void* _sle, void* _ctx ) {
+   SystemLinearEquations* sle;
+   DomainContext* ctx = (DomainContext*)_ctx;
+   FieldVariable_Register* fieldVar_Register;
+   StressField* stressVar;
+
+	sle = (SystemLinearEquations*)_sle;
+   fieldVar_Register = ctx->fieldVariable_Register;
+   stressVar = (StressField*)FieldVariable_Register_GetByName( fieldVar_Register, "StressField" );
+   ParticleFeVariable_Update( stressVar );
+}
+
+void _StressField_AssignFromXML( void* stressField, Stg_ComponentFactory* cf, void* data ){
+	StressField*          self = (StressField*) stressField;
+	FeVariable*           strainRateField;
+	ConstitutiveMatrix*   constitutiveMatrix;
+	Variable_Register*    variable_Register;
+	Name                  stressVariableName;
+	Variable*             stressVariable;
+	SystemLinearEquations* sle;
+
+	/* Construct Parent */
+	_ParticleFeVariable_AssignFromXML( self, cf, data );
+
+	strainRateField =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"StrainRateField", FeVariable, True, data  );
+	constitutiveMatrix = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"ConstitutiveMatrix", ConstitutiveMatrix, True, data );
+	variable_Register = self->context->variable_Register; 
+	assert( variable_Register  );
+
+	stressVariableName = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"StressVariable", "Stress"  );
+	stressVariable = Variable_Register_GetByName( variable_Register, stressVariableName );
+
+   sle = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"SLE", SystemLinearEquations, False, data  );
+
+	_StressField_Init( self, strainRateField, constitutiveMatrix, stressVariable, variable_Register, sle );
+}
+
+void _StressField_Build( void* stressField, void* data ) {
+	StressField* self = (StressField*) stressField;
+	char*              tmpName;
+	char*              variableName[6];
+	Dimension_Index   dim = self->constitutiveMatrix->dim;
+	Variable_Index variable_I;
+	Node_DomainIndex  node_I;
+
+	Stg_Component_Build( self->feMesh, data, False );
+	Stg_Component_Build( self->strainRateField, data, False );
+	Stg_Component_Build( self->constitutiveMatrix, data, False );
+	if ( self->stressVariable ) Stg_Component_Build( self->stressVariable, data, False );
+
+	if ( dim == 2 ) {
+		variableName[0] = StG_Strdup( "tau_xx" );
+		variableName[1] = StG_Strdup( "tau_yy" );
+		variableName[2] = StG_Strdup( "tau_xy" );
+	}
+	else {
+		variableName[0] = StG_Strdup( "tau_xx" );
+		variableName[1] = StG_Strdup( "tau_yy" );
+		variableName[2] = StG_Strdup( "tau_zz" );
+		variableName[3] = StG_Strdup( "tau_xy" );
+		variableName[4] = StG_Strdup( "tau_xz" );
+		variableName[5] = StG_Strdup( "tau_yz" );
+	}
+
+	/* Create Variable to store data */
+	assert( Class_IsSuper( self->feMesh->topo, IGraph ) );
+	tmpName = Stg_Object_AppendSuffix( self, (Name)"DataVariable"  );
+	self->dataVariable = Variable_NewVector(
+		tmpName,
+		(AbstractContext*)self->context,
+		Variable_DataType_Double, 
+		self->fieldComponentCount,
+		(Index*)(&((IGraph*)self->feMesh->topo)->remotes[MT_VERTEX]->nDomains), 
+		NULL,
+		(void**)&self->data, 
+		self->variable_Register,
+		variableName[0],
+		variableName[1],
+		variableName[2],
+		variableName[3],
+		variableName[4],
+		variableName[5] );
+	Memory_Free( tmpName );
+	
+	/* Create Dof Layout */
+	tmpName = Stg_Object_AppendSuffix( self, (Name)"DofLayout"  );
+	self->dofLayout = DofLayout_New( tmpName, self->context, self->variable_Register, 0, self->feMesh );
+	self->dofLayout->_numItemsInLayout = FeMesh_GetNodeDomainSize( self->feMesh );
+	for( variable_I = 0; variable_I < self->fieldComponentCount ; variable_I++ ) {
+		self->dataVariableList[ variable_I ] = Variable_Register_GetByName( self->variable_Register, 
+                             variableName[ variable_I ] );
+		for( node_I = 0; node_I < FeMesh_GetNodeDomainSize( self->feMesh ); node_I++ )
+			DofLayout_AddDof_ByVarName( self->dofLayout, variableName[variable_I], node_I );
+		/* Free Name */
+		Memory_Free( variableName[ variable_I ] );
+	}
+	Memory_Free( tmpName );
+	self->eqNum->dofLayout = self->dofLayout;
+
+	/* Build and Update all Variables that this component has created */
+	Stg_Component_Build( self->dataVariable, data, False); Variable_Update( self->dataVariable );
+	for( variable_I = 0; variable_I < self->fieldComponentCount ; variable_I++ ) {
+		Stg_Component_Build( self->dataVariableList[ variable_I ], data, False); Variable_Update( self->dataVariableList[ variable_I ] );
+	}
+
+	_ParticleFeVariable_Build( self, data );
+	/* Update again, just in case things were changed/reallocated when ICs loaded */
+	Variable_Update( self->dataVariable );
+	for( variable_I = 0; variable_I < self->fieldComponentCount ; variable_I++ ) {
+		Variable_Update( self->dataVariableList[ variable_I ] );
+	}
+}
+
+void _StressField_Initialise( void* stressField, void* data ) {
+	StressField* self = (StressField*) stressField;
+	Variable_Index variable_I;
+
+	Stg_Component_Initialise( self->strainRateField, data, False );
+	Stg_Component_Initialise( self->constitutiveMatrix, data, False );
+	/* Initialise and Update all Variables that this component has created */
+	Stg_Component_Initialise( self->dataVariable, data, False); Variable_Update( self->dataVariable );
+	for( variable_I = 0; variable_I < self->fieldComponentCount ; variable_I++ ) {
+		Stg_Component_Initialise( self->dataVariableList[ variable_I ], data, False); Variable_Update( self->dataVariableList[ variable_I ] );
+	}
+	
+	_ParticleFeVariable_Initialise( self, data );
+
+	/* Do a post-update just in case */
+	Variable_Update( self->dataVariable );
+	for( variable_I = 0; variable_I < self->fieldComponentCount ; variable_I++ ) {
+		Variable_Update( self->dataVariableList[ variable_I ] );
+	}
+
+}
+
+void _StressField_Execute( void* stressField, void* data ) {
+	StressField* self = (StressField*) stressField;
+
+	_ParticleFeVariable_Execute( self, data );
+}
+
+void _StressField_Destroy( void* stressField, void* data ) {
+	StressField* self = (StressField*) stressField;
+
+	Stg_Component_Destroy( self->strainRateField, data, False );
+	Stg_Component_Destroy( self->constitutiveMatrix, data, False );
+	Stg_Component_Destroy( self->dataVariable, data, False);
+
+	_ParticleFeVariable_Destroy( self, data );
+}
+
+void _StressField_ValueAtParticle_Recalculate( void* stressField, IntegrationPointsSwarm* swarm, Element_LocalIndex lElement_I, void* _particle, double* stress ) {
+	StressField*      self         = (StressField*) stressField;
+	SymmetricTensor   strainRate;
+	IntegrationPoint* particle     = (IntegrationPoint*) _particle;
+	
+	/* Calculate stress from strain rate and constitutive matrix */
+	ConstitutiveMatrix_Assemble( self->constitutiveMatrix, lElement_I,
+                                     self->currentParticleIndex, particle );
+	FeVariable_InterpolateWithinElement( self->strainRateField, lElement_I, particle->xi, strainRate );
+	ConstitutiveMatrix_CalculateStress( self->constitutiveMatrix, strainRate, stress );
+
+	assert ( !isnan( stress[0] ) );
+	assert ( !isnan( stress[1] ) );
+	assert ( !isnan( stress[2] ) );
+	
+}
+
+void _StressField_ValueAtParticle_FromVariable( void* stressField, IntegrationPointsSwarm* swarm, Element_LocalIndex lElement_I, void* particle, double* stress ) {
+	StressField*      self         = (StressField*) stressField;
+	double*           stressParticleExt;
+	MaterialPointsSwarm* materialPointsSwarm;
+	void* materialPoint;
+	
+	/* Ok, we break any fancy mapper stuff here and assume the materialParticles correspond exactly to the
+	 * Integration ones: */
+	materialPoint = OneToOneMapper_GetMaterialPoint( swarm->mapper, particle, &materialPointsSwarm );	
+
+	/* Get pointer to stress using variable */
+	stressParticleExt = (double*) ((ArithPointer) materialPoint + (ArithPointer)self->stressVariable->offsets[0]);
+	memcpy( stress, stressParticleExt, sizeof(double)*self->fieldComponentCount );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/TracerOutput.c
--- a/Utils/src/TracerOutput.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,290 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: TracerOutput.c 610 2007-10-11 08:09:29Z SteveQuenette $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "TracerOutput.h"
-
-#include <assert.h>
-#include <string.h>
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type TracerOutput_Type = "TracerOutput";
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-TracerOutput* TracerOutput_New(Name name,
-                               TimeIntegrator* timeIntegrator,
-                               FeVariable* velocityField )
-{
-  TracerOutput* self = (TracerOutput*) _TracerOutput_DefaultNew( name );
-
-  /* 	TracerOutput_InitAll */
-  abort();
-
-  return self;
-}
-
-TracerOutput* _TracerOutput_New(  TRACEROUTPUT_DEFARGS  )
-{
-  TracerOutput* self;
-	
-  /* Call private constructor of parent - this will set virtual
-     functions of parent and continue up the hierarchy tree. At the
-     beginning of the tree it will allocate memory of the size of
-     object and initialise all the memory to zero. */
-  assert( _sizeOfSelf >= sizeof(TracerOutput) );
-  self = (TracerOutput*)_SwarmOutput_New(  SWARMOUTPUT_PASSARGS  );
-
-  /* General info */
-
-  /* Virtual Info */
-	
-  return self;
-}
-
-void _TracerOutput_Init(void*                                 swarmOutput,
-                        FeVariable*                           pressureField,
-                        FeVariable**                           fields,
-                        unsigned int num_fields)
-{
-  TracerOutput*   self                = (TracerOutput*)swarmOutput;
-
-  self->pressureField      = pressureField;
-  self->num_fields=num_fields;
-  self->fields=Memory_Alloc_Array( FeVariable*, num_fields, "fields" );
-  memcpy( self->fields, fields, num_fields * sizeof(FeVariable*) );
-}
-
-
-/*------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _TracerOutput_Delete( void* swarmOutput ) {
-  TracerOutput* self = (TracerOutput*)swarmOutput;
-
-  Memory_Free(self->fields);
-  _SwarmOutput_Delete( self );
-}
-
-
-void _TracerOutput_Print( void* swarmOutput, Stream* stream ) {
-  TracerOutput* self = (TracerOutput*)swarmOutput;
-	
-  /* Print parent */
-  _SwarmOutput_Print( self, stream );
-}
-
-void* _TracerOutput_Copy( const void* swarmOutput, void* dest, Bool deep,
-                          Name nameExt, PtrMap* ptrMap ) {
-  TracerOutput*	self = (TracerOutput*)swarmOutput;
-  TracerOutput*	newTracerOutput;
-	
-  newTracerOutput = (TracerOutput*)_SwarmOutput_Copy( self, dest, deep, nameExt, ptrMap );
-  memcpy(newTracerOutput->fields, self->fields,
-         self->num_fields * sizeof(FeVariable*) );
-  newTracerOutput->num_fields = self->num_fields;
-	
-  return (void*)newTracerOutput;
-}
-
-void* _TracerOutput_DefaultNew( Name name ) {
-  /* Variables set in this function */
-  SizeT _sizeOfSelf = sizeof(TracerOutput);
-  Type type = TracerOutput_Type;
-  Stg_Class_DeleteFunction* _delete = _TracerOutput_Delete;
-  Stg_Class_PrintFunction* _print = _TracerOutput_Print;
-  Stg_Class_CopyFunction* _copy = _TracerOutput_Copy;
-  Stg_Component_DefaultConstructorFunction* _defaultConstructor
-    = _TracerOutput_DefaultNew;
-  Stg_Component_ConstructFunction* _construct = _TracerOutput_AssignFromXML;
-  Stg_Component_BuildFunction* _build = _TracerOutput_Build;
-  Stg_Component_InitialiseFunction* _initialise = _TracerOutput_Initialise;
-  Stg_Component_ExecuteFunction* _execute = _TracerOutput_Execute;
-  Stg_Component_DestroyFunction* _destroy = _TracerOutput_Destroy;
-  SwarmOutput_PrintHeaderFunction* _printHeader = _TracerOutput_PrintHeader;
-  SwarmOutput_PrintDataFunction* _printData = _TracerOutput_PrintData;
-
-  /* Variables that are set to ZERO are variables that will be set
-     either by the current _New function or another parent _New
-     function further up the hierachy */
-  AllocationType nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
-
-  return (void*) _TracerOutput_New(  TRACEROUTPUT_PASSARGS  );
-}
-
-
-void _TracerOutput_AssignFromXML( void* swarmOutput,
-                                  Stg_ComponentFactory* cf, void* data ) {
-  TracerOutput*  self          = (TracerOutput*) swarmOutput;
-  FeVariable*                 pressureField;
-  FeVariable**                 fields;
-  unsigned int num_fields;
-
-  _SwarmOutput_AssignFromXML( self, cf, data );
-
-  pressureField =
-    Stg_ComponentFactory_ConstructByKey(cf, self->name,
-                                        (Dictionary_Entry_Key)"PressureField",
-                                        FeVariable, False, data) ;
-  
-  fields=Stg_ComponentFactory_ConstructByList(cf,self->name,
-                                              (Dictionary_Entry_Key)"Fields",
-                                              Stg_ComponentFactory_Unlimited,
-                                              FeVariable,False,&num_fields,data);
-
-  _TracerOutput_Init(self,pressureField,fields,num_fields);
-
-  Memory_Free(fields);
-}
-
-void _TracerOutput_Build( void* swarmOutput, void* data ) {
-  int i;
-  TracerOutput*	self = (TracerOutput*) swarmOutput;
-
-  Stg_Component_Build( self->pressureField, data, False );
-  for(i=0;i<self->num_fields;++i)
-    Stg_Component_Build( self->fields[i], data, False );
-
-  _SwarmOutput_Build( self, data );
-}
-void _TracerOutput_Initialise( void* swarmOutput, void* data ) {
-  int i;
-  TracerOutput*	self = (TracerOutput*) swarmOutput;
-
-  Stg_Component_Initialise( self->pressureField, data, False );
-  for(i=0;i<self->num_fields;++i)
-    Stg_Component_Initialise( self->fields[i], data, False );
-	
-  _SwarmOutput_Initialise( self, data );
-}
-void _TracerOutput_Execute( void* swarmOutput, void* data ) {
-  TracerOutput*	self = (TracerOutput*)swarmOutput;
-	
-  _SwarmOutput_Execute( self, data );
-}
-void _TracerOutput_Destroy( void* swarmOutput, void* data ) {
-  int i;
-  TracerOutput*	self = (TracerOutput*)swarmOutput;
-
-  Stg_Component_Destroy( self->pressureField, data, False );
-  for(i=0;i<self->num_fields;++i)
-    Stg_Component_Destroy( self->fields[i], data, False );
-	
-  _SwarmOutput_Destroy( self, data );
-}
-
-void _TracerOutput_PrintHeader( void* swarmOutput, Stream* stream,
-                                Particle_Index lParticle_I, void* context ){
-  int i;
-  char name[32];
-  TracerOutput*	self = (TracerOutput*)swarmOutput;
-	
-  Stream_Enable(stream,True);
-  _SwarmOutput_PrintHeader( self, stream, lParticle_I, context );
-	
-  SwarmOutput_PrintString( self, stream, "Pressure" );
-  for(i=0;i<self->num_fields;++i)
-    {
-      sprintf(name,"Field%d",i);
-      SwarmOutput_PrintString( self, stream, name );
-    }
-}
-
-void _TracerOutput_PrintData( void* swarmOutput, Stream* stream,
-                              Particle_Index lParticle_I, void* context ){
-  TracerOutput*	self = (TracerOutput*)swarmOutput;
-  FiniteElementContext* fe_context = (FiniteElementContext*) context;
-  Swarm* swarm = self->swarm;
-  GlobalParticle* particle = (GlobalParticle*)Swarm_ParticleAt(swarm,
-                                                               lParticle_I);
-  double* coord = particle->coord;
-  HydrostaticTerm *hydrostaticTerm;
-  double pressure, field;
-  int i;
-
-  hydrostaticTerm =
-    (HydrostaticTerm*)LiveComponentRegister_Get(fe_context->CF->LCRegister,
-                                                "hydrostaticTerm" );
-
-  Journal_Firewall(swarm->particleLayout->coordSystem == GlobalCoordSystem,
-                   Journal_MyStream( Error_Type, self ),
-                   "Swarm is not using global coord system! Modify this code to use both systems\n" );
-
-  _SwarmOutput_PrintData( self, stream, lParticle_I, context );
-
-  FieldVariable_InterpolateValueAt(self->pressureField,coord,&pressure );
-  if(hydrostaticTerm){
-    pressure+=HydrostaticTerm_Pressure(hydrostaticTerm,coord);
-  }
-  SwarmOutput_PrintValue( self, stream, pressure );
-
-  for(i=0;i<self->num_fields;++i)
-    {
-      FieldVariable_InterpolateValueAt(self->fields[i],coord,&field);
-      SwarmOutput_PrintValue( self, stream, field );
-    }
-}
-
-/*-------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-/*---------------------------------------------------------------------------------------------------------------------
-** Entry Point Hooks
-*/
-
-/*-------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-
-
-
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/TracerOutput.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/TracerOutput.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,290 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: TracerOutput.c 610 2007-10-11 08:09:29Z SteveQuenette $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "TracerOutput.h"
+
+#include <assert.h>
+#include <string.h>
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type TracerOutput_Type = "TracerOutput";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+TracerOutput* TracerOutput_New(Name name,
+                               TimeIntegrator* timeIntegrator,
+                               FeVariable* velocityField )
+{
+  TracerOutput* self = (TracerOutput*) _TracerOutput_DefaultNew( name );
+
+  /* 	TracerOutput_InitAll */
+  abort();
+
+  return self;
+}
+
+TracerOutput* _TracerOutput_New(  TRACEROUTPUT_DEFARGS  )
+{
+  TracerOutput* self;
+	
+  /* Call private constructor of parent - this will set virtual
+     functions of parent and continue up the hierarchy tree. At the
+     beginning of the tree it will allocate memory of the size of
+     object and initialise all the memory to zero. */
+  assert( _sizeOfSelf >= sizeof(TracerOutput) );
+  self = (TracerOutput*)_SwarmOutput_New(  SWARMOUTPUT_PASSARGS  );
+
+  /* General info */
+
+  /* Virtual Info */
+	
+  return self;
+}
+
+void _TracerOutput_Init(void*                                 swarmOutput,
+                        FeVariable*                           pressureField,
+                        FeVariable**                           fields,
+                        unsigned int num_fields)
+{
+  TracerOutput*   self                = (TracerOutput*)swarmOutput;
+
+  self->pressureField      = pressureField;
+  self->num_fields=num_fields;
+  self->fields=Memory_Alloc_Array( FeVariable*, num_fields, "fields" );
+  memcpy( self->fields, fields, num_fields * sizeof(FeVariable*) );
+}
+
+
+/*------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _TracerOutput_Delete( void* swarmOutput ) {
+  TracerOutput* self = (TracerOutput*)swarmOutput;
+
+  Memory_Free(self->fields);
+  _SwarmOutput_Delete( self );
+}
+
+
+void _TracerOutput_Print( void* swarmOutput, Stream* stream ) {
+  TracerOutput* self = (TracerOutput*)swarmOutput;
+	
+  /* Print parent */
+  _SwarmOutput_Print( self, stream );
+}
+
+void* _TracerOutput_Copy( const void* swarmOutput, void* dest, Bool deep,
+                          Name nameExt, PtrMap* ptrMap ) {
+  TracerOutput*	self = (TracerOutput*)swarmOutput;
+  TracerOutput*	newTracerOutput;
+	
+  newTracerOutput = (TracerOutput*)_SwarmOutput_Copy( self, dest, deep, nameExt, ptrMap );
+  memcpy(newTracerOutput->fields, self->fields,
+         self->num_fields * sizeof(FeVariable*) );
+  newTracerOutput->num_fields = self->num_fields;
+	
+  return (void*)newTracerOutput;
+}
+
+void* _TracerOutput_DefaultNew( Name name ) {
+  /* Variables set in this function */
+  SizeT _sizeOfSelf = sizeof(TracerOutput);
+  Type type = TracerOutput_Type;
+  Stg_Class_DeleteFunction* _delete = _TracerOutput_Delete;
+  Stg_Class_PrintFunction* _print = _TracerOutput_Print;
+  Stg_Class_CopyFunction* _copy = _TracerOutput_Copy;
+  Stg_Component_DefaultConstructorFunction* _defaultConstructor
+    = _TracerOutput_DefaultNew;
+  Stg_Component_ConstructFunction* _construct = _TracerOutput_AssignFromXML;
+  Stg_Component_BuildFunction* _build = _TracerOutput_Build;
+  Stg_Component_InitialiseFunction* _initialise = _TracerOutput_Initialise;
+  Stg_Component_ExecuteFunction* _execute = _TracerOutput_Execute;
+  Stg_Component_DestroyFunction* _destroy = _TracerOutput_Destroy;
+  SwarmOutput_PrintHeaderFunction* _printHeader = _TracerOutput_PrintHeader;
+  SwarmOutput_PrintDataFunction* _printData = _TracerOutput_PrintData;
+
+  /* Variables that are set to ZERO are variables that will be set
+     either by the current _New function or another parent _New
+     function further up the hierachy */
+  AllocationType nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+
+  return (void*) _TracerOutput_New(  TRACEROUTPUT_PASSARGS  );
+}
+
+
+void _TracerOutput_AssignFromXML( void* swarmOutput,
+                                  Stg_ComponentFactory* cf, void* data ) {
+  TracerOutput*  self          = (TracerOutput*) swarmOutput;
+  FeVariable*                 pressureField;
+  FeVariable**                 fields;
+  unsigned int num_fields;
+
+  _SwarmOutput_AssignFromXML( self, cf, data );
+
+  pressureField =
+    Stg_ComponentFactory_ConstructByKey(cf, self->name,
+                                        (Dictionary_Entry_Key)"PressureField",
+                                        FeVariable, False, data) ;
+  
+  fields=Stg_ComponentFactory_ConstructByList(cf,self->name,
+                                              (Dictionary_Entry_Key)"Fields",
+                                              Stg_ComponentFactory_Unlimited,
+                                              FeVariable,False,&num_fields,data);
+
+  _TracerOutput_Init(self,pressureField,fields,num_fields);
+
+  Memory_Free(fields);
+}
+
+void _TracerOutput_Build( void* swarmOutput, void* data ) {
+  int i;
+  TracerOutput*	self = (TracerOutput*) swarmOutput;
+
+  Stg_Component_Build( self->pressureField, data, False );
+  for(i=0;i<self->num_fields;++i)
+    Stg_Component_Build( self->fields[i], data, False );
+
+  _SwarmOutput_Build( self, data );
+}
+void _TracerOutput_Initialise( void* swarmOutput, void* data ) {
+  int i;
+  TracerOutput*	self = (TracerOutput*) swarmOutput;
+
+  Stg_Component_Initialise( self->pressureField, data, False );
+  for(i=0;i<self->num_fields;++i)
+    Stg_Component_Initialise( self->fields[i], data, False );
+	
+  _SwarmOutput_Initialise( self, data );
+}
+void _TracerOutput_Execute( void* swarmOutput, void* data ) {
+  TracerOutput*	self = (TracerOutput*)swarmOutput;
+	
+  _SwarmOutput_Execute( self, data );
+}
+void _TracerOutput_Destroy( void* swarmOutput, void* data ) {
+  int i;
+  TracerOutput*	self = (TracerOutput*)swarmOutput;
+
+  Stg_Component_Destroy( self->pressureField, data, False );
+  for(i=0;i<self->num_fields;++i)
+    Stg_Component_Destroy( self->fields[i], data, False );
+	
+  _SwarmOutput_Destroy( self, data );
+}
+
+void _TracerOutput_PrintHeader( void* swarmOutput, Stream* stream,
+                                Particle_Index lParticle_I, void* context ){
+  int i;
+  char name[32];
+  TracerOutput*	self = (TracerOutput*)swarmOutput;
+	
+  Stream_Enable(stream,True);
+  _SwarmOutput_PrintHeader( self, stream, lParticle_I, context );
+	
+  SwarmOutput_PrintString( self, stream, "Pressure" );
+  for(i=0;i<self->num_fields;++i)
+    {
+      sprintf(name,"Field%d",i);
+      SwarmOutput_PrintString( self, stream, name );
+    }
+}
+
+void _TracerOutput_PrintData( void* swarmOutput, Stream* stream,
+                              Particle_Index lParticle_I, void* context ){
+  TracerOutput*	self = (TracerOutput*)swarmOutput;
+  FiniteElementContext* fe_context = (FiniteElementContext*) context;
+  Swarm* swarm = self->swarm;
+  GlobalParticle* particle = (GlobalParticle*)Swarm_ParticleAt(swarm,
+                                                               lParticle_I);
+  double* coord = particle->coord;
+  HydrostaticTerm *hydrostaticTerm;
+  double pressure, field;
+  int i;
+
+  hydrostaticTerm =
+    (HydrostaticTerm*)LiveComponentRegister_Get(fe_context->CF->LCRegister,
+                                                "hydrostaticTerm" );
+
+  Journal_Firewall(swarm->particleLayout->coordSystem == GlobalCoordSystem,
+                   Journal_MyStream( Error_Type, self ),
+                   "Swarm is not using global coord system! Modify this code to use both systems\n" );
+
+  _SwarmOutput_PrintData( self, stream, lParticle_I, context );
+
+  FieldVariable_InterpolateValueAt(self->pressureField,coord,&pressure );
+  if(hydrostaticTerm){
+    pressure+=HydrostaticTerm_Pressure(hydrostaticTerm,coord);
+  }
+  SwarmOutput_PrintValue( self, stream, pressure );
+
+  for(i=0;i<self->num_fields;++i)
+    {
+      FieldVariable_InterpolateValueAt(self->fields[i],coord,&field);
+      SwarmOutput_PrintValue( self, stream, field );
+    }
+}
+
+/*-------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+/*---------------------------------------------------------------------------------------------------------------------
+** Entry Point Hooks
+*/
+
+/*-------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+
+
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/UnderworldContext.c
--- a/Utils/src/UnderworldContext.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,222 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: Context.c 725 2008-05-08 05:15:45Z WendySharples $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Rheology/Rheology.h>
-#include <Underworld/Rheology/Rheology.h>
-
-#include "types.h"
-#include "UnderworldContext.h"
-#include "XDMFGenerator.h"
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type UnderworldContext_Type = "UnderworldContext";
-
-/* Constructors ------------------------------------------------------------------------------------------------*/
-
-UnderworldContext* UnderworldContext_New( 
-	Name			name,
-	double		start,
-	double		stop,
-	MPI_Comm		communicator,
-	Dictionary*	dictionary )
-{
-  UnderworldContext* self = (UnderworldContext*)_UnderworldContext_DefaultNew( name );
-
-	self->isConstructed = True;
-	_AbstractContext_Init( (AbstractContext*) self );
-	_DomainContext_Init( (DomainContext*) self );	
-	_FiniteElementContext_Init( (FiniteElementContext*) self );
-	_PICelleratorContext_Init( (PICelleratorContext*) self );
-	_UnderworldContext_Init( self );
-
-	return self;
-}	
-
-void* _UnderworldContext_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(UnderworldContext);
-	Type                                                      type = UnderworldContext_Type;
-	Stg_Class_DeleteFunction*                              _delete = _UnderworldContext_Delete;
-	Stg_Class_PrintFunction*                                _print = _UnderworldContext_Print;
-	Stg_Class_CopyFunction*                                  _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _UnderworldContext_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _UnderworldContext_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _AbstractContext_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _AbstractContext_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _AbstractContext_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = (Stg_Component_DestroyFunction*)_UnderworldContext_Destroy;
-	AllocationType                              nameAllocationType = NON_GLOBAL;
-	AbstractContext_SetDt*                                  _setDt = _UnderworldContext_SetDt;
-	double                                               startTime = 0;
-	double                                                stopTime = 0;
-	MPI_Comm                                          communicator = MPI_COMM_WORLD;
-	Dictionary*                                         dictionary = NULL;
-
-	return (void*) _UnderworldContext_New(  UNDERWORLDCONTEXT_PASSARGS  );
-}
-
-UnderworldContext* _UnderworldContext_New(  UNDERWORLDCONTEXT_DEFARGS  ) {
-	UnderworldContext* self;
-	
-	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. 
-		At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-	self = (UnderworldContext*)_PICelleratorContext_New(  PICELLERATORCONTEXT_PASSARGS  );
-	
-	/* General info */
-	
-	/* Function pointers for this class that are not on the parent class should be set here */
-	
-	return self;
-}
-
-void _UnderworldContext_Init( UnderworldContext* self ) {
-	self->isConstructed = True;
-   /*
-   self->timeIntegrator = NULL;
-   self->stokesSLE = NULL;
-   self->energySLE = NULL;
-   self->compositionSLE = NULL;
-   self->constitutiveMatrix = NULL;
-   */
-
-	/* always generate XDMF files when we generate HDF5 checkpoints */
-#ifdef WRITE_HDF5
-	if( Dictionary_Entry_Value_AsBool( Dictionary_GetDefault( self->dictionary, "generateXDMF", Dictionary_Entry_Value_FromBool( True ) ) ) ){
-		ContextEP_Append( self, AbstractContext_EP_Save, XDMFGenerator_GenerateAll );
-		ContextEP_Append( self, AbstractContext_EP_DataSave, XDMFGenerator_GenerateAll );
-	}
-#endif
-   
-   /* turn off because the context no longer holds things
-	EntryPoint_Append_AlwaysLast( Context_GetEntryPoint( self, AbstractContext_EP_AssignFromXML ),
-		"Underworld App Assign Pointers",
-		UnderworldContext_AssignPointers,
-		"Underworld_App_Construct" );
-      */
-}
-
-/* Virtual Functions -------------------------------------------------------------------------------------------------------------*/
-
-void _UnderworldContext_AssignFromXML( void* context, Stg_ComponentFactory* cf, void* data ) {
-	UnderworldContext* self = (UnderworldContext*)context;
-
-	_PICelleratorContext_AssignFromXML( context, cf, data );
-
-	_UnderworldContext_Init( self );
-}
-
-void _UnderworldContext_Delete( void* context ) {
-	UnderworldContext* self = (UnderworldContext*)context;
-	
-	Journal_DPrintf( self->debug, "In: %s()\n", __func__ );
-
-	/* Stg_Class_Delete parent */
-	_PICelleratorContext_Delete( self );
-}
-
-void _UnderworldContext_Destroy( void *component, void* context ) {
-	UnderworldContext* self = (UnderworldContext*)component;
-	
-	_PICelleratorContext_Destroy( self, self );
-}
-
-void _UnderworldContext_Print( void* context, Stream* stream ) {
-	UnderworldContext* self = (UnderworldContext*)context;
-	
-	/* General info */
-	Journal_Printf( (void*) stream, "UnderworldContext (ptr): %p\n", self );
-	
-	/* Print parent */
-	_PICelleratorContext_Print( self, stream );
-
-#if 0
-	Journal_PrintPointer( stream, self->stokesSLE );
-	Journal_PrintPointer( stream, self->energySLE );
-	Journal_PrintPointer( stream, self->compositionSLE );
-	Journal_PrintPointer( stream, self->constitutiveMatrix );
-#endif
-}
-
-
-void _UnderworldContext_SetDt( void* context, double dt ) {
-	UnderworldContext* self = (UnderworldContext*)context;
-	
-	self->dt = dt;
-}
-
-
-/* Public Functions ----------------------------------------------------------------------------------------------------*/
-
-
-/* EntryPoint Hooks ----------------------------------------------------------------------------------------------------*/
-
-void UnderworldContext_AssignPointers( void* context, void* ptrToContext ) {
-	UnderworldContext* self = (UnderworldContext*) context;
-	
-	Stream_IndentBranch( StgFEM_Debug );
-	Journal_DPrintf( self->debug, "In: %s()\n", __func__ );
-
-	if ( !self->CF )
-		return;
-	
-#if 0
-	self->timeIntegrator = (TimeIntegrator*)  LiveComponentRegister_Get( self->CF->LCRegister, (Name)"timeIntegrator" );
-
-	/* Get SLEs */
-	self->stokesSLE = (Stokes_SLE* )            LiveComponentRegister_Get( self->CF->LCRegister, (Name)"stokesEqn" );
-	self->energySLE = (AdvectionDiffusionSLE* ) LiveComponentRegister_Get( self->CF->LCRegister, (Name)"EnergyEqn" );
-	self->compositionSLE = (AdvectionDiffusionSLE* ) LiveComponentRegister_Get( self->CF->LCRegister, (Name)"CompositionEqn" );
-	self->constitutiveMatrix = (ConstitutiveMatrix* ) LiveComponentRegister_Get( self->CF->LCRegister, (Name)"constitutiveMatrix" );
-#endif
-	
-	Stream_UnIndentBranch( StgFEM_Debug  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/UnderworldContext.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/UnderworldContext.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,222 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: Context.c 725 2008-05-08 05:15:45Z WendySharples $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Rheology/Rheology.h>
+#include <Underworld/Rheology/Rheology.h>
+
+#include "types.h"
+#include "UnderworldContext.h"
+#include "XDMFGenerator.h"
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type UnderworldContext_Type = "UnderworldContext";
+
+/* Constructors ------------------------------------------------------------------------------------------------*/
+
+UnderworldContext* UnderworldContext_New( 
+	Name			name,
+	double		start,
+	double		stop,
+	MPI_Comm		communicator,
+	Dictionary*	dictionary )
+{
+  UnderworldContext* self = (UnderworldContext*)_UnderworldContext_DefaultNew( name );
+
+	self->isConstructed = True;
+	_AbstractContext_Init( (AbstractContext*) self );
+	_DomainContext_Init( (DomainContext*) self );	
+	_FiniteElementContext_Init( (FiniteElementContext*) self );
+	_PICelleratorContext_Init( (PICelleratorContext*) self );
+	_UnderworldContext_Init( self );
+
+	return self;
+}	
+
+void* _UnderworldContext_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(UnderworldContext);
+	Type                                                      type = UnderworldContext_Type;
+	Stg_Class_DeleteFunction*                              _delete = _UnderworldContext_Delete;
+	Stg_Class_PrintFunction*                                _print = _UnderworldContext_Print;
+	Stg_Class_CopyFunction*                                  _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _UnderworldContext_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _UnderworldContext_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _AbstractContext_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _AbstractContext_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _AbstractContext_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = (Stg_Component_DestroyFunction*)_UnderworldContext_Destroy;
+	AllocationType                              nameAllocationType = NON_GLOBAL;
+	AbstractContext_SetDt*                                  _setDt = _UnderworldContext_SetDt;
+	double                                               startTime = 0;
+	double                                                stopTime = 0;
+	MPI_Comm                                          communicator = MPI_COMM_WORLD;
+	Dictionary*                                         dictionary = NULL;
+
+	return (void*) _UnderworldContext_New(  UNDERWORLDCONTEXT_PASSARGS  );
+}
+
+UnderworldContext* _UnderworldContext_New(  UNDERWORLDCONTEXT_DEFARGS  ) {
+	UnderworldContext* self;
+	
+	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. 
+		At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+	self = (UnderworldContext*)_PICelleratorContext_New(  PICELLERATORCONTEXT_PASSARGS  );
+	
+	/* General info */
+	
+	/* Function pointers for this class that are not on the parent class should be set here */
+	
+	return self;
+}
+
+void _UnderworldContext_Init( UnderworldContext* self ) {
+	self->isConstructed = True;
+   /*
+   self->timeIntegrator = NULL;
+   self->stokesSLE = NULL;
+   self->energySLE = NULL;
+   self->compositionSLE = NULL;
+   self->constitutiveMatrix = NULL;
+   */
+
+	/* always generate XDMF files when we generate HDF5 checkpoints */
+#ifdef WRITE_HDF5
+	if( Dictionary_Entry_Value_AsBool( Dictionary_GetDefault( self->dictionary, "generateXDMF", Dictionary_Entry_Value_FromBool( True ) ) ) ){
+		ContextEP_Append( self, AbstractContext_EP_Save, XDMFGenerator_GenerateAll );
+		ContextEP_Append( self, AbstractContext_EP_DataSave, XDMFGenerator_GenerateAll );
+	}
+#endif
+   
+   /* turn off because the context no longer holds things
+	EntryPoint_Append_AlwaysLast( Context_GetEntryPoint( self, AbstractContext_EP_AssignFromXML ),
+		"Underworld App Assign Pointers",
+		UnderworldContext_AssignPointers,
+		"Underworld_App_Construct" );
+      */
+}
+
+/* Virtual Functions -------------------------------------------------------------------------------------------------------------*/
+
+void _UnderworldContext_AssignFromXML( void* context, Stg_ComponentFactory* cf, void* data ) {
+	UnderworldContext* self = (UnderworldContext*)context;
+
+	_PICelleratorContext_AssignFromXML( context, cf, data );
+
+	_UnderworldContext_Init( self );
+}
+
+void _UnderworldContext_Delete( void* context ) {
+	UnderworldContext* self = (UnderworldContext*)context;
+	
+	Journal_DPrintf( self->debug, "In: %s()\n", __func__ );
+
+	/* Stg_Class_Delete parent */
+	_PICelleratorContext_Delete( self );
+}
+
+void _UnderworldContext_Destroy( void *component, void* context ) {
+	UnderworldContext* self = (UnderworldContext*)component;
+	
+	_PICelleratorContext_Destroy( self, self );
+}
+
+void _UnderworldContext_Print( void* context, Stream* stream ) {
+	UnderworldContext* self = (UnderworldContext*)context;
+	
+	/* General info */
+	Journal_Printf( (void*) stream, "UnderworldContext (ptr): %p\n", self );
+	
+	/* Print parent */
+	_PICelleratorContext_Print( self, stream );
+
+#if 0
+	Journal_PrintPointer( stream, self->stokesSLE );
+	Journal_PrintPointer( stream, self->energySLE );
+	Journal_PrintPointer( stream, self->compositionSLE );
+	Journal_PrintPointer( stream, self->constitutiveMatrix );
+#endif
+}
+
+
+void _UnderworldContext_SetDt( void* context, double dt ) {
+	UnderworldContext* self = (UnderworldContext*)context;
+	
+	self->dt = dt;
+}
+
+
+/* Public Functions ----------------------------------------------------------------------------------------------------*/
+
+
+/* EntryPoint Hooks ----------------------------------------------------------------------------------------------------*/
+
+void UnderworldContext_AssignPointers( void* context, void* ptrToContext ) {
+	UnderworldContext* self = (UnderworldContext*) context;
+	
+	Stream_IndentBranch( StgFEM_Debug );
+	Journal_DPrintf( self->debug, "In: %s()\n", __func__ );
+
+	if ( !self->CF )
+		return;
+	
+#if 0
+	self->timeIntegrator = (TimeIntegrator*)  LiveComponentRegister_Get( self->CF->LCRegister, (Name)"timeIntegrator" );
+
+	/* Get SLEs */
+	self->stokesSLE = (Stokes_SLE* )            LiveComponentRegister_Get( self->CF->LCRegister, (Name)"stokesEqn" );
+	self->energySLE = (AdvectionDiffusionSLE* ) LiveComponentRegister_Get( self->CF->LCRegister, (Name)"EnergyEqn" );
+	self->compositionSLE = (AdvectionDiffusionSLE* ) LiveComponentRegister_Get( self->CF->LCRegister, (Name)"CompositionEqn" );
+	self->constitutiveMatrix = (ConstitutiveMatrix* ) LiveComponentRegister_Get( self->CF->LCRegister, (Name)"constitutiveMatrix" );
+#endif
+	
+	Stream_UnIndentBranch( StgFEM_Debug  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/Underworld_SwarmOutput.c
--- a/Utils/src/Underworld_SwarmOutput.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,371 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: Underworld_SwarmOutput.c 358 2006-10-18 06:17:30Z SteveQuenette $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "types.h"
-#include "Underworld_SwarmOutput.h"
-
-#include <assert.h>
-#include <string.h>
-
-/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
-const Type Underworld_SwarmOutput_Type = "Underworld_SwarmOutput";
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-Underworld_SwarmOutput* Underworld_SwarmOutput_New(
-		Name                                  name,
-		TimeIntegrator*                       timeIntegrator,
-		FeVariable*                           velocityField )
-{
-	Underworld_SwarmOutput* self = (Underworld_SwarmOutput*) _Underworld_SwarmOutput_DefaultNew( name );
-
-	/* 	Underworld_SwarmOutput_InitAll */
-	abort();
-
-	return self;
-}
-
-Underworld_SwarmOutput* _Underworld_SwarmOutput_New(  UNDERWORLD_SWARMOUTPUT_DEFARGS  )
-{
-	Underworld_SwarmOutput* self;
-	
-	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-	assert( _sizeOfSelf >= sizeof(Underworld_SwarmOutput) );
-	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
-	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
-	   and so should be set to ZERO in any children of this class. */
-	nameAllocationType = NON_GLOBAL;
-
-	self = (Underworld_SwarmOutput*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
-
-	
-	/* General info */
-
-	/* Virtual Info */
-	
-	return self;
-}
-
-
-/*------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _Underworld_SwarmOutput_Delete( void* uwSwarmOutput ) {
-	Underworld_SwarmOutput* self = (Underworld_SwarmOutput*)uwSwarmOutput;
-
-	Memory_Free( self->feVariableList );
-	/* Delete parent */
-	_SwarmOutput_Delete( self );
-}
-
-
-void _Underworld_SwarmOutput_Print( void* uwSwarmOutput, Stream* stream ) {
-	Underworld_SwarmOutput* self = (Underworld_SwarmOutput*)uwSwarmOutput;
-	
-	/* Print parent */
-	_SwarmOutput_Print( self, stream );
-}
-
-void* _Underworld_SwarmOutput_Copy( const void* uwSwarmOutput, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	Underworld_SwarmOutput*	self = (Underworld_SwarmOutput*)uwSwarmOutput;
-	Underworld_SwarmOutput*	newUnderworld_SwarmOutput;
-	
-	newUnderworld_SwarmOutput = (Underworld_SwarmOutput*)_SwarmOutput_Copy( self, dest, deep, nameExt, ptrMap );
-	
-	return (void*)newUnderworld_SwarmOutput;
-}
-
-void* _Underworld_SwarmOutput_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Underworld_SwarmOutput);
-	Type                                                      type = Underworld_SwarmOutput_Type;
-	Stg_Class_DeleteFunction*                              _delete = _Underworld_SwarmOutput_Delete;
-	Stg_Class_PrintFunction*                                _print = _Underworld_SwarmOutput_Print;
-	Stg_Class_CopyFunction*                                  _copy = _Underworld_SwarmOutput_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_SwarmOutput_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Underworld_SwarmOutput_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _Underworld_SwarmOutput_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _Underworld_SwarmOutput_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _Underworld_SwarmOutput_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _Underworld_SwarmOutput_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*) _Underworld_SwarmOutput_New(  UNDERWORLD_SWARMOUTPUT_PASSARGS  );
-}
-
-void _Underworld_SwarmOutput_Init( Underworld_SwarmOutput* self,
-				PICelleratorContext*  context,
-				MaterialPointsSwarm*  materialSwarm,
-				unsigned int          listCount,
-				FeVariable**          feVariableList) {
-	self->materialSwarm = materialSwarm;
-	self->sizeList = listCount;
-	self->_getFeValuesFunc = _Underworld_SwarmOutput_GetFeVariableValues;
-	self->_printFunc = _Underworld_SwarmOutput_PrintStandardFormat;
-	self->feVariableList = feVariableList;
-
-	/* my Swarm output will run on the SaveClass EP - the same time as standard checkpointing */
-	EP_AppendClassHook( Context_GetEntryPoint( context, AbstractContext_EP_SaveClass ), _Underworld_SwarmOutput_Execute, self );
-}
-
-void _Underworld_SwarmOutput_AssignFromXML( void* uwSwarmOutput, Stg_ComponentFactory* cf, void* data ) {
-	Underworld_SwarmOutput*  self          = (Underworld_SwarmOutput*) uwSwarmOutput;
-
-	PICelleratorContext*    context;
-	MaterialPointsSwarm*    materialSwarm;
-	Dictionary*             dictionary = Dictionary_GetDictionary( cf->componentDict, self->name );
-	Dictionary_Entry_Value* list;
-	unsigned int            listCount, feVar_I;
-	char*                   varName;
-	Stream                  *errorStream = Journal_Register( Error_Type, (Name)"_Underworld_SwarmOutput_Construct"  );
-   FeVariable**            feVariableList;
-	
-	context      =  Stg_ComponentFactory_ConstructByName( cf, (Name)"context", PICelleratorContext, True, data ) ;
-	materialSwarm = (MaterialPointsSwarm* )Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Swarm", MaterialPointsSwarm, True, data  );
-	
-	/* Get all Swarms specified in input file, under swarms */
-	list = Dictionary_Get( dictionary, (Dictionary_Entry_Key)"FeVariables"  );
-	
-	Journal_Firewall(
-			list != NULL,
-			errorStream,
-			"Error in %s:\n"
-			"You must specify a list of fevariables to interpolate onto the swarm in your xml. Example:\n"
-			"<list name=\"FeVariables\">\n"
-				"\t<param>PressureField</param>\n"
-			"</list>\n", __func__ );
-	
-	listCount = Dictionary_Entry_Value_GetCount( list );
-
-   Journal_Firewall(
-			listCount != 0,
-			errorStream,
-			"Error in %s:\n"
-			"You have no FeVariables defined in the FeVariable list. At least one FeVariable must be included. Example:\n"
-			"<list name=\"FeVariables\">\n"
-				"\t<param>PressureField</param>\n"
-			"</list>\n", __func__ );
-	
-	/* Allocate the memory to store pointers to them */
-	feVariableList = Memory_Alloc_Array( FeVariable*, listCount, "List FeVariables" );
-
-	for( feVar_I = 0 ; feVar_I < listCount ; feVar_I++ ) {
-		varName = Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetElement( list, feVar_I ) );
-		feVariableList[ feVar_I ] = Stg_ComponentFactory_ConstructByName( cf, (Name)varName, FeVariable, True, data  );
-	}
-
-	_Underworld_SwarmOutput_Init( self,
-				 context,
-				 materialSwarm,
-				 listCount,
-				 feVariableList);
-
-}
-
-void _Underworld_SwarmOutput_Build( void* uwSwarmOutput, void* data ) {
-	Underworld_SwarmOutput*	self = (Underworld_SwarmOutput*) uwSwarmOutput;
-	unsigned int feVar_I, feVarNum;
-	
-	/* Build all StGermain based data structure this component uses */
-	feVarNum = self->sizeList;
-	for( feVar_I = 0 ; feVar_I < feVarNum; feVar_I++ ) 
-		Stg_Component_Build( self->feVariableList[feVar_I], data, False );
-
-	Stg_Component_Build( self->materialSwarm, data, False );
-}
-void _Underworld_SwarmOutput_Initialise( void* uwSwarmOutput, void* data ) {
-	Underworld_SwarmOutput*	self = (Underworld_SwarmOutput*) uwSwarmOutput;
-	unsigned int feVar_I, feVarNum;
-	
-	/* Initialise all StGermain based data structure this component uses */
-	feVarNum = self->sizeList;
-	for( feVar_I = 0 ; feVar_I < feVarNum; feVar_I++ ) 
-		Stg_Component_Initialise( self->feVariableList[feVar_I], data, False );
-
-	Stg_Component_Initialise( self->materialSwarm, data, False );
-}
-
-void _Underworld_SwarmOutput_Execute( void* uwSwarmOutput, void* data ) {
-	Underworld_SwarmOutput*	self = (Underworld_SwarmOutput*)uwSwarmOutput;
-	PICelleratorContext*    context = (PICelleratorContext*)data;
-	MaterialPointsSwarm*    materialSwarm;
-	FeVariable*             feVar;
-	char*                   filename;
-	char*                   outputPath = context->outputPath;
-	unsigned int            feVar_I, feVarNum, timeStep;
-
-	FILE*              outputFile;
-	MPI_Comm	   comm;
-	int                myRank;
-	int                nProcs;
-	MPI_Status         status;
-	const int          FINISHED_WRITING_TAG = 100;
-	int                canExecute = 0;
-
-	
-	timeStep = context->timeStep;
-	feVarNum = self->sizeList;
-	materialSwarm = self->materialSwarm;
-	
-	/* for each field create file and then write */
-	for( feVar_I = 0 ; feVar_I < feVarNum; feVar_I++ ) {
-		feVar = self->feVariableList[feVar_I];
-
-		comm = Comm_GetMPIComm( Mesh_GetCommTopology( feVar->feMesh, MT_VERTEX ) );
-
-		MPI_Comm_size( comm, (int*)&nProcs );
-		MPI_Comm_rank( comm, (int*)&myRank );
-
-		filename = Memory_Alloc_Array_Unnamed( char,
-		        /*           OutputPath     .      FieldName        .      SwarmName                . time . dat\0 */
-			       	strlen(outputPath) +1+ strlen(feVar->name) +1+ strlen(materialSwarm->name) +1+ 5 + 1+ 3 +1 );
-		sprintf( filename, "%s/%s.%s.%.5u.dat", outputPath, feVar->name, materialSwarm->name, timeStep );
-		/* wait for go-ahead from process ranked lower than me, to avoid competition writing to file */
-		if ( myRank != 0  && canExecute == 0 ) {
-			MPI_Recv( &canExecute, 1, MPI_INT, myRank - 1, FINISHED_WRITING_TAG, comm, &status );
-		}	
-
-		/* if myRank is 0, create or append file, otherwise append to file */
-		if (myRank == 0) {
-			/* append to file if restarting from checkpoint */
-			if( context->loadFromCheckPoint )
-				outputFile = fopen( filename, "a" );
-			else
-				outputFile = fopen( filename, "w" );
-			fprintf( outputFile, "# FORMAT is:\n# MaterialID, Xpos, Ypos, Zpos, (values of field)\n" );
-		} else {
-		       	outputFile = fopen( filename, "a" );
-		}
-
-		self->_getFeValuesFunc( self, feVar, materialSwarm, outputFile );
-		fclose( outputFile );
-	}
-
-	/* confirms this processor is finshed */
-	canExecute = 1;
-	/* send go-ahead from process ranked lower than me, to avoid competition writing to file */
-	if ( myRank != nProcs - 1 ) {
-		MPI_Ssend( &canExecute, 1, MPI_INT, myRank + 1, FINISHED_WRITING_TAG, comm );
-	}
-
-	Memory_Free( filename );
-}
-
-void _Underworld_SwarmOutput_Destroy( void* uwSwarmOutput, void* data ) {
-	Underworld_SwarmOutput*	self = (Underworld_SwarmOutput*)uwSwarmOutput;
-	unsigned int feVar_I, feVarNum;
-
-	/* Destroy all StGermain based data structure this component uses */
-	feVarNum = self->sizeList;	
-	for( feVar_I = 0 ; feVar_I < feVarNum; feVar_I++ ) 
-		Stg_Component_Destroy( self->feVariableList[feVar_I], data, False );
-
-	Stg_Component_Destroy( self->materialSwarm, data, False );
-	
-}
-
-void _Underworld_SwarmOutput_PrintStandardFormat( MaterialPoint* particle, double* result, unsigned fieldComponentCount, FILE* outputFile ) {
-		unsigned dof_I;
-		fprintf( outputFile, "%u ", particle->materialIndex );
-                fprintf( outputFile, "%.15g %.15g %.15g ", particle->coord[0], particle->coord[1], particle->coord[2] ); 
-		for ( dof_I = 0; dof_I < fieldComponentCount; dof_I++ ) 
-			fprintf( outputFile, "%.15g ", result[dof_I] );
-			
-		fprintf( outputFile, "\n" );
-}
-	
-void _Underworld_SwarmOutput_GetFeVariableValues(Underworld_SwarmOutput* uwSwarmOutput, FeVariable* feVariable, MaterialPointsSwarm* swarm, FILE* outputFile) {
-	Underworld_SwarmOutput*	self = (Underworld_SwarmOutput*)uwSwarmOutput;
-	MaterialPoint*          particle;
-	unsigned int            localElementCount, lElement_I; 
-	unsigned int            cellID, cellParticleCount, cParticle_I;
-	unsigned int            fieldComponentCount = feVariable->fieldComponentCount;
-	FeMesh*                 feMesh = feVariable->feMesh;
-	double*                 result = Memory_Alloc_Array( double, fieldComponentCount, "Answer to Life?" );
-
-	localElementCount = FeMesh_GetElementLocalSize( feMesh );
-
-	/* Loop over local elements in problem */
-	for( lElement_I = 0 ; lElement_I < localElementCount ; lElement_I++ ) {
-		cellID            = CellLayout_MapElementIdToCellId( swarm->cellLayout, lElement_I );
-		cellParticleCount = swarm->cellParticleCountTbl[ cellID ];
-
-		/* Loop over materialPoints in element */
-		for ( cParticle_I = 0 ; cParticle_I < cellParticleCount ; cParticle_I++ ) {
-			particle = (MaterialPoint*)Swarm_ParticleInCellAt( swarm, cellID, cParticle_I );
-			/* Interpolate field to particle location (is Global because it uses the
-			 * material Points Swarm, could be a bit slow ???*/
-			_FeVariable_InterpolateValueAt( feVariable, particle->coord, result );
-
-			self->_printFunc( particle, result, fieldComponentCount, outputFile );
-
-		}
-	}
-	Memory_Free( result );
-}
-
-/*-------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-/*---------------------------------------------------------------------------------------------------------------------
-** Entry Point Hooks
-*/
-
-/*-------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-
-
-
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/Underworld_SwarmOutput.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/Underworld_SwarmOutput.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,371 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: Underworld_SwarmOutput.c 358 2006-10-18 06:17:30Z SteveQuenette $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "types.h"
+#include "Underworld_SwarmOutput.h"
+
+#include <assert.h>
+#include <string.h>
+
+/* Textual name of this class - This is a global pointer which is used for times when you need to refer to class and not a particular instance of a class */
+const Type Underworld_SwarmOutput_Type = "Underworld_SwarmOutput";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+Underworld_SwarmOutput* Underworld_SwarmOutput_New(
+		Name                                  name,
+		TimeIntegrator*                       timeIntegrator,
+		FeVariable*                           velocityField )
+{
+	Underworld_SwarmOutput* self = (Underworld_SwarmOutput*) _Underworld_SwarmOutput_DefaultNew( name );
+
+	/* 	Underworld_SwarmOutput_InitAll */
+	abort();
+
+	return self;
+}
+
+Underworld_SwarmOutput* _Underworld_SwarmOutput_New(  UNDERWORLD_SWARMOUTPUT_DEFARGS  )
+{
+	Underworld_SwarmOutput* self;
+	
+	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree. At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+	assert( _sizeOfSelf >= sizeof(Underworld_SwarmOutput) );
+	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
+	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
+	   and so should be set to ZERO in any children of this class. */
+	nameAllocationType = NON_GLOBAL;
+
+	self = (Underworld_SwarmOutput*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
+
+	
+	/* General info */
+
+	/* Virtual Info */
+	
+	return self;
+}
+
+
+/*------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _Underworld_SwarmOutput_Delete( void* uwSwarmOutput ) {
+	Underworld_SwarmOutput* self = (Underworld_SwarmOutput*)uwSwarmOutput;
+
+	Memory_Free( self->feVariableList );
+	/* Delete parent */
+	_SwarmOutput_Delete( self );
+}
+
+
+void _Underworld_SwarmOutput_Print( void* uwSwarmOutput, Stream* stream ) {
+	Underworld_SwarmOutput* self = (Underworld_SwarmOutput*)uwSwarmOutput;
+	
+	/* Print parent */
+	_SwarmOutput_Print( self, stream );
+}
+
+void* _Underworld_SwarmOutput_Copy( const void* uwSwarmOutput, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	Underworld_SwarmOutput*	self = (Underworld_SwarmOutput*)uwSwarmOutput;
+	Underworld_SwarmOutput*	newUnderworld_SwarmOutput;
+	
+	newUnderworld_SwarmOutput = (Underworld_SwarmOutput*)_SwarmOutput_Copy( self, dest, deep, nameExt, ptrMap );
+	
+	return (void*)newUnderworld_SwarmOutput;
+}
+
+void* _Underworld_SwarmOutput_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Underworld_SwarmOutput);
+	Type                                                      type = Underworld_SwarmOutput_Type;
+	Stg_Class_DeleteFunction*                              _delete = _Underworld_SwarmOutput_Delete;
+	Stg_Class_PrintFunction*                                _print = _Underworld_SwarmOutput_Print;
+	Stg_Class_CopyFunction*                                  _copy = _Underworld_SwarmOutput_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_SwarmOutput_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Underworld_SwarmOutput_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _Underworld_SwarmOutput_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _Underworld_SwarmOutput_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _Underworld_SwarmOutput_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _Underworld_SwarmOutput_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*) _Underworld_SwarmOutput_New(  UNDERWORLD_SWARMOUTPUT_PASSARGS  );
+}
+
+void _Underworld_SwarmOutput_Init( Underworld_SwarmOutput* self,
+				PICelleratorContext*  context,
+				MaterialPointsSwarm*  materialSwarm,
+				unsigned int          listCount,
+				FeVariable**          feVariableList) {
+	self->materialSwarm = materialSwarm;
+	self->sizeList = listCount;
+	self->_getFeValuesFunc = _Underworld_SwarmOutput_GetFeVariableValues;
+	self->_printFunc = _Underworld_SwarmOutput_PrintStandardFormat;
+	self->feVariableList = feVariableList;
+
+	/* my Swarm output will run on the SaveClass EP - the same time as standard checkpointing */
+	EP_AppendClassHook( Context_GetEntryPoint( context, AbstractContext_EP_SaveClass ), _Underworld_SwarmOutput_Execute, self );
+}
+
+void _Underworld_SwarmOutput_AssignFromXML( void* uwSwarmOutput, Stg_ComponentFactory* cf, void* data ) {
+	Underworld_SwarmOutput*  self          = (Underworld_SwarmOutput*) uwSwarmOutput;
+
+	PICelleratorContext*    context;
+	MaterialPointsSwarm*    materialSwarm;
+	Dictionary*             dictionary = Dictionary_GetDictionary( cf->componentDict, self->name );
+	Dictionary_Entry_Value* list;
+	unsigned int            listCount, feVar_I;
+	char*                   varName;
+	Stream                  *errorStream = Journal_Register( Error_Type, (Name)"_Underworld_SwarmOutput_Construct"  );
+   FeVariable**            feVariableList;
+	
+	context      =  Stg_ComponentFactory_ConstructByName( cf, (Name)"context", PICelleratorContext, True, data ) ;
+	materialSwarm = (MaterialPointsSwarm* )Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Swarm", MaterialPointsSwarm, True, data  );
+	
+	/* Get all Swarms specified in input file, under swarms */
+	list = Dictionary_Get( dictionary, (Dictionary_Entry_Key)"FeVariables"  );
+	
+	Journal_Firewall(
+			list != NULL,
+			errorStream,
+			"Error in %s:\n"
+			"You must specify a list of fevariables to interpolate onto the swarm in your xml. Example:\n"
+			"<list name=\"FeVariables\">\n"
+				"\t<param>PressureField</param>\n"
+			"</list>\n", __func__ );
+	
+	listCount = Dictionary_Entry_Value_GetCount( list );
+
+   Journal_Firewall(
+			listCount != 0,
+			errorStream,
+			"Error in %s:\n"
+			"You have no FeVariables defined in the FeVariable list. At least one FeVariable must be included. Example:\n"
+			"<list name=\"FeVariables\">\n"
+				"\t<param>PressureField</param>\n"
+			"</list>\n", __func__ );
+	
+	/* Allocate the memory to store pointers to them */
+	feVariableList = Memory_Alloc_Array( FeVariable*, listCount, "List FeVariables" );
+
+	for( feVar_I = 0 ; feVar_I < listCount ; feVar_I++ ) {
+		varName = Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetElement( list, feVar_I ) );
+		feVariableList[ feVar_I ] = Stg_ComponentFactory_ConstructByName( cf, (Name)varName, FeVariable, True, data  );
+	}
+
+	_Underworld_SwarmOutput_Init( self,
+				 context,
+				 materialSwarm,
+				 listCount,
+				 feVariableList);
+
+}
+
+void _Underworld_SwarmOutput_Build( void* uwSwarmOutput, void* data ) {
+	Underworld_SwarmOutput*	self = (Underworld_SwarmOutput*) uwSwarmOutput;
+	unsigned int feVar_I, feVarNum;
+	
+	/* Build all StGermain based data structure this component uses */
+	feVarNum = self->sizeList;
+	for( feVar_I = 0 ; feVar_I < feVarNum; feVar_I++ ) 
+		Stg_Component_Build( self->feVariableList[feVar_I], data, False );
+
+	Stg_Component_Build( self->materialSwarm, data, False );
+}
+void _Underworld_SwarmOutput_Initialise( void* uwSwarmOutput, void* data ) {
+	Underworld_SwarmOutput*	self = (Underworld_SwarmOutput*) uwSwarmOutput;
+	unsigned int feVar_I, feVarNum;
+	
+	/* Initialise all StGermain based data structure this component uses */
+	feVarNum = self->sizeList;
+	for( feVar_I = 0 ; feVar_I < feVarNum; feVar_I++ ) 
+		Stg_Component_Initialise( self->feVariableList[feVar_I], data, False );
+
+	Stg_Component_Initialise( self->materialSwarm, data, False );
+}
+
+void _Underworld_SwarmOutput_Execute( void* uwSwarmOutput, void* data ) {
+	Underworld_SwarmOutput*	self = (Underworld_SwarmOutput*)uwSwarmOutput;
+	PICelleratorContext*    context = (PICelleratorContext*)data;
+	MaterialPointsSwarm*    materialSwarm;
+	FeVariable*             feVar;
+	char*                   filename;
+	char*                   outputPath = context->outputPath;
+	unsigned int            feVar_I, feVarNum, timeStep;
+
+	FILE*              outputFile;
+	MPI_Comm	   comm;
+	int                myRank;
+	int                nProcs;
+	MPI_Status         status;
+	const int          FINISHED_WRITING_TAG = 100;
+	int                canExecute = 0;
+
+	
+	timeStep = context->timeStep;
+	feVarNum = self->sizeList;
+	materialSwarm = self->materialSwarm;
+	
+	/* for each field create file and then write */
+	for( feVar_I = 0 ; feVar_I < feVarNum; feVar_I++ ) {
+		feVar = self->feVariableList[feVar_I];
+
+		comm = Comm_GetMPIComm( Mesh_GetCommTopology( feVar->feMesh, MT_VERTEX ) );
+
+		MPI_Comm_size( comm, (int*)&nProcs );
+		MPI_Comm_rank( comm, (int*)&myRank );
+
+		filename = Memory_Alloc_Array_Unnamed( char,
+		        /*           OutputPath     .      FieldName        .      SwarmName                . time . dat\0 */
+			       	strlen(outputPath) +1+ strlen(feVar->name) +1+ strlen(materialSwarm->name) +1+ 5 + 1+ 3 +1 );
+		sprintf( filename, "%s/%s.%s.%.5u.dat", outputPath, feVar->name, materialSwarm->name, timeStep );
+		/* wait for go-ahead from process ranked lower than me, to avoid competition writing to file */
+		if ( myRank != 0  && canExecute == 0 ) {
+			MPI_Recv( &canExecute, 1, MPI_INT, myRank - 1, FINISHED_WRITING_TAG, comm, &status );
+		}	
+
+		/* if myRank is 0, create or append file, otherwise append to file */
+		if (myRank == 0) {
+			/* append to file if restarting from checkpoint */
+			if( context->loadFromCheckPoint )
+				outputFile = fopen( filename, "a" );
+			else
+				outputFile = fopen( filename, "w" );
+			fprintf( outputFile, "# FORMAT is:\n# MaterialID, Xpos, Ypos, Zpos, (values of field)\n" );
+		} else {
+		       	outputFile = fopen( filename, "a" );
+		}
+
+		self->_getFeValuesFunc( self, feVar, materialSwarm, outputFile );
+		fclose( outputFile );
+	}
+
+	/* confirms this processor is finshed */
+	canExecute = 1;
+	/* send go-ahead from process ranked lower than me, to avoid competition writing to file */
+	if ( myRank != nProcs - 1 ) {
+		MPI_Ssend( &canExecute, 1, MPI_INT, myRank + 1, FINISHED_WRITING_TAG, comm );
+	}
+
+	Memory_Free( filename );
+}
+
+void _Underworld_SwarmOutput_Destroy( void* uwSwarmOutput, void* data ) {
+	Underworld_SwarmOutput*	self = (Underworld_SwarmOutput*)uwSwarmOutput;
+	unsigned int feVar_I, feVarNum;
+
+	/* Destroy all StGermain based data structure this component uses */
+	feVarNum = self->sizeList;	
+	for( feVar_I = 0 ; feVar_I < feVarNum; feVar_I++ ) 
+		Stg_Component_Destroy( self->feVariableList[feVar_I], data, False );
+
+	Stg_Component_Destroy( self->materialSwarm, data, False );
+	
+}
+
+void _Underworld_SwarmOutput_PrintStandardFormat( MaterialPoint* particle, double* result, unsigned fieldComponentCount, FILE* outputFile ) {
+		unsigned dof_I;
+		fprintf( outputFile, "%u ", particle->materialIndex );
+                fprintf( outputFile, "%.15g %.15g %.15g ", particle->coord[0], particle->coord[1], particle->coord[2] ); 
+		for ( dof_I = 0; dof_I < fieldComponentCount; dof_I++ ) 
+			fprintf( outputFile, "%.15g ", result[dof_I] );
+			
+		fprintf( outputFile, "\n" );
+}
+	
+void _Underworld_SwarmOutput_GetFeVariableValues(Underworld_SwarmOutput* uwSwarmOutput, FeVariable* feVariable, MaterialPointsSwarm* swarm, FILE* outputFile) {
+	Underworld_SwarmOutput*	self = (Underworld_SwarmOutput*)uwSwarmOutput;
+	MaterialPoint*          particle;
+	unsigned int            localElementCount, lElement_I; 
+	unsigned int            cellID, cellParticleCount, cParticle_I;
+	unsigned int            fieldComponentCount = feVariable->fieldComponentCount;
+	FeMesh*                 feMesh = feVariable->feMesh;
+	double*                 result = Memory_Alloc_Array( double, fieldComponentCount, "Answer to Life?" );
+
+	localElementCount = FeMesh_GetElementLocalSize( feMesh );
+
+	/* Loop over local elements in problem */
+	for( lElement_I = 0 ; lElement_I < localElementCount ; lElement_I++ ) {
+		cellID            = CellLayout_MapElementIdToCellId( swarm->cellLayout, lElement_I );
+		cellParticleCount = swarm->cellParticleCountTbl[ cellID ];
+
+		/* Loop over materialPoints in element */
+		for ( cParticle_I = 0 ; cParticle_I < cellParticleCount ; cParticle_I++ ) {
+			particle = (MaterialPoint*)Swarm_ParticleInCellAt( swarm, cellID, cParticle_I );
+			/* Interpolate field to particle location (is Global because it uses the
+			 * material Points Swarm, could be a bit slow ???*/
+			_FeVariable_InterpolateValueAt( feVariable, particle->coord, result );
+
+			self->_printFunc( particle, result, fieldComponentCount, outputFile );
+
+		}
+	}
+	Memory_Free( result );
+}
+
+/*-------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+/*---------------------------------------------------------------------------------------------------------------------
+** Entry Point Hooks
+*/
+
+/*-------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+
+
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/ViscosityField.c
--- a/Utils/src/ViscosityField.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,179 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Monash Cluster Computing, Australia
-** (C) 2003-2004 All Rights Reserved
-**
-** Primary Authors:
-** Robert Turnbull, MCC
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include <Underworld/Rheology/Rheology.h>
-
-#include "types.h"
-#include "ViscosityField.h"
-#include <assert.h>
-
-const Type ViscosityField_Type = "ViscosityField";
-
-ViscosityField* _ViscosityField_New(  VISCOSITYFIELD_DEFARGS  ) {
-	ViscosityField* self;
-	
-	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree.
-		At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
-	assert( _sizeOfSelf >= sizeof(ViscosityField) );
-	self = (ViscosityField*) _ParticleFeVariable_New(  PARTICLEFEVARIABLE_PASSARGS  );
-	
-	return self;
-}
-
-void _ViscosityField_Init( 
-	ViscosityField*		self,
-	ConstitutiveMatrix*	constitutiveMatrix,
-	Variable_Register*	variable_Register )
-{
-	/* Assign Pointers */
-	self->variable_Register = variable_Register;
-	self->constitutiveMatrix = constitutiveMatrix;
-	
-	/* Set pointers to swarm to be the same as the one on the constitutive matrix */
-	self->assemblyTerm->integrationSwarm = self->constitutiveMatrix->integrationSwarm;
-	self->massMatrixForceTerm->integrationSwarm = self->constitutiveMatrix->integrationSwarm;	
-}
-
-/* --- Virtual Function Implementations --- */
-void _ViscosityField_Delete( void* viscosityField ) {
-	ViscosityField* self = (ViscosityField*) viscosityField;
-
-	_FeVariable_Delete( self );
-}
-
-void _ViscosityField_Print( void* viscosityField, Stream* stream ) {
-	ViscosityField* self = (ViscosityField*) viscosityField;
-	
-	/* General info */
-	Journal_Printf( stream, "ViscosityField (ptr): %p\n", self );
-	
-	/* Print parent */
-	_FeVariable_Print( self, stream );
-	
-	/* ViscosityField info */
-	Journal_PrintPointer( stream, self->constitutiveMatrix );
-}
-
-
-void* _ViscosityField_Copy( const void* feVariable, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	ViscosityField*	self = (ViscosityField*)feVariable;
-	ViscosityField*	newViscosityField;
-	
-	newViscosityField = (ViscosityField*) _FeVariable_Copy( feVariable, dest, deep, nameExt, ptrMap );
-
-	newViscosityField->constitutiveMatrix = self->constitutiveMatrix;
-	
-	return (void*)newViscosityField;
-}
-
-void* _ViscosityField_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                       _sizeOfSelf = sizeof(ViscosityField);
-	Type                                                               type = ViscosityField_Type;
-	Stg_Class_DeleteFunction*                                       _delete = _ViscosityField_Delete;
-	Stg_Class_PrintFunction*                                         _print = _ViscosityField_Print;
-	Stg_Class_CopyFunction*                                           _copy = _ViscosityField_Copy;
-	Stg_Component_DefaultConstructorFunction*           _defaultConstructor = _ViscosityField_DefaultNew;
-	Stg_Component_ConstructFunction*                             _construct = _ViscosityField_AssignFromXML;
-	Stg_Component_BuildFunction*                                     _build = _ViscosityField_Build;
-	Stg_Component_InitialiseFunction*                           _initialise = _ViscosityField_Initialise;
-	Stg_Component_ExecuteFunction*                                 _execute = _ViscosityField_Execute;
-	Stg_Component_DestroyFunction*                                 _destroy = _ViscosityField_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 = _ViscosityField_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 = ZERO;
-	FieldVariable_GetValueFunction*   _getMaxGlobalFieldMagnitude = ZERO;
-	FeVariable_SyncShadowValuesFunc*            _syncShadowValues = ZERO;
-
-	return (void*) _ViscosityField_New(  VISCOSITYFIELD_PASSARGS  );
-}
-
-void _ViscosityField_AssignFromXML( void* viscosityField, Stg_ComponentFactory* cf, void* data ){
-	ViscosityField*		self = (ViscosityField*) viscosityField;
-	ConstitutiveMatrix*	constitutiveMatrix;
-	Variable_Register*	variable_Register;
-
-	/* Construct Parent */
-	_ParticleFeVariable_AssignFromXML( self, cf, data );
-
-	constitutiveMatrix = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"ConstitutiveMatrix", ConstitutiveMatrix, True, data );
-	variable_Register = self->context->variable_Register; 
-	assert( variable_Register  );
-
-	_ViscosityField_Init( self, constitutiveMatrix, variable_Register );
-}
-
-void _ViscosityField_Build( void* viscosityField, void* data ) {
-	ViscosityField* self = (ViscosityField*) viscosityField;
-	char*              tmpName;
-
-	Stg_Component_Build( self->feMesh, data, False );
-	Stg_Component_Build( self->constitutiveMatrix, data, False );
-
-	/* Create Dof Layout */
-	assert( Class_IsSuper( self->feMesh->topo, IGraph ) );
-	tmpName = Stg_Object_AppendSuffix( self, (Name)"viscosityVariable"  );
-	self->dataVariable = Variable_NewScalar( tmpName, (AbstractContext*)self->context, Variable_DataType_Double, (Index*)&((IGraph*)self->feMesh->topo)->remotes[MT_VERTEX]->nDomains, NULL, (void**)&self->data, self->variable_Register );
-	Memory_Free( tmpName  );
-	self->fieldComponentCount = 1;
-	
-	tmpName = Stg_Object_AppendSuffix( self, (Name)"viscosityDOF"  );
-	self->dofLayout = DofLayout_New( tmpName, self->context, self->variable_Register, 0, self->feMesh );
-	self->dofLayout->_numItemsInLayout = FeMesh_GetNodeDomainSize( self->feMesh );
-	DofLayout_AddAllFromVariableArray( self->dofLayout, 1, &self->dataVariable );
-	Memory_Free( tmpName );
-	self->eqNum->dofLayout = self->dofLayout;
-
-	_ParticleFeVariable_Build( self, data );
-}
-void _ViscosityField_Initialise( void* viscosityField, void* data ) {
-	ViscosityField* self = (ViscosityField*) viscosityField;
-
-   Stg_Component_Initialise( self->constitutiveMatrix, data, False );
-	_ParticleFeVariable_Initialise( self, data );
-}
-void _ViscosityField_Execute( void* viscosityField, void* data ) {
-	ViscosityField* self = (ViscosityField*) viscosityField;
-
-	_ParticleFeVariable_Execute( self, data );
-}
-void _ViscosityField_Destroy( void* viscosityField, void* data ) {
-	ViscosityField* self = (ViscosityField*) viscosityField;
-
-   Stg_Component_Destroy( self->constitutiveMatrix, data, False );
-
-	_ParticleFeVariable_Destroy( self, data );
-}
-void _ViscosityField_ValueAtParticle( void* viscosityField, IntegrationPointsSwarm* swarm, Element_LocalIndex lElement_I, void* _particle, double* viscosity ) {
-	ViscosityField*   self         = (ViscosityField*) viscosityField;
-	IntegrationPoint* particle     = (IntegrationPoint*) _particle;
-	
-	/* Calculate viscosity from constitutive matrix */
-	ConstitutiveMatrix_Assemble( self->constitutiveMatrix, lElement_I,
-                                     self->currentParticleIndex, particle );
-	*viscosity = ConstitutiveMatrix_GetIsotropicViscosity( self->constitutiveMatrix );
-}
-
-
-
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/ViscosityField.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/ViscosityField.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,179 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Monash Cluster Computing, Australia
+** (C) 2003-2004 All Rights Reserved
+**
+** Primary Authors:
+** Robert Turnbull, MCC
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include <Underworld/Rheology/Rheology.h>
+
+#include "types.h"
+#include "ViscosityField.h"
+#include <assert.h>
+
+const Type ViscosityField_Type = "ViscosityField";
+
+ViscosityField* _ViscosityField_New(  VISCOSITYFIELD_DEFARGS  ) {
+	ViscosityField* self;
+	
+	/* Call private constructor of parent - this will set virtual functions of parent and continue up the hierarchy tree.
+		At the beginning of the tree it will allocate memory of the size of object and initialise all the memory to zero. */
+	assert( _sizeOfSelf >= sizeof(ViscosityField) );
+	self = (ViscosityField*) _ParticleFeVariable_New(  PARTICLEFEVARIABLE_PASSARGS  );
+	
+	return self;
+}
+
+void _ViscosityField_Init( 
+	ViscosityField*		self,
+	ConstitutiveMatrix*	constitutiveMatrix,
+	Variable_Register*	variable_Register )
+{
+	/* Assign Pointers */
+	self->variable_Register = variable_Register;
+	self->constitutiveMatrix = constitutiveMatrix;
+	
+	/* Set pointers to swarm to be the same as the one on the constitutive matrix */
+	self->assemblyTerm->integrationSwarm = self->constitutiveMatrix->integrationSwarm;
+	self->massMatrixForceTerm->integrationSwarm = self->constitutiveMatrix->integrationSwarm;	
+}
+
+/* --- Virtual Function Implementations --- */
+void _ViscosityField_Delete( void* viscosityField ) {
+	ViscosityField* self = (ViscosityField*) viscosityField;
+
+	_FeVariable_Delete( self );
+}
+
+void _ViscosityField_Print( void* viscosityField, Stream* stream ) {
+	ViscosityField* self = (ViscosityField*) viscosityField;
+	
+	/* General info */
+	Journal_Printf( stream, "ViscosityField (ptr): %p\n", self );
+	
+	/* Print parent */
+	_FeVariable_Print( self, stream );
+	
+	/* ViscosityField info */
+	Journal_PrintPointer( stream, self->constitutiveMatrix );
+}
+
+
+void* _ViscosityField_Copy( const void* feVariable, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	ViscosityField*	self = (ViscosityField*)feVariable;
+	ViscosityField*	newViscosityField;
+	
+	newViscosityField = (ViscosityField*) _FeVariable_Copy( feVariable, dest, deep, nameExt, ptrMap );
+
+	newViscosityField->constitutiveMatrix = self->constitutiveMatrix;
+	
+	return (void*)newViscosityField;
+}
+
+void* _ViscosityField_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                       _sizeOfSelf = sizeof(ViscosityField);
+	Type                                                               type = ViscosityField_Type;
+	Stg_Class_DeleteFunction*                                       _delete = _ViscosityField_Delete;
+	Stg_Class_PrintFunction*                                         _print = _ViscosityField_Print;
+	Stg_Class_CopyFunction*                                           _copy = _ViscosityField_Copy;
+	Stg_Component_DefaultConstructorFunction*           _defaultConstructor = _ViscosityField_DefaultNew;
+	Stg_Component_ConstructFunction*                             _construct = _ViscosityField_AssignFromXML;
+	Stg_Component_BuildFunction*                                     _build = _ViscosityField_Build;
+	Stg_Component_InitialiseFunction*                           _initialise = _ViscosityField_Initialise;
+	Stg_Component_ExecuteFunction*                                 _execute = _ViscosityField_Execute;
+	Stg_Component_DestroyFunction*                                 _destroy = _ViscosityField_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 = _ViscosityField_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 = ZERO;
+	FieldVariable_GetValueFunction*   _getMaxGlobalFieldMagnitude = ZERO;
+	FeVariable_SyncShadowValuesFunc*            _syncShadowValues = ZERO;
+
+	return (void*) _ViscosityField_New(  VISCOSITYFIELD_PASSARGS  );
+}
+
+void _ViscosityField_AssignFromXML( void* viscosityField, Stg_ComponentFactory* cf, void* data ){
+	ViscosityField*		self = (ViscosityField*) viscosityField;
+	ConstitutiveMatrix*	constitutiveMatrix;
+	Variable_Register*	variable_Register;
+
+	/* Construct Parent */
+	_ParticleFeVariable_AssignFromXML( self, cf, data );
+
+	constitutiveMatrix = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"ConstitutiveMatrix", ConstitutiveMatrix, True, data );
+	variable_Register = self->context->variable_Register; 
+	assert( variable_Register  );
+
+	_ViscosityField_Init( self, constitutiveMatrix, variable_Register );
+}
+
+void _ViscosityField_Build( void* viscosityField, void* data ) {
+	ViscosityField* self = (ViscosityField*) viscosityField;
+	char*              tmpName;
+
+	Stg_Component_Build( self->feMesh, data, False );
+	Stg_Component_Build( self->constitutiveMatrix, data, False );
+
+	/* Create Dof Layout */
+	assert( Class_IsSuper( self->feMesh->topo, IGraph ) );
+	tmpName = Stg_Object_AppendSuffix( self, (Name)"viscosityVariable"  );
+	self->dataVariable = Variable_NewScalar( tmpName, (AbstractContext*)self->context, Variable_DataType_Double, (Index*)&((IGraph*)self->feMesh->topo)->remotes[MT_VERTEX]->nDomains, NULL, (void**)&self->data, self->variable_Register );
+	Memory_Free( tmpName  );
+	self->fieldComponentCount = 1;
+	
+	tmpName = Stg_Object_AppendSuffix( self, (Name)"viscosityDOF"  );
+	self->dofLayout = DofLayout_New( tmpName, self->context, self->variable_Register, 0, self->feMesh );
+	self->dofLayout->_numItemsInLayout = FeMesh_GetNodeDomainSize( self->feMesh );
+	DofLayout_AddAllFromVariableArray( self->dofLayout, 1, &self->dataVariable );
+	Memory_Free( tmpName );
+	self->eqNum->dofLayout = self->dofLayout;
+
+	_ParticleFeVariable_Build( self, data );
+}
+void _ViscosityField_Initialise( void* viscosityField, void* data ) {
+	ViscosityField* self = (ViscosityField*) viscosityField;
+
+   Stg_Component_Initialise( self->constitutiveMatrix, data, False );
+	_ParticleFeVariable_Initialise( self, data );
+}
+void _ViscosityField_Execute( void* viscosityField, void* data ) {
+	ViscosityField* self = (ViscosityField*) viscosityField;
+
+	_ParticleFeVariable_Execute( self, data );
+}
+void _ViscosityField_Destroy( void* viscosityField, void* data ) {
+	ViscosityField* self = (ViscosityField*) viscosityField;
+
+   Stg_Component_Destroy( self->constitutiveMatrix, data, False );
+
+	_ParticleFeVariable_Destroy( self, data );
+}
+void _ViscosityField_ValueAtParticle( void* viscosityField, IntegrationPointsSwarm* swarm, Element_LocalIndex lElement_I, void* _particle, double* viscosity ) {
+	ViscosityField*   self         = (ViscosityField*) viscosityField;
+	IntegrationPoint* particle     = (IntegrationPoint*) _particle;
+	
+	/* Calculate viscosity from constitutive matrix */
+	ConstitutiveMatrix_Assemble( self->constitutiveMatrix, lElement_I,
+                                     self->currentParticleIndex, particle );
+	*viscosity = ConstitutiveMatrix_GetIsotropicViscosity( self->constitutiveMatrix );
+}
+
+
+
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/Wall.c
--- a/Utils/src/Wall.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include "types.h"
-
-Name WallEnumToStr[Wall_Size] = {
-       "back",
-       "left",
-       "bottom",
-       "right",
-       "top",
-       "front" };
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/Wall.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/Wall.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,14 @@
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include "types.h"
+
+Name WallEnumToStr[Wall_Size] = {
+       "back",
+       "left",
+       "bottom",
+       "right",
+       "top",
+       "front" };
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/XDMFGenerator.c
--- a/Utils/src/XDMFGenerator.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,506 +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: $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Underworld.h>
-
-#include "XDMFGenerator.h"
-
-#include <stdlib.h>
-#include <string.h>
-
-#ifndef MASTER
-	#define MASTER 0
-#endif
-
-const Type XDMFGenerator_Type = "XDMFGenerator";
-
-void XDMFGenerator_GenerateAll( void* _context ) {
-   UnderworldContext*   context    = (UnderworldContext*)_context;
-   Stream*              stream;
-
-   /** only the MASTER process writes to the file.  other processes send information to the MASTER where required **/   
-   if(context->rank == MASTER) {
-      Bool                 fileOpened;
-      Stream*              errorStream  = Journal_Register( Error_Type, (Name)CURR_MODULE_NAME  );
-      char*                 filename;
-      char*                outputPathString;
-
-      /** Create Stream **/
-      stream = Journal_Register( InfoStream_Type, (Name)"XDMFOutputFile"  );
-   
-      /** Set auto flush on stream **/
-      Stream_SetAutoFlush( stream, True );
-
-		outputPathString = Context_GetCheckPointWritePrefixString( context );
-   
-      /** Get name of XDMF schema file **/
-      Stg_asprintf( &filename, "%s/XDMF.%05d.xmf", outputPathString, context->timeStep );
-   
-      /** Init file, always overwriting any existing **/
-      fileOpened = Stream_RedirectFile( stream, filename );
-      Journal_Firewall( fileOpened, errorStream, 
-            "Could not open file %s. Possibly directory %s does not exist or is not writable.\n"
-            "Check 'checkpointWritePath' in input file.\n", filename, outputPathString );
-      Memory_Free( filename );
-      Memory_Free( outputPathString );
-      
-      /** write header information **/
-      _XDMFGenerator_WriteHeader( context, stream );
-
-      /** Write all (checkpointed) FeVariable field information  **/
-      _XDMFGenerator_WriteFieldSchema( context, stream );
-
-      /** Write all (checkpointed) FeVariable field information  **/
-      if ( (context->timeStep % context->checkpointEvery == 0) || 
-           (context->checkpointAtTimeInc && (context->currentTime >= context->nextCheckpointTime)) ) _XDMFGenerator_WriteSwarmSchema( context, stream);
-
-      /** writes footer information and close file/stream **/
-      _XDMFGenerator_WriteFooter( context, stream );
-
-      /** close the file **/
-      Stream_CloseFile( stream );	
-
-   } else {
-      /** other process send information about swarms populations to MASTER **/
-      _XDMFGenerator_SendInfo( context );
-   }
-
-}
-
-void _XDMFGenerator_WriteFieldSchema( UnderworldContext* context, Stream* stream ) {
-   FieldVariable*       fieldVar = NULL;
-   FeVariable*          feVar    = NULL;
-   Mesh*                mesh     = NULL;
-   FeMesh*              feMesh   = NULL;
-   unsigned             nDims;
-   unsigned             totalVerts;
-   Index                maxNodes;
-   Index                elementGlobalSize;
-   Element_GlobalIndex  gElement_I;
-	Index                var_I = 0;
-   Bool                 saveCoords  = Dictionary_GetBool_WithDefault( context->dictionary, (Dictionary_Entry_Key)"saveCoordsWithFields", False  );
-   Stream*              errorStream = Journal_Register( Error_Type, (Name)CURR_MODULE_NAME );
-   char*                variableType = NULL;
-   char*                topologyType = NULL;
-   unsigned             componentCount = LiveComponentRegister_GetCount(stgLiveComponentRegister);
-   unsigned             compI;
-   Stg_Component*       stgComp;
-
-   /** search for entire live component register for feMesh types  **/
-   for( compI = 0 ; compI < componentCount ; compI++ ){
-      stgComp = LiveComponentRegister_At( stgLiveComponentRegister, compI );
-      /* check that component is of type FeMesh, and that its element family is linear */
-      if ( Stg_Class_IsInstance( stgComp, FeMesh_Type ) && !strcmp( ((FeMesh*)stgComp)->feElFamily, "linear" ) ) {
-         mesh   = (  Mesh*)stgComp;
-         feMesh = (FeMesh*)stgComp;
-
-         nDims             = Mesh_GetDimSize( mesh );
-         totalVerts        = Mesh_GetGlobalSize( mesh, (MeshTopology_Dim)0 );
-         elementGlobalSize = FeMesh_GetElementGlobalSize(mesh);
-
-         /* get connectivity array size */
-         if (mesh->nElTypes == 1)
-            maxNodes = FeMesh_GetElementNodeSize( mesh, 0);
-         else {
-            /* determine the maximum number of nodes each element has */
-            maxNodes = 0;
-            for ( gElement_I = 0 ; gElement_I < FeMesh_GetElementGlobalSize(mesh); gElement_I++ ) {
-               unsigned numNodes;
-               numNodes = FeMesh_GetElementNodeSize( mesh, gElement_I);
-               if( maxNodes < numNodes ) maxNodes = numNodes;
-            }
-         }
-         /** now write all the xdmf geometry info **/
-         /**----------------------- START GEOMETRY   ------------------------------------------------------------------------------------------------------------------- **/
-         if(         maxNodes == 4 ){
-            Stg_asprintf( &topologyType, "Quadrilateral" );
-         } else if ( maxNodes == 8  ) {
-            Stg_asprintf( &topologyType, "Hexahedron" );
-         } else {
-            Journal_DPrintf( errorStream, "\n\n Error: number of element nodes %u not supported by XDMF generator...\n should be 4 (2D quadrilateral) " 
-                                    "or should be 8 (3D hexahedron). \n\n", maxNodes );
-            Stg_asprintf( &topologyType, "UNKNOWN_POSSIBLY_ERROR" );
-         }
-         /** first create the grid which is applicable to the checkpointed fevariables **/
-                                 Journal_Printf( stream, "   <Grid Name=\"FEM_Grid_%s\">\n\n", feMesh->name);
-                                 Journal_Printf( stream, "      <Time Value=\"%f\" />\n\n", context->currentTime );
-         /** now print out topology info, only quadrilateral elements are supported at the moment **/
-                                 Journal_Printf( stream, "         <Topology Type=\"%s\" NumberOfElements=\"%u\"> \n", topologyType, elementGlobalSize );
-                                 Journal_Printf( stream, "            <DataItem Format=\"HDF\" DataType=\"Int\"  Dimensions=\"%u %u\">Mesh.%s.%05d.h5:/connectivity</DataItem>\n", elementGlobalSize, maxNodes, feMesh->name, context->timeStep );
-                                 Journal_Printf( stream, "         </Topology>\n\n" );
-                                 Journal_Printf( stream, "         <Geometry Type=\"XYZ\">\n" );
-
-         Stg_asprintf( &variableType, "NumberType=\"Float\" Precision=\"8\"" );                              
-         if(         nDims == 2 ){
-            /** note that for 2d, we feed back a quasi 3d array, with the 3rd Dof zeroed.  so in effect we always work in 3d.
-                this is done because paraview in particular seems to do everything in 3d, and if you try and give it a 2d vector 
-                or array, it complains.... and hence the verbosity of the following 2d definitions**/
-                                 Journal_Printf( stream, "            <DataItem ItemType=\"Function\"  Dimensions=\"%u 3\" Function=\"JOIN($0, $1, 0*$1)\">\n", totalVerts );
-                                 Journal_Printf( stream, "               <DataItem ItemType=\"HyperSlab\" Dimensions=\"%u 1\" Name=\"XCoords\">\n", totalVerts );
-                                 Journal_Printf( stream, "                  <DataItem Dimensions=\"3 2\" Format=\"XML\"> 0 0 1 1 %u 1 </DataItem>\n", totalVerts );
-                                 Journal_Printf( stream, "                  <DataItem Format=\"HDF\" %s Dimensions=\"%u 2\">Mesh.%s.%05d.h5:/vertices</DataItem>\n", variableType, totalVerts, feMesh->name,  context->timeStep );
-                                 Journal_Printf( stream, "               </DataItem>\n" );
-                                 Journal_Printf( stream, "               <DataItem ItemType=\"HyperSlab\" Dimensions=\"%u 1\" Name=\"YCoords\">\n", totalVerts );
-                                 Journal_Printf( stream, "                  <DataItem Dimensions=\"3 2\" Format=\"XML\"> 0 1 1 1 %u 1 </DataItem>\n", totalVerts );
-                                 Journal_Printf( stream, "                  <DataItem Format=\"HDF\" %s Dimensions=\"%u 2\">Mesh.%s.%05d.h5:/vertices</DataItem>\n", variableType, totalVerts, feMesh->name, context->timeStep );
-                                 Journal_Printf( stream, "               </DataItem>\n" );
-                                 Journal_Printf( stream, "            </DataItem>\n" );
-         } else if ( nDims == 3 ) {
-            /** in 3d we simply feed back the 3d hdf5 array, nice and easy **/
-                                 Journal_Printf( stream, "            <DataItem Format=\"HDF\" %s Dimensions=\"%u 3\">Mesh.%s.%05d.h5:/vertices</DataItem>\n", variableType, totalVerts, feMesh->name, context->timeStep );
-         } else {
-            Journal_DPrintf( errorStream, "\n\n Error: Mesh vertex location is not of dofCount 2 or 3.\n\n" );
-         }
-                                 Journal_Printf( stream, "         </Geometry>\n\n" );
-         /**----------------------- FINISH GEOMETRY  ------------------------------------------------------------------------------------------------------------------- **/
-
-
-      /** now write FeVariable data **/   
-      for ( var_I = 0; var_I < context->fieldVariable_Register->objects->count; var_I++ ) {
-         fieldVar = FieldVariable_Register_GetByIndex( context->fieldVariable_Register, var_I );
-
-         if ( Stg_Class_IsInstance( fieldVar, FeVariable_Type ) ) {
-            feVar = (FeVariable*)fieldVar;
-            if ( (feVar->isCheckpointedAndReloaded && (context->timeStep % context->checkpointEvery == 0))                                     || 
-                 (feVar->isCheckpointedAndReloaded && (context->checkpointAtTimeInc && (context->currentTime >= context->nextCheckpointTime))) ||
-                 (feVar->isSavedData               && (context->timeStep % context->saveDataEvery   == 0)) ){
-               FeMesh* feVarMesh = NULL;
-               /** check what type of generator was used to know where elementMesh is **/
-               if( Stg_Class_IsInstance( feVar->feMesh->generator, C0Generator_Type))        feVarMesh = (FeMesh*)(((C0Generator*)feVar->feMesh->generator)->elMesh);
-               if( Stg_Class_IsInstance( feVar->feMesh->generator, CartesianGenerator_Type)) feVarMesh = feVar->feMesh;
-               if( Stg_Class_IsInstance( feVar->feMesh->generator, MeshAdaptor_Type))        feVarMesh = feVar->feMesh;
-               /** make sure that the fevariable femesh is the same as that used above for the geometry definition, if so proceed **/
-               if( feVarMesh == feMesh ){
-                 char*   centering = NULL;
-                     Index  offset = 0;
-                     Index  meshSize = Mesh_GetGlobalSize( feVar->feMesh, (MeshTopology_Dim)0 );
-                     Index  dofCountIndex;
-                     Index  dofAtEachNodeCount;
-
-               /**----------------------- START ATTRIBUTES ------------------------------------------------------------------------------------------------------------------- **/
-                     /** if coordinates are being stored with feVariable, account for this **/
-                     if( saveCoords) offset = nDims; 
-                     /** all feVariables are currently stored as doubles **/
-                     Stg_asprintf( &variableType, "NumberType=\"Float\" Precision=\"8\"" );
-                     /** determine whether feVariable data is cell centered (like Pressure), or on the nodes (like Velocity) **/
-                     if(        meshSize == elementGlobalSize ){
-                        Stg_asprintf( &centering, "Cell" );
-                     } else if( meshSize == totalVerts ) {
-                        Stg_asprintf( &centering, "Node" );
-                     } else {
-                        /* unknown/unsupported type */
-                        Stg_asprintf( &centering, "UNKNOWN_POSSIBLY_ERROR" );
-                     }
-                     /** how many degrees of freedom does the fevariable have? **/
-                     dofAtEachNodeCount = feVar->fieldComponentCount;
-                     if (        dofAtEachNodeCount == 1 ) {
-                                 Journal_Printf( stream, "         <Attribute Type=\"Scalar\" Center=\"%s\" Name=\"%s\">\n", centering,  feVar->name);
-                                 Journal_Printf( stream, "            <DataItem ItemType=\"HyperSlab\" Dimensions=\"%u 1\" >\n", meshSize );
-                                 Journal_Printf( stream, "               <DataItem Dimensions=\"3 2\" Format=\"XML\"> 0 %u 1 1 %u 1 </DataItem>\n", offset, meshSize );
-                                 Journal_Printf( stream, "               <DataItem Format=\"HDF\" %s Dimensions=\"%u %u\">%s.%05d.h5:/data</DataItem>\n", variableType, meshSize, (offset + dofAtEachNodeCount), feVar->name, context->timeStep);
-                                 Journal_Printf( stream, "            </DataItem>\n" );
-                                 Journal_Printf( stream, "         </Attribute>\n\n" );
-                     } else if ( dofAtEachNodeCount == 2 ){
-                        /** note that for 2d, we feed back a quasi 3d array, with the 3rd Dof zeroed.  so in effect we always work in 3d.
-                            this is done because paraview in particular seems to do everything in 3d, and if you try and give it a 2d vector 
-                            or array, it complains.... and hence the verbosity of the following 2d definitions **/
-                                 Journal_Printf( stream, "         <Attribute Type=\"Vector\" Center=\"%s\" Name=\"%s\">\n", centering,  feVar->name);
-                                 Journal_Printf( stream, "            <DataItem ItemType=\"Function\"  Dimensions=\"%u 3\" Function=\"JOIN($0, $1, 0*$1)\">\n", meshSize );
-                                 Journal_Printf( stream, "               <DataItem ItemType=\"HyperSlab\" Dimensions=\"%u 1\" Name=\"XValue\">\n", meshSize );
-                                 Journal_Printf( stream, "                  <DataItem Dimensions=\"3 2\" Format=\"XML\"> 0 %u 1 1 %u 1 </DataItem>\n", offset, meshSize );
-                                 Journal_Printf( stream, "                  <DataItem Format=\"HDF\" %s Dimensions=\"%u %u\">%s.%05d.h5:/data</DataItem>\n", variableType, meshSize, (offset + dofAtEachNodeCount), feVar->name, context->timeStep);
-                                 Journal_Printf( stream, "               </DataItem>\n" );
-                                 Journal_Printf( stream, "               <DataItem ItemType=\"HyperSlab\" Dimensions=\"%u 1\" Name=\"YValue\">\n", meshSize );
-                                 Journal_Printf( stream, "                  <DataItem Dimensions=\"3 2\" Format=\"XML\"> 0 %u 1 1 %u 1 </DataItem>\n", (offset+1), meshSize );
-                                 Journal_Printf( stream, "                  <DataItem Format=\"HDF\" %s Dimensions=\"%u %u\">%s.%05d.h5:/data</DataItem>\n", variableType, meshSize, (offset + dofAtEachNodeCount), feVar->name, context->timeStep);
-                                 Journal_Printf( stream, "               </DataItem>\n" );
-                                 Journal_Printf( stream, "            </DataItem>\n" );
-                                 Journal_Printf( stream, "         </Attribute>\n\n" );
-                     } else if ( dofAtEachNodeCount == 3 ) {
-                        /** in 3d we simply feed back the 3d hdf5 array, nice and easy **/
-                                 Journal_Printf( stream, "         <Attribute Type=\"Vector\" Center=\"%s\" Name=\"%s\">\n", centering,  feVar->name);
-                                 Journal_Printf( stream, "            <DataItem ItemType=\"HyperSlab\" Dimensions=\"%u 3\" >\n", meshSize );
-                                 Journal_Printf( stream, "               <DataItem Dimensions=\"3 2\" Format=\"XML\"> 0 %u 1 1 %u 3 </DataItem>\n", offset, meshSize );
-                                 Journal_Printf( stream, "               <DataItem Format=\"HDF\" %s Dimensions=\"%u %u\">%s.%05d.h5:/data</DataItem>\n", variableType, meshSize, (offset + dofAtEachNodeCount), feVar->name, context->timeStep);
-                                 Journal_Printf( stream, "            </DataItem>\n" );
-                                 Journal_Printf( stream, "         </Attribute>\n\n" );
-                     } else {
-                        /** where there are more than 3 components, we write each one out as a scalar **/
-                        for(dofCountIndex = 0 ; dofCountIndex < dofAtEachNodeCount ; ++dofCountIndex){
-                                 Journal_Printf( stream, "         <Attribute Type=\"Scalar\" Center=\"%s\" Name=\"%s-Component-%u\">\n", centering,  feVar->name, dofCountIndex);
-                                 Journal_Printf( stream, "            <DataItem ItemType=\"HyperSlab\" Dimensions=\"%u 1\" >\n", meshSize );
-                                 Journal_Printf( stream, "               <DataItem Dimensions=\"3 2\" Format=\"XML\"> 0 %u 1 1 %u 1 </DataItem>\n", (offset+dofCountIndex), meshSize );
-                                 Journal_Printf( stream, "               <DataItem Format=\"HDF\" %s Dimensions=\"%u %u\">%s.%05d.h5:/data</DataItem>\n", variableType, meshSize, (offset + dofAtEachNodeCount), feVar->name, context->timeStep);
-                                 Journal_Printf( stream, "            </DataItem>\n" );
-                                 Journal_Printf( stream, "         </Attribute>\n" );
-                        }
-                                 Journal_Printf( stream, "\n" );
-                     }
-               /**----------------------- END ATTRIBUTES   ------------------------------------------------------------------------------------------------------------------- **/
-               if(centering) Memory_Free( centering );
-               }
-               }
-         }
-      }
-                                 Journal_Printf( stream, "   </Grid>\n\n" );
-      if(variableType) Memory_Free( variableType );
-      if(topologyType) Memory_Free( topologyType );
-      }
-   }
-}
-
-void _XDMFGenerator_WriteSwarmSchema( UnderworldContext* context, Stream* stream ) {
-   Swarm_Register* swarmRegister = Swarm_Register_GetSwarm_Register();
-   Index           swarmCount;
-   Index           swarmcountindex;
-   Index           variablecount;
-   Index           dofCountIndex;
-   Index           swarmParticleLocalCount;
-   Index           countindex;
-   Index           ii;
-   Swarm*          currentSwarm;
-   SwarmVariable*  swarmVar;
-   char*           swarmVarName;
-   char*           variableType = NULL;
-   char*           filename_part = NULL;
-   Stream*         errorStream  = Journal_Register( Error_Type, (Name)CURR_MODULE_NAME  );
-	const int       FINISHED_WRITING_TAG = 100;
-	MPI_Status      status;
-   
-   /** get total number of different swarms **/
-   swarmCount  = swarmRegister->swarmList->count;
-   
-   /** parse swarm list, checking which are actually stored to HDF5.  **/
-   /** We assume that all processes have the same number of swarms on them, with the same swarms checkpointed**/
-   for(swarmcountindex = 0; swarmcountindex < swarmCount; ++swarmcountindex){
-      currentSwarm  = Swarm_Register_At( swarmRegister, swarmcountindex );
-
-      if ( currentSwarm->isSwarmTypeToCheckPointAndReload != True ) 
-         continue;
-
-      swarmParticleLocalCount = currentSwarm->particleLocalCount;
-      /** first create a grid collection which will contain the collection of swarms from each process. 
-          there will be one of these collections for each swarm (not swarmvariable) that is checkpointed **/
-                              Journal_Printf( stream, "   <Grid Name=\"%s\" GridType=\"Collection\">\n\n", currentSwarm->name );
-                              Journal_Printf( stream, "      <Time Value=\"%f\" />\n\n", context->currentTime );
-
-      Stg_asprintf( &filename_part, "" );
-      for (ii = 0 ; ii < context->nproc ; ++ii) {
-
-         /** get the number of particles in each swarm from each process **/
-         if (ii != MASTER        ) MPI_Recv( &swarmParticleLocalCount, 1, MPI_INT, ii, FINISHED_WRITING_TAG, context->communicator, &status );
-         if (context->nproc != 1 ) Stg_asprintf( &filename_part, ".%uof%u", (ii + 1), context->nproc );
-         
-         /** first write all the MASTER procs swarm info **/
-         if (swarmParticleLocalCount != 0) {
-                              Journal_Printf( stream, "      <Grid Name=\"%s_proc_%u\">\n\n", currentSwarm->name, ii );
-            
-            /** now write all the xdmf geometry info **/
-            /**----------------------- START GEOMETRY   ------------------------------------------------------------------------------------------------------------------- **/
-                              Journal_Printf( stream, "         <Topology Type=\"POLYVERTEX\" NodesPerElement=\"%u\"> </Topology>\n", swarmParticleLocalCount );
-                              Journal_Printf( stream, "         <Geometry Type=\"XYZ\">\n" );
-            Stg_asprintf( &swarmVarName, "%s-Position", currentSwarm->name );
-            swarmVar = SwarmVariable_Register_GetByName( currentSwarm->swarmVariable_Register, swarmVarName );
-            if (!swarmVar) 
-               Journal_DPrintf( errorStream, "\n\n Error: Could not find required Position SwarmVariable. \n\n" );
-            Memory_Free( swarmVarName );
-            
-            /** check what precision it Position variable is stored at **/
-            if(        swarmVar->variable->dataTypes[0] == Variable_DataType_Int ){
-               Journal_DPrintf( errorStream, "\n\n Error: Position variable can not be of type Int. \n\n" );
-            } else if ( swarmVar->variable->dataTypes[0] == Variable_DataType_Char){
-               Journal_DPrintf( errorStream, "\n\n Error: Position variable can not be of type Char. \n\n" );
-            } else if ( swarmVar->variable->dataTypes[0] == Variable_DataType_Float ){
-               Stg_asprintf( &variableType, "NumberType=\"Float\" Precision=\"4\"" );
-            } else {
-               Stg_asprintf( &variableType, "NumberType=\"Float\" Precision=\"8\"" );
-            }
-           
-            if(         swarmVar->dofCount == 2 ){
-               /** note that for 2d, we feed back a quasi 3d array, with the 3rd Dof zeroed.  so in effect we always work in 3d.
-                   this is done because paraview in particular seems to do everything in 3d, and if you try and give it a 2d vector 
-                   or array, it complains.... and hence the verbosity of the following 2d definitions**/
-                              Journal_Printf( stream, "            <DataItem ItemType=\"Function\"  Dimensions=\"%u 3\" Function=\"JOIN($0, $1, 0*$1)\">\n", swarmParticleLocalCount );
-                              Journal_Printf( stream, "               <DataItem ItemType=\"HyperSlab\" Dimensions=\"%u 1\" Name=\"XCoords\">\n", swarmParticleLocalCount );
-                              Journal_Printf( stream, "                  <DataItem Dimensions=\"3 2\" Format=\"XML\"> 0 0 1 1 %u 1 </DataItem>\n", swarmParticleLocalCount );
-                              Journal_Printf( stream, "                  <DataItem Format=\"HDF\" %s Dimensions=\"%u 2\">%s.%05d%s.h5:/Position</DataItem>\n", variableType, swarmParticleLocalCount, currentSwarm->name, context->timeStep, filename_part );
-                              Journal_Printf( stream, "               </DataItem>\n" );
-                              Journal_Printf( stream, "               <DataItem ItemType=\"HyperSlab\" Dimensions=\"%u 1\" Name=\"YCoords\">\n", swarmParticleLocalCount );
-                              Journal_Printf( stream, "                  <DataItem Dimensions=\"3 2\" Format=\"XML\"> 0 1 1 1 %u 1 </DataItem>\n", swarmParticleLocalCount );
-                              Journal_Printf( stream, "                  <DataItem Format=\"HDF\" %s Dimensions=\"%u 2\">%s.%05d%s.h5:/Position</DataItem>\n", variableType, swarmParticleLocalCount, currentSwarm->name, context->timeStep, filename_part );
-                              Journal_Printf( stream, "               </DataItem>\n" );
-                              Journal_Printf( stream, "            </DataItem>\n" );
-            } else if ( swarmVar->dofCount == 3 ) {
-               /** in 3d we simply feed back the 3d hdf5 array, nice and easy **/
-                              Journal_Printf( stream, "            <DataItem Format=\"HDF\" %s Dimensions=\"%u 3\">%s.%05d%s.h5:/Position</DataItem>\n", variableType, swarmParticleLocalCount, currentSwarm->name, context->timeStep, filename_part );
-            } else {
-               Journal_DPrintf( errorStream, "\n\n Error: Position SwarmVariable is not of dofCount 2 or 3.\n\n" );
-            }
-                              Journal_Printf( stream, "         </Geometry>\n\n" );
-            /**----------------------- FINISH GEOMETRY  ------------------------------------------------------------------------------------------------------------------- **/
-   
-            
-            /** now write all the swarm attributes.. ie all the checkpointed swarmVariables **/
-            
-            variablecount = currentSwarm->swarmVariable_Register->objects->count;
-            for(countindex = 0; countindex < variablecount; ++countindex){
-               swarmVar = SwarmVariable_Register_GetByIndex( currentSwarm->swarmVariable_Register, countindex );
-               if( swarmVar->isCheckpointedAndReloaded ) {
-            /**----------------------- START ATTRIBUTES ------------------------------------------------------------------------------------------------------------------- **/
-                  if(         swarmVar->variable->dataTypes[0] == Variable_DataType_Int ){
-                     Stg_asprintf( &variableType, "NumberType=\"Int\"" );
-                  } else if ( swarmVar->variable->dataTypes[0] == Variable_DataType_Char){
-                     Stg_asprintf( &variableType, "NumberType=\"Char\"" );
-                  } else if ( swarmVar->variable->dataTypes[0] == Variable_DataType_Float ){
-                     Stg_asprintf( &variableType, "NumberType=\"Float\" Precision=\"4\"" );
-                  } else {
-                     Stg_asprintf( &variableType, "NumberType=\"Float\" Precision=\"8\"" );
-                  }
-                  if (        swarmVar->dofCount == 1 ) {
-                              Journal_Printf( stream, "         <Attribute Type=\"Scalar\" Center=\"Node\" Name=\"%s\">\n", swarmVar->name);
-                              Journal_Printf( stream, "            <DataItem Format=\"HDF\" %s Dimensions=\"%u 1\">%s.%05d%s.h5:/%s</DataItem>\n", variableType, swarmParticleLocalCount, currentSwarm->name, context->timeStep, filename_part, swarmVar->name + strlen(currentSwarm->name)+1 );
-                              Journal_Printf( stream, "         </Attribute>\n\n" );
-                  } else if ( swarmVar->dofCount == 2 ){
-                     /** note that for 2d, we feed back a quasi 3d array, with the 3rd Dof zeroed.  so in effect we always work in 3d.
-                         this is done because paraview in particular seems to do everything in 3d, and if you try and give it a 2d vector 
-                         or array, it complains.... and hence the verbosity of the following 2d definitions **/
-                              Journal_Printf( stream, "         <Attribute Type=\"Vector\" Center=\"Node\" Name=\"%s\">\n", swarmVar->name);
-                              Journal_Printf( stream, "            <DataItem ItemType=\"Function\"  Dimensions=\"%u 3\" Function=\"JOIN($0, $1, 0*$1)\">\n", swarmParticleLocalCount );
-                              Journal_Printf( stream, "               <DataItem ItemType=\"HyperSlab\" Dimensions=\"%u 1\" Name=\"XValue\">\n", swarmParticleLocalCount );
-                              Journal_Printf( stream, "                  <DataItem Dimensions=\"3 2\" Format=\"XML\"> 0 0 1 1 %u 1 </DataItem>\n", swarmParticleLocalCount );
-                              Journal_Printf( stream, "                  <DataItem Format=\"HDF\" %s Dimensions=\"%u 2\">%s.%05d%s.h5:/%s</DataItem>\n", variableType, swarmParticleLocalCount, currentSwarm->name, context->timeStep, filename_part, swarmVar->name + strlen(currentSwarm->name)+1 );
-                              Journal_Printf( stream, "               </DataItem>\n" );
-                              Journal_Printf( stream, "               <DataItem ItemType=\"HyperSlab\" Dimensions=\"%u 1\" Name=\"YValue\">\n", swarmParticleLocalCount );
-                              Journal_Printf( stream, "                  <DataItem Dimensions=\"3 2\" Format=\"XML\"> 0 1 1 1 %u 1 </DataItem>\n", swarmParticleLocalCount );
-                              Journal_Printf( stream, "                  <DataItem Format=\"HDF\" %s Dimensions=\"%u 2\">%s.%05d%s.h5:/%s</DataItem>\n", variableType, swarmParticleLocalCount, currentSwarm->name, context->timeStep, filename_part, swarmVar->name + strlen(currentSwarm->name)+1 );
-                              Journal_Printf( stream, "               </DataItem>\n" );
-                              Journal_Printf( stream, "            </DataItem>\n" );
-                              Journal_Printf( stream, "         </Attribute>\n\n" );
-                  } else if ( swarmVar->dofCount == 3 ) {
-                     /** in 3d we simply feed back the 3d hdf5 array, nice and easy **/
-                              Journal_Printf( stream, "         <Attribute Type=\"Vector\" Center=\"Node\" Name=\"%s\">\n", swarmVar->name);
-                              Journal_Printf( stream, "            <DataItem Format=\"HDF\" %s Dimensions=\"%u 3\">%s.%05d%s.h5:/%s</DataItem>\n", variableType, swarmParticleLocalCount, currentSwarm->name, context->timeStep, filename_part, swarmVar->name + strlen(currentSwarm->name)+1 );
-                              Journal_Printf( stream, "         </Attribute>\n\n" );
-                  } else {
-                     /** where there are more than 3 components, we write each one out as a scalar **/
-                     for(dofCountIndex = 0 ; dofCountIndex < swarmVar->dofCount ; ++dofCountIndex){
-                              Journal_Printf( stream, "         <Attribute Type=\"Scalar\" Center=\"Node\" Name=\"%s-Component-%u\">\n", swarmVar->name, dofCountIndex);
-                              Journal_Printf( stream, "            <DataItem ItemType=\"HyperSlab\" Dimensions=\"%u 1\" >\n", swarmParticleLocalCount );
-                              Journal_Printf( stream, "               <DataItem Dimensions=\"3 2\" Format=\"XML\"> 0 %u 1 1 %u 1 </DataItem>\n", dofCountIndex, swarmParticleLocalCount );
-                              Journal_Printf( stream, "               <DataItem Format=\"HDF\" %s Dimensions=\"%u %u\">%s.%05d%s.h5:/%s</DataItem>\n", variableType, swarmParticleLocalCount, swarmVar->dofCount, currentSwarm->name, context->timeStep, filename_part, swarmVar->name + strlen(currentSwarm->name)+1 );
-                              Journal_Printf( stream, "            </DataItem>\n" );
-                              Journal_Printf( stream, "         </Attribute>\n" );
-                     }
-                              Journal_Printf( stream, "\n" );
-                  }
-            /**----------------------- END ATTRIBUTES   ------------------------------------------------------------------------------------------------------------------- **/
-               }
-         
-            }
-   
-                              Journal_Printf( stream, "      </Grid>\n\n" );
-   
-         }
-      
-      }
-
-                              Journal_Printf( stream, "   </Grid>\n\n" );
-
-   if(variableType)  Memory_Free( variableType );
-   if(filename_part) Memory_Free( filename_part );
-      
-   }
-
-
-}
-
-void  _XDMFGenerator_WriteHeader( UnderworldContext* context, Stream* stream ) {
-   
-	/** Print XDMF header info **/
-                              Journal_Printf( stream, "<?xml version=\"1.0\" ?>\n" );
-                              Journal_Printf( stream, "<!DOCTYPE Xdmf SYSTEM \"Xdmf.dtd\" []>\n" );
-                              Journal_Printf( stream, "<Xdmf xmlns:xi=\"http://www.w3.org/2001/XInclude\" Version=\"2.0\">\n" );
-                              Journal_Printf( stream, "\n" );
-                              Journal_Printf( stream, "<Domain>\n" );
-                              Journal_Printf( stream, "\n" );
-
-}
-
-
-void _XDMFGenerator_WriteFooter( UnderworldContext* context, Stream* stream ) {
-
-                              Journal_Printf( stream, "</Domain>\n" );
-                              Journal_Printf( stream, "\n" );
-                              Journal_Printf( stream, "</Xdmf>\n" );
-                              Journal_Printf( stream, "\n" );
-
-}
-
-void _XDMFGenerator_SendInfo( UnderworldContext* context ) {
-   Swarm_Register* swarmRegister = Swarm_Register_GetSwarm_Register();
-   Index           swarmCount;
-   Index           swarmcountindex;
-   Index           swarmParticleLocalCount;
-   Swarm*          currentSwarm;
-	const int       FINISHED_WRITING_TAG = 100;
-   
-   /** get total number of different swarms **/
-   swarmCount  = swarmRegister->swarmList->count;
-   
-   /** parse swarm list, checking which are actually stored to HDF5.  **/
-   /** We assume that all processes have the same number of swarms on them, with the same swarms checkpointed**/
-   for(swarmcountindex = 0; swarmcountindex < swarmCount; ++swarmcountindex){
-      currentSwarm  = Swarm_Register_At( swarmRegister, swarmcountindex );
-
-      if ( currentSwarm->isSwarmTypeToCheckPointAndReload != True ) 
-         continue;
-
-      swarmParticleLocalCount = currentSwarm->particleLocalCount;
-		MPI_Ssend( &swarmParticleLocalCount, 1, MPI_INT, MASTER, FINISHED_WRITING_TAG, context->communicator );
-   }
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d Utils/src/XDMFGenerator.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/XDMFGenerator.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,506 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** 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: $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Underworld.h>
+
+#include "XDMFGenerator.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#ifndef MASTER
+	#define MASTER 0
+#endif
+
+const Type XDMFGenerator_Type = "XDMFGenerator";
+
+void XDMFGenerator_GenerateAll( void* _context ) {
+   UnderworldContext*   context    = (UnderworldContext*)_context;
+   Stream*              stream;
+
+   /** only the MASTER process writes to the file.  other processes send information to the MASTER where required **/   
+   if(context->rank == MASTER) {
+      Bool                 fileOpened;
+      Stream*              errorStream  = Journal_Register( Error_Type, (Name)CURR_MODULE_NAME  );
+      char*                 filename;
+      char*                outputPathString;
+
+      /** Create Stream **/
+      stream = Journal_Register( InfoStream_Type, (Name)"XDMFOutputFile"  );
+   
+      /** Set auto flush on stream **/
+      Stream_SetAutoFlush( stream, True );
+
+		outputPathString = Context_GetCheckPointWritePrefixString( context );
+   
+      /** Get name of XDMF schema file **/
+      Stg_asprintf( &filename, "%s/XDMF.%05d.xmf", outputPathString, context->timeStep );
+   
+      /** Init file, always overwriting any existing **/
+      fileOpened = Stream_RedirectFile( stream, filename );
+      Journal_Firewall( fileOpened, errorStream, 
+            "Could not open file %s. Possibly directory %s does not exist or is not writable.\n"
+            "Check 'checkpointWritePath' in input file.\n", filename, outputPathString );
+      Memory_Free( filename );
+      Memory_Free( outputPathString );
+      
+      /** write header information **/
+      _XDMFGenerator_WriteHeader( context, stream );
+
+      /** Write all (checkpointed) FeVariable field information  **/
+      _XDMFGenerator_WriteFieldSchema( context, stream );
+
+      /** Write all (checkpointed) FeVariable field information  **/
+      if ( (context->timeStep % context->checkpointEvery == 0) || 
+           (context->checkpointAtTimeInc && (context->currentTime >= context->nextCheckpointTime)) ) _XDMFGenerator_WriteSwarmSchema( context, stream);
+
+      /** writes footer information and close file/stream **/
+      _XDMFGenerator_WriteFooter( context, stream );
+
+      /** close the file **/
+      Stream_CloseFile( stream );	
+
+   } else {
+      /** other process send information about swarms populations to MASTER **/
+      _XDMFGenerator_SendInfo( context );
+   }
+
+}
+
+void _XDMFGenerator_WriteFieldSchema( UnderworldContext* context, Stream* stream ) {
+   FieldVariable*       fieldVar = NULL;
+   FeVariable*          feVar    = NULL;
+   Mesh*                mesh     = NULL;
+   FeMesh*              feMesh   = NULL;
+   unsigned             nDims;
+   unsigned             totalVerts;
+   Index                maxNodes;
+   Index                elementGlobalSize;
+   Element_GlobalIndex  gElement_I;
+	Index                var_I = 0;
+   Bool                 saveCoords  = Dictionary_GetBool_WithDefault( context->dictionary, (Dictionary_Entry_Key)"saveCoordsWithFields", False  );
+   Stream*              errorStream = Journal_Register( Error_Type, (Name)CURR_MODULE_NAME );
+   char*                variableType = NULL;
+   char*                topologyType = NULL;
+   unsigned             componentCount = LiveComponentRegister_GetCount(stgLiveComponentRegister);
+   unsigned             compI;
+   Stg_Component*       stgComp;
+
+   /** search for entire live component register for feMesh types  **/
+   for( compI = 0 ; compI < componentCount ; compI++ ){
+      stgComp = LiveComponentRegister_At( stgLiveComponentRegister, compI );
+      /* check that component is of type FeMesh, and that its element family is linear */
+      if ( Stg_Class_IsInstance( stgComp, FeMesh_Type ) && !strcmp( ((FeMesh*)stgComp)->feElFamily, "linear" ) ) {
+         mesh   = (  Mesh*)stgComp;
+         feMesh = (FeMesh*)stgComp;
+
+         nDims             = Mesh_GetDimSize( mesh );
+         totalVerts        = Mesh_GetGlobalSize( mesh, (MeshTopology_Dim)0 );
+         elementGlobalSize = FeMesh_GetElementGlobalSize(mesh);
+
+         /* get connectivity array size */
+         if (mesh->nElTypes == 1)
+            maxNodes = FeMesh_GetElementNodeSize( mesh, 0);
+         else {
+            /* determine the maximum number of nodes each element has */
+            maxNodes = 0;
+            for ( gElement_I = 0 ; gElement_I < FeMesh_GetElementGlobalSize(mesh); gElement_I++ ) {
+               unsigned numNodes;
+               numNodes = FeMesh_GetElementNodeSize( mesh, gElement_I);
+               if( maxNodes < numNodes ) maxNodes = numNodes;
+            }
+         }
+         /** now write all the xdmf geometry info **/
+         /**----------------------- START GEOMETRY   ------------------------------------------------------------------------------------------------------------------- **/
+         if(         maxNodes == 4 ){
+            Stg_asprintf( &topologyType, "Quadrilateral" );
+         } else if ( maxNodes == 8  ) {
+            Stg_asprintf( &topologyType, "Hexahedron" );
+         } else {
+            Journal_DPrintf( errorStream, "\n\n Error: number of element nodes %u not supported by XDMF generator...\n should be 4 (2D quadrilateral) " 
+                                    "or should be 8 (3D hexahedron). \n\n", maxNodes );
+            Stg_asprintf( &topologyType, "UNKNOWN_POSSIBLY_ERROR" );
+         }
+         /** first create the grid which is applicable to the checkpointed fevariables **/
+                                 Journal_Printf( stream, "   <Grid Name=\"FEM_Grid_%s\">\n\n", feMesh->name);
+                                 Journal_Printf( stream, "      <Time Value=\"%f\" />\n\n", context->currentTime );
+         /** now print out topology info, only quadrilateral elements are supported at the moment **/
+                                 Journal_Printf( stream, "         <Topology Type=\"%s\" NumberOfElements=\"%u\"> \n", topologyType, elementGlobalSize );
+                                 Journal_Printf( stream, "            <DataItem Format=\"HDF\" DataType=\"Int\"  Dimensions=\"%u %u\">Mesh.%s.%05d.h5:/connectivity</DataItem>\n", elementGlobalSize, maxNodes, feMesh->name, context->timeStep );
+                                 Journal_Printf( stream, "         </Topology>\n\n" );
+                                 Journal_Printf( stream, "         <Geometry Type=\"XYZ\">\n" );
+
+         Stg_asprintf( &variableType, "NumberType=\"Float\" Precision=\"8\"" );                              
+         if(         nDims == 2 ){
+            /** note that for 2d, we feed back a quasi 3d array, with the 3rd Dof zeroed.  so in effect we always work in 3d.
+                this is done because paraview in particular seems to do everything in 3d, and if you try and give it a 2d vector 
+                or array, it complains.... and hence the verbosity of the following 2d definitions**/
+                                 Journal_Printf( stream, "            <DataItem ItemType=\"Function\"  Dimensions=\"%u 3\" Function=\"JOIN($0, $1, 0*$1)\">\n", totalVerts );
+                                 Journal_Printf( stream, "               <DataItem ItemType=\"HyperSlab\" Dimensions=\"%u 1\" Name=\"XCoords\">\n", totalVerts );
+                                 Journal_Printf( stream, "                  <DataItem Dimensions=\"3 2\" Format=\"XML\"> 0 0 1 1 %u 1 </DataItem>\n", totalVerts );
+                                 Journal_Printf( stream, "                  <DataItem Format=\"HDF\" %s Dimensions=\"%u 2\">Mesh.%s.%05d.h5:/vertices</DataItem>\n", variableType, totalVerts, feMesh->name,  context->timeStep );
+                                 Journal_Printf( stream, "               </DataItem>\n" );
+                                 Journal_Printf( stream, "               <DataItem ItemType=\"HyperSlab\" Dimensions=\"%u 1\" Name=\"YCoords\">\n", totalVerts );
+                                 Journal_Printf( stream, "                  <DataItem Dimensions=\"3 2\" Format=\"XML\"> 0 1 1 1 %u 1 </DataItem>\n", totalVerts );
+                                 Journal_Printf( stream, "                  <DataItem Format=\"HDF\" %s Dimensions=\"%u 2\">Mesh.%s.%05d.h5:/vertices</DataItem>\n", variableType, totalVerts, feMesh->name, context->timeStep );
+                                 Journal_Printf( stream, "               </DataItem>\n" );
+                                 Journal_Printf( stream, "            </DataItem>\n" );
+         } else if ( nDims == 3 ) {
+            /** in 3d we simply feed back the 3d hdf5 array, nice and easy **/
+                                 Journal_Printf( stream, "            <DataItem Format=\"HDF\" %s Dimensions=\"%u 3\">Mesh.%s.%05d.h5:/vertices</DataItem>\n", variableType, totalVerts, feMesh->name, context->timeStep );
+         } else {
+            Journal_DPrintf( errorStream, "\n\n Error: Mesh vertex location is not of dofCount 2 or 3.\n\n" );
+         }
+                                 Journal_Printf( stream, "         </Geometry>\n\n" );
+         /**----------------------- FINISH GEOMETRY  ------------------------------------------------------------------------------------------------------------------- **/
+
+
+      /** now write FeVariable data **/   
+      for ( var_I = 0; var_I < context->fieldVariable_Register->objects->count; var_I++ ) {
+         fieldVar = FieldVariable_Register_GetByIndex( context->fieldVariable_Register, var_I );
+
+         if ( Stg_Class_IsInstance( fieldVar, FeVariable_Type ) ) {
+            feVar = (FeVariable*)fieldVar;
+            if ( (feVar->isCheckpointedAndReloaded && (context->timeStep % context->checkpointEvery == 0))                                     || 
+                 (feVar->isCheckpointedAndReloaded && (context->checkpointAtTimeInc && (context->currentTime >= context->nextCheckpointTime))) ||
+                 (feVar->isSavedData               && (context->timeStep % context->saveDataEvery   == 0)) ){
+               FeMesh* feVarMesh = NULL;
+               /** check what type of generator was used to know where elementMesh is **/
+               if( Stg_Class_IsInstance( feVar->feMesh->generator, C0Generator_Type))        feVarMesh = (FeMesh*)(((C0Generator*)feVar->feMesh->generator)->elMesh);
+               if( Stg_Class_IsInstance( feVar->feMesh->generator, CartesianGenerator_Type)) feVarMesh = feVar->feMesh;
+               if( Stg_Class_IsInstance( feVar->feMesh->generator, MeshAdaptor_Type))        feVarMesh = feVar->feMesh;
+               /** make sure that the fevariable femesh is the same as that used above for the geometry definition, if so proceed **/
+               if( feVarMesh == feMesh ){
+                 char*   centering = NULL;
+                     Index  offset = 0;
+                     Index  meshSize = Mesh_GetGlobalSize( feVar->feMesh, (MeshTopology_Dim)0 );
+                     Index  dofCountIndex;
+                     Index  dofAtEachNodeCount;
+
+               /**----------------------- START ATTRIBUTES ------------------------------------------------------------------------------------------------------------------- **/
+                     /** if coordinates are being stored with feVariable, account for this **/
+                     if( saveCoords) offset = nDims; 
+                     /** all feVariables are currently stored as doubles **/
+                     Stg_asprintf( &variableType, "NumberType=\"Float\" Precision=\"8\"" );
+                     /** determine whether feVariable data is cell centered (like Pressure), or on the nodes (like Velocity) **/
+                     if(        meshSize == elementGlobalSize ){
+                        Stg_asprintf( &centering, "Cell" );
+                     } else if( meshSize == totalVerts ) {
+                        Stg_asprintf( &centering, "Node" );
+                     } else {
+                        /* unknown/unsupported type */
+                        Stg_asprintf( &centering, "UNKNOWN_POSSIBLY_ERROR" );
+                     }
+                     /** how many degrees of freedom does the fevariable have? **/
+                     dofAtEachNodeCount = feVar->fieldComponentCount;
+                     if (        dofAtEachNodeCount == 1 ) {
+                                 Journal_Printf( stream, "         <Attribute Type=\"Scalar\" Center=\"%s\" Name=\"%s\">\n", centering,  feVar->name);
+                                 Journal_Printf( stream, "            <DataItem ItemType=\"HyperSlab\" Dimensions=\"%u 1\" >\n", meshSize );
+                                 Journal_Printf( stream, "               <DataItem Dimensions=\"3 2\" Format=\"XML\"> 0 %u 1 1 %u 1 </DataItem>\n", offset, meshSize );
+                                 Journal_Printf( stream, "               <DataItem Format=\"HDF\" %s Dimensions=\"%u %u\">%s.%05d.h5:/data</DataItem>\n", variableType, meshSize, (offset + dofAtEachNodeCount), feVar->name, context->timeStep);
+                                 Journal_Printf( stream, "            </DataItem>\n" );
+                                 Journal_Printf( stream, "         </Attribute>\n\n" );
+                     } else if ( dofAtEachNodeCount == 2 ){
+                        /** note that for 2d, we feed back a quasi 3d array, with the 3rd Dof zeroed.  so in effect we always work in 3d.
+                            this is done because paraview in particular seems to do everything in 3d, and if you try and give it a 2d vector 
+                            or array, it complains.... and hence the verbosity of the following 2d definitions **/
+                                 Journal_Printf( stream, "         <Attribute Type=\"Vector\" Center=\"%s\" Name=\"%s\">\n", centering,  feVar->name);
+                                 Journal_Printf( stream, "            <DataItem ItemType=\"Function\"  Dimensions=\"%u 3\" Function=\"JOIN($0, $1, 0*$1)\">\n", meshSize );
+                                 Journal_Printf( stream, "               <DataItem ItemType=\"HyperSlab\" Dimensions=\"%u 1\" Name=\"XValue\">\n", meshSize );
+                                 Journal_Printf( stream, "                  <DataItem Dimensions=\"3 2\" Format=\"XML\"> 0 %u 1 1 %u 1 </DataItem>\n", offset, meshSize );
+                                 Journal_Printf( stream, "                  <DataItem Format=\"HDF\" %s Dimensions=\"%u %u\">%s.%05d.h5:/data</DataItem>\n", variableType, meshSize, (offset + dofAtEachNodeCount), feVar->name, context->timeStep);
+                                 Journal_Printf( stream, "               </DataItem>\n" );
+                                 Journal_Printf( stream, "               <DataItem ItemType=\"HyperSlab\" Dimensions=\"%u 1\" Name=\"YValue\">\n", meshSize );
+                                 Journal_Printf( stream, "                  <DataItem Dimensions=\"3 2\" Format=\"XML\"> 0 %u 1 1 %u 1 </DataItem>\n", (offset+1), meshSize );
+                                 Journal_Printf( stream, "                  <DataItem Format=\"HDF\" %s Dimensions=\"%u %u\">%s.%05d.h5:/data</DataItem>\n", variableType, meshSize, (offset + dofAtEachNodeCount), feVar->name, context->timeStep);
+                                 Journal_Printf( stream, "               </DataItem>\n" );
+                                 Journal_Printf( stream, "            </DataItem>\n" );
+                                 Journal_Printf( stream, "         </Attribute>\n\n" );
+                     } else if ( dofAtEachNodeCount == 3 ) {
+                        /** in 3d we simply feed back the 3d hdf5 array, nice and easy **/
+                                 Journal_Printf( stream, "         <Attribute Type=\"Vector\" Center=\"%s\" Name=\"%s\">\n", centering,  feVar->name);
+                                 Journal_Printf( stream, "            <DataItem ItemType=\"HyperSlab\" Dimensions=\"%u 3\" >\n", meshSize );
+                                 Journal_Printf( stream, "               <DataItem Dimensions=\"3 2\" Format=\"XML\"> 0 %u 1 1 %u 3 </DataItem>\n", offset, meshSize );
+                                 Journal_Printf( stream, "               <DataItem Format=\"HDF\" %s Dimensions=\"%u %u\">%s.%05d.h5:/data</DataItem>\n", variableType, meshSize, (offset + dofAtEachNodeCount), feVar->name, context->timeStep);
+                                 Journal_Printf( stream, "            </DataItem>\n" );
+                                 Journal_Printf( stream, "         </Attribute>\n\n" );
+                     } else {
+                        /** where there are more than 3 components, we write each one out as a scalar **/
+                        for(dofCountIndex = 0 ; dofCountIndex < dofAtEachNodeCount ; ++dofCountIndex){
+                                 Journal_Printf( stream, "         <Attribute Type=\"Scalar\" Center=\"%s\" Name=\"%s-Component-%u\">\n", centering,  feVar->name, dofCountIndex);
+                                 Journal_Printf( stream, "            <DataItem ItemType=\"HyperSlab\" Dimensions=\"%u 1\" >\n", meshSize );
+                                 Journal_Printf( stream, "               <DataItem Dimensions=\"3 2\" Format=\"XML\"> 0 %u 1 1 %u 1 </DataItem>\n", (offset+dofCountIndex), meshSize );
+                                 Journal_Printf( stream, "               <DataItem Format=\"HDF\" %s Dimensions=\"%u %u\">%s.%05d.h5:/data</DataItem>\n", variableType, meshSize, (offset + dofAtEachNodeCount), feVar->name, context->timeStep);
+                                 Journal_Printf( stream, "            </DataItem>\n" );
+                                 Journal_Printf( stream, "         </Attribute>\n" );
+                        }
+                                 Journal_Printf( stream, "\n" );
+                     }
+               /**----------------------- END ATTRIBUTES   ------------------------------------------------------------------------------------------------------------------- **/
+               if(centering) Memory_Free( centering );
+               }
+               }
+         }
+      }
+                                 Journal_Printf( stream, "   </Grid>\n\n" );
+      if(variableType) Memory_Free( variableType );
+      if(topologyType) Memory_Free( topologyType );
+      }
+   }
+}
+
+void _XDMFGenerator_WriteSwarmSchema( UnderworldContext* context, Stream* stream ) {
+   Swarm_Register* swarmRegister = Swarm_Register_GetSwarm_Register();
+   Index           swarmCount;
+   Index           swarmcountindex;
+   Index           variablecount;
+   Index           dofCountIndex;
+   Index           swarmParticleLocalCount;
+   Index           countindex;
+   Index           ii;
+   Swarm*          currentSwarm;
+   SwarmVariable*  swarmVar;
+   char*           swarmVarName;
+   char*           variableType = NULL;
+   char*           filename_part = NULL;
+   Stream*         errorStream  = Journal_Register( Error_Type, (Name)CURR_MODULE_NAME  );
+	const int       FINISHED_WRITING_TAG = 100;
+	MPI_Status      status;
+   
+   /** get total number of different swarms **/
+   swarmCount  = swarmRegister->swarmList->count;
+   
+   /** parse swarm list, checking which are actually stored to HDF5.  **/
+   /** We assume that all processes have the same number of swarms on them, with the same swarms checkpointed**/
+   for(swarmcountindex = 0; swarmcountindex < swarmCount; ++swarmcountindex){
+      currentSwarm  = Swarm_Register_At( swarmRegister, swarmcountindex );
+
+      if ( currentSwarm->isSwarmTypeToCheckPointAndReload != True ) 
+         continue;
+
+      swarmParticleLocalCount = currentSwarm->particleLocalCount;
+      /** first create a grid collection which will contain the collection of swarms from each process. 
+          there will be one of these collections for each swarm (not swarmvariable) that is checkpointed **/
+                              Journal_Printf( stream, "   <Grid Name=\"%s\" GridType=\"Collection\">\n\n", currentSwarm->name );
+                              Journal_Printf( stream, "      <Time Value=\"%f\" />\n\n", context->currentTime );
+
+      Stg_asprintf( &filename_part, "" );
+      for (ii = 0 ; ii < context->nproc ; ++ii) {
+
+         /** get the number of particles in each swarm from each process **/
+         if (ii != MASTER        ) MPI_Recv( &swarmParticleLocalCount, 1, MPI_INT, ii, FINISHED_WRITING_TAG, context->communicator, &status );
+         if (context->nproc != 1 ) Stg_asprintf( &filename_part, ".%uof%u", (ii + 1), context->nproc );
+         
+         /** first write all the MASTER procs swarm info **/
+         if (swarmParticleLocalCount != 0) {
+                              Journal_Printf( stream, "      <Grid Name=\"%s_proc_%u\">\n\n", currentSwarm->name, ii );
+            
+            /** now write all the xdmf geometry info **/
+            /**----------------------- START GEOMETRY   ------------------------------------------------------------------------------------------------------------------- **/
+                              Journal_Printf( stream, "         <Topology Type=\"POLYVERTEX\" NodesPerElement=\"%u\"> </Topology>\n", swarmParticleLocalCount );
+                              Journal_Printf( stream, "         <Geometry Type=\"XYZ\">\n" );
+            Stg_asprintf( &swarmVarName, "%s-Position", currentSwarm->name );
+            swarmVar = SwarmVariable_Register_GetByName( currentSwarm->swarmVariable_Register, swarmVarName );
+            if (!swarmVar) 
+               Journal_DPrintf( errorStream, "\n\n Error: Could not find required Position SwarmVariable. \n\n" );
+            Memory_Free( swarmVarName );
+            
+            /** check what precision it Position variable is stored at **/
+            if(        swarmVar->variable->dataTypes[0] == Variable_DataType_Int ){
+               Journal_DPrintf( errorStream, "\n\n Error: Position variable can not be of type Int. \n\n" );
+            } else if ( swarmVar->variable->dataTypes[0] == Variable_DataType_Char){
+               Journal_DPrintf( errorStream, "\n\n Error: Position variable can not be of type Char. \n\n" );
+            } else if ( swarmVar->variable->dataTypes[0] == Variable_DataType_Float ){
+               Stg_asprintf( &variableType, "NumberType=\"Float\" Precision=\"4\"" );
+            } else {
+               Stg_asprintf( &variableType, "NumberType=\"Float\" Precision=\"8\"" );
+            }
+           
+            if(         swarmVar->dofCount == 2 ){
+               /** note that for 2d, we feed back a quasi 3d array, with the 3rd Dof zeroed.  so in effect we always work in 3d.
+                   this is done because paraview in particular seems to do everything in 3d, and if you try and give it a 2d vector 
+                   or array, it complains.... and hence the verbosity of the following 2d definitions**/
+                              Journal_Printf( stream, "            <DataItem ItemType=\"Function\"  Dimensions=\"%u 3\" Function=\"JOIN($0, $1, 0*$1)\">\n", swarmParticleLocalCount );
+                              Journal_Printf( stream, "               <DataItem ItemType=\"HyperSlab\" Dimensions=\"%u 1\" Name=\"XCoords\">\n", swarmParticleLocalCount );
+                              Journal_Printf( stream, "                  <DataItem Dimensions=\"3 2\" Format=\"XML\"> 0 0 1 1 %u 1 </DataItem>\n", swarmParticleLocalCount );
+                              Journal_Printf( stream, "                  <DataItem Format=\"HDF\" %s Dimensions=\"%u 2\">%s.%05d%s.h5:/Position</DataItem>\n", variableType, swarmParticleLocalCount, currentSwarm->name, context->timeStep, filename_part );
+                              Journal_Printf( stream, "               </DataItem>\n" );
+                              Journal_Printf( stream, "               <DataItem ItemType=\"HyperSlab\" Dimensions=\"%u 1\" Name=\"YCoords\">\n", swarmParticleLocalCount );
+                              Journal_Printf( stream, "                  <DataItem Dimensions=\"3 2\" Format=\"XML\"> 0 1 1 1 %u 1 </DataItem>\n", swarmParticleLocalCount );
+                              Journal_Printf( stream, "                  <DataItem Format=\"HDF\" %s Dimensions=\"%u 2\">%s.%05d%s.h5:/Position</DataItem>\n", variableType, swarmParticleLocalCount, currentSwarm->name, context->timeStep, filename_part );
+                              Journal_Printf( stream, "               </DataItem>\n" );
+                              Journal_Printf( stream, "            </DataItem>\n" );
+            } else if ( swarmVar->dofCount == 3 ) {
+               /** in 3d we simply feed back the 3d hdf5 array, nice and easy **/
+                              Journal_Printf( stream, "            <DataItem Format=\"HDF\" %s Dimensions=\"%u 3\">%s.%05d%s.h5:/Position</DataItem>\n", variableType, swarmParticleLocalCount, currentSwarm->name, context->timeStep, filename_part );
+            } else {
+               Journal_DPrintf( errorStream, "\n\n Error: Position SwarmVariable is not of dofCount 2 or 3.\n\n" );
+            }
+                              Journal_Printf( stream, "         </Geometry>\n\n" );
+            /**----------------------- FINISH GEOMETRY  ------------------------------------------------------------------------------------------------------------------- **/
+   
+            
+            /** now write all the swarm attributes.. ie all the checkpointed swarmVariables **/
+            
+            variablecount = currentSwarm->swarmVariable_Register->objects->count;
+            for(countindex = 0; countindex < variablecount; ++countindex){
+               swarmVar = SwarmVariable_Register_GetByIndex( currentSwarm->swarmVariable_Register, countindex );
+               if( swarmVar->isCheckpointedAndReloaded ) {
+            /**----------------------- START ATTRIBUTES ------------------------------------------------------------------------------------------------------------------- **/
+                  if(         swarmVar->variable->dataTypes[0] == Variable_DataType_Int ){
+                     Stg_asprintf( &variableType, "NumberType=\"Int\"" );
+                  } else if ( swarmVar->variable->dataTypes[0] == Variable_DataType_Char){
+                     Stg_asprintf( &variableType, "NumberType=\"Char\"" );
+                  } else if ( swarmVar->variable->dataTypes[0] == Variable_DataType_Float ){
+                     Stg_asprintf( &variableType, "NumberType=\"Float\" Precision=\"4\"" );
+                  } else {
+                     Stg_asprintf( &variableType, "NumberType=\"Float\" Precision=\"8\"" );
+                  }
+                  if (        swarmVar->dofCount == 1 ) {
+                              Journal_Printf( stream, "         <Attribute Type=\"Scalar\" Center=\"Node\" Name=\"%s\">\n", swarmVar->name);
+                              Journal_Printf( stream, "            <DataItem Format=\"HDF\" %s Dimensions=\"%u 1\">%s.%05d%s.h5:/%s</DataItem>\n", variableType, swarmParticleLocalCount, currentSwarm->name, context->timeStep, filename_part, swarmVar->name + strlen(currentSwarm->name)+1 );
+                              Journal_Printf( stream, "         </Attribute>\n\n" );
+                  } else if ( swarmVar->dofCount == 2 ){
+                     /** note that for 2d, we feed back a quasi 3d array, with the 3rd Dof zeroed.  so in effect we always work in 3d.
+                         this is done because paraview in particular seems to do everything in 3d, and if you try and give it a 2d vector 
+                         or array, it complains.... and hence the verbosity of the following 2d definitions **/
+                              Journal_Printf( stream, "         <Attribute Type=\"Vector\" Center=\"Node\" Name=\"%s\">\n", swarmVar->name);
+                              Journal_Printf( stream, "            <DataItem ItemType=\"Function\"  Dimensions=\"%u 3\" Function=\"JOIN($0, $1, 0*$1)\">\n", swarmParticleLocalCount );
+                              Journal_Printf( stream, "               <DataItem ItemType=\"HyperSlab\" Dimensions=\"%u 1\" Name=\"XValue\">\n", swarmParticleLocalCount );
+                              Journal_Printf( stream, "                  <DataItem Dimensions=\"3 2\" Format=\"XML\"> 0 0 1 1 %u 1 </DataItem>\n", swarmParticleLocalCount );
+                              Journal_Printf( stream, "                  <DataItem Format=\"HDF\" %s Dimensions=\"%u 2\">%s.%05d%s.h5:/%s</DataItem>\n", variableType, swarmParticleLocalCount, currentSwarm->name, context->timeStep, filename_part, swarmVar->name + strlen(currentSwarm->name)+1 );
+                              Journal_Printf( stream, "               </DataItem>\n" );
+                              Journal_Printf( stream, "               <DataItem ItemType=\"HyperSlab\" Dimensions=\"%u 1\" Name=\"YValue\">\n", swarmParticleLocalCount );
+                              Journal_Printf( stream, "                  <DataItem Dimensions=\"3 2\" Format=\"XML\"> 0 1 1 1 %u 1 </DataItem>\n", swarmParticleLocalCount );
+                              Journal_Printf( stream, "                  <DataItem Format=\"HDF\" %s Dimensions=\"%u 2\">%s.%05d%s.h5:/%s</DataItem>\n", variableType, swarmParticleLocalCount, currentSwarm->name, context->timeStep, filename_part, swarmVar->name + strlen(currentSwarm->name)+1 );
+                              Journal_Printf( stream, "               </DataItem>\n" );
+                              Journal_Printf( stream, "            </DataItem>\n" );
+                              Journal_Printf( stream, "         </Attribute>\n\n" );
+                  } else if ( swarmVar->dofCount == 3 ) {
+                     /** in 3d we simply feed back the 3d hdf5 array, nice and easy **/
+                              Journal_Printf( stream, "         <Attribute Type=\"Vector\" Center=\"Node\" Name=\"%s\">\n", swarmVar->name);
+                              Journal_Printf( stream, "            <DataItem Format=\"HDF\" %s Dimensions=\"%u 3\">%s.%05d%s.h5:/%s</DataItem>\n", variableType, swarmParticleLocalCount, currentSwarm->name, context->timeStep, filename_part, swarmVar->name + strlen(currentSwarm->name)+1 );
+                              Journal_Printf( stream, "         </Attribute>\n\n" );
+                  } else {
+                     /** where there are more than 3 components, we write each one out as a scalar **/
+                     for(dofCountIndex = 0 ; dofCountIndex < swarmVar->dofCount ; ++dofCountIndex){
+                              Journal_Printf( stream, "         <Attribute Type=\"Scalar\" Center=\"Node\" Name=\"%s-Component-%u\">\n", swarmVar->name, dofCountIndex);
+                              Journal_Printf( stream, "            <DataItem ItemType=\"HyperSlab\" Dimensions=\"%u 1\" >\n", swarmParticleLocalCount );
+                              Journal_Printf( stream, "               <DataItem Dimensions=\"3 2\" Format=\"XML\"> 0 %u 1 1 %u 1 </DataItem>\n", dofCountIndex, swarmParticleLocalCount );
+                              Journal_Printf( stream, "               <DataItem Format=\"HDF\" %s Dimensions=\"%u %u\">%s.%05d%s.h5:/%s</DataItem>\n", variableType, swarmParticleLocalCount, swarmVar->dofCount, currentSwarm->name, context->timeStep, filename_part, swarmVar->name + strlen(currentSwarm->name)+1 );
+                              Journal_Printf( stream, "            </DataItem>\n" );
+                              Journal_Printf( stream, "         </Attribute>\n" );
+                     }
+                              Journal_Printf( stream, "\n" );
+                  }
+            /**----------------------- END ATTRIBUTES   ------------------------------------------------------------------------------------------------------------------- **/
+               }
+         
+            }
+   
+                              Journal_Printf( stream, "      </Grid>\n\n" );
+   
+         }
+      
+      }
+
+                              Journal_Printf( stream, "   </Grid>\n\n" );
+
+   if(variableType)  Memory_Free( variableType );
+   if(filename_part) Memory_Free( filename_part );
+      
+   }
+
+
+}
+
+void  _XDMFGenerator_WriteHeader( UnderworldContext* context, Stream* stream ) {
+   
+	/** Print XDMF header info **/
+                              Journal_Printf( stream, "<?xml version=\"1.0\" ?>\n" );
+                              Journal_Printf( stream, "<!DOCTYPE Xdmf SYSTEM \"Xdmf.dtd\" []>\n" );
+                              Journal_Printf( stream, "<Xdmf xmlns:xi=\"http://www.w3.org/2001/XInclude\" Version=\"2.0\">\n" );
+                              Journal_Printf( stream, "\n" );
+                              Journal_Printf( stream, "<Domain>\n" );
+                              Journal_Printf( stream, "\n" );
+
+}
+
+
+void _XDMFGenerator_WriteFooter( UnderworldContext* context, Stream* stream ) {
+
+                              Journal_Printf( stream, "</Domain>\n" );
+                              Journal_Printf( stream, "\n" );
+                              Journal_Printf( stream, "</Xdmf>\n" );
+                              Journal_Printf( stream, "\n" );
+
+}
+
+void _XDMFGenerator_SendInfo( UnderworldContext* context ) {
+   Swarm_Register* swarmRegister = Swarm_Register_GetSwarm_Register();
+   Index           swarmCount;
+   Index           swarmcountindex;
+   Index           swarmParticleLocalCount;
+   Swarm*          currentSwarm;
+	const int       FINISHED_WRITING_TAG = 100;
+   
+   /** get total number of different swarms **/
+   swarmCount  = swarmRegister->swarmList->count;
+   
+   /** parse swarm list, checking which are actually stored to HDF5.  **/
+   /** We assume that all processes have the same number of swarms on them, with the same swarms checkpointed**/
+   for(swarmcountindex = 0; swarmcountindex < swarmCount; ++swarmcountindex){
+      currentSwarm  = Swarm_Register_At( swarmRegister, swarmcountindex );
+
+      if ( currentSwarm->isSwarmTypeToCheckPointAndReload != True ) 
+         continue;
+
+      swarmParticleLocalCount = currentSwarm->particleLocalCount;
+		MPI_Ssend( &swarmParticleLocalCount, 1, MPI_INT, MASTER, FINISHED_WRITING_TAG, context->communicator );
+   }
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d libUnderworld/Toolbox/Toolbox.c
--- a/libUnderworld/Toolbox/Toolbox.c	Wed May 11 13:27:52 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 <Underworld/Underworld.h>
-#include "Toolbox.h"
-
-const Type Underworld_Toolbox_Type = "Underworld_Toolbox";
-
-void _Underworld_Toolbox_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
-}
-
-void* _Underworld_Toolbox_DefaultNew( Name name ) {
-	return Codelet_New(
-			Underworld_Toolbox_Type,
-			_Underworld_Toolbox_DefaultNew,
-			_Underworld_Toolbox_AssignFromXML,
-			_Codelet_Build,
-			_Codelet_Initialise,
-			_Codelet_Execute,
-			_Codelet_Destroy,
-			name );
-}
-
-void Underworld_Toolbox_Initialise( PluginsManager* pluginsManager, int* argc, char*** argv ) {
-	Underworld_Init( argc, argv );
-}
-
-void Underworld_Toolbox_Finalise( PluginsManager* pluginsManager ) {
-	Underworld_Finalise();
-	
-	Journal_RPrintf( Journal_Register( DebugStream_Type, (Name)Underworld_Toolbox_Type  ), "Finalised: Underworld Toolbox.\n" );
-}
-
-Index Underworld_Toolbox_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Underworld_Toolbox_Type, (Name)"0", _Underworld_Toolbox_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d libUnderworld/Toolbox/Toolbox.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libUnderworld/Toolbox/Toolbox.cxx	Thu May 12 11:19:19 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 <Underworld/Underworld.h>
+#include "Toolbox.h"
+
+const Type Underworld_Toolbox_Type = "Underworld_Toolbox";
+
+void _Underworld_Toolbox_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
+}
+
+void* _Underworld_Toolbox_DefaultNew( Name name ) {
+	return Codelet_New(
+			Underworld_Toolbox_Type,
+			_Underworld_Toolbox_DefaultNew,
+			_Underworld_Toolbox_AssignFromXML,
+			_Codelet_Build,
+			_Codelet_Initialise,
+			_Codelet_Execute,
+			_Codelet_Destroy,
+			name );
+}
+
+void Underworld_Toolbox_Initialise( PluginsManager* pluginsManager, int* argc, char*** argv ) {
+	Underworld_Init( argc, argv );
+}
+
+void Underworld_Toolbox_Finalise( PluginsManager* pluginsManager ) {
+	Underworld_Finalise();
+	
+	Journal_RPrintf( Journal_Register( DebugStream_Type, (Name)Underworld_Toolbox_Type  ), "Finalised: Underworld Toolbox.\n" );
+}
+
+Index Underworld_Toolbox_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Underworld_Toolbox_Type, (Name)"0", _Underworld_Toolbox_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d libUnderworld/src/Finalise.c
--- a/libUnderworld/src/Finalise.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,72 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: Finalise.c 610 2007-10-11 08:09:29Z SteveQuenette $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include <Underworld/Rheology/Rheology.h>
-#include <Underworld/Utils/Utils.h>
-
-#include "Finalise.h"
-
-#include <stdio.h>
-
-Bool Underworld_Finalise( void ) {
-	if( ToolboxesManager_IsInitialised( stgToolboxesManager, "Underworld" ) ) {
-		Underworld_Utils_Finalise();
-		Underworld_Rheology_Finalise();
-		
-		Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
-
-		return True;
-	} else {
-		return False;
-	}
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d libUnderworld/src/Finalise.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libUnderworld/src/Finalise.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,72 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: Finalise.c 610 2007-10-11 08:09:29Z SteveQuenette $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include <Underworld/Rheology/Rheology.h>
+#include <Underworld/Utils/Utils.h>
+
+#include "Finalise.h"
+
+#include <stdio.h>
+
+Bool Underworld_Finalise( void ) {
+	if( ToolboxesManager_IsInitialised( stgToolboxesManager, "Underworld" ) ) {
+		Underworld_Utils_Finalise();
+		Underworld_Rheology_Finalise();
+		
+		Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
+
+		return True;
+	} else {
+		return False;
+	}
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d libUnderworld/src/Init.c
--- a/libUnderworld/src/Init.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,152 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: Init.c 610 2007-10-11 08:09:29Z SteveQuenette $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "Underworld/Rheology/Rheology.h"
-#include "Underworld/Utils/Utils.h"
-
-#include "Init.h"
-
-#include <stdio.h>
-#include <signal.h>
-#include <string.h>
-
-/** Initialises this package, then any init for this package
-such as streams etc */
-
-Stream* Underworld_Debug = NULL;
-Stream* Underworld_Info = NULL;
-Stream* Underworld_Error = NULL;
-
-Bool Underworld_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, "Underworld" ) ) {
-		char* argString;
-		int arg_I;
-		int tmp;
-		Bool useSignalHandler = True;
-		char* directory;
-
-		for ( arg_I = 0; argc && arg_I < *argc; arg_I++ ) {
-			argString = (*argv)[arg_I];
-			/* Leverage from PETSC's no signal flag */
-			if ( strcmp( argString, "-no_signal_handler" ) == 0 ) {
-				useSignalHandler = False;
-			}
-		}
-
-		if ( useSignalHandler ) {
-			signal( SIGSEGV, Underworld_SignalHandler );
-			signal( SIGTERM, Underworld_SignalHandler );
-		}
-
-		Underworld_Rheology_Init( argc, argv );
-		Underworld_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"  ), 
-			"Underworld (Geodynamics framework) revision %s. Copyright (C) 2005 Monash Cluster Computing.\n", VERSION );
-		Stream_Flush( Journal_Register( InfoStream_Type, (Name)"Context" )  );
-		Stream_SetPrintingRank( Journal_Register( InfoStream_Type, (Name)"Context"  ), tmp );
-
-		/* Create Streams */
-		Underworld_Debug  = Journal_Register( Debug_Type, (Name)"Context"  );
-		Underworld_Info   = Journal_Register( Info_Type, (Name)"Context"  );
-		Underworld_Error  = Journal_Register( Error_Type, (Name)"Context"  );
-	
-		/* Add the Underworld path to the global xml path dictionary */
-		directory = Memory_Alloc_Array( char, 400, "xmlDirectory" ) ;
-		sprintf(directory, "%s%s", LIB_DIR, "/StGermain" );
-		XML_IO_Handler_AddDirectory( "Underworld", directory );
-		Memory_Free(directory);
-
-		/* Add the plugin path to the global plugin list */
-		#ifdef GLUCIFER_LIBDIR
-			ModulesManager_AddDirectory( "gLucifer", GLUCIFER_LIBDIR );
-		#endif
-	
-		ModulesManager_AddDirectory( "Underworld", LIB_DIR );
-
-		return True;
-	}
-	return False;
-}
-
-
-void Underworld_SignalHandler( int signal ) {
-	fprintf( stderr, 
-			"\n\n=====================================================================================\n"
-			"Error running Underworld (revision %s) - Signal %d ",
-			VERSION, signal );
-
-	switch ( signal ) {
-		case SIGSEGV:
-			fprintf( stderr, 
-					"'SIGSEGV' (Segmentation Fault).\n" 
-					"This is probably caused by an illegal access of memory.\n"
-					"We recommend running the code in a debugger to work out where the problem is (e.g. 'gdb')\n"
-					"and also to contact the developers.\n" );
-			break;
-		case SIGTERM:
-			fprintf( stderr, 
-					"'SIGTERM' (Termination Request).\n" 
-					"This is caused by an external call to terminate the code.\n"
-					"This could have happened by a queueing system (e.g. if the code has run longer than allowed),\n"
-					"the code might have been killed on another processor or it may have been killed by the user.\n" );
-			break;
-	}
-	exit(EXIT_FAILURE);
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d libUnderworld/src/Init.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libUnderworld/src/Init.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,152 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: Init.c 610 2007-10-11 08:09:29Z SteveQuenette $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "Underworld/Rheology/Rheology.h"
+#include "Underworld/Utils/Utils.h"
+
+#include "Init.h"
+
+#include <stdio.h>
+#include <signal.h>
+#include <string.h>
+
+/** Initialises this package, then any init for this package
+such as streams etc */
+
+Stream* Underworld_Debug = NULL;
+Stream* Underworld_Info = NULL;
+Stream* Underworld_Error = NULL;
+
+Bool Underworld_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, "Underworld" ) ) {
+		char* argString;
+		int arg_I;
+		int tmp;
+		Bool useSignalHandler = True;
+		char* directory;
+
+		for ( arg_I = 0; argc && arg_I < *argc; arg_I++ ) {
+			argString = (*argv)[arg_I];
+			/* Leverage from PETSC's no signal flag */
+			if ( strcmp( argString, "-no_signal_handler" ) == 0 ) {
+				useSignalHandler = False;
+			}
+		}
+
+		if ( useSignalHandler ) {
+			signal( SIGSEGV, Underworld_SignalHandler );
+			signal( SIGTERM, Underworld_SignalHandler );
+		}
+
+		Underworld_Rheology_Init( argc, argv );
+		Underworld_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"  ), 
+			"Underworld (Geodynamics framework) revision %s. Copyright (C) 2005 Monash Cluster Computing.\n", VERSION );
+		Stream_Flush( Journal_Register( InfoStream_Type, (Name)"Context" )  );
+		Stream_SetPrintingRank( Journal_Register( InfoStream_Type, (Name)"Context"  ), tmp );
+
+		/* Create Streams */
+		Underworld_Debug  = Journal_Register( Debug_Type, (Name)"Context"  );
+		Underworld_Info   = Journal_Register( Info_Type, (Name)"Context"  );
+		Underworld_Error  = Journal_Register( Error_Type, (Name)"Context"  );
+	
+		/* Add the Underworld path to the global xml path dictionary */
+		directory = Memory_Alloc_Array( char, 400, "xmlDirectory" ) ;
+		sprintf(directory, "%s%s", LIB_DIR, "/StGermain" );
+		XML_IO_Handler_AddDirectory( "Underworld", directory );
+		Memory_Free(directory);
+
+		/* Add the plugin path to the global plugin list */
+		#ifdef GLUCIFER_LIBDIR
+			ModulesManager_AddDirectory( "gLucifer", GLUCIFER_LIBDIR );
+		#endif
+	
+		ModulesManager_AddDirectory( "Underworld", LIB_DIR );
+
+		return True;
+	}
+	return False;
+}
+
+
+void Underworld_SignalHandler( int signal ) {
+	fprintf( stderr, 
+			"\n\n=====================================================================================\n"
+			"Error running Underworld (revision %s) - Signal %d ",
+			VERSION, signal );
+
+	switch ( signal ) {
+		case SIGSEGV:
+			fprintf( stderr, 
+					"'SIGSEGV' (Segmentation Fault).\n" 
+					"This is probably caused by an illegal access of memory.\n"
+					"We recommend running the code in a debugger to work out where the problem is (e.g. 'gdb')\n"
+					"and also to contact the developers.\n" );
+			break;
+		case SIGTERM:
+			fprintf( stderr, 
+					"'SIGTERM' (Termination Request).\n" 
+					"This is caused by an external call to terminate the code.\n"
+					"This could have happened by a queueing system (e.g. if the code has run longer than allowed),\n"
+					"the code might have been killed on another processor or it may have been killed by the user.\n" );
+			break;
+	}
+	exit(EXIT_FAILURE);
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d libUnderworld/tests/testLibUnderworld.c
--- a/libUnderworld/tests/testLibUnderworld.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,173 +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: testLibStgFEM.c 656 2006-10-18 06:45:50Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include "Underworld/Underworld.h"
-#include "Underworld/Init.h"
-#include "Underworld/Finalise.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-int main( int argc, char* argv[] ) {
-	MPI_Comm		CommWorld;
-	int			rank;
-	int			numProcessors;
-	int			procToWatch;
-	
-	/* Initialise MPI, get world info */
-	MPI_Init( &argc, &argv );
-	MPI_Comm_dup( MPI_COMM_WORLD, &CommWorld );
-	MPI_Comm_size( CommWorld, &numProcessors );
-	MPI_Comm_rank( CommWorld, &rank );
-	/* Read input */
-
-	if( !StGermain_Init( &argc, &argv ) ) {
-		fprintf( stderr, "Error initialising StGermain, exiting.\n" );
-		exit( EXIT_FAILURE );
-	}
-	if (!StgDomain_Init( &argc, &argv ) ) {
-		fprintf( stderr, "Error initialising StgDomain, exiting.\n" );
-		exit( EXIT_FAILURE );
-	}
-	if (!StgFEM_Init( &argc, &argv ) ) {
-		fprintf( stderr, "Error initialising StgFEM, exiting.\n" );
-		exit( EXIT_FAILURE );
-	}
-	if (!PICellerator_Init( &argc, &argv ) ) {
-		fprintf( stderr, "Error initialising PICellerator, exiting.\n" );
-		exit( EXIT_FAILURE );
-	}	
-	Underworld_Init( &argc, &argv );
-	MPI_Barrier( CommWorld ); /* Ensures copyright info always come first in output */
-
-	if( argc >= 2 ) {
-		procToWatch = atoi( argv[1] );
-	}
-	else {
-		procToWatch = 0;
-	}
-	if( rank == procToWatch ) {
-		Stg_Object* testDirectory;
-
-		printf( "Watching rank: %i\n", rank );
-		/* Testing entries in xmlSearchPaths */
-		testDirectory = Stg_ObjectList_Get( xmlSearchPaths, (Name)"StGermain" );
-		if (testDirectory != NULL) {
-			printf("StGermain XML library Path found.\n");
-		}
-		else {
-			printf("StGermain XML library Path not found.\n"); 
-		}
-		/* For build in the same build directory */
-		if (strcmp((char* )LIB_DIR, (char*)testDirectory)) {
-			printf("StgDomain XML library Path found.\n");
-		}
-		/* For build in separate directories */
-		else{
-			testDirectory = Stg_ObjectList_Get( xmlSearchPaths, (Name)"StgDomain" );
-			if (testDirectory != NULL) {
-				printf("StgDomain XML library Path found.\n");
-			}
-			else {
-				printf("StgDomain XML library Path not found.\n"); 
-			}
-		}
-		if (strcmp((char* )LIB_DIR, (char*)testDirectory)) {
-			printf("StgFEM XML library Path found.\n");
-		}
-		/* For build in separate directories */
-		else{
-			testDirectory = Stg_ObjectList_Get( xmlSearchPaths, (Name)"StgFEM" );
-			if (testDirectory != NULL) {
-				printf("StgFEM XML library Path found.\n");
-			}
-			else {
-				printf("StgFEM XML library Path not found.\n"); 
-			}
-		}
-		/* For build in the same build directory */
-		if (strcmp((char* )LIB_DIR, (char*)testDirectory)) {
-			printf("PICellerator XML library Path found.\n");
-		}
-		/* For build in separate directories */
-		else{
-			testDirectory = Stg_ObjectList_Get( xmlSearchPaths, (Name)"PICellerator" );
-			if (testDirectory != NULL) {
-				printf("PICellerator XML library Path found.\n");
-			}
-			else {
-				printf("PICellerator XML library Path not found.\n"); 
-			}
-		}
-		/* For build in the same build directory */
-		if (strcmp((char* )LIB_DIR, (char*)testDirectory)) {
-			printf("Underworld XML library Path found.\n");
-		}
-		/* For build in separate directories */
-		else{
-			testDirectory = Stg_ObjectList_Get( xmlSearchPaths, (Name)"Underworld" );
-			if (testDirectory != NULL) {
-				printf("Underworld XML library Path found.\n");
-			}
-			else {
-				printf("Underworld XML library Path not found.\n"); 
-			}
-		}		
-	}
-	Underworld_Finalise();
-	PICellerator_Finalise(); 
-	StgFEM_Finalise();
-	StgDomain_Finalise();
-	StGermain_Finalise();
-	
-	/* Close off MPI */
-	MPI_Finalize( );
-
-	return 0; /* success */
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d libUnderworld/tests/testLibUnderworld.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libUnderworld/tests/testLibUnderworld.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,173 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** 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: testLibStgFEM.c 656 2006-10-18 06:45:50Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include "Underworld/Underworld.h"
+#include "Underworld/Init.h"
+#include "Underworld/Finalise.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main( int argc, char* argv[] ) {
+	MPI_Comm		CommWorld;
+	int			rank;
+	int			numProcessors;
+	int			procToWatch;
+	
+	/* Initialise MPI, get world info */
+	MPI_Init( &argc, &argv );
+	MPI_Comm_dup( MPI_COMM_WORLD, &CommWorld );
+	MPI_Comm_size( CommWorld, &numProcessors );
+	MPI_Comm_rank( CommWorld, &rank );
+	/* Read input */
+
+	if( !StGermain_Init( &argc, &argv ) ) {
+		fprintf( stderr, "Error initialising StGermain, exiting.\n" );
+		exit( EXIT_FAILURE );
+	}
+	if (!StgDomain_Init( &argc, &argv ) ) {
+		fprintf( stderr, "Error initialising StgDomain, exiting.\n" );
+		exit( EXIT_FAILURE );
+	}
+	if (!StgFEM_Init( &argc, &argv ) ) {
+		fprintf( stderr, "Error initialising StgFEM, exiting.\n" );
+		exit( EXIT_FAILURE );
+	}
+	if (!PICellerator_Init( &argc, &argv ) ) {
+		fprintf( stderr, "Error initialising PICellerator, exiting.\n" );
+		exit( EXIT_FAILURE );
+	}	
+	Underworld_Init( &argc, &argv );
+	MPI_Barrier( CommWorld ); /* Ensures copyright info always come first in output */
+
+	if( argc >= 2 ) {
+		procToWatch = atoi( argv[1] );
+	}
+	else {
+		procToWatch = 0;
+	}
+	if( rank == procToWatch ) {
+		Stg_Object* testDirectory;
+
+		printf( "Watching rank: %i\n", rank );
+		/* Testing entries in xmlSearchPaths */
+		testDirectory = Stg_ObjectList_Get( xmlSearchPaths, (Name)"StGermain" );
+		if (testDirectory != NULL) {
+			printf("StGermain XML library Path found.\n");
+		}
+		else {
+			printf("StGermain XML library Path not found.\n"); 
+		}
+		/* For build in the same build directory */
+		if (strcmp((char* )LIB_DIR, (char*)testDirectory)) {
+			printf("StgDomain XML library Path found.\n");
+		}
+		/* For build in separate directories */
+		else{
+			testDirectory = Stg_ObjectList_Get( xmlSearchPaths, (Name)"StgDomain" );
+			if (testDirectory != NULL) {
+				printf("StgDomain XML library Path found.\n");
+			}
+			else {
+				printf("StgDomain XML library Path not found.\n"); 
+			}
+		}
+		if (strcmp((char* )LIB_DIR, (char*)testDirectory)) {
+			printf("StgFEM XML library Path found.\n");
+		}
+		/* For build in separate directories */
+		else{
+			testDirectory = Stg_ObjectList_Get( xmlSearchPaths, (Name)"StgFEM" );
+			if (testDirectory != NULL) {
+				printf("StgFEM XML library Path found.\n");
+			}
+			else {
+				printf("StgFEM XML library Path not found.\n"); 
+			}
+		}
+		/* For build in the same build directory */
+		if (strcmp((char* )LIB_DIR, (char*)testDirectory)) {
+			printf("PICellerator XML library Path found.\n");
+		}
+		/* For build in separate directories */
+		else{
+			testDirectory = Stg_ObjectList_Get( xmlSearchPaths, (Name)"PICellerator" );
+			if (testDirectory != NULL) {
+				printf("PICellerator XML library Path found.\n");
+			}
+			else {
+				printf("PICellerator XML library Path not found.\n"); 
+			}
+		}
+		/* For build in the same build directory */
+		if (strcmp((char* )LIB_DIR, (char*)testDirectory)) {
+			printf("Underworld XML library Path found.\n");
+		}
+		/* For build in separate directories */
+		else{
+			testDirectory = Stg_ObjectList_Get( xmlSearchPaths, (Name)"Underworld" );
+			if (testDirectory != NULL) {
+				printf("Underworld XML library Path found.\n");
+			}
+			else {
+				printf("Underworld XML library Path not found.\n"); 
+			}
+		}		
+	}
+	Underworld_Finalise();
+	PICellerator_Finalise(); 
+	StgFEM_Finalise();
+	StgDomain_Finalise();
+	StGermain_Finalise();
+	
+	/* Close off MPI */
+	MPI_Finalize( );
+
+	return 0; /* success */
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d plugins/DensityChangeAtDepth/DensityChangeAtDepth.c
--- a/plugins/DensityChangeAtDepth/DensityChangeAtDepth.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,167 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id:  $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Underworld.h>
-#include <assert.h>
-
-
-const Type Underworld_DensityChange_Type = "Underworld_DensityChange";
-
-typedef struct { 
-	__Codelet
-	BuoyancyForceTerm_MaterialExt* bftExt;
-	IntegrationPointsSwarm*     swarm;
-	Material*  material;
-	double     height;
-	double     newDensity;
-} Underworld_DensityChange;
-
-void Underworld_DensityChange_Check( UnderworldContext* context ) {
-	/* Function runs each timestep to check if centroid is at certain height */
-
-	double volume;
-	double centroid[3];
-	static int densityChangeIsDone = 0;
-
-	/* test if this has already happened, if so leave function */
-	if ( densityChangeIsDone )
-		return;
-
-	/* Get self (the plugin) */
-	Underworld_DensityChange* self = (Underworld_DensityChange*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_DensityChange_Type  );
-
-	/* get centroid coordinate */
-	volume = Material_Volume( self->material, (IntegrationPointsSwarm*)self->swarm, centroid );
-
-	/* test if centroid height (y-coord) is >= input height
-	 * 	Note following code is only run once */
-	if( centroid[1] >= self->height ) {
-		self->bftExt->density = self->newDensity;
-		densityChangeIsDone = 1;
-		Journal_RPrintf( Journal_Register( Info_Type, (Name)"DensityChange"  ), 
-				"************** Density Change for material %s, new density is %g**************\n",
-				self->material->name, self->bftExt->density );
-	}
-
-}
-void Underworld_DensityChange_Setup( UnderworldContext* context ) {
-		/* Function pulls and checks user input from the xml file */
-	BuoyancyForceTerm*  bft = NULL;
-	BuoyancyForceTerm_MaterialExt* materialExt = NULL;;
-	Stream* stream = Journal_Register( Info_Type, (Name)"cows" );
-	Name   materialName = NULL;
-	int materialIndex;
-
-	/* Get self (the plugin) */
-	Underworld_DensityChange* self = (Underworld_DensityChange* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_DensityChange_Type  ); 
-
-	/* Initialise plugin data */
-	self->bftExt = NULL;
-	self->swarm = NULL;
-	self->material = NULL;
-	self->height = 0;
-	self->newDensity = 0;
-
-	/* Need buoyancy force term, to get density infomation from bft extension + the integration swarm */
-	bft = Stg_ComponentFactory_ConstructByName( context->CF, (Name)"buoyancyForceTerm", BuoyancyForceTerm, True, NULL  );
-
-	/* Read in input from root xml dictionary */
-	self->height = Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"materialDensityChangeHeight", 0.5  );
-	self->newDensity = Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"materialDensityNewDensity", 0.3 );
-	self->swarm = (IntegrationPointsSwarm* )bft->integrationSwarm;
-	materialName = Dictionary_GetString( context->dictionary, (Dictionary_Entry_Key)"materialDensityToChange"  );
-	self->material = Materials_Register_GetByName( self->swarm->materials_Register, materialName );
-
-	/* check if material index exists */
-	if( self->material==NULL ) {
-		printf("Error\nCounld find the material with index %d\n", materialIndex ); exit(0);
-	}
-	materialExt = (BuoyancyForceTerm_MaterialExt*)ExtensionManager_Get( self->material->extensionMgr, self->material, bft->materialExtHandle );
-	Journal_RPrintf( stream, "Will change %s's density at height %g from %g to %g\n", 
-			self->material->name, self->height, materialExt->density, self->newDensity );
-
-	self->bftExt = materialExt;
-}
-
-void _Underworld_DensityChange_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
-	UnderworldContext* context;
-
-	context = (UnderworldContext*)Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data  ); 
-
-	/* Add functions to entry points */
-	ContextEP_Append( context, AbstractContext_EP_Initialise, Underworld_DensityChange_Setup );
-	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, Underworld_DensityChange_Check );
-	
-}
-
-void* _Underworld_DensityChange_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof( Underworld_DensityChange );
-	Type                                                      type = Underworld_DensityChange_Type;
-	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
-	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
-	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_DensityChange_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Underworld_DensityChange_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 Underworld_DensityChangeAtDepth_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Underworld_DensityChange_Type, (Name)"0", _Underworld_DensityChange_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d plugins/DensityChangeAtDepth/DensityChangeAtDepth.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/DensityChangeAtDepth/DensityChangeAtDepth.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,167 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id:  $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Underworld.h>
+#include <assert.h>
+
+
+const Type Underworld_DensityChange_Type = "Underworld_DensityChange";
+
+typedef struct { 
+	__Codelet
+	BuoyancyForceTerm_MaterialExt* bftExt;
+	IntegrationPointsSwarm*     swarm;
+	Material*  material;
+	double     height;
+	double     newDensity;
+} Underworld_DensityChange;
+
+void Underworld_DensityChange_Check( UnderworldContext* context ) {
+	/* Function runs each timestep to check if centroid is at certain height */
+
+	double volume;
+	double centroid[3];
+	static int densityChangeIsDone = 0;
+
+	/* test if this has already happened, if so leave function */
+	if ( densityChangeIsDone )
+		return;
+
+	/* Get self (the plugin) */
+	Underworld_DensityChange* self = (Underworld_DensityChange*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_DensityChange_Type  );
+
+	/* get centroid coordinate */
+	volume = Material_Volume( self->material, (IntegrationPointsSwarm*)self->swarm, centroid );
+
+	/* test if centroid height (y-coord) is >= input height
+	 * 	Note following code is only run once */
+	if( centroid[1] >= self->height ) {
+		self->bftExt->density = self->newDensity;
+		densityChangeIsDone = 1;
+		Journal_RPrintf( Journal_Register( Info_Type, (Name)"DensityChange"  ), 
+				"************** Density Change for material %s, new density is %g**************\n",
+				self->material->name, self->bftExt->density );
+	}
+
+}
+void Underworld_DensityChange_Setup( UnderworldContext* context ) {
+		/* Function pulls and checks user input from the xml file */
+	BuoyancyForceTerm*  bft = NULL;
+	BuoyancyForceTerm_MaterialExt* materialExt = NULL;;
+	Stream* stream = Journal_Register( Info_Type, (Name)"cows" );
+	Name   materialName = NULL;
+	int materialIndex;
+
+	/* Get self (the plugin) */
+	Underworld_DensityChange* self = (Underworld_DensityChange* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_DensityChange_Type  ); 
+
+	/* Initialise plugin data */
+	self->bftExt = NULL;
+	self->swarm = NULL;
+	self->material = NULL;
+	self->height = 0;
+	self->newDensity = 0;
+
+	/* Need buoyancy force term, to get density infomation from bft extension + the integration swarm */
+	bft = Stg_ComponentFactory_ConstructByName( context->CF, (Name)"buoyancyForceTerm", BuoyancyForceTerm, True, NULL  );
+
+	/* Read in input from root xml dictionary */
+	self->height = Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"materialDensityChangeHeight", 0.5  );
+	self->newDensity = Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"materialDensityNewDensity", 0.3 );
+	self->swarm = (IntegrationPointsSwarm* )bft->integrationSwarm;
+	materialName = Dictionary_GetString( context->dictionary, (Dictionary_Entry_Key)"materialDensityToChange"  );
+	self->material = Materials_Register_GetByName( self->swarm->materials_Register, materialName );
+
+	/* check if material index exists */
+	if( self->material==NULL ) {
+		printf("Error\nCounld find the material with index %d\n", materialIndex ); exit(0);
+	}
+	materialExt = (BuoyancyForceTerm_MaterialExt*)ExtensionManager_Get( self->material->extensionMgr, self->material, bft->materialExtHandle );
+	Journal_RPrintf( stream, "Will change %s's density at height %g from %g to %g\n", 
+			self->material->name, self->height, materialExt->density, self->newDensity );
+
+	self->bftExt = materialExt;
+}
+
+void _Underworld_DensityChange_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
+	UnderworldContext* context;
+
+	context = (UnderworldContext*)Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data  ); 
+
+	/* Add functions to entry points */
+	ContextEP_Append( context, AbstractContext_EP_Initialise, Underworld_DensityChange_Setup );
+	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, Underworld_DensityChange_Check );
+	
+}
+
+void* _Underworld_DensityChange_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof( Underworld_DensityChange );
+	Type                                                      type = Underworld_DensityChange_Type;
+	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
+	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
+	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_DensityChange_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Underworld_DensityChange_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 Underworld_DensityChangeAtDepth_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Underworld_DensityChange_Type, (Name)"0", _Underworld_DensityChange_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d plugins/EulerDeform/EulerDeform.c
--- a/plugins/EulerDeform/EulerDeform.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1529 +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)
-**	David May, PhD Student Monash University, VPAC. (david.may at sci.maths.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)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: LevelSetPlg.c 200 2005-07-08 08:24:41Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Underworld.h>
-
-#include "types.h"
-#include "Context.h"
-#include "EulerDeform.h"
-
-
-Name		EULERDEFORM_PLUGIN_TAG = "EulerDeform";
-const Type		Underworld_EulerDeform_Type = "EulerDeform";
-ExtensionInfo_Index	EulerDeform_ContextHandle;
-
-
-Index Underworld_EulerDeform_Register( PluginsManager* pluginsMgr ) {
-	return PluginsManager_Submit( pluginsMgr, Underworld_EulerDeform_Type, (Name)"0", _Underworld_EulerDeform_DefaultNew );
-}
-
-
-void* _Underworld_EulerDeform_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Codelet);
-	Type                                                      type = Underworld_EulerDeform_Type;
-	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
-	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
-	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_EulerDeform_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Underworld_EulerDeform_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _Underworld_EulerDeform_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _Codelet_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _Codelet_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _Underworld_EulerDeform_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   );
-}
-
-
-void _Underworld_EulerDeform_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
-	Codelet*					ed = (Codelet*)component;
-	UnderworldContext*	uwCtx;
-	EulerDeform_Context*	edCtx;
-
-	assert( component );
-	assert( cf );
-
-	Journal_DPrintf( Underworld_Debug, "In: %s( void* )\n", __func__ );
-
-	/* Retrieve context. */
-	uwCtx = (UnderworldContext*)Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data );
-	ed->context = (AbstractContext* )uwCtx;
-
-	/* Create new context. */
-	EulerDeform_ContextHandle = ExtensionManager_Add( uwCtx->extensionMgr, (Name)Underworld_EulerDeform_Type, sizeof(EulerDeform_Context)  );
-	edCtx = (EulerDeform_Context*)ExtensionManager_Get( uwCtx->extensionMgr, uwCtx, EulerDeform_ContextHandle );
-	memset( edCtx, 0, sizeof(EulerDeform_Context) );
-	edCtx->ctx = (AbstractContext*)uwCtx;
-
-	/* Get the time integrator. */
-	edCtx->timeIntegrator = Stg_ComponentFactory_ConstructByName( cf, (Name)"timeIntegrator", TimeIntegrator, True, data  );
-
-	/* Grab the ArtDisplacementField from the dictionary */
-	edCtx->artDField = Stg_ComponentFactory_ConstructByName( cf, (Name)"ArtDisplacementField", FeVariable, False, data  );
-}
-
-
-void _Underworld_EulerDeform_Build( void* component, void* data ) {
-	Codelet*						ed	= (Codelet*)component;
-	UnderworldContext*		uwCtx	= (UnderworldContext*)ed->context;
-	EulerDeform_Context*		edCtx;
-	Variable*					crdVar;
-	TimeIntegrand*			crdAdvector;
-	Stg_Component*				tiData[2];
-	unsigned						sys_i;
-	Dictionary_Entry_Value*	edDict;
-	Dictionary_Entry_Value*	sysLst;
-
-	assert( component );
-	assert( uwCtx );
-
-	edCtx = (EulerDeform_Context*)ExtensionManager_Get( uwCtx->extensionMgr, uwCtx, EulerDeform_ContextHandle );
-
-	/* Get the dictionary. */
-	edDict = Dictionary_Get( uwCtx->dictionary, (Dictionary_Entry_Key)"EulerDeform" );
-	if( !edDict  ) {
-		return;
-	}
-
-	/* Read system list. */
-	sysLst = Dictionary_Entry_Value_GetMember( edDict, (Dictionary_Entry_Key)"systems" );
-	if( sysLst ) {
-		unsigned	sys_i;
-
-		/* Allocate for systems. */
-		edCtx->nSystems = Dictionary_Entry_Value_GetCount( sysLst  );
-		edCtx->systems = Memory_Alloc_Array( EulerDeform_System, edCtx->nSystems, "EulerDeform->systems" );
-		memset( edCtx->systems, 0, sizeof(EulerDeform_System) * edCtx->nSystems );
-
-		for( sys_i = 0; sys_i < edCtx->nSystems; sys_i++ ) {
-			EulerDeform_System*		sys = edCtx->systems + sys_i;
-			Dictionary*					sysDict;
-			Dictionary_Entry_Value*	varLst;
-			char*							meshName;
-			char*							remesherName;
-			char*							velFieldName;
-			char*							name;
-
-			/* Get the dictionary for this system. */
-			sysDict = Dictionary_Entry_Value_AsDictionary( Dictionary_Entry_Value_GetElement( sysLst, sys_i ) );
-			assert( sysDict );
-
-			/* Read contents. */
-			meshName = Dictionary_GetString( sysDict, (Dictionary_Entry_Key)"mesh"  );
-			remesherName = Dictionary_GetString( sysDict, (Dictionary_Entry_Key)"remesher"  );
-
-			if( strcmp( remesherName, "" ) )
-				sys->remesher = Stg_ComponentFactory_ConstructByName( uwCtx->CF, (Name)remesherName, Remesher, True, data  );
-			name = Dictionary_GetString( sysDict, (Dictionary_Entry_Key)"displacementField" );
-
-			if(strcmp(name, ""))
-			    sys->dispField = Stg_ComponentFactory_ConstructByName( uwCtx->CF, (Name)name, FeVariable, True, data  );
-			else
-			    sys->dispField = NULL;
-
-			velFieldName = Dictionary_GetString( sysDict, (Dictionary_Entry_Key)"VelocityField"  );
-			sys->interval = Dictionary_GetInt_WithDefault( sysDict, (Dictionary_Entry_Key)"interval", -1  );
-			sys->wrapTop = Dictionary_GetBool_WithDefault( sysDict, (Dictionary_Entry_Key)"wrapTop", False  );
-			sys->wrapBottom = Dictionary_GetBool_WithDefault( sysDict, (Dictionary_Entry_Key)"wrapBottom", False  );
-			sys->wrapLeft = Dictionary_GetBool_WithDefault( sysDict, (Dictionary_Entry_Key)"wrapLeft", False  );
-			sys->mesh = Stg_ComponentFactory_ConstructByName( uwCtx->CF, (Name)meshName, Mesh, True, data  );
-			/* This line is currently not working, have to manually set the velocity field name.
-				This should be fixed once this plugin has been converted to a component. */
-			/*sys->velField = Stg_ComponentFactory_ConstructByName( uwCtx->CF, (Name)velFieldName, FieldVariable, True, data  );*/
-			sys->velField = Stg_ComponentFactory_ConstructByName( uwCtx->CF, (Name)"VelocityField", FieldVariable, True, data  );
-
-			sys->staticTop = Dictionary_GetBool_WithDefault( sysDict, (Dictionary_Entry_Key)"staticTop", False  );
-			sys->staticBottom = Dictionary_GetBool_WithDefault( sysDict, (Dictionary_Entry_Key)"staticBottom", False  );
-			sys->staticLeft = Dictionary_GetBool_WithDefault( sysDict, (Dictionary_Entry_Key)"staticLeft", False  );
-			sys->staticRight = Dictionary_GetBool_WithDefault( sysDict, (Dictionary_Entry_Key)"staticRight", False  );
-			sys->staticFront = Dictionary_GetBool_WithDefault( sysDict, (Dictionary_Entry_Key)"staticFront", False  );
-			sys->staticBack = Dictionary_GetBool_WithDefault( sysDict, (Dictionary_Entry_Key)"staticBack", False  );
-
-			sys->staticLeftTop = Dictionary_GetBool_WithDefault( sysDict, "staticLeftTop", (sys->staticLeft && sys->staticTop)
-                                                                             ? True : False);
-			sys->staticRightTop = Dictionary_GetBool_WithDefault( sysDict, "staticRightTop", (sys->staticRight && sys->staticTop)
-                                                                             ? True : False );
-			sys->staticLeftTopFront = Dictionary_GetBool_WithDefault( sysDict, "staticLeftTopFront",
-                                                                                  (sys->staticLeft && sys->staticTop && sys->staticFront)
-                                                                             ? True : False );
-			sys->staticRightTopFront = Dictionary_GetBool_WithDefault( sysDict, "staticRightTopFront",
-                                                                                   (sys->staticRight && sys->staticTop && sys->staticFront)
-                                                                             ? True : False );
-			sys->staticLeftTopBack = Dictionary_GetBool_WithDefault( sysDict, "staticLeftTopBack",
-                                                                                  (sys->staticLeft && sys->staticTop && sys->staticBack)
-                                                                             ? True : False );
-			sys->staticRightTopBack = Dictionary_GetBool_WithDefault( sysDict, "staticRightTopBack",
-                                                                                   (sys->staticRight && sys->staticTop && sys->staticBack)
-                                                                             ? True : False );
-
-			sys->staticLeftBottom = Dictionary_GetBool_WithDefault( sysDict, "staticLeftBottom", (sys->staticLeft && sys->staticBottom)
-                                                                             ? True : False );
-			sys->staticRightBottom = Dictionary_GetBool_WithDefault( sysDict, "staticRightBottom", (sys->staticRight && sys->staticBottom)
-                                                                             ? True : False );
-			sys->staticLeftBottomFront = Dictionary_GetBool_WithDefault( sysDict, "staticLeftBottomFront",
-                                                                                  (sys->staticLeft && sys->staticBottom && sys->staticFront)
-                                                                             ? True : False );
-			sys->staticRightBottomFront = Dictionary_GetBool_WithDefault( sysDict, "staticRightBottomFront",
-                                                                                   (sys->staticRight && sys->staticBottom && sys->staticFront)
-                                                                             ? True : False );
-			sys->staticLeftBottomBack = Dictionary_GetBool_WithDefault( sysDict, "staticLeftBottomBack",
-                                                                                  (sys->staticLeft && sys->staticBottom && sys->staticBack)
-                                                                             ? True : False );
-			sys->staticRightBottomBack = Dictionary_GetBool_WithDefault( sysDict, "staticRightBottomBack",
-                                                                                   (sys->staticRight && sys->staticBottom && sys->staticBack)
-                                                                             ? True : False );
-
-			sys->staticLeftFront = Dictionary_GetBool_WithDefault( sysDict, "staticLeftFront", (sys->staticLeft && sys->staticFront)
-                                                                             ? True : False );
-			sys->staticRightFront = Dictionary_GetBool_WithDefault( sysDict, "staticRightFront", (sys->staticRight && sys->staticFront)
-                                                                             ? True : False );
-			sys->staticLeftBack = Dictionary_GetBool_WithDefault( sysDict, "staticLeftBack", (sys->staticLeft && sys->staticBack)
-                                                                             ? True : False );
-			sys->staticRightBack = Dictionary_GetBool_WithDefault( sysDict, "staticRightBack", (sys->staticRight && sys->staticBack)
-                                                                             ? True : False );
-
-			sys->staticTopFront = Dictionary_GetBool_WithDefault( sysDict, "staticTopFront", (sys->staticTop && sys->staticFront)
-                                                                             ? True : False );
-			sys->staticBottomFront = Dictionary_GetBool_WithDefault( sysDict, "staticBottomFront", (sys->staticBottom && sys->staticFront)
-                                                                             ? True : False );
-			sys->staticTopBack = Dictionary_GetBool_WithDefault( sysDict, "staticTopBack", (sys->staticTop && sys->staticBack)
-                                                                             ? True : False );
-			sys->staticBottomBack = Dictionary_GetBool_WithDefault( sysDict, "staticBottomBack", (sys->staticBottom && sys->staticBack)
-                                                                             ? True : False );
-
-			sys->floatLeftTop = Dictionary_GetBool_WithDefault( sysDict, "floatLeftTop", False );
-			sys->floatRightTop = Dictionary_GetBool_WithDefault( sysDict, "floatRightTop", False );
-
-			sys->staticSides = 
-                          (sys->staticLeft
-                           || sys->staticRight
-                           || sys->staticTop
-                           || sys->staticBottom
-                           || sys->staticFront
-                           || sys->staticBack
-                           || sys->staticLeftTop
-                           || sys->staticRightTop
-                           || sys->staticLeftTopFront
-                           || sys->staticRightTopFront
-                           || sys->staticLeftTopBack
-                           || sys->staticRightTopBack
-                           || sys->staticLeftBottom
-                           || sys->staticRightBottom
-                           || sys->staticLeftBottomFront
-                           || sys->staticRightBottomFront
-                           || sys->staticLeftBottomBack
-                           || sys->staticRightBottomBack
-                           || sys->staticLeftFront
-                           || sys->staticRightFront
-                           || sys->staticLeftBack
-                           || sys->staticRightBack
-                           || sys->staticTopFront
-                           || sys->staticBottomFront
-                           || sys->staticTopBack
-                           || sys->staticBottomBack)
-                          ? True : False;
-
-
-                        if(sys->staticRight && sys->wrapTop
-                           && !sys->staticRightTop)
-                          sys->x_right_coord =
-                            Dictionary_GetDouble( uwCtx->dictionary, "maxX");
-
-                        if(sys->staticLeft && sys->wrapTop
-                           && !sys->staticLeftTop)
-                          sys->x_left_coord =
-                            Dictionary_GetDouble( uwCtx->dictionary, "minX");
-                          
-			/* Read the list of variables to interpolate. */
-			varLst = Dictionary_Entry_Value_GetMember( Dictionary_Entry_Value_GetElement( sysLst, sys_i  ), "fields" );
-
-			if( varLst ) {
-				unsigned	var_i;
-
-				sys->nFields = Dictionary_Entry_Value_GetCount( varLst );
-				sys->fields = Memory_Alloc_Array( FieldVariable*, sys->nFields, "EulerDeform->systems[].fields" );
-				sys->vars = Memory_Alloc_Array( Variable*, sys->nFields, "EulerDeform->systemsp[].vars" );
-
-				for( var_i = 0; var_i <sys->nFields; var_i++ ) {
-					Dictionary*	varDict;
-					char*			varName;
-
-					/* Get the dictionary for this field tuple. */
-					varDict = Dictionary_Entry_Value_AsDictionary( Dictionary_Entry_Value_GetElement( varLst, var_i ) );
-					assert( varDict );
-
-					/* Get the field and its variable. */
-					varName = Dictionary_GetString( varDict, (Dictionary_Entry_Key)"field"  );
-					sys->fields[var_i] = Stg_ComponentFactory_ConstructByName( uwCtx->CF, (Name)varName, FieldVariable, True, data  ); 
-					varName = Dictionary_GetString( varDict, (Dictionary_Entry_Key)"variable"  );
-					sys->vars[var_i] = Stg_ComponentFactory_ConstructByName( uwCtx->CF, (Name)varName, Variable, True, data ); 
-				}
-			}
-		}
-	}
-
-	for( sys_i = 0; sys_i < edCtx->nSystems; sys_i++  ) {
-		EulerDeform_System*	sys = edCtx->systems + sys_i;
-
-		/* Create a time integrand for the mesh's coordinates. */
-		crdVar = EulerDeform_RegisterLocalNodeCoordsAsVariables( sys, uwCtx->variable_Register, NULL );
-		Stg_Component_Build( crdVar, data, False );
-
-		tiData[0] = (Stg_Component*)sys->velField;
-		tiData[1] = (Stg_Component*)&sys->mesh->verts;
-		crdAdvector = TimeIntegrand_New( "EulerDeform_Velocity", (DomainContext*)uwCtx, edCtx->timeIntegrator, crdVar, 2, tiData, True
-			 /* Presume we need to allow fallback on edges of stretching mesh - PatrickSunter, 7 June 2006 */ );
-		crdAdvector->_calculateTimeDeriv = EulerDeform_TimeDeriv;
-
-		/* Add to live component register... */
-		LiveComponentRegister_Add( uwCtx->CF->LCRegister, (Stg_Component*)crdAdvector );
-		Stg_Component_Build( crdAdvector, data, False );
-	}
-
-	if( edCtx->nSystems > 0 ) {
-		/* Insert the sync step. */
-          TimeIntegrator_PrependSetupEP( edCtx->timeIntegrator, "EulerDeform_IntegrationSetup", (void*)EulerDeform_IntegrationSetup, "EulerDeform", edCtx );
-	}
-
-	/* Insert the remesh step. Note that this should look for the surface process
-	   plugin's time integrator finish routine and ensure we enter the remesh step
-	   after that one but before the particle updating routines. */
-	TimeIntegrator_PrependFinishEP( edCtx->timeIntegrator, "EulerDeform_Execute", (void*)EulerDeform_Remesh, "EulerDeform", edCtx );
-}
-
-
-void _Underworld_EulerDeform_Destroy( void* component, void* data ) {
-	Codelet*					ed	= (Codelet*)component;
-	UnderworldContext*	uwCtx = (UnderworldContext*)ed->context;
-
-	assert( component );
-	assert( uwCtx );
-
-	/* Clear the lot. */
-	/* TODO */
-}
-
-/* This creates a set which makes sure not to include the corners if
-   we have not made both sides of the corner static. */
-
-IndexSet* EulerDeform_CreateStaticSet(EulerDeform_System* sys)
-{
-  Grid*		grid;
-  unsigned	nNodes;
-  unsigned	n_i;
-  IndexSet	*set;
-  IJK			ijk;
-
-  grid = *(Grid**)ExtensionManager_Get ( sys->mesh->info, sys->mesh, ExtensionManager_GetHandle( sys->mesh->info, (Name)"vertexGrid" )  );
-
-  nNodes = Mesh_GetDomainSize( sys->mesh, MT_VERTEX );
-  set = IndexSet_New( nNodes );
-
-  for( n_i = 0; n_i < nNodes; n_i++ ) {
-    Bool add;
-    add=False;
-    RegularMeshUtils_Node_1DTo3D
-      ( sys->mesh, Mesh_DomainToGlobal( sys->mesh, MT_VERTEX, n_i ), ijk );
-
-    /* 2D */
-    if(sys->mesh->topo->nDims == 2)
-      {
-        /* Left side and Corner */
-        if(ijk[0]==0)
-          {
-            if(ijk[1]==0)
-              {
-                if(sys->staticLeftBottom)
-                  add=True;
-              }
-            else if(ijk[1]==grid->sizes[1]-1)
-              {
-                if(sys->staticLeftTop)
-                  add=True;
-              }
-            else if(sys->staticLeft)
-              add=True;
-          }
-        /* Right side and corner */
-        else if(ijk[0]==grid->sizes[0]-1)
-          {
-            if(ijk[1]==0)
-              {
-                if(sys->staticRightBottom)
-                  add=True;
-              }
-            else if(ijk[1]==grid->sizes[1]-1)
-              {
-                if(sys->staticRightTop)
-                  add=True;
-              }
-            else if(sys->staticRight)
-              add=True;
-          }
-        /* Top and Bottom */
-        else if((ijk[1]==0 && sys->staticBottom)
-                || (ijk[1]==grid->sizes[1]-1 && sys->staticTop))
-          add=True;
-      }
-    /* 3D */
-    else if(sys->mesh->topo->nDims == 3)
-      {
-        /* Left side */
-        if(ijk[0]==0)
-          {
-            /* Left Bottom */
-            if(ijk[1]==0)
-              {
-                if(ijk[2]==0)
-                  {
-                    if(sys->staticLeftBottomBack)
-                      add=True;
-                  }
-                else if(ijk[2]==grid->sizes[2]-1)
-                  {
-                    if(sys->staticLeftBottomFront)
-                      add=True;
-                  }
-                else if(sys->staticLeftBottom)
-                  add=True;
-              }
-            /* Left Top */
-            else if(ijk[1]==grid->sizes[1]-1)
-              {
-                if(ijk[2]==0)
-                  {
-                    if(sys->staticLeftTopBack)
-                      add=True;
-                  }
-                else if(ijk[2]==grid->sizes[2]-1)
-                  {
-                    if(sys->staticLeftTopFront)
-                      add=True;
-                  }
-                else if(sys->staticLeftTop)
-                  add=True;
-              }
-            /* Left Back */
-            else if(ijk[2]==0)
-              {
-                if(sys->staticLeftBack)
-                  add=True;
-              }
-            /* Left Front */
-            else if(ijk[2]==grid->sizes[2]-1)
-              {
-                if(sys->staticLeftFront)
-                  add=True;
-              }
-            /* Left */
-            else if(sys->staticLeft)
-              add=True;
-          }
-        /* Right side */
-        else if(ijk[0]==grid->sizes[0]-1)
-          {
-            /* Right Bottom */
-            if(ijk[1]==0)
-              {
-                if(ijk[2]==0)
-                  {
-                    if(sys->staticRightBottomBack)
-                      add=True;
-                  }
-                else if(ijk[2]==grid->sizes[2]-1)
-                  {
-                    if(sys->staticRightBottomFront)
-                      add=True;
-                  }
-                else if(sys->staticRightBottom)
-                  add=True;
-              }
-            /* Right Top */
-            else if(ijk[1]==grid->sizes[1]-1)
-              {
-                if(ijk[2]==0)
-                  {
-                    if(sys->staticRightTopBack)
-                      add=True;
-                  }
-                else if(ijk[2]==grid->sizes[2]-1)
-                  {
-                    if(sys->staticRightTopFront)
-                      add=True;
-                  }
-                else if(sys->staticRightTop)
-                  add=True;
-              }
-            /* Right Back */
-            else if(ijk[2]==0)
-              {
-                if(sys->staticRightBack)
-                  add=True;
-              }
-            /* Right Front */
-            else if(ijk[2]==grid->sizes[2]-1)
-              {
-                if(sys->staticRightFront)
-                  add=True;
-              }
-            /* Right */
-            else if(sys->staticRight)
-              add=True;
-          }
-        /* Bottom */
-        else if(ijk[1]==0)
-          {
-            if(ijk[2]==0)
-              {
-                if(sys->staticBottomBack)
-                  add=True;
-              }
-            else if(ijk[2]==grid->sizes[2]-1)
-              {
-                if(sys->staticBottomFront)
-                  add=True;
-              }
-            else if(sys->staticBottom)
-              add=True;
-          }
-        /* Top */
-        else if(ijk[1]==grid->sizes[1]-1)
-          {
-            if(ijk[2]==0)
-              {
-                if(sys->staticTopBack)
-                  add=True;
-              }
-            else if(ijk[2]==grid->sizes[2]-1)
-              {
-                if(sys->staticTopFront)
-                  add=True;
-              }
-            else if(sys->staticTop)
-              add=True;
-          }
-        /*  Front and Back */
-        else if((ijk[2]==0 && sys->staticBack)
-                || (ijk[2]==grid->sizes[2]-1 && sys->staticFront))
-          add=True;
-      }
-
-    if( add )
-      IndexSet_Add( set, n_i );
-  }
-  return set;
-}
-
-Variable* EulerDeform_RegisterLocalNodeCoordsAsVariables( EulerDeform_System* sys, void* _variable_Register, Variable** variableList ) {
-	FeMesh*					self = (FeMesh*)sys->mesh;
-	Variable_Register*	variable_Register = (Variable_Register*) _variable_Register;
-	Variable*				variable;
-	char*						variableName;
-	char*						variableNameX;
-	char*						variableNameY;
-	char*						variableNameZ;
-
-	/* Allocate advection array. */
-	sys->verts = AllocArray( double, Mesh_GetLocalSize( self, MT_VERTEX ) * Mesh_GetDimSize( self ) );
-	
-	/* Append Extension onto names */
-	variableName  = Memory_Alloc_Array( char, strlen( self->name ) + strlen( "NodeCoords" ) + 1, "variableName" );
-	sprintf( variableName , "%sNodeCoords", self->name );
-	
-	variableNameX = Memory_Alloc_Array( char, strlen( self->name ) + strlen( "NodeCoordX" ) + 1, "variableNameX" );
-	sprintf( variableNameX, "%sNodeCoordX", self->name );
-
-	variableNameY = Memory_Alloc_Array( char, strlen( self->name ) + strlen( "NodeCoordY" ) + 1, "variableNameY" );
-	sprintf( variableNameY, "%sNodeCoordY", self->name );
-
-	variableNameZ = Memory_Alloc_Array( char, strlen( self->name ) + strlen( "NodeCoordZ" ) + 1, "variableNameZ" );
-	sprintf( variableNameZ, "%sNodeCoordZ", self->name );
-	
-	/* Construct */
-	variable = Variable_NewVector( 
-		variableName, 
-		self->context,	
-		Variable_DataType_Double, 
-		Mesh_GetDimSize( self ), 
-		(unsigned*)&((IGraph*)self->topo)->remotes[MT_VERTEX]->decomp->locals->size, 
-		NULL,
-		(void**)&sys->verts, 
-		variable_Register, 
-		variableNameX,
-		variableNameY,
-		variableNameZ );
-
-	if ( variableList != NULL ) {
-		variableList[ I_AXIS ] = Variable_Register_GetByName( variable_Register, variableNameX );
-		variableList[ J_AXIS ] = Variable_Register_GetByName( variable_Register, variableNameY );
-		variableList[ K_AXIS ] = Variable_Register_GetByName( variable_Register, variableNameZ );
-	}
-
-	/* Clean Up */
-	Memory_Free( variableNameZ );
-	Memory_Free( variableNameY );
-	Memory_Free( variableNameX );
-	Memory_Free( variableName );
-
-	return variable;
-}
-
-
-void EulerDeform_IntegrationSetup( void* _timeIntegrator, void* context ) {
-	EulerDeform_Context*	edCtx = (EulerDeform_Context*)context;
-	unsigned					sys_i;
-
-	FeVariable_SyncShadowValues( edCtx->systems[0].velField );
-
-	/* 
-	** We'll need to store side values that we require to be static here, for later
-	** return to the mesh.
-	*/
-
-	for( sys_i = 0; sys_i < edCtx->nSystems; sys_i++ ) {
-		EulerDeform_System* sys = edCtx->systems + sys_i;
-
-		if( sys->staticSides ) {
-			IndexSet	*tmpIndSet;
-			unsigned	nInds, *inds;
-			unsigned	nDims;
-			unsigned	ind_i;
-
-			/* Collect indices of all the sides. */
-
-                        tmpIndSet = EulerDeform_CreateStaticSet(sys);
-                        IndexSet_GetMembers( tmpIndSet, &nInds, &inds );
-
-			/* Copy coords to temporary array. */
-			nDims = Mesh_GetDimSize( sys->mesh );
-			sys->sideCoords = AllocArray2D( double, nInds, nDims );
-			for( ind_i = 0; ind_i < nInds; ind_i++ )
-				memcpy( sys->sideCoords[ind_i], sys->mesh->verts[inds[ind_i]], nDims * sizeof(double) );
-                        FreeObject( tmpIndSet );
-                        FreeArray( inds );
-		}
-	}
-
-	/* Update advection arrays. */
-	for( sys_i = 0; sys_i < edCtx->nSystems; sys_i++ ) {
-		EulerDeform_System*	sys = edCtx->systems + sys_i;
-		unsigned					nDims;
-		unsigned					nLocalNodes;
-		unsigned					n_i;
-
-		nDims = Mesh_GetDimSize( sys->mesh );
-		nLocalNodes = Mesh_GetLocalSize( sys->mesh, MT_VERTEX );
-
-		for( n_i = 0; n_i < nLocalNodes; n_i++ )
-			memcpy( sys->verts + n_i * nDims, sys->mesh->verts[n_i], nDims * sizeof(double) );
-	}
-}
-
-
-Bool EulerDeform_TimeDeriv( void* crdAdvector, Index arrayInd, double* timeDeriv ) {
-	TimeIntegrand*		self = (TimeIntegrand*)crdAdvector;
-	FeVariable*				velocityField = (FeVariable*)self->data[0];
-	InterpolationResult	result = LOCAL;
-
-	/* check if the node information is on the local proc */
-	if (arrayInd >= Mesh_GetDomainSize(velocityField->feMesh,MT_VERTEX) )
-		result = OTHER_PROC;
-
-	FeVariable_GetValueAtNode( velocityField, arrayInd, timeDeriv );
-
-	/* Check if periodic */
-	if ( Stg_Class_IsInstance( velocityField->feMesh->generator, CartesianGenerator_Type ) ) {
-		CartesianGenerator* cartesianGenerator = (CartesianGenerator*) velocityField->feMesh->generator;
-		if ( cartesianGenerator->periodic[ I_AXIS ] )
-			timeDeriv[I_AXIS] = 0.0;
-		if ( cartesianGenerator->periodic[ J_AXIS ] )
-			timeDeriv[J_AXIS] = 0.0;
-		if ( cartesianGenerator->periodic[ K_AXIS ] )
-			timeDeriv[K_AXIS] = 0.0;
-	}
-		
-	if ( result == OTHER_PROC || result == OUTSIDE_GLOBAL || isinf(timeDeriv[0]) || isinf(timeDeriv[1]) || 
-	     ( velocityField->dim == 3 && isinf(timeDeriv[2]) ) ) 
-	{
-#if 0
-		Journal_Printf( Journal_Register( Error_Type, (Name)self->type  ),
-				"Error in func '%s' for particle with index %u.\n\tPosition (%g, %g, %g)\n\tVelocity here is (%g, %g, %g)."
-				"\n\tInterpolation result is %s.\n",
-				__func__, array_I, coord[0], coord[1], coord[2], 
-
-				InterpolationResultToStringMap[result]  );
-#endif	
-		return False;	
-	}
-
-	return True;
-}
-
-Bool _EulerDeform_LineInterp(double** crds,const double* pnt,
-                             unsigned fromDim,unsigned toDim, 
-			     double* val);
-Bool _EulerDeform_QuadYInterp(double** crds,const double* pnt,double* val);
-
-/* Make the top left or right corners float up to the height of the
-   point just inside. */
-
-void EulerDeform_FloatRightTop(EulerDeform_System* sys, Grid *grid,
-                               double** crds)
-{
-  int i, max_z;
-  IJK ijk, inside_ijk;
-  unsigned ind, nLocalNodes, inside;
-
-  nLocalNodes = Mesh_GetLocalSize( sys->mesh, MT_VERTEX );
-  ijk[0]=grid->sizes[0]-1;
-  ijk[1]=grid->sizes[1]-1;
-
-  if(Mesh_GetDimSize(sys->mesh)==2)
-    {
-      max_z=1;
-    }
-  else
-    {
-      max_z=grid->sizes[2];
-    }
-
-  for(i=0;i<max_z;++i)
-    {
-      ijk[2]=i;
-      ind=Grid_Project(grid,ijk);
-      if( !(!Mesh_GlobalToDomain( sys->mesh, MT_VERTEX, ind, &ind )
-            || ind >= nLocalNodes ))
-        {
-          inside_ijk[0]=ijk[0]-1;
-          inside_ijk[1]=ijk[1];
-          inside_ijk[2]=ijk[2];
-          inside=Grid_Project(grid,inside_ijk);
-          if(!(!Mesh_GlobalToDomain( sys->mesh, MT_VERTEX, inside, &inside )
-               || inside >= nLocalNodes ))
-            {
-              crds[ind][1]=crds[inside][1];
-            }
-        }
-    }
-}
-
-void EulerDeform_FloatLeftTop(EulerDeform_System* sys, Grid *grid,
-                              double** crds)
-{
-  int i, max_z;
-  IJK ijk, inside_ijk;
-  unsigned ind, nLocalNodes, inside;
-
-  nLocalNodes = Mesh_GetLocalSize( sys->mesh, MT_VERTEX );
-  ijk[0]=0;
-  ijk[1]=grid->sizes[1]-1;
-
-  if(Mesh_GetDimSize(sys->mesh)==2)
-    {
-      max_z=1;
-    }
-  else
-    {
-      max_z=grid->sizes[2];
-    }
-
-  for(i=0;i<max_z;++i)
-    {
-      ijk[2]=i;
-      ind=Grid_Project(grid,ijk);
-      if( !(!Mesh_GlobalToDomain( sys->mesh, MT_VERTEX, ind, &ind )
-            || ind >= nLocalNodes ))
-        {
-          inside_ijk[0]=ijk[0]+1;
-          inside_ijk[1]=ijk[1];
-          inside_ijk[2]=ijk[2];
-          inside=Grid_Project(grid,inside_ijk);
-          if(!(!Mesh_GlobalToDomain( sys->mesh, MT_VERTEX, inside, &inside )
-               || inside >= nLocalNodes ))
-            crds[ind][1]=crds[inside][1];
-        }
-    }
-}
-
-/* Remesh the left or right top corners in 2D or 3D */
-
-void EulerDeform_Remesh_Corner(Mesh *mesh, int corner, int inside,
-                               double side_coord) {
-  IJK		ijk;
-  Grid *grid;
-  grid =
-    *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-                                   ExtensionManager_GetHandle( mesh->info,
-                                                               "vertexGrid" ) );
-  ijk[0]=corner;
-  ijk[1]=grid->sizes[1]-1;
-  if(Mesh_GetDimSize(mesh)==2)
-    {
-      unsigned n_corner, n_interior, n, n_in;
-      n_corner=RegularMeshUtils_Node_3DTo1D(mesh,ijk);
-      ijk[0]=inside;
-      n_interior=RegularMeshUtils_Node_3DTo1D(mesh,ijk);
-      if(Mesh_GlobalToDomain(mesh,MT_VERTEX,
-                             n_corner,&n)
-         && Mesh_GlobalToDomain(mesh,MT_VERTEX,
-                                n_interior,&n_in))
-        {
-          double *crds[2];
-
-          crds[0]=mesh->verts[n];
-          crds[1]=mesh->verts[n_in];
-          if(!_EulerDeform_LineInterp(crds,&side_coord,0,1,
-                                       &(mesh->verts[n][1])))
-            {
-              printf("The side is moving in the wrong direction.\n");
-              printf("%g %g %g %g %g\n",side_coord,crds[0][0],crds[0][1],crds[1][0],crds[1][1]);
-              abort();
-            }
-          mesh->verts[n][0]=side_coord;
-        }
-    }
-  else /* 3D */
-    {
-      for(ijk[2]=0; ijk[2]<grid->sizes[2]; ++ijk[2])
-        {
-          unsigned n_corner, n_interior, n, n_in;
-          ijk[0]=corner;
-          n_corner=RegularMeshUtils_Node_3DTo1D(mesh,ijk);
-          ijk[0]=inside;
-          n_interior=RegularMeshUtils_Node_3DTo1D(mesh,ijk);
-          if(Mesh_GlobalToDomain(mesh,MT_VERTEX,n_corner,&n)
-             && Mesh_GlobalToDomain(mesh,MT_VERTEX,n_interior,&n_in))
-            {
-              double *crds[2];
-              crds[0]=mesh->verts[n];
-              crds[1]=mesh->verts[n_in];
-
-              if(!_EulerDeform_LineInterp(crds,&side_coord,0,1,&(mesh->verts[n][1]))
-                 || !_EulerDeform_LineInterp(crds,&side_coord,0,2,&(mesh->verts[n][2])))
-                {
-                  printf("The side is moving in the wrong direction.\n");
-                  printf("%g %g %g %g %g\n",side_coord,crds[0][0],crds[0][1],crds[1][0],crds[1][1]);
-                  abort();
-                }
-              mesh->verts[n][0]=side_coord;
-            }
-        }
-    }
-}
-
-void EulerDeform_WrapSurface( EulerDeform_System* sys, double** oldCrds, int top );
-
-void EulerDeform_Remesh( TimeIntegrand* crdAdvector, EulerDeform_Context* edCtx ) {
-  Mesh_Algorithms	*tmpAlgs, *oldAlgs;
-  unsigned	sys_i;
-
-  assert( edCtx );
-
-  /* We do the second system first, because that is the vertex
-     centered system.  We want the cell centered and vertex
-     centered systems to be compatible, so the cell centered
-     system is based on the vertex centered one. */
-
-  for( sys_i = 1; sys_i < edCtx->nSystems+1; sys_i++ ) {
-    EulerDeform_System*	sys = edCtx->systems
-      + sys_i%edCtx->nSystems;
-    double**		oldCrds;
-    double**		newCrds;
-    unsigned		nDomainNodes;
-    unsigned		nDims;
-    unsigned		var_i, n_i, dof_i;
-    Grid *grid;
-    grid =
-      *(Grid**)ExtensionManager_Get(sys->mesh->info, sys->mesh, 
-                                    ExtensionManager_GetHandle( sys->mesh->info,
-                                                                "vertexGrid" ));
-    /* Update the displacement field. */
-    if(sys->dispField) {
-      double disp[3];
-      int num_verts, num_dims;
-      int ii, jj;
-
-      num_dims = Mesh_GetDimSize(sys->mesh);
-      num_verts = Mesh_GetLocalSize(sys->mesh, MT_VERTEX);
-      for(ii = 0; ii < num_verts; ii++) {
-        FeVariable_GetValueAtNode(sys->dispField, ii, disp);
-        for(jj = 0; jj < num_dims; jj++)
-          disp[jj] += sys->verts[ii*num_dims + jj] - sys->mesh->verts[ii][jj];
-        FeVariable_SetValueAtNode(sys->dispField, ii, disp);
-      }
-    }
-
-    nDims = Mesh_GetDimSize( sys->mesh );
-    
-    /* Update all local coordinates. */
-    for( n_i = 0; n_i < Mesh_GetLocalSize( sys->mesh, MT_VERTEX ); n_i++ )
-      memcpy( sys->mesh->verts[n_i], sys->verts + n_i * nDims, nDims * sizeof(double) );
-    
-    /* Revert side coordinates if required. */
-    if( sys->staticSides ) {
-      IndexSet	*tmpIndSet;
-      unsigned	nInds, *inds;
-      unsigned	ind_i;
-      
-      /* Collect indices of all the sides. */
-      
-      tmpIndSet = EulerDeform_CreateStaticSet(sys);
-      IndexSet_GetMembers( tmpIndSet, &nInds, &inds );
-      
-      /* Copy back coords. */
-      for( ind_i = 0; ind_i < nInds; ind_i++ )
-        memcpy( sys->mesh->verts[inds[ind_i]], sys->sideCoords[ind_i], nDims * sizeof(double) );
-      FreeObject( tmpIndSet );
-      FreeArray( sys->sideCoords );
-      
-      if(sys->wrapTop)
-        {
-          if(sys->staticLeft && !sys->staticLeftTop && !sys->floatLeftTop)
-            {
-              EulerDeform_Remesh_Corner(sys->mesh,0,1,sys->x_left_coord);
-            }
-          if(sys->staticRight && !sys->staticRightTop && !sys->floatRightTop)
-            {
-              EulerDeform_Remesh_Corner(sys->mesh,grid->sizes[0]-1,
-                                        grid->sizes[0]-2,
-                                        sys->x_right_coord);
-            }
-        }
-
-    }
-
-    /* If we have regular mesh algorithms specified, set the
-       algorithms temporarily to an irregular method. */
-    if( !strcmp( sys->mesh->algorithms->type, "Mesh_RegularAlgorithms" ) && sys->remesher ) {
-      tmpAlgs = Mesh_Algorithms_New( "", edCtx->ctx );
-      oldAlgs = sys->mesh->algorithms;
-      sys->mesh->algorithms = NULL;
-      Mesh_SetAlgorithms( sys->mesh, tmpAlgs );
-    }
-    else
-      tmpAlgs = NULL;
-
-    /* Every system should synchronise the mesh coordinates. */
-    Mesh_Sync( sys->mesh );
-    Mesh_DeformationUpdate( sys->mesh );
-
-    /* Only if remesher specified. */
-    if( !sys->remesher ) {
-      continue;
-    }
-
-    /* If a remesh interval is requested, check now. */
-    if( sys->interval > 0 && edCtx->ctx->timeStep % sys->interval > 0 ) {
-      Journal_Printf( Underworld_Info,
-                      "*** EulerDeform: Not remeshing this timestep.\n" );
-      continue;
-    }
-    Journal_Printf( Underworld_Info, "*** EulerDeform: Remeshing.\n" );
-
-    /* Store old coordinates. */
-    nDomainNodes = FeMesh_GetNodeDomainSize( sys->mesh );
-    oldCrds = AllocArray2D( double, nDomainNodes, nDims );
-    for( n_i = 0; n_i < nDomainNodes; n_i++ )
-      memcpy( oldCrds[n_i], sys->mesh->verts[n_i], nDims * sizeof(double) );
-
-    /* Remesh the system. */
-    Stg_Component_Execute( sys->remesher, NULL, True );
-    Mesh_Sync( sys->mesh );
-
-    /* Shrink wrap the top/bottom surface. */
-    if( sys->wrapTop )
-      EulerDeform_WrapSurface( sys, oldCrds, 1 );
-    if( sys->wrapBottom )
-      EulerDeform_WrapSurface( sys, oldCrds, 0 );
-
-    /* Swap old coordinates back in temporarily. */
-    newCrds = sys->mesh->verts;
-    sys->mesh->verts = oldCrds;
-
-    /* Interpolate the variables. */
-    for( var_i = 0; var_i < sys->nFields; var_i++ )
-      EulerDeform_InterpVar( sys->fields[var_i],
-                             NULL/*sys->vars[var_i]*/, sys->mesh, newCrds );
-
-    /* Float the top left and right corners if needed.  We do this
-       after interpolating, because these points almost certainly are
-       outside of the domain, and so can not be interpolated to. */
-    if(sys->floatLeftTop)
-      EulerDeform_FloatLeftTop(sys,grid,newCrds);
-    if(sys->floatRightTop)
-      EulerDeform_FloatRightTop(sys,grid,newCrds);
-
-    /* Create an artificial displacement field from the nodal
-     * displacements between newCrds and oldCrds.  This displacement
-     * is currently used to correct the advDiffEqn's nodal velocity
-     * input */
-    if( edCtx->artDField ) {
-      double artDis[3]; /* temporary displacement vector */
-
-      for( n_i = 0 ; n_i < nDomainNodes; n_i++ ) {
-        for( dof_i = 0 ; dof_i < nDims ; dof_i++ ) {
-          artDis[dof_i] = newCrds[n_i][dof_i] - oldCrds[n_i][dof_i];
-        }
-        FeVariable_SetValueAtNode( edCtx->artDField, n_i, artDis );
-      }
-        
-    }
-
-    /* Swap back coordinates and free memory. */
-    sys->mesh->verts = newCrds;
-    FreeArray( oldCrds );
-    
-    /* Swap back old algorithms. */
-    if( tmpAlgs ) {
-      Mesh_SetAlgorithms( sys->mesh, oldAlgs );
-    }
-
-    /* Re-sync with new coordinates. */
-    Mesh_Sync( sys->mesh );
-    Mesh_DeformationUpdate( sys->mesh );
-    for( var_i = 0; var_i < sys->nFields; var_i++ )
-      FeVariable_SyncShadowValues( sys->fields[var_i] );
-  }
-}
-
-
-void EulerDeform_InterpVar( FieldVariable* field, Variable* var, Mesh* mesh, double** newCrds ) {
-	double*		newVals;
-	unsigned	curValInd = 0;
-	unsigned	nLocalNodes;
-	unsigned	n_i, c_i;
-
-	assert( field );
-	/*assert( var );*/
-	assert( newCrds );
-
-	/* Allocate for new values. */
-	nLocalNodes = Mesh_GetLocalSize( mesh, MT_VERTEX );
-	newVals = Memory_Alloc_Array( double, field->fieldComponentCount * nLocalNodes, "EulerDeform_InterpVar::newVals" );
-
-	/* Interpolate using new node coordinates. */
-	for( n_i = 0; n_i < nLocalNodes; n_i++ ) {
-		InterpolationResult	res;
-
-		/* Interpolate the value. */
-		res = FieldVariable_InterpolateValueAt( field, newCrds[n_i], newVals + n_i * field->fieldComponentCount );
-		if( res == OTHER_PROC || res == OUTSIDE_GLOBAL ) {
-			FeVariable_GetValueAtNode( (FeVariable*)field, n_i, 
-						   newVals + n_i * field->fieldComponentCount );
-		}
-	}
-
-	/* Transfer the new values back to the variable. */
-	for( n_i = 0; n_i < nLocalNodes; n_i++ ) {
-	   for( c_i = 0; c_i < field->fieldComponentCount; c_i++ )
-	      DofLayout_SetValueDouble( ((FeVariable*)field)->dofLayout, n_i, c_i, newVals[curValInd++] );
-	}
-
-	/* Free the values array. */
-	FreeArray( newVals );
-}
-
-void EulerDeform_InternalLoop( EulerDeform_System* sys, Grid* grm, double** oldCrds, unsigned* ijk, unsigned curDim, int top );
-
-void EulerDeform_WrapSurface( EulerDeform_System* sys, double** oldCrds, int top ) {
-	IJK	ijk;
-	Grid*	grm;
-	Mesh*	mesh;
-
-	assert( sys );
-	assert( oldCrds );
-
-	/* Loop over top internal surface. */
-	mesh = sys->mesh;
-	grm = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-					     ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
-	EulerDeform_InternalLoop( sys, grm, oldCrds, ijk, 0, top );
-}
-
-#if 0
-void EulerDeform_WrapLeftSurface( EulerDeform_System* sys, double** oldCrds ) {
-	IJK	ijk;
-	GRM	grm;
-
-	assert( sys );
-	assert( oldCrds );
-
-	/* Loop over top internal surface. */
-	RegMesh_Generalise( sys->mesh, &grm );
-	EulerDeform_LeftInternalLoop( sys, &grm, oldCrds, ijk, 0 );
-}
-#endif
-
-
-void _EulerDeform_TriBarycenter( double** tri, const double* pnt, double* dst ) {
-	double	a = tri[0][0] - tri[2][0];
-	double	b = tri[1][0] - tri[2][0];
-	double	c = tri[2][0] - pnt[0];
-	double	d = tri[0][1] - tri[2][1];
-	double	e = tri[1][1] - tri[2][1];
-	double	f = tri[2][1] - pnt[1];
-	double	g = tri[0][2] - tri[2][2];
-	double	h = tri[1][2] - tri[2][2];
-	double	i = tri[2][2] - pnt[2];
-
-	dst[0] = (b * (f + i) - c * (e + h)) / (a * (e + h) - b * (d + g));
-	dst[1] = (a * (f + i) - c * (d + g)) / (b * (d + g) - a * (e + h));
-	dst[2] = 1.0 - dst[0] - dst[1];
-}
-
-
-Bool _EulerDeform_QuadYInterp( double** crds, const double* pnt, double* val ) {
-	double*		modCrds[4];
-	double		modCrds0[2], modCrds1[2], modCrds2[2], modCrds3[2];
-	unsigned*	inds[2];
-	unsigned	inds0[3], inds1[3];
-	unsigned	inc[4];
-	double		modPnt[3];
-	unsigned	inside;
-	double		bc[3];
-
-	modCrds[0] = modCrds0;
-	modCrds[1] = modCrds1;
-	modCrds[2] = modCrds2;
-	modCrds[3] = modCrds3;
-	modCrds[0][0] = crds[0][0]; modCrds[0][1] = crds[0][2];
-	modCrds[1][0] = crds[1][0]; modCrds[1][1] = crds[1][2];
-	modCrds[2][0] = crds[2][0]; modCrds[2][1] = crds[2][2];
-	modCrds[3][0] = crds[3][0]; modCrds[3][1] = crds[3][2];
-	modPnt[0] = pnt[0]; modPnt[1] = pnt[2];
-
-	inds[0] = inds0;
-	inds[1] = inds1;
-	inds[0][0] = 0; inds[0][1] = 1; inds[0][2] = 2;
-	inds[1][0] = 1; inds[1][1] = 3; inds[1][2] = 2;
-	inc[0] = 0; inc[1] = 1; inc[2] = 2; inc[3] = 3;
-
-	if( Simplex_Search2D( modCrds, inc, 2, inds, 
-			      modPnt, bc, &inside ) )
-	{
-		*val = bc[0] * crds[inds[inside][0]][1] + bc[1] * crds[inds[inside][1]][1] + 
-			bc[2] * crds[inds[inside][2]][1];
-		return True;
-	}
-	else
-		return False;
-}
-
-
-Bool _EulerDeform_FindBarycenter1D( const double* crds, const double pnt, 
-				    double* bcs )
-{
-	assert( crds );
-	assert( bcs );
-
-	bcs[1] = (pnt - crds[0])/(crds[1] - crds[0]);
-	bcs[0] = 1.0 - bcs[1];
-
-	return (bcs[0] >= 0.0 && bcs[0] <= 1.0 && bcs[1] >= 0.0 && bcs[1] <= 1.0) ? True : False;
-}
-
-
-Bool _EulerDeform_LineInterp(double** crds, const double* pnt, unsigned fromDim, unsigned toDim, 
-			      double* val ) {
-	double	bcCrds[2];
-	double	bcs[2];
-
-	assert( crds );
-	assert( val );
-
-	bcCrds[0] = crds[0][fromDim];
-	bcCrds[1] = crds[1][fromDim];
-	if( _EulerDeform_FindBarycenter1D( bcCrds, pnt[fromDim], bcs ) ) {
-		*val = bcs[0]*crds[0][toDim] + bcs[1]*crds[1][toDim];
-		return True;
-	}
-
-	return False;
-}
-
-
-#if 0
-Bool _EulerDeform_QuadZInterp( double** crds, const double* pnt, double* val ) {
-	double		modCrds[4][3];
-	double		modPnt[3];
-	unsigned	inds[3];
-	double		bc[3];
-
-	modCrds[0][0] = crds[0][0]; modCrds[0][1] = crds[0][1]; modCrds[0][2] = 0.0;
-	modCrds[1][0] = crds[1][0]; modCrds[1][1] = crds[1][1]; modCrds[1][2] = 0.0;
-	modCrds[2][0] = crds[2][0]; modCrds[2][1] = crds[2][1]; modCrds[2][2] = 0.0;
-	modCrds[3][0] = crds[3][0]; modCrds[3][1] = crds[3][1]; modCrds[3][2] = 0.0;
-	modPnt[0] = pnt[0]; modPnt[1] = pnt[1]; modPnt[2] = 0.0;
-
-	if( _HexaEL_FindTriBarycenter( (const double**)modCrds, modPnt, bc, inds, INCLUSIVE_UPPER_BOUNDARY, NULL, 0 ) ) {
-		*val = bc[0]*crds[inds[0]][1] + bc[1]*crds[inds[1]][1] + bc[2]*crds[inds[2]][1];
-		return True;
-	}
-	else
-		return False;
-}
-#endif
-
-
-void EulerDeform_InternalLoop( EulerDeform_System* sys, Grid* grm, double** oldCrds, unsigned* ijk, unsigned curDim, int top ) {
-	unsigned	nDims;
-	XYZ		newCrd, oldCrd;
-	double*		crds[4];
-	double		crds0[3], crds1[3], crds2[3], crds3[3];
-	unsigned	centerInd;
-	Mesh*		mesh;
-	unsigned	nLocalNodes;
-	unsigned	ind;
-        double          fudge_factor;
-        
-        /* fudge_factor nudges the coordinate inside the mesh a little
-           to avoid failed interpolations */
-        fudge_factor=1.0e-10;
-
-	if( curDim < grm->nDims ) {
-		if( curDim == 1 ) {
-                        if(top) {
-                          ijk[1] = grm->sizes[curDim] - 1;
-                        }
-                        else {
-                          ijk[1]=0;
-                        }
-			EulerDeform_InternalLoop( sys, grm, oldCrds, ijk, curDim + 1, top );
-		}
-		else {
-			for( ijk[curDim] = 0; ijk[curDim] < grm->sizes[curDim]; ijk[curDim]++ ) {
-                          EulerDeform_InternalLoop( sys, grm, oldCrds, ijk, curDim + 1, top );
-			}
-		}
-	}
-	else {
-		if( grm->nDims == 2 ) {
-			mesh = sys->mesh;
-			nDims = Mesh_GetDimSize( mesh );
-
-			crds[0] = crds0;
-			crds[1] = crds1;
-			nLocalNodes = Mesh_GetLocalSize( mesh, MT_VERTEX );
-
-			/* Skip corners. */
-			if( ijk[0] == 0 || ijk[0] == grm->sizes[0] - 1 ) {
-				return;
-			}
-
-			/* Get old and new coordinate. */
-			centerInd = Grid_Project( grm, ijk );
-			if( !Mesh_GlobalToDomain( mesh, MT_VERTEX, centerInd, &centerInd ) || centerInd >= nLocalNodes )
-				return;
-
-			newCrd[0] = mesh->verts[centerInd][0];
-			newCrd[1] = mesh->verts[centerInd][1];
-			oldCrd[0] = oldCrds[centerInd][0];
-			oldCrd[1] = oldCrds[centerInd][1];
-
-			/* Are we left or right? */
-			if( newCrd[0] < oldCrd[0] ) {
-				ijk[0]--; ind = Grid_Project( grm, ijk ); ijk[0]++;
-				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
-				memcpy( crds[0], oldCrds[ind], nDims * sizeof(double) );
-				memcpy( crds[1], oldCrd, nDims * sizeof(double) );
-			}
-			else if( newCrd[0] > oldCrd[0] ) {
-				ijk[0]++; ind = Grid_Project( grm, ijk ); ijk[0]--;
-				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
-				memcpy( crds[1], oldCrds[ind], nDims * sizeof(double) );
-				memcpy( crds[0], oldCrd, nDims * sizeof(double) );
-			}
-
-                        if(newCrd[0]==oldCrd[0]) {
-                          mesh->verts[centerInd][1]=oldCrd[1];
-                        }
-                        else {
-
-                          /* Interpolate. */
-#ifndef NDEBUG
-			assert( _EulerDeform_LineInterp(crds, newCrd, 0, 1, &mesh->verts[centerInd][1] ) );
-#else
-			_EulerDeform_LineInterp(crds, newCrd, 0, 1, &mesh->verts[centerInd][1] );
-#endif
-                        if((mesh->verts[centerInd][1]>0) ^ top)
-                          {
-                            mesh->verts[centerInd][1] *= 1+fudge_factor;
-                          }
-                        else
-                          {
-                            mesh->verts[centerInd][1] *= 1-fudge_factor;
-                          }
-                        }
-		}
-		else if( grm->nDims == 3 ) {
-			mesh = sys->mesh;
-			nDims = Mesh_GetDimSize( mesh );
-
-			crds[0] = crds0; crds[1] = crds1; crds[2] = crds2; crds[3] = crds3;
-			nLocalNodes = Mesh_GetLocalSize( mesh, MT_VERTEX );
-
-			/* Skip corners. */
-			if( (ijk[0] == 0 || ijk[0] == grm->sizes[0] - 1) && 
-			    (ijk[2] == 0 || ijk[2] == grm->sizes[2] - 1))
-			{
-				return;
-			}
-
-			/* Get old and new coordinate. */
-			centerInd = Grid_Project( grm, ijk );
-			if( !Mesh_GlobalToDomain( mesh, MT_VERTEX, centerInd, &centerInd ) || centerInd >= nLocalNodes )
-				return;
-
-			newCrd[0] = mesh->verts[centerInd][0];
-			newCrd[1] = mesh->verts[centerInd][1];
-			newCrd[2] = mesh->verts[centerInd][2];
-			oldCrd[0] = oldCrds[centerInd][0];
-			oldCrd[1] = oldCrds[centerInd][1];
-			oldCrd[2] = oldCrds[centerInd][2];
-
-			/* Handle internal nodes. */
-			if( ijk[0] > 0 && ijk[2] > 0 ) {
-				ijk[0]--; ijk[2]--; ind = Grid_Project( grm, ijk );
-				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
-				memcpy( crds[0], oldCrds[ind], nDims * sizeof(double) );
-
-				ijk[0]++; ind = Grid_Project( grm, ijk );
-				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
-				memcpy( crds[1], oldCrds[ind], nDims * sizeof(double) );
-
-				ijk[0]--; ijk[2]++; ind = Grid_Project( grm, ijk );
-				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
-				memcpy( crds[2], oldCrds[ind], nDims * sizeof(double) );
-
-				ijk[0]++; ind = Grid_Project( grm, ijk );
-				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
-				memcpy( crds[3], oldCrds[ind], nDims * sizeof(double) );
-
-				if( _EulerDeform_QuadYInterp( crds, newCrd, &mesh->verts[centerInd][1] ) ) {
-                                  if((mesh->verts[centerInd][1]>0) ^ top)
-                                    {
-                                      mesh->verts[centerInd][1] *= 1+fudge_factor;
-                                    }
-                                  else
-                                    {
-                                      mesh->verts[centerInd][1] *= 1-fudge_factor;
-                                    }
-                                  return;
-				}
-			}
-
-			if( ijk[0] > 0 && ijk[2] < grm->sizes[2] - 1 ) {
-				ijk[0]--; ind = Grid_Project( grm, ijk );
-				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
-				memcpy( crds[0], oldCrds[ind], nDims * sizeof(double) );
-
-				ijk[0]++; ind = Grid_Project( grm, ijk );
-				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
-				memcpy( crds[1], oldCrds[ind], nDims * sizeof(double) );
-
-				ijk[0]--; ijk[2]++; ind = Grid_Project( grm, ijk );
-				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
-				memcpy( crds[2], oldCrds[ind], nDims * sizeof(double) );
-
-				ijk[0]++; ind = Grid_Project( grm, ijk );
-				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
-				memcpy( crds[3], oldCrds[ind], nDims * sizeof(double) );
-
-				ijk[2]--;
-				if( _EulerDeform_QuadYInterp( crds, newCrd, &mesh->verts[centerInd][1] ) ) {
-                                  if((mesh->verts[centerInd][1]>0) ^ top)
-                                    {
-                                      mesh->verts[centerInd][1] *= 1+fudge_factor;
-                                    }
-                                  else
-                                    {
-                                      mesh->verts[centerInd][1] *= 1-fudge_factor;
-                                    }
-                                  return;
-				}
-			}
-
-			if( ijk[0] < grm->sizes[0] - 1 && ijk[2] > 0 ) {
-				ijk[2]--; ind = Grid_Project( grm, ijk );
-				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
-				memcpy( crds[0], oldCrds[ind], nDims * sizeof(double) );
-
-				ijk[0]++; ind = Grid_Project( grm, ijk );
-				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
-				memcpy( crds[1], oldCrds[ind], nDims * sizeof(double) );
-
-				ijk[0]--; ijk[2]++; ind = Grid_Project( grm, ijk );
-				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
-				memcpy( crds[2], oldCrds[ind], nDims * sizeof(double) );
-
-				ijk[0]++; ind = Grid_Project( grm, ijk );
-				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
-				memcpy( crds[3], oldCrds[ind], nDims * sizeof(double) );
-
-				ijk[0]--;
-				if( _EulerDeform_QuadYInterp( crds, newCrd, &mesh->verts[centerInd][1] ) ) {
-                                  if((mesh->verts[centerInd][1]>0) ^ top)
-                                    {
-                                      mesh->verts[centerInd][1] *= 1+fudge_factor;
-                                    }
-                                  else
-                                    {
-                                      mesh->verts[centerInd][1] *= 1-fudge_factor;
-                                    }
-                                  return;
-				}
-			}
-
-			if( ijk[0] < grm->sizes[0] - 1 && ijk[2] < grm->sizes[2] - 1 ) {
-				ind = Grid_Project( grm, ijk );
-				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
-				memcpy( crds[0], oldCrds[ind], nDims * sizeof(double) );
-
-				ijk[0]++; ind = Grid_Project( grm, ijk );
-				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
-				memcpy( crds[1], oldCrds[ind], nDims * sizeof(double) );
-
-				ijk[0]--; ijk[2]++; ind = Grid_Project( grm, ijk );
-				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
-				memcpy( crds[2], oldCrds[ind], nDims * sizeof(double) );
-
-				ijk[0]++; ind = Grid_Project( grm, ijk );
-				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
-				memcpy( crds[3], oldCrds[ind], nDims * sizeof(double) );
-
-				ijk[0]--; ijk[2]--;
-				if( _EulerDeform_QuadYInterp( crds, newCrd, &mesh->verts[centerInd][1] ) ) {
-                                  if((mesh->verts[centerInd][1]>0) ^ top)
-                                    {
-                                      mesh->verts[centerInd][1] *= 1+fudge_factor;
-                                    }
-                                  else
-                                    {
-                                      mesh->verts[centerInd][1] *= 1-fudge_factor;
-                                    }
-                                  return;
-				}
-			}
-
-			assert( 0 );
-		}
-		else {
-			assert( 0 );
-		}
-	}
-}
-
-#if 0
-void EulerDeform_LeftInternalLoop( EulerDeform_System* sys, GRM* grm, Coord* oldCrds, unsigned* ijk, unsigned curDim ) {
-	if( curDim < grm->nDims ) {
-		if( curDim == 0 ) {
-			ijk[0] = 0;
-			EulerDeform_LeftInternalLoop( sys, grm, oldCrds, ijk, curDim + 1 );
-		}
-		else {
-			for( ijk[curDim] = 1; ijk[curDim] < grm->nNodes[curDim] - 1; ijk[curDim]++ ) {
-				EulerDeform_LeftInternalLoop( sys, grm, oldCrds, ijk, curDim + 1 );
-			}
-		}
-	}
-	else {
-		if( grm->nDims == 2 ) {
-			XYZ		newCrd, oldCrd;
-			unsigned	centerInd;
-			Mesh*		mesh = sys->mesh;
-
-			/* Get old and new coordinate. */
-			GRM_Project( grm, ijk, &centerInd );
-			newCrd[0] = mesh->nodeCoord[centerInd][0];
-			newCrd[1] = mesh->nodeCoord[centerInd][1];
-			oldCrd[0] = oldCrds[centerInd][0];
-			oldCrd[1] = oldCrds[centerInd][1];
-
-			/* Are we above or below? */
-			if( newCrd[1] < oldCrd[1] ) {
-				XYZ		leftCrd;
-				unsigned	leftInd;
-				double		a0, a1;
-
-				/* Get left old coord. */
-				ijk[1]--;
-				GRM_Project( grm, ijk, &leftInd );
-				ijk[1]++;
-				leftCrd[0] = oldCrds[leftInd][0];
-				leftCrd[1] = oldCrds[leftInd][1];
-
-				/* Calc barycenter. */
-				a1 = (newCrd[1] - leftCrd[1]) / (oldCrd[1] - leftCrd[1]);
-				a0 = 1.0 - a1;
-				mesh->nodeCoord[centerInd][0] = (a0 * leftCrd[0] + a1 * oldCrd[0])*(1.0+1.0e-10);
-			}
-			else {
-				XYZ		rightCrd;
-				unsigned	rightInd;
-				double		a0, a1;
-
-				/* Get right old coord. */
-				ijk[1]++;
-				GRM_Project( grm, ijk, &rightInd );
-				ijk[1]--;
-				rightCrd[0] = oldCrds[rightInd][0];
-				rightCrd[1] = oldCrds[rightInd][1];
-
-				/* Calc barycenter. */
-				a1 = (newCrd[1] - oldCrd[1]) / (rightCrd[1] - oldCrd[1]);
-				a0 = 1.0 - a1;
-				mesh->nodeCoord[centerInd][0] = (a0 * oldCrd[0] + a1 * rightCrd[0])*(1.0+1.0e-10);
-			}
-		}
-		else if( grm->nDims == 3 ) {
-			assert( 0 );
-		}
-		else {
-			assert( 0 );
-		}
-	}
-}
-#endif
-
-
diff -r 038180046f6f -r 4b2d36e5021d plugins/EulerDeform/EulerDeform.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/EulerDeform/EulerDeform.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,1529 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	David May, PhD Student Monash University, VPAC. (david.may at sci.maths.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)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: LevelSetPlg.c 200 2005-07-08 08:24:41Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Underworld.h>
+
+#include "types.h"
+#include "Context.h"
+#include "EulerDeform.h"
+
+
+Name		EULERDEFORM_PLUGIN_TAG = "EulerDeform";
+const Type		Underworld_EulerDeform_Type = "EulerDeform";
+ExtensionInfo_Index	EulerDeform_ContextHandle;
+
+
+Index Underworld_EulerDeform_Register( PluginsManager* pluginsMgr ) {
+	return PluginsManager_Submit( pluginsMgr, Underworld_EulerDeform_Type, (Name)"0", _Underworld_EulerDeform_DefaultNew );
+}
+
+
+void* _Underworld_EulerDeform_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Codelet);
+	Type                                                      type = Underworld_EulerDeform_Type;
+	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
+	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
+	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_EulerDeform_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Underworld_EulerDeform_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _Underworld_EulerDeform_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _Codelet_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _Codelet_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _Underworld_EulerDeform_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   );
+}
+
+
+void _Underworld_EulerDeform_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
+	Codelet*					ed = (Codelet*)component;
+	UnderworldContext*	uwCtx;
+	EulerDeform_Context*	edCtx;
+
+	assert( component );
+	assert( cf );
+
+	Journal_DPrintf( Underworld_Debug, "In: %s( void* )\n", __func__ );
+
+	/* Retrieve context. */
+	uwCtx = (UnderworldContext*)Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data );
+	ed->context = (AbstractContext* )uwCtx;
+
+	/* Create new context. */
+	EulerDeform_ContextHandle = ExtensionManager_Add( uwCtx->extensionMgr, (Name)Underworld_EulerDeform_Type, sizeof(EulerDeform_Context)  );
+	edCtx = (EulerDeform_Context*)ExtensionManager_Get( uwCtx->extensionMgr, uwCtx, EulerDeform_ContextHandle );
+	memset( edCtx, 0, sizeof(EulerDeform_Context) );
+	edCtx->ctx = (AbstractContext*)uwCtx;
+
+	/* Get the time integrator. */
+	edCtx->timeIntegrator = Stg_ComponentFactory_ConstructByName( cf, (Name)"timeIntegrator", TimeIntegrator, True, data  );
+
+	/* Grab the ArtDisplacementField from the dictionary */
+	edCtx->artDField = Stg_ComponentFactory_ConstructByName( cf, (Name)"ArtDisplacementField", FeVariable, False, data  );
+}
+
+
+void _Underworld_EulerDeform_Build( void* component, void* data ) {
+	Codelet*						ed	= (Codelet*)component;
+	UnderworldContext*		uwCtx	= (UnderworldContext*)ed->context;
+	EulerDeform_Context*		edCtx;
+	Variable*					crdVar;
+	TimeIntegrand*			crdAdvector;
+	Stg_Component*				tiData[2];
+	unsigned						sys_i;
+	Dictionary_Entry_Value*	edDict;
+	Dictionary_Entry_Value*	sysLst;
+
+	assert( component );
+	assert( uwCtx );
+
+	edCtx = (EulerDeform_Context*)ExtensionManager_Get( uwCtx->extensionMgr, uwCtx, EulerDeform_ContextHandle );
+
+	/* Get the dictionary. */
+	edDict = Dictionary_Get( uwCtx->dictionary, (Dictionary_Entry_Key)"EulerDeform" );
+	if( !edDict  ) {
+		return;
+	}
+
+	/* Read system list. */
+	sysLst = Dictionary_Entry_Value_GetMember( edDict, (Dictionary_Entry_Key)"systems" );
+	if( sysLst ) {
+		unsigned	sys_i;
+
+		/* Allocate for systems. */
+		edCtx->nSystems = Dictionary_Entry_Value_GetCount( sysLst  );
+		edCtx->systems = Memory_Alloc_Array( EulerDeform_System, edCtx->nSystems, "EulerDeform->systems" );
+		memset( edCtx->systems, 0, sizeof(EulerDeform_System) * edCtx->nSystems );
+
+		for( sys_i = 0; sys_i < edCtx->nSystems; sys_i++ ) {
+			EulerDeform_System*		sys = edCtx->systems + sys_i;
+			Dictionary*					sysDict;
+			Dictionary_Entry_Value*	varLst;
+			char*							meshName;
+			char*							remesherName;
+			char*							velFieldName;
+			char*							name;
+
+			/* Get the dictionary for this system. */
+			sysDict = Dictionary_Entry_Value_AsDictionary( Dictionary_Entry_Value_GetElement( sysLst, sys_i ) );
+			assert( sysDict );
+
+			/* Read contents. */
+			meshName = Dictionary_GetString( sysDict, (Dictionary_Entry_Key)"mesh"  );
+			remesherName = Dictionary_GetString( sysDict, (Dictionary_Entry_Key)"remesher"  );
+
+			if( strcmp( remesherName, "" ) )
+				sys->remesher = Stg_ComponentFactory_ConstructByName( uwCtx->CF, (Name)remesherName, Remesher, True, data  );
+			name = Dictionary_GetString( sysDict, (Dictionary_Entry_Key)"displacementField" );
+
+			if(strcmp(name, ""))
+			    sys->dispField = Stg_ComponentFactory_ConstructByName( uwCtx->CF, (Name)name, FeVariable, True, data  );
+			else
+			    sys->dispField = NULL;
+
+			velFieldName = Dictionary_GetString( sysDict, (Dictionary_Entry_Key)"VelocityField"  );
+			sys->interval = Dictionary_GetInt_WithDefault( sysDict, (Dictionary_Entry_Key)"interval", -1  );
+			sys->wrapTop = Dictionary_GetBool_WithDefault( sysDict, (Dictionary_Entry_Key)"wrapTop", False  );
+			sys->wrapBottom = Dictionary_GetBool_WithDefault( sysDict, (Dictionary_Entry_Key)"wrapBottom", False  );
+			sys->wrapLeft = Dictionary_GetBool_WithDefault( sysDict, (Dictionary_Entry_Key)"wrapLeft", False  );
+			sys->mesh = Stg_ComponentFactory_ConstructByName( uwCtx->CF, (Name)meshName, Mesh, True, data  );
+			/* This line is currently not working, have to manually set the velocity field name.
+				This should be fixed once this plugin has been converted to a component. */
+			/*sys->velField = Stg_ComponentFactory_ConstructByName( uwCtx->CF, (Name)velFieldName, FieldVariable, True, data  );*/
+			sys->velField = Stg_ComponentFactory_ConstructByName( uwCtx->CF, (Name)"VelocityField", FieldVariable, True, data  );
+
+			sys->staticTop = Dictionary_GetBool_WithDefault( sysDict, (Dictionary_Entry_Key)"staticTop", False  );
+			sys->staticBottom = Dictionary_GetBool_WithDefault( sysDict, (Dictionary_Entry_Key)"staticBottom", False  );
+			sys->staticLeft = Dictionary_GetBool_WithDefault( sysDict, (Dictionary_Entry_Key)"staticLeft", False  );
+			sys->staticRight = Dictionary_GetBool_WithDefault( sysDict, (Dictionary_Entry_Key)"staticRight", False  );
+			sys->staticFront = Dictionary_GetBool_WithDefault( sysDict, (Dictionary_Entry_Key)"staticFront", False  );
+			sys->staticBack = Dictionary_GetBool_WithDefault( sysDict, (Dictionary_Entry_Key)"staticBack", False  );
+
+			sys->staticLeftTop = Dictionary_GetBool_WithDefault( sysDict, "staticLeftTop", (sys->staticLeft && sys->staticTop)
+                                                                             ? True : False);
+			sys->staticRightTop = Dictionary_GetBool_WithDefault( sysDict, "staticRightTop", (sys->staticRight && sys->staticTop)
+                                                                             ? True : False );
+			sys->staticLeftTopFront = Dictionary_GetBool_WithDefault( sysDict, "staticLeftTopFront",
+                                                                                  (sys->staticLeft && sys->staticTop && sys->staticFront)
+                                                                             ? True : False );
+			sys->staticRightTopFront = Dictionary_GetBool_WithDefault( sysDict, "staticRightTopFront",
+                                                                                   (sys->staticRight && sys->staticTop && sys->staticFront)
+                                                                             ? True : False );
+			sys->staticLeftTopBack = Dictionary_GetBool_WithDefault( sysDict, "staticLeftTopBack",
+                                                                                  (sys->staticLeft && sys->staticTop && sys->staticBack)
+                                                                             ? True : False );
+			sys->staticRightTopBack = Dictionary_GetBool_WithDefault( sysDict, "staticRightTopBack",
+                                                                                   (sys->staticRight && sys->staticTop && sys->staticBack)
+                                                                             ? True : False );
+
+			sys->staticLeftBottom = Dictionary_GetBool_WithDefault( sysDict, "staticLeftBottom", (sys->staticLeft && sys->staticBottom)
+                                                                             ? True : False );
+			sys->staticRightBottom = Dictionary_GetBool_WithDefault( sysDict, "staticRightBottom", (sys->staticRight && sys->staticBottom)
+                                                                             ? True : False );
+			sys->staticLeftBottomFront = Dictionary_GetBool_WithDefault( sysDict, "staticLeftBottomFront",
+                                                                                  (sys->staticLeft && sys->staticBottom && sys->staticFront)
+                                                                             ? True : False );
+			sys->staticRightBottomFront = Dictionary_GetBool_WithDefault( sysDict, "staticRightBottomFront",
+                                                                                   (sys->staticRight && sys->staticBottom && sys->staticFront)
+                                                                             ? True : False );
+			sys->staticLeftBottomBack = Dictionary_GetBool_WithDefault( sysDict, "staticLeftBottomBack",
+                                                                                  (sys->staticLeft && sys->staticBottom && sys->staticBack)
+                                                                             ? True : False );
+			sys->staticRightBottomBack = Dictionary_GetBool_WithDefault( sysDict, "staticRightBottomBack",
+                                                                                   (sys->staticRight && sys->staticBottom && sys->staticBack)
+                                                                             ? True : False );
+
+			sys->staticLeftFront = Dictionary_GetBool_WithDefault( sysDict, "staticLeftFront", (sys->staticLeft && sys->staticFront)
+                                                                             ? True : False );
+			sys->staticRightFront = Dictionary_GetBool_WithDefault( sysDict, "staticRightFront", (sys->staticRight && sys->staticFront)
+                                                                             ? True : False );
+			sys->staticLeftBack = Dictionary_GetBool_WithDefault( sysDict, "staticLeftBack", (sys->staticLeft && sys->staticBack)
+                                                                             ? True : False );
+			sys->staticRightBack = Dictionary_GetBool_WithDefault( sysDict, "staticRightBack", (sys->staticRight && sys->staticBack)
+                                                                             ? True : False );
+
+			sys->staticTopFront = Dictionary_GetBool_WithDefault( sysDict, "staticTopFront", (sys->staticTop && sys->staticFront)
+                                                                             ? True : False );
+			sys->staticBottomFront = Dictionary_GetBool_WithDefault( sysDict, "staticBottomFront", (sys->staticBottom && sys->staticFront)
+                                                                             ? True : False );
+			sys->staticTopBack = Dictionary_GetBool_WithDefault( sysDict, "staticTopBack", (sys->staticTop && sys->staticBack)
+                                                                             ? True : False );
+			sys->staticBottomBack = Dictionary_GetBool_WithDefault( sysDict, "staticBottomBack", (sys->staticBottom && sys->staticBack)
+                                                                             ? True : False );
+
+			sys->floatLeftTop = Dictionary_GetBool_WithDefault( sysDict, "floatLeftTop", False );
+			sys->floatRightTop = Dictionary_GetBool_WithDefault( sysDict, "floatRightTop", False );
+
+			sys->staticSides = 
+                          (sys->staticLeft
+                           || sys->staticRight
+                           || sys->staticTop
+                           || sys->staticBottom
+                           || sys->staticFront
+                           || sys->staticBack
+                           || sys->staticLeftTop
+                           || sys->staticRightTop
+                           || sys->staticLeftTopFront
+                           || sys->staticRightTopFront
+                           || sys->staticLeftTopBack
+                           || sys->staticRightTopBack
+                           || sys->staticLeftBottom
+                           || sys->staticRightBottom
+                           || sys->staticLeftBottomFront
+                           || sys->staticRightBottomFront
+                           || sys->staticLeftBottomBack
+                           || sys->staticRightBottomBack
+                           || sys->staticLeftFront
+                           || sys->staticRightFront
+                           || sys->staticLeftBack
+                           || sys->staticRightBack
+                           || sys->staticTopFront
+                           || sys->staticBottomFront
+                           || sys->staticTopBack
+                           || sys->staticBottomBack)
+                          ? True : False;
+
+
+                        if(sys->staticRight && sys->wrapTop
+                           && !sys->staticRightTop)
+                          sys->x_right_coord =
+                            Dictionary_GetDouble( uwCtx->dictionary, "maxX");
+
+                        if(sys->staticLeft && sys->wrapTop
+                           && !sys->staticLeftTop)
+                          sys->x_left_coord =
+                            Dictionary_GetDouble( uwCtx->dictionary, "minX");
+                          
+			/* Read the list of variables to interpolate. */
+			varLst = Dictionary_Entry_Value_GetMember( Dictionary_Entry_Value_GetElement( sysLst, sys_i  ), "fields" );
+
+			if( varLst ) {
+				unsigned	var_i;
+
+				sys->nFields = Dictionary_Entry_Value_GetCount( varLst );
+				sys->fields = Memory_Alloc_Array( FieldVariable*, sys->nFields, "EulerDeform->systems[].fields" );
+				sys->vars = Memory_Alloc_Array( Variable*, sys->nFields, "EulerDeform->systemsp[].vars" );
+
+				for( var_i = 0; var_i <sys->nFields; var_i++ ) {
+					Dictionary*	varDict;
+					char*			varName;
+
+					/* Get the dictionary for this field tuple. */
+					varDict = Dictionary_Entry_Value_AsDictionary( Dictionary_Entry_Value_GetElement( varLst, var_i ) );
+					assert( varDict );
+
+					/* Get the field and its variable. */
+					varName = Dictionary_GetString( varDict, (Dictionary_Entry_Key)"field"  );
+					sys->fields[var_i] = Stg_ComponentFactory_ConstructByName( uwCtx->CF, (Name)varName, FieldVariable, True, data  ); 
+					varName = Dictionary_GetString( varDict, (Dictionary_Entry_Key)"variable"  );
+					sys->vars[var_i] = Stg_ComponentFactory_ConstructByName( uwCtx->CF, (Name)varName, Variable, True, data ); 
+				}
+			}
+		}
+	}
+
+	for( sys_i = 0; sys_i < edCtx->nSystems; sys_i++  ) {
+		EulerDeform_System*	sys = edCtx->systems + sys_i;
+
+		/* Create a time integrand for the mesh's coordinates. */
+		crdVar = EulerDeform_RegisterLocalNodeCoordsAsVariables( sys, uwCtx->variable_Register, NULL );
+		Stg_Component_Build( crdVar, data, False );
+
+		tiData[0] = (Stg_Component*)sys->velField;
+		tiData[1] = (Stg_Component*)&sys->mesh->verts;
+		crdAdvector = TimeIntegrand_New( "EulerDeform_Velocity", (DomainContext*)uwCtx, edCtx->timeIntegrator, crdVar, 2, tiData, True
+			 /* Presume we need to allow fallback on edges of stretching mesh - PatrickSunter, 7 June 2006 */ );
+		crdAdvector->_calculateTimeDeriv = EulerDeform_TimeDeriv;
+
+		/* Add to live component register... */
+		LiveComponentRegister_Add( uwCtx->CF->LCRegister, (Stg_Component*)crdAdvector );
+		Stg_Component_Build( crdAdvector, data, False );
+	}
+
+	if( edCtx->nSystems > 0 ) {
+		/* Insert the sync step. */
+          TimeIntegrator_PrependSetupEP( edCtx->timeIntegrator, "EulerDeform_IntegrationSetup", (void*)EulerDeform_IntegrationSetup, "EulerDeform", edCtx );
+	}
+
+	/* Insert the remesh step. Note that this should look for the surface process
+	   plugin's time integrator finish routine and ensure we enter the remesh step
+	   after that one but before the particle updating routines. */
+	TimeIntegrator_PrependFinishEP( edCtx->timeIntegrator, "EulerDeform_Execute", (void*)EulerDeform_Remesh, "EulerDeform", edCtx );
+}
+
+
+void _Underworld_EulerDeform_Destroy( void* component, void* data ) {
+	Codelet*					ed	= (Codelet*)component;
+	UnderworldContext*	uwCtx = (UnderworldContext*)ed->context;
+
+	assert( component );
+	assert( uwCtx );
+
+	/* Clear the lot. */
+	/* TODO */
+}
+
+/* This creates a set which makes sure not to include the corners if
+   we have not made both sides of the corner static. */
+
+IndexSet* EulerDeform_CreateStaticSet(EulerDeform_System* sys)
+{
+  Grid*		grid;
+  unsigned	nNodes;
+  unsigned	n_i;
+  IndexSet	*set;
+  IJK			ijk;
+
+  grid = *(Grid**)ExtensionManager_Get ( sys->mesh->info, sys->mesh, ExtensionManager_GetHandle( sys->mesh->info, (Name)"vertexGrid" )  );
+
+  nNodes = Mesh_GetDomainSize( sys->mesh, MT_VERTEX );
+  set = IndexSet_New( nNodes );
+
+  for( n_i = 0; n_i < nNodes; n_i++ ) {
+    Bool add;
+    add=False;
+    RegularMeshUtils_Node_1DTo3D
+      ( sys->mesh, Mesh_DomainToGlobal( sys->mesh, MT_VERTEX, n_i ), ijk );
+
+    /* 2D */
+    if(sys->mesh->topo->nDims == 2)
+      {
+        /* Left side and Corner */
+        if(ijk[0]==0)
+          {
+            if(ijk[1]==0)
+              {
+                if(sys->staticLeftBottom)
+                  add=True;
+              }
+            else if(ijk[1]==grid->sizes[1]-1)
+              {
+                if(sys->staticLeftTop)
+                  add=True;
+              }
+            else if(sys->staticLeft)
+              add=True;
+          }
+        /* Right side and corner */
+        else if(ijk[0]==grid->sizes[0]-1)
+          {
+            if(ijk[1]==0)
+              {
+                if(sys->staticRightBottom)
+                  add=True;
+              }
+            else if(ijk[1]==grid->sizes[1]-1)
+              {
+                if(sys->staticRightTop)
+                  add=True;
+              }
+            else if(sys->staticRight)
+              add=True;
+          }
+        /* Top and Bottom */
+        else if((ijk[1]==0 && sys->staticBottom)
+                || (ijk[1]==grid->sizes[1]-1 && sys->staticTop))
+          add=True;
+      }
+    /* 3D */
+    else if(sys->mesh->topo->nDims == 3)
+      {
+        /* Left side */
+        if(ijk[0]==0)
+          {
+            /* Left Bottom */
+            if(ijk[1]==0)
+              {
+                if(ijk[2]==0)
+                  {
+                    if(sys->staticLeftBottomBack)
+                      add=True;
+                  }
+                else if(ijk[2]==grid->sizes[2]-1)
+                  {
+                    if(sys->staticLeftBottomFront)
+                      add=True;
+                  }
+                else if(sys->staticLeftBottom)
+                  add=True;
+              }
+            /* Left Top */
+            else if(ijk[1]==grid->sizes[1]-1)
+              {
+                if(ijk[2]==0)
+                  {
+                    if(sys->staticLeftTopBack)
+                      add=True;
+                  }
+                else if(ijk[2]==grid->sizes[2]-1)
+                  {
+                    if(sys->staticLeftTopFront)
+                      add=True;
+                  }
+                else if(sys->staticLeftTop)
+                  add=True;
+              }
+            /* Left Back */
+            else if(ijk[2]==0)
+              {
+                if(sys->staticLeftBack)
+                  add=True;
+              }
+            /* Left Front */
+            else if(ijk[2]==grid->sizes[2]-1)
+              {
+                if(sys->staticLeftFront)
+                  add=True;
+              }
+            /* Left */
+            else if(sys->staticLeft)
+              add=True;
+          }
+        /* Right side */
+        else if(ijk[0]==grid->sizes[0]-1)
+          {
+            /* Right Bottom */
+            if(ijk[1]==0)
+              {
+                if(ijk[2]==0)
+                  {
+                    if(sys->staticRightBottomBack)
+                      add=True;
+                  }
+                else if(ijk[2]==grid->sizes[2]-1)
+                  {
+                    if(sys->staticRightBottomFront)
+                      add=True;
+                  }
+                else if(sys->staticRightBottom)
+                  add=True;
+              }
+            /* Right Top */
+            else if(ijk[1]==grid->sizes[1]-1)
+              {
+                if(ijk[2]==0)
+                  {
+                    if(sys->staticRightTopBack)
+                      add=True;
+                  }
+                else if(ijk[2]==grid->sizes[2]-1)
+                  {
+                    if(sys->staticRightTopFront)
+                      add=True;
+                  }
+                else if(sys->staticRightTop)
+                  add=True;
+              }
+            /* Right Back */
+            else if(ijk[2]==0)
+              {
+                if(sys->staticRightBack)
+                  add=True;
+              }
+            /* Right Front */
+            else if(ijk[2]==grid->sizes[2]-1)
+              {
+                if(sys->staticRightFront)
+                  add=True;
+              }
+            /* Right */
+            else if(sys->staticRight)
+              add=True;
+          }
+        /* Bottom */
+        else if(ijk[1]==0)
+          {
+            if(ijk[2]==0)
+              {
+                if(sys->staticBottomBack)
+                  add=True;
+              }
+            else if(ijk[2]==grid->sizes[2]-1)
+              {
+                if(sys->staticBottomFront)
+                  add=True;
+              }
+            else if(sys->staticBottom)
+              add=True;
+          }
+        /* Top */
+        else if(ijk[1]==grid->sizes[1]-1)
+          {
+            if(ijk[2]==0)
+              {
+                if(sys->staticTopBack)
+                  add=True;
+              }
+            else if(ijk[2]==grid->sizes[2]-1)
+              {
+                if(sys->staticTopFront)
+                  add=True;
+              }
+            else if(sys->staticTop)
+              add=True;
+          }
+        /*  Front and Back */
+        else if((ijk[2]==0 && sys->staticBack)
+                || (ijk[2]==grid->sizes[2]-1 && sys->staticFront))
+          add=True;
+      }
+
+    if( add )
+      IndexSet_Add( set, n_i );
+  }
+  return set;
+}
+
+Variable* EulerDeform_RegisterLocalNodeCoordsAsVariables( EulerDeform_System* sys, void* _variable_Register, Variable** variableList ) {
+	FeMesh*					self = (FeMesh*)sys->mesh;
+	Variable_Register*	variable_Register = (Variable_Register*) _variable_Register;
+	Variable*				variable;
+	char*						variableName;
+	char*						variableNameX;
+	char*						variableNameY;
+	char*						variableNameZ;
+
+	/* Allocate advection array. */
+	sys->verts = AllocArray( double, Mesh_GetLocalSize( self, MT_VERTEX ) * Mesh_GetDimSize( self ) );
+	
+	/* Append Extension onto names */
+	variableName  = Memory_Alloc_Array( char, strlen( self->name ) + strlen( "NodeCoords" ) + 1, "variableName" );
+	sprintf( variableName , "%sNodeCoords", self->name );
+	
+	variableNameX = Memory_Alloc_Array( char, strlen( self->name ) + strlen( "NodeCoordX" ) + 1, "variableNameX" );
+	sprintf( variableNameX, "%sNodeCoordX", self->name );
+
+	variableNameY = Memory_Alloc_Array( char, strlen( self->name ) + strlen( "NodeCoordY" ) + 1, "variableNameY" );
+	sprintf( variableNameY, "%sNodeCoordY", self->name );
+
+	variableNameZ = Memory_Alloc_Array( char, strlen( self->name ) + strlen( "NodeCoordZ" ) + 1, "variableNameZ" );
+	sprintf( variableNameZ, "%sNodeCoordZ", self->name );
+	
+	/* Construct */
+	variable = Variable_NewVector( 
+		variableName, 
+		self->context,	
+		Variable_DataType_Double, 
+		Mesh_GetDimSize( self ), 
+		(unsigned*)&((IGraph*)self->topo)->remotes[MT_VERTEX]->decomp->locals->size, 
+		NULL,
+		(void**)&sys->verts, 
+		variable_Register, 
+		variableNameX,
+		variableNameY,
+		variableNameZ );
+
+	if ( variableList != NULL ) {
+		variableList[ I_AXIS ] = Variable_Register_GetByName( variable_Register, variableNameX );
+		variableList[ J_AXIS ] = Variable_Register_GetByName( variable_Register, variableNameY );
+		variableList[ K_AXIS ] = Variable_Register_GetByName( variable_Register, variableNameZ );
+	}
+
+	/* Clean Up */
+	Memory_Free( variableNameZ );
+	Memory_Free( variableNameY );
+	Memory_Free( variableNameX );
+	Memory_Free( variableName );
+
+	return variable;
+}
+
+
+void EulerDeform_IntegrationSetup( void* _timeIntegrator, void* context ) {
+	EulerDeform_Context*	edCtx = (EulerDeform_Context*)context;
+	unsigned					sys_i;
+
+	FeVariable_SyncShadowValues( edCtx->systems[0].velField );
+
+	/* 
+	** We'll need to store side values that we require to be static here, for later
+	** return to the mesh.
+	*/
+
+	for( sys_i = 0; sys_i < edCtx->nSystems; sys_i++ ) {
+		EulerDeform_System* sys = edCtx->systems + sys_i;
+
+		if( sys->staticSides ) {
+			IndexSet	*tmpIndSet;
+			unsigned	nInds, *inds;
+			unsigned	nDims;
+			unsigned	ind_i;
+
+			/* Collect indices of all the sides. */
+
+                        tmpIndSet = EulerDeform_CreateStaticSet(sys);
+                        IndexSet_GetMembers( tmpIndSet, &nInds, &inds );
+
+			/* Copy coords to temporary array. */
+			nDims = Mesh_GetDimSize( sys->mesh );
+			sys->sideCoords = AllocArray2D( double, nInds, nDims );
+			for( ind_i = 0; ind_i < nInds; ind_i++ )
+				memcpy( sys->sideCoords[ind_i], sys->mesh->verts[inds[ind_i]], nDims * sizeof(double) );
+                        FreeObject( tmpIndSet );
+                        FreeArray( inds );
+		}
+	}
+
+	/* Update advection arrays. */
+	for( sys_i = 0; sys_i < edCtx->nSystems; sys_i++ ) {
+		EulerDeform_System*	sys = edCtx->systems + sys_i;
+		unsigned					nDims;
+		unsigned					nLocalNodes;
+		unsigned					n_i;
+
+		nDims = Mesh_GetDimSize( sys->mesh );
+		nLocalNodes = Mesh_GetLocalSize( sys->mesh, MT_VERTEX );
+
+		for( n_i = 0; n_i < nLocalNodes; n_i++ )
+			memcpy( sys->verts + n_i * nDims, sys->mesh->verts[n_i], nDims * sizeof(double) );
+	}
+}
+
+
+Bool EulerDeform_TimeDeriv( void* crdAdvector, Index arrayInd, double* timeDeriv ) {
+	TimeIntegrand*		self = (TimeIntegrand*)crdAdvector;
+	FeVariable*				velocityField = (FeVariable*)self->data[0];
+	InterpolationResult	result = LOCAL;
+
+	/* check if the node information is on the local proc */
+	if (arrayInd >= Mesh_GetDomainSize(velocityField->feMesh,MT_VERTEX) )
+		result = OTHER_PROC;
+
+	FeVariable_GetValueAtNode( velocityField, arrayInd, timeDeriv );
+
+	/* Check if periodic */
+	if ( Stg_Class_IsInstance( velocityField->feMesh->generator, CartesianGenerator_Type ) ) {
+		CartesianGenerator* cartesianGenerator = (CartesianGenerator*) velocityField->feMesh->generator;
+		if ( cartesianGenerator->periodic[ I_AXIS ] )
+			timeDeriv[I_AXIS] = 0.0;
+		if ( cartesianGenerator->periodic[ J_AXIS ] )
+			timeDeriv[J_AXIS] = 0.0;
+		if ( cartesianGenerator->periodic[ K_AXIS ] )
+			timeDeriv[K_AXIS] = 0.0;
+	}
+		
+	if ( result == OTHER_PROC || result == OUTSIDE_GLOBAL || isinf(timeDeriv[0]) || isinf(timeDeriv[1]) || 
+	     ( velocityField->dim == 3 && isinf(timeDeriv[2]) ) ) 
+	{
+#if 0
+		Journal_Printf( Journal_Register( Error_Type, (Name)self->type  ),
+				"Error in func '%s' for particle with index %u.\n\tPosition (%g, %g, %g)\n\tVelocity here is (%g, %g, %g)."
+				"\n\tInterpolation result is %s.\n",
+				__func__, array_I, coord[0], coord[1], coord[2], 
+
+				InterpolationResultToStringMap[result]  );
+#endif	
+		return False;	
+	}
+
+	return True;
+}
+
+Bool _EulerDeform_LineInterp(double** crds,const double* pnt,
+                             unsigned fromDim,unsigned toDim, 
+			     double* val);
+Bool _EulerDeform_QuadYInterp(double** crds,const double* pnt,double* val);
+
+/* Make the top left or right corners float up to the height of the
+   point just inside. */
+
+void EulerDeform_FloatRightTop(EulerDeform_System* sys, Grid *grid,
+                               double** crds)
+{
+  int i, max_z;
+  IJK ijk, inside_ijk;
+  unsigned ind, nLocalNodes, inside;
+
+  nLocalNodes = Mesh_GetLocalSize( sys->mesh, MT_VERTEX );
+  ijk[0]=grid->sizes[0]-1;
+  ijk[1]=grid->sizes[1]-1;
+
+  if(Mesh_GetDimSize(sys->mesh)==2)
+    {
+      max_z=1;
+    }
+  else
+    {
+      max_z=grid->sizes[2];
+    }
+
+  for(i=0;i<max_z;++i)
+    {
+      ijk[2]=i;
+      ind=Grid_Project(grid,ijk);
+      if( !(!Mesh_GlobalToDomain( sys->mesh, MT_VERTEX, ind, &ind )
+            || ind >= nLocalNodes ))
+        {
+          inside_ijk[0]=ijk[0]-1;
+          inside_ijk[1]=ijk[1];
+          inside_ijk[2]=ijk[2];
+          inside=Grid_Project(grid,inside_ijk);
+          if(!(!Mesh_GlobalToDomain( sys->mesh, MT_VERTEX, inside, &inside )
+               || inside >= nLocalNodes ))
+            {
+              crds[ind][1]=crds[inside][1];
+            }
+        }
+    }
+}
+
+void EulerDeform_FloatLeftTop(EulerDeform_System* sys, Grid *grid,
+                              double** crds)
+{
+  int i, max_z;
+  IJK ijk, inside_ijk;
+  unsigned ind, nLocalNodes, inside;
+
+  nLocalNodes = Mesh_GetLocalSize( sys->mesh, MT_VERTEX );
+  ijk[0]=0;
+  ijk[1]=grid->sizes[1]-1;
+
+  if(Mesh_GetDimSize(sys->mesh)==2)
+    {
+      max_z=1;
+    }
+  else
+    {
+      max_z=grid->sizes[2];
+    }
+
+  for(i=0;i<max_z;++i)
+    {
+      ijk[2]=i;
+      ind=Grid_Project(grid,ijk);
+      if( !(!Mesh_GlobalToDomain( sys->mesh, MT_VERTEX, ind, &ind )
+            || ind >= nLocalNodes ))
+        {
+          inside_ijk[0]=ijk[0]+1;
+          inside_ijk[1]=ijk[1];
+          inside_ijk[2]=ijk[2];
+          inside=Grid_Project(grid,inside_ijk);
+          if(!(!Mesh_GlobalToDomain( sys->mesh, MT_VERTEX, inside, &inside )
+               || inside >= nLocalNodes ))
+            crds[ind][1]=crds[inside][1];
+        }
+    }
+}
+
+/* Remesh the left or right top corners in 2D or 3D */
+
+void EulerDeform_Remesh_Corner(Mesh *mesh, int corner, int inside,
+                               double side_coord) {
+  IJK		ijk;
+  Grid *grid;
+  grid =
+    *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+                                   ExtensionManager_GetHandle( mesh->info,
+                                                               "vertexGrid" ) );
+  ijk[0]=corner;
+  ijk[1]=grid->sizes[1]-1;
+  if(Mesh_GetDimSize(mesh)==2)
+    {
+      unsigned n_corner, n_interior, n, n_in;
+      n_corner=RegularMeshUtils_Node_3DTo1D(mesh,ijk);
+      ijk[0]=inside;
+      n_interior=RegularMeshUtils_Node_3DTo1D(mesh,ijk);
+      if(Mesh_GlobalToDomain(mesh,MT_VERTEX,
+                             n_corner,&n)
+         && Mesh_GlobalToDomain(mesh,MT_VERTEX,
+                                n_interior,&n_in))
+        {
+          double *crds[2];
+
+          crds[0]=mesh->verts[n];
+          crds[1]=mesh->verts[n_in];
+          if(!_EulerDeform_LineInterp(crds,&side_coord,0,1,
+                                       &(mesh->verts[n][1])))
+            {
+              printf("The side is moving in the wrong direction.\n");
+              printf("%g %g %g %g %g\n",side_coord,crds[0][0],crds[0][1],crds[1][0],crds[1][1]);
+              abort();
+            }
+          mesh->verts[n][0]=side_coord;
+        }
+    }
+  else /* 3D */
+    {
+      for(ijk[2]=0; ijk[2]<grid->sizes[2]; ++ijk[2])
+        {
+          unsigned n_corner, n_interior, n, n_in;
+          ijk[0]=corner;
+          n_corner=RegularMeshUtils_Node_3DTo1D(mesh,ijk);
+          ijk[0]=inside;
+          n_interior=RegularMeshUtils_Node_3DTo1D(mesh,ijk);
+          if(Mesh_GlobalToDomain(mesh,MT_VERTEX,n_corner,&n)
+             && Mesh_GlobalToDomain(mesh,MT_VERTEX,n_interior,&n_in))
+            {
+              double *crds[2];
+              crds[0]=mesh->verts[n];
+              crds[1]=mesh->verts[n_in];
+
+              if(!_EulerDeform_LineInterp(crds,&side_coord,0,1,&(mesh->verts[n][1]))
+                 || !_EulerDeform_LineInterp(crds,&side_coord,0,2,&(mesh->verts[n][2])))
+                {
+                  printf("The side is moving in the wrong direction.\n");
+                  printf("%g %g %g %g %g\n",side_coord,crds[0][0],crds[0][1],crds[1][0],crds[1][1]);
+                  abort();
+                }
+              mesh->verts[n][0]=side_coord;
+            }
+        }
+    }
+}
+
+void EulerDeform_WrapSurface( EulerDeform_System* sys, double** oldCrds, int top );
+
+void EulerDeform_Remesh( TimeIntegrand* crdAdvector, EulerDeform_Context* edCtx ) {
+  Mesh_Algorithms	*tmpAlgs, *oldAlgs;
+  unsigned	sys_i;
+
+  assert( edCtx );
+
+  /* We do the second system first, because that is the vertex
+     centered system.  We want the cell centered and vertex
+     centered systems to be compatible, so the cell centered
+     system is based on the vertex centered one. */
+
+  for( sys_i = 1; sys_i < edCtx->nSystems+1; sys_i++ ) {
+    EulerDeform_System*	sys = edCtx->systems
+      + sys_i%edCtx->nSystems;
+    double**		oldCrds;
+    double**		newCrds;
+    unsigned		nDomainNodes;
+    unsigned		nDims;
+    unsigned		var_i, n_i, dof_i;
+    Grid *grid;
+    grid =
+      *(Grid**)ExtensionManager_Get(sys->mesh->info, sys->mesh, 
+                                    ExtensionManager_GetHandle( sys->mesh->info,
+                                                                "vertexGrid" ));
+    /* Update the displacement field. */
+    if(sys->dispField) {
+      double disp[3];
+      int num_verts, num_dims;
+      int ii, jj;
+
+      num_dims = Mesh_GetDimSize(sys->mesh);
+      num_verts = Mesh_GetLocalSize(sys->mesh, MT_VERTEX);
+      for(ii = 0; ii < num_verts; ii++) {
+        FeVariable_GetValueAtNode(sys->dispField, ii, disp);
+        for(jj = 0; jj < num_dims; jj++)
+          disp[jj] += sys->verts[ii*num_dims + jj] - sys->mesh->verts[ii][jj];
+        FeVariable_SetValueAtNode(sys->dispField, ii, disp);
+      }
+    }
+
+    nDims = Mesh_GetDimSize( sys->mesh );
+    
+    /* Update all local coordinates. */
+    for( n_i = 0; n_i < Mesh_GetLocalSize( sys->mesh, MT_VERTEX ); n_i++ )
+      memcpy( sys->mesh->verts[n_i], sys->verts + n_i * nDims, nDims * sizeof(double) );
+    
+    /* Revert side coordinates if required. */
+    if( sys->staticSides ) {
+      IndexSet	*tmpIndSet;
+      unsigned	nInds, *inds;
+      unsigned	ind_i;
+      
+      /* Collect indices of all the sides. */
+      
+      tmpIndSet = EulerDeform_CreateStaticSet(sys);
+      IndexSet_GetMembers( tmpIndSet, &nInds, &inds );
+      
+      /* Copy back coords. */
+      for( ind_i = 0; ind_i < nInds; ind_i++ )
+        memcpy( sys->mesh->verts[inds[ind_i]], sys->sideCoords[ind_i], nDims * sizeof(double) );
+      FreeObject( tmpIndSet );
+      FreeArray( sys->sideCoords );
+      
+      if(sys->wrapTop)
+        {
+          if(sys->staticLeft && !sys->staticLeftTop && !sys->floatLeftTop)
+            {
+              EulerDeform_Remesh_Corner(sys->mesh,0,1,sys->x_left_coord);
+            }
+          if(sys->staticRight && !sys->staticRightTop && !sys->floatRightTop)
+            {
+              EulerDeform_Remesh_Corner(sys->mesh,grid->sizes[0]-1,
+                                        grid->sizes[0]-2,
+                                        sys->x_right_coord);
+            }
+        }
+
+    }
+
+    /* If we have regular mesh algorithms specified, set the
+       algorithms temporarily to an irregular method. */
+    if( !strcmp( sys->mesh->algorithms->type, "Mesh_RegularAlgorithms" ) && sys->remesher ) {
+      tmpAlgs = Mesh_Algorithms_New( "", edCtx->ctx );
+      oldAlgs = sys->mesh->algorithms;
+      sys->mesh->algorithms = NULL;
+      Mesh_SetAlgorithms( sys->mesh, tmpAlgs );
+    }
+    else
+      tmpAlgs = NULL;
+
+    /* Every system should synchronise the mesh coordinates. */
+    Mesh_Sync( sys->mesh );
+    Mesh_DeformationUpdate( sys->mesh );
+
+    /* Only if remesher specified. */
+    if( !sys->remesher ) {
+      continue;
+    }
+
+    /* If a remesh interval is requested, check now. */
+    if( sys->interval > 0 && edCtx->ctx->timeStep % sys->interval > 0 ) {
+      Journal_Printf( Underworld_Info,
+                      "*** EulerDeform: Not remeshing this timestep.\n" );
+      continue;
+    }
+    Journal_Printf( Underworld_Info, "*** EulerDeform: Remeshing.\n" );
+
+    /* Store old coordinates. */
+    nDomainNodes = FeMesh_GetNodeDomainSize( sys->mesh );
+    oldCrds = AllocArray2D( double, nDomainNodes, nDims );
+    for( n_i = 0; n_i < nDomainNodes; n_i++ )
+      memcpy( oldCrds[n_i], sys->mesh->verts[n_i], nDims * sizeof(double) );
+
+    /* Remesh the system. */
+    Stg_Component_Execute( sys->remesher, NULL, True );
+    Mesh_Sync( sys->mesh );
+
+    /* Shrink wrap the top/bottom surface. */
+    if( sys->wrapTop )
+      EulerDeform_WrapSurface( sys, oldCrds, 1 );
+    if( sys->wrapBottom )
+      EulerDeform_WrapSurface( sys, oldCrds, 0 );
+
+    /* Swap old coordinates back in temporarily. */
+    newCrds = sys->mesh->verts;
+    sys->mesh->verts = oldCrds;
+
+    /* Interpolate the variables. */
+    for( var_i = 0; var_i < sys->nFields; var_i++ )
+      EulerDeform_InterpVar( sys->fields[var_i],
+                             NULL/*sys->vars[var_i]*/, sys->mesh, newCrds );
+
+    /* Float the top left and right corners if needed.  We do this
+       after interpolating, because these points almost certainly are
+       outside of the domain, and so can not be interpolated to. */
+    if(sys->floatLeftTop)
+      EulerDeform_FloatLeftTop(sys,grid,newCrds);
+    if(sys->floatRightTop)
+      EulerDeform_FloatRightTop(sys,grid,newCrds);
+
+    /* Create an artificial displacement field from the nodal
+     * displacements between newCrds and oldCrds.  This displacement
+     * is currently used to correct the advDiffEqn's nodal velocity
+     * input */
+    if( edCtx->artDField ) {
+      double artDis[3]; /* temporary displacement vector */
+
+      for( n_i = 0 ; n_i < nDomainNodes; n_i++ ) {
+        for( dof_i = 0 ; dof_i < nDims ; dof_i++ ) {
+          artDis[dof_i] = newCrds[n_i][dof_i] - oldCrds[n_i][dof_i];
+        }
+        FeVariable_SetValueAtNode( edCtx->artDField, n_i, artDis );
+      }
+        
+    }
+
+    /* Swap back coordinates and free memory. */
+    sys->mesh->verts = newCrds;
+    FreeArray( oldCrds );
+    
+    /* Swap back old algorithms. */
+    if( tmpAlgs ) {
+      Mesh_SetAlgorithms( sys->mesh, oldAlgs );
+    }
+
+    /* Re-sync with new coordinates. */
+    Mesh_Sync( sys->mesh );
+    Mesh_DeformationUpdate( sys->mesh );
+    for( var_i = 0; var_i < sys->nFields; var_i++ )
+      FeVariable_SyncShadowValues( sys->fields[var_i] );
+  }
+}
+
+
+void EulerDeform_InterpVar( FieldVariable* field, Variable* var, Mesh* mesh, double** newCrds ) {
+	double*		newVals;
+	unsigned	curValInd = 0;
+	unsigned	nLocalNodes;
+	unsigned	n_i, c_i;
+
+	assert( field );
+	/*assert( var );*/
+	assert( newCrds );
+
+	/* Allocate for new values. */
+	nLocalNodes = Mesh_GetLocalSize( mesh, MT_VERTEX );
+	newVals = Memory_Alloc_Array( double, field->fieldComponentCount * nLocalNodes, "EulerDeform_InterpVar::newVals" );
+
+	/* Interpolate using new node coordinates. */
+	for( n_i = 0; n_i < nLocalNodes; n_i++ ) {
+		InterpolationResult	res;
+
+		/* Interpolate the value. */
+		res = FieldVariable_InterpolateValueAt( field, newCrds[n_i], newVals + n_i * field->fieldComponentCount );
+		if( res == OTHER_PROC || res == OUTSIDE_GLOBAL ) {
+			FeVariable_GetValueAtNode( (FeVariable*)field, n_i, 
+						   newVals + n_i * field->fieldComponentCount );
+		}
+	}
+
+	/* Transfer the new values back to the variable. */
+	for( n_i = 0; n_i < nLocalNodes; n_i++ ) {
+	   for( c_i = 0; c_i < field->fieldComponentCount; c_i++ )
+	      DofLayout_SetValueDouble( ((FeVariable*)field)->dofLayout, n_i, c_i, newVals[curValInd++] );
+	}
+
+	/* Free the values array. */
+	FreeArray( newVals );
+}
+
+void EulerDeform_InternalLoop( EulerDeform_System* sys, Grid* grm, double** oldCrds, unsigned* ijk, unsigned curDim, int top );
+
+void EulerDeform_WrapSurface( EulerDeform_System* sys, double** oldCrds, int top ) {
+	IJK	ijk;
+	Grid*	grm;
+	Mesh*	mesh;
+
+	assert( sys );
+	assert( oldCrds );
+
+	/* Loop over top internal surface. */
+	mesh = sys->mesh;
+	grm = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+					     ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
+	EulerDeform_InternalLoop( sys, grm, oldCrds, ijk, 0, top );
+}
+
+#if 0
+void EulerDeform_WrapLeftSurface( EulerDeform_System* sys, double** oldCrds ) {
+	IJK	ijk;
+	GRM	grm;
+
+	assert( sys );
+	assert( oldCrds );
+
+	/* Loop over top internal surface. */
+	RegMesh_Generalise( sys->mesh, &grm );
+	EulerDeform_LeftInternalLoop( sys, &grm, oldCrds, ijk, 0 );
+}
+#endif
+
+
+void _EulerDeform_TriBarycenter( double** tri, const double* pnt, double* dst ) {
+	double	a = tri[0][0] - tri[2][0];
+	double	b = tri[1][0] - tri[2][0];
+	double	c = tri[2][0] - pnt[0];
+	double	d = tri[0][1] - tri[2][1];
+	double	e = tri[1][1] - tri[2][1];
+	double	f = tri[2][1] - pnt[1];
+	double	g = tri[0][2] - tri[2][2];
+	double	h = tri[1][2] - tri[2][2];
+	double	i = tri[2][2] - pnt[2];
+
+	dst[0] = (b * (f + i) - c * (e + h)) / (a * (e + h) - b * (d + g));
+	dst[1] = (a * (f + i) - c * (d + g)) / (b * (d + g) - a * (e + h));
+	dst[2] = 1.0 - dst[0] - dst[1];
+}
+
+
+Bool _EulerDeform_QuadYInterp( double** crds, const double* pnt, double* val ) {
+	double*		modCrds[4];
+	double		modCrds0[2], modCrds1[2], modCrds2[2], modCrds3[2];
+	unsigned*	inds[2];
+	unsigned	inds0[3], inds1[3];
+	unsigned	inc[4];
+	double		modPnt[3];
+	unsigned	inside;
+	double		bc[3];
+
+	modCrds[0] = modCrds0;
+	modCrds[1] = modCrds1;
+	modCrds[2] = modCrds2;
+	modCrds[3] = modCrds3;
+	modCrds[0][0] = crds[0][0]; modCrds[0][1] = crds[0][2];
+	modCrds[1][0] = crds[1][0]; modCrds[1][1] = crds[1][2];
+	modCrds[2][0] = crds[2][0]; modCrds[2][1] = crds[2][2];
+	modCrds[3][0] = crds[3][0]; modCrds[3][1] = crds[3][2];
+	modPnt[0] = pnt[0]; modPnt[1] = pnt[2];
+
+	inds[0] = inds0;
+	inds[1] = inds1;
+	inds[0][0] = 0; inds[0][1] = 1; inds[0][2] = 2;
+	inds[1][0] = 1; inds[1][1] = 3; inds[1][2] = 2;
+	inc[0] = 0; inc[1] = 1; inc[2] = 2; inc[3] = 3;
+
+	if( Simplex_Search2D( modCrds, inc, 2, inds, 
+			      modPnt, bc, &inside ) )
+	{
+		*val = bc[0] * crds[inds[inside][0]][1] + bc[1] * crds[inds[inside][1]][1] + 
+			bc[2] * crds[inds[inside][2]][1];
+		return True;
+	}
+	else
+		return False;
+}
+
+
+Bool _EulerDeform_FindBarycenter1D( const double* crds, const double pnt, 
+				    double* bcs )
+{
+	assert( crds );
+	assert( bcs );
+
+	bcs[1] = (pnt - crds[0])/(crds[1] - crds[0]);
+	bcs[0] = 1.0 - bcs[1];
+
+	return (bcs[0] >= 0.0 && bcs[0] <= 1.0 && bcs[1] >= 0.0 && bcs[1] <= 1.0) ? True : False;
+}
+
+
+Bool _EulerDeform_LineInterp(double** crds, const double* pnt, unsigned fromDim, unsigned toDim, 
+			      double* val ) {
+	double	bcCrds[2];
+	double	bcs[2];
+
+	assert( crds );
+	assert( val );
+
+	bcCrds[0] = crds[0][fromDim];
+	bcCrds[1] = crds[1][fromDim];
+	if( _EulerDeform_FindBarycenter1D( bcCrds, pnt[fromDim], bcs ) ) {
+		*val = bcs[0]*crds[0][toDim] + bcs[1]*crds[1][toDim];
+		return True;
+	}
+
+	return False;
+}
+
+
+#if 0
+Bool _EulerDeform_QuadZInterp( double** crds, const double* pnt, double* val ) {
+	double		modCrds[4][3];
+	double		modPnt[3];
+	unsigned	inds[3];
+	double		bc[3];
+
+	modCrds[0][0] = crds[0][0]; modCrds[0][1] = crds[0][1]; modCrds[0][2] = 0.0;
+	modCrds[1][0] = crds[1][0]; modCrds[1][1] = crds[1][1]; modCrds[1][2] = 0.0;
+	modCrds[2][0] = crds[2][0]; modCrds[2][1] = crds[2][1]; modCrds[2][2] = 0.0;
+	modCrds[3][0] = crds[3][0]; modCrds[3][1] = crds[3][1]; modCrds[3][2] = 0.0;
+	modPnt[0] = pnt[0]; modPnt[1] = pnt[1]; modPnt[2] = 0.0;
+
+	if( _HexaEL_FindTriBarycenter( (const double**)modCrds, modPnt, bc, inds, INCLUSIVE_UPPER_BOUNDARY, NULL, 0 ) ) {
+		*val = bc[0]*crds[inds[0]][1] + bc[1]*crds[inds[1]][1] + bc[2]*crds[inds[2]][1];
+		return True;
+	}
+	else
+		return False;
+}
+#endif
+
+
+void EulerDeform_InternalLoop( EulerDeform_System* sys, Grid* grm, double** oldCrds, unsigned* ijk, unsigned curDim, int top ) {
+	unsigned	nDims;
+	XYZ		newCrd, oldCrd;
+	double*		crds[4];
+	double		crds0[3], crds1[3], crds2[3], crds3[3];
+	unsigned	centerInd;
+	Mesh*		mesh;
+	unsigned	nLocalNodes;
+	unsigned	ind;
+        double          fudge_factor;
+        
+        /* fudge_factor nudges the coordinate inside the mesh a little
+           to avoid failed interpolations */
+        fudge_factor=1.0e-10;
+
+	if( curDim < grm->nDims ) {
+		if( curDim == 1 ) {
+                        if(top) {
+                          ijk[1] = grm->sizes[curDim] - 1;
+                        }
+                        else {
+                          ijk[1]=0;
+                        }
+			EulerDeform_InternalLoop( sys, grm, oldCrds, ijk, curDim + 1, top );
+		}
+		else {
+			for( ijk[curDim] = 0; ijk[curDim] < grm->sizes[curDim]; ijk[curDim]++ ) {
+                          EulerDeform_InternalLoop( sys, grm, oldCrds, ijk, curDim + 1, top );
+			}
+		}
+	}
+	else {
+		if( grm->nDims == 2 ) {
+			mesh = sys->mesh;
+			nDims = Mesh_GetDimSize( mesh );
+
+			crds[0] = crds0;
+			crds[1] = crds1;
+			nLocalNodes = Mesh_GetLocalSize( mesh, MT_VERTEX );
+
+			/* Skip corners. */
+			if( ijk[0] == 0 || ijk[0] == grm->sizes[0] - 1 ) {
+				return;
+			}
+
+			/* Get old and new coordinate. */
+			centerInd = Grid_Project( grm, ijk );
+			if( !Mesh_GlobalToDomain( mesh, MT_VERTEX, centerInd, &centerInd ) || centerInd >= nLocalNodes )
+				return;
+
+			newCrd[0] = mesh->verts[centerInd][0];
+			newCrd[1] = mesh->verts[centerInd][1];
+			oldCrd[0] = oldCrds[centerInd][0];
+			oldCrd[1] = oldCrds[centerInd][1];
+
+			/* Are we left or right? */
+			if( newCrd[0] < oldCrd[0] ) {
+				ijk[0]--; ind = Grid_Project( grm, ijk ); ijk[0]++;
+				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
+				memcpy( crds[0], oldCrds[ind], nDims * sizeof(double) );
+				memcpy( crds[1], oldCrd, nDims * sizeof(double) );
+			}
+			else if( newCrd[0] > oldCrd[0] ) {
+				ijk[0]++; ind = Grid_Project( grm, ijk ); ijk[0]--;
+				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
+				memcpy( crds[1], oldCrds[ind], nDims * sizeof(double) );
+				memcpy( crds[0], oldCrd, nDims * sizeof(double) );
+			}
+
+                        if(newCrd[0]==oldCrd[0]) {
+                          mesh->verts[centerInd][1]=oldCrd[1];
+                        }
+                        else {
+
+                          /* Interpolate. */
+#ifndef NDEBUG
+			assert( _EulerDeform_LineInterp(crds, newCrd, 0, 1, &mesh->verts[centerInd][1] ) );
+#else
+			_EulerDeform_LineInterp(crds, newCrd, 0, 1, &mesh->verts[centerInd][1] );
+#endif
+                        if((mesh->verts[centerInd][1]>0) ^ top)
+                          {
+                            mesh->verts[centerInd][1] *= 1+fudge_factor;
+                          }
+                        else
+                          {
+                            mesh->verts[centerInd][1] *= 1-fudge_factor;
+                          }
+                        }
+		}
+		else if( grm->nDims == 3 ) {
+			mesh = sys->mesh;
+			nDims = Mesh_GetDimSize( mesh );
+
+			crds[0] = crds0; crds[1] = crds1; crds[2] = crds2; crds[3] = crds3;
+			nLocalNodes = Mesh_GetLocalSize( mesh, MT_VERTEX );
+
+			/* Skip corners. */
+			if( (ijk[0] == 0 || ijk[0] == grm->sizes[0] - 1) && 
+			    (ijk[2] == 0 || ijk[2] == grm->sizes[2] - 1))
+			{
+				return;
+			}
+
+			/* Get old and new coordinate. */
+			centerInd = Grid_Project( grm, ijk );
+			if( !Mesh_GlobalToDomain( mesh, MT_VERTEX, centerInd, &centerInd ) || centerInd >= nLocalNodes )
+				return;
+
+			newCrd[0] = mesh->verts[centerInd][0];
+			newCrd[1] = mesh->verts[centerInd][1];
+			newCrd[2] = mesh->verts[centerInd][2];
+			oldCrd[0] = oldCrds[centerInd][0];
+			oldCrd[1] = oldCrds[centerInd][1];
+			oldCrd[2] = oldCrds[centerInd][2];
+
+			/* Handle internal nodes. */
+			if( ijk[0] > 0 && ijk[2] > 0 ) {
+				ijk[0]--; ijk[2]--; ind = Grid_Project( grm, ijk );
+				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
+				memcpy( crds[0], oldCrds[ind], nDims * sizeof(double) );
+
+				ijk[0]++; ind = Grid_Project( grm, ijk );
+				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
+				memcpy( crds[1], oldCrds[ind], nDims * sizeof(double) );
+
+				ijk[0]--; ijk[2]++; ind = Grid_Project( grm, ijk );
+				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
+				memcpy( crds[2], oldCrds[ind], nDims * sizeof(double) );
+
+				ijk[0]++; ind = Grid_Project( grm, ijk );
+				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
+				memcpy( crds[3], oldCrds[ind], nDims * sizeof(double) );
+
+				if( _EulerDeform_QuadYInterp( crds, newCrd, &mesh->verts[centerInd][1] ) ) {
+                                  if((mesh->verts[centerInd][1]>0) ^ top)
+                                    {
+                                      mesh->verts[centerInd][1] *= 1+fudge_factor;
+                                    }
+                                  else
+                                    {
+                                      mesh->verts[centerInd][1] *= 1-fudge_factor;
+                                    }
+                                  return;
+				}
+			}
+
+			if( ijk[0] > 0 && ijk[2] < grm->sizes[2] - 1 ) {
+				ijk[0]--; ind = Grid_Project( grm, ijk );
+				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
+				memcpy( crds[0], oldCrds[ind], nDims * sizeof(double) );
+
+				ijk[0]++; ind = Grid_Project( grm, ijk );
+				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
+				memcpy( crds[1], oldCrds[ind], nDims * sizeof(double) );
+
+				ijk[0]--; ijk[2]++; ind = Grid_Project( grm, ijk );
+				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
+				memcpy( crds[2], oldCrds[ind], nDims * sizeof(double) );
+
+				ijk[0]++; ind = Grid_Project( grm, ijk );
+				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
+				memcpy( crds[3], oldCrds[ind], nDims * sizeof(double) );
+
+				ijk[2]--;
+				if( _EulerDeform_QuadYInterp( crds, newCrd, &mesh->verts[centerInd][1] ) ) {
+                                  if((mesh->verts[centerInd][1]>0) ^ top)
+                                    {
+                                      mesh->verts[centerInd][1] *= 1+fudge_factor;
+                                    }
+                                  else
+                                    {
+                                      mesh->verts[centerInd][1] *= 1-fudge_factor;
+                                    }
+                                  return;
+				}
+			}
+
+			if( ijk[0] < grm->sizes[0] - 1 && ijk[2] > 0 ) {
+				ijk[2]--; ind = Grid_Project( grm, ijk );
+				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
+				memcpy( crds[0], oldCrds[ind], nDims * sizeof(double) );
+
+				ijk[0]++; ind = Grid_Project( grm, ijk );
+				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
+				memcpy( crds[1], oldCrds[ind], nDims * sizeof(double) );
+
+				ijk[0]--; ijk[2]++; ind = Grid_Project( grm, ijk );
+				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
+				memcpy( crds[2], oldCrds[ind], nDims * sizeof(double) );
+
+				ijk[0]++; ind = Grid_Project( grm, ijk );
+				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
+				memcpy( crds[3], oldCrds[ind], nDims * sizeof(double) );
+
+				ijk[0]--;
+				if( _EulerDeform_QuadYInterp( crds, newCrd, &mesh->verts[centerInd][1] ) ) {
+                                  if((mesh->verts[centerInd][1]>0) ^ top)
+                                    {
+                                      mesh->verts[centerInd][1] *= 1+fudge_factor;
+                                    }
+                                  else
+                                    {
+                                      mesh->verts[centerInd][1] *= 1-fudge_factor;
+                                    }
+                                  return;
+				}
+			}
+
+			if( ijk[0] < grm->sizes[0] - 1 && ijk[2] < grm->sizes[2] - 1 ) {
+				ind = Grid_Project( grm, ijk );
+				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
+				memcpy( crds[0], oldCrds[ind], nDims * sizeof(double) );
+
+				ijk[0]++; ind = Grid_Project( grm, ijk );
+				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
+				memcpy( crds[1], oldCrds[ind], nDims * sizeof(double) );
+
+				ijk[0]--; ijk[2]++; ind = Grid_Project( grm, ijk );
+				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
+				memcpy( crds[2], oldCrds[ind], nDims * sizeof(double) );
+
+				ijk[0]++; ind = Grid_Project( grm, ijk );
+				insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, ind, &ind ), != 0 );
+				memcpy( crds[3], oldCrds[ind], nDims * sizeof(double) );
+
+				ijk[0]--; ijk[2]--;
+				if( _EulerDeform_QuadYInterp( crds, newCrd, &mesh->verts[centerInd][1] ) ) {
+                                  if((mesh->verts[centerInd][1]>0) ^ top)
+                                    {
+                                      mesh->verts[centerInd][1] *= 1+fudge_factor;
+                                    }
+                                  else
+                                    {
+                                      mesh->verts[centerInd][1] *= 1-fudge_factor;
+                                    }
+                                  return;
+				}
+			}
+
+			assert( 0 );
+		}
+		else {
+			assert( 0 );
+		}
+	}
+}
+
+#if 0
+void EulerDeform_LeftInternalLoop( EulerDeform_System* sys, GRM* grm, Coord* oldCrds, unsigned* ijk, unsigned curDim ) {
+	if( curDim < grm->nDims ) {
+		if( curDim == 0 ) {
+			ijk[0] = 0;
+			EulerDeform_LeftInternalLoop( sys, grm, oldCrds, ijk, curDim + 1 );
+		}
+		else {
+			for( ijk[curDim] = 1; ijk[curDim] < grm->nNodes[curDim] - 1; ijk[curDim]++ ) {
+				EulerDeform_LeftInternalLoop( sys, grm, oldCrds, ijk, curDim + 1 );
+			}
+		}
+	}
+	else {
+		if( grm->nDims == 2 ) {
+			XYZ		newCrd, oldCrd;
+			unsigned	centerInd;
+			Mesh*		mesh = sys->mesh;
+
+			/* Get old and new coordinate. */
+			GRM_Project( grm, ijk, &centerInd );
+			newCrd[0] = mesh->nodeCoord[centerInd][0];
+			newCrd[1] = mesh->nodeCoord[centerInd][1];
+			oldCrd[0] = oldCrds[centerInd][0];
+			oldCrd[1] = oldCrds[centerInd][1];
+
+			/* Are we above or below? */
+			if( newCrd[1] < oldCrd[1] ) {
+				XYZ		leftCrd;
+				unsigned	leftInd;
+				double		a0, a1;
+
+				/* Get left old coord. */
+				ijk[1]--;
+				GRM_Project( grm, ijk, &leftInd );
+				ijk[1]++;
+				leftCrd[0] = oldCrds[leftInd][0];
+				leftCrd[1] = oldCrds[leftInd][1];
+
+				/* Calc barycenter. */
+				a1 = (newCrd[1] - leftCrd[1]) / (oldCrd[1] - leftCrd[1]);
+				a0 = 1.0 - a1;
+				mesh->nodeCoord[centerInd][0] = (a0 * leftCrd[0] + a1 * oldCrd[0])*(1.0+1.0e-10);
+			}
+			else {
+				XYZ		rightCrd;
+				unsigned	rightInd;
+				double		a0, a1;
+
+				/* Get right old coord. */
+				ijk[1]++;
+				GRM_Project( grm, ijk, &rightInd );
+				ijk[1]--;
+				rightCrd[0] = oldCrds[rightInd][0];
+				rightCrd[1] = oldCrds[rightInd][1];
+
+				/* Calc barycenter. */
+				a1 = (newCrd[1] - oldCrd[1]) / (rightCrd[1] - oldCrd[1]);
+				a0 = 1.0 - a1;
+				mesh->nodeCoord[centerInd][0] = (a0 * oldCrd[0] + a1 * rightCrd[0])*(1.0+1.0e-10);
+			}
+		}
+		else if( grm->nDims == 3 ) {
+			assert( 0 );
+		}
+		else {
+			assert( 0 );
+		}
+	}
+}
+#endif
+
+
diff -r 038180046f6f -r 4b2d36e5021d plugins/ExtractPetscObjects/ExtractPetscObjects.c
--- a/plugins/ExtractPetscObjects/ExtractPetscObjects.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,305 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: ExtractPetscObjects.c 358 2007-06-02 06:17:30Z Mayhem $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-#include <string.h>
-#include <mpi.h>
-#include <petsc.h>
-#include <petscmat.h>
-#include <petscvec.h>
-
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Underworld.h>
-#include <StgFEM/FrequentOutput/FrequentOutput.h>
-
-
-
-#include "ExtractPetscObjects.h"
-
-const Type Underworld_ExtractPetscObjects_Type = "Underworld_ExtractPetscObjects";
-
-void _Underworld_ExtractPetscObjects_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) 
-{
-	UnderworldContext*  context;
-	
-	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data ); 
-	
-	Underworld_ExtractPetscObjects_PrintHeaderToFile( context  );
-	ContextEP_Append( context, AbstractContext_EP_FrequentOutput     , Underworld_ExtractPetscObjects_Dump );
-}
-
-void* _Underworld_ExtractPetscObjects_DefaultNew( Name name ) 
-{
-	return Codelet_New(
-		Underworld_ExtractPetscObjects_Type,
-		_Underworld_ExtractPetscObjects_DefaultNew,
-		_Underworld_ExtractPetscObjects_AssignFromXML,
-		_Codelet_Build,
-		_Codelet_Initialise,
-		_Codelet_Execute,
-		_Codelet_Destroy,
-		name );
-}
-
-Index Underworld_ExtractPetscObjects_Register( PluginsManager* pluginsManager ) 
-{
-	return PluginsManager_Submit( pluginsManager, Underworld_ExtractPetscObjects_Type, (Name)"0", _Underworld_ExtractPetscObjects_DefaultNew  );
-}
-
-
-/* 
-Dump the matrices and vectors to binary files
-The file suffix is extracted from the xml variable <ProbDescription>
-
-The file,
-    ProbDescription-xxxx.info,
-(where xxxx is the time step counter) contains the list of file names associated with 
-the current problem. The list defines the names for the matrices K,G,D,C and vectors f,h.
-If the name is NULL, there is no saved petsc object.
-
-*/
-
-void Underworld_ExtractPetscObjects_Dump( void* _context ) 
-{
-	UnderworldContext *context = (UnderworldContext*) _context;
-	
-	int		length;
-	char	machine_name[256];
-	int		rank;
-	char	*probName, fileName[256];
-	FILE	*info;
-	char	kName[256];
-	char	GradName[256];
-	char	DivName[256];
-	char	CName[256];
-	char	FName[256];
-	char	HName[256];
-	char	SpcName[256];
-	
-	char			mat_name[256];
-	char			vec_name[256];
-	PetscViewer		mat_view_file;
-	PetscViewer		vec_view_file;
-	Stokes_SLE		*stokesSLE = context->stokesSLE;
-	Mat A;
-	Vec b;
-	MPI_Comm comm;
-	int step;
-	Stokes_SLE_UzawaSolver *uzawaSolver;
-	Bool uzawa_present;
-	int ex_step, default_step;
-	
-	/* Init names */
-	strcpy( kName,    "NULL" );
-	strcpy( GradName, "NULL" );
-	strcpy( DivName,  "NULL" );
-	strcpy( CName,    "NULL" );
-	strcpy( FName,    "NULL" );
-	strcpy( HName,    "NULL" );
-	
-	
-	step = context->timeStep;
-
-	/* Get time step to perform extraction */
-	default_step =  -6699;
-	ex_step = Dictionary_Entry_Value_AsInt(
-			Dictionary_GetDefault( context->dictionary, "ExtractMatricesAtStep", Dictionary_Entry_Value_FromInt(default_step) )
-						);
-	if( ex_step != default_step ) { /* Then we want to dump a specific step */
-		if( ex_step != step ) { /* If current step does not match required step */
-			return;
-		}
-	}	
-
-	
-	/* Write the matrices and vectors to disk */
-	comm = context->communicator;
-	
-	// get filename from problem description
-	probName = strdup( Dictionary_Entry_Value_AsString( Dictionary_Get( context->dictionary, (Dictionary_Entry_Key)"ProbDescription" ) ));
-	printf("\n\n");
-	printf("**********************************************\n" );
-	printf("******     Extracting PetscObjects      ******\n" );
-	printf("**********************************************\n" );
-	printf("  ProbDescription: %s \n", probName );
-	
-	MPI_Get_processor_name( machine_name, &length);
-	MPI_Comm_rank( context->communicator, &rank );
-
-	
-	
-	/* Write K to file */
-	if( stokesSLE->kStiffMat != NULL ) {
-		sprintf( kName, "k--%s-step%d-%s", probName,step, machine_name );
-		sprintf( mat_name, "%s/%s", context->outputPath, kName );
-		printf("  Writing kMatrix:                    %s \n",mat_name );
-		
-/* 		if( !stokesSLE->kStiffMat->useShellMatrix ) */
-			A = stokesSLE->kStiffMat->matrix;
-/* 		else */
-/* 			A = stokesSLE->kStiffMat->shellMatrix->matrix; */
-		PetscViewerBinaryOpen( comm, mat_name, FILE_MODE_WRITE, &mat_view_file );
-		MatView( A, mat_view_file );
-		PetscViewerDestroy( mat_view_file );
-	}
-	/* Write G to file */
-	if( stokesSLE->gStiffMat != NULL ) {
-		sprintf( GradName, "g--%s-step%d-%s", probName,step, machine_name );
-		sprintf( mat_name, "%s/%s", context->outputPath, GradName );
-		printf("  Writing Grad:                       %s \n",mat_name );
-		
-/* 		if( !stokesSLE->gStiffMat->useShellMatrix ) */
-			A = stokesSLE->gStiffMat->matrix;
-/* 		else */
-/* 			A = stokesSLE->gStiffMat->shellMatrix->matrix; */
-		PetscViewerBinaryOpen( comm, mat_name, FILE_MODE_WRITE, &mat_view_file );
-		MatView( A, mat_view_file );
-		PetscViewerDestroy( mat_view_file );
-	}
-	
-	/* Write Div to file */	
-	if( stokesSLE->dStiffMat != NULL ) {
-		sprintf( DivName, "div--%s-step%d-%s", probName, step, machine_name );
-		sprintf( mat_name, "%s/%s", context->outputPath, DivName );
-		printf("  Writing Div:                        %s \n",mat_name );
-		
-/* 		if( !stokesSLE->dStiffMat->useShellMatrix ) */
-			A = stokesSLE->dStiffMat->matrix;
-/* 		else */
-/* 			A = stokesSLE->dStiffMat->shellMatrix->matrix; */
-		PetscViewerBinaryOpen( comm, mat_name, FILE_MODE_WRITE, &mat_view_file );
-		MatView( A, mat_view_file );
-		PetscViewerDestroy( mat_view_file );
-	}
-	
-	/* Write C to file */
-	if( stokesSLE->cStiffMat != NULL ) {
-		sprintf( CName, "c--%s-step%d-%s", probName, step, machine_name );
-		sprintf( mat_name, "%s/%s", context->outputPath, CName );
-		printf("  Writing C:                          %s \n",mat_name );
-		
-/* 		if( !stokesSLE->cStiffMat->useShellMatrix ) */
-			A = stokesSLE->cStiffMat->matrix;
-/* 		else */
-/* 			A = stokesSLE->cStiffMat->shellMatrix->matrix; */
-		PetscViewerBinaryOpen( comm, mat_name, FILE_MODE_WRITE, &mat_view_file );
-		MatView( A, mat_view_file );
-		PetscViewerDestroy( mat_view_file );
-	}
-	
-	
-	/* Momentum rhs */
-	if( stokesSLE->fForceVec != NULL ) {
-		sprintf( FName, "F--%s-step%d-%s", probName, step, machine_name );
-		sprintf( vec_name, "%s/%s", context->outputPath, FName );
-		printf("  Writing F:                          %s \n", vec_name );
-		
-		b = stokesSLE->fForceVec->vector;
-		PetscViewerBinaryOpen( comm, vec_name, FILE_MODE_WRITE, &vec_view_file );
-		VecView( b, vec_view_file );
-		PetscViewerDestroy( vec_view_file );
-	}
-	
-	/* Continuity rhs */
-	if( stokesSLE->hForceVec != NULL ) {
-		sprintf( HName, "H--%s-step%d-%s", probName, step, machine_name );
-		sprintf( vec_name, "%s/%s", context->outputPath, HName );
-		printf("  Writing H:                          %s \n", vec_name );
-		
-		b = stokesSLE->hForceVec->vector;
-		PetscViewerBinaryOpen( comm, vec_name, FILE_MODE_WRITE, &vec_view_file );
-		VecView( b, vec_view_file );
-		PetscViewerDestroy( vec_view_file );
-	}
-	
-	/* Check if solver is Uzawa and spit out the preconditioner used */
-	uzawa_present = False;
-	uzawa_present = Stg_Class_IsInstance( stokesSLE->solver, Stokes_SLE_UzawaSolver_Type );
-	if( uzawa_present == True ) {
-		sprintf( SpcName, "Spc--%s-step%d-%s", probName, step, machine_name );
-		sprintf( mat_name, "%s/%s", context->outputPath, SpcName );
-		printf("  Writing Schur pc operator (UW_Q22): %s \n",mat_name );
-	
-		uzawaSolver = (Stokes_SLE_UzawaSolver*)stokesSLE->solver;
-		A = uzawaSolver->preconditioner->matrix;
-		PetscViewerBinaryOpen( comm, mat_name, FILE_MODE_WRITE, &mat_view_file );
-		MatView( A, mat_view_file );
-		PetscViewerDestroy( mat_view_file );
-	}
-	
-	
-	
-	if( rank == 0 ) {
-		
-		sprintf( fileName, "%s/%s-step%d.info", context->outputPath, probName, context->timeStep );
-		printf("  Info file:                          %s \n", fileName );			
-		
-		if (( info = fopen (fileName, "w")) == NULL)  {
-			(void) fprintf(stderr, "Error: couldn't open file %s for writing. Exiting.\n", fileName);
-			PetscFinalize();
-			exit(1);
-		}
-		
-		/* Write the object info to file */
-		fprintf( info, "%s %s %s %s %s %s",
-				kName, GradName, DivName, CName,
-				FName, HName );
-		
-		fclose( info );
-	}
-	
-//	b = (Vec)stokesSLE->pSolnVec->vector;
-//	VecView( b, PETSC_VIEWER_STDOUT_WORLD );
-	
-	
-}
-
-void Underworld_ExtractPetscObjects_PrintHeaderToFile( void* context ) 
-{
-	StgFEM_FrequentOutput_PrintString( context, "ExtractPetscObjects" );
-}
-
-
-
diff -r 038180046f6f -r 4b2d36e5021d plugins/ExtractPetscObjects/ExtractPetscObjects.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/ExtractPetscObjects/ExtractPetscObjects.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,305 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: ExtractPetscObjects.c 358 2007-06-02 06:17:30Z Mayhem $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+#include <string.h>
+#include <mpi.h>
+#include <petsc.h>
+#include <petscmat.h>
+#include <petscvec.h>
+
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Underworld.h>
+#include <StgFEM/FrequentOutput/FrequentOutput.h>
+
+
+
+#include "ExtractPetscObjects.h"
+
+const Type Underworld_ExtractPetscObjects_Type = "Underworld_ExtractPetscObjects";
+
+void _Underworld_ExtractPetscObjects_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) 
+{
+	UnderworldContext*  context;
+	
+	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data ); 
+	
+	Underworld_ExtractPetscObjects_PrintHeaderToFile( context  );
+	ContextEP_Append( context, AbstractContext_EP_FrequentOutput     , Underworld_ExtractPetscObjects_Dump );
+}
+
+void* _Underworld_ExtractPetscObjects_DefaultNew( Name name ) 
+{
+	return Codelet_New(
+		Underworld_ExtractPetscObjects_Type,
+		_Underworld_ExtractPetscObjects_DefaultNew,
+		_Underworld_ExtractPetscObjects_AssignFromXML,
+		_Codelet_Build,
+		_Codelet_Initialise,
+		_Codelet_Execute,
+		_Codelet_Destroy,
+		name );
+}
+
+Index Underworld_ExtractPetscObjects_Register( PluginsManager* pluginsManager ) 
+{
+	return PluginsManager_Submit( pluginsManager, Underworld_ExtractPetscObjects_Type, (Name)"0", _Underworld_ExtractPetscObjects_DefaultNew  );
+}
+
+
+/* 
+Dump the matrices and vectors to binary files
+The file suffix is extracted from the xml variable <ProbDescription>
+
+The file,
+    ProbDescription-xxxx.info,
+(where xxxx is the time step counter) contains the list of file names associated with 
+the current problem. The list defines the names for the matrices K,G,D,C and vectors f,h.
+If the name is NULL, there is no saved petsc object.
+
+*/
+
+void Underworld_ExtractPetscObjects_Dump( void* _context ) 
+{
+	UnderworldContext *context = (UnderworldContext*) _context;
+	
+	int		length;
+	char	machine_name[256];
+	int		rank;
+	char	*probName, fileName[256];
+	FILE	*info;
+	char	kName[256];
+	char	GradName[256];
+	char	DivName[256];
+	char	CName[256];
+	char	FName[256];
+	char	HName[256];
+	char	SpcName[256];
+	
+	char			mat_name[256];
+	char			vec_name[256];
+	PetscViewer		mat_view_file;
+	PetscViewer		vec_view_file;
+	Stokes_SLE		*stokesSLE = context->stokesSLE;
+	Mat A;
+	Vec b;
+	MPI_Comm comm;
+	int step;
+	Stokes_SLE_UzawaSolver *uzawaSolver;
+	Bool uzawa_present;
+	int ex_step, default_step;
+	
+	/* Init names */
+	strcpy( kName,    "NULL" );
+	strcpy( GradName, "NULL" );
+	strcpy( DivName,  "NULL" );
+	strcpy( CName,    "NULL" );
+	strcpy( FName,    "NULL" );
+	strcpy( HName,    "NULL" );
+	
+	
+	step = context->timeStep;
+
+	/* Get time step to perform extraction */
+	default_step =  -6699;
+	ex_step = Dictionary_Entry_Value_AsInt(
+			Dictionary_GetDefault( context->dictionary, "ExtractMatricesAtStep", Dictionary_Entry_Value_FromInt(default_step) )
+						);
+	if( ex_step != default_step ) { /* Then we want to dump a specific step */
+		if( ex_step != step ) { /* If current step does not match required step */
+			return;
+		}
+	}	
+
+	
+	/* Write the matrices and vectors to disk */
+	comm = context->communicator;
+	
+	// get filename from problem description
+	probName = strdup( Dictionary_Entry_Value_AsString( Dictionary_Get( context->dictionary, (Dictionary_Entry_Key)"ProbDescription" ) ));
+	printf("\n\n");
+	printf("**********************************************\n" );
+	printf("******     Extracting PetscObjects      ******\n" );
+	printf("**********************************************\n" );
+	printf("  ProbDescription: %s \n", probName );
+	
+	MPI_Get_processor_name( machine_name, &length);
+	MPI_Comm_rank( context->communicator, &rank );
+
+	
+	
+	/* Write K to file */
+	if( stokesSLE->kStiffMat != NULL ) {
+		sprintf( kName, "k--%s-step%d-%s", probName,step, machine_name );
+		sprintf( mat_name, "%s/%s", context->outputPath, kName );
+		printf("  Writing kMatrix:                    %s \n",mat_name );
+		
+/* 		if( !stokesSLE->kStiffMat->useShellMatrix ) */
+			A = stokesSLE->kStiffMat->matrix;
+/* 		else */
+/* 			A = stokesSLE->kStiffMat->shellMatrix->matrix; */
+		PetscViewerBinaryOpen( comm, mat_name, FILE_MODE_WRITE, &mat_view_file );
+		MatView( A, mat_view_file );
+		PetscViewerDestroy( mat_view_file );
+	}
+	/* Write G to file */
+	if( stokesSLE->gStiffMat != NULL ) {
+		sprintf( GradName, "g--%s-step%d-%s", probName,step, machine_name );
+		sprintf( mat_name, "%s/%s", context->outputPath, GradName );
+		printf("  Writing Grad:                       %s \n",mat_name );
+		
+/* 		if( !stokesSLE->gStiffMat->useShellMatrix ) */
+			A = stokesSLE->gStiffMat->matrix;
+/* 		else */
+/* 			A = stokesSLE->gStiffMat->shellMatrix->matrix; */
+		PetscViewerBinaryOpen( comm, mat_name, FILE_MODE_WRITE, &mat_view_file );
+		MatView( A, mat_view_file );
+		PetscViewerDestroy( mat_view_file );
+	}
+	
+	/* Write Div to file */	
+	if( stokesSLE->dStiffMat != NULL ) {
+		sprintf( DivName, "div--%s-step%d-%s", probName, step, machine_name );
+		sprintf( mat_name, "%s/%s", context->outputPath, DivName );
+		printf("  Writing Div:                        %s \n",mat_name );
+		
+/* 		if( !stokesSLE->dStiffMat->useShellMatrix ) */
+			A = stokesSLE->dStiffMat->matrix;
+/* 		else */
+/* 			A = stokesSLE->dStiffMat->shellMatrix->matrix; */
+		PetscViewerBinaryOpen( comm, mat_name, FILE_MODE_WRITE, &mat_view_file );
+		MatView( A, mat_view_file );
+		PetscViewerDestroy( mat_view_file );
+	}
+	
+	/* Write C to file */
+	if( stokesSLE->cStiffMat != NULL ) {
+		sprintf( CName, "c--%s-step%d-%s", probName, step, machine_name );
+		sprintf( mat_name, "%s/%s", context->outputPath, CName );
+		printf("  Writing C:                          %s \n",mat_name );
+		
+/* 		if( !stokesSLE->cStiffMat->useShellMatrix ) */
+			A = stokesSLE->cStiffMat->matrix;
+/* 		else */
+/* 			A = stokesSLE->cStiffMat->shellMatrix->matrix; */
+		PetscViewerBinaryOpen( comm, mat_name, FILE_MODE_WRITE, &mat_view_file );
+		MatView( A, mat_view_file );
+		PetscViewerDestroy( mat_view_file );
+	}
+	
+	
+	/* Momentum rhs */
+	if( stokesSLE->fForceVec != NULL ) {
+		sprintf( FName, "F--%s-step%d-%s", probName, step, machine_name );
+		sprintf( vec_name, "%s/%s", context->outputPath, FName );
+		printf("  Writing F:                          %s \n", vec_name );
+		
+		b = stokesSLE->fForceVec->vector;
+		PetscViewerBinaryOpen( comm, vec_name, FILE_MODE_WRITE, &vec_view_file );
+		VecView( b, vec_view_file );
+		PetscViewerDestroy( vec_view_file );
+	}
+	
+	/* Continuity rhs */
+	if( stokesSLE->hForceVec != NULL ) {
+		sprintf( HName, "H--%s-step%d-%s", probName, step, machine_name );
+		sprintf( vec_name, "%s/%s", context->outputPath, HName );
+		printf("  Writing H:                          %s \n", vec_name );
+		
+		b = stokesSLE->hForceVec->vector;
+		PetscViewerBinaryOpen( comm, vec_name, FILE_MODE_WRITE, &vec_view_file );
+		VecView( b, vec_view_file );
+		PetscViewerDestroy( vec_view_file );
+	}
+	
+	/* Check if solver is Uzawa and spit out the preconditioner used */
+	uzawa_present = False;
+	uzawa_present = Stg_Class_IsInstance( stokesSLE->solver, Stokes_SLE_UzawaSolver_Type );
+	if( uzawa_present == True ) {
+		sprintf( SpcName, "Spc--%s-step%d-%s", probName, step, machine_name );
+		sprintf( mat_name, "%s/%s", context->outputPath, SpcName );
+		printf("  Writing Schur pc operator (UW_Q22): %s \n",mat_name );
+	
+		uzawaSolver = (Stokes_SLE_UzawaSolver*)stokesSLE->solver;
+		A = uzawaSolver->preconditioner->matrix;
+		PetscViewerBinaryOpen( comm, mat_name, FILE_MODE_WRITE, &mat_view_file );
+		MatView( A, mat_view_file );
+		PetscViewerDestroy( mat_view_file );
+	}
+	
+	
+	
+	if( rank == 0 ) {
+		
+		sprintf( fileName, "%s/%s-step%d.info", context->outputPath, probName, context->timeStep );
+		printf("  Info file:                          %s \n", fileName );			
+		
+		if (( info = fopen (fileName, "w")) == NULL)  {
+			(void) fprintf(stderr, "Error: couldn't open file %s for writing. Exiting.\n", fileName);
+			PetscFinalize();
+			exit(1);
+		}
+		
+		/* Write the object info to file */
+		fprintf( info, "%s %s %s %s %s %s",
+				kName, GradName, DivName, CName,
+				FName, HName );
+		
+		fclose( info );
+	}
+	
+//	b = (Vec)stokesSLE->pSolnVec->vector;
+//	VecView( b, PETSC_VIEWER_STDOUT_WORLD );
+	
+	
+}
+
+void Underworld_ExtractPetscObjects_PrintHeaderToFile( void* context ) 
+{
+	StgFEM_FrequentOutput_PrintString( context, "ExtractPetscObjects" );
+}
+
+
+
diff -r 038180046f6f -r 4b2d36e5021d plugins/HRS_Erosion/HRS_Erosion.c
--- a/plugins/HRS_Erosion/HRS_Erosion.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,403 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-** An implementation of the erosion rule in 
-**
-** Hilley, G. E., M. R. Strecker, and V. A. Ramos (2004), Growth and
-** erosion of fold-and- thrust belts with an application to the
-** Aconcagua fold-and-thrust belt, Argentina, J. Geophys. Res., 109,
-** B01410, doi:10.1029/2002JB002282.
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-** Copyright (C) 2008, 2010 California Institute of Technology
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	David May, PhD Student Monash University, VPAC. (david.may at sci.maths.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)
-**      Walter Landry, CIG
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: LevelSetPlg.c 200 2005-07-08 08:24:41Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Underworld.h>
-#include <math.h>
-#include <float.h>
-
-#include "types.h"
-#include "Context.h"
-#include "HRS_Erosion.h"
-
-
-const Type		Underworld_HRS_Erosion_Type = "HRS_Erosion";
-ExtensionInfo_Index	Underworld_HRS_Erosion_ContextHandle;
-
-static double a_mean_old=0;
-static double next_t_erosion=0;
-static double t_erosion=0;
-static double last_erosion_t=0;
-
-void Underworld_HRS_Erosion_Execute( TimeIntegrand* crdAdvector,
-                                        Underworld_HRS_Erosion_Context* spCtx)
-{
-  double				dt;
-  FeVariable *velocity;
-  const double K = spCtx->K;
-  Grid* grid;
-  Mesh* mesh;
-  unsigned nDims;
-  Node_LocalIndex n_i, n_left;
-  unsigned nNodes;
-  MPI_Comm comm;
-  double DT = spCtx->DT;
-  double first_t_erosion = spCtx->first_t_erosion;
-  const double vT = spCtx->vT;
-  IJK ijk_right;
-  IJK ijk_left;
-  Bool on_top, on_right, found;
-  double x_right, y_right, x_left, y_left, temp,
-    base_height, fudge_factor;
-
-  fudge_factor=1.01;
-  assert( spCtx );
-  
-  dt = spCtx->ctx->dt;
-  mesh=spCtx->mesh;
-  velocity=spCtx->v;
-  t_erosion = t_erosion + dt;
-  comm = Comm_GetMPIComm( Mesh_GetCommTopology( mesh, MT_VERTEX ) );
-		
-  /* Handle erosion times */
-
-  if(next_t_erosion < first_t_erosion) {
-    next_t_erosion = first_t_erosion;
-  }
-		
-  if(t_erosion < next_t_erosion)
-    return;
-
-  next_t_erosion = next_t_erosion + DT;
-
-  DT = t_erosion-last_erosion_t;
-
-  last_erosion_t=t_erosion;
-
-  nDims = Mesh_GetDimSize( mesh );
-  grid =
-    *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-                                   ExtensionManager_GetHandle( mesh->info, 
-                                                               "vertexGrid" ) );
-  if( nDims != 2 )
-    abort();
-
-  nNodes = FeMesh_GetNodeLocalSize( mesh);
-
-  /* Get the coordinates for the top right corner */
-
-  RegularMeshUtils_Node_1DTo3D
-    ( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, nNodes-1 ), ijk_right );
-  on_top=(ijk_right[1]==grid->sizes[1]-1) ? True : False;
-  on_right=(ijk_right[0]==grid->sizes[0]-1) ? True : False;
-  if(on_top && on_right)
-    {
-      x_right=mesh->verts[nNodes-1][0];
-      y_right=mesh->verts[nNodes-1][1];
-    }
-  else
-    {
-      x_right=DBL_MAX;
-      y_right=DBL_MAX;
-    }
-  MPI_Allreduce( &x_right, &temp, 1, MPI_DOUBLE, MPI_MIN, comm );
-  x_right=temp;
-  MPI_Allreduce( &y_right, &temp, 1, MPI_DOUBLE, MPI_MIN, comm );
-  y_right=temp;
-
-  /* Get the coordinates on the left for where the height rises above
-     the base height */
-  base_height=DBL_MAX;
-  y_left=DBL_MAX;
-  x_left=DBL_MAX;
-
-  if(on_top)
-    {
-      int i_right, i_left, i, j;
-      i_right=ijk_right[0];
-      j=ijk_right[1];
-      
-      RegularMeshUtils_Node_1DTo3D
-        ( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, 0 ), ijk_left );
-
-      i_left=ijk_left[0];
-      ijk_left[1]=j;
-
-      if(!Mesh_GlobalToDomain
-         (mesh,MT_VERTEX,
-          RegularMeshUtils_Node_3DTo1D(mesh,ijk_left),&n_left))
-        {
-          printf("Can not map to local domain %d %d\n",
-                 ijk_left[0],ijk_left[1]);
-          abort();
-        }
-      base_height=mesh->verts[n_left][1];
-      found=False;
-      for(i=i_left+1; i<=i_right; ++i)
-        {
-          ijk_left[0]=i;
-          if(!Mesh_GlobalToDomain
-             (mesh,MT_VERTEX,
-              RegularMeshUtils_Node_3DTo1D(mesh,ijk_left),&n_left))
-            {
-              printf("Can not map to local domain %d %d\n",
-                     ijk_left[0],ijk_left[1]);
-              abort();
-            }
-          if(mesh->verts[n_left][1]>base_height*fudge_factor)
-            {
-              found=True;
-              x_left=mesh->verts[n_left][0];
-              y_left=mesh->verts[n_left][1];
-              break;
-            }
-        }
-      if(!found)
-        {
-          y_left=DBL_MAX;
-          x_left=DBL_MAX;
-        }
-    }
-  MPI_Allreduce( &x_left, &temp, 1, MPI_DOUBLE, MPI_MIN, comm );
-  x_left=temp;
-  MPI_Allreduce( &y_left, &temp, 1, MPI_DOUBLE, MPI_MIN, comm );
-  y_left=temp;
-  MPI_Allreduce( &base_height, &temp, 1, MPI_DOUBLE, MPI_MIN, comm );
-  base_height=temp;
-
-
-  /* Leave if no one found the rise */
-
-  if(x_left==DBL_MAX)
-    {
-      printf("Could not locate the edge of the wedge.  Not eroding.\n");
-      return;
-    }
-
-  /* Start the erosion calculation */
-
-  double W = x_right-x_left;
-  double a_mean = atan((y_right-base_height)/W);
-				
-  /* Insert equation here and calculate new slope: */
-
-  const double m=spCtx->m; 
-  const double n=spCtx->n; 
-  const double ka=spCtx->ka;
-  const double h=spCtx->h;
-  double S=tan(a_mean_old);
-
-  /* alpha_calculated=(alpha1+atan((2.*vT./W1.^2 - 2*K*ka^m*W1^(h*m-1)*S^n/(h*m+1))*dt)) */
-  double alpha_calculated=
-    (a_mean_old+atan((2*vT/pow(W,2)
-                      - (2*K*pow(ka,m)*pow(W,(h*m-1))*pow(S,n))/(h*m+1))*DT));
-
-  /* At the end of this calculation, we need a variable called alpha_calculated (in radians): */
-				
-  double slope_calculated = tan(alpha_calculated);
-  double ypred;
-				
-  printf("a_mean_old | a_mean | alpha_calculated | width | DT\n%11.9g %11.9g %11.9g %11.9g %11.9g\n",a_mean_old,a_mean,alpha_calculated, W, DT);
-				
-  if (a_mean>alpha_calculated)
-    {
-      a_mean_old=alpha_calculated;
-      
-      for( n_i = 0; n_i < nNodes; n_i++ ) 
-        {
-          IJK ijk;
-          RegularMeshUtils_Node_1DTo3D
-            ( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-					
-          if(ijk[1]==grid->sizes[1]-1)
-            {
-              double y_old,delta_v, v[3];
-              double x; 
-              
-              x=mesh->verts[n_i][0];
-              ypred = slope_calculated * (x-x_left) + y_left;
-              y_old = mesh->verts[n_i][1];
-              if(ypred < y_old && x>x_left) 
-                {
-                  delta_v = (ypred-y_old)/dt;
-                }
-              else 
-                {
-                  delta_v = 0;
-                }
-						
-              FeVariable_GetValueAtNode(velocity,n_i,v);
-
-              v[1]+=delta_v;
-              FeVariable_SetValueAtNode(velocity,n_i,v);
-            }
-        }
-    }
-  else
-    {	
-      a_mean_old=a_mean;
-    }
-  FeVariable_SyncShadowValues(velocity);
-}
-
-Index Underworld_HRS_Erosion_Register( PluginsManager* pluginsMgr ) {
-	return PluginsManager_Submit( pluginsMgr, 
-				      Underworld_HRS_Erosion_Type, 
-				      "0", 
-				      _Underworld_HRS_Erosion_DefaultNew );
-}
-
-void* _Underworld_HRS_Erosion_DefaultNew( Name name ) {
-
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Codelet);
-	Type                                                      type = Underworld_HRS_Erosion_Type;
-	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
-	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
-	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_HRS_Erosion_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Underworld_HRS_Erosion_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _Underworld_HRS_Erosion_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _Codelet_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _Codelet_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _Underworld_HRS_Erosion_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   );
-}
-
-void _Underworld_HRS_Erosion_AssignFromXML( void* component,
-                                               Stg_ComponentFactory* cf,
-                                               void* data ) {
-  Codelet* sp = (Codelet*)component;
-  UnderworldContext*			uwCtx;
-  Underworld_HRS_Erosion_Context*	spCtx;
-  Dictionary*			spDict;
-  char*				meshName;
-  char*                         velocityName;
-
-  assert( component );
-  assert( cf );
-
-  Journal_DPrintf( Underworld_Debug, "In: %s( void* )\n", __func__ );
-
-  /* Retrieve context. */
-  uwCtx =
-    (UnderworldContext*)Stg_ComponentFactory_ConstructByName(cf,"context",
-                                                             UnderworldContext,
-                                                             True, data );
-  sp->context=(AbstractContext* )uwCtx;
-  /* Create new context. */
-  Underworld_HRS_Erosion_ContextHandle =
-    ExtensionManager_Add( uwCtx->extensionMgr, 
-                          Underworld_HRS_Erosion_Type, 
-                          sizeof(Underworld_HRS_Erosion_Context) );
-
-  spCtx = (Underworld_HRS_Erosion_Context*)ExtensionManager_Get( uwCtx->extensionMgr, uwCtx,
-                                Underworld_HRS_Erosion_ContextHandle );
-  memset( spCtx, 0, sizeof(Underworld_HRS_Erosion_Context) );
-  spCtx->ctx = (AbstractContext*)uwCtx;
-
-  /* Get the time integrator. */
-  spCtx->timeIntegrator =
-    Stg_ComponentFactory_ConstructByName( cf, (Name)"timeIntegrator",
-                                          TimeIntegrator, True, data  );
-
-  /* Get the dictionary. */
-  spDict = Dictionary_GetDictionary( uwCtx->dictionary, "HRS_Erosion" );
-  if( !spDict )
-    return;
-
-  /* Read in the variables. */
-  meshName = Dictionary_GetString( spDict, "mesh" );
-  assert( meshName && strcmp( meshName, "" ) );
-  spCtx->mesh = Stg_ComponentFactory_ConstructByName( cf, meshName, Mesh, True,
-                                                      NULL );
-  velocityName = Dictionary_GetString( spDict, "VelocityField" );
-  assert( velocityName && strcmp( velocityName, "" ) );
-  spCtx->v = Stg_ComponentFactory_ConstructByName( cf, velocityName, FeVariable,
-                                                   True, NULL );
-  assert( spCtx->v);
-  spCtx->K = Dictionary_GetDouble( spDict, "K" );
-
-  spCtx->DT = Dictionary_GetDouble(spDict, "dt_erosion");
-  spCtx->first_t_erosion = Dictionary_GetDouble(spDict, "first_t_erosion");
-  spCtx->vT = Dictionary_GetDouble(spDict, "vT");
-  spCtx->m = Dictionary_GetDouble(spDict, "m");
-  spCtx->n = Dictionary_GetDouble(spDict, "n");
-  spCtx->ka = Dictionary_GetDouble(spDict, "ka");
-  spCtx->h = Dictionary_GetDouble(spDict, "h");
-}
-
-void _Underworld_HRS_Erosion_Build( void* codelet, void* data ) {
-	Codelet* sp= (Codelet*)codelet;
-	UnderworldContext* UnderworldCtx = (UnderworldContext*)sp->context;
-	Underworld_HRS_Erosion_Context*	spCtx;
-
-	assert( codelet );
-	assert( UnderworldCtx );
-
-	/* Get the context. */
-	spCtx = (Underworld_HRS_Erosion_Context*)ExtensionManager_Get( UnderworldCtx->extensionMgr, UnderworldCtx, Underworld_HRS_Erosion_ContextHandle );
-
-	if( !spCtx->mesh )
-		return;
-
-	/* Append to the list of time integratee finish routines.  It
-           should come last, because EulerDeform will reset the
-           values. */
-	TimeIntegrator_AppendSetupEP( spCtx->timeIntegrator, 
-					"Underworld_HRS_Erosion_Execute", 
-                                      (void*)Underworld_HRS_Erosion_Execute, 
-					"HRS_Erosion", 
-					spCtx );
-}
-
-void _Underworld_HRS_Erosion_Destroy( void* codelet, void* data ) {
-	UnderworldContext*	UnderworldCtx = (UnderworldContext*)data;
-
-	assert( codelet );
-	assert( UnderworldCtx );
-
-	/* Clear the lot. */
-	/* TODO */
-}
-
diff -r 038180046f6f -r 4b2d36e5021d plugins/HRS_Erosion/HRS_Erosion.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/HRS_Erosion/HRS_Erosion.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,403 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** An implementation of the erosion rule in 
+**
+** Hilley, G. E., M. R. Strecker, and V. A. Ramos (2004), Growth and
+** erosion of fold-and- thrust belts with an application to the
+** Aconcagua fold-and-thrust belt, Argentina, J. Geophys. Res., 109,
+** B01410, doi:10.1029/2002JB002282.
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+** Copyright (C) 2008, 2010 California Institute of Technology
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	David May, PhD Student Monash University, VPAC. (david.may at sci.maths.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)
+**      Walter Landry, CIG
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: LevelSetPlg.c 200 2005-07-08 08:24:41Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Underworld.h>
+#include <math.h>
+#include <float.h>
+
+#include "types.h"
+#include "Context.h"
+#include "HRS_Erosion.h"
+
+
+const Type		Underworld_HRS_Erosion_Type = "HRS_Erosion";
+ExtensionInfo_Index	Underworld_HRS_Erosion_ContextHandle;
+
+static double a_mean_old=0;
+static double next_t_erosion=0;
+static double t_erosion=0;
+static double last_erosion_t=0;
+
+void Underworld_HRS_Erosion_Execute( TimeIntegrand* crdAdvector,
+                                        Underworld_HRS_Erosion_Context* spCtx)
+{
+  double				dt;
+  FeVariable *velocity;
+  const double K = spCtx->K;
+  Grid* grid;
+  Mesh* mesh;
+  unsigned nDims;
+  Node_LocalIndex n_i, n_left;
+  unsigned nNodes;
+  MPI_Comm comm;
+  double DT = spCtx->DT;
+  double first_t_erosion = spCtx->first_t_erosion;
+  const double vT = spCtx->vT;
+  IJK ijk_right;
+  IJK ijk_left;
+  Bool on_top, on_right, found;
+  double x_right, y_right, x_left, y_left, temp,
+    base_height, fudge_factor;
+
+  fudge_factor=1.01;
+  assert( spCtx );
+  
+  dt = spCtx->ctx->dt;
+  mesh=spCtx->mesh;
+  velocity=spCtx->v;
+  t_erosion = t_erosion + dt;
+  comm = Comm_GetMPIComm( Mesh_GetCommTopology( mesh, MT_VERTEX ) );
+		
+  /* Handle erosion times */
+
+  if(next_t_erosion < first_t_erosion) {
+    next_t_erosion = first_t_erosion;
+  }
+		
+  if(t_erosion < next_t_erosion)
+    return;
+
+  next_t_erosion = next_t_erosion + DT;
+
+  DT = t_erosion-last_erosion_t;
+
+  last_erosion_t=t_erosion;
+
+  nDims = Mesh_GetDimSize( mesh );
+  grid =
+    *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+                                   ExtensionManager_GetHandle( mesh->info, 
+                                                               "vertexGrid" ) );
+  if( nDims != 2 )
+    abort();
+
+  nNodes = FeMesh_GetNodeLocalSize( mesh);
+
+  /* Get the coordinates for the top right corner */
+
+  RegularMeshUtils_Node_1DTo3D
+    ( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, nNodes-1 ), ijk_right );
+  on_top=(ijk_right[1]==grid->sizes[1]-1) ? True : False;
+  on_right=(ijk_right[0]==grid->sizes[0]-1) ? True : False;
+  if(on_top && on_right)
+    {
+      x_right=mesh->verts[nNodes-1][0];
+      y_right=mesh->verts[nNodes-1][1];
+    }
+  else
+    {
+      x_right=DBL_MAX;
+      y_right=DBL_MAX;
+    }
+  MPI_Allreduce( &x_right, &temp, 1, MPI_DOUBLE, MPI_MIN, comm );
+  x_right=temp;
+  MPI_Allreduce( &y_right, &temp, 1, MPI_DOUBLE, MPI_MIN, comm );
+  y_right=temp;
+
+  /* Get the coordinates on the left for where the height rises above
+     the base height */
+  base_height=DBL_MAX;
+  y_left=DBL_MAX;
+  x_left=DBL_MAX;
+
+  if(on_top)
+    {
+      int i_right, i_left, i, j;
+      i_right=ijk_right[0];
+      j=ijk_right[1];
+      
+      RegularMeshUtils_Node_1DTo3D
+        ( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, 0 ), ijk_left );
+
+      i_left=ijk_left[0];
+      ijk_left[1]=j;
+
+      if(!Mesh_GlobalToDomain
+         (mesh,MT_VERTEX,
+          RegularMeshUtils_Node_3DTo1D(mesh,ijk_left),&n_left))
+        {
+          printf("Can not map to local domain %d %d\n",
+                 ijk_left[0],ijk_left[1]);
+          abort();
+        }
+      base_height=mesh->verts[n_left][1];
+      found=False;
+      for(i=i_left+1; i<=i_right; ++i)
+        {
+          ijk_left[0]=i;
+          if(!Mesh_GlobalToDomain
+             (mesh,MT_VERTEX,
+              RegularMeshUtils_Node_3DTo1D(mesh,ijk_left),&n_left))
+            {
+              printf("Can not map to local domain %d %d\n",
+                     ijk_left[0],ijk_left[1]);
+              abort();
+            }
+          if(mesh->verts[n_left][1]>base_height*fudge_factor)
+            {
+              found=True;
+              x_left=mesh->verts[n_left][0];
+              y_left=mesh->verts[n_left][1];
+              break;
+            }
+        }
+      if(!found)
+        {
+          y_left=DBL_MAX;
+          x_left=DBL_MAX;
+        }
+    }
+  MPI_Allreduce( &x_left, &temp, 1, MPI_DOUBLE, MPI_MIN, comm );
+  x_left=temp;
+  MPI_Allreduce( &y_left, &temp, 1, MPI_DOUBLE, MPI_MIN, comm );
+  y_left=temp;
+  MPI_Allreduce( &base_height, &temp, 1, MPI_DOUBLE, MPI_MIN, comm );
+  base_height=temp;
+
+
+  /* Leave if no one found the rise */
+
+  if(x_left==DBL_MAX)
+    {
+      printf("Could not locate the edge of the wedge.  Not eroding.\n");
+      return;
+    }
+
+  /* Start the erosion calculation */
+
+  double W = x_right-x_left;
+  double a_mean = atan((y_right-base_height)/W);
+				
+  /* Insert equation here and calculate new slope: */
+
+  const double m=spCtx->m; 
+  const double n=spCtx->n; 
+  const double ka=spCtx->ka;
+  const double h=spCtx->h;
+  double S=tan(a_mean_old);
+
+  /* alpha_calculated=(alpha1+atan((2.*vT./W1.^2 - 2*K*ka^m*W1^(h*m-1)*S^n/(h*m+1))*dt)) */
+  double alpha_calculated=
+    (a_mean_old+atan((2*vT/pow(W,2)
+                      - (2*K*pow(ka,m)*pow(W,(h*m-1))*pow(S,n))/(h*m+1))*DT));
+
+  /* At the end of this calculation, we need a variable called alpha_calculated (in radians): */
+				
+  double slope_calculated = tan(alpha_calculated);
+  double ypred;
+				
+  printf("a_mean_old | a_mean | alpha_calculated | width | DT\n%11.9g %11.9g %11.9g %11.9g %11.9g\n",a_mean_old,a_mean,alpha_calculated, W, DT);
+				
+  if (a_mean>alpha_calculated)
+    {
+      a_mean_old=alpha_calculated;
+      
+      for( n_i = 0; n_i < nNodes; n_i++ ) 
+        {
+          IJK ijk;
+          RegularMeshUtils_Node_1DTo3D
+            ( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+					
+          if(ijk[1]==grid->sizes[1]-1)
+            {
+              double y_old,delta_v, v[3];
+              double x; 
+              
+              x=mesh->verts[n_i][0];
+              ypred = slope_calculated * (x-x_left) + y_left;
+              y_old = mesh->verts[n_i][1];
+              if(ypred < y_old && x>x_left) 
+                {
+                  delta_v = (ypred-y_old)/dt;
+                }
+              else 
+                {
+                  delta_v = 0;
+                }
+						
+              FeVariable_GetValueAtNode(velocity,n_i,v);
+
+              v[1]+=delta_v;
+              FeVariable_SetValueAtNode(velocity,n_i,v);
+            }
+        }
+    }
+  else
+    {	
+      a_mean_old=a_mean;
+    }
+  FeVariable_SyncShadowValues(velocity);
+}
+
+Index Underworld_HRS_Erosion_Register( PluginsManager* pluginsMgr ) {
+	return PluginsManager_Submit( pluginsMgr, 
+				      Underworld_HRS_Erosion_Type, 
+				      "0", 
+				      _Underworld_HRS_Erosion_DefaultNew );
+}
+
+void* _Underworld_HRS_Erosion_DefaultNew( Name name ) {
+
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Codelet);
+	Type                                                      type = Underworld_HRS_Erosion_Type;
+	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
+	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
+	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_HRS_Erosion_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Underworld_HRS_Erosion_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _Underworld_HRS_Erosion_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _Codelet_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _Codelet_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _Underworld_HRS_Erosion_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   );
+}
+
+void _Underworld_HRS_Erosion_AssignFromXML( void* component,
+                                               Stg_ComponentFactory* cf,
+                                               void* data ) {
+  Codelet* sp = (Codelet*)component;
+  UnderworldContext*			uwCtx;
+  Underworld_HRS_Erosion_Context*	spCtx;
+  Dictionary*			spDict;
+  char*				meshName;
+  char*                         velocityName;
+
+  assert( component );
+  assert( cf );
+
+  Journal_DPrintf( Underworld_Debug, "In: %s( void* )\n", __func__ );
+
+  /* Retrieve context. */
+  uwCtx =
+    (UnderworldContext*)Stg_ComponentFactory_ConstructByName(cf,"context",
+                                                             UnderworldContext,
+                                                             True, data );
+  sp->context=(AbstractContext* )uwCtx;
+  /* Create new context. */
+  Underworld_HRS_Erosion_ContextHandle =
+    ExtensionManager_Add( uwCtx->extensionMgr, 
+                          Underworld_HRS_Erosion_Type, 
+                          sizeof(Underworld_HRS_Erosion_Context) );
+
+  spCtx = (Underworld_HRS_Erosion_Context*)ExtensionManager_Get( uwCtx->extensionMgr, uwCtx,
+                                Underworld_HRS_Erosion_ContextHandle );
+  memset( spCtx, 0, sizeof(Underworld_HRS_Erosion_Context) );
+  spCtx->ctx = (AbstractContext*)uwCtx;
+
+  /* Get the time integrator. */
+  spCtx->timeIntegrator =
+    Stg_ComponentFactory_ConstructByName( cf, (Name)"timeIntegrator",
+                                          TimeIntegrator, True, data  );
+
+  /* Get the dictionary. */
+  spDict = Dictionary_GetDictionary( uwCtx->dictionary, "HRS_Erosion" );
+  if( !spDict )
+    return;
+
+  /* Read in the variables. */
+  meshName = Dictionary_GetString( spDict, "mesh" );
+  assert( meshName && strcmp( meshName, "" ) );
+  spCtx->mesh = Stg_ComponentFactory_ConstructByName( cf, meshName, Mesh, True,
+                                                      NULL );
+  velocityName = Dictionary_GetString( spDict, "VelocityField" );
+  assert( velocityName && strcmp( velocityName, "" ) );
+  spCtx->v = Stg_ComponentFactory_ConstructByName( cf, velocityName, FeVariable,
+                                                   True, NULL );
+  assert( spCtx->v);
+  spCtx->K = Dictionary_GetDouble( spDict, "K" );
+
+  spCtx->DT = Dictionary_GetDouble(spDict, "dt_erosion");
+  spCtx->first_t_erosion = Dictionary_GetDouble(spDict, "first_t_erosion");
+  spCtx->vT = Dictionary_GetDouble(spDict, "vT");
+  spCtx->m = Dictionary_GetDouble(spDict, "m");
+  spCtx->n = Dictionary_GetDouble(spDict, "n");
+  spCtx->ka = Dictionary_GetDouble(spDict, "ka");
+  spCtx->h = Dictionary_GetDouble(spDict, "h");
+}
+
+void _Underworld_HRS_Erosion_Build( void* codelet, void* data ) {
+	Codelet* sp= (Codelet*)codelet;
+	UnderworldContext* UnderworldCtx = (UnderworldContext*)sp->context;
+	Underworld_HRS_Erosion_Context*	spCtx;
+
+	assert( codelet );
+	assert( UnderworldCtx );
+
+	/* Get the context. */
+	spCtx = (Underworld_HRS_Erosion_Context*)ExtensionManager_Get( UnderworldCtx->extensionMgr, UnderworldCtx, Underworld_HRS_Erosion_ContextHandle );
+
+	if( !spCtx->mesh )
+		return;
+
+	/* Append to the list of time integratee finish routines.  It
+           should come last, because EulerDeform will reset the
+           values. */
+	TimeIntegrator_AppendSetupEP( spCtx->timeIntegrator, 
+					"Underworld_HRS_Erosion_Execute", 
+                                      (void*)Underworld_HRS_Erosion_Execute, 
+					"HRS_Erosion", 
+					spCtx );
+}
+
+void _Underworld_HRS_Erosion_Destroy( void* codelet, void* data ) {
+	UnderworldContext*	UnderworldCtx = (UnderworldContext*)data;
+
+	assert( codelet );
+	assert( UnderworldCtx );
+
+	/* Clear the lot. */
+	/* TODO */
+}
+
diff -r 038180046f6f -r 4b2d36e5021d plugins/IncompressibleExtensionBC/IncompressibleExtensionBC.c
--- a/plugins/IncompressibleExtensionBC/IncompressibleExtensionBC.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,350 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: IncompressibleExtensionBC.c 728 2008-05-12 02:29:30Z LouisMoresi $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdlib.h>
-#include <string.h>
-#include <mpi.h>
-#include <assert.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Underworld.h>
-#include "IncompressibleExtensionBC.h"
-
-/* Each component type needs a unique identifier (as a string for us to read and as an integer for realtime comparisions) */
-const Type Underworld_IncompressibleExtensionBC_Type = "Underworld_IncompressibleExtensionBC_Type";
-
-	/*
-
-	                       ^ V_e
-	                      /
-	         ____________/__________________________
-	        /                                      /|
-	       /                                      / |
-	      /                                      /  |
-	     /                  ^ V_c               /   |
-	    /                   |                  /    |
-	   /          ^ V_f                       /     |
-	  /          /                           /      |
-	 /__________/___________________________/       |
-	|     ^                                |        |
-	|     |                                |        |
-	|     h_1                              |  ->V_a |
-	|     |                                |        |
-	|     v                                |        |
-	|--------------------------------------|       /
-	|         ^                            |      /
-	|         |                            |     /
-	|-> V_b   |                            |    /
-	|         |h_2                         |   / 
-	|         |                            |  /
-	|         |      ^V_d                  | /
-	|________________|_____________________|/
-
-	*/
-
-double GetLeftWallVelocity( UnderworldContext* context ) {
-	return Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"leftWallVelocity", 0.0 );
-}	
-
-double GetLeftWallShearVelocity( UnderworldContext* context  ) {
-		return Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"leftWallShearVelocity", 0.0 );
-	}
-	
-double GetRightWallVelocity( UnderworldContext* context  ) {
-		return Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"rightWallVelocity", 0.0 );
-	}	
-	
-double GetRightWallShearVelocity( UnderworldContext* context  ) {
-			return Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"rightWallShearVelocity", 0.0 );
-}
-
-double GetBackWallVelocity( UnderworldContext* context ) {
-	if ( context->dim == 2  )
-		return 0.0;
-	
-	return Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"backWallVelocity", 0.0 );
-}
-double GetFrontWallVelocity( UnderworldContext* context ) {
-	if ( context->dim == 2  )
-		return 0.0;
-	
-	return Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"frontWallVelocity", 0.0 );
-}
-double GetReferenceHeight( UnderworldContext* context  ) {
-	return Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"constantHeight", 0.0 );
-}
-
-double GetTopWallVelocity( UnderworldContext* context ) {
-	FeVariable*         velocityField = (FeVariable* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"VelocityField" );
-	double              y   = GetReferenceHeight( context );
-	double              V_a = GetRightWallVelocity( context );
-	double              V_b = GetLeftWallVelocity( context );
-	double              V_e = GetBackWallVelocity( context );
-	double              V_f = GetFrontWallVelocity( context  );
-	double              V_c;
-	double              h_1;
-	XYZ                 min, max;
-	double              width;
-	double              depth;
-	
-	/* Calculate Width and Height */
-	FieldVariable_GetMinAndMaxGlobalCoords( velocityField, min, max );
-	width  = (max[ I_AXIS ] - min[ I_AXIS ]);
-	depth  = context->dim == 3 ? (max[ K_AXIS ] - min[ K_AXIS ]) : 1.0; /* if only 3D depth cancels in division */
-
-	h_1 = max[ J_AXIS ] - y;
-
-	/* Calculate velocity at the top and at the bottom of the nodes */
-	V_c = - h_1 * ( (V_a - V_b) * depth + (V_f - V_e) * width )/(width*depth);
-	
-	return V_c;
-}
-
-double GetBottomWallVelocity( UnderworldContext* context ) {
-	FeVariable*         velocityField = (FeVariable*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"VelocityField" );
-	double              y   = GetReferenceHeight( context );
-	double              V_a = GetRightWallVelocity( context );
-	double              V_b = GetLeftWallVelocity( context );
-	double              V_e = GetBackWallVelocity( context );
-	double              V_f = GetFrontWallVelocity( context  );
-	double              V_d;
-	double              h_2;
-	XYZ                 min, max;
-	double              width;
-	double              depth;
-	
-	/* Calculate Width and Height */
-	FieldVariable_GetMinAndMaxGlobalCoords( velocityField, min, max );
-	width  = (max[ I_AXIS ] - min[ I_AXIS ]);
-	depth  = context->dim == 3 ? (max[ K_AXIS ] - min[ K_AXIS ]) : 1.0; /* if only 3D depth cancels in division */
-
-	h_2 = y - min[ J_AXIS ];
-	
-	/* Calculate velocity at the top and at the bottom of the nodes */
-	V_d =   h_2 * ( (V_a - V_b) * depth + (V_f - V_e) * width )/(width*depth);
-
-	return V_d;
-}
-
-void IncompressibleExtensionBC_RightCondition( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
-	UnderworldContext* context = (UnderworldContext*) _context;
-	double*            result  = (double*) _result;
-
-	*result = GetRightWallVelocity( context );
-}
-
-void IncompressibleExtensionBC_RightShearCondition( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
-	UnderworldContext* context = (UnderworldContext*) _context;
-	double*            result  = (double*) _result;
-
-	*result = GetRightWallShearVelocity( context );
-}
-
-
-void IncompressibleExtensionBC_LeftCondition( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
-	UnderworldContext* context = (UnderworldContext*) _context;
-	double*            result  = (double*) _result;
-
-	*result = GetLeftWallVelocity( context );
-}
-
-void IncompressibleExtensionBC_LeftShearCondition( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
-	UnderworldContext* context = (UnderworldContext*) _context;
-	double*            result  = (double*) _result;
-
-	*result = GetLeftWallShearVelocity( context );
-}
-
-
-void IncompressibleExtensionBC_BackCondition( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
-	UnderworldContext* context = (UnderworldContext*) _context;
-	double*            result  = (double*) _result;
-
-	*result = GetBackWallVelocity( context );
-}
-void IncompressibleExtensionBC_FrontCondition( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
-	UnderworldContext* context = (UnderworldContext*) _context;
-	double*            result  = (double*) _result;
-
-	*result = GetFrontWallVelocity( context );
-}
-
-void IncompressibleExtensionBC_TopCondition( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
-	UnderworldContext* context = (UnderworldContext*) _context;
-	double*            result  = (double*) _result;
-
-	*result = GetTopWallVelocity( context );
-}
-
-void IncompressibleExtensionBC_BottomCondition( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
-	UnderworldContext* context = (UnderworldContext*) _context;
-	double*            result  = (double*) _result;
-
-	*result = GetBottomWallVelocity( context );
-}
-
-void Underworld_IncompressibleExtensionBC_Remesh( TimeIntegrator* timeIntegrator, IncExtBC* self ) {
-    FeVariable* velocityField = (FeVariable*) LiveComponentRegister_Get( self->context->CF->LCRegister, (Name)"VelocityField" );
-    FeVariable* pressureField = (FeVariable* ) LiveComponentRegister_Get( self->context->CF->LCRegister, (Name)"PressureField"  );
-    FeMesh *mesh;
-    Grid *nodeGrid;
-    double dt;
-    double top, bottom, left, right;
-    double minCrd[3], maxCrd[3];
-    double nodeWidth[3];
-    int numNodes;
-    int nodeInds[3];
-    int ii;
-
-    mesh = velocityField->feMesh;
-
-    nodeGrid = *Mesh_GetExtension(mesh, Grid**, "vertexGrid");
-
-    dt = AbstractContext_Dt(self->ctx);
-    top = GetTopWallVelocity(self->ctx);
-    bottom = GetBottomWallVelocity(self->ctx);
-    left = GetLeftWallVelocity(self->ctx);
-    right = GetRightWallVelocity(self->ctx);
-    Mesh_GetGlobalCoordRange(mesh, minCrd, maxCrd);
-
-    minCrd[0] += dt*left;
-    minCrd[1] += dt*bottom;
-    maxCrd[0] += dt*right;
-    maxCrd[1] += dt*top;
-
-    nodeWidth[0] = (maxCrd[0] - minCrd[0])/(double)(nodeGrid->sizes[0] - 1);
-    nodeWidth[1] = (maxCrd[1] - minCrd[1])/(double)(nodeGrid->sizes[1] - 1);
-
-    numNodes = FeMesh_GetNodeLocalSize(mesh);
-    for(ii = 0; ii < numNodes; ii++) {
-      Grid_Lift(nodeGrid, FeMesh_NodeDomainToGlobal(mesh, ii), (unsigned*)nodeInds);
-		Mesh_GetVertex(mesh, ii)[0] = minCrd[0] + ((double)nodeInds[0])*nodeWidth[0];
-		Mesh_GetVertex(mesh, ii)[1] = minCrd[1] + ((double)nodeInds[1])*nodeWidth[1];
-    }
-
-    Mesh_Sync(mesh);
-    Mesh_DeformationUpdate(mesh);
-
-    if(velocityField->feMesh != pressureField->feMesh) {
-	if(!strcmp(pressureField->feMesh->type, "CartesianGenerator")) {
-	    FeMesh *pmesh;
-	    Grid *pnodeGrid;
-	    int lind;
-
-	    pmesh = pressureField->feMesh;
-	    pnodeGrid = *Mesh_GetExtension(pmesh, Grid**, "vertexGrid");
-
-	    numNodes = FeMesh_GetNodeLocalSize(pmesh);
-	    for(ii = 0; ii < numNodes; ii++) {
-		Grid_Lift(pnodeGrid, FeMesh_NodeDomainToGlobal(pmesh, ii), (unsigned*)nodeInds);
-		nodeInds[0] *= 2;
-		nodeInds[1] *= 2;
-		insist(FeMesh_NodeGlobalToDomain(mesh, Grid_Project(nodeGrid, (unsigned*)nodeInds), (unsigned*)(&lind)), != 0);
-		memcpy(Mesh_GetVertex(pmesh, ii), Mesh_GetVertex(mesh, lind), 2*sizeof(double));
-	    }
-	}
-    }
-}
-
-void _Underworld_IncompressibleExtensionBC_AssignFromXML( void* _self, Stg_ComponentFactory* cf, void* data ) {
-    IncExtBC* self = (IncExtBC*)_self;
-	UnderworldContext*  context  = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data );
-	ConditionFunction*  condFunc;
-   TimeIntegrator* timeIntegrator = (TimeIntegrator* )  LiveComponentRegister_Get( context->CF->LCRegister, (Name)"timeIntegrator"  );
-
-        self->context   = (AbstractContext*)context;
-        self->ctx   = context;
-
-	condFunc = ConditionFunction_New( IncompressibleExtensionBC_TopCondition, (Name)"IncompressibleExtensionBC_TopCondition"  );
-	ConditionFunction_Register_Add( condFunc_Register, condFunc );
-	condFunc = ConditionFunction_New( IncompressibleExtensionBC_BottomCondition, (Name)"IncompressibleExtensionBC_BottomCondition"  );
-	ConditionFunction_Register_Add( condFunc_Register, condFunc );
-	condFunc = ConditionFunction_New( IncompressibleExtensionBC_LeftCondition, (Name)"IncompressibleExtensionBC_LeftCondition"  );
-	ConditionFunction_Register_Add( condFunc_Register, condFunc );
-	condFunc = ConditionFunction_New( IncompressibleExtensionBC_LeftShearCondition, (Name)"IncompressibleExtensionBC_LeftShearCondition"  );
-	ConditionFunction_Register_Add( condFunc_Register, condFunc );
-	condFunc = ConditionFunction_New( IncompressibleExtensionBC_RightCondition, (Name)"IncompressibleExtensionBC_RightCondition"  );
-	ConditionFunction_Register_Add( condFunc_Register, condFunc );
-	condFunc = ConditionFunction_New( IncompressibleExtensionBC_RightShearCondition, (Name)"IncompressibleExtensionBC_RightShearCondition"  );
-	ConditionFunction_Register_Add( condFunc_Register, condFunc );
-	condFunc = ConditionFunction_New( IncompressibleExtensionBC_FrontCondition, (Name)"IncompressibleExtensionBC_FrontCondition"  );
-	ConditionFunction_Register_Add( condFunc_Register, condFunc );
-	condFunc = ConditionFunction_New( IncompressibleExtensionBC_BackCondition, (Name)"IncompressibleExtensionBC_BackCondition"  );
-	ConditionFunction_Register_Add( condFunc_Register, condFunc );
-
-        if( Stg_ComponentFactory_PluginGetBool( cf, self, (Dictionary_Entry_Key)"Remesh", False )  ) {
-	    TimeIntegrator_PrependFinishEP( 
-                                           timeIntegrator, "Underworld_IncompressibleExtensionBC_Remesh", (void*)Underworld_IncompressibleExtensionBC_Remesh, 
-		CURR_MODULE_NAME, self );
-	}
-}
-
-
-/* This function will provide StGermain the abilty to instantiate (create) this codelet on demand. */
-void* _Underworld_IncompressibleExtensionBC_DefaultNew( Name name ) {
-   return _Codelet_New(
-			sizeof( IncExtBC ),
-			Underworld_IncompressibleExtensionBC_Type,
-			_Codelet_Delete,
-			_Codelet_Print, 
-			_Codelet_Copy,
-                        name,
-                        NON_GLOBAL,
-			_Underworld_IncompressibleExtensionBC_DefaultNew,
-			_Underworld_IncompressibleExtensionBC_AssignFromXML,
-			_Codelet_Build,
-			_Codelet_Initialise,
-			_Codelet_Execute,
-			_Codelet_Destroy );
-}
-	
-/* This function is automatically run by StGermain when this plugin is loaded. The name must be "<plugin-name>_Register". */
-Index Underworld_IncompressibleExtensionBC_Register( PluginsManager* pluginsManager ) {
-	/* A plugin is only properly registered once it returns the handle provided when submitting a codelet to StGermain. */
-	return PluginsManager_Submit( pluginsManager, Underworld_IncompressibleExtensionBC_Type, (Name)"0", _Underworld_IncompressibleExtensionBC_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d plugins/IncompressibleExtensionBC/IncompressibleExtensionBC.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/IncompressibleExtensionBC/IncompressibleExtensionBC.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,350 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: IncompressibleExtensionBC.c 728 2008-05-12 02:29:30Z LouisMoresi $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdlib.h>
+#include <string.h>
+#include <mpi.h>
+#include <assert.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Underworld.h>
+#include "IncompressibleExtensionBC.h"
+
+/* Each component type needs a unique identifier (as a string for us to read and as an integer for realtime comparisions) */
+const Type Underworld_IncompressibleExtensionBC_Type = "Underworld_IncompressibleExtensionBC_Type";
+
+	/*
+
+	                       ^ V_e
+	                      /
+	         ____________/__________________________
+	        /                                      /|
+	       /                                      / |
+	      /                                      /  |
+	     /                  ^ V_c               /   |
+	    /                   |                  /    |
+	   /          ^ V_f                       /     |
+	  /          /                           /      |
+	 /__________/___________________________/       |
+	|     ^                                |        |
+	|     |                                |        |
+	|     h_1                              |  ->V_a |
+	|     |                                |        |
+	|     v                                |        |
+	|--------------------------------------|       /
+	|         ^                            |      /
+	|         |                            |     /
+	|-> V_b   |                            |    /
+	|         |h_2                         |   / 
+	|         |                            |  /
+	|         |      ^V_d                  | /
+	|________________|_____________________|/
+
+	*/
+
+double GetLeftWallVelocity( UnderworldContext* context ) {
+	return Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"leftWallVelocity", 0.0 );
+}	
+
+double GetLeftWallShearVelocity( UnderworldContext* context  ) {
+		return Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"leftWallShearVelocity", 0.0 );
+	}
+	
+double GetRightWallVelocity( UnderworldContext* context  ) {
+		return Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"rightWallVelocity", 0.0 );
+	}	
+	
+double GetRightWallShearVelocity( UnderworldContext* context  ) {
+			return Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"rightWallShearVelocity", 0.0 );
+}
+
+double GetBackWallVelocity( UnderworldContext* context ) {
+	if ( context->dim == 2  )
+		return 0.0;
+	
+	return Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"backWallVelocity", 0.0 );
+}
+double GetFrontWallVelocity( UnderworldContext* context ) {
+	if ( context->dim == 2  )
+		return 0.0;
+	
+	return Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"frontWallVelocity", 0.0 );
+}
+double GetReferenceHeight( UnderworldContext* context  ) {
+	return Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"constantHeight", 0.0 );
+}
+
+double GetTopWallVelocity( UnderworldContext* context ) {
+	FeVariable*         velocityField = (FeVariable* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"VelocityField" );
+	double              y   = GetReferenceHeight( context );
+	double              V_a = GetRightWallVelocity( context );
+	double              V_b = GetLeftWallVelocity( context );
+	double              V_e = GetBackWallVelocity( context );
+	double              V_f = GetFrontWallVelocity( context  );
+	double              V_c;
+	double              h_1;
+	XYZ                 min, max;
+	double              width;
+	double              depth;
+	
+	/* Calculate Width and Height */
+	FieldVariable_GetMinAndMaxGlobalCoords( velocityField, min, max );
+	width  = (max[ I_AXIS ] - min[ I_AXIS ]);
+	depth  = context->dim == 3 ? (max[ K_AXIS ] - min[ K_AXIS ]) : 1.0; /* if only 3D depth cancels in division */
+
+	h_1 = max[ J_AXIS ] - y;
+
+	/* Calculate velocity at the top and at the bottom of the nodes */
+	V_c = - h_1 * ( (V_a - V_b) * depth + (V_f - V_e) * width )/(width*depth);
+	
+	return V_c;
+}
+
+double GetBottomWallVelocity( UnderworldContext* context ) {
+	FeVariable*         velocityField = (FeVariable*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"VelocityField" );
+	double              y   = GetReferenceHeight( context );
+	double              V_a = GetRightWallVelocity( context );
+	double              V_b = GetLeftWallVelocity( context );
+	double              V_e = GetBackWallVelocity( context );
+	double              V_f = GetFrontWallVelocity( context  );
+	double              V_d;
+	double              h_2;
+	XYZ                 min, max;
+	double              width;
+	double              depth;
+	
+	/* Calculate Width and Height */
+	FieldVariable_GetMinAndMaxGlobalCoords( velocityField, min, max );
+	width  = (max[ I_AXIS ] - min[ I_AXIS ]);
+	depth  = context->dim == 3 ? (max[ K_AXIS ] - min[ K_AXIS ]) : 1.0; /* if only 3D depth cancels in division */
+
+	h_2 = y - min[ J_AXIS ];
+	
+	/* Calculate velocity at the top and at the bottom of the nodes */
+	V_d =   h_2 * ( (V_a - V_b) * depth + (V_f - V_e) * width )/(width*depth);
+
+	return V_d;
+}
+
+void IncompressibleExtensionBC_RightCondition( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
+	UnderworldContext* context = (UnderworldContext*) _context;
+	double*            result  = (double*) _result;
+
+	*result = GetRightWallVelocity( context );
+}
+
+void IncompressibleExtensionBC_RightShearCondition( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
+	UnderworldContext* context = (UnderworldContext*) _context;
+	double*            result  = (double*) _result;
+
+	*result = GetRightWallShearVelocity( context );
+}
+
+
+void IncompressibleExtensionBC_LeftCondition( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
+	UnderworldContext* context = (UnderworldContext*) _context;
+	double*            result  = (double*) _result;
+
+	*result = GetLeftWallVelocity( context );
+}
+
+void IncompressibleExtensionBC_LeftShearCondition( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
+	UnderworldContext* context = (UnderworldContext*) _context;
+	double*            result  = (double*) _result;
+
+	*result = GetLeftWallShearVelocity( context );
+}
+
+
+void IncompressibleExtensionBC_BackCondition( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
+	UnderworldContext* context = (UnderworldContext*) _context;
+	double*            result  = (double*) _result;
+
+	*result = GetBackWallVelocity( context );
+}
+void IncompressibleExtensionBC_FrontCondition( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
+	UnderworldContext* context = (UnderworldContext*) _context;
+	double*            result  = (double*) _result;
+
+	*result = GetFrontWallVelocity( context );
+}
+
+void IncompressibleExtensionBC_TopCondition( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
+	UnderworldContext* context = (UnderworldContext*) _context;
+	double*            result  = (double*) _result;
+
+	*result = GetTopWallVelocity( context );
+}
+
+void IncompressibleExtensionBC_BottomCondition( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
+	UnderworldContext* context = (UnderworldContext*) _context;
+	double*            result  = (double*) _result;
+
+	*result = GetBottomWallVelocity( context );
+}
+
+void Underworld_IncompressibleExtensionBC_Remesh( TimeIntegrator* timeIntegrator, IncExtBC* self ) {
+    FeVariable* velocityField = (FeVariable*) LiveComponentRegister_Get( self->context->CF->LCRegister, (Name)"VelocityField" );
+    FeVariable* pressureField = (FeVariable* ) LiveComponentRegister_Get( self->context->CF->LCRegister, (Name)"PressureField"  );
+    FeMesh *mesh;
+    Grid *nodeGrid;
+    double dt;
+    double top, bottom, left, right;
+    double minCrd[3], maxCrd[3];
+    double nodeWidth[3];
+    int numNodes;
+    int nodeInds[3];
+    int ii;
+
+    mesh = velocityField->feMesh;
+
+    nodeGrid = *Mesh_GetExtension(mesh, Grid**, "vertexGrid");
+
+    dt = AbstractContext_Dt(self->ctx);
+    top = GetTopWallVelocity(self->ctx);
+    bottom = GetBottomWallVelocity(self->ctx);
+    left = GetLeftWallVelocity(self->ctx);
+    right = GetRightWallVelocity(self->ctx);
+    Mesh_GetGlobalCoordRange(mesh, minCrd, maxCrd);
+
+    minCrd[0] += dt*left;
+    minCrd[1] += dt*bottom;
+    maxCrd[0] += dt*right;
+    maxCrd[1] += dt*top;
+
+    nodeWidth[0] = (maxCrd[0] - minCrd[0])/(double)(nodeGrid->sizes[0] - 1);
+    nodeWidth[1] = (maxCrd[1] - minCrd[1])/(double)(nodeGrid->sizes[1] - 1);
+
+    numNodes = FeMesh_GetNodeLocalSize(mesh);
+    for(ii = 0; ii < numNodes; ii++) {
+      Grid_Lift(nodeGrid, FeMesh_NodeDomainToGlobal(mesh, ii), (unsigned*)nodeInds);
+		Mesh_GetVertex(mesh, ii)[0] = minCrd[0] + ((double)nodeInds[0])*nodeWidth[0];
+		Mesh_GetVertex(mesh, ii)[1] = minCrd[1] + ((double)nodeInds[1])*nodeWidth[1];
+    }
+
+    Mesh_Sync(mesh);
+    Mesh_DeformationUpdate(mesh);
+
+    if(velocityField->feMesh != pressureField->feMesh) {
+	if(!strcmp(pressureField->feMesh->type, "CartesianGenerator")) {
+	    FeMesh *pmesh;
+	    Grid *pnodeGrid;
+	    int lind;
+
+	    pmesh = pressureField->feMesh;
+	    pnodeGrid = *Mesh_GetExtension(pmesh, Grid**, "vertexGrid");
+
+	    numNodes = FeMesh_GetNodeLocalSize(pmesh);
+	    for(ii = 0; ii < numNodes; ii++) {
+		Grid_Lift(pnodeGrid, FeMesh_NodeDomainToGlobal(pmesh, ii), (unsigned*)nodeInds);
+		nodeInds[0] *= 2;
+		nodeInds[1] *= 2;
+		insist(FeMesh_NodeGlobalToDomain(mesh, Grid_Project(nodeGrid, (unsigned*)nodeInds), (unsigned*)(&lind)), != 0);
+		memcpy(Mesh_GetVertex(pmesh, ii), Mesh_GetVertex(mesh, lind), 2*sizeof(double));
+	    }
+	}
+    }
+}
+
+void _Underworld_IncompressibleExtensionBC_AssignFromXML( void* _self, Stg_ComponentFactory* cf, void* data ) {
+    IncExtBC* self = (IncExtBC*)_self;
+	UnderworldContext*  context  = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data );
+	ConditionFunction*  condFunc;
+   TimeIntegrator* timeIntegrator = (TimeIntegrator* )  LiveComponentRegister_Get( context->CF->LCRegister, (Name)"timeIntegrator"  );
+
+        self->context   = (AbstractContext*)context;
+        self->ctx   = context;
+
+	condFunc = ConditionFunction_New( IncompressibleExtensionBC_TopCondition, (Name)"IncompressibleExtensionBC_TopCondition"  );
+	ConditionFunction_Register_Add( condFunc_Register, condFunc );
+	condFunc = ConditionFunction_New( IncompressibleExtensionBC_BottomCondition, (Name)"IncompressibleExtensionBC_BottomCondition"  );
+	ConditionFunction_Register_Add( condFunc_Register, condFunc );
+	condFunc = ConditionFunction_New( IncompressibleExtensionBC_LeftCondition, (Name)"IncompressibleExtensionBC_LeftCondition"  );
+	ConditionFunction_Register_Add( condFunc_Register, condFunc );
+	condFunc = ConditionFunction_New( IncompressibleExtensionBC_LeftShearCondition, (Name)"IncompressibleExtensionBC_LeftShearCondition"  );
+	ConditionFunction_Register_Add( condFunc_Register, condFunc );
+	condFunc = ConditionFunction_New( IncompressibleExtensionBC_RightCondition, (Name)"IncompressibleExtensionBC_RightCondition"  );
+	ConditionFunction_Register_Add( condFunc_Register, condFunc );
+	condFunc = ConditionFunction_New( IncompressibleExtensionBC_RightShearCondition, (Name)"IncompressibleExtensionBC_RightShearCondition"  );
+	ConditionFunction_Register_Add( condFunc_Register, condFunc );
+	condFunc = ConditionFunction_New( IncompressibleExtensionBC_FrontCondition, (Name)"IncompressibleExtensionBC_FrontCondition"  );
+	ConditionFunction_Register_Add( condFunc_Register, condFunc );
+	condFunc = ConditionFunction_New( IncompressibleExtensionBC_BackCondition, (Name)"IncompressibleExtensionBC_BackCondition"  );
+	ConditionFunction_Register_Add( condFunc_Register, condFunc );
+
+        if( Stg_ComponentFactory_PluginGetBool( cf, self, (Dictionary_Entry_Key)"Remesh", False )  ) {
+	    TimeIntegrator_PrependFinishEP( 
+                                           timeIntegrator, "Underworld_IncompressibleExtensionBC_Remesh", (void*)Underworld_IncompressibleExtensionBC_Remesh, 
+		CURR_MODULE_NAME, self );
+	}
+}
+
+
+/* This function will provide StGermain the abilty to instantiate (create) this codelet on demand. */
+void* _Underworld_IncompressibleExtensionBC_DefaultNew( Name name ) {
+   return _Codelet_New(
+			sizeof( IncExtBC ),
+			Underworld_IncompressibleExtensionBC_Type,
+			_Codelet_Delete,
+			_Codelet_Print, 
+			_Codelet_Copy,
+                        name,
+                        NON_GLOBAL,
+			_Underworld_IncompressibleExtensionBC_DefaultNew,
+			_Underworld_IncompressibleExtensionBC_AssignFromXML,
+			_Codelet_Build,
+			_Codelet_Initialise,
+			_Codelet_Execute,
+			_Codelet_Destroy );
+}
+	
+/* This function is automatically run by StGermain when this plugin is loaded. The name must be "<plugin-name>_Register". */
+Index Underworld_IncompressibleExtensionBC_Register( PluginsManager* pluginsManager ) {
+	/* A plugin is only properly registered once it returns the handle provided when submitting a codelet to StGermain. */
+	return PluginsManager_Submit( pluginsManager, Underworld_IncompressibleExtensionBC_Type, (Name)"0", _Underworld_IncompressibleExtensionBC_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d plugins/MeshAdvectionCorrection/MeshAdvectionCorrection.c
--- a/plugins/MeshAdvectionCorrection/MeshAdvectionCorrection.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,250 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: MeshAdvectionCorrection.c 610 2007-10-11 08:09:29Z SteveQuenette $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Underworld.h>
-
-#include <string.h>
-
-/* Each component type needs a unique identifier (as a string for us to read and as an integer for realtime comparisions) */
-const Type Underworld_MeshAdvectionCorrection_Type = "Underworld_MeshAdvectionCorrection_Type";
-
-ExtensionInfo_Index Underworld_MeshAdvectionCorrection_ContextExtHandle;
-
-typedef struct {
-	/* Save the "old" execute function pointer (which we replace) */ 
-	Stg_Component_ExecuteFunction* energySolverExecute;
-	FeVariable* artDisplacement;
-	double dt;
-} Underworld_MeshAdvectionCorrection_ContextExt;
-
-
-typedef enum {
-	ADD,
-	MINUS
-} CorrectionFlag;
-
-void MeshAdvectionCorrection_AddCorrection( FeVariable* velocityField, double* oldVelocity, double* artVelocity, CorrectionFlag flag ) {
-	/* This function offsets the VelocityField depending on the the flag:
-	 * if flag == ADD
-	 * 		velocity = oldVelocity
-	 * else {
-	 * 		if( artificalVelocity ) {	velocity = artVelocity }
-	 * 		else { velocity = (0,0) } 
-	 */
-	FeVariable*  self          = (FeVariable*)  velocityField;
-	FeMesh*      mesh          = self->feMesh;
-	int          lNodeCount    = FeMesh_GetNodeLocalSize( mesh );
-	int          dof           = self->fieldComponentCount;
-	double       oldV[3], artV[3], zero[3];
-	int lNode_I;
-
-	zero[0]=zero[1]=zero[2] = 0;
-
-	for( lNode_I = 0 ; lNode_I < lNodeCount ; lNode_I++ ) {
-
-		if ( flag == ADD ) {
-			/* velocity = stored values from oldVelocity */
-			memcpy( oldV, &oldVelocity[lNode_I*dof], dof*sizeof(double) );
-			FeVariable_SetValueAtNode( velocityField, lNode_I, oldV );
-		}
-		else {
-			if( artVelocity != 0 ) { /* use artificial velocity */
-				memcpy( artV, &artVelocity[lNode_I*dof], dof*sizeof(double) );
-				FeVariable_SetValueAtNode( velocityField, lNode_I, artV );
-			} else { /* just zero the velocity */
-				FeVariable_SetValueAtNode( velocityField, lNode_I, zero );
-			}
-		}
-
-	}
-}
-
-void MeshAdvectionCorrection_StoreCurrentVelocity( FeVariable *velocityField, double *oldVelocity ) {
-	/* save the current values of the velocity field in the oldVelocity array */
-	FeMesh *mesh = velocityField->feMesh;
-	unsigned dof = velocityField->fieldComponentCount;
-	unsigned numLocalNodes = FeMesh_GetNodeLocalSize( mesh );
-	unsigned lNode_I;
-	double vel[3];
-
-	for( lNode_I = 0 ; lNode_I < numLocalNodes ; lNode_I++ ) {
-		FeVariable_GetValueAtNode( velocityField, lNode_I, vel );
-		memcpy( &oldVelocity[lNode_I*dof], vel, dof*sizeof(double) );
-	}
-}
-
-void MeshAdvectionCorrection_EulerDeformCorrection( FeVariable *artDField, double *artVelocity, double dt ) {
-	/* save the purely artificial bit of the remeshing in the artVelocity */
-	FeMesh*      mesh = artDField->feMesh;
-	Dof_Index    dof  = artDField->fieldComponentCount;
-	double       artV[3], artD[3];
-	int numLocalNodes = FeMesh_GetNodeLocalSize( mesh );
-	Dof_Index    dof_I, lNode_I;
-
-		/* INITIAL CONDITION: artV = 0 */
-	if( dt == 0 ) {
-		for( lNode_I = 0 ; lNode_I < numLocalNodes ; lNode_I++ ) {
-			for( dof_I = 0 ; dof_I < dof ; dof_I++ ) 
-				artV[dof_I] = 0;
-
-			memcpy( &artVelocity[lNode_I*dof] , artV, dof*sizeof(double) );
-		}
-		return;
-	}
-	
-	 /* GENERAL algorithm artV = -1*artD / dt. It's -ve because we 
-		* want to reverse the effects of the artificial displacement */
-	for( lNode_I = 0 ; lNode_I < numLocalNodes ; lNode_I++ ) {
-		FeVariable_GetValueAtNode( artDField, lNode_I, artD );
-		/* artV = artD / dt */
-		for( dof_I = 0 ; dof_I < dof ; dof_I++ ) 
-			artV[dof_I] = -1*artD[dof_I] / dt;
-
-		memcpy( &artVelocity[lNode_I*dof] , artV, dof*sizeof(double) );
-	}
-
-}
-
-void MeshAdvectionCorrection( void* sle, void* data ) {
-	UnderworldContext*                                      context                 = (UnderworldContext*) data;
-	Underworld_MeshAdvectionCorrection_ContextExt*          plugin;
-	FeVariable*		velocityField 	= (FeVariable*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"VelocityField"  );
-	double dt = context->dt;
-	double *artVelocity, *oldVelocity;
-	int lNodeCount;
-	lNodeCount = FeMesh_GetNodeLocalSize( velocityField->feMesh );
-
-	artVelocity = oldVelocity = NULL;
-
-	/* store the current velocity in oldVelocity */
-	oldVelocity = Memory_Alloc_Array( double, 
-			lNodeCount * velocityField->fieldComponentCount, 
-			"artificial nodal velocities" );
-
-	/* get the plugin from the context */
-	plugin = (Underworld_MeshAdvectionCorrection_ContextExt*)ExtensionManager_Get( 
-		context->extensionMgr, 
-		context, 
-		Underworld_MeshAdvectionCorrection_ContextExtHandle );
-
-	MeshAdvectionCorrection_StoreCurrentVelocity( velocityField, oldVelocity );
-
-	if( plugin->artDisplacement ) {
-		artVelocity = Memory_Alloc_Array( double, lNodeCount * velocityField->fieldComponentCount, "artificial nodal velocities" );
-		MeshAdvectionCorrection_EulerDeformCorrection( plugin->artDisplacement, artVelocity, dt );
-	}
-
-	/* Correct velocity and re-sync shadow space */
-	MeshAdvectionCorrection_AddCorrection( velocityField, oldVelocity, artVelocity, MINUS );
-	FeVariable_SyncShadowValues( velocityField );
-
-	/* Solve Energy equation */
-	plugin->energySolverExecute( sle, context );
-
-	/* Reverse correction and re-sync */
-	MeshAdvectionCorrection_AddCorrection( velocityField, oldVelocity, artVelocity, ADD );
-	FeVariable_SyncShadowValues( velocityField );
-
-	if( plugin->artDisplacement )
-		Memory_Free( artVelocity );
-	Memory_Free( oldVelocity );
-}
-
-void _Underworld_MeshAdvectionCorrection_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
-	UnderworldContext*                                      context = 
-	Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data ); 
-	Underworld_MeshAdvectionCorrection_ContextExt*       plugin;
-   AdvectionDiffusionSLE* energySLE = (AdvectionDiffusionSLE* ) Stg_ComponentFactory_ConstructByName( cf, (Name)"EnergyEqn", UnderworldContext, True, data );
-	
-	Journal_DFirewall( 
-		context!=NULL, 
-		Journal_Register( Error_Type, (Name)Underworld_MeshAdvectionCorrection_Type  ), 
-		"No context found\n" );
-	Journal_DFirewall( 
-		energySLE!=NULL, 
-		Journal_Register( Error_Type, (Name)Underworld_MeshAdvectionCorrection_Type  ), 
-		"The required energy SLE component has not been created or placed on the context.\n");	
-	
-	/* Add the extension to the context */
-	Underworld_MeshAdvectionCorrection_ContextExtHandle = ExtensionManager_Add( context->extensionMgr, (Name)Underworld_MeshAdvectionCorrection_Type, sizeof( Underworld_MeshAdvectionCorrection_ContextExt )  );
-	plugin = (Underworld_MeshAdvectionCorrection_ContextExt*)ExtensionManager_Get( 
-		context->extensionMgr, 
-		context, 
-		Underworld_MeshAdvectionCorrection_ContextExtHandle );
-
-	if( Stg_ComponentFactory_GetRootDictBool( cf, (Dictionary_Entry_Key)"MeshAdvectionCorrection_UseArtDisplacementField", False)  ) {
-		/* get the artificial displacement field */
-		plugin->artDisplacement = Stg_ComponentFactory_ConstructByName( cf, (Name)"ArtDisplacementField", FeVariable, True, data );
-	}
-
-	/* Replace the energy SLE's execute with this one. Save the old value for use later. */
-	plugin->energySolverExecute = energySLE->_execute;
-	energySLE->_execute = MeshAdvectionCorrection;
-}
-
-/* This function will provide StGermain the abilty to instantiate (create) this codelet on demand. */
-void* _Underworld_MeshAdvectionCorrection_DefaultNew( Name name  ) {
-	return Codelet_New(
-			Underworld_MeshAdvectionCorrection_Type,
-			_Underworld_MeshAdvectionCorrection_DefaultNew,
-			_Underworld_MeshAdvectionCorrection_AssignFromXML, /* SQ NOTE: Used to be a construct extensions. */
-			_Codelet_Build,
-			_Codelet_Initialise,
-			_Codelet_Execute,
-			_Codelet_Destroy,
-			name );
-}
-
-/* This function is automatically run by StGermain when this plugin is loaded. The name must be "<plugin-name>_Register". */
-Index Underworld_MeshAdvectionCorrection_Register( PluginsManager* pluginsManager ) {
-	/* A plugin is only properly registered once it returns the handle provided when submitting a codelet to StGermain. */
-	return PluginsManager_Submit( pluginsManager, Underworld_MeshAdvectionCorrection_Type, (Name)"0", _Underworld_MeshAdvectionCorrection_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d plugins/MeshAdvectionCorrection/MeshAdvectionCorrection.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/MeshAdvectionCorrection/MeshAdvectionCorrection.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,250 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: MeshAdvectionCorrection.c 610 2007-10-11 08:09:29Z SteveQuenette $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Underworld.h>
+
+#include <string.h>
+
+/* Each component type needs a unique identifier (as a string for us to read and as an integer for realtime comparisions) */
+const Type Underworld_MeshAdvectionCorrection_Type = "Underworld_MeshAdvectionCorrection_Type";
+
+ExtensionInfo_Index Underworld_MeshAdvectionCorrection_ContextExtHandle;
+
+typedef struct {
+	/* Save the "old" execute function pointer (which we replace) */ 
+	Stg_Component_ExecuteFunction* energySolverExecute;
+	FeVariable* artDisplacement;
+	double dt;
+} Underworld_MeshAdvectionCorrection_ContextExt;
+
+
+typedef enum {
+	ADD,
+	MINUS
+} CorrectionFlag;
+
+void MeshAdvectionCorrection_AddCorrection( FeVariable* velocityField, double* oldVelocity, double* artVelocity, CorrectionFlag flag ) {
+	/* This function offsets the VelocityField depending on the the flag:
+	 * if flag == ADD
+	 * 		velocity = oldVelocity
+	 * else {
+	 * 		if( artificalVelocity ) {	velocity = artVelocity }
+	 * 		else { velocity = (0,0) } 
+	 */
+	FeVariable*  self          = (FeVariable*)  velocityField;
+	FeMesh*      mesh          = self->feMesh;
+	int          lNodeCount    = FeMesh_GetNodeLocalSize( mesh );
+	int          dof           = self->fieldComponentCount;
+	double       oldV[3], artV[3], zero[3];
+	int lNode_I;
+
+	zero[0]=zero[1]=zero[2] = 0;
+
+	for( lNode_I = 0 ; lNode_I < lNodeCount ; lNode_I++ ) {
+
+		if ( flag == ADD ) {
+			/* velocity = stored values from oldVelocity */
+			memcpy( oldV, &oldVelocity[lNode_I*dof], dof*sizeof(double) );
+			FeVariable_SetValueAtNode( velocityField, lNode_I, oldV );
+		}
+		else {
+			if( artVelocity != 0 ) { /* use artificial velocity */
+				memcpy( artV, &artVelocity[lNode_I*dof], dof*sizeof(double) );
+				FeVariable_SetValueAtNode( velocityField, lNode_I, artV );
+			} else { /* just zero the velocity */
+				FeVariable_SetValueAtNode( velocityField, lNode_I, zero );
+			}
+		}
+
+	}
+}
+
+void MeshAdvectionCorrection_StoreCurrentVelocity( FeVariable *velocityField, double *oldVelocity ) {
+	/* save the current values of the velocity field in the oldVelocity array */
+	FeMesh *mesh = velocityField->feMesh;
+	unsigned dof = velocityField->fieldComponentCount;
+	unsigned numLocalNodes = FeMesh_GetNodeLocalSize( mesh );
+	unsigned lNode_I;
+	double vel[3];
+
+	for( lNode_I = 0 ; lNode_I < numLocalNodes ; lNode_I++ ) {
+		FeVariable_GetValueAtNode( velocityField, lNode_I, vel );
+		memcpy( &oldVelocity[lNode_I*dof], vel, dof*sizeof(double) );
+	}
+}
+
+void MeshAdvectionCorrection_EulerDeformCorrection( FeVariable *artDField, double *artVelocity, double dt ) {
+	/* save the purely artificial bit of the remeshing in the artVelocity */
+	FeMesh*      mesh = artDField->feMesh;
+	Dof_Index    dof  = artDField->fieldComponentCount;
+	double       artV[3], artD[3];
+	int numLocalNodes = FeMesh_GetNodeLocalSize( mesh );
+	Dof_Index    dof_I, lNode_I;
+
+		/* INITIAL CONDITION: artV = 0 */
+	if( dt == 0 ) {
+		for( lNode_I = 0 ; lNode_I < numLocalNodes ; lNode_I++ ) {
+			for( dof_I = 0 ; dof_I < dof ; dof_I++ ) 
+				artV[dof_I] = 0;
+
+			memcpy( &artVelocity[lNode_I*dof] , artV, dof*sizeof(double) );
+		}
+		return;
+	}
+	
+	 /* GENERAL algorithm artV = -1*artD / dt. It's -ve because we 
+		* want to reverse the effects of the artificial displacement */
+	for( lNode_I = 0 ; lNode_I < numLocalNodes ; lNode_I++ ) {
+		FeVariable_GetValueAtNode( artDField, lNode_I, artD );
+		/* artV = artD / dt */
+		for( dof_I = 0 ; dof_I < dof ; dof_I++ ) 
+			artV[dof_I] = -1*artD[dof_I] / dt;
+
+		memcpy( &artVelocity[lNode_I*dof] , artV, dof*sizeof(double) );
+	}
+
+}
+
+void MeshAdvectionCorrection( void* sle, void* data ) {
+	UnderworldContext*                                      context                 = (UnderworldContext*) data;
+	Underworld_MeshAdvectionCorrection_ContextExt*          plugin;
+	FeVariable*		velocityField 	= (FeVariable*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"VelocityField"  );
+	double dt = context->dt;
+	double *artVelocity, *oldVelocity;
+	int lNodeCount;
+	lNodeCount = FeMesh_GetNodeLocalSize( velocityField->feMesh );
+
+	artVelocity = oldVelocity = NULL;
+
+	/* store the current velocity in oldVelocity */
+	oldVelocity = Memory_Alloc_Array( double, 
+			lNodeCount * velocityField->fieldComponentCount, 
+			"artificial nodal velocities" );
+
+	/* get the plugin from the context */
+	plugin = (Underworld_MeshAdvectionCorrection_ContextExt*)ExtensionManager_Get( 
+		context->extensionMgr, 
+		context, 
+		Underworld_MeshAdvectionCorrection_ContextExtHandle );
+
+	MeshAdvectionCorrection_StoreCurrentVelocity( velocityField, oldVelocity );
+
+	if( plugin->artDisplacement ) {
+		artVelocity = Memory_Alloc_Array( double, lNodeCount * velocityField->fieldComponentCount, "artificial nodal velocities" );
+		MeshAdvectionCorrection_EulerDeformCorrection( plugin->artDisplacement, artVelocity, dt );
+	}
+
+	/* Correct velocity and re-sync shadow space */
+	MeshAdvectionCorrection_AddCorrection( velocityField, oldVelocity, artVelocity, MINUS );
+	FeVariable_SyncShadowValues( velocityField );
+
+	/* Solve Energy equation */
+	plugin->energySolverExecute( sle, context );
+
+	/* Reverse correction and re-sync */
+	MeshAdvectionCorrection_AddCorrection( velocityField, oldVelocity, artVelocity, ADD );
+	FeVariable_SyncShadowValues( velocityField );
+
+	if( plugin->artDisplacement )
+		Memory_Free( artVelocity );
+	Memory_Free( oldVelocity );
+}
+
+void _Underworld_MeshAdvectionCorrection_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
+	UnderworldContext*                                      context = 
+	Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data ); 
+	Underworld_MeshAdvectionCorrection_ContextExt*       plugin;
+   AdvectionDiffusionSLE* energySLE = (AdvectionDiffusionSLE* ) Stg_ComponentFactory_ConstructByName( cf, (Name)"EnergyEqn", UnderworldContext, True, data );
+	
+	Journal_DFirewall( 
+		context!=NULL, 
+		Journal_Register( Error_Type, (Name)Underworld_MeshAdvectionCorrection_Type  ), 
+		"No context found\n" );
+	Journal_DFirewall( 
+		energySLE!=NULL, 
+		Journal_Register( Error_Type, (Name)Underworld_MeshAdvectionCorrection_Type  ), 
+		"The required energy SLE component has not been created or placed on the context.\n");	
+	
+	/* Add the extension to the context */
+	Underworld_MeshAdvectionCorrection_ContextExtHandle = ExtensionManager_Add( context->extensionMgr, (Name)Underworld_MeshAdvectionCorrection_Type, sizeof( Underworld_MeshAdvectionCorrection_ContextExt )  );
+	plugin = (Underworld_MeshAdvectionCorrection_ContextExt*)ExtensionManager_Get( 
+		context->extensionMgr, 
+		context, 
+		Underworld_MeshAdvectionCorrection_ContextExtHandle );
+
+	if( Stg_ComponentFactory_GetRootDictBool( cf, (Dictionary_Entry_Key)"MeshAdvectionCorrection_UseArtDisplacementField", False)  ) {
+		/* get the artificial displacement field */
+		plugin->artDisplacement = Stg_ComponentFactory_ConstructByName( cf, (Name)"ArtDisplacementField", FeVariable, True, data );
+	}
+
+	/* Replace the energy SLE's execute with this one. Save the old value for use later. */
+	plugin->energySolverExecute = energySLE->_execute;
+	energySLE->_execute = MeshAdvectionCorrection;
+}
+
+/* This function will provide StGermain the abilty to instantiate (create) this codelet on demand. */
+void* _Underworld_MeshAdvectionCorrection_DefaultNew( Name name  ) {
+	return Codelet_New(
+			Underworld_MeshAdvectionCorrection_Type,
+			_Underworld_MeshAdvectionCorrection_DefaultNew,
+			_Underworld_MeshAdvectionCorrection_AssignFromXML, /* SQ NOTE: Used to be a construct extensions. */
+			_Codelet_Build,
+			_Codelet_Initialise,
+			_Codelet_Execute,
+			_Codelet_Destroy,
+			name );
+}
+
+/* This function is automatically run by StGermain when this plugin is loaded. The name must be "<plugin-name>_Register". */
+Index Underworld_MeshAdvectionCorrection_Register( PluginsManager* pluginsManager ) {
+	/* A plugin is only properly registered once it returns the handle provided when submitting a codelet to StGermain. */
+	return PluginsManager_Submit( pluginsManager, Underworld_MeshAdvectionCorrection_Type, (Name)"0", _Underworld_MeshAdvectionCorrection_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d plugins/MovingMesh/MovingMesh.c
--- a/plugins/MovingMesh/MovingMesh.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,563 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: MovingMesh.c 734 2008-05-15 23:15:29Z LukeHodkinson $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Underworld.h>
-
-#include "MovingMesh.h"
-#include <assert.h>
-
-
-/* Each component type needs a unique identifier (as a string for us to read and as an integer for realtime comparisions) */
-const Type Underworld_MovingMesh_Type = "Underworld_MovingMesh";
-
-void _Underworld_MovingMesh_AssignFromXML( void* meshExtender, Stg_ComponentFactory* cf, void* data ) {
-	UnderworldContext*  context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data );
-	MeshExtender*       self = (MeshExtender*) meshExtender;
-	Dimension_Index     dim_I = 0;
-	Dimension_Index     axisToRemeshOnTotal = 0;
-	
-	Journal_Firewall( 
-		(Bool )context, 
-		Journal_Register( Error_Type, (Name)Underworld_MovingMesh_Type  ), 
-		"No context found\n" );
-
-	self->context = (AbstractContext*)context;	
-	self->velocityField = context->velocityField;
-
-	Journal_Firewall( (Bool)self->velocityField, 
-			  Journal_Register( Error_Type, (Name)Underworld_MovingMesh_Type  ), 
-			  "The required velocity field component has not been created or placed on the context.\n");
-
-	self->remeshAccordingToAxis[I_AXIS] = 		
-		Dictionary_GetBool_WithDefault( context->dictionary, (Dictionary_Entry_Key)"remeshAccordingToIAxis", True  );
-	self->remeshAccordingToAxis[J_AXIS] = 		
-		Dictionary_GetBool_WithDefault( context->dictionary, (Dictionary_Entry_Key)"remeshAccordingToJAxis", True );
-	if ( self->velocityField->dim == 2  ) {
-		self->remeshAccordingToAxis[K_AXIS] = False;
-	}
-	else {
-		self->remeshAccordingToAxis[K_AXIS] = 		
-			Dictionary_GetBool_WithDefault( context->dictionary, (Dictionary_Entry_Key)"remeshAccordingToKAxis", True );
-	}
-
-	axisToRemeshOnTotal = 0;
-	for ( dim_I = 0; dim_I < self->velocityField->dim; dim_I++ ) {
-		if ( self->remeshAccordingToAxis[dim_I] == True  ) {
-			axisToRemeshOnTotal++;
-		}
-	}
-
-	Journal_Firewall( 
-		axisToRemeshOnTotal > 0,
-		Journal_Register( Error_Type, (Name)Underworld_MovingMesh_Type  ), 
-		"Error: in %s: you have disabled remeshing on all axis. Please set at least one axis to remesh on "
-		"using the remeshAccordingToIAxis, remeshAccordingToJAxis, remeshAccordingToKAxis dictionary "
-		"parameters, if you wish to use the remesher.\n",
-		__func__ );
-
-	/*  */ 
-	/* TODO: this timeIntegrator interface seems weird. Would have thought you'd pass a ptr to self. */
-	TimeIntegrator_PrependFinishEP( 
-			context->timeIntegrator, "Underworld_MovingMesh_Remesh", Underworld_MovingMesh_Remesh, 
-			CURR_MODULE_NAME, self );
-
-	/* Add to Live Stg_Component Register so it gets automatically built, initialised and deleted */
-	LiveComponentRegister_Add( context->CF->LCRegister, (Stg_Component*) self );
-}
-
-void Underworld_MovingMesh_Build( void* meshExtender, void* data ) {
-	MeshExtender*       self = (MeshExtender*)meshExtender;
-	Mesh*		    mesh;
-
-	mesh = (Mesh*)self->velocityField->feMesh;
-
-	Journal_Firewall( ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" ) != (unsigned )-1, 
-			  Journal_Register( Error_Type, (Name)Underworld_MovingMesh_Type  ), 
-			  "Error: in %s: provided Velocity field's mesh doesn't have a regular decomposition.\n",
-			  __func__ );
-}
-
-
-void Underworld_MovingMesh_Remesh( TimeIntegrator* timeIntegrator, MeshExtender* self ) {
-	FeVariable*           velocityField = self->velocityField;
-	Mesh*                 mesh          = (Mesh*) velocityField->feMesh;
-	unsigned	      rank;
-	Stream*               debug = Journal_Register( Debug_Type, (Name)Underworld_MovingMesh_Type  );
-	Stream*               info = Journal_Register( Info_Type, (Name)self->type  );
-	double                remeshTime, remeshTimeStart, remeshTimeEnd;
-	Dimension_Index       dim_I = 0;
-	Dimension_Index       axisToRemeshOnTotal = 0;
-	double                dt = 0.0;
-	MPI_Comm	      comm;
-	#if DEBUG
-	Index                 element_dI;
-	#endif
-
-	/*comm = CommTopology_GetComm( Mesh_GetCommTopology( mesh, MT_VERTEX ) );*/
-	comm = Comm_GetMPIComm( Mesh_GetCommTopology( mesh, MT_VERTEX ) );
-	MPI_Comm_rank( comm, (int*)&rank );
-
-	Journal_Printf( info, "%d: starting remeshing of mesh \"%s\":\n", rank, mesh->name );
-	axisToRemeshOnTotal = 0;
-	Journal_Printf( info, "Axis set to remesh on are : " );
-	for ( dim_I = 0; dim_I < velocityField->dim; dim_I++ ) {
-		if ( self->remeshAccordingToAxis[dim_I] == True ) {
-                  /* Journal_Printf( info, "%c, ", IJKTopology_DimNumToDimLetter[dim_I] );*/
-			axisToRemeshOnTotal++;
-		}
-	}
-	Journal_Printf( info, "\n" );
-	Journal_DPrintf( debug, "In %s(): about to remesh:\n", __func__ );
-	Stream_Indent( debug );
-
-	Journal_Firewall( 
-		axisToRemeshOnTotal > 0,
-		Journal_Register( Error_Type, (Name)Underworld_MovingMesh_Type  ), 
-		"Error: in %s: you have disabled remeshing on all axis. Please set at least one axis to remesh on "
-		"using the remeshAccordingToIAxis, remeshAccordingToJAxis, remeshAccordingToKAxis dictionary "
-		"parameters, if you wish to use the remesher.\n",
-		__func__ );
-
-	dt = AbstractContext_Dt( self->context );
-	/* TODO: the if statement is here since we seem to be using last timestep's dt to update. Is this correct?
-	 PatrickSunter - 5 June 2006 */
-	if ( self->context->timeStep > 1 ) {
-		Journal_Firewall( 
-			dt > 0.0,
-			Journal_Register( Error_Type, (Name)Underworld_MovingMesh_Type  ), 
-			"Error- in %s: in timeStep %u, provided Context \"%s\"'s dt <= 0.\n",
-			__func__, self->context->timeStep, self->context->name );
-	}	
-	
-	remeshTimeStart = MPI_Wtime();
-
-	Journal_Firewall( ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" ) != (unsigned )-1, 
-			  Journal_Register( Error_Type, (Name)Underworld_MovingMesh_Type  ), 
-			  "Error: in %s: provided Velocity field's mesh doesn't have a regular decomposition.\n",
-			  __func__ );
-
-	/*
-	Journal_Firewall( 
-		True == Stg_Class_IsInstance( velocityField->feMesh->layout->elementLayout, ParallelPipedHexaEL_Type ),
-		Journal_Register( Error_Type, (Name)Underworld_MovingMesh_Type  ), 
-		"Error: in %s: provided Velocity field's mesh doesn't have a %s elementLayout.\n",
-		__func__, ParallelPipedHexaEL_Type );
-	*/
-
-	Underworld_MovingMesh_RemeshAccordingToSidewalls( self, velocityField );
-	
-	Journal_DPrintf( debug, "remeshing complete.\n" );
-
-	/*
-	#if DEBUG
-	if ( Stream_IsEnable( debug ) && Stream_IsPrintableLevel( debug, 3 ) ) {
-		Journal_DPrintfL( debug, 3, "Updated node coords:\n" );
-		Stream_Indent( debug );
-		for ( element_dI = 0; element_dI < Mesh_GetDomainSize( velocityField->feMesh, MT_VERTEX ); element_dI++ ) {
-			Journal_DPrintfL( debug, 3, "In Element %3d: ", element_dI );
-			Mesh_PrintNodeCoordsOfElement( velocityField->feMesh, element_dI, debug );
-		}	
-		Stream_UnIndent( debug );
-	}	
-	#endif
-	*/
-
-	remeshTimeEnd = MPI_Wtime();
-	remeshTime = remeshTimeEnd - remeshTimeStart;
-	Journal_Printf( info, "%d: finished remeshing: took %f sec.\n", rank, remeshTime );
-
-	Stream_UnIndent( debug );
-
-	return;
-}
-
-
-void Underworld_MovingMesh_RemeshAccordingToSidewalls( MeshExtender* self, FeVariable* velocityField ) {
-	Mesh*                 mesh          = (Mesh*) velocityField->feMesh;
-	Dimension_Index       remeshAxis_I;
-	
-	for ( remeshAxis_I = 0 ; remeshAxis_I < velocityField->dim ; remeshAxis_I++ ) {
-		if ( self->remeshAccordingToAxis[remeshAxis_I] == True ) {
-			Underworld_MovingMesh_RemeshAccordingToSidewall_SingleAxis( self, velocityField, remeshAxis_I );
-		}	
-	}
-
-	/* Update mesh details. */
-	Mesh_DeformationUpdate( mesh );
-}
-
-
-void Underworld_MovingMesh_RemeshAccordingToSidewall_SingleAxis(
-		MeshExtender*    self,
-		FeVariable*      velocityField,
-		Dimension_Index  remeshAxis )
-{
-	Mesh*                      mesh          = (Mesh*) velocityField->feMesh;
-	double			   maxCrd[3], minCrd[3];
-	Grid*			   vertGrid;
-	/* Assume IJK Topology */
-	double*                    minGlobal;
-	double*                    maxGlobal;
-	Node_Index                 sideWallNodeCount;
-	Dimension_Index            otherAxisA = (remeshAxis + 1) % 3;
-	Dimension_Index            otherAxisB = (remeshAxis + 2) % 3;
-	IJK                        nodeIJK;
-	Node_Index                 sideWallNode_I;
-	Node_Index                 aNode_I;
-	Node_Index                 bNode_I;
-	Node_Index                 remeshAxisNode_I;
-	Node_GlobalIndex           nodeGlobal_I;
-	Node_DomainIndex           nodeDomain_I;
-	double                     newElementWidthInRemeshAxis;
-	double                     minGlobalCoord =  HUGE_VAL;
-	double                     maxGlobalCoord = -HUGE_VAL;
-	/*Bool                       nodeG2DBuiltTemporarily = False;*/
-	double                     newCoordInRemeshAxis = 0;
-	double                     tolerance;
-
-	Stream* debug = Journal_Register( Debug_Type, (Name)Underworld_MovingMesh_Type  );
-
-	/*Journal_DPrintf( debug, "In %s(): for remeshAxis %c\n", __func__, IJKTopology_DimNumToDimLetter[remeshAxis] );*/
-	Stream_Indent( debug );	
-
-	Mesh_GetGlobalCoordRange( mesh, minCrd, maxCrd );
-	tolerance = (maxCrd[remeshAxis] - minCrd[remeshAxis]) * 1e-9;
-
-	vertGrid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-						  ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
-
-	sideWallNodeCount = vertGrid->sizes[ otherAxisA ] * vertGrid->sizes[ otherAxisB ];
-	minGlobal = Memory_Alloc_Array( double, sideWallNodeCount, "min node coords" );
-	maxGlobal = Memory_Alloc_Array( double, sideWallNodeCount, "max node coords" );
-
-	/* As long as memory not too tight, create temporary tables to massively speed up
-	   necessary global to local calculations. */
-	/*
-	if ( (mesh->buildTemporaryGlobalTables == True) && (mesh->nodeG2D == 0) ) {
-		mesh->nodeG2D = MeshDecomp_BuildNodeGlobalToDomainMap( meshDecomp );
-		nodeG2DBuiltTemporarily = True;
-	}
-	*/
-	
-	/* calc min and max wall new coords given velocity field */
-	Underworld_MovingMesh_CalculateMinOrMaxCoordsOnSidewall(
-		self, velocityField, remeshAxis, MIN_COORDS, minGlobal );
-	Underworld_MovingMesh_CalculateMinOrMaxCoordsOnSidewall(
-		self, velocityField, remeshAxis, MAX_COORDS, maxGlobal );
-
-	/* calc overall min and max wall new coords */
-	for ( sideWallNode_I = 0; sideWallNode_I < sideWallNodeCount; sideWallNode_I++ ) {
-		if ( minGlobal[ sideWallNode_I ] < minGlobalCoord )
-			minGlobalCoord = minGlobal[ sideWallNode_I ];
-		if ( maxGlobal[ sideWallNode_I ] > maxGlobalCoord )
-			maxGlobalCoord = maxGlobal[ sideWallNode_I ];
-	}	
-
-	if ( ( fabs( minGlobalCoord - minCrd[ remeshAxis ] ) < tolerance ) &&
-		( fabs( maxGlobalCoord - maxCrd[ remeshAxis ] ) < tolerance ) )
-	{
-          /*Journal_DPrintfL( debug, 1, "Found no extension/compression in remeshAxis %c: thus not "
-            "updating node coords.\n", IJKTopology_DimNumToDimLetter[remeshAxis] );*/
-		Memory_Free( minGlobal );
-		Memory_Free( maxGlobal );
-		/*
-		if ( nodeG2DBuiltTemporarily ) {
-			Memory_Free( mesh->nodeG2D );
-			mesh->nodeG2D = NULL;
-		}
-		*/
-		Stream_UnIndent( debug );	
-		return;
-	}
-
-	/* Change Geometry */
-	/*
-	Journal_DPrintfL( debug, 3, "Updating mesh's BlockGeometry \"%s\" with new global "
-		"min and max in remesh axis %c: min=%.3f, max=%.3f\n",
-		geometry->name, IJKTopology_DimNumToDimLetter[remeshAxis], minGlobalCoord, maxGlobalCoord );
-
-	minCrd[ remeshAxis ] = minGlobalCoord;
-	maxCrd[ remeshAxis ] = maxGlobalCoord;
-	*/
-
-	/*Journal_DPrintfL( debug, 2, "Looping over all nodes, updating coordinates in remeshAxis %c based on "
-          "stretch/compression on the relevant side walls.\n", IJKTopology_DimNumToDimLetter[remeshAxis] );*/
-	Stream_Indent( debug );	
-	sideWallNode_I = 0;
-	for ( aNode_I = 0 ; aNode_I < vertGrid->sizes[ otherAxisA ] ; aNode_I++ ) {
-		nodeIJK[ otherAxisA ] = aNode_I;
-		for ( bNode_I = 0 ; bNode_I < vertGrid->sizes[ otherAxisB ] ; bNode_I++ ) {
-			nodeIJK[ otherAxisB ] = bNode_I;
-
-			newElementWidthInRemeshAxis = (maxGlobal[ sideWallNode_I ] - minGlobal[ sideWallNode_I ])
-				/ ( (double)vertGrid->sizes[ remeshAxis ] - 1.0 );
-
-			/*Journal_DPrintfL( debug, 3, "For slice with aNode_I=%u in otherAxisA=%c and bNode_I=%u in "
-				"otherAxisB=%c: calculated new element width in remesh axis= %.3f\n",
-				aNode_I, IJKTopology_DimNumToDimLetter[otherAxisA],
-				bNode_I, IJKTopology_DimNumToDimLetter[otherAxisB],
-				newElementWidthInRemeshAxis );*/
-			Stream_Indent( debug );	
-
-			for ( remeshAxisNode_I = 0 ; remeshAxisNode_I < vertGrid->sizes[ remeshAxis ] ; remeshAxisNode_I++ ) {
-				nodeIJK[ remeshAxis ] = remeshAxisNode_I;
-
-				/* Find this local coord */
-				nodeGlobal_I = Grid_Project( vertGrid, nodeIJK );
-
-				/* Adjust position if this node is on my processor */
-				if ( Mesh_GlobalToDomain( mesh, MT_VERTEX, nodeGlobal_I, &nodeDomain_I ) && 
-				     nodeDomain_I < Mesh_GetDomainSize( mesh, MT_VERTEX ) )
-				{
-					newCoordInRemeshAxis = minGlobal[ sideWallNode_I ] +
-						newElementWidthInRemeshAxis * (double) remeshAxisNode_I;
-					Journal_DPrintfL( debug, 3, "updating node coord[%u] at IJK(%u,%u,%u) (domain "
-						"node I %u) from %.3f to %.3f\n", remeshAxis, nodeIJK[0], nodeIJK[1], nodeIJK[2],
-						nodeDomain_I, Mesh_GetVertex( mesh, nodeDomain_I )[ remeshAxis ],
-						newCoordInRemeshAxis );
-					Mesh_GetVertex( mesh, nodeDomain_I )[ remeshAxis ] = newCoordInRemeshAxis;
-				}		
-			}
-			Stream_UnIndent( debug );	
-
-			/* Increment counter for side wall node index */
-			sideWallNode_I++;
-		}
-	}
-	Stream_UnIndent( debug );	
-
-	/*
-	if ( nodeG2DBuiltTemporarily ) {
-		Memory_Free( mesh->nodeG2D );
-		mesh->nodeG2D = NULL;
-	}
-	*/
-
-	/* Update the element layout's partition info based on geometry changes... */
-	/*
-	ParallelPipedHexaEL_UpdateGeometryPartitionInfo( mesh->layout->elementLayout, mesh->layout->decomp );
-	*/
-
-	/* Update mesh information. */
-	Mesh_Sync( mesh );
-	Mesh_DeformationUpdate( mesh );
-
-	Memory_Free( minGlobal );
-	Memory_Free( maxGlobal );
-	Stream_UnIndent( debug );	
-}
-
-
-void Underworld_MovingMesh_CalculateMinOrMaxCoordsOnSidewall(
-		MeshExtender*    self,
-		FeVariable*      velocityField,
-		Dimension_Index  remeshAxis,
-		MinOrMaxFlag     minOrMaxFlag,
-		double*          newWallCoordsInRemeshAxisGlobal )
-{
-	Mesh*                      mesh          = (Mesh*) velocityField->feMesh;
-	Grid*			   vertGrid;
-	double			   maxCrd[3], minCrd[3];
-	IJK                        wallNodeIJK;
-	Node_Index                 sideWallNode_I;
-	Node_LocalIndex            wallNode_lI;
-	Node_Index                 aNode_I;
-	Node_Index                 bNode_I;
-	Node_Index                 sideWallNodeCount;
-	Dimension_Index            otherAxisA = (remeshAxis + 1) % 3;
-	Dimension_Index            otherAxisB = (remeshAxis + 2) % 3;
-	MPI_Op                     mpiOperation;
-	double*                    newWallCoordsInRemeshAxis = NULL;
-	Node_LocalIndex            lastCalculatedWallNode_lI = 0;
-	Node_Index                 lastCalculatedWallNode_sideI = 0;
-	double                     lastCalculatedNewWallCoordInRemeshAxis;
-	double*                    currNodeCoord;
-	double                     velVector[3];
-	/* Somewhat arbitrary tolerance to check that extension of the mesh is not irregular in the current axis */
-	double                     tolerance;
-	double                     dt = AbstractContext_Dt( self->context );
-	Bool                       atLeastOneLocalSideNodeProcessed = False;
-	MPI_Comm		   comm;
-
-	Mesh_GetGlobalCoordRange( mesh, minCrd, maxCrd );
-	tolerance = (maxCrd[remeshAxis] - minCrd[remeshAxis]) * 1e-9;
-
-	vertGrid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-						  ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
-
-	sideWallNodeCount = vertGrid->sizes[ otherAxisA ] * vertGrid->sizes[ otherAxisB ];
-	newWallCoordsInRemeshAxis = Memory_Alloc_Array( double, sideWallNodeCount, "newWallCoordsInRemeshAxis" );
-
-	if ( minOrMaxFlag == MIN_COORDS ) {
-		/* Loop over all nodes on the minimum side wall */
-		wallNodeIJK[ remeshAxis ] = 0;
-	}
-	else {
-		/* Loop over all nodes on the maximum side wall */
-		wallNodeIJK[ remeshAxis ] = vertGrid->sizes[ remeshAxis ] - 1 ;
-	}
-
-	sideWallNode_I = 0;
-	for ( aNode_I = 0 ; aNode_I < vertGrid->sizes[ otherAxisA ] ; aNode_I++ ) {
-		wallNodeIJK[ otherAxisA ] = aNode_I;
-		for ( bNode_I = 0 ; bNode_I < vertGrid->sizes[ otherAxisB ] ; bNode_I++ ) {
-			wallNodeIJK[ otherAxisB ] = bNode_I;
-
-			/* Convert to Local Index */
-			wallNode_lI = RegularMeshUtils_Node_3DTo1D( mesh, wallNodeIJK );
-
-			/* Check to see whether this wall node is on this processor */
-			if ( Mesh_GlobalToDomain( mesh, MT_VERTEX, wallNode_lI, &wallNode_lI ) && 
-			     wallNode_lI < Mesh_GetLocalSize( mesh, MT_VERTEX ) )
-			{
-				/* Record the current coord at this node */
-				currNodeCoord = Mesh_GetVertex( mesh, wallNode_lI );
-				newWallCoordsInRemeshAxis[sideWallNode_I] = currNodeCoord[remeshAxis];
-				/* Now add the velocity BC / solved velocity on this wall to see where it will move to */
-				FeVariable_GetValueAtNode( velocityField, wallNode_lI, velVector );
-				newWallCoordsInRemeshAxis[sideWallNode_I] += velVector[remeshAxis] * dt;
-				/* make sure that all the side wall stretches are the same if this is for a
-				 * parallelPipedHexa mesh */
-				/*
-				if ( ( True == atLeastOneLocalSideNodeProcessed ) &&
-					Stg_Class_IsInstance( mesh->layout->elementLayout, ParallelPipedHexaEL_Type ) )
-				{
-					double                     differenceBetweenCurrAndPrev = 0;
-					Stream*    errorStream = Journal_Register( Error_Type, (Name)self->type );
-					differenceBetweenCurrAndPrev = fabs( newWallCoordsInRemeshAxis[ sideWallNode_I ]
-						- lastCalculatedNewWallCoordInRemeshAxis  );
-
-					Journal_Firewall( differenceBetweenCurrAndPrev < tolerance,
-						errorStream,
-						"Error - in %s(): While calculating new coords to remesh to in axis %c for mesh "
-						"\"%s\" with element layout type %s, found side wall node %u (with IJK={%u,%u,%u}, "
-						"local index %u and coord={%.2f,%.2f,%.2f}) has "
-						"new coord in remeshAxis of %.2f (= coord %.2f + new vel %.2f in remesh "
-						"axis * dt=%.2f), but "
-						"already calculated side wall node %u (local index %u) has new wall coord in remesh "
-						"axis of %.2f. "
-						"This would cause irregular deformation, which is not supported for this "
-						"mesh type. Check your Boundary Condition specifications.\n",
-						__func__, IJKTopology_DimNumToDimLetter[remeshAxis], mesh->name,
-						ParallelPipedHexaEL_Type,
-						sideWallNode_I, wallNodeIJK[0], wallNodeIJK[1], wallNodeIJK[2],
-						wallNode_lI,
-						currNodeCoord[0], currNodeCoord[1], currNodeCoord[2],
-						newWallCoordsInRemeshAxis[sideWallNode_I], currNodeCoord[remeshAxis],
-						velVector[remeshAxis], dt,
-						lastCalculatedWallNode_sideI, lastCalculatedWallNode_lI,
-						lastCalculatedNewWallCoordInRemeshAxis );
-				}
-				*/
-				/* Copy values for comparison */
-				lastCalculatedWallNode_sideI = sideWallNode_I;
-				lastCalculatedWallNode_lI = wallNode_lI;
-				lastCalculatedNewWallCoordInRemeshAxis = newWallCoordsInRemeshAxis[sideWallNode_I];
-				atLeastOneLocalSideNodeProcessed = True;
-			}	
-			else {
-				if ( minOrMaxFlag == MIN_COORDS ) {
-					newWallCoordsInRemeshAxis[sideWallNode_I] = HUGE_VAL;
-				}	
-				else {
-					newWallCoordsInRemeshAxis[ sideWallNode_I ] = -HUGE_VAL;
-				}
-			}	
-			
-			/* Increment counter for side wall node index */
-			sideWallNode_I++;
-		}
-	}
-
-	if ( minOrMaxFlag == MIN_COORDS ) {
-		mpiOperation = MPI_MIN;
-	}	
-	else {
-		mpiOperation = MPI_MAX;
-	}	
-
-	/*comm = CommTopology_GetComm( Mesh_GetCommTopology( mesh, MT_VERTEX ) );*/
-	comm = Comm_GetMPIComm( Mesh_GetCommTopology( mesh, MT_VERTEX ) );
-	MPI_Allreduce( newWallCoordsInRemeshAxis, newWallCoordsInRemeshAxisGlobal, sideWallNodeCount,
-		       MPI_DOUBLE, mpiOperation, comm );
-
-	/* TODO : should really do another iteration over all the nodes, checking identical 	 */
-
-	Memory_Free( newWallCoordsInRemeshAxis );	
-}
-
-		
-/* This function will provide StGermain the abilty to instantiate (create) this codelet on demand. */
-void* _Underworld_MovingMesh_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof( MeshExtender );
-	Type                                                      type = Underworld_MovingMesh_Type;
-	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
-	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
-	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_MovingMesh_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Underworld_MovingMesh_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  );		
-}
-	
-/* This function is automatically run by StGermain when this plugin is loaded. The name must be "<plugin-name>_Register". */
-Index Underworld_MovingMesh_Register( PluginsManager* pluginsManager ) {
-	/* A plugin is only properly registered once it returns the handle provided when submitting a codelet to StGermain. */
-	return PluginsManager_Submit( pluginsManager, Underworld_MovingMesh_Type, (Name)"0", _Underworld_MovingMesh_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d plugins/MovingMesh/MovingMesh.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/MovingMesh/MovingMesh.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,563 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: MovingMesh.c 734 2008-05-15 23:15:29Z LukeHodkinson $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Underworld.h>
+
+#include "MovingMesh.h"
+#include <assert.h>
+
+
+/* Each component type needs a unique identifier (as a string for us to read and as an integer for realtime comparisions) */
+const Type Underworld_MovingMesh_Type = "Underworld_MovingMesh";
+
+void _Underworld_MovingMesh_AssignFromXML( void* meshExtender, Stg_ComponentFactory* cf, void* data ) {
+	UnderworldContext*  context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data );
+	MeshExtender*       self = (MeshExtender*) meshExtender;
+	Dimension_Index     dim_I = 0;
+	Dimension_Index     axisToRemeshOnTotal = 0;
+	
+	Journal_Firewall( 
+		(Bool )context, 
+		Journal_Register( Error_Type, (Name)Underworld_MovingMesh_Type  ), 
+		"No context found\n" );
+
+	self->context = (AbstractContext*)context;	
+	self->velocityField = context->velocityField;
+
+	Journal_Firewall( (Bool)self->velocityField, 
+			  Journal_Register( Error_Type, (Name)Underworld_MovingMesh_Type  ), 
+			  "The required velocity field component has not been created or placed on the context.\n");
+
+	self->remeshAccordingToAxis[I_AXIS] = 		
+		Dictionary_GetBool_WithDefault( context->dictionary, (Dictionary_Entry_Key)"remeshAccordingToIAxis", True  );
+	self->remeshAccordingToAxis[J_AXIS] = 		
+		Dictionary_GetBool_WithDefault( context->dictionary, (Dictionary_Entry_Key)"remeshAccordingToJAxis", True );
+	if ( self->velocityField->dim == 2  ) {
+		self->remeshAccordingToAxis[K_AXIS] = False;
+	}
+	else {
+		self->remeshAccordingToAxis[K_AXIS] = 		
+			Dictionary_GetBool_WithDefault( context->dictionary, (Dictionary_Entry_Key)"remeshAccordingToKAxis", True );
+	}
+
+	axisToRemeshOnTotal = 0;
+	for ( dim_I = 0; dim_I < self->velocityField->dim; dim_I++ ) {
+		if ( self->remeshAccordingToAxis[dim_I] == True  ) {
+			axisToRemeshOnTotal++;
+		}
+	}
+
+	Journal_Firewall( 
+		axisToRemeshOnTotal > 0,
+		Journal_Register( Error_Type, (Name)Underworld_MovingMesh_Type  ), 
+		"Error: in %s: you have disabled remeshing on all axis. Please set at least one axis to remesh on "
+		"using the remeshAccordingToIAxis, remeshAccordingToJAxis, remeshAccordingToKAxis dictionary "
+		"parameters, if you wish to use the remesher.\n",
+		__func__ );
+
+	/*  */ 
+	/* TODO: this timeIntegrator interface seems weird. Would have thought you'd pass a ptr to self. */
+	TimeIntegrator_PrependFinishEP( 
+			context->timeIntegrator, "Underworld_MovingMesh_Remesh", Underworld_MovingMesh_Remesh, 
+			CURR_MODULE_NAME, self );
+
+	/* Add to Live Stg_Component Register so it gets automatically built, initialised and deleted */
+	LiveComponentRegister_Add( context->CF->LCRegister, (Stg_Component*) self );
+}
+
+void Underworld_MovingMesh_Build( void* meshExtender, void* data ) {
+	MeshExtender*       self = (MeshExtender*)meshExtender;
+	Mesh*		    mesh;
+
+	mesh = (Mesh*)self->velocityField->feMesh;
+
+	Journal_Firewall( ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" ) != (unsigned )-1, 
+			  Journal_Register( Error_Type, (Name)Underworld_MovingMesh_Type  ), 
+			  "Error: in %s: provided Velocity field's mesh doesn't have a regular decomposition.\n",
+			  __func__ );
+}
+
+
+void Underworld_MovingMesh_Remesh( TimeIntegrator* timeIntegrator, MeshExtender* self ) {
+	FeVariable*           velocityField = self->velocityField;
+	Mesh*                 mesh          = (Mesh*) velocityField->feMesh;
+	unsigned	      rank;
+	Stream*               debug = Journal_Register( Debug_Type, (Name)Underworld_MovingMesh_Type  );
+	Stream*               info = Journal_Register( Info_Type, (Name)self->type  );
+	double                remeshTime, remeshTimeStart, remeshTimeEnd;
+	Dimension_Index       dim_I = 0;
+	Dimension_Index       axisToRemeshOnTotal = 0;
+	double                dt = 0.0;
+	MPI_Comm	      comm;
+	#if DEBUG
+	Index                 element_dI;
+	#endif
+
+	/*comm = CommTopology_GetComm( Mesh_GetCommTopology( mesh, MT_VERTEX ) );*/
+	comm = Comm_GetMPIComm( Mesh_GetCommTopology( mesh, MT_VERTEX ) );
+	MPI_Comm_rank( comm, (int*)&rank );
+
+	Journal_Printf( info, "%d: starting remeshing of mesh \"%s\":\n", rank, mesh->name );
+	axisToRemeshOnTotal = 0;
+	Journal_Printf( info, "Axis set to remesh on are : " );
+	for ( dim_I = 0; dim_I < velocityField->dim; dim_I++ ) {
+		if ( self->remeshAccordingToAxis[dim_I] == True ) {
+                  /* Journal_Printf( info, "%c, ", IJKTopology_DimNumToDimLetter[dim_I] );*/
+			axisToRemeshOnTotal++;
+		}
+	}
+	Journal_Printf( info, "\n" );
+	Journal_DPrintf( debug, "In %s(): about to remesh:\n", __func__ );
+	Stream_Indent( debug );
+
+	Journal_Firewall( 
+		axisToRemeshOnTotal > 0,
+		Journal_Register( Error_Type, (Name)Underworld_MovingMesh_Type  ), 
+		"Error: in %s: you have disabled remeshing on all axis. Please set at least one axis to remesh on "
+		"using the remeshAccordingToIAxis, remeshAccordingToJAxis, remeshAccordingToKAxis dictionary "
+		"parameters, if you wish to use the remesher.\n",
+		__func__ );
+
+	dt = AbstractContext_Dt( self->context );
+	/* TODO: the if statement is here since we seem to be using last timestep's dt to update. Is this correct?
+	 PatrickSunter - 5 June 2006 */
+	if ( self->context->timeStep > 1 ) {
+		Journal_Firewall( 
+			dt > 0.0,
+			Journal_Register( Error_Type, (Name)Underworld_MovingMesh_Type  ), 
+			"Error- in %s: in timeStep %u, provided Context \"%s\"'s dt <= 0.\n",
+			__func__, self->context->timeStep, self->context->name );
+	}	
+	
+	remeshTimeStart = MPI_Wtime();
+
+	Journal_Firewall( ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" ) != (unsigned )-1, 
+			  Journal_Register( Error_Type, (Name)Underworld_MovingMesh_Type  ), 
+			  "Error: in %s: provided Velocity field's mesh doesn't have a regular decomposition.\n",
+			  __func__ );
+
+	/*
+	Journal_Firewall( 
+		True == Stg_Class_IsInstance( velocityField->feMesh->layout->elementLayout, ParallelPipedHexaEL_Type ),
+		Journal_Register( Error_Type, (Name)Underworld_MovingMesh_Type  ), 
+		"Error: in %s: provided Velocity field's mesh doesn't have a %s elementLayout.\n",
+		__func__, ParallelPipedHexaEL_Type );
+	*/
+
+	Underworld_MovingMesh_RemeshAccordingToSidewalls( self, velocityField );
+	
+	Journal_DPrintf( debug, "remeshing complete.\n" );
+
+	/*
+	#if DEBUG
+	if ( Stream_IsEnable( debug ) && Stream_IsPrintableLevel( debug, 3 ) ) {
+		Journal_DPrintfL( debug, 3, "Updated node coords:\n" );
+		Stream_Indent( debug );
+		for ( element_dI = 0; element_dI < Mesh_GetDomainSize( velocityField->feMesh, MT_VERTEX ); element_dI++ ) {
+			Journal_DPrintfL( debug, 3, "In Element %3d: ", element_dI );
+			Mesh_PrintNodeCoordsOfElement( velocityField->feMesh, element_dI, debug );
+		}	
+		Stream_UnIndent( debug );
+	}	
+	#endif
+	*/
+
+	remeshTimeEnd = MPI_Wtime();
+	remeshTime = remeshTimeEnd - remeshTimeStart;
+	Journal_Printf( info, "%d: finished remeshing: took %f sec.\n", rank, remeshTime );
+
+	Stream_UnIndent( debug );
+
+	return;
+}
+
+
+void Underworld_MovingMesh_RemeshAccordingToSidewalls( MeshExtender* self, FeVariable* velocityField ) {
+	Mesh*                 mesh          = (Mesh*) velocityField->feMesh;
+	Dimension_Index       remeshAxis_I;
+	
+	for ( remeshAxis_I = 0 ; remeshAxis_I < velocityField->dim ; remeshAxis_I++ ) {
+		if ( self->remeshAccordingToAxis[remeshAxis_I] == True ) {
+			Underworld_MovingMesh_RemeshAccordingToSidewall_SingleAxis( self, velocityField, remeshAxis_I );
+		}	
+	}
+
+	/* Update mesh details. */
+	Mesh_DeformationUpdate( mesh );
+}
+
+
+void Underworld_MovingMesh_RemeshAccordingToSidewall_SingleAxis(
+		MeshExtender*    self,
+		FeVariable*      velocityField,
+		Dimension_Index  remeshAxis )
+{
+	Mesh*                      mesh          = (Mesh*) velocityField->feMesh;
+	double			   maxCrd[3], minCrd[3];
+	Grid*			   vertGrid;
+	/* Assume IJK Topology */
+	double*                    minGlobal;
+	double*                    maxGlobal;
+	Node_Index                 sideWallNodeCount;
+	Dimension_Index            otherAxisA = (remeshAxis + 1) % 3;
+	Dimension_Index            otherAxisB = (remeshAxis + 2) % 3;
+	IJK                        nodeIJK;
+	Node_Index                 sideWallNode_I;
+	Node_Index                 aNode_I;
+	Node_Index                 bNode_I;
+	Node_Index                 remeshAxisNode_I;
+	Node_GlobalIndex           nodeGlobal_I;
+	Node_DomainIndex           nodeDomain_I;
+	double                     newElementWidthInRemeshAxis;
+	double                     minGlobalCoord =  HUGE_VAL;
+	double                     maxGlobalCoord = -HUGE_VAL;
+	/*Bool                       nodeG2DBuiltTemporarily = False;*/
+	double                     newCoordInRemeshAxis = 0;
+	double                     tolerance;
+
+	Stream* debug = Journal_Register( Debug_Type, (Name)Underworld_MovingMesh_Type  );
+
+	/*Journal_DPrintf( debug, "In %s(): for remeshAxis %c\n", __func__, IJKTopology_DimNumToDimLetter[remeshAxis] );*/
+	Stream_Indent( debug );	
+
+	Mesh_GetGlobalCoordRange( mesh, minCrd, maxCrd );
+	tolerance = (maxCrd[remeshAxis] - minCrd[remeshAxis]) * 1e-9;
+
+	vertGrid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+						  ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
+
+	sideWallNodeCount = vertGrid->sizes[ otherAxisA ] * vertGrid->sizes[ otherAxisB ];
+	minGlobal = Memory_Alloc_Array( double, sideWallNodeCount, "min node coords" );
+	maxGlobal = Memory_Alloc_Array( double, sideWallNodeCount, "max node coords" );
+
+	/* As long as memory not too tight, create temporary tables to massively speed up
+	   necessary global to local calculations. */
+	/*
+	if ( (mesh->buildTemporaryGlobalTables == True) && (mesh->nodeG2D == 0) ) {
+		mesh->nodeG2D = MeshDecomp_BuildNodeGlobalToDomainMap( meshDecomp );
+		nodeG2DBuiltTemporarily = True;
+	}
+	*/
+	
+	/* calc min and max wall new coords given velocity field */
+	Underworld_MovingMesh_CalculateMinOrMaxCoordsOnSidewall(
+		self, velocityField, remeshAxis, MIN_COORDS, minGlobal );
+	Underworld_MovingMesh_CalculateMinOrMaxCoordsOnSidewall(
+		self, velocityField, remeshAxis, MAX_COORDS, maxGlobal );
+
+	/* calc overall min and max wall new coords */
+	for ( sideWallNode_I = 0; sideWallNode_I < sideWallNodeCount; sideWallNode_I++ ) {
+		if ( minGlobal[ sideWallNode_I ] < minGlobalCoord )
+			minGlobalCoord = minGlobal[ sideWallNode_I ];
+		if ( maxGlobal[ sideWallNode_I ] > maxGlobalCoord )
+			maxGlobalCoord = maxGlobal[ sideWallNode_I ];
+	}	
+
+	if ( ( fabs( minGlobalCoord - minCrd[ remeshAxis ] ) < tolerance ) &&
+		( fabs( maxGlobalCoord - maxCrd[ remeshAxis ] ) < tolerance ) )
+	{
+          /*Journal_DPrintfL( debug, 1, "Found no extension/compression in remeshAxis %c: thus not "
+            "updating node coords.\n", IJKTopology_DimNumToDimLetter[remeshAxis] );*/
+		Memory_Free( minGlobal );
+		Memory_Free( maxGlobal );
+		/*
+		if ( nodeG2DBuiltTemporarily ) {
+			Memory_Free( mesh->nodeG2D );
+			mesh->nodeG2D = NULL;
+		}
+		*/
+		Stream_UnIndent( debug );	
+		return;
+	}
+
+	/* Change Geometry */
+	/*
+	Journal_DPrintfL( debug, 3, "Updating mesh's BlockGeometry \"%s\" with new global "
+		"min and max in remesh axis %c: min=%.3f, max=%.3f\n",
+		geometry->name, IJKTopology_DimNumToDimLetter[remeshAxis], minGlobalCoord, maxGlobalCoord );
+
+	minCrd[ remeshAxis ] = minGlobalCoord;
+	maxCrd[ remeshAxis ] = maxGlobalCoord;
+	*/
+
+	/*Journal_DPrintfL( debug, 2, "Looping over all nodes, updating coordinates in remeshAxis %c based on "
+          "stretch/compression on the relevant side walls.\n", IJKTopology_DimNumToDimLetter[remeshAxis] );*/
+	Stream_Indent( debug );	
+	sideWallNode_I = 0;
+	for ( aNode_I = 0 ; aNode_I < vertGrid->sizes[ otherAxisA ] ; aNode_I++ ) {
+		nodeIJK[ otherAxisA ] = aNode_I;
+		for ( bNode_I = 0 ; bNode_I < vertGrid->sizes[ otherAxisB ] ; bNode_I++ ) {
+			nodeIJK[ otherAxisB ] = bNode_I;
+
+			newElementWidthInRemeshAxis = (maxGlobal[ sideWallNode_I ] - minGlobal[ sideWallNode_I ])
+				/ ( (double)vertGrid->sizes[ remeshAxis ] - 1.0 );
+
+			/*Journal_DPrintfL( debug, 3, "For slice with aNode_I=%u in otherAxisA=%c and bNode_I=%u in "
+				"otherAxisB=%c: calculated new element width in remesh axis= %.3f\n",
+				aNode_I, IJKTopology_DimNumToDimLetter[otherAxisA],
+				bNode_I, IJKTopology_DimNumToDimLetter[otherAxisB],
+				newElementWidthInRemeshAxis );*/
+			Stream_Indent( debug );	
+
+			for ( remeshAxisNode_I = 0 ; remeshAxisNode_I < vertGrid->sizes[ remeshAxis ] ; remeshAxisNode_I++ ) {
+				nodeIJK[ remeshAxis ] = remeshAxisNode_I;
+
+				/* Find this local coord */
+				nodeGlobal_I = Grid_Project( vertGrid, nodeIJK );
+
+				/* Adjust position if this node is on my processor */
+				if ( Mesh_GlobalToDomain( mesh, MT_VERTEX, nodeGlobal_I, &nodeDomain_I ) && 
+				     nodeDomain_I < Mesh_GetDomainSize( mesh, MT_VERTEX ) )
+				{
+					newCoordInRemeshAxis = minGlobal[ sideWallNode_I ] +
+						newElementWidthInRemeshAxis * (double) remeshAxisNode_I;
+					Journal_DPrintfL( debug, 3, "updating node coord[%u] at IJK(%u,%u,%u) (domain "
+						"node I %u) from %.3f to %.3f\n", remeshAxis, nodeIJK[0], nodeIJK[1], nodeIJK[2],
+						nodeDomain_I, Mesh_GetVertex( mesh, nodeDomain_I )[ remeshAxis ],
+						newCoordInRemeshAxis );
+					Mesh_GetVertex( mesh, nodeDomain_I )[ remeshAxis ] = newCoordInRemeshAxis;
+				}		
+			}
+			Stream_UnIndent( debug );	
+
+			/* Increment counter for side wall node index */
+			sideWallNode_I++;
+		}
+	}
+	Stream_UnIndent( debug );	
+
+	/*
+	if ( nodeG2DBuiltTemporarily ) {
+		Memory_Free( mesh->nodeG2D );
+		mesh->nodeG2D = NULL;
+	}
+	*/
+
+	/* Update the element layout's partition info based on geometry changes... */
+	/*
+	ParallelPipedHexaEL_UpdateGeometryPartitionInfo( mesh->layout->elementLayout, mesh->layout->decomp );
+	*/
+
+	/* Update mesh information. */
+	Mesh_Sync( mesh );
+	Mesh_DeformationUpdate( mesh );
+
+	Memory_Free( minGlobal );
+	Memory_Free( maxGlobal );
+	Stream_UnIndent( debug );	
+}
+
+
+void Underworld_MovingMesh_CalculateMinOrMaxCoordsOnSidewall(
+		MeshExtender*    self,
+		FeVariable*      velocityField,
+		Dimension_Index  remeshAxis,
+		MinOrMaxFlag     minOrMaxFlag,
+		double*          newWallCoordsInRemeshAxisGlobal )
+{
+	Mesh*                      mesh          = (Mesh*) velocityField->feMesh;
+	Grid*			   vertGrid;
+	double			   maxCrd[3], minCrd[3];
+	IJK                        wallNodeIJK;
+	Node_Index                 sideWallNode_I;
+	Node_LocalIndex            wallNode_lI;
+	Node_Index                 aNode_I;
+	Node_Index                 bNode_I;
+	Node_Index                 sideWallNodeCount;
+	Dimension_Index            otherAxisA = (remeshAxis + 1) % 3;
+	Dimension_Index            otherAxisB = (remeshAxis + 2) % 3;
+	MPI_Op                     mpiOperation;
+	double*                    newWallCoordsInRemeshAxis = NULL;
+	Node_LocalIndex            lastCalculatedWallNode_lI = 0;
+	Node_Index                 lastCalculatedWallNode_sideI = 0;
+	double                     lastCalculatedNewWallCoordInRemeshAxis;
+	double*                    currNodeCoord;
+	double                     velVector[3];
+	/* Somewhat arbitrary tolerance to check that extension of the mesh is not irregular in the current axis */
+	double                     tolerance;
+	double                     dt = AbstractContext_Dt( self->context );
+	Bool                       atLeastOneLocalSideNodeProcessed = False;
+	MPI_Comm		   comm;
+
+	Mesh_GetGlobalCoordRange( mesh, minCrd, maxCrd );
+	tolerance = (maxCrd[remeshAxis] - minCrd[remeshAxis]) * 1e-9;
+
+	vertGrid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+						  ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
+
+	sideWallNodeCount = vertGrid->sizes[ otherAxisA ] * vertGrid->sizes[ otherAxisB ];
+	newWallCoordsInRemeshAxis = Memory_Alloc_Array( double, sideWallNodeCount, "newWallCoordsInRemeshAxis" );
+
+	if ( minOrMaxFlag == MIN_COORDS ) {
+		/* Loop over all nodes on the minimum side wall */
+		wallNodeIJK[ remeshAxis ] = 0;
+	}
+	else {
+		/* Loop over all nodes on the maximum side wall */
+		wallNodeIJK[ remeshAxis ] = vertGrid->sizes[ remeshAxis ] - 1 ;
+	}
+
+	sideWallNode_I = 0;
+	for ( aNode_I = 0 ; aNode_I < vertGrid->sizes[ otherAxisA ] ; aNode_I++ ) {
+		wallNodeIJK[ otherAxisA ] = aNode_I;
+		for ( bNode_I = 0 ; bNode_I < vertGrid->sizes[ otherAxisB ] ; bNode_I++ ) {
+			wallNodeIJK[ otherAxisB ] = bNode_I;
+
+			/* Convert to Local Index */
+			wallNode_lI = RegularMeshUtils_Node_3DTo1D( mesh, wallNodeIJK );
+
+			/* Check to see whether this wall node is on this processor */
+			if ( Mesh_GlobalToDomain( mesh, MT_VERTEX, wallNode_lI, &wallNode_lI ) && 
+			     wallNode_lI < Mesh_GetLocalSize( mesh, MT_VERTEX ) )
+			{
+				/* Record the current coord at this node */
+				currNodeCoord = Mesh_GetVertex( mesh, wallNode_lI );
+				newWallCoordsInRemeshAxis[sideWallNode_I] = currNodeCoord[remeshAxis];
+				/* Now add the velocity BC / solved velocity on this wall to see where it will move to */
+				FeVariable_GetValueAtNode( velocityField, wallNode_lI, velVector );
+				newWallCoordsInRemeshAxis[sideWallNode_I] += velVector[remeshAxis] * dt;
+				/* make sure that all the side wall stretches are the same if this is for a
+				 * parallelPipedHexa mesh */
+				/*
+				if ( ( True == atLeastOneLocalSideNodeProcessed ) &&
+					Stg_Class_IsInstance( mesh->layout->elementLayout, ParallelPipedHexaEL_Type ) )
+				{
+					double                     differenceBetweenCurrAndPrev = 0;
+					Stream*    errorStream = Journal_Register( Error_Type, (Name)self->type );
+					differenceBetweenCurrAndPrev = fabs( newWallCoordsInRemeshAxis[ sideWallNode_I ]
+						- lastCalculatedNewWallCoordInRemeshAxis  );
+
+					Journal_Firewall( differenceBetweenCurrAndPrev < tolerance,
+						errorStream,
+						"Error - in %s(): While calculating new coords to remesh to in axis %c for mesh "
+						"\"%s\" with element layout type %s, found side wall node %u (with IJK={%u,%u,%u}, "
+						"local index %u and coord={%.2f,%.2f,%.2f}) has "
+						"new coord in remeshAxis of %.2f (= coord %.2f + new vel %.2f in remesh "
+						"axis * dt=%.2f), but "
+						"already calculated side wall node %u (local index %u) has new wall coord in remesh "
+						"axis of %.2f. "
+						"This would cause irregular deformation, which is not supported for this "
+						"mesh type. Check your Boundary Condition specifications.\n",
+						__func__, IJKTopology_DimNumToDimLetter[remeshAxis], mesh->name,
+						ParallelPipedHexaEL_Type,
+						sideWallNode_I, wallNodeIJK[0], wallNodeIJK[1], wallNodeIJK[2],
+						wallNode_lI,
+						currNodeCoord[0], currNodeCoord[1], currNodeCoord[2],
+						newWallCoordsInRemeshAxis[sideWallNode_I], currNodeCoord[remeshAxis],
+						velVector[remeshAxis], dt,
+						lastCalculatedWallNode_sideI, lastCalculatedWallNode_lI,
+						lastCalculatedNewWallCoordInRemeshAxis );
+				}
+				*/
+				/* Copy values for comparison */
+				lastCalculatedWallNode_sideI = sideWallNode_I;
+				lastCalculatedWallNode_lI = wallNode_lI;
+				lastCalculatedNewWallCoordInRemeshAxis = newWallCoordsInRemeshAxis[sideWallNode_I];
+				atLeastOneLocalSideNodeProcessed = True;
+			}	
+			else {
+				if ( minOrMaxFlag == MIN_COORDS ) {
+					newWallCoordsInRemeshAxis[sideWallNode_I] = HUGE_VAL;
+				}	
+				else {
+					newWallCoordsInRemeshAxis[ sideWallNode_I ] = -HUGE_VAL;
+				}
+			}	
+			
+			/* Increment counter for side wall node index */
+			sideWallNode_I++;
+		}
+	}
+
+	if ( minOrMaxFlag == MIN_COORDS ) {
+		mpiOperation = MPI_MIN;
+	}	
+	else {
+		mpiOperation = MPI_MAX;
+	}	
+
+	/*comm = CommTopology_GetComm( Mesh_GetCommTopology( mesh, MT_VERTEX ) );*/
+	comm = Comm_GetMPIComm( Mesh_GetCommTopology( mesh, MT_VERTEX ) );
+	MPI_Allreduce( newWallCoordsInRemeshAxis, newWallCoordsInRemeshAxisGlobal, sideWallNodeCount,
+		       MPI_DOUBLE, mpiOperation, comm );
+
+	/* TODO : should really do another iteration over all the nodes, checking identical 	 */
+
+	Memory_Free( newWallCoordsInRemeshAxis );	
+}
+
+		
+/* This function will provide StGermain the abilty to instantiate (create) this codelet on demand. */
+void* _Underworld_MovingMesh_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof( MeshExtender );
+	Type                                                      type = Underworld_MovingMesh_Type;
+	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
+	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
+	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_MovingMesh_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Underworld_MovingMesh_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  );		
+}
+	
+/* This function is automatically run by StGermain when this plugin is loaded. The name must be "<plugin-name>_Register". */
+Index Underworld_MovingMesh_Register( PluginsManager* pluginsManager ) {
+	/* A plugin is only properly registered once it returns the handle provided when submitting a codelet to StGermain. */
+	return PluginsManager_Submit( pluginsManager, Underworld_MovingMesh_Type, (Name)"0", _Underworld_MovingMesh_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d plugins/MovingMesh/tests/plugins/testMovingMesh.c
--- a/plugins/MovingMesh/tests/plugins/testMovingMesh.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,208 +0,0 @@
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Underworld.h>
-
-#include <math.h>
-#include <string.h>
-#include <assert.h>
-
-ExtensionInfo_Index handle;
-
-double dt( void* class, PICelleratorContext* context ) {
-	return Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"dt", 0.01  );
-}
-
-void MovingMeshTestVelBCs_IncreasingWithY( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
-	DomainContext*	context            = (DomainContext*)_context;
-	FeVariable*             feVariable         = NULL;
-	FeMesh*     		mesh               = NULL;
-	double*                 result             = (double*) _result;
-	double			min[3], max[3];
-	double*                 coord;
-	
-	feVariable = (FeVariable*)FieldVariable_Register_GetByName( context->fieldVariable_Register, "VelocityField" );
-	mesh       = feVariable->feMesh;
-
-	/* Find coordinate of node */
-	Mesh_GetGlobalCoordRange( mesh, min, max );
-	coord = Mesh_GetVertex( mesh, node_lI );
-	
-	*result = ( coord[J_AXIS] - min[J_AXIS] ) / ( max[J_AXIS] - min[J_AXIS] );
-}
-
-
-void MovingMeshTestVelBCs_ToCentreY( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
-	DomainContext*	context            = (DomainContext*)_context;
-	FeVariable*             feVariable         = NULL;
-	FeMesh* 		mesh               = NULL;
-	double*                 result             = (double*) _result;
-	double*                 coord;
-	double                  toCentreJ_Max = 0;
-	double                  boxHeight = 0;
-	double                  centreInJ = 0;
-	double                  coordJ_RelativeToCentreJ = 0;
-	double			min[3], max[3];
-	
-	feVariable = (FeVariable*)FieldVariable_Register_GetByName( context->fieldVariable_Register, "VelocityField" );
-	mesh       = feVariable->feMesh;
-
-	/* Find coordinate of node */
-	Mesh_GetGlobalCoordRange( mesh, min, max );
-	coord = Mesh_GetVertex( mesh, node_lI );
-	
-	boxHeight = max[J_AXIS] - min[J_AXIS];
-	centreInJ = ( max[J_AXIS] + min[J_AXIS] ) / 2;
-	coordJ_RelativeToCentreJ = coord[J_AXIS] - centreInJ;
-
-	toCentreJ_Max  = Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"toCentreJ_Max", 1.0 );
-	/* Need the -1 factor to "flip" so both above and below coords go towards the centre */
-	*result = (-1) * coordJ_RelativeToCentreJ / (boxHeight / 2) * toCentreJ_Max;
-}
-
-
-void construct( PICelleratorContext* context ) {
-	MaterialPointsSwarm* materialSwarm;
-
-	/* Add original pos to particle */
-	materialSwarm = (MaterialPointsSwarm* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialSwarm"  );
-	handle = ExtensionManager_Add( materialSwarm->particleExtensionMgr, (Name)CURR_MODULE_NAME, sizeof( Coord )  );
-
-	ConditionFunction_Register_Add( context->condFunc_Register,
-		ConditionFunction_New( MovingMeshTestVelBCs_IncreasingWithY, (Name)"MovingMeshTestVelBCs_IncreasingWithY" )  );
-	ConditionFunction_Register_Add( context->condFunc_Register,
-		ConditionFunction_New( MovingMeshTestVelBCs_ToCentreY, (Name)"MovingMeshTestVelBCs_ToCentreY" ) );
-
-	/* Need to do this so we can test the remesher handles incorrect BCs properly */	
-	stJournal->firewallProducesAssert = False; 
-}
-
-void storeOriginalPos( PICelleratorContext* context ) {
-	MaterialPointsSwarm*   materialSwarm;
-	GlobalParticle*   particle;
-	double*           originalCoord;
-	Particle_Index    lParticle_I;
-
-	materialSwarm = (MaterialPointsSwarm* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialSwarm" );
-
-	for ( lParticle_I = 0 ; lParticle_I < materialSwarm->particleLocalCount ; lParticle_I++ ) {
-		particle = (GlobalParticle* ) Swarm_ParticleAt( materialSwarm, lParticle_I );
-		originalCoord = ExtensionManager_Get( materialSwarm->particleExtensionMgr, particle, handle );
-
-		memcpy( originalCoord, particle->coord, sizeof(Coord) );
-	}
-}
-
-void check( PICelleratorContext* context ) {
-	MaterialPointsSwarm*   materialSwarm;
-	GlobalParticle*   particle;
-	double*           originalCoord;
-	double*           coord;
-	Particle_Index    lParticle_I;
-	double            maxError             = 0.0;
-	double            errorGlobal;
-	double            currLeft;
-	double            currRight;
-	double            startLeft;
-	double            startRight;
-	double            velocityLeft;
-	double            velocityRight;
-	double            analyticCoord;
-	/* Since this test is occuring _after_ time integration using the latest dt, have to add dt on to the
-		total time up to the start of this timestep */
-	double            time                 = context->currentTime + context->dt;
-	Dictionary*       dictionary           = context->dictionary;
-	Stream*           stream               = Journal_Register( Info_Type, (Name)CURR_MODULE_NAME  );
-	double            tolerance;
-	Dimension_Index   dim;
-
-	/* BIG HACK - SHOULD DO PROPERLEY */
-	startLeft  = Dictionary_GetDouble( dictionary, "minX" );
-	startRight = Dictionary_GetDouble( dictionary, "maxX" );
-	velocityLeft  = -0.5;
-	velocityRight = +0.5;
-	dim = 2;
-	
-	/* Add original pos to particle */
-	materialSwarm = (MaterialPointsSwarm*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialSwarm"  );
-
-	tolerance = Dictionary_GetDouble_WithDefault( dictionary, (Dictionary_Entry_Key)"tolerance", 1.0e-6  );
-
-	Journal_Printf( stream, "Timestep = %u: ", context->timeStep );
-
-	for ( lParticle_I = 0 ; lParticle_I < materialSwarm->particleLocalCount ; lParticle_I++ ) {
-		particle      = (GlobalParticle*)Swarm_ParticleAt( materialSwarm, lParticle_I );
-
-		coord         = particle->coord;
-		originalCoord = ExtensionManager_Get( materialSwarm->particleExtensionMgr, particle, handle );
-
-		currLeft  = startLeft + velocityLeft * time;
-		currRight = startRight + velocityRight * time;
-
-		analyticCoord = 
-			currLeft + ( originalCoord[ I_AXIS ] - startLeft ) * ( currRight - currLeft ) / ( startRight - startLeft );
-
-		maxError = MAX( maxError, fabs( analyticCoord - coord[ I_AXIS ] ) );
-
-		Journal_Firewall( maxError < tolerance, stream, 
-			"Failed - for local particle %u, orig coord was (%.3f,%.3f,%.3f), thus given "
-			"startLeft of %.3f, startRight of %.3f, velocityLeft of %.3f, velocityRight of "
-			"%.3f, and currTime of %.2f (calc. currLeft is %.3f and currRight is %.3f):\n"
-			"\tanalytic coord in I axis is %.3f, but actual coord in I is %.3f.\n",
-			lParticle_I, originalCoord[0], originalCoord[1], originalCoord[2],
-			startLeft, startRight, velocityLeft, velocityRight, time, currLeft, currRight,
-			analyticCoord, coord[I_AXIS] );
-
-		if ( maxError > 0.45 )
-			abort();
-	}
-
-	MPI_Allreduce( &maxError,  &errorGlobal,  1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );
-
-	if ( errorGlobal < tolerance )
-		Journal_Printf( stream, "Passed\n" );
-	else 
-		Journal_Printf( stream, "Failed - Error = %g - Tolerance = %g\n", errorGlobal, tolerance );
-}
-
-const Type testMovingMesh_Type = "testMovingMesh";
-typedef struct {
-	__Codelet
-} testMovingMesh;
-
-void _testMovingMesh_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
-	DomainContext* context;
-	Stream*                stream               = Journal_Register( Info_Type, (Name)CURR_MODULE_NAME  );
-
-	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", DomainContext, True, data  ); 
-
-	ContextEP_Append( context, AbstractContext_EP_AssignFromXMLExtensions, construct );
-	ContextEP_Append( context, AbstractContext_EP_Initialise, storeOriginalPos );
-	ContextEP_Prepend( context, AbstractContext_EP_Step, check );
-	EP_AppendClassHook( Context_GetEntryPoint( context, FiniteElementContext_EP_CalcDt ), dt, context );
-
-	Stream_RedirectFile_WithPrependedPath( stream, context->outputPath, "output.dat" );
-	Stream_SetPrintingRank( stream, 0 );
-	
-}
-
-void* _testMovingMesh_DefaultNew( Name name ) {
-	return Codelet_New(
-			testMovingMesh_Type,
-			_testMovingMesh_DefaultNew,
-			_testMovingMesh_AssignFromXML,
-			_Codelet_Build,
-			_Codelet_Initialise,
-			_Codelet_Execute,
-			_Codelet_Destroy,
-			name );
-}
-
-Index testMovingMesh_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, testMovingMesh_Type, (Name)"0", _testMovingMesh_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d plugins/MovingMesh/tests/plugins/testMovingMesh.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/MovingMesh/tests/plugins/testMovingMesh.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,208 @@
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Underworld.h>
+
+#include <math.h>
+#include <string.h>
+#include <assert.h>
+
+ExtensionInfo_Index handle;
+
+double dt( void* class, PICelleratorContext* context ) {
+	return Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"dt", 0.01  );
+}
+
+void MovingMeshTestVelBCs_IncreasingWithY( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
+	DomainContext*	context            = (DomainContext*)_context;
+	FeVariable*             feVariable         = NULL;
+	FeMesh*     		mesh               = NULL;
+	double*                 result             = (double*) _result;
+	double			min[3], max[3];
+	double*                 coord;
+	
+	feVariable = (FeVariable*)FieldVariable_Register_GetByName( context->fieldVariable_Register, "VelocityField" );
+	mesh       = feVariable->feMesh;
+
+	/* Find coordinate of node */
+	Mesh_GetGlobalCoordRange( mesh, min, max );
+	coord = Mesh_GetVertex( mesh, node_lI );
+	
+	*result = ( coord[J_AXIS] - min[J_AXIS] ) / ( max[J_AXIS] - min[J_AXIS] );
+}
+
+
+void MovingMeshTestVelBCs_ToCentreY( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
+	DomainContext*	context            = (DomainContext*)_context;
+	FeVariable*             feVariable         = NULL;
+	FeMesh* 		mesh               = NULL;
+	double*                 result             = (double*) _result;
+	double*                 coord;
+	double                  toCentreJ_Max = 0;
+	double                  boxHeight = 0;
+	double                  centreInJ = 0;
+	double                  coordJ_RelativeToCentreJ = 0;
+	double			min[3], max[3];
+	
+	feVariable = (FeVariable*)FieldVariable_Register_GetByName( context->fieldVariable_Register, "VelocityField" );
+	mesh       = feVariable->feMesh;
+
+	/* Find coordinate of node */
+	Mesh_GetGlobalCoordRange( mesh, min, max );
+	coord = Mesh_GetVertex( mesh, node_lI );
+	
+	boxHeight = max[J_AXIS] - min[J_AXIS];
+	centreInJ = ( max[J_AXIS] + min[J_AXIS] ) / 2;
+	coordJ_RelativeToCentreJ = coord[J_AXIS] - centreInJ;
+
+	toCentreJ_Max  = Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"toCentreJ_Max", 1.0 );
+	/* Need the -1 factor to "flip" so both above and below coords go towards the centre */
+	*result = (-1) * coordJ_RelativeToCentreJ / (boxHeight / 2) * toCentreJ_Max;
+}
+
+
+void construct( PICelleratorContext* context ) {
+	MaterialPointsSwarm* materialSwarm;
+
+	/* Add original pos to particle */
+	materialSwarm = (MaterialPointsSwarm* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialSwarm"  );
+	handle = ExtensionManager_Add( materialSwarm->particleExtensionMgr, (Name)CURR_MODULE_NAME, sizeof( Coord )  );
+
+	ConditionFunction_Register_Add( context->condFunc_Register,
+		ConditionFunction_New( MovingMeshTestVelBCs_IncreasingWithY, (Name)"MovingMeshTestVelBCs_IncreasingWithY" )  );
+	ConditionFunction_Register_Add( context->condFunc_Register,
+		ConditionFunction_New( MovingMeshTestVelBCs_ToCentreY, (Name)"MovingMeshTestVelBCs_ToCentreY" ) );
+
+	/* Need to do this so we can test the remesher handles incorrect BCs properly */	
+	stJournal->firewallProducesAssert = False; 
+}
+
+void storeOriginalPos( PICelleratorContext* context ) {
+	MaterialPointsSwarm*   materialSwarm;
+	GlobalParticle*   particle;
+	double*           originalCoord;
+	Particle_Index    lParticle_I;
+
+	materialSwarm = (MaterialPointsSwarm* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialSwarm" );
+
+	for ( lParticle_I = 0 ; lParticle_I < materialSwarm->particleLocalCount ; lParticle_I++ ) {
+		particle = (GlobalParticle* ) Swarm_ParticleAt( materialSwarm, lParticle_I );
+		originalCoord = ExtensionManager_Get( materialSwarm->particleExtensionMgr, particle, handle );
+
+		memcpy( originalCoord, particle->coord, sizeof(Coord) );
+	}
+}
+
+void check( PICelleratorContext* context ) {
+	MaterialPointsSwarm*   materialSwarm;
+	GlobalParticle*   particle;
+	double*           originalCoord;
+	double*           coord;
+	Particle_Index    lParticle_I;
+	double            maxError             = 0.0;
+	double            errorGlobal;
+	double            currLeft;
+	double            currRight;
+	double            startLeft;
+	double            startRight;
+	double            velocityLeft;
+	double            velocityRight;
+	double            analyticCoord;
+	/* Since this test is occuring _after_ time integration using the latest dt, have to add dt on to the
+		total time up to the start of this timestep */
+	double            time                 = context->currentTime + context->dt;
+	Dictionary*       dictionary           = context->dictionary;
+	Stream*           stream               = Journal_Register( Info_Type, (Name)CURR_MODULE_NAME  );
+	double            tolerance;
+	Dimension_Index   dim;
+
+	/* BIG HACK - SHOULD DO PROPERLEY */
+	startLeft  = Dictionary_GetDouble( dictionary, "minX" );
+	startRight = Dictionary_GetDouble( dictionary, "maxX" );
+	velocityLeft  = -0.5;
+	velocityRight = +0.5;
+	dim = 2;
+	
+	/* Add original pos to particle */
+	materialSwarm = (MaterialPointsSwarm*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialSwarm"  );
+
+	tolerance = Dictionary_GetDouble_WithDefault( dictionary, (Dictionary_Entry_Key)"tolerance", 1.0e-6  );
+
+	Journal_Printf( stream, "Timestep = %u: ", context->timeStep );
+
+	for ( lParticle_I = 0 ; lParticle_I < materialSwarm->particleLocalCount ; lParticle_I++ ) {
+		particle      = (GlobalParticle*)Swarm_ParticleAt( materialSwarm, lParticle_I );
+
+		coord         = particle->coord;
+		originalCoord = ExtensionManager_Get( materialSwarm->particleExtensionMgr, particle, handle );
+
+		currLeft  = startLeft + velocityLeft * time;
+		currRight = startRight + velocityRight * time;
+
+		analyticCoord = 
+			currLeft + ( originalCoord[ I_AXIS ] - startLeft ) * ( currRight - currLeft ) / ( startRight - startLeft );
+
+		maxError = MAX( maxError, fabs( analyticCoord - coord[ I_AXIS ] ) );
+
+		Journal_Firewall( maxError < tolerance, stream, 
+			"Failed - for local particle %u, orig coord was (%.3f,%.3f,%.3f), thus given "
+			"startLeft of %.3f, startRight of %.3f, velocityLeft of %.3f, velocityRight of "
+			"%.3f, and currTime of %.2f (calc. currLeft is %.3f and currRight is %.3f):\n"
+			"\tanalytic coord in I axis is %.3f, but actual coord in I is %.3f.\n",
+			lParticle_I, originalCoord[0], originalCoord[1], originalCoord[2],
+			startLeft, startRight, velocityLeft, velocityRight, time, currLeft, currRight,
+			analyticCoord, coord[I_AXIS] );
+
+		if ( maxError > 0.45 )
+			abort();
+	}
+
+	MPI_Allreduce( &maxError,  &errorGlobal,  1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );
+
+	if ( errorGlobal < tolerance )
+		Journal_Printf( stream, "Passed\n" );
+	else 
+		Journal_Printf( stream, "Failed - Error = %g - Tolerance = %g\n", errorGlobal, tolerance );
+}
+
+const Type testMovingMesh_Type = "testMovingMesh";
+typedef struct {
+	__Codelet
+} testMovingMesh;
+
+void _testMovingMesh_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
+	DomainContext* context;
+	Stream*                stream               = Journal_Register( Info_Type, (Name)CURR_MODULE_NAME  );
+
+	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", DomainContext, True, data  ); 
+
+	ContextEP_Append( context, AbstractContext_EP_AssignFromXMLExtensions, construct );
+	ContextEP_Append( context, AbstractContext_EP_Initialise, storeOriginalPos );
+	ContextEP_Prepend( context, AbstractContext_EP_Step, check );
+	EP_AppendClassHook( Context_GetEntryPoint( context, FiniteElementContext_EP_CalcDt ), dt, context );
+
+	Stream_RedirectFile_WithPrependedPath( stream, context->outputPath, "output.dat" );
+	Stream_SetPrintingRank( stream, 0 );
+	
+}
+
+void* _testMovingMesh_DefaultNew( Name name ) {
+	return Codelet_New(
+			testMovingMesh_Type,
+			_testMovingMesh_DefaultNew,
+			_testMovingMesh_AssignFromXML,
+			_Codelet_Build,
+			_Codelet_Initialise,
+			_Codelet_Execute,
+			_Codelet_Destroy,
+			name );
+}
+
+Index testMovingMesh_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, testMovingMesh_Type, (Name)"0", _testMovingMesh_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d plugins/Multigrid/Multigrid.c
--- a/plugins/Multigrid/Multigrid.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,147 +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: Multigrid.c 2192 2004-10-15 02:45:38Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <mpi.h>
-#include <petsc.h>
-#include <petscvec.h>
-#include <petscmat.h>
-#include <petscksp.h>
-#include <petscsnes.h>
-
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Underworld.h>
-
-#include "Multigrid.h"
-
-
-const Type Underworld_Multigrid_Type = "Underworld_Multigrid";
-Underworld_Multigrid* Underworld_Multigrid_selfPointer = NULL;
-
-
-void Underworld_Multigrid_SolverSetup( void* _solver, void* _stokesSLE ) {
-    Underworld_Multigrid* self = Underworld_Multigrid_selfPointer;
-	Stokes_SLE_UzawaSolver* solver = (Stokes_SLE_UzawaSolver*)_solver;
-	Stokes_SLE* sle = (Stokes_SLE*)_stokesSLE;
-	
- 	Journal_DPrintf( solver->debug, "In %s:\n", __func__ );
-	Stream_IndentBranch( StgFEM_Debug );
-
-	Journal_DPrintfL( solver->debug, 1, "Setting up MatrixSolver for the velocity eqn.\n" );
-   self->mgSolver->mgData->matrixChanged = True;
-	//MatrixSolver_SetMatrix( self->velSolver, sle->kStiffMat->matrix );
-	//KSPSetOperators( self->velSolver, ((PETScMatrix*)sle->kStiffMat->matrix)->petscMat, 
-	//		((PETScMatrix*)sle->kStiffMat->matrix)->petscMat, DIFFERENT_NONZERO_PATTERN );
-
-        self->mgSolver->mgData->matrix = sle->kStiffMat->matrix;
-        PETScMGSolver_Setup( self->mgSolver, NULL, NULL );
-        solver->velSolver = self->mgSolver->mgData->ksp;
-	KSPSetOperators( solver->velSolver, sle->kStiffMat->matrix, sle->kStiffMat->matrix, DIFFERENT_NONZERO_PATTERN );
-/*
-	KSPSetOperators( solver->velSolver, sle->kStiffMat->matrix, sle->kStiffMat->matrix, DIFFERENT_NONZERO_PATTERN );
-        KSPSetFromOptions( solver->velSolver );
-*/
-
-	if( solver->pcSolver ) {
-		Journal_DPrintfL( solver->debug, 1, "Setting up MatrixSolver for the Preconditioner.\n" );
-		//MatrixSolver_SetMatrix( self->pcSolver, self->preconditioner->matrix );
-		//KSPSetOperators( self->pcSolver, ((PETScMatrix*)self->preconditioner->matrix)->petscMat, 
-		//		((PETScMatrix*)self->preconditioner->matrix)->petscMat, DIFFERENT_NONZERO_PATTERN );
-		KSPSetOperators( solver->pcSolver, solver->preconditioner->matrix, solver->preconditioner->matrix, DIFFERENT_NONZERO_PATTERN );
-    KSPSetFromOptions( solver->pcSolver );
-	}
-
-	Stream_UnIndentBranch( StgFEM_Debug );
-}
-
-
-void Underworld_Multigrid_AssignFromXML( void* _self, Stg_ComponentFactory* cf, void* data ) {
-   Underworld_Multigrid* self = (Underworld_Multigrid*)_self;
-   UnderworldContext* ctx;
-
-   Underworld_Multigrid_selfPointer = self;
-
-   self->ctx = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data  );
-   self->sle = Stg_ComponentFactory_ConstructByName( cf, (Name)"stokesEqn", Stokes_SLE, True, data  );
-   self->mgSolver = Stg_ComponentFactory_ConstructByName( cf, (Name)"mgSolver", PETScMGSolver, True, data  );
-
-   /* Replace the setup routine... hacky. */
-   self->sle->solver->_solverSetup = Underworld_Multigrid_SolverSetup;   
-   
-}
-
-void Underworld_Multigrid_Build( void* _self, void* data ) {
-   Underworld_Multigrid* self = (Underworld_Multigrid*)_self;
-
-   Stg_Component_Build( self->mgSolver, data, False );
-   Stg_Component_Build( self->sle, data, False );
-}
-
-void Underworld_Multigrid_Initialise( void* _self, void* data ) {
-   Underworld_Multigrid* self = (Underworld_Multigrid*)_self;
-
-   Stg_Component_Initialise( self->mgSolver, data, False );
-   Stg_Component_Initialise( self->sle, data, False );
-
-   /* Setup the MG solver. */
-   PETScMGSolver_SetComm( self->mgSolver, MPI_COMM_WORLD );
-}
-
-void* Underworld_Multigrid_New( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Underworld_Multigrid);
-	Type                                                      type = Underworld_Multigrid_Type;
-	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
-	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
-	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = Underworld_Multigrid_New;
-	Stg_Component_ConstructFunction*                    _construct = Underworld_Multigrid_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = Underworld_Multigrid_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = Underworld_Multigrid_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 Underworld_Multigrid_Register( PluginsManager* mgr ) {
-   return PluginsManager_Submit( mgr, Underworld_Multigrid_Type, (Name)"0", Underworld_Multigrid_New  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d plugins/Multigrid/Multigrid.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/Multigrid/Multigrid.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,147 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd,
+** 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Multigrid.c 2192 2004-10-15 02:45:38Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <mpi.h>
+#include <petsc.h>
+#include <petscvec.h>
+#include <petscmat.h>
+#include <petscksp.h>
+#include <petscsnes.h>
+
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Underworld.h>
+
+#include "Multigrid.h"
+
+
+const Type Underworld_Multigrid_Type = "Underworld_Multigrid";
+Underworld_Multigrid* Underworld_Multigrid_selfPointer = NULL;
+
+
+void Underworld_Multigrid_SolverSetup( void* _solver, void* _stokesSLE ) {
+    Underworld_Multigrid* self = Underworld_Multigrid_selfPointer;
+	Stokes_SLE_UzawaSolver* solver = (Stokes_SLE_UzawaSolver*)_solver;
+	Stokes_SLE* sle = (Stokes_SLE*)_stokesSLE;
+	
+ 	Journal_DPrintf( solver->debug, "In %s:\n", __func__ );
+	Stream_IndentBranch( StgFEM_Debug );
+
+	Journal_DPrintfL( solver->debug, 1, "Setting up MatrixSolver for the velocity eqn.\n" );
+   self->mgSolver->mgData->matrixChanged = True;
+	//MatrixSolver_SetMatrix( self->velSolver, sle->kStiffMat->matrix );
+	//KSPSetOperators( self->velSolver, ((PETScMatrix*)sle->kStiffMat->matrix)->petscMat, 
+	//		((PETScMatrix*)sle->kStiffMat->matrix)->petscMat, DIFFERENT_NONZERO_PATTERN );
+
+        self->mgSolver->mgData->matrix = sle->kStiffMat->matrix;
+        PETScMGSolver_Setup( self->mgSolver, NULL, NULL );
+        solver->velSolver = self->mgSolver->mgData->ksp;
+	KSPSetOperators( solver->velSolver, sle->kStiffMat->matrix, sle->kStiffMat->matrix, DIFFERENT_NONZERO_PATTERN );
+/*
+	KSPSetOperators( solver->velSolver, sle->kStiffMat->matrix, sle->kStiffMat->matrix, DIFFERENT_NONZERO_PATTERN );
+        KSPSetFromOptions( solver->velSolver );
+*/
+
+	if( solver->pcSolver ) {
+		Journal_DPrintfL( solver->debug, 1, "Setting up MatrixSolver for the Preconditioner.\n" );
+		//MatrixSolver_SetMatrix( self->pcSolver, self->preconditioner->matrix );
+		//KSPSetOperators( self->pcSolver, ((PETScMatrix*)self->preconditioner->matrix)->petscMat, 
+		//		((PETScMatrix*)self->preconditioner->matrix)->petscMat, DIFFERENT_NONZERO_PATTERN );
+		KSPSetOperators( solver->pcSolver, solver->preconditioner->matrix, solver->preconditioner->matrix, DIFFERENT_NONZERO_PATTERN );
+    KSPSetFromOptions( solver->pcSolver );
+	}
+
+	Stream_UnIndentBranch( StgFEM_Debug );
+}
+
+
+void Underworld_Multigrid_AssignFromXML( void* _self, Stg_ComponentFactory* cf, void* data ) {
+   Underworld_Multigrid* self = (Underworld_Multigrid*)_self;
+   UnderworldContext* ctx;
+
+   Underworld_Multigrid_selfPointer = self;
+
+   self->ctx = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data  );
+   self->sle = Stg_ComponentFactory_ConstructByName( cf, (Name)"stokesEqn", Stokes_SLE, True, data  );
+   self->mgSolver = Stg_ComponentFactory_ConstructByName( cf, (Name)"mgSolver", PETScMGSolver, True, data  );
+
+   /* Replace the setup routine... hacky. */
+   self->sle->solver->_solverSetup = Underworld_Multigrid_SolverSetup;   
+   
+}
+
+void Underworld_Multigrid_Build( void* _self, void* data ) {
+   Underworld_Multigrid* self = (Underworld_Multigrid*)_self;
+
+   Stg_Component_Build( self->mgSolver, data, False );
+   Stg_Component_Build( self->sle, data, False );
+}
+
+void Underworld_Multigrid_Initialise( void* _self, void* data ) {
+   Underworld_Multigrid* self = (Underworld_Multigrid*)_self;
+
+   Stg_Component_Initialise( self->mgSolver, data, False );
+   Stg_Component_Initialise( self->sle, data, False );
+
+   /* Setup the MG solver. */
+   PETScMGSolver_SetComm( self->mgSolver, MPI_COMM_WORLD );
+}
+
+void* Underworld_Multigrid_New( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Underworld_Multigrid);
+	Type                                                      type = Underworld_Multigrid_Type;
+	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
+	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
+	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = Underworld_Multigrid_New;
+	Stg_Component_ConstructFunction*                    _construct = Underworld_Multigrid_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = Underworld_Multigrid_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = Underworld_Multigrid_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 Underworld_Multigrid_Register( PluginsManager* mgr ) {
+   return PluginsManager_Submit( mgr, Underworld_Multigrid_Type, (Name)"0", Underworld_Multigrid_New  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/AverageTemperature/AverageTemperature.c
--- a/plugins/Output/AverageTemperature/AverageTemperature.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,136 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id:  $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Underworld.h>
-#include <StgFEM/FrequentOutput/FrequentOutput.h>
-
-const Type Underworld_AverageTemperature_Type = "Underworld_AverageTemperature";
-void Underworld_AverageTemperature_PrintHeaderToFile( void* context );
-void Underworld_AverageTemperature_Output( void* _context );
-
-void _Underworld_AverageTemperature_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
-	UnderworldContext*  context;
-
-	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data );
-
-	Underworld_AverageTemperature_PrintHeaderToFile( context  );
-	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, Underworld_AverageTemperature_Output );
-}
-
-void* _Underworld_AverageTemperature_DefaultNew( Name name ) {
-	return Codelet_New(
-		Underworld_AverageTemperature_Type,
-		_Underworld_AverageTemperature_DefaultNew,
-		_Underworld_AverageTemperature_AssignFromXML,
-		_Codelet_Build,
-		_Codelet_Initialise,
-		_Codelet_Execute,
-		_Codelet_Destroy,
-		name );
-}
-
-Index Underworld_AverageTemperature_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Underworld_AverageTemperature_Type, (Name)"0", _Underworld_AverageTemperature_DefaultNew );
-}
-
-void Underworld_AverageTemperature_Output( void* _context ) {
-	UnderworldContext* context       = (UnderworldContext*) _context;
-	FeVariable*        temperatureFe = (FeVariable* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"TemperatureField" );
-	FeMesh*		   mesh         = temperatureFe->feMesh;
-	IntegrationPointsSwarm* swarm    = (IntegrationPointsSwarm* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"gaussSwarm"  );
-	IntegrationPoint*  particle;
-	ElementType*       elementType;
-	Element_LocalIndex lElement_I, lCell_I;
-	Cell_LocalIndex    cParticle_I;
-	Index              cellParticleCount, dim;
-	double             particleTemperature;
-	double             lTempIntegral = 0;
-	double             lAvg = 0;
-	double             simulationBuoyancyVolumeIntegral = 0;
-	double             lBuoyancyVolumeIntegral = 0;
-	double             simulationAvg = 0;
-	double             detJac;
-
-	dim = context->dim;
-
-	for( lElement_I = 0 ; lElement_I < FeMesh_GetElementLocalSize( mesh ); lElement_I++ ) {
-		elementType       = FeMesh_GetElementType( mesh, lElement_I );
-		lCell_I           = CellLayout_MapElementIdToCellId( swarm->cellLayout, lElement_I );
-		cellParticleCount = swarm->cellParticleCountTbl[ lCell_I ];
-		/* get particles in each element that makes up the patch */
-		for( cParticle_I = 0 ; cParticle_I < cellParticleCount ; cParticle_I++ ) {
-			particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
-			FeVariable_InterpolateWithinElement( temperatureFe, lElement_I, particle->xi, &particleTemperature );
-
-			if( particleTemperature > 1e-6 ) {
-				/* Calculate Determinant of Jacobian */
-				detJac = ElementType_JacobianDeterminant( elementType, mesh, lElement_I, particle->xi, dim );
-				/* Sum Integral */
-				lBuoyancyVolumeIntegral += detJac * particle->weight;
-				lTempIntegral += detJac * particle->weight * particleTemperature;
-			}
-		}
-	}
-
-	lAvg = lTempIntegral / lBuoyancyVolumeIntegral; 
-	
-	MPI_Reduce( &lAvg, &simulationAvg, 1, MPI_DOUBLE, MPI_SUM, 0, context->communicator );
-	MPI_Reduce( &lBuoyancyVolumeIntegral, &simulationBuoyancyVolumeIntegral, 1, MPI_DOUBLE, MPI_SUM, 0, context->communicator );
-	simulationAvg = simulationAvg / context->nproc;
-	simulationBuoyancyVolumeIntegral = simulationBuoyancyVolumeIntegral / context->nproc;
-	StgFEM_FrequentOutput_PrintValue( context, simulationAvg );
-	StgFEM_FrequentOutput_PrintValue( context, simulationBuoyancyVolumeIntegral );
-}
-
-void Underworld_AverageTemperature_PrintHeaderToFile( void* context ) {
-	StgFEM_FrequentOutput_PrintString( context, "AvgBuoyancyTemperature" );
-	StgFEM_FrequentOutput_PrintString( context, "BuoyancyVolume" );
-}
-
-
-
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/AverageTemperature/AverageTemperature.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/Output/AverageTemperature/AverageTemperature.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,136 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id:  $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Underworld.h>
+#include <StgFEM/FrequentOutput/FrequentOutput.h>
+
+const Type Underworld_AverageTemperature_Type = "Underworld_AverageTemperature";
+void Underworld_AverageTemperature_PrintHeaderToFile( void* context );
+void Underworld_AverageTemperature_Output( void* _context );
+
+void _Underworld_AverageTemperature_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
+	UnderworldContext*  context;
+
+	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data );
+
+	Underworld_AverageTemperature_PrintHeaderToFile( context  );
+	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, Underworld_AverageTemperature_Output );
+}
+
+void* _Underworld_AverageTemperature_DefaultNew( Name name ) {
+	return Codelet_New(
+		Underworld_AverageTemperature_Type,
+		_Underworld_AverageTemperature_DefaultNew,
+		_Underworld_AverageTemperature_AssignFromXML,
+		_Codelet_Build,
+		_Codelet_Initialise,
+		_Codelet_Execute,
+		_Codelet_Destroy,
+		name );
+}
+
+Index Underworld_AverageTemperature_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Underworld_AverageTemperature_Type, (Name)"0", _Underworld_AverageTemperature_DefaultNew );
+}
+
+void Underworld_AverageTemperature_Output( void* _context ) {
+	UnderworldContext* context       = (UnderworldContext*) _context;
+	FeVariable*        temperatureFe = (FeVariable* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"TemperatureField" );
+	FeMesh*		   mesh         = temperatureFe->feMesh;
+	IntegrationPointsSwarm* swarm    = (IntegrationPointsSwarm* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"gaussSwarm"  );
+	IntegrationPoint*  particle;
+	ElementType*       elementType;
+	Element_LocalIndex lElement_I, lCell_I;
+	Cell_LocalIndex    cParticle_I;
+	Index              cellParticleCount, dim;
+	double             particleTemperature;
+	double             lTempIntegral = 0;
+	double             lAvg = 0;
+	double             simulationBuoyancyVolumeIntegral = 0;
+	double             lBuoyancyVolumeIntegral = 0;
+	double             simulationAvg = 0;
+	double             detJac;
+
+	dim = context->dim;
+
+	for( lElement_I = 0 ; lElement_I < FeMesh_GetElementLocalSize( mesh ); lElement_I++ ) {
+		elementType       = FeMesh_GetElementType( mesh, lElement_I );
+		lCell_I           = CellLayout_MapElementIdToCellId( swarm->cellLayout, lElement_I );
+		cellParticleCount = swarm->cellParticleCountTbl[ lCell_I ];
+		/* get particles in each element that makes up the patch */
+		for( cParticle_I = 0 ; cParticle_I < cellParticleCount ; cParticle_I++ ) {
+			particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
+			FeVariable_InterpolateWithinElement( temperatureFe, lElement_I, particle->xi, &particleTemperature );
+
+			if( particleTemperature > 1e-6 ) {
+				/* Calculate Determinant of Jacobian */
+				detJac = ElementType_JacobianDeterminant( elementType, mesh, lElement_I, particle->xi, dim );
+				/* Sum Integral */
+				lBuoyancyVolumeIntegral += detJac * particle->weight;
+				lTempIntegral += detJac * particle->weight * particleTemperature;
+			}
+		}
+	}
+
+	lAvg = lTempIntegral / lBuoyancyVolumeIntegral; 
+	
+	MPI_Reduce( &lAvg, &simulationAvg, 1, MPI_DOUBLE, MPI_SUM, 0, context->communicator );
+	MPI_Reduce( &lBuoyancyVolumeIntegral, &simulationBuoyancyVolumeIntegral, 1, MPI_DOUBLE, MPI_SUM, 0, context->communicator );
+	simulationAvg = simulationAvg / context->nproc;
+	simulationBuoyancyVolumeIntegral = simulationBuoyancyVolumeIntegral / context->nproc;
+	StgFEM_FrequentOutput_PrintValue( context, simulationAvg );
+	StgFEM_FrequentOutput_PrintValue( context, simulationBuoyancyVolumeIntegral );
+}
+
+void Underworld_AverageTemperature_PrintHeaderToFile( void* context ) {
+	StgFEM_FrequentOutput_PrintString( context, "AvgBuoyancyTemperature" );
+	StgFEM_FrequentOutput_PrintString( context, "BuoyancyVolume" );
+}
+
+
+
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/BoundaryLayers/BoundaryLayers.c
--- a/plugins/Output/BoundaryLayers/BoundaryLayers.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,301 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: BoundaryLayers.c 708 2008-04-09 07:00:44Z JulianGiordani $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Underworld.h>
-
-#include <StgFEM/FrequentOutput/FrequentOutput.h>
-#include <Underworld/Nusselt/Nusselt.h>
-
-#include "BoundaryLayers.h"
-
-#include <assert.h>
-#include <string.h>
-
-const Type Underworld_BoundaryLayers_Type = "Underworld_BoundaryLayers";
-
-void _Underworld_BoundaryLayers_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
-	UnderworldContext* context;
-
-	/*printf("AKJFHQEIUH)@$UFKAJSDHRF\nKJASHRFOPUEH\nsaljkdh9\n9)#@$\n213\n\n"); The coordinates of the California Moon ??   */ 
-	
-	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data  ); 
-
-	/* Add functions to entry points */
-	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, Underworld_BoundaryLayers_Output );
-	
-	Underworld_BoundaryLayers_Setup( context );
-}
-
-void* _Underworld_BoundaryLayers_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Underworld_BoundaryLayers);
-	Type                                                      type = Underworld_BoundaryLayers_Type;
-	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
-	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
-	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_BoundaryLayers_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Underworld_BoundaryLayers_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 */;
-
-	/* printf("2  AKJFHQEIUH)@$UFKAJSDHRF\nKJASHRFOPUEH\nsaljkdh9\n9)#@$\n213\n\n"); */
-	return _Codelet_New(  CODELET_PASSARGS  );
-}
-
-Index Underworld_BoundaryLayers_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Underworld_BoundaryLayers_Type, (Name)"0", _Underworld_BoundaryLayers_DefaultNew );
-}
-
-void Underworld_BoundaryLayers_Setup( UnderworldContext* context ) {
-	Underworld_BoundaryLayers* self;
-	Dictionary*  dictionary = context->dictionary;
-
-	self = (Underworld_BoundaryLayers* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_BoundaryLayers_Type  );
-
-	self->internalTemperature = 0.5;
-	self->tolerance = Dictionary_GetDouble_WithDefault( dictionary, (Dictionary_Entry_Key)"BoundaryLayersTolerance", 0.0001  );
-	self->maxIterations = Dictionary_GetUnsignedInt_WithDefault( dictionary, "BoundaryLayersMaxIterations", 100 );
-	self->minIterations = Dictionary_GetUnsignedInt_WithDefault( dictionary, "BoundaryLayersMinIterations", 2 );
-
-	StgFEM_FrequentOutput_PrintString( context, "InternalTemp" );
-	StgFEM_FrequentOutput_PrintString( context, "HotLayer" );
-	StgFEM_FrequentOutput_PrintString( context, "ColdLayer" );
-}
-
-
-void Underworld_BoundaryLayers_Output( UnderworldContext* context ) {
-	Underworld_BoundaryLayers* self;
-	Underworld_Nusselt*        nusseltPlugin;
-	Iteration_Index            iteration_I;
-	Iteration_Index            maxIterations;
-	Iteration_Index            minIterations;
-	double                     internalTemperature;
-	double                     prevInternalTemperature;
-	double                     tolerance;
-	double                     nusseltNumber;
-	double                     hotLayerThickness;
-	double                     coldLayerThickness;
-
-	self = (Underworld_BoundaryLayers*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_BoundaryLayers_Type );
-	nusseltPlugin = (Underworld_Nusselt* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_Nusselt_Type  );	
-
-	iteration_I             = 0;
-	maxIterations           = self->maxIterations;
-	minIterations           = self->minIterations;
-	internalTemperature     = 0.5;
-	tolerance               = self->tolerance;
-	nusseltNumber           = nusseltPlugin->nusseltNumber;	
-	hotLayerThickness       = 0.0; 
-	coldLayerThickness      = 0.0;
-	
-	do {
-		prevInternalTemperature = internalTemperature;
-		internalTemperature = Underworld_BoundaryLayers_InternalTemperature( context, hotLayerThickness, coldLayerThickness );
-		if ( internalTemperature > 1.0 )
-			internalTemperature = 1.0;
-		if ( internalTemperature < 0.0 )
-			internalTemperature = 0.0;
-		
-		hotLayerThickness = (1.0 - internalTemperature)/nusseltNumber;
-		coldLayerThickness = internalTemperature/nusseltNumber;			
-
-		assert( !isnan( hotLayerThickness ) && !isnan( coldLayerThickness ) );
-
-		iteration_I++;
-		if ( iteration_I >= maxIterations ) {
-			break;
-		}
-	} while ( fabs(internalTemperature - prevInternalTemperature) > tolerance || iteration_I < minIterations );
-
-	StgFEM_FrequentOutput_PrintValue( context, internalTemperature );
-	StgFEM_FrequentOutput_PrintValue( context, hotLayerThickness );
-	StgFEM_FrequentOutput_PrintValue( context, coldLayerThickness );
-
-	self->internalTemperature = internalTemperature;
-	self->hotLayerThickness = hotLayerThickness;
-	self->coldLayerThickness = coldLayerThickness;
-}
-
-double Underworld_BoundaryLayers_InternalTemperature( UnderworldContext* context, double hotLayerThickness, double coldLayerThickness ) {
-	Dimension_Index     dim                    = context->dim;
-	double		    maxCrd[3], minCrd[3];
-	double              volume;
-	double              internalTemperature;
-	double              integral               = 0.0;
-	double              integralGlobal         = 0.0;
-	Swarm*              gaussSwarm             = (Swarm*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"gaussSwarm" );
-	IntegrationPoint*   particle;
-	double              bottomLayerHeight;
-	double              topLayerHeight;
-	FeVariable*         temperatureField       = (FeVariable* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"TemperatureField"  );
-	FeMesh*		    mesh                   = temperatureField->feMesh;
-	Element_LocalIndex  lElement_I;
-	Node_LocalIndex    	nodeAtElementBottom;
-	Node_LocalIndex    	nodeAtElementTop;
-	int                 elementNodeCount, *elementNodes;
-	double              elementBottomHeight;
-	double              elementTopHeight;
-	double              detJac;
-	double              factor;
-	Coord               xi;
-	double              temperature;
-	Particle_Index      gaussPoint_I;
-	Particle_Index      gaussPointCount        = gaussSwarm->particleLocalCount;
-	ElementType*        elementType;
-	IArray*			incArray;
-
-	Mesh_GetGlobalCoordRange( mesh, minCrd, maxCrd );
-	bottomLayerHeight = minCrd[ J_AXIS ] + hotLayerThickness;  
-	topLayerHeight    = maxCrd[ J_AXIS ] - coldLayerThickness; 
-	
-	/* volume (or area) Integrating and Averaging over */
-	volume = (maxCrd[ I_AXIS ] - minCrd[ I_AXIS ]) * (topLayerHeight - bottomLayerHeight);
-	if (dim == 3)
-		volume *= maxCrd[ K_AXIS ] - minCrd[ K_AXIS ];
-	
-	/************************************** Do Integration ************************************************/
-	
-	/* Loop over Elements */
-	incArray = IArray_New();
-	for ( lElement_I = 0 ; lElement_I < FeMesh_GetElementLocalSize( mesh ) ; lElement_I++ ) {
-		elementType         = FeMesh_GetElementType( mesh, lElement_I );
-		FeMesh_GetElementNodes( mesh, lElement_I, incArray );
-		elementNodeCount = IArray_GetSize( incArray );
-		elementNodes = IArray_GetPtr( incArray );
-
-		nodeAtElementBottom = elementNodes[ 0 ] ;
-		nodeAtElementTop    = elementNodes[ 2 ] ;
-
-		elementBottomHeight = Mesh_GetVertex( mesh, nodeAtElementBottom )[ J_AXIS ];
-		elementTopHeight    = Mesh_GetVertex( mesh, nodeAtElementTop    )[ J_AXIS ];
-		
-		/* Test where elements are relative to boundaries */
-		if ( elementTopHeight < bottomLayerHeight || elementBottomHeight > topLayerHeight ) {
-			/* Element in Boundary */
-			continue;
-		}
-		else if ( elementBottomHeight >= bottomLayerHeight && elementTopHeight <= topLayerHeight ) {
-			/* Element completely in interior */
-			integral += FeVariable_IntegrateElement( temperatureField, gaussSwarm, lElement_I );
-		}
-		else if ( elementBottomHeight <= bottomLayerHeight && elementTopHeight >= topLayerHeight ) {
-			/* Element in intersection of both Hot and Cold Bottom Boundary Layers */
-			factor = ( topLayerHeight - bottomLayerHeight ) / ( elementTopHeight - elementBottomHeight );
-			for ( gaussPoint_I = 0 ; gaussPoint_I < gaussPointCount ; gaussPoint_I++ ) {
-				particle = (IntegrationPoint*) Swarm_ParticleAt( gaussSwarm, gaussPoint_I );
-
-				/* Get Local Coord of particle in pseudo element */
-				memcpy( xi, particle->xi, sizeof(Coord) );
-				xi[ J_AXIS ] = factor * xi[ J_AXIS ] + ( topLayerHeight + bottomLayerHeight - 2.0 * elementBottomHeight )/( elementTopHeight - elementBottomHeight ) - 1.0;
-				assert( fabs( xi[ J_AXIS ] ) <= 1.0 );
-
-				/* Sum integral at this pseudo particle */
-				FeVariable_InterpolateWithinElement( temperatureField, lElement_I, xi, &temperature );
-				detJac = factor * ElementType_JacobianDeterminant( elementType, mesh, lElement_I, xi, dim );
-				integral += particle->weight * temperature * detJac;
-			}
-		}
-		else if (elementBottomHeight <= bottomLayerHeight) {		
-			/* Element in intersection at Hot Bottom Boundary*/
-			factor = ( elementTopHeight - bottomLayerHeight ) / ( elementTopHeight - elementBottomHeight );
-			for ( gaussPoint_I = 0 ; gaussPoint_I < gaussPointCount ; gaussPoint_I++ ) {
-				particle = (IntegrationPoint*) Swarm_ParticleAt( gaussSwarm, gaussPoint_I );
-
-				/* Get Local Coord of particle in pseudo element */
-				memcpy( xi, particle->xi, sizeof(Coord) );
-				xi[ J_AXIS ] = 1.0 - factor * ( 1.0 - xi[ J_AXIS ] );
-				assert( fabs( xi[ J_AXIS ] ) <= 1.0 );
-
-				/* Sum integral at this pseudo particle */
-				FeVariable_InterpolateWithinElement( temperatureField, lElement_I, xi, &temperature );
-				detJac = factor * ElementType_JacobianDeterminant( elementType, mesh, lElement_I, xi, dim );
-				integral += particle->weight * temperature * detJac;
-			}
-		}     
-		/* Element in Cold Top Layer */
-		else if (elementTopHeight >= topLayerHeight) {	
-			factor = ( topLayerHeight - elementBottomHeight ) / ( elementTopHeight - elementBottomHeight );
-			for ( gaussPoint_I = 0 ; gaussPoint_I < gaussPointCount ; gaussPoint_I++ ) {
-				particle = (IntegrationPoint*) Swarm_ParticleAt( gaussSwarm, gaussPoint_I );
-
-				/* Get Local Coord of particle in pseudo element */
-				memcpy( xi, particle->xi, sizeof(Coord) );
-				xi[ J_AXIS ] = factor * ( xi[ J_AXIS ] + 1.0 ) - 1.0;
-				assert( fabs( xi[ J_AXIS ] ) <= 1.0 );
-
-				/* Sum integral at this pseudo particle */
-				FeVariable_InterpolateWithinElement( temperatureField, lElement_I, xi, &temperature );
-				detJac = factor * ElementType_JacobianDeterminant( elementType, mesh, lElement_I, xi, dim );
-				integral += particle->weight * temperature * detJac;
-			}
-		}
-		else {
-			assert(0);
-		}
-	}
-
-	NewClass_Delete( incArray );
-		
-	/* Gather data from other processors */
-	MPI_Allreduce( &integral, &integralGlobal, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
-	
-	/* Find Average */
-	internalTemperature = integralGlobal/volume;
-		
-	return internalTemperature;
-}
-
-
-
-
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/BoundaryLayers/BoundaryLayers.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/Output/BoundaryLayers/BoundaryLayers.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,301 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: BoundaryLayers.c 708 2008-04-09 07:00:44Z JulianGiordani $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Underworld.h>
+
+#include <StgFEM/FrequentOutput/FrequentOutput.h>
+#include <Underworld/Nusselt/Nusselt.h>
+
+#include "BoundaryLayers.h"
+
+#include <assert.h>
+#include <string.h>
+
+const Type Underworld_BoundaryLayers_Type = "Underworld_BoundaryLayers";
+
+void _Underworld_BoundaryLayers_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
+	UnderworldContext* context;
+
+	/*printf("AKJFHQEIUH)@$UFKAJSDHRF\nKJASHRFOPUEH\nsaljkdh9\n9)#@$\n213\n\n"); The coordinates of the California Moon ??   */ 
+	
+	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data  ); 
+
+	/* Add functions to entry points */
+	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, Underworld_BoundaryLayers_Output );
+	
+	Underworld_BoundaryLayers_Setup( context );
+}
+
+void* _Underworld_BoundaryLayers_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Underworld_BoundaryLayers);
+	Type                                                      type = Underworld_BoundaryLayers_Type;
+	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
+	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
+	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_BoundaryLayers_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Underworld_BoundaryLayers_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 */;
+
+	/* printf("2  AKJFHQEIUH)@$UFKAJSDHRF\nKJASHRFOPUEH\nsaljkdh9\n9)#@$\n213\n\n"); */
+	return _Codelet_New(  CODELET_PASSARGS  );
+}
+
+Index Underworld_BoundaryLayers_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Underworld_BoundaryLayers_Type, (Name)"0", _Underworld_BoundaryLayers_DefaultNew );
+}
+
+void Underworld_BoundaryLayers_Setup( UnderworldContext* context ) {
+	Underworld_BoundaryLayers* self;
+	Dictionary*  dictionary = context->dictionary;
+
+	self = (Underworld_BoundaryLayers* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_BoundaryLayers_Type  );
+
+	self->internalTemperature = 0.5;
+	self->tolerance = Dictionary_GetDouble_WithDefault( dictionary, (Dictionary_Entry_Key)"BoundaryLayersTolerance", 0.0001  );
+	self->maxIterations = Dictionary_GetUnsignedInt_WithDefault( dictionary, "BoundaryLayersMaxIterations", 100 );
+	self->minIterations = Dictionary_GetUnsignedInt_WithDefault( dictionary, "BoundaryLayersMinIterations", 2 );
+
+	StgFEM_FrequentOutput_PrintString( context, "InternalTemp" );
+	StgFEM_FrequentOutput_PrintString( context, "HotLayer" );
+	StgFEM_FrequentOutput_PrintString( context, "ColdLayer" );
+}
+
+
+void Underworld_BoundaryLayers_Output( UnderworldContext* context ) {
+	Underworld_BoundaryLayers* self;
+	Underworld_Nusselt*        nusseltPlugin;
+	Iteration_Index            iteration_I;
+	Iteration_Index            maxIterations;
+	Iteration_Index            minIterations;
+	double                     internalTemperature;
+	double                     prevInternalTemperature;
+	double                     tolerance;
+	double                     nusseltNumber;
+	double                     hotLayerThickness;
+	double                     coldLayerThickness;
+
+	self = (Underworld_BoundaryLayers*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_BoundaryLayers_Type );
+	nusseltPlugin = (Underworld_Nusselt* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_Nusselt_Type  );	
+
+	iteration_I             = 0;
+	maxIterations           = self->maxIterations;
+	minIterations           = self->minIterations;
+	internalTemperature     = 0.5;
+	tolerance               = self->tolerance;
+	nusseltNumber           = nusseltPlugin->nusseltNumber;	
+	hotLayerThickness       = 0.0; 
+	coldLayerThickness      = 0.0;
+	
+	do {
+		prevInternalTemperature = internalTemperature;
+		internalTemperature = Underworld_BoundaryLayers_InternalTemperature( context, hotLayerThickness, coldLayerThickness );
+		if ( internalTemperature > 1.0 )
+			internalTemperature = 1.0;
+		if ( internalTemperature < 0.0 )
+			internalTemperature = 0.0;
+		
+		hotLayerThickness = (1.0 - internalTemperature)/nusseltNumber;
+		coldLayerThickness = internalTemperature/nusseltNumber;			
+
+		assert( !isnan( hotLayerThickness ) && !isnan( coldLayerThickness ) );
+
+		iteration_I++;
+		if ( iteration_I >= maxIterations ) {
+			break;
+		}
+	} while ( fabs(internalTemperature - prevInternalTemperature) > tolerance || iteration_I < minIterations );
+
+	StgFEM_FrequentOutput_PrintValue( context, internalTemperature );
+	StgFEM_FrequentOutput_PrintValue( context, hotLayerThickness );
+	StgFEM_FrequentOutput_PrintValue( context, coldLayerThickness );
+
+	self->internalTemperature = internalTemperature;
+	self->hotLayerThickness = hotLayerThickness;
+	self->coldLayerThickness = coldLayerThickness;
+}
+
+double Underworld_BoundaryLayers_InternalTemperature( UnderworldContext* context, double hotLayerThickness, double coldLayerThickness ) {
+	Dimension_Index     dim                    = context->dim;
+	double		    maxCrd[3], minCrd[3];
+	double              volume;
+	double              internalTemperature;
+	double              integral               = 0.0;
+	double              integralGlobal         = 0.0;
+	Swarm*              gaussSwarm             = (Swarm*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"gaussSwarm" );
+	IntegrationPoint*   particle;
+	double              bottomLayerHeight;
+	double              topLayerHeight;
+	FeVariable*         temperatureField       = (FeVariable* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"TemperatureField"  );
+	FeMesh*		    mesh                   = temperatureField->feMesh;
+	Element_LocalIndex  lElement_I;
+	Node_LocalIndex    	nodeAtElementBottom;
+	Node_LocalIndex    	nodeAtElementTop;
+	int                 elementNodeCount, *elementNodes;
+	double              elementBottomHeight;
+	double              elementTopHeight;
+	double              detJac;
+	double              factor;
+	Coord               xi;
+	double              temperature;
+	Particle_Index      gaussPoint_I;
+	Particle_Index      gaussPointCount        = gaussSwarm->particleLocalCount;
+	ElementType*        elementType;
+	IArray*			incArray;
+
+	Mesh_GetGlobalCoordRange( mesh, minCrd, maxCrd );
+	bottomLayerHeight = minCrd[ J_AXIS ] + hotLayerThickness;  
+	topLayerHeight    = maxCrd[ J_AXIS ] - coldLayerThickness; 
+	
+	/* volume (or area) Integrating and Averaging over */
+	volume = (maxCrd[ I_AXIS ] - minCrd[ I_AXIS ]) * (topLayerHeight - bottomLayerHeight);
+	if (dim == 3)
+		volume *= maxCrd[ K_AXIS ] - minCrd[ K_AXIS ];
+	
+	/************************************** Do Integration ************************************************/
+	
+	/* Loop over Elements */
+	incArray = IArray_New();
+	for ( lElement_I = 0 ; lElement_I < FeMesh_GetElementLocalSize( mesh ) ; lElement_I++ ) {
+		elementType         = FeMesh_GetElementType( mesh, lElement_I );
+		FeMesh_GetElementNodes( mesh, lElement_I, incArray );
+		elementNodeCount = IArray_GetSize( incArray );
+		elementNodes = IArray_GetPtr( incArray );
+
+		nodeAtElementBottom = elementNodes[ 0 ] ;
+		nodeAtElementTop    = elementNodes[ 2 ] ;
+
+		elementBottomHeight = Mesh_GetVertex( mesh, nodeAtElementBottom )[ J_AXIS ];
+		elementTopHeight    = Mesh_GetVertex( mesh, nodeAtElementTop    )[ J_AXIS ];
+		
+		/* Test where elements are relative to boundaries */
+		if ( elementTopHeight < bottomLayerHeight || elementBottomHeight > topLayerHeight ) {
+			/* Element in Boundary */
+			continue;
+		}
+		else if ( elementBottomHeight >= bottomLayerHeight && elementTopHeight <= topLayerHeight ) {
+			/* Element completely in interior */
+			integral += FeVariable_IntegrateElement( temperatureField, gaussSwarm, lElement_I );
+		}
+		else if ( elementBottomHeight <= bottomLayerHeight && elementTopHeight >= topLayerHeight ) {
+			/* Element in intersection of both Hot and Cold Bottom Boundary Layers */
+			factor = ( topLayerHeight - bottomLayerHeight ) / ( elementTopHeight - elementBottomHeight );
+			for ( gaussPoint_I = 0 ; gaussPoint_I < gaussPointCount ; gaussPoint_I++ ) {
+				particle = (IntegrationPoint*) Swarm_ParticleAt( gaussSwarm, gaussPoint_I );
+
+				/* Get Local Coord of particle in pseudo element */
+				memcpy( xi, particle->xi, sizeof(Coord) );
+				xi[ J_AXIS ] = factor * xi[ J_AXIS ] + ( topLayerHeight + bottomLayerHeight - 2.0 * elementBottomHeight )/( elementTopHeight - elementBottomHeight ) - 1.0;
+				assert( fabs( xi[ J_AXIS ] ) <= 1.0 );
+
+				/* Sum integral at this pseudo particle */
+				FeVariable_InterpolateWithinElement( temperatureField, lElement_I, xi, &temperature );
+				detJac = factor * ElementType_JacobianDeterminant( elementType, mesh, lElement_I, xi, dim );
+				integral += particle->weight * temperature * detJac;
+			}
+		}
+		else if (elementBottomHeight <= bottomLayerHeight) {		
+			/* Element in intersection at Hot Bottom Boundary*/
+			factor = ( elementTopHeight - bottomLayerHeight ) / ( elementTopHeight - elementBottomHeight );
+			for ( gaussPoint_I = 0 ; gaussPoint_I < gaussPointCount ; gaussPoint_I++ ) {
+				particle = (IntegrationPoint*) Swarm_ParticleAt( gaussSwarm, gaussPoint_I );
+
+				/* Get Local Coord of particle in pseudo element */
+				memcpy( xi, particle->xi, sizeof(Coord) );
+				xi[ J_AXIS ] = 1.0 - factor * ( 1.0 - xi[ J_AXIS ] );
+				assert( fabs( xi[ J_AXIS ] ) <= 1.0 );
+
+				/* Sum integral at this pseudo particle */
+				FeVariable_InterpolateWithinElement( temperatureField, lElement_I, xi, &temperature );
+				detJac = factor * ElementType_JacobianDeterminant( elementType, mesh, lElement_I, xi, dim );
+				integral += particle->weight * temperature * detJac;
+			}
+		}     
+		/* Element in Cold Top Layer */
+		else if (elementTopHeight >= topLayerHeight) {	
+			factor = ( topLayerHeight - elementBottomHeight ) / ( elementTopHeight - elementBottomHeight );
+			for ( gaussPoint_I = 0 ; gaussPoint_I < gaussPointCount ; gaussPoint_I++ ) {
+				particle = (IntegrationPoint*) Swarm_ParticleAt( gaussSwarm, gaussPoint_I );
+
+				/* Get Local Coord of particle in pseudo element */
+				memcpy( xi, particle->xi, sizeof(Coord) );
+				xi[ J_AXIS ] = factor * ( xi[ J_AXIS ] + 1.0 ) - 1.0;
+				assert( fabs( xi[ J_AXIS ] ) <= 1.0 );
+
+				/* Sum integral at this pseudo particle */
+				FeVariable_InterpolateWithinElement( temperatureField, lElement_I, xi, &temperature );
+				detJac = factor * ElementType_JacobianDeterminant( elementType, mesh, lElement_I, xi, dim );
+				integral += particle->weight * temperature * detJac;
+			}
+		}
+		else {
+			assert(0);
+		}
+	}
+
+	NewClass_Delete( incArray );
+		
+	/* Gather data from other processors */
+	MPI_Allreduce( &integral, &integralGlobal, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
+	
+	/* Find Average */
+	internalTemperature = integralGlobal/volume;
+		
+	return internalTemperature;
+}
+
+
+
+
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/BuoyancyIntegrals/BuoyancyIntegrals.c
--- a/plugins/Output/BuoyancyIntegrals/BuoyancyIntegrals.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,525 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: BuoyancyIntegrals.c 487 2007-06-07 05:48:32Z LukeHodkinson $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Underworld.h>
-#include <StgFEM/FrequentOutput/FrequentOutput.h>
-
-
-/* prototypes */
-Index Underworld_BuoyancyIntegrals_Register( PluginsManager *pluginsManager );
-void* _Underworld_BuoyancyIntegrals_DefaultNew( Name name );
-void _Underworld_BuoyancyIntegrals_CTX_Delete( void *component );
-void _Underworld_BuoyancyIntegrals_AssignFromXML( void *component, Stg_ComponentFactory *cf, void *data );
-void Underworld_BuoyancyIntegrals_Output( UnderworldContext *context );
-void Underworld_BuoyancyIntegrals_Setup( void* _context );
-void _Underworld_BuoyancyIntegrals_CTX_Destroy( void* component, void* data );
-typedef struct {
-	__Codelet
-			double int_w_bar_dt;
-	double beta;
-	double gravity;
-	int dim;
-	double y_b_initial;
-	FieldVariable *temperatureField;
-	double x_b, z_b;
-	MaterialPointsSwarm *cob_swarm; /* center of buouyancy swarm */
-} Underworld_BuoyancyIntegrals_CTX;
-
-
-
-/*---------------------------------- PLUGIN SOURCE CODE --------------------------------------*/
-
-const Type Underworld_BuoyancyIntegrals_Type = "Underworld_BuoyancyIntegrals";
-
-Index Underworld_BuoyancyIntegrals_Register( PluginsManager *pluginsManager ) 
-{
-	return PluginsManager_Submit( pluginsManager, Underworld_BuoyancyIntegrals_Type, (Name)"0", _Underworld_BuoyancyIntegrals_DefaultNew );
-}
-
-void* _Underworld_BuoyancyIntegrals_DefaultNew( Name name ) 
-{
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Underworld_BuoyancyIntegrals_CTX);
-	Type                                                      type = Underworld_BuoyancyIntegrals_Type;
-	Stg_Class_DeleteFunction*                              _delete = _Underworld_BuoyancyIntegrals_CTX_Delete;
-	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
-	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_BuoyancyIntegrals_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Underworld_BuoyancyIntegrals_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _Codelet_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _Codelet_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _Codelet_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _Underworld_BuoyancyIntegrals_CTX_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  );
-}
-
-void _Underworld_BuoyancyIntegrals_CTX_Delete( void *component ) 
-{
-	Underworld_BuoyancyIntegrals_CTX  *ctx = (Underworld_BuoyancyIntegrals_CTX*)component;
-	
-	_Codelet_Delete( ctx  );
-}
-
-void _Underworld_BuoyancyIntegrals_CTX_Destroy( void* component, void* data ) {
-	Underworld_BuoyancyIntegrals_CTX*	self = (Underworld_BuoyancyIntegrals_CTX*)component;
-
-   _Codelet_Destroy( self, data );
-
-	if( self->cob_swarm != NULL )
-		Stg_Component_Destroy( self->cob_swarm, data, False );
-}
-
-void _Underworld_BuoyancyIntegrals_AssignFromXML( void *component, Stg_ComponentFactory *cf, void *data ) 
-{
-	UnderworldContext *context;
-	Underworld_BuoyancyIntegrals_CTX *ctx;
-	MaterialPointsSwarm *cob_swarm; /* center of buouyancy swarm */
-	
-	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data  ); 
-	
-	/* Add functions to entry points */
-	ContextEP_Append( context, AbstractContext_EP_AssignFromXMLExtensions, Underworld_BuoyancyIntegrals_Setup );
-	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, Underworld_BuoyancyIntegrals_Output );
-	
-	
-	ctx = (Underworld_BuoyancyIntegrals_CTX*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_BuoyancyIntegrals_Type  );
-	
-	/* Look for a swarm to which we will assign the calculated center of buoyancy to */
-	ctx->cob_swarm = NULL;
-	cob_swarm = Stg_ComponentFactory_ConstructByName( cf, (Name)"center_buoyancy_swarm", MaterialPointsSwarm, False, data );
-	if( cob_swarm != NULL ) {
-		ctx->cob_swarm = cob_swarm;
-	}
-	
-}
-
-void Underworld_BuoyancyIntegrals_Setup( void *_context )
-{
-	UnderworldContext *context = (UnderworldContext*) _context;
-	FieldVariable_Register *fV_Register = context->fieldVariable_Register;
-	Underworld_BuoyancyIntegrals_CTX *ctx;
-	Stg_Shape *shape;
-	
-	
-	/* allocate memory */
-	ctx = (Underworld_BuoyancyIntegrals_CTX* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_BuoyancyIntegrals_Type  );
-	
-	/* init values */
-	ctx->dim = Stg_ComponentFactory_GetRootDictInt( context->CF, "dim", -1 );
-	if( (int)ctx->dim == -1 ) {
-		printf("******************** ERROR dim IS UNINITIALISED ******************************** \n");
-	}
-	
-	
-	ctx->beta = Stg_ComponentFactory_GetRootDictDouble( context->CF, (Dictionary_Entry_Key)"alpha", -1 );
-	if( (int)ctx->beta == -1 ) {
-		printf("******************** ERROR ALPHA IS UNINITIALISED ******************************** \n" );
-	}
-	
-	ctx->gravity = Stg_ComponentFactory_GetRootDictDouble( context->CF, (Dictionary_Entry_Key)"gravity", -1 );
-	if( (int)ctx->gravity == -1 ) {
-		printf("******************** ERROR GRAVITY IS UNINITIALISED ******************************** \n" );
-	}
-	
-	ctx->y_b_initial = Stg_ComponentFactory_GetRootDictDouble( context->CF, (Dictionary_Entry_Key)"y_b_initial", -1 );
-	if( (int)ctx->y_b_initial == -1 ) {
-		printf("********************* ERROR Y_B_INITIAL IS NOT SET *********************** \n");
-	}
-
-	ctx->int_w_bar_dt = ctx->y_b_initial;
-	
-	if (ctx->dim ==3){
-		shape = (Stg_Shape* )Stg_ComponentFactory_ConstructByName( context->CF, (Name)"cylinder", Stg_Shape, True, 0 /* dummy */ );
-		ctx->x_b = shape->centre[0];
-		ctx->z_b = shape->centre[2];
-	} else if (ctx->dim==2){
-		shape = (Stg_Shape* )Stg_ComponentFactory_ConstructByName( context->CF, (Name)"disk", Stg_Shape, True, 0 /* dummy */  );
-		ctx->x_b = shape->centre[0];
-	}
-	
-	ctx->temperatureField = FieldVariable_Register_GetByName( fV_Register, "TemperatureField" );
-	
-	
-	
-#if 0
-	/* Create Some FeVariables to calculate nusselt number */
-	temperatureField          = FieldVariable_Register_GetByName( fV_Register, "TemperatureField" );
-	velocityField             = FieldVariable_Register_GetByName( fV_Register, "VelocityField" );
-	
-	
-	/* To compute B */
-	/* perturbed_temperatre := T - T_0 */
-	/*
-	self->perturbed_temperatre_field = OperatorFeVariable_NewUnary(
-	"AdvectiveHeatFluxField",
-	temperatureField,
-	"VectorScale" );
-	*/
-	/* 
-	Does not appear to be anything to shift fields by a scalar. 
-	Will just assume that T0 = 0
-	*/
-	self->perturbed_temperatre_field = temperatureField;
-	
-	
-	/* To compute w_bar */
-	/* grab the second component of the velocity field ez \dot u */
-	self->vertical_velocity_field = (FeVariable*) OperatorFeVariable_NewUnary(
-			"VerticalVelocityField",
-			velocityField,
-			"TakeSecondComponent" );
-	self->vertical_velocity_field->feMesh = ((FeVariable*)velocityField)->feMesh;
-	
-	self->vT_field = OperatorFeVariable_NewBinary(
-			"VerticalAdvectiveTemperatureField",
-			temperatureField,
-			self->vertical_velocity_field,
-			"VectorScale" );
-	self->vT_field->feMesh = ((FeVariable*)velocityField)->feMesh;
-#endif
-	
-	
-	
-	/* Add names to the integrals in the frequent output */
-	StgFEM_FrequentOutput_PrintString( context, "B" );
-	StgFEM_FrequentOutput_PrintString( context, "w_bar" );
-	StgFEM_FrequentOutput_PrintString( context, "x_b" );
-	StgFEM_FrequentOutput_PrintString( context, "y_b" );
-	if (ctx->dim==3){
-	StgFEM_FrequentOutput_PrintString( context, "z_b" );
-	}
-	StgFEM_FrequentOutput_PrintString( context, "int_w_bar_dt" );
-	StgFEM_FrequentOutput_PrintString( context, "temp_b" );
-	StgFEM_FrequentOutput_PrintString( context, "temp_max" );
-	
-	
-	/* Set the initial coordinates for the cob swarm */
-	if( ctx->cob_swarm != NULL ) {
-		Swarm *swarm;
-		GlobalParticle *particle;
-		
-		/* Force swarm to allocate points so that I can set initial values */
-		Stg_Component_Build( ctx->cob_swarm, NULL, False );
-		Stg_Component_Initialise( ctx->cob_swarm, NULL, False );
-		
-		swarm = (Swarm*)ctx->cob_swarm;
-		/* Set initial coords based on existing data from input xml */
-		particle = (GlobalParticle*)Swarm_ParticleAt( swarm, 0 );
-		particle->coord[0] = ctx->x_b;
-		particle->coord[1] = ctx->y_b_initial;
-		particle->coord[2] = ctx->z_b;
-	}
-}
-
-
-void perform_integrals( UnderworldContext *context, double *B, double *w_bar, double *y_b, double *int_w_bar_dt )
-{
-	Underworld_BuoyancyIntegrals_CTX *ctx;
-	IntegrationPoint *ip;
-	double *xi;
-	double weight;
-	Particle_InCellIndex p, ngp;
-	Cell_Index cell_I;
-	double velocity[3], global_coord[3];
-	FeMesh* mesh;
-	Element_LocalIndex e;
-	
-	double i_T, i_v, i_y, i_vT; /* interpolated quantity */
-	double sum_T, sum_vT, sum_yT; /* integral sum */
-	double _sum_T, _sum_vT, _sum_yT; /* element sums */
-	double g_sum_T, g_sum_vT, g_sum_yT; /* element sums */
-	int n_elements;
-	ElementType *elementType;
-	Node_Index elementNodeCount;
-	Dimension_Index dim;
-	double det_jac, dt;
-	double **GNx;
-	double _sum_vol, sum_vol;
-	
-	FeVariable *velocityField, *temperatureField;
-	Swarm* gaussSwarm;
-	
-	ctx = (Underworld_BuoyancyIntegrals_CTX*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_BuoyancyIntegrals_Type );
-	
-	velocityField = (FeVariable* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"VelocityField" );
-	temperatureField = (FeVariable* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"TemperatureField" );
-	gaussSwarm = (Swarm* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"gaussSwarm" );
-
-	/* initialise values to compute */
-	*B = *w_bar = *y_b = -1.0;
-	*int_w_bar_dt = ctx->int_w_bar_dt;
-	
-	
-	
-#if 0
-	/* test 1 - get beta */
-	*B = ctx->beta;	
-	/* test 2 - get gravity */
-	*w_bar = ctx->gravity;
-	/* test 3 get dt */
-	*y_b = context->dt;
-#endif	
-	
-	/* evaluate some integrals */
-	
-#if 0
-	ngp = context->gaussSwarm->particleLocalCount;
-	cell_I = 0;
-	for( p = 0; p<ngp; p++ ) {
-		ip = (IntegrationPoint* )Swarm_ParticleInCellAt( context->gaussSwarm, cell_I, p );
-		xi = ip->xi;
-		weight = ip->weight;
-		///*
-		printf("[%d] w = %f : xi = %f %f \n", p, weight, xi[0], xi[1] );
-		//*/
-	}
-#endif
-	
-	/* assuming all elements are the same */
-	dim = ctx->dim;
-	elementType = FeMesh_GetElementType( velocityField->feMesh, 0 );
-	elementNodeCount = elementType->nodeCount;
-	GNx = Memory_Alloc_2DArray( double, dim, elementNodeCount, (Name)"Global Shape Function Derivatives for mayhem" );
-
-	mesh = temperatureField->feMesh;
-	
-	
-	_sum_T = _sum_vT = _sum_yT = 0.0;
-	_sum_vol = 0.0;
-	
-	ngp = gaussSwarm->particleLocalCount;
-	n_elements = FeMesh_GetElementLocalSize( mesh  );
-	//	printf("n_elements = %d \n", n_elements );
-	
-	for( e=0; e<n_elements; e++ ) {
-		cell_I = CellLayout_MapElementIdToCellId( gaussSwarm->cellLayout, e );
-		elementType = FeMesh_GetElementType( mesh, e );
-		
-		sum_T  = 0.0;
-		sum_vT = 0.0;
-		sum_yT = 0.0;
-		sum_vol = 0.0;
-		
-		i_T = i_v = i_vT = i_y = 0.0;
-		
-		for( p=0; p<ngp; p++ ) {
-			ip = (IntegrationPoint*)Swarm_ParticleInCellAt( gaussSwarm, cell_I, p );
-			xi = ip->xi;
-			weight = ip->weight;
-			
-			ElementType_ShapeFunctionsGlobalDerivs(
-					elementType,
-					mesh, e,
-					xi, dim, &det_jac, GNx );
-			
-			FeVariable_InterpolateFromMeshLocalCoord( temperatureField, mesh, e, xi, &i_T );
-			FeVariable_InterpolateFromMeshLocalCoord( velocityField,    mesh, e, xi, velocity );
-			
-			i_v = velocity[1];
-			i_vT = i_v * i_T;
-			
-			FeMesh_CoordLocalToGlobal( mesh, e, xi, global_coord );
-			i_y = global_coord[1];
-			
-			//printf("%f %f %f %f J=%f \n", i_T, i_v, i_vT, i_y, det_jac );
-			
-			sum_T  = sum_T  + weight * i_T * det_jac;
-			sum_vT = sum_vT + weight * i_vT * det_jac;
-			sum_yT = sum_yT + weight * i_y * i_T * det_jac;
-			sum_vol = sum_vol + weight * det_jac;
-		}
-		
-		_sum_T = _sum_T + sum_T;
-		_sum_vT = _sum_vT + sum_vT;
-		_sum_yT = _sum_yT + sum_yT;
-		_sum_vol = _sum_vol + sum_vol;		
-		
-	}
-	//printf("%f %f %f \n", _sum_T, _sum_vT, _sum_yT );
-	
-	
-	
-	/* all reduce */
-	MPI_Allreduce ( &_sum_T, &g_sum_T, 1, MPI_DOUBLE, MPI_SUM, context->communicator );
-	MPI_Allreduce ( &_sum_vT, &g_sum_vT, 1, MPI_DOUBLE, MPI_SUM, context->communicator );
-	MPI_Allreduce ( &_sum_yT, &g_sum_yT, 1, MPI_DOUBLE, MPI_SUM, context->communicator );
-	/*
-	MPI_Allreduce ( &_sum_vol, &g_sum_vol, 1, MPI_DOUBLE, MPI_SUM, context->communicator );
-	printf("l_sum_vol = %f \n", _sum_vol );
-	printf("g_sum_vol = %f \n", g_sum_vol );
-	*/
-	
-	*B     = ctx->gravity * ctx->beta * g_sum_T;
-	*w_bar = (ctx->gravity * ctx->beta/ *B) * g_sum_vT;
-	*y_b   = (ctx->gravity * ctx->beta/ *B) * g_sum_yT;
-	
-	dt = context->dt;
-	*int_w_bar_dt = *int_w_bar_dt + (*w_bar) * dt;
-	ctx->int_w_bar_dt = *int_w_bar_dt;
-	
-	Memory_Free( GNx );
-	
-}
-
-
-
-void eval_temperature( UnderworldContext *context, double y_b, double *temp_b )
-{
-	Underworld_BuoyancyIntegrals_CTX *ctx;
-	double global_coord[3];
-	InterpolationResult result;
-	double T;
-	FeVariable* temperatureField;
-
-	T = -66.99;
-	
-	ctx = (Underworld_BuoyancyIntegrals_CTX*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_BuoyancyIntegrals_Type );
-	
-	temperatureField = (FeVariable* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"TemperatureField"  );
-	/* Get x_b, and z_b from xml */
-	/* "cylinder" z_b = CentreZ (0.5), x_b = CentreX (1.0) */
-	if (ctx->dim==3){
-		global_coord[0] = ctx->x_b;
-		global_coord[1] = y_b;
-		global_coord[2] = ctx->z_b;
-	}
-    	if (ctx->dim==2){
-		global_coord[0] = ctx->x_b;
-		global_coord[1] = y_b;
-	}
-
-	result = FieldVariable_InterpolateValueAt( temperatureField, global_coord, &T );
-	MPI_Allreduce ( &T, temp_b, 1, MPI_DOUBLE, MPI_MAX, context->communicator );
-
-}
-
-
-void assign_coords_to_swarm( double x_b, double y_b, double z_b, MaterialPointsSwarm *cob_swarm )
-{
-	Swarm *swarm;
-	int point_count;
-	GlobalParticle *particle;
-	Particle_Index lParticle_I;
-	Stream *errorStream = Journal_Register( Error_Type, (Name)"Underworld_BuoyancyIntegrals: assign_coords_to_swarm" );
-	/* int rank; */
-	
-	/* Cast to get parent */
-	swarm = (Swarm* )cob_swarm;
-	
-	
-	/* check cob swarm only has one point */
-	point_count = swarm->particleLocalCount;
-	/*
-	MPI_Comm_rank( MPI_COMM_WORLD, &rank );
-	printf("rank[%d]: np (cob) = %d \n", rank, point_count );
-	*/
-	Journal_Firewall(
-			point_count == 1,
-			errorStream,
-			"Error in %s:\n"
-			"Swarm with name %s is be used to plot center of buoyancy.\n"
-			"This swarm contains more then 1 point. This is unexpected!!", __func__, swarm->name );
-	
-	/* get point to the first particle */
-	lParticle_I = 0;
-	particle = (GlobalParticle*)Swarm_ParticleAt( swarm, lParticle_I );
-	
-	/* Set the coorindates */
-	/*printf("*********** ASSIGNING COORDS TO COB ****************** \n");*/
-	particle->coord[0] = x_b;
-	particle->coord[1] = y_b;
-	particle->coord[2] = z_b;
-	
-}
-
-
-void Underworld_BuoyancyIntegrals_Output( UnderworldContext *context ) 
-{
-	Underworld_BuoyancyIntegrals_CTX *ctx;
-	double B, w_bar, y_b, int_w_bar_dt;
-	double temp_b; /* the temperature at (x_b,y_b,z_b) */
-	double temp_max;
-	FeVariable* temperatureField;
-	
-	perform_integrals( context, &B, &w_bar, &y_b, &int_w_bar_dt );
-	eval_temperature( context, y_b, &temp_b );
-	
-	ctx = (Underworld_BuoyancyIntegrals_CTX*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_BuoyancyIntegrals_Type );
-	
-	temperatureField = (FeVariable* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"TemperatureField"  );
-	
-	StgFEM_FrequentOutput_PrintValue( context, B );
-	StgFEM_FrequentOutput_PrintValue( context, w_bar );
-	StgFEM_FrequentOutput_PrintValue( context, ctx->x_b );
-	StgFEM_FrequentOutput_PrintValue( context, y_b );
-	if (ctx->dim==3){
-		StgFEM_FrequentOutput_PrintValue( context, ctx->z_b );
-	}
-	StgFEM_FrequentOutput_PrintValue( context, int_w_bar_dt );
-	StgFEM_FrequentOutput_PrintValue( context, temp_b );
-	
-	temp_max = _FeVariable_GetMaxGlobalFieldMagnitude( temperatureField );
-	StgFEM_FrequentOutput_PrintValue( context, temp_max );
-	
-	
-	/* assign coords of center of buoyancy to swarm (if it exists) */
-	if( ctx->cob_swarm != NULL ) {
-		assign_coords_to_swarm( ctx->x_b, y_b, ctx->z_b, ctx->cob_swarm );
-	}
-	
-	
-	
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/BuoyancyIntegrals/BuoyancyIntegrals.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/Output/BuoyancyIntegrals/BuoyancyIntegrals.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,525 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: BuoyancyIntegrals.c 487 2007-06-07 05:48:32Z LukeHodkinson $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Underworld.h>
+#include <StgFEM/FrequentOutput/FrequentOutput.h>
+
+
+/* prototypes */
+Index Underworld_BuoyancyIntegrals_Register( PluginsManager *pluginsManager );
+void* _Underworld_BuoyancyIntegrals_DefaultNew( Name name );
+void _Underworld_BuoyancyIntegrals_CTX_Delete( void *component );
+void _Underworld_BuoyancyIntegrals_AssignFromXML( void *component, Stg_ComponentFactory *cf, void *data );
+void Underworld_BuoyancyIntegrals_Output( UnderworldContext *context );
+void Underworld_BuoyancyIntegrals_Setup( void* _context );
+void _Underworld_BuoyancyIntegrals_CTX_Destroy( void* component, void* data );
+typedef struct {
+	__Codelet
+			double int_w_bar_dt;
+	double beta;
+	double gravity;
+	int dim;
+	double y_b_initial;
+	FieldVariable *temperatureField;
+	double x_b, z_b;
+	MaterialPointsSwarm *cob_swarm; /* center of buouyancy swarm */
+} Underworld_BuoyancyIntegrals_CTX;
+
+
+
+/*---------------------------------- PLUGIN SOURCE CODE --------------------------------------*/
+
+const Type Underworld_BuoyancyIntegrals_Type = "Underworld_BuoyancyIntegrals";
+
+Index Underworld_BuoyancyIntegrals_Register( PluginsManager *pluginsManager ) 
+{
+	return PluginsManager_Submit( pluginsManager, Underworld_BuoyancyIntegrals_Type, (Name)"0", _Underworld_BuoyancyIntegrals_DefaultNew );
+}
+
+void* _Underworld_BuoyancyIntegrals_DefaultNew( Name name ) 
+{
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Underworld_BuoyancyIntegrals_CTX);
+	Type                                                      type = Underworld_BuoyancyIntegrals_Type;
+	Stg_Class_DeleteFunction*                              _delete = _Underworld_BuoyancyIntegrals_CTX_Delete;
+	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
+	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_BuoyancyIntegrals_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Underworld_BuoyancyIntegrals_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _Codelet_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _Codelet_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _Codelet_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _Underworld_BuoyancyIntegrals_CTX_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  );
+}
+
+void _Underworld_BuoyancyIntegrals_CTX_Delete( void *component ) 
+{
+	Underworld_BuoyancyIntegrals_CTX  *ctx = (Underworld_BuoyancyIntegrals_CTX*)component;
+	
+	_Codelet_Delete( ctx  );
+}
+
+void _Underworld_BuoyancyIntegrals_CTX_Destroy( void* component, void* data ) {
+	Underworld_BuoyancyIntegrals_CTX*	self = (Underworld_BuoyancyIntegrals_CTX*)component;
+
+   _Codelet_Destroy( self, data );
+
+	if( self->cob_swarm != NULL )
+		Stg_Component_Destroy( self->cob_swarm, data, False );
+}
+
+void _Underworld_BuoyancyIntegrals_AssignFromXML( void *component, Stg_ComponentFactory *cf, void *data ) 
+{
+	UnderworldContext *context;
+	Underworld_BuoyancyIntegrals_CTX *ctx;
+	MaterialPointsSwarm *cob_swarm; /* center of buouyancy swarm */
+	
+	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data  ); 
+	
+	/* Add functions to entry points */
+	ContextEP_Append( context, AbstractContext_EP_AssignFromXMLExtensions, Underworld_BuoyancyIntegrals_Setup );
+	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, Underworld_BuoyancyIntegrals_Output );
+	
+	
+	ctx = (Underworld_BuoyancyIntegrals_CTX*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_BuoyancyIntegrals_Type  );
+	
+	/* Look for a swarm to which we will assign the calculated center of buoyancy to */
+	ctx->cob_swarm = NULL;
+	cob_swarm = Stg_ComponentFactory_ConstructByName( cf, (Name)"center_buoyancy_swarm", MaterialPointsSwarm, False, data );
+	if( cob_swarm != NULL ) {
+		ctx->cob_swarm = cob_swarm;
+	}
+	
+}
+
+void Underworld_BuoyancyIntegrals_Setup( void *_context )
+{
+	UnderworldContext *context = (UnderworldContext*) _context;
+	FieldVariable_Register *fV_Register = context->fieldVariable_Register;
+	Underworld_BuoyancyIntegrals_CTX *ctx;
+	Stg_Shape *shape;
+	
+	
+	/* allocate memory */
+	ctx = (Underworld_BuoyancyIntegrals_CTX* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_BuoyancyIntegrals_Type  );
+	
+	/* init values */
+	ctx->dim = Stg_ComponentFactory_GetRootDictInt( context->CF, "dim", -1 );
+	if( (int)ctx->dim == -1 ) {
+		printf("******************** ERROR dim IS UNINITIALISED ******************************** \n");
+	}
+	
+	
+	ctx->beta = Stg_ComponentFactory_GetRootDictDouble( context->CF, (Dictionary_Entry_Key)"alpha", -1 );
+	if( (int)ctx->beta == -1 ) {
+		printf("******************** ERROR ALPHA IS UNINITIALISED ******************************** \n" );
+	}
+	
+	ctx->gravity = Stg_ComponentFactory_GetRootDictDouble( context->CF, (Dictionary_Entry_Key)"gravity", -1 );
+	if( (int)ctx->gravity == -1 ) {
+		printf("******************** ERROR GRAVITY IS UNINITIALISED ******************************** \n" );
+	}
+	
+	ctx->y_b_initial = Stg_ComponentFactory_GetRootDictDouble( context->CF, (Dictionary_Entry_Key)"y_b_initial", -1 );
+	if( (int)ctx->y_b_initial == -1 ) {
+		printf("********************* ERROR Y_B_INITIAL IS NOT SET *********************** \n");
+	}
+
+	ctx->int_w_bar_dt = ctx->y_b_initial;
+	
+	if (ctx->dim ==3){
+		shape = (Stg_Shape* )Stg_ComponentFactory_ConstructByName( context->CF, (Name)"cylinder", Stg_Shape, True, 0 /* dummy */ );
+		ctx->x_b = shape->centre[0];
+		ctx->z_b = shape->centre[2];
+	} else if (ctx->dim==2){
+		shape = (Stg_Shape* )Stg_ComponentFactory_ConstructByName( context->CF, (Name)"disk", Stg_Shape, True, 0 /* dummy */  );
+		ctx->x_b = shape->centre[0];
+	}
+	
+	ctx->temperatureField = FieldVariable_Register_GetByName( fV_Register, "TemperatureField" );
+	
+	
+	
+#if 0
+	/* Create Some FeVariables to calculate nusselt number */
+	temperatureField          = FieldVariable_Register_GetByName( fV_Register, "TemperatureField" );
+	velocityField             = FieldVariable_Register_GetByName( fV_Register, "VelocityField" );
+	
+	
+	/* To compute B */
+	/* perturbed_temperatre := T - T_0 */
+	/*
+	self->perturbed_temperatre_field = OperatorFeVariable_NewUnary(
+	"AdvectiveHeatFluxField",
+	temperatureField,
+	"VectorScale" );
+	*/
+	/* 
+	Does not appear to be anything to shift fields by a scalar. 
+	Will just assume that T0 = 0
+	*/
+	self->perturbed_temperatre_field = temperatureField;
+	
+	
+	/* To compute w_bar */
+	/* grab the second component of the velocity field ez \dot u */
+	self->vertical_velocity_field = (FeVariable*) OperatorFeVariable_NewUnary(
+			"VerticalVelocityField",
+			velocityField,
+			"TakeSecondComponent" );
+	self->vertical_velocity_field->feMesh = ((FeVariable*)velocityField)->feMesh;
+	
+	self->vT_field = OperatorFeVariable_NewBinary(
+			"VerticalAdvectiveTemperatureField",
+			temperatureField,
+			self->vertical_velocity_field,
+			"VectorScale" );
+	self->vT_field->feMesh = ((FeVariable*)velocityField)->feMesh;
+#endif
+	
+	
+	
+	/* Add names to the integrals in the frequent output */
+	StgFEM_FrequentOutput_PrintString( context, "B" );
+	StgFEM_FrequentOutput_PrintString( context, "w_bar" );
+	StgFEM_FrequentOutput_PrintString( context, "x_b" );
+	StgFEM_FrequentOutput_PrintString( context, "y_b" );
+	if (ctx->dim==3){
+	StgFEM_FrequentOutput_PrintString( context, "z_b" );
+	}
+	StgFEM_FrequentOutput_PrintString( context, "int_w_bar_dt" );
+	StgFEM_FrequentOutput_PrintString( context, "temp_b" );
+	StgFEM_FrequentOutput_PrintString( context, "temp_max" );
+	
+	
+	/* Set the initial coordinates for the cob swarm */
+	if( ctx->cob_swarm != NULL ) {
+		Swarm *swarm;
+		GlobalParticle *particle;
+		
+		/* Force swarm to allocate points so that I can set initial values */
+		Stg_Component_Build( ctx->cob_swarm, NULL, False );
+		Stg_Component_Initialise( ctx->cob_swarm, NULL, False );
+		
+		swarm = (Swarm*)ctx->cob_swarm;
+		/* Set initial coords based on existing data from input xml */
+		particle = (GlobalParticle*)Swarm_ParticleAt( swarm, 0 );
+		particle->coord[0] = ctx->x_b;
+		particle->coord[1] = ctx->y_b_initial;
+		particle->coord[2] = ctx->z_b;
+	}
+}
+
+
+void perform_integrals( UnderworldContext *context, double *B, double *w_bar, double *y_b, double *int_w_bar_dt )
+{
+	Underworld_BuoyancyIntegrals_CTX *ctx;
+	IntegrationPoint *ip;
+	double *xi;
+	double weight;
+	Particle_InCellIndex p, ngp;
+	Cell_Index cell_I;
+	double velocity[3], global_coord[3];
+	FeMesh* mesh;
+	Element_LocalIndex e;
+	
+	double i_T, i_v, i_y, i_vT; /* interpolated quantity */
+	double sum_T, sum_vT, sum_yT; /* integral sum */
+	double _sum_T, _sum_vT, _sum_yT; /* element sums */
+	double g_sum_T, g_sum_vT, g_sum_yT; /* element sums */
+	int n_elements;
+	ElementType *elementType;
+	Node_Index elementNodeCount;
+	Dimension_Index dim;
+	double det_jac, dt;
+	double **GNx;
+	double _sum_vol, sum_vol;
+	
+	FeVariable *velocityField, *temperatureField;
+	Swarm* gaussSwarm;
+	
+	ctx = (Underworld_BuoyancyIntegrals_CTX*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_BuoyancyIntegrals_Type );
+	
+	velocityField = (FeVariable* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"VelocityField" );
+	temperatureField = (FeVariable* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"TemperatureField" );
+	gaussSwarm = (Swarm* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"gaussSwarm" );
+
+	/* initialise values to compute */
+	*B = *w_bar = *y_b = -1.0;
+	*int_w_bar_dt = ctx->int_w_bar_dt;
+	
+	
+	
+#if 0
+	/* test 1 - get beta */
+	*B = ctx->beta;	
+	/* test 2 - get gravity */
+	*w_bar = ctx->gravity;
+	/* test 3 get dt */
+	*y_b = context->dt;
+#endif	
+	
+	/* evaluate some integrals */
+	
+#if 0
+	ngp = context->gaussSwarm->particleLocalCount;
+	cell_I = 0;
+	for( p = 0; p<ngp; p++ ) {
+		ip = (IntegrationPoint* )Swarm_ParticleInCellAt( context->gaussSwarm, cell_I, p );
+		xi = ip->xi;
+		weight = ip->weight;
+		///*
+		printf("[%d] w = %f : xi = %f %f \n", p, weight, xi[0], xi[1] );
+		//*/
+	}
+#endif
+	
+	/* assuming all elements are the same */
+	dim = ctx->dim;
+	elementType = FeMesh_GetElementType( velocityField->feMesh, 0 );
+	elementNodeCount = elementType->nodeCount;
+	GNx = Memory_Alloc_2DArray( double, dim, elementNodeCount, (Name)"Global Shape Function Derivatives for mayhem" );
+
+	mesh = temperatureField->feMesh;
+	
+	
+	_sum_T = _sum_vT = _sum_yT = 0.0;
+	_sum_vol = 0.0;
+	
+	ngp = gaussSwarm->particleLocalCount;
+	n_elements = FeMesh_GetElementLocalSize( mesh  );
+	//	printf("n_elements = %d \n", n_elements );
+	
+	for( e=0; e<n_elements; e++ ) {
+		cell_I = CellLayout_MapElementIdToCellId( gaussSwarm->cellLayout, e );
+		elementType = FeMesh_GetElementType( mesh, e );
+		
+		sum_T  = 0.0;
+		sum_vT = 0.0;
+		sum_yT = 0.0;
+		sum_vol = 0.0;
+		
+		i_T = i_v = i_vT = i_y = 0.0;
+		
+		for( p=0; p<ngp; p++ ) {
+			ip = (IntegrationPoint*)Swarm_ParticleInCellAt( gaussSwarm, cell_I, p );
+			xi = ip->xi;
+			weight = ip->weight;
+			
+			ElementType_ShapeFunctionsGlobalDerivs(
+					elementType,
+					mesh, e,
+					xi, dim, &det_jac, GNx );
+			
+			FeVariable_InterpolateFromMeshLocalCoord( temperatureField, mesh, e, xi, &i_T );
+			FeVariable_InterpolateFromMeshLocalCoord( velocityField,    mesh, e, xi, velocity );
+			
+			i_v = velocity[1];
+			i_vT = i_v * i_T;
+			
+			FeMesh_CoordLocalToGlobal( mesh, e, xi, global_coord );
+			i_y = global_coord[1];
+			
+			//printf("%f %f %f %f J=%f \n", i_T, i_v, i_vT, i_y, det_jac );
+			
+			sum_T  = sum_T  + weight * i_T * det_jac;
+			sum_vT = sum_vT + weight * i_vT * det_jac;
+			sum_yT = sum_yT + weight * i_y * i_T * det_jac;
+			sum_vol = sum_vol + weight * det_jac;
+		}
+		
+		_sum_T = _sum_T + sum_T;
+		_sum_vT = _sum_vT + sum_vT;
+		_sum_yT = _sum_yT + sum_yT;
+		_sum_vol = _sum_vol + sum_vol;		
+		
+	}
+	//printf("%f %f %f \n", _sum_T, _sum_vT, _sum_yT );
+	
+	
+	
+	/* all reduce */
+	MPI_Allreduce ( &_sum_T, &g_sum_T, 1, MPI_DOUBLE, MPI_SUM, context->communicator );
+	MPI_Allreduce ( &_sum_vT, &g_sum_vT, 1, MPI_DOUBLE, MPI_SUM, context->communicator );
+	MPI_Allreduce ( &_sum_yT, &g_sum_yT, 1, MPI_DOUBLE, MPI_SUM, context->communicator );
+	/*
+	MPI_Allreduce ( &_sum_vol, &g_sum_vol, 1, MPI_DOUBLE, MPI_SUM, context->communicator );
+	printf("l_sum_vol = %f \n", _sum_vol );
+	printf("g_sum_vol = %f \n", g_sum_vol );
+	*/
+	
+	*B     = ctx->gravity * ctx->beta * g_sum_T;
+	*w_bar = (ctx->gravity * ctx->beta/ *B) * g_sum_vT;
+	*y_b   = (ctx->gravity * ctx->beta/ *B) * g_sum_yT;
+	
+	dt = context->dt;
+	*int_w_bar_dt = *int_w_bar_dt + (*w_bar) * dt;
+	ctx->int_w_bar_dt = *int_w_bar_dt;
+	
+	Memory_Free( GNx );
+	
+}
+
+
+
+void eval_temperature( UnderworldContext *context, double y_b, double *temp_b )
+{
+	Underworld_BuoyancyIntegrals_CTX *ctx;
+	double global_coord[3];
+	InterpolationResult result;
+	double T;
+	FeVariable* temperatureField;
+
+	T = -66.99;
+	
+	ctx = (Underworld_BuoyancyIntegrals_CTX*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_BuoyancyIntegrals_Type );
+	
+	temperatureField = (FeVariable* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"TemperatureField"  );
+	/* Get x_b, and z_b from xml */
+	/* "cylinder" z_b = CentreZ (0.5), x_b = CentreX (1.0) */
+	if (ctx->dim==3){
+		global_coord[0] = ctx->x_b;
+		global_coord[1] = y_b;
+		global_coord[2] = ctx->z_b;
+	}
+    	if (ctx->dim==2){
+		global_coord[0] = ctx->x_b;
+		global_coord[1] = y_b;
+	}
+
+	result = FieldVariable_InterpolateValueAt( temperatureField, global_coord, &T );
+	MPI_Allreduce ( &T, temp_b, 1, MPI_DOUBLE, MPI_MAX, context->communicator );
+
+}
+
+
+void assign_coords_to_swarm( double x_b, double y_b, double z_b, MaterialPointsSwarm *cob_swarm )
+{
+	Swarm *swarm;
+	int point_count;
+	GlobalParticle *particle;
+	Particle_Index lParticle_I;
+	Stream *errorStream = Journal_Register( Error_Type, (Name)"Underworld_BuoyancyIntegrals: assign_coords_to_swarm" );
+	/* int rank; */
+	
+	/* Cast to get parent */
+	swarm = (Swarm* )cob_swarm;
+	
+	
+	/* check cob swarm only has one point */
+	point_count = swarm->particleLocalCount;
+	/*
+	MPI_Comm_rank( MPI_COMM_WORLD, &rank );
+	printf("rank[%d]: np (cob) = %d \n", rank, point_count );
+	*/
+	Journal_Firewall(
+			point_count == 1,
+			errorStream,
+			"Error in %s:\n"
+			"Swarm with name %s is be used to plot center of buoyancy.\n"
+			"This swarm contains more then 1 point. This is unexpected!!", __func__, swarm->name );
+	
+	/* get point to the first particle */
+	lParticle_I = 0;
+	particle = (GlobalParticle*)Swarm_ParticleAt( swarm, lParticle_I );
+	
+	/* Set the coorindates */
+	/*printf("*********** ASSIGNING COORDS TO COB ****************** \n");*/
+	particle->coord[0] = x_b;
+	particle->coord[1] = y_b;
+	particle->coord[2] = z_b;
+	
+}
+
+
+void Underworld_BuoyancyIntegrals_Output( UnderworldContext *context ) 
+{
+	Underworld_BuoyancyIntegrals_CTX *ctx;
+	double B, w_bar, y_b, int_w_bar_dt;
+	double temp_b; /* the temperature at (x_b,y_b,z_b) */
+	double temp_max;
+	FeVariable* temperatureField;
+	
+	perform_integrals( context, &B, &w_bar, &y_b, &int_w_bar_dt );
+	eval_temperature( context, y_b, &temp_b );
+	
+	ctx = (Underworld_BuoyancyIntegrals_CTX*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_BuoyancyIntegrals_Type );
+	
+	temperatureField = (FeVariable* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"TemperatureField"  );
+	
+	StgFEM_FrequentOutput_PrintValue( context, B );
+	StgFEM_FrequentOutput_PrintValue( context, w_bar );
+	StgFEM_FrequentOutput_PrintValue( context, ctx->x_b );
+	StgFEM_FrequentOutput_PrintValue( context, y_b );
+	if (ctx->dim==3){
+		StgFEM_FrequentOutput_PrintValue( context, ctx->z_b );
+	}
+	StgFEM_FrequentOutput_PrintValue( context, int_w_bar_dt );
+	StgFEM_FrequentOutput_PrintValue( context, temp_b );
+	
+	temp_max = _FeVariable_GetMaxGlobalFieldMagnitude( temperatureField );
+	StgFEM_FrequentOutput_PrintValue( context, temp_max );
+	
+	
+	/* assign coords of center of buoyancy to swarm (if it exists) */
+	if( ctx->cob_swarm != NULL ) {
+		assign_coords_to_swarm( ctx->x_b, y_b, ctx->z_b, ctx->cob_swarm );
+	}
+	
+	
+	
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/ConvectionData/ConvectionData.c
--- a/plugins/Output/ConvectionData/ConvectionData.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,284 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: ConvectionData.c 182 2006-05-01 12:32:01Z RobertTurnbull $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Underworld.h>
-#include <Underworld/BoundaryLayers/BoundaryLayers.h>
-#include <StgFEM/FrequentOutput/FrequentOutput.h>
-#include <assert.h>
-#include <string.h>
-
-typedef struct {
-	__Codelet
-	OperatorFeVariable*        velocitySquaredField;
-	Underworld_BoundaryLayers* boundaryLayersPlugin;
-	char*                      rheologyName;
-	double                     stressExponent;
-	double                     eta0;
-	double                     Ra;
-	double                     vrms;
-	double                     diffusivity;
-        double                     horizontalDimOfConvecCell;
-} Underworld_ConvectionData;
-
-double Underworld_ConvectionData_XZPlaneVrms( UnderworldContext* context, double yCoord_Of_XZPlane ); 
-
-const Type Underworld_ConvectionData_Type = "Underworld_ConvectionData";
-Stream* dataStream;
-
-void _Underworld_ConvectionData_Build( void* component, void* data ) {
-	Underworld_ConvectionData*	self = (Underworld_ConvectionData*)component;
-
-	assert( self );
-
-	Stg_Component_Build( self->velocitySquaredField, data, False );
-   
-   _Codelet_Build( self, data );
-}
-
-void _Underworld_ConvectionData_Destroy( void* component, void* data ) {
-	Underworld_ConvectionData*	self = (Underworld_ConvectionData*)component;
-
-   _Codelet_Destroy( self, data );
-
-	Stg_Component_Destroy( self->velocitySquaredField, data, False );
-}
-
-void _Underworld_ConvectionData_Initialise( void* component, void* data ) {
-	Underworld_ConvectionData*	self = (Underworld_ConvectionData*)component;
-
-	assert( self );
-
-	Stg_Component_Initialise( self->velocitySquaredField, data, False );
-   
-   _Codelet_Initialise( self, data );
-}
-
-void Underworld_ConvectionData_Setup( void* _context ) {
-	UnderworldContext*          context       = (UnderworldContext*) _context;
-	Underworld_ConvectionData*  self;
-	Arrhenius*                  arrhenius;
-	FrankKamenetskii*           frankKamenetskii;
-	Rheology*                   rheology;
-	NonNewtonian*               nonNewtonian;
-   Swarm*					       gaussSwarm    = (Swarm*)     LiveComponentRegister_Get( context->CF->LCRegister, (Name)"gaussSwarm" );
-	FeVariable*				       velocityField = (FeVariable* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"VelocityField"  );
-	char*  filename;
-
-	dataStream = Journal_Register( Info_Type, (Name)"ConvectionData Info Stream"  );
-	Stream_SetPrintingRank( dataStream, 0 ); /** Only prints to main proccessor */
-	
-	self = (Underworld_ConvectionData*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_ConvectionData_Type );
-	
-	rheology = (Rheology* )Stg_ComponentFactory_ConstructByName( context->CF, (Name)"temperatureDependence", Rheology, False, 0 /* dummy */ );	
-	nonNewtonian = (NonNewtonian* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)NonNewtonian_Type );
-        /* (NonNewtonian* )Stg_ComponentFactory_ConstructByName( context->CF, (Name)"nonNewtonian", NonNewtonian, True, 0 */ /* dummy */ /* );	*/
-	(nonNewtonian == NULL) ?  (self->stressExponent = 1) :
-		       	(self->stressExponent = nonNewtonian->stressExponent ) ;
-
-	if( !strcmp( rheology->type, "FrankKamenetskii" ) ) {
-		frankKamenetskii = (FrankKamenetskii*)rheology; 
-		arrhenius=NULL;
-	} else {
-		arrhenius = (Arrhenius*)rheology;
-		frankKamenetskii=NULL;
-	}
-	
-	self->diffusivity = Stg_ComponentFactory_GetRootDictDouble( context->CF, (Dictionary_Entry_Key)"diffusivity", 1.0  );
-	self->horizontalDimOfConvecCell = Stg_ComponentFactory_GetRootDictDouble( context->CF, (Dictionary_Entry_Key)"horizontalDimOfConvecCell", 1.0  );
-	self->Ra = Stg_ComponentFactory_GetRootDictDouble( context->CF, (Dictionary_Entry_Key)"Ra", 1.0 );
-	
-	self->eta0 = ( arrhenius != NULL ? arrhenius->eta0 : frankKamenetskii->eta0 );
-        /*	self->stressExponent = nonNewtonian->stressExponent; */
-	self->rheologyName = rheology->type;/*( arrhenius != NULL ? StG_Strdup(arrhenius->type) : StG_Strdup(frankKamenetskii->type) ); */
-	self->boundaryLayersPlugin = (Underworld_BoundaryLayers* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_BoundaryLayers_Type  );
-	Journal_Firewall( self->boundaryLayersPlugin != NULL, Underworld_Error, "Error in %s. Cannot find the BoundaryLayers Plugin. Make sure <param>Underworld_BoundaryLayers</param> is in your plugins list\n");
-
-	Journal_Firewall( 
-			gaussSwarm != NULL, 
-			Underworld_Error,
-			"Cannot find gauss swarm. Cannot use %s.\n", CURR_MODULE_NAME );
-	Journal_Firewall( 
-			velocityField != NULL, 
-			Underworld_Error,
-			"Cannot find velocityField. Cannot use %s.\n", CURR_MODULE_NAME );
-
-	/* Create new Field Variable */
-	self->velocitySquaredField = OperatorFeVariable_NewUnary(
-      "VelocitySquaredField",
-      (DomainContext*)context,
-      (void*)velocityField, 
-      "VectorSquare" );
-
-	Stg_asprintf( &filename, "ConvectionData.%dof%d.dat", context->rank, context->nproc );
-	Stream_RedirectFile_WithPrependedPath( dataStream, context->outputPath, filename );
-	Stream_SetAutoFlush( dataStream, True );
-	/* Print Header */
-	Journal_Printf( dataStream, "#Rheology | etaContrast | Ra | UpperVrms | LowerVrms | UTBL | LTBL | SurfaceMobility\n");
-	Memory_Free( filename );
-
-}
-
-void Underworld_ConvectionData_Dump( void* _context ) {
-	UnderworldContext*         context = (UnderworldContext*) _context;
-	Underworld_ConvectionData* self;
-	Mesh*			   mesh;
-	double		    	   maxCrd[3], minCrd[3];
-	double                     topVrms;
-	double                     bottomVrms;
-	double                     Upper_tbl_Thinckness;
-	double                     Lower_tbl_Thinckness;
-	double                     surfaceMobility;
-	double                     deltaViscosity;
-
-	self = (Underworld_ConvectionData*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_ConvectionData_Type  );
-
-	Journal_Printf( dataStream, "ID = %s_%.3g_%.3g_%.3g\n", self->rheologyName, self->stressExponent, self->eta0, self->Ra ); 
-
-	mesh = (Mesh*)self->velocitySquaredField->feMesh;
-	Mesh_GetGlobalCoordRange( mesh, minCrd, maxCrd );
-
-	assert( self->stressExponent != 0 );
-	deltaViscosity = pow(self->eta0, (-1/self->stressExponent) );
-	Journal_Printf( dataStream, "%s %g %g ", self->rheologyName, deltaViscosity, self->Ra ); 
-	
-	/* Prints out Surface Vrms  */
-	topVrms = Underworld_ConvectionData_XZPlaneVrms( context, maxCrd[ J_AXIS ] );
-	Journal_Printf( dataStream, " %g", topVrms );
-
-	bottomVrms = Underworld_ConvectionData_XZPlaneVrms( context, minCrd[ J_AXIS ] );
-	Journal_Printf( dataStream, " %g", bottomVrms );
-	
-	Upper_tbl_Thinckness = self->boundaryLayersPlugin->hotLayerThickness;
-	Journal_Printf( dataStream, " %g", Upper_tbl_Thinckness );
-
-	Lower_tbl_Thinckness = self->boundaryLayersPlugin->coldLayerThickness;
-	Journal_Printf( dataStream, " %g", Lower_tbl_Thinckness );
-
-	surfaceMobility = ( Upper_tbl_Thinckness * topVrms ) / ( self->diffusivity * self->horizontalDimOfConvecCell );
-	Journal_Printf( dataStream, " %g", surfaceMobility );
-/*
-*/
-	Journal_Printf( dataStream, "\n" );
-}
-	
-
-double Underworld_ConvectionData_XZPlaneVrms( UnderworldContext* context, double yCoord_Of_XZPlane ) {
-	Mesh*			   	     mesh;
-	double		    	  	     maxCrd[3], minCrd[3];
-	double                               integral;
-	double                               samplingSpace = 0.0;
-	Dimension_Index                      dim           = context->dim;
-
-	Underworld_ConvectionData* self;
-
-	mesh = (Mesh*)self->velocitySquaredField->feMesh;
-	Mesh_GetGlobalCoordRange( mesh, minCrd, maxCrd );
-
-	/*
-	TODO:PAT help:
-	   Here I would like to get the VelocitySquareField instead of getting the whole plugin
-	 */
-	self = (Underworld_ConvectionData*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_ConvectionData_Type  );
-	
-	/* Sum integral */
-	integral = FeVariable_IntegratePlane( self->velocitySquaredField, J_AXIS, yCoord_Of_XZPlane );
-
-	/* Get Volume of Mesh - TODO Make general for irregular meshes */
-	samplingSpace = ( maxCrd[ I_AXIS ] - minCrd[ I_AXIS ] ); 
-		
-	if ( dim == 3 ) 
-		samplingSpace *= maxCrd[ K_AXIS ] - minCrd[ K_AXIS ];
-
-	/* Calculate ConvectionData 
-	 * V_{rms} = \sqrt{ \frac{ \int_\Omega \mathbf{u . u} d\Omega }{\Omega} } */
-
-	return ( sqrt( integral / samplingSpace ) ) ;
-
-}
-	
-void _Underworld_ConvectionData_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
-	UnderworldContext*  context;
-
-	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data  );
-
-	ContextEP_Append( context, AbstractContext_EP_AssignFromXMLExtensions, Underworld_ConvectionData_Setup );
-	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, Underworld_ConvectionData_Dump );
-}
-
-void _Underworld_ConvectionData_Delete( void* component ) {
-	Underworld_ConvectionData* self = (Underworld_ConvectionData*) component;
-
-	if( self->rheologyName )
-		Memory_Free( self->rheologyName );
-	_Codelet_Delete( self );
-}
-void* _Underworld_ConvectionData_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Underworld_ConvectionData);
-	Type                                                      type = Underworld_ConvectionData_Type;
-	Stg_Class_DeleteFunction*                              _delete = _Underworld_ConvectionData_Delete;
-	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
-	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_ConvectionData_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Underworld_ConvectionData_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 Underworld_ConvectionData_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Underworld_ConvectionData_Type, (Name)"0", _Underworld_ConvectionData_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/ConvectionData/ConvectionData.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/Output/ConvectionData/ConvectionData.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,284 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: ConvectionData.c 182 2006-05-01 12:32:01Z RobertTurnbull $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Underworld.h>
+#include <Underworld/BoundaryLayers/BoundaryLayers.h>
+#include <StgFEM/FrequentOutput/FrequentOutput.h>
+#include <assert.h>
+#include <string.h>
+
+typedef struct {
+	__Codelet
+	OperatorFeVariable*        velocitySquaredField;
+	Underworld_BoundaryLayers* boundaryLayersPlugin;
+	char*                      rheologyName;
+	double                     stressExponent;
+	double                     eta0;
+	double                     Ra;
+	double                     vrms;
+	double                     diffusivity;
+        double                     horizontalDimOfConvecCell;
+} Underworld_ConvectionData;
+
+double Underworld_ConvectionData_XZPlaneVrms( UnderworldContext* context, double yCoord_Of_XZPlane ); 
+
+const Type Underworld_ConvectionData_Type = "Underworld_ConvectionData";
+Stream* dataStream;
+
+void _Underworld_ConvectionData_Build( void* component, void* data ) {
+	Underworld_ConvectionData*	self = (Underworld_ConvectionData*)component;
+
+	assert( self );
+
+	Stg_Component_Build( self->velocitySquaredField, data, False );
+   
+   _Codelet_Build( self, data );
+}
+
+void _Underworld_ConvectionData_Destroy( void* component, void* data ) {
+	Underworld_ConvectionData*	self = (Underworld_ConvectionData*)component;
+
+   _Codelet_Destroy( self, data );
+
+	Stg_Component_Destroy( self->velocitySquaredField, data, False );
+}
+
+void _Underworld_ConvectionData_Initialise( void* component, void* data ) {
+	Underworld_ConvectionData*	self = (Underworld_ConvectionData*)component;
+
+	assert( self );
+
+	Stg_Component_Initialise( self->velocitySquaredField, data, False );
+   
+   _Codelet_Initialise( self, data );
+}
+
+void Underworld_ConvectionData_Setup( void* _context ) {
+	UnderworldContext*          context       = (UnderworldContext*) _context;
+	Underworld_ConvectionData*  self;
+	Arrhenius*                  arrhenius;
+	FrankKamenetskii*           frankKamenetskii;
+	Rheology*                   rheology;
+	NonNewtonian*               nonNewtonian;
+   Swarm*					       gaussSwarm    = (Swarm*)     LiveComponentRegister_Get( context->CF->LCRegister, (Name)"gaussSwarm" );
+	FeVariable*				       velocityField = (FeVariable* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"VelocityField"  );
+	char*  filename;
+
+	dataStream = Journal_Register( Info_Type, (Name)"ConvectionData Info Stream"  );
+	Stream_SetPrintingRank( dataStream, 0 ); /** Only prints to main proccessor */
+	
+	self = (Underworld_ConvectionData*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_ConvectionData_Type );
+	
+	rheology = (Rheology* )Stg_ComponentFactory_ConstructByName( context->CF, (Name)"temperatureDependence", Rheology, False, 0 /* dummy */ );	
+	nonNewtonian = (NonNewtonian* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)NonNewtonian_Type );
+        /* (NonNewtonian* )Stg_ComponentFactory_ConstructByName( context->CF, (Name)"nonNewtonian", NonNewtonian, True, 0 */ /* dummy */ /* );	*/
+	(nonNewtonian == NULL) ?  (self->stressExponent = 1) :
+		       	(self->stressExponent = nonNewtonian->stressExponent ) ;
+
+	if( !strcmp( rheology->type, "FrankKamenetskii" ) ) {
+		frankKamenetskii = (FrankKamenetskii*)rheology; 
+		arrhenius=NULL;
+	} else {
+		arrhenius = (Arrhenius*)rheology;
+		frankKamenetskii=NULL;
+	}
+	
+	self->diffusivity = Stg_ComponentFactory_GetRootDictDouble( context->CF, (Dictionary_Entry_Key)"diffusivity", 1.0  );
+	self->horizontalDimOfConvecCell = Stg_ComponentFactory_GetRootDictDouble( context->CF, (Dictionary_Entry_Key)"horizontalDimOfConvecCell", 1.0  );
+	self->Ra = Stg_ComponentFactory_GetRootDictDouble( context->CF, (Dictionary_Entry_Key)"Ra", 1.0 );
+	
+	self->eta0 = ( arrhenius != NULL ? arrhenius->eta0 : frankKamenetskii->eta0 );
+        /*	self->stressExponent = nonNewtonian->stressExponent; */
+	self->rheologyName = rheology->type;/*( arrhenius != NULL ? StG_Strdup(arrhenius->type) : StG_Strdup(frankKamenetskii->type) ); */
+	self->boundaryLayersPlugin = (Underworld_BoundaryLayers* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_BoundaryLayers_Type  );
+	Journal_Firewall( self->boundaryLayersPlugin != NULL, Underworld_Error, "Error in %s. Cannot find the BoundaryLayers Plugin. Make sure <param>Underworld_BoundaryLayers</param> is in your plugins list\n");
+
+	Journal_Firewall( 
+			gaussSwarm != NULL, 
+			Underworld_Error,
+			"Cannot find gauss swarm. Cannot use %s.\n", CURR_MODULE_NAME );
+	Journal_Firewall( 
+			velocityField != NULL, 
+			Underworld_Error,
+			"Cannot find velocityField. Cannot use %s.\n", CURR_MODULE_NAME );
+
+	/* Create new Field Variable */
+	self->velocitySquaredField = OperatorFeVariable_NewUnary(
+      "VelocitySquaredField",
+      (DomainContext*)context,
+      (void*)velocityField, 
+      "VectorSquare" );
+
+	Stg_asprintf( &filename, "ConvectionData.%dof%d.dat", context->rank, context->nproc );
+	Stream_RedirectFile_WithPrependedPath( dataStream, context->outputPath, filename );
+	Stream_SetAutoFlush( dataStream, True );
+	/* Print Header */
+	Journal_Printf( dataStream, "#Rheology | etaContrast | Ra | UpperVrms | LowerVrms | UTBL | LTBL | SurfaceMobility\n");
+	Memory_Free( filename );
+
+}
+
+void Underworld_ConvectionData_Dump( void* _context ) {
+	UnderworldContext*         context = (UnderworldContext*) _context;
+	Underworld_ConvectionData* self;
+	Mesh*			   mesh;
+	double		    	   maxCrd[3], minCrd[3];
+	double                     topVrms;
+	double                     bottomVrms;
+	double                     Upper_tbl_Thinckness;
+	double                     Lower_tbl_Thinckness;
+	double                     surfaceMobility;
+	double                     deltaViscosity;
+
+	self = (Underworld_ConvectionData*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_ConvectionData_Type  );
+
+	Journal_Printf( dataStream, "ID = %s_%.3g_%.3g_%.3g\n", self->rheologyName, self->stressExponent, self->eta0, self->Ra ); 
+
+	mesh = (Mesh*)self->velocitySquaredField->feMesh;
+	Mesh_GetGlobalCoordRange( mesh, minCrd, maxCrd );
+
+	assert( self->stressExponent != 0 );
+	deltaViscosity = pow(self->eta0, (-1/self->stressExponent) );
+	Journal_Printf( dataStream, "%s %g %g ", self->rheologyName, deltaViscosity, self->Ra ); 
+	
+	/* Prints out Surface Vrms  */
+	topVrms = Underworld_ConvectionData_XZPlaneVrms( context, maxCrd[ J_AXIS ] );
+	Journal_Printf( dataStream, " %g", topVrms );
+
+	bottomVrms = Underworld_ConvectionData_XZPlaneVrms( context, minCrd[ J_AXIS ] );
+	Journal_Printf( dataStream, " %g", bottomVrms );
+	
+	Upper_tbl_Thinckness = self->boundaryLayersPlugin->hotLayerThickness;
+	Journal_Printf( dataStream, " %g", Upper_tbl_Thinckness );
+
+	Lower_tbl_Thinckness = self->boundaryLayersPlugin->coldLayerThickness;
+	Journal_Printf( dataStream, " %g", Lower_tbl_Thinckness );
+
+	surfaceMobility = ( Upper_tbl_Thinckness * topVrms ) / ( self->diffusivity * self->horizontalDimOfConvecCell );
+	Journal_Printf( dataStream, " %g", surfaceMobility );
+/*
+*/
+	Journal_Printf( dataStream, "\n" );
+}
+	
+
+double Underworld_ConvectionData_XZPlaneVrms( UnderworldContext* context, double yCoord_Of_XZPlane ) {
+	Mesh*			   	     mesh;
+	double		    	  	     maxCrd[3], minCrd[3];
+	double                               integral;
+	double                               samplingSpace = 0.0;
+	Dimension_Index                      dim           = context->dim;
+
+	Underworld_ConvectionData* self;
+
+	mesh = (Mesh*)self->velocitySquaredField->feMesh;
+	Mesh_GetGlobalCoordRange( mesh, minCrd, maxCrd );
+
+	/*
+	TODO:PAT help:
+	   Here I would like to get the VelocitySquareField instead of getting the whole plugin
+	 */
+	self = (Underworld_ConvectionData*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_ConvectionData_Type  );
+	
+	/* Sum integral */
+	integral = FeVariable_IntegratePlane( self->velocitySquaredField, J_AXIS, yCoord_Of_XZPlane );
+
+	/* Get Volume of Mesh - TODO Make general for irregular meshes */
+	samplingSpace = ( maxCrd[ I_AXIS ] - minCrd[ I_AXIS ] ); 
+		
+	if ( dim == 3 ) 
+		samplingSpace *= maxCrd[ K_AXIS ] - minCrd[ K_AXIS ];
+
+	/* Calculate ConvectionData 
+	 * V_{rms} = \sqrt{ \frac{ \int_\Omega \mathbf{u . u} d\Omega }{\Omega} } */
+
+	return ( sqrt( integral / samplingSpace ) ) ;
+
+}
+	
+void _Underworld_ConvectionData_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
+	UnderworldContext*  context;
+
+	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data  );
+
+	ContextEP_Append( context, AbstractContext_EP_AssignFromXMLExtensions, Underworld_ConvectionData_Setup );
+	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, Underworld_ConvectionData_Dump );
+}
+
+void _Underworld_ConvectionData_Delete( void* component ) {
+	Underworld_ConvectionData* self = (Underworld_ConvectionData*) component;
+
+	if( self->rheologyName )
+		Memory_Free( self->rheologyName );
+	_Codelet_Delete( self );
+}
+void* _Underworld_ConvectionData_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Underworld_ConvectionData);
+	Type                                                      type = Underworld_ConvectionData_Type;
+	Stg_Class_DeleteFunction*                              _delete = _Underworld_ConvectionData_Delete;
+	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
+	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_ConvectionData_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Underworld_ConvectionData_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 Underworld_ConvectionData_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Underworld_ConvectionData_Type, (Name)"0", _Underworld_ConvectionData_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/CylinderNodeProfiling/CylinderNodeProfiling.c
--- a/plugins/Output/CylinderNodeProfiling/CylinderNodeProfiling.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,170 +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: TempNodeHeight.c 340 2006-06-27 00:54:55Z AlanLo $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <assert.h>
-
-const Type Experimental_CylinderNodeProfiling = "Experimental_CylinderNodeProfiling";
-
-void Experimental_NodeTempProfile( PICelleratorContext* context ) {
-#if 0
-	static FeVariable*          temperatureFe;
-	FiniteElement_Mesh*         mesh;
-	double*                     nodeCoord;
-	double                      lmaxTemp, nodeTemp;
-	Index                       lNode_I, newNodeID;
-	int                         startProfileNodeID; 
-	static Bool                 beenHere              = False;
-	Stream*                     stream                = Journal_Register( Info_Type, (Name)"TempNodeHeight"  );
-	char*                       filename;
-	double*                     maxTempList = Memory_Alloc_Array( double, context->nproc, "Hold the max temperature of each array");
-	unsigned                    rootProc;
-	
-	rootProc = 0;
-	if (!beenHere) {
-		Name                 tempFeName;
-		tempFeName = Dictionary_GetString_WithDefault( context->dictionary, "TemperatureField", "TemperatureField" );
-		
-		/* Get TemperatureField FeVariable */
-		temperatureFe = (FeVariable*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)tempFeName );
-		assert( temperatureFe  );
-	
-		/* Set up stream */
-		Stg_asprintf( &filename, "CylinderNodeProfiling.%dof%d.dat", context->rank, context->nproc );
-		Stream_RedirectFile_WithPrependedPath( stream, context->outputPath, filename );
-		Memory_Free( filename );
-		Stream_SetAutoFlush( stream, True );
-
-		/* Print header to stream */
-		Journal_Printf( stream, "Timestep\tCentralPosition\t\tNodeTemperature\n" );
-		beenHere = True;
-	}
-	mesh = temperatureFe->feMesh;
-	
-	for( lNode_I = 0; lNode_I < temperatureFe->feMesh->nodeLocalCount ; lNode_I++ ) {
-		nodeTemp = FeVariable_GetScalarAtNode( temperatureFe , lNode_I );
-		if( lNode_I == 0 ) {
-			lmaxTemp = nodeTemp;
-			startProfileNodeID = lNode_I;
-		}
-		if ( nodeTemp > lmaxTemp ) {
-			lmaxTemp = nodeTemp;
-			startProfileNodeID = lNode_I;
-		}
-	}
-	MPI_Gather( &lmaxTemp, 1, MPI_DOUBLE, maxTempList, 1, MPI_DOUBLE, rootProc, context->communicator );
-
-	Journal_Printf( stream, "%.6g   ******************************\n", (double)context->timeStep );
-	nodeCoord = Mesh_CoordAt( mesh , startProfileNodeID );
-	nodeTemp  = FeVariable_GetScalarAtNode( temperatureFe, startProfileNodeID );
-	Journal_Printf( stream, "\t\tNode Profile in Y direction, starting at (%.6g, %.6g, %.6g)\tat temperature = %g\n",
-				nodeCoord[0], nodeCoord[1], nodeCoord[2], nodeTemp );
-
-	newNodeID = mesh->nodeNeighbourTbl[ startProfileNodeID ][ 1 ]; /* 1 = +y direction, 2 = +z direction */
-	if( newNodeID >= mesh->nodeLocalCount ) { /* is node NOT a local, thus stop profiling */
-		Journal_Printf( stream, "\t\tProfiling has reached the boundary of the local processor\n");
-	} else {  /* continue profiling */
-		nodeTemp = FeVariable_GetScalarAtNode( temperatureFe, newNodeID );
-		while( nodeTemp > 0.0 ) {
-			nodeCoord = Mesh_CoordAt( mesh, newNodeID );
-			Journal_Printf( stream, "\t\t (%.6g, %.6g, %.6g)\tat temperature = %g\n", nodeCoord[0], nodeCoord[1], nodeCoord[2], nodeTemp );
-			newNodeID = mesh->nodeNeighbourTbl[ newNodeID ][ 1 ];
-			if( newNodeID >= mesh->nodeLocalCount ) {
-                          /* is node not a local i.e. not on processor, tus stop profiling	 */
-				Journal_Printf( stream, "\t\tProfiling has reached the boundary of the local processor\n");
-				break;
-			}
-			nodeTemp = FeVariable_GetScalarAtNode( temperatureFe, newNodeID );
-		}
-	}
-	Memory_Free( maxTempList );
-	MPI_Barrier( context->communicator );
-#endif
-}
-
-void _Experimental_CylinderNodeProfiling_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
-
-	AbstractContext* context;
-	FeVariable*  temperatureField  = Stg_ComponentFactory_ConstructByName( cf, (Name)"TemperatureField", FeVariable, True, data  );
-	FeMesh* mesh     = temperatureField->feMesh;
-
-	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  );
-	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, Experimental_NodeTempProfile );
-}
-
-
-void* _Experimental_CylinderNodeProfiling_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof( Codelet );
-	Type                                                      type = Experimental_CylinderNodeProfiling;
-	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
-	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
-	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Experimental_CylinderNodeProfiling_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Experimental_CylinderNodeProfiling_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 Experimental_CylinderNodeProfiling_Register( PluginsManager* pluginsManager ) {
-	Index result;
-
-	result = PluginsManager_Submit( pluginsManager, Experimental_CylinderNodeProfiling, (Name)"0", _Experimental_CylinderNodeProfiling_DefaultNew  );
-
-	return result;
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/CylinderNodeProfiling/CylinderNodeProfiling.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/Output/CylinderNodeProfiling/CylinderNodeProfiling.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,170 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** 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: TempNodeHeight.c 340 2006-06-27 00:54:55Z AlanLo $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <assert.h>
+
+const Type Experimental_CylinderNodeProfiling = "Experimental_CylinderNodeProfiling";
+
+void Experimental_NodeTempProfile( PICelleratorContext* context ) {
+#if 0
+	static FeVariable*          temperatureFe;
+	FiniteElement_Mesh*         mesh;
+	double*                     nodeCoord;
+	double                      lmaxTemp, nodeTemp;
+	Index                       lNode_I, newNodeID;
+	int                         startProfileNodeID; 
+	static Bool                 beenHere              = False;
+	Stream*                     stream                = Journal_Register( Info_Type, (Name)"TempNodeHeight"  );
+	char*                       filename;
+	double*                     maxTempList = Memory_Alloc_Array( double, context->nproc, "Hold the max temperature of each array");
+	unsigned                    rootProc;
+	
+	rootProc = 0;
+	if (!beenHere) {
+		Name                 tempFeName;
+		tempFeName = Dictionary_GetString_WithDefault( context->dictionary, "TemperatureField", "TemperatureField" );
+		
+		/* Get TemperatureField FeVariable */
+		temperatureFe = (FeVariable*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)tempFeName );
+		assert( temperatureFe  );
+	
+		/* Set up stream */
+		Stg_asprintf( &filename, "CylinderNodeProfiling.%dof%d.dat", context->rank, context->nproc );
+		Stream_RedirectFile_WithPrependedPath( stream, context->outputPath, filename );
+		Memory_Free( filename );
+		Stream_SetAutoFlush( stream, True );
+
+		/* Print header to stream */
+		Journal_Printf( stream, "Timestep\tCentralPosition\t\tNodeTemperature\n" );
+		beenHere = True;
+	}
+	mesh = temperatureFe->feMesh;
+	
+	for( lNode_I = 0; lNode_I < temperatureFe->feMesh->nodeLocalCount ; lNode_I++ ) {
+		nodeTemp = FeVariable_GetScalarAtNode( temperatureFe , lNode_I );
+		if( lNode_I == 0 ) {
+			lmaxTemp = nodeTemp;
+			startProfileNodeID = lNode_I;
+		}
+		if ( nodeTemp > lmaxTemp ) {
+			lmaxTemp = nodeTemp;
+			startProfileNodeID = lNode_I;
+		}
+	}
+	MPI_Gather( &lmaxTemp, 1, MPI_DOUBLE, maxTempList, 1, MPI_DOUBLE, rootProc, context->communicator );
+
+	Journal_Printf( stream, "%.6g   ******************************\n", (double)context->timeStep );
+	nodeCoord = Mesh_CoordAt( mesh , startProfileNodeID );
+	nodeTemp  = FeVariable_GetScalarAtNode( temperatureFe, startProfileNodeID );
+	Journal_Printf( stream, "\t\tNode Profile in Y direction, starting at (%.6g, %.6g, %.6g)\tat temperature = %g\n",
+				nodeCoord[0], nodeCoord[1], nodeCoord[2], nodeTemp );
+
+	newNodeID = mesh->nodeNeighbourTbl[ startProfileNodeID ][ 1 ]; /* 1 = +y direction, 2 = +z direction */
+	if( newNodeID >= mesh->nodeLocalCount ) { /* is node NOT a local, thus stop profiling */
+		Journal_Printf( stream, "\t\tProfiling has reached the boundary of the local processor\n");
+	} else {  /* continue profiling */
+		nodeTemp = FeVariable_GetScalarAtNode( temperatureFe, newNodeID );
+		while( nodeTemp > 0.0 ) {
+			nodeCoord = Mesh_CoordAt( mesh, newNodeID );
+			Journal_Printf( stream, "\t\t (%.6g, %.6g, %.6g)\tat temperature = %g\n", nodeCoord[0], nodeCoord[1], nodeCoord[2], nodeTemp );
+			newNodeID = mesh->nodeNeighbourTbl[ newNodeID ][ 1 ];
+			if( newNodeID >= mesh->nodeLocalCount ) {
+                          /* is node not a local i.e. not on processor, tus stop profiling	 */
+				Journal_Printf( stream, "\t\tProfiling has reached the boundary of the local processor\n");
+				break;
+			}
+			nodeTemp = FeVariable_GetScalarAtNode( temperatureFe, newNodeID );
+		}
+	}
+	Memory_Free( maxTempList );
+	MPI_Barrier( context->communicator );
+#endif
+}
+
+void _Experimental_CylinderNodeProfiling_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
+
+	AbstractContext* context;
+	FeVariable*  temperatureField  = Stg_ComponentFactory_ConstructByName( cf, (Name)"TemperatureField", FeVariable, True, data  );
+	FeMesh* mesh     = temperatureField->feMesh;
+
+	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  );
+	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, Experimental_NodeTempProfile );
+}
+
+
+void* _Experimental_CylinderNodeProfiling_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof( Codelet );
+	Type                                                      type = Experimental_CylinderNodeProfiling;
+	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
+	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
+	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Experimental_CylinderNodeProfiling_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Experimental_CylinderNodeProfiling_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 Experimental_CylinderNodeProfiling_Register( PluginsManager* pluginsManager ) {
+	Index result;
+
+	result = PluginsManager_Submit( pluginsManager, Experimental_CylinderNodeProfiling, (Name)"0", _Experimental_CylinderNodeProfiling_DefaultNew  );
+
+	return result;
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/Localisation/Localisation.c
--- a/plugins/Output/Localisation/Localisation.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,578 +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:
-*+              Robert Turnbull
-*+              Vincent Lemiale
-*+              Louis Moresi
-*+              David May
-*+              David Stegman
-*+              Mirko Velic
-*+              Patrick Sunter
-*+              Julian Giordani
-*+
-** $Id:  $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Underworld.h>
-#include <StgFEM/FrequentOutput/FrequentOutput.h>
-
-#include "Localisation.h"
-
-unsigned     globPartInc;
-MPI_Datatype Localisation_MPI_Datatype;
-
-const Type Underworld_Localisation_Type = "Underworld_Localisation";
-
-void _Underworld_Localisation_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
-        UnderworldContext* context;
-
-        context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data ); 
-
-        /* Add functions to entry points */
-        Underworld_Localisation_Setup( context  );
-        ContextEP_Append( context, AbstractContext_EP_FrequentOutput, Underworld_Localisation_Output );
-}
-
-void _Underworld_Localisation_Build( void* component, void* data ) {
-        Underworld_Localisation*        self = (Underworld_Localisation*)component;
-
-        Stg_Component_Build( self->reducedStrainRateFieldInvariantRoot, data, False );
-
-}
-
-void* _Underworld_Localisation_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Underworld_Localisation);
-	Type                                                      type = Underworld_Localisation_Type;
-	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
-	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
-	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_Localisation_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Underworld_Localisation_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _Underworld_Localisation_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 Underworld_Localisation_Register( PluginsManager* pluginsManager ) {
-        return PluginsManager_Submit( pluginsManager, Underworld_Localisation_Type, (Name)"0", _Underworld_Localisation_DefaultNew );
-}
-
-void Underworld_Localisation_Setup( UnderworldContext* context ) {
-        FieldVariable_Register*  fV_Register               = context->fieldVariable_Register;
-        FieldVariable*           strainRateField;
-        Func_Ptr                 _carryOut;
-        Dof_Index                resultDofs;
-        Dof_Index                operandDofs;
-        Index                    numberOfOperands;
-        Operator*                ownOperator;
-        Dimension_Index          dim;
-        Swarm*					      gaussSwarm = (Swarm* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"gaussSwarm" );
-
-        Underworld_Localisation* self;
-
-        /* create datatype for MPI communications */
-        Localisation_Create_MPI_Datatype();
-        
-        self = (Underworld_Localisation* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_Localisation_Type  );
-        
-        StgFEM_FrequentOutput_PrintString( context, "Localisation" );
-
-	/* get localisation parameter */
-	self->deformationFactor = Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"localisationDeformationFactor", 0.8  );
-
-        Journal_Firewall( 
-                        gaussSwarm != NULL, 
-                        Underworld_Error,
-                        "Cannot find gauss swarm. Cannot use %s.\n", CURR_MODULE_NAME );
-
-        /* create Some FeVariables to determine Localisation */
-        strainRateField  = FieldVariable_Register_GetByName( fV_Register, "StrainRateField" );
-
-        dim = strainRateField->dim;
-        /* setup required parameters to create new operate */
-        resultDofs       = 1 ;
-        numberOfOperands = 1 ;
-        operandDofs      = ( dim == 2 ? 3 : 6 );
-        _carryOut        = ( dim == 2 ? Underworld_Localisation_SymmetricTensor_LowerDimension_InvariantRoot_2d : Underworld_Localisation_SymmetricTensor_LowerDimension_InvariantRoot_3d );
-        
-        ownOperator = Operator_New( "Localisation_SymmetricTensor_LowerDimension_InvariantRoot", _carryOut, numberOfOperands, operandDofs, resultDofs, dim );
-
-        self->reducedStrainRateFieldInvariantRoot = OperatorFeVariable_NewUnary_OwnOperator(
-                        "ReducedStrainRateFieldInvariantRoot",
-                        (DomainContext*)	context,
-                        strainRateField, 
-                        ownOperator );
-
-        /* add the variables to register so we can checkpoint & examine if necessary */
-        FieldVariable_Register_Add( fV_Register, self->reducedStrainRateFieldInvariantRoot );
-        
-}
-
-void Underworld_Localisation_Output( UnderworldContext* context ) {
-        Underworld_Localisation* self;
-        double   totalIntegral;
-        double   integralSoFar;
-        double   weightSoFar;
-        double   weightSoFar2;
-        double   *min, *max;
-        double   translate;
-        int meshSizeJ = Dictionary_GetInt_WithDefault( context->dictionary, (Dictionary_Entry_Key)"elementResJ", 1  );
-        int ii;
-        int aa;
-        int numPoints;
-        int numPointsGlob;
-        int numPointsProc;
-	int myRank;
-	int nProcs;
-	MPI_Status         status;        
-	IntegrandWeightStruct* integrandWeightGlob;
-        const int FINISHED_WRITING_TAG = 100;
-
-        MPI_Comm_size( context->communicator, (int*)&nProcs );
-        MPI_Comm_rank( context->communicator, (int*)&myRank );
-
-        globPartInc = 0;
-        
-        self = (Underworld_Localisation*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_Localisation_Type  );
-
-        /* find the size of the domain */
-        min = Memory_Alloc_Array_Unnamed( double, Mesh_GetDimSize( self->reducedStrainRateFieldInvariantRoot->feMesh ) );
-        max = Memory_Alloc_Array_Unnamed( double, Mesh_GetDimSize( self->reducedStrainRateFieldInvariantRoot->feMesh ) );
-
-        Mesh_GetGlobalCoordRange( self->reducedStrainRateFieldInvariantRoot->feMesh, min, max );
-        
-        translate = ( max[ J_AXIS ] - min[ J_AXIS ] ) / (2*meshSizeJ);
-
-        /* create arrays to store the integral sum integrands and weights */
-        /* first determine how large array needs to be */
-        /* factor of 2 or 4 allows for number of particles used to integrate surface */
-        if(self->reducedStrainRateFieldInvariantRoot->dim == 2)
-           numPoints = 2*Localisation_FindTotElements( self->reducedStrainRateFieldInvariantRoot , J_AXIS, max[ J_AXIS ] - translate );
-        else
-           numPoints = 2*Localisation_FindTotElements( self->reducedStrainRateFieldInvariantRoot , J_AXIS, max[ J_AXIS ] - translate );
-        
-        self->integrandWeight  = Memory_Alloc_Array_Unnamed( IntegrandWeightStruct, numPoints );
-                
-        /* use modified integrate plane routine to do the work!
-           these routines store the integrand values, and corresponding weights, for each particle used to 
-           construct the integral.. these are then qsort(ed) by integrand value, and summed starting at the top, until 
-           a set percentage of the total integral is reached.. the ratio of the weight of all the thus far counted particles, 
-           to all the particles, is then the localisation value. */
-        totalIntegral = Localisation_IntegratePlane( self->reducedStrainRateFieldInvariantRoot, J_AXIS, max[ J_AXIS ] - translate, self );
-	
-	/* find the total global number of integration points */
-	MPI_Allreduce( &globPartInc, &numPointsGlob, 1, MPI_INT, MPI_SUM, context->communicator );
-        
-        /* collect data */
-        if ( myRank == 0 ) {
-                int count = 0;
-                /* allocate global list array */
-                integrandWeightGlob = Memory_Alloc_Array_Unnamed( IntegrandWeightStruct, numPointsGlob );
-                
-                /* first copy the rank=0 data into the global array */
-                for(ii = 0; ii < globPartInc; ii++){
-                        integrandWeightGlob[ii].integrand = self->integrandWeight[ii].integrand;
-                        integrandWeightGlob[ii].weight    = self->integrandWeight[ii].weight;
-                        count += 1;
-                }
-                
-                /* collect data from other processors. */
-                for(aa = 1; aa < nProcs; aa++){
-                        /* first get the size of the processors array */
-                        MPI_Recv( &numPointsProc, 1, MPI_INT, aa, FINISHED_WRITING_TAG, context->communicator, &status );
-                        /* get the data */
-                        MPI_Recv( integrandWeightGlob+count, numPointsProc, Localisation_MPI_Datatype, aa, FINISHED_WRITING_TAG, context->communicator, &status );
-                        /*find position for next dataset to be placed*/
-                        count += numPointsProc;
-                }
-        } else {
-                        /* send the size of this processors array */
-                        MPI_Ssend( &globPartInc, 1, MPI_INT, 0, FINISHED_WRITING_TAG, context->communicator );
-                        /* send the data */
-                        MPI_Ssend( self->integrandWeight, globPartInc, Localisation_MPI_Datatype, 0, FINISHED_WRITING_TAG, context->communicator );
-        }
-        /* now determine localisation */
-        if ( myRank == 0 ) {
-                /* sort data array in ascending order (smallest integral contributor placed first in array) */ 
-                qsort( integrandWeightGlob, numPointsGlob, sizeof( IntegrandWeightStruct ), _QsortIntegrand );
-                /* sum integral contributors, starting from the largest values, and stopping once integral contributions exceed deformationFactor*totalIntegral */
-                integralSoFar = 0.;
-                weightSoFar   = 0.;
-                for(ii = numPointsGlob - 1; ii >= 0 ; ii--){
-                        integralSoFar += integrandWeightGlob[ii].integrand;
-                        weightSoFar   += integrandWeightGlob[ii].weight;
-                        if (integralSoFar > self->deformationFactor*totalIntegral) break;
-                }
-                /* do sum again this time to find total area */
-                weightSoFar2   = 0.;
-                for(ii = numPointsGlob - 1; ii >= 0 ; ii--){
-                        weightSoFar2   += integrandWeightGlob[ii].weight;
-                }
-                /* set Localisation to be ratio of area for which 80% of the deformation occurs, to the total area */
-                self->Localisation = weightSoFar/weightSoFar2;   
-                StgFEM_FrequentOutput_PrintValue( context, self->Localisation );
-                
-                FreeArray( integrandWeightGlob );
-        }
-        
-        FreeArray( min );
-        FreeArray( max );
-        FreeArray( self->integrandWeight );
-}
-
-void Underworld_Localisation_SymmetricTensor_LowerDimension_InvariantRoot_2d( void* operator, double* operand0, double* result ) {
-        Operator* self = (Operator*) operator;
-        double    temp;
-        
-        Operator_FirewallUnary( self );
-        Operator_FirewallResultDofs( self, 1 );
-        
-        temp      = operand0[0];
-        result[0] = fabs( temp );
-}
-
-void Underworld_Localisation_SymmetricTensor_LowerDimension_InvariantRoot_3d( void* operator, double* operand0, double* result ) {
-        Operator* self = (Operator*) operator;
-        SymmetricTensor temp;
-        
-        Operator_FirewallUnary( self );
-        Operator_FirewallResultDofs( self, 1 );
-        
-        temp[0] = operand0[0];  /* strainrate_{xx} */
-        temp[1] = operand0[2];  /* strainrate_{zz} */
-        temp[2] = operand0[4];  /* strainrate_{xz} */
-        
-        *result = SymmetricTensor_2ndInvariant( temp, 2 );
-}
-
-
-double Localisation_IntegratePlane( void* feVariable, Axis planeAxis, double planeHeight, void* _Localisation  ){
-        FeVariable*                fevariable = (FeVariable*) feVariable;
-        Underworld_Localisation*   Localisation  = (Underworld_Localisation*) _Localisation;
-        IJK                        planeIJK;
-        Element_LocalIndex         lElement_I;
-        Element_GlobalIndex        gElement_I;
-        Element_LocalIndex         elementLocalCount  = FeMesh_GetElementLocalSize( fevariable->feMesh );
-        Axis                       aAxis              = ( planeAxis == I_AXIS ? J_AXIS : I_AXIS );
-        Axis                       bAxis              = ( planeAxis == K_AXIS ? J_AXIS : K_AXIS );
-        double                     integral;
-        /* Swarm Stuff */
-        Swarm*                     tmpSwarm;
-        Bool                       dimExists[]        = { False, False, False };
-        ExtensionManager_Register* extensionMgr_Register;
-        SingleCellLayout*          singleCellLayout;
-        GaussParticleLayout*       gaussParticleLayout;
-        Particle_Index             lParticle_I;
-        IntegrationPoint*          particle;
-        /* Plane location stuff */
-        double                     storedXi_J_AXIS;
-        Coord                      planeCoord;
-        double                     planeXi           = -1;
-        double                     planeXiGlobal;
-        Index                      planeLayer        = 0;
-        Index                      planeLayerGlobal;
-        Particle_InCellIndex       particlesPerDim[] = {2,2,2};
-        AbstractContext*           context = (AbstractContext*) fevariable->context;
-
-        /* Find Elements which plane cuts through */
-        memcpy( planeCoord, Mesh_GetVertex( fevariable->feMesh, 0 ), sizeof( Coord ) );
-        planeCoord[ planeAxis ] = planeHeight;
-
-        if( Mesh_Algorithms_SearchElements( fevariable->feMesh->algorithms, planeCoord, &lElement_I ) && 
-            lElement_I < elementLocalCount )
-        {
-                Coord           planeXiCoord;
-
-                gElement_I = FeMesh_ElementDomainToGlobal( fevariable->feMesh, lElement_I );
-                RegularMeshUtils_Element_1DTo3D( fevariable->feMesh, gElement_I, planeIJK );
-                planeLayer = planeIJK[ planeAxis ];
-                
-                /* Find Local Coordinate of plane */
-                FeMesh_CoordGlobalToLocal( fevariable->feMesh, lElement_I, planeCoord, planeXiCoord );
-                planeXi = planeXiCoord[ planeAxis ];
-        }
-        
-        /* Should be broadcast */
-        MPI_Allreduce( &planeXi,    &planeXiGlobal, 1, MPI_DOUBLE, MPI_MAX, fevariable->communicator );
-        MPI_Allreduce( &planeLayer, &planeLayerGlobal, 1, MPI_UNSIGNED, MPI_MAX, fevariable->communicator );
-
-        /* Create Swarm in plane */
-        extensionMgr_Register = ExtensionManager_Register_New();
-        dimExists[ aAxis ] = True;
-        if (fevariable->dim == 3)
-                dimExists[ bAxis ] = True;
-        
-        singleCellLayout = SingleCellLayout_New( "cellLayout", (AbstractContext*) context, dimExists, NULL, NULL );
-        particlesPerDim[ planeAxis ] = 1;
-        gaussParticleLayout = GaussParticleLayout_New( "particleLayout", (AbstractContext*) context, LocalCoordSystem, True, fevariable->dim - 1, particlesPerDim );
-        tmpSwarm = Swarm_New( 
-                        "tmpgaussSwarm",
-                        (AbstractContext*) context,
-                        singleCellLayout, 
-                        gaussParticleLayout,
-                        fevariable->dim,
-                        sizeof(IntegrationPoint), 
-                        extensionMgr_Register, 
-                        NULL,
-                        fevariable->communicator,
-                        NULL    );
-        Stg_Component_Build( tmpSwarm, NULL, False );
-
-        /* Change Positions of the particles */
-        Stg_Component_Initialise( tmpSwarm, NULL, False );
-        for ( lParticle_I = 0 ; lParticle_I < tmpSwarm->particleLocalCount ; lParticle_I++ ) {
-                particle = (IntegrationPoint*) Swarm_ParticleAt( tmpSwarm, lParticle_I );
-
-                storedXi_J_AXIS = particle->xi[ J_AXIS ];
-                particle->xi[ aAxis ]     = particle->xi[ I_AXIS ];
-                particle->xi[ bAxis ]     = storedXi_J_AXIS;
-                particle->xi[ planeAxis ] = planeXiGlobal;
-        }
-        
-        integral = Localisation_IntegrateLayer_AxisIndependent( fevariable, tmpSwarm, planeAxis, planeLayerGlobal, 
-                        fevariable->dim - 1, aAxis, bAxis, planeAxis, Localisation ); 
-
-        /* Delete */
-        Stg_Class_Delete( tmpSwarm );
-        Stg_Class_Delete( gaussParticleLayout );
-        Stg_Class_Delete( singleCellLayout );
-        Stg_Class_Delete( extensionMgr_Register );
-        
-        return integral;
-}
-
-double Localisation_IntegrateLayer_AxisIndependent( 
-                void* feVariable, void* _swarm,
-                Axis layerAxis, Index layerIndex, Dimension_Index dim, 
-                Axis axis0, Axis axis1, Axis axis2, void* _Localisation )
-{ 
-        FeVariable*                fevariable = (FeVariable*)         feVariable;
-        Swarm*                     swarm      = (Swarm*)              _swarm;
-        Underworld_Localisation*      Localisation  = (Underworld_Localisation*) _Localisation;
-        Element_LocalIndex         lElement_I;
-        Element_GlobalIndex        gElement_I;
-        IJK                        elementIJK;
-        double                     elementIntegral;
-        double                     integral;
-        double                     integralGlobal;
-        
-        Journal_DPrintf( fevariable->debug, "In %s() for FeVariable \"%s\":\n", __func__, fevariable->name );
-
-        /* Initialise Sumation of Integral */
-        integral = 0.0;
-
-        Stream_Indent( fevariable->debug );
-        
-        for ( gElement_I = 0 ; gElement_I < FeMesh_GetElementGlobalSize( fevariable->feMesh ); gElement_I++ ) {
-                RegularMeshUtils_Element_1DTo3D( fevariable->feMesh, gElement_I, elementIJK );
-
-                /* Check if element is in layer plane */
-                if ( elementIJK[ layerAxis ] != layerIndex )
-                        continue;
-
-                /* Check if element is local */
-                if( !FeMesh_ElementGlobalToDomain( fevariable->feMesh, gElement_I, &lElement_I ) || 
-                    lElement_I >= FeMesh_GetElementLocalSize( fevariable->feMesh ) )
-                {
-                        continue;
-                }
-
-                elementIntegral = Localisation_IntegrateElement_AxisIndependent( fevariable, swarm, lElement_I, dim, axis0, axis1, axis2,  Localisation  );
-                Journal_DPrintfL( fevariable->debug, 2, "Integral of element %d was %f\n", lElement_I, elementIntegral );
-                integral += elementIntegral;
-        }
-        Stream_UnIndent( fevariable->debug );
-
-
-        /* Gather and sum integrals from other processors */
-        MPI_Allreduce( &integral, &integralGlobal, 1, MPI_DOUBLE, MPI_SUM, fevariable->communicator );
-
-        Journal_DPrintf( fevariable->debug, "Calculated global integral of layer %d in Axis %d was %f\n", layerIndex, layerAxis, integralGlobal );
-        return integralGlobal;
-}
-
-double Localisation_IntegrateElement_AxisIndependent( 
-                void* feVariable, void* _swarm, 
-                Element_DomainIndex dElement_I, Dimension_Index dim, 
-                Axis axis0, Axis axis1, Axis axis2, void* _Localisation ) 
-{
-        FeVariable*           fevariable = (FeVariable*)           feVariable;
-        Swarm*                swarm      = (Swarm*)                _swarm;
-        Underworld_Localisation* Localisation  = (Underworld_Localisation*) _Localisation;
-        FeMesh*                 feMesh             = fevariable->feMesh;
-        FeMesh*                 mesh;
-        ElementType*         elementType;
-        Cell_LocalIndex      cell_I;
-        Particle_InCellIndex cParticle_I;
-        Particle_InCellIndex cellParticleCount;
-        IntegrationPoint*    particle;
-        double               detJac;
-        double               integral;
-        double               value;
-        
-        /* Initialise Summation of Integral */
-        integral = 0.0;
-
-        /* Use feVariable's mesh as geometry mesh if one isn't passed in */
-        if( Stg_Class_IsInstance( feMesh->algorithms, Mesh_CentroidAlgorithms_Type ) )
-                mesh = (FeMesh*)((Mesh_CentroidAlgorithms*)feMesh->algorithms)->elMesh;
-        else
-                mesh = feMesh;
-        elementType = FeMesh_GetElementType( mesh, dElement_I );
-
-        /* Determine number of particles in element */
-        cell_I = CellLayout_MapElementIdToCellId( swarm->cellLayout, dElement_I );
-        cellParticleCount = swarm->cellParticleCountTbl[ cell_I ];
-
-        /* Loop over all particles in element to get integral*/
-        for( cParticle_I = 0 ; cParticle_I < cellParticleCount ; cParticle_I++ ) {
-                Particle_Index dParticle_I;
-                /* Get Pointer to particle */
-                particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
-
-                dParticle_I = swarm->cellParticleTbl[(cell_I)][(cParticle_I)];
-                /* Interpolate Value of Field at Particle */
-                FeVariable_InterpolateWithinElement( feVariable, dElement_I, particle->xi, &value );
-
-                Journal_DPrintfL( fevariable->debug, 3, "%s: Integrating element %d - particle %d - Value = %g\n", fevariable->name, dElement_I, cParticle_I, value );
-
-                /* Calculate Determinant of Jacobian */
-                detJac = ElementType_JacobianDeterminant_AxisIndependent( 
-                                elementType, mesh, dElement_I, particle->xi, dim, axis0, axis1, axis2 );
-                
-                /* store values for later sorting and usage */
-                Localisation->integrandWeight[globPartInc].integrand = detJac * particle->weight * value;
-                Localisation->integrandWeight[globPartInc].weight    = detJac * particle->weight;
-                
-                globPartInc += 1 ;
-                
-                /* Sum Integral */
-                integral += detJac * particle->weight * value;
-        }
-        
-        return integral;
-}
-
-unsigned Localisation_FindTotElements( void* feVariable, Axis layerAxis, double planeHeight )
-{ 
-        FeVariable*                fevariable = (FeVariable*)         feVariable;
-        Element_LocalIndex         lElement_I;
-        Element_GlobalIndex        gElement_I;
-        unsigned                   totElements;
-        IJK                        elementIJK;
-        Coord                      planeCoord;
-        Element_LocalIndex         elementLocalCount  = FeMesh_GetElementLocalSize( fevariable->feMesh );
-        IJK                        planeIJK;
-        double                     planeXi           = -1;
-        double                     planeXiGlobal;
-        Index                      planeLayer        = 0;
-        Index                      planeLayerGlobal;
-        
-        /* Find Elements which plane cuts through */
-        memcpy( planeCoord, Mesh_GetVertex( fevariable->feMesh, 0 ), sizeof( Coord ) );
-        planeCoord[ layerAxis ] = planeHeight;
-
-        if( Mesh_Algorithms_SearchElements( fevariable->feMesh->algorithms, planeCoord, &lElement_I ) && 
-            lElement_I < elementLocalCount )
-        {
-                Coord           planeXiCoord;
-
-                gElement_I = FeMesh_ElementDomainToGlobal( fevariable->feMesh, lElement_I );
-                RegularMeshUtils_Element_1DTo3D( fevariable->feMesh, gElement_I, planeIJK );
-                planeLayer = planeIJK[ layerAxis ];
-                
-                /* Find Local Coordinate of plane */
-                FeMesh_CoordGlobalToLocal( fevariable->feMesh, lElement_I, planeCoord, planeXiCoord );
-                planeXi = planeXiCoord[ layerAxis ];
-        }
-        
-        /* Should be broadcast */
-        MPI_Allreduce( &planeXi,    &planeXiGlobal, 1, MPI_DOUBLE, MPI_MAX, fevariable->communicator );
-        MPI_Allreduce( &planeLayer, &planeLayerGlobal, 1, MPI_UNSIGNED, MPI_MAX, fevariable->communicator );
-        
-        totElements = 0.;
-        
-        for ( gElement_I = 0 ; gElement_I < FeMesh_GetElementGlobalSize( fevariable->feMesh ); gElement_I++ ) {
-                RegularMeshUtils_Element_1DTo3D( fevariable->feMesh, gElement_I, elementIJK );
-
-                /* Check if element is in layer plane */
-                if ( elementIJK[ layerAxis ] != planeLayerGlobal )
-                        continue;
-
-                /* Check if element is local */
-                if( !FeMesh_ElementGlobalToDomain( fevariable->feMesh, gElement_I, &lElement_I ) || 
-                    lElement_I >= FeMesh_GetElementLocalSize( fevariable->feMesh ) )
-                {
-                        continue;
-                }
-                
-                totElements += 1;
-
-        }
-        return totElements;
-}
-
-
-int _QsortIntegrand( const void* _a, const void* _b ) {
-	IntegrandWeightStruct* a = (IntegrandWeightStruct*) _a;
-	IntegrandWeightStruct* b = (IntegrandWeightStruct*) _b;
-	if ( a->integrand > b->integrand )
-		return 1;
-	else
-		return -1;
-}
-void Localisation_Create_MPI_Datatype() {
-	MPI_Datatype          typeList[2] = { MPI_DOUBLE, MPI_DOUBLE };
-	int                   blocklen[2] = { 1, 1 };
-	MPI_Aint              displacement[2];
-	IntegrandWeightStruct integrandWeightStruct;
-
-	displacement[0] = GetOffsetOfMember( integrandWeightStruct, integrand );
-	displacement[1] = GetOffsetOfMember( integrandWeightStruct, weight );
-	
-	MPI_Type_struct( 2, blocklen, displacement, typeList, &Localisation_MPI_Datatype );
-	MPI_Type_commit( & Localisation_MPI_Datatype );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/Localisation/Localisation.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/Output/Localisation/Localisation.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,578 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+              Robert Turnbull
+*+              Vincent Lemiale
+*+              Louis Moresi
+*+              David May
+*+              David Stegman
+*+              Mirko Velic
+*+              Patrick Sunter
+*+              Julian Giordani
+*+
+** $Id:  $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Underworld.h>
+#include <StgFEM/FrequentOutput/FrequentOutput.h>
+
+#include "Localisation.h"
+
+unsigned     globPartInc;
+MPI_Datatype Localisation_MPI_Datatype;
+
+const Type Underworld_Localisation_Type = "Underworld_Localisation";
+
+void _Underworld_Localisation_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
+        UnderworldContext* context;
+
+        context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data ); 
+
+        /* Add functions to entry points */
+        Underworld_Localisation_Setup( context  );
+        ContextEP_Append( context, AbstractContext_EP_FrequentOutput, Underworld_Localisation_Output );
+}
+
+void _Underworld_Localisation_Build( void* component, void* data ) {
+        Underworld_Localisation*        self = (Underworld_Localisation*)component;
+
+        Stg_Component_Build( self->reducedStrainRateFieldInvariantRoot, data, False );
+
+}
+
+void* _Underworld_Localisation_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Underworld_Localisation);
+	Type                                                      type = Underworld_Localisation_Type;
+	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
+	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
+	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_Localisation_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Underworld_Localisation_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _Underworld_Localisation_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 Underworld_Localisation_Register( PluginsManager* pluginsManager ) {
+        return PluginsManager_Submit( pluginsManager, Underworld_Localisation_Type, (Name)"0", _Underworld_Localisation_DefaultNew );
+}
+
+void Underworld_Localisation_Setup( UnderworldContext* context ) {
+        FieldVariable_Register*  fV_Register               = context->fieldVariable_Register;
+        FieldVariable*           strainRateField;
+        Func_Ptr                 _carryOut;
+        Dof_Index                resultDofs;
+        Dof_Index                operandDofs;
+        Index                    numberOfOperands;
+        Operator*                ownOperator;
+        Dimension_Index          dim;
+        Swarm*					      gaussSwarm = (Swarm* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"gaussSwarm" );
+
+        Underworld_Localisation* self;
+
+        /* create datatype for MPI communications */
+        Localisation_Create_MPI_Datatype();
+        
+        self = (Underworld_Localisation* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_Localisation_Type  );
+        
+        StgFEM_FrequentOutput_PrintString( context, "Localisation" );
+
+	/* get localisation parameter */
+	self->deformationFactor = Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"localisationDeformationFactor", 0.8  );
+
+        Journal_Firewall( 
+                        gaussSwarm != NULL, 
+                        Underworld_Error,
+                        "Cannot find gauss swarm. Cannot use %s.\n", CURR_MODULE_NAME );
+
+        /* create Some FeVariables to determine Localisation */
+        strainRateField  = FieldVariable_Register_GetByName( fV_Register, "StrainRateField" );
+
+        dim = strainRateField->dim;
+        /* setup required parameters to create new operate */
+        resultDofs       = 1 ;
+        numberOfOperands = 1 ;
+        operandDofs      = ( dim == 2 ? 3 : 6 );
+        _carryOut        = ( dim == 2 ? Underworld_Localisation_SymmetricTensor_LowerDimension_InvariantRoot_2d : Underworld_Localisation_SymmetricTensor_LowerDimension_InvariantRoot_3d );
+        
+        ownOperator = Operator_New( "Localisation_SymmetricTensor_LowerDimension_InvariantRoot", _carryOut, numberOfOperands, operandDofs, resultDofs, dim );
+
+        self->reducedStrainRateFieldInvariantRoot = OperatorFeVariable_NewUnary_OwnOperator(
+                        "ReducedStrainRateFieldInvariantRoot",
+                        (DomainContext*)	context,
+                        strainRateField, 
+                        ownOperator );
+
+        /* add the variables to register so we can checkpoint & examine if necessary */
+        FieldVariable_Register_Add( fV_Register, self->reducedStrainRateFieldInvariantRoot );
+        
+}
+
+void Underworld_Localisation_Output( UnderworldContext* context ) {
+        Underworld_Localisation* self;
+        double   totalIntegral;
+        double   integralSoFar;
+        double   weightSoFar;
+        double   weightSoFar2;
+        double   *min, *max;
+        double   translate;
+        int meshSizeJ = Dictionary_GetInt_WithDefault( context->dictionary, (Dictionary_Entry_Key)"elementResJ", 1  );
+        int ii;
+        int aa;
+        int numPoints;
+        int numPointsGlob;
+        int numPointsProc;
+	int myRank;
+	int nProcs;
+	MPI_Status         status;        
+	IntegrandWeightStruct* integrandWeightGlob;
+        const int FINISHED_WRITING_TAG = 100;
+
+        MPI_Comm_size( context->communicator, (int*)&nProcs );
+        MPI_Comm_rank( context->communicator, (int*)&myRank );
+
+        globPartInc = 0;
+        
+        self = (Underworld_Localisation*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_Localisation_Type  );
+
+        /* find the size of the domain */
+        min = Memory_Alloc_Array_Unnamed( double, Mesh_GetDimSize( self->reducedStrainRateFieldInvariantRoot->feMesh ) );
+        max = Memory_Alloc_Array_Unnamed( double, Mesh_GetDimSize( self->reducedStrainRateFieldInvariantRoot->feMesh ) );
+
+        Mesh_GetGlobalCoordRange( self->reducedStrainRateFieldInvariantRoot->feMesh, min, max );
+        
+        translate = ( max[ J_AXIS ] - min[ J_AXIS ] ) / (2*meshSizeJ);
+
+        /* create arrays to store the integral sum integrands and weights */
+        /* first determine how large array needs to be */
+        /* factor of 2 or 4 allows for number of particles used to integrate surface */
+        if(self->reducedStrainRateFieldInvariantRoot->dim == 2)
+           numPoints = 2*Localisation_FindTotElements( self->reducedStrainRateFieldInvariantRoot , J_AXIS, max[ J_AXIS ] - translate );
+        else
+           numPoints = 2*Localisation_FindTotElements( self->reducedStrainRateFieldInvariantRoot , J_AXIS, max[ J_AXIS ] - translate );
+        
+        self->integrandWeight  = Memory_Alloc_Array_Unnamed( IntegrandWeightStruct, numPoints );
+                
+        /* use modified integrate plane routine to do the work!
+           these routines store the integrand values, and corresponding weights, for each particle used to 
+           construct the integral.. these are then qsort(ed) by integrand value, and summed starting at the top, until 
+           a set percentage of the total integral is reached.. the ratio of the weight of all the thus far counted particles, 
+           to all the particles, is then the localisation value. */
+        totalIntegral = Localisation_IntegratePlane( self->reducedStrainRateFieldInvariantRoot, J_AXIS, max[ J_AXIS ] - translate, self );
+	
+	/* find the total global number of integration points */
+	MPI_Allreduce( &globPartInc, &numPointsGlob, 1, MPI_INT, MPI_SUM, context->communicator );
+        
+        /* collect data */
+        if ( myRank == 0 ) {
+                int count = 0;
+                /* allocate global list array */
+                integrandWeightGlob = Memory_Alloc_Array_Unnamed( IntegrandWeightStruct, numPointsGlob );
+                
+                /* first copy the rank=0 data into the global array */
+                for(ii = 0; ii < globPartInc; ii++){
+                        integrandWeightGlob[ii].integrand = self->integrandWeight[ii].integrand;
+                        integrandWeightGlob[ii].weight    = self->integrandWeight[ii].weight;
+                        count += 1;
+                }
+                
+                /* collect data from other processors. */
+                for(aa = 1; aa < nProcs; aa++){
+                        /* first get the size of the processors array */
+                        MPI_Recv( &numPointsProc, 1, MPI_INT, aa, FINISHED_WRITING_TAG, context->communicator, &status );
+                        /* get the data */
+                        MPI_Recv( integrandWeightGlob+count, numPointsProc, Localisation_MPI_Datatype, aa, FINISHED_WRITING_TAG, context->communicator, &status );
+                        /*find position for next dataset to be placed*/
+                        count += numPointsProc;
+                }
+        } else {
+                        /* send the size of this processors array */
+                        MPI_Ssend( &globPartInc, 1, MPI_INT, 0, FINISHED_WRITING_TAG, context->communicator );
+                        /* send the data */
+                        MPI_Ssend( self->integrandWeight, globPartInc, Localisation_MPI_Datatype, 0, FINISHED_WRITING_TAG, context->communicator );
+        }
+        /* now determine localisation */
+        if ( myRank == 0 ) {
+                /* sort data array in ascending order (smallest integral contributor placed first in array) */ 
+                qsort( integrandWeightGlob, numPointsGlob, sizeof( IntegrandWeightStruct ), _QsortIntegrand );
+                /* sum integral contributors, starting from the largest values, and stopping once integral contributions exceed deformationFactor*totalIntegral */
+                integralSoFar = 0.;
+                weightSoFar   = 0.;
+                for(ii = numPointsGlob - 1; ii >= 0 ; ii--){
+                        integralSoFar += integrandWeightGlob[ii].integrand;
+                        weightSoFar   += integrandWeightGlob[ii].weight;
+                        if (integralSoFar > self->deformationFactor*totalIntegral) break;
+                }
+                /* do sum again this time to find total area */
+                weightSoFar2   = 0.;
+                for(ii = numPointsGlob - 1; ii >= 0 ; ii--){
+                        weightSoFar2   += integrandWeightGlob[ii].weight;
+                }
+                /* set Localisation to be ratio of area for which 80% of the deformation occurs, to the total area */
+                self->Localisation = weightSoFar/weightSoFar2;   
+                StgFEM_FrequentOutput_PrintValue( context, self->Localisation );
+                
+                FreeArray( integrandWeightGlob );
+        }
+        
+        FreeArray( min );
+        FreeArray( max );
+        FreeArray( self->integrandWeight );
+}
+
+void Underworld_Localisation_SymmetricTensor_LowerDimension_InvariantRoot_2d( void* operator, double* operand0, double* result ) {
+        Operator* self = (Operator*) operator;
+        double    temp;
+        
+        Operator_FirewallUnary( self );
+        Operator_FirewallResultDofs( self, 1 );
+        
+        temp      = operand0[0];
+        result[0] = fabs( temp );
+}
+
+void Underworld_Localisation_SymmetricTensor_LowerDimension_InvariantRoot_3d( void* operator, double* operand0, double* result ) {
+        Operator* self = (Operator*) operator;
+        SymmetricTensor temp;
+        
+        Operator_FirewallUnary( self );
+        Operator_FirewallResultDofs( self, 1 );
+        
+        temp[0] = operand0[0];  /* strainrate_{xx} */
+        temp[1] = operand0[2];  /* strainrate_{zz} */
+        temp[2] = operand0[4];  /* strainrate_{xz} */
+        
+        *result = SymmetricTensor_2ndInvariant( temp, 2 );
+}
+
+
+double Localisation_IntegratePlane( void* feVariable, Axis planeAxis, double planeHeight, void* _Localisation  ){
+        FeVariable*                fevariable = (FeVariable*) feVariable;
+        Underworld_Localisation*   Localisation  = (Underworld_Localisation*) _Localisation;
+        IJK                        planeIJK;
+        Element_LocalIndex         lElement_I;
+        Element_GlobalIndex        gElement_I;
+        Element_LocalIndex         elementLocalCount  = FeMesh_GetElementLocalSize( fevariable->feMesh );
+        Axis                       aAxis              = ( planeAxis == I_AXIS ? J_AXIS : I_AXIS );
+        Axis                       bAxis              = ( planeAxis == K_AXIS ? J_AXIS : K_AXIS );
+        double                     integral;
+        /* Swarm Stuff */
+        Swarm*                     tmpSwarm;
+        Bool                       dimExists[]        = { False, False, False };
+        ExtensionManager_Register* extensionMgr_Register;
+        SingleCellLayout*          singleCellLayout;
+        GaussParticleLayout*       gaussParticleLayout;
+        Particle_Index             lParticle_I;
+        IntegrationPoint*          particle;
+        /* Plane location stuff */
+        double                     storedXi_J_AXIS;
+        Coord                      planeCoord;
+        double                     planeXi           = -1;
+        double                     planeXiGlobal;
+        Index                      planeLayer        = 0;
+        Index                      planeLayerGlobal;
+        Particle_InCellIndex       particlesPerDim[] = {2,2,2};
+        AbstractContext*           context = (AbstractContext*) fevariable->context;
+
+        /* Find Elements which plane cuts through */
+        memcpy( planeCoord, Mesh_GetVertex( fevariable->feMesh, 0 ), sizeof( Coord ) );
+        planeCoord[ planeAxis ] = planeHeight;
+
+        if( Mesh_Algorithms_SearchElements( fevariable->feMesh->algorithms, planeCoord, &lElement_I ) && 
+            lElement_I < elementLocalCount )
+        {
+                Coord           planeXiCoord;
+
+                gElement_I = FeMesh_ElementDomainToGlobal( fevariable->feMesh, lElement_I );
+                RegularMeshUtils_Element_1DTo3D( fevariable->feMesh, gElement_I, planeIJK );
+                planeLayer = planeIJK[ planeAxis ];
+                
+                /* Find Local Coordinate of plane */
+                FeMesh_CoordGlobalToLocal( fevariable->feMesh, lElement_I, planeCoord, planeXiCoord );
+                planeXi = planeXiCoord[ planeAxis ];
+        }
+        
+        /* Should be broadcast */
+        MPI_Allreduce( &planeXi,    &planeXiGlobal, 1, MPI_DOUBLE, MPI_MAX, fevariable->communicator );
+        MPI_Allreduce( &planeLayer, &planeLayerGlobal, 1, MPI_UNSIGNED, MPI_MAX, fevariable->communicator );
+
+        /* Create Swarm in plane */
+        extensionMgr_Register = ExtensionManager_Register_New();
+        dimExists[ aAxis ] = True;
+        if (fevariable->dim == 3)
+                dimExists[ bAxis ] = True;
+        
+        singleCellLayout = SingleCellLayout_New( "cellLayout", (AbstractContext*) context, dimExists, NULL, NULL );
+        particlesPerDim[ planeAxis ] = 1;
+        gaussParticleLayout = GaussParticleLayout_New( "particleLayout", (AbstractContext*) context, LocalCoordSystem, True, fevariable->dim - 1, particlesPerDim );
+        tmpSwarm = Swarm_New( 
+                        "tmpgaussSwarm",
+                        (AbstractContext*) context,
+                        singleCellLayout, 
+                        gaussParticleLayout,
+                        fevariable->dim,
+                        sizeof(IntegrationPoint), 
+                        extensionMgr_Register, 
+                        NULL,
+                        fevariable->communicator,
+                        NULL    );
+        Stg_Component_Build( tmpSwarm, NULL, False );
+
+        /* Change Positions of the particles */
+        Stg_Component_Initialise( tmpSwarm, NULL, False );
+        for ( lParticle_I = 0 ; lParticle_I < tmpSwarm->particleLocalCount ; lParticle_I++ ) {
+                particle = (IntegrationPoint*) Swarm_ParticleAt( tmpSwarm, lParticle_I );
+
+                storedXi_J_AXIS = particle->xi[ J_AXIS ];
+                particle->xi[ aAxis ]     = particle->xi[ I_AXIS ];
+                particle->xi[ bAxis ]     = storedXi_J_AXIS;
+                particle->xi[ planeAxis ] = planeXiGlobal;
+        }
+        
+        integral = Localisation_IntegrateLayer_AxisIndependent( fevariable, tmpSwarm, planeAxis, planeLayerGlobal, 
+                        fevariable->dim - 1, aAxis, bAxis, planeAxis, Localisation ); 
+
+        /* Delete */
+        Stg_Class_Delete( tmpSwarm );
+        Stg_Class_Delete( gaussParticleLayout );
+        Stg_Class_Delete( singleCellLayout );
+        Stg_Class_Delete( extensionMgr_Register );
+        
+        return integral;
+}
+
+double Localisation_IntegrateLayer_AxisIndependent( 
+                void* feVariable, void* _swarm,
+                Axis layerAxis, Index layerIndex, Dimension_Index dim, 
+                Axis axis0, Axis axis1, Axis axis2, void* _Localisation )
+{ 
+        FeVariable*                fevariable = (FeVariable*)         feVariable;
+        Swarm*                     swarm      = (Swarm*)              _swarm;
+        Underworld_Localisation*      Localisation  = (Underworld_Localisation*) _Localisation;
+        Element_LocalIndex         lElement_I;
+        Element_GlobalIndex        gElement_I;
+        IJK                        elementIJK;
+        double                     elementIntegral;
+        double                     integral;
+        double                     integralGlobal;
+        
+        Journal_DPrintf( fevariable->debug, "In %s() for FeVariable \"%s\":\n", __func__, fevariable->name );
+
+        /* Initialise Sumation of Integral */
+        integral = 0.0;
+
+        Stream_Indent( fevariable->debug );
+        
+        for ( gElement_I = 0 ; gElement_I < FeMesh_GetElementGlobalSize( fevariable->feMesh ); gElement_I++ ) {
+                RegularMeshUtils_Element_1DTo3D( fevariable->feMesh, gElement_I, elementIJK );
+
+                /* Check if element is in layer plane */
+                if ( elementIJK[ layerAxis ] != layerIndex )
+                        continue;
+
+                /* Check if element is local */
+                if( !FeMesh_ElementGlobalToDomain( fevariable->feMesh, gElement_I, &lElement_I ) || 
+                    lElement_I >= FeMesh_GetElementLocalSize( fevariable->feMesh ) )
+                {
+                        continue;
+                }
+
+                elementIntegral = Localisation_IntegrateElement_AxisIndependent( fevariable, swarm, lElement_I, dim, axis0, axis1, axis2,  Localisation  );
+                Journal_DPrintfL( fevariable->debug, 2, "Integral of element %d was %f\n", lElement_I, elementIntegral );
+                integral += elementIntegral;
+        }
+        Stream_UnIndent( fevariable->debug );
+
+
+        /* Gather and sum integrals from other processors */
+        MPI_Allreduce( &integral, &integralGlobal, 1, MPI_DOUBLE, MPI_SUM, fevariable->communicator );
+
+        Journal_DPrintf( fevariable->debug, "Calculated global integral of layer %d in Axis %d was %f\n", layerIndex, layerAxis, integralGlobal );
+        return integralGlobal;
+}
+
+double Localisation_IntegrateElement_AxisIndependent( 
+                void* feVariable, void* _swarm, 
+                Element_DomainIndex dElement_I, Dimension_Index dim, 
+                Axis axis0, Axis axis1, Axis axis2, void* _Localisation ) 
+{
+        FeVariable*           fevariable = (FeVariable*)           feVariable;
+        Swarm*                swarm      = (Swarm*)                _swarm;
+        Underworld_Localisation* Localisation  = (Underworld_Localisation*) _Localisation;
+        FeMesh*                 feMesh             = fevariable->feMesh;
+        FeMesh*                 mesh;
+        ElementType*         elementType;
+        Cell_LocalIndex      cell_I;
+        Particle_InCellIndex cParticle_I;
+        Particle_InCellIndex cellParticleCount;
+        IntegrationPoint*    particle;
+        double               detJac;
+        double               integral;
+        double               value;
+        
+        /* Initialise Summation of Integral */
+        integral = 0.0;
+
+        /* Use feVariable's mesh as geometry mesh if one isn't passed in */
+        if( Stg_Class_IsInstance( feMesh->algorithms, Mesh_CentroidAlgorithms_Type ) )
+                mesh = (FeMesh*)((Mesh_CentroidAlgorithms*)feMesh->algorithms)->elMesh;
+        else
+                mesh = feMesh;
+        elementType = FeMesh_GetElementType( mesh, dElement_I );
+
+        /* Determine number of particles in element */
+        cell_I = CellLayout_MapElementIdToCellId( swarm->cellLayout, dElement_I );
+        cellParticleCount = swarm->cellParticleCountTbl[ cell_I ];
+
+        /* Loop over all particles in element to get integral*/
+        for( cParticle_I = 0 ; cParticle_I < cellParticleCount ; cParticle_I++ ) {
+                Particle_Index dParticle_I;
+                /* Get Pointer to particle */
+                particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
+
+                dParticle_I = swarm->cellParticleTbl[(cell_I)][(cParticle_I)];
+                /* Interpolate Value of Field at Particle */
+                FeVariable_InterpolateWithinElement( feVariable, dElement_I, particle->xi, &value );
+
+                Journal_DPrintfL( fevariable->debug, 3, "%s: Integrating element %d - particle %d - Value = %g\n", fevariable->name, dElement_I, cParticle_I, value );
+
+                /* Calculate Determinant of Jacobian */
+                detJac = ElementType_JacobianDeterminant_AxisIndependent( 
+                                elementType, mesh, dElement_I, particle->xi, dim, axis0, axis1, axis2 );
+                
+                /* store values for later sorting and usage */
+                Localisation->integrandWeight[globPartInc].integrand = detJac * particle->weight * value;
+                Localisation->integrandWeight[globPartInc].weight    = detJac * particle->weight;
+                
+                globPartInc += 1 ;
+                
+                /* Sum Integral */
+                integral += detJac * particle->weight * value;
+        }
+        
+        return integral;
+}
+
+unsigned Localisation_FindTotElements( void* feVariable, Axis layerAxis, double planeHeight )
+{ 
+        FeVariable*                fevariable = (FeVariable*)         feVariable;
+        Element_LocalIndex         lElement_I;
+        Element_GlobalIndex        gElement_I;
+        unsigned                   totElements;
+        IJK                        elementIJK;
+        Coord                      planeCoord;
+        Element_LocalIndex         elementLocalCount  = FeMesh_GetElementLocalSize( fevariable->feMesh );
+        IJK                        planeIJK;
+        double                     planeXi           = -1;
+        double                     planeXiGlobal;
+        Index                      planeLayer        = 0;
+        Index                      planeLayerGlobal;
+        
+        /* Find Elements which plane cuts through */
+        memcpy( planeCoord, Mesh_GetVertex( fevariable->feMesh, 0 ), sizeof( Coord ) );
+        planeCoord[ layerAxis ] = planeHeight;
+
+        if( Mesh_Algorithms_SearchElements( fevariable->feMesh->algorithms, planeCoord, &lElement_I ) && 
+            lElement_I < elementLocalCount )
+        {
+                Coord           planeXiCoord;
+
+                gElement_I = FeMesh_ElementDomainToGlobal( fevariable->feMesh, lElement_I );
+                RegularMeshUtils_Element_1DTo3D( fevariable->feMesh, gElement_I, planeIJK );
+                planeLayer = planeIJK[ layerAxis ];
+                
+                /* Find Local Coordinate of plane */
+                FeMesh_CoordGlobalToLocal( fevariable->feMesh, lElement_I, planeCoord, planeXiCoord );
+                planeXi = planeXiCoord[ layerAxis ];
+        }
+        
+        /* Should be broadcast */
+        MPI_Allreduce( &planeXi,    &planeXiGlobal, 1, MPI_DOUBLE, MPI_MAX, fevariable->communicator );
+        MPI_Allreduce( &planeLayer, &planeLayerGlobal, 1, MPI_UNSIGNED, MPI_MAX, fevariable->communicator );
+        
+        totElements = 0.;
+        
+        for ( gElement_I = 0 ; gElement_I < FeMesh_GetElementGlobalSize( fevariable->feMesh ); gElement_I++ ) {
+                RegularMeshUtils_Element_1DTo3D( fevariable->feMesh, gElement_I, elementIJK );
+
+                /* Check if element is in layer plane */
+                if ( elementIJK[ layerAxis ] != planeLayerGlobal )
+                        continue;
+
+                /* Check if element is local */
+                if( !FeMesh_ElementGlobalToDomain( fevariable->feMesh, gElement_I, &lElement_I ) || 
+                    lElement_I >= FeMesh_GetElementLocalSize( fevariable->feMesh ) )
+                {
+                        continue;
+                }
+                
+                totElements += 1;
+
+        }
+        return totElements;
+}
+
+
+int _QsortIntegrand( const void* _a, const void* _b ) {
+	IntegrandWeightStruct* a = (IntegrandWeightStruct*) _a;
+	IntegrandWeightStruct* b = (IntegrandWeightStruct*) _b;
+	if ( a->integrand > b->integrand )
+		return 1;
+	else
+		return -1;
+}
+void Localisation_Create_MPI_Datatype() {
+	MPI_Datatype          typeList[2] = { MPI_DOUBLE, MPI_DOUBLE };
+	int                   blocklen[2] = { 1, 1 };
+	MPI_Aint              displacement[2];
+	IntegrandWeightStruct integrandWeightStruct;
+
+	displacement[0] = GetOffsetOfMember( integrandWeightStruct, integrand );
+	displacement[1] = GetOffsetOfMember( integrandWeightStruct, weight );
+	
+	MPI_Type_struct( 2, blocklen, displacement, typeList, &Localisation_MPI_Datatype );
+	MPI_Type_commit( & Localisation_MPI_Datatype );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/MaxTemperature/MaxTemperature.c
--- a/plugins/Output/MaxTemperature/MaxTemperature.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,95 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: Vrms.c 182 2006-05-01 12:32:01Z RobertTurnbull $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Underworld.h>
-#include <StgFEM/FrequentOutput/FrequentOutput.h>
-
-const Type Underworld_MaxTemperature_Type = "Underworld_MaxTemperature";
-void Underworld_MaxTemperature_PrintHeaderToFile( void* context );
-void Underworld_MaxTemperature_Output( void* _context );
-
-void _Underworld_MaxTemperature_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
-	UnderworldContext*  context;
-
-	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data );
-
-	Underworld_MaxTemperature_PrintHeaderToFile( context  );
-	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, Underworld_MaxTemperature_Output );
-}
-
-void* _Underworld_MaxTemperature_DefaultNew( Name name ) {
-	return Codelet_New(
-		Underworld_MaxTemperature_Type,
-		_Underworld_MaxTemperature_DefaultNew,
-		_Underworld_MaxTemperature_AssignFromXML,
-		_Codelet_Build,
-		_Codelet_Initialise,
-		_Codelet_Execute,
-		_Codelet_Destroy,
-		name );
-}
-
-Index Underworld_MaxTemperature_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Underworld_MaxTemperature_Type, (Name)"0", _Underworld_MaxTemperature_DefaultNew );
-}
-
-void Underworld_MaxTemperature_Output( void* _context ) {
-	UnderworldContext* context       = (UnderworldContext*) _context;
-	FeVariable*        temperatureFe = (FeVariable* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"TemperatureField" );
-	double             maxTemp;
-
-	maxTemp = _FeVariable_GetMaxGlobalFieldMagnitude( temperatureFe  );
-	StgFEM_FrequentOutput_PrintValue( context, maxTemp );
-}
-
-void Underworld_MaxTemperature_PrintHeaderToFile( void* context ) {
-	StgFEM_FrequentOutput_PrintString( context, "MaxTemp" );
-}
-
-
-
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/MaxTemperature/MaxTemperature.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/Output/MaxTemperature/MaxTemperature.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,95 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: Vrms.c 182 2006-05-01 12:32:01Z RobertTurnbull $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Underworld.h>
+#include <StgFEM/FrequentOutput/FrequentOutput.h>
+
+const Type Underworld_MaxTemperature_Type = "Underworld_MaxTemperature";
+void Underworld_MaxTemperature_PrintHeaderToFile( void* context );
+void Underworld_MaxTemperature_Output( void* _context );
+
+void _Underworld_MaxTemperature_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
+	UnderworldContext*  context;
+
+	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data );
+
+	Underworld_MaxTemperature_PrintHeaderToFile( context  );
+	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, Underworld_MaxTemperature_Output );
+}
+
+void* _Underworld_MaxTemperature_DefaultNew( Name name ) {
+	return Codelet_New(
+		Underworld_MaxTemperature_Type,
+		_Underworld_MaxTemperature_DefaultNew,
+		_Underworld_MaxTemperature_AssignFromXML,
+		_Codelet_Build,
+		_Codelet_Initialise,
+		_Codelet_Execute,
+		_Codelet_Destroy,
+		name );
+}
+
+Index Underworld_MaxTemperature_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Underworld_MaxTemperature_Type, (Name)"0", _Underworld_MaxTemperature_DefaultNew );
+}
+
+void Underworld_MaxTemperature_Output( void* _context ) {
+	UnderworldContext* context       = (UnderworldContext*) _context;
+	FeVariable*        temperatureFe = (FeVariable* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"TemperatureField" );
+	double             maxTemp;
+
+	maxTemp = _FeVariable_GetMaxGlobalFieldMagnitude( temperatureFe  );
+	StgFEM_FrequentOutput_PrintValue( context, maxTemp );
+}
+
+void Underworld_MaxTemperature_PrintHeaderToFile( void* context ) {
+	StgFEM_FrequentOutput_PrintString( context, "MaxTemp" );
+}
+
+
+
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/MaxVelocity/MaxVelocity.c
--- a/plugins/Output/MaxVelocity/MaxVelocity.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,197 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: Vrms.c 182 2006-05-01 12:32:01Z RobertTurnbull $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Underworld.h>
-#include <StgFEM/FrequentOutput/FrequentOutput.h>
-
-/* Every plugin or component should have a Type (a class name), which specifies the name of the data structure it is */ 
-const Type Underworld_MaxVelocity_Type = "Underworld_MaxVelocity";
-
-void Underworld_MaxVelocity_PrintHeaderToFile( void* context );
-void Underworld_MaxVelocity_Output( void* _context );
-void _Underworld_MaxVelocity_AssignFromXML( void* plugin, Stg_ComponentFactory* cf, void* data );
-void* _Underworld_MaxVelocity_DefaultNew( Name name );
-
-
-Index Underworld_MaxVelocity_Register( PluginsManager* pluginsManager ) {
-/*
- * 	Purpose:
- * 		Registers the Plugin, by linking the function _Underworld_MaxVelocity_DefaultNew
- * 		to the place holder (string type) Underworld_MaxVelocity_Type.
- * 		When the place holder is read from the input file the plugin manager needs to
- * 		identify the place holder string to the creation of a plugin data structure. 
- *
- * 	Inputs:
- * 		Inputs are all automatic and this code never needs to be called explicitly
- *
- * 	Interactions:
- * 		It's VERY IMPORTANT that the name of this function (prefix of the function name)
- * 		is spelt exactly the same as the Type place holder string.
- * 		In this case Underworld_MaxVelocity_Register, where the
- * 		prefix = "Underworld_MaxVelocity", is exactly the same as 
- * 		Underworld_MaxVelocity_Type = "Underworld_MaxVelocity".
- * 		
- * 		The function PluginsManager_Submit, needs to be given an Instantiation function
- * 		as it's final argument. This argument should define the functionality of the plugin
- */
-
-	return PluginsManager_Submit( pluginsManager, Underworld_MaxVelocity_Type, (Name)"0", _Underworld_MaxVelocity_DefaultNew );
-}
-
-void* _Underworld_MaxVelocity_DefaultNew( Name name  ) {
-/*
- * 	Purpose:
- * 		Registers the 'key' StGermain functions that will be used by this plugin.
- * 		The 'key' functions are called during the different StGermain 'phases'.
- * 		The important 'phases' are: Construct, Build, Initialise, Exectute, Destroy.
- *
- * 	Inputs:
- * 		Inputs are all automatic.
- *
- * 	Interactions:
- * 		The Instantiation funtion calls a New function that contains either 
- * 		functions defined within this plugin OR a parent plugin. Depending on the level
- * 		of complexity of the plugin you may need to defined custom _Build or _Initialise
- * 		functions; in this case the plugin is straight forward and no overriding is
- * 		needed  
- */
-	return Codelet_New(
-		Underworld_MaxVelocity_Type,
-		_Underworld_MaxVelocity_DefaultNew,
-		_Underworld_MaxVelocity_AssignFromXML,
-		_Codelet_Build,
-		_Codelet_Initialise,
-		_Codelet_Execute,
-		_Codelet_Destroy,
-		name );
-}
-
-void _Underworld_MaxVelocity_AssignFromXML( void* plugin, Stg_ComponentFactory* cf, void* data ) {
-/*
- * 	Purpose:
- * 		This function is called on the 'Construct phase' as defined by the
- * 		Codelet_New(.....) above. The construct phase is called at the beginning of the 
- * 		code. 
- * 		In this function all data structures (objects or components) that this 
- * 		plugin needs should be collected. To be more specific, the objects that
- * 		are defined in the inputfile (and thus are static) should be collected here.
- *
- * 		Also the user functionily (as opposed to non StGermain functionality) 
- * 		should be defined in here. 
- * 		So users defined functions should be attached to EntryPoints. These user
- * 		defined functions are called Hooks. So StGermain executes entry points, which
- * 		kick off user defined Hooks.
- *
- * 	Input:
- * 		Inputs are all automatic. 
- * 		1st args is the plugin pointer itself. (Not used here)
- * 		2nd is the component factory. Will be used to collect components from
- * 			the inputfile.
- * 		3rd Ask Steve.
- *
- * 	Interactions:
- * 		The context is generally gathered first from the ComponentFactory in
- * 		every plugin's construction phase. This allows the plugin we're constructing
- * 		to have access to a wide range of data. (Note this is not the behaviour of components;
- * 		they only access the data structures they need).
- * 		Once the context has been gathered we append a hook to the EP called 
- * 		AbstractContext_EP_FrequentOutput. A list of StGermain entry points can
- * 		be found in StGermain/Base/Context/src/AbstractContext.c
- * 		
- *
- */
-	UnderworldContext*  context;
-
-	/* Gather context from the ComponentFactory here */
-	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data );
-
-	/* Simple user defined function which belong to no EntryPoint */
-	Underworld_MaxVelocity_PrintHeaderToFile( context  );
-
-	/* Append user defined function, Underworld_MaxVelocity_Output, onto the EntryPoint
-	 * AbstractContext_EP_FrequentOutput */
-	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, Underworld_MaxVelocity_Output );
-}
-
-
-
-void Underworld_MaxVelocity_Output( void* _context ) {
-/*
- * 	Purpose:
- * 		User defined function. In this case is just prints out the max velocity to 
- * 		the FrequentOutput.dat file.
- *
- * 	Inputs:
- * 		The context, which can be used to control any other object in the code.
- * 		As this function is on the AbstractContext_EP_FrequentOutput it
- * 		receives the input which is defined for that entry point. Other entry points
- * 		have a different set of input args so be sure your user defined plugin is receiving
- * 		the right data structure as the void*. 
- * 		(Note some entry point specify multiple input args).
- *
- * 	Interactions:
- * 		Using the velocityField, which is pointered to from the context, the max velocity
- * 		component value is gathered and piped to the frequent output file. 
- */
-
-	UnderworldContext* context       = (UnderworldContext*) _context;
-	FeVariable*        velocityFe    = (FeVariable*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"VelocityField" );
-	double             maxVel;
-
-	/* Find the max field component */
-	maxVel = _FeVariable_GetMaxGlobalFieldMagnitude( velocityFe  );
-	/* Print to the FrequentOutput stream */
-	StgFEM_FrequentOutput_PrintValue( context, maxVel );
-}
-
-void Underworld_MaxVelocity_PrintHeaderToFile( void* context ) {
-	StgFEM_FrequentOutput_PrintString( context, "MaxVelocity" );
-}
-
-
-
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/MaxVelocity/MaxVelocity.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/Output/MaxVelocity/MaxVelocity.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,197 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: Vrms.c 182 2006-05-01 12:32:01Z RobertTurnbull $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Underworld.h>
+#include <StgFEM/FrequentOutput/FrequentOutput.h>
+
+/* Every plugin or component should have a Type (a class name), which specifies the name of the data structure it is */ 
+const Type Underworld_MaxVelocity_Type = "Underworld_MaxVelocity";
+
+void Underworld_MaxVelocity_PrintHeaderToFile( void* context );
+void Underworld_MaxVelocity_Output( void* _context );
+void _Underworld_MaxVelocity_AssignFromXML( void* plugin, Stg_ComponentFactory* cf, void* data );
+void* _Underworld_MaxVelocity_DefaultNew( Name name );
+
+
+Index Underworld_MaxVelocity_Register( PluginsManager* pluginsManager ) {
+/*
+ * 	Purpose:
+ * 		Registers the Plugin, by linking the function _Underworld_MaxVelocity_DefaultNew
+ * 		to the place holder (string type) Underworld_MaxVelocity_Type.
+ * 		When the place holder is read from the input file the plugin manager needs to
+ * 		identify the place holder string to the creation of a plugin data structure. 
+ *
+ * 	Inputs:
+ * 		Inputs are all automatic and this code never needs to be called explicitly
+ *
+ * 	Interactions:
+ * 		It's VERY IMPORTANT that the name of this function (prefix of the function name)
+ * 		is spelt exactly the same as the Type place holder string.
+ * 		In this case Underworld_MaxVelocity_Register, where the
+ * 		prefix = "Underworld_MaxVelocity", is exactly the same as 
+ * 		Underworld_MaxVelocity_Type = "Underworld_MaxVelocity".
+ * 		
+ * 		The function PluginsManager_Submit, needs to be given an Instantiation function
+ * 		as it's final argument. This argument should define the functionality of the plugin
+ */
+
+	return PluginsManager_Submit( pluginsManager, Underworld_MaxVelocity_Type, (Name)"0", _Underworld_MaxVelocity_DefaultNew );
+}
+
+void* _Underworld_MaxVelocity_DefaultNew( Name name  ) {
+/*
+ * 	Purpose:
+ * 		Registers the 'key' StGermain functions that will be used by this plugin.
+ * 		The 'key' functions are called during the different StGermain 'phases'.
+ * 		The important 'phases' are: Construct, Build, Initialise, Exectute, Destroy.
+ *
+ * 	Inputs:
+ * 		Inputs are all automatic.
+ *
+ * 	Interactions:
+ * 		The Instantiation funtion calls a New function that contains either 
+ * 		functions defined within this plugin OR a parent plugin. Depending on the level
+ * 		of complexity of the plugin you may need to defined custom _Build or _Initialise
+ * 		functions; in this case the plugin is straight forward and no overriding is
+ * 		needed  
+ */
+	return Codelet_New(
+		Underworld_MaxVelocity_Type,
+		_Underworld_MaxVelocity_DefaultNew,
+		_Underworld_MaxVelocity_AssignFromXML,
+		_Codelet_Build,
+		_Codelet_Initialise,
+		_Codelet_Execute,
+		_Codelet_Destroy,
+		name );
+}
+
+void _Underworld_MaxVelocity_AssignFromXML( void* plugin, Stg_ComponentFactory* cf, void* data ) {
+/*
+ * 	Purpose:
+ * 		This function is called on the 'Construct phase' as defined by the
+ * 		Codelet_New(.....) above. The construct phase is called at the beginning of the 
+ * 		code. 
+ * 		In this function all data structures (objects or components) that this 
+ * 		plugin needs should be collected. To be more specific, the objects that
+ * 		are defined in the inputfile (and thus are static) should be collected here.
+ *
+ * 		Also the user functionily (as opposed to non StGermain functionality) 
+ * 		should be defined in here. 
+ * 		So users defined functions should be attached to EntryPoints. These user
+ * 		defined functions are called Hooks. So StGermain executes entry points, which
+ * 		kick off user defined Hooks.
+ *
+ * 	Input:
+ * 		Inputs are all automatic. 
+ * 		1st args is the plugin pointer itself. (Not used here)
+ * 		2nd is the component factory. Will be used to collect components from
+ * 			the inputfile.
+ * 		3rd Ask Steve.
+ *
+ * 	Interactions:
+ * 		The context is generally gathered first from the ComponentFactory in
+ * 		every plugin's construction phase. This allows the plugin we're constructing
+ * 		to have access to a wide range of data. (Note this is not the behaviour of components;
+ * 		they only access the data structures they need).
+ * 		Once the context has been gathered we append a hook to the EP called 
+ * 		AbstractContext_EP_FrequentOutput. A list of StGermain entry points can
+ * 		be found in StGermain/Base/Context/src/AbstractContext.c
+ * 		
+ *
+ */
+	UnderworldContext*  context;
+
+	/* Gather context from the ComponentFactory here */
+	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data );
+
+	/* Simple user defined function which belong to no EntryPoint */
+	Underworld_MaxVelocity_PrintHeaderToFile( context  );
+
+	/* Append user defined function, Underworld_MaxVelocity_Output, onto the EntryPoint
+	 * AbstractContext_EP_FrequentOutput */
+	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, Underworld_MaxVelocity_Output );
+}
+
+
+
+void Underworld_MaxVelocity_Output( void* _context ) {
+/*
+ * 	Purpose:
+ * 		User defined function. In this case is just prints out the max velocity to 
+ * 		the FrequentOutput.dat file.
+ *
+ * 	Inputs:
+ * 		The context, which can be used to control any other object in the code.
+ * 		As this function is on the AbstractContext_EP_FrequentOutput it
+ * 		receives the input which is defined for that entry point. Other entry points
+ * 		have a different set of input args so be sure your user defined plugin is receiving
+ * 		the right data structure as the void*. 
+ * 		(Note some entry point specify multiple input args).
+ *
+ * 	Interactions:
+ * 		Using the velocityField, which is pointered to from the context, the max velocity
+ * 		component value is gathered and piped to the frequent output file. 
+ */
+
+	UnderworldContext* context       = (UnderworldContext*) _context;
+	FeVariable*        velocityFe    = (FeVariable*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"VelocityField" );
+	double             maxVel;
+
+	/* Find the max field component */
+	maxVel = _FeVariable_GetMaxGlobalFieldMagnitude( velocityFe  );
+	/* Print to the FrequentOutput stream */
+	StgFEM_FrequentOutput_PrintValue( context, maxVel );
+}
+
+void Underworld_MaxVelocity_PrintHeaderToFile( void* context ) {
+	StgFEM_FrequentOutput_PrintString( context, "MaxVelocity" );
+}
+
+
+
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/Mobility/Mobility.c
--- a/plugins/Output/Mobility/Mobility.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,181 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id:  $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-#include <mpi.h>
-#include <assert.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Underworld.h>
-#include <StgFEM/FrequentOutput/FrequentOutput.h>
-
-#include "Mobility.h"
-
-const Type Underworld_Mobility_Type = "Underworld_Mobility";
-
-void _Underworld_Mobility_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
-	UnderworldContext*  context;
-
-	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data ); 
-
-	Underworld_Mobility_PrintHeaderToFile( context  );
-	ContextEP_Append( context, AbstractContext_EP_AssignFromXMLExtensions, Underworld_Mobility_Setup );
-	ContextEP_Append( context, AbstractContext_EP_FrequentOutput     , Underworld_Mobility_Dump );
-}
-
-void _Underworld_Mobility_Build( void* component, void* data ) {
-	Underworld_Mobility*	self = (Underworld_Mobility*)component;
-
-	assert( self );
-
-	Stg_Component_Build( self->velocitySquaredField, data, False );
-   
-   _Codelet_Build( self, data );
-}
-
-void _Underworld_Mobility_Destroy( void* component, void* data ) {
-	Underworld_Mobility*	self = (Underworld_Mobility*)component;
-
-   _Codelet_Destroy( self, data );
-
-	Stg_Component_Destroy( self->velocitySquaredField, data, False );
-}
-
-void _Underworld_Mobility_Initialise( void* component, void* data ) {
-	Underworld_Mobility*	self = (Underworld_Mobility*)component;
-
-	assert( self );
-
-	Stg_Component_Initialise( self->velocitySquaredField, data, False );
-   
-   _Codelet_Initialise( self, data );
-}
-
-void* _Underworld_Mobility_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Underworld_Mobility);
-	Type                                                      type = Underworld_Mobility_Type;
-	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
-	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
-	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_Mobility_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Underworld_Mobility_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _Underworld_Mobility_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _Underworld_Mobility_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _Codelet_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _Underworld_Mobility_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 Underworld_Mobility_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Underworld_Mobility_Type, (Name)"0", _Underworld_Mobility_DefaultNew );
-}
-
-void Underworld_Mobility_Setup( void* _context ) {
-	UnderworldContext*	context = (UnderworldContext*) _context;
-	Swarm*					gaussSwarm = (Swarm* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"gaussSwarm" );
-	FeVariable*				velocityField = (FeVariable* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"VelocityField" );
-
-	Underworld_Mobility* self;
-
-	self = (Underworld_Mobility* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_Mobility_Type  );
-
-	Journal_Firewall( gaussSwarm != NULL, Underworld_Error, "Cannot find gauss swarm. Cannot use %s.\n", CURR_MODULE_NAME );
-	Journal_Firewall( velocityField != NULL, Underworld_Error, "Cannot find velocityField. Cannot use %s.\n", CURR_MODULE_NAME );
-
-	/* Create new Field Variable */
-	self->velocitySquaredField = OperatorFeVariable_NewUnary( "VelocitySquaredField", (DomainContext*)context, velocityField, "VectorSquare" );
-}
-
-/* Integrate Every Step and dump to file */
-void Underworld_Mobility_Dump( void* _context ) {
-	UnderworldContext*	context = (UnderworldContext*) _context;
-	Swarm*					gaussSwarm = (Swarm*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"gaussSwarm"  );
-	Mesh*						mesh;
-	double					maxCrd[3], minCrd[3];
-	double					integral;
-	double					topLayerAverage;
-	double					mobility;
-	double					vrms;
-	double					volume = 0.0;
-	Dimension_Index		dim = context->dim;
-
-	Underworld_Mobility* self;
-
-	self = (Underworld_Mobility*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_Mobility_Type );
-
-	mesh = (Mesh* )self->velocitySquaredField->feMesh;
-	Mesh_GetGlobalCoordRange( mesh, minCrd, maxCrd );
-	
-	/* Sum integral */
-	integral = FeVariable_Integrate( self->velocitySquaredField, gaussSwarm );
-	topLayerAverage = FeVariable_AverageTopLayer( self->velocitySquaredField, gaussSwarm, J_AXIS );
-	/* Get Volume of Mesh - TODO Make general for irregular meshes */
-	volume = ( maxCrd[ I_AXIS ] - minCrd[ I_AXIS ] ) * 
-		( maxCrd[ J_AXIS ] - minCrd[ J_AXIS ] );
-	if ( dim == 3 ) 
-		volume *= maxCrd[ K_AXIS ] - minCrd[ K_AXIS ];
-
-	/* Calculate Vrms 
-	 * V_{rms} = \sqrt{ \frac{ \int_\Omega \mathbf{u . u} d\Omega }{\Omega} } */
-	vrms = sqrt( integral / volume );
-
-	/* Calculate Mobility */	
-	mobility = sqrt(topLayerAverage)/vrms;
-
-	/* Print data to file */
-	StgFEM_FrequentOutput_PrintValue( context, mobility );
-
-}
-
-void Underworld_Mobility_PrintHeaderToFile( void* context ) {
-	StgFEM_FrequentOutput_PrintString( context, "Mobility" );
-}
-
-
-
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/Mobility/Mobility.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/Output/Mobility/Mobility.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,181 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id:  $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+#include <mpi.h>
+#include <assert.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Underworld.h>
+#include <StgFEM/FrequentOutput/FrequentOutput.h>
+
+#include "Mobility.h"
+
+const Type Underworld_Mobility_Type = "Underworld_Mobility";
+
+void _Underworld_Mobility_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
+	UnderworldContext*  context;
+
+	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data ); 
+
+	Underworld_Mobility_PrintHeaderToFile( context  );
+	ContextEP_Append( context, AbstractContext_EP_AssignFromXMLExtensions, Underworld_Mobility_Setup );
+	ContextEP_Append( context, AbstractContext_EP_FrequentOutput     , Underworld_Mobility_Dump );
+}
+
+void _Underworld_Mobility_Build( void* component, void* data ) {
+	Underworld_Mobility*	self = (Underworld_Mobility*)component;
+
+	assert( self );
+
+	Stg_Component_Build( self->velocitySquaredField, data, False );
+   
+   _Codelet_Build( self, data );
+}
+
+void _Underworld_Mobility_Destroy( void* component, void* data ) {
+	Underworld_Mobility*	self = (Underworld_Mobility*)component;
+
+   _Codelet_Destroy( self, data );
+
+	Stg_Component_Destroy( self->velocitySquaredField, data, False );
+}
+
+void _Underworld_Mobility_Initialise( void* component, void* data ) {
+	Underworld_Mobility*	self = (Underworld_Mobility*)component;
+
+	assert( self );
+
+	Stg_Component_Initialise( self->velocitySquaredField, data, False );
+   
+   _Codelet_Initialise( self, data );
+}
+
+void* _Underworld_Mobility_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Underworld_Mobility);
+	Type                                                      type = Underworld_Mobility_Type;
+	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
+	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
+	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_Mobility_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Underworld_Mobility_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _Underworld_Mobility_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _Underworld_Mobility_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _Codelet_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _Underworld_Mobility_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 Underworld_Mobility_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Underworld_Mobility_Type, (Name)"0", _Underworld_Mobility_DefaultNew );
+}
+
+void Underworld_Mobility_Setup( void* _context ) {
+	UnderworldContext*	context = (UnderworldContext*) _context;
+	Swarm*					gaussSwarm = (Swarm* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"gaussSwarm" );
+	FeVariable*				velocityField = (FeVariable* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"VelocityField" );
+
+	Underworld_Mobility* self;
+
+	self = (Underworld_Mobility* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_Mobility_Type  );
+
+	Journal_Firewall( gaussSwarm != NULL, Underworld_Error, "Cannot find gauss swarm. Cannot use %s.\n", CURR_MODULE_NAME );
+	Journal_Firewall( velocityField != NULL, Underworld_Error, "Cannot find velocityField. Cannot use %s.\n", CURR_MODULE_NAME );
+
+	/* Create new Field Variable */
+	self->velocitySquaredField = OperatorFeVariable_NewUnary( "VelocitySquaredField", (DomainContext*)context, velocityField, "VectorSquare" );
+}
+
+/* Integrate Every Step and dump to file */
+void Underworld_Mobility_Dump( void* _context ) {
+	UnderworldContext*	context = (UnderworldContext*) _context;
+	Swarm*					gaussSwarm = (Swarm*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"gaussSwarm"  );
+	Mesh*						mesh;
+	double					maxCrd[3], minCrd[3];
+	double					integral;
+	double					topLayerAverage;
+	double					mobility;
+	double					vrms;
+	double					volume = 0.0;
+	Dimension_Index		dim = context->dim;
+
+	Underworld_Mobility* self;
+
+	self = (Underworld_Mobility*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_Mobility_Type );
+
+	mesh = (Mesh* )self->velocitySquaredField->feMesh;
+	Mesh_GetGlobalCoordRange( mesh, minCrd, maxCrd );
+	
+	/* Sum integral */
+	integral = FeVariable_Integrate( self->velocitySquaredField, gaussSwarm );
+	topLayerAverage = FeVariable_AverageTopLayer( self->velocitySquaredField, gaussSwarm, J_AXIS );
+	/* Get Volume of Mesh - TODO Make general for irregular meshes */
+	volume = ( maxCrd[ I_AXIS ] - minCrd[ I_AXIS ] ) * 
+		( maxCrd[ J_AXIS ] - minCrd[ J_AXIS ] );
+	if ( dim == 3 ) 
+		volume *= maxCrd[ K_AXIS ] - minCrd[ K_AXIS ];
+
+	/* Calculate Vrms 
+	 * V_{rms} = \sqrt{ \frac{ \int_\Omega \mathbf{u . u} d\Omega }{\Omega} } */
+	vrms = sqrt( integral / volume );
+
+	/* Calculate Mobility */	
+	mobility = sqrt(topLayerAverage)/vrms;
+
+	/* Print data to file */
+	StgFEM_FrequentOutput_PrintValue( context, mobility );
+
+}
+
+void Underworld_Mobility_PrintHeaderToFile( void* context ) {
+	StgFEM_FrequentOutput_PrintString( context, "Mobility" );
+}
+
+
+
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/Nusselt/Nusselt.c
--- a/plugins/Output/Nusselt/Nusselt.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,177 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: Nusselt.c 619 2007-10-29 11:43:40Z RobertTurnbull $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Underworld.h>
-#include <StgFEM/FrequentOutput/FrequentOutput.h>
-
-#include "Nusselt.h"
-
-const Type Underworld_Nusselt_Type = "Underworld_Nusselt";
-
-void _Underworld_Nusselt_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
-	Underworld_Nusselt*		self = (Underworld_Nusselt*)component;
-	UnderworldContext*		context;
-	FieldVariable_Register*	fV_Register;
-	FieldVariable*				temperatureGradientsField;
-	FieldVariable*				velocityField;
-	FieldVariable*				temperatureField;
-
-	self->context = (AbstractContext*)Stg_ComponentFactory_PluginConstructByKey( cf, self, (Dictionary_Entry_Key)"Context", UnderworldContext, True, data  );
-	self->gaussSwarm = Stg_ComponentFactory_PluginConstructByKey( cf, self, (Dictionary_Entry_Key)"GaussSwarm", Swarm, True, data  );
-
-	StgFEM_FrequentOutput_PrintString( self->context, "Nusselt" );
-
-	context = (UnderworldContext*)self->context;
-	fV_Register = context->fieldVariable_Register;
-	/* Create Some FeVariables to calculate nusselt number */
-	temperatureField          = FieldVariable_Register_GetByName( fV_Register, "TemperatureField" );
-	velocityField             = FieldVariable_Register_GetByName( fV_Register, "VelocityField" );
-	temperatureGradientsField = FieldVariable_Register_GetByName( fV_Register, "TemperatureGradientsField" );
-	
-	self->advectiveHeatFluxField = OperatorFeVariable_NewBinary(  
-		"AdvectiveHeatFluxField",
-		(DomainContext*) context,
-		temperatureField, 
-		velocityField, 
-		"VectorScale" );
-
-	self->temperatureTotalDerivField = OperatorFeVariable_NewBinary(  
-		"TemperatureTotalDerivField",
-		(DomainContext*) context,
-		self->advectiveHeatFluxField, 
-		temperatureGradientsField, 
-		"Subtraction" );
-	
-	self->temperatureVertDerivField = (FeVariable*) OperatorFeVariable_NewUnary(  
-		"VerticalAdvectiveHeatFluxField",
-		(DomainContext*) context,
-		self->temperatureTotalDerivField, 
-		"TakeSecondComponent" );
-
-	/* Add the variables to register so we can checkpoint & examine if necessary */
-	FieldVariable_Register_Add( fV_Register, self->advectiveHeatFluxField );
-	FieldVariable_Register_Add( fV_Register, self->temperatureTotalDerivField );
-	FieldVariable_Register_Add( fV_Register, self->temperatureVertDerivField );
-
-	/* Add functions to entry points */
-	ContextEP_Append( self->context, AbstractContext_EP_FrequentOutput, Underworld_Nusselt_Output );
-}
-
-void _Underworld_Nusselt_Build( void* component, void* data ) {
-	Underworld_Nusselt*	self = (Underworld_Nusselt*)component;
-
-   Stg_Component_Build( self->gaussSwarm, data, False );
-	Stg_Component_Build( self->advectiveHeatFluxField, data, False );
-	Stg_Component_Build( self->temperatureTotalDerivField, data, False );
-	Stg_Component_Build( self->temperatureVertDerivField, data, False );
-   
-   _Codelet_Build( component, data );
-}
-
-void _Underworld_Nusselt_Initialise( void* component, void* data ) {
-	Underworld_Nusselt*	self = (Underworld_Nusselt*)component;
-
-   Stg_Component_Initialise( self->gaussSwarm, data, False );
-	Stg_Component_Initialise( self->advectiveHeatFluxField, data, False );
-	Stg_Component_Initialise( self->temperatureTotalDerivField, data, False );
-	Stg_Component_Initialise( self->temperatureVertDerivField, data, False );
-   
-   _Codelet_Initialise( component, data );
-}
-
-void _Underworld_Nusselt_Destroy( void* component, void* data ) {
-	Underworld_Nusselt*	self = (Underworld_Nusselt*)component;
-
-   Stg_Component_Destroy( self->gaussSwarm, data, False );
-	Stg_Component_Destroy( self->advectiveHeatFluxField, data, False );
-	Stg_Component_Destroy( self->temperatureTotalDerivField, data, False );
-	Stg_Component_Destroy( self->temperatureVertDerivField, data, False );
-   
-   _Codelet_Destroy( component, data );
-}
-
-void* _Underworld_Nusselt_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Underworld_Nusselt);
-	Type                                                      type = Underworld_Nusselt_Type;
-	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
-	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
-	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_Nusselt_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Underworld_Nusselt_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _Underworld_Nusselt_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _Underworld_Nusselt_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _Codelet_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _Underworld_Nusselt_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 Underworld_Nusselt_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Underworld_Nusselt_Type, (Name)"0", _Underworld_Nusselt_DefaultNew );
-}
-
-void Underworld_Nusselt_Output( UnderworldContext* context ) {
-	Underworld_Nusselt* self;
-
-	self = (Underworld_Nusselt* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_Nusselt_Type  );
-
-	/* This performs in integral given in the first half of equation 23 in 
-	 *  Moresi, L. N. and Solomatov, V. S.,  
-	 *  Numerical investigation of 2d convection with extremely large viscosity variations,  
-	 *  Phys. Fluids, 1995, Volume 7, pp 2154-2162. */
-	self->nusseltNumber = FeVariable_AverageTopLayer( self->temperatureVertDerivField, self->gaussSwarm, J_AXIS );
-
-	StgFEM_FrequentOutput_PrintValue( context, self->nusseltNumber );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/Nusselt/Nusselt.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/Output/Nusselt/Nusselt.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,177 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: Nusselt.c 619 2007-10-29 11:43:40Z RobertTurnbull $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Underworld.h>
+#include <StgFEM/FrequentOutput/FrequentOutput.h>
+
+#include "Nusselt.h"
+
+const Type Underworld_Nusselt_Type = "Underworld_Nusselt";
+
+void _Underworld_Nusselt_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
+	Underworld_Nusselt*		self = (Underworld_Nusselt*)component;
+	UnderworldContext*		context;
+	FieldVariable_Register*	fV_Register;
+	FieldVariable*				temperatureGradientsField;
+	FieldVariable*				velocityField;
+	FieldVariable*				temperatureField;
+
+	self->context = (AbstractContext*)Stg_ComponentFactory_PluginConstructByKey( cf, self, (Dictionary_Entry_Key)"Context", UnderworldContext, True, data  );
+	self->gaussSwarm = Stg_ComponentFactory_PluginConstructByKey( cf, self, (Dictionary_Entry_Key)"GaussSwarm", Swarm, True, data  );
+
+	StgFEM_FrequentOutput_PrintString( self->context, "Nusselt" );
+
+	context = (UnderworldContext*)self->context;
+	fV_Register = context->fieldVariable_Register;
+	/* Create Some FeVariables to calculate nusselt number */
+	temperatureField          = FieldVariable_Register_GetByName( fV_Register, "TemperatureField" );
+	velocityField             = FieldVariable_Register_GetByName( fV_Register, "VelocityField" );
+	temperatureGradientsField = FieldVariable_Register_GetByName( fV_Register, "TemperatureGradientsField" );
+	
+	self->advectiveHeatFluxField = OperatorFeVariable_NewBinary(  
+		"AdvectiveHeatFluxField",
+		(DomainContext*) context,
+		temperatureField, 
+		velocityField, 
+		"VectorScale" );
+
+	self->temperatureTotalDerivField = OperatorFeVariable_NewBinary(  
+		"TemperatureTotalDerivField",
+		(DomainContext*) context,
+		self->advectiveHeatFluxField, 
+		temperatureGradientsField, 
+		"Subtraction" );
+	
+	self->temperatureVertDerivField = (FeVariable*) OperatorFeVariable_NewUnary(  
+		"VerticalAdvectiveHeatFluxField",
+		(DomainContext*) context,
+		self->temperatureTotalDerivField, 
+		"TakeSecondComponent" );
+
+	/* Add the variables to register so we can checkpoint & examine if necessary */
+	FieldVariable_Register_Add( fV_Register, self->advectiveHeatFluxField );
+	FieldVariable_Register_Add( fV_Register, self->temperatureTotalDerivField );
+	FieldVariable_Register_Add( fV_Register, self->temperatureVertDerivField );
+
+	/* Add functions to entry points */
+	ContextEP_Append( self->context, AbstractContext_EP_FrequentOutput, Underworld_Nusselt_Output );
+}
+
+void _Underworld_Nusselt_Build( void* component, void* data ) {
+	Underworld_Nusselt*	self = (Underworld_Nusselt*)component;
+
+   Stg_Component_Build( self->gaussSwarm, data, False );
+	Stg_Component_Build( self->advectiveHeatFluxField, data, False );
+	Stg_Component_Build( self->temperatureTotalDerivField, data, False );
+	Stg_Component_Build( self->temperatureVertDerivField, data, False );
+   
+   _Codelet_Build( component, data );
+}
+
+void _Underworld_Nusselt_Initialise( void* component, void* data ) {
+	Underworld_Nusselt*	self = (Underworld_Nusselt*)component;
+
+   Stg_Component_Initialise( self->gaussSwarm, data, False );
+	Stg_Component_Initialise( self->advectiveHeatFluxField, data, False );
+	Stg_Component_Initialise( self->temperatureTotalDerivField, data, False );
+	Stg_Component_Initialise( self->temperatureVertDerivField, data, False );
+   
+   _Codelet_Initialise( component, data );
+}
+
+void _Underworld_Nusselt_Destroy( void* component, void* data ) {
+	Underworld_Nusselt*	self = (Underworld_Nusselt*)component;
+
+   Stg_Component_Destroy( self->gaussSwarm, data, False );
+	Stg_Component_Destroy( self->advectiveHeatFluxField, data, False );
+	Stg_Component_Destroy( self->temperatureTotalDerivField, data, False );
+	Stg_Component_Destroy( self->temperatureVertDerivField, data, False );
+   
+   _Codelet_Destroy( component, data );
+}
+
+void* _Underworld_Nusselt_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Underworld_Nusselt);
+	Type                                                      type = Underworld_Nusselt_Type;
+	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
+	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
+	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_Nusselt_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Underworld_Nusselt_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _Underworld_Nusselt_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _Underworld_Nusselt_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _Codelet_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _Underworld_Nusselt_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 Underworld_Nusselt_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Underworld_Nusselt_Type, (Name)"0", _Underworld_Nusselt_DefaultNew );
+}
+
+void Underworld_Nusselt_Output( UnderworldContext* context ) {
+	Underworld_Nusselt* self;
+
+	self = (Underworld_Nusselt* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_Nusselt_Type  );
+
+	/* This performs in integral given in the first half of equation 23 in 
+	 *  Moresi, L. N. and Solomatov, V. S.,  
+	 *  Numerical investigation of 2d convection with extremely large viscosity variations,  
+	 *  Phys. Fluids, 1995, Volume 7, pp 2154-2162. */
+	self->nusseltNumber = FeVariable_AverageTopLayer( self->temperatureVertDerivField, self->gaussSwarm, J_AXIS );
+
+	StgFEM_FrequentOutput_PrintValue( context, self->nusseltNumber );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/Nusselt_deltaT/Nusselt_deltaT.c
--- a/plugins/Output/Nusselt_deltaT/Nusselt_deltaT.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,152 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-** Copyright (c) 2005, Your Mom
-** 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 YOUR MOM 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.
-**
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Underworld.h>
-#include <StgFEM/FrequentOutput/FrequentOutput.h>
-
-#include "Nusselt_deltaT.h"
-
-const Type Underworld_Nusselt_deltaT_Type = "Underworld_Nusselt_deltaT";
-
-void _Underworld_Nusselt_deltaT_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
-	UnderworldContext* context;
-
-	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data ); 
-
-	/* Add functions to entry points */
-	Underworld_Nusselt_deltaT_Setup( context  );
-	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, Underworld_Nusselt_deltaT_Output );
-}
-
-void _Underworld_Nusselt_deltaT_Build( void* component, void* data ) {
-	Underworld_Nusselt_deltaT*	self = (Underworld_Nusselt_deltaT*)component;
-
-	Stg_Component_Build( self->dTField, data, False );
-}
-
-
-void* _Underworld_Nusselt_deltaT_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Underworld_Nusselt_deltaT);
-	Type                                                      type = Underworld_Nusselt_deltaT_Type;
-	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
-	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
-	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_Nusselt_deltaT_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Underworld_Nusselt_deltaT_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _Underworld_Nusselt_deltaT_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 Underworld_Nusselt_deltaT_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Underworld_Nusselt_deltaT_Type, (Name)"0", _Underworld_Nusselt_deltaT_DefaultNew );
-}
-
-
-
-void Underworld_Nusselt_deltaT_Setup( UnderworldContext* context ) {
-	FieldVariable_Register*              fV_Register               = context->fieldVariable_Register;
-	FieldVariable*                       temperatureGradientsField;
-	FieldVariable*                       velocityField;
-	FieldVariable*                       temperatureField;
-	OperatorFeVariable*                  advectiveHeatFluxField;
-	OperatorFeVariable*                  temperatureTotalDerivField;
-
-	Underworld_Nusselt_deltaT* self;
-
-	self = (Underworld_Nusselt_deltaT* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_Nusselt_deltaT_Type  );
-	
-	StgFEM_FrequentOutput_PrintString( context, "Nu/DeltaT" );
-
-	Journal_Firewall( 
-			context->gaussSwarm != NULL, 
-			Underworld_Error,
-			"Cannot find gauss swarm. Cannot use %s.\n", CURR_MODULE_NAME );
-
-	/* Create Some FeVariables to calculate nusselt number */
-	temperatureField          = FieldVariable_Register_GetByName( fV_Register, "TemperatureField" );
-	velocityField             = FieldVariable_Register_GetByName( fV_Register, "VelocityField" );
-	temperatureGradientsField = FieldVariable_Register_GetByName( fV_Register, "TemperatureGradientsField" );
-	
-	advectiveHeatFluxField = OperatorFeVariable_NewBinary(  
-			"AdvectiveHeatFluxField",
-			temperatureField, 
-			velocityField, 
-			"VectorScale" );
-
-	temperatureTotalDerivField = OperatorFeVariable_NewBinary(  
-			"TemperatureTotalDerivField",
-			advectiveHeatFluxField, 
-			temperatureGradientsField, 
-			"Subtraction" );
-	
-	self->dTField = (FeVariable*) OperatorFeVariable_NewUnary(  
-			"TemperatureTotalDerivField",
-			temperatureTotalDerivField, 
-			"TakeSecondComponent" );
-	self->dTField->feMesh = ((FeVariable*)velocityField)->feMesh;
-	
-}
-
-void Underworld_Nusselt_deltaT_Output( UnderworldContext* context ) {
-
-	Underworld_Nusselt_deltaT* self;
-	FieldVariable_Register*              fV_Register               = context->fieldVariable_Register;
-	FieldVariable*                       temperatureField;
-	double								temp;
-	
-	temperatureField          = FieldVariable_Register_GetByName( fV_Register, "TemperatureField" );
-	
-	self = (Underworld_Nusselt_deltaT*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_Nusselt_deltaT_Type  );
-
-	/* get_layer value */
-	/*self->shfl = FeVariable_AverageTopLayer( self->dTField, context->gaussSwarm, NULL, J_AXIS ); */
-	self->shfl = FeVariable_AverageTopLayer( self->dTField, context->gaussSwarm, J_AXIS );
-	
-	temp =   FeVariable_AveragePlane( temperatureField, J_AXIS, 0.0 );
-	
-	self->shfl/=temp;
-	
-		
-	StgFEM_FrequentOutput_PrintValue( context, self->shfl  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/Nusselt_deltaT/Nusselt_deltaT.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/Output/Nusselt_deltaT/Nusselt_deltaT.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,152 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** Copyright (c) 2005, Your Mom
+** 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 YOUR MOM 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.
+**
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Underworld.h>
+#include <StgFEM/FrequentOutput/FrequentOutput.h>
+
+#include "Nusselt_deltaT.h"
+
+const Type Underworld_Nusselt_deltaT_Type = "Underworld_Nusselt_deltaT";
+
+void _Underworld_Nusselt_deltaT_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
+	UnderworldContext* context;
+
+	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data ); 
+
+	/* Add functions to entry points */
+	Underworld_Nusselt_deltaT_Setup( context  );
+	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, Underworld_Nusselt_deltaT_Output );
+}
+
+void _Underworld_Nusselt_deltaT_Build( void* component, void* data ) {
+	Underworld_Nusselt_deltaT*	self = (Underworld_Nusselt_deltaT*)component;
+
+	Stg_Component_Build( self->dTField, data, False );
+}
+
+
+void* _Underworld_Nusselt_deltaT_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Underworld_Nusselt_deltaT);
+	Type                                                      type = Underworld_Nusselt_deltaT_Type;
+	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
+	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
+	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_Nusselt_deltaT_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Underworld_Nusselt_deltaT_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _Underworld_Nusselt_deltaT_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 Underworld_Nusselt_deltaT_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Underworld_Nusselt_deltaT_Type, (Name)"0", _Underworld_Nusselt_deltaT_DefaultNew );
+}
+
+
+
+void Underworld_Nusselt_deltaT_Setup( UnderworldContext* context ) {
+	FieldVariable_Register*              fV_Register               = context->fieldVariable_Register;
+	FieldVariable*                       temperatureGradientsField;
+	FieldVariable*                       velocityField;
+	FieldVariable*                       temperatureField;
+	OperatorFeVariable*                  advectiveHeatFluxField;
+	OperatorFeVariable*                  temperatureTotalDerivField;
+
+	Underworld_Nusselt_deltaT* self;
+
+	self = (Underworld_Nusselt_deltaT* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_Nusselt_deltaT_Type  );
+	
+	StgFEM_FrequentOutput_PrintString( context, "Nu/DeltaT" );
+
+	Journal_Firewall( 
+			context->gaussSwarm != NULL, 
+			Underworld_Error,
+			"Cannot find gauss swarm. Cannot use %s.\n", CURR_MODULE_NAME );
+
+	/* Create Some FeVariables to calculate nusselt number */
+	temperatureField          = FieldVariable_Register_GetByName( fV_Register, "TemperatureField" );
+	velocityField             = FieldVariable_Register_GetByName( fV_Register, "VelocityField" );
+	temperatureGradientsField = FieldVariable_Register_GetByName( fV_Register, "TemperatureGradientsField" );
+	
+	advectiveHeatFluxField = OperatorFeVariable_NewBinary(  
+			"AdvectiveHeatFluxField",
+			temperatureField, 
+			velocityField, 
+			"VectorScale" );
+
+	temperatureTotalDerivField = OperatorFeVariable_NewBinary(  
+			"TemperatureTotalDerivField",
+			advectiveHeatFluxField, 
+			temperatureGradientsField, 
+			"Subtraction" );
+	
+	self->dTField = (FeVariable*) OperatorFeVariable_NewUnary(  
+			"TemperatureTotalDerivField",
+			temperatureTotalDerivField, 
+			"TakeSecondComponent" );
+	self->dTField->feMesh = ((FeVariable*)velocityField)->feMesh;
+	
+}
+
+void Underworld_Nusselt_deltaT_Output( UnderworldContext* context ) {
+
+	Underworld_Nusselt_deltaT* self;
+	FieldVariable_Register*              fV_Register               = context->fieldVariable_Register;
+	FieldVariable*                       temperatureField;
+	double								temp;
+	
+	temperatureField          = FieldVariable_Register_GetByName( fV_Register, "TemperatureField" );
+	
+	self = (Underworld_Nusselt_deltaT*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_Nusselt_deltaT_Type  );
+
+	/* get_layer value */
+	/*self->shfl = FeVariable_AverageTopLayer( self->dTField, context->gaussSwarm, NULL, J_AXIS ); */
+	self->shfl = FeVariable_AverageTopLayer( self->dTField, context->gaussSwarm, J_AXIS );
+	
+	temp =   FeVariable_AveragePlane( temperatureField, J_AXIS, 0.0 );
+	
+	self->shfl/=temp;
+	
+		
+	StgFEM_FrequentOutput_PrintValue( context, self->shfl  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/OutputForSPModel/OutputForSPModel.c
--- a/plugins/Output/OutputForSPModel/OutputForSPModel.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,320 +0,0 @@
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Underworld.h>
-
-#include<string.h>
-#include<assert.h>
-#include<stdlib.h>
-
-
-const Type Underworld_OutputForSPModel_Type = "Underworld_OutputForSPModel";
-
-FILE *iFile, *oFile;
-unsigned outputTimestep=0;
-Index Underworld_OutputForSPModel_Register( PluginsManager* pluginsManager );
-void _Underworld_OutputForSPModel_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data );
-void* _Underworld_OutputForSPModel_DefaultNew( Name name );
-void Underworld_OutputForSPModelDo( UnderworldContext* context );
-
-
-void Underworld_DoHeightInterpolation( FeMesh* mesh, ElementType* elType, unsigned *nodes, double *Nx, unsigned nodesPerFace, double *height ) {
-	double weight, nodeHeight;
-	int node_I;
-	/* initialise height */
-	*height = 0;
-	for( node_I = 0 ; node_I < nodesPerFace ; node_I++ ) {
-		/* interpolate each surface node's height to the 
-		 * wantedCoord using the shapeFunctions */
-		weight = Nx[node_I];
-		nodeHeight = Mesh_GetVertex(mesh, nodes[node_I])[1];
-		*height += (weight*nodeHeight);
-	}
-}
-
-void myConvertGlobalCoordToElLocal( double *tmpMax, double *tmpMin, double *wantCoord, double *lProjCoord ) {
-	/* converts the a global coordinate to local coordinate defined between [-1,1] */
-	lProjCoord[0] = ( (2*wantCoord[0]-tmpMin[0]-tmpMax[0])/(tmpMax[0]-tmpMin[0]) );
-	lProjCoord[1] = ( (2*wantCoord[2]-tmpMin[2]-tmpMax[2])/(tmpMax[2]-tmpMin[2]) );
-}
-
-Bool OutputForSPModel_Recursive( FeMesh* mesh, double* wantCoord, unsigned *minIJK, unsigned *maxIJK, unsigned* set, int axis ) {
-	unsigned IJK[3];
-	double maxX, halfX;
-
-	/* finish condition */
-	if ( (maxIJK[axis] - minIJK[axis]) == 1 ) {
-		set[0] = minIJK[axis];
-		set[1] = maxIJK[axis];
-		return True;
-	}
-
-	/* set IJK to be the same as minIJK but in the axis of interest */
-	memcpy( IJK, minIJK, 3*sizeof(unsigned) );
-	/* new index = x0 + (x1-x0)/2 */
-	IJK[axis] =  (double)( minIJK[axis] + ((maxIJK[axis] - minIJK[axis])/2) );
-
-	halfX = Mesh_GetVertex( mesh, RegularMeshUtils_Node_3DTo1D( mesh, IJK ) )[axis];
-	maxX = Mesh_GetVertex( mesh, RegularMeshUtils_Node_3DTo1D( mesh, maxIJK ) )[axis];
-
-	if( Num_InRange( wantCoord[axis], halfX, maxX ) ) {
-		/* halfX < wantCoord <= maxX */
-		return OutputForSPModel_Recursive( mesh, wantCoord, IJK, maxIJK, set, axis );
-	} else {
-		/* minX < wantCoord <= halfX */
-		return OutputForSPModel_Recursive( mesh, wantCoord, minIJK, IJK, set, axis );
-	}
-	/* report error */
-	return 0;
-}
-
-int Underworld_OutputForSPModel_InterpolateHeightInXZ( FeMesh* mesh, double* wantCoord ) {
-	Grid* vertGrid;
-	IArray* inc;
-	ElementType* elType;
-	double *coord, tmpMin[3], tmpMax[3], lProjCoord[2], Nx[4], tmpGMin[3], tmpGMax[3];
-	unsigned setI[2], setK[2], nodes[4], node_I, minIJK[3], maxIJK[3], nodesPerFace, gMinVertOnProc, gMaxVertOnProc;
-	int ii, jj, kk, ijk[3];
-
-	inc = IArray_New();
-
-	assert( mesh );
-
-	/* first check if location is on this proc */
-	Mesh_GetLocalCoordRange( mesh, tmpMin, tmpMax );
-	Mesh_GetGlobalCoordRange( mesh, tmpGMin, tmpGMax );
-	if( !Num_InRange( wantCoord[0], tmpMin[0], tmpMax[0] ) || !Num_InRange( wantCoord[2], tmpMin[2], tmpMax[2] ) ) {
-		printf("Error ... the coord (x,z) = (%g, %g), is not a local coord!!!\n", wantCoord[0], wantCoord[2] );
-		assert(0);
-	}
-
-	vertGrid = *(Grid**)ExtensionManager_Get( mesh->info, mesh,
-  	ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
-
-	nodesPerFace = 4;
-	/* set up IJK parametrisation of nodes */
-	minIJK[0] = minIJK[1] = minIJK[2] = 0;
-
-	maxIJK[0] = vertGrid->sizes[0];
-	maxIJK[1] = vertGrid->sizes[1];
-	maxIJK[2] = vertGrid->sizes[2];
-
-	jj = maxIJK[1]-1;
-	/* get global indicies of min max nodes
-	 * ASSUME they are the left bottom closest corner and the right heighest farthest corner ??? */
-	gMinVertOnProc = Mesh_DomainToGlobal( mesh, MT_VERTEX, 0 ); 
-	gMaxVertOnProc = Mesh_DomainToGlobal( mesh, MT_VERTEX, Mesh_GetLocalSize(mesh, MT_VERTEX)-1 ); 
-	
-	/* convert to ijk definitions */
-	RegularMeshUtils_Node_1DTo3D( mesh, gMinVertOnProc, minIJK );
-	RegularMeshUtils_Node_1DTo3D( mesh, gMaxVertOnProc, maxIJK );
-
-	/* get the 2 nodes indecies in the I-axis */
-	OutputForSPModel_Recursive( mesh, wantCoord, minIJK, maxIJK, setI, 0 );
-
-	/* get the 2 nodes indecies in the K-axis */
-	OutputForSPModel_Recursive( mesh, wantCoord, minIJK, maxIJK, setK, 2 );
-
-	/* set y to maximum */
-	minIJK[1] = jj;
-	/* move in x */
-	minIJK[0] = setI[0]; minIJK[2] = setK[0];
-	nodes[0] = RegularMeshUtils_Node_3DTo1D( mesh, minIJK );
-	minIJK[0] = setI[1]; minIJK[2] = setK[0];
-	nodes[1] = RegularMeshUtils_Node_3DTo1D( mesh, minIJK );
-
-	/* move in z */
-	minIJK[0] = setI[0]; minIJK[2] = setK[1];
-	nodes[2] = RegularMeshUtils_Node_3DTo1D( mesh, minIJK );
-	minIJK[0] = setI[1]; minIJK[2] = setK[1];
-	nodes[3] = RegularMeshUtils_Node_3DTo1D( mesh, minIJK );
-
-	tmpMax[0] = tmpMin[0] = Mesh_GetVertex(mesh, nodes[0])[0];
-	tmpMax[2] = tmpMin[2] = Mesh_GetVertex(mesh, nodes[0])[2];
-
-	for( node_I = 1 ; node_I < nodesPerFace ; node_I++ ) { 
-		coord = Mesh_GetVertex( mesh, nodes[node_I] );
-		/* x-coord test */
-		if( coord[0] > tmpMax[0] )
-			tmpMax[0] = coord[0];
-		else if (coord[0] < tmpMin[0] ) 
-			tmpMin[0] = coord[0];
-		/* z-coord test */
-		if( coord[2] > tmpMax[2] )
-			tmpMax[2] = coord[2];
-		else if (coord[2] < tmpMin[2] ) 
-			tmpMin[2] = coord[2];
-	}
-
-	if( Num_InRange( wantCoord[0], tmpMin[0], tmpMax[0] ) )  {
-		/* lets get interested */
-		if( Num_InRange( wantCoord[2], tmpMin[2], tmpMax[2] ) ) {
-			/* wantCoord is in this face, now take the shapeFunctions of this element
-			 * to aid interpolation */
-			myConvertGlobalCoordToElLocal( tmpMax, tmpMin, wantCoord, lProjCoord );
-			/* evaluate the shape functions at that local spot */
-			_BilinearElementType_SF_allNodes( elType, lProjCoord, Nx ); 
-
-			/* now we have the nodes, next interpolate heights */
-			Underworld_DoHeightInterpolation( mesh, elType, nodes, Nx, nodesPerFace, &wantCoord[1] );
-			return 1;
-		}
-	}
-	/* report failure */
-	return 0;
-}
-
-void Underworld_OutputForSPModelDo( UnderworldContext* context ) {
-	FeMesh* mesh = context->velocityField->feMesh;
-	double wantCoord[3], minInputCrd[2], maxInputCrd[2], uw_Coord[3], Trans[3][3];
-	double originalHeight, bc;
-	int coordCount, line_I = 0;
-	char buffer[512];
-	
-	MPI_Comm comm;
-	int      myRank;
-	int      nProcs;
-
-	/* don't do anything if this isn't the outputTimestep */
-	if( context->timeStep != outputTimestep ) return; 
-
-	double startTime;
-
-	oFile = NULL;
-	iFile = NULL; 
-	
-	char *iFileName = Dictionary_GetString_WithDefault( context->dictionary, "OutputForSPModel_InputFile", "spm.input" );
-	char *oFileName = Memory_Alloc_Array_Unnamed( char, 
-			/*		outputPath/SPModelMeshOutput.time.dat */ 
-			strlen(context->outputPath)+1+strlen("spmMeshOutput")+2+5+1+3 );
-
-	comm = Comm_GetMPIComm( Mesh_GetCommTopology( mesh, MT_VERTEX ) );
-
-	MPI_Comm_size( comm, (int*)&nProcs );
-	MPI_Comm_rank( comm, (int*)&myRank );
-
-	sprintf( oFileName, "%s/spmMeshOutput.%.5u.dat", context->outputPath, context->timeStep );
-
-	startTime = MPI_Wtime();
-
-	/* open the input file and get the number of test coord */
-	if( (iFile=fopen(iFileName, "r" )) == NULL ) {
-		printf("ERROR in %s: couldn't open file %s\n", __func__, iFileName );
-		exit(0);
-	}
-
-	maxInputCrd[0] = maxInputCrd[1] = 0;
-	minInputCrd[0] = minInputCrd[1] = 0;
-
-	while( fgets( buffer, 512, iFile ) != NULL ) { 
-		line_I++; 
-		/* test for the max and min coord in x and z */
-		sscanf( buffer, "%lf %lf", &wantCoord[0], &wantCoord[2] );
-		if( wantCoord[0] > maxInputCrd[0] ) maxInputCrd[0] = wantCoord[0];
-		else if (wantCoord[0] < minInputCrd[0] ) minInputCrd[0] = wantCoord[0];
-
-		if( wantCoord[2] > maxInputCrd[1] ) maxInputCrd[1] = wantCoord[2];
-		else if (wantCoord[2] < minInputCrd[1] ) minInputCrd[1] = wantCoord[2];
-	}
-	/* allocate the right amount of memory for the coords */
-	coordCount = line_I;
-
-	/* close the input file */
-	fclose( iFile );
-
-
-	/* setup affine transformation.
-	 * |x'|   | A 0 xt | |x|
-	 * |z'| = | 0 B yt | |z|
-	 * |1 |   | 0 0 1  | |1|
-	 *
-	 * where:
-	 *  x' and z' are the uw_Coord
-	 *  x and z are the spmodel coords
-	 *  xt and yt and the scaled offsets in each axis
-	 */
-
-	/* setup coord transform matrix */
-	Trans[0][0] = Trans[0][1] = Trans[0][2] = 0;
-	Trans[1][0] = Trans[1][1] = Trans[1][2] = 0;
-	Trans[2][0] = Trans[2][1] = Trans[2][2] = 0;
-
-	/* setup scaling transformation */
-	Trans[0][0] = (mesh->maxGlobalCrd[0]-mesh->minGlobalCrd[0]) / (maxInputCrd[0] - minInputCrd[0]);
-	Trans[1][1] = (mesh->maxGlobalCrd[2]-mesh->minGlobalCrd[2]) / (maxInputCrd[1] - minInputCrd[1]);
-
-	/* setup translation transformation */
-	Trans[0][2] = mesh->minGlobalCrd[0]- (Trans[0][0]*minInputCrd[0]);
-	Trans[1][2] = mesh->minGlobalCrd[2]- (Trans[1][1]*minInputCrd[1]);
-
-	/* re-open the input file */
-	if( (iFile=fopen(iFileName, "r" )) == NULL ) {
-			printf("ERROR in %s: couldn't open file %s\n", __func__, iFileName );
-			exit(0);
-	}
-	
-	/* open file if proc 0 */
-	if( myRank == 0 ) 
-		oFile = fopen( oFileName, "w" );
-	else 
-		oFile = fopen( oFileName, "a" );
-
-	assert( mesh );
-
-	for( line_I = 0 ; line_I < coordCount ; line_I++ ) {
-		fscanf( iFile, "%lf %lf %lf %lf", &(wantCoord[0]), &(wantCoord[2]), &originalHeight, &bc);
-		/* do top surface interpolation at the (x-z) - where 
-		 * x = wantCoord[0]
-		 * z = wantCoord[2]
-		 * and the interpolated y will be evaluate in wantCoord[1] */
-
-		/* do an transformation here, into the Underworld coords */
-		uw_Coord[0] = Trans[0][0]*wantCoord[0] + Trans[0][1]*wantCoord[2] + Trans[0][2]*1;
-		uw_Coord[2] = Trans[1][0]*wantCoord[0] + Trans[1][1]*wantCoord[2] + Trans[1][2]*1;
-
-		if (Underworld_OutputForSPModel_InterpolateHeightInXZ( mesh, uw_Coord ) == 0 ) {
-			/* report error */
-			printf("\n\nError with the %d-th coord = (%g, %g, %g)\n\n", line_I, wantCoord[0], wantCoord[1], wantCoord[2] );
-		}
-		/* output is in format (x,y,z). Where y is the interpolated coord */
-		fprintf( oFile, "%lf %lf %lf %lf\n", wantCoord[0], uw_Coord[1], wantCoord[2], bc );
-	}
-
-	printf("*******************************\n");
-	printf("Time taken for OutputForSPModel\n");
-	printf("            %g\n", MPI_Wtime()-startTime);
-	printf("*******************************\n");
-
-	fclose( iFile );
-	fclose( oFile );
-	Memory_Free( oFileName );
-}
-		
-Index Underworld_OutputForSPModel_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Underworld_OutputForSPModel_Type, (Name)"0", _Underworld_OutputForSPModel_DefaultNew );
-}
-
-void* _Underworld_OutputForSPModel_DefaultNew( Name name  ) {
-	return Codelet_New( 
-			Underworld_OutputForSPModel_Type,
-			_Underworld_OutputForSPModel_DefaultNew,
-			_Underworld_OutputForSPModel_AssignFromXML,
-			_Codelet_Build,
-			_Codelet_Initialise,
-			_Codelet_Execute,
-			_Codelet_Destroy,
-			name );
-}
-
-void _Underworld_OutputForSPModel_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
-	UnderworldContext* context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data  );
-
-	outputTimestep = Dictionary_GetUnsignedInt_WithDefault( context->dictionary, "OutputForSPModel_OutputTimestep", 10 );
-
-	ContextEP_Append( context, AbstractContext_EP_Dump, Underworld_OutputForSPModelDo );
-}
-
-
-
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/OutputForSPModel/OutputForSPModel.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/Output/OutputForSPModel/OutputForSPModel.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,320 @@
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Underworld.h>
+
+#include<string.h>
+#include<assert.h>
+#include<stdlib.h>
+
+
+const Type Underworld_OutputForSPModel_Type = "Underworld_OutputForSPModel";
+
+FILE *iFile, *oFile;
+unsigned outputTimestep=0;
+Index Underworld_OutputForSPModel_Register( PluginsManager* pluginsManager );
+void _Underworld_OutputForSPModel_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data );
+void* _Underworld_OutputForSPModel_DefaultNew( Name name );
+void Underworld_OutputForSPModelDo( UnderworldContext* context );
+
+
+void Underworld_DoHeightInterpolation( FeMesh* mesh, ElementType* elType, unsigned *nodes, double *Nx, unsigned nodesPerFace, double *height ) {
+	double weight, nodeHeight;
+	int node_I;
+	/* initialise height */
+	*height = 0;
+	for( node_I = 0 ; node_I < nodesPerFace ; node_I++ ) {
+		/* interpolate each surface node's height to the 
+		 * wantedCoord using the shapeFunctions */
+		weight = Nx[node_I];
+		nodeHeight = Mesh_GetVertex(mesh, nodes[node_I])[1];
+		*height += (weight*nodeHeight);
+	}
+}
+
+void myConvertGlobalCoordToElLocal( double *tmpMax, double *tmpMin, double *wantCoord, double *lProjCoord ) {
+	/* converts the a global coordinate to local coordinate defined between [-1,1] */
+	lProjCoord[0] = ( (2*wantCoord[0]-tmpMin[0]-tmpMax[0])/(tmpMax[0]-tmpMin[0]) );
+	lProjCoord[1] = ( (2*wantCoord[2]-tmpMin[2]-tmpMax[2])/(tmpMax[2]-tmpMin[2]) );
+}
+
+Bool OutputForSPModel_Recursive( FeMesh* mesh, double* wantCoord, unsigned *minIJK, unsigned *maxIJK, unsigned* set, int axis ) {
+	unsigned IJK[3];
+	double maxX, halfX;
+
+	/* finish condition */
+	if ( (maxIJK[axis] - minIJK[axis]) == 1 ) {
+		set[0] = minIJK[axis];
+		set[1] = maxIJK[axis];
+		return True;
+	}
+
+	/* set IJK to be the same as minIJK but in the axis of interest */
+	memcpy( IJK, minIJK, 3*sizeof(unsigned) );
+	/* new index = x0 + (x1-x0)/2 */
+	IJK[axis] =  (double)( minIJK[axis] + ((maxIJK[axis] - minIJK[axis])/2) );
+
+	halfX = Mesh_GetVertex( mesh, RegularMeshUtils_Node_3DTo1D( mesh, IJK ) )[axis];
+	maxX = Mesh_GetVertex( mesh, RegularMeshUtils_Node_3DTo1D( mesh, maxIJK ) )[axis];
+
+	if( Num_InRange( wantCoord[axis], halfX, maxX ) ) {
+		/* halfX < wantCoord <= maxX */
+		return OutputForSPModel_Recursive( mesh, wantCoord, IJK, maxIJK, set, axis );
+	} else {
+		/* minX < wantCoord <= halfX */
+		return OutputForSPModel_Recursive( mesh, wantCoord, minIJK, IJK, set, axis );
+	}
+	/* report error */
+	return 0;
+}
+
+int Underworld_OutputForSPModel_InterpolateHeightInXZ( FeMesh* mesh, double* wantCoord ) {
+	Grid* vertGrid;
+	IArray* inc;
+	ElementType* elType;
+	double *coord, tmpMin[3], tmpMax[3], lProjCoord[2], Nx[4], tmpGMin[3], tmpGMax[3];
+	unsigned setI[2], setK[2], nodes[4], node_I, minIJK[3], maxIJK[3], nodesPerFace, gMinVertOnProc, gMaxVertOnProc;
+	int ii, jj, kk, ijk[3];
+
+	inc = IArray_New();
+
+	assert( mesh );
+
+	/* first check if location is on this proc */
+	Mesh_GetLocalCoordRange( mesh, tmpMin, tmpMax );
+	Mesh_GetGlobalCoordRange( mesh, tmpGMin, tmpGMax );
+	if( !Num_InRange( wantCoord[0], tmpMin[0], tmpMax[0] ) || !Num_InRange( wantCoord[2], tmpMin[2], tmpMax[2] ) ) {
+		printf("Error ... the coord (x,z) = (%g, %g), is not a local coord!!!\n", wantCoord[0], wantCoord[2] );
+		assert(0);
+	}
+
+	vertGrid = *(Grid**)ExtensionManager_Get( mesh->info, mesh,
+  	ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
+
+	nodesPerFace = 4;
+	/* set up IJK parametrisation of nodes */
+	minIJK[0] = minIJK[1] = minIJK[2] = 0;
+
+	maxIJK[0] = vertGrid->sizes[0];
+	maxIJK[1] = vertGrid->sizes[1];
+	maxIJK[2] = vertGrid->sizes[2];
+
+	jj = maxIJK[1]-1;
+	/* get global indicies of min max nodes
+	 * ASSUME they are the left bottom closest corner and the right heighest farthest corner ??? */
+	gMinVertOnProc = Mesh_DomainToGlobal( mesh, MT_VERTEX, 0 ); 
+	gMaxVertOnProc = Mesh_DomainToGlobal( mesh, MT_VERTEX, Mesh_GetLocalSize(mesh, MT_VERTEX)-1 ); 
+	
+	/* convert to ijk definitions */
+	RegularMeshUtils_Node_1DTo3D( mesh, gMinVertOnProc, minIJK );
+	RegularMeshUtils_Node_1DTo3D( mesh, gMaxVertOnProc, maxIJK );
+
+	/* get the 2 nodes indecies in the I-axis */
+	OutputForSPModel_Recursive( mesh, wantCoord, minIJK, maxIJK, setI, 0 );
+
+	/* get the 2 nodes indecies in the K-axis */
+	OutputForSPModel_Recursive( mesh, wantCoord, minIJK, maxIJK, setK, 2 );
+
+	/* set y to maximum */
+	minIJK[1] = jj;
+	/* move in x */
+	minIJK[0] = setI[0]; minIJK[2] = setK[0];
+	nodes[0] = RegularMeshUtils_Node_3DTo1D( mesh, minIJK );
+	minIJK[0] = setI[1]; minIJK[2] = setK[0];
+	nodes[1] = RegularMeshUtils_Node_3DTo1D( mesh, minIJK );
+
+	/* move in z */
+	minIJK[0] = setI[0]; minIJK[2] = setK[1];
+	nodes[2] = RegularMeshUtils_Node_3DTo1D( mesh, minIJK );
+	minIJK[0] = setI[1]; minIJK[2] = setK[1];
+	nodes[3] = RegularMeshUtils_Node_3DTo1D( mesh, minIJK );
+
+	tmpMax[0] = tmpMin[0] = Mesh_GetVertex(mesh, nodes[0])[0];
+	tmpMax[2] = tmpMin[2] = Mesh_GetVertex(mesh, nodes[0])[2];
+
+	for( node_I = 1 ; node_I < nodesPerFace ; node_I++ ) { 
+		coord = Mesh_GetVertex( mesh, nodes[node_I] );
+		/* x-coord test */
+		if( coord[0] > tmpMax[0] )
+			tmpMax[0] = coord[0];
+		else if (coord[0] < tmpMin[0] ) 
+			tmpMin[0] = coord[0];
+		/* z-coord test */
+		if( coord[2] > tmpMax[2] )
+			tmpMax[2] = coord[2];
+		else if (coord[2] < tmpMin[2] ) 
+			tmpMin[2] = coord[2];
+	}
+
+	if( Num_InRange( wantCoord[0], tmpMin[0], tmpMax[0] ) )  {
+		/* lets get interested */
+		if( Num_InRange( wantCoord[2], tmpMin[2], tmpMax[2] ) ) {
+			/* wantCoord is in this face, now take the shapeFunctions of this element
+			 * to aid interpolation */
+			myConvertGlobalCoordToElLocal( tmpMax, tmpMin, wantCoord, lProjCoord );
+			/* evaluate the shape functions at that local spot */
+			_BilinearElementType_SF_allNodes( elType, lProjCoord, Nx ); 
+
+			/* now we have the nodes, next interpolate heights */
+			Underworld_DoHeightInterpolation( mesh, elType, nodes, Nx, nodesPerFace, &wantCoord[1] );
+			return 1;
+		}
+	}
+	/* report failure */
+	return 0;
+}
+
+void Underworld_OutputForSPModelDo( UnderworldContext* context ) {
+	FeMesh* mesh = context->velocityField->feMesh;
+	double wantCoord[3], minInputCrd[2], maxInputCrd[2], uw_Coord[3], Trans[3][3];
+	double originalHeight, bc;
+	int coordCount, line_I = 0;
+	char buffer[512];
+	
+	MPI_Comm comm;
+	int      myRank;
+	int      nProcs;
+
+	/* don't do anything if this isn't the outputTimestep */
+	if( context->timeStep != outputTimestep ) return; 
+
+	double startTime;
+
+	oFile = NULL;
+	iFile = NULL; 
+	
+	char *iFileName = Dictionary_GetString_WithDefault( context->dictionary, "OutputForSPModel_InputFile", "spm.input" );
+	char *oFileName = Memory_Alloc_Array_Unnamed( char, 
+			/*		outputPath/SPModelMeshOutput.time.dat */ 
+			strlen(context->outputPath)+1+strlen("spmMeshOutput")+2+5+1+3 );
+
+	comm = Comm_GetMPIComm( Mesh_GetCommTopology( mesh, MT_VERTEX ) );
+
+	MPI_Comm_size( comm, (int*)&nProcs );
+	MPI_Comm_rank( comm, (int*)&myRank );
+
+	sprintf( oFileName, "%s/spmMeshOutput.%.5u.dat", context->outputPath, context->timeStep );
+
+	startTime = MPI_Wtime();
+
+	/* open the input file and get the number of test coord */
+	if( (iFile=fopen(iFileName, "r" )) == NULL ) {
+		printf("ERROR in %s: couldn't open file %s\n", __func__, iFileName );
+		exit(0);
+	}
+
+	maxInputCrd[0] = maxInputCrd[1] = 0;
+	minInputCrd[0] = minInputCrd[1] = 0;
+
+	while( fgets( buffer, 512, iFile ) != NULL ) { 
+		line_I++; 
+		/* test for the max and min coord in x and z */
+		sscanf( buffer, "%lf %lf", &wantCoord[0], &wantCoord[2] );
+		if( wantCoord[0] > maxInputCrd[0] ) maxInputCrd[0] = wantCoord[0];
+		else if (wantCoord[0] < minInputCrd[0] ) minInputCrd[0] = wantCoord[0];
+
+		if( wantCoord[2] > maxInputCrd[1] ) maxInputCrd[1] = wantCoord[2];
+		else if (wantCoord[2] < minInputCrd[1] ) minInputCrd[1] = wantCoord[2];
+	}
+	/* allocate the right amount of memory for the coords */
+	coordCount = line_I;
+
+	/* close the input file */
+	fclose( iFile );
+
+
+	/* setup affine transformation.
+	 * |x'|   | A 0 xt | |x|
+	 * |z'| = | 0 B yt | |z|
+	 * |1 |   | 0 0 1  | |1|
+	 *
+	 * where:
+	 *  x' and z' are the uw_Coord
+	 *  x and z are the spmodel coords
+	 *  xt and yt and the scaled offsets in each axis
+	 */
+
+	/* setup coord transform matrix */
+	Trans[0][0] = Trans[0][1] = Trans[0][2] = 0;
+	Trans[1][0] = Trans[1][1] = Trans[1][2] = 0;
+	Trans[2][0] = Trans[2][1] = Trans[2][2] = 0;
+
+	/* setup scaling transformation */
+	Trans[0][0] = (mesh->maxGlobalCrd[0]-mesh->minGlobalCrd[0]) / (maxInputCrd[0] - minInputCrd[0]);
+	Trans[1][1] = (mesh->maxGlobalCrd[2]-mesh->minGlobalCrd[2]) / (maxInputCrd[1] - minInputCrd[1]);
+
+	/* setup translation transformation */
+	Trans[0][2] = mesh->minGlobalCrd[0]- (Trans[0][0]*minInputCrd[0]);
+	Trans[1][2] = mesh->minGlobalCrd[2]- (Trans[1][1]*minInputCrd[1]);
+
+	/* re-open the input file */
+	if( (iFile=fopen(iFileName, "r" )) == NULL ) {
+			printf("ERROR in %s: couldn't open file %s\n", __func__, iFileName );
+			exit(0);
+	}
+	
+	/* open file if proc 0 */
+	if( myRank == 0 ) 
+		oFile = fopen( oFileName, "w" );
+	else 
+		oFile = fopen( oFileName, "a" );
+
+	assert( mesh );
+
+	for( line_I = 0 ; line_I < coordCount ; line_I++ ) {
+		fscanf( iFile, "%lf %lf %lf %lf", &(wantCoord[0]), &(wantCoord[2]), &originalHeight, &bc);
+		/* do top surface interpolation at the (x-z) - where 
+		 * x = wantCoord[0]
+		 * z = wantCoord[2]
+		 * and the interpolated y will be evaluate in wantCoord[1] */
+
+		/* do an transformation here, into the Underworld coords */
+		uw_Coord[0] = Trans[0][0]*wantCoord[0] + Trans[0][1]*wantCoord[2] + Trans[0][2]*1;
+		uw_Coord[2] = Trans[1][0]*wantCoord[0] + Trans[1][1]*wantCoord[2] + Trans[1][2]*1;
+
+		if (Underworld_OutputForSPModel_InterpolateHeightInXZ( mesh, uw_Coord ) == 0 ) {
+			/* report error */
+			printf("\n\nError with the %d-th coord = (%g, %g, %g)\n\n", line_I, wantCoord[0], wantCoord[1], wantCoord[2] );
+		}
+		/* output is in format (x,y,z). Where y is the interpolated coord */
+		fprintf( oFile, "%lf %lf %lf %lf\n", wantCoord[0], uw_Coord[1], wantCoord[2], bc );
+	}
+
+	printf("*******************************\n");
+	printf("Time taken for OutputForSPModel\n");
+	printf("            %g\n", MPI_Wtime()-startTime);
+	printf("*******************************\n");
+
+	fclose( iFile );
+	fclose( oFile );
+	Memory_Free( oFileName );
+}
+		
+Index Underworld_OutputForSPModel_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Underworld_OutputForSPModel_Type, (Name)"0", _Underworld_OutputForSPModel_DefaultNew );
+}
+
+void* _Underworld_OutputForSPModel_DefaultNew( Name name  ) {
+	return Codelet_New( 
+			Underworld_OutputForSPModel_Type,
+			_Underworld_OutputForSPModel_DefaultNew,
+			_Underworld_OutputForSPModel_AssignFromXML,
+			_Codelet_Build,
+			_Codelet_Initialise,
+			_Codelet_Execute,
+			_Codelet_Destroy,
+			name );
+}
+
+void _Underworld_OutputForSPModel_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
+	UnderworldContext* context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data  );
+
+	outputTimestep = Dictionary_GetUnsignedInt_WithDefault( context->dictionary, "OutputForSPModel_OutputTimestep", 10 );
+
+	ContextEP_Append( context, AbstractContext_EP_Dump, Underworld_OutputForSPModelDo );
+}
+
+
+
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/Shfl/Shfl.c
--- a/plugins/Output/Shfl/Shfl.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,175 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-** Copyright (c) 2005, Your Mom
-** 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 YOUR MOM 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.
-**
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Underworld.h>
-#include <StgFEM/FrequentOutput/FrequentOutput.h>
-
-#include "Shfl.h"
-
-const Type Underworld_Shfl_Type = "Underworld_Shfl";
-
-void _Underworld_Shfl_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
-	UnderworldContext* context;
-
-	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data ); 
-
-	/* Add functions to entry points */
-	Underworld_Shfl_Setup( context  );
-	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, Underworld_Shfl_Output );
-}
-
-void _Underworld_Shfl_Build( void* component, void* data ) {
-	Underworld_Shfl*	self = (Underworld_Shfl*)component;
-
-	assert( self );
-
-	Stg_Component_Build( self->dTField, data, False );
-   
-   _Codelet_Build( self, data );
-}
-
-void _Underworld_Shfl_Destroy( void* component, void* data ) {
-	Underworld_Shfl*	self = (Underworld_Shfl*)component;
-
-   _Codelet_Destroy( self, data );
-
-	Stg_Component_Destroy( self->dTField, data, False );
-}
-
-void _Underworld_Shfl_Initialise( void* component, void* data ) {
-	Underworld_Shfl*	self = (Underworld_Shfl*)component;
-
-	assert( self );
-
-	Stg_Component_Initialise( self->dTField, data, False );
-   
-   _Codelet_Initialise( self, data );
-}
-
-void* _Underworld_Shfl_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Underworld_Shfl);
-	Type                                                      type = Underworld_Shfl_Type;
-	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
-	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
-	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_Shfl_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Underworld_Shfl_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _Underworld_Shfl_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _Underworld_Shfl_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _Codelet_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _Underworld_Shfl_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 Underworld_Shfl_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Underworld_Shfl_Type, (Name)"0", _Underworld_Shfl_DefaultNew );
-}
-
-
-void Underworld_Shfl_Setup( UnderworldContext* context ) {
-	FieldVariable_Register*  fV_Register               = context->fieldVariable_Register;
-	FieldVariable*           temperatureGradientsField;
-	FieldVariable*           velocityField;
-	FieldVariable*           temperatureField;
-	OperatorFeVariable*      advectiveHeatFluxField;
-	OperatorFeVariable*      temperatureTotalDerivField;
-	Swarm*					    gaussSwarm = (Swarm* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"gaussSwarm" );
-
-	Underworld_Shfl* self;
-
-	self = (Underworld_Shfl* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_Shfl_Type  );
-	
-	StgFEM_FrequentOutput_PrintString( context, "Shfl" );
-
-	Journal_Firewall( 
-			gaussSwarm != NULL, 
-			Underworld_Error,
-			"Cannot find gauss swarm. Cannot use %s.\n", CURR_MODULE_NAME );
-
-	/* Create Some FeVariables to calculate shear heat flux  */
-	temperatureField          = FieldVariable_Register_GetByName( fV_Register, "TemperatureField" );
-	velocityField             = FieldVariable_Register_GetByName( fV_Register, "VelocityField" );
-	temperatureGradientsField = FieldVariable_Register_GetByName( fV_Register, "TemperatureGradientsField" );
-	
-	/* get uT */
-	advectiveHeatFluxField = OperatorFeVariable_NewBinary(  
-			"AdvectiveHeatFluxField",
-         (DomainContext*)	context,
-			temperatureField, 
-			velocityField, 
-			"VectorScale" );
-	/* get dTdz - uT */
-	temperatureTotalDerivField = OperatorFeVariable_NewBinary(  
-			"TemperatureTotalDerivField",
-         (DomainContext*)	context,
-			advectiveHeatFluxField, 
-			temperatureGradientsField, 
-			"Addition" );
-	
-	self->dTField = (FeVariable*) OperatorFeVariable_NewUnary(  
-			"dTfieldz",
-         (DomainContext*)	context,
-			temperatureGradientsField, 
-			"TakeSecondComponent" );
-	self->dTField->feMesh = ((FeVariable*)velocityField)->feMesh;
-	
-}
-
-void Underworld_Shfl_Output( UnderworldContext* context ) {
-
-	Underworld_Shfl* self;
-	FieldVariable_Register*              fV_Register               = context->fieldVariable_Register;
-	FieldVariable*                       temperatureField;
-	double								 temp;
-
-	temperatureField          			 = FieldVariable_Register_GetByName( fV_Register, "TemperatureField" );
-	
-	self = (Underworld_Shfl*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_Shfl_Type  );
-
-	/* get_layer value */
-	self->shfl = FeVariable_AveragePlane( self->dTField, J_AXIS, 1.0 );
-	temp =   FeVariable_AveragePlane( temperatureField, J_AXIS, 0.0 );
-	
-		
-	self->shfl/=temp;
-		
-	StgFEM_FrequentOutput_PrintValue( context, -self->shfl  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/Shfl/Shfl.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/Output/Shfl/Shfl.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,175 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** Copyright (c) 2005, Your Mom
+** 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 YOUR MOM 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.
+**
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Underworld.h>
+#include <StgFEM/FrequentOutput/FrequentOutput.h>
+
+#include "Shfl.h"
+
+const Type Underworld_Shfl_Type = "Underworld_Shfl";
+
+void _Underworld_Shfl_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
+	UnderworldContext* context;
+
+	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data ); 
+
+	/* Add functions to entry points */
+	Underworld_Shfl_Setup( context  );
+	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, Underworld_Shfl_Output );
+}
+
+void _Underworld_Shfl_Build( void* component, void* data ) {
+	Underworld_Shfl*	self = (Underworld_Shfl*)component;
+
+	assert( self );
+
+	Stg_Component_Build( self->dTField, data, False );
+   
+   _Codelet_Build( self, data );
+}
+
+void _Underworld_Shfl_Destroy( void* component, void* data ) {
+	Underworld_Shfl*	self = (Underworld_Shfl*)component;
+
+   _Codelet_Destroy( self, data );
+
+	Stg_Component_Destroy( self->dTField, data, False );
+}
+
+void _Underworld_Shfl_Initialise( void* component, void* data ) {
+	Underworld_Shfl*	self = (Underworld_Shfl*)component;
+
+	assert( self );
+
+	Stg_Component_Initialise( self->dTField, data, False );
+   
+   _Codelet_Initialise( self, data );
+}
+
+void* _Underworld_Shfl_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Underworld_Shfl);
+	Type                                                      type = Underworld_Shfl_Type;
+	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
+	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
+	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_Shfl_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Underworld_Shfl_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _Underworld_Shfl_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _Underworld_Shfl_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _Codelet_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _Underworld_Shfl_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 Underworld_Shfl_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Underworld_Shfl_Type, (Name)"0", _Underworld_Shfl_DefaultNew );
+}
+
+
+void Underworld_Shfl_Setup( UnderworldContext* context ) {
+	FieldVariable_Register*  fV_Register               = context->fieldVariable_Register;
+	FieldVariable*           temperatureGradientsField;
+	FieldVariable*           velocityField;
+	FieldVariable*           temperatureField;
+	OperatorFeVariable*      advectiveHeatFluxField;
+	OperatorFeVariable*      temperatureTotalDerivField;
+	Swarm*					    gaussSwarm = (Swarm* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"gaussSwarm" );
+
+	Underworld_Shfl* self;
+
+	self = (Underworld_Shfl* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_Shfl_Type  );
+	
+	StgFEM_FrequentOutput_PrintString( context, "Shfl" );
+
+	Journal_Firewall( 
+			gaussSwarm != NULL, 
+			Underworld_Error,
+			"Cannot find gauss swarm. Cannot use %s.\n", CURR_MODULE_NAME );
+
+	/* Create Some FeVariables to calculate shear heat flux  */
+	temperatureField          = FieldVariable_Register_GetByName( fV_Register, "TemperatureField" );
+	velocityField             = FieldVariable_Register_GetByName( fV_Register, "VelocityField" );
+	temperatureGradientsField = FieldVariable_Register_GetByName( fV_Register, "TemperatureGradientsField" );
+	
+	/* get uT */
+	advectiveHeatFluxField = OperatorFeVariable_NewBinary(  
+			"AdvectiveHeatFluxField",
+         (DomainContext*)	context,
+			temperatureField, 
+			velocityField, 
+			"VectorScale" );
+	/* get dTdz - uT */
+	temperatureTotalDerivField = OperatorFeVariable_NewBinary(  
+			"TemperatureTotalDerivField",
+         (DomainContext*)	context,
+			advectiveHeatFluxField, 
+			temperatureGradientsField, 
+			"Addition" );
+	
+	self->dTField = (FeVariable*) OperatorFeVariable_NewUnary(  
+			"dTfieldz",
+         (DomainContext*)	context,
+			temperatureGradientsField, 
+			"TakeSecondComponent" );
+	self->dTField->feMesh = ((FeVariable*)velocityField)->feMesh;
+	
+}
+
+void Underworld_Shfl_Output( UnderworldContext* context ) {
+
+	Underworld_Shfl* self;
+	FieldVariable_Register*              fV_Register               = context->fieldVariable_Register;
+	FieldVariable*                       temperatureField;
+	double								 temp;
+
+	temperatureField          			 = FieldVariable_Register_GetByName( fV_Register, "TemperatureField" );
+	
+	self = (Underworld_Shfl*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_Shfl_Type  );
+
+	/* get_layer value */
+	self->shfl = FeVariable_AveragePlane( self->dTField, J_AXIS, 1.0 );
+	temp =   FeVariable_AveragePlane( temperatureField, J_AXIS, 0.0 );
+	
+		
+	self->shfl/=temp;
+		
+	StgFEM_FrequentOutput_PrintValue( context, -self->shfl  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/VTKOutput/VTKOutput.c
--- a/plugins/Output/VTKOutput/VTKOutput.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,853 +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: /cig/src/StgFEM/plugins/Output/PrintFeVariableDiscreteValues/Plugin.c 21 2006-04-07T21:29:57.251207Z walter  $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Underworld.h>
-#include "VTKOutput.h"
-#include <PICellerator/Utils/HydrostaticTerm.h>
-
-#include <stdlib.h>
-#include <string.h>
-
-const Type Underworld_VTKOutput_Type = "Underworld_VTKOutput";
-
-void _Underworld_VTKOutput_AssignFromXML( void* component, Stg_ComponentFactory* cf, void *data ) {
-	UnderworldContext* context;
-
-	context = (UnderworldContext*)Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data  );
-
-        /* Run after the solve, but before time integration
-           (e.g. advection).  This gives us data that is always valid.
-           It also simplifies intepretation because we do not have to
-           separate mesh deformation from what the solver gave us. */
-
-	ContextEP_Append( context, AbstractContext_EP_Solve,
-                          VTKOutput );
-}
-
-void* _Underworld_VTKOutput_DefaultNew( Name name ) {
-	return Codelet_New(
-			Underworld_VTKOutput_Type,
-			_Underworld_VTKOutput_DefaultNew,
-			_Underworld_VTKOutput_AssignFromXML,
-			_Codelet_Build,
-			_Codelet_Initialise,
-			_Codelet_Execute,
-			_Codelet_Destroy,
-			name );
-}
-
-Index Underworld_VTKOutput_Register( PluginsManager* pluginsManager ) {
-	Journal_DPrintf( StgFEM_Debug, "In: %s( void* )\n", __func__ );
-	
-	return PluginsManager_Submit( pluginsManager, Underworld_VTKOutput_Type, (Name)"0", _Underworld_VTKOutput_DefaultNew  );
-}
-
-void VTKOutput_particles(Swarm* swarm, 
-                         double defaultDiffusivity,
-                         int stepping,
-                         char *outputPath, const int timeStep,
-                         int dim, int myRank, int nprocs);
-void VTKOutput_fields(void *context, int myRank, int nprocs,
-                      const int timeStep);
-
-void VTKOutput( void* _context ) {
-  UnderworldContext* context = (UnderworldContext*)_context;
-  Dictionary* dictionary = context->dictionary;
-
-  /* Only dump if at the right time step.  We use timeStep-1, because
-     we are outputing after a solve, but before advection.  So
-     timeStep-1 makes more sense in terms of when the simulation looks
-     like this. */
-  if((context->timeStep-1) % context->dumpEvery != 0)
-    return;
-	
-
-  /* Write the particles and then all of the fields. */
-  
-  if(Dictionary_GetBool_WithDefault(dictionary,"VTKOutput_Particles",
-                                    True))
-    {
-      Name swarmName;
-      Swarm* swarm;
-      Dictionary_Entry_Value* swarm_list;
-      int swarm_list_size, s;
-      swarm_list=Dictionary_Get(dictionary, "VTKOutput_SwarmList" );
-
-      if(!swarm_list)
-        {
-          swarm_list=Dictionary_Entry_Value_NewList();
-          Dictionary_Entry_Value_AddElement(swarm_list,Dictionary_Entry_Value_FromString("picIntegrationPoints"));
-        }
-      swarm_list_size=Dictionary_Entry_Value_GetCount(swarm_list);
-      for(s=0;s<swarm_list_size;++s)
-        {
-          swarmName=Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetElement(swarm_list,s));
-          swarm=(Swarm*)LiveComponentRegister_Get(context->CF->LCRegister,
-                                                  swarmName);
-
-          VTKOutput_particles(swarm,
-                              Dictionary_GetDouble_WithDefault
-                              (dictionary,"defaultDiffusivity",1.0),
-                              Dictionary_GetInt_WithDefault
-                              (dictionary,"particleStepping",1),
-                              context->outputPath, context->timeStep-1,
-                              context->dim,context->rank,context->nproc);
-        }
-    }
-  if(Dictionary_GetBool_WithDefault(dictionary,"VTKOutput_Fields",
-                                    True))
-    VTKOutput_fields(context,context->rank,context->nproc,
-                     context->timeStep-1);
-}
-
-void VTKOutput_particles(Swarm* swarm,
-                         double defaultDiffusivity,
-                         int stepping, char *outputPath,
-                         const int timeStep, int dim, int myRank, int nprocs) {
-  double *coord;
-  int iteration, i;
-  Particle_Index          num_particles = swarm->particleLocalCount;
-  Particle_Index          lParticle_I;
-  
-  RheologyMaterial*       material;
-  MaterialPointsSwarm*    materialSwarm;
-  MaterialPoint*          materialparticle;
- 
-  Rheology_Register*      rheology_register;
-  Rheology_Index      rheology_I; 
-  Rheology_Index      rheologyCount;
-  YieldRheology*      rheology; 
- 
-  FILE *fp, *pfp;
-  char* filename;
-  
-  /* Open the processor specific output file */
-  Stg_asprintf(&filename,"%s/%s.%d.%05d.vtu",outputPath,swarm->name,myRank,
-               timeStep);
-  fp=fopen(filename,"w");
-  Memory_Free( filename );
-
-  if(fp==NULL)
-    {
-      fprintf(stderr,"WARNING: Can not open particle file for rank %d step %d\n",myRank,
-              timeStep);
-      return;
-    }
-  /* Open the parallel control file */
-  if(myRank==0)
-    {
-      Stg_asprintf( &filename, "%s/%s.%05d.pvtu", outputPath, swarm->name, timeStep);
-      pfp=fopen(filename,"w");
-      Memory_Free( filename );
-
-      if(pfp==NULL)
-        {
-          fprintf(stderr,"FATAL ERROR: Can not open master particle file for step %d",timeStep);
-          abort();
-        }
-    }
-      
-  /* Write a header */
-  fprintf(fp,"<?xml version=\"1.0\"?>\n");
-  fprintf(fp,"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n");
-  fprintf(fp,"  <UnstructuredGrid>\n");
-  fprintf(fp,"    <Piece NumberOfPoints=\"%d\" NumberOfCells=\"1\">\n",
-          (num_particles-1)/stepping+1);
-  fprintf(fp,"      <Points>\n");
-  fprintf(fp,"      <DataArray type=\"Float64\" NumberOfComponents=\"3\" format=\"ascii\">\n");
-
-  if(myRank==0)
-    {
-      fprintf(pfp,"<?xml version=\"1.0\"?>\n\
-<VTKFile type=\"PUnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n\
-  <PUnstructuredGrid GhostLevel=\"0\">\n\
-    <PPoints>\n\
-      <DataArray type=\"Float64\" NumberOfComponents=\"3\" format=\"ascii\"/>\n\
-    </PPoints>\n\
-    <PCellData></PCellData>\n");
-    }
-  
-  /* We need many iterations, because the values are written
-     separately from the coordinates. */
-  for(iteration=0; iteration<10; ++iteration)
-    {
-      /* Loop over all of the particles */
-      for ( lParticle_I = 0 ; lParticle_I < num_particles ;
-            lParticle_I+=stepping ){
-        double postFailureStrain, viscosity, density, alpha, diffusivity;
-        int currently_yielding;
-        Material_Index material_index;
-        SymmetricTensor stress;
-        BuoyancyForceTerm_MaterialExt*   materialExt;
-        Material *extension_info;
-        XYZ normal;
-        
-        if(Stg_Class_IsInstance(swarm,IntegrationPointsSwarm_Type))
-          {
-            IntegrationPoint* integrationparticle = (IntegrationPoint*)Swarm_ParticleAt( ((IntegrationPointsSwarm*)swarm), lParticle_I );
-        
-            material = (RheologyMaterial*) IntegrationPointsSwarm_GetMaterialOn( ((IntegrationPointsSwarm*)swarm), integrationparticle );
-            materialparticle = OneToOneMapper_GetMaterialPoint( ((IntegrationPointsSwarm*)swarm)->mapper, integrationparticle, &materialSwarm );
-        
-            density=Dictionary_GetDouble_WithDefault( material->dictionary, (Dictionary_Entry_Key)"density", 0.0  );
-            alpha=Dictionary_GetDouble_WithDefault( material->dictionary, (Dictionary_Entry_Key)"alpha", 0.0  );
-            diffusivity=Dictionary_GetDouble_WithDefault( material->dictionary, (Dictionary_Entry_Key)"diffusivity", defaultDiffusivity );
-
-            material_index=material->index;
-            rheology_register=(Rheology_Register* )material->rheology_Register;
-        
-            if( rheology_register && strcmp( material->name, Material_Type ) )
-              rheologyCount = Rheology_Register_GetCount( rheology_register );
-            else
-              rheologyCount = 0;
-            coord = materialparticle->coord;
-          }
-        else
-          {
-            GlobalParticle *particle;
-            particle=(GlobalParticle *)Swarm_ParticleAt(swarm,lParticle_I);
-            coord = particle->coord;
-            material_index=0;
-            density=alpha=0;
-            diffusivity=defaultDiffusivity;
-            rheologyCount=0;
-          }
-        postFailureStrain=0;
-        viscosity=0;
-        currently_yielding=0;
-        SymmetricTensor_Zero(stress);
-        normal[0]=normal[1]=normal[2]=0;
-        
-        /* First print out only the coordinates. */
-        if(iteration==0)
-          {
-            if (dim == 2) {
-              fprintf(fp,"%lf %lf 0.0 ",(double)coord[0],
-                      (double)coord[1]);
-            } else {
-              fprintf(fp,"%lf %lf %lf ", (double)coord[0],
-                      (double)coord[1], (double)coord[2]);
-            }
-          }
-        else
-          {
-            /* Loop over all of the rheologies for a particle. */
-                  
-            for( rheology_I = 0; rheology_I < rheologyCount ; rheology_I++ ) { 
-              rheology = (YieldRheology*)Rheology_Register_GetByIndex( rheology_register, rheology_I ); 
-                
-              /* Get postFailureStrain and current_yielding information */
-              if(Stg_Class_IsInstance(rheology,YieldRheology_Type)
-                 && rheology->strainWeakening)
-                {
-                  postFailureStrain=
-                    StrainWeakening_GetPostFailureWeakening
-                    (rheology->strainWeakening,materialparticle);
-                  currently_yielding=YieldRheology_GetParticleFlag
-                    (rheology,materialSwarm,materialparticle);
-                }
-              /* Get viscosity */
-              if(Stg_Class_IsInstance(rheology,StoreVisc_Type))
-                {
-                  StoreVisc* self = (StoreVisc*) rheology;
-                  StoreVisc_ParticleExt* particleExt;
-                  particleExt=
-                    (StoreVisc_ParticleExt*)ExtensionManager_Get( materialSwarm->particleExtensionMgr, materialparticle, self->particleExtHandle );
-                  viscosity=particleExt->effVisc;
-                }
-              /* Get stress */
-              if(Stg_Class_IsInstance(rheology,StoreStress_Type))
-                {
-                  StoreStress* self = (StoreStress*) rheology;
-                  StoreStress_ParticleExt* particleExt;
-                  particleExt=
-                    (StoreStress_ParticleExt*)ExtensionManager_Get( materialSwarm->particleExtensionMgr, materialparticle, self->particleExtHandle );
-                  stress[0]=particleExt->stress[0];
-                  stress[1]=particleExt->stress[1];
-                  stress[2]=particleExt->stress[2];
-                  stress[3]=particleExt->stress[3];
-                  if(dim==3)
-                    {
-                      stress[4]=particleExt->stress[4];
-                      stress[5]=particleExt->stress[5];
-                    }
-                }
-
-              if(Stg_Class_IsInstance(rheology,Anisotropic_Type))
-                {
-                  Anisotropic* self = (Anisotropic*) rheology;
-                  XYZ normal;
-                  Director_GetNormal(self->director,materialparticle,normal);
-                }
-
-
-            }
-            switch(iteration)
-              {
-              case 1:
-                fprintf(fp,"%lf ",viscosity);
-                break;
-              case 2:
-                fprintf(fp,"%lf ",postFailureStrain);
-                break;
-              case 3:
-                if(dim==2)
-                  {
-                    fprintf(fp,"%lf %lf 0.0 %lf %lf 0.0 0.0 0.0 0.0 ",
-                            stress[0],stress[1],
-                            stress[1],stress[2]);
-                  }
-                else
-                  {
-                    fprintf(fp,"%lf %lf %lf %lf %lf %lf %lf %lf %lf ",
-                            stress[0],stress[1],stress[2],
-                            stress[1],stress[3],stress[4],
-                            stress[2],stress[4],stress[5]);
-                  }
-                break;
-              case 4:
-                fprintf(fp,"%lf ",density);
-                break;
-              case 5:
-                fprintf(fp,"%d ",material_index);
-                break;
-              case 6:
-                fprintf(fp,"%lf ",alpha);
-                break;
-              case 7:
-                fprintf(fp,"%lf ",diffusivity);
-                break;
-              case 8:
-                fprintf(fp,"%d ",currently_yielding);
-                break;
-              case 9:
-                if(dim==2)
-                  {
-                    fprintf(fp,"%lf %lf 0.0 ",normal[0],normal[1]);
-                  }
-                else
-                  {
-                    fprintf(fp,"%lf %lf %lf ",normal[0],normal[1],normal[2]);
-                  }
-                break;
-              }
-          }
-      }
-      switch(iteration)
-        {
-        case 0:
-          fprintf(fp,"\n        </DataArray>\n");
-          fprintf(fp,"      </Points>\n");
-          fprintf(fp,"      <PointData Scalars=\"Viscosity\" Tensors=\"Stress\">\n");
-          fprintf(fp,"        <DataArray type=\"Float64\" Name=\"Viscosity\" format=\"ascii\">\n");
-          if(myRank==0)
-            {
-              fprintf(pfp,"      <PPointData Scalars=\"Viscosity\" Tensors=\"Stress\">\n");
-              fprintf(pfp,"        <PDataArray type=\"Float64\" Name=\"Viscosity\" format=\"ascii\"/>\n");
-            }
-          break;
-        case 1:
-          fprintf(fp,"\n        </DataArray>\n");
-          fprintf(fp,"        <DataArray type=\"Float64\" Name=\"Post_Failure_Strain\" format=\"ascii\">\n");
-          if(myRank==0)
-            fprintf(pfp,"        <PDataArray type=\"Float64\" Name=\"Post_Failure_Strain\" format=\"ascii\"/>\n");
-          break;
-        case 2:
-          fprintf(fp,"\n        </DataArray>\n");
-          fprintf(fp,"        <DataArray type=\"Float64\" Name=\"Stress\" format=\"ascii\" NumberOfComponents=\"9\">\n");
-          if(myRank==0)
-            fprintf(pfp,"        <PDataArray type=\"Float64\" Name=\"Stress\" format=\"ascii\" NumberOfComponents=\"9\"/>\n");
-          break;
-        case 3:
-          fprintf(fp,"\n        </DataArray>\n");
-          fprintf(fp,"        <DataArray type=\"Float64\" Name=\"Density\" format=\"ascii\">\n");
-          if(myRank==0)
-            fprintf(pfp,"        <PDataArray type=\"Float64\" Name=\"Density\" format=\"ascii\"/>\n");
-          break;
-        case 4:
-          fprintf(fp,"\n        </DataArray>\n");
-          fprintf(fp,"        <DataArray type=\"Int32\" Name=\"Material_Index\" format=\"ascii\">\n");
-          if(myRank==0)
-            fprintf(pfp,"        <PDataArray type=\"Int32\" Name=\"Material_Index\" format=\"ascii\"/>\n");
-          break;
-        case 5:
-          fprintf(fp,"\n        </DataArray>\n");
-          fprintf(fp,"        <DataArray type=\"Float64\" Name=\"Alpha\" format=\"ascii\">\n");
-          if(myRank==0)
-            fprintf(pfp,"        <PDataArray type=\"Float64\" Name=\"Alpha\" format=\"ascii\"/>\n");
-          break;
-        case 6:
-          fprintf(fp,"\n        </DataArray>\n");
-          fprintf(fp,"        <DataArray type=\"Float64\" Name=\"Thermal_Diffusivity\" format=\"ascii\">\n");
-          if(myRank==0)
-            fprintf(pfp,"        <PDataArray type=\"Float64\" Name=\"Thermal_Diffusivity\" format=\"ascii\"/>\n");
-          break;
-        case 7:
-          fprintf(fp,"\n        </DataArray>\n");
-          fprintf(fp,"        <DataArray type=\"Int32\" Name=\"Currently_Yielding\" format=\"ascii\">\n");
-          if(myRank==0)
-            fprintf(pfp,"        <PDataArray type=\"Int32\" Name=\"Currently_Yielding\" format=\"ascii\"/>\n");
-          break;
-        case 8:
-          fprintf(fp,"\n        </DataArray>\n");
-          fprintf(fp,"        <DataArray type=\"Float64\" Name=\"Orientation\" format=\"ascii\" NumberOfComponents=\"3\">\n");
-          if(myRank==0)
-            fprintf(pfp,"        <PDataArray type=\"Float64\" Name=\"Orientation\" format=\"ascii\" NumberOfComponents=\"3\"/>\n");
-          break;
-        case 9:
-          fprintf(fp,"\n        </DataArray>\n");
-          fprintf(fp,"      </PointData>\n");
-          fprintf(fp,"      <CellData>\n");
-          fprintf(fp,"      </CellData>\n");
-          fprintf(fp,"      <Cells>\n");
-          fprintf(fp,"        <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n");
-          for(i=0;i<(num_particles-1)/stepping+1;++i)
-            fprintf(fp,"%d ",i);
-          fprintf(fp,"\n        </DataArray>\n");
-          fprintf(fp,"        <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n");
-          fprintf(fp,"          %d\n",(num_particles-1)/stepping+1);
-          fprintf(fp,"        </DataArray>\n");
-          fprintf(fp,"        <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n");
-          fprintf(fp,"          2\n");
-          fprintf(fp,"        </DataArray>\n");
-          fprintf(fp,"      </Cells>\n");
-          fprintf(fp,"    </Piece>\n");
-          fprintf(fp,"  </UnstructuredGrid>\n");
-          fprintf(fp,"</VTKFile>\n");
-        }
-    }
-  fclose(fp);
-  if(myRank==0)
-    {
-      fprintf(pfp,"        </PPointData>\n");
-      for(i=0;i<nprocs;++i)
-        fprintf(pfp,"    <Piece Source=\"%s.%d.%05d.vtu\"/>\n",
-                swarm->name,i,timeStep);
-      fprintf(pfp,"  </PUnstructuredGrid>\n\
-</VTKFile>\n");
-      fclose(pfp);
-    }
-}
-
-/* Print out the coordinates of the mesh. */
-
-void VTKOutput_print_coords(FILE *fp, FeMesh *feMesh, Grid *grid, int nDims,
-                            int lower[3], int upper[3]) {
-  IJK ijk;
-
-  fprintf(fp,"      <Points>\n");
-  fprintf(fp,"        <DataArray type=\"Float64\" NumberOfComponents=\"3\" format=\"ascii\">\n");
-  
-  for(ijk[2]=lower[2];ijk[2]<upper[2];++ijk[2])
-    for(ijk[1]=lower[1];ijk[1]<upper[1];++ijk[1])
-      for(ijk[0]=lower[0];ijk[0]<upper[0];++ijk[0])
-        {
-          double *coord;
-          unsigned local;
-          Mesh_GlobalToDomain(feMesh,MT_VERTEX,Grid_Project(grid,ijk),&local);
-          coord=Mesh_GetVertex(feMesh,local);
-          if(nDims==2)
-            fprintf(fp, "%.15g %.15g 0\n", coord[0], coord[1]);
-          else
-            fprintf(fp, "%.15g %.15g %.15g\n", coord[0], coord[1], coord[2]);
-        }
-  fprintf(fp,"        </DataArray>\n      </Points>\n");
-}
-
-
-/* Everything is stored on cell vertices. */
-void VTKOutput_fields(void *context, int myRank, int nprocs,
-                      const int timeStep) {
-  
-  FiniteElementContext*     self = (FiniteElementContext*) context;
-  Index var_I;
-  int header_printed=0;
-  int nDims, i;
-  int lower[3], upper[3], p_lower[3], p_upper[3];
-
-  HydrostaticTerm *hydrostaticTerm;
-  char* field_filename;
-  FILE *field_fp, *pfield_fp;
-
-  Dictionary_Entry_Value* field_list;
-  int field_list_size;
-
-  /* We need to save the grids to map between 1D and 3D indices for
-     the values. */
-  Grid *elGrid, *vertGrid;
-
-  hydrostaticTerm =
-    (HydrostaticTerm*)LiveComponentRegister_Get(self->CF->LCRegister,
-                                                "hydrostaticTerm" );
-  /* Open the file */
-
-  field_list=Dictionary_Get(self->dictionary, "VTKOutput_FieldList" );
-  if(field_list)
-    {
-      field_list_size=Dictionary_Entry_Value_GetCount(field_list);
-      Journal_Firewall(field_list_size>=0,
-                       Journal_Register( Error_Type, self->type ),
-                       "The list of fields in VTKOutput_FieldList is %d but must not be negative.\n",
-                       field_list_size );
-    }
-
-  Stg_asprintf( &field_filename, "%s/fields.%d.%05d.vts", self->outputPath,
-                myRank, timeStep);
-  field_fp=fopen(field_filename,"w");
-  Memory_Free( field_filename );
-
-  if(field_fp==NULL)
-    {
-      fprintf(stderr,"WARNING: Can not open fields file for rank %d step %d\n",
-              myRank,timeStep);
-      return;
-    }
-
-  /* Print out the parallel control files if rank==0 */
-  if(myRank==0)
-    {
-      Stg_asprintf( &field_filename, "%s/fields.%05d.pvts", self->outputPath,
-                    timeStep);
-      pfield_fp=fopen(field_filename,"w");
-      Memory_Free( field_filename );
-      if(pfield_fp==NULL)
-        {
-          fprintf(stderr,
-                  "FATAL ERROR: Can not open master fields file for step %d\n",
-                  timeStep);
-          abort();
-        }
-    }
-
-  /* First, update the fields that are derived from particles.  This
-     is needed to get an accurate pressure, because it needs the
-     stresses. */
-
-  for ( var_I = 0; var_I < self->fieldVariable_Register->objects->count;
-        var_I++ ) {
-    FieldVariable* fieldVar;
-    fieldVar = FieldVariable_Register_GetByIndex( self->fieldVariable_Register,
-                                                  var_I );
-    if (Stg_Class_IsInstance( fieldVar, ParticleFeVariable_Type ))
-      {
-        ParticleFeVariable_Update( fieldVar );
-      }
-  }
-
-  /* First, output the coordinates.  We have to do a huge song and
-     dance just to get the extents of the mesh. */
-
-  for ( var_I = 0; var_I < self->fieldVariable_Register->objects->count;
-        var_I++ ) {
-    int fields;
-    FieldVariable* fieldVar;
-    fieldVar = FieldVariable_Register_GetByIndex( self->fieldVariable_Register,
-                                                  var_I );
-    if (Stg_Class_IsInstance( fieldVar, FeVariable_Type )) {
-      FeVariable* feVar;
-      Dof_Index          dofAtEachNodeCount;
-      int *low, *up;
-      Grid *grid;
-      IJK ijk;
-
-      feVar=(FeVariable*)fieldVar;
-
-      if(!header_printed)
-        {
-          Mesh *mesh;
-          CartesianGenerator *gen;
-
-          mesh=(Mesh*)(feVar->feMesh);
-          gen=((CartesianGenerator *)(mesh->generator));
-          /* If we got the surface adaptor instead of the cartesian
-             mesh generator, go to the mesh generator.  */
-          if(!strcmp(gen->type,"SurfaceAdaptor"))
-            gen=(CartesianGenerator *)((SurfaceAdaptor *)(gen))->generator;
-
-          elGrid=gen->elGrid;
-          vertGrid=gen->vertGrid;
-          nDims=gen->nDims;
-
-          p_lower[2]=lower[2]=0;
-          p_upper[2]=upper[2]=1;
-          for(i=0;i<nDims;++i)
-            {
-              p_lower[i]=gen->origin[i];
-              p_upper[i]=p_lower[i]+gen->range[i];
-
-              /* The grid is split up by elements, so for the element
-                 grid, we simply add the ghost zones.  Ghost zones are
-                 only added at the top, not the bottom. */
-              if(p_upper[i]!=gen->elGrid->sizes[i])
-                ++p_upper[i];
-
-              /* Then we get the vertices by adding appropriate
-                 offsets to the element grid. */
-              upper[i]=p_upper[i]+1;
-              lower[i]=p_lower[i];
-              if(p_lower[i]!=0)
-                --lower[i];
-            }
-
-          /* Now that we have the extents, write the header. */
-
-          fprintf(field_fp,"<?xml version=\"1.0\"?>\n\
-<VTKFile type=\"StructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n\
-  <StructuredGrid WholeExtent=\"%d %d %d %d %d %d\">\n\
-    <Piece Extent=\"%d %d %d %d %d %d\">\n\
-      <CellData></CellData>\n",
-                  lower[0],upper[0]-1,lower[1],upper[1]-1,lower[2],upper[2]-1,
-                  lower[0],upper[0]-1,lower[1],upper[1]-1,lower[2],upper[2]-1);
-
-          /* Write the coordinates for the fields */
-          VTKOutput_print_coords(field_fp, feVar->feMesh, gen->vertGrid, nDims,
-                                 lower, upper);
-          fprintf(field_fp,"      <PointData Scalars=\"StrainRateInvariantField\" Vectors=\"VelocityField\" Tensors=\"Stress\">\n");
-          
-          /* Write out parallel control file headers. */
-          if(myRank==0)
-            {
-              int global[3], p_global[3];
-              global[0]=gen->vertGrid->sizes[0];
-              global[1]=gen->vertGrid->sizes[1];
-              if(nDims==3)
-                {
-                  global[2]=gen->vertGrid->sizes[2];
-                  p_global[2]=global[2]-1;
-                }
-              else
-                {
-                  global[2]=p_global[2]=1;
-                }
-              fprintf(pfield_fp,"<?xml version=\"1.0\"?>\n\
-<VTKFile type=\"PStructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n\
-  <PStructuredGrid GhostLevel=\"0\" WholeExtent=\"0 %d 0 %d 0 %d\">\n\
-    <PCellData></PCellData>\n\
-    <PPoints>\n\
-      <PDataArray type=\"Float64\" NumberOfComponents=\"3\"/>\n\
-    </PPoints>\n\
-    <PPointData Scalars=\"StrainRateInvariantField\" Vectors=\"VelocityField\" Tensors=\"Stress\">\n",global[0]-1,global[1]-1,global[2]-1);
-            }
-          header_printed=1;
-        }
-      
-      /* Finally, output the fields. */
-      
-      /* Check whether the field is in the field list */
-      if(field_list)
-        {
-          for(fields=0; fields<field_list_size; ++fields)
-            {
-              if(!strcmp(Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetElement(field_list,fields)),
-                         fieldVar->name))
-                {
-                  break;
-                }
-            }
-          if(fields==field_list_size)
-            continue;
-        }
-
-      dofAtEachNodeCount = feVar->fieldComponentCount;
-
-      switch(dofAtEachNodeCount*nDims)
-        {
-          /* Scalars */
-        case 2:
-        case 3:
-          fprintf(field_fp,"        <DataArray type=\"Float64\" Name=\"%s\" format=\"ascii\">\n",feVar->name);
-          if(myRank==0)
-            fprintf(pfield_fp,"      <PDataArray type=\"Float64\" Name=\"%s\" format=\"ascii\"/>\n",feVar->name);
-          break;
-          /* Vectors */
-        case 4:
-        case 9:
-          fprintf(field_fp,"        <DataArray type=\"Float64\" Name=\"%s\" format=\"ascii\" NumberOfComponents=\"3\">\n",feVar->name);
-          if(myRank==0)
-            fprintf(pfield_fp,"      <PDataArray type=\"Float64\" Name=\"%s\" format=\"ascii\" NumberOfComponents=\"3\"/>\n",feVar->name);
-          break;
-          /* Rank 2 Tensors */
-        case 6:
-        case 8:
-        case 18:
-        case 27:
-          fprintf(field_fp,"        <DataArray type=\"Float64\" Name=\"%s\" format=\"ascii\" NumberOfComponents=\"9\">\n",feVar->name);
-          if(myRank==0)
-            fprintf(pfield_fp,"      <PDataArray type=\"Float64\" Name=\"%s\" format=\"ascii\" NumberOfComponents=\"9\"/>\n",feVar->name);
-          break;
-          /* Unknown */
-        default:
-          fprintf(stderr,
-                  "Bad number of degrees of freedom for variable %s: %d\n",
-                 feVar->name, dofAtEachNodeCount);
-          abort();
-        }
-
-      for(ijk[2]=lower[2];ijk[2]<upper[2];++ijk[2])
-        for(ijk[1]=lower[1];ijk[1]<upper[1];++ijk[1])
-          for(ijk[0]=lower[0];ijk[0]<upper[0];++ijk[0])
-            {
-              double variableValues[MAX_FIELD_COMPONENTS];	
-              Dof_Index          dof_I;
-              unsigned local;
-              Mesh_GlobalToDomain(feVar->feMesh,MT_VERTEX,
-                                  Grid_Project(vertGrid,ijk),&local);
-              FeVariable_GetValueAtNode(feVar,local,variableValues);
-                                        
-              switch(dofAtEachNodeCount*nDims)
-                {
-                  /* If writing scalars or 3D objects, then just write
-                     the values.  Otherwise, we have to fill in the 3D
-                     components with zeros. */
-                case 2:
-                case 3:
-                case 9:
-                case 27:
-                  /* Special case the pressure */
-                  if(!strcmp(feVar->name,"PressureField"))
-                    {
-                      double p;
-                      /* First add the trace of the stress */
-                      int stress_I;
-
-                      for(stress_I = 0;
-                          stress_I<self->fieldVariable_Register->objects->count;
-                          stress_I++ ) {
-                        FieldVariable* stressVar;
-                        stressVar =
-                          FieldVariable_Register_GetByIndex(self->fieldVariable_Register,
-                                                            stress_I );
-                        if(!strcmp(stressVar->name,"StressField"))
-                          {
-                            if (Stg_Class_IsInstance( stressVar,
-                                                      FeVariable_Type ))
-                              {
-                                FeVariable* sVar;
-                                double stressValues[MAX_FIELD_COMPONENTS];	
-                                sVar=(FeVariable*)stressVar;
-                                
-                                FeVariable_GetValueAtNode(sVar,local,stressValues);
-                                if(nDims==2)
-                                  {
-                                    p=(stressValues[0]+stressValues[1])/2;
-                                  }
-                                else
-                                  {
-                                    p=(stressValues[0]+stressValues[1]
-                                       +stressValues[2])/3;
-                                  }
-                              }
-                            break;
-                          }
-                      }
-                      /* Next add the hydrostatic term */
-                      if(hydrostaticTerm)
-                        {
-                          double *coord;
-                          coord=Mesh_GetVertex(feVar->feMesh,local);
-                          p+=HydrostaticTerm_Pressure(hydrostaticTerm,coord);
-                        }
-                      p+=variableValues[0];
-                      fprintf(field_fp, "%.15g ", p );
-                    }
-                  else
-                    {
-                      for ( dof_I = 0; dof_I < dofAtEachNodeCount; dof_I++ ) {
-                        fprintf(field_fp, "%.15g ", variableValues[dof_I] );
-                      }
-                    }
-                  break;
-                case 4:
-                  fprintf(field_fp, "%.15g %.15g 0", variableValues[0],
-                          variableValues[1] );
-                  break;
-                case 6:
-                  /* Ordering is xx, yy, xy */
-                  fprintf(field_fp, "%.15g %.15g 0 %.15g %.15g 0 0 0 0 ",
-                          variableValues[0], variableValues[2],
-                          variableValues[2], variableValues[1]);
-                  break;
-                case 8:
-                  fprintf(field_fp, "%.15g %.15g 0 %.15g %.15g 0 0 0 0 ",
-                          variableValues[0], variableValues[1],
-                          variableValues[2], variableValues[3]);
-                  break;
-                case 18:
-                  /* Ordering is xx, yy, zz, xy, xz, yz */
-                  fprintf(field_fp, "%.15g %.15g %.15g %.15g %.15g %.15g %.15g %.15g %.15g ",
-                          variableValues[0], variableValues[3],
-                          variableValues[4], variableValues[3],
-                          variableValues[1], variableValues[5],
-                          variableValues[4], variableValues[5],
-                          variableValues[2]);
-                  break;
-                }
-              fprintf(field_fp, "\n" );
-            }
-      fprintf(field_fp,"        </DataArray>\n");
-    }
-  }
-  fprintf(field_fp,"      </PointData>\n    </Piece>\n\
-  </StructuredGrid>\n\
-</VTKFile>\n");
-  fclose(field_fp);
-
-  if(myRank==0)
-    {
-      fprintf(pfield_fp,"      </PPointData>\n");
-      for(i=0;i<nprocs;++i)
-        {
-          fprintf(pfield_fp,"    <Piece Extent=\"%d %d %d %d %d %d\"\n\
-             Source=\"fields.%d.%05d.vts\"/>\n",lower[0],upper[0]-1,
-                  lower[1],upper[1]-1,lower[2],upper[2]-1,
-                  i,timeStep);
-        }
-      fprintf(pfield_fp,"  </PStructuredGrid>\n\
-</VTKFile>\n");
-      fclose(pfield_fp);
-     }
-
-}
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/VTKOutput/VTKOutput.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/Output/VTKOutput/VTKOutput.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,853 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** 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: /cig/src/StgFEM/plugins/Output/PrintFeVariableDiscreteValues/Plugin.c 21 2006-04-07T21:29:57.251207Z walter  $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Underworld.h>
+#include "VTKOutput.h"
+#include <PICellerator/Utils/HydrostaticTerm.h>
+
+#include <stdlib.h>
+#include <string.h>
+
+const Type Underworld_VTKOutput_Type = "Underworld_VTKOutput";
+
+void _Underworld_VTKOutput_AssignFromXML( void* component, Stg_ComponentFactory* cf, void *data ) {
+	UnderworldContext* context;
+
+	context = (UnderworldContext*)Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data  );
+
+        /* Run after the solve, but before time integration
+           (e.g. advection).  This gives us data that is always valid.
+           It also simplifies intepretation because we do not have to
+           separate mesh deformation from what the solver gave us. */
+
+	ContextEP_Append( context, AbstractContext_EP_Solve,
+                          VTKOutput );
+}
+
+void* _Underworld_VTKOutput_DefaultNew( Name name ) {
+	return Codelet_New(
+			Underworld_VTKOutput_Type,
+			_Underworld_VTKOutput_DefaultNew,
+			_Underworld_VTKOutput_AssignFromXML,
+			_Codelet_Build,
+			_Codelet_Initialise,
+			_Codelet_Execute,
+			_Codelet_Destroy,
+			name );
+}
+
+Index Underworld_VTKOutput_Register( PluginsManager* pluginsManager ) {
+	Journal_DPrintf( StgFEM_Debug, "In: %s( void* )\n", __func__ );
+	
+	return PluginsManager_Submit( pluginsManager, Underworld_VTKOutput_Type, (Name)"0", _Underworld_VTKOutput_DefaultNew  );
+}
+
+void VTKOutput_particles(Swarm* swarm, 
+                         double defaultDiffusivity,
+                         int stepping,
+                         char *outputPath, const int timeStep,
+                         int dim, int myRank, int nprocs);
+void VTKOutput_fields(void *context, int myRank, int nprocs,
+                      const int timeStep);
+
+void VTKOutput( void* _context ) {
+  UnderworldContext* context = (UnderworldContext*)_context;
+  Dictionary* dictionary = context->dictionary;
+
+  /* Only dump if at the right time step.  We use timeStep-1, because
+     we are outputing after a solve, but before advection.  So
+     timeStep-1 makes more sense in terms of when the simulation looks
+     like this. */
+  if((context->timeStep-1) % context->dumpEvery != 0)
+    return;
+	
+
+  /* Write the particles and then all of the fields. */
+  
+  if(Dictionary_GetBool_WithDefault(dictionary,"VTKOutput_Particles",
+                                    True))
+    {
+      Name swarmName;
+      Swarm* swarm;
+      Dictionary_Entry_Value* swarm_list;
+      int swarm_list_size, s;
+      swarm_list=Dictionary_Get(dictionary, "VTKOutput_SwarmList" );
+
+      if(!swarm_list)
+        {
+          swarm_list=Dictionary_Entry_Value_NewList();
+          Dictionary_Entry_Value_AddElement(swarm_list,Dictionary_Entry_Value_FromString("picIntegrationPoints"));
+        }
+      swarm_list_size=Dictionary_Entry_Value_GetCount(swarm_list);
+      for(s=0;s<swarm_list_size;++s)
+        {
+          swarmName=Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetElement(swarm_list,s));
+          swarm=(Swarm*)LiveComponentRegister_Get(context->CF->LCRegister,
+                                                  swarmName);
+
+          VTKOutput_particles(swarm,
+                              Dictionary_GetDouble_WithDefault
+                              (dictionary,"defaultDiffusivity",1.0),
+                              Dictionary_GetInt_WithDefault
+                              (dictionary,"particleStepping",1),
+                              context->outputPath, context->timeStep-1,
+                              context->dim,context->rank,context->nproc);
+        }
+    }
+  if(Dictionary_GetBool_WithDefault(dictionary,"VTKOutput_Fields",
+                                    True))
+    VTKOutput_fields(context,context->rank,context->nproc,
+                     context->timeStep-1);
+}
+
+void VTKOutput_particles(Swarm* swarm,
+                         double defaultDiffusivity,
+                         int stepping, char *outputPath,
+                         const int timeStep, int dim, int myRank, int nprocs) {
+  double *coord;
+  int iteration, i;
+  Particle_Index          num_particles = swarm->particleLocalCount;
+  Particle_Index          lParticle_I;
+  
+  RheologyMaterial*       material;
+  MaterialPointsSwarm*    materialSwarm;
+  MaterialPoint*          materialparticle;
+ 
+  Rheology_Register*      rheology_register;
+  Rheology_Index      rheology_I; 
+  Rheology_Index      rheologyCount;
+  YieldRheology*      rheology; 
+ 
+  FILE *fp, *pfp;
+  char* filename;
+  
+  /* Open the processor specific output file */
+  Stg_asprintf(&filename,"%s/%s.%d.%05d.vtu",outputPath,swarm->name,myRank,
+               timeStep);
+  fp=fopen(filename,"w");
+  Memory_Free( filename );
+
+  if(fp==NULL)
+    {
+      fprintf(stderr,"WARNING: Can not open particle file for rank %d step %d\n",myRank,
+              timeStep);
+      return;
+    }
+  /* Open the parallel control file */
+  if(myRank==0)
+    {
+      Stg_asprintf( &filename, "%s/%s.%05d.pvtu", outputPath, swarm->name, timeStep);
+      pfp=fopen(filename,"w");
+      Memory_Free( filename );
+
+      if(pfp==NULL)
+        {
+          fprintf(stderr,"FATAL ERROR: Can not open master particle file for step %d",timeStep);
+          abort();
+        }
+    }
+      
+  /* Write a header */
+  fprintf(fp,"<?xml version=\"1.0\"?>\n");
+  fprintf(fp,"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n");
+  fprintf(fp,"  <UnstructuredGrid>\n");
+  fprintf(fp,"    <Piece NumberOfPoints=\"%d\" NumberOfCells=\"1\">\n",
+          (num_particles-1)/stepping+1);
+  fprintf(fp,"      <Points>\n");
+  fprintf(fp,"      <DataArray type=\"Float64\" NumberOfComponents=\"3\" format=\"ascii\">\n");
+
+  if(myRank==0)
+    {
+      fprintf(pfp,"<?xml version=\"1.0\"?>\n\
+<VTKFile type=\"PUnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n\
+  <PUnstructuredGrid GhostLevel=\"0\">\n\
+    <PPoints>\n\
+      <DataArray type=\"Float64\" NumberOfComponents=\"3\" format=\"ascii\"/>\n\
+    </PPoints>\n\
+    <PCellData></PCellData>\n");
+    }
+  
+  /* We need many iterations, because the values are written
+     separately from the coordinates. */
+  for(iteration=0; iteration<10; ++iteration)
+    {
+      /* Loop over all of the particles */
+      for ( lParticle_I = 0 ; lParticle_I < num_particles ;
+            lParticle_I+=stepping ){
+        double postFailureStrain, viscosity, density, alpha, diffusivity;
+        int currently_yielding;
+        Material_Index material_index;
+        SymmetricTensor stress;
+        BuoyancyForceTerm_MaterialExt*   materialExt;
+        Material *extension_info;
+        XYZ normal;
+        
+        if(Stg_Class_IsInstance(swarm,IntegrationPointsSwarm_Type))
+          {
+            IntegrationPoint* integrationparticle = (IntegrationPoint*)Swarm_ParticleAt( ((IntegrationPointsSwarm*)swarm), lParticle_I );
+        
+            material = (RheologyMaterial*) IntegrationPointsSwarm_GetMaterialOn( ((IntegrationPointsSwarm*)swarm), integrationparticle );
+            materialparticle = OneToOneMapper_GetMaterialPoint( ((IntegrationPointsSwarm*)swarm)->mapper, integrationparticle, &materialSwarm );
+        
+            density=Dictionary_GetDouble_WithDefault( material->dictionary, (Dictionary_Entry_Key)"density", 0.0  );
+            alpha=Dictionary_GetDouble_WithDefault( material->dictionary, (Dictionary_Entry_Key)"alpha", 0.0  );
+            diffusivity=Dictionary_GetDouble_WithDefault( material->dictionary, (Dictionary_Entry_Key)"diffusivity", defaultDiffusivity );
+
+            material_index=material->index;
+            rheology_register=(Rheology_Register* )material->rheology_Register;
+        
+            if( rheology_register && strcmp( material->name, Material_Type ) )
+              rheologyCount = Rheology_Register_GetCount( rheology_register );
+            else
+              rheologyCount = 0;
+            coord = materialparticle->coord;
+          }
+        else
+          {
+            GlobalParticle *particle;
+            particle=(GlobalParticle *)Swarm_ParticleAt(swarm,lParticle_I);
+            coord = particle->coord;
+            material_index=0;
+            density=alpha=0;
+            diffusivity=defaultDiffusivity;
+            rheologyCount=0;
+          }
+        postFailureStrain=0;
+        viscosity=0;
+        currently_yielding=0;
+        SymmetricTensor_Zero(stress);
+        normal[0]=normal[1]=normal[2]=0;
+        
+        /* First print out only the coordinates. */
+        if(iteration==0)
+          {
+            if (dim == 2) {
+              fprintf(fp,"%lf %lf 0.0 ",(double)coord[0],
+                      (double)coord[1]);
+            } else {
+              fprintf(fp,"%lf %lf %lf ", (double)coord[0],
+                      (double)coord[1], (double)coord[2]);
+            }
+          }
+        else
+          {
+            /* Loop over all of the rheologies for a particle. */
+                  
+            for( rheology_I = 0; rheology_I < rheologyCount ; rheology_I++ ) { 
+              rheology = (YieldRheology*)Rheology_Register_GetByIndex( rheology_register, rheology_I ); 
+                
+              /* Get postFailureStrain and current_yielding information */
+              if(Stg_Class_IsInstance(rheology,YieldRheology_Type)
+                 && rheology->strainWeakening)
+                {
+                  postFailureStrain=
+                    StrainWeakening_GetPostFailureWeakening
+                    (rheology->strainWeakening,materialparticle);
+                  currently_yielding=YieldRheology_GetParticleFlag
+                    (rheology,materialSwarm,materialparticle);
+                }
+              /* Get viscosity */
+              if(Stg_Class_IsInstance(rheology,StoreVisc_Type))
+                {
+                  StoreVisc* self = (StoreVisc*) rheology;
+                  StoreVisc_ParticleExt* particleExt;
+                  particleExt=
+                    (StoreVisc_ParticleExt*)ExtensionManager_Get( materialSwarm->particleExtensionMgr, materialparticle, self->particleExtHandle );
+                  viscosity=particleExt->effVisc;
+                }
+              /* Get stress */
+              if(Stg_Class_IsInstance(rheology,StoreStress_Type))
+                {
+                  StoreStress* self = (StoreStress*) rheology;
+                  StoreStress_ParticleExt* particleExt;
+                  particleExt=
+                    (StoreStress_ParticleExt*)ExtensionManager_Get( materialSwarm->particleExtensionMgr, materialparticle, self->particleExtHandle );
+                  stress[0]=particleExt->stress[0];
+                  stress[1]=particleExt->stress[1];
+                  stress[2]=particleExt->stress[2];
+                  stress[3]=particleExt->stress[3];
+                  if(dim==3)
+                    {
+                      stress[4]=particleExt->stress[4];
+                      stress[5]=particleExt->stress[5];
+                    }
+                }
+
+              if(Stg_Class_IsInstance(rheology,Anisotropic_Type))
+                {
+                  Anisotropic* self = (Anisotropic*) rheology;
+                  XYZ normal;
+                  Director_GetNormal(self->director,materialparticle,normal);
+                }
+
+
+            }
+            switch(iteration)
+              {
+              case 1:
+                fprintf(fp,"%lf ",viscosity);
+                break;
+              case 2:
+                fprintf(fp,"%lf ",postFailureStrain);
+                break;
+              case 3:
+                if(dim==2)
+                  {
+                    fprintf(fp,"%lf %lf 0.0 %lf %lf 0.0 0.0 0.0 0.0 ",
+                            stress[0],stress[1],
+                            stress[1],stress[2]);
+                  }
+                else
+                  {
+                    fprintf(fp,"%lf %lf %lf %lf %lf %lf %lf %lf %lf ",
+                            stress[0],stress[1],stress[2],
+                            stress[1],stress[3],stress[4],
+                            stress[2],stress[4],stress[5]);
+                  }
+                break;
+              case 4:
+                fprintf(fp,"%lf ",density);
+                break;
+              case 5:
+                fprintf(fp,"%d ",material_index);
+                break;
+              case 6:
+                fprintf(fp,"%lf ",alpha);
+                break;
+              case 7:
+                fprintf(fp,"%lf ",diffusivity);
+                break;
+              case 8:
+                fprintf(fp,"%d ",currently_yielding);
+                break;
+              case 9:
+                if(dim==2)
+                  {
+                    fprintf(fp,"%lf %lf 0.0 ",normal[0],normal[1]);
+                  }
+                else
+                  {
+                    fprintf(fp,"%lf %lf %lf ",normal[0],normal[1],normal[2]);
+                  }
+                break;
+              }
+          }
+      }
+      switch(iteration)
+        {
+        case 0:
+          fprintf(fp,"\n        </DataArray>\n");
+          fprintf(fp,"      </Points>\n");
+          fprintf(fp,"      <PointData Scalars=\"Viscosity\" Tensors=\"Stress\">\n");
+          fprintf(fp,"        <DataArray type=\"Float64\" Name=\"Viscosity\" format=\"ascii\">\n");
+          if(myRank==0)
+            {
+              fprintf(pfp,"      <PPointData Scalars=\"Viscosity\" Tensors=\"Stress\">\n");
+              fprintf(pfp,"        <PDataArray type=\"Float64\" Name=\"Viscosity\" format=\"ascii\"/>\n");
+            }
+          break;
+        case 1:
+          fprintf(fp,"\n        </DataArray>\n");
+          fprintf(fp,"        <DataArray type=\"Float64\" Name=\"Post_Failure_Strain\" format=\"ascii\">\n");
+          if(myRank==0)
+            fprintf(pfp,"        <PDataArray type=\"Float64\" Name=\"Post_Failure_Strain\" format=\"ascii\"/>\n");
+          break;
+        case 2:
+          fprintf(fp,"\n        </DataArray>\n");
+          fprintf(fp,"        <DataArray type=\"Float64\" Name=\"Stress\" format=\"ascii\" NumberOfComponents=\"9\">\n");
+          if(myRank==0)
+            fprintf(pfp,"        <PDataArray type=\"Float64\" Name=\"Stress\" format=\"ascii\" NumberOfComponents=\"9\"/>\n");
+          break;
+        case 3:
+          fprintf(fp,"\n        </DataArray>\n");
+          fprintf(fp,"        <DataArray type=\"Float64\" Name=\"Density\" format=\"ascii\">\n");
+          if(myRank==0)
+            fprintf(pfp,"        <PDataArray type=\"Float64\" Name=\"Density\" format=\"ascii\"/>\n");
+          break;
+        case 4:
+          fprintf(fp,"\n        </DataArray>\n");
+          fprintf(fp,"        <DataArray type=\"Int32\" Name=\"Material_Index\" format=\"ascii\">\n");
+          if(myRank==0)
+            fprintf(pfp,"        <PDataArray type=\"Int32\" Name=\"Material_Index\" format=\"ascii\"/>\n");
+          break;
+        case 5:
+          fprintf(fp,"\n        </DataArray>\n");
+          fprintf(fp,"        <DataArray type=\"Float64\" Name=\"Alpha\" format=\"ascii\">\n");
+          if(myRank==0)
+            fprintf(pfp,"        <PDataArray type=\"Float64\" Name=\"Alpha\" format=\"ascii\"/>\n");
+          break;
+        case 6:
+          fprintf(fp,"\n        </DataArray>\n");
+          fprintf(fp,"        <DataArray type=\"Float64\" Name=\"Thermal_Diffusivity\" format=\"ascii\">\n");
+          if(myRank==0)
+            fprintf(pfp,"        <PDataArray type=\"Float64\" Name=\"Thermal_Diffusivity\" format=\"ascii\"/>\n");
+          break;
+        case 7:
+          fprintf(fp,"\n        </DataArray>\n");
+          fprintf(fp,"        <DataArray type=\"Int32\" Name=\"Currently_Yielding\" format=\"ascii\">\n");
+          if(myRank==0)
+            fprintf(pfp,"        <PDataArray type=\"Int32\" Name=\"Currently_Yielding\" format=\"ascii\"/>\n");
+          break;
+        case 8:
+          fprintf(fp,"\n        </DataArray>\n");
+          fprintf(fp,"        <DataArray type=\"Float64\" Name=\"Orientation\" format=\"ascii\" NumberOfComponents=\"3\">\n");
+          if(myRank==0)
+            fprintf(pfp,"        <PDataArray type=\"Float64\" Name=\"Orientation\" format=\"ascii\" NumberOfComponents=\"3\"/>\n");
+          break;
+        case 9:
+          fprintf(fp,"\n        </DataArray>\n");
+          fprintf(fp,"      </PointData>\n");
+          fprintf(fp,"      <CellData>\n");
+          fprintf(fp,"      </CellData>\n");
+          fprintf(fp,"      <Cells>\n");
+          fprintf(fp,"        <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n");
+          for(i=0;i<(num_particles-1)/stepping+1;++i)
+            fprintf(fp,"%d ",i);
+          fprintf(fp,"\n        </DataArray>\n");
+          fprintf(fp,"        <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n");
+          fprintf(fp,"          %d\n",(num_particles-1)/stepping+1);
+          fprintf(fp,"        </DataArray>\n");
+          fprintf(fp,"        <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n");
+          fprintf(fp,"          2\n");
+          fprintf(fp,"        </DataArray>\n");
+          fprintf(fp,"      </Cells>\n");
+          fprintf(fp,"    </Piece>\n");
+          fprintf(fp,"  </UnstructuredGrid>\n");
+          fprintf(fp,"</VTKFile>\n");
+        }
+    }
+  fclose(fp);
+  if(myRank==0)
+    {
+      fprintf(pfp,"        </PPointData>\n");
+      for(i=0;i<nprocs;++i)
+        fprintf(pfp,"    <Piece Source=\"%s.%d.%05d.vtu\"/>\n",
+                swarm->name,i,timeStep);
+      fprintf(pfp,"  </PUnstructuredGrid>\n\
+</VTKFile>\n");
+      fclose(pfp);
+    }
+}
+
+/* Print out the coordinates of the mesh. */
+
+void VTKOutput_print_coords(FILE *fp, FeMesh *feMesh, Grid *grid, int nDims,
+                            int lower[3], int upper[3]) {
+  IJK ijk;
+
+  fprintf(fp,"      <Points>\n");
+  fprintf(fp,"        <DataArray type=\"Float64\" NumberOfComponents=\"3\" format=\"ascii\">\n");
+  
+  for(ijk[2]=lower[2];ijk[2]<upper[2];++ijk[2])
+    for(ijk[1]=lower[1];ijk[1]<upper[1];++ijk[1])
+      for(ijk[0]=lower[0];ijk[0]<upper[0];++ijk[0])
+        {
+          double *coord;
+          unsigned local;
+          Mesh_GlobalToDomain(feMesh,MT_VERTEX,Grid_Project(grid,ijk),&local);
+          coord=Mesh_GetVertex(feMesh,local);
+          if(nDims==2)
+            fprintf(fp, "%.15g %.15g 0\n", coord[0], coord[1]);
+          else
+            fprintf(fp, "%.15g %.15g %.15g\n", coord[0], coord[1], coord[2]);
+        }
+  fprintf(fp,"        </DataArray>\n      </Points>\n");
+}
+
+
+/* Everything is stored on cell vertices. */
+void VTKOutput_fields(void *context, int myRank, int nprocs,
+                      const int timeStep) {
+  
+  FiniteElementContext*     self = (FiniteElementContext*) context;
+  Index var_I;
+  int header_printed=0;
+  int nDims, i;
+  int lower[3], upper[3], p_lower[3], p_upper[3];
+
+  HydrostaticTerm *hydrostaticTerm;
+  char* field_filename;
+  FILE *field_fp, *pfield_fp;
+
+  Dictionary_Entry_Value* field_list;
+  int field_list_size;
+
+  /* We need to save the grids to map between 1D and 3D indices for
+     the values. */
+  Grid *elGrid, *vertGrid;
+
+  hydrostaticTerm =
+    (HydrostaticTerm*)LiveComponentRegister_Get(self->CF->LCRegister,
+                                                "hydrostaticTerm" );
+  /* Open the file */
+
+  field_list=Dictionary_Get(self->dictionary, "VTKOutput_FieldList" );
+  if(field_list)
+    {
+      field_list_size=Dictionary_Entry_Value_GetCount(field_list);
+      Journal_Firewall(field_list_size>=0,
+                       Journal_Register( Error_Type, self->type ),
+                       "The list of fields in VTKOutput_FieldList is %d but must not be negative.\n",
+                       field_list_size );
+    }
+
+  Stg_asprintf( &field_filename, "%s/fields.%d.%05d.vts", self->outputPath,
+                myRank, timeStep);
+  field_fp=fopen(field_filename,"w");
+  Memory_Free( field_filename );
+
+  if(field_fp==NULL)
+    {
+      fprintf(stderr,"WARNING: Can not open fields file for rank %d step %d\n",
+              myRank,timeStep);
+      return;
+    }
+
+  /* Print out the parallel control files if rank==0 */
+  if(myRank==0)
+    {
+      Stg_asprintf( &field_filename, "%s/fields.%05d.pvts", self->outputPath,
+                    timeStep);
+      pfield_fp=fopen(field_filename,"w");
+      Memory_Free( field_filename );
+      if(pfield_fp==NULL)
+        {
+          fprintf(stderr,
+                  "FATAL ERROR: Can not open master fields file for step %d\n",
+                  timeStep);
+          abort();
+        }
+    }
+
+  /* First, update the fields that are derived from particles.  This
+     is needed to get an accurate pressure, because it needs the
+     stresses. */
+
+  for ( var_I = 0; var_I < self->fieldVariable_Register->objects->count;
+        var_I++ ) {
+    FieldVariable* fieldVar;
+    fieldVar = FieldVariable_Register_GetByIndex( self->fieldVariable_Register,
+                                                  var_I );
+    if (Stg_Class_IsInstance( fieldVar, ParticleFeVariable_Type ))
+      {
+        ParticleFeVariable_Update( fieldVar );
+      }
+  }
+
+  /* First, output the coordinates.  We have to do a huge song and
+     dance just to get the extents of the mesh. */
+
+  for ( var_I = 0; var_I < self->fieldVariable_Register->objects->count;
+        var_I++ ) {
+    int fields;
+    FieldVariable* fieldVar;
+    fieldVar = FieldVariable_Register_GetByIndex( self->fieldVariable_Register,
+                                                  var_I );
+    if (Stg_Class_IsInstance( fieldVar, FeVariable_Type )) {
+      FeVariable* feVar;
+      Dof_Index          dofAtEachNodeCount;
+      int *low, *up;
+      Grid *grid;
+      IJK ijk;
+
+      feVar=(FeVariable*)fieldVar;
+
+      if(!header_printed)
+        {
+          Mesh *mesh;
+          CartesianGenerator *gen;
+
+          mesh=(Mesh*)(feVar->feMesh);
+          gen=((CartesianGenerator *)(mesh->generator));
+          /* If we got the surface adaptor instead of the cartesian
+             mesh generator, go to the mesh generator.  */
+          if(!strcmp(gen->type,"SurfaceAdaptor"))
+            gen=(CartesianGenerator *)((SurfaceAdaptor *)(gen))->generator;
+
+          elGrid=gen->elGrid;
+          vertGrid=gen->vertGrid;
+          nDims=gen->nDims;
+
+          p_lower[2]=lower[2]=0;
+          p_upper[2]=upper[2]=1;
+          for(i=0;i<nDims;++i)
+            {
+              p_lower[i]=gen->origin[i];
+              p_upper[i]=p_lower[i]+gen->range[i];
+
+              /* The grid is split up by elements, so for the element
+                 grid, we simply add the ghost zones.  Ghost zones are
+                 only added at the top, not the bottom. */
+              if(p_upper[i]!=gen->elGrid->sizes[i])
+                ++p_upper[i];
+
+              /* Then we get the vertices by adding appropriate
+                 offsets to the element grid. */
+              upper[i]=p_upper[i]+1;
+              lower[i]=p_lower[i];
+              if(p_lower[i]!=0)
+                --lower[i];
+            }
+
+          /* Now that we have the extents, write the header. */
+
+          fprintf(field_fp,"<?xml version=\"1.0\"?>\n\
+<VTKFile type=\"StructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n\
+  <StructuredGrid WholeExtent=\"%d %d %d %d %d %d\">\n\
+    <Piece Extent=\"%d %d %d %d %d %d\">\n\
+      <CellData></CellData>\n",
+                  lower[0],upper[0]-1,lower[1],upper[1]-1,lower[2],upper[2]-1,
+                  lower[0],upper[0]-1,lower[1],upper[1]-1,lower[2],upper[2]-1);
+
+          /* Write the coordinates for the fields */
+          VTKOutput_print_coords(field_fp, feVar->feMesh, gen->vertGrid, nDims,
+                                 lower, upper);
+          fprintf(field_fp,"      <PointData Scalars=\"StrainRateInvariantField\" Vectors=\"VelocityField\" Tensors=\"Stress\">\n");
+          
+          /* Write out parallel control file headers. */
+          if(myRank==0)
+            {
+              int global[3], p_global[3];
+              global[0]=gen->vertGrid->sizes[0];
+              global[1]=gen->vertGrid->sizes[1];
+              if(nDims==3)
+                {
+                  global[2]=gen->vertGrid->sizes[2];
+                  p_global[2]=global[2]-1;
+                }
+              else
+                {
+                  global[2]=p_global[2]=1;
+                }
+              fprintf(pfield_fp,"<?xml version=\"1.0\"?>\n\
+<VTKFile type=\"PStructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n\
+  <PStructuredGrid GhostLevel=\"0\" WholeExtent=\"0 %d 0 %d 0 %d\">\n\
+    <PCellData></PCellData>\n\
+    <PPoints>\n\
+      <PDataArray type=\"Float64\" NumberOfComponents=\"3\"/>\n\
+    </PPoints>\n\
+    <PPointData Scalars=\"StrainRateInvariantField\" Vectors=\"VelocityField\" Tensors=\"Stress\">\n",global[0]-1,global[1]-1,global[2]-1);
+            }
+          header_printed=1;
+        }
+      
+      /* Finally, output the fields. */
+      
+      /* Check whether the field is in the field list */
+      if(field_list)
+        {
+          for(fields=0; fields<field_list_size; ++fields)
+            {
+              if(!strcmp(Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetElement(field_list,fields)),
+                         fieldVar->name))
+                {
+                  break;
+                }
+            }
+          if(fields==field_list_size)
+            continue;
+        }
+
+      dofAtEachNodeCount = feVar->fieldComponentCount;
+
+      switch(dofAtEachNodeCount*nDims)
+        {
+          /* Scalars */
+        case 2:
+        case 3:
+          fprintf(field_fp,"        <DataArray type=\"Float64\" Name=\"%s\" format=\"ascii\">\n",feVar->name);
+          if(myRank==0)
+            fprintf(pfield_fp,"      <PDataArray type=\"Float64\" Name=\"%s\" format=\"ascii\"/>\n",feVar->name);
+          break;
+          /* Vectors */
+        case 4:
+        case 9:
+          fprintf(field_fp,"        <DataArray type=\"Float64\" Name=\"%s\" format=\"ascii\" NumberOfComponents=\"3\">\n",feVar->name);
+          if(myRank==0)
+            fprintf(pfield_fp,"      <PDataArray type=\"Float64\" Name=\"%s\" format=\"ascii\" NumberOfComponents=\"3\"/>\n",feVar->name);
+          break;
+          /* Rank 2 Tensors */
+        case 6:
+        case 8:
+        case 18:
+        case 27:
+          fprintf(field_fp,"        <DataArray type=\"Float64\" Name=\"%s\" format=\"ascii\" NumberOfComponents=\"9\">\n",feVar->name);
+          if(myRank==0)
+            fprintf(pfield_fp,"      <PDataArray type=\"Float64\" Name=\"%s\" format=\"ascii\" NumberOfComponents=\"9\"/>\n",feVar->name);
+          break;
+          /* Unknown */
+        default:
+          fprintf(stderr,
+                  "Bad number of degrees of freedom for variable %s: %d\n",
+                 feVar->name, dofAtEachNodeCount);
+          abort();
+        }
+
+      for(ijk[2]=lower[2];ijk[2]<upper[2];++ijk[2])
+        for(ijk[1]=lower[1];ijk[1]<upper[1];++ijk[1])
+          for(ijk[0]=lower[0];ijk[0]<upper[0];++ijk[0])
+            {
+              double variableValues[MAX_FIELD_COMPONENTS];	
+              Dof_Index          dof_I;
+              unsigned local;
+              Mesh_GlobalToDomain(feVar->feMesh,MT_VERTEX,
+                                  Grid_Project(vertGrid,ijk),&local);
+              FeVariable_GetValueAtNode(feVar,local,variableValues);
+                                        
+              switch(dofAtEachNodeCount*nDims)
+                {
+                  /* If writing scalars or 3D objects, then just write
+                     the values.  Otherwise, we have to fill in the 3D
+                     components with zeros. */
+                case 2:
+                case 3:
+                case 9:
+                case 27:
+                  /* Special case the pressure */
+                  if(!strcmp(feVar->name,"PressureField"))
+                    {
+                      double p;
+                      /* First add the trace of the stress */
+                      int stress_I;
+
+                      for(stress_I = 0;
+                          stress_I<self->fieldVariable_Register->objects->count;
+                          stress_I++ ) {
+                        FieldVariable* stressVar;
+                        stressVar =
+                          FieldVariable_Register_GetByIndex(self->fieldVariable_Register,
+                                                            stress_I );
+                        if(!strcmp(stressVar->name,"StressField"))
+                          {
+                            if (Stg_Class_IsInstance( stressVar,
+                                                      FeVariable_Type ))
+                              {
+                                FeVariable* sVar;
+                                double stressValues[MAX_FIELD_COMPONENTS];	
+                                sVar=(FeVariable*)stressVar;
+                                
+                                FeVariable_GetValueAtNode(sVar,local,stressValues);
+                                if(nDims==2)
+                                  {
+                                    p=(stressValues[0]+stressValues[1])/2;
+                                  }
+                                else
+                                  {
+                                    p=(stressValues[0]+stressValues[1]
+                                       +stressValues[2])/3;
+                                  }
+                              }
+                            break;
+                          }
+                      }
+                      /* Next add the hydrostatic term */
+                      if(hydrostaticTerm)
+                        {
+                          double *coord;
+                          coord=Mesh_GetVertex(feVar->feMesh,local);
+                          p+=HydrostaticTerm_Pressure(hydrostaticTerm,coord);
+                        }
+                      p+=variableValues[0];
+                      fprintf(field_fp, "%.15g ", p );
+                    }
+                  else
+                    {
+                      for ( dof_I = 0; dof_I < dofAtEachNodeCount; dof_I++ ) {
+                        fprintf(field_fp, "%.15g ", variableValues[dof_I] );
+                      }
+                    }
+                  break;
+                case 4:
+                  fprintf(field_fp, "%.15g %.15g 0", variableValues[0],
+                          variableValues[1] );
+                  break;
+                case 6:
+                  /* Ordering is xx, yy, xy */
+                  fprintf(field_fp, "%.15g %.15g 0 %.15g %.15g 0 0 0 0 ",
+                          variableValues[0], variableValues[2],
+                          variableValues[2], variableValues[1]);
+                  break;
+                case 8:
+                  fprintf(field_fp, "%.15g %.15g 0 %.15g %.15g 0 0 0 0 ",
+                          variableValues[0], variableValues[1],
+                          variableValues[2], variableValues[3]);
+                  break;
+                case 18:
+                  /* Ordering is xx, yy, zz, xy, xz, yz */
+                  fprintf(field_fp, "%.15g %.15g %.15g %.15g %.15g %.15g %.15g %.15g %.15g ",
+                          variableValues[0], variableValues[3],
+                          variableValues[4], variableValues[3],
+                          variableValues[1], variableValues[5],
+                          variableValues[4], variableValues[5],
+                          variableValues[2]);
+                  break;
+                }
+              fprintf(field_fp, "\n" );
+            }
+      fprintf(field_fp,"        </DataArray>\n");
+    }
+  }
+  fprintf(field_fp,"      </PointData>\n    </Piece>\n\
+  </StructuredGrid>\n\
+</VTKFile>\n");
+  fclose(field_fp);
+
+  if(myRank==0)
+    {
+      fprintf(pfield_fp,"      </PPointData>\n");
+      for(i=0;i<nprocs;++i)
+        {
+          fprintf(pfield_fp,"    <Piece Extent=\"%d %d %d %d %d %d\"\n\
+             Source=\"fields.%d.%05d.vts\"/>\n",lower[0],upper[0]-1,
+                  lower[1],upper[1]-1,lower[2],upper[2]-1,
+                  i,timeStep);
+        }
+      fprintf(pfield_fp,"  </PStructuredGrid>\n\
+</VTKFile>\n");
+      fclose(pfield_fp);
+     }
+
+}
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/Vrms/Vrms.c
--- a/plugins/Output/Vrms/Vrms.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,176 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: Vrms.c 610 2007-10-11 08:09:29Z SteveQuenette $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-#include <mpi.h>
-#include <assert.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Underworld.h>
-#include <StgFEM/FrequentOutput/FrequentOutput.h>
-
-#include "Vrms.h"
-
-const Type Underworld_Vrms_Type = "Underworld_Vrms";
-
-void _Underworld_Vrms_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
-	Underworld_Vrms*	self 		= (Underworld_Vrms*)component;
-
-	self->context       = (AbstractContext*)Stg_ComponentFactory_PluginConstructByKey( cf, self, (Dictionary_Entry_Key)"Context", UnderworldContext, True, data  );
-	self->gaussSwarm    = Stg_ComponentFactory_PluginConstructByKey( cf, self, (Dictionary_Entry_Key)"GaussSwarm", Swarm, True, data  );
-	self->velocityField = Stg_ComponentFactory_PluginConstructByKey( cf, self, (Dictionary_Entry_Key)"VelocityField", FeVariable, True, data  );
-
-	/* Create new Field Variable */
-	self->velocitySquaredField = OperatorFeVariable_NewUnary( "VelocitySquaredField", (DomainContext*)self->context, self->velocityField, "VectorSquare" );
-	self->velocitySquaredField->context = (DomainContext*)self->context;
-
-	Underworld_Vrms_PrintHeaderToFile( self->context );
-	ContextEP_Append( self->context, AbstractContext_EP_FrequentOutput, Underworld_Vrms_Dump );
-}
-
-void _Underworld_Vrms_Build( void* component, void* data ) {
-	Underworld_Vrms*	self = (Underworld_Vrms*)component;
-
-	assert( self );
-
-   Stg_Component_Build( self->gaussSwarm, data, False );
-   Stg_Component_Build( self->velocityField, data, False );
-	Stg_Component_Build( self->velocitySquaredField, data, False );
-   
-   _Codelet_Build( self, data );
-}
-
-void _Underworld_Vrms_Initialise( void* component, void* data ) {
-	Underworld_Vrms*	self = (Underworld_Vrms*)component;
-
-	assert( self );
-
-   Stg_Component_Initialise( self->gaussSwarm, data, False );
-   Stg_Component_Initialise( self->velocityField, data, False );
-	Stg_Component_Initialise( self->velocitySquaredField, data, False );
-   
-   _Codelet_Initialise( self, data );
-
-}
-
-void _Underworld_Vrms_Destroy( void* component, void* data ) {
-	Underworld_Vrms*	self = (Underworld_Vrms*)component;
-
-	assert( self );
-
-   _Codelet_Destroy( self, data );
-   
-   Stg_Component_Destroy( self->gaussSwarm, data, False );
-   Stg_Component_Destroy( self->velocityField, data, False );
-	Stg_Component_Destroy( self->velocitySquaredField, data, False );
-
-}
-
-void* _Underworld_Vrms_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Underworld_Vrms);
-	Type                                                      type = Underworld_Vrms_Type;
-	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
-	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
-	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_Vrms_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Underworld_Vrms_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _Underworld_Vrms_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _Underworld_Vrms_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _Codelet_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _Underworld_Vrms_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 Underworld_Vrms_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, Underworld_Vrms_Type, (Name)"0", _Underworld_Vrms_DefaultNew );
-}
-
-/* Integrate Every Step and dump to file */
-void Underworld_Vrms_Dump( void* _context ) {
-	UnderworldContext*                   context       = (UnderworldContext* ) _context;
-	Mesh*			   	     mesh;
-	double		    	  	     maxCrd[3], minCrd[3];
-	double                               integral;
-	double                               vrms;
-	double                               volume        = 0.0;
-	Dimension_Index                      dim           = context->dim;
-
-	Underworld_Vrms* self;
-
-	self = (Underworld_Vrms*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_Vrms_Type );
-
-	mesh = (Mesh* )self->velocitySquaredField->feMesh;
-	Mesh_GetGlobalCoordRange( mesh, minCrd, maxCrd );
-	
-	/* Sum integral */
-	integral = FeVariable_Integrate( self->velocitySquaredField, self->gaussSwarm );
-
-	/* Get Volume of Mesh - TODO Make general for irregular meshes */
-	volume = ( maxCrd[ I_AXIS ] - minCrd[ I_AXIS ] ) * 
-		( maxCrd[ J_AXIS ] - minCrd[ J_AXIS ] );
-	if ( dim == 3 ) 
-		volume *= maxCrd[ K_AXIS ] - minCrd[ K_AXIS ];
-
-	/* Calculate Vrms 
-	 * V_{rms} = \sqrt{ \frac{ \int_\Omega \mathbf{u . u} d\Omega }{\Omega} } */
-	vrms = sqrt( integral / volume );
-
-	/* Print data to file */
-	StgFEM_FrequentOutput_PrintValue( context, vrms );
-
-	/* Put Value onto context */
-	self->vrms = vrms;
-}
-
-void Underworld_Vrms_PrintHeaderToFile( void* context ) {
-	StgFEM_FrequentOutput_PrintString( context, "Vrms" );
-}
-
-
-
diff -r 038180046f6f -r 4b2d36e5021d plugins/Output/Vrms/Vrms.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/Output/Vrms/Vrms.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,176 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: Vrms.c 610 2007-10-11 08:09:29Z SteveQuenette $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+#include <mpi.h>
+#include <assert.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Underworld.h>
+#include <StgFEM/FrequentOutput/FrequentOutput.h>
+
+#include "Vrms.h"
+
+const Type Underworld_Vrms_Type = "Underworld_Vrms";
+
+void _Underworld_Vrms_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
+	Underworld_Vrms*	self 		= (Underworld_Vrms*)component;
+
+	self->context       = (AbstractContext*)Stg_ComponentFactory_PluginConstructByKey( cf, self, (Dictionary_Entry_Key)"Context", UnderworldContext, True, data  );
+	self->gaussSwarm    = Stg_ComponentFactory_PluginConstructByKey( cf, self, (Dictionary_Entry_Key)"GaussSwarm", Swarm, True, data  );
+	self->velocityField = Stg_ComponentFactory_PluginConstructByKey( cf, self, (Dictionary_Entry_Key)"VelocityField", FeVariable, True, data  );
+
+	/* Create new Field Variable */
+	self->velocitySquaredField = OperatorFeVariable_NewUnary( "VelocitySquaredField", (DomainContext*)self->context, self->velocityField, "VectorSquare" );
+	self->velocitySquaredField->context = (DomainContext*)self->context;
+
+	Underworld_Vrms_PrintHeaderToFile( self->context );
+	ContextEP_Append( self->context, AbstractContext_EP_FrequentOutput, Underworld_Vrms_Dump );
+}
+
+void _Underworld_Vrms_Build( void* component, void* data ) {
+	Underworld_Vrms*	self = (Underworld_Vrms*)component;
+
+	assert( self );
+
+   Stg_Component_Build( self->gaussSwarm, data, False );
+   Stg_Component_Build( self->velocityField, data, False );
+	Stg_Component_Build( self->velocitySquaredField, data, False );
+   
+   _Codelet_Build( self, data );
+}
+
+void _Underworld_Vrms_Initialise( void* component, void* data ) {
+	Underworld_Vrms*	self = (Underworld_Vrms*)component;
+
+	assert( self );
+
+   Stg_Component_Initialise( self->gaussSwarm, data, False );
+   Stg_Component_Initialise( self->velocityField, data, False );
+	Stg_Component_Initialise( self->velocitySquaredField, data, False );
+   
+   _Codelet_Initialise( self, data );
+
+}
+
+void _Underworld_Vrms_Destroy( void* component, void* data ) {
+	Underworld_Vrms*	self = (Underworld_Vrms*)component;
+
+	assert( self );
+
+   _Codelet_Destroy( self, data );
+   
+   Stg_Component_Destroy( self->gaussSwarm, data, False );
+   Stg_Component_Destroy( self->velocityField, data, False );
+	Stg_Component_Destroy( self->velocitySquaredField, data, False );
+
+}
+
+void* _Underworld_Vrms_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Underworld_Vrms);
+	Type                                                      type = Underworld_Vrms_Type;
+	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
+	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
+	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_Vrms_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Underworld_Vrms_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _Underworld_Vrms_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _Underworld_Vrms_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _Codelet_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _Underworld_Vrms_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 Underworld_Vrms_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, Underworld_Vrms_Type, (Name)"0", _Underworld_Vrms_DefaultNew );
+}
+
+/* Integrate Every Step and dump to file */
+void Underworld_Vrms_Dump( void* _context ) {
+	UnderworldContext*                   context       = (UnderworldContext* ) _context;
+	Mesh*			   	     mesh;
+	double		    	  	     maxCrd[3], minCrd[3];
+	double                               integral;
+	double                               vrms;
+	double                               volume        = 0.0;
+	Dimension_Index                      dim           = context->dim;
+
+	Underworld_Vrms* self;
+
+	self = (Underworld_Vrms*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_Vrms_Type );
+
+	mesh = (Mesh* )self->velocitySquaredField->feMesh;
+	Mesh_GetGlobalCoordRange( mesh, minCrd, maxCrd );
+	
+	/* Sum integral */
+	integral = FeVariable_Integrate( self->velocitySquaredField, self->gaussSwarm );
+
+	/* Get Volume of Mesh - TODO Make general for irregular meshes */
+	volume = ( maxCrd[ I_AXIS ] - minCrd[ I_AXIS ] ) * 
+		( maxCrd[ J_AXIS ] - minCrd[ J_AXIS ] );
+	if ( dim == 3 ) 
+		volume *= maxCrd[ K_AXIS ] - minCrd[ K_AXIS ];
+
+	/* Calculate Vrms 
+	 * V_{rms} = \sqrt{ \frac{ \int_\Omega \mathbf{u . u} d\Omega }{\Omega} } */
+	vrms = sqrt( integral / volume );
+
+	/* Print data to file */
+	StgFEM_FrequentOutput_PrintValue( context, vrms );
+
+	/* Put Value onto context */
+	self->vrms = vrms;
+}
+
+void Underworld_Vrms_PrintHeaderToFile( void* context ) {
+	StgFEM_FrequentOutput_PrintString( context, "Vrms" );
+}
+
+
+
diff -r 038180046f6f -r 4b2d36e5021d plugins/ScalingChecks/Ra_Scaling/Ra_Scaling.c
--- a/plugins/ScalingChecks/Ra_Scaling/Ra_Scaling.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,137 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id:  $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Underworld.h>
-
-#include <string.h>
-
-/* Each component type needs a unique identifier (as a string for us to read and as an integer for realtime comparisions) */
-const Type Underworld_Ra_Scaling_Type = "Underworld_Ra_Scaling_Type";
-
-void _Ra_CheckScalings_Func( void* context, void* ptrToContext ) {
-  UnderworldContext*      self         = (UnderworldContext*) context;
-  ForceTerm* bfTerm         = (ForceTerm*)LiveComponentRegister_Get( self->CF->LCRegister, (Name)"buoyancyForceTerm" );
-
-  /* check the Rayleigh Number Scaling:
-   * first check the RHS for the stokes SLE has a force term which uses Ra*/
-  if( bfTerm != NULL && (bfTerm->type == ThermalBuoyancyForceTerm_Type )  ) {
-    RheologyMaterial* material;
-    Rheology* rheology;
-    Materials_Register*     materials_Register = self->materials_Register;
-    char* errorMesg = "";
-    double Ra, Ra_0, eta0, diffusivity, gravity, thermalExp=1;
-    int isValid = 1; /* is this scaling check valid */
-
-    /* check if there's only one material */
-    if( Materials_Register_GetCount( materials_Register ) > 1 ) {
-      isValid=0; 
-			Journal_RPrintf( self->info, "\n\n** Warning - The Ra_ScalingCheck plugin is on but you're using more than two materials, thus the Ra_ScalingCheck is invalid because a Rayleigh number doesn't make sense when multiply materials are used **\n" );
-    }
-
-		/* get the material rheology */
-    material = (RheologyMaterial*)Materials_Register_GetByIndex( materials_Register, 0 );
-
-    /* check if there's only one rheology on that material */
-		if (material->rheology_Register->objects->count > 1 ) isValid = 0;
-    
-    Ra        = ((ThermalBuoyancyForceTerm*)bfTerm)->rayleighNumber;
-    rheology  = Rheology_Register_GetByIndex( material->rheology_Register, 0 ); /* assume one rheology */
-
-    /* check if this is a valid test */
-    if( rheology->type == MaterialViscosity_Type && isValid ) { 
-      eta0 = ((MaterialViscosity*)rheology)->eta0;
-
-      diffusivity   = Stg_ComponentFactory_GetDouble( self->CF, "defaultResidualForceTerm", (Dictionary_Entry_Key)"defaultDiffusivity", 1.0  );
-      gravity       = Stg_ComponentFactory_GetRootDictDouble( self->CF, (Dictionary_Entry_Key)"gravity", 1.0 );
-
-      Ra_0 = (gravity * thermalExp)/(diffusivity * eta0  );
-			/* check if the Ra matches the viscosity, gravity, thermal expansivity and diffusivity of the problem */
-      if( abs(Ra - Ra_0) > 1e-3 ) {
-        Stg_asprintf( &errorMesg, "* Error - Your combination of diffusivity, gravity and eta0 (rheology) don't agree with your Ra:"
-            "input:\ndiffusivity = %g\ngravity = %g\neta0 = %g from rheology %s\nthermal expansivity force = %g\nRa = %g\n", diffusivity, gravity, eta0, rheology->name, thermalExp, Ra );
-        Journal_RPrintf( self->info, "\n\n** Scaling issues detected **\n%s\nIf you believe the problem(s) above are ok in your model and you want to get rid of this error message use the command line argument --Ra_ScalingCheck=false\n\n", errorMesg );
-        exit(0);
-      }
-    }
-  }
-}
-
-void _Underworld_Ra_Scaling_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
-   UnderworldContext* context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data  ); 
-
-   Bool checkScaling = Stg_ComponentFactory_GetRootDictBool( cf, (Dictionary_Entry_Key)"Ra_ScalingCheck", True ); 
-
-   if ( checkScaling  ) {
-      EntryPoint_Append( Context_GetEntryPoint( context, AbstractContext_EP_Build ),
-      "Underworld CheckScalings",
-                         (void*)_Ra_CheckScalings_Func,
-      Underworld_Ra_Scaling_Type );
-   }
-}
-
-/* This function will provide StGermain the abilty to instantiate (create) this codelet on demand. */
-void* _Underworld_Ra_Scaling_DefaultNew( Name name ) {
-	return Codelet_New(
-			Underworld_Ra_Scaling_Type,
-			_Underworld_Ra_Scaling_DefaultNew,
-			_Underworld_Ra_Scaling_AssignFromXML, /* SQ NOTE: Used to be a construct extensions. */
-			_Codelet_Build,
-			_Codelet_Initialise,
-			_Codelet_Execute,
-			_Codelet_Destroy,
-			name );
-}
-
-/* This function is automatically run by StGermain when this plugin is loaded. The name must be "<plugin-name>_Register". */
-Index Underworld_Ra_Scaling_Register( PluginsManager* pluginsManager ) {
-	/* A plugin is only properly registered once it returns the handle provided when submitting a codelet to StGermain. */
-	return PluginsManager_Submit( pluginsManager, Underworld_Ra_Scaling_Type, (Name)"0", _Underworld_Ra_Scaling_DefaultNew  );
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d plugins/ScalingChecks/Ra_Scaling/Ra_Scaling.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/ScalingChecks/Ra_Scaling/Ra_Scaling.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,137 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id:  $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Underworld.h>
+
+#include <string.h>
+
+/* Each component type needs a unique identifier (as a string for us to read and as an integer for realtime comparisions) */
+const Type Underworld_Ra_Scaling_Type = "Underworld_Ra_Scaling_Type";
+
+void _Ra_CheckScalings_Func( void* context, void* ptrToContext ) {
+  UnderworldContext*      self         = (UnderworldContext*) context;
+  ForceTerm* bfTerm         = (ForceTerm*)LiveComponentRegister_Get( self->CF->LCRegister, (Name)"buoyancyForceTerm" );
+
+  /* check the Rayleigh Number Scaling:
+   * first check the RHS for the stokes SLE has a force term which uses Ra*/
+  if( bfTerm != NULL && (bfTerm->type == ThermalBuoyancyForceTerm_Type )  ) {
+    RheologyMaterial* material;
+    Rheology* rheology;
+    Materials_Register*     materials_Register = self->materials_Register;
+    char* errorMesg = "";
+    double Ra, Ra_0, eta0, diffusivity, gravity, thermalExp=1;
+    int isValid = 1; /* is this scaling check valid */
+
+    /* check if there's only one material */
+    if( Materials_Register_GetCount( materials_Register ) > 1 ) {
+      isValid=0; 
+			Journal_RPrintf( self->info, "\n\n** Warning - The Ra_ScalingCheck plugin is on but you're using more than two materials, thus the Ra_ScalingCheck is invalid because a Rayleigh number doesn't make sense when multiply materials are used **\n" );
+    }
+
+		/* get the material rheology */
+    material = (RheologyMaterial*)Materials_Register_GetByIndex( materials_Register, 0 );
+
+    /* check if there's only one rheology on that material */
+		if (material->rheology_Register->objects->count > 1 ) isValid = 0;
+    
+    Ra        = ((ThermalBuoyancyForceTerm*)bfTerm)->rayleighNumber;
+    rheology  = Rheology_Register_GetByIndex( material->rheology_Register, 0 ); /* assume one rheology */
+
+    /* check if this is a valid test */
+    if( rheology->type == MaterialViscosity_Type && isValid ) { 
+      eta0 = ((MaterialViscosity*)rheology)->eta0;
+
+      diffusivity   = Stg_ComponentFactory_GetDouble( self->CF, "defaultResidualForceTerm", (Dictionary_Entry_Key)"defaultDiffusivity", 1.0  );
+      gravity       = Stg_ComponentFactory_GetRootDictDouble( self->CF, (Dictionary_Entry_Key)"gravity", 1.0 );
+
+      Ra_0 = (gravity * thermalExp)/(diffusivity * eta0  );
+			/* check if the Ra matches the viscosity, gravity, thermal expansivity and diffusivity of the problem */
+      if( abs(Ra - Ra_0) > 1e-3 ) {
+        Stg_asprintf( &errorMesg, "* Error - Your combination of diffusivity, gravity and eta0 (rheology) don't agree with your Ra:"
+            "input:\ndiffusivity = %g\ngravity = %g\neta0 = %g from rheology %s\nthermal expansivity force = %g\nRa = %g\n", diffusivity, gravity, eta0, rheology->name, thermalExp, Ra );
+        Journal_RPrintf( self->info, "\n\n** Scaling issues detected **\n%s\nIf you believe the problem(s) above are ok in your model and you want to get rid of this error message use the command line argument --Ra_ScalingCheck=false\n\n", errorMesg );
+        exit(0);
+      }
+    }
+  }
+}
+
+void _Underworld_Ra_Scaling_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
+   UnderworldContext* context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data  ); 
+
+   Bool checkScaling = Stg_ComponentFactory_GetRootDictBool( cf, (Dictionary_Entry_Key)"Ra_ScalingCheck", True ); 
+
+   if ( checkScaling  ) {
+      EntryPoint_Append( Context_GetEntryPoint( context, AbstractContext_EP_Build ),
+      "Underworld CheckScalings",
+                         (void*)_Ra_CheckScalings_Func,
+      Underworld_Ra_Scaling_Type );
+   }
+}
+
+/* This function will provide StGermain the abilty to instantiate (create) this codelet on demand. */
+void* _Underworld_Ra_Scaling_DefaultNew( Name name ) {
+	return Codelet_New(
+			Underworld_Ra_Scaling_Type,
+			_Underworld_Ra_Scaling_DefaultNew,
+			_Underworld_Ra_Scaling_AssignFromXML, /* SQ NOTE: Used to be a construct extensions. */
+			_Codelet_Build,
+			_Codelet_Initialise,
+			_Codelet_Execute,
+			_Codelet_Destroy,
+			name );
+}
+
+/* This function is automatically run by StGermain when this plugin is loaded. The name must be "<plugin-name>_Register". */
+Index Underworld_Ra_Scaling_Register( PluginsManager* pluginsManager ) {
+	/* A plugin is only properly registered once it returns the handle provided when submitting a codelet to StGermain. */
+	return PluginsManager_Submit( pluginsManager, Underworld_Ra_Scaling_Type, (Name)"0", _Underworld_Ra_Scaling_DefaultNew  );
+}
+
+
diff -r 038180046f6f -r 4b2d36e5021d plugins/SurfaceProcess/SurfaceProcess.c
--- a/plugins/SurfaceProcess/SurfaceProcess.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,271 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-** Copyright (C) 2008, 2010 California Institute of Technology
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	David May, PhD Student Monash University, VPAC. (david.may at sci.maths.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)
-**      Walter Landry, CIG
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: LevelSetPlg.c 200 2005-07-08 08:24:41Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Underworld.h>
-#include <math.h>
-
-#include "types.h"
-#include "Context.h"
-#include "SurfaceProcess.h"
-
-
-const Type		Underworld_SurfaceProcess_Type = "SurfaceProcess";
-ExtensionInfo_Index	Underworld_SurfaceProcess_ContextHandle;
-
-void Underworld_SurfaceProcess_Execute( TimeIntegrand* crdAdvector,
-                                        Underworld_SurfaceProcess_Context* spCtx)
-{
-  double				dt;
-  
-  /*
-  ** SURFACE PROCESS CODE GOES HERE, SHOULD MODIFY THE VELOCITIES ONLY.
-  */
-  FeVariable *velocity;
-  double K = spCtx->K;
-  Grid* grid;
-  Mesh* mesh;
-  unsigned nDims;
-  Node_LocalIndex n_i;
-  unsigned nNodes;
-
-  assert( spCtx );
-  
-  /* Extract information from contexts. */
-  dt = spCtx->ctx->dt;
-
-  mesh=spCtx->mesh;
-  velocity=spCtx->v;
-    
-  nDims = Mesh_GetDimSize( mesh );
-  grid =
-    *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-                                   ExtensionManager_GetHandle( mesh->info, 
-                                                               "vertexGrid" ) );
-    
-  if( nDims != 2 )
-    abort();
-
-  nNodes = FeMesh_GetNodeLocalSize( mesh);
-      
-  for( n_i = 0; n_i < nNodes; n_i++ )
-    {
-      IJK ijk;
-      RegularMeshUtils_Node_1DTo3D
-        ( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-                  
-      if(ijk[1]==grid->sizes[1]-1
-         && ijk[0]!=0 && ijk[0]!=grid->sizes[0]-1)
-        {
-          IJK ijk_minus, ijk_plus;
-          Node_LocalIndex n_plus, n_minus;
-          double y, y_plus, y_minus, new_y, average_y, dx, delta_v, v[3];
-
-          Vec_Set2D(ijk_minus,ijk);
-          ijk_minus[0]-=1;
-          if(!Mesh_GlobalToDomain
-             (mesh,MT_VERTEX,
-              RegularMeshUtils_Node_3DTo1D(mesh,ijk_minus),&n_minus))
-            {
-              printf("Can not map to local domain %d %d %d\n",
-                     ijk_minus[0],ijk_minus[1],n_i);
-              abort();
-            }
-          Vec_Set2D(ijk_plus,ijk);
-          ijk_plus[0]+=1;
-          if(!Mesh_GlobalToDomain
-             (mesh,MT_VERTEX,
-              RegularMeshUtils_Node_3DTo1D(mesh,ijk_plus),&n_plus))
-            {
-              printf("Can not map to local domain %d %d %d\n",
-                     ijk_plus[0],ijk_plus[1],n_i);
-              abort();
-            }
-
-          y_plus=mesh->verts[n_plus][1];
-          y_minus=mesh->verts[n_minus][1];
-          y=mesh->verts[n_i][1];
-
-          dx=mesh->verts[n_i][0]-mesh->verts[n_minus][0];
-
-          /* If the diffusion overcorrects, then we set the
-             new value to the average */
-          new_y=y+dt*K*(y_plus+y_minus-2*y)/(dx*dx);
-          average_y=(y_plus+y_minus)/2;
-          if((average_y>y && average_y>new_y)
-             || (average_y<y && average_y<new_y))
-            {
-              delta_v=(new_y-y)/dt;
-            }
-          else
-            {
-              delta_v=(average_y-y)/dt;
-            }
-          FeVariable_GetValueAtNode(velocity,n_i,v);
-          v[1]+=delta_v;
-          FeVariable_SetValueAtNode(velocity,n_i,v);
-        }
-    }
-  /*
-  ** END SURFACE PROCESS CODE.
-  */
-  FeVariable_SyncShadowValues(velocity);
-}
-
-Index Underworld_SurfaceProcess_Register( PluginsManager* pluginsMgr ) {
-	return PluginsManager_Submit( pluginsMgr, 
-				      Underworld_SurfaceProcess_Type, 
-				      "0", 
-				      _Underworld_SurfaceProcess_DefaultNew );
-}
-
-void* _Underworld_SurfaceProcess_DefaultNew( Name name ) {
-
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Codelet);
-	Type                                                      type = Underworld_SurfaceProcess_Type;
-	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
-	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
-	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_SurfaceProcess_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Underworld_SurfaceProcess_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _Underworld_SurfaceProcess_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _Codelet_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _Codelet_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _Underworld_SurfaceProcess_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   );
-}
-
-void _Underworld_SurfaceProcess_AssignFromXML( void* component,
-                                               Stg_ComponentFactory* cf,
-                                               void* data ) {
-  Codelet* sp = (Codelet*)component;
-  UnderworldContext*			uwCtx;
-  Underworld_SurfaceProcess_Context*	spCtx;
-  Dictionary*			spDict;
-  char*				meshName;
-  char*                         velocityName;
-
-  assert( component );
-  assert( cf );
-
-  Journal_DPrintf( Underworld_Debug, "In: %s( void* )\n", __func__ );
-
-  /* Retrieve context. */
-  uwCtx =
-    (UnderworldContext*)Stg_ComponentFactory_ConstructByName(cf,"context",
-                                                             UnderworldContext,
-                                                             True, data );
-  sp->context=(AbstractContext* )uwCtx;
-  /* Create new context. */
-  Underworld_SurfaceProcess_ContextHandle =
-    ExtensionManager_Add( uwCtx->extensionMgr, 
-                          Underworld_SurfaceProcess_Type, 
-                          sizeof(Underworld_SurfaceProcess_Context) );
-
-  spCtx = (Underworld_SurfaceProcess_Context*)ExtensionManager_Get( uwCtx->extensionMgr, uwCtx,
-                                Underworld_SurfaceProcess_ContextHandle );
-  memset( spCtx, 0, sizeof(Underworld_SurfaceProcess_Context) );
-  spCtx->ctx = (AbstractContext*)uwCtx;
-
-  /* Get the time integrator. */
-  spCtx->timeIntegrator =
-    Stg_ComponentFactory_ConstructByName( cf, (Name)"timeIntegrator",
-                                          TimeIntegrator, True, data  );
-
-  /* Get the dictionary. */
-  spDict = Dictionary_GetDictionary( uwCtx->dictionary, "SurfaceProcess" );
-  if( !spDict )
-    return;
-
-  /* Read in the variables. */
-  meshName = Dictionary_GetString( spDict, "mesh" );
-  assert( meshName && strcmp( meshName, "" ) );
-  spCtx->mesh = Stg_ComponentFactory_ConstructByName( cf, meshName, Mesh, True,
-                                                      NULL );
-  velocityName = Dictionary_GetString( spDict, "VelocityField" );
-  assert( velocityName && strcmp( velocityName, "" ) );
-  spCtx->v = Stg_ComponentFactory_ConstructByName( cf, velocityName, FeVariable,
-                                                   True, NULL );
-  assert( spCtx->v);
-  spCtx->K = Dictionary_GetDouble( spDict, "diffusionCoefficient" );
-}
-
-void _Underworld_SurfaceProcess_Build( void* codelet, void* data ) {
-	Codelet* sp= (Codelet*)codelet;
-	UnderworldContext* UnderworldCtx = (UnderworldContext*)sp->context;
-	Underworld_SurfaceProcess_Context*	spCtx;
-
-	assert( codelet );
-	assert( UnderworldCtx );
-
-	/* Get the context. */
-	spCtx = (Underworld_SurfaceProcess_Context*)ExtensionManager_Get( UnderworldCtx->extensionMgr, UnderworldCtx, Underworld_SurfaceProcess_ContextHandle );
-
-	if( !spCtx->mesh )
-		return;
-
-	/* Append to the list of time integratee finish routines.  It
-           should come last, because EulerDeform will reset the
-           values. */
-	TimeIntegrator_AppendSetupEP( spCtx->timeIntegrator, 
-					"Underworld_SurfaceProcess_Execute", 
-                                      (void*)Underworld_SurfaceProcess_Execute, 
-					"SurfaceProcess", 
-					spCtx );
-}
-
-void _Underworld_SurfaceProcess_Destroy( void* codelet, void* data ) {
-	UnderworldContext*	UnderworldCtx = (UnderworldContext*)data;
-
-	assert( codelet );
-	assert( UnderworldCtx );
-
-	/* Clear the lot. */
-	/* TODO */
-}
-
diff -r 038180046f6f -r 4b2d36e5021d plugins/SurfaceProcess/SurfaceProcess.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/SurfaceProcess/SurfaceProcess.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,271 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+** Copyright (C) 2008, 2010 California Institute of Technology
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	David May, PhD Student Monash University, VPAC. (david.may at sci.maths.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)
+**      Walter Landry, CIG
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: LevelSetPlg.c 200 2005-07-08 08:24:41Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Underworld.h>
+#include <math.h>
+
+#include "types.h"
+#include "Context.h"
+#include "SurfaceProcess.h"
+
+
+const Type		Underworld_SurfaceProcess_Type = "SurfaceProcess";
+ExtensionInfo_Index	Underworld_SurfaceProcess_ContextHandle;
+
+void Underworld_SurfaceProcess_Execute( TimeIntegrand* crdAdvector,
+                                        Underworld_SurfaceProcess_Context* spCtx)
+{
+  double				dt;
+  
+  /*
+  ** SURFACE PROCESS CODE GOES HERE, SHOULD MODIFY THE VELOCITIES ONLY.
+  */
+  FeVariable *velocity;
+  double K = spCtx->K;
+  Grid* grid;
+  Mesh* mesh;
+  unsigned nDims;
+  Node_LocalIndex n_i;
+  unsigned nNodes;
+
+  assert( spCtx );
+  
+  /* Extract information from contexts. */
+  dt = spCtx->ctx->dt;
+
+  mesh=spCtx->mesh;
+  velocity=spCtx->v;
+    
+  nDims = Mesh_GetDimSize( mesh );
+  grid =
+    *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+                                   ExtensionManager_GetHandle( mesh->info, 
+                                                               "vertexGrid" ) );
+    
+  if( nDims != 2 )
+    abort();
+
+  nNodes = FeMesh_GetNodeLocalSize( mesh);
+      
+  for( n_i = 0; n_i < nNodes; n_i++ )
+    {
+      IJK ijk;
+      RegularMeshUtils_Node_1DTo3D
+        ( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+                  
+      if(ijk[1]==grid->sizes[1]-1
+         && ijk[0]!=0 && ijk[0]!=grid->sizes[0]-1)
+        {
+          IJK ijk_minus, ijk_plus;
+          Node_LocalIndex n_plus, n_minus;
+          double y, y_plus, y_minus, new_y, average_y, dx, delta_v, v[3];
+
+          Vec_Set2D(ijk_minus,ijk);
+          ijk_minus[0]-=1;
+          if(!Mesh_GlobalToDomain
+             (mesh,MT_VERTEX,
+              RegularMeshUtils_Node_3DTo1D(mesh,ijk_minus),&n_minus))
+            {
+              printf("Can not map to local domain %d %d %d\n",
+                     ijk_minus[0],ijk_minus[1],n_i);
+              abort();
+            }
+          Vec_Set2D(ijk_plus,ijk);
+          ijk_plus[0]+=1;
+          if(!Mesh_GlobalToDomain
+             (mesh,MT_VERTEX,
+              RegularMeshUtils_Node_3DTo1D(mesh,ijk_plus),&n_plus))
+            {
+              printf("Can not map to local domain %d %d %d\n",
+                     ijk_plus[0],ijk_plus[1],n_i);
+              abort();
+            }
+
+          y_plus=mesh->verts[n_plus][1];
+          y_minus=mesh->verts[n_minus][1];
+          y=mesh->verts[n_i][1];
+
+          dx=mesh->verts[n_i][0]-mesh->verts[n_minus][0];
+
+          /* If the diffusion overcorrects, then we set the
+             new value to the average */
+          new_y=y+dt*K*(y_plus+y_minus-2*y)/(dx*dx);
+          average_y=(y_plus+y_minus)/2;
+          if((average_y>y && average_y>new_y)
+             || (average_y<y && average_y<new_y))
+            {
+              delta_v=(new_y-y)/dt;
+            }
+          else
+            {
+              delta_v=(average_y-y)/dt;
+            }
+          FeVariable_GetValueAtNode(velocity,n_i,v);
+          v[1]+=delta_v;
+          FeVariable_SetValueAtNode(velocity,n_i,v);
+        }
+    }
+  /*
+  ** END SURFACE PROCESS CODE.
+  */
+  FeVariable_SyncShadowValues(velocity);
+}
+
+Index Underworld_SurfaceProcess_Register( PluginsManager* pluginsMgr ) {
+	return PluginsManager_Submit( pluginsMgr, 
+				      Underworld_SurfaceProcess_Type, 
+				      "0", 
+				      _Underworld_SurfaceProcess_DefaultNew );
+}
+
+void* _Underworld_SurfaceProcess_DefaultNew( Name name ) {
+
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Codelet);
+	Type                                                      type = Underworld_SurfaceProcess_Type;
+	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
+	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
+	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Underworld_SurfaceProcess_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Underworld_SurfaceProcess_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _Underworld_SurfaceProcess_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _Codelet_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _Codelet_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _Underworld_SurfaceProcess_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   );
+}
+
+void _Underworld_SurfaceProcess_AssignFromXML( void* component,
+                                               Stg_ComponentFactory* cf,
+                                               void* data ) {
+  Codelet* sp = (Codelet*)component;
+  UnderworldContext*			uwCtx;
+  Underworld_SurfaceProcess_Context*	spCtx;
+  Dictionary*			spDict;
+  char*				meshName;
+  char*                         velocityName;
+
+  assert( component );
+  assert( cf );
+
+  Journal_DPrintf( Underworld_Debug, "In: %s( void* )\n", __func__ );
+
+  /* Retrieve context. */
+  uwCtx =
+    (UnderworldContext*)Stg_ComponentFactory_ConstructByName(cf,"context",
+                                                             UnderworldContext,
+                                                             True, data );
+  sp->context=(AbstractContext* )uwCtx;
+  /* Create new context. */
+  Underworld_SurfaceProcess_ContextHandle =
+    ExtensionManager_Add( uwCtx->extensionMgr, 
+                          Underworld_SurfaceProcess_Type, 
+                          sizeof(Underworld_SurfaceProcess_Context) );
+
+  spCtx = (Underworld_SurfaceProcess_Context*)ExtensionManager_Get( uwCtx->extensionMgr, uwCtx,
+                                Underworld_SurfaceProcess_ContextHandle );
+  memset( spCtx, 0, sizeof(Underworld_SurfaceProcess_Context) );
+  spCtx->ctx = (AbstractContext*)uwCtx;
+
+  /* Get the time integrator. */
+  spCtx->timeIntegrator =
+    Stg_ComponentFactory_ConstructByName( cf, (Name)"timeIntegrator",
+                                          TimeIntegrator, True, data  );
+
+  /* Get the dictionary. */
+  spDict = Dictionary_GetDictionary( uwCtx->dictionary, "SurfaceProcess" );
+  if( !spDict )
+    return;
+
+  /* Read in the variables. */
+  meshName = Dictionary_GetString( spDict, "mesh" );
+  assert( meshName && strcmp( meshName, "" ) );
+  spCtx->mesh = Stg_ComponentFactory_ConstructByName( cf, meshName, Mesh, True,
+                                                      NULL );
+  velocityName = Dictionary_GetString( spDict, "VelocityField" );
+  assert( velocityName && strcmp( velocityName, "" ) );
+  spCtx->v = Stg_ComponentFactory_ConstructByName( cf, velocityName, FeVariable,
+                                                   True, NULL );
+  assert( spCtx->v);
+  spCtx->K = Dictionary_GetDouble( spDict, "diffusionCoefficient" );
+}
+
+void _Underworld_SurfaceProcess_Build( void* codelet, void* data ) {
+	Codelet* sp= (Codelet*)codelet;
+	UnderworldContext* UnderworldCtx = (UnderworldContext*)sp->context;
+	Underworld_SurfaceProcess_Context*	spCtx;
+
+	assert( codelet );
+	assert( UnderworldCtx );
+
+	/* Get the context. */
+	spCtx = (Underworld_SurfaceProcess_Context*)ExtensionManager_Get( UnderworldCtx->extensionMgr, UnderworldCtx, Underworld_SurfaceProcess_ContextHandle );
+
+	if( !spCtx->mesh )
+		return;
+
+	/* Append to the list of time integratee finish routines.  It
+           should come last, because EulerDeform will reset the
+           values. */
+	TimeIntegrator_AppendSetupEP( spCtx->timeIntegrator, 
+					"Underworld_SurfaceProcess_Execute", 
+                                      (void*)Underworld_SurfaceProcess_Execute, 
+					"SurfaceProcess", 
+					spCtx );
+}
+
+void _Underworld_SurfaceProcess_Destroy( void* codelet, void* data ) {
+	UnderworldContext*	UnderworldCtx = (UnderworldContext*)data;
+
+	assert( codelet );
+	assert( UnderworldCtx );
+
+	/* Clear the lot. */
+	/* TODO */
+}
+
diff -r 038180046f6f -r 4b2d36e5021d plugins/VariableConditions/ShapeFemIC/ShapeFemIC.c
--- a/plugins/VariableConditions/ShapeFemIC/ShapeFemIC.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,339 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id:  $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <Underworld/Underworld.h>
-
-#include <string.h>
-#include <math.h>
-#include <stdio.h>
-#include <assert.h>
-
-#define STD   1
-#define PM    2
-
-const Type Underworld_ShapeFemIC_Type = "Underworld_ShapeFemIC";
-typedef struct {
-	__Codelet
-} Underworld_ShapeFemIC;
-
-
-
-void Underworld_LinearShapeIC( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
-
-  UnderworldContext*       context            = (UnderworldContext*)_context;
-
-  Dictionary*              theDictionary      = context->dictionary;
-  FeVariable*    tempField   = (FeVariable*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"TemperatureField" );
-  FeMesh*	           theMesh            = NULL;
-  double*                  result             = (double* ) _result;
-  Stg_Shape*               shape;
-  Name                     shapeName;
-  double*                  coord;
-  Dictionary_Entry_Value*  shapeSpecs;	
-  Index                    numSpecs = 0;
-  Index	                   shapeSpec_I;
-  Dictionary_Entry_Value*  shapeSpec = NULL;
-  Dictionary*	           shapeSpecDict;
-
-  int setup;
-  /* STD config */
-  double gz, p1x, p1y, p1z, p2x, p2y, p2z, z, ux, uy, uz, nu, d, zp;
-  double gx, gy, T0, x, y, az, xp, yp;
-  double ox, oy;
-  /* PM config */
-  double ox1,oy1,T1,H1,gy1;
-  double ox2,oy2,T2,H2,gy2;
-  double T1u, T1l;
-  double T2u, T2l;
-  double Tmu, Tml;
-  double o1ux, o1uy;
-  double o1ly;
-  double o2ux, o2uy;
-  double o2ly;
-  double omuy, omly;
-  double alpha, beta, W;
-
-  theMesh = tempField->feMesh;
-
-  shapeSpecs = Dictionary_Get( theDictionary, (Dictionary_Entry_Key)"linearShapeIC" );
-  numSpecs = Dictionary_Entry_Value_GetCount( shapeSpecs );
-
-  for( shapeSpec_I = 0; shapeSpec_I < numSpecs; shapeSpec_I++  ) {
-    shapeSpec = Dictionary_Entry_Value_GetElement( shapeSpecs, shapeSpec_I );
-    shapeSpecDict = Dictionary_Entry_Value_AsDictionary( shapeSpec );
-    shapeName = Dictionary_Entry_Value_AsString( Dictionary_Get( shapeSpecDict, (Dictionary_Entry_Key)"Shape" ) );
-
-    /* Get the shape */
-    shape = (Stg_Shape* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)shapeName );
-
-    Journal_Firewall( shape!=NULL, 
-		      Journal_Register( Error_Type, (Name)Underworld_ShapeFemIC_Type  ), 
-		      "Shape %s not found.\n", shapeName );
-
-    /* Find coordinate of node */
-    coord = Mesh_GetVertex( theMesh, node_lI );
-
-    if( Stg_Shape_IsCoordInside( shape, coord ) ) {
-
-      setup = Dictionary_GetInt_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"setup", STD );
-
-      switch( setup  ) {
-      case STD:
-	/* rotation angle */
-	az = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"rotation", 0.0  );
-	/* gradient in each direction */
-	gx = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"gradientx", 0.0  );
-	gy = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"gradienty", 0.0  );
-	/* value of the field at origin */
-	T0 = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"valueAtOrigin", 0.0 );
-
-	x = coord[I_AXIS];
-	y = coord[J_AXIS];
-	az = az/180.0*M_PI;
-
-	switch( theMesh->topo->nDims  ) {
-	case 2: 
-	  /* origin */
-	  ox = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"originx", 0.0  );
-	  oy = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"originy", 0.0 );
-	  /* rotations and translations */
-	  xp = (x-ox)*cos(az) - (y-oy)*sin(az);
-	  yp = (x-ox)*sin(az) + (y-oy)*cos(az );
-	  /* compute value at the point */
-	  *result = T0 + xp*gx + yp*gy; 
-	  break;
-	
-	case 3: 
-	  gz = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"gradientz", 0.0 );
-	  /* two points defining the rotational axis (3D case ) First point is the origin */
-	  p1x = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"p1x", 0.0  );
-	  p1y = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"p1y", 0.0  );
-	  p1z = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"p1z", 0.0  );
-	  p2x = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"p2x", 0.0  );
-	  p2y = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"p2y", 0.0  );
-	  p2z = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"p2z", 1.0 );
-
-	  z   = coord[K_AXIS];
-
-	  /* unit axis of rotation */
-	  ux = p1x-p2x;
-	  uy = p1y-p2y;
-	  uz = p1z-p2z;
-	  nu = sqrt(ux*ux + uy*uy + uz*uz);
-
-	  ux /= nu;
-	  uy /= nu;
-	  uz /= nu;
-	  
-	  /* Rotate and translate */
-	  d = sqrt( uy*uy + uz*uz );
-	  xp = cos(az)*( -uy*(y-p1y) - uz*(z-p1z) ) - sin(az)*( uz/d*(y-p1y) - uy/ux*(z-p1z) );
-	  yp = sin(az)*( -uy*(y-p1y) - uz*(z-p1z) ) + cos(az)*( uz/d*(y-p1y) - uy/ux*(z-p1z) );
-	  zp = d*uy/ux*(y-p1y) + d*uz/ux*(z-p1z );
-
-	  /* compute value at the point */
-	  *result = T0 + xp*gx + yp*gy + zp*gz; 
-	  break;	
-	}
-	break;
-
-      case PM:
-	/* Advanced config */
-	ox1 = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"originx1", 0.0  );
-	oy1 = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"originy1", 0.0  );
-	gy1 = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"gradienty1", 0.0  );
-	T1 = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"valueAtOrigin1", 0.0  );
-	H1 = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"height1", 0.0  );
-
-	ox2 = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"originx2", 0.0  );
-	oy2 = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"originy2", 0.0  );
-	gy2 = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"gradienty2", 0.0  );
-	T2 = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"valueAtOrigin2", 0.0  );
-	H2 = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"height2", 0.0 );
-
-	x = coord[I_AXIS];
-	y = coord[J_AXIS];
-
-	T1u = T1;
-	T1l = T1 + H1 * gy1;
-	T2u = T2;
-	T2l = T2 + H2 * gy2;
-
-	o1ux = ox1;
-	o1uy = oy1;
-	o1ly = oy1 + H1;
-            
-	o2ux = ox2;
-	o2uy = oy2;
-	o2ly = oy2 + H2;
-
-	W = o2ux - o1ux;
-	alpha = (x - o1ux) / W;
-            
-	Tmu = (1-alpha)*T1u + alpha*T2u;
-	Tml = (1-alpha)*T1l + alpha*T2l;            
-	omuy = (1-alpha)*o1uy + alpha*o2uy;
-	omly = (1-alpha)*o1ly + alpha*o2ly;
-            
-	beta = (y - omuy) / (omly - omuy);
-
-	*result = (1-beta )*Tmu + beta*Tml;
-	break;
-      }
-    }
-  }
-}
-
-
-void Underworld_SimpleShapeIC( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
-	UnderworldContext* context    = (UnderworldContext*)_context;
-	Dictionary* dictionary = context->dictionary;
-	MeshVariable* meshVar    = NULL;
-	FeMesh* mesh       = NULL;
-	double* result     = (double*) _result;
-	Stg_Shape* shape;
-	Name shapeName;
-	double* coord;
-
-	meshVar = (MeshVariable*)Variable_Register_GetByIndex( context->variable_Register, var_I );
-	mesh = (FeMesh*)meshVar->mesh; assert( mesh != NULL );
-
-	shapeName = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"ShapeFemIC" );
-	shape = (Stg_Shape* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)shapeName );
-	assert( shape  );
-
-	/* Find coordinate of node */
-	coord = Mesh_GetVertex( mesh, node_lI );
-
-	if ( Stg_Shape_IsCoordInside( shape, coord ) ) 
-		*result = 1.0;
-	else 
-		*result = 0.0;
-}
-
-void Underworld_GaussianIC( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
-	UnderworldContext*      context            = (UnderworldContext*)_context;
-	Dictionary*             dictionary         = context->dictionary;
-  FeVariable*    tempField   = (FeVariable*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"TemperatureField" );
-	FeMesh*			mesh               = NULL;
-	double*                 result             = (double* ) _result;
-	Stg_Shape*              shape;
-	Name                    shapeName;
-	double*                 coord;
-	double                  disVec[3];
-	double                  amplitude, width;
-	double                  rSq;
-	
-	mesh       = tempField->feMesh;
-
-	amplitude = Dictionary_GetDouble_WithDefault( dictionary, (Dictionary_Entry_Key)"GaussianIC-Amplitude", 1.0  );
-	width = Dictionary_GetDouble_WithDefault( dictionary, (Dictionary_Entry_Key)"GaussianIC-Width", 1e-2  );
-
-	shapeName = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"ShapeFemIC" );
-	shape = (Stg_Shape* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)shapeName );
-	assert( shape  );
-	Journal_Firewall( !strcmp(shape->type, "Sphere") || !strcmp(shape->type, "Cylinder"),
-			Journal_Register( Error_Type, (Name)Underworld_ShapeFemIC_Type  ),
-			"Error in %s: You're applying the GaussianIC to a shape of type %s, which can't be done."
-			" It can only work on Sphere\' or \'Cylinder\' shapes\n", __func__,  shape->type );
-	/* Find coordinate of node */
-	coord = Mesh_GetVertex( mesh, node_lI );
-
-	if( !strcmp(shape->type, "Sphere") ) {
-		_Sphere_DistanceFromCenterAxis( shape, coord, disVec );
-
-		rSq = disVec[0]*disVec[0]+disVec[1]*disVec[1];
-		*result = amplitude * exp( -1 * rSq / (2 * width) );
-	} 
-	else if(  !strcmp(shape->type, "Cylinder") )  {
-		_Cylinder_DistanceFromCenterAxis( shape, coord, disVec );
-
-		rSq = disVec[0]*disVec[0]+disVec[1]*disVec[1];
-		if( shape->dim == 3 ) rSq += disVec[2]*disVec[2];
-
-		*result = amplitude * exp( -1 * rSq / (2 * width) );
-	}
-
-}
-
-void _Underworld_ShapeFemIC_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
-	ConditionFunction*      condFunc;
-	UnderworldContext*      context;
-
-	context = (UnderworldContext*)Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data  ); 
-	
-	condFunc = ConditionFunction_New( Underworld_SimpleShapeIC, (Name)"Inside1_Outside0_ShapeIC"  );
-	ConditionFunction_Register_Add( condFunc_Register, condFunc );
-	condFunc = ConditionFunction_New( Underworld_GaussianIC, (Name)"GaussianIC"  );
-	ConditionFunction_Register_Add( condFunc_Register, condFunc );
-	condFunc = ConditionFunction_New( Underworld_LinearShapeIC, (Name)"linearShapeIC"  );
-	ConditionFunction_Register_Add( condFunc_Register, condFunc );
-}
-
-void* _Underworld_ShapeFemIC_DefaultNew( Name name ) {
-	return Codelet_New(
-		Underworld_ShapeFemIC_Type,
-		_Underworld_ShapeFemIC_DefaultNew,
-		_Underworld_ShapeFemIC_AssignFromXML,
-		_Codelet_Build,
-		_Codelet_Initialise,
-		_Codelet_Execute,
-		_Codelet_Destroy,
-		name );
-}
-
-Index Underworld_ShapeFemIC_Register( PluginsManager* pluginsManager ) {
-	Journal_DPrintf( Underworld_Debug, "In: %s( void* )\n", __func__ );
-
-	return PluginsManager_Submit( pluginsManager, Underworld_ShapeFemIC_Type, (Name)"0", _Underworld_ShapeFemIC_DefaultNew  );
-}
-
-
-
diff -r 038180046f6f -r 4b2d36e5021d plugins/VariableConditions/ShapeFemIC/ShapeFemIC.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/VariableConditions/ShapeFemIC/ShapeFemIC.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,339 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id:  $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <Underworld/Underworld.h>
+
+#include <string.h>
+#include <math.h>
+#include <stdio.h>
+#include <assert.h>
+
+#define STD   1
+#define PM    2
+
+const Type Underworld_ShapeFemIC_Type = "Underworld_ShapeFemIC";
+typedef struct {
+	__Codelet
+} Underworld_ShapeFemIC;
+
+
+
+void Underworld_LinearShapeIC( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
+
+  UnderworldContext*       context            = (UnderworldContext*)_context;
+
+  Dictionary*              theDictionary      = context->dictionary;
+  FeVariable*    tempField   = (FeVariable*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"TemperatureField" );
+  FeMesh*	           theMesh            = NULL;
+  double*                  result             = (double* ) _result;
+  Stg_Shape*               shape;
+  Name                     shapeName;
+  double*                  coord;
+  Dictionary_Entry_Value*  shapeSpecs;	
+  Index                    numSpecs = 0;
+  Index	                   shapeSpec_I;
+  Dictionary_Entry_Value*  shapeSpec = NULL;
+  Dictionary*	           shapeSpecDict;
+
+  int setup;
+  /* STD config */
+  double gz, p1x, p1y, p1z, p2x, p2y, p2z, z, ux, uy, uz, nu, d, zp;
+  double gx, gy, T0, x, y, az, xp, yp;
+  double ox, oy;
+  /* PM config */
+  double ox1,oy1,T1,H1,gy1;
+  double ox2,oy2,T2,H2,gy2;
+  double T1u, T1l;
+  double T2u, T2l;
+  double Tmu, Tml;
+  double o1ux, o1uy;
+  double o1ly;
+  double o2ux, o2uy;
+  double o2ly;
+  double omuy, omly;
+  double alpha, beta, W;
+
+  theMesh = tempField->feMesh;
+
+  shapeSpecs = Dictionary_Get( theDictionary, (Dictionary_Entry_Key)"linearShapeIC" );
+  numSpecs = Dictionary_Entry_Value_GetCount( shapeSpecs );
+
+  for( shapeSpec_I = 0; shapeSpec_I < numSpecs; shapeSpec_I++  ) {
+    shapeSpec = Dictionary_Entry_Value_GetElement( shapeSpecs, shapeSpec_I );
+    shapeSpecDict = Dictionary_Entry_Value_AsDictionary( shapeSpec );
+    shapeName = Dictionary_Entry_Value_AsString( Dictionary_Get( shapeSpecDict, (Dictionary_Entry_Key)"Shape" ) );
+
+    /* Get the shape */
+    shape = (Stg_Shape* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)shapeName );
+
+    Journal_Firewall( shape!=NULL, 
+		      Journal_Register( Error_Type, (Name)Underworld_ShapeFemIC_Type  ), 
+		      "Shape %s not found.\n", shapeName );
+
+    /* Find coordinate of node */
+    coord = Mesh_GetVertex( theMesh, node_lI );
+
+    if( Stg_Shape_IsCoordInside( shape, coord ) ) {
+
+      setup = Dictionary_GetInt_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"setup", STD );
+
+      switch( setup  ) {
+      case STD:
+	/* rotation angle */
+	az = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"rotation", 0.0  );
+	/* gradient in each direction */
+	gx = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"gradientx", 0.0  );
+	gy = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"gradienty", 0.0  );
+	/* value of the field at origin */
+	T0 = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"valueAtOrigin", 0.0 );
+
+	x = coord[I_AXIS];
+	y = coord[J_AXIS];
+	az = az/180.0*M_PI;
+
+	switch( theMesh->topo->nDims  ) {
+	case 2: 
+	  /* origin */
+	  ox = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"originx", 0.0  );
+	  oy = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"originy", 0.0 );
+	  /* rotations and translations */
+	  xp = (x-ox)*cos(az) - (y-oy)*sin(az);
+	  yp = (x-ox)*sin(az) + (y-oy)*cos(az );
+	  /* compute value at the point */
+	  *result = T0 + xp*gx + yp*gy; 
+	  break;
+	
+	case 3: 
+	  gz = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"gradientz", 0.0 );
+	  /* two points defining the rotational axis (3D case ) First point is the origin */
+	  p1x = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"p1x", 0.0  );
+	  p1y = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"p1y", 0.0  );
+	  p1z = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"p1z", 0.0  );
+	  p2x = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"p2x", 0.0  );
+	  p2y = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"p2y", 0.0  );
+	  p2z = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"p2z", 1.0 );
+
+	  z   = coord[K_AXIS];
+
+	  /* unit axis of rotation */
+	  ux = p1x-p2x;
+	  uy = p1y-p2y;
+	  uz = p1z-p2z;
+	  nu = sqrt(ux*ux + uy*uy + uz*uz);
+
+	  ux /= nu;
+	  uy /= nu;
+	  uz /= nu;
+	  
+	  /* Rotate and translate */
+	  d = sqrt( uy*uy + uz*uz );
+	  xp = cos(az)*( -uy*(y-p1y) - uz*(z-p1z) ) - sin(az)*( uz/d*(y-p1y) - uy/ux*(z-p1z) );
+	  yp = sin(az)*( -uy*(y-p1y) - uz*(z-p1z) ) + cos(az)*( uz/d*(y-p1y) - uy/ux*(z-p1z) );
+	  zp = d*uy/ux*(y-p1y) + d*uz/ux*(z-p1z );
+
+	  /* compute value at the point */
+	  *result = T0 + xp*gx + yp*gy + zp*gz; 
+	  break;	
+	}
+	break;
+
+      case PM:
+	/* Advanced config */
+	ox1 = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"originx1", 0.0  );
+	oy1 = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"originy1", 0.0  );
+	gy1 = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"gradienty1", 0.0  );
+	T1 = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"valueAtOrigin1", 0.0  );
+	H1 = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"height1", 0.0  );
+
+	ox2 = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"originx2", 0.0  );
+	oy2 = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"originy2", 0.0  );
+	gy2 = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"gradienty2", 0.0  );
+	T2 = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"valueAtOrigin2", 0.0  );
+	H2 = Dictionary_GetDouble_WithDefault( shapeSpecDict, (Dictionary_Entry_Key)"height2", 0.0 );
+
+	x = coord[I_AXIS];
+	y = coord[J_AXIS];
+
+	T1u = T1;
+	T1l = T1 + H1 * gy1;
+	T2u = T2;
+	T2l = T2 + H2 * gy2;
+
+	o1ux = ox1;
+	o1uy = oy1;
+	o1ly = oy1 + H1;
+            
+	o2ux = ox2;
+	o2uy = oy2;
+	o2ly = oy2 + H2;
+
+	W = o2ux - o1ux;
+	alpha = (x - o1ux) / W;
+            
+	Tmu = (1-alpha)*T1u + alpha*T2u;
+	Tml = (1-alpha)*T1l + alpha*T2l;            
+	omuy = (1-alpha)*o1uy + alpha*o2uy;
+	omly = (1-alpha)*o1ly + alpha*o2ly;
+            
+	beta = (y - omuy) / (omly - omuy);
+
+	*result = (1-beta )*Tmu + beta*Tml;
+	break;
+      }
+    }
+  }
+}
+
+
+void Underworld_SimpleShapeIC( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
+	UnderworldContext* context    = (UnderworldContext*)_context;
+	Dictionary* dictionary = context->dictionary;
+	MeshVariable* meshVar    = NULL;
+	FeMesh* mesh       = NULL;
+	double* result     = (double*) _result;
+	Stg_Shape* shape;
+	Name shapeName;
+	double* coord;
+
+	meshVar = (MeshVariable*)Variable_Register_GetByIndex( context->variable_Register, var_I );
+	mesh = (FeMesh*)meshVar->mesh; assert( mesh != NULL );
+
+	shapeName = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"ShapeFemIC" );
+	shape = (Stg_Shape* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)shapeName );
+	assert( shape  );
+
+	/* Find coordinate of node */
+	coord = Mesh_GetVertex( mesh, node_lI );
+
+	if ( Stg_Shape_IsCoordInside( shape, coord ) ) 
+		*result = 1.0;
+	else 
+		*result = 0.0;
+}
+
+void Underworld_GaussianIC( Node_LocalIndex node_lI, Variable_Index var_I, void* _context, void* _result ) {
+	UnderworldContext*      context            = (UnderworldContext*)_context;
+	Dictionary*             dictionary         = context->dictionary;
+  FeVariable*    tempField   = (FeVariable*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"TemperatureField" );
+	FeMesh*			mesh               = NULL;
+	double*                 result             = (double* ) _result;
+	Stg_Shape*              shape;
+	Name                    shapeName;
+	double*                 coord;
+	double                  disVec[3];
+	double                  amplitude, width;
+	double                  rSq;
+	
+	mesh       = tempField->feMesh;
+
+	amplitude = Dictionary_GetDouble_WithDefault( dictionary, (Dictionary_Entry_Key)"GaussianIC-Amplitude", 1.0  );
+	width = Dictionary_GetDouble_WithDefault( dictionary, (Dictionary_Entry_Key)"GaussianIC-Width", 1e-2  );
+
+	shapeName = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"ShapeFemIC" );
+	shape = (Stg_Shape* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)shapeName );
+	assert( shape  );
+	Journal_Firewall( !strcmp(shape->type, "Sphere") || !strcmp(shape->type, "Cylinder"),
+			Journal_Register( Error_Type, (Name)Underworld_ShapeFemIC_Type  ),
+			"Error in %s: You're applying the GaussianIC to a shape of type %s, which can't be done."
+			" It can only work on Sphere\' or \'Cylinder\' shapes\n", __func__,  shape->type );
+	/* Find coordinate of node */
+	coord = Mesh_GetVertex( mesh, node_lI );
+
+	if( !strcmp(shape->type, "Sphere") ) {
+		_Sphere_DistanceFromCenterAxis( shape, coord, disVec );
+
+		rSq = disVec[0]*disVec[0]+disVec[1]*disVec[1];
+		*result = amplitude * exp( -1 * rSq / (2 * width) );
+	} 
+	else if(  !strcmp(shape->type, "Cylinder") )  {
+		_Cylinder_DistanceFromCenterAxis( shape, coord, disVec );
+
+		rSq = disVec[0]*disVec[0]+disVec[1]*disVec[1];
+		if( shape->dim == 3 ) rSq += disVec[2]*disVec[2];
+
+		*result = amplitude * exp( -1 * rSq / (2 * width) );
+	}
+
+}
+
+void _Underworld_ShapeFemIC_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
+	ConditionFunction*      condFunc;
+	UnderworldContext*      context;
+
+	context = (UnderworldContext*)Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data  ); 
+	
+	condFunc = ConditionFunction_New( Underworld_SimpleShapeIC, (Name)"Inside1_Outside0_ShapeIC"  );
+	ConditionFunction_Register_Add( condFunc_Register, condFunc );
+	condFunc = ConditionFunction_New( Underworld_GaussianIC, (Name)"GaussianIC"  );
+	ConditionFunction_Register_Add( condFunc_Register, condFunc );
+	condFunc = ConditionFunction_New( Underworld_LinearShapeIC, (Name)"linearShapeIC"  );
+	ConditionFunction_Register_Add( condFunc_Register, condFunc );
+}
+
+void* _Underworld_ShapeFemIC_DefaultNew( Name name ) {
+	return Codelet_New(
+		Underworld_ShapeFemIC_Type,
+		_Underworld_ShapeFemIC_DefaultNew,
+		_Underworld_ShapeFemIC_AssignFromXML,
+		_Codelet_Build,
+		_Codelet_Initialise,
+		_Codelet_Execute,
+		_Codelet_Destroy,
+		name );
+}
+
+Index Underworld_ShapeFemIC_Register( PluginsManager* pluginsManager ) {
+	Journal_DPrintf( Underworld_Debug, "In: %s( void* )\n", __func__ );
+
+	return PluginsManager_Submit( pluginsManager, Underworld_ShapeFemIC_Type, (Name)"0", _Underworld_ShapeFemIC_DefaultNew  );
+}
+
+
+
diff -r 038180046f6f -r 4b2d36e5021d src/main.c
--- a/src/main.c	Wed May 11 13:27:52 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,114 +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:
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Mirko Velic
-*+		Patrick Sunter
-*+		Julian Giordani
-*+
-** $Id: main.c 701 2008-04-07 02:12:42Z JulianGiordani $
-** 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#ifdef HAVE_PYTHON
-	#include <Python.h>
-#endif
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-const Type Underworld_Type = "Underworld";
-
-int main( int argc, char* argv[] ) {
-	/* StGermain standard bits & pieces */
-	MPI_Comm			CommWorld;
-	int				rank;
-	int				numProcessors;
-	Dictionary*			dictionary;
-	XML_IO_Handler*			ioHandler;
-	Stream*                         stream;
-
-	/* Initialise PETSc, get world info */
-	MPI_Init( &argc, &argv );
-	MPI_Comm_dup( MPI_COMM_WORLD, &CommWorld );
-	MPI_Comm_size( CommWorld, &numProcessors );
-	MPI_Comm_rank( CommWorld, &rank );
-	StGermain_Init( &argc, &argv );
-	stream = Journal_Register( DebugStream_Type, (Name)Underworld_Type );
-	#ifdef HAVE_PYTHON
-		Py_Initialize();
-	#endif	
-	MPI_Barrier( CommWorld ); /* Ensures copyright info always come first in output */
-	
-	/* Create the application's dictionary & read input */
-	dictionary = Dictionary_New();
-	ioHandler = XML_IO_Handler_New( );
-	IO_Handler_ReadAllFromCommandLine( ioHandler, argc, argv, dictionary );
-	Journal_ReadFromDictionary( dictionary );
-
-	/* Error check for input parameters in the dictionary */
-	if( dictionary->count == 0 ) {
-		printf("********************************************\n"
-		       "Error in function %s\n"
-		       "%d input parameters have been defined.\n"
-		       "check what you are passing to the executable\n"
-		       "********************************************\n",
-			 __func__, dictionary->count );
-		abort();
-	}
-
-	stgImportToolbox( dictionary, "Underworld" );
-	 
-	stgMainLoop( dictionary, CommWorld );
-	
-	Stg_Class_Delete( dictionary );
-	
-	/* Close off everything */
-	#ifdef HAVE_PYTHON
-		Py_Finalize();
-	#endif
-	StGermain_Finalise();
-	Journal_RPrintf( stream, "Finalised: StGermain Framework.\n");
-	MPI_Finalize();
-	
-	return 0; /* success */
-}
-
-
diff -r 038180046f6f -r 4b2d36e5021d src/main.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main.cxx	Thu May 12 11:19:19 2011 -0700
@@ -0,0 +1,114 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** 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:
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Mirko Velic
+*+		Patrick Sunter
+*+		Julian Giordani
+*+
+** $Id: main.c 701 2008-04-07 02:12:42Z JulianGiordani $
+** 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#ifdef HAVE_PYTHON
+	#include <Python.h>
+#endif
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+const Type Underworld_Type = "Underworld";
+
+int main( int argc, char* argv[] ) {
+	/* StGermain standard bits & pieces */
+	MPI_Comm			CommWorld;
+	int				rank;
+	int				numProcessors;
+	Dictionary*			dictionary;
+	XML_IO_Handler*			ioHandler;
+	Stream*                         stream;
+
+	/* Initialise PETSc, get world info */
+	MPI_Init( &argc, &argv );
+	MPI_Comm_dup( MPI_COMM_WORLD, &CommWorld );
+	MPI_Comm_size( CommWorld, &numProcessors );
+	MPI_Comm_rank( CommWorld, &rank );
+	StGermain_Init( &argc, &argv );
+	stream = Journal_Register( DebugStream_Type, (Name)Underworld_Type );
+	#ifdef HAVE_PYTHON
+		Py_Initialize();
+	#endif	
+	MPI_Barrier( CommWorld ); /* Ensures copyright info always come first in output */
+	
+	/* Create the application's dictionary & read input */
+	dictionary = Dictionary_New();
+	ioHandler = XML_IO_Handler_New( );
+	IO_Handler_ReadAllFromCommandLine( ioHandler, argc, argv, dictionary );
+	Journal_ReadFromDictionary( dictionary );
+
+	/* Error check for input parameters in the dictionary */
+	if( dictionary->count == 0 ) {
+		printf("********************************************\n"
+		       "Error in function %s\n"
+		       "%d input parameters have been defined.\n"
+		       "check what you are passing to the executable\n"
+		       "********************************************\n",
+			 __func__, dictionary->count );
+		abort();
+	}
+
+	stgImportToolbox( dictionary, "Underworld" );
+	 
+	stgMainLoop( dictionary, CommWorld );
+	
+	Stg_Class_Delete( dictionary );
+	
+	/* Close off everything */
+	#ifdef HAVE_PYTHON
+		Py_Finalize();
+	#endif
+	StGermain_Finalise();
+	Journal_RPrintf( stream, "Finalised: StGermain Framework.\n");
+	MPI_Finalize();
+	
+	return 0; /* success */
+}
+
+



More information about the CIG-COMMITS mailing list