xref: /libCEED/interface/ceed-qfunction.c (revision aefd83785c2df88dfccc51fc4901501fa3238add)
1d7b241e6Sjeremylt // Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at
2d7b241e6Sjeremylt // the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights
3d7b241e6Sjeremylt // reserved. See files LICENSE and NOTICE for details.
4d7b241e6Sjeremylt //
5d7b241e6Sjeremylt // This file is part of CEED, a collection of benchmarks, miniapps, software
6d7b241e6Sjeremylt // libraries and APIs for efficient high-order finite element and spectral
7d7b241e6Sjeremylt // element discretizations for exascale applications. For more information and
8d7b241e6Sjeremylt // source code availability see http://github.com/ceed.
9d7b241e6Sjeremylt //
10d7b241e6Sjeremylt // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
11d7b241e6Sjeremylt // a collaborative effort of two U.S. Department of Energy organizations (Office
12d7b241e6Sjeremylt // of Science and the National Nuclear Security Administration) responsible for
13d7b241e6Sjeremylt // the planning and preparation of a capable exascale ecosystem, including
14d7b241e6Sjeremylt // software, applications, hardware, advanced system engineering and early
15d7b241e6Sjeremylt // testbed platforms, in support of the nation's exascale computing imperative.
16d7b241e6Sjeremylt 
17d7b241e6Sjeremylt #include <ceed-impl.h>
18d863ab9bSjeremylt #include <ceed-backend.h>
19d7b241e6Sjeremylt #include <string.h>
20d7b241e6Sjeremylt 
21dfdf5a53Sjeremylt /// @file
22dfdf5a53Sjeremylt /// Implementation of public CeedQFunction interfaces
23dfdf5a53Sjeremylt ///
24dfdf5a53Sjeremylt /// @addtogroup CeedQFunction
25dfdf5a53Sjeremylt /// @{
26d7b241e6Sjeremylt 
27d7b241e6Sjeremylt /**
28d7b241e6Sjeremylt   @brief Create a CeedQFunction for evaluating interior (volumetric) terms.
29d7b241e6Sjeremylt 
30b11c1e72Sjeremylt   @param ceed       A Ceed object where the CeedQFunction will be created
31d7b241e6Sjeremylt   @param vlength    Vector length.  Caller must ensure that number of quadrature
32d7b241e6Sjeremylt                     points is a multiple of vlength.
33d7b241e6Sjeremylt   @param f          Function pointer to evaluate action at quadrature points.
349f0427d9SYohann                     See \ref CeedQFunctionUser.
35d7b241e6Sjeremylt   @param focca      OCCA identifier "file.c:function_name" for definition of `f`
36b11c1e72Sjeremylt   @param[out] qf    Address of the variable where the newly created
37b11c1e72Sjeremylt                      CeedQFunction will be stored
38b11c1e72Sjeremylt 
39b11c1e72Sjeremylt   @return An error code: 0 - success, otherwise - failure
40d7b241e6Sjeremylt 
419f0427d9SYohann   See \ref CeedQFunctionUser for details on the call-back function @a f's arguments.
42d7b241e6Sjeremylt 
43dfdf5a53Sjeremylt   @ref Basic
44dfdf5a53Sjeremylt **/
45d7b241e6Sjeremylt int CeedQFunctionCreateInterior(Ceed ceed, CeedInt vlength,
469f0427d9SYohann                                 CeedQFunctionUser f,
47d7b241e6Sjeremylt                                 const char *focca, CeedQFunction *qf) {
48d7b241e6Sjeremylt   int ierr;
49d7b241e6Sjeremylt   char *focca_copy;
50d7b241e6Sjeremylt 
515fe0d4faSjeremylt   if (!ceed->QFunctionCreate) {
525fe0d4faSjeremylt     Ceed delegate;
53*aefd8378Sjeremylt     ierr = CeedGetObjectDelegate(ceed, &delegate, "QFunction"); CeedChk(ierr);
545fe0d4faSjeremylt 
555fe0d4faSjeremylt     if (!delegate)
56d7b241e6Sjeremylt       return CeedError(ceed, 1, "Backend does not support QFunctionCreate");
575fe0d4faSjeremylt 
581dfeef1dSjeremylt     ierr = CeedQFunctionCreateInterior(delegate, vlength, f, focca, qf);
591dfeef1dSjeremylt     CeedChk(ierr);
605fe0d4faSjeremylt     return 0;
615fe0d4faSjeremylt   }
625fe0d4faSjeremylt 
63d7b241e6Sjeremylt   ierr = CeedCalloc(1,qf); CeedChk(ierr);
64d7b241e6Sjeremylt   (*qf)->ceed = ceed;
65d7b241e6Sjeremylt   ceed->refcount++;
66d7b241e6Sjeremylt   (*qf)->refcount = 1;
67d7b241e6Sjeremylt   (*qf)->vlength = vlength;
68d7b241e6Sjeremylt   (*qf)->function = f;
69d7b241e6Sjeremylt   ierr = CeedCalloc(strlen(focca)+1, &focca_copy); CeedChk(ierr);
70409ab9adSjeremylt   strncpy(focca_copy, focca, strlen(focca)+1);
71d7b241e6Sjeremylt   (*qf)->focca = focca_copy;
72fe2413ffSjeremylt   ierr = CeedCalloc(16, &(*qf)->inputfields); CeedChk(ierr);
73fe2413ffSjeremylt   ierr = CeedCalloc(16, &(*qf)->outputfields); CeedChk(ierr);
74d7b241e6Sjeremylt   ierr = ceed->QFunctionCreate(*qf); CeedChk(ierr);
75d7b241e6Sjeremylt   return 0;
76d7b241e6Sjeremylt }
77d7b241e6Sjeremylt 
78b11c1e72Sjeremylt /**
79a0a97fcfSJed Brown   @brief Set a CeedQFunction field, used by CeedQFunctionAddInput/Output
80b11c1e72Sjeremylt 
81b11c1e72Sjeremylt   @param f          CeedQFunctionField
82b11c1e72Sjeremylt   @param fieldname  Name of QFunction field
83b11c1e72Sjeremylt   @param ncomp      Number of components per quadrature node
84b11c1e72Sjeremylt   @param emode      \ref CEED_EVAL_NONE to use values directly,
85b11c1e72Sjeremylt                       \ref CEED_EVAL_INTERP to use interpolated values,
86b11c1e72Sjeremylt                       \ref CEED_EVAL_GRAD to use gradients.
87b11c1e72Sjeremylt 
88b11c1e72Sjeremylt   @return An error code: 0 - success, otherwise - failure
89dfdf5a53Sjeremylt 
90dfdf5a53Sjeremylt   @ref Developer
91b11c1e72Sjeremylt **/
92fe2413ffSjeremylt static int CeedQFunctionFieldSet(CeedQFunctionField *f,const char *fieldname,
93fe2413ffSjeremylt                                  CeedInt ncomp, CeedEvalMode emode) {
94d7b241e6Sjeremylt   size_t len = strlen(fieldname);
95d7b241e6Sjeremylt   char *tmp;
96fe2413ffSjeremylt   int ierr;
97fe2413ffSjeremylt   ierr = CeedCalloc(1,f); CeedChk(ierr);
98fe2413ffSjeremylt 
99fe2413ffSjeremylt   ierr = CeedCalloc(len+1, &tmp); CeedChk(ierr);
100d7b241e6Sjeremylt   memcpy(tmp, fieldname, len+1);
101fe2413ffSjeremylt   (*f)->fieldname = tmp;
102fe2413ffSjeremylt   (*f)->ncomp = ncomp;
103fe2413ffSjeremylt   (*f)->emode = emode;
104d7b241e6Sjeremylt   return 0;
105d7b241e6Sjeremylt }
106d7b241e6Sjeremylt 
107b11c1e72Sjeremylt /**
108a0a97fcfSJed Brown   @brief Add a CeedQFunction input
109b11c1e72Sjeremylt 
110b11c1e72Sjeremylt   @param qf         CeedQFunction
111b11c1e72Sjeremylt   @param fieldname  Name of QFunction field
112b11c1e72Sjeremylt   @param ncomp      Number of components per quadrature node
113b11c1e72Sjeremylt   @param emode      \ref CEED_EVAL_NONE to use values directly,
114b11c1e72Sjeremylt                       \ref CEED_EVAL_INTERP to use interpolated values,
115b11c1e72Sjeremylt                       \ref CEED_EVAL_GRAD to use gradients.
116b11c1e72Sjeremylt 
117b11c1e72Sjeremylt   @return An error code: 0 - success, otherwise - failure
118dfdf5a53Sjeremylt 
119dfdf5a53Sjeremylt   @ref Basic
120b11c1e72Sjeremylt **/
121d7b241e6Sjeremylt int CeedQFunctionAddInput(CeedQFunction qf, const char *fieldname,
122d7b241e6Sjeremylt                           CeedInt ncomp, CeedEvalMode emode) {
123fe2413ffSjeremylt   int ierr = CeedQFunctionFieldSet(&qf->inputfields[qf->numinputfields],
124fe2413ffSjeremylt                                    fieldname, ncomp, emode);
125fe2413ffSjeremylt   CeedChk(ierr);
126fe2413ffSjeremylt   qf->numinputfields++;
127d7b241e6Sjeremylt   return 0;
128d7b241e6Sjeremylt }
129d7b241e6Sjeremylt 
130b11c1e72Sjeremylt /**
131a0a97fcfSJed Brown   @brief Add a CeedQFunction output
132b11c1e72Sjeremylt 
133b11c1e72Sjeremylt   @param qf         CeedQFunction
134b11c1e72Sjeremylt   @param fieldname  Name of QFunction field
135b11c1e72Sjeremylt   @param ncomp      Number of components per quadrature node
136b11c1e72Sjeremylt   @param emode      \ref CEED_EVAL_NONE to use values directly,
137b11c1e72Sjeremylt                       \ref CEED_EVAL_INTERP to use interpolated values,
138b11c1e72Sjeremylt                       \ref CEED_EVAL_GRAD to use gradients.
139b11c1e72Sjeremylt 
140b11c1e72Sjeremylt   @return An error code: 0 - success, otherwise - failure
141dfdf5a53Sjeremylt 
142dfdf5a53Sjeremylt   @ref Basic
143b11c1e72Sjeremylt **/
144d7b241e6Sjeremylt int CeedQFunctionAddOutput(CeedQFunction qf, const char *fieldname,
145d7b241e6Sjeremylt                            CeedInt ncomp, CeedEvalMode emode) {
146d7b241e6Sjeremylt   if (emode == CEED_EVAL_WEIGHT)
147d7b241e6Sjeremylt     return CeedError(qf->ceed, 1,
148d7b241e6Sjeremylt                      "Cannot create qfunction output with CEED_EVAL_WEIGHT");
149fe2413ffSjeremylt   int ierr = CeedQFunctionFieldSet(&qf->outputfields[qf->numoutputfields],
150fe2413ffSjeremylt                                    fieldname, ncomp, emode);
151fe2413ffSjeremylt   CeedChk(ierr);
152fe2413ffSjeremylt   qf->numoutputfields++;
153d7b241e6Sjeremylt   return 0;
154d7b241e6Sjeremylt }
155d7b241e6Sjeremylt 
156dfdf5a53Sjeremylt /**
1574ce2993fSjeremylt   @brief Get the Ceed associated with a CeedQFunction
1584ce2993fSjeremylt 
1594ce2993fSjeremylt   @param qf              CeedQFunction
1604ce2993fSjeremylt   @param[out] ceed       Variable to store Ceed
1614ce2993fSjeremylt 
1624ce2993fSjeremylt   @return An error code: 0 - success, otherwise - failure
1634ce2993fSjeremylt 
16423617272Sjeremylt   @ref Advanced
1654ce2993fSjeremylt **/
1664ce2993fSjeremylt 
1674ce2993fSjeremylt int CeedQFunctionGetCeed(CeedQFunction qf, Ceed *ceed) {
1684ce2993fSjeremylt   *ceed = qf->ceed;
1694ce2993fSjeremylt   return 0;
1704ce2993fSjeremylt }
1714ce2993fSjeremylt 
1724ce2993fSjeremylt /**
1734ce2993fSjeremylt   @brief Get the vector length of a CeedQFunction
1744ce2993fSjeremylt 
1754ce2993fSjeremylt   @param qf              CeedQFunction
1764ce2993fSjeremylt   @param[out] veclength  Variable to store vector length
1774ce2993fSjeremylt 
1784ce2993fSjeremylt   @return An error code: 0 - success, otherwise - failure
1794ce2993fSjeremylt 
18023617272Sjeremylt   @ref Advanced
1814ce2993fSjeremylt **/
1824ce2993fSjeremylt 
1834ce2993fSjeremylt int CeedQFunctionGetVectorLength(CeedQFunction qf, CeedInt *vlength) {
1844ce2993fSjeremylt   *vlength = qf->vlength;
1854ce2993fSjeremylt   return 0;
1864ce2993fSjeremylt }
1874ce2993fSjeremylt 
1884ce2993fSjeremylt /**
189dfdf5a53Sjeremylt   @brief Get the number of inputs and outputs to a CeedQFunction
190dfdf5a53Sjeremylt 
191dfdf5a53Sjeremylt   @param qf              CeedQFunction
1924ce2993fSjeremylt   @param[out] numinput   Variable to store number of input fields
1934ce2993fSjeremylt   @param[out] numoutput  Variable to store number of output fields
194dfdf5a53Sjeremylt 
195dfdf5a53Sjeremylt   @return An error code: 0 - success, otherwise - failure
196dfdf5a53Sjeremylt 
19723617272Sjeremylt   @ref Advanced
198dfdf5a53Sjeremylt **/
199dfdf5a53Sjeremylt 
200d7b241e6Sjeremylt int CeedQFunctionGetNumArgs(CeedQFunction qf, CeedInt *numinput,
201d7b241e6Sjeremylt                             CeedInt *numoutput) {
2021a4ead9bSjeremylt   if (numinput) *numinput = qf->numinputfields;
2031a4ead9bSjeremylt   if (numoutput) *numoutput = qf->numoutputfields;
204d7b241e6Sjeremylt   return 0;
205d7b241e6Sjeremylt }
206d7b241e6Sjeremylt 
207d7b241e6Sjeremylt /**
2084ce2993fSjeremylt   @brief Get the FOCCA string for a CeedQFunction
2094ce2993fSjeremylt 
2104ce2993fSjeremylt   @param qf              CeedQFunction
2114ce2993fSjeremylt   @param[out] focca      Variable to store focca string
2124ce2993fSjeremylt 
2134ce2993fSjeremylt   @return An error code: 0 - success, otherwise - failure
2144ce2993fSjeremylt 
21523617272Sjeremylt   @ref Advanced
2164ce2993fSjeremylt **/
2174ce2993fSjeremylt 
2184ce2993fSjeremylt int CeedQFunctionGetFOCCA(CeedQFunction qf, char* *focca) {
2194ce2993fSjeremylt   *focca = (char *) qf->focca;
2204ce2993fSjeremylt   return 0;
2214ce2993fSjeremylt }
2224ce2993fSjeremylt 
2234ce2993fSjeremylt /**
224fe2413ffSjeremylt   @brief Get the User Function for a CeedQFunction
225fe2413ffSjeremylt 
226fe2413ffSjeremylt   @param qf              CeedQFunction
227fe2413ffSjeremylt   @param[out] f          Variable to store user function
228fe2413ffSjeremylt 
229fe2413ffSjeremylt   @return An error code: 0 - success, otherwise - failure
230fe2413ffSjeremylt 
231fe2413ffSjeremylt   @ref Advanced
232fe2413ffSjeremylt **/
233fe2413ffSjeremylt 
23428d161eeSjeremylt int CeedQFunctionGetUserFunction(CeedQFunction qf, int (**f)()) {
23528d161eeSjeremylt   *f = (int (*)())qf->function;
236fe2413ffSjeremylt   return 0;
237fe2413ffSjeremylt }
238fe2413ffSjeremylt 
239fe2413ffSjeremylt /**
2404ce2993fSjeremylt   @brief Get global context size for a CeedQFunction
2414ce2993fSjeremylt 
2424ce2993fSjeremylt   @param qf              CeedQFunction
2434ce2993fSjeremylt   @param[out] ctxsize    Variable to store size of context data values
2444ce2993fSjeremylt 
2454ce2993fSjeremylt   @return An error code: 0 - success, otherwise - failure
2464ce2993fSjeremylt 
24723617272Sjeremylt   @ref Advanced
2484ce2993fSjeremylt **/
2494ce2993fSjeremylt 
2504ce2993fSjeremylt int CeedQFunctionGetContextSize(CeedQFunction qf, size_t *ctxsize) {
251069aeabaSjeremylt   if (qf->fortranstatus) {
252069aeabaSjeremylt     fContext *fctx = qf->ctx;
253069aeabaSjeremylt     *ctxsize = fctx->innerctxsize;
254069aeabaSjeremylt   } else {
2554ce2993fSjeremylt     *ctxsize = qf->ctxsize;
256069aeabaSjeremylt   }
2574ce2993fSjeremylt   return 0;
2584ce2993fSjeremylt }
2594ce2993fSjeremylt 
2604ce2993fSjeremylt /**
2614ce2993fSjeremylt   @brief Get global context for a CeedQFunction
2624ce2993fSjeremylt 
2634ce2993fSjeremylt   @param qf              CeedQFunction
2644ce2993fSjeremylt   @param[out] ctx        Variable to store context data values
2654ce2993fSjeremylt 
2664ce2993fSjeremylt   @return An error code: 0 - success, otherwise - failure
2674ce2993fSjeremylt 
26823617272Sjeremylt   @ref Advanced
2694ce2993fSjeremylt **/
2704ce2993fSjeremylt 
2714ce2993fSjeremylt int CeedQFunctionGetContext(CeedQFunction qf, void* *ctx) {
2724ce2993fSjeremylt   *ctx = qf->ctx;
2734ce2993fSjeremylt   return 0;
2744ce2993fSjeremylt }
2754ce2993fSjeremylt 
2764ce2993fSjeremylt /**
277418fb8c2Sjeremylt   @brief Determine if Fortran interface was used
278418fb8c2Sjeremylt 
279418fb8c2Sjeremylt   @param qf                  CeedQFunction
280418fb8c2Sjeremylt   @param[out] fortranstatus  Variable to store Fortran status
281418fb8c2Sjeremylt 
282418fb8c2Sjeremylt   @return An error code: 0 - success, otherwise - failure
283418fb8c2Sjeremylt 
284418fb8c2Sjeremylt   @ref Advanced
285418fb8c2Sjeremylt **/
286418fb8c2Sjeremylt 
287418fb8c2Sjeremylt int CeedQFunctionGetFortranStatus(CeedQFunction qf, bool *fortranstatus) {
288418fb8c2Sjeremylt   *fortranstatus = qf->fortranstatus;
289418fb8c2Sjeremylt   return 0;
290418fb8c2Sjeremylt }
291418fb8c2Sjeremylt 
292418fb8c2Sjeremylt /**
29314922b2aSjeremylt   @brief Get true user context for a CeedQFunction
294069aeabaSjeremylt 
295069aeabaSjeremylt   @param qf              CeedQFunction
296069aeabaSjeremylt   @param[out] ctx        Variable to store context data values
297069aeabaSjeremylt 
298069aeabaSjeremylt   @return An error code: 0 - success, otherwise - failure
299069aeabaSjeremylt 
300069aeabaSjeremylt   @ref Advanced
301069aeabaSjeremylt **/
302069aeabaSjeremylt 
30314922b2aSjeremylt int CeedQFunctionGetInnerContext(CeedQFunction qf, void* *ctx) {
30414922b2aSjeremylt   if (qf->fortranstatus) {
305069aeabaSjeremylt     fContext *fctx = qf->ctx;
306069aeabaSjeremylt     *ctx = fctx->innerctx;
30714922b2aSjeremylt   } else {
30814922b2aSjeremylt     *ctx = qf->ctx;
30914922b2aSjeremylt   }
31014922b2aSjeremylt 
3119f0427d9SYohann 
312069aeabaSjeremylt   return 0;
313069aeabaSjeremylt }
314069aeabaSjeremylt 
315069aeabaSjeremylt /**
3164ce2993fSjeremylt   @brief Get backend data of a CeedQFunction
3174ce2993fSjeremylt 
3184ce2993fSjeremylt   @param qf              CeedQFunction
3194ce2993fSjeremylt   @param[out] data       Variable to store data
3204ce2993fSjeremylt 
3214ce2993fSjeremylt   @return An error code: 0 - success, otherwise - failure
3224ce2993fSjeremylt 
32323617272Sjeremylt   @ref Advanced
3244ce2993fSjeremylt **/
3254ce2993fSjeremylt 
3264ce2993fSjeremylt int CeedQFunctionGetData(CeedQFunction qf, void* *data) {
3274ce2993fSjeremylt   *data = qf->data;
3284ce2993fSjeremylt   return 0;
3294ce2993fSjeremylt }
3304ce2993fSjeremylt 
3314ce2993fSjeremylt /**
332fe2413ffSjeremylt   @brief Set backend data of a CeedQFunction
333fe2413ffSjeremylt 
334fe2413ffSjeremylt   @param[out] qf         CeedQFunction
335fe2413ffSjeremylt   @param data            Data to set
336fe2413ffSjeremylt 
337fe2413ffSjeremylt   @return An error code: 0 - success, otherwise - failure
338fe2413ffSjeremylt 
339fe2413ffSjeremylt   @ref Advanced
340fe2413ffSjeremylt **/
341fe2413ffSjeremylt 
342fe2413ffSjeremylt int CeedQFunctionSetData(CeedQFunction qf, void* *data) {
343fe2413ffSjeremylt   qf->data = *data;
344fe2413ffSjeremylt   return 0;
345fe2413ffSjeremylt }
346fe2413ffSjeremylt 
347fe2413ffSjeremylt /**
3484ce2993fSjeremylt   @brief Set global context for a CeedQFunction
349b11c1e72Sjeremylt 
350b11c1e72Sjeremylt   @param qf       CeedQFunction
351b11c1e72Sjeremylt   @param ctx      Context data to set
352b11c1e72Sjeremylt   @param ctxsize  Size of context data values
353b11c1e72Sjeremylt 
354b11c1e72Sjeremylt   @return An error code: 0 - success, otherwise - failure
355dfdf5a53Sjeremylt 
356dfdf5a53Sjeremylt   @ref Basic
357b11c1e72Sjeremylt **/
358d7b241e6Sjeremylt int CeedQFunctionSetContext(CeedQFunction qf, void *ctx, size_t ctxsize) {
359d7b241e6Sjeremylt   qf->ctx = ctx;
360d7b241e6Sjeremylt   qf->ctxsize = ctxsize;
361d7b241e6Sjeremylt   return 0;
362d7b241e6Sjeremylt }
363d7b241e6Sjeremylt 
364b11c1e72Sjeremylt /**
365b11c1e72Sjeremylt   @brief Apply the action of a CeedQFunction
366b11c1e72Sjeremylt 
367b11c1e72Sjeremylt   @param qf      CeedQFunction
368b11c1e72Sjeremylt   @param Q       Number of quadrature points
369b11c1e72Sjeremylt   @param[in] u   Array of input data arrays
370b11c1e72Sjeremylt   @param[out] v  Array of output data arrays
371b11c1e72Sjeremylt 
372b11c1e72Sjeremylt   @return An error code: 0 - success, otherwise - failure
373dfdf5a53Sjeremylt 
374dfdf5a53Sjeremylt   @ref Advanced
375b11c1e72Sjeremylt **/
376d7b241e6Sjeremylt int CeedQFunctionApply(CeedQFunction qf, CeedInt Q,
377aedaa0e5Sjeremylt                        CeedVector *u, CeedVector *v) {
378d7b241e6Sjeremylt   int ierr;
379d7b241e6Sjeremylt   if (!qf->Apply)
380d7b241e6Sjeremylt     return CeedError(qf->ceed, 1, "Backend does not support QFunctionApply");
381d7b241e6Sjeremylt   if (Q % qf->vlength)
382d7b241e6Sjeremylt     return CeedError(qf->ceed, 2,
383d7b241e6Sjeremylt                      "Number of quadrature points %d must be a multiple of %d",
384d7b241e6Sjeremylt                      Q, qf->vlength);
385d7b241e6Sjeremylt   ierr = qf->Apply(qf, Q, u, v); CeedChk(ierr);
386d7b241e6Sjeremylt   return 0;
387d7b241e6Sjeremylt }
388d7b241e6Sjeremylt 
389b11c1e72Sjeremylt /**
390d1bcdac9Sjeremylt   @brief Get the CeedQFunctionFields of a CeedQFunction
391d1bcdac9Sjeremylt 
392d1bcdac9Sjeremylt   @param qf                 CeedQFunction
393d1bcdac9Sjeremylt   @param[out] inputfields   Variable to store inputfields
394d1bcdac9Sjeremylt   @param[out] outputfields  Variable to store outputfields
395d1bcdac9Sjeremylt 
396d1bcdac9Sjeremylt   @return An error code: 0 - success, otherwise - failure
397d1bcdac9Sjeremylt 
398d1bcdac9Sjeremylt   @ref Advanced
399d1bcdac9Sjeremylt **/
400d1bcdac9Sjeremylt 
401d1bcdac9Sjeremylt int CeedQFunctionGetFields(CeedQFunction qf,
402d1bcdac9Sjeremylt                            CeedQFunctionField* *inputfields,
403d1bcdac9Sjeremylt                            CeedQFunctionField* *outputfields) {
404d1bcdac9Sjeremylt   if (inputfields) *inputfields = qf->inputfields;
405d1bcdac9Sjeremylt   if (outputfields) *outputfields = qf->outputfields;
406d1bcdac9Sjeremylt   return 0;
407d1bcdac9Sjeremylt }
408d1bcdac9Sjeremylt 
409d1bcdac9Sjeremylt /**
410fe2413ffSjeremylt   @brief Get the name of a CeedQFunctionField
411fe2413ffSjeremylt 
412fe2413ffSjeremylt   @param qffield         CeedQFunctionField
413fe2413ffSjeremylt   @param[out] fieldname  Variable to store the field name
414fe2413ffSjeremylt 
415fe2413ffSjeremylt   @return An error code: 0 - success, otherwise - failure
416fe2413ffSjeremylt 
417fe2413ffSjeremylt   @ref Advanced
418fe2413ffSjeremylt **/
419fe2413ffSjeremylt 
420fe2413ffSjeremylt int CeedQFunctionFieldGetName(CeedQFunctionField qffield,
421fe2413ffSjeremylt                               char* *fieldname) {
422fe2413ffSjeremylt   *fieldname = (char *)qffield->fieldname;
423fe2413ffSjeremylt   return 0;
424fe2413ffSjeremylt }
425fe2413ffSjeremylt 
426fe2413ffSjeremylt /**
427d1bcdac9Sjeremylt   @brief Get the number of components of a CeedQFunctionField
428d1bcdac9Sjeremylt 
429d1bcdac9Sjeremylt   @param qffield         CeedQFunctionField
430d1bcdac9Sjeremylt   @param[out] numcomp    Variable to store the number of components
431d1bcdac9Sjeremylt 
432d1bcdac9Sjeremylt   @return An error code: 0 - success, otherwise - failure
433d1bcdac9Sjeremylt 
434d1bcdac9Sjeremylt   @ref Advanced
435d1bcdac9Sjeremylt **/
436d1bcdac9Sjeremylt 
437d1bcdac9Sjeremylt int CeedQFunctionFieldGetNumComponents(CeedQFunctionField qffield,
438d1bcdac9Sjeremylt                                        CeedInt *numcomp) {
439fe2413ffSjeremylt   *numcomp = qffield->ncomp;
440d1bcdac9Sjeremylt   return 0;
441d1bcdac9Sjeremylt }
442d1bcdac9Sjeremylt 
443d1bcdac9Sjeremylt /**
444d1bcdac9Sjeremylt   @brief Get the CeedEvalMode of a CeedQFunctionField
445d1bcdac9Sjeremylt 
446d1bcdac9Sjeremylt   @param qffield         CeedQFunctionField
447d1bcdac9Sjeremylt   @param[out] vec        Variable to store the number of components
448d1bcdac9Sjeremylt 
449d1bcdac9Sjeremylt   @return An error code: 0 - success, otherwise - failure
450d1bcdac9Sjeremylt 
451d1bcdac9Sjeremylt   @ref Advanced
452d1bcdac9Sjeremylt **/
453d1bcdac9Sjeremylt 
454d1bcdac9Sjeremylt int CeedQFunctionFieldGetEvalMode(CeedQFunctionField qffield,
455d1bcdac9Sjeremylt                                   CeedEvalMode *emode) {
456fe2413ffSjeremylt   *emode = qffield->emode;
457d1bcdac9Sjeremylt   return 0;
458d1bcdac9Sjeremylt }
459d1bcdac9Sjeremylt 
460d1bcdac9Sjeremylt /**
461b11c1e72Sjeremylt   @brief Destroy a CeedQFunction
462b11c1e72Sjeremylt 
463b11c1e72Sjeremylt   @param qf CeedQFunction to destroy
464b11c1e72Sjeremylt 
465b11c1e72Sjeremylt   @return An error code: 0 - success, otherwise - failure
466dfdf5a53Sjeremylt 
467dfdf5a53Sjeremylt   @ref Basic
468b11c1e72Sjeremylt **/
469d7b241e6Sjeremylt int CeedQFunctionDestroy(CeedQFunction *qf) {
470d7b241e6Sjeremylt   int ierr;
471d7b241e6Sjeremylt 
472d7b241e6Sjeremylt   if (!*qf || --(*qf)->refcount > 0) return 0;
473fe2413ffSjeremylt   // Backend destroy
474d7b241e6Sjeremylt   if ((*qf)->Destroy) {
475d7b241e6Sjeremylt     ierr = (*qf)->Destroy(*qf); CeedChk(ierr);
476d7b241e6Sjeremylt   }
477fe2413ffSjeremylt   // Free fields
478fe2413ffSjeremylt   for (int i=0; i<(*qf)->numinputfields; i++) {
479fe2413ffSjeremylt     ierr = CeedFree(&(*(*qf)->inputfields[i]).fieldname); CeedChk(ierr);
480fe2413ffSjeremylt     ierr = CeedFree(&(*qf)->inputfields[i]); CeedChk(ierr);
481fe2413ffSjeremylt   }
482fe2413ffSjeremylt   for (int i=0; i<(*qf)->numoutputfields; i++) {
483fe2413ffSjeremylt     ierr = CeedFree(&(*(*qf)->outputfields[i]).fieldname); CeedChk(ierr);
484fe2413ffSjeremylt     ierr = CeedFree(&(*qf)->outputfields[i]); CeedChk(ierr);
485fe2413ffSjeremylt   }
486fe2413ffSjeremylt   ierr = CeedFree(&(*qf)->inputfields); CeedChk(ierr);
487fe2413ffSjeremylt   ierr = CeedFree(&(*qf)->outputfields); CeedChk(ierr);
488fe2413ffSjeremylt 
489d7b241e6Sjeremylt   ierr = CeedFree(&(*qf)->focca); CeedChk(ierr);
490d7b241e6Sjeremylt   ierr = CeedDestroy(&(*qf)->ceed); CeedChk(ierr);
491d7b241e6Sjeremylt   ierr = CeedFree(qf); CeedChk(ierr);
492d7b241e6Sjeremylt   return 0;
493d7b241e6Sjeremylt }
494d7b241e6Sjeremylt 
495d7b241e6Sjeremylt /// @}
496