xref: /petsc/src/dm/dt/interface/dtweakform.c (revision 6528b96d098a3a0d8b5eec2f1c205a3c25c0d721)
1*6528b96dSMatthew G. Knepley #include <petsc/private/petscdsimpl.h> /*I "petscds.h" I*/
2*6528b96dSMatthew G. Knepley 
3*6528b96dSMatthew G. Knepley PetscClassId PETSCWEAKFORM_CLASSID = 0;
4*6528b96dSMatthew G. Knepley 
5*6528b96dSMatthew G. Knepley static PetscErrorCode PetscChunkBufferCreate(size_t unitbytes, size_t expected, PetscChunkBuffer **buffer)
6*6528b96dSMatthew G. Knepley {
7*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
8*6528b96dSMatthew G. Knepley 
9*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
10*6528b96dSMatthew G. Knepley   ierr = PetscNew(buffer);CHKERRQ(ierr);
11*6528b96dSMatthew G. Knepley   ierr = PetscCalloc1(expected*unitbytes, &(*buffer)->array);CHKERRQ(ierr);
12*6528b96dSMatthew G. Knepley   (*buffer)->size      = expected;
13*6528b96dSMatthew G. Knepley   (*buffer)->unitbytes = unitbytes;
14*6528b96dSMatthew G. Knepley   (*buffer)->alloc     = expected*unitbytes;
15*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
16*6528b96dSMatthew G. Knepley }
17*6528b96dSMatthew G. Knepley 
18*6528b96dSMatthew G. Knepley static PetscErrorCode PetscChunkBufferDestroy(PetscChunkBuffer **buffer)
19*6528b96dSMatthew G. Knepley {
20*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
21*6528b96dSMatthew G. Knepley 
22*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
23*6528b96dSMatthew G. Knepley   ierr = PetscFree((*buffer)->array);CHKERRQ(ierr);
24*6528b96dSMatthew G. Knepley   ierr = PetscFree(*buffer);CHKERRQ(ierr);
25*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
26*6528b96dSMatthew G. Knepley }
27*6528b96dSMatthew G. Knepley 
28*6528b96dSMatthew G. Knepley static PetscErrorCode PetscChunkBufferCreateChunk(PetscChunkBuffer *buffer, PetscInt size, PetscChunk *chunk)
29*6528b96dSMatthew G. Knepley {
30*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
31*6528b96dSMatthew G. Knepley 
32*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
33*6528b96dSMatthew G. Knepley   if ((buffer->size + size)*buffer->unitbytes > buffer->alloc) {
34*6528b96dSMatthew G. Knepley     char *tmp;
35*6528b96dSMatthew G. Knepley 
36*6528b96dSMatthew G. Knepley     if (!buffer->alloc) buffer->alloc = (buffer->size + size)*buffer->unitbytes;
37*6528b96dSMatthew G. Knepley     while ((buffer->size + size)*buffer->unitbytes > buffer->alloc) buffer->alloc *= 2;
38*6528b96dSMatthew G. Knepley     ierr = PetscMalloc(buffer->alloc, &tmp);CHKERRQ(ierr);
39*6528b96dSMatthew G. Knepley     ierr = PetscMemcpy(tmp, buffer->array, buffer->size*buffer->unitbytes);CHKERRQ(ierr);
40*6528b96dSMatthew G. Knepley     ierr = PetscFree(buffer->array);CHKERRQ(ierr);
41*6528b96dSMatthew G. Knepley     buffer->array = tmp;
42*6528b96dSMatthew G. Knepley   }
43*6528b96dSMatthew G. Knepley   chunk->start    = buffer->size;
44*6528b96dSMatthew G. Knepley   chunk->size     = size;
45*6528b96dSMatthew G. Knepley   chunk->reserved = size;
46*6528b96dSMatthew G. Knepley   buffer->size   += size;
47*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
48*6528b96dSMatthew G. Knepley }
49*6528b96dSMatthew G. Knepley 
50*6528b96dSMatthew G. Knepley static PetscErrorCode PetscChunkBufferEnlargeChunk(PetscChunkBuffer *buffer, PetscInt size, PetscChunk *chunk)
51*6528b96dSMatthew G. Knepley {
52*6528b96dSMatthew G. Knepley   size_t         siz = size;
53*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
54*6528b96dSMatthew G. Knepley 
55*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
56*6528b96dSMatthew G. Knepley   if (chunk->size + size > chunk->reserved) {
57*6528b96dSMatthew G. Knepley     PetscChunk newchunk;
58*6528b96dSMatthew G. Knepley     PetscInt   reserved = chunk->size;
59*6528b96dSMatthew G. Knepley 
60*6528b96dSMatthew G. Knepley     /* TODO Here if we had a chunk list, we could update them all to reclaim unused space */
61*6528b96dSMatthew G. Knepley     while (reserved < chunk->size+size) reserved *= 2;
62*6528b96dSMatthew G. Knepley     ierr = PetscChunkBufferCreateChunk(buffer, (size_t) reserved, &newchunk);CHKERRQ(ierr);
63*6528b96dSMatthew G. Knepley     newchunk.size = chunk->size+size;
64*6528b96dSMatthew G. Knepley     ierr = PetscMemcpy(&buffer->array[newchunk.start], &buffer->array[chunk->start], chunk->size * buffer->unitbytes);CHKERRQ(ierr);
65*6528b96dSMatthew G. Knepley     *chunk = newchunk;
66*6528b96dSMatthew G. Knepley   } else {
67*6528b96dSMatthew G. Knepley     chunk->size += siz;
68*6528b96dSMatthew G. Knepley   }
69*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
70*6528b96dSMatthew G. Knepley }
71*6528b96dSMatthew G. Knepley 
72*6528b96dSMatthew G. Knepley /*@C
73*6528b96dSMatthew G. Knepley   PetscHashFormKeySort - Sorts an array of PetscHashFormKey in place in increasing order.
74*6528b96dSMatthew G. Knepley 
75*6528b96dSMatthew G. Knepley   Not Collective
76*6528b96dSMatthew G. Knepley 
77*6528b96dSMatthew G. Knepley   Input Parameters:
78*6528b96dSMatthew G. Knepley + n - number of values
79*6528b96dSMatthew G. Knepley - X - array of PetscHashFormKey
80*6528b96dSMatthew G. Knepley 
81*6528b96dSMatthew G. Knepley   Level: intermediate
82*6528b96dSMatthew G. Knepley 
83*6528b96dSMatthew G. Knepley .seealso: PetscIntSortSemiOrdered(), PetscSortInt()
84*6528b96dSMatthew G. Knepley @*/
85*6528b96dSMatthew G. Knepley PetscErrorCode PetscHashFormKeySort(PetscInt n, PetscHashFormKey arr[])
86*6528b96dSMatthew G. Knepley {
87*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
88*6528b96dSMatthew G. Knepley 
89*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
90*6528b96dSMatthew G. Knepley   if (n <= 1) PetscFunctionReturn(0);
91*6528b96dSMatthew G. Knepley   PetscValidPointer(arr, 2);
92*6528b96dSMatthew G. Knepley   ierr = PetscTimSort(n, arr, sizeof(PetscHashFormKey), Compare_PetscHashFormKey_Private, NULL);CHKERRQ(ierr);
93*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
94*6528b96dSMatthew G. Knepley }
95*6528b96dSMatthew G. Knepley 
96*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormGetFunction_Private(PetscWeakForm wf, PetscHMapForm ht, DMLabel label, PetscInt value, PetscInt f, PetscInt *n, void (***func)())
97*6528b96dSMatthew G. Knepley {
98*6528b96dSMatthew G. Knepley   PetscHashFormKey key;
99*6528b96dSMatthew G. Knepley   PetscChunk       chunk;
100*6528b96dSMatthew G. Knepley   PetscErrorCode   ierr;
101*6528b96dSMatthew G. Knepley 
102*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
103*6528b96dSMatthew G. Knepley   key.label = label; key.value = value; key.field = f;
104*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormGet(ht, key, &chunk);CHKERRQ(ierr);
105*6528b96dSMatthew G. Knepley   if (chunk.size < 0) {*n = 0;          *func = NULL;}
106*6528b96dSMatthew G. Knepley   else                {*n = chunk.size; *func = &((void (**)()) wf->funcs->array)[chunk.start];}
107*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
108*6528b96dSMatthew G. Knepley }
109*6528b96dSMatthew G. Knepley 
110*6528b96dSMatthew G. Knepley /* A NULL argument for func causes this to clear the key */
111*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormSetFunction_Private(PetscWeakForm wf, PetscHMapForm ht, DMLabel label, PetscInt value, PetscInt f, PetscInt n, void (**func)())
112*6528b96dSMatthew G. Knepley {
113*6528b96dSMatthew G. Knepley   PetscHashFormKey key;
114*6528b96dSMatthew G. Knepley   PetscChunk       chunk;
115*6528b96dSMatthew G. Knepley   PetscInt         i;
116*6528b96dSMatthew G. Knepley   PetscErrorCode   ierr;
117*6528b96dSMatthew G. Knepley 
118*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
119*6528b96dSMatthew G. Knepley   key.label = label; key.value = value; key.field = f;
120*6528b96dSMatthew G. Knepley   if (!func) {
121*6528b96dSMatthew G. Knepley     ierr = PetscHMapFormDel(ht, key);CHKERRQ(ierr);
122*6528b96dSMatthew G. Knepley     PetscFunctionReturn(0);
123*6528b96dSMatthew G. Knepley   } else {
124*6528b96dSMatthew G. Knepley     ierr = PetscHMapFormGet(ht, key, &chunk);CHKERRQ(ierr);
125*6528b96dSMatthew G. Knepley   }
126*6528b96dSMatthew G. Knepley   if (chunk.size < 0) {
127*6528b96dSMatthew G. Knepley     ierr = PetscChunkBufferCreateChunk(wf->funcs, n, &chunk);CHKERRQ(ierr);
128*6528b96dSMatthew G. Knepley     ierr = PetscHMapFormSet(ht, key, chunk);CHKERRQ(ierr);
129*6528b96dSMatthew G. Knepley   } else if (chunk.size <= n) {
130*6528b96dSMatthew G. Knepley     ierr = PetscChunkBufferEnlargeChunk(wf->funcs, n - chunk.size, &chunk);CHKERRQ(ierr);
131*6528b96dSMatthew G. Knepley     ierr = PetscHMapFormSet(ht, key, chunk);CHKERRQ(ierr);
132*6528b96dSMatthew G. Knepley   }
133*6528b96dSMatthew G. Knepley   for (i = 0; i < n; ++i) ((void (**)()) wf->funcs->array)[chunk.start+i] = func[i];
134*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
135*6528b96dSMatthew G. Knepley }
136*6528b96dSMatthew G. Knepley 
137*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormAddFunction_Private(PetscWeakForm wf, PetscHMapForm ht, DMLabel label, PetscInt value, PetscInt f, void (*func)())
138*6528b96dSMatthew G. Knepley {
139*6528b96dSMatthew G. Knepley   PetscHashFormKey key;
140*6528b96dSMatthew G. Knepley   PetscChunk       chunk;
141*6528b96dSMatthew G. Knepley   PetscErrorCode   ierr;
142*6528b96dSMatthew G. Knepley 
143*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
144*6528b96dSMatthew G. Knepley   if (!func) PetscFunctionReturn(0);
145*6528b96dSMatthew G. Knepley   key.label = label; key.value = value; key.field = f;
146*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormGet(ht, key, &chunk);CHKERRQ(ierr);
147*6528b96dSMatthew G. Knepley   if (chunk.size < 0) {
148*6528b96dSMatthew G. Knepley     ierr = PetscChunkBufferCreateChunk(wf->funcs, 1, &chunk);CHKERRQ(ierr);
149*6528b96dSMatthew G. Knepley     ierr = PetscHMapFormSet(ht, key, chunk);CHKERRQ(ierr);
150*6528b96dSMatthew G. Knepley     ((void (**)()) wf->funcs->array)[chunk.start] = func;
151*6528b96dSMatthew G. Knepley   } else {
152*6528b96dSMatthew G. Knepley     ierr = PetscChunkBufferEnlargeChunk(wf->funcs, 1, &chunk);CHKERRQ(ierr);
153*6528b96dSMatthew G. Knepley     ierr = PetscHMapFormSet(ht, key, chunk);CHKERRQ(ierr);
154*6528b96dSMatthew G. Knepley     ((void (**)()) wf->funcs->array)[chunk.start+chunk.size-1] = func;
155*6528b96dSMatthew G. Knepley   }
156*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
157*6528b96dSMatthew G. Knepley }
158*6528b96dSMatthew G. Knepley 
159*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormGetIndexFunction_Private(PetscWeakForm wf, PetscHMapForm ht, DMLabel label, PetscInt value, PetscInt f, PetscInt ind, void (**func)())
160*6528b96dSMatthew G. Knepley {
161*6528b96dSMatthew G. Knepley   PetscHashFormKey key;
162*6528b96dSMatthew G. Knepley   PetscChunk       chunk;
163*6528b96dSMatthew G. Knepley   PetscErrorCode   ierr;
164*6528b96dSMatthew G. Knepley 
165*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
166*6528b96dSMatthew G. Knepley   key.label = label; key.value = value; key.field = f;
167*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormGet(ht, key, &chunk);CHKERRQ(ierr);
168*6528b96dSMatthew G. Knepley   if (chunk.size < 0) {*func = NULL;}
169*6528b96dSMatthew G. Knepley   else {
170*6528b96dSMatthew G. Knepley     if (ind >= chunk.size) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Index %D not in [0, %D)", ind, chunk.size);
171*6528b96dSMatthew G. Knepley     *func = ((void (**)()) wf->funcs->array)[chunk.start+ind];
172*6528b96dSMatthew G. Knepley   }
173*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
174*6528b96dSMatthew G. Knepley }
175*6528b96dSMatthew G. Knepley 
176*6528b96dSMatthew G. Knepley /* A NULL argument for func causes this to clear the slot, and if there is nothing else, clear the key */
177*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormSetIndexFunction_Private(PetscWeakForm wf, PetscHMapForm ht, DMLabel label, PetscInt value, PetscInt f, PetscInt ind, void (*func)())
178*6528b96dSMatthew G. Knepley {
179*6528b96dSMatthew G. Knepley   PetscHashFormKey key;
180*6528b96dSMatthew G. Knepley   PetscChunk       chunk;
181*6528b96dSMatthew G. Knepley   PetscErrorCode   ierr;
182*6528b96dSMatthew G. Knepley 
183*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
184*6528b96dSMatthew G. Knepley   key.label = label; key.value = value; key.field = f;
185*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormGet(ht, key, &chunk);CHKERRQ(ierr);
186*6528b96dSMatthew G. Knepley   if (chunk.size < 0) {
187*6528b96dSMatthew G. Knepley     if (!func) PetscFunctionReturn(0);
188*6528b96dSMatthew G. Knepley     ierr = PetscChunkBufferCreateChunk(wf->funcs, ind+1, &chunk);CHKERRQ(ierr);
189*6528b96dSMatthew G. Knepley     ierr = PetscHMapFormSet(ht, key, chunk);CHKERRQ(ierr);
190*6528b96dSMatthew G. Knepley   } else if (!func && !ind && chunk.size == 1) {
191*6528b96dSMatthew G. Knepley     ierr = PetscHMapFormDel(ht, key);CHKERRQ(ierr);
192*6528b96dSMatthew G. Knepley     PetscFunctionReturn(0);
193*6528b96dSMatthew G. Knepley   } else if (chunk.size <= ind) {
194*6528b96dSMatthew G. Knepley     ierr = PetscChunkBufferEnlargeChunk(wf->funcs, ind - chunk.size + 1, &chunk);CHKERRQ(ierr);
195*6528b96dSMatthew G. Knepley     ierr = PetscHMapFormSet(ht, key, chunk);CHKERRQ(ierr);
196*6528b96dSMatthew G. Knepley   }
197*6528b96dSMatthew G. Knepley   ((void (**)()) wf->funcs->array)[chunk.start+ind] = func;
198*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
199*6528b96dSMatthew G. Knepley }
200*6528b96dSMatthew G. Knepley 
201*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormGetObjective(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt *n,
202*6528b96dSMatthew G. Knepley                                          void (***obj)(PetscInt, PetscInt, PetscInt,
203*6528b96dSMatthew G. Knepley                                                        const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
204*6528b96dSMatthew G. Knepley                                                        const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
205*6528b96dSMatthew G. Knepley                                                        PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
206*6528b96dSMatthew G. Knepley {
207*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
208*6528b96dSMatthew G. Knepley 
209*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
210*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->obj, label, val, f, n, (void (***)(void)) obj);CHKERRQ(ierr);
211*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
212*6528b96dSMatthew G. Knepley }
213*6528b96dSMatthew G. Knepley 
214*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormSetObjective(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt n,
215*6528b96dSMatthew G. Knepley                                          void (**obj)(PetscInt, PetscInt, PetscInt,
216*6528b96dSMatthew G. Knepley                                                       const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const  PetscScalar[],
217*6528b96dSMatthew G. Knepley                                                       const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
218*6528b96dSMatthew G. Knepley                                                       PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
219*6528b96dSMatthew G. Knepley {
220*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
221*6528b96dSMatthew G. Knepley 
222*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
223*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->obj, label, val, f, n, (void (**)(void)) obj);CHKERRQ(ierr);
224*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
225*6528b96dSMatthew G. Knepley }
226*6528b96dSMatthew G. Knepley 
227*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormAddObjective(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f,
228*6528b96dSMatthew G. Knepley                                          void (*obj)(PetscInt, PetscInt, PetscInt,
229*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
230*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
231*6528b96dSMatthew G. Knepley                                                      PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
232*6528b96dSMatthew G. Knepley {
233*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
234*6528b96dSMatthew G. Knepley 
235*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
236*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->obj, label, val, f, (void (*)(void)) obj);CHKERRQ(ierr);
237*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
238*6528b96dSMatthew G. Knepley }
239*6528b96dSMatthew G. Knepley 
240*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormGetIndexObjective(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt ind,
241*6528b96dSMatthew G. Knepley                                               void (**obj)(PetscInt, PetscInt, PetscInt,
242*6528b96dSMatthew G. Knepley                                                            const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
243*6528b96dSMatthew G. Knepley                                                            const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
244*6528b96dSMatthew G. Knepley                                                            PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
245*6528b96dSMatthew G. Knepley {
246*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
247*6528b96dSMatthew G. Knepley 
248*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
249*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetIndexFunction_Private(wf, wf->obj, label, val, f, ind, (void (**)(void)) obj);CHKERRQ(ierr);
250*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
251*6528b96dSMatthew G. Knepley }
252*6528b96dSMatthew G. Knepley 
253*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormSetIndexObjective(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt ind,
254*6528b96dSMatthew G. Knepley                                               void (*obj)(PetscInt, PetscInt, PetscInt,
255*6528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
256*6528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
257*6528b96dSMatthew G. Knepley                                                           PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
258*6528b96dSMatthew G. Knepley {
259*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
260*6528b96dSMatthew G. Knepley 
261*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
262*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->obj, label, val, f, ind, (void (*)(void)) obj);CHKERRQ(ierr);
263*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
264*6528b96dSMatthew G. Knepley }
265*6528b96dSMatthew G. Knepley 
266*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormGetResidual(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f,
267*6528b96dSMatthew G. Knepley                                         PetscInt *n0,
268*6528b96dSMatthew G. Knepley                                         void (***f0)(PetscInt, PetscInt, PetscInt,
269*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
270*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
271*6528b96dSMatthew G. Knepley                                                      PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
272*6528b96dSMatthew G. Knepley                                         PetscInt *n1,
273*6528b96dSMatthew G. Knepley                                         void (***f1)(PetscInt, PetscInt, PetscInt,
274*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
275*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
276*6528b96dSMatthew G. Knepley                                                      PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
277*6528b96dSMatthew G. Knepley {
278*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
279*6528b96dSMatthew G. Knepley 
280*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
281*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->f0, label, val, f, n0, (void (***)(void)) f0);CHKERRQ(ierr);
282*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->f1, label, val, f, n1, (void (***)(void)) f1);CHKERRQ(ierr);
283*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
284*6528b96dSMatthew G. Knepley }
285*6528b96dSMatthew G. Knepley 
286*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormAddResidual(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f,
287*6528b96dSMatthew G. Knepley                                         void (*f0)(PetscInt, PetscInt, PetscInt,
288*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
289*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
290*6528b96dSMatthew G. Knepley                                                    PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
291*6528b96dSMatthew G. Knepley                                         void (*f1)(PetscInt, PetscInt, PetscInt,
292*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
293*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
294*6528b96dSMatthew G. Knepley                                                    PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
295*6528b96dSMatthew G. Knepley {
296*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
297*6528b96dSMatthew G. Knepley 
298*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
299*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->f0, label, val, f, (void (*)(void)) f0);CHKERRQ(ierr);
300*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->f1, label, val, f, (void (*)(void)) f1);CHKERRQ(ierr);
301*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
302*6528b96dSMatthew G. Knepley }
303*6528b96dSMatthew G. Knepley 
304*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormSetResidual(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f,
305*6528b96dSMatthew G. Knepley                                         PetscInt n0,
306*6528b96dSMatthew G. Knepley                                         void (**f0)(PetscInt, PetscInt, PetscInt,
307*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
308*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
309*6528b96dSMatthew G. Knepley                                                    PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
310*6528b96dSMatthew G. Knepley                                         PetscInt n1,
311*6528b96dSMatthew G. Knepley                                         void (**f1)(PetscInt, PetscInt, PetscInt,
312*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
313*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
314*6528b96dSMatthew G. Knepley                                                    PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
315*6528b96dSMatthew G. Knepley {
316*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
317*6528b96dSMatthew G. Knepley 
318*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
319*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->f0, label, val, f, n0, (void (**)(void)) f0);CHKERRQ(ierr);
320*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->f1, label, val, f, n1, (void (**)(void)) f1);CHKERRQ(ierr);
321*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
322*6528b96dSMatthew G. Knepley }
323*6528b96dSMatthew G. Knepley 
324*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormSetIndexResidual(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f,
325*6528b96dSMatthew G. Knepley                                         PetscInt i0,
326*6528b96dSMatthew G. Knepley                                         void (*f0)(PetscInt, PetscInt, PetscInt,
327*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
328*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
329*6528b96dSMatthew G. Knepley                                                    PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
330*6528b96dSMatthew G. Knepley                                         PetscInt i1,
331*6528b96dSMatthew G. Knepley                                         void (*f1)(PetscInt, PetscInt, PetscInt,
332*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
333*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
334*6528b96dSMatthew G. Knepley                                                    PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
335*6528b96dSMatthew G. Knepley {
336*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
337*6528b96dSMatthew G. Knepley 
338*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
339*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->f0, label, val, f, i0, (void (*)(void)) f0);CHKERRQ(ierr);
340*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->f1, label, val, f, i1, (void (*)(void)) f1);CHKERRQ(ierr);
341*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
342*6528b96dSMatthew G. Knepley }
343*6528b96dSMatthew G. Knepley 
344*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormGetBdResidual(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f,
345*6528b96dSMatthew G. Knepley                                           PetscInt *n0,
346*6528b96dSMatthew G. Knepley                                         void (***f0)(PetscInt, PetscInt, PetscInt,
347*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
348*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
349*6528b96dSMatthew G. Knepley                                                      PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
350*6528b96dSMatthew G. Knepley                                         PetscInt *n1,
351*6528b96dSMatthew G. Knepley                                         void (***f1)(PetscInt, PetscInt, PetscInt,
352*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
353*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
354*6528b96dSMatthew G. Knepley                                                      PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
355*6528b96dSMatthew G. Knepley {
356*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
357*6528b96dSMatthew G. Knepley 
358*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
359*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->bdf0, label, val, f, n0, (void (***)(void)) f0);CHKERRQ(ierr);
360*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->bdf1, label, val, f, n1, (void (***)(void)) f1);CHKERRQ(ierr);
361*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
362*6528b96dSMatthew G. Knepley }
363*6528b96dSMatthew G. Knepley 
364*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormAddBdResidual(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f,
365*6528b96dSMatthew G. Knepley                                           void (*f0)(PetscInt, PetscInt, PetscInt,
366*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
367*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
368*6528b96dSMatthew G. Knepley                                                      PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
369*6528b96dSMatthew G. Knepley                                           void (*f1)(PetscInt, PetscInt, PetscInt,
370*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
371*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
372*6528b96dSMatthew G. Knepley                                                      PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
373*6528b96dSMatthew G. Knepley {
374*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
375*6528b96dSMatthew G. Knepley 
376*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
377*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->bdf0, label, val, f, (void (*)(void)) f0);CHKERRQ(ierr);
378*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->bdf1, label, val, f, (void (*)(void)) f1);CHKERRQ(ierr);
379*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
380*6528b96dSMatthew G. Knepley }
381*6528b96dSMatthew G. Knepley 
382*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormSetBdResidual(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f,
383*6528b96dSMatthew G. Knepley                                           PetscInt n0,
384*6528b96dSMatthew G. Knepley                                           void (**f0)(PetscInt, PetscInt, PetscInt,
385*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
386*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
387*6528b96dSMatthew G. Knepley                                                      PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
388*6528b96dSMatthew G. Knepley                                           PetscInt n1,
389*6528b96dSMatthew G. Knepley                                           void (**f1)(PetscInt, PetscInt, PetscInt,
390*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
391*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
392*6528b96dSMatthew G. Knepley                                                      PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
393*6528b96dSMatthew G. Knepley {
394*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
395*6528b96dSMatthew G. Knepley 
396*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
397*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->bdf0, label, val, f, n0, (void (**)(void)) f0);CHKERRQ(ierr);
398*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->bdf1, label, val, f, n1, (void (**)(void)) f1);CHKERRQ(ierr);
399*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
400*6528b96dSMatthew G. Knepley }
401*6528b96dSMatthew G. Knepley 
402*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormSetIndexBdResidual(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f,
403*6528b96dSMatthew G. Knepley                                           PetscInt i0,
404*6528b96dSMatthew G. Knepley                                           void (*f0)(PetscInt, PetscInt, PetscInt,
405*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
406*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
407*6528b96dSMatthew G. Knepley                                                      PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
408*6528b96dSMatthew G. Knepley                                           PetscInt i1,
409*6528b96dSMatthew G. Knepley                                           void (*f1)(PetscInt, PetscInt, PetscInt,
410*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
411*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
412*6528b96dSMatthew G. Knepley                                                      PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
413*6528b96dSMatthew G. Knepley {
414*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
415*6528b96dSMatthew G. Knepley 
416*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
417*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->bdf0, label, val, f, i0, (void (*)(void)) f0);CHKERRQ(ierr);
418*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->bdf1, label, val, f, i1, (void (*)(void)) f1);CHKERRQ(ierr);
419*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
420*6528b96dSMatthew G. Knepley }
421*6528b96dSMatthew G. Knepley 
422*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormHasJacobian(PetscWeakForm wf, PetscBool *hasJac)
423*6528b96dSMatthew G. Knepley {
424*6528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
425*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
426*6528b96dSMatthew G. Knepley 
427*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
428*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(wf, PETSCWEAKFORM_CLASSID, 1);
429*6528b96dSMatthew G. Knepley   PetscValidBoolPointer(hasJac, 2);
430*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->g0, &n0);CHKERRQ(ierr);
431*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->g1, &n1);CHKERRQ(ierr);
432*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->g2, &n2);CHKERRQ(ierr);
433*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->g3, &n3);CHKERRQ(ierr);
434*6528b96dSMatthew G. Knepley   *hasJac = n0+n1+n2+n3 ? PETSC_TRUE : PETSC_FALSE;
435*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
436*6528b96dSMatthew G. Knepley }
437*6528b96dSMatthew G. Knepley 
438*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormGetJacobian(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g,
439*6528b96dSMatthew G. Knepley                                         PetscInt *n0,
440*6528b96dSMatthew G. Knepley                                         void (***g0)(PetscInt, PetscInt, PetscInt,
441*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
442*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
443*6528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
444*6528b96dSMatthew G. Knepley                                         PetscInt *n1,
445*6528b96dSMatthew G. Knepley                                         void (***g1)(PetscInt, PetscInt, PetscInt,
446*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
447*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
448*6528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
449*6528b96dSMatthew G. Knepley                                         PetscInt *n2,
450*6528b96dSMatthew G. Knepley                                         void (***g2)(PetscInt, PetscInt, PetscInt,
451*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
452*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
453*6528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
454*6528b96dSMatthew G. Knepley                                         PetscInt *n3,
455*6528b96dSMatthew G. Knepley                                         void (***g3)(PetscInt, PetscInt, PetscInt,
456*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
457*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
458*6528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
459*6528b96dSMatthew G. Knepley {
460*6528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
461*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
462*6528b96dSMatthew G. Knepley 
463*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
464*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->g0, label, val, find, n0, (void (***)(void)) g0);CHKERRQ(ierr);
465*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->g1, label, val, find, n1, (void (***)(void)) g1);CHKERRQ(ierr);
466*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->g2, label, val, find, n2, (void (***)(void)) g2);CHKERRQ(ierr);
467*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->g3, label, val, find, n3, (void (***)(void)) g3);CHKERRQ(ierr);
468*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
469*6528b96dSMatthew G. Knepley }
470*6528b96dSMatthew G. Knepley 
471*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormAddJacobian(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g,
472*6528b96dSMatthew G. Knepley                                         void (*g0)(PetscInt, PetscInt, PetscInt,
473*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
474*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
475*6528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
476*6528b96dSMatthew G. Knepley                                         void (*g1)(PetscInt, PetscInt, PetscInt,
477*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
478*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
479*6528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
480*6528b96dSMatthew G. Knepley                                         void (*g2)(PetscInt, PetscInt, PetscInt,
481*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
482*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
483*6528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
484*6528b96dSMatthew G. Knepley                                         void (*g3)(PetscInt, PetscInt, PetscInt,
485*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
486*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
487*6528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
488*6528b96dSMatthew G. Knepley {
489*6528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
490*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
491*6528b96dSMatthew G. Knepley 
492*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
493*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->g0, label, val, find, (void (*)(void)) g0);CHKERRQ(ierr);
494*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->g1, label, val, find, (void (*)(void)) g1);CHKERRQ(ierr);
495*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->g2, label, val, find, (void (*)(void)) g2);CHKERRQ(ierr);
496*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->g3, label, val, find, (void (*)(void)) g3);CHKERRQ(ierr);
497*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
498*6528b96dSMatthew G. Knepley }
499*6528b96dSMatthew G. Knepley 
500*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormSetJacobian(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g,
501*6528b96dSMatthew G. Knepley                                         PetscInt n0,
502*6528b96dSMatthew G. Knepley                                         void (**g0)(PetscInt, PetscInt, PetscInt,
503*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
504*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
505*6528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
506*6528b96dSMatthew G. Knepley                                         PetscInt n1,
507*6528b96dSMatthew G. Knepley                                         void (**g1)(PetscInt, PetscInt, PetscInt,
508*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
509*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
510*6528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
511*6528b96dSMatthew G. Knepley                                         PetscInt n2,
512*6528b96dSMatthew G. Knepley                                         void (**g2)(PetscInt, PetscInt, PetscInt,
513*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
514*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
515*6528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
516*6528b96dSMatthew G. Knepley                                         PetscInt n3,
517*6528b96dSMatthew G. Knepley                                         void (**g3)(PetscInt, PetscInt, PetscInt,
518*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
519*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
520*6528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
521*6528b96dSMatthew G. Knepley {
522*6528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
523*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
524*6528b96dSMatthew G. Knepley 
525*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
526*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->g0, label, val, find, n0, (void (**)(void)) g0);CHKERRQ(ierr);
527*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->g1, label, val, find, n1, (void (**)(void)) g1);CHKERRQ(ierr);
528*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->g2, label, val, find, n2, (void (**)(void)) g2);CHKERRQ(ierr);
529*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->g3, label, val, find, n3, (void (**)(void)) g3);CHKERRQ(ierr);
530*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
531*6528b96dSMatthew G. Knepley }
532*6528b96dSMatthew G. Knepley 
533*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormSetIndexJacobian(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g,
534*6528b96dSMatthew G. Knepley                                         PetscInt i0,
535*6528b96dSMatthew G. Knepley                                         void (*g0)(PetscInt, PetscInt, PetscInt,
536*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
537*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
538*6528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
539*6528b96dSMatthew G. Knepley                                         PetscInt i1,
540*6528b96dSMatthew G. Knepley                                         void (*g1)(PetscInt, PetscInt, PetscInt,
541*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
542*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
543*6528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
544*6528b96dSMatthew G. Knepley                                         PetscInt i2,
545*6528b96dSMatthew G. Knepley                                         void (*g2)(PetscInt, PetscInt, PetscInt,
546*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
547*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
548*6528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
549*6528b96dSMatthew G. Knepley                                         PetscInt i3,
550*6528b96dSMatthew G. Knepley                                         void (*g3)(PetscInt, PetscInt, PetscInt,
551*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
552*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
553*6528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
554*6528b96dSMatthew G. Knepley {
555*6528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
556*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
557*6528b96dSMatthew G. Knepley 
558*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
559*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->g0, label, val, find, i0, (void (*)(void)) g0);CHKERRQ(ierr);
560*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->g1, label, val, find, i1, (void (*)(void)) g1);CHKERRQ(ierr);
561*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->g2, label, val, find, i2, (void (*)(void)) g2);CHKERRQ(ierr);
562*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->g3, label, val, find, i3, (void (*)(void)) g3);CHKERRQ(ierr);
563*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
564*6528b96dSMatthew G. Knepley }
565*6528b96dSMatthew G. Knepley 
566*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormHasJacobianPreconditioner(PetscWeakForm wf, PetscBool *hasJacPre)
567*6528b96dSMatthew G. Knepley {
568*6528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
569*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
570*6528b96dSMatthew G. Knepley 
571*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
572*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(wf, PETSCWEAKFORM_CLASSID, 1);
573*6528b96dSMatthew G. Knepley   PetscValidBoolPointer(hasJacPre, 2);
574*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->gp0, &n0);CHKERRQ(ierr);
575*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->gp1, &n1);CHKERRQ(ierr);
576*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->gp2, &n2);CHKERRQ(ierr);
577*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->gp3, &n3);CHKERRQ(ierr);
578*6528b96dSMatthew G. Knepley   *hasJacPre = n0+n1+n2+n3 ? PETSC_TRUE : PETSC_FALSE;
579*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
580*6528b96dSMatthew G. Knepley }
581*6528b96dSMatthew G. Knepley 
582*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormGetJacobianPreconditioner(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g,
583*6528b96dSMatthew G. Knepley                                                       PetscInt *n0,
584*6528b96dSMatthew G. Knepley                                                       void (***g0)(PetscInt, PetscInt, PetscInt,
585*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
586*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
587*6528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
588*6528b96dSMatthew G. Knepley                                                       PetscInt *n1,
589*6528b96dSMatthew G. Knepley                                                       void (***g1)(PetscInt, PetscInt, PetscInt,
590*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
591*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
592*6528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
593*6528b96dSMatthew G. Knepley                                                       PetscInt *n2,
594*6528b96dSMatthew G. Knepley                                                       void (***g2)(PetscInt, PetscInt, PetscInt,
595*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
596*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
597*6528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
598*6528b96dSMatthew G. Knepley                                                       PetscInt *n3,
599*6528b96dSMatthew G. Knepley                                                       void (***g3)(PetscInt, PetscInt, PetscInt,
600*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
601*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
602*6528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
603*6528b96dSMatthew G. Knepley {
604*6528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
605*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
606*6528b96dSMatthew G. Knepley 
607*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
608*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->gp0, label, val, find, n0, (void (***)(void)) g0);CHKERRQ(ierr);
609*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->gp1, label, val, find, n1, (void (***)(void)) g1);CHKERRQ(ierr);
610*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->gp2, label, val, find, n2, (void (***)(void)) g2);CHKERRQ(ierr);
611*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->gp3, label, val, find, n3, (void (***)(void)) g3);CHKERRQ(ierr);
612*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
613*6528b96dSMatthew G. Knepley }
614*6528b96dSMatthew G. Knepley 
615*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormAddJacobianPreconditioner(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g,
616*6528b96dSMatthew G. Knepley                                         void (*g0)(PetscInt, PetscInt, PetscInt,
617*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
618*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
619*6528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
620*6528b96dSMatthew G. Knepley                                         void (*g1)(PetscInt, PetscInt, PetscInt,
621*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
622*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
623*6528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
624*6528b96dSMatthew G. Knepley                                         void (*g2)(PetscInt, PetscInt, PetscInt,
625*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
626*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
627*6528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
628*6528b96dSMatthew G. Knepley                                         void (*g3)(PetscInt, PetscInt, PetscInt,
629*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
630*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
631*6528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
632*6528b96dSMatthew G. Knepley {
633*6528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
634*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
635*6528b96dSMatthew G. Knepley 
636*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
637*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->gp0, label, val, find, (void (*)(void)) g0);CHKERRQ(ierr);
638*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->gp1, label, val, find, (void (*)(void)) g1);CHKERRQ(ierr);
639*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->gp2, label, val, find, (void (*)(void)) g2);CHKERRQ(ierr);
640*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->gp3, label, val, find, (void (*)(void)) g3);CHKERRQ(ierr);
641*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
642*6528b96dSMatthew G. Knepley }
643*6528b96dSMatthew G. Knepley 
644*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormSetJacobianPreconditioner(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g,
645*6528b96dSMatthew G. Knepley                                                       PetscInt n0,
646*6528b96dSMatthew G. Knepley                                                       void (**g0)(PetscInt, PetscInt, PetscInt,
647*6528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
648*6528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
649*6528b96dSMatthew G. Knepley                                                                  PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
650*6528b96dSMatthew G. Knepley                                                       PetscInt n1,
651*6528b96dSMatthew G. Knepley                                                       void (**g1)(PetscInt, PetscInt, PetscInt,
652*6528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
653*6528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
654*6528b96dSMatthew G. Knepley                                                                  PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
655*6528b96dSMatthew G. Knepley                                                       PetscInt n2,
656*6528b96dSMatthew G. Knepley                                                       void (**g2)(PetscInt, PetscInt, PetscInt,
657*6528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
658*6528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
659*6528b96dSMatthew G. Knepley                                                                  PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
660*6528b96dSMatthew G. Knepley                                                       PetscInt n3,
661*6528b96dSMatthew G. Knepley                                                       void (**g3)(PetscInt, PetscInt, PetscInt,
662*6528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
663*6528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
664*6528b96dSMatthew G. Knepley                                                                  PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
665*6528b96dSMatthew G. Knepley {
666*6528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
667*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
668*6528b96dSMatthew G. Knepley 
669*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
670*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->gp0, label, val, find, n0, (void (**)(void)) g0);CHKERRQ(ierr);
671*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->gp1, label, val, find, n1, (void (**)(void)) g1);CHKERRQ(ierr);
672*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->gp2, label, val, find, n2, (void (**)(void)) g2);CHKERRQ(ierr);
673*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->gp3, label, val, find, n3, (void (**)(void)) g3);CHKERRQ(ierr);
674*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
675*6528b96dSMatthew G. Knepley }
676*6528b96dSMatthew G. Knepley 
677*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormSetIndexJacobianPreconditioner(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g,
678*6528b96dSMatthew G. Knepley                                                       PetscInt i0,
679*6528b96dSMatthew G. Knepley                                                       void (*g0)(PetscInt, PetscInt, PetscInt,
680*6528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
681*6528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
682*6528b96dSMatthew G. Knepley                                                                  PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
683*6528b96dSMatthew G. Knepley                                                       PetscInt i1,
684*6528b96dSMatthew G. Knepley                                                       void (*g1)(PetscInt, PetscInt, PetscInt,
685*6528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
686*6528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
687*6528b96dSMatthew G. Knepley                                                                  PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
688*6528b96dSMatthew G. Knepley                                                       PetscInt i2,
689*6528b96dSMatthew G. Knepley                                                       void (*g2)(PetscInt, PetscInt, PetscInt,
690*6528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
691*6528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
692*6528b96dSMatthew G. Knepley                                                                  PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
693*6528b96dSMatthew G. Knepley                                                       PetscInt i3,
694*6528b96dSMatthew G. Knepley                                                       void (*g3)(PetscInt, PetscInt, PetscInt,
695*6528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
696*6528b96dSMatthew G. Knepley                                                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
697*6528b96dSMatthew G. Knepley                                                                  PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
698*6528b96dSMatthew G. Knepley {
699*6528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
700*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
701*6528b96dSMatthew G. Knepley 
702*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
703*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->gp0, label, val, find, i0, (void (*)(void)) g0);CHKERRQ(ierr);
704*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->gp1, label, val, find, i1, (void (*)(void)) g1);CHKERRQ(ierr);
705*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->gp2, label, val, find, i2, (void (*)(void)) g2);CHKERRQ(ierr);
706*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->gp3, label, val, find, i3, (void (*)(void)) g3);CHKERRQ(ierr);
707*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
708*6528b96dSMatthew G. Knepley }
709*6528b96dSMatthew G. Knepley 
710*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormHasBdJacobian(PetscWeakForm wf, PetscBool *hasJac)
711*6528b96dSMatthew G. Knepley {
712*6528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
713*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
714*6528b96dSMatthew G. Knepley 
715*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
716*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(wf, PETSCWEAKFORM_CLASSID, 1);
717*6528b96dSMatthew G. Knepley   PetscValidBoolPointer(hasJac, 2);
718*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->bdg0, &n0);CHKERRQ(ierr);
719*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->bdg1, &n1);CHKERRQ(ierr);
720*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->bdg2, &n2);CHKERRQ(ierr);
721*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->bdg3, &n3);CHKERRQ(ierr);
722*6528b96dSMatthew G. Knepley   *hasJac = n0+n1+n2+n3 ? PETSC_TRUE : PETSC_FALSE;
723*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
724*6528b96dSMatthew G. Knepley }
725*6528b96dSMatthew G. Knepley 
726*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormGetBdJacobian(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g,
727*6528b96dSMatthew G. Knepley                                           PetscInt *n0,
728*6528b96dSMatthew G. Knepley                                           void (***g0)(PetscInt, PetscInt, PetscInt,
729*6528b96dSMatthew G. Knepley                                                        const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
730*6528b96dSMatthew G. Knepley                                                        const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
731*6528b96dSMatthew G. Knepley                                                        PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
732*6528b96dSMatthew G. Knepley                                           PetscInt *n1,
733*6528b96dSMatthew G. Knepley                                           void (***g1)(PetscInt, PetscInt, PetscInt,
734*6528b96dSMatthew G. Knepley                                                        const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
735*6528b96dSMatthew G. Knepley                                                        const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
736*6528b96dSMatthew G. Knepley                                                        PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
737*6528b96dSMatthew G. Knepley                                           PetscInt *n2,
738*6528b96dSMatthew G. Knepley                                           void (***g2)(PetscInt, PetscInt, PetscInt,
739*6528b96dSMatthew G. Knepley                                                        const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
740*6528b96dSMatthew G. Knepley                                                        const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
741*6528b96dSMatthew G. Knepley                                                        PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
742*6528b96dSMatthew G. Knepley                                           PetscInt *n3,
743*6528b96dSMatthew G. Knepley                                           void (***g3)(PetscInt, PetscInt, PetscInt,
744*6528b96dSMatthew G. Knepley                                                        const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
745*6528b96dSMatthew G. Knepley                                                        const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
746*6528b96dSMatthew G. Knepley                                                        PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
747*6528b96dSMatthew G. Knepley {
748*6528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
749*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
750*6528b96dSMatthew G. Knepley 
751*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
752*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->bdg0, label, val, find, n0, (void (***)(void)) g0);CHKERRQ(ierr);
753*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->bdg1, label, val, find, n1, (void (***)(void)) g1);CHKERRQ(ierr);
754*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->bdg2, label, val, find, n2, (void (***)(void)) g2);CHKERRQ(ierr);
755*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->bdg3, label, val, find, n3, (void (***)(void)) g3);CHKERRQ(ierr);
756*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
757*6528b96dSMatthew G. Knepley }
758*6528b96dSMatthew G. Knepley 
759*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormAddBdJacobian(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g,
760*6528b96dSMatthew G. Knepley                                           void (*g0)(PetscInt, PetscInt, PetscInt,
761*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
762*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
763*6528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
764*6528b96dSMatthew G. Knepley                                           void (*g1)(PetscInt, PetscInt, PetscInt,
765*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
766*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
767*6528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
768*6528b96dSMatthew G. Knepley                                           void (*g2)(PetscInt, PetscInt, PetscInt,
769*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
770*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
771*6528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
772*6528b96dSMatthew G. Knepley                                           void (*g3)(PetscInt, PetscInt, PetscInt,
773*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
774*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
775*6528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
776*6528b96dSMatthew G. Knepley {
777*6528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
778*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
779*6528b96dSMatthew G. Knepley 
780*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
781*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->bdg0, label, val, find, (void (*)(void)) g0);CHKERRQ(ierr);
782*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->bdg1, label, val, find, (void (*)(void)) g1);CHKERRQ(ierr);
783*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->bdg2, label, val, find, (void (*)(void)) g2);CHKERRQ(ierr);
784*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->bdg3, label, val, find, (void (*)(void)) g3);CHKERRQ(ierr);
785*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
786*6528b96dSMatthew G. Knepley }
787*6528b96dSMatthew G. Knepley 
788*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormSetBdJacobian(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g,
789*6528b96dSMatthew G. Knepley                                           PetscInt n0,
790*6528b96dSMatthew G. Knepley                                           void (**g0)(PetscInt, PetscInt, PetscInt,
791*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
792*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
793*6528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
794*6528b96dSMatthew G. Knepley                                           PetscInt n1,
795*6528b96dSMatthew G. Knepley                                           void (**g1)(PetscInt, PetscInt, PetscInt,
796*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
797*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
798*6528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
799*6528b96dSMatthew G. Knepley                                           PetscInt n2,
800*6528b96dSMatthew G. Knepley                                           void (**g2)(PetscInt, PetscInt, PetscInt,
801*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
802*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
803*6528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
804*6528b96dSMatthew G. Knepley                                           PetscInt n3,
805*6528b96dSMatthew G. Knepley                                           void (**g3)(PetscInt, PetscInt, PetscInt,
806*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
807*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
808*6528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
809*6528b96dSMatthew G. Knepley {
810*6528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
811*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
812*6528b96dSMatthew G. Knepley 
813*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
814*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->bdg0, label, val, find, n0, (void (**)(void)) g0);CHKERRQ(ierr);
815*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->bdg1, label, val, find, n1, (void (**)(void)) g1);CHKERRQ(ierr);
816*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->bdg2, label, val, find, n2, (void (**)(void)) g2);CHKERRQ(ierr);
817*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->bdg3, label, val, find, n3, (void (**)(void)) g3);CHKERRQ(ierr);
818*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
819*6528b96dSMatthew G. Knepley }
820*6528b96dSMatthew G. Knepley 
821*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormSetIndexBdJacobian(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g,
822*6528b96dSMatthew G. Knepley                                           PetscInt i0,
823*6528b96dSMatthew G. Knepley                                           void (*g0)(PetscInt, PetscInt, PetscInt,
824*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
825*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
826*6528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
827*6528b96dSMatthew G. Knepley                                           PetscInt i1,
828*6528b96dSMatthew G. Knepley                                           void (*g1)(PetscInt, PetscInt, PetscInt,
829*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
830*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
831*6528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
832*6528b96dSMatthew G. Knepley                                           PetscInt i2,
833*6528b96dSMatthew G. Knepley                                           void (*g2)(PetscInt, PetscInt, PetscInt,
834*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
835*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
836*6528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
837*6528b96dSMatthew G. Knepley                                           PetscInt i3,
838*6528b96dSMatthew G. Knepley                                           void (*g3)(PetscInt, PetscInt, PetscInt,
839*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
840*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
841*6528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
842*6528b96dSMatthew G. Knepley {
843*6528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
844*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
845*6528b96dSMatthew G. Knepley 
846*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
847*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->bdg0, label, val, find, i0, (void (*)(void)) g0);CHKERRQ(ierr);
848*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->bdg1, label, val, find, i1, (void (*)(void)) g1);CHKERRQ(ierr);
849*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->bdg2, label, val, find, i2, (void (*)(void)) g2);CHKERRQ(ierr);
850*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->bdg3, label, val, find, i3, (void (*)(void)) g3);CHKERRQ(ierr);
851*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
852*6528b96dSMatthew G. Knepley }
853*6528b96dSMatthew G. Knepley 
854*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormHasBdJacobianPreconditioner(PetscWeakForm wf, PetscBool *hasJacPre)
855*6528b96dSMatthew G. Knepley {
856*6528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
857*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
858*6528b96dSMatthew G. Knepley 
859*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
860*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(wf, PETSCWEAKFORM_CLASSID, 1);
861*6528b96dSMatthew G. Knepley   PetscValidBoolPointer(hasJacPre, 2);
862*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->bdgp0, &n0);CHKERRQ(ierr);
863*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->bdgp1, &n1);CHKERRQ(ierr);
864*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->bdgp2, &n2);CHKERRQ(ierr);
865*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->bdgp3, &n3);CHKERRQ(ierr);
866*6528b96dSMatthew G. Knepley   *hasJacPre = n0+n1+n2+n3 ? PETSC_TRUE : PETSC_FALSE;
867*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
868*6528b96dSMatthew G. Knepley }
869*6528b96dSMatthew G. Knepley 
870*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormGetBdJacobianPreconditioner(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g,
871*6528b96dSMatthew G. Knepley                                                         PetscInt *n0,
872*6528b96dSMatthew G. Knepley                                                         void (***g0)(PetscInt, PetscInt, PetscInt,
873*6528b96dSMatthew G. Knepley                                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
874*6528b96dSMatthew G. Knepley                                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
875*6528b96dSMatthew G. Knepley                                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
876*6528b96dSMatthew G. Knepley                                                         PetscInt *n1,
877*6528b96dSMatthew G. Knepley                                                         void (***g1)(PetscInt, PetscInt, PetscInt,
878*6528b96dSMatthew G. Knepley                                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
879*6528b96dSMatthew G. Knepley                                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
880*6528b96dSMatthew G. Knepley                                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
881*6528b96dSMatthew G. Knepley                                                         PetscInt *n2,
882*6528b96dSMatthew G. Knepley                                                         void (***g2)(PetscInt, PetscInt, PetscInt,
883*6528b96dSMatthew G. Knepley                                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
884*6528b96dSMatthew G. Knepley                                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
885*6528b96dSMatthew G. Knepley                                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
886*6528b96dSMatthew G. Knepley                                                         PetscInt *n3,
887*6528b96dSMatthew G. Knepley                                                         void (***g3)(PetscInt, PetscInt, PetscInt,
888*6528b96dSMatthew G. Knepley                                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
889*6528b96dSMatthew G. Knepley                                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
890*6528b96dSMatthew G. Knepley                                                                      PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
891*6528b96dSMatthew G. Knepley {
892*6528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
893*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
894*6528b96dSMatthew G. Knepley 
895*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
896*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->bdgp0, label, val, find, n0, (void (***)(void)) g0);CHKERRQ(ierr);
897*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->bdgp1, label, val, find, n1, (void (***)(void)) g1);CHKERRQ(ierr);
898*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->bdgp2, label, val, find, n2, (void (***)(void)) g2);CHKERRQ(ierr);
899*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->bdgp3, label, val, find, n3, (void (***)(void)) g3);CHKERRQ(ierr);
900*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
901*6528b96dSMatthew G. Knepley }
902*6528b96dSMatthew G. Knepley 
903*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormAddBdJacobianPreconditioner(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g,
904*6528b96dSMatthew G. Knepley                                                         void (*g0)(PetscInt, PetscInt, PetscInt,
905*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
906*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
907*6528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
908*6528b96dSMatthew G. Knepley                                                         void (*g1)(PetscInt, PetscInt, PetscInt,
909*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
910*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
911*6528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
912*6528b96dSMatthew G. Knepley                                                         void (*g2)(PetscInt, PetscInt, PetscInt,
913*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
914*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
915*6528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
916*6528b96dSMatthew G. Knepley                                                         void (*g3)(PetscInt, PetscInt, PetscInt,
917*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
918*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
919*6528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
920*6528b96dSMatthew G. Knepley {
921*6528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
922*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
923*6528b96dSMatthew G. Knepley 
924*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
925*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->bdgp0, label, val, find, (void (*)(void)) g0);CHKERRQ(ierr);
926*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->bdgp1, label, val, find, (void (*)(void)) g1);CHKERRQ(ierr);
927*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->bdgp2, label, val, find, (void (*)(void)) g2);CHKERRQ(ierr);
928*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->bdgp3, label, val, find, (void (*)(void)) g3);CHKERRQ(ierr);
929*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
930*6528b96dSMatthew G. Knepley }
931*6528b96dSMatthew G. Knepley 
932*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormSetBdJacobianPreconditioner(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g,
933*6528b96dSMatthew G. Knepley                                                         PetscInt n0,
934*6528b96dSMatthew G. Knepley                                                         void (**g0)(PetscInt, PetscInt, PetscInt,
935*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
936*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
937*6528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
938*6528b96dSMatthew G. Knepley                                                         PetscInt n1,
939*6528b96dSMatthew G. Knepley                                                         void (**g1)(PetscInt, PetscInt, PetscInt,
940*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
941*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
942*6528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
943*6528b96dSMatthew G. Knepley                                                         PetscInt n2,
944*6528b96dSMatthew G. Knepley                                                         void (**g2)(PetscInt, PetscInt, PetscInt,
945*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
946*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
947*6528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
948*6528b96dSMatthew G. Knepley                                                         PetscInt n3,
949*6528b96dSMatthew G. Knepley                                                         void (**g3)(PetscInt, PetscInt, PetscInt,
950*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
951*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
952*6528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
953*6528b96dSMatthew G. Knepley {
954*6528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
955*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
956*6528b96dSMatthew G. Knepley 
957*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
958*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->bdgp0, label, val, find, n0, (void (**)(void)) g0);CHKERRQ(ierr);
959*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->bdgp1, label, val, find, n1, (void (**)(void)) g1);CHKERRQ(ierr);
960*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->bdgp2, label, val, find, n2, (void (**)(void)) g2);CHKERRQ(ierr);
961*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->bdgp3, label, val, find, n3, (void (**)(void)) g3);CHKERRQ(ierr);
962*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
963*6528b96dSMatthew G. Knepley }
964*6528b96dSMatthew G. Knepley 
965*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormSetIndexBdJacobianPreconditioner(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g,
966*6528b96dSMatthew G. Knepley                                                         PetscInt i0,
967*6528b96dSMatthew G. Knepley                                                         void (*g0)(PetscInt, PetscInt, PetscInt,
968*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
969*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
970*6528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
971*6528b96dSMatthew G. Knepley                                                         PetscInt i1,
972*6528b96dSMatthew G. Knepley                                                         void (*g1)(PetscInt, PetscInt, PetscInt,
973*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
974*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
975*6528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
976*6528b96dSMatthew G. Knepley                                                         PetscInt i2,
977*6528b96dSMatthew G. Knepley                                                         void (*g2)(PetscInt, PetscInt, PetscInt,
978*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
979*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
980*6528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
981*6528b96dSMatthew G. Knepley                                                         PetscInt i3,
982*6528b96dSMatthew G. Knepley                                                         void (*g3)(PetscInt, PetscInt, PetscInt,
983*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
984*6528b96dSMatthew G. Knepley                                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
985*6528b96dSMatthew G. Knepley                                                                    PetscReal, PetscReal, const PetscReal[], const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
986*6528b96dSMatthew G. Knepley {
987*6528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
988*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
989*6528b96dSMatthew G. Knepley 
990*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
991*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->bdgp0, label, val, find, i0, (void (*)(void)) g0);CHKERRQ(ierr);
992*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->bdgp1, label, val, find, i1, (void (*)(void)) g1);CHKERRQ(ierr);
993*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->bdgp2, label, val, find, i2, (void (*)(void)) g2);CHKERRQ(ierr);
994*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->bdgp3, label, val, find, i3, (void (*)(void)) g3);CHKERRQ(ierr);
995*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
996*6528b96dSMatthew G. Knepley }
997*6528b96dSMatthew G. Knepley 
998*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormHasDynamicJacobian(PetscWeakForm wf, PetscBool *hasDynJac)
999*6528b96dSMatthew G. Knepley {
1000*6528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
1001*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
1002*6528b96dSMatthew G. Knepley 
1003*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
1004*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(wf, PETSCWEAKFORM_CLASSID, 1);
1005*6528b96dSMatthew G. Knepley   PetscValidBoolPointer(hasDynJac, 2);
1006*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->gt0, &n0);CHKERRQ(ierr);
1007*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->gt1, &n1);CHKERRQ(ierr);
1008*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->gt2, &n2);CHKERRQ(ierr);
1009*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormGetSize(wf->gt3, &n3);CHKERRQ(ierr);
1010*6528b96dSMatthew G. Knepley   *hasDynJac = n0+n1+n2+n3 ? PETSC_TRUE : PETSC_FALSE;
1011*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
1012*6528b96dSMatthew G. Knepley }
1013*6528b96dSMatthew G. Knepley 
1014*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormGetDynamicJacobian(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g,
1015*6528b96dSMatthew G. Knepley                                         PetscInt *n0,
1016*6528b96dSMatthew G. Knepley                                         void (***g0)(PetscInt, PetscInt, PetscInt,
1017*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1018*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1019*6528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
1020*6528b96dSMatthew G. Knepley                                         PetscInt *n1,
1021*6528b96dSMatthew G. Knepley                                         void (***g1)(PetscInt, PetscInt, PetscInt,
1022*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1023*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1024*6528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
1025*6528b96dSMatthew G. Knepley                                         PetscInt *n2,
1026*6528b96dSMatthew G. Knepley                                         void (***g2)(PetscInt, PetscInt, PetscInt,
1027*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1028*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1029*6528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
1030*6528b96dSMatthew G. Knepley                                         PetscInt *n3,
1031*6528b96dSMatthew G. Knepley                                         void (***g3)(PetscInt, PetscInt, PetscInt,
1032*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1033*6528b96dSMatthew G. Knepley                                                      const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1034*6528b96dSMatthew G. Knepley                                                      PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
1035*6528b96dSMatthew G. Knepley {
1036*6528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
1037*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
1038*6528b96dSMatthew G. Knepley 
1039*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
1040*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->gt0, label, val, find, n0, (void (***)(void)) g0);CHKERRQ(ierr);
1041*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->gt1, label, val, find, n1, (void (***)(void)) g1);CHKERRQ(ierr);
1042*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->gt2, label, val, find, n2, (void (***)(void)) g2);CHKERRQ(ierr);
1043*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->gt3, label, val, find, n3, (void (***)(void)) g3);CHKERRQ(ierr);
1044*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
1045*6528b96dSMatthew G. Knepley }
1046*6528b96dSMatthew G. Knepley 
1047*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormAddDynamicJacobian(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g,
1048*6528b96dSMatthew G. Knepley                                         void (*g0)(PetscInt, PetscInt, PetscInt,
1049*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1050*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1051*6528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
1052*6528b96dSMatthew G. Knepley                                         void (*g1)(PetscInt, PetscInt, PetscInt,
1053*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1054*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1055*6528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
1056*6528b96dSMatthew G. Knepley                                         void (*g2)(PetscInt, PetscInt, PetscInt,
1057*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1058*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1059*6528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
1060*6528b96dSMatthew G. Knepley                                         void (*g3)(PetscInt, PetscInt, PetscInt,
1061*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1062*6528b96dSMatthew G. Knepley                                                    const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1063*6528b96dSMatthew G. Knepley                                                    PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
1064*6528b96dSMatthew G. Knepley {
1065*6528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
1066*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
1067*6528b96dSMatthew G. Knepley 
1068*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
1069*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->gt0, label, val, find, (void (*)(void)) g0);CHKERRQ(ierr);
1070*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->gt1, label, val, find, (void (*)(void)) g1);CHKERRQ(ierr);
1071*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->gt2, label, val, find, (void (*)(void)) g2);CHKERRQ(ierr);
1072*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormAddFunction_Private(wf, wf->gt3, label, val, find, (void (*)(void)) g3);CHKERRQ(ierr);
1073*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
1074*6528b96dSMatthew G. Knepley }
1075*6528b96dSMatthew G. Knepley 
1076*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormSetDynamicJacobian(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g,
1077*6528b96dSMatthew G. Knepley                                                PetscInt n0,
1078*6528b96dSMatthew G. Knepley                                                void (**g0)(PetscInt, PetscInt, PetscInt,
1079*6528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1080*6528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1081*6528b96dSMatthew G. Knepley                                                           PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
1082*6528b96dSMatthew G. Knepley                                                PetscInt n1,
1083*6528b96dSMatthew G. Knepley                                                void (**g1)(PetscInt, PetscInt, PetscInt,
1084*6528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1085*6528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1086*6528b96dSMatthew G. Knepley                                                           PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
1087*6528b96dSMatthew G. Knepley                                                PetscInt n2,
1088*6528b96dSMatthew G. Knepley                                                void (**g2)(PetscInt, PetscInt, PetscInt,
1089*6528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1090*6528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1091*6528b96dSMatthew G. Knepley                                                           PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
1092*6528b96dSMatthew G. Knepley                                                PetscInt n3,
1093*6528b96dSMatthew G. Knepley                                                void (**g3)(PetscInt, PetscInt, PetscInt,
1094*6528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1095*6528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1096*6528b96dSMatthew G. Knepley                                                           PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
1097*6528b96dSMatthew G. Knepley {
1098*6528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
1099*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
1100*6528b96dSMatthew G. Knepley 
1101*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
1102*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->gt0, label, val, find, n0, (void (**)(void)) g0);CHKERRQ(ierr);
1103*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->gt1, label, val, find, n1, (void (**)(void)) g1);CHKERRQ(ierr);
1104*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->gt2, label, val, find, n2, (void (**)(void)) g2);CHKERRQ(ierr);
1105*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->gt3, label, val, find, n3, (void (**)(void)) g3);CHKERRQ(ierr);
1106*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
1107*6528b96dSMatthew G. Knepley }
1108*6528b96dSMatthew G. Knepley 
1109*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormSetIndexDynamicJacobian(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt g,
1110*6528b96dSMatthew G. Knepley                                                PetscInt i0,
1111*6528b96dSMatthew G. Knepley                                                void (*g0)(PetscInt, PetscInt, PetscInt,
1112*6528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1113*6528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1114*6528b96dSMatthew G. Knepley                                                           PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
1115*6528b96dSMatthew G. Knepley                                                PetscInt i1,
1116*6528b96dSMatthew G. Knepley                                                void (*g1)(PetscInt, PetscInt, PetscInt,
1117*6528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1118*6528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1119*6528b96dSMatthew G. Knepley                                                           PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
1120*6528b96dSMatthew G. Knepley                                                PetscInt i2,
1121*6528b96dSMatthew G. Knepley                                                void (*g2)(PetscInt, PetscInt, PetscInt,
1122*6528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1123*6528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1124*6528b96dSMatthew G. Knepley                                                           PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]),
1125*6528b96dSMatthew G. Knepley                                                PetscInt i3,
1126*6528b96dSMatthew G. Knepley                                                void (*g3)(PetscInt, PetscInt, PetscInt,
1127*6528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1128*6528b96dSMatthew G. Knepley                                                           const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
1129*6528b96dSMatthew G. Knepley                                                           PetscReal, PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]))
1130*6528b96dSMatthew G. Knepley {
1131*6528b96dSMatthew G. Knepley   PetscInt       find = f*wf->Nf + g;
1132*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
1133*6528b96dSMatthew G. Knepley 
1134*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
1135*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->gt0, label, val, find, i0, (void (*)(void)) g0);CHKERRQ(ierr);
1136*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->gt1, label, val, find, i1, (void (*)(void)) g1);CHKERRQ(ierr);
1137*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->gt2, label, val, find, i2, (void (*)(void)) g2);CHKERRQ(ierr);
1138*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->gt3, label, val, find, i3, (void (*)(void)) g3);CHKERRQ(ierr);
1139*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
1140*6528b96dSMatthew G. Knepley }
1141*6528b96dSMatthew G. Knepley 
1142*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormGetRiemannSolver(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f, PetscInt *n,
1143*6528b96dSMatthew G. Knepley                                              void (***r)(PetscInt, PetscInt, const PetscReal[], const PetscReal[], const PetscScalar[], const PetscScalar[], PetscInt, const PetscScalar[], PetscScalar[], void *))
1144*6528b96dSMatthew G. Knepley {
1145*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
1146*6528b96dSMatthew G. Knepley 
1147*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
1148*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormGetFunction_Private(wf, wf->r, label, val, f, n, (void (***)(void)) r);CHKERRQ(ierr);
1149*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
1150*6528b96dSMatthew G. Knepley }
1151*6528b96dSMatthew G. Knepley 
1152*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormSetRiemannSolver(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f,
1153*6528b96dSMatthew G. Knepley                                              PetscInt n,
1154*6528b96dSMatthew G. Knepley                                              void (**r)(PetscInt, PetscInt, const PetscReal[], const PetscReal[], const PetscScalar[], const PetscScalar[], PetscInt, const PetscScalar[], PetscScalar[], void *))
1155*6528b96dSMatthew G. Knepley {
1156*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
1157*6528b96dSMatthew G. Knepley 
1158*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
1159*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetFunction_Private(wf, wf->r, label, val, f, n, (void (**)(void)) r);CHKERRQ(ierr);
1160*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
1161*6528b96dSMatthew G. Knepley }
1162*6528b96dSMatthew G. Knepley 
1163*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormSetIndexRiemannSolver(PetscWeakForm wf, DMLabel label, PetscInt val, PetscInt f,
1164*6528b96dSMatthew G. Knepley                                                   PetscInt i,
1165*6528b96dSMatthew G. Knepley                                                   void (*r)(PetscInt, PetscInt, const PetscReal[], const PetscReal[], const PetscScalar[], const PetscScalar[], PetscInt, const PetscScalar[], PetscScalar[], void *))
1166*6528b96dSMatthew G. Knepley {
1167*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
1168*6528b96dSMatthew G. Knepley 
1169*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
1170*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormSetIndexFunction_Private(wf, wf->r, label, val, f, i, (void (*)(void)) r);CHKERRQ(ierr);
1171*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
1172*6528b96dSMatthew G. Knepley }
1173*6528b96dSMatthew G. Knepley 
1174*6528b96dSMatthew G. Knepley /*@
1175*6528b96dSMatthew G. Knepley   PetscWeakFormGetNumFields - Returns the number of fields
1176*6528b96dSMatthew G. Knepley 
1177*6528b96dSMatthew G. Knepley   Not collective
1178*6528b96dSMatthew G. Knepley 
1179*6528b96dSMatthew G. Knepley   Input Parameter:
1180*6528b96dSMatthew G. Knepley . wf - The PetscWeakForm object
1181*6528b96dSMatthew G. Knepley 
1182*6528b96dSMatthew G. Knepley   Output Parameter:
1183*6528b96dSMatthew G. Knepley . Nf - The nubmer of fields
1184*6528b96dSMatthew G. Knepley 
1185*6528b96dSMatthew G. Knepley   Level: beginner
1186*6528b96dSMatthew G. Knepley 
1187*6528b96dSMatthew G. Knepley .seealso: PetscWeakFormSetNumFields(), PetscWeakFormCreate()
1188*6528b96dSMatthew G. Knepley @*/
1189*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormGetNumFields(PetscWeakForm wf, PetscInt *Nf)
1190*6528b96dSMatthew G. Knepley {
1191*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
1192*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(wf, PETSCWEAKFORM_CLASSID, 1);
1193*6528b96dSMatthew G. Knepley   PetscValidPointer(Nf, 2);
1194*6528b96dSMatthew G. Knepley   *Nf = wf->Nf;
1195*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
1196*6528b96dSMatthew G. Knepley }
1197*6528b96dSMatthew G. Knepley 
1198*6528b96dSMatthew G. Knepley /*@
1199*6528b96dSMatthew G. Knepley   PetscWeakFormSetNumFields - Sets the number of fields
1200*6528b96dSMatthew G. Knepley 
1201*6528b96dSMatthew G. Knepley   Not collective
1202*6528b96dSMatthew G. Knepley 
1203*6528b96dSMatthew G. Knepley   Input Parameters:
1204*6528b96dSMatthew G. Knepley + wf - The PetscWeakForm object
1205*6528b96dSMatthew G. Knepley - Nf - The number of fields
1206*6528b96dSMatthew G. Knepley 
1207*6528b96dSMatthew G. Knepley   Level: beginner
1208*6528b96dSMatthew G. Knepley 
1209*6528b96dSMatthew G. Knepley .seealso: PetscWeakFormGetNumFields(), PetscWeakFormCreate()
1210*6528b96dSMatthew G. Knepley @*/
1211*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormSetNumFields(PetscWeakForm wf, PetscInt Nf)
1212*6528b96dSMatthew G. Knepley {
1213*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
1214*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(wf, PETSCWEAKFORM_CLASSID, 1);
1215*6528b96dSMatthew G. Knepley   wf->Nf = Nf;
1216*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
1217*6528b96dSMatthew G. Knepley }
1218*6528b96dSMatthew G. Knepley 
1219*6528b96dSMatthew G. Knepley /*@
1220*6528b96dSMatthew G. Knepley   PetscWeakFormDestroy - Destroys a PetscWeakForm object
1221*6528b96dSMatthew G. Knepley 
1222*6528b96dSMatthew G. Knepley   Collective on wf
1223*6528b96dSMatthew G. Knepley 
1224*6528b96dSMatthew G. Knepley   Input Parameter:
1225*6528b96dSMatthew G. Knepley . wf - the PetscWeakForm object to destroy
1226*6528b96dSMatthew G. Knepley 
1227*6528b96dSMatthew G. Knepley   Level: developer
1228*6528b96dSMatthew G. Knepley 
1229*6528b96dSMatthew G. Knepley .seealso PetscWeakFormCreate(), PetscWeakFormView()
1230*6528b96dSMatthew G. Knepley @*/
1231*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormDestroy(PetscWeakForm *wf)
1232*6528b96dSMatthew G. Knepley {
1233*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
1234*6528b96dSMatthew G. Knepley 
1235*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
1236*6528b96dSMatthew G. Knepley   if (!*wf) PetscFunctionReturn(0);
1237*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific((*wf), PETSCWEAKFORM_CLASSID, 1);
1238*6528b96dSMatthew G. Knepley 
1239*6528b96dSMatthew G. Knepley   if (--((PetscObject)(*wf))->refct > 0) {*wf = NULL; PetscFunctionReturn(0);}
1240*6528b96dSMatthew G. Knepley   ((PetscObject) (*wf))->refct = 0;
1241*6528b96dSMatthew G. Knepley   ierr = PetscChunkBufferDestroy(&(*wf)->funcs);CHKERRQ(ierr);
1242*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormDestroy(&(*wf)->obj);CHKERRQ(ierr);
1243*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormDestroy(&(*wf)->f0);CHKERRQ(ierr);
1244*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormDestroy(&(*wf)->f1);CHKERRQ(ierr);
1245*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormDestroy(&(*wf)->g0);CHKERRQ(ierr);
1246*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormDestroy(&(*wf)->g1);CHKERRQ(ierr);
1247*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormDestroy(&(*wf)->g2);CHKERRQ(ierr);
1248*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormDestroy(&(*wf)->g3);CHKERRQ(ierr);
1249*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormDestroy(&(*wf)->gp0);CHKERRQ(ierr);
1250*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormDestroy(&(*wf)->gp1);CHKERRQ(ierr);
1251*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormDestroy(&(*wf)->gp2);CHKERRQ(ierr);
1252*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormDestroy(&(*wf)->gp3);CHKERRQ(ierr);
1253*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormDestroy(&(*wf)->gt0);CHKERRQ(ierr);
1254*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormDestroy(&(*wf)->gt1);CHKERRQ(ierr);
1255*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormDestroy(&(*wf)->gt2);CHKERRQ(ierr);
1256*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormDestroy(&(*wf)->gt3);CHKERRQ(ierr);
1257*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormDestroy(&(*wf)->bdf0);CHKERRQ(ierr);
1258*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormDestroy(&(*wf)->bdf1);CHKERRQ(ierr);
1259*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormDestroy(&(*wf)->bdg0);CHKERRQ(ierr);
1260*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormDestroy(&(*wf)->bdg1);CHKERRQ(ierr);
1261*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormDestroy(&(*wf)->bdg2);CHKERRQ(ierr);
1262*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormDestroy(&(*wf)->bdg3);CHKERRQ(ierr);
1263*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormDestroy(&(*wf)->bdgp0);CHKERRQ(ierr);
1264*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormDestroy(&(*wf)->bdgp1);CHKERRQ(ierr);
1265*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormDestroy(&(*wf)->bdgp2);CHKERRQ(ierr);
1266*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormDestroy(&(*wf)->bdgp3);CHKERRQ(ierr);
1267*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormDestroy(&(*wf)->r);CHKERRQ(ierr);
1268*6528b96dSMatthew G. Knepley   ierr = PetscHeaderDestroy(wf);CHKERRQ(ierr);
1269*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
1270*6528b96dSMatthew G. Knepley }
1271*6528b96dSMatthew G. Knepley 
1272*6528b96dSMatthew G. Knepley static PetscErrorCode PetscWeakFormViewTable_Ascii(PetscWeakForm wf, PetscViewer viewer, const char tableName[], PetscHMapForm map)
1273*6528b96dSMatthew G. Knepley {
1274*6528b96dSMatthew G. Knepley   PetscInt       Nk, k;
1275*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
1276*6528b96dSMatthew G. Knepley 
1277*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
1278*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormGetSize(map, &Nk);CHKERRQ(ierr);
1279*6528b96dSMatthew G. Knepley   if (Nk) {
1280*6528b96dSMatthew G. Knepley     PetscHashFormKey *keys;
1281*6528b96dSMatthew G. Knepley     void           (**funcs)(void);
1282*6528b96dSMatthew G. Knepley     const char       *name;
1283*6528b96dSMatthew G. Knepley     PetscInt          off = 0, n, i;
1284*6528b96dSMatthew G. Knepley 
1285*6528b96dSMatthew G. Knepley     ierr = PetscMalloc1(Nk, &keys);CHKERRQ(ierr);
1286*6528b96dSMatthew G. Knepley     ierr = PetscHMapFormGetKeys(map, &off, keys);CHKERRQ(ierr);
1287*6528b96dSMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, "%s\n", tableName);CHKERRQ(ierr);
1288*6528b96dSMatthew G. Knepley     ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
1289*6528b96dSMatthew G. Knepley     for (k = 0; k < Nk; ++k) {
1290*6528b96dSMatthew G. Knepley       if (keys[k].label) {ierr = PetscObjectGetName((PetscObject) keys[k].label, &name);CHKERRQ(ierr);}
1291*6528b96dSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, "Key (%s, %D, %D) ", keys[k].label ? name : "None", keys[k].value, keys[k].field);CHKERRQ(ierr);
1292*6528b96dSMatthew G. Knepley       ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr);
1293*6528b96dSMatthew G. Knepley       ierr = PetscWeakFormGetFunction_Private(wf, map, keys[k].label, keys[k].value, keys[k].field, &n, &funcs);CHKERRQ(ierr);
1294*6528b96dSMatthew G. Knepley       for (i = 0; i < n; ++i) {
1295*6528b96dSMatthew G. Knepley         if (i > 0) {ierr = PetscViewerASCIIPrintf(viewer, ", ");CHKERRQ(ierr);}
1296*6528b96dSMatthew G. Knepley         ierr = PetscDLAddr(funcs[i], &name);CHKERRQ(ierr);
1297*6528b96dSMatthew G. Knepley         if (name) {ierr = PetscViewerASCIIPrintf(viewer, "%s", name);CHKERRQ(ierr);}
1298*6528b96dSMatthew G. Knepley         else      {ierr = PetscViewerASCIIPrintf(viewer, "%p", funcs[i]);CHKERRQ(ierr);}
1299*6528b96dSMatthew G. Knepley       }
1300*6528b96dSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr);
1301*6528b96dSMatthew G. Knepley       ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr);
1302*6528b96dSMatthew G. Knepley     }
1303*6528b96dSMatthew G. Knepley     ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
1304*6528b96dSMatthew G. Knepley     ierr = PetscFree(keys);CHKERRQ(ierr);
1305*6528b96dSMatthew G. Knepley   }
1306*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
1307*6528b96dSMatthew G. Knepley }
1308*6528b96dSMatthew G. Knepley 
1309*6528b96dSMatthew G. Knepley static PetscErrorCode PetscWeakFormView_Ascii(PetscWeakForm wf, PetscViewer viewer)
1310*6528b96dSMatthew G. Knepley {
1311*6528b96dSMatthew G. Knepley   PetscViewerFormat format;
1312*6528b96dSMatthew G. Knepley   PetscErrorCode    ierr;
1313*6528b96dSMatthew G. Knepley 
1314*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
1315*6528b96dSMatthew G. Knepley   ierr = PetscViewerGetFormat(viewer, &format);CHKERRQ(ierr);
1316*6528b96dSMatthew G. Knepley   ierr = PetscViewerASCIIPrintf(viewer, "Weak Form System with %d fields\n", wf->Nf);CHKERRQ(ierr);
1317*6528b96dSMatthew G. Knepley   ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
1318*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormViewTable_Ascii(wf, viewer, "Objective", wf->obj);CHKERRQ(ierr);
1319*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormViewTable_Ascii(wf, viewer, "Residual f0", wf->f0);CHKERRQ(ierr);
1320*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormViewTable_Ascii(wf, viewer, "Residual f1", wf->f1);CHKERRQ(ierr);
1321*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormViewTable_Ascii(wf, viewer, "Boudnary Residual f0", wf->bdf0);CHKERRQ(ierr);
1322*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormViewTable_Ascii(wf, viewer, "Boundary Residual f1", wf->bdf1);CHKERRQ(ierr);
1323*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormViewTable_Ascii(wf, viewer, "Jacobian g0", wf->g0);CHKERRQ(ierr);
1324*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormViewTable_Ascii(wf, viewer, "Jacobian g1", wf->g1);CHKERRQ(ierr);
1325*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormViewTable_Ascii(wf, viewer, "Jacobian g2", wf->g2);CHKERRQ(ierr);
1326*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormViewTable_Ascii(wf, viewer, "Jacobian g3", wf->g3);CHKERRQ(ierr);
1327*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormViewTable_Ascii(wf, viewer, "Jacobian Preconditioner g0", wf->gp0);CHKERRQ(ierr);
1328*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormViewTable_Ascii(wf, viewer, "Jacobian Preconditioner g1", wf->gp1);CHKERRQ(ierr);
1329*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormViewTable_Ascii(wf, viewer, "Jacobian Preconditioner g2", wf->gp2);CHKERRQ(ierr);
1330*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormViewTable_Ascii(wf, viewer, "Jacobian Preconditioner g3", wf->gp3);CHKERRQ(ierr);
1331*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormViewTable_Ascii(wf, viewer, "Dynamic Jacobian g0", wf->gt0);CHKERRQ(ierr);
1332*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormViewTable_Ascii(wf, viewer, "Dynamic Jacobian g1", wf->gt1);CHKERRQ(ierr);
1333*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormViewTable_Ascii(wf, viewer, "Dynamic Jacobian g2", wf->gt2);CHKERRQ(ierr);
1334*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormViewTable_Ascii(wf, viewer, "Dynamic Jacobian g3", wf->gt3);CHKERRQ(ierr);
1335*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormViewTable_Ascii(wf, viewer, "Boundary Jacobian g0", wf->bdg0);CHKERRQ(ierr);
1336*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormViewTable_Ascii(wf, viewer, "Boundary Jacobian g1", wf->bdg1);CHKERRQ(ierr);
1337*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormViewTable_Ascii(wf, viewer, "Boundary Jacobian g2", wf->bdg2);CHKERRQ(ierr);
1338*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormViewTable_Ascii(wf, viewer, "Boundary Jacobian g3", wf->bdg3);CHKERRQ(ierr);
1339*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormViewTable_Ascii(wf, viewer, "Boundary Jacobian Preconditioner g0", wf->bdgp0);CHKERRQ(ierr);
1340*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormViewTable_Ascii(wf, viewer, "Boundary Jacobian Preconditioner g1", wf->bdgp1);CHKERRQ(ierr);
1341*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormViewTable_Ascii(wf, viewer, "Boundary Jacobian Preconditioner g2", wf->bdgp2);CHKERRQ(ierr);
1342*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormViewTable_Ascii(wf, viewer, "Boundary Jacobian Preconditioner g3", wf->bdgp3);CHKERRQ(ierr);
1343*6528b96dSMatthew G. Knepley   ierr = PetscWeakFormViewTable_Ascii(wf, viewer, "Riemann Solver", wf->r);CHKERRQ(ierr);
1344*6528b96dSMatthew G. Knepley   ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
1345*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
1346*6528b96dSMatthew G. Knepley }
1347*6528b96dSMatthew G. Knepley 
1348*6528b96dSMatthew G. Knepley /*@C
1349*6528b96dSMatthew G. Knepley   PetscWeakFormView - Views a PetscWeakForm
1350*6528b96dSMatthew G. Knepley 
1351*6528b96dSMatthew G. Knepley   Collective on wf
1352*6528b96dSMatthew G. Knepley 
1353*6528b96dSMatthew G. Knepley   Input Parameter:
1354*6528b96dSMatthew G. Knepley + wf - the PetscWeakForm object to view
1355*6528b96dSMatthew G. Knepley - v  - the viewer
1356*6528b96dSMatthew G. Knepley 
1357*6528b96dSMatthew G. Knepley   Level: developer
1358*6528b96dSMatthew G. Knepley 
1359*6528b96dSMatthew G. Knepley .seealso PetscWeakFormDestroy(), PetscWeakFormCreate()
1360*6528b96dSMatthew G. Knepley @*/
1361*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormView(PetscWeakForm wf, PetscViewer v)
1362*6528b96dSMatthew G. Knepley {
1363*6528b96dSMatthew G. Knepley   PetscBool      iascii;
1364*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
1365*6528b96dSMatthew G. Knepley 
1366*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
1367*6528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(wf, PETSCWEAKFORM_CLASSID, 1);
1368*6528b96dSMatthew G. Knepley   if (!v) {ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject) wf), &v);CHKERRQ(ierr);}
1369*6528b96dSMatthew G. Knepley   else    {PetscValidHeaderSpecific(v, PETSC_VIEWER_CLASSID, 2);}
1370*6528b96dSMatthew G. Knepley   ierr = PetscObjectTypeCompare((PetscObject) v, PETSCVIEWERASCII, &iascii);CHKERRQ(ierr);
1371*6528b96dSMatthew G. Knepley   if (iascii) {ierr = PetscWeakFormView_Ascii(wf, v);CHKERRQ(ierr);}
1372*6528b96dSMatthew G. Knepley   if (wf->ops->view) {ierr = (*wf->ops->view)(wf, v);CHKERRQ(ierr);}
1373*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
1374*6528b96dSMatthew G. Knepley }
1375*6528b96dSMatthew G. Knepley 
1376*6528b96dSMatthew G. Knepley /*@
1377*6528b96dSMatthew G. Knepley   PetscWeakFormCreate - Creates an empty PetscWeakForm object.
1378*6528b96dSMatthew G. Knepley 
1379*6528b96dSMatthew G. Knepley   Collective
1380*6528b96dSMatthew G. Knepley 
1381*6528b96dSMatthew G. Knepley   Input Parameter:
1382*6528b96dSMatthew G. Knepley . comm - The communicator for the PetscWeakForm object
1383*6528b96dSMatthew G. Knepley 
1384*6528b96dSMatthew G. Knepley   Output Parameter:
1385*6528b96dSMatthew G. Knepley . wf - The PetscWeakForm object
1386*6528b96dSMatthew G. Knepley 
1387*6528b96dSMatthew G. Knepley   Level: beginner
1388*6528b96dSMatthew G. Knepley 
1389*6528b96dSMatthew G. Knepley .seealso: PetscDS, PetscWeakFormDestroy()
1390*6528b96dSMatthew G. Knepley @*/
1391*6528b96dSMatthew G. Knepley PetscErrorCode PetscWeakFormCreate(MPI_Comm comm, PetscWeakForm *wf)
1392*6528b96dSMatthew G. Knepley {
1393*6528b96dSMatthew G. Knepley   PetscWeakForm  p;
1394*6528b96dSMatthew G. Knepley   PetscErrorCode ierr;
1395*6528b96dSMatthew G. Knepley 
1396*6528b96dSMatthew G. Knepley   PetscFunctionBegin;
1397*6528b96dSMatthew G. Knepley   PetscValidPointer(wf, 2);
1398*6528b96dSMatthew G. Knepley   *wf  = NULL;
1399*6528b96dSMatthew G. Knepley   ierr = PetscDSInitializePackage();CHKERRQ(ierr);
1400*6528b96dSMatthew G. Knepley 
1401*6528b96dSMatthew G. Knepley   ierr = PetscHeaderCreate(p, PETSCWEAKFORM_CLASSID, "PetscWeakForm", "Weak Form System", "PetscWeakForm", comm, PetscWeakFormDestroy, PetscWeakFormView);CHKERRQ(ierr);
1402*6528b96dSMatthew G. Knepley 
1403*6528b96dSMatthew G. Knepley   p->Nf = 0;
1404*6528b96dSMatthew G. Knepley   ierr = PetscChunkBufferCreate(sizeof(&PetscWeakFormCreate), 2, &p->funcs);CHKERRQ(ierr);
1405*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormCreate(&p->obj);CHKERRQ(ierr);
1406*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormCreate(&p->f0);CHKERRQ(ierr);
1407*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormCreate(&p->f1);CHKERRQ(ierr);
1408*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormCreate(&p->g0);CHKERRQ(ierr);
1409*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormCreate(&p->g1);CHKERRQ(ierr);
1410*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormCreate(&p->g2);CHKERRQ(ierr);
1411*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormCreate(&p->g3);CHKERRQ(ierr);
1412*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormCreate(&p->gp0);CHKERRQ(ierr);
1413*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormCreate(&p->gp1);CHKERRQ(ierr);
1414*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormCreate(&p->gp2);CHKERRQ(ierr);
1415*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormCreate(&p->gp3);CHKERRQ(ierr);
1416*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormCreate(&p->gt0);CHKERRQ(ierr);
1417*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormCreate(&p->gt1);CHKERRQ(ierr);
1418*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormCreate(&p->gt2);CHKERRQ(ierr);
1419*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormCreate(&p->gt3);CHKERRQ(ierr);
1420*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormCreate(&p->bdf0);CHKERRQ(ierr);
1421*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormCreate(&p->bdf1);CHKERRQ(ierr);
1422*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormCreate(&p->bdg0);CHKERRQ(ierr);
1423*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormCreate(&p->bdg1);CHKERRQ(ierr);
1424*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormCreate(&p->bdg2);CHKERRQ(ierr);
1425*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormCreate(&p->bdg3);CHKERRQ(ierr);
1426*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormCreate(&p->bdgp0);CHKERRQ(ierr);
1427*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormCreate(&p->bdgp1);CHKERRQ(ierr);
1428*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormCreate(&p->bdgp2);CHKERRQ(ierr);
1429*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormCreate(&p->bdgp3);CHKERRQ(ierr);
1430*6528b96dSMatthew G. Knepley   ierr = PetscHMapFormCreate(&p->r);CHKERRQ(ierr);
1431*6528b96dSMatthew G. Knepley   *wf = p;
1432*6528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
1433*6528b96dSMatthew G. Knepley }
1434