Actual source code: tri2d_GRUMMP.c
1: #ifdef PETSC_RCS_HEADER
2: static char vcid[] = "$Id: tri2d_GRUMMP.c,v 1.1 1999/12/08 14:45:09 knepley Exp $";
3: #endif
5: #include "src/mesh/impls/triangular/2d/2dimpl.h" /*I "mesh.h" I*/
6: #include "GRUMMP.h"
8: #undef __FUNCT__
10: /*@C MeshInitInput_GRUMMP
11: This function initializes the input structure for GRUMMP.
13: Collective on Mesh
15: Output Parameters:
16: . inputCtx - Structure for communicating with GRUMMP
18: Level: developer
20: .keywords mesh, GRUMMP
21: .seealso MeshInitOutput_GRUMMP()
22: @*/
23: int MeshInitInput_GRUMMP(struct _GRUMMP_io *inputCtx)
24: {
26: /* Setup the input structure */
27: inputCtx->numVertices = 0;
28: inputCtx->numCells = 0;
29: inputCtx->numHoles = 0;
30: inputCtx->vertices = PETSC_NULL;
31: inputCtx->perimeter.size = 0;
32: inputCtx->perimeter.numBC = 0;
33: inputCtx->perimeter.bc = PETSC_NULL;
34: inputCtx->perimeter.bcSize = PETSC_NULL;
35: inputCtx->holes = PETSC_NULL;
36: return(0);
37: }
39: #undef __FUNCT__
41: int MeshParsePolygon_GRUMMP(int *markers, struct _GRUMMP_polygon *poly)
42: {
43: #if 0
44: int start; /* First node in the polygon */
45: int first; /* First node on this edge */
46: int next; /* End node on this edge */
47: int size, bc;
48: #endif
51: #if 0
52: /* Walk around the polygon */
53: poly->size = 1;
54: poly->numBC = 1;
55: start = segments[0];
56: first = start;
57: next = segments[in.perimeter.size*2];
58: /* First get number of boundary conditions */
59: while(next != start) {
60: if (next != segments[poly->size*2+1]) SETERRQ(PETSC_ERR_LIB, "Boundary must be connected");
61: if (markers[first] != markers[next])
62: poly->numBC++;
63: poly->size++;
64: first = next;
65: next = segments[poly->size*2];
66: }
67: /* Handle multiple BC */
68: PetscMalloc(poly->numBC * sizeof(int), &poly->bc);
69: PetscMalloc(poly->numBC * sizeof(int), &poly->bcSize);
70: poly->bc[0] = markers[start];
71: if (poly->numBC == 1) {
72: poly->bcSize[0] = poly->size;
73: } else {
74: poly->bcSize[0] = 0;
75: bc = 0;
76: size = 1;
77: start = segments[0];
78: first = start;
79: next = segments[size*2];
80: /* Get the number of nodes in each BC */
81: while(next != start) {
82: poly->bcSize[bc]++;
83: if (next != segments[size*2+1]) SETERRQ(PETSC_ERR_LIB0, "Boundary must be connected");
84: if (markers[first] != markers[next]) {
85: bc++;
86: poly->bcSize[bc] = 0;
87: }
88: size++;
89: first = next;
90: next = segments[size*2];
91: }
92: }
93: #endif
94: return(0);
95: }
97: #undef __FUNCT__
99: /*@C MeshCreate_GRUMMP
100: This function creates a 2D unstructured mesh using GRUMMP.
102: Collective on Mesh
104: Input Parameters:
105: + b - The number of closed boundaries in the geometry, or different markers
106: . n - Number of boundary points
107: . points - (x,y) coordinates of the boundary points
108: . markers - Boundary markers for nodes, 0 indicates an interior point, each boundary must have a different marker
109: . m - Number of boundary segments
110: . segments - Endpoints of boundary segments or PETSC_NULL
111: . segmarkers - Boundary markers for each segment
112: . h - Number of holes
113: . holes - (x,y) coordinates of holes or PETSC_NULL
114: - numLocNodes - Number of nodes in an element
116: Output Parameter:
117: . mesh - The new mesh created by Triangle
119: Level: developer
121: .keywords mesh, GRUMMP
122: .seealso MeshInitInput_GRUMMP
123: @*/
124: int MeshCreate_GRUMMP(int b, int n, double *points, int *markers, int m, int *segments, int *segmarkers, int h,
125: double *holes, int numLocNodes, Mesh mesh)
126: {
127: struct _GRUMMP_io in; /* Input for GRUMMP mesh generator */
128: int hole;
129: int rank;
130: int ierr;
133: /* Initialize communication structures for GRUMMP */
134: MeshInitInput_GRUMMP(&in);
135: /*MeshInitOutput_GRUMMP(&out); */
137: mesh->numBd = b;
138: mesh->holes = PETSC_NULL;
139: mesh->numCorners = numLocNodes;
140: mesh->numHoles = h;
142: MPI_Comm_rank(mesh->comm, &rank);
143: if (rank == 0) {
144: /* Setup boundaries and holes */
145: in.numVertices = n;
146: if (n > 0) {
148: in.vertices = points;
149: }
150: in.numCells = h + 1;
151: if (m > 0) {
155: MeshParsePolygon_GRUMMP(markers, &in.perimeter);
156: }
157: in.numHoles = h;
158: if (h > 0) {
159: /* We keep these */
161: PetscMalloc(in.numHoles * sizeof(struct _GRUMMP_polygon), &in.holes);
162: for(hole = 0; hole < in.numHoles; hole++) {
163: MeshParsePolygon_GRUMMP(markers, &in.holes[hole]);
164: }
165: }
167: /* Generate the inital coarse mesh and check whether we should create midnodes */
168: if (numLocNodes != 3) SETERRQ(PETSC_ERR_SUP, "Number of local nodes not supported");
169: /*Mesh2DToPetsc(&in, tri); */
171: /* Get rid of extra information */
172: }
174: /* Communicate values */
175: /*MeshDistribute_GRUMMP(mesh); */
177: return(0);
178: }