[cig-commits] r4876 - in long/3D/Gale/trunk/src/StGermain: . Discretisation/Mesh/src

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


Author: walter
Date: 2006-10-11 13:48:10 -0700 (Wed, 11 Oct 2006)
New Revision: 4876

Modified:
   long/3D/Gale/trunk/src/StGermain/
   long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/CartesianGenerator.c
   long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/CartesianGenerator.h
Log:
 r2933 at earth:  boo | 2006-10-11 13:42:47 -0700
  r2849 at earth (orig r3837):  LukeHodkinson | 2006-10-04 23:47:20 -0700
  Adding flexibility to the cartesian generator's 
  decomposition.
  
 



Property changes on: long/3D/Gale/trunk/src/StGermain
___________________________________________________________________
Name: svk:merge
   - 1ef209d2-b310-0410-a72d-e20c9eb0015c:/cig:2932
afb6c753-b9d0-0310-b4e7-dbd8d91cdd35:/trunk/StGermain:3836
   + 1ef209d2-b310-0410-a72d-e20c9eb0015c:/cig:2933
afb6c753-b9d0-0310-b4e7-dbd8d91cdd35:/trunk/StGermain:3837

Modified: long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/CartesianGenerator.c
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/CartesianGenerator.c	2006-10-11 20:48:08 UTC (rev 4875)
+++ long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/CartesianGenerator.c	2006-10-11 20:48:10 UTC (rev 4876)
@@ -95,6 +95,7 @@
 
 void _CartesianGenerator_Init( CartesianGenerator* self ) {
 	self->shadowDepth = 1;
+	self->maxDecompDims = 0;
 	self->minDecomp = NULL;
 	self->maxDecomp = NULL;
 	self->crdMin = NULL;
@@ -176,112 +177,107 @@
 	double*			crdMin;
 	double*			crdMax;
 	unsigned*		size;
-	HexaMD*			decomp;
 	unsigned		rank;
 	unsigned		d_i;
 
+	HexaMD*			decomp;
+
 	assert( self );
 	assert( cf );
 
 	/* Call parent construct. */
 	_MeshGenerator_Construct( self, cf );
 
-	/* Read the number of dimensions. */
-	dict = cf->rootDict;
-	nDims = Dictionary_GetDouble( dict, "dim" );
+	/* Check if we're using the antiquated version. */
+	decomp = Stg_ComponentFactory_ConstructByKey( cf, self->name, "decomp", HexaMD, False );
+	if( decomp ) {
+		/* Read the number of dimensions. */
+		dict = cf->rootDict;
+		nDims = Dictionary_GetDouble( dict, "dim" );
 
-	/* Allocate for values. */
-	self->minDecomp = Memory_Alloc_Array_Unnamed( unsigned, nDims );
-	self->maxDecomp = Memory_Alloc_Array_Unnamed( unsigned, nDims );
-	crdMin = Memory_Alloc_Array_Unnamed( double, nDims );
-	crdMax = Memory_Alloc_Array_Unnamed( double, nDims );
-	size = Memory_Alloc_Array_Unnamed( unsigned, nDims );
+		/* Allocate for values. */
+		crdMin = Memory_Alloc_Array_Unnamed( double, nDims );
+		crdMax = Memory_Alloc_Array_Unnamed( double, nDims );
+		size = Memory_Alloc_Array_Unnamed( unsigned, nDims );
 
-	/* Read size and coords. */
-	size[0] = Dictionary_GetUnsignedInt( dict, "elementResI" );
-	crdMin[0] = Dictionary_GetDouble( dict, "minX" );
-	crdMax[0] = Dictionary_GetDouble( dict, "maxX" );
-	if( nDims >= 2 ) {
-		size[1] = Dictionary_GetUnsignedInt( dict, "elementResJ" );
-		crdMin[1] = Dictionary_GetDouble( dict, "minY" );
-		crdMax[1] = Dictionary_GetDouble( dict, "maxY" );
+		/* Read size and coords. */
+		size[0] = Dictionary_GetUnsignedInt( dict, "elementResI" );
+		crdMin[0] = Dictionary_GetDouble( dict, "minX" );
+		crdMax[0] = Dictionary_GetDouble( dict, "maxX" );
+		if( nDims >= 2 ) {
+			size[1] = Dictionary_GetUnsignedInt( dict, "elementResJ" );
+			crdMin[1] = Dictionary_GetDouble( dict, "minY" );
+			crdMax[1] = Dictionary_GetDouble( dict, "maxY" );
 
-		if( nDims >= 3 ) {
-			size[2] = Dictionary_GetUnsignedInt( dict, "elementResK" );
-			crdMin[2] = Dictionary_GetDouble( dict, "minZ" );
-			crdMax[2] = Dictionary_GetDouble( dict, "maxZ" );
+			if( nDims >= 3 ) {
+				size[2] = Dictionary_GetUnsignedInt( dict, "elementResK" );
+				crdMin[2] = Dictionary_GetDouble( dict, "minZ" );
+				crdMax[2] = Dictionary_GetDouble( dict, "maxZ" );
+			}
 		}
-	}
 
-	/* Read shadow depth. */
-	self->shadowDepth = Dictionary_GetUnsignedInt( dict, "shadowDepth" );
+		/* Read shadow depth. */
+		self->shadowDepth = Dictionary_GetUnsignedInt( dict, "shadowDepth" );
 
-	/* Clear restrictions. */
-	memset( self->minDecomp, 0, nDims * sizeof(unsigned) );
-	memset( self->maxDecomp, 0, nDims * sizeof(unsigned) );
+		/* Setup. */
+		CartesianGenerator_SetTopologyParams( self, nDims, size, 0, NULL, NULL );
+		CartesianGenerator_SetGeometryParams( self, crdMin, crdMax );
 
-	/* Setup. */
-	CartesianGenerator_SetTopologyParams( self, nDims, size );
-	CartesianGenerator_SetGeometryParams( self, crdMin, crdMax );
+		/* Free stuff. */
+		FreeArray( size );
+		FreeArray( crdMin );
+		FreeArray( crdMax );
 
-	/* Free stuff. */
-	FreeArray( size );
-	FreeArray( crdMin );
-	FreeArray( crdMax );
-
-	/* Make sure we're the same decomp as old mesh. */
-	decomp = Stg_ComponentFactory_ConstructByKey( cf, self->name, "decomp", HexaMD, True );
-	Grid_SetSizes( self->procGrid, decomp->partition3DCounts );
-	MPI_Comm_rank( self->comm, (int*)&rank );
-	for( d_i = 0; d_i < nDims; d_i++ ) {
-		self->origin[d_i] = decomp->_elementOffsets[rank][d_i];
-		self->range[d_i] = decomp->elementLocal3DCounts[rank][d_i];
+		/* Make sure we're the same decomp as old mesh. */
+		Grid_SetSizes( self->procGrid, decomp->partition3DCounts );
+		MPI_Comm_rank( self->comm, (int*)&rank );
+		for( d_i = 0; d_i < nDims; d_i++ ) {
+			self->origin[d_i] = decomp->_elementOffsets[rank][d_i];
+			self->range[d_i] = decomp->elementLocal3DCounts[rank][d_i];
+		}
 	}
+	else {
+		/* Rip out the components structure as a dictionary. */
+		dict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( cf->componentDict, self->name ) );
 
-#if 0
-	/* NOTE: All this stuff is for the new mesh, still using old. */
+		/* Read the sizes. */
+		sizeList = Dictionary_Get( dict, "size" );
+		assert( sizeList );
+		nDims = Dictionary_Entry_Value_GetCount( sizeList );
+		assert( nDims );
+		size = Memory_Alloc_Array_Unnamed( unsigned, nDims );
+		for( d_i = 0; d_i < nDims; d_i++ )
+			size[d_i] = Dictionary_Entry_Value_AsUnsignedInt( Dictionary_Entry_Value_GetElement( sizeList, d_i ) );
 
-	/* Rip out the components structure as a dictionary. */
-	dict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( cf->componentDict, self->name ) );
+		/* Initial setup. */
+		CartesianGenerator_SetTopologyParams( self, nDims, size, 0, NULL, NULL );
 
-	/* Read the sizes. */
-	sizeList = Dictionary_Get( dict, "size" );
-	assert( sizeList );
-	nDims = Dictionary_Entry_Value_GetCount( sizeList );
-	assert( nDims );
-	size = Memory_Alloc_Array_Unnamed( unsigned, nDims );
-	for( d_i = 0; d_i < nDims; d_i++ )
-		size[d_i] = Dictionary_Entry_Value_AsUnsignedInt( Dictionary_Entry_Value_GetElement( sizeList, d_i ) );
+		/* Read geometry. */
+		minList = Dictionary_Get( dict, "coordMin" );
+		maxList = Dictionary_Get( dict, "coordMax" );
+		if( minList && maxList ) {
 
-	/* Initial setup. */
-	CartesianGenerator_SetTopologyParams( self, nDims, size );
 
-	/* Read geometry. */
-	minList = Dictionary_Get( dict, "coordMin" );
-	maxList = Dictionary_Get( dict, "coordMax" );
-	if( minList && maxList ) {
+			assert( Dictionary_Entry_Value_GetCount( sizeList ) == nDims );
+			assert( Dictionary_Entry_Value_GetCount( sizeList ) == nDims );
+			crdMin = Memory_Alloc_Array_Unnamed( double, nDims );
+			crdMax = Memory_Alloc_Array_Unnamed( double, nDims );
+			for( d_i = 0; d_i < nDims; d_i++ ) {
+				crdMin[d_i] = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetElement( minList, d_i ) );
+				crdMax[d_i] = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetElement( maxList, d_i ) );
+			}
 
+			/* Initial setup. */
+			CartesianGenerator_SetGeometryParams( self, crdMin, crdMax );
 
-		assert( Dictionary_Entry_Value_GetCount( sizeList ) == nDims );
-		assert( Dictionary_Entry_Value_GetCount( sizeList ) == nDims );
-		crdMin = Memory_Alloc_Array_Unnamed( double, nDims );
-		crdMax = Memory_Alloc_Array_Unnamed( double, nDims );
-		for( d_i = 0; d_i < nDims; d_i++ ) {
-			crdMin[d_i] = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetElement( minList, d_i ) );
-			crdMax[d_i] = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetElement( maxList, d_i ) );
+			/* Free coordinate arrays. */
+			FreeArray( crdMin );
+			FreeArray( crdMax );
 		}
 
-		/* Initial setup. */
-		CartesianGenerator_SetGeometryParams( self, crdMin, crdMax );
-
-		/* Free coordinate arrays. */
-		FreeArray( crdMin );
-		FreeArray( crdMax );
+		/* Free stuff. */
+		FreeArray( size );
 	}
-
-	/* Free stuff. */
-	FreeArray( size );
-#endif
 }
 
 void _CartesianGenerator_Build( void* generator, void* data ) {
@@ -301,7 +297,9 @@
 ** Public Functions
 */
 
-void CartesianGenerator_SetTopologyParams( void* generator, unsigned nDims, unsigned* sizes ) {
+void CartesianGenerator_SetTopologyParams( void* generator, unsigned nDims, unsigned* sizes, 
+					   unsigned maxDecompDims, unsigned* minDecomp, unsigned* maxDecomp )
+{
 	CartesianGenerator*	self = (CartesianGenerator*)generator;
 
 	/* Sanity check. */
@@ -320,6 +318,22 @@
 	Grid_SetNDims( self->topoGrid, nDims );
 	Grid_SetSizes( self->topoGrid, sizes );
 
+	/* Allocate and set restrictions. */
+	self->minDecomp = Memory_Alloc_Array( unsigned, nDims, "CartesianGenerator::minDecomp" );
+	self->maxDecomp = Memory_Alloc_Array( unsigned, nDims, "CartesianGenerator::maxDecomp" );
+
+	if( minDecomp )
+		memcpy( self->minDecomp, minDecomp, nDims * sizeof(unsigned) );
+	else
+		memset( self->minDecomp, 0, nDims * sizeof(unsigned) );
+
+	if( maxDecomp )
+		memcpy( self->maxDecomp, maxDecomp, nDims * sizeof(unsigned) );
+	else
+		memset( self->maxDecomp, 0, nDims * sizeof(unsigned) );
+
+	self->maxDecompDims = maxDecompDims;
+
 	/* As soon as we know the topology, we can decompose. */
 	CartesianGenerator_BuildDecomp( self );
 }
@@ -422,7 +436,15 @@
 	bestPos = -1;
 	for( p_i = 0; p_i < nPos; p_i++ ) {
 		double		curRatio = 0.0;
+		unsigned	decompDims = 0;
 
+		/* If decomposed in more dimensions than allowed, skip. */
+		for( d_i = 0; d_i < self->topoGrid->nDims; d_i++ )
+			decompDims += (posNSubDomains[p_i][d_i] > 1) ? 1 : 0;
+		if( self->maxDecompDims && decompDims > self->maxDecompDims )
+			continue;
+
+		/* Evaluate ratios. */
 		for( d_i = 0; d_i < self->topoGrid->nDims; d_i++ ) {
 			double		nI = (double)self->topoGrid->sizes[d_i] / (double)posNSubDomains[p_i][d_i];
 			unsigned	d_j;

Modified: long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/CartesianGenerator.h
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/CartesianGenerator.h	2006-10-11 20:48:08 UTC (rev 4875)
+++ long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/CartesianGenerator.h	2006-10-11 20:48:10 UTC (rev 4876)
@@ -54,6 +54,7 @@
 		/* Virtual info */		\
 						\
 		/* CartesianGenerator info */	\
+		unsigned	maxDecompDims;	\
 		unsigned*	minDecomp;	\
 		unsigned*	maxDecomp;	\
 		unsigned	shadowDepth;	\
@@ -106,7 +107,8 @@
 	** Public functions
 	*/
 
-	void CartesianGenerator_SetTopologyParams( void* generator, unsigned nDims, unsigned* sizes );
+	void CartesianGenerator_SetTopologyParams( void* generator, unsigned nDims, unsigned* sizes, 
+						   unsigned maxDecompDims, unsigned* minDecomp, unsigned* maxDecomp );
 	void CartesianGenerator_SetGeometryParams( void* generator, double* min, double* max );
 
 	/*--------------------------------------------------------------------------------------------------------------------------



More information about the cig-commits mailing list