StgDomain simple example in C

StgDomain is a library of routines for geometric and solver workflow functionality. To use it, certain C headers and libraries are required.

What's required?

The C headers required are:

#include <mpi.h>
#include <StGermain/StGermain.h>
#include <StgDomain/StgDomain.h>

The libraries required are:

... -lStgDomain -lStGermain...

If VMake is used for building the code, then the following packages are required (refer to the VMake example for how to do this):

packages = STGDOMAIN STGERMAIN MPI XML MATH

Example: Creating a mesh

This example does a simple task of setting up a mesh. To begin with we need to include the right headers, and initialise MPI, StGermain and StgDomain.

#include <mpi.h>
#include <StGermain/StGermain.h>
#include <StgDomain/StgDomain.h>

int main( int argc, char* argv[] ) {
CartesianGenerator* gen;
Mesh* mesh;
int nDims;
int sizes[3];
double minCrd[3];
double maxCrd[3];
int nRanks;

MPI_Init(&argc, &argv );
MPI_Comm_size( MPI_COMM_WORLD, &nRanks );
StGermain_Init( &argc, &argv );
StgDomain_Init( &argc, & argv );

To begin with, we'll ask MPI for how many processes we have.

MPI_Comm_size( MPI_COMM_WORLD, &nRanks );

We'll create a 3 dimensional cartesian mesh. In honour that we're interested in parallelisation, we'll make a mesh 4 times larger than the number of processes in each of the mesh axes, and equivalent geometry. A CartesianGenerator is set up to do this for us. It is a StGermain component, and hence needs to be named.

nDims = 3;
sizes[0] = sizes[1] = sizes[2] = 4 * nRanks;
minCrd[0] = minCrd[1] = minCrd[2] = 0.0;
maxCrd[0] = maxCrd[1] = maxCrd[2] = (double)nRanks;
gen = CartesianGenerator_New( "MyCartesianGenerator" );
MeshGenerator_SetDimSize( gen, nDims );
CartesianGenerator_SetShadowDepth( gen, 1 );
CartesianGenerator_SetTopologyParams( gen, sizes, 0, NULL, NULL );
CartesianGenerator_SetGeometryParams( gen, minCrd, maxCrd );
Then we'll create an actual mesh instance (i.e. we don't actually allocate memory for the mesh itself yet), and attach the generator to it. A Mesh is also a StGermain component, and hence also needs to be named.
mesh = Mesh_New( "My Mesh" );
Mesh_SetGenerator( mesh, gen );

Then we'll actually create the mesh. Following the StGermain component workflow, this can be triggered by building it.

Stg_Component_Build( mesh, NULL, False );
Clean up and exit.
StgDomain_Finalise();
StGermain_Finalise();
MPI_Finalize();
return 1;
}

Available as a flattened mesh-example.c .