Mesh* WallVCSuite_buildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg ) {
   CartesianGenerator* gen;
   Mesh*               mesh;
   unsigned            maxDecomp[3] = {0, 1, 1};

   gen = CartesianGenerator_New( "", NULL );
   gen->shadowDepth = 0;
   CartesianGenerator_SetDimSize( gen, nDims );
   CartesianGenerator_SetTopologyParams( gen, size, 0, NULL, maxDecomp );
   CartesianGenerator_SetGeometryParams( gen, minCrds, maxCrds );

   mesh = Mesh_New( "", NULL );
   Mesh_SetExtensionManagerRegister( mesh, emReg );
   Mesh_SetGenerator( mesh, gen );

   Stg_Component_Build( mesh, NULL, False );
   Stg_Component_Initialise( mesh, NULL, False );

   return mesh;
}
Mesh* ElementCellLayout_BuildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg ) {
   CartesianGenerator* gen;
   Mesh*               mesh;
   unsigned            maxDecomp[3] = {1, 0, 1};

   gen = CartesianGenerator_New( "", NULL );
   CartesianGenerator_SetDimSize( gen, nDims );
   CartesianGenerator_SetTopologyParams( gen, size, 0, NULL, maxDecomp );
   CartesianGenerator_SetGeometryParams( gen, minCrds, maxCrds );

   mesh = Mesh_New( "" );
   Mesh_SetExtensionManagerRegister( mesh, emReg );
   Mesh_SetGenerator( mesh, gen );

   Stg_Component_Build( mesh, NULL, False );
   Stg_Component_Initialise( mesh, NULL, False );

   FreeObject( mesh->generator );

   return mesh;
}
Mesh* SpaceFillerParticleLayoutSuite_BuildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg ) {
   CartesianGenerator* gen;
   Mesh*               mesh;

   gen = CartesianGenerator_New( "", NULL );
   CartesianGenerator_SetDimSize( gen, nDims );
   CartesianGenerator_SetTopologyParams( gen, size, 0, NULL, NULL );
   CartesianGenerator_SetGeometryParams( gen, minCrds, maxCrds );

   mesh = Mesh_New( "", NULL );
   Mesh_SetExtensionManagerRegister( mesh, emReg );
   Mesh_SetGenerator( mesh, gen );
   Mesh_SetAlgorithms( mesh, Mesh_RegularAlgorithms_New( "", NULL ) );

   Stg_Component_Build( mesh, NULL, False );
   Stg_Component_Initialise( mesh, NULL, False );

   FreeObject( mesh->generator );

   return mesh;
}
Ejemplo n.º 4
0
int main(int argc, char **argv)
{
	MPI_Comm		CommWorld;
	XML_IO_Handler 		*io_handler = XML_IO_Handler_New();
	int			rank, procCount, procToWatch;
	Dictionary		*dictionary;
	EmbeddedSurface		*surface;
	MeshTopology		*rmt, *imt;
	MeshGeometry		*rmg, *img;
	MeshDecomp		*rmd, *imd;
	MeshLayout		*rml, *isl;
	ExtensionManager_Register	*extensionMgr_Register;
	Mesh			*mesh;
	Element_GlobalIndex	intersectCnt, *intersect;
	Index			i;
	
	/* Initialise MPI, get world info */
	MPI_Init( &argc, &argv );
	MPI_Comm_dup( MPI_COMM_WORLD, &CommWorld );
	MPI_Comm_size( CommWorld, &procCount );
	MPI_Comm_rank( CommWorld, &rank );
	
	Base_Init( &argc, &argv );
	
	DiscretisationGeometry_Init( &argc, &argv );
	DiscretisationShape_Init( &argc, &argv );
	DiscretisationMesh_Init( &argc, &argv );
	DiscretisationUtils_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 ) printf( "Watching rank: %i\n", rank );
	
	dictionary = Dictionary_New();
	Dictionary_Add( dictionary, "rank", Dictionary_Entry_Value_FromUnsignedInt( rank ) );
	Dictionary_Add( dictionary, "numProcessors", Dictionary_Entry_Value_FromUnsignedInt( procCount ) );
	Dictionary_Add( dictionary, "meshSizeI", Dictionary_Entry_Value_FromUnsignedInt( 2 ) );
	Dictionary_Add( dictionary, "meshSizeJ", Dictionary_Entry_Value_FromUnsignedInt( 2 ) );
	Dictionary_Add( dictionary, "meshSizeK", Dictionary_Entry_Value_FromUnsignedInt( 4 ) );
	Dictionary_Add( dictionary, "allowUnusedCPUs", Dictionary_Entry_Value_FromBool( True ) );
	Dictionary_Add( dictionary, "allowPartitionOnElement", Dictionary_Entry_Value_FromBool( True ) );
	Dictionary_Add( dictionary, "allowPartitionOnNode", Dictionary_Entry_Value_FromBool( True ) );
	Dictionary_Add( dictionary, "shadowDepth", Dictionary_Entry_Value_FromUnsignedInt( 0 ) );
	IO_Handler_ReadAllFromFile(io_handler, "data/surface.xml", dictionary);
	
	rmt = (MeshTopology *)HexaMeshTopology_New(dictionary);
	rmg = (MeshGeometry *)HexaMeshGeometry_New(dictionary);
	rmd = (MeshDecomp *)HexaMeshDecomp_New(dictionary, MPI_COMM_WORLD, (HexaMeshTopology *)rmt);
	rml = MeshLayout_New(dictionary, rmt, rmg, rmd);
	
	imt = (MeshTopology *)TriSurfTopology_New(dictionary, "imElements");
	img = (MeshGeometry *)TriSurfGeometry_New(dictionary, "imNodes");
	imd = (MeshDecomp *)IrregularMeshDecomp_New1(dictionary, MPI_COMM_WORLD, imt, img, rml);
	isl = MeshLayout_New(dictionary, imt, img, imd);
	
	extensionMgr_Register = ExtensionManager_Register_New( );
	mesh = Mesh_New( isl, sizeof(Node), sizeof(Element), extensionMgr_Register, dictionary );
	Mesh_Build( mesh );
	Mesh_Initialise(mesh);
	
	surface = EmbeddedSurface_New(mesh);
	
	if (procToWatch == rank)
	{
		intersect = Memory_Alloc_Array( Element_GlobalIndex, isl->decomp->elementGlobalCount(isl->decomp), "intersect" );
		intersectCnt = EmbeddedSurface_BuildIntersection(surface, intersect);
	
		printf("Intersects: %u\n", intersectCnt);
		for (i = 0; i < intersectCnt; i++)
			printf("\tinstersect[%u]: %u\n", i, intersect[i]);
		printf("\n");
	
		if (intersect) Memory_Free(intersect);
	
		for (i = 0; i < isl->decomp->nodeGlobalCount(isl->decomp); i++)
		{
			Coord point;
		
			point[0] = ((TriSurfGeometry *)img)->node[i][0] + 1.0;
			point[1] = ((TriSurfGeometry *)img)->node[i][1];
			point[2] = ((TriSurfGeometry *)img)->node[i][2];

			printf("Distance to point {%.3f, %.3f, %.3f}: ", point[0], point[1], point[2]);
			printf("%.3f\n", EmbeddedSurface_DistanceToPoint(surface, point));
		}
	}
	
	Stg_Class_Delete(surface);
	Stg_Class_Delete(isl);
	Stg_Class_Delete(imd);
	Stg_Class_Delete(img);
	Stg_Class_Delete(imt);
	Stg_Class_Delete(rml);
	Stg_Class_Delete(rmd);
	Stg_Class_Delete(rmg);
	Stg_Class_Delete(rmt);
	
	DiscretisationUtils_Finalise();
	DiscretisationMesh_Finalise();
	DiscretisationShape_Finalise();
	DiscretisationGeometry_Finalise();
	
	Base_Finalise();
	
	/* Close off MPI */
	MPI_Finalize();
	
	return 0;
}
Ejemplo n.º 5
0
int main(int argc, char *argv[])
{
	MPI_Comm		CommWorld;
	int			rank;
	int			procCount;
	int			procToWatch;
	Dictionary*		dictionary;
	ExtensionManager_Register*	extensionMgr_Register;
	Topology*		nTopology;
	ElementLayout*		eLayout;
	NodeLayout*		nLayout;
	MeshDecomp*		decomp;
	MeshLayout*		ml;
	Mesh*			mesh;
	Stream*			stream;

	
	/* Initialise MPI, get world info */
	MPI_Init(&argc, &argv);
	MPI_Comm_dup( MPI_COMM_WORLD, &CommWorld );
	MPI_Comm_size(CommWorld, &procCount);
	MPI_Comm_rank(CommWorld, &rank);

	Base_Init( &argc, &argv );
	
	DiscretisationGeometry_Init( &argc, &argv );
	DiscretisationShape_Init( &argc, &argv );
	DiscretisationMesh_Init( &argc, &argv );

	stream = Journal_Register (Info_Type, "myStream");
	procToWatch = argc >= 2 ? atoi(argv[1]) : 0;
	
	dictionary = Dictionary_New();
	Dictionary_Add( dictionary, "rank", Dictionary_Entry_Value_FromUnsignedInt( rank ) );
	Dictionary_Add( dictionary, "numProcessors", Dictionary_Entry_Value_FromUnsignedInt( procCount ) );
	Dictionary_Add( dictionary, "meshSizeI", Dictionary_Entry_Value_FromUnsignedInt( 7 ) );
	Dictionary_Add( dictionary, "meshSizeJ", Dictionary_Entry_Value_FromUnsignedInt( 7 ) );
	Dictionary_Add( dictionary, "meshSizeK", Dictionary_Entry_Value_FromUnsignedInt( 7 ) );
	Dictionary_Add( dictionary, "allowUnusedCPUs", Dictionary_Entry_Value_FromBool( False ) );
	Dictionary_Add( dictionary, "allowPartitionOnNode", Dictionary_Entry_Value_FromBool( True ) );
	Dictionary_Add( dictionary, "allowUnbalancing", Dictionary_Entry_Value_FromBool( False ) );
	Dictionary_Add( dictionary, "shadowDepth", Dictionary_Entry_Value_FromUnsignedInt( 1 ) );
	
	nTopology = (Topology*)IJK6Topology_New( "IJK6Topology", dictionary );
	eLayout = (ElementLayout*)ParallelPipedHexaEL_New( "PPHexaEL", 3, dictionary );
	nLayout = (NodeLayout*)CornerNL_New( "CornerNL", dictionary, eLayout, nTopology );
	decomp = (MeshDecomp*)HexaMD_New( "HexaMD", dictionary, MPI_COMM_WORLD, eLayout, nLayout );
	ml = MeshLayout_New( "MeshLayout", eLayout, nLayout, decomp );
	
	extensionMgr_Register = ExtensionManager_Register_New();
	mesh = Mesh_New( "Mesh", ml, sizeof(Node), sizeof(Element), extensionMgr_Register, dictionary );
	
	mesh->buildNodeLocalToGlobalMap = True;
	mesh->buildNodeDomainToGlobalMap = True;
	mesh->buildNodeGlobalToLocalMap = True;
	mesh->buildNodeGlobalToDomainMap = True;
	mesh->buildNodeNeighbourTbl = True;
	mesh->buildNodeElementTbl = True;
	mesh->buildElementLocalToGlobalMap = True;
	mesh->buildElementDomainToGlobalMap = True;
	mesh->buildElementGlobalToDomainMap = True;
	mesh->buildElementGlobalToLocalMap = True;
	mesh->buildElementNeighbourTbl = True;
	mesh->buildElementNodeTbl = True;
	
	Build( mesh, 0, False );
	Initialise(mesh, 0, False );
	

	
	if (rank == procToWatch)
	{
		Node_Index				currElementNodesCount=0;	
		Node_Index*         	currElementNodes = NULL;
		Element_Index          	element_dI = 0;
		Node_Index             	refNode_eI = 0;
		Node_Index				node_Diagonal = 0;
		Node_Index				node_Diagonal_gI = 0;
		
		// only use this while setting up the test
		//Print(mesh, stream);
				
		// Some tests involving RegularMeshUtils_GetDiagOppositeAcrossElementNodeIndex()
		
		
		for (element_dI=0; element_dI < mesh->elementDomainCount; element_dI++) {
			
			currElementNodes = mesh->elementNodeTbl[element_dI];
			currElementNodesCount = mesh->elementNodeCountTbl[element_dI];
			
			for (refNode_eI = 0; refNode_eI < currElementNodesCount; refNode_eI++ ) {
				
				node_Diagonal = RegularMeshUtils_GetDiagOppositeAcrossElementNodeIndex(mesh, element_dI, 
					currElementNodes[refNode_eI]) ;
				node_Diagonal_gI = Mesh_NodeMapDomainToGlobal( mesh, node_Diagonal );
				//print message stating: Element #, curr node #, diag opp node #
				printf("Element #: %d, Current Node #: %d, Diagonal Node #: %d, (%d) \n",
					element_dI, currElementNodes[refNode_eI], node_Diagonal, node_Diagonal_gI);
				
			}
		}	
	}
	
	Stg_Class_Delete(mesh);
	Stg_Class_Delete(ml);
	Stg_Class_Delete(decomp);
	Stg_Class_Delete(nLayout);
	Stg_Class_Delete(eLayout);
	Stg_Class_Delete( nTopology );
	Stg_Class_Delete(dictionary);
	
	DiscretisationMesh_Finalise();
	DiscretisationShape_Finalise();
	DiscretisationGeometry_Finalise();
	
	Base_Finalise();
	
	/* Close off MPI */
	MPI_Finalize();
	
	return 0; /* success */
}
Ejemplo n.º 6
0
PyObject* Mesh_Python_New( PyObject* self, PyObject* args ) {
    return PyCObject_FromVoidPtr( Mesh_New(), 0 );
}
Ejemplo n.º 7
0
int main(int argc, char *argv[])
{
	MPI_Comm		CommWorld;
	int		rank;
	int		procCount;
	int		procToWatch;
	Stream*		stream;
	
	Dictionary*		dictionary;
	XML_IO_Handler*		io_handler;
	
	Topology*       nTopology;
	ElementLayout*	eLayout;
	NodeLayout*	nLayout;
	MeshDecomp*	decomp;
	MeshLayout*	layout;
	Mesh*		mesh;
	
	Variable*			var[7];
	Variable_Register*		variable_Register;
	WallVC*				vc;
	ConditionFunction*		quadCF;
	ConditionFunction*		expCF;
	ConditionFunction_Register*	conFunc_Register;

	ExtensionManager_Register*		extensionMgr_Register;
	
	double*		array[7];
	char*		vcKey[] = {"WallVC_Front", "WallVC_Back", "WallVC_Left", "WallVC_Right",
				"WallVC_Top", "WallVC_Bottom"};
	char*		vcKeyName[] = {"WallVC_FrontName", "WallVC_BackName", "WallVC_LeftName", "WallVC_RightName",
				"WallVC_TopName", "WallVC_BottomName"};
	char*		varName[] = {"x", "y", "z", "vx", "vy", "vz", "temp"};
	
	Index	i;

	
	/* Initialise MPI, get world info */
	MPI_Init(&argc, &argv);
	MPI_Comm_dup( MPI_COMM_WORLD, &CommWorld );
	MPI_Comm_size(CommWorld, &procCount);
	MPI_Comm_rank(CommWorld, &rank);
	
	Base_Init( &argc, &argv );
	
	DiscretisationGeometry_Init( &argc, &argv );
	DiscretisationShape_Init( &argc, &argv );
	DiscretisationMesh_Init( &argc, &argv );
	DiscretisationUtils_Init( &argc, &argv );
	MPI_Barrier( CommWorld ); /* Ensures copyright info always come first in output */

	io_handler = XML_IO_Handler_New();

	stream = Journal_Register (Info_Type, "myStream");
	
	procToWatch = argc >= 2 ? atoi(argv[1]) : 0;
	
	dictionary = Dictionary_New();
	IO_Handler_ReadAllFromFile(io_handler, "data/wallVC.xml", dictionary);
	fflush(stdout);
	MPI_Barrier(MPI_COMM_WORLD);
	Dictionary_Add(dictionary, "rank", Dictionary_Entry_Value_FromUnsignedInt(rank));
	Dictionary_Add(dictionary, "numProcessors", Dictionary_Entry_Value_FromUnsignedInt(procCount));
	Dictionary_Add(dictionary, "meshSizeI", Dictionary_Entry_Value_FromUnsignedInt(4));
	Dictionary_Add(dictionary, "meshSizeJ", Dictionary_Entry_Value_FromUnsignedInt(4));
	Dictionary_Add(dictionary, "meshSizeK", Dictionary_Entry_Value_FromUnsignedInt(4));
	Dictionary_Add(dictionary, "allowUnbalancing", Dictionary_Entry_Value_FromBool(True));

	extensionMgr_Register = ExtensionManager_Register_New();	
	
	nTopology = (Topology*)IJK6Topology_New( "IJK6Topology", dictionary );
	eLayout = (ElementLayout*)ParallelPipedHexaEL_New( "PPHexaEL", 3, dictionary );
	nLayout = (NodeLayout*)CornerNL_New( "CornerNL", dictionary, eLayout, nTopology );
	decomp = (MeshDecomp*)HexaMD_New( "HexaMD", dictionary, MPI_COMM_WORLD, eLayout, nLayout );
	layout = MeshLayout_New( "MeshLayout", eLayout, nLayout, decomp );
	mesh = Mesh_New( "Mesh", layout, 0, 0, extensionMgr_Register, dictionary );
	
	/* Create CF stuff */
	quadCF = ConditionFunction_New(quadratic, "quadratic");
	expCF = ConditionFunction_New(exponential, "exponential");
	conFunc_Register = ConditionFunction_Register_New();
	ConditionFunction_Register_Add(conFunc_Register, quadCF);
	ConditionFunction_Register_Add(conFunc_Register, expCF);
	
	/* Create variable register */
	variable_Register = Variable_Register_New();
	
	/* Create variables */
	for (i = 0; i < 6; i++) {
		array[i] = Memory_Alloc_Array( double, decomp->nodeLocalCount, "array[i]" );
		var[i] = Variable_NewScalar( varName[i], Variable_DataType_Double, &decomp->nodeLocalCount, (void**)&array[i], 0 ); 
		Variable_Register_Add(variable_Register, var[i]);
	}
	array[6] = Memory_Alloc_Array( double, decomp->nodeLocalCount * 5, "array[6]" );
	var[6] = Variable_NewVector( varName[6], Variable_DataType_Double, 5, &decomp->nodeLocalCount, (void**)&array[6], 0 );
	Variable_Register_Add(variable_Register, var[6]);
	Variable_Register_BuildAll(variable_Register);
	
	/* Create WallVC */
	for (i = 0; i < 6; i++)
	{
		Index	j, k;
		
		vc = WallVC_New( vcKeyName[i], vcKey[i], variable_Register, conFunc_Register, dictionary, mesh );
		Build( vc, 0, False );
		
		for (j = 0; j < 6; j++)
			memset(array[j], 0, sizeof(double)* decomp->nodeLocalCount );
		memset(array[6], 0, sizeof(double)* decomp->nodeLocalCount * 5);
		VariableCondition_Apply(vc, NULL);
	
		if (rank == procToWatch)
		{
			printf("Testing for %s\n", vcKey[i]);
			Print(vc, stream);
			printf("\n");
			for (j = 0; j < 6; j++)
			{
				printf("\nvar[%u]: %.2lf", j, array[j][0]);
				for (k = 1; k < decomp->nodeLocalCount; k++)
					printf(", %.2lf", array[j][k]);
			}
			printf("\nvar[6]: %.2lf", array[6][0]);
			for (j = 1; j < decomp->nodeLocalCount*5; j++)
				printf(", %.2lf", array[6][j]);
			printf("\n\n");
			
			for (j = 0; j < 7; j++)
			{
				for (k = 0; k < decomp->nodeLocalCount; k++)
					printf("%s ", VariableCondition_IsCondition(vc, k, j) ? "True " : "False");
				printf("\n");
			}
			printf("\n");
			
			for (j = 0; j < 7; j++)
			{
				for (k = 0; k < decomp->nodeLocalCount; k++)
				{
					VariableCondition_ValueIndex	valIndex;
					
					valIndex = VariableCondition_GetValueIndex(vc, k, j);
					if (valIndex != (unsigned)-1)
						printf("%03u ", valIndex);
					else
						printf("XXX ");
				}
				printf("\n");
			}
			printf("\n");
		}
		
		Stg_Class_Delete(vc);
	}
		
	Stg_Class_Delete(variable_Register);
	for (i = 0; i < 7; i++)
	{
		Stg_Class_Delete(var[i]);
		if (array[i]) Memory_Free(array[i]);
	}
	Stg_Class_Delete(conFunc_Register);
	Stg_Class_Delete(quadCF);
	Stg_Class_Delete(expCF);
	Stg_Class_Delete(layout);
	Stg_Class_Delete(decomp);
	Stg_Class_Delete(nLayout);
	Stg_Class_Delete(eLayout);
	Stg_Class_Delete( nTopology );
	Stg_Class_Delete(dictionary);
	
	DiscretisationUtils_Finalise();
	DiscretisationMesh_Finalise();
	DiscretisationShape_Finalise();
	DiscretisationGeometry_Finalise();
	
	Base_Finalise();
	
	/* Close off MPI */
	MPI_Finalize();
	
	return 0; /* success */
}