xref: /petsc/src/dm/dt/interface/dtweakform.c (revision 5fedec97950c19de564efaecd0f125b1a6cb2b20)
16528b96dSMatthew G. Knepley #include <petsc/private/petscdsimpl.h> /*I "petscds.h" I*/
26528b96dSMatthew G. Knepley 
36528b96dSMatthew G. Knepley PetscClassId PETSCWEAKFORM_CLASSID = 0;
46528b96dSMatthew G. Knepley 
506ad1575SMatthew G. Knepley const char *const PetscWeakFormKinds[] = {"objective", "residual_f0", "residual_f1", "jacobian_g0", "jacobian_g1", "jacobian_g2", "jacobian_g3", "jacobian_preconditioner_g0", "jacobian_preconditioner_g1", "jacobian_preconditioner_g2", "jacobian_preconditioner_g3", "dynamic_jacobian_g0", "dynamic_jacobian_g1", "dynamic_jacobian_g2", "dynamic_jacobian_g3", "boundary_residual_f0", "boundary_residual_f1", "boundary_jacobian_g0", "boundary_jacobian_g1", "boundary_jacobian_g2", "boundary_jacobian_g3", "boundary_jacobian_preconditioner_g0", "boundary_jacobian_preconditioner_g1", "boundary_jacobian_preconditioner_g2", "boundary_jacobian_preconditioner_g3", "riemann_solver", "PetscWeakFormKind", "PETSC_WF_", NULL};
606ad1575SMatthew G. Knepley 
76528b96dSMatthew G. Knepley static PetscErrorCode PetscChunkBufferCreate(size_t unitbytes, size_t expected, PetscChunkBuffer **buffer)
86528b96dSMatthew G. Knepley {
96528b96dSMatthew G. Knepley   PetscErrorCode ierr;
106528b96dSMatthew G. Knepley 
116528b96dSMatthew G. Knepley   PetscFunctionBegin;
126528b96dSMatthew G. Knepley   ierr = PetscNew(buffer);CHKERRQ(ierr);
136528b96dSMatthew G. Knepley   ierr = PetscCalloc1(expected*unitbytes, &(*buffer)->array);CHKERRQ(ierr);
146528b96dSMatthew G. Knepley   (*buffer)->size      = expected;
156528b96dSMatthew G. Knepley   (*buffer)->unitbytes = unitbytes;
166528b96dSMatthew G. Knepley   (*buffer)->alloc     = expected*unitbytes;
176528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
186528b96dSMatthew G. Knepley }
196528b96dSMatthew G. Knepley 
2045480ffeSMatthew G. Knepley static PetscErrorCode PetscChunkBufferDuplicate(PetscChunkBuffer *buffer, PetscChunkBuffer **bufferNew)
2145480ffeSMatthew G. Knepley {
2245480ffeSMatthew G. Knepley   PetscErrorCode ierr;
2345480ffeSMatthew G. Knepley 
2445480ffeSMatthew G. Knepley   PetscFunctionBegin;
2545480ffeSMatthew G. Knepley   ierr = PetscNew(bufferNew);CHKERRQ(ierr);
2645480ffeSMatthew G. Knepley   ierr = PetscCalloc1(buffer->size*buffer->unitbytes, &(*bufferNew)->array);CHKERRQ(ierr);
2745480ffeSMatthew G. Knepley   ierr = PetscMemcpy((*bufferNew)->array, buffer->array, buffer->size*buffer->unitbytes);CHKERRQ(ierr);
2845480ffeSMatthew G. Knepley   (*bufferNew)->size      = buffer->size;
2945480ffeSMatthew G. Knepley   (*bufferNew)->unitbytes = buffer->unitbytes;
3045480ffeSMatthew G. Knepley   (*bufferNew)->alloc     = buffer->size*buffer->unitbytes;
3145480ffeSMatthew G. Knepley   PetscFunctionReturn(0);
3245480ffeSMatthew G. Knepley }
3345480ffeSMatthew G. Knepley 
346528b96dSMatthew G. Knepley static PetscErrorCode PetscChunkBufferDestroy(PetscChunkBuffer **buffer)
356528b96dSMatthew G. Knepley {
366528b96dSMatthew G. Knepley   PetscErrorCode ierr;
376528b96dSMatthew G. Knepley 
386528b96dSMatthew G. Knepley   PetscFunctionBegin;
396528b96dSMatthew G. Knepley   ierr = PetscFree((*buffer)->array);CHKERRQ(ierr);
406528b96dSMatthew G. Knepley   ierr = PetscFree(*buffer);CHKERRQ(ierr);
416528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
426528b96dSMatthew G. Knepley }
436528b96dSMatthew G. Knepley 
446528b96dSMatthew G. Knepley static PetscErrorCode PetscChunkBufferCreateChunk(PetscChunkBuffer *buffer, PetscInt size, PetscChunk *chunk)
456528b96dSMatthew G. Knepley {
466528b96dSMatthew G. Knepley   PetscErrorCode ierr;
476528b96dSMatthew G. Knepley 
486528b96dSMatthew G. Knepley   PetscFunctionBegin;
496528b96dSMatthew G. Knepley   if ((buffer->size + size)*buffer->unitbytes > buffer->alloc) {
506528b96dSMatthew G. Knepley     char *tmp;
516528b96dSMatthew G. Knepley 
526528b96dSMatthew G. Knepley     if (!buffer->alloc) buffer->alloc = (buffer->size + size)*buffer->unitbytes;
536528b96dSMatthew G. Knepley     while ((buffer->size + size)*buffer->unitbytes > buffer->alloc) buffer->alloc *= 2;
546528b96dSMatthew G. Knepley     ierr = PetscMalloc(buffer->alloc, &tmp);CHKERRQ(ierr);
556528b96dSMatthew G. Knepley     ierr = PetscMemcpy(tmp, buffer->array, buffer->size*buffer->unitbytes);CHKERRQ(ierr);
566528b96dSMatthew G. Knepley     ierr = PetscFree(buffer->array);CHKERRQ(ierr);
576528b96dSMatthew G. Knepley     buffer->array = tmp;
586528b96dSMatthew G. Knepley   }
592baeeceeSMatthew G. Knepley   chunk->start    = buffer->size*buffer->unitbytes;
606528b96dSMatthew G. Knepley   chunk->size     = size;
616528b96dSMatthew G. Knepley   chunk->reserved = size;
626528b96dSMatthew G. Knepley   buffer->size   += size;
636528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
646528b96dSMatthew G. Knepley }
656528b96dSMatthew G. Knepley 
666528b96dSMatthew G. Knepley static PetscErrorCode PetscChunkBufferEnlargeChunk(PetscChunkBuffer *buffer, PetscInt size, PetscChunk *chunk)
676528b96dSMatthew G. Knepley {
686528b96dSMatthew G. Knepley   size_t         siz = size;
696528b96dSMatthew G. Knepley   PetscErrorCode ierr;
706528b96dSMatthew G. Knepley 
716528b96dSMatthew G. Knepley   PetscFunctionBegin;
726528b96dSMatthew G. Knepley   if (chunk->size + size > chunk->reserved) {
736528b96dSMatthew G. Knepley     PetscChunk newchunk;
746528b96dSMatthew G. Knepley     PetscInt   reserved = chunk->size;
756528b96dSMatthew G. Knepley 
766528b96dSMatthew G. Knepley     /* TODO Here if we had a chunk list, we could update them all to reclaim unused space */
776528b96dSMatthew G. Knepley     while (reserved < chunk->size+size) reserved *= 2;
786528b96dSMatthew G. Knepley     ierr = PetscChunkBufferCreateChunk(buffer, (size_t) reserved, &newchunk);CHKERRQ(ierr);
796528b96dSMatthew G. Knepley     newchunk.size = chunk->size+size;
806528b96dSMatthew G. Knepley     ierr = PetscMemcpy(&buffer->array[newchunk.start], &buffer->array[chunk->start], chunk->size * buffer->unitbytes);CHKERRQ(ierr);
816528b96dSMatthew G. Knepley     *chunk = newchunk;
826528b96dSMatthew G. Knepley   } else {
836528b96dSMatthew G. Knepley     chunk->size += siz;
846528b96dSMatthew G. Knepley   }
856528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
866528b96dSMatthew G. Knepley }
876528b96dSMatthew G. Knepley 
886528b96dSMatthew G. Knepley /*@C
8906ad1575SMatthew G. Knepley   PetscFormKeySort - Sorts an array of PetscFormKey in place in increasing order.
906528b96dSMatthew G. Knepley 
916528b96dSMatthew G. Knepley   Not Collective
926528b96dSMatthew G. Knepley 
936528b96dSMatthew G. Knepley   Input Parameters:
946528b96dSMatthew G. Knepley + n - number of values
9506ad1575SMatthew G. Knepley - X - array of PetscFormKey
966528b96dSMatthew G. Knepley 
976528b96dSMatthew G. Knepley   Level: intermediate
986528b96dSMatthew G. Knepley 
996528b96dSMatthew G. Knepley .seealso: PetscIntSortSemiOrdered(), PetscSortInt()
1006528b96dSMatthew G. Knepley @*/
10106ad1575SMatthew G. Knepley PetscErrorCode PetscFormKeySort(PetscInt n, PetscFormKey arr[])
1026528b96dSMatthew G. Knepley {
1036528b96dSMatthew G. Knepley   PetscErrorCode ierr;
1046528b96dSMatthew G. Knepley 
1056528b96dSMatthew G. Knepley   PetscFunctionBegin;
1066528b96dSMatthew G. Knepley   if (n <= 1) PetscFunctionReturn(0);
1076528b96dSMatthew G. Knepley   PetscValidPointer(arr, 2);
10806ad1575SMatthew G. Knepley   ierr = PetscTimSort(n, arr, sizeof(PetscFormKey), Compare_PetscFormKey_Private, NULL);CHKERRQ(ierr);
1096528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
1106528b96dSMatthew G. Knepley }
1116528b96dSMatthew G. Knepley 
11206ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormGetFunction_Private(PetscWeakForm wf, PetscHMapForm ht, DMLabel label, PetscInt value, PetscInt f, PetscInt part, PetscInt *n, void (***func)())
1136528b96dSMatthew G. Knepley {
11406ad1575SMatthew G. Knepley   PetscFormKey   key;
1156528b96dSMatthew G. Knepley   PetscChunk     chunk;
1166528b96dSMatthew G. Knepley   PetscErrorCode ierr;
1176528b96dSMatthew G. Knepley 
1186528b96dSMatthew G. Knepley   PetscFunctionBegin;
11906ad1575SMatthew G. Knepley   key.label = label; key.value = value; key.field = f; key.part = part;
1206528b96dSMatthew G. Knepley   ierr = PetscHMapFormGet(ht, key, &chunk);CHKERRQ(ierr);
1216528b96dSMatthew G. Knepley   if (chunk.size < 0) {*n = 0;          *func = NULL;}
1222baeeceeSMatthew G. Knepley   else                {*n = chunk.size; *func = (void (**)()) &wf->funcs->array[chunk.start];}
1236528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
1246528b96dSMatthew G. Knepley }
1256528b96dSMatthew G. Knepley 
1266528b96dSMatthew G. Knepley /* A NULL argument for func causes this to clear the key */
12706ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormSetFunction_Private(PetscWeakForm wf, PetscHMapForm ht, DMLabel label, PetscInt value, PetscInt f, PetscInt part, PetscInt n, void (**func)())
1286528b96dSMatthew G. Knepley {
12906ad1575SMatthew G. Knepley   PetscFormKey   key;
1306528b96dSMatthew G. Knepley   PetscChunk     chunk;
1316528b96dSMatthew G. Knepley   PetscInt       i;
1326528b96dSMatthew G. Knepley   PetscErrorCode ierr;
1336528b96dSMatthew G. Knepley 
1346528b96dSMatthew G. Knepley   PetscFunctionBegin;
13506ad1575SMatthew G. Knepley   key.label = label; key.value = value; key.field = f; key.part = part;
1366528b96dSMatthew G. Knepley   if (!func) {
1376528b96dSMatthew G. Knepley     ierr = PetscHMapFormDel(ht, key);CHKERRQ(ierr);
1386528b96dSMatthew G. Knepley     PetscFunctionReturn(0);
1396528b96dSMatthew G. Knepley   } else {
1406528b96dSMatthew G. Knepley     ierr = PetscHMapFormGet(ht, key, &chunk);CHKERRQ(ierr);
1416528b96dSMatthew G. Knepley   }
1426528b96dSMatthew G. Knepley   if (chunk.size < 0) {
1436528b96dSMatthew G. Knepley     ierr = PetscChunkBufferCreateChunk(wf->funcs, n, &chunk);CHKERRQ(ierr);
1446528b96dSMatthew G. Knepley     ierr = PetscHMapFormSet(ht, key, chunk);CHKERRQ(ierr);
1456528b96dSMatthew G. Knepley   } else if (chunk.size <= n) {
1466528b96dSMatthew G. Knepley     ierr = PetscChunkBufferEnlargeChunk(wf->funcs, n - chunk.size, &chunk);CHKERRQ(ierr);
1476528b96dSMatthew G. Knepley     ierr = PetscHMapFormSet(ht, key, chunk);CHKERRQ(ierr);
1486528b96dSMatthew G. Knepley   }
1492baeeceeSMatthew G. Knepley   for (i = 0; i < n; ++i) ((void (**)()) &wf->funcs->array[chunk.start])[i] = func[i];
1506528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
1516528b96dSMatthew G. Knepley }
1526528b96dSMatthew G. Knepley 
15306ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormAddFunction_Private(PetscWeakForm wf, PetscHMapForm ht, DMLabel label, PetscInt value, PetscInt f, PetscInt part, void (*func)())
1546528b96dSMatthew G. Knepley {
15506ad1575SMatthew G. Knepley   PetscFormKey   key;
1566528b96dSMatthew G. Knepley   PetscChunk     chunk;
1576528b96dSMatthew G. Knepley   PetscErrorCode ierr;
1586528b96dSMatthew G. Knepley 
1596528b96dSMatthew G. Knepley   PetscFunctionBegin;
1606528b96dSMatthew G. Knepley   if (!func) PetscFunctionReturn(0);
16106ad1575SMatthew G. Knepley   key.label = label; key.value = value; key.field = f; key.part = part;
1626528b96dSMatthew G. Knepley   ierr = PetscHMapFormGet(ht, key, &chunk);CHKERRQ(ierr);
1636528b96dSMatthew G. Knepley   if (chunk.size < 0) {
1646528b96dSMatthew G. Knepley     ierr = PetscChunkBufferCreateChunk(wf->funcs, 1, &chunk);CHKERRQ(ierr);
1656528b96dSMatthew G. Knepley     ierr = PetscHMapFormSet(ht, key, chunk);CHKERRQ(ierr);
1662baeeceeSMatthew G. Knepley     ((void (**)()) &wf->funcs->array[chunk.start])[0] = func;
1676528b96dSMatthew G. Knepley   } else {
1686528b96dSMatthew G. Knepley     ierr = PetscChunkBufferEnlargeChunk(wf->funcs, 1, &chunk);CHKERRQ(ierr);
1696528b96dSMatthew G. Knepley     ierr = PetscHMapFormSet(ht, key, chunk);CHKERRQ(ierr);
1702baeeceeSMatthew G. Knepley     ((void (**)()) &wf->funcs->array[chunk.start])[chunk.size-1] = func;
1716528b96dSMatthew G. Knepley   }
1726528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
1736528b96dSMatthew G. Knepley }
1746528b96dSMatthew G. Knepley 
17506ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormGetIndexFunction_Private(PetscWeakForm wf, PetscHMapForm ht, DMLabel label, PetscInt value, PetscInt f, PetscInt part, PetscInt ind, void (**func)())
1766528b96dSMatthew G. Knepley {
17706ad1575SMatthew G. Knepley   PetscFormKey key;
1786528b96dSMatthew G. Knepley   PetscChunk       chunk;
1796528b96dSMatthew G. Knepley   PetscErrorCode   ierr;
1806528b96dSMatthew G. Knepley 
1816528b96dSMatthew G. Knepley   PetscFunctionBegin;
18206ad1575SMatthew G. Knepley   key.label = label; key.value = value; key.field = f; key.part = part;
1836528b96dSMatthew G. Knepley   ierr = PetscHMapFormGet(ht, key, &chunk);CHKERRQ(ierr);
1846528b96dSMatthew G. Knepley   if (chunk.size < 0) {*func = NULL;}
1856528b96dSMatthew G. Knepley   else {
1866528b96dSMatthew G. Knepley     if (ind >= chunk.size) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Index %D not in [0, %D)", ind, chunk.size);
1872baeeceeSMatthew G. Knepley     *func = ((void (**)()) &wf->funcs->array[chunk.start])[ind];
1886528b96dSMatthew G. Knepley   }
1896528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
1906528b96dSMatthew G. Knepley }
1916528b96dSMatthew G. Knepley 
19206ad1575SMatthew G. Knepley /* Ignore a NULL func */
19306ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormSetIndexFunction_Private(PetscWeakForm wf, PetscHMapForm ht, DMLabel label, PetscInt value, PetscInt f, PetscInt part, PetscInt ind, void (*func)())
1946528b96dSMatthew G. Knepley {
19506ad1575SMatthew G. Knepley   PetscFormKey key;
1966528b96dSMatthew G. Knepley   PetscChunk       chunk;
1976528b96dSMatthew G. Knepley   PetscErrorCode   ierr;
1986528b96dSMatthew G. Knepley 
1996528b96dSMatthew G. Knepley   PetscFunctionBegin;
20006ad1575SMatthew G. Knepley   if (!func) PetscFunctionReturn(0);
20106ad1575SMatthew G. Knepley   key.label = label; key.value = value; key.field = f; key.part = part;
2026528b96dSMatthew G. Knepley   ierr = PetscHMapFormGet(ht, key, &chunk);CHKERRQ(ierr);
2036528b96dSMatthew G. Knepley   if (chunk.size < 0) {
2046528b96dSMatthew G. Knepley     ierr = PetscChunkBufferCreateChunk(wf->funcs, ind+1, &chunk);CHKERRQ(ierr);
2056528b96dSMatthew G. Knepley     ierr = PetscHMapFormSet(ht, key, chunk);CHKERRQ(ierr);
2066528b96dSMatthew G. Knepley   } else if (chunk.size <= ind) {
2076528b96dSMatthew G. Knepley     ierr = PetscChunkBufferEnlargeChunk(wf->funcs, ind - chunk.size + 1, &chunk);CHKERRQ(ierr);
2086528b96dSMatthew G. Knepley     ierr = PetscHMapFormSet(ht, key, chunk);CHKERRQ(ierr);
2096528b96dSMatthew G. Knepley   }
2102baeeceeSMatthew G. Knepley   ((void (**)()) &wf->funcs->array[chunk.start])[ind] = func;
2116528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
2126528b96dSMatthew G. Knepley }
2136528b96dSMatthew G. Knepley 
21406ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormClearIndexFunction_Private(PetscWeakForm wf, PetscHMapForm ht, DMLabel label, PetscInt value, PetscInt f, PetscInt part, PetscInt ind)
21506ad1575SMatthew G. Knepley {
21606ad1575SMatthew G. Knepley   PetscFormKey key;
21706ad1575SMatthew G. Knepley   PetscChunk       chunk;
21806ad1575SMatthew G. Knepley   PetscErrorCode   ierr;
21906ad1575SMatthew G. Knepley 
22006ad1575SMatthew G. Knepley   PetscFunctionBegin;
22106ad1575SMatthew G. Knepley   key.label = label; key.value = value; key.field = f; key.part = part;
22206ad1575SMatthew G. Knepley   ierr = PetscHMapFormGet(ht, key, &chunk);CHKERRQ(ierr);
22306ad1575SMatthew G. Knepley   if (chunk.size < 0) {
22406ad1575SMatthew G. Knepley     PetscFunctionReturn(0);
22506ad1575SMatthew G. Knepley   } else if (!ind && chunk.size == 1) {
22606ad1575SMatthew G. Knepley     ierr = PetscHMapFormDel(ht, key);CHKERRQ(ierr);
22706ad1575SMatthew G. Knepley     PetscFunctionReturn(0);
22806ad1575SMatthew G. Knepley   } else if (chunk.size <= ind) {
22906ad1575SMatthew G. Knepley     PetscFunctionReturn(0);
23006ad1575SMatthew G. Knepley   }
23106ad1575SMatthew G. Knepley   ((void (**)()) &wf->funcs->array[chunk.start])[ind] = NULL;
23206ad1575SMatthew G. Knepley   PetscFunctionReturn(0);
23306ad1575SMatthew G. Knepley }
23406ad1575SMatthew G. Knepley 
23545480ffeSMatthew G. Knepley /*@
23645480ffeSMatthew G. Knepley   PetscWeakFormCopy - Copy the pointwise functions to another PetscWeakForm
23745480ffeSMatthew G. Knepley 
23845480ffeSMatthew G. Knepley   Not Collective
23945480ffeSMatthew G. Knepley 
24045480ffeSMatthew G. Knepley   Input Parameter:
24145480ffeSMatthew G. Knepley . wf - The original PetscWeakForm
24245480ffeSMatthew G. Knepley 
24345480ffeSMatthew G. Knepley   Output Parameter:
24445480ffeSMatthew G. Knepley . wfNew - The copy PetscWeakForm
24545480ffeSMatthew G. Knepley 
24645480ffeSMatthew G. Knepley   Level: intermediate
24745480ffeSMatthew G. Knepley 
24845480ffeSMatthew G. Knepley .seealso: PetscWeakFormCreate(), PetscWeakFormDestroy()
24945480ffeSMatthew G. Knepley @*/
25045480ffeSMatthew G. Knepley PetscErrorCode PetscWeakFormCopy(PetscWeakForm wf, PetscWeakForm wfNew)
25145480ffeSMatthew G. Knepley {
25206ad1575SMatthew G. Knepley   PetscInt       f;
25345480ffeSMatthew G. Knepley   PetscErrorCode ierr;
25445480ffeSMatthew G. Knepley 
25545480ffeSMatthew G. Knepley   PetscFunctionBegin;
25645480ffeSMatthew G. Knepley   wfNew->Nf = wf->Nf;
25745480ffeSMatthew G. Knepley   ierr = PetscChunkBufferDestroy(&wfNew->funcs);CHKERRQ(ierr);
25845480ffeSMatthew G. Knepley   ierr = PetscChunkBufferDuplicate(wf->funcs, &wfNew->funcs);CHKERRQ(ierr);
25906ad1575SMatthew G. Knepley   for (f = 0; f < PETSC_NUM_WF; ++f) {
26006ad1575SMatthew G. Knepley     ierr = PetscHMapFormDestroy(&wfNew->form[f]);CHKERRQ(ierr);
26106ad1575SMatthew G. Knepley     ierr = PetscHMapFormDuplicate(wf->form[f], &wfNew->form[f]);CHKERRQ(ierr);
26206ad1575SMatthew G. Knepley   }
26306ad1575SMatthew G. Knepley   PetscFunctionReturn(0);
26406ad1575SMatthew G. Knepley }
26506ad1575SMatthew G. Knepley 
26606ad1575SMatthew G. Knepley /*@
26706ad1575SMatthew G. Knepley   PetscWeakFormClear - Clear all functions from the PetscWeakForm
26806ad1575SMatthew G. Knepley 
26906ad1575SMatthew G. Knepley   Not Collective
27006ad1575SMatthew G. Knepley 
27106ad1575SMatthew G. Knepley   Input Parameter:
27206ad1575SMatthew G. Knepley . wf - The original PetscWeakForm
27306ad1575SMatthew G. Knepley 
27406ad1575SMatthew G. Knepley   Level: intermediate
27506ad1575SMatthew G. Knepley 
27606ad1575SMatthew G. Knepley .seealso: PetscWeakFormCopy(), PetscWeakFormCreate(), PetscWeakFormDestroy()
27706ad1575SMatthew G. Knepley @*/
27806ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormClear(PetscWeakForm wf)
27906ad1575SMatthew G. Knepley {
28006ad1575SMatthew G. Knepley   PetscInt       f;
28106ad1575SMatthew G. Knepley   PetscErrorCode ierr;
28206ad1575SMatthew G. Knepley 
28306ad1575SMatthew G. Knepley   PetscFunctionBegin;
28406ad1575SMatthew G. Knepley   for (f = 0; f < PETSC_NUM_WF; ++f) {ierr = PetscHMapFormClear(wf->form[f]);CHKERRQ(ierr);}
28545480ffeSMatthew G. Knepley   PetscFunctionReturn(0);
28645480ffeSMatthew G. Knepley }
28745480ffeSMatthew G. Knepley 
28845480ffeSMatthew G. Knepley static PetscErrorCode PetscWeakFormRewriteKeys_Internal(PetscWeakForm wf, PetscHMapForm hmap, DMLabel label, PetscInt Nv, const PetscInt values[])
28945480ffeSMatthew G. Knepley {
29006ad1575SMatthew G. Knepley   PetscFormKey  *keys;
29145480ffeSMatthew G. Knepley   PetscInt       n, i, v, off = 0;
29245480ffeSMatthew G. Knepley   PetscErrorCode ierr;
29345480ffeSMatthew G. Knepley 
29445480ffeSMatthew G. Knepley   PetscFunctionBegin;
29545480ffeSMatthew G. Knepley   ierr = PetscHMapFormGetSize(hmap, &n);CHKERRQ(ierr);
29645480ffeSMatthew G. Knepley   ierr = PetscMalloc1(n, &keys);CHKERRQ(ierr);
29745480ffeSMatthew G. Knepley   ierr = PetscHMapFormGetKeys(hmap, &off, keys);CHKERRQ(ierr);
29845480ffeSMatthew G. Knepley   for (i = 0; i < n; ++i) {
29945480ffeSMatthew G. Knepley     if (keys[i].label == label) {
30045480ffeSMatthew G. Knepley       PetscBool clear = PETSC_TRUE;
30145480ffeSMatthew G. Knepley       void   (**funcs)();
30245480ffeSMatthew G. Knepley       PetscInt  Nf;
30345480ffeSMatthew G. Knepley 
30406ad1575SMatthew G. Knepley       ierr = PetscWeakFormGetFunction_Private(wf, hmap, keys[i].label, keys[i].value, keys[i].field, keys[i].part, &Nf, &funcs);CHKERRQ(ierr);
30545480ffeSMatthew G. Knepley       for (v = 0; v < Nv; ++v) {
30606ad1575SMatthew G. Knepley         ierr = PetscWeakFormSetFunction_Private(wf, hmap, keys[i].label, values[v], keys[i].field, keys[i].part, Nf, funcs);CHKERRQ(ierr);
30745480ffeSMatthew G. Knepley         if (values[v] == keys[i].value) clear = PETSC_FALSE;
30845480ffeSMatthew G. Knepley       }
30906ad1575SMatthew G. Knepley       if (clear) {ierr = PetscWeakFormSetFunction_Private(wf, hmap, keys[i].label, keys[i].value, keys[i].field, keys[i].part, 0, NULL);CHKERRQ(ierr);}
31045480ffeSMatthew G. Knepley     }
31145480ffeSMatthew G. Knepley   }
31245480ffeSMatthew G. Knepley   ierr = PetscFree(keys);CHKERRQ(ierr);
31345480ffeSMatthew G. Knepley   PetscFunctionReturn(0);
31445480ffeSMatthew G. Knepley }
31545480ffeSMatthew G. Knepley 
31645480ffeSMatthew G. Knepley /*@C
31745480ffeSMatthew G. Knepley   PetscWeakFormRewriteKeys - Change any key on the given label to use the new set of label values
31845480ffeSMatthew G. Knepley 
31945480ffeSMatthew G. Knepley   Not Collective
32045480ffeSMatthew G. Knepley 
32145480ffeSMatthew G. Knepley   Input Parameters:
32245480ffeSMatthew G. Knepley + wf     - The original PetscWeakForm
32345480ffeSMatthew G. Knepley . label  - The label to change keys for
32445480ffeSMatthew G. Knepley . Nv     - The number of new label values
32545480ffeSMatthew G. Knepley - values - The set of new values to relabel keys with
32645480ffeSMatthew G. Knepley 
32745480ffeSMatthew G. Knepley   Note: This is used internally when boundary label values are specified from the command line.
32845480ffeSMatthew G. Knepley 
32945480ffeSMatthew G. Knepley   Level: intermediate
33045480ffeSMatthew G. Knepley 
331d700741fSMatthew G. Knepley .seealso: PetscWeakFormReplaceLabel(), PetscWeakFormCreate(), PetscWeakFormDestroy()
33245480ffeSMatthew G. Knepley @*/
33345480ffeSMatthew G. Knepley PetscErrorCode PetscWeakFormRewriteKeys(PetscWeakForm wf, DMLabel label, PetscInt Nv, const PetscInt values[])
33445480ffeSMatthew G. Knepley {
33506ad1575SMatthew G. Knepley   PetscInt       f;
33645480ffeSMatthew G. Knepley   PetscErrorCode ierr;
33745480ffeSMatthew G. Knepley 
33845480ffeSMatthew G. Knepley   PetscFunctionBegin;
33906ad1575SMatthew G. Knepley   for (f = 0; f < PETSC_NUM_WF; ++f) {ierr = PetscWeakFormRewriteKeys_Internal(wf, wf->form[f], label, Nv, values);CHKERRQ(ierr);}
34045480ffeSMatthew G. Knepley   PetscFunctionReturn(0);
34145480ffeSMatthew G. Knepley }
34245480ffeSMatthew G. Knepley 
343d700741fSMatthew G. Knepley static PetscErrorCode PetscWeakFormReplaceLabel_Internal(PetscWeakForm wf, PetscHMapForm hmap, DMLabel label)
344d700741fSMatthew G. Knepley {
345d700741fSMatthew G. Knepley   PetscFormKey  *keys;
346d700741fSMatthew G. Knepley   PetscInt       n, i, off = 0, maxFuncs = 0;
347d700741fSMatthew G. Knepley   void       (**tmpf)();
348d700741fSMatthew G. Knepley   const char    *name = NULL;
349d700741fSMatthew G. Knepley   PetscErrorCode ierr;
350d700741fSMatthew G. Knepley 
351d700741fSMatthew G. Knepley   PetscFunctionBegin;
352d700741fSMatthew G. Knepley   if (label) {ierr = PetscObjectGetName((PetscObject) label, &name);CHKERRQ(ierr);}
353d700741fSMatthew G. Knepley   ierr = PetscHMapFormGetSize(hmap, &n);CHKERRQ(ierr);
354d700741fSMatthew G. Knepley   ierr = PetscMalloc1(n, &keys);CHKERRQ(ierr);
355d700741fSMatthew G. Knepley   ierr = PetscHMapFormGetKeys(hmap, &off, keys);CHKERRQ(ierr);
356d700741fSMatthew G. Knepley   for (i = 0; i < n; ++i) {
357d700741fSMatthew G. Knepley     PetscBool   match = PETSC_FALSE;
358d700741fSMatthew G. Knepley     const char *lname = NULL;
359d700741fSMatthew G. Knepley 
360d700741fSMatthew G. Knepley     if (label == keys[i].label) continue;
361d700741fSMatthew G. Knepley     if (keys[i].label) {ierr = PetscObjectGetName((PetscObject) keys[i].label, &lname);CHKERRQ(ierr);}
362d700741fSMatthew G. Knepley     ierr = PetscStrcmp(name, lname, &match);CHKERRQ(ierr);
363d700741fSMatthew G. Knepley     if ((!name && !lname) || match) {
364d700741fSMatthew G. Knepley       void  (**funcs)();
365d700741fSMatthew G. Knepley       PetscInt Nf;
366d700741fSMatthew G. Knepley 
367d700741fSMatthew G. Knepley       ierr = PetscWeakFormGetFunction_Private(wf, hmap, keys[i].label, keys[i].value, keys[i].field, keys[i].part, &Nf, &funcs);CHKERRQ(ierr);
368d700741fSMatthew G. Knepley       maxFuncs = PetscMax(maxFuncs, Nf);
369d700741fSMatthew G. Knepley     }
370d700741fSMatthew G. Knepley   }
371d700741fSMatthew G. Knepley   /* Need temp space because chunk buffer can be reallocated in SetFunction() call */
372d700741fSMatthew G. Knepley   ierr = PetscMalloc1(maxFuncs, &tmpf);CHKERRQ(ierr);
373d700741fSMatthew G. Knepley   for (i = 0; i < n; ++i) {
374d700741fSMatthew G. Knepley     PetscBool   match = PETSC_FALSE;
375d700741fSMatthew G. Knepley     const char *lname = NULL;
376d700741fSMatthew G. Knepley 
377d700741fSMatthew G. Knepley     if (label == keys[i].label) continue;
378d700741fSMatthew G. Knepley     if (keys[i].label) {ierr = PetscObjectGetName((PetscObject) keys[i].label, &lname);CHKERRQ(ierr);}
379d700741fSMatthew G. Knepley     ierr = PetscStrcmp(name, lname, &match);CHKERRQ(ierr);
380d700741fSMatthew G. Knepley     if ((!name && !lname) || match) {
381d700741fSMatthew G. Knepley       void  (**funcs)();
382d700741fSMatthew G. Knepley       PetscInt Nf, j;
383d700741fSMatthew G. Knepley 
384d700741fSMatthew G. Knepley       ierr = PetscWeakFormGetFunction_Private(wf, hmap, keys[i].label, keys[i].value, keys[i].field, keys[i].part, &Nf, &funcs);CHKERRQ(ierr);
385d700741fSMatthew G. Knepley       for (j = 0; j < Nf; ++j) tmpf[j] = funcs[j];
386d700741fSMatthew G. Knepley       ierr = PetscWeakFormSetFunction_Private(wf, hmap, label,         keys[i].value, keys[i].field, keys[i].part,  Nf,  tmpf);CHKERRQ(ierr);
387d700741fSMatthew G. Knepley       ierr = PetscWeakFormSetFunction_Private(wf, hmap, keys[i].label, keys[i].value, keys[i].field, keys[i].part,  0,   NULL);CHKERRQ(ierr);
388d700741fSMatthew G. Knepley     }
389d700741fSMatthew G. Knepley   }
390d700741fSMatthew G. Knepley   ierr = PetscFree(tmpf);CHKERRQ(ierr);
391d700741fSMatthew G. Knepley   ierr = PetscFree(keys);CHKERRQ(ierr);
392d700741fSMatthew G. Knepley   PetscFunctionReturn(0);
393d700741fSMatthew G. Knepley }
394d700741fSMatthew G. Knepley 
395d700741fSMatthew G. Knepley /*@C
396d700741fSMatthew G. Knepley   PetscWeakFormReplaceLabel - Change any key on a label of the same name to use the new label
397d700741fSMatthew G. Knepley 
398d700741fSMatthew G. Knepley   Not Collective
399d700741fSMatthew G. Knepley 
400d700741fSMatthew G. Knepley   Input Parameters:
401d700741fSMatthew G. Knepley + wf    - The original PetscWeakForm
402d700741fSMatthew G. Knepley - label - The label to change keys for
403d700741fSMatthew G. Knepley 
404d700741fSMatthew G. Knepley   Note: This is used internally when meshes are modified
405d700741fSMatthew G. Knepley 
406d700741fSMatthew G. Knepley   Level: intermediate
407d700741fSMatthew G. Knepley 
408d700741fSMatthew G. Knepley .seealso: PetscWeakFormRewriteKeys(), PetscWeakFormCreate(), PetscWeakFormDestroy()
409d700741fSMatthew G. Knepley @*/
410d700741fSMatthew G. Knepley PetscErrorCode PetscWeakFormReplaceLabel(PetscWeakForm wf, DMLabel label)
411d700741fSMatthew G. Knepley {
412d700741fSMatthew G. Knepley   PetscInt       f;
413d700741fSMatthew G. Knepley   PetscErrorCode ierr;
414d700741fSMatthew G. Knepley 
415d700741fSMatthew G. Knepley   PetscFunctionBegin;
416d700741fSMatthew G. Knepley   for (f = 0; f < PETSC_NUM_WF; ++f) {ierr = PetscWeakFormReplaceLabel_Internal(wf, wf->form[f], label);CHKERRQ(ierr);}
417d700741fSMatthew G. Knepley   PetscFunctionReturn(0);
418d700741fSMatthew G. Knepley }
419d700741fSMatthew G. Knepley 
42006ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormClearIndex(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt part, PetscWeakFormKind kind, PetscInt ind)
42106ad1575SMatthew G. Knepley {
42206ad1575SMatthew G. Knepley   PetscErrorCode ierr;
42306ad1575SMatthew G. Knepley 
42406ad1575SMatthew G. Knepley   PetscFunctionBegin;
42506ad1575SMatthew G. Knepley   ierr = PetscWeakFormClearIndexFunction_Private(wf, wf->form[kind], label, val, f, part, ind);CHKERRQ(ierr);
42606ad1575SMatthew G. Knepley   PetscFunctionReturn(0);
42706ad1575SMatthew G. Knepley }
42806ad1575SMatthew G. Knepley 
42906ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormGetObjective(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt part, PetscInt *n,
4306528b96dSMatthew G. Knepley                                          void (***obj)(PetscInt, PetscInt, PetscInt,
4316528b96dSMatthew G. Knepley                                                        const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
4326528b96dSMatthew G. Knepley                                                        const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
4336528b96dSMatthew G. Knepley                                                        PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
4346528b96dSMatthew G. Knepley {
4356528b96dSMatthew G. Knepley   PetscErrorCode ierr;
4366528b96dSMatthew G. Knepley 
4376528b96dSMatthew G. Knepley   PetscFunctionBegin;
43806ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->form[PETSC_WF_OBJECTIVE], label, val, f, part, n, (void (***)(void)) obj);CHKERRQ(ierr);
4396528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
4406528b96dSMatthew G. Knepley }
4416528b96dSMatthew G. Knepley 
44206ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormSetObjective(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt part, PetscInt n,
4436528b96dSMatthew G. Knepley                                          void (**obj)(PetscInt, PetscInt, PetscInt,
4446528b96dSMatthew G. Knepley                                                       const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const  PetscScalar[],
4456528b96dSMatthew G. Knepley                                                       const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
4466528b96dSMatthew G. Knepley                                                       PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
4476528b96dSMatthew G. Knepley {
4486528b96dSMatthew G. Knepley   PetscErrorCode ierr;
4496528b96dSMatthew G. Knepley 
4506528b96dSMatthew G. Knepley   PetscFunctionBegin;
45106ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->form[PETSC_WF_OBJECTIVE], label, val, f, part, n, (void (**)(void)) obj);CHKERRQ(ierr);
4526528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
4536528b96dSMatthew G. Knepley }
4546528b96dSMatthew G. Knepley 
45506ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormAddObjective(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt part,
4566528b96dSMatthew G. Knepley                                          void (*obj)(PetscInt, PetscInt, PetscInt,
4576528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
4586528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
4596528b96dSMatthew G. Knepley                                                      PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
4606528b96dSMatthew G. Knepley {
4616528b96dSMatthew G. Knepley   PetscErrorCode ierr;
4626528b96dSMatthew G. Knepley 
4636528b96dSMatthew G. Knepley   PetscFunctionBegin;
46406ad1575SMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->form[PETSC_WF_OBJECTIVE], label, val, f, part, (void (*)(void)) obj);CHKERRQ(ierr);
4656528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
4666528b96dSMatthew G. Knepley }
4676528b96dSMatthew G. Knepley 
46806ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormGetIndexObjective(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt part, PetscInt ind,
4696528b96dSMatthew G. Knepley                                               void (**obj)(PetscInt, PetscInt, PetscInt,
4706528b96dSMatthew G. Knepley                                                            const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
4716528b96dSMatthew G. Knepley                                                            const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
4726528b96dSMatthew G. Knepley                                                            PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
4736528b96dSMatthew G. Knepley {
4746528b96dSMatthew G. Knepley   PetscErrorCode ierr;
4756528b96dSMatthew G. Knepley 
4766528b96dSMatthew G. Knepley   PetscFunctionBegin;
47706ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetIndexFunction_Private(wf, wf->form[PETSC_WF_OBJECTIVE], label, val, f, part, ind, (void (**)(void)) obj);CHKERRQ(ierr);
4786528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
4796528b96dSMatthew G. Knepley }
4806528b96dSMatthew G. Knepley 
48106ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormSetIndexObjective(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt part, PetscInt ind,
4826528b96dSMatthew G. Knepley                                               void (*obj)(PetscInt, PetscInt, PetscInt,
4836528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
4846528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
4856528b96dSMatthew G. Knepley                                                           PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
4866528b96dSMatthew G. Knepley {
4876528b96dSMatthew G. Knepley   PetscErrorCode ierr;
4886528b96dSMatthew G. Knepley 
4896528b96dSMatthew G. Knepley   PetscFunctionBegin;
49006ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->form[PETSC_WF_OBJECTIVE], label, val, f, part, ind, (void (*)(void)) obj);CHKERRQ(ierr);
4916528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
4926528b96dSMatthew G. Knepley }
4936528b96dSMatthew G. Knepley 
49406ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormGetResidual(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt part,
4956528b96dSMatthew G. Knepley                                         PetscInt *n0,
4966528b96dSMatthew G. Knepley                                         void (***f0)(PetscInt, PetscInt, PetscInt,
4976528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
4986528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
4996528b96dSMatthew G. Knepley                                                      PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
5006528b96dSMatthew G. Knepley                                         PetscInt *n1,
5016528b96dSMatthew G. Knepley                                         void (***f1)(PetscInt, PetscInt, PetscInt,
5026528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
5036528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
5046528b96dSMatthew G. Knepley                                                      PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
5056528b96dSMatthew G. Knepley {
5066528b96dSMatthew G. Knepley   PetscErrorCode ierr;
5076528b96dSMatthew G. Knepley 
5086528b96dSMatthew G. Knepley   PetscFunctionBegin;
50906ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->form[PETSC_WF_F0], label, val, f, part, n0, (void (***)(void)) f0);CHKERRQ(ierr);
51006ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->form[PETSC_WF_F1], label, val, f, part, n1, (void (***)(void)) f1);CHKERRQ(ierr);
5116528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
5126528b96dSMatthew G. Knepley }
5136528b96dSMatthew G. Knepley 
51406ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormAddResidual(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt part,
5156528b96dSMatthew G. Knepley                                         void (*f0)(PetscInt, PetscInt, PetscInt,
5166528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
5176528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
5186528b96dSMatthew G. Knepley                                                    PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
5196528b96dSMatthew G. Knepley                                         void (*f1)(PetscInt, PetscInt, PetscInt,
5206528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
5216528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
5226528b96dSMatthew G. Knepley                                                    PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
5236528b96dSMatthew G. Knepley {
5246528b96dSMatthew G. Knepley   PetscErrorCode ierr;
5256528b96dSMatthew G. Knepley 
5266528b96dSMatthew G. Knepley   PetscFunctionBegin;
52706ad1575SMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->form[PETSC_WF_F0], label, val, f, part, (void (*)(void)) f0);CHKERRQ(ierr);
52806ad1575SMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->form[PETSC_WF_F1], label, val, f, part, (void (*)(void)) f1);CHKERRQ(ierr);
5296528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
5306528b96dSMatthew G. Knepley }
5316528b96dSMatthew G. Knepley 
53206ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormSetResidual(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt part,
5336528b96dSMatthew G. Knepley                                         PetscInt n0,
5346528b96dSMatthew G. Knepley                                         void (**f0)(PetscInt, PetscInt, PetscInt,
5356528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
5366528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
5376528b96dSMatthew G. Knepley                                                    PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
5386528b96dSMatthew G. Knepley                                         PetscInt n1,
5396528b96dSMatthew G. Knepley                                         void (**f1)(PetscInt, PetscInt, PetscInt,
5406528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
5416528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
5426528b96dSMatthew G. Knepley                                                    PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
5436528b96dSMatthew G. Knepley {
5446528b96dSMatthew G. Knepley   PetscErrorCode ierr;
5456528b96dSMatthew G. Knepley 
5466528b96dSMatthew G. Knepley   PetscFunctionBegin;
54706ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->form[PETSC_WF_F0], label, val, f, part, n0, (void (**)(void)) f0);CHKERRQ(ierr);
54806ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->form[PETSC_WF_F1], label, val, f, part, n1, (void (**)(void)) f1);CHKERRQ(ierr);
5496528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
5506528b96dSMatthew G. Knepley }
5516528b96dSMatthew G. Knepley 
55206ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormSetIndexResidual(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt part,
5536528b96dSMatthew G. Knepley                                         PetscInt i0,
5546528b96dSMatthew G. Knepley                                         void (*f0)(PetscInt, PetscInt, PetscInt,
5556528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
5566528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
5576528b96dSMatthew G. Knepley                                                    PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
5586528b96dSMatthew G. Knepley                                         PetscInt i1,
5596528b96dSMatthew G. Knepley                                         void (*f1)(PetscInt, PetscInt, PetscInt,
5606528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
5616528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
5626528b96dSMatthew G. Knepley                                                    PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
5636528b96dSMatthew G. Knepley {
5646528b96dSMatthew G. Knepley   PetscErrorCode ierr;
5656528b96dSMatthew G. Knepley 
5666528b96dSMatthew G. Knepley   PetscFunctionBegin;
56706ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->form[PETSC_WF_F0], label, val, f, part, i0, (void (*)(void)) f0);CHKERRQ(ierr);
56806ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->form[PETSC_WF_F1], label, val, f, part, i1, (void (*)(void)) f1);CHKERRQ(ierr);
5696528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
5706528b96dSMatthew G. Knepley }
5716528b96dSMatthew G. Knepley 
57206ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormGetBdResidual(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt part,
5736528b96dSMatthew G. Knepley                                           PetscInt *n0,
5746528b96dSMatthew G. Knepley                                         void (***f0)(PetscInt, PetscInt, PetscInt,
5756528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
5766528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
5776528b96dSMatthew G. Knepley                                                      PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
5786528b96dSMatthew G. Knepley                                         PetscInt *n1,
5796528b96dSMatthew G. Knepley                                         void (***f1)(PetscInt, PetscInt, PetscInt,
5806528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
5816528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
5826528b96dSMatthew G. Knepley                                                      PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
5836528b96dSMatthew G. Knepley {
5846528b96dSMatthew G. Knepley   PetscErrorCode ierr;
5856528b96dSMatthew G. Knepley 
5866528b96dSMatthew G. Knepley   PetscFunctionBegin;
58706ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->form[PETSC_WF_BDF0], label, val, f, part, n0, (void (***)(void)) f0);CHKERRQ(ierr);
58806ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->form[PETSC_WF_BDF1], label, val, f, part, n1, (void (***)(void)) f1);CHKERRQ(ierr);
5896528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
5906528b96dSMatthew G. Knepley }
5916528b96dSMatthew G. Knepley 
59206ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormAddBdResidual(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt part,
5936528b96dSMatthew G. Knepley                                           void (*f0)(PetscInt, PetscInt, PetscInt,
5946528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
5956528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
5966528b96dSMatthew G. Knepley                                                      PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
5976528b96dSMatthew G. Knepley                                           void (*f1)(PetscInt, PetscInt, PetscInt,
5986528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
5996528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
6006528b96dSMatthew G. Knepley                                                      PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
6016528b96dSMatthew G. Knepley {
6026528b96dSMatthew G. Knepley   PetscErrorCode ierr;
6036528b96dSMatthew G. Knepley 
6046528b96dSMatthew G. Knepley   PetscFunctionBegin;
60506ad1575SMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->form[PETSC_WF_BDF0], label, val, f, part, (void (*)(void)) f0);CHKERRQ(ierr);
60606ad1575SMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->form[PETSC_WF_BDF1], label, val, f, part, (void (*)(void)) f1);CHKERRQ(ierr);
6076528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
6086528b96dSMatthew G. Knepley }
6096528b96dSMatthew G. Knepley 
61006ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormSetBdResidual(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt part,
6116528b96dSMatthew G. Knepley                                           PetscInt n0,
6126528b96dSMatthew G. Knepley                                           void (**f0)(PetscInt, PetscInt, PetscInt,
6136528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
6146528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
6156528b96dSMatthew G. Knepley                                                      PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
6166528b96dSMatthew G. Knepley                                           PetscInt n1,
6176528b96dSMatthew G. Knepley                                           void (**f1)(PetscInt, PetscInt, PetscInt,
6186528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
6196528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
6206528b96dSMatthew G. Knepley                                                      PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
6216528b96dSMatthew G. Knepley {
6226528b96dSMatthew G. Knepley   PetscErrorCode ierr;
6236528b96dSMatthew G. Knepley 
6246528b96dSMatthew G. Knepley   PetscFunctionBegin;
62506ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->form[PETSC_WF_BDF0], label, val, f, part, n0, (void (**)(void)) f0);CHKERRQ(ierr);
62606ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->form[PETSC_WF_BDF1], label, val, f, part, n1, (void (**)(void)) f1);CHKERRQ(ierr);
6276528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
6286528b96dSMatthew G. Knepley }
6296528b96dSMatthew G. Knepley 
63006ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormSetIndexBdResidual(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt part,
6316528b96dSMatthew G. Knepley                                           PetscInt i0,
6326528b96dSMatthew G. Knepley                                           void (*f0)(PetscInt, PetscInt, PetscInt,
6336528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
6346528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
6356528b96dSMatthew G. Knepley                                                      PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
6366528b96dSMatthew G. Knepley                                           PetscInt i1,
6376528b96dSMatthew G. Knepley                                           void (*f1)(PetscInt, PetscInt, PetscInt,
6386528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
6396528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
6406528b96dSMatthew G. Knepley                                                      PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
6416528b96dSMatthew G. Knepley {
6426528b96dSMatthew G. Knepley   PetscErrorCode ierr;
6436528b96dSMatthew G. Knepley 
6446528b96dSMatthew G. Knepley   PetscFunctionBegin;
64506ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->form[PETSC_WF_BDF0], label, val, f, part, i0, (void (*)(void)) f0);CHKERRQ(ierr);
64606ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->form[PETSC_WF_BDF1], label, val, f, part, i1, (void (*)(void)) f1);CHKERRQ(ierr);
6476528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
6486528b96dSMatthew G. Knepley }
6496528b96dSMatthew G. Knepley 
6506528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormHasJacobian(PetscWeakForm wf, PetscBool *hasJac)
6516528b96dSMatthew G. Knepley {
6526528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
6536528b96dSMatthew G. Knepley   PetscErrorCode ierr;
6546528b96dSMatthew G. Knepley 
6556528b96dSMatthew G. Knepley   PetscFunctionBegin;
6566528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(wf, PETSCWEAKFORM_CLASSID, 1);
6576528b96dSMatthew G. Knepley   PetscValidBoolPointer(hasJac, 2);
65806ad1575SMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->form[PETSC_WF_G0], &n0);CHKERRQ(ierr);
65906ad1575SMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->form[PETSC_WF_G1], &n1);CHKERRQ(ierr);
66006ad1575SMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->form[PETSC_WF_G2], &n2);CHKERRQ(ierr);
66106ad1575SMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->form[PETSC_WF_G3], &n3);CHKERRQ(ierr);
6626528b96dSMatthew G. Knepley   *hasJac = n0+n1+n2+n3 ? PETSC_TRUE : PETSC_FALSE;
6636528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
6646528b96dSMatthew G. Knepley }
6656528b96dSMatthew G. Knepley 
66606ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormGetJacobian(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g, PetscInt part,
6676528b96dSMatthew G. Knepley                                         PetscInt *n0,
6686528b96dSMatthew G. Knepley                                         void (***g0)(PetscInt, PetscInt, PetscInt,
6696528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
6706528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
6716528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
6726528b96dSMatthew G. Knepley                                         PetscInt *n1,
6736528b96dSMatthew G. Knepley                                         void (***g1)(PetscInt, PetscInt, PetscInt,
6746528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
6756528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
6766528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
6776528b96dSMatthew G. Knepley                                         PetscInt *n2,
6786528b96dSMatthew G. Knepley                                         void (***g2)(PetscInt, PetscInt, PetscInt,
6796528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
6806528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
6816528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
6826528b96dSMatthew G. Knepley                                         PetscInt *n3,
6836528b96dSMatthew G. Knepley                                         void (***g3)(PetscInt, PetscInt, PetscInt,
6846528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
6856528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
6866528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
6876528b96dSMatthew G. Knepley {
6886528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
6896528b96dSMatthew G. Knepley   PetscErrorCode ierr;
6906528b96dSMatthew G. Knepley 
6916528b96dSMatthew G. Knepley   PetscFunctionBegin;
69206ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->form[PETSC_WF_G0], label, val, find, part, n0, (void (***)(void)) g0);CHKERRQ(ierr);
69306ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->form[PETSC_WF_G1], label, val, find, part, n1, (void (***)(void)) g1);CHKERRQ(ierr);
69406ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->form[PETSC_WF_G2], label, val, find, part, n2, (void (***)(void)) g2);CHKERRQ(ierr);
69506ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->form[PETSC_WF_G3], label, val, find, part, n3, (void (***)(void)) g3);CHKERRQ(ierr);
6966528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
6976528b96dSMatthew G. Knepley }
6986528b96dSMatthew G. Knepley 
69906ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormAddJacobian(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g, PetscInt part,
7006528b96dSMatthew G. Knepley                                         void (*g0)(PetscInt, PetscInt, PetscInt,
7016528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
7026528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
7036528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
7046528b96dSMatthew G. Knepley                                         void (*g1)(PetscInt, PetscInt, PetscInt,
7056528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
7066528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
7076528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
7086528b96dSMatthew G. Knepley                                         void (*g2)(PetscInt, PetscInt, PetscInt,
7096528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
7106528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
7116528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
7126528b96dSMatthew G. Knepley                                         void (*g3)(PetscInt, PetscInt, PetscInt,
7136528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
7146528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
7156528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
7166528b96dSMatthew G. Knepley {
7176528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
7186528b96dSMatthew G. Knepley   PetscErrorCode ierr;
7196528b96dSMatthew G. Knepley 
7206528b96dSMatthew G. Knepley   PetscFunctionBegin;
72106ad1575SMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->form[PETSC_WF_G0], label, val, find, part, (void (*)(void)) g0);CHKERRQ(ierr);
72206ad1575SMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->form[PETSC_WF_G1], label, val, find, part, (void (*)(void)) g1);CHKERRQ(ierr);
72306ad1575SMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->form[PETSC_WF_G2], label, val, find, part, (void (*)(void)) g2);CHKERRQ(ierr);
72406ad1575SMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->form[PETSC_WF_G3], label, val, find, part, (void (*)(void)) g3);CHKERRQ(ierr);
7256528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
7266528b96dSMatthew G. Knepley }
7276528b96dSMatthew G. Knepley 
72806ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormSetJacobian(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g, PetscInt part,
7296528b96dSMatthew G. Knepley                                         PetscInt n0,
7306528b96dSMatthew G. Knepley                                         void (**g0)(PetscInt, PetscInt, PetscInt,
7316528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
7326528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
7336528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
7346528b96dSMatthew G. Knepley                                         PetscInt n1,
7356528b96dSMatthew G. Knepley                                         void (**g1)(PetscInt, PetscInt, PetscInt,
7366528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
7376528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
7386528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
7396528b96dSMatthew G. Knepley                                         PetscInt n2,
7406528b96dSMatthew G. Knepley                                         void (**g2)(PetscInt, PetscInt, PetscInt,
7416528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
7426528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
7436528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
7446528b96dSMatthew G. Knepley                                         PetscInt n3,
7456528b96dSMatthew G. Knepley                                         void (**g3)(PetscInt, PetscInt, PetscInt,
7466528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
7476528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
7486528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
7496528b96dSMatthew G. Knepley {
7506528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
7516528b96dSMatthew G. Knepley   PetscErrorCode ierr;
7526528b96dSMatthew G. Knepley 
7536528b96dSMatthew G. Knepley   PetscFunctionBegin;
75406ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->form[PETSC_WF_G0], label, val, find, part, n0, (void (**)(void)) g0);CHKERRQ(ierr);
75506ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->form[PETSC_WF_G1], label, val, find, part, n1, (void (**)(void)) g1);CHKERRQ(ierr);
75606ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->form[PETSC_WF_G2], label, val, find, part, n2, (void (**)(void)) g2);CHKERRQ(ierr);
75706ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->form[PETSC_WF_G3], label, val, find, part, n3, (void (**)(void)) g3);CHKERRQ(ierr);
7586528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
7596528b96dSMatthew G. Knepley }
7606528b96dSMatthew G. Knepley 
76106ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormSetIndexJacobian(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g, PetscInt part,
7626528b96dSMatthew G. Knepley                                         PetscInt i0,
7636528b96dSMatthew G. Knepley                                         void (*g0)(PetscInt, PetscInt, PetscInt,
7646528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
7656528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
7666528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
7676528b96dSMatthew G. Knepley                                         PetscInt i1,
7686528b96dSMatthew G. Knepley                                         void (*g1)(PetscInt, PetscInt, PetscInt,
7696528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
7706528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
7716528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
7726528b96dSMatthew G. Knepley                                         PetscInt i2,
7736528b96dSMatthew G. Knepley                                         void (*g2)(PetscInt, PetscInt, PetscInt,
7746528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
7756528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
7766528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
7776528b96dSMatthew G. Knepley                                         PetscInt i3,
7786528b96dSMatthew G. Knepley                                         void (*g3)(PetscInt, PetscInt, PetscInt,
7796528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
7806528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
7816528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
7826528b96dSMatthew G. Knepley {
7836528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
7846528b96dSMatthew G. Knepley   PetscErrorCode ierr;
7856528b96dSMatthew G. Knepley 
7866528b96dSMatthew G. Knepley   PetscFunctionBegin;
78706ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->form[PETSC_WF_G0], label, val, find, part, i0, (void (*)(void)) g0);CHKERRQ(ierr);
78806ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->form[PETSC_WF_G1], label, val, find, part, i1, (void (*)(void)) g1);CHKERRQ(ierr);
78906ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->form[PETSC_WF_G2], label, val, find, part, i2, (void (*)(void)) g2);CHKERRQ(ierr);
79006ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->form[PETSC_WF_G3], label, val, find, part, i3, (void (*)(void)) g3);CHKERRQ(ierr);
7916528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
7926528b96dSMatthew G. Knepley }
7936528b96dSMatthew G. Knepley 
7946528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormHasJacobianPreconditioner(PetscWeakForm wf, PetscBool *hasJacPre)
7956528b96dSMatthew G. Knepley {
7966528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
7976528b96dSMatthew G. Knepley   PetscErrorCode ierr;
7986528b96dSMatthew G. Knepley 
7996528b96dSMatthew G. Knepley   PetscFunctionBegin;
8006528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(wf, PETSCWEAKFORM_CLASSID, 1);
8016528b96dSMatthew G. Knepley   PetscValidBoolPointer(hasJacPre, 2);
80206ad1575SMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->form[PETSC_WF_GP0], &n0);CHKERRQ(ierr);
80306ad1575SMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->form[PETSC_WF_GP1], &n1);CHKERRQ(ierr);
80406ad1575SMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->form[PETSC_WF_GP2], &n2);CHKERRQ(ierr);
80506ad1575SMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->form[PETSC_WF_GP3], &n3);CHKERRQ(ierr);
8066528b96dSMatthew G. Knepley   *hasJacPre = n0+n1+n2+n3 ? PETSC_TRUE : PETSC_FALSE;
8076528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
8086528b96dSMatthew G. Knepley }
8096528b96dSMatthew G. Knepley 
81006ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormGetJacobianPreconditioner(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g, PetscInt part,
8116528b96dSMatthew G. Knepley                                                       PetscInt *n0,
8126528b96dSMatthew G. Knepley                                                       void (***g0)(PetscInt, PetscInt, PetscInt,
8136528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
8146528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
8156528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
8166528b96dSMatthew G. Knepley                                                       PetscInt *n1,
8176528b96dSMatthew G. Knepley                                                       void (***g1)(PetscInt, PetscInt, PetscInt,
8186528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
8196528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
8206528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
8216528b96dSMatthew G. Knepley                                                       PetscInt *n2,
8226528b96dSMatthew G. Knepley                                                       void (***g2)(PetscInt, PetscInt, PetscInt,
8236528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
8246528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
8256528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
8266528b96dSMatthew G. Knepley                                                       PetscInt *n3,
8276528b96dSMatthew G. Knepley                                                       void (***g3)(PetscInt, PetscInt, PetscInt,
8286528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
8296528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
8306528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
8316528b96dSMatthew G. Knepley {
8326528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
8336528b96dSMatthew G. Knepley   PetscErrorCode ierr;
8346528b96dSMatthew G. Knepley 
8356528b96dSMatthew G. Knepley   PetscFunctionBegin;
83606ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->form[PETSC_WF_GP0], label, val, find, part, n0, (void (***)(void)) g0);CHKERRQ(ierr);
83706ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->form[PETSC_WF_GP1], label, val, find, part, n1, (void (***)(void)) g1);CHKERRQ(ierr);
83806ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->form[PETSC_WF_GP2], label, val, find, part, n2, (void (***)(void)) g2);CHKERRQ(ierr);
83906ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->form[PETSC_WF_GP3], label, val, find, part, n3, (void (***)(void)) g3);CHKERRQ(ierr);
8406528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
8416528b96dSMatthew G. Knepley }
8426528b96dSMatthew G. Knepley 
84306ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormAddJacobianPreconditioner(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g, PetscInt part,
8446528b96dSMatthew G. Knepley                                         void (*g0)(PetscInt, PetscInt, PetscInt,
8456528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
8466528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
8476528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
8486528b96dSMatthew G. Knepley                                         void (*g1)(PetscInt, PetscInt, PetscInt,
8496528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
8506528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
8516528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
8526528b96dSMatthew G. Knepley                                         void (*g2)(PetscInt, PetscInt, PetscInt,
8536528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
8546528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
8556528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
8566528b96dSMatthew G. Knepley                                         void (*g3)(PetscInt, PetscInt, PetscInt,
8576528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
8586528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
8596528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
8606528b96dSMatthew G. Knepley {
8616528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
8626528b96dSMatthew G. Knepley   PetscErrorCode ierr;
8636528b96dSMatthew G. Knepley 
8646528b96dSMatthew G. Knepley   PetscFunctionBegin;
86506ad1575SMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->form[PETSC_WF_GP0], label, val, find, part, (void (*)(void)) g0);CHKERRQ(ierr);
86606ad1575SMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->form[PETSC_WF_GP1], label, val, find, part, (void (*)(void)) g1);CHKERRQ(ierr);
86706ad1575SMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->form[PETSC_WF_GP2], label, val, find, part, (void (*)(void)) g2);CHKERRQ(ierr);
86806ad1575SMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->form[PETSC_WF_GP3], label, val, find, part, (void (*)(void)) g3);CHKERRQ(ierr);
8696528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
8706528b96dSMatthew G. Knepley }
8716528b96dSMatthew G. Knepley 
87206ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormSetJacobianPreconditioner(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g, PetscInt part,
8736528b96dSMatthew G. Knepley                                                       PetscInt n0,
8746528b96dSMatthew G. Knepley                                                       void (**g0)(PetscInt, PetscInt, PetscInt,
8756528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
8766528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
8776528b96dSMatthew G. Knepley                                                                  PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
8786528b96dSMatthew G. Knepley                                                       PetscInt n1,
8796528b96dSMatthew G. Knepley                                                       void (**g1)(PetscInt, PetscInt, PetscInt,
8806528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
8816528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
8826528b96dSMatthew G. Knepley                                                                  PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
8836528b96dSMatthew G. Knepley                                                       PetscInt n2,
8846528b96dSMatthew G. Knepley                                                       void (**g2)(PetscInt, PetscInt, PetscInt,
8856528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
8866528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
8876528b96dSMatthew G. Knepley                                                                  PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
8886528b96dSMatthew G. Knepley                                                       PetscInt n3,
8896528b96dSMatthew G. Knepley                                                       void (**g3)(PetscInt, PetscInt, PetscInt,
8906528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
8916528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
8926528b96dSMatthew G. Knepley                                                                  PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
8936528b96dSMatthew G. Knepley {
8946528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
8956528b96dSMatthew G. Knepley   PetscErrorCode ierr;
8966528b96dSMatthew G. Knepley 
8976528b96dSMatthew G. Knepley   PetscFunctionBegin;
89806ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->form[PETSC_WF_GP0], label, val, find, part, n0, (void (**)(void)) g0);CHKERRQ(ierr);
89906ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->form[PETSC_WF_GP1], label, val, find, part, n1, (void (**)(void)) g1);CHKERRQ(ierr);
90006ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->form[PETSC_WF_GP2], label, val, find, part, n2, (void (**)(void)) g2);CHKERRQ(ierr);
90106ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->form[PETSC_WF_GP3], label, val, find, part, n3, (void (**)(void)) g3);CHKERRQ(ierr);
9026528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
9036528b96dSMatthew G. Knepley }
9046528b96dSMatthew G. Knepley 
90506ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormSetIndexJacobianPreconditioner(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g, PetscInt part,
9066528b96dSMatthew G. Knepley                                                       PetscInt i0,
9076528b96dSMatthew G. Knepley                                                       void (*g0)(PetscInt, PetscInt, PetscInt,
9086528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
9096528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
9106528b96dSMatthew G. Knepley                                                                  PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
9116528b96dSMatthew G. Knepley                                                       PetscInt i1,
9126528b96dSMatthew G. Knepley                                                       void (*g1)(PetscInt, PetscInt, PetscInt,
9136528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
9146528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
9156528b96dSMatthew G. Knepley                                                                  PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
9166528b96dSMatthew G. Knepley                                                       PetscInt i2,
9176528b96dSMatthew G. Knepley                                                       void (*g2)(PetscInt, PetscInt, PetscInt,
9186528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
9196528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
9206528b96dSMatthew G. Knepley                                                                  PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
9216528b96dSMatthew G. Knepley                                                       PetscInt i3,
9226528b96dSMatthew G. Knepley                                                       void (*g3)(PetscInt, PetscInt, PetscInt,
9236528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
9246528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
9256528b96dSMatthew G. Knepley                                                                  PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
9266528b96dSMatthew G. Knepley {
9276528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
9286528b96dSMatthew G. Knepley   PetscErrorCode ierr;
9296528b96dSMatthew G. Knepley 
9306528b96dSMatthew G. Knepley   PetscFunctionBegin;
93106ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->form[PETSC_WF_GP0], label, val, find, part, i0, (void (*)(void)) g0);CHKERRQ(ierr);
93206ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->form[PETSC_WF_GP1], label, val, find, part, i1, (void (*)(void)) g1);CHKERRQ(ierr);
93306ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->form[PETSC_WF_GP2], label, val, find, part, i2, (void (*)(void)) g2);CHKERRQ(ierr);
93406ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->form[PETSC_WF_GP3], label, val, find, part, i3, (void (*)(void)) g3);CHKERRQ(ierr);
9356528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
9366528b96dSMatthew G. Knepley }
9376528b96dSMatthew G. Knepley 
9386528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormHasBdJacobian(PetscWeakForm wf, PetscBool *hasJac)
9396528b96dSMatthew G. Knepley {
9406528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
9416528b96dSMatthew G. Knepley   PetscErrorCode ierr;
9426528b96dSMatthew G. Knepley 
9436528b96dSMatthew G. Knepley   PetscFunctionBegin;
9446528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(wf, PETSCWEAKFORM_CLASSID, 1);
9456528b96dSMatthew G. Knepley   PetscValidBoolPointer(hasJac, 2);
94606ad1575SMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->form[PETSC_WF_BDG0], &n0);CHKERRQ(ierr);
94706ad1575SMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->form[PETSC_WF_BDG1], &n1);CHKERRQ(ierr);
94806ad1575SMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->form[PETSC_WF_BDG2], &n2);CHKERRQ(ierr);
94906ad1575SMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->form[PETSC_WF_BDG3], &n3);CHKERRQ(ierr);
9506528b96dSMatthew G. Knepley   *hasJac = n0+n1+n2+n3 ? PETSC_TRUE : PETSC_FALSE;
9516528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
9526528b96dSMatthew G. Knepley }
9536528b96dSMatthew G. Knepley 
95406ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormGetBdJacobian(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g, PetscInt part,
9556528b96dSMatthew G. Knepley                                           PetscInt *n0,
9566528b96dSMatthew G. Knepley                                           void (***g0)(PetscInt, PetscInt, PetscInt,
9576528b96dSMatthew G. Knepley                                                        const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
9586528b96dSMatthew G. Knepley                                                        const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
9596528b96dSMatthew G. Knepley                                                        PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
9606528b96dSMatthew G. Knepley                                           PetscInt *n1,
9616528b96dSMatthew G. Knepley                                           void (***g1)(PetscInt, PetscInt, PetscInt,
9626528b96dSMatthew G. Knepley                                                        const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
9636528b96dSMatthew G. Knepley                                                        const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
9646528b96dSMatthew G. Knepley                                                        PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
9656528b96dSMatthew G. Knepley                                           PetscInt *n2,
9666528b96dSMatthew G. Knepley                                           void (***g2)(PetscInt, PetscInt, PetscInt,
9676528b96dSMatthew G. Knepley                                                        const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
9686528b96dSMatthew G. Knepley                                                        const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
9696528b96dSMatthew G. Knepley                                                        PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
9706528b96dSMatthew G. Knepley                                           PetscInt *n3,
9716528b96dSMatthew G. Knepley                                           void (***g3)(PetscInt, PetscInt, PetscInt,
9726528b96dSMatthew G. Knepley                                                        const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
9736528b96dSMatthew G. Knepley                                                        const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
9746528b96dSMatthew G. Knepley                                                        PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
9756528b96dSMatthew G. Knepley {
9766528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
9776528b96dSMatthew G. Knepley   PetscErrorCode ierr;
9786528b96dSMatthew G. Knepley 
9796528b96dSMatthew G. Knepley   PetscFunctionBegin;
98006ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->form[PETSC_WF_BDG0], label, val, find, part, n0, (void (***)(void)) g0);CHKERRQ(ierr);
98106ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->form[PETSC_WF_BDG1], label, val, find, part, n1, (void (***)(void)) g1);CHKERRQ(ierr);
98206ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->form[PETSC_WF_BDG2], label, val, find, part, n2, (void (***)(void)) g2);CHKERRQ(ierr);
98306ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->form[PETSC_WF_BDG3], label, val, find, part, n3, (void (***)(void)) g3);CHKERRQ(ierr);
9846528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
9856528b96dSMatthew G. Knepley }
9866528b96dSMatthew G. Knepley 
98706ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormAddBdJacobian(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g, PetscInt part,
9886528b96dSMatthew G. Knepley                                           void (*g0)(PetscInt, PetscInt, PetscInt,
9896528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
9906528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
9916528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
9926528b96dSMatthew G. Knepley                                           void (*g1)(PetscInt, PetscInt, PetscInt,
9936528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
9946528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
9956528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
9966528b96dSMatthew G. Knepley                                           void (*g2)(PetscInt, PetscInt, PetscInt,
9976528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
9986528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
9996528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
10006528b96dSMatthew G. Knepley                                           void (*g3)(PetscInt, PetscInt, PetscInt,
10016528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
10026528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
10036528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
10046528b96dSMatthew G. Knepley {
10056528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
10066528b96dSMatthew G. Knepley   PetscErrorCode ierr;
10076528b96dSMatthew G. Knepley 
10086528b96dSMatthew G. Knepley   PetscFunctionBegin;
100906ad1575SMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->form[PETSC_WF_BDG0], label, val, find, part, (void (*)(void)) g0);CHKERRQ(ierr);
101006ad1575SMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->form[PETSC_WF_BDG1], label, val, find, part, (void (*)(void)) g1);CHKERRQ(ierr);
101106ad1575SMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->form[PETSC_WF_BDG2], label, val, find, part, (void (*)(void)) g2);CHKERRQ(ierr);
101206ad1575SMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->form[PETSC_WF_BDG3], label, val, find, part, (void (*)(void)) g3);CHKERRQ(ierr);
10136528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
10146528b96dSMatthew G. Knepley }
10156528b96dSMatthew G. Knepley 
101606ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormSetBdJacobian(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g, PetscInt part,
10176528b96dSMatthew G. Knepley                                           PetscInt n0,
10186528b96dSMatthew G. Knepley                                           void (**g0)(PetscInt, PetscInt, PetscInt,
10196528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
10206528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
10216528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
10226528b96dSMatthew G. Knepley                                           PetscInt n1,
10236528b96dSMatthew G. Knepley                                           void (**g1)(PetscInt, PetscInt, PetscInt,
10246528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
10256528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
10266528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
10276528b96dSMatthew G. Knepley                                           PetscInt n2,
10286528b96dSMatthew G. Knepley                                           void (**g2)(PetscInt, PetscInt, PetscInt,
10296528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
10306528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
10316528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
10326528b96dSMatthew G. Knepley                                           PetscInt n3,
10336528b96dSMatthew G. Knepley                                           void (**g3)(PetscInt, PetscInt, PetscInt,
10346528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
10356528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
10366528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
10376528b96dSMatthew G. Knepley {
10386528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
10396528b96dSMatthew G. Knepley   PetscErrorCode ierr;
10406528b96dSMatthew G. Knepley 
10416528b96dSMatthew G. Knepley   PetscFunctionBegin;
104206ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->form[PETSC_WF_BDG0], label, val, find, part, n0, (void (**)(void)) g0);CHKERRQ(ierr);
104306ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->form[PETSC_WF_BDG1], label, val, find, part, n1, (void (**)(void)) g1);CHKERRQ(ierr);
104406ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->form[PETSC_WF_BDG2], label, val, find, part, n2, (void (**)(void)) g2);CHKERRQ(ierr);
104506ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->form[PETSC_WF_BDG3], label, val, find, part, n3, (void (**)(void)) g3);CHKERRQ(ierr);
10466528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
10476528b96dSMatthew G. Knepley }
10486528b96dSMatthew G. Knepley 
104906ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormSetIndexBdJacobian(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g, PetscInt part,
10506528b96dSMatthew G. Knepley                                           PetscInt i0,
10516528b96dSMatthew G. Knepley                                           void (*g0)(PetscInt, PetscInt, PetscInt,
10526528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
10536528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
10546528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
10556528b96dSMatthew G. Knepley                                           PetscInt i1,
10566528b96dSMatthew G. Knepley                                           void (*g1)(PetscInt, PetscInt, PetscInt,
10576528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
10586528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
10596528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
10606528b96dSMatthew G. Knepley                                           PetscInt i2,
10616528b96dSMatthew G. Knepley                                           void (*g2)(PetscInt, PetscInt, PetscInt,
10626528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
10636528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
10646528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
10656528b96dSMatthew G. Knepley                                           PetscInt i3,
10666528b96dSMatthew G. Knepley                                           void (*g3)(PetscInt, PetscInt, PetscInt,
10676528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
10686528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
10696528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
10706528b96dSMatthew G. Knepley {
10716528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
10726528b96dSMatthew G. Knepley   PetscErrorCode ierr;
10736528b96dSMatthew G. Knepley 
10746528b96dSMatthew G. Knepley   PetscFunctionBegin;
107506ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->form[PETSC_WF_BDG0], label, val, find, part, i0, (void (*)(void)) g0);CHKERRQ(ierr);
107606ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->form[PETSC_WF_BDG1], label, val, find, part, i1, (void (*)(void)) g1);CHKERRQ(ierr);
107706ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->form[PETSC_WF_BDG2], label, val, find, part, i2, (void (*)(void)) g2);CHKERRQ(ierr);
107806ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->form[PETSC_WF_BDG3], label, val, find, part, i3, (void (*)(void)) g3);CHKERRQ(ierr);
10796528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
10806528b96dSMatthew G. Knepley }
10816528b96dSMatthew G. Knepley 
10826528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormHasBdJacobianPreconditioner(PetscWeakForm wf, PetscBool *hasJacPre)
10836528b96dSMatthew G. Knepley {
10846528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
10856528b96dSMatthew G. Knepley   PetscErrorCode ierr;
10866528b96dSMatthew G. Knepley 
10876528b96dSMatthew G. Knepley   PetscFunctionBegin;
10886528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(wf, PETSCWEAKFORM_CLASSID, 1);
10896528b96dSMatthew G. Knepley   PetscValidBoolPointer(hasJacPre, 2);
109006ad1575SMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->form[PETSC_WF_BDGP0], &n0);CHKERRQ(ierr);
109106ad1575SMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->form[PETSC_WF_BDGP1], &n1);CHKERRQ(ierr);
109206ad1575SMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->form[PETSC_WF_BDGP2], &n2);CHKERRQ(ierr);
109306ad1575SMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->form[PETSC_WF_BDGP3], &n3);CHKERRQ(ierr);
10946528b96dSMatthew G. Knepley   *hasJacPre = n0+n1+n2+n3 ? PETSC_TRUE : PETSC_FALSE;
10956528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
10966528b96dSMatthew G. Knepley }
10976528b96dSMatthew G. Knepley 
109806ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormGetBdJacobianPreconditioner(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g, PetscInt part,
10996528b96dSMatthew G. Knepley                                                         PetscInt *n0,
11006528b96dSMatthew G. Knepley                                                         void (***g0)(PetscInt, PetscInt, PetscInt,
11016528b96dSMatthew G. Knepley                                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
11026528b96dSMatthew G. Knepley                                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
11036528b96dSMatthew G. Knepley                                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
11046528b96dSMatthew G. Knepley                                                         PetscInt *n1,
11056528b96dSMatthew G. Knepley                                                         void (***g1)(PetscInt, PetscInt, PetscInt,
11066528b96dSMatthew G. Knepley                                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
11076528b96dSMatthew G. Knepley                                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
11086528b96dSMatthew G. Knepley                                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
11096528b96dSMatthew G. Knepley                                                         PetscInt *n2,
11106528b96dSMatthew G. Knepley                                                         void (***g2)(PetscInt, PetscInt, PetscInt,
11116528b96dSMatthew G. Knepley                                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
11126528b96dSMatthew G. Knepley                                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
11136528b96dSMatthew G. Knepley                                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
11146528b96dSMatthew G. Knepley                                                         PetscInt *n3,
11156528b96dSMatthew G. Knepley                                                         void (***g3)(PetscInt, PetscInt, PetscInt,
11166528b96dSMatthew G. Knepley                                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
11176528b96dSMatthew G. Knepley                                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
11186528b96dSMatthew G. Knepley                                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
11196528b96dSMatthew G. Knepley {
11206528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
11216528b96dSMatthew G. Knepley   PetscErrorCode ierr;
11226528b96dSMatthew G. Knepley 
11236528b96dSMatthew G. Knepley   PetscFunctionBegin;
112406ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->form[PETSC_WF_BDGP0], label, val, find, part, n0, (void (***)(void)) g0);CHKERRQ(ierr);
112506ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->form[PETSC_WF_BDGP1], label, val, find, part, n1, (void (***)(void)) g1);CHKERRQ(ierr);
112606ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->form[PETSC_WF_BDGP2], label, val, find, part, n2, (void (***)(void)) g2);CHKERRQ(ierr);
112706ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->form[PETSC_WF_BDGP3], label, val, find, part, n3, (void (***)(void)) g3);CHKERRQ(ierr);
11286528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
11296528b96dSMatthew G. Knepley }
11306528b96dSMatthew G. Knepley 
113106ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormAddBdJacobianPreconditioner(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g, PetscInt part,
11326528b96dSMatthew G. Knepley                                                         void (*g0)(PetscInt, PetscInt, PetscInt,
11336528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
11346528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
11356528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
11366528b96dSMatthew G. Knepley                                                         void (*g1)(PetscInt, PetscInt, PetscInt,
11376528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
11386528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
11396528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
11406528b96dSMatthew G. Knepley                                                         void (*g2)(PetscInt, PetscInt, PetscInt,
11416528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
11426528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
11436528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
11446528b96dSMatthew G. Knepley                                                         void (*g3)(PetscInt, PetscInt, PetscInt,
11456528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
11466528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
11476528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
11486528b96dSMatthew G. Knepley {
11496528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
11506528b96dSMatthew G. Knepley   PetscErrorCode ierr;
11516528b96dSMatthew G. Knepley 
11526528b96dSMatthew G. Knepley   PetscFunctionBegin;
115306ad1575SMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->form[PETSC_WF_BDGP0], label, val, find, part, (void (*)(void)) g0);CHKERRQ(ierr);
115406ad1575SMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->form[PETSC_WF_BDGP1], label, val, find, part, (void (*)(void)) g1);CHKERRQ(ierr);
115506ad1575SMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->form[PETSC_WF_BDGP2], label, val, find, part, (void (*)(void)) g2);CHKERRQ(ierr);
115606ad1575SMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->form[PETSC_WF_BDGP3], label, val, find, part, (void (*)(void)) g3);CHKERRQ(ierr);
11576528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
11586528b96dSMatthew G. Knepley }
11596528b96dSMatthew G. Knepley 
116006ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormSetBdJacobianPreconditioner(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g, PetscInt part,
11616528b96dSMatthew G. Knepley                                                         PetscInt n0,
11626528b96dSMatthew G. Knepley                                                         void (**g0)(PetscInt, PetscInt, PetscInt,
11636528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
11646528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
11656528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
11666528b96dSMatthew G. Knepley                                                         PetscInt n1,
11676528b96dSMatthew G. Knepley                                                         void (**g1)(PetscInt, PetscInt, PetscInt,
11686528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
11696528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
11706528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
11716528b96dSMatthew G. Knepley                                                         PetscInt n2,
11726528b96dSMatthew G. Knepley                                                         void (**g2)(PetscInt, PetscInt, PetscInt,
11736528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
11746528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
11756528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
11766528b96dSMatthew G. Knepley                                                         PetscInt n3,
11776528b96dSMatthew G. Knepley                                                         void (**g3)(PetscInt, PetscInt, PetscInt,
11786528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
11796528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
11806528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
11816528b96dSMatthew G. Knepley {
11826528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
11836528b96dSMatthew G. Knepley   PetscErrorCode ierr;
11846528b96dSMatthew G. Knepley 
11856528b96dSMatthew G. Knepley   PetscFunctionBegin;
118606ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->form[PETSC_WF_BDGP0], label, val, find, part, n0, (void (**)(void)) g0);CHKERRQ(ierr);
118706ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->form[PETSC_WF_BDGP1], label, val, find, part, n1, (void (**)(void)) g1);CHKERRQ(ierr);
118806ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->form[PETSC_WF_BDGP2], label, val, find, part, n2, (void (**)(void)) g2);CHKERRQ(ierr);
118906ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->form[PETSC_WF_BDGP3], label, val, find, part, n3, (void (**)(void)) g3);CHKERRQ(ierr);
11906528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
11916528b96dSMatthew G. Knepley }
11926528b96dSMatthew G. Knepley 
119306ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormSetIndexBdJacobianPreconditioner(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g, PetscInt part,
11946528b96dSMatthew G. Knepley                                                         PetscInt i0,
11956528b96dSMatthew G. Knepley                                                         void (*g0)(PetscInt, PetscInt, PetscInt,
11966528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
11976528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
11986528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
11996528b96dSMatthew G. Knepley                                                         PetscInt i1,
12006528b96dSMatthew G. Knepley                                                         void (*g1)(PetscInt, PetscInt, PetscInt,
12016528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
12026528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
12036528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
12046528b96dSMatthew G. Knepley                                                         PetscInt i2,
12056528b96dSMatthew G. Knepley                                                         void (*g2)(PetscInt, PetscInt, PetscInt,
12066528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
12076528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
12086528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
12096528b96dSMatthew G. Knepley                                                         PetscInt i3,
12106528b96dSMatthew G. Knepley                                                         void (*g3)(PetscInt, PetscInt, PetscInt,
12116528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
12126528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
12136528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
12146528b96dSMatthew G. Knepley {
12156528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
12166528b96dSMatthew G. Knepley   PetscErrorCode ierr;
12176528b96dSMatthew G. Knepley 
12186528b96dSMatthew G. Knepley   PetscFunctionBegin;
121906ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->form[PETSC_WF_BDGP0], label, val, find, part, i0, (void (*)(void)) g0);CHKERRQ(ierr);
122006ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->form[PETSC_WF_BDGP1], label, val, find, part, i1, (void (*)(void)) g1);CHKERRQ(ierr);
122106ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->form[PETSC_WF_BDGP2], label, val, find, part, i2, (void (*)(void)) g2);CHKERRQ(ierr);
122206ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->form[PETSC_WF_BDGP3], label, val, find, part, i3, (void (*)(void)) g3);CHKERRQ(ierr);
12236528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
12246528b96dSMatthew G. Knepley }
12256528b96dSMatthew G. Knepley 
12266528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormHasDynamicJacobian(PetscWeakForm wf, PetscBool *hasDynJac)
12276528b96dSMatthew G. Knepley {
12286528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
12296528b96dSMatthew G. Knepley   PetscErrorCode ierr;
12306528b96dSMatthew G. Knepley 
12316528b96dSMatthew G. Knepley   PetscFunctionBegin;
12326528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(wf, PETSCWEAKFORM_CLASSID, 1);
12336528b96dSMatthew G. Knepley   PetscValidBoolPointer(hasDynJac, 2);
123406ad1575SMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->form[PETSC_WF_GT0], &n0);CHKERRQ(ierr);
123506ad1575SMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->form[PETSC_WF_GT1], &n1);CHKERRQ(ierr);
123606ad1575SMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->form[PETSC_WF_GT2], &n2);CHKERRQ(ierr);
123706ad1575SMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->form[PETSC_WF_GT3], &n3);CHKERRQ(ierr);
12386528b96dSMatthew G. Knepley   *hasDynJac = n0+n1+n2+n3 ? PETSC_TRUE : PETSC_FALSE;
12396528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
12406528b96dSMatthew G. Knepley }
12416528b96dSMatthew G. Knepley 
124206ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormGetDynamicJacobian(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g, PetscInt part,
12436528b96dSMatthew G. Knepley                                         PetscInt *n0,
12446528b96dSMatthew G. Knepley                                         void (***g0)(PetscInt, PetscInt, PetscInt,
12456528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
12466528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
12476528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
12486528b96dSMatthew G. Knepley                                         PetscInt *n1,
12496528b96dSMatthew G. Knepley                                         void (***g1)(PetscInt, PetscInt, PetscInt,
12506528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
12516528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
12526528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
12536528b96dSMatthew G. Knepley                                         PetscInt *n2,
12546528b96dSMatthew G. Knepley                                         void (***g2)(PetscInt, PetscInt, PetscInt,
12556528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
12566528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
12576528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
12586528b96dSMatthew G. Knepley                                         PetscInt *n3,
12596528b96dSMatthew G. Knepley                                         void (***g3)(PetscInt, PetscInt, PetscInt,
12606528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
12616528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
12626528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
12636528b96dSMatthew G. Knepley {
12646528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
12656528b96dSMatthew G. Knepley   PetscErrorCode ierr;
12666528b96dSMatthew G. Knepley 
12676528b96dSMatthew G. Knepley   PetscFunctionBegin;
126806ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->form[PETSC_WF_GT0], label, val, find, part, n0, (void (***)(void)) g0);CHKERRQ(ierr);
126906ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->form[PETSC_WF_GT1], label, val, find, part, n1, (void (***)(void)) g1);CHKERRQ(ierr);
127006ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->form[PETSC_WF_GT2], label, val, find, part, n2, (void (***)(void)) g2);CHKERRQ(ierr);
127106ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->form[PETSC_WF_GT3], label, val, find, part, n3, (void (***)(void)) g3);CHKERRQ(ierr);
12726528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
12736528b96dSMatthew G. Knepley }
12746528b96dSMatthew G. Knepley 
127506ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormAddDynamicJacobian(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g, PetscInt part,
12766528b96dSMatthew G. Knepley                                         void (*g0)(PetscInt, PetscInt, PetscInt,
12776528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
12786528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
12796528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
12806528b96dSMatthew G. Knepley                                         void (*g1)(PetscInt, PetscInt, PetscInt,
12816528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
12826528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
12836528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
12846528b96dSMatthew G. Knepley                                         void (*g2)(PetscInt, PetscInt, PetscInt,
12856528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
12866528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
12876528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
12886528b96dSMatthew G. Knepley                                         void (*g3)(PetscInt, PetscInt, PetscInt,
12896528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
12906528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
12916528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
12926528b96dSMatthew G. Knepley {
12936528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
12946528b96dSMatthew G. Knepley   PetscErrorCode ierr;
12956528b96dSMatthew G. Knepley 
12966528b96dSMatthew G. Knepley   PetscFunctionBegin;
129706ad1575SMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->form[PETSC_WF_GT0], label, val, find, part, (void (*)(void)) g0);CHKERRQ(ierr);
129806ad1575SMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->form[PETSC_WF_GT1], label, val, find, part, (void (*)(void)) g1);CHKERRQ(ierr);
129906ad1575SMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->form[PETSC_WF_GT2], label, val, find, part, (void (*)(void)) g2);CHKERRQ(ierr);
130006ad1575SMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->form[PETSC_WF_GT3], label, val, find, part, (void (*)(void)) g3);CHKERRQ(ierr);
13016528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
13026528b96dSMatthew G. Knepley }
13036528b96dSMatthew G. Knepley 
130406ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormSetDynamicJacobian(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g, PetscInt part,
13056528b96dSMatthew G. Knepley                                                PetscInt n0,
13066528b96dSMatthew G. Knepley                                                void (**g0)(PetscInt, PetscInt, PetscInt,
13076528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
13086528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
13096528b96dSMatthew G. Knepley                                                           PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
13106528b96dSMatthew G. Knepley                                                PetscInt n1,
13116528b96dSMatthew G. Knepley                                                void (**g1)(PetscInt, PetscInt, PetscInt,
13126528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
13136528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
13146528b96dSMatthew G. Knepley                                                           PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
13156528b96dSMatthew G. Knepley                                                PetscInt n2,
13166528b96dSMatthew G. Knepley                                                void (**g2)(PetscInt, PetscInt, PetscInt,
13176528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
13186528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
13196528b96dSMatthew G. Knepley                                                           PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
13206528b96dSMatthew G. Knepley                                                PetscInt n3,
13216528b96dSMatthew G. Knepley                                                void (**g3)(PetscInt, PetscInt, PetscInt,
13226528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
13236528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
13246528b96dSMatthew G. Knepley                                                           PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
13256528b96dSMatthew G. Knepley {
13266528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
13276528b96dSMatthew G. Knepley   PetscErrorCode ierr;
13286528b96dSMatthew G. Knepley 
13296528b96dSMatthew G. Knepley   PetscFunctionBegin;
133006ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->form[PETSC_WF_GT0], label, val, find, part, n0, (void (**)(void)) g0);CHKERRQ(ierr);
133106ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->form[PETSC_WF_GT1], label, val, find, part, n1, (void (**)(void)) g1);CHKERRQ(ierr);
133206ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->form[PETSC_WF_GT2], label, val, find, part, n2, (void (**)(void)) g2);CHKERRQ(ierr);
133306ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->form[PETSC_WF_GT3], label, val, find, part, n3, (void (**)(void)) g3);CHKERRQ(ierr);
13346528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
13356528b96dSMatthew G. Knepley }
13366528b96dSMatthew G. Knepley 
133706ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormSetIndexDynamicJacobian(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g, PetscInt part,
13386528b96dSMatthew G. Knepley                                                PetscInt i0,
13396528b96dSMatthew G. Knepley                                                void (*g0)(PetscInt, PetscInt, PetscInt,
13406528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
13416528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
13426528b96dSMatthew G. Knepley                                                           PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
13436528b96dSMatthew G. Knepley                                                PetscInt i1,
13446528b96dSMatthew G. Knepley                                                void (*g1)(PetscInt, PetscInt, PetscInt,
13456528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
13466528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
13476528b96dSMatthew G. Knepley                                                           PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
13486528b96dSMatthew G. Knepley                                                PetscInt i2,
13496528b96dSMatthew G. Knepley                                                void (*g2)(PetscInt, PetscInt, PetscInt,
13506528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
13516528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
13526528b96dSMatthew G. Knepley                                                           PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
13536528b96dSMatthew G. Knepley                                                PetscInt i3,
13546528b96dSMatthew G. Knepley                                                void (*g3)(PetscInt, PetscInt, PetscInt,
13556528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
13566528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
13576528b96dSMatthew G. Knepley                                                           PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
13586528b96dSMatthew G. Knepley {
13596528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
13606528b96dSMatthew G. Knepley   PetscErrorCode ierr;
13616528b96dSMatthew G. Knepley 
13626528b96dSMatthew G. Knepley   PetscFunctionBegin;
136306ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->form[PETSC_WF_GT0], label, val, find, part, i0, (void (*)(void)) g0);CHKERRQ(ierr);
136406ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->form[PETSC_WF_GT1], label, val, find, part, i1, (void (*)(void)) g1);CHKERRQ(ierr);
136506ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->form[PETSC_WF_GT2], label, val, find, part, i2, (void (*)(void)) g2);CHKERRQ(ierr);
136606ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->form[PETSC_WF_GT3], label, val, find, part, i3, (void (*)(void)) g3);CHKERRQ(ierr);
13676528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
13686528b96dSMatthew G. Knepley }
13696528b96dSMatthew G. Knepley 
137006ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormGetRiemannSolver(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt part, PetscInt *n,
13716528b96dSMatthew G. Knepley                                              void (***r)(PetscInt, PetscInt, const PetscReal[], const PetscReal[], const PetscScalar[], const PetscScalar[], PetscInt, const PetscScalar[], PetscScalar[], void *))
13726528b96dSMatthew G. Knepley {
13736528b96dSMatthew G. Knepley   PetscErrorCode ierr;
13746528b96dSMatthew G. Knepley 
13756528b96dSMatthew G. Knepley   PetscFunctionBegin;
137606ad1575SMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->form[PETSC_WF_R], label, val, f, part, n, (void (***)(void)) r);CHKERRQ(ierr);
13776528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
13786528b96dSMatthew G. Knepley }
13796528b96dSMatthew G. Knepley 
138006ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormSetRiemannSolver(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt part,
13816528b96dSMatthew G. Knepley                                              PetscInt n,
13826528b96dSMatthew G. Knepley                                              void (**r)(PetscInt, PetscInt, const PetscReal[], const PetscReal[], const PetscScalar[], const PetscScalar[], PetscInt, const PetscScalar[], PetscScalar[], void *))
13836528b96dSMatthew G. Knepley {
13846528b96dSMatthew G. Knepley   PetscErrorCode ierr;
13856528b96dSMatthew G. Knepley 
13866528b96dSMatthew G. Knepley   PetscFunctionBegin;
138706ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->form[PETSC_WF_R], label, val, f, part, n, (void (**)(void)) r);CHKERRQ(ierr);
13886528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
13896528b96dSMatthew G. Knepley }
13906528b96dSMatthew G. Knepley 
139106ad1575SMatthew G. Knepley PetscErrorCode PetscWeakFormSetIndexRiemannSolver(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt part,
13926528b96dSMatthew G. Knepley                                                   PetscInt i,
13936528b96dSMatthew G. Knepley                                                   void (*r)(PetscInt, PetscInt, const PetscReal[], const PetscReal[], const PetscScalar[], const PetscScalar[], PetscInt, const PetscScalar[], PetscScalar[], void *))
13946528b96dSMatthew G. Knepley {
13956528b96dSMatthew G. Knepley   PetscErrorCode ierr;
13966528b96dSMatthew G. Knepley 
13976528b96dSMatthew G. Knepley   PetscFunctionBegin;
139806ad1575SMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->form[PETSC_WF_R], label, val, f, part, i, (void (*)(void)) r);CHKERRQ(ierr);
13996528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
14006528b96dSMatthew G. Knepley }
14016528b96dSMatthew G. Knepley 
14026528b96dSMatthew G. Knepley /*@
14036528b96dSMatthew G. Knepley   PetscWeakFormGetNumFields - Returns the number of fields
14046528b96dSMatthew G. Knepley 
14056528b96dSMatthew G. Knepley   Not collective
14066528b96dSMatthew G. Knepley 
14076528b96dSMatthew G. Knepley   Input Parameter:
14086528b96dSMatthew G. Knepley . wf - The PetscWeakForm object
14096528b96dSMatthew G. Knepley 
14106528b96dSMatthew G. Knepley   Output Parameter:
1411a5b23f4aSJose E. Roman . Nf - The number of fields
14126528b96dSMatthew G. Knepley 
14136528b96dSMatthew G. Knepley   Level: beginner
14146528b96dSMatthew G. Knepley 
14156528b96dSMatthew G. Knepley .seealso: PetscWeakFormSetNumFields(), PetscWeakFormCreate()
14166528b96dSMatthew G. Knepley @*/
14176528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormGetNumFields(PetscWeakForm wf, PetscInt *Nf)
14186528b96dSMatthew G. Knepley {
14196528b96dSMatthew G. Knepley   PetscFunctionBegin;
14206528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(wf, PETSCWEAKFORM_CLASSID, 1);
14216528b96dSMatthew G. Knepley   PetscValidPointer(Nf, 2);
14226528b96dSMatthew G. Knepley   *Nf = wf->Nf;
14236528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
14246528b96dSMatthew G. Knepley }
14256528b96dSMatthew G. Knepley 
14266528b96dSMatthew G. Knepley /*@
14276528b96dSMatthew G. Knepley   PetscWeakFormSetNumFields - Sets the number of fields
14286528b96dSMatthew G. Knepley 
14296528b96dSMatthew G. Knepley   Not collective
14306528b96dSMatthew G. Knepley 
14316528b96dSMatthew G. Knepley   Input Parameters:
14326528b96dSMatthew G. Knepley + wf - The PetscWeakForm object
14336528b96dSMatthew G. Knepley - Nf - The number of fields
14346528b96dSMatthew G. Knepley 
14356528b96dSMatthew G. Knepley   Level: beginner
14366528b96dSMatthew G. Knepley 
14376528b96dSMatthew G. Knepley .seealso: PetscWeakFormGetNumFields(), PetscWeakFormCreate()
14386528b96dSMatthew G. Knepley @*/
14396528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormSetNumFields(PetscWeakForm wf, PetscInt Nf)
14406528b96dSMatthew G. Knepley {
14416528b96dSMatthew G. Knepley   PetscFunctionBegin;
14426528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(wf, PETSCWEAKFORM_CLASSID, 1);
14436528b96dSMatthew G. Knepley   wf->Nf = Nf;
14446528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
14456528b96dSMatthew G. Knepley }
14466528b96dSMatthew G. Knepley 
14476528b96dSMatthew G. Knepley /*@
14486528b96dSMatthew G. Knepley   PetscWeakFormDestroy - Destroys a PetscWeakForm object
14496528b96dSMatthew G. Knepley 
14506528b96dSMatthew G. Knepley   Collective on wf
14516528b96dSMatthew G. Knepley 
14526528b96dSMatthew G. Knepley   Input Parameter:
14536528b96dSMatthew G. Knepley . wf - the PetscWeakForm object to destroy
14546528b96dSMatthew G. Knepley 
14556528b96dSMatthew G. Knepley   Level: developer
14566528b96dSMatthew G. Knepley 
14576528b96dSMatthew G. Knepley .seealso PetscWeakFormCreate(), PetscWeakFormView()
14586528b96dSMatthew G. Knepley @*/
14596528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormDestroy(PetscWeakForm *wf)
14606528b96dSMatthew G. Knepley {
146106ad1575SMatthew G. Knepley   PetscInt       f;
14626528b96dSMatthew G. Knepley   PetscErrorCode ierr;
14636528b96dSMatthew G. Knepley 
14646528b96dSMatthew G. Knepley   PetscFunctionBegin;
14656528b96dSMatthew G. Knepley   if (!*wf) PetscFunctionReturn(0);
14666528b96dSMatthew G. Knepley   PetscValidHeaderSpecific((*wf), PETSCWEAKFORM_CLASSID, 1);
14676528b96dSMatthew G. Knepley 
14686528b96dSMatthew G. Knepley   if (--((PetscObject)(*wf))->refct > 0) {*wf = NULL; PetscFunctionReturn(0);}
14696528b96dSMatthew G. Knepley   ((PetscObject) (*wf))->refct = 0;
14706528b96dSMatthew G. Knepley   ierr = PetscChunkBufferDestroy(&(*wf)->funcs);CHKERRQ(ierr);
147106ad1575SMatthew G. Knepley   for (f = 0; f < PETSC_NUM_WF; ++f) {ierr = PetscHMapFormDestroy(&(*wf)->form[f]);CHKERRQ(ierr);}
147206ad1575SMatthew G. Knepley   ierr = PetscFree((*wf)->form);CHKERRQ(ierr);
14736528b96dSMatthew G. Knepley   ierr = PetscHeaderDestroy(wf);CHKERRQ(ierr);
14746528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
14756528b96dSMatthew G. Knepley }
14766528b96dSMatthew G. Knepley 
147745480ffeSMatthew G. Knepley static PetscErrorCode PetscWeakFormViewTable_Ascii(PetscWeakForm wf, PetscViewer viewer, PetscBool splitField, const char tableName[], PetscHMapForm map)
14786528b96dSMatthew G. Knepley {
147945480ffeSMatthew G. Knepley   PetscInt       Nf = wf->Nf, Nk, k;
14806528b96dSMatthew G. Knepley   PetscErrorCode ierr;
14816528b96dSMatthew G. Knepley 
14826528b96dSMatthew G. Knepley   PetscFunctionBegin;
14836528b96dSMatthew G. Knepley   ierr = PetscHMapFormGetSize(map, &Nk);CHKERRQ(ierr);
14846528b96dSMatthew G. Knepley   if (Nk) {
148506ad1575SMatthew G. Knepley     PetscFormKey *keys;
14866528b96dSMatthew G. Knepley     void       (**funcs)(void);
1487*5fedec97SMatthew G. Knepley     const char  **names;
1488*5fedec97SMatthew G. Knepley     PetscInt     *values, *idx1, *idx2, *idx;
1489*5fedec97SMatthew G. Knepley     PetscBool     showPart = PETSC_FALSE, showPointer = PETSC_FALSE;
1490*5fedec97SMatthew G. Knepley     PetscInt      off = 0;
14916528b96dSMatthew G. Knepley 
1492*5fedec97SMatthew G. Knepley     ierr = PetscMalloc6(Nk, &keys, Nk, &names, Nk, &values, Nk, &idx1, Nk, &idx2, Nk, &idx);CHKERRQ(ierr);
14936528b96dSMatthew G. Knepley     ierr = PetscHMapFormGetKeys(map, &off, keys);CHKERRQ(ierr);
1494*5fedec97SMatthew G. Knepley     /* Sort keys by label name and value */
1495*5fedec97SMatthew G. Knepley     {
1496*5fedec97SMatthew G. Knepley       /* First sort values */
1497*5fedec97SMatthew G. Knepley       for (k = 0; k < Nk; ++k) {values[k] = keys[k].value; idx1[k] = k;}
1498*5fedec97SMatthew G. Knepley       ierr = PetscSortIntWithPermutation(Nk, values, idx1);CHKERRQ(ierr);
1499*5fedec97SMatthew G. Knepley       /* If the string sort is stable, it will be sorted correctly overall */
1500*5fedec97SMatthew G. Knepley       for (k = 0; k < Nk; ++k) {
1501*5fedec97SMatthew G. Knepley         if (keys[idx1[k]].label) {ierr = PetscObjectGetName((PetscObject) keys[idx1[k]].label, &names[k]);CHKERRQ(ierr);}
1502*5fedec97SMatthew G. Knepley         else                     {names[k] = "";}
1503*5fedec97SMatthew G. Knepley         idx2[k] = k;
1504*5fedec97SMatthew G. Knepley       }
1505*5fedec97SMatthew G. Knepley       ierr = PetscSortStrWithPermutation(Nk, names, idx2);CHKERRQ(ierr);
1506*5fedec97SMatthew G. Knepley       for (k = 0; k < Nk; ++k) {
1507*5fedec97SMatthew G. Knepley         if (keys[k].label) {ierr = PetscObjectGetName((PetscObject) keys[k].label, &names[k]);CHKERRQ(ierr);}
1508*5fedec97SMatthew G. Knepley         else               {names[k] = "";}
1509*5fedec97SMatthew G. Knepley         idx[k] = idx1[idx2[k]];
1510*5fedec97SMatthew G. Knepley       }
1511*5fedec97SMatthew G. Knepley     }
15126528b96dSMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, "%s\n", tableName);CHKERRQ(ierr);
15136528b96dSMatthew G. Knepley     ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
15146528b96dSMatthew G. Knepley     for (k = 0; k < Nk; ++k) {
15150944a4d6SMatthew G. Knepley       if (keys[k].part != 0) showPart = PETSC_TRUE;
15160944a4d6SMatthew G. Knepley     }
15170944a4d6SMatthew G. Knepley     for (k = 0; k < Nk; ++k) {
1518*5fedec97SMatthew G. Knepley       const PetscInt i = idx[k];
1519*5fedec97SMatthew G. Knepley       PetscInt       n, f;
1520*5fedec97SMatthew G. Knepley 
1521*5fedec97SMatthew G. Knepley       if (keys[i].label) {
1522*5fedec97SMatthew G. Knepley         if (showPointer) {ierr = PetscViewerASCIIPrintf(viewer, "(%s:%p, %D) ", names[i], keys[i].label, keys[i].value);CHKERRQ(ierr);}
1523*5fedec97SMatthew G. Knepley         else             {ierr = PetscViewerASCIIPrintf(viewer, "(%s, %D) ", names[i], keys[i].value);CHKERRQ(ierr);}
152445480ffeSMatthew G. Knepley       } else {ierr = PetscViewerASCIIPrintf(viewer, "");CHKERRQ(ierr);}
15256528b96dSMatthew G. Knepley       ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr);
1526*5fedec97SMatthew G. Knepley       if (splitField) {ierr = PetscViewerASCIIPrintf(viewer, "(%D, %D) ", keys[i].field/Nf, keys[i].field%Nf);CHKERRQ(ierr);}
1527*5fedec97SMatthew G. Knepley       else            {ierr = PetscViewerASCIIPrintf(viewer, "(%D) ", keys[i].field);CHKERRQ(ierr);}
1528*5fedec97SMatthew G. Knepley       if (showPart)   {ierr = PetscViewerASCIIPrintf(viewer, "(%D) ", keys[i].part);CHKERRQ(ierr);}
1529*5fedec97SMatthew G. Knepley       ierr = PetscWeakFormGetFunction_Private(wf, map, keys[i].label, keys[i].value, keys[i].field, keys[i].part, &n, &funcs);CHKERRQ(ierr);
1530*5fedec97SMatthew G. Knepley       for (f = 0; f < n; ++f) {
1531258ec3d2SMatthew G. Knepley         char  *fname;
1532*5fedec97SMatthew G. Knepley         size_t len, l;
1533258ec3d2SMatthew G. Knepley 
1534*5fedec97SMatthew G. Knepley         if (f > 0) {ierr = PetscViewerASCIIPrintf(viewer, ", ");CHKERRQ(ierr);}
1535*5fedec97SMatthew G. Knepley         ierr = PetscDLAddr(funcs[f], &fname);CHKERRQ(ierr);
1536*5fedec97SMatthew G. Knepley         if (fname) {
1537*5fedec97SMatthew G. Knepley           /* Eliminate argument types */
1538*5fedec97SMatthew G. Knepley           ierr = PetscStrlen(fname, &len);CHKERRQ(ierr);
1539*5fedec97SMatthew G. Knepley           for (l = 0; l < len; ++l) if (fname[l] == '(') {fname[l] = '\0'; break;}
1540*5fedec97SMatthew G. Knepley           ierr = PetscViewerASCIIPrintf(viewer, "%s", fname);CHKERRQ(ierr);
1541*5fedec97SMatthew G. Knepley         } else if (showPointer) {
1542*5fedec97SMatthew G. Knepley           ierr = PetscViewerASCIIPrintf(viewer, "%p", funcs[f]);CHKERRQ(ierr);
1543*5fedec97SMatthew G. Knepley         }
1544258ec3d2SMatthew G. Knepley         ierr = PetscFree(fname);CHKERRQ(ierr);
15456528b96dSMatthew G. Knepley       }
15466528b96dSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr);
15476528b96dSMatthew G. Knepley       ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr);
15486528b96dSMatthew G. Knepley     }
15496528b96dSMatthew G. Knepley     ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
1550*5fedec97SMatthew G. Knepley     ierr = PetscFree6(keys, names, values, idx1, idx2, idx);CHKERRQ(ierr);
15516528b96dSMatthew G. Knepley   }
15526528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
15536528b96dSMatthew G. Knepley }
15546528b96dSMatthew G. Knepley 
15556528b96dSMatthew G. Knepley static PetscErrorCode PetscWeakFormView_Ascii(PetscWeakForm wf, PetscViewer viewer)
15566528b96dSMatthew G. Knepley {
15576528b96dSMatthew G. Knepley   PetscViewerFormat format;
155806ad1575SMatthew G. Knepley   PetscInt          f;
15596528b96dSMatthew G. Knepley   PetscErrorCode    ierr;
15606528b96dSMatthew G. Knepley 
15616528b96dSMatthew G. Knepley   PetscFunctionBegin;
15626528b96dSMatthew G. Knepley   ierr = PetscViewerGetFormat(viewer, &format);CHKERRQ(ierr);
15636528b96dSMatthew G. Knepley   ierr = PetscViewerASCIIPrintf(viewer, "Weak Form System with %d fields\n", wf->Nf);CHKERRQ(ierr);
15646528b96dSMatthew G. Knepley   ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
156506ad1575SMatthew G. Knepley   for (f = 0; f < PETSC_NUM_WF; ++f) {
15660944a4d6SMatthew G. Knepley     ierr = PetscWeakFormViewTable_Ascii(wf, viewer, PETSC_TRUE, PetscWeakFormKinds[f], wf->form[f]);CHKERRQ(ierr);
156706ad1575SMatthew G. Knepley   }
15686528b96dSMatthew G. Knepley   ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
15696528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
15706528b96dSMatthew G. Knepley }
15716528b96dSMatthew G. Knepley 
15726528b96dSMatthew G. Knepley /*@C
15736528b96dSMatthew G. Knepley   PetscWeakFormView - Views a PetscWeakForm
15746528b96dSMatthew G. Knepley 
15756528b96dSMatthew G. Knepley   Collective on wf
15766528b96dSMatthew G. Knepley 
1577d8d19677SJose E. Roman   Input Parameters:
15786528b96dSMatthew G. Knepley + wf - the PetscWeakForm object to view
15796528b96dSMatthew G. Knepley - v  - the viewer
15806528b96dSMatthew G. Knepley 
15816528b96dSMatthew G. Knepley   Level: developer
15826528b96dSMatthew G. Knepley 
15836528b96dSMatthew G. Knepley .seealso PetscWeakFormDestroy(), PetscWeakFormCreate()
15846528b96dSMatthew G. Knepley @*/
15856528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormView(PetscWeakForm wf, PetscViewer v)
15866528b96dSMatthew G. Knepley {
15876528b96dSMatthew G. Knepley   PetscBool      iascii;
15886528b96dSMatthew G. Knepley   PetscErrorCode ierr;
15896528b96dSMatthew G. Knepley 
15906528b96dSMatthew G. Knepley   PetscFunctionBegin;
15916528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(wf, PETSCWEAKFORM_CLASSID, 1);
15926528b96dSMatthew G. Knepley   if (!v) {ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject) wf), &v);CHKERRQ(ierr);}
15936528b96dSMatthew G. Knepley   else    {PetscValidHeaderSpecific(v, PETSC_VIEWER_CLASSID, 2);}
15946528b96dSMatthew G. Knepley   ierr = PetscObjectTypeCompare((PetscObject) v, PETSCVIEWERASCII, &iascii);CHKERRQ(ierr);
15956528b96dSMatthew G. Knepley   if (iascii) {ierr = PetscWeakFormView_Ascii(wf, v);CHKERRQ(ierr);}
15966528b96dSMatthew G. Knepley   if (wf->ops->view) {ierr = (*wf->ops->view)(wf, v);CHKERRQ(ierr);}
15976528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
15986528b96dSMatthew G. Knepley }
15996528b96dSMatthew G. Knepley 
16006528b96dSMatthew G. Knepley /*@
16016528b96dSMatthew G. Knepley   PetscWeakFormCreate - Creates an empty PetscWeakForm object.
16026528b96dSMatthew G. Knepley 
16036528b96dSMatthew G. Knepley   Collective
16046528b96dSMatthew G. Knepley 
16056528b96dSMatthew G. Knepley   Input Parameter:
16066528b96dSMatthew G. Knepley . comm - The communicator for the PetscWeakForm object
16076528b96dSMatthew G. Knepley 
16086528b96dSMatthew G. Knepley   Output Parameter:
16096528b96dSMatthew G. Knepley . wf - The PetscWeakForm object
16106528b96dSMatthew G. Knepley 
16116528b96dSMatthew G. Knepley   Level: beginner
16126528b96dSMatthew G. Knepley 
16136528b96dSMatthew G. Knepley .seealso: PetscDS, PetscWeakFormDestroy()
16146528b96dSMatthew G. Knepley @*/
16156528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormCreate(MPI_Comm comm, PetscWeakForm *wf)
16166528b96dSMatthew G. Knepley {
16176528b96dSMatthew G. Knepley   PetscWeakForm  p;
161806ad1575SMatthew G. Knepley   PetscInt       f;
16196528b96dSMatthew G. Knepley   PetscErrorCode ierr;
16206528b96dSMatthew G. Knepley 
16216528b96dSMatthew G. Knepley   PetscFunctionBegin;
16226528b96dSMatthew G. Knepley   PetscValidPointer(wf, 2);
16236528b96dSMatthew G. Knepley   *wf  = NULL;
16246528b96dSMatthew G. Knepley   ierr = PetscDSInitializePackage();CHKERRQ(ierr);
16256528b96dSMatthew G. Knepley 
16266528b96dSMatthew G. Knepley   ierr = PetscHeaderCreate(p, PETSCWEAKFORM_CLASSID, "PetscWeakForm", "Weak Form System", "PetscWeakForm", comm, PetscWeakFormDestroy, PetscWeakFormView);CHKERRQ(ierr);
16276528b96dSMatthew G. Knepley 
16286528b96dSMatthew G. Knepley   p->Nf = 0;
16296528b96dSMatthew G. Knepley   ierr = PetscChunkBufferCreate(sizeof(&PetscWeakFormCreate), 2, &p->funcs);CHKERRQ(ierr);
163006ad1575SMatthew G. Knepley   ierr = PetscMalloc1(PETSC_NUM_WF, &p->form);CHKERRQ(ierr);
163106ad1575SMatthew G. Knepley   for (f = 0; f < PETSC_NUM_WF; ++f) {ierr = PetscHMapFormCreate(&p->form[f]);CHKERRQ(ierr);}
16326528b96dSMatthew G. Knepley   *wf = p;
16336528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
16346528b96dSMatthew G. Knepley }
1635