[cig-commits] r4803 - in long/3D/Gale/trunk/src/PICellerator: . PopulationControl/src Voronoi/src

walter at geodynamics.org walter at geodynamics.org
Wed Oct 11 13:42:02 PDT 2006


Author: walter
Date: 2006-10-11 13:42:01 -0700 (Wed, 11 Oct 2006)
New Revision: 4803

Modified:
   long/3D/Gale/trunk/src/PICellerator/
   long/3D/Gale/trunk/src/PICellerator/PopulationControl/src/DiscreteVoronoiRemove.c
   long/3D/Gale/trunk/src/PICellerator/PopulationControl/src/DiscreteVoronoiSplitting.c
   long/3D/Gale/trunk/src/PICellerator/Voronoi/src/DiscreteVoronoi.c
   long/3D/Gale/trunk/src/PICellerator/Voronoi/src/DiscreteVoronoi.h
Log:
 r492 at earth:  boo | 2006-10-11 13:40:23 -0700
  r485 at earth (orig r372):  RobertTurnbull | 2006-10-06 00:13:48 -0700
  Fixing up a problem with the Discrete Voronoi code. 
  	Adding check to see if a coord is nan.
  	If a particle doesn't claim any discrete voronoi cells - it now uses it's own coordinate as its centroid
  	Getting the Discrete Voronoi Splitting to split the particles with the largest voronoi cell rather than the smallest. (!)
  
 



Property changes on: long/3D/Gale/trunk/src/PICellerator
___________________________________________________________________
Name: svk:merge
   - 00de75e2-39f1-0310-8538-9683d00a49cc:/trunk:371
aee11096-cf10-0410-a191-eea5772ba81f:/cig:491
   + 00de75e2-39f1-0310-8538-9683d00a49cc:/trunk:372
aee11096-cf10-0410-a191-eea5772ba81f:/cig:492

Modified: long/3D/Gale/trunk/src/PICellerator/PopulationControl/src/DiscreteVoronoiRemove.c
===================================================================
--- long/3D/Gale/trunk/src/PICellerator/PopulationControl/src/DiscreteVoronoiRemove.c	2006-10-11 20:41:59 UTC (rev 4802)
+++ long/3D/Gale/trunk/src/PICellerator/PopulationControl/src/DiscreteVoronoiRemove.c	2006-10-11 20:42:01 UTC (rev 4803)
@@ -171,7 +171,7 @@
 	Particle_InCellIndex         particlesToRemoveCount = cellParticleCount - self->idealParticleCount;
 
 	DiscreteVoronoi_CalculateForCell( self->discreteVoronoi, swarm, lCell_I );
-	voronoiParticleInfo = DiscreteVoronoi_CreateParticleInfo( self->discreteVoronoi, cellParticleCount );
+	voronoiParticleInfo = DiscreteVoronoi_CreateParticleInfo( self->discreteVoronoi, swarm, lCell_I );
 	DiscreteVoronoiParticleInfo_SortByVolume( voronoiParticleInfo, cellParticleCount );
 
 	/* Go through particles with smallest area and set them for removal */

Modified: long/3D/Gale/trunk/src/PICellerator/PopulationControl/src/DiscreteVoronoiSplitting.c
===================================================================
--- long/3D/Gale/trunk/src/PICellerator/PopulationControl/src/DiscreteVoronoiSplitting.c	2006-10-11 20:41:59 UTC (rev 4802)
+++ long/3D/Gale/trunk/src/PICellerator/PopulationControl/src/DiscreteVoronoiSplitting.c	2006-10-11 20:42:01 UTC (rev 4803)
@@ -173,17 +173,23 @@
 	Particle_InCellIndex         particlesToSplitCount = self->idealParticleCount - cellParticleCount;
 
 	DiscreteVoronoi_CalculateForCell( self->discreteVoronoi, swarm, lCell_I );
-	voronoiParticleInfo = DiscreteVoronoi_CreateParticleInfo( self->discreteVoronoi, cellParticleCount );
+	voronoiParticleInfo = DiscreteVoronoi_CreateParticleInfo( self->discreteVoronoi, swarm, lCell_I );
 	DiscreteVoronoiParticleInfo_SortByVolume( voronoiParticleInfo, cellParticleCount );
 
 	/* Make sure number of particles to split is no more than the particles in the box */
 	if ( particlesToSplitCount > cellParticleCount )
 		particlesToSplitCount = cellParticleCount;
-
+	
 	/* Go through particles with largest area split them by putting the new particle on centroid */
-	for ( cParticle_I = particlesToSplitCount - 1 ; cParticle_I != (Particle_InCellIndex) -1 ; cParticle_I-- ) {
+	for ( cParticle_I = cellParticleCount - particlesToSplitCount ; cParticle_I < cellParticleCount ; cParticle_I++ ) {
 		currParticleInfo = &voronoiParticleInfo[ cParticle_I ];
 		SplittingRoutine_SplitParticle( self, swarm, lCell_I, currParticleInfo->particle_I, currParticleInfo->centroid );
+
+		/* Make sure that centroid has a proper number */
+		assert( !( 
+					isnan ( currParticleInfo->centroid[0] ) || 
+					isnan ( currParticleInfo->centroid[1] ) || 
+					isnan ( currParticleInfo->centroid[2] ) ) );
 	}
 
 	DiscreteVoronoiParticleInfo_Delete( voronoiParticleInfo );

Modified: long/3D/Gale/trunk/src/PICellerator/Voronoi/src/DiscreteVoronoi.c
===================================================================
--- long/3D/Gale/trunk/src/PICellerator/Voronoi/src/DiscreteVoronoi.c	2006-10-11 20:41:59 UTC (rev 4802)
+++ long/3D/Gale/trunk/src/PICellerator/Voronoi/src/DiscreteVoronoi.c	2006-10-11 20:42:01 UTC (rev 4803)
@@ -182,16 +182,18 @@
 	self->_calculateForCell( self, _swarm, lCell_I );
 }
 
-DiscreteVoronoiParticleInfo* DiscreteVoronoi_CreateParticleInfo( void* discreteVoronoi, Particle_InCellIndex cellParticleCount ) {
+DiscreteVoronoiParticleInfo* DiscreteVoronoi_CreateParticleInfo( void* discreteVoronoi, void* _swarm, Cell_LocalIndex lCell_I ) {
 	DiscreteVoronoi*	         self          = (DiscreteVoronoi*) discreteVoronoi;
+	Swarm*                       swarm         = (Swarm*)                 _swarm;
 	DiscreteVoronoiParticleInfo* particleInfoArray;
 	DiscreteVoronoiParticleInfo* currParticleInfo;
+	Particle_InCellIndex         cellParticleCount = swarm->cellParticleCountTbl[lCell_I];
 	Particle_InCellIndex         cParticle_I;
 	Voronoi_CellIndex            vCell_I;
 	double                       volume;
 	Coord                        centroid;
 	Dimension_Index              dim           = self->dim;
-	
+
 	particleInfoArray = Memory_Alloc_Array( DiscreteVoronoiParticleInfo, cellParticleCount, "particle info" );
 	memset(particleInfoArray, 0, sizeof( DiscreteVoronoiParticleInfo ) * cellParticleCount );
 	
@@ -210,6 +212,8 @@
 		currParticleInfo->centroid[ J_AXIS ] += volume * centroid[ J_AXIS ];
 		if ( dim == 3 )
 			currParticleInfo->centroid[ K_AXIS ] += volume * centroid[ K_AXIS ];
+
+		currParticleInfo->voronoiCellCount++;
 	}
 
 	/* Set particle numbers and normalise centroids */
@@ -219,10 +223,19 @@
 		currParticleInfo->particle_I = cParticle_I;
 		volume = currParticleInfo->volume;
 		
-		currParticleInfo->centroid[ I_AXIS ] /= volume;
-		currParticleInfo->centroid[ J_AXIS ] /= volume;
-		if ( dim == 3 )
-			currParticleInfo->centroid[ K_AXIS ] += volume;
+		/* Sort out coordinate for centroid */
+		if ( currParticleInfo->voronoiCellCount > 0 ) {
+			currParticleInfo->centroid[ I_AXIS ] /= volume;
+			currParticleInfo->centroid[ J_AXIS ] /= volume;
+			if ( dim == 3 )
+				currParticleInfo->centroid[ K_AXIS ] /= volume;
+		}
+		else {
+			GlobalParticle* particle = (GlobalParticle*) Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
+			/* If this particle hasn't claimed any voronoi cells - 
+			 * then the centroid is co-incident with the particle */
+			memcpy( currParticleInfo->centroid, particle->coord, dim*sizeof(double) );
+		}
 	}
 
 	return particleInfoArray;
@@ -238,6 +251,7 @@
 		return 1;
 }
 	
+/* Sorts the particle info list in order of volume - from smallest volume to largest */
 void DiscreteVoronoiParticleInfo_SortByVolume( DiscreteVoronoiParticleInfo* particleInfo, Particle_InCellIndex cellParticleCount ) {
 	qsort(particleInfo, cellParticleCount, sizeof(DiscreteVoronoiParticleInfo), _DiscreteVoronoiParticleInfo_CompareVolume);
 }

Modified: long/3D/Gale/trunk/src/PICellerator/Voronoi/src/DiscreteVoronoi.h
===================================================================
--- long/3D/Gale/trunk/src/PICellerator/Voronoi/src/DiscreteVoronoi.h	2006-10-11 20:41:59 UTC (rev 4802)
+++ long/3D/Gale/trunk/src/PICellerator/Voronoi/src/DiscreteVoronoi.h	2006-10-11 20:42:01 UTC (rev 4803)
@@ -84,6 +84,7 @@
 		Coord                centroid;
 		double               volume;
 		Particle_InCellIndex particle_I;
+		Voronoi_CellIndex    voronoiCellCount;
 	};
 	
 	/*---------------------------------------------------------------------------------------------------------------------
@@ -138,8 +139,8 @@
 	#define DiscreteVoronoi_GetCentroid( discreteVoronoi, vCell_I, centroid ) \
 		( ( (DiscreteVoronoi*) discreteVoronoi )->_getCentroid( discreteVoronoi, vCell_I, centroid ) )
 
-	DiscreteVoronoiParticleInfo* DiscreteVoronoi_CreateParticleInfo( void* discreteVoronoi, Particle_InCellIndex cellParticleCount ) ;
 	
+	DiscreteVoronoiParticleInfo* DiscreteVoronoi_CreateParticleInfo( void* discreteVoronoi, void* _swarm, Cell_LocalIndex lCell_I ) ;
 	void DiscreteVoronoiParticleInfo_SortByVolume( DiscreteVoronoiParticleInfo* particleInfo, Particle_InCellIndex cellParticleCount ) ;
 	
 	#define DiscreteVoronoiParticleInfo_Delete( particleInfo ) \



More information about the cig-commits mailing list