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: /*@C MeshInitInput_GRUMMP
9: This function initializes the input structure for GRUMMP.
11: Collective on Mesh
13: Output Parameters:
14: . inputCtx - Structure for communicating with GRUMMP
16: Level: developer
18: .keywords mesh, GRUMMP
19: .seealso MeshInitOutput_GRUMMP()
20: @*/
21: int MeshInitInput_GRUMMP(struct _GRUMMP_io *inputCtx)
22: {
24: /* Setup the input structure */
25: inputCtx->numVertices = 0;
26: inputCtx->numCells = 0;
27: inputCtx->numHoles = 0;
28: inputCtx->vertices = PETSC_NULL;
29: inputCtx->perimeter.size = 0;
30: inputCtx->perimeter.numBC = 0;
31: inputCtx->perimeter.bc = PETSC_NULL;
32: inputCtx->perimeter.bcSize = PETSC_NULL;
33: inputCtx->holes = PETSC_NULL;
34: return(0);
35: }
37: int MeshParsePolygon_GRUMMP(int *markers, struct _GRUMMP_polygon *poly)
38: {
39: #if 0
40: int start; /* First node in the polygon */
41: int first; /* First node on this edge */
42: int next; /* End node on this edge */
43: int size, bc;
44: #endif
47: #if 0
48: /* Walk around the polygon */
49: poly->size = 1;
50: poly->numBC = 1;
51: start = segments[0];
52: first = start;
53: next = segments[in.perimeter.size*2];
54: /* First get number of boundary conditions */
55: while(next != start) {
56: if (next != segments[poly->size*2+1]) SETERRQ(PETSC_ERR_LIB, "Boundary must be connected");
57: if (markers[first] != markers[next])
58: poly->numBC++;
59: poly->size++;
60: first = next;
61: next = segments[poly->size*2];
62: }
63: /* Handle multiple BC */
64: PetscMalloc(poly->numBC * sizeof(int), &poly->bc);
65: PetscMalloc(poly->numBC * sizeof(int), &poly->bcSize);
66: poly->bc[0] = markers[start];
67: if (poly->numBC == 1) {
68: poly->bcSize[0] = poly->size;
69: } else {
70: poly->bcSize[0] = 0;
71: bc = 0;
72: size = 1;
73: start = segments[0];
74: first = start;
75: next = segments[size*2];
76: /* Get the number of nodes in each BC */
77: while(next != start) {
78: poly->bcSize[bc]++;
79: if (next != segments[size*2+1]) SETERRQ(PETSC_ERR_LIB0, "Boundary must be connected");
80: if (markers[first] != markers[next]) {
81: bc++;
82: poly->bcSize[bc] = 0;
83: }
84: size++;
85: first = next;
86: next = segments[size*2];
87: }
88: }
89: #endif
90: return(0);
91: }
93: /*@C MeshCreate_GRUMMP
94: This function creates a 2D unstructured mesh using GRUMMP.
96: Collective on Mesh
98: Input Parameters:
99: + b - The number of closed boundaries in the geometry, or different markers
100: . n - Number of boundary points
101: . points - (x,y) coordinates of the boundary points
102: . markers - Boundary markers for nodes, 0 indicates an interior point, each boundary must have a different marker
103: . m - Number of boundary segments
104: . segments - Endpoints of boundary segments or PETSC_NULL
105: . segmarkers - Boundary markers for each segment
106: . h - Number of holes
107: . holes - (x,y) coordinates of holes or PETSC_NULL
108: - numLocNodes - Number of nodes in an element
110: Output Parameter:
111: . mesh - The new mesh created by Triangle
113: Level: developer
115: .keywords mesh, GRUMMP
116: .seealso MeshInitInput_GRUMMP
117: @*/
118: int MeshCreate_GRUMMP(int b, int n, double *points, int *markers, int m, int *segments, int *segmarkers, int h,
119: double *holes, int numLocNodes, Mesh mesh)
120: {
121: struct _GRUMMP_io in; /* Input for GRUMMP mesh generator */
122: int hole;
123: int rank;
124: int ierr;
127: /* Initialize communication structures for GRUMMP */
128: MeshInitInput_GRUMMP(&in);
129: /*MeshInitOutput_GRUMMP(&out); */
131: mesh->numBd = b;
132: mesh->holes = PETSC_NULL;
133: mesh->numCorners = numLocNodes;
134: mesh->numHoles = h;
136: MPI_Comm_rank(mesh->comm, &rank);
137: if (rank == 0) {
138: /* Setup boundaries and holes */
139: in.numVertices = n;
140: if (n > 0) {
142: in.vertices = points;
143: }
144: in.numCells = h + 1;
145: if (m > 0) {
149: MeshParsePolygon_GRUMMP(markers, &in.perimeter);
150: }
151: in.numHoles = h;
152: if (h > 0) {
153: /* We keep these */
155: PetscMalloc(in.numHoles * sizeof(struct _GRUMMP_polygon), &in.holes);
156: for(hole = 0; hole < in.numHoles; hole++) {
157: MeshParsePolygon_GRUMMP(markers, &in.holes[hole]);
158: }
159: }
161: /* Generate the inital coarse mesh and check whether we should create midnodes */
162: if (numLocNodes != 3) SETERRQ(PETSC_ERR_SUP, "Number of local nodes not supported");
163: /*Mesh2DToPetsc(&in, tri); */
165: /* Get rid of extra information */
166: }
168: /* Communicate values */
169: /*MeshDistribute_GRUMMP(mesh); */
171: return(0);
172: }