[cig-commits] r3944 - in long/3D/Gale/trunk/src/StGermain: . Discretisation/Utils/src Discretisation/Utils/tests

walter at geodynamics.org walter at geodynamics.org
Thu Jul 6 02:06:27 PDT 2006


Author: walter
Date: 2006-07-06 02:06:27 -0700 (Thu, 06 Jul 2006)
New Revision: 3944

Modified:
   long/3D/Gale/trunk/src/StGermain/
   long/3D/Gale/trunk/src/StGermain/Discretisation/Utils/src/ShapeAdvector.c
   long/3D/Gale/trunk/src/StGermain/Discretisation/Utils/src/ShapeAdvector.h
   long/3D/Gale/trunk/src/StGermain/Discretisation/Utils/src/TimeIntegratee.c
   long/3D/Gale/trunk/src/StGermain/Discretisation/Utils/src/TimeIntegratee.h
   long/3D/Gale/trunk/src/StGermain/Discretisation/Utils/tests/testTimeIntegration.c
Log:
 r2472 at earth:  boo | 2006-07-06 02:02:42 -0700
  r2461 at earth (orig r3665):  PatrickSunter | 2006-07-03 21:56:29 -0700
  Updates to the TimeIntegrator/TimeIntegratee system to allow
  2nd order advection of particles for extension & outflow problems:
  
  Changed the TimeIntegratee's virtual function TimeIntegratee_CalculateTimeDeriv()
  so it must now return a Bool stating whether it was successfully able to calculate
  the time derivative of a particular item (eg particle or node) at the
  given point in time/space. 
  
  If it fails in the first step, then the TimeIntegratee's integration
  functions such as TimeIntegratee_SecondOrder() will print an error then exit.
  However if it fails in a second or later step, then added an option to the
  component such that you can allow it to "fallback" to first order. This
  option is enabled using option "allowFallbackToFirstOrder" in the component's
  XML description.
  
  This means that if this option is enabled for Swarm particle advectors, we
  can use 2nd order advection for extension problems, and only the particles
  on the very edges which temporarily go outside the box until remeshing is
  done will fallback to use first order - which should be fine as the velocities
  at the edge are almost linear anyway due to the BCs.
  
  TODO: intend to add more journalling so you can eg see a report of how many
  particles had to fallback to first order etc...
  
  
 



Property changes on: long/3D/Gale/trunk/src/StGermain
___________________________________________________________________
Name: svk:merge
   - 1ef209d2-b310-0410-a72d-e20c9eb0015c:/cig:2471
afb6c753-b9d0-0310-b4e7-dbd8d91cdd35:/trunk/StGermain:3664
   + 1ef209d2-b310-0410-a72d-e20c9eb0015c:/cig:2472
afb6c753-b9d0-0310-b4e7-dbd8d91cdd35:/trunk/StGermain:3665

Modified: long/3D/Gale/trunk/src/StGermain/Discretisation/Utils/src/ShapeAdvector.c
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Discretisation/Utils/src/ShapeAdvector.c	2006-07-06 09:06:20 UTC (rev 3943)
+++ long/3D/Gale/trunk/src/StGermain/Discretisation/Utils/src/ShapeAdvector.c	2006-07-06 09:06:27 UTC (rev 3944)
@@ -56,12 +56,13 @@
 		Name                                       name,
 		TimeIntegrator*                            timeIntegrator,
 		FieldVariable*                             velocityField,
-		Stg_Shape*                                 shape )
+		Stg_Shape*                                 shape,
+		Bool                                       allowFallbackToFirstOrder )
 {
 	ShapeAdvector* self = (ShapeAdvector*) _ShapeAdvector_DefaultNew( name );
 
 	/* 	ShapeAdvector_InitAll */
-	_ShapeAdvector_Init( self, timeIntegrator, velocityField, shape );
+	_ShapeAdvector_Init( self, timeIntegrator, velocityField, shape, allowFallbackToFirstOrder );
 
 	return self;
 }
@@ -110,7 +111,8 @@
 		ShapeAdvector*                             self,
 		TimeIntegrator*                            timeIntegrator,
 		FieldVariable*                             velocityField,
-		Stg_Shape*                                 shape )
+		Stg_Shape*                                 shape,
+		Bool                                       allowFallbackToFirstOrder )
 {
 	self->velocityField = velocityField;
 	self->shape = shape;
@@ -120,7 +122,8 @@
 	self->shapeCentreVariable = 
 		Variable_NewVector( "shapeCentreVariable", Variable_DataType_Double, shape->dim, &self->shapeCount, &self->shapeCentrePtr, NULL );
 	self->timeIntegratee = 
-		TimeIntegratee_New( "shapeTimeIntegratee", timeIntegrator, self->shapeCentreVariable, 1, (Stg_Component**) &velocityField );
+		TimeIntegratee_New( "shapeTimeIntegratee", timeIntegrator, self->shapeCentreVariable, 1,
+		(Stg_Component**) &velocityField, allowFallbackToFirstOrder );
 }
 
 
@@ -181,12 +184,14 @@
 	FieldVariable*              velocityField;
 	Stg_Shape*                  shape;
 	TimeIntegrator*             timeIntegrator;
+	Bool                        allowFallbackToFirstOrder = False;
 
 	timeIntegrator = Stg_ComponentFactory_ConstructByKey( cf, self->name, "TimeIntegrator", TimeIntegrator, True  ) ;
 	velocityField  = Stg_ComponentFactory_ConstructByKey( cf, self->name, "VelocityField", FieldVariable, True  ) ;
 	shape          = Stg_ComponentFactory_ConstructByKey( cf, self->name, "Shape", Stg_Shape, True ) ;
+	allowFallbackToFirstOrder = Stg_ComponentFactory_GetBool( cf, self->name, "allowFallbackToFirstOrder", False );
 
-	_ShapeAdvector_Init( self, timeIntegrator, velocityField, shape );
+	_ShapeAdvector_Init( self, timeIntegrator, velocityField, shape, allowFallbackToFirstOrder );
 }
 
 void _ShapeAdvector_Build( void* shapeAdvector, void* data ) {

Modified: long/3D/Gale/trunk/src/StGermain/Discretisation/Utils/src/ShapeAdvector.h
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Discretisation/Utils/src/ShapeAdvector.h	2006-07-06 09:06:20 UTC (rev 3943)
+++ long/3D/Gale/trunk/src/StGermain/Discretisation/Utils/src/ShapeAdvector.h	2006-07-06 09:06:27 UTC (rev 3944)
@@ -64,7 +64,8 @@
 		Name                                       name,
 		TimeIntegrator*                            timeIntegrator,
 		FieldVariable*                             velocityField,
-		Stg_Shape*                                 shape );
+		Stg_Shape*                                 shape,
+		Bool                                       allowFallbackToFirstOrder );
 
 	ShapeAdvector* _ShapeAdvector_New(
 		SizeT                                      _sizeOfSelf, 
@@ -84,7 +85,8 @@
 		ShapeAdvector*                             self,
 		TimeIntegrator*                            timeIntegrator,
 		FieldVariable*                             velocityField,
-		Stg_Shape*                                 shape );
+		Stg_Shape*                                 shape,
+		Bool                                       allowFallbackToFirstOrder );
 
 	void _ShapeAdvector_Delete( void* materialPoints );
 	void _ShapeAdvector_Print( void* materialPoints, Stream* stream );

Modified: long/3D/Gale/trunk/src/StGermain/Discretisation/Utils/src/TimeIntegratee.c
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Discretisation/Utils/src/TimeIntegratee.c	2006-07-06 09:06:20 UTC (rev 3943)
+++ long/3D/Gale/trunk/src/StGermain/Discretisation/Utils/src/TimeIntegratee.c	2006-07-06 09:06:27 UTC (rev 3944)
@@ -52,12 +52,13 @@
 		TimeIntegrator*                            timeIntegrator, 
 		Variable*                                  variable,
 		Index                                      dataCount, 
-		Stg_Component**                                data )
+		Stg_Component**                            data,
+		Bool                                       allowFallbackToFirstOrder )
 {
 	TimeIntegratee*	self;
 
 	self = (TimeIntegratee*) _TimeIntegratee_DefaultNew( name );
-	_TimeIntegratee_Init( self, timeIntegrator, variable, dataCount, data );
+	_TimeIntegratee_Init( self, timeIntegrator, variable, dataCount, data, allowFallbackToFirstOrder );
 	return self;
 }
 
@@ -75,7 +76,7 @@
 		Stg_Component_DestroyFunction*             _destroy,
 		TimeIntegratee_CalculateTimeDerivFunction* _calculateTimeDeriv,
 		TimeIntegratee_IntermediateFunction*       _intermediate,
-		Name 							           name )
+		Name                                       name )
 {
 	TimeIntegratee*	self;
 	
@@ -109,7 +110,8 @@
 		TimeIntegrator*                            timeIntegrator, 
 		Variable*                                  variable, 
 		Index                                      dataCount, 
-		Stg_Component**                                data )
+		Stg_Component**                            data,
+		Bool                                       allowFallbackToFirstOrder )
 {
 	TimeIntegratee* self = (TimeIntegratee*)timeIntegratee;
 	
@@ -118,6 +120,7 @@
 	self->dataCount      = dataCount;
 	self->timeIntegrator = timeIntegrator;
 	self->data           = Memory_Alloc_Array( Stg_Component*, dataCount, "data" );
+	self->allowFallbackToFirstOrder = allowFallbackToFirstOrder;
 	memcpy( self->data, data, dataCount * sizeof(Stg_Component*) );
 
 	TimeIntegrator_Add( timeIntegrator, self );
@@ -186,13 +189,15 @@
 	Stg_Component**         data                    = NULL;
 	Variable*               variable                = NULL;
 	TimeIntegrator*         timeIntegrator          = NULL;
+	Bool                    allowFallbackToFirstOrder = False;
 	
 	variable       =  Stg_ComponentFactory_ConstructByKey( cf, self->name, Variable_Type,       Variable,       False ) ;
 	timeIntegrator =  Stg_ComponentFactory_ConstructByKey( cf, self->name, TimeIntegrator_Type, TimeIntegrator, True ) ;
 	data = Stg_ComponentFactory_ConstructByList( 
 			cf, self->name, "data", Stg_ComponentFactory_Unlimited, Stg_Component, False, &dataCount );
+	allowFallbackToFirstOrder = Stg_ComponentFactory_GetBool( cf, self->name, "allowFallbackToFirstOrder", False );	
 
-	_TimeIntegratee_Init( self, timeIntegrator, variable, dataCount, data );
+	_TimeIntegratee_Init( self, timeIntegrator, variable, dataCount, data, allowFallbackToFirstOrder );
 
 	if (data != NULL)
 		Memory_Free(data);
@@ -233,6 +238,8 @@
 	Index           componentCount = *variable->dataTypeCounts;
 	Index           array_I; 
 	Index           arrayCount;
+	Bool            successFlag = False;
+	Stream*         errorStream = Journal_Register( Error_Type, self->type );
 
 	Journal_DPrintf( self->debug, "In func %s for %s '%s'\n", __func__, self->type, self->name );
 
@@ -245,10 +252,15 @@
 	arrayCount     = variable->arraySize;
 	
 	for ( array_I = 0 ; array_I < arrayCount ; array_I++ ) {
-		TimeIntegratee_CalculateTimeDeriv( self, array_I, timeDeriv );
 		arrayDataPtr = Variable_GetPtrDouble( variable, array_I );
 		startDataPtr = Variable_GetPtrDouble( startValue, array_I );
 		
+		successFlag = TimeIntegratee_CalculateTimeDeriv( self, array_I, timeDeriv );
+		Journal_Firewall( True == successFlag, errorStream,
+			"Error - in %s(), for TimeIntegratee \"%s\" of type %s: When trying to find time "
+			"deriv for item %u in step %u, *failed*.\n",
+			__func__, self->name, self->type, array_I, 1 );
+
 		for ( component_I = 0 ; component_I < componentCount ; component_I++ ) {
 			arrayDataPtr[ component_I ] = startDataPtr[ component_I ] + dt * timeDeriv[ component_I ];
 		}
@@ -271,6 +283,8 @@
 	Index           array_I; 
 	Index           arrayCount;
 	double          startTime      = TimeIntegrator_GetTime( self->timeIntegrator );
+	Bool            successFlag = False;
+	Stream*         errorStream = Journal_Register( Error_Type, self->type );
 
 	timeDeriv = Memory_Alloc_Array( double, componentCount, "Time Deriv" );
 	startData = Memory_Alloc_Array( double, componentCount, "StartData" );
@@ -292,7 +306,12 @@
 		memcpy( startData, startDataPtr, sizeof( double ) * componentCount );
 
 		/* Do Predictor Step */
-		TimeIntegratee_CalculateTimeDeriv( self, array_I, timeDeriv );
+		successFlag = TimeIntegratee_CalculateTimeDeriv( self, array_I, timeDeriv );
+		Journal_Firewall( True == successFlag, errorStream,
+			"Error - in %s(), for TimeIntegratee \"%s\" of type %s: When trying to find time "
+			"deriv for item %u in step %u, *failed*.\n",
+			__func__, self->name, self->type, array_I, 1 );
+		
 		for ( component_I = 0 ; component_I < componentCount ; component_I++ ) 
 			arrayDataPtr[ component_I ] = startData[ component_I ] + 0.5 * dt * timeDeriv[ component_I ];
 		TimeIntegratee_Intermediate( self, array_I );
@@ -300,10 +319,24 @@
 		TimeIntegrator_SetTime( self->timeIntegrator, startTime + 0.5 * dt );
 
 		/* Do Corrector Step */
-		TimeIntegratee_CalculateTimeDeriv( self, array_I, timeDeriv );
-		for ( component_I = 0 ; component_I < componentCount ; component_I++ ) 
-			arrayDataPtr[ component_I ] = startData[ component_I ] + dt * timeDeriv[ component_I ];
-		TimeIntegratee_Intermediate( self, array_I );
+		successFlag = TimeIntegratee_CalculateTimeDeriv( self, array_I, timeDeriv );
+
+		if ( True == successFlag ) {
+			for ( component_I = 0 ; component_I < componentCount ; component_I++ ) 
+				arrayDataPtr[ component_I ] = startData[ component_I ] + dt * timeDeriv[ component_I ];
+			
+			TimeIntegratee_Intermediate( self, array_I );
+		}
+		else {
+			Journal_Firewall( True == self->allowFallbackToFirstOrder, errorStream,
+				"Error - in %s(), for TimeIntegratee \"%s\" of type %s: When trying to find time "
+				"deriv for item %u in step %u, *failed*, and self->allowFallbackToFirstOrder "
+				"not enabled.\n", __func__, self->name, self->type, array_I, 2 );
+				
+			_TimeIntegratee_RewindToStartAndApplyFirstOrderUpdate( self,
+				arrayDataPtr, startData, startTime, dt,
+				timeDeriv, array_I );
+		}
 	}
 
 	Memory_Free( timeDeriv );
@@ -323,6 +356,8 @@
 	Index           array_I; 
 	Index           arrayCount;
 	double          startTime      = TimeIntegrator_GetTime( self->timeIntegrator );
+	Bool            successFlag = False;
+	Stream*         errorStream = Journal_Register( Error_Type, self->type );
 
 	timeDeriv      = Memory_Alloc_Array( double, componentCount, "Time Deriv" );
 	startData      = Memory_Alloc_Array( double, componentCount, "StartData" );
@@ -346,7 +381,12 @@
 		memcpy( startData, startDataPtr, sizeof( double ) * componentCount );
 
 		/* Do first Step - store K1 in finalTimeDeriv and update for next step */
-		TimeIntegratee_CalculateTimeDeriv( self, array_I, finalTimeDeriv );
+		successFlag = TimeIntegratee_CalculateTimeDeriv( self, array_I, finalTimeDeriv );
+		Journal_Firewall( True == successFlag, errorStream,
+			"Error - in %s(), for TimeIntegratee \"%s\" of type %s: When trying to find time "
+			"deriv for item %u in step %u, *failed*.\n",
+			__func__, self->name, self->type, array_I, 1 );
+
 		for ( component_I = 0 ; component_I < componentCount ; component_I++ ) 
 			arrayDataPtr[ component_I ] = startData[ component_I ] + 0.5 * dt * finalTimeDeriv[ component_I ];
 		TimeIntegratee_Intermediate( self, array_I );
@@ -354,30 +394,66 @@
 		TimeIntegrator_SetTime( self->timeIntegrator, startTime + 0.5 * dt );
 
 		/* Do Second Step - add 2xK2 value to finalTimeDeriv and update for next step */
-		TimeIntegratee_CalculateTimeDeriv( self, array_I, timeDeriv );
-		for ( component_I = 0 ; component_I < componentCount ; component_I++ ) {
-			arrayDataPtr[ component_I ] = startData[ component_I ] + 0.5 * dt * timeDeriv[ component_I ];
-			finalTimeDeriv[ component_I ] += 2.0 * timeDeriv[ component_I ];
+		successFlag = TimeIntegratee_CalculateTimeDeriv( self, array_I, timeDeriv );
+		if ( True == successFlag ) {
+			for ( component_I = 0 ; component_I < componentCount ; component_I++ ) {
+				arrayDataPtr[ component_I ] = startData[ component_I ] + 0.5 * dt * timeDeriv[ component_I ];
+				finalTimeDeriv[ component_I ] += 2.0 * timeDeriv[ component_I ];
+			}
+			TimeIntegratee_Intermediate( self, array_I );
 		}
-		TimeIntegratee_Intermediate( self, array_I );
+		else {
+			Journal_Firewall( True == self->allowFallbackToFirstOrder, errorStream,
+				"Error - in %s(), for TimeIntegratee \"%s\" of type %s: When trying to find time "
+				"deriv for item %u in step %u, *failed*, and self->allowFallbackToFirstOrder "
+				"not enabled.\n", __func__, self->name, self->type, array_I, 2 );
+				
+			_TimeIntegratee_RewindToStartAndApplyFirstOrderUpdate( self,
+				arrayDataPtr, startData, startTime, dt,
+				timeDeriv, array_I );
+		}
 
 		/* Do Third Step - add 2xK3 value to finalTimeDeriv and update for next step */
-		TimeIntegratee_CalculateTimeDeriv( self, array_I, timeDeriv );
-		for ( component_I = 0 ; component_I < componentCount ; component_I++ ) {
-			arrayDataPtr[ component_I ] = startData[ component_I ] + dt * timeDeriv[ component_I ];
-			finalTimeDeriv[ component_I ] += 2.0 * timeDeriv[ component_I ];
+		successFlag = TimeIntegratee_CalculateTimeDeriv( self, array_I, timeDeriv );
+		if ( True == successFlag ) {
+			for ( component_I = 0 ; component_I < componentCount ; component_I++ ) {
+				arrayDataPtr[ component_I ] = startData[ component_I ] + dt * timeDeriv[ component_I ];
+				finalTimeDeriv[ component_I ] += 2.0 * timeDeriv[ component_I ];
+			}
+			TimeIntegratee_Intermediate( self, array_I );
 		}
-		TimeIntegratee_Intermediate( self, array_I );
+		else {
+			Journal_Firewall( True == self->allowFallbackToFirstOrder, errorStream,
+				"Error - in %s(), for TimeIntegratee \"%s\" of type %s: When trying to find time "
+				"deriv for item %u in step %u, *failed*, and self->allowFallbackToFirstOrder "
+				"not enabled.\n", __func__, self->name, self->type, array_I, 3 );
+				
+			_TimeIntegratee_RewindToStartAndApplyFirstOrderUpdate( self,
+				arrayDataPtr, startData, startTime, dt,
+				timeDeriv, array_I );
+		}
 
 		TimeIntegrator_SetTime( self->timeIntegrator, startTime + dt );
 
 		/* Do Fourth Step - 'K1 + 2K2 + 2K3' and K4 finalTimeDeriv to find final value */
-		TimeIntegratee_CalculateTimeDeriv( self, array_I, timeDeriv );
-		for ( component_I = 0 ; component_I < componentCount ; component_I++ ) {
-			arrayDataPtr[ component_I ] = startData[ component_I ] + 
-				dt/6.0 * (timeDeriv[ component_I ] + finalTimeDeriv[ component_I ] );
-		}		
-		TimeIntegratee_Intermediate( self, array_I );
+		successFlag = TimeIntegratee_CalculateTimeDeriv( self, array_I, timeDeriv );
+		if ( True == successFlag ) {
+			for ( component_I = 0 ; component_I < componentCount ; component_I++ ) {
+				arrayDataPtr[ component_I ] = startData[ component_I ] + 
+					dt/6.0 * (timeDeriv[ component_I ] + finalTimeDeriv[ component_I ] );
+			}		
+			TimeIntegratee_Intermediate( self, array_I );
+		}
+		else {
+			Journal_Firewall( True == self->allowFallbackToFirstOrder, errorStream,
+				"Error - in %s(), for TimeIntegratee \"%s\" of type %s: When trying to find time "
+				"deriv for item %u in step %u, *failed*, and self->allowFallbackToFirstOrder "
+				"not enabled.\n", __func__, self->name, self->type, array_I, 4 );
+				
+			_TimeIntegratee_RewindToStartAndApplyFirstOrderUpdate( self,
+				arrayDataPtr, startData, startTime, dt,
+				timeDeriv, array_I );
+		}
 	}
 
 	Memory_Free( timeDeriv );
@@ -386,6 +462,37 @@
 }
 
 
+/* Note : this function is used to apply to just one item/particle - see the array_I parameter */
+void _TimeIntegratee_RewindToStartAndApplyFirstOrderUpdate( 
+		TimeIntegratee* self,
+		double*         arrayDataPtr,
+		double*         startData,
+		double          startTime,
+		double          dt,
+		double*         timeDeriv,
+		Index           array_I )
+{
+	Variable*       variable       = self->variable;
+	Index           component_I; 
+	Index           componentCount = *variable->dataTypeCounts;
+	Bool            successFlag = False;
+
+	/* First, go back to initial positions, so we can re-calculate the time derivative there */
+	for ( component_I = 0 ; component_I < componentCount ; component_I++ ) {
+		arrayDataPtr[ component_I ] = startData[ component_I ];
+	}	
+	TimeIntegratee_Intermediate( self, array_I );
+
+	/* Now recalculate time deriv at start positions, then do a full dt first order update from
+	 * there */
+	TimeIntegrator_SetTime( self->timeIntegrator, startTime );
+	successFlag = TimeIntegratee_CalculateTimeDeriv( self, array_I, timeDeriv );
+	for ( component_I = 0 ; component_I < componentCount ; component_I++ ) 
+		arrayDataPtr[ component_I ] = startData[ component_I ] + dt * timeDeriv[ component_I ];
+	TimeIntegratee_Intermediate( self, array_I );
+}
+
+
 /** +++ Sample Time Deriv Functions +++ **/
 
 
@@ -393,17 +500,35 @@
  *            the ODE that we are solving is \dot \phi = u(x,y) 
  *            the velocity Field Variable is stored in data[0]
  *            the variable being updated is the global coordinate of the object */
-void _TimeIntegratee_AdvectionTimeDeriv( void* timeIntegratee, Index array_I, double* timeDeriv ) {
-	TimeIntegratee*	self          = (TimeIntegratee*) timeIntegratee;
-	FieldVariable*  velocityField = (FieldVariable*)  self->data[0];
-	double*         coord;
+Bool _TimeIntegratee_AdvectionTimeDeriv( void* timeIntegratee, Index array_I, double* timeDeriv ) {
+	TimeIntegratee*	     self          = (TimeIntegratee*) timeIntegratee;
+	FieldVariable*       velocityField = (FieldVariable*)  self->data[0];
+	double*              coord;
+	InterpolationResult  result;
 
 	/* Get Coordinate of Object using Variable */
 	coord = Variable_GetPtrDouble( self->variable, array_I );
 
-	FieldVariable_InterpolateValueAt( velocityField, coord, timeDeriv );
+	result = FieldVariable_InterpolateValueAt( velocityField, coord, timeDeriv );
+
+	if ( result == OTHER_PROC || result == OUTSIDE_GLOBAL || isinf(timeDeriv[0]) || isinf(timeDeriv[1]) || 
+			( velocityField->dim == 3 && isinf(timeDeriv[2]) ) ) 
+	{
+		#if 0
+		Journal_Printf( Journal_Register( Error_Type, self->type ),
+			"Error in func '%s' for particle with index %u.\n\tPosition (%g, %g, %g)\n\tVelocity here is (%g, %g, %g)."
+			"\n\tInterpolation result is %s.\n",
+			__func__, array_I, coord[0], coord[1], coord[2], 
+			timeDeriv[0], timeDeriv[1], ( velocityField->dim == 3 ? timeDeriv[2] : 0.0 ),
+			InterpolationResultToStringMap[result]  );
+		return False;	
+		#endif
+	}
+
+	return True;
 }
 
+
 void _TimeIntegratee_Intermediate( void* timeIntegratee, Index array_I ) {}
 
 /* +++ Public Functions +++ */

Modified: long/3D/Gale/trunk/src/StGermain/Discretisation/Utils/src/TimeIntegratee.h
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Discretisation/Utils/src/TimeIntegratee.h	2006-07-06 09:06:20 UTC (rev 3943)
+++ long/3D/Gale/trunk/src/StGermain/Discretisation/Utils/src/TimeIntegratee.h	2006-07-06 09:06:27 UTC (rev 3944)
@@ -41,7 +41,7 @@
 #ifndef __Discretisation_Utils_TimeIntegratee_h__
 #define __Discretisation_Utils_TimeIntegratee_h__
 	
-	typedef void (TimeIntegratee_CalculateTimeDerivFunction) ( void* timeIntegrator, Index array_I, double* timeDeriv );
+	typedef Bool (TimeIntegratee_CalculateTimeDerivFunction) ( void* timeIntegrator, Index array_I, double* timeDeriv );
 	typedef void (TimeIntegratee_IntermediateFunction) ( void* timeIntegrator, Index array_I );
 
 	extern const Type TimeIntegratee_Type;
@@ -59,17 +59,19 @@
 		Variable*                                  variable;             \
 		Index                                      dataCount;            \
 		Stg_Component**                            data;                 \
+		Bool                                       allowFallbackToFirstOrder; \
 		Stream*                                    debug;                \
 		
 	struct TimeIntegratee { __TimeIntegratee };
 	
 	/* Creation implementation / Virtual constructor */
 	TimeIntegratee* TimeIntegratee_New( 
-			Name                                   name, 
-			TimeIntegrator*                        timeIntegrator, 
-			Variable*                              variable, 
-			Index                                  dataCount, 
-			Stg_Component**                        data );
+		Name                                   name, 
+		TimeIntegrator*                        timeIntegrator, 
+		Variable*                              variable, 
+		Index                                  dataCount, 
+		Stg_Component**                        data,
+		Bool                                   allowFallbackToFirstOrder );
 
 	TimeIntegratee* _TimeIntegratee_New( 
 		SizeT                                      _sizeOfSelf,
@@ -92,7 +94,8 @@
 		TimeIntegrator*                            timeIntegrator, 
 		Variable*                                  variable, 
 		Index                                      dataCount, 
-		Stg_Component**                                data );
+		Stg_Component**                            data,
+		Bool                                       allowFallbackToFirstOrder );
 		
 	/* 'Class' Virtual Functions */
 	void _TimeIntegratee_Delete( void* timeIntegrator );
@@ -118,8 +121,16 @@
 		( ((TimeIntegratee*) timeIntegratee )->_intermediate( timeIntegratee, array_I ) )
 
 	/* +++ Private Functions +++ */
-	void _TimeIntegratee_AdvectionTimeDeriv( void* timeIntegratee, Index array_I, double* timeDeriv ) ;
+	Bool _TimeIntegratee_AdvectionTimeDeriv( void* timeIntegratee, Index array_I, double* timeDeriv ) ;
 	void _TimeIntegratee_Intermediate( void* timeIntegratee, Index array_I );
+	void _TimeIntegratee_RewindToStartAndApplyFirstOrderUpdate( 
+		TimeIntegratee* self,
+		double*         arrayDataPtr,
+		double*         startData,
+		double          startTime,
+		double          dt,
+		double*         timeDeriv,
+		Index           array_I );
 
 	/* +++ Public Functions +++ */
 	void TimeIntegratee_FirstOrder( void* timeIntegrator, Variable* startValue, double dt );

Modified: long/3D/Gale/trunk/src/StGermain/Discretisation/Utils/tests/testTimeIntegration.c
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Discretisation/Utils/tests/testTimeIntegration.c	2006-07-06 09:06:20 UTC (rev 3943)
+++ long/3D/Gale/trunk/src/StGermain/Discretisation/Utils/tests/testTimeIntegration.c	2006-07-06 09:06:27 UTC (rev 3944)
@@ -52,37 +52,49 @@
 	return 0.1;
 }
 
-void ConstantTimeDeriv( void* timeIntegratee, Index array_I, double* timeDeriv ) {
+Bool ConstantTimeDeriv( void* timeIntegratee, Index array_I, double* timeDeriv ) {
 	timeDeriv[0] = 2.0 * array_I;
 	timeDeriv[1] = -1.0 * array_I;
+
+	return True;
 }
-void ConstantTimeDeriv2( void* timeIntegratee, Index array_I, double* timeDeriv ) {
+Bool ConstantTimeDeriv2( void* timeIntegratee, Index array_I, double* timeDeriv ) {
 	timeDeriv[0] = -0.5 * array_I;
 	timeDeriv[1] = 3.0 * array_I;
+	
+	return True;
 }
-void LinearTimeDeriv( void* timeIntegratee, Index array_I, double* timeDeriv ) {
+Bool LinearTimeDeriv( void* timeIntegratee, Index array_I, double* timeDeriv ) {
 	double time = TimeIntegratee_GetTime( timeIntegratee );
 
 	timeDeriv[0] = 2.0 * array_I * time;
 	timeDeriv[1] = -1.0 * array_I * time;
+	
+	return True;
 }
-void LinearTimeDeriv2( void* timeIntegratee, Index array_I, double* timeDeriv ) {
+Bool LinearTimeDeriv2( void* timeIntegratee, Index array_I, double* timeDeriv ) {
 	double time = TimeIntegratee_GetTime( timeIntegratee );
 
 	timeDeriv[0] = -0.5 * array_I * time;
 	timeDeriv[1] = 3.0 * array_I * time;
+	
+	return True;
 }
-void CubicTimeDeriv( void* timeIntegratee, Index array_I, double* timeDeriv ) {
+Bool CubicTimeDeriv( void* timeIntegratee, Index array_I, double* timeDeriv ) {
 	double time = TimeIntegratee_GetTime( timeIntegratee );
 
 	timeDeriv[0] = 2.0 * array_I * ( time * time * time - time*time );
 	timeDeriv[1] = -1.0 * array_I * ( time * time * time - time*time );
+	
+	return True;
 }
-void CubicTimeDeriv2( void* timeIntegratee, Index array_I, double* timeDeriv ) {
+Bool CubicTimeDeriv2( void* timeIntegratee, Index array_I, double* timeDeriv ) {
 	double time = TimeIntegratee_GetTime( timeIntegratee );
 
 	timeDeriv[0] = -0.5 * array_I * ( time * time * time - time*time );
 	timeDeriv[1] = 3.0 * array_I * ( time * time * time - time*time );
+	
+	return True;
 }
 
 TimeIntegratee_CalculateTimeDerivFunction* GetFunctionPtr( Name derivName ) {
@@ -202,8 +214,10 @@
 	variableList[0] = Variable_NewVector( "testVariable",  Variable_DataType_Double, 2, &size0, (void**)&array, NULL );
 	variableList[1] = Variable_NewVector( "testVariable2", Variable_DataType_Double, 2, &size1, (void**)&array2, NULL );
 	timeIntegrator  = TimeIntegrator_New( "testTimeIntegrator", order, simultaneous, NULL, NULL );
-	timeIntegrateeList[0] = TimeIntegratee_New( "testTimeIntegratee0", timeIntegrator, variableList[0], 0, NULL );
-	timeIntegrateeList[1] = TimeIntegratee_New( "testTimeIntegratee1", timeIntegrator, variableList[1], 0, NULL );
+	timeIntegrateeList[0] = TimeIntegratee_New( "testTimeIntegratee0", timeIntegrator, variableList[0],
+		0, NULL, True );
+	timeIntegrateeList[1] = TimeIntegratee_New( "testTimeIntegratee1", timeIntegrator, variableList[1],
+		0, NULL, True );
 
 	derivName = Dictionary_GetString( dictionary, "DerivName0" );
 	timeIntegrateeList[0]->_calculateTimeDeriv = GetFunctionPtr( derivName );



More information about the cig-commits mailing list