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

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


Author: walter
Date: 2006-10-11 13:47:56 -0700 (Wed, 11 Oct 2006)
New Revision: 4870

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:
 r2927 at earth:  boo | 2006-10-11 13:42:45 -0700
  r2843 at earth (orig r3831):  LukeHodkinson | 2006-10-04 18:16:00 -0700
  * Added routines to generate mesh coordinates.
  * Added restriction parameters to allow for tuning
    of the decomposition through the XML.
  
 



Property changes on: long/3D/Gale/trunk/src/StGermain
___________________________________________________________________
Name: svk:merge
   - 1ef209d2-b310-0410-a72d-e20c9eb0015c:/cig:2926
afb6c753-b9d0-0310-b4e7-dbd8d91cdd35:/trunk/StGermain:3830
   + 1ef209d2-b310-0410-a72d-e20c9eb0015c:/cig:2927
afb6c753-b9d0-0310-b4e7-dbd8d91cdd35:/trunk/StGermain:3831

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:47:54 UTC (rev 4869)
+++ long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/CartesianGenerator.c	2006-10-11 20:47:56 UTC (rev 4870)
@@ -42,6 +42,7 @@
 #include "types.h"
 #include "shortcuts.h"
 #include "Grid.h"
+#include "CommTopology.h"
 #include "Decomp.h"
 #include "Decomp_Sync.h"
 #include "MeshTopology.h"
@@ -49,7 +50,10 @@
 #include "MeshGenerator.h"
 #include "CartesianGenerator.h"
 
+#include "MeshDecomp.h"
+#include "HexaMD.h"
 
+
 /* Textual name of this class */
 const Type CartesianGenerator_Type = "CartesianGenerator";
 
@@ -91,9 +95,12 @@
 
 void _CartesianGenerator_Init( CartesianGenerator* self ) {
 	self->shadowDepth = 1;
-	self->topoGrid = NULL;
+	self->minDecomp = NULL;
+	self->maxDecomp = NULL;
 	self->crdMin = NULL;
 	self->crdMax = NULL;
+
+	self->topoGrid = NULL;
 	self->procGrid = NULL;
 	self->origin = NULL;
 	self->range = NULL;
@@ -163,8 +170,14 @@
 	CartesianGenerator*	self = (CartesianGenerator*)generator;
 	Dictionary*		dict;
 	Dictionary_Entry_Value*	sizeList;
+	Dictionary_Entry_Value*	minList;
+	Dictionary_Entry_Value*	maxList;
 	unsigned		nDims;
+	double*			crdMin;
+	double*			crdMax;
 	unsigned*		size;
+	HexaMD*			decomp;
+	unsigned		rank;
 	unsigned		d_i;
 
 	assert( self );
@@ -173,6 +186,61 @@
 	/* Call parent construct. */
 	_MeshGenerator_Construct( self, cf );
 
+	/* 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 );
+
+	/* 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" );
+		}
+	}
+
+	/* 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 );
+	CartesianGenerator_SetGeometryParams( self, crdMin, 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];
+	}
+
+#if 0
+	/* NOTE: All this stuff is for the new mesh, still using old. */
+
 	/* Rip out the components structure as a dictionary. */
 	dict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( cf->componentDict, self->name ) );
 
@@ -188,8 +256,32 @@
 	/* 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 );
+
+		/* Free coordinate arrays. */
+		FreeArray( crdMin );
+		FreeArray( crdMax );
+	}
+
 	/* Free stuff. */
 	FreeArray( size );
+#endif
 }
 
 void _CartesianGenerator_Build( void* generator, void* data ) {
@@ -269,6 +361,9 @@
 		/* Fill topological values. */
 		MeshTopology_SetNDims( mesh->topo, self->topoGrid->nDims );
 		CartesianGenerator_GenTopo( self, mesh->topo );
+
+		/* Fill geometric values. */
+		CartesianGenerator_GenGeom( self, mesh );
 	}
 	else {
 		MeshTopology_SetNDims( mesh->topo, 0 );
@@ -422,9 +517,20 @@
 		/* Loop over all remaining */
 		for( p_i = 0; p_i < max; p_i++ ) {
 			/* Don't try and decompose more than this dimension allows. */
-			if( p_i >= self->topoGrid->sizes[dim] ) continue;
+			if( p_i >= self->topoGrid->sizes[dim] || 
+			    (self->maxDecomp[dim] && p_i >= self->maxDecomp[dim]) )
+			{
+				break;
+			}
 
+			/* If we have a minimum decomp, skip until we reach it. */
+			if( self->minDecomp[dim] && p_i < self->minDecomp[dim] - 1 )
+				continue;
+
+			/* Set the number of sub-domains. */
 			nSubDomains[dim] = p_i + 1;
+
+			/* Try this combination. */
 			CartesianGenerator_RecurseDecomps( self, dim + 1, max - nSDs + 1, nSubDomains, 
 							   nPos, posNSubDomains );
 		}
@@ -504,12 +610,13 @@
 	/* Generate topological elements. */
 	CartesianGenerator_GenElements( self, topo, grids );
 	CartesianGenerator_GenVertices( self, topo, grids );
-	if( self->topoGrid->nDims > 1 )
+	if( topo->nDims >= 2 ) {
 		CartesianGenerator_GenEdges( self, topo, grids );
-	if( self->topoGrid->nDims > 2 )
-		CartesianGenerator_GenFaces( self, topo, grids );
+		if( topo->nDims >= 3 )
+			CartesianGenerator_GenFaces( self, topo, grids );
+	}
 
-	/* Generate basic topological incidence. */
+	/* Generate topological incidence. */
 	CartesianGenerator_GenEdgeVertexInc( self, topo, grids );
 	if( topo->nDims >= 2 ) {
 		CartesianGenerator_GenFaceEdgeInc( self, topo, grids );
@@ -517,31 +624,45 @@
 			CartesianGenerator_GenVolumeFaceInc( self, topo, grids );
 	}
 
-	/* Build remaining default incidence relations. */
-	MeshTopology_Complete( topo );
-
 	/* Set the shadow depth and correct incidence. */
-	MeshTopology_SetShadowDepth( topo, self->shadowDepth );
-	for( d_i = 0; d_i < topo->nDims; d_i++ ) {
-		unsigned	d_j;
+	if( self->shadowDepth && topo->domains[MT_VERTEX]->commTopo->nProcs > 1 ) {
+		/* Build enough incidence to set shadow depth. */
+		CartesianGenerator_GenElementVertexInc( self, topo, grids );
+		if( topo->nDims >= 3 )
+			MeshTopology_Cascade( topo, MT_VOLUME, MT_EDGE );
+		MeshTopology_Invert( topo, MT_VERTEX, topo->nDims );
+		MeshTopology_Invert( topo, MT_VERTEX, MT_EDGE );
+		MeshTopology_Neighbourhood( topo, MT_VERTEX );
+		MeshTopology_Neighbourhood( topo, topo->nDims );
 
-		for( d_j = d_i; d_j < topo->nTDims; d_j++ ) {
-			KillArray( topo->nIncEls[d_i][d_j] );
-			KillArray( topo->incEls[d_i][d_j] );
+		MeshTopology_SetShadowDepth( topo, self->shadowDepth );
+
+		/* Kill up relations and neighbours. */
+		for( d_i = 0; d_i < topo->nDims; d_i++ ) {
+			unsigned	d_j;
+
+			for( d_j = d_i; d_j < topo->nTDims; d_j++ ) {
+				KillArray( topo->nIncEls[d_i][d_j] );
+				KillArray( topo->incEls[d_i][d_j] );
+			}
 		}
-	}
-	for( d_i = 2; d_i < topo->nTDims; d_i++ ) {
-		unsigned	d_j;
+		KillArray( topo->nIncEls[topo->nDims][topo->nDims] );
+		KillArray( topo->incEls[topo->nDims][topo->nDims] );
 
-		for( d_j = 0; d_j < d_i - 1; d_j++ ) {
-			KillArray( topo->nIncEls[d_i][d_j] );
-			KillArray( topo->incEls[d_i][d_j] );
+		/* Kill cascaded relations. */
+		for( d_i = 2; d_i < topo->nTDims; d_i++ ) {
+			unsigned	d_j;
+
+			for( d_j = 0; d_j < d_i - 1; d_j++ ) {
+				KillArray( topo->nIncEls[d_i][d_j] );
+				KillArray( topo->incEls[d_i][d_j] );
+			}
 		}
 	}
-	KillArray( topo->nIncEls[topo->nDims][topo->nDims] );
-	KillArray( topo->incEls[topo->nDims][topo->nDims] );
-	MeshTopology_Complete( topo );
 
+	/* Complete all relations. */
+	/*MeshTopology_Complete( topo );*/
+
 	/* Free allocated grids. */
 	grids[topo->nDims][0] = NULL;
 	for( d_i = 0; d_i < topo->nDims; d_i++ ) {
@@ -922,6 +1043,70 @@
 	FreeObject( globalGrid );
 }
 
+void CartesianGenerator_GenElementVertexInc( CartesianGenerator* self, MeshTopology* topo, Grid*** grids ) {
+	unsigned*	nIncEls;
+	unsigned**	incEls;
+	unsigned*	dimInds;
+	unsigned	vertsPerEl;
+	unsigned	e_i;
+
+	assert( self );
+	assert( topo );
+	assert( grids );
+
+	vertsPerEl = (topo->nDims == 1) ? 2 : (topo->nDims == 2) ? 4 : 8;
+
+	nIncEls = Memory_Alloc_Array_Unnamed( unsigned, topo->nDomainEls[topo->nDims] );
+	incEls = Memory_Alloc_2DArray_Unnamed( unsigned, topo->nDomainEls[topo->nDims], vertsPerEl );
+	dimInds = Memory_Alloc_Array_Unnamed( unsigned, topo->nDims );
+	for( e_i = 0; e_i < topo->nDomainEls[topo->nDims]; e_i++ ) {
+		unsigned	gInd = Decomp_Sync_DomainToGlobal( topo->domains[topo->nDims], e_i );
+
+		nIncEls[e_i] = vertsPerEl;
+		Grid_Lift( grids[topo->nDims][0], gInd, dimInds );
+
+		incEls[e_i][0] = Grid_Project( grids[0][0], dimInds );
+
+		dimInds[0]++;
+		incEls[e_i][1] = Grid_Project( grids[0][0], dimInds );
+		dimInds[0]--;
+
+		if( topo->nDims >= 2 ) {
+			dimInds[1]++;
+			incEls[e_i][2] = Grid_Project( grids[0][0], dimInds );
+
+			dimInds[0]++;
+			incEls[e_i][3] = Grid_Project( grids[0][0], dimInds );
+			dimInds[0]--;
+			dimInds[1]--;
+
+			if( topo->nDims >= 3 ) {
+				dimInds[2]++;
+				incEls[e_i][4] = Grid_Project( grids[0][0], dimInds );
+
+				dimInds[0]++;
+				incEls[e_i][5] = Grid_Project( grids[0][0], dimInds );
+				dimInds[0]--;
+
+				dimInds[1]++;
+				incEls[e_i][6] = Grid_Project( grids[0][0], dimInds );
+
+				dimInds[0]++;
+				incEls[e_i][7] = Grid_Project( grids[0][0], dimInds );
+				dimInds[0]--;
+				dimInds[1]--;
+				dimInds[2]--;
+			}
+		}
+	}
+
+	CartesianGenerator_MapToDomain( self, topo->domains[MT_VERTEX], topo->nDomainEls[topo->nDims], nIncEls, incEls );
+	MeshTopology_SetIncidence( topo, topo->nDims, MT_VERTEX, nIncEls, incEls );
+	FreeArray( nIncEls );
+	FreeArray( incEls );
+	FreeArray( dimInds );
+}
+
 void CartesianGenerator_GenVolumeFaceInc( CartesianGenerator* self, MeshTopology* topo, Grid*** grids ) {
 	unsigned*	nIncEls;
 	unsigned**	incEls;
@@ -1123,6 +1308,54 @@
 	}
 }
 
+void CartesianGenerator_GenGeom( CartesianGenerator* self, Mesh* mesh ) {
+	Grid*		grid;
+	unsigned*	inds;
+	double*		steps;
+	unsigned	n_i, d_i;
+
+	assert( self );
+	assert( mesh );
+
+	/* Build grid and space for indices. */
+	grid = Grid_New();
+	Grid_SetNDims( grid, mesh->topo->nDims );
+	for( d_i = 0; d_i < mesh->topo->nDims; d_i++ )
+		self->topoGrid->sizes[d_i]++;
+	Grid_SetSizes( grid, self->topoGrid->sizes );
+	for( d_i = 0; d_i < mesh->topo->nDims; d_i++ )
+		self->topoGrid->sizes[d_i]--;
+	inds = Memory_Alloc_Array_Unnamed( unsigned, mesh->topo->nDims );
+
+	/* Calculate steps. */
+	steps = Memory_Alloc_Array_Unnamed( double, mesh->topo->nDims );
+	for( d_i = 0; d_i < mesh->topo->nDims; d_i++ )
+		steps[d_i] = self->crdMax[d_i] - self->crdMin[d_i];
+
+	/* Allocate for coordinates. */
+	mesh->nodeCoord = Memory_Alloc_Array( Coord, MeshTopology_GetDomainSize( mesh->topo, MT_VERTEX ), 
+					      "Mesh::nodeCoord" );
+
+	/* Loop over domain nodes. */
+	for( n_i = 0; n_i < MeshTopology_GetDomainSize( mesh->topo, MT_VERTEX ); n_i++ ) {
+		unsigned	gNode;
+
+		gNode = MeshTopology_DomainToGlobal( mesh->topo, MT_VERTEX, n_i );
+		Grid_Lift( grid, gNode, inds );
+
+		/* Calculate coordinate. */
+		for( d_i = 0; d_i < mesh->topo->nDims; d_i++ ) {
+			mesh->nodeCoord[n_i][d_i] = self->crdMin[d_i] + 
+				((double)inds[d_i] / (double)self->topoGrid->sizes[d_i]) * steps[d_i];
+		}
+	}
+
+	/* Free resources. */
+	FreeArray( inds );
+	FreeArray( steps );
+	FreeObject( grid );
+}
+
 void CartesianGenerator_Destruct( CartesianGenerator* self ) {
 	assert( self );
 

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:47:54 UTC (rev 4869)
+++ long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/CartesianGenerator.h	2006-10-11 20:47:56 UTC (rev 4870)
@@ -54,10 +54,13 @@
 		/* Virtual info */		\
 						\
 		/* CartesianGenerator info */	\
+		unsigned*	minDecomp;	\
+		unsigned*	maxDecomp;	\
 		unsigned	shadowDepth;	\
-		Grid*		topoGrid;	\
 		double*		crdMin;		\
 		double*		crdMax;		\
+						\
+		Grid*		topoGrid;	\
 		Grid*		procGrid;	\
 		unsigned*	origin;		\
 		unsigned*	range;
@@ -122,11 +125,13 @@
 	void CartesianGenerator_GenEdges2D( CartesianGenerator* self, MeshTopology* topo, Grid*** grids );
 	void CartesianGenerator_GenEdges3D( CartesianGenerator* self, MeshTopology* topo, Grid*** grids );
 	void CartesianGenerator_GenFaces( CartesianGenerator* self, MeshTopology* topo, Grid*** grids );
+	void CartesianGenerator_GenElementVertexInc( CartesianGenerator* self, MeshTopology* topo, Grid*** grids );
 	void CartesianGenerator_GenVolumeFaceInc( CartesianGenerator* self, MeshTopology* topo, Grid*** grids );
 	void CartesianGenerator_GenFaceEdgeInc( CartesianGenerator* self, MeshTopology* topo, Grid*** grids );
 	void CartesianGenerator_GenEdgeVertexInc( CartesianGenerator* self, MeshTopology* topo, Grid*** grids );
 	void CartesianGenerator_MapToDomain( CartesianGenerator* self, Decomp_Sync* sync, 
 					     unsigned size, unsigned* nIncEls, unsigned** incEls );
+	void CartesianGenerator_GenGeom( CartesianGenerator* self, Mesh* mesh );
 	void CartesianGenerator_Destruct( CartesianGenerator* self );
 
 #endif /* __Discretisaton_Mesh_CartesianGenerator_h__ */



More information about the cig-commits mailing list