Actual source code: discretization.c
1: #ifdef PETSC_RCS_HEADER
2: static char vcid[] = "$Id: disc.c,v 1.3 2000/01/10 03:54:16 knepley Exp $";
3: #endif
5: /*
6: This is the interface to discretization objects
7: */
9: #include src/grid/discretization/discimpl.h
11: /* Logging support */
12: int DISCRETIZATION_COOKIE;
13: int DISCRETIZATION_EvaluateOperatorGalerkin;
15: /*------------------------------------------------- Generic Functions ------------------------------------------------*/
16: /*@
17: DiscretizationDestroy - Destroys a discretization object.
19: Collective on Discretization
21: Input Parameter:
22: . disc - The discretization
24: Level: beginner
26: .keywords: discretization, destroy
27: .seealso: DiscretizationView()
28: @*/
29: int DiscretizationDestroy(Discretization disc) {
30: int op, arg;
35: if (--disc->refct > 0) return(0);
36: if (disc->bdDisc != PETSC_NULL) {
37: DiscretizationDestroy(disc->bdDisc);
38: }
39: PetscFree(disc->quadPoints);
40: PetscFree(disc->quadWeights);
41: PetscFree(disc->quadShapeFuncs);
42: PetscFree(disc->quadShapeFuncDers);
43: PetscFree(disc->funcVal);
44: for(op = 0; op < disc->numOps; op++) {
45: if (disc->operators[op]->precompInt) {
46: PetscFree(disc->operators[op]->precompInt);
47: }
48: PetscFree(disc->operators[op]);
49: }
50: PetscFree(disc->operators);
51: for(arg = 0; arg < 2; arg++) {
52: PetscFree(disc->fieldVal[arg]);
53: }
54: PetscFree(disc->fieldVal);
55: (*disc->ops->destroy)(disc);
56: PetscLogObjectDestroy(disc);
57: PetscHeaderDestroy(disc);
58: return(0);
59: }
61: /*@
62: DiscretizationView - Views a discretization object.
64: Collective on Discretization
66: Input Parameters:
67: + disc - The disc context to distroy
68: - viewer - The viewer
70: Level: beginner
72: .keywords: discretization, view
73: .seealso: DiscretizationDestroy()
74: @*/
75: int DiscretizationView(Discretization disc, PetscViewer viewer)
76: {
81: if (viewer == PETSC_NULL) {
82: viewer = PETSC_VIEWER_STDOUT_SELF;
83: } else {
85: }
86: (*disc->ops->view)(disc, viewer);
87: return(0);
88: }
90: EXTERN_C_BEGIN
91: int DiscretizationSerialize_Generic(MPI_Comm comm, Discretization *disc, PetscViewer viewer, PetscTruth store) {
92: Discretization d;
93: int fd;
94: int len;
95: char *type_name = PETSC_NULL;
96: PetscTruth match;
97: int ierr;
103: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_BINARY, &match);
104: if (match == PETSC_FALSE) SETERRQ(PETSC_ERR_ARG_WRONG, "Must be binary viewer");
105: PetscViewerBinaryGetDescriptor(viewer, &fd);
107: if (store) {
108: d = *disc;
109: PetscStrlen(d->type_name, &len);
110: PetscBinaryWrite(fd, &len, 1, PETSC_INT, 0);
111: PetscBinaryWrite(fd, d->type_name, len, PETSC_CHAR, 0);
112: PetscBinaryWrite(fd, &d->comp, 1, PETSC_INT, 0);
113: PetscBinaryWrite(fd, &d->field, 1, PETSC_INT, 0);
114: } else {
115: DiscretizationCreate(comm, &d);
116: PetscBinaryRead(fd, &len, 1, PETSC_INT);
117: if (len) {
118: PetscMalloc((len+1) * sizeof(char), &type_name);
119: type_name[len] = 0;
120: }
121: PetscBinaryRead(fd, type_name, len, PETSC_CHAR);
122: PetscBinaryRead(fd, &d->comp, 1, PETSC_INT);
123: PetscBinaryRead(fd, &d->field, 1, PETSC_INT);
124: DiscretizationSetType(d, type_name);
125: if (len) {
126: PetscFree(type_name);
127: }
128: *disc = d;
129: }
131: return(0);
132: }
133: EXTERN_C_END
135: /*
136: DiscretizationSetTypeFromOptions - Sets the type of discretization from user options.
138: Collective on Discretization
140: Input Parameter:
141: . disc - The discretization
143: Level: intermediate
145: .keywords: Discretization, set, options, database, type
146: .seealso: DiscretizationSetFromOptions(), DiscretizationSetType()
147: */
148: static int DiscretizationSetTypeFromOptions(Discretization disc) {
149: PetscTruth opt;
150: char *defaultType;
151: char typeName[256];
152: int ierr;
155: if (disc->type_name != PETSC_NULL) {
156: defaultType = disc->type_name;
157: } else {
158: defaultType = DISCRETIZATION_TRIANGULAR_2D_LINEAR;
159: }
161: if (DiscretizationRegisterAllCalled == PETSC_FALSE) {
162: DiscretizationRegisterAll(PETSC_NULL);
163: }
164: PetscOptionsList("-disc_type", "Discretization method"," DiscretizationSetType", DiscretizationList, defaultType, typeName, 256, &opt);
165: if (opt == PETSC_TRUE) {
166: DiscretizationSetType(disc, typeName);
167: } else {
168: DiscretizationSetType(disc, defaultType);
169: }
170: return(0);
171: }
173: /*
174: DiscretizationSetSerializeTypeFromOptions - Sets the type of discretization serialization from user options.
176: Collective on Discretization
178: Input Parameter:
179: . disc - The discretization
181: Level: intermediate
183: .keywords: Discretization, set, options, database, type
184: .seealso: DiscretizationSetFromOptions(), DiscretizationSetSerializeType()
185: */
186: static int DiscretizationSetSerializeTypeFromOptions(Discretization disc) {
187: PetscTruth opt;
188: char *defaultType;
189: char typeName[256];
190: int ierr;
193: if (disc->serialize_name != PETSC_NULL) {
194: defaultType = disc->serialize_name;
195: } else {
196: defaultType = DISCRETIZATION_SER_GENERIC;
197: }
199: if (DiscretizationSerializeRegisterAllCalled == PETSC_FALSE) {
200: DiscretizationSerializeRegisterAll(PETSC_NULL);
201: }
202: PetscOptionsList("-disc_serialize_type", "Discretization serialization method"," DiscretizationSetSerializeType",
203: DiscretizationSerializeList, defaultType, typeName, 256, &opt);
204: if (opt == PETSC_TRUE) {
205: DiscretizationSetSerializeType(disc, typeName);
206: } else {
207: DiscretizationSetSerializeType(disc, defaultType);
208: }
209: return(0);
210: }
212: /*@
213: DiscretizationSetFromOptions - Sets various Discretization parameters from user options.
215: Collective on Discretization
217: Input Parameter:
218: . disc - The discretization
220: Notes: To see all options, run your program with the -help option, or consult the users manual.
221: Must be called after DiscretizationCreate() but before the Discretization is used.
223: Level: intermediate
225: .keywords: Discretization, set, options, database
226: .seealso: DiscretizationCreate(), DiscretizationPrintHelp(), DiscretizationSetOptionsPrefix()
227: @*/
228: int DiscretizationSetFromOptions(Discretization disc) {
229: Discretization bdDisc;
230: PetscTruth opt;
231: int ierr;
235: PetscOptionsBegin(disc->comm, disc->prefix, "Discretization options", "Discretization");
237: /* Handle generic disc options */
238: PetscOptionsHasName(PETSC_NULL, "-help", &opt);
239: if (opt == PETSC_TRUE) {
240: DiscretizationPrintHelp(disc);
241: }
243: /* Handle disc type options */
244: DiscretizationSetTypeFromOptions(disc);
246: /* Handle disc serialization options */
247: DiscretizationSetSerializeTypeFromOptions(disc);
249: /* Handle specific disc options */
250: if (disc->ops->setfromoptions != PETSC_NULL) {
251: (*disc->ops->setfromoptions)(disc);
252: }
254: PetscOptionsEnd();
256: /* Handle subobject options */
257: DiscretizationGetBoundaryDiscretization(disc, &bdDisc);
258: if (bdDisc != PETSC_NULL) {
259: DiscretizationSetFromOptions(bdDisc);
260: }
262: DiscretizationViewFromOptions(disc, disc->name);
263: return(0);
264: }
266: /*@
267: DiscretizationViewFromOptions - This function visualizes the discretization based upon user options.
269: Collective on Discretization
271: Input Parameter:
272: . disc - The discretization
274: Level: intermediate
276: .keywords: Discretization, view, options, database
277: .seealso: DiscretizationSetFromOptions(), DiscretizationView()
278: @*/
279: int DiscretizationViewFromOptions(Discretization disc, char *title) {
280: PetscViewer viewer;
281: PetscDraw draw;
282: PetscTruth opt;
283: char *titleStr;
284: char typeName[1024];
285: char fileName[1024];
286: int len;
287: int ierr;
290: PetscOptionsHasName(disc->prefix, "-disc_view", &opt);
291: if (opt == PETSC_TRUE) {
292: PetscOptionsGetString(disc->prefix, "-disc_view", typeName, 1024, &opt);
293: PetscStrlen(typeName, &len);
294: if (len > 0) {
295: PetscViewerCreate(disc->comm, &viewer);
296: PetscViewerSetType(viewer, typeName);
297: PetscOptionsGetString(disc->prefix, "-disc_view_file", fileName, 1024, &opt);
298: if (opt == PETSC_TRUE) {
299: PetscViewerSetFilename(viewer, fileName);
300: } else {
301: PetscViewerSetFilename(viewer, disc->name);
302: }
303: DiscretizationView(disc, viewer);
304: PetscViewerFlush(viewer);
305: PetscViewerDestroy(viewer);
306: } else {
307: DiscretizationView(disc, PETSC_NULL);
308: }
309: }
310: PetscOptionsHasName(disc->prefix, "-disc_view_draw", &opt);
311: if (opt == PETSC_TRUE) {
312: PetscViewerDrawOpen(disc->comm, 0, 0, 0, 0, 300, 300, &viewer);
313: PetscViewerDrawGetDraw(viewer, 0, &draw);
314: if (title != PETSC_NULL) {
315: titleStr = title;
316: } else {
317: PetscObjectName((PetscObject) disc); CHKERRQ(ierr) ;
318: titleStr = disc->name;
319: }
320: PetscDrawSetTitle(draw, titleStr);
321: DiscretizationView(disc, viewer);
322: PetscViewerFlush(viewer);
323: PetscDrawPause(draw);
324: PetscViewerDestroy(viewer);
325: }
326: return(0);
327: }
329: /*@
330: DiscretizationPrintHelp - Prints all options for the discretization.
332: Input Parameter:
333: . disc - The discretization
335: Options Database Keys:
336: $ -help, -h
338: Level: intermediate
340: .keywords: Discretization, help
341: .seealso: DiscretizationSetFromOptions()
342: @*/
343: int DiscretizationPrintHelp(Discretization disc) {
344: char p[64];
345: int ierr;
350: PetscStrcpy(p, "-");
351: if (disc->prefix != PETSC_NULL) {
352: PetscStrcat(p, disc->prefix);
353: }
355: (*PetscHelpPrintf)(disc->comm, "Discretization options ------------------------------------------------n");
356: (*PetscHelpPrintf)(disc->comm," %sdisc_type <typename> : Sets the discretization typen", p);
357: return(0);
358: }
360: /*@C
361: DiscretizationSetOptionsPrefix - Sets the prefix used for searching for all discretization options in the database.
363: Input Parameters:
364: + disc - The discretization
365: - prefix - The prefix to prepend to all option names
367: Notes:
368: A hyphen (-) must NOT be given at the beginning of the prefix name.
369: The first character of all runtime options is AUTOMATICALLY the hyphen.
371: Level: intermediate
373: .keywords: Discretization, set, options, prefix, database
374: .seealso: DiscretizationSetFromOptions()
375: @*/
376: int DiscretizationSetOptionsPrefix(Discretization disc, char *prefix) {
381: PetscObjectSetOptionsPrefix((PetscObject) disc, prefix);
382: return(0);
383: }
385: /*@C
386: DiscretizationAppendOptionsPrefix - Appends to the prefix used for searching for all discretization options in the database.
388: Collective on Discretization
390: Input Parameters:
391: + disc - The discretization
392: - prefix - The prefix to prepend to all option names
394: Notes:
395: A hyphen (-) must NOT be given at the beginning of the prefix name.
396: The first character of all runtime options is AUTOMATICALLY the hyphen.
398: Level: intermediate
400: .keywords: Discretization, append, options, prefix, database
401: .seealso: DiscretizationGetOptionsPrefix()
402: @*/
403: int DiscretizationAppendOptionsPrefix(Discretization disc, char *prefix) {
405:
408: PetscObjectAppendOptionsPrefix((PetscObject) disc, prefix);
409: return(0);
410: }
412: /*@C
413: DiscretizationGetOptionsPrefix - Sets the prefix used for searching for all discretization options in the database.
415: Input Parameter:
416: . disc - The discretization
418: Output Parameter:
419: . prefix - A pointer to the prefix string used
421: Level: intermediate
423: .keywords: Discretization, get, options, prefix, database
424: .seealso: DiscretizationAppendOptionsPrefix()
425: @*/
426: int DiscretizationGetOptionsPrefix(Discretization disc, char **prefix) {
431: PetscObjectGetOptionsPrefix((PetscObject) disc, prefix);
432: return(0);
433: }
435: /*@
436: DiscretizationSetupDefaultOperators - Adds the default set of operators to the discretization if they are
437: not already present.
439: Input Parameter:
440: . disc - The discretization
442: Level: intermediate
444: .keywords: Discretization, default, operator
445: .seealso: DiscretizationSetup(), DiscretizationSerialize()
446: @*/
447: int DiscretizationSetupDefaultOperators(Discretization disc) {
452: if (disc->numOps > 0) return(0);
453: (*disc->ops->setupoperators)(disc);
454: return(0);
455: }
457: /*-------------------------------------------------- Query Functions -------------------------------------------------*/
458: /*@C
459: DiscretizationSetNumComponents - This function sets the number of components in the field being discretized.
461: Not collective
463: Input Parameters:
464: . disc - The discretization
465: . numComp - The number of components in the field
467: Level: intermediate
469: .keywords discretization, component, field
470: .seealso DiscretizationCreate(), DiscretizationRegisterOperator()
471: @*/
472: int DiscretizationSetNumComponents(Discretization disc, int numComp) {
475: if (numComp <= 0) SETERRQ(PETSC_ERR_ARG_WRONG, "Discretization msut have at least one component");
476: disc->comp = numComp;
477: return(0);
478: }
480: /*@C
481: DiscretizationGetNumComponents - This function returns the number of components in the field being discretized.
483: Not collective
485: Input Parameter:
486: . disc - The discretization
488: Output Parameter:
489: . numComp - The number of components in the field
491: Level: intermediate
493: .keywords discretization, component, field
494: .seealso DiscretizationCreate(), DiscretizationRegisterOperator()
495: @*/
496: int DiscretizationGetNumComponents(Discretization disc, int *numComp) {
500: *numComp = disc->comp;
501: return(0);
502: }
504: /*@C
505: DiscretizationGetNumFunctions - This function returns the number of functions per element in the Discretization.
507: Not collective
509: Input Parameter:
510: . disc - The discretization
512: Output Parameter:
513: . numFunc - The number of functions per element
515: Level: intermediate
517: .keywords discretization, functions
518: .seealso DiscretizationCreate(), DiscretizationRegisterOperator()
519: @*/
520: int DiscretizationGetNumFunctions(Discretization disc, int *numFunc) {
524: *numFunc = disc->funcs;
525: return(0);
526: }
528: /*@C
529: DiscretizationGetBoundaryDiscretization - This function returns boundary discretization, or PETSC_NULL if none exists.
531: Not collective
533: Input Parameter:
534: . disc - The discretization
536: Output Parameter:
537: . bdDisc - The boundary discretization, or PETSC_NULL
539: Level: intermediate
541: .keywords discretization, functions
542: .seealso DiscretizationCreate(), DiscretizationRegisterOperator()
543: @*/
544: int DiscretizationGetBoundaryDiscretization(Discretization disc, Discretization *bdDisc) {
548: *bdDisc = disc->bdDisc;
549: return(0);
550: }
552: /*@C
553: DiscretizationSetField - This function sets the corresponding field in the Grid for this Discretization.
555: Not collective
557: Input Parameters:
558: . disc - The discretization
559: . field - The corresponding field in the Grid
561: Level: intermediate
563: .keywords Discretization, component, field
564: .seealso DiscretizationGetField(), DiscretizationCreate(), DiscretizationRegisterOperator()
565: @*/
566: int DiscretizationSetField(Discretization disc, int field) {
569: /* Could possibly validate with an associated Grid */
570: disc->field = field;
571: return(0);
572: }
574: /*@C
575: DiscretizationGetField - This function gets the corresponding field in the Grid for this Discretization.
577: Not collective
579: Input Parameter:
580: . disc - The discretization
582: Output Parameter:
583: . field - The corresponding field in the Grid
585: Level: intermediate
587: .keywords discretization, component, field
588: .seealso DiscretizationSetField(), DiscretizationCreate(), DiscretizationRegisterOperator()
589: @*/
590: int DiscretizationGetField(Discretization disc, int *field) {
594: *field = disc->field;
595: return(0);
596: }
598: /*--------------------------------------------- Quadrature Query Functions -------------------------------------------*/
599: /*@C
600: DiscretizationGetNumQuadraturePoints - This function returns the number of points used in the element quadrature.
602: Not collective
604: Input Parameter:
605: . disc - The discretization
607: Output Parameter:
608: . numPoints - The number of quadrature points
610: Level: intermediate
612: .keywords discretization, quadrature, points
613: .seealso DiscretizationCreate(), DiscretizationRegisterOperator()
614: @*/
615: int DiscretizationGetNumQuadraturePoints(Discretization disc, int *numPoints) {
619: *numPoints = disc->numQuadPoints;
620: return(0);
621: }
623: /*@C
624: DiscretizationGetQuadraturePoints - This function returns the coordinates of each quadrature point.
626: Not collective
628: Input Parameter:
629: . disc - The discretization
631: Output Parameter:
632: . coords - The quadrature point coordinates
634: Level: intermediate
636: .keywords discretization, quadrature, coordinates, points
637: .seealso DiscretizationCreate(), DiscretizationRegisterOperator()
638: @*/
639: int DiscretizationGetQuadraturePoints(Discretization disc, double **coords) {
643: *coords = disc->quadPoints;
644: return(0);
645: }
647: /*@C
648: DiscretizationGetQuadratureWeights - This function returns the weight associated with each quadrature point.
650: Not collective
652: Input Parameter:
653: . disc - The discretization
655: Output Parameter:
656: . weights - The quadrature weights
658: Level: intermediate
660: .keywords discretization, quadrature, weights
661: .seealso DiscretizationCreate(), DiscretizationRegisterOperator()
662: @*/
663: int DiscretizationGetQuadratureWeights(Discretization disc, double **weights) {
667: *weights = disc->quadWeights;
668: return(0);
669: }
671: /*@C
672: DiscretizationGetQuadratureFunctions - This function returns each shape function evaluated at the quadrature points.
674: Not collective
676: Input Parameter:
677: . disc - The discretization
679: Output Parameter:
680: . funcs - The shape functions evaluated at the quadrature points
682: Level: intermediate
684: .keywords discretization, quadrature, functions
685: .seealso DiscretizationCreate(), DiscretizationRegisterOperator()
686: @*/
687: int DiscretizationGetQuadratureFunctions(Discretization disc, double **funcs) {
691: *funcs = disc->quadShapeFuncs;
692: return(0);
693: }
695: /*@C
696: DiscretizationGetQuadratureDerivatives - This function returns the derivatives of each shape function evaluated
697: at the quadrature points.
699: Not collective
701: Input Parameter:
702: . disc - The discretization
704: Output Parameter:
705: . ders - The shape function derivatives evaluated at the quadrature points
707: Level: intermediate
709: .keywords discretization, quadrature, derivatives
710: .seealso DiscretizationCreate(), DiscretizationRegisterOperator()
711: @*/
712: int DiscretizationGetQuadratureDerivatives(Discretization disc, double **ders) {
716: *ders = disc->quadShapeFuncDers;
717: return(0);
718: }
720: /*----------------------------------------------- Registration Functions ---------------------------------------------*/
721: static int DiscretizationRegisterOperator_Private(Discretization disc, PetscScalar *precompInt, OperatorFunction func,
722: ALEOperatorFunction ALEFunc, int *newOp)
723: {
724: Operator *tempOperators;
725: Operator op;
726: int ierr;
729: while (disc->numOps >= disc->maxOps) {
730: PetscMalloc(disc->maxOps*2 * sizeof(Operator), &tempOperators);
731: PetscLogObjectMemory(disc, disc->maxOps * sizeof(Operator));
732: PetscMemcpy(tempOperators, disc->operators, disc->maxOps * sizeof(Operator));
733: PetscFree(disc->operators);
734: disc->operators = tempOperators;
735: disc->maxOps *= 2;
736: }
737: /* Create the new operator */
738: PetscNew(struct _Operator, &op);
739: PetscLogObjectMemory(disc, sizeof(struct _Operator));
740: op->precompInt = precompInt;
741: op->test = PETSC_NULL;
742: op->opFunc = func;
743: op->ALEOpFunc = ALEFunc;
744: disc->operators[disc->numOps] = op;
745: *newOp = disc->numOps;
746: disc->numOps++;
747: return(0);
748: }
750: /*@C
751: DiscretizationRegisterOperator - This function defines a new operator
753: Collective on Discretization
755: Input Parameters:
756: + disc - The discretization
757: - func - The function defining the operator
759: Output Parameter:
760: . newOp - The index of the new operator
762: Level: advanced
764: .keywords Discretization, operator, register
765: .seealso DiscretizationRegisterALEOperator(), GridAddMatOperator(), GridAddRhsOperator()
766: @*/
767: int DiscretizationRegisterOperator(Discretization disc, OperatorFunction func, int *newOp) {
773: DiscretizationRegisterOperator_Private(disc, PETSC_NULL, func, PETSC_NULL, newOp);
774: return(0);
775: }
777: /*@C
778: DiscretizationRegisterALEOperator - This function defines a new ALE operator
780: Collective on Discretization
782: Input Parameters:
783: + disc - The discretization
784: - func - The function deinfing the operator
786: Output Parameter:
787: . newOp - The index of the new operator
789: Level: advanced
791: .keywords Discretization, operator, register
792: .seealso DiscretizationRegisterOperator(), GridAddMatOperator(), GridAddRhsOperator()
793: @*/
794: int DiscretizationRegisterALEOperator(Discretization disc, ALEOperatorFunction func, int *newOp) {
800: DiscretizationRegisterOperator_Private(disc, PETSC_NULL, PETSC_NULL, func, newOp);
801: return(0);
802: }
804: /*@C
805: DiscretizationRegisterPrecomputedOperator - This function defines a new operator for which the integral can be precomputed .
806: This requires knowledge of the discretization itself and the storage format, and thus is only useful for developers.
808: Collective on Discretization
810: Input Parameters:
811: + disc - The discretization
812: - precompInt - The array of precomputed values
814: Output Parameter:
815: . newOp - The index of the new operator
817: Level: developer
819: .keywords Discretization, operator, register
820: .seealso DiscretizationRegisterALEOperator(), GridAddMatOperator(), GridAddRhsOperator()
821: @*/
822: int DiscretizationRegisterPrecomputedOperator(Discretization disc, PetscScalar *precompInt, int *newOp) {
829: DiscretizationRegisterOperator_Private(disc, precompInt, PETSC_NULL, PETSC_NULL, newOp);
830: return(0);
831: }
833: /*------------------------------------------------ Evaluation Functions ----------------------------------------------*/
834: /*@
835: DiscretizationEvaluateFunctionGalerkin - This function calculates the
836: weak form of a function over a single element.
838: Collective on Discretization
840: Input Parameters:
841: + disc - The discretization
842: . mesh - The associated mesh
843: . f - The PointFunction of which we want the weak form
844: . alpha - A scalar multiplier
845: . elem - The local element number
846: - ctx - The user-supplied context
848: Output Parameter:
849: . v - The element vector for the given element
851: Level: beginner
853: .keywords: discretization, function, weak form
854: .seealso: DiscretizationEvaluateOperatorGalerkin(), DiscretizationEvaluateNonlinearOperatorGalerkin()
855: @*/
856: int DiscretizationEvaluateFunctionGalerkin(Discretization disc, Mesh mesh, PointFunction f, PetscScalar alpha, int elem, PetscScalar *v, void *ctx)
857: {
864: (*(disc->ops->evaluatefunctiongalerkin))(disc, mesh, f, alpha, elem, v, ctx);
865: return(0);
866: }
868: /*@
869: DiscretizationEvaluateOperatorGalerkin - This function calculates the
870: weak form of an operator over a single element.
872: Collective on Discretization
874: Input Parameters:
875: + disc - The discretization for the basis functions
876: . mesh - The associated mesh
877: . elemSize - The size of the element matrix
878: . rowStart - The starting row index in the element matrix
879: . colStart - The starting column index in the element matrix
880: . op - The operator index (of registered operators)
881: . alpha - The scalar multiple of the operator
882: . elem - The local element number
883: . field - The field values
884: - ctx - The user-supplied context
886: Output Parameter:
887: . mat - The element matrix for the given element
889: Level: beginner
891: .keywords: discretization, operator, weak form
892: .seealso: DiscretizationEvaluateFunctionGalerkin(), DiscretizationEvaluateALEOperatorGalerkin(), DiscretizationEvaluateOperatorGalerkinMF(),
893: DiscretizationEvaluateNonlinearOperatorGalerkin()
894: @*/
895: int DiscretizationEvaluateOperatorGalerkin(Discretization disc, Mesh mesh, int elemSize, int rowStart, int colStart,
896: int op, PetscScalar alpha, int elem, PetscScalar *field, PetscScalar *mat, void *ctx)
897: {
903: /* field may be PETSC_NULL */
905: (*(disc->ops->evaluateoperatorgalerkin))(disc, mesh, elemSize, rowStart, colStart, op, alpha, elem,
906: field, mat, ctx);
907:
908: return(0);
909: }
911: /*@
912: DiscretizationEvaluateALEOperatorGalerkin - This function calculates the
913: weak form of an operator over a single element.
915: Collective on Discretization
917: Input Parameters:
918: + disc - The discretization for the basis functions
919: . mesh - The associated mesh
920: . elemSize - The size of the element matrix
921: . rowStart - The starting row index in the element matrix
922: . colStart - The starting column index in the element matrix
923: . op - The operator index (of registered operators)
924: . alpha - The scalar multiple of the operator
925: . elem - The local element number
926: . field - The field values
927: . ALEfield - The mesh velocity field values
928: - ctx - The user-supplied context
930: Output Parameter:
931: . mat - The element matrix for the given element
933: Level: beginner
935: .keywords: discretization, operator, ALE, weak form
936: .seealso: DiscretizationEvaluateOperatorGalerkin()
937: @*/
938: int DiscretizationEvaluateALEOperatorGalerkin(Discretization disc, Mesh mesh, int elemSize, int rowStart, int colStart,
939: int op, PetscScalar alpha, int elem, PetscScalar *field, PetscScalar *ALEfield, PetscScalar *mat, void *ctx)
940: {
946: /* field may be PETSC_NULL */
949: (*(disc->ops->evaluatealeoperatorgalerkin))(disc, mesh, elemSize, rowStart, colStart, op, alpha, elem,
950: field, ALEfield, mat, ctx);
951:
952: return(0);
953: }
955: /*@
956: DiscretizationEvaluateOperatorGalerkinMF - This function calculates the
957: weak form of the action of an operator over a single element.
959: Collective on Discretization
961: Input Parameters:
962: + disc - The discretization
963: . mesh - The associated mesh
964: . elemSize - The size of the element matrix
965: . rowStart - The starting row index in the element matrix
966: . colStart - The starting column index in the element matrix
967: . op - The operator index (of registered operators)
968: . alpha - The scalar multiple of the operator
969: . elem - The local element number
970: . field - The element vector for the grid vector acted upon
971: . app - The element vector to which to apply the matrix, usually identical to field
972: . mat - A temporary element matrix for work space
973: - ctx - The user-supplied context
975: Output Parameter:
976: . vec - The element vector for the given element
978: Level: beginner
980: .keywords: discretization, operator, MF, weak form
981: .seealso: DiscretizationEvaluateOperatorGalerkin()
982: @*/
983: int DiscretizationEvaluateOperatorGalerkinMF(Discretization disc, Mesh mesh, int elemSize, int rowStart, int colStart, int op,
984: PetscScalar alpha, int elem, PetscScalar *field, PetscScalar *app, PetscScalar *vec, PetscScalar *mat, void *ctx)
985: {
986: Discretization test; /* The space of test functions */
987: int rowSize; /* The number of shape functions per element */
988: int colSize; /* The number of test functions per element */
989: int i, j;
990: int ierr;
993: /* Get discretization info */
996: /* field may be PETSC_NULL */
999: test = disc->operators[op]->test;
1001: rowSize = test->size;
1002: colSize = disc->size;
1004: DiscretizationEvaluateOperatorGalerkin(disc, mesh, elemSize, rowStart, colStart, op, alpha, elem, field, mat, ctx);
1005:
1006: /* Perform the local element matvec */
1007: for(i = 0; i < rowSize; i++)
1008: for(j = 0; j < colSize; j++)
1009: vec[i+rowStart] += mat[(i+rowStart)*elemSize+j+colStart]*app[j];
1010: PetscLogFlops(2*rowSize*colSize);
1011: return(0);
1012: }
1014: /*@
1015: DiscretizationEvaluateALEOperatorGalerkinMF - This function calculates the
1016: weak form of the action of an operator over a single element.
1018: Collective on Discretization
1020: Input Parameters:
1021: + disc - The discretization
1022: . mesh - The associated mesh
1023: . elemSize - The size of the element matrix
1024: . rowStart - The starting row index in the element matrix
1025: . colStart - The starting column index in the element matrix
1026: . op - The operator index (of registered operators)
1027: . alpha - The scalar multiple of the operator
1028: . elem - The local element number
1029: . field - The element vector for the grid vector acted upon
1030: . app - The element vector to which to apply the matrix, usually identical to field
1031: . ALEfield - The element vector for the ALE velocity field
1032: . mat - A temporary element matrix for work space
1033: - ctx - The user-supplied context
1035: Output Parameter:
1036: . vec - The element vector for the given element
1038: Level: beginner
1040: .keywords: discretization, operator, ALE, MF, weak form
1041: .seealso: DiscretizationEvaluateOperatorGalerkin()
1042: @*/
1043: int DiscretizationEvaluateALEOperatorGalerkinMF(Discretization disc, Mesh mesh, int elemSize, int rowStart, int colStart, int op,
1044: PetscScalar alpha, int elem, PetscScalar *field, PetscScalar *app, PetscScalar *ALEfield, PetscScalar *vec,
1045: PetscScalar *mat, void *ctx)
1046: {
1047: Discretization test; /* The space of test functions */
1048: int rowSize; /* The number of shape functions per element */
1049: int colSize; /* The number of test functions per element */
1050: int i, j;
1051: int ierr;
1054: /* Get discretization info */
1057: /* field may be PETSC_NULL */
1061: test = disc->operators[op]->test;
1063: rowSize = test->size;
1064: colSize = disc->size;
1066: DiscretizationEvaluateALEOperatorGalerkin(disc, mesh, elemSize, rowStart, colStart, op, alpha, elem, field, ALEfield, mat, ctx);
1067:
1068: /* Perform the local element matvec */
1069: for(i = 0; i < rowSize; i++)
1070: for(j = 0; j < colSize; j++)
1071: vec[i+rowStart] += mat[(i+rowStart)*elemSize+j+colStart]*app[j];
1072: PetscLogFlops(2*rowSize*colSize);
1073: return(0);
1074: }
1076: /*@
1077: DiscretizationEvaluateNonlinearOperatorGalerkin - This function calculates the
1078: weak form of a nonlinear operator over a single element.
1080: Collective on Discretization
1082: Input Parameters:
1083: + disc - The discretization
1084: . mesh - The associated mesh
1085: . op - The function defining the nonlinear operator
1086: . alpha - A scalar multiplier
1087: . elem - The local element number
1088: . numArgs - THe number of input element vectors
1089: . field - The element vectors for the grid vectors acted upon
1090: - ctx - The user-supplied context
1092: Output Parameter:
1093: . vec - The global element vector for the given element
1095: Level: beginner
1097: .keywords: discretization, operator, nonlinear, weak form
1098: .seealso: DiscretizationEvaluateFunctionGalerkin(), DiscretizationEvaluateOperatorGalerkin(), DiscretizationEvaluateNonlinearALEOperatorGalerkin()
1099: @*/
1100: int DiscretizationEvaluateNonlinearOperatorGalerkin(Discretization disc, Mesh mesh, NonlinearOperator op, PetscScalar alpha, int elem,
1101: int numArgs, PetscScalar **field, PetscScalar *vec, void *ctx)
1102: {
1110: (*(disc->ops->evaluatenonlinearoperatorgalerkin))(disc, mesh, op, alpha, elem, numArgs, field, vec, ctx);
1111:
1112: return(0);
1113: }
1115: /*@
1116: DiscretizationEvaluateNonlinearALEOperatorGalerkin - This function calculates the
1117: weak form of a nonlinear operator over a single element.
1119: Input Parameters:
1120: + disc - The discretization
1121: . mesh - The associated mesh
1122: . op - The function defining the nonlinear operator
1123: . alpha - A scalar multiplier
1124: . elem - The local element number
1125: . numArgs - THe number of input element vectors
1126: . field - The element vectors for the grid vectors acted upon
1127: . ALEfield - The element vector for the mesh velocity field
1128: - ctx - The user-supplied context
1130: Output Parameter:
1131: . vec - The global element vector for the given element
1133: Level: beginner
1135: .keywords: discretization, operator, nonlinear, ALE, weak form
1136: .seealso: DiscretizationEvaluateFunctionGalerkin(), DiscretizationEvaluateOperatorGalerkin(), DiscretizationEvaluateNonlinearOperatorGalerkin()
1137: @*/
1138: int DiscretizationEvaluateNonlinearALEOperatorGalerkin(Discretization disc, Mesh mesh, NonlinearOperator op, PetscScalar alpha, int elem,
1139: int numArgs, PetscScalar **field, PetscScalar *ALEfield, PetscScalar *vec, void *ctx)
1140: {
1149: (*(disc->ops->evaluatenonlinearaleoperatorgalerkin))(disc, mesh, op, alpha, elem, numArgs, field, ALEfield, vec, ctx);
1150:
1151: return(0);
1152: }
1154: /*---------------------------------------------- Interpolation Functions ---------------------------------------------*/
1155: /*@
1156: DiscretizationInterpolateField - This function interpolates a field at a given point.
1158: Collective on Discretization
1160: Input Parameters:
1161: + disc - The discretization
1162: . mesh - The associated mesh
1163: . elem - The element containing the point
1164: . x,y,z - The interpolation point
1165: . oldFieldVal - The element vector for 'elem'
1166: - type - The method of interpolation, e.g. INTERPOLATION_LOCAL
1168: Output Parameter:
1169: . newFieldVal - The field components at the given point
1171: Level: beginner
1173: .keywords: discretization, interpolation
1174: .seealso: DiscretizationInterpolateElementVec()
1175: @*/
1176: int DiscretizationInterpolateField(Discretization disc, Mesh mesh, int elem, double x, double y, double z,
1177: PetscScalar *oldFieldVal, PetscScalar *newFieldVal, InterpolationType type)
1178: {
1186: (*disc->ops->interpolatefield)(disc, mesh, elem, x, y, z, oldFieldVal, newFieldVal, type);
1187: return(0);
1188: }
1190: /*@
1191: DiscretizationInterpolateElementVec - Interpolates a given element vector from one discretization to another.
1193: Input Parameters:
1194: + disc - The original discretization
1195: . vec - The original element vector
1196: - newDisc - The discretization defining the new element vector
1198: Output Parameter:
1199: . newVec - The interpolated element vector
1201: Level: beginner
1203: .keywords: discretization, interpolation
1204: .seealso: DiscretizationInterpolateField()
1205: @*/
1206: int DiscretizationInterpolateElementVec(Discretization disc, ElementVec vec, Discretization newDisc, ElementVec newVec) {
1207: int size, newSize;
1215: if (disc->comp != newDisc->comp) SETERRQ(PETSC_ERR_ARG_INCOMP, "Fields must have the same number of components");
1216: ElementVecGetSize(vec, &size);
1217: ElementVecGetSize(newVec, &newSize);
1218: if ((disc->size > size) || (newDisc->size > newSize)) SETERRQ(PETSC_ERR_ARG_WRONG, "Element vector is too small to contain field");
1219: (*disc->ops->interpolateelemvec)(disc, vec, newDisc, newVec);
1220: return(0);
1221: }