Actual source code: elemvec.c
1: #ifdef PETSC_RCS_HEADER
2: static char vcid[] = "$Id: elemvec.c,v 1.13 2000/07/16 23:20:02 knepley Exp $";
3: #endif
5: #include src/grid/gridimpl.h
7: /* Logging support */
8: int ELEMENT_VEC_COOKIE;
9: int ELEMENT_MAT_COOKIE;
11: /*---------------------------------------------- Element Matrix Functions -------------------------------------------*/
12: /*@C ElementMatCreate
13: This function creates an element matrix for a finite element calculation.
15: Collective on MPI_Comm
17: Input Parameters:
18: + comm - The communicator to associate with the matrix
19: . rowSize - The number of test functions per element
20: - colSize - The number of basis functions per element
22: Output Parameter:
23: . mat - The element matrix
25: Level: beginner
27: .keywords element matrix, finite element
28: .seealso ElementMatDestroy(), ElementVecCreate()
29: @*/
30: int ElementMatCreate(MPI_Comm comm, int rowSize, int colSize, ElementMat *mat)
31: {
32: ElementMat m;
33: int ierr;
37: *mat = PETSC_NULL;
38: #ifndef PETSC_USE_DYNAMIC_LIBRARIES
39: GridInitializePackage(PETSC_NULL);
40: #endif
42: PetscHeaderCreate(m, _ElementMat, int, ELEMENT_MAT_COOKIE, 0, "ElementMat", comm, ElementMatDestroy, 0);
43: PetscLogObjectCreate(m);
44: m->rowSize = rowSize;
45: m->colSize = colSize;
46: m->reduceRowSize = rowSize;
47: m->reduceColSize = colSize;
48: PetscMalloc(rowSize*colSize * sizeof(PetscScalar), &m->array);
49: PetscMalloc(rowSize * sizeof(int), &m->rowIndices);
50: PetscMalloc(colSize * sizeof(int), &m->colIndices);
51: PetscMalloc(colSize * sizeof(int), &m->reduceCols);
52: PetscMalloc(rowSize*colSize * sizeof(PetscScalar), &m->tempArray);
53: PetscMalloc(PetscMax(rowSize, colSize) * sizeof(int), &m->tempIndices);
54: PetscLogObjectMemory(m, (rowSize + colSize*2 + PetscMax(rowSize, colSize)) * sizeof(int) + (rowSize*colSize*2) * sizeof(PetscScalar));
55: *mat = m;
57: return(0);
58: }
60: /*@C ElementMatDestroy
61: This function destroys an element matrix.
63: Not collective
65: Input Parameter:
66: . vec - The element matrix
68: Level: beginner
70: .keywords element matrix, finite element
71: .seealso ElementMatCreate(), ElementVecDestroy()
72: @*/
73: int ElementMatDestroy(ElementMat mat)
74: {
79: if (--mat->refct > 0)
80: return(0);
81: PetscFree(mat->array);
82: PetscFree(mat->rowIndices);
83: PetscFree(mat->colIndices);
84: PetscFree(mat->reduceCols);
85: PetscFree(mat->tempArray);
86: PetscFree(mat->tempIndices);
87: PetscLogObjectDestroy(mat);
88: PetscHeaderDestroy(mat);
89: return(0);
90: }
92: /*@C ElementMatView
93: This function destroys an element matrix.
95: Not collective
97: Input Parameter:
98: . vec - The element matrix
100: Level: beginner
102: .keywords element matrix, finite element
103: .seealso ElementMatCreate(), ElementVecView()
104: @*/
105: int ElementMatView(ElementMat mat, PetscViewer viewer)
106: {
107: int row, col;
108: PetscTruth isascii;
109: int ierr;
114: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_ASCII, &isascii);
115: if (isascii == PETSC_TRUE) {
116: if (mat->reduceColSize > 0) {
117: PetscViewerASCIIPrintf(viewer, " %3d", mat->colIndices[0]);
118: for(col = 1; col < mat->reduceColSize; col++)
119: PetscViewerASCIIPrintf(viewer, " %3d", mat->colIndices[col]);
120: PetscViewerASCIIPrintf(viewer, "n");
121: }
122: for(row = 0; row < mat->reduceRowSize; row++) {
123: PetscViewerASCIIPrintf(viewer, "%3d ", mat->rowIndices[row]);
124: for(col = 0; col < mat->reduceColSize; col++)
125: PetscViewerASCIIPrintf(viewer, "%5.2g ", PetscRealPart(mat->array[row*mat->reduceColSize+col]));
126: PetscViewerASCIIPrintf(viewer, "n");
127: }
128: }
129: return(0);
130: }
132: /*@C ElementMatDuplicate
133: This function duplicates an element matrix.
135: Collective on ElementMat
137: Input Parameter:
138: . mat - The original element matrix
140: Output Parameter:
141: . newmat - The new element matrix
143: Level: beginner
145: .keywords element matrix, finite element
146: .seealso GridCalcElementMatIndices()
147: @*/
148: int ElementMatDuplicate(ElementMat mat, ElementMat *newmat)
149: {
155: ElementMatCreate(mat->comm, mat->rowSize, mat->colSize, newmat);
156: return(0);
157: }
159: /*@C ElementMatDuplicateIndices
160: This function copies the global matrix indices to another element matrix.
162: Collective on ElementMat
164: Input Parameter:
165: . mat - The original element matrix
167: Output Parameter:
168: . newmat - The element matrix with updated indices
170: Level: intermediate
172: .keywords element matrix, finite element
173: .seealso GridCalcElementMatIndices()
174: @*/
175: int ElementMatDuplicateIndices(ElementMat mat, ElementMat newmat)
176: {
182: if (mat == newmat)
183: return(0);
184: if ((mat->rowSize != newmat->rowSize) || (mat->colSize != newmat->colSize)) {
185: SETERRQ(PETSC_ERR_ARG_INCOMP, "Incompatible matrix sizes");
186: }
187: PetscMemcpy(newmat->rowIndices, mat->rowIndices, mat->rowSize * sizeof(int));
188: PetscMemcpy(newmat->colIndices, mat->colIndices, mat->colSize * sizeof(int));
189: return(0);
190: }
192: /*@C ElementMatZero
193: This function sets all the entries in the element matrix to zero.
195: Collective on ElementMat
197: Output Parameter:
198: . mat - The element matrix
200: Level: beginner
202: .keywords element matrix, finite element
203: .seealso ElementMatCreate()
204: @*/
205: int ElementMatZero(ElementMat mat)
206: {
211: PetscMemzero(mat->array, mat->rowSize*mat->colSize * sizeof(PetscScalar));
212: return(0);
213: }
215: /*@C ElementMatSetValues
216: This function puts all the entries in the element matrix into
217: the global matrix.
219: Collective on GMat
221: Input Parameters:
222: + mat - The element matrix
223: - addv - The insertion mode
224:
225: Output Parameter:
226: . M - The global matrix
228: Level: beginner
230: .keywords element matrix, finite element
231: .seealso ElementMatCreate
232: @*/
233: int ElementMatSetValues(ElementMat mat, GMat M, InsertMode addv)
234: {
238: /* Place entries in the global matrix */
241: MatSetValues(M, mat->reduceRowSize, mat->rowIndices, mat->reduceColSize, mat->colIndices, mat->array, addv);
242:
243: mat->reduceRowSize = mat->rowSize;
244: mat->reduceColSize = mat->colSize;
245: return(0);
246: }
248: /*@C ElementMatSetDiagonalValues
249: This function puts only the diagonal entries of the element matrix into a global vector.
251: Collective on GVec
253: Input Parameters:
254: + mat - The element matrix
255: - addv - The insertion mode
256:
257: Output Parameter:
258: . d - The global vector
260: Level: beginner
262: .keywords element matrix, finite element
263: .seealso ElementMatSetValues
264: @*/
265: int ElementMatSetDiagonalValues(ElementMat mat, GVec d, InsertMode addv)
266: {
267: int *rows = mat->rowIndices;
268: int *cols = mat->colIndices;
269: int row, col;
270: int ierr;
273: /* Place entries in the global matrix */
276: for(row = 0; row < mat->reduceRowSize; row++) {
277: for(col = 0; col < mat->reduceColSize; col++) {
278: if (rows[row] == cols[col]) {
279: VecSetValue(d, rows[row], mat->array[row*mat->reduceColSize+col], addv);
280: }
281: }
282: }
283: mat->reduceRowSize = mat->rowSize;
284: mat->reduceColSize = mat->colSize;
285: return(0);
286: }
288: /*@C ElementMatGetSize
289: This function returns the size of the element matrix.
291: Not collective
293: Input Parameter:
294: . mat - The element matrix
295:
296: Output Parameters:
297: + rowSize - The number of rows
298: - colSize - The number of rows
300: Level: intermediate
302: .keywords element matrix, finite element
303: .seealso ElementMatGetReduceSize(), ElementMatCreate()
304: @*/
305: int ElementMatGetSize(ElementMat mat, int *rowSize, int *colSize)
306: {
311: *rowSize = mat->rowSize;
312: *colSize = mat->colSize;
313: return(0);
314: }
316: /*@C
317: ElementMatGetReduceSize - This function returns the size of the element matrix
318: after all reduction have been carried out..
320: Not collective
322: Input Parameter:
323: . mat - The element matrix
324:
325: Output Parameters:
326: + rowSize - The number of rows
327: - colSize - The number of rows
329: Level: intermediate
331: .keywords: element matrix, finite element
332: .seealso: ElementMatGetSize(), ElementMatCreate()
333: @*/
334: int ElementMatGetReduceSize(ElementMat mat, int *rowSize, int *colSize)
335: {
340: *rowSize = mat->reduceRowSize;
341: *colSize = mat->reduceColSize;
342: return(0);
343: }
345: /*@C ElementMatGetIndices
346: This function returns the index mappings for the element matrix.
348: Collective on ElementMat
350: Input Parameter:
351: . mat - The element matrix
352:
353: Output Parameters:
354: + rowIdx - The row mapping
355: - colIdx - The column mapping
357: Level: intermediate
359: .keywords element matrix, finite element
360: .seealso ElementMatCreate
361: @*/
362: int ElementMatGetIndices(ElementMat mat, int **rowIdx, int **colIdx)
363: {
368: *rowIdx = mat->rowIndices;
369: *colIdx = mat->colIndices;
370: return(0);
371: }
373: /*@C ElementMatGetArray
374: This function allows access directly to the element matrix;
376: Collective on ElementMat
378: Input Parameters:
379: . mat - The element matrix
380:
381: Output Parameter:
382: . array - The array of values
384: Level: intermediate
386: .keywords element matrix, finite element
387: .seealso ElementMatCreate
388: @*/
389: int ElementMatGetArray(ElementMat mat, PetscScalar **array)
390: {
394: *array = mat->array;
395: return(0);
396: }
398: /*---------------------------------------------- Element Vector Functions -------------------------------------------*/
399: /*@C ElementVecCreate
400: This function creates an element vector for a finite element calculation.
402: Collective on MPI_Comm
404: Input Parameters:
405: + comm - The communicator to associate with the vector
406: - size - The number of local variables per element
408: Output Parameter:
409: . vec - The element vector
411: Level: beginner
413: .keywords: element vector
414: .seealso: ElementVecDestroy(), ElementMatCreate()
415: @*/
416: int ElementVecCreate(MPI_Comm comm, int size, ElementVec *vec)
417: {
418: ElementVec v;
419: int ierr;
423: *vec = PETSC_NULL;
424: #ifndef PETSC_USE_DYNAMIC_LIBRARIES
425: GridInitializePackage(PETSC_NULL);
426: #endif
428: PetscHeaderCreate(v, _ElementVec, int, ELEMENT_VEC_COOKIE, 0, "ElementVec", comm, ElementVecDestroy, 0);
429: PetscLogObjectCreate(v);
430: v->size = size;
431: v->reduceSize = size;
432: PetscMalloc(size * sizeof(PetscScalar), &v->array);
433: PetscMalloc(size * sizeof(int), &v->indices);
434: PetscLogObjectMemory(v, size * (sizeof(int) + sizeof(PetscScalar)));
435: *vec = v;
436: return(0);
437: }
439: /*@C ElementVecDestroy
440: This function destroys an element vector.
442: Not collective
444: Input Parameter:
445: . vec - The element vector
447: Level: beginner
449: .keywords: element vector
450: .seealso: ElementVecCreate(), ElementMatDestroy()
451: @*/
452: int ElementVecDestroy(ElementVec vec)
453: {
458: if (--vec->refct > 0)
459: return(0);
460: PetscFree(vec->array);
461: PetscFree(vec->indices);
462: PetscLogObjectDestroy(vec);
463: PetscHeaderDestroy(vec);
464: return(0);
465: }
467: /*@C ElementVecDuplicate
468: This function duplicates an element vector.
470: Collective on ElementVec
472: Input Parameter:
473: . vec - The original element vector
475: Output Parameter:
476: . newvec - The new element vector
478: Level: beginner
480: .keywords element vector, finite element
481: .seealso GridCalcElementVecIndices()
482: @*/
483: int ElementVecDuplicate(ElementVec vec, ElementVec *newvec)
484: {
490: ElementVecCreate(vec->comm, vec->size, newvec);
491: return(0);
492: }
494: /*@C ElementVecDuplicateIndices
495: This function copies the global vector indices to another element vector.
497: Collective on ElementVec
499: Input Parameter:
500: . vec - The original element vector
502: Output Parameter:
503: . newvec - The element vector with updated indices
505: Level: intermediate
507: .keywords element vector, finite element
508: .seealso GridCalcElementVecIndices()
509: @*/
510: int ElementVecDuplicateIndices(ElementVec vec, ElementVec newvec)
511: {
517: if (vec == newvec)
518: return(0);
519: if (vec->size != newvec->size) SETERRQ(PETSC_ERR_ARG_INCOMP, "Incompatible vector sizes");
520: PetscMemcpy(newvec->indices, vec->indices, vec->size * sizeof(int));
521: return(0);
522: }
524: /*@C ElementVecZero
525: This function sets all the entries in the element vector to zero.
527: Collective on ElementVec
529: Output Parameter:
530: . vec - The element vector
532: Level: beginner
534: .keywords: element vector
535: .seealso: ElementVecCreate()
536: @*/
537: int ElementVecZero(ElementVec vec)
538: {
543: PetscMemzero(vec->array, vec->size * sizeof(PetscScalar));
544: return(0);
545: }
547: /*@C ElementVecSetValues
548: This function puts all the entries in the element vector into
549: the global vector.
551: Collective on GVec
553: Input Parameters:
554: + vec - The element vector
555: - addv - The insertion mode
556:
557: Output Parameter:
558: . M - The global vector
560: Level: beginner
562: .keywords: element vector
563: .seealso: ElementVecCreate()
564: @*/
565: int ElementVecSetValues(ElementVec vec, GVec v, InsertMode addv)
566: {
570: /* Place entries in the global vector */
573: VecSetValues(v, vec->reduceSize, vec->indices, vec->array, addv);
574: vec->reduceSize = vec->size;
575: return(0);
576: }
578: /*@C ElementVecGetSize
579: This function returns the size of the element vector.
581: Not collective
583: Input Parameter:
584: . vec - The element vector
585:
586: Output Parameter:
587: + size - The number of rows
589: Level: intermediate
591: .keywords element vector, finite element
592: .seealso ElementVecGetReduceSize(), ElementVecCreate()
593: @*/
594: int ElementVecGetSize(ElementVec vec, int *size)
595: {
599: *size = vec->size;
600: return(0);
601: }
603: /*@C
604: ElementVecGetReduceSize - This function returns the size of the element vector
605: after all reductions have been carried out.
607: Not collective
609: Input Parameter:
610: . vec - The element vector
611:
612: Output Parameter:
613: + size - The number of rows
615: Level: intermediate
617: .keywords: element vector, finite element
618: .seealso: ElementVecGetSize(), ElementVecCreate()
619: @*/
620: int ElementVecGetReduceSize(ElementVec vec, int *size)
621: {
625: *size = vec->reduceSize;
626: return(0);
627: }
629: /*@C ElementVecGetIndices
630: This function returns the index mapping for the element vector.
632: Collective on ElementVec
634: Input Parameter:
635: . vec - The element vector
636:
637: Output Parameter:
638: . idx - The mapping
640: Level: intermediate
642: .keywords: element vector
643: .seealso: ElementVecCreate()
644: @*/
645: int ElementVecGetIndices(ElementVec vec, int **idx)
646: {
650: *idx = vec->indices;
651: return(0);
652: }
654: /*@C ElementVecGetArray
655: This function allows access directly to the element vector;
657: Collective on ElementVec
659: Input Parameter:
660: . vec - The element vector
661:
662: Output Parameter:
663: . array - The array of values
665: Level: intermediate
667: .keywords element vector, finite element
668: .seealso ElementVecRestoreArray(), ElementVecCreate()
669: @*/
670: int ElementVecGetArray(ElementVec vec, PetscScalar **array)
671: {
675: *array = vec->array;
676: return(0);
677: }
679: /*@C ElementVecRestoreArray
680: This function relinquishes access to the element vector;
682: Collective on ElementVec
684: Input Parameters:
685: + vec - The element vector
686: - array - The array of values
688: Level: intermediate
690: .keywords element vector, finite element
691: .seealso ElementVecGetArray(), ElementVecCreate()
692: @*/
693: int ElementVecRestoreArray(ElementVec vec, PetscScalar **array)
694: {
698: /* Right now we don't check */
699: return(0);
700: }
702: /*------------------------------------- Element Vector Index Calculation Functions ----------------------------------*/
703: /*@C
704: GridCalcElementVecIndices - This function calculates the global row indices for a particular element.
706: Not collective
708: Input Parameters:
709: + grid - The Grid
710: - elem - The element
712: Output Parameter:
713: . vec - The element vector
715: Level: advanced
717: .keywords: element vector, index
718: .seealso: GridCalcLocalElementVecIndices(), GridCalcInterpolationElementVecIndices(), GridCalcBoundaryElementVecIndices(),
719: ElementVecSetValues()
720: @*/
721: int GridCalcElementVecIndices(Grid grid, int elem, ElementVec vec)
722: {
726: GridCalcGeneralElementVecIndices(grid, elem, grid->order, PETSC_NULL, PETSC_FALSE, vec);
727: return(0);
728: }
730: /*@C
731: GridCalcLocalElementVecIndices - This function calculates the local row indices for a particular element.
733: Not collective
735: Input Parameters:
736: + grid - The Grid
737: - elem - The element
739: Output Parameter:
740: . vec - The element vector
742: Level: advanced
744: .keywords: element vector, index, local
745: .seealso: GridCalcElementVecIndices(), GridCalcInterpolationElementVecIndices(), GridCalcBoundaryElementVecIndices(),
746: ElementVecSetValues()
747: @*/
748: int GridCalcLocalElementVecIndices(Grid grid, int elem, ElementVec vec)
749: {
750: PetscTruth expConst;
751: int ierr;
754: GridGetExplicitConstraints(grid, &expConst);
755: if (expConst == PETSC_FALSE) {
756: GridCalcGeneralElementVecIndices(grid, elem, grid->order, PETSC_NULL, PETSC_TRUE, vec);
757: } else {
758: GridCalcGeneralElementVecIndices(grid, elem, grid->constraintOrder, PETSC_NULL, PETSC_TRUE, vec);
759: }
760: return(0);
761: }
763: /*@C
764: GridCalcGeneralElementVecIndices - This function calculates the row and column indices
765: for a particular element using alternate variable orderings.
767: Not collective
769: Input Parameters:
770: + grid - The Grid
771: . elem - The element
772: . order - The global variable ordering
773: . reductionOrder - The ordering on the reduction space, or PETSC_NULL for the default
774: - useLocal - The flag for local numbering of ghost nodes
776: Output Parameter:
777: . vec - The element vector
779: Level: advanced
781: .keywords: element vector, index, general
782: .seealso: ElementVecSetValues()
783: @*/
784: int GridCalcGeneralElementVecIndices(Grid grid, int elem, VarOrdering order, VarOrdering reductionOrder,
785: PetscTruth useLocal, ElementVec vec)
786: {
793: if (reductionOrder == PETSC_NULL) {
794: (*grid->ops->gridcalcelemvecidx)(grid, grid->mesh, elem, order, grid->reduceOrder, useLocal, PETSC_FALSE, vec);
795:
796: } else {
798: (*grid->ops->gridcalcelemvecidx)(grid, grid->mesh, elem, order, reductionOrder, useLocal, PETSC_FALSE, vec);
799:
800: }
801: return(0);
802: }
804: /*@C
805: GridCalcInterpolationElementVecIndices - This function calculates the local row indices for
806: a particular element using values of the previous mesh and ordering.
808: Not collective
810: Input Parameters:
811: + grid - The Grid
812: . mesh - The old mesh
813: . elem - The element
814: - order - The new global variable ordering
816: Output Parameter:
817: . vec - The element vector
819: Level: advanced
821: .keywords: element vector, index, interpolation
822: .seealso: GridCalcElementVecIndices(), GridCalcLocalElementVecIndices(), GridCalcBoundaryElementVecIndices(),
823: ElementVecSetValues()
824: @*/
825: int GridCalcInterpolationElementVecIndices(Grid grid, Mesh mesh, int elem, VarOrdering order, ElementVec vec)
826: {
834: (*grid->ops->gridcalcelemvecidx)(grid, mesh, elem, order, grid->reduceOrder, PETSC_TRUE, PETSC_TRUE, vec);
835:
836: return(0);
837: }
839: /*@C
840: GridCalcBoundaryElementVecIndices - This function calculates the global row indices for a particular boundary element.
842: Not collective
844: Input Parameters:
845: + grid - The discretization context
846: . bd - The boundary index
847: . edge - The boundary element
848: . midNode - The midnode on an edge, or -1 if none exists
849: . order - The new global variable ordering
850: - useLocal - The flag for local numbering of ghost nodes
852: Output Parameter:
853: . vec - The element vector
855: Note:
856: The boundary is specified by its index, not marker. Use
857: MeshGetBoundaryIndex() to retrieve this from the marker.
859: Level: advanced
861: .keywords element vector, index, boundary
862: .seealso: GridCalcElementVecIndices(), GridCalcLocalElementVecIndices(), GridCalcInterpolationElementVecIndices(),
863: ElementVecSetValues()
864: @*/
865: int GridCalcBoundaryElementVecIndices(Grid grid, int bd, int edge, int midNode, VarOrdering order, PetscTruth useLocal,
866: ElementVec vec)
867: {
874: if ((bd < 0) || (bd >= grid->numBd)) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE, "Invalid boundary index %d", bd);
875: (*grid->ops->gridcalcboundaryelemvecidx)(grid, bd, edge, midNode, order, grid->reduceOrder, useLocal, vec);
876:
877: return(0);
878: }
880: /*----------------------------------------- Element Vector Projection Functions -------------------------------------*/
881: /*@C
882: GridProjectElementVec - This function calculates the global row and column indices
883: for a particular element using alternate variable orderings, in the space constrained variables.
885: Not collective
887: Input Parameters:
888: + grid - The Grid
889: . mesh - The mesh
890: . elem - The element
891: . order - The global variable ordering
892: - constrain - The flag for constraining (applying P^T), or unconstraining (applying P)
894: Output Parameter:
895: . vec - The element vector
897: Level: advanced
899: .keywords: element vector, constraint, projection
900: .seealso: ElementVecSetValues()
901: @*/
902: int GridProjectElementVec(Grid grid, Mesh mesh, int elem, VarOrdering order, PetscTruth constrain, ElementVec vec)
903: {
909: (*grid->ops->gridprojectelemvec)(grid, mesh, elem, order, grid->reduceOrder, constrain, PETSC_FALSE, vec);
910:
911: return(0);
912: }
914: /*@C
915: GridProjectInterpolationElementVec - This function calculates the global row and column indices
916: for a particular element using alternate variable orderings, in the space constrained variables,
917: and uses the previous numbering constructs for interpolation.
919: Not collective
921: Input Parameters:
922: + grid - The Grid
923: . mesh - The mesh
924: . elem - The element
925: . order - The global variable ordering
926: - constrain - The flag for constraining (applying P^T), or unconstraining (applying P)
928: Output Parameter:
929: . vec - The element vector
931: Level: advanced
933: .keywords: element vector, constraint, projection
934: .seealso: ElementVecSetValues()
935: @*/
936: int GridProjectInterpolationElementVec(Grid grid, Mesh mesh, int elem, VarOrdering order, PetscTruth constrain, ElementVec vec)
937: {
943: (*grid->ops->gridprojectelemvec)(grid, mesh, elem, order, grid->reduceOrder, constrain, PETSC_TRUE, vec);
944:
945: return(0);
946: }
948: /*------------------------------------- Element Matrix Index Calculation Functions ----------------------------------*/
949: /*@C
950: GridCalcElementMatIndices - This function calculates the global row and column indices for a particular element.
952: Not collective
954: Input Parameters:
955: + grid - The Grid
956: - elem - The element
958: Output Parameter:
959: . mat - The element matrix
961: Level: advanced
963: .keywords: element matrix, index
964: .seealso: ElementMatSetValues()
965: @*/
966: int GridCalcElementMatIndices(Grid grid, int elem, ElementMat mat)
967: {
971: GridCalcGeneralElementMatIndices(grid, elem, grid->order, grid->order, PETSC_FALSE, mat);
972: return(0);
973: }
975: /*@C
976: GridCalcLocalElementMatIndices - This function calculates the local row and column indices for a particular element.
978: Not collective
980: Input Parameters:
981: + grid - The Grid
982: - elem - The element
984: Output Parameter:
985: . mat - The element matrix
987: Level: advanced
989: .keywords: element matrix, index, local
990: .seealso: ElementMatSetValues()
991: @*/
992: int GridCalcLocalElementMatIndices(Grid grid, int elem, ElementMat mat)
993: {
997: GridCalcGeneralElementMatIndices(grid, elem, grid->order, grid->order, PETSC_TRUE, mat);
998: return(0);
999: }
1001: /*@C
1002: GridCalcGeneralElementMatIndices - This function calculates the row and column indices
1003: for a particular element using alternate variable orderings.
1005: Not collective
1007: Input Parameters:
1008: + grid - The Grid
1009: . elem - The element
1010: . sOrder - The global variable ordering for the shape functions
1011: . tOrder - The global variable ordering for the test functions
1012: - useLocal - The flag for local numbering of ghost nodes
1014: Output Parameter:
1015: . mat - The element matrix
1017: Level: advanced
1019: .keywords: element matrix, index, general
1020: .seealso: ElementMatSetValues()
1021: @*/
1022: int GridCalcGeneralElementMatIndices(Grid grid, int elem, VarOrdering sOrder, VarOrdering tOrder, PetscTruth useLocal,
1023: ElementMat mat)
1024: {
1032: (*grid->ops->gridcalcelemmatidx)(grid, elem, sOrder, tOrder, grid->reduceOrder, useLocal, mat);
1033: return(0);
1034: }
1036: /*@C
1037: GridCalcBoundaryElementMatIndices - This function calculates the global row and column indices
1038: for a particular boundary element using alternate variable orderings.
1040: Not collective
1042: Input Parameters:
1043: + grid - The Grid
1044: . bd - The boundary index
1045: . edge - The canonical edge number
1046: . midNode - [Optional] The canonical node number of the midnode on the edge, or -1 if none exists
1047: . sOrder - The global variable ordering for the shape functions
1048: . tOrder - The global variable ordering for the test functions
1049: - useLocal - The flag for local numbering of ghost nodes
1051: Output Parameter:
1052: . mat - The element matrix
1054: Note:
1055: The boundary is specified by its index, not marker. Use
1056: MeshGetBoundaryIndex() to retrieve this from the marker.
1058: Level: advanced
1060: .keywords: element matrix, index, boundary
1061: .seealso: ElementMatSetValues()
1062: @*/
1063: int GridCalcBoundaryElementMatIndices(Grid grid, int bd, int edge, int midNode, VarOrdering sOrder, VarOrdering tOrder,
1064: PetscTruth useLocal, ElementMat mat)
1065: {
1073: if ((bd < 0) || (bd >= grid->numBd)) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE, "Invalid boundary index %d", bd);
1074: (*grid->ops->gridcalcboundaryelemmatidx)(grid, bd, edge, midNode, sOrder, tOrder, grid->reduceOrder, useLocal, mat);
1075:
1076: return(0);
1077: }