xref: /libCEED/interface/ceed-qfunction.c (revision 8795c9458136fc8cad6e4d699e4c8f3c99be02e2)
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 
41*8795c945Sjeremylt   See \ref CeedQFunctionUser for details on the call-back function @a f's
42*8795c945Sjeremylt     arguments.
43d7b241e6Sjeremylt 
44dfdf5a53Sjeremylt   @ref Basic
45dfdf5a53Sjeremylt **/
46d7b241e6Sjeremylt int CeedQFunctionCreateInterior(Ceed ceed, CeedInt vlength,
479f0427d9SYohann                                 CeedQFunctionUser f,
48d7b241e6Sjeremylt                                 const char *focca, CeedQFunction *qf) {
49d7b241e6Sjeremylt   int ierr;
50d7b241e6Sjeremylt   char *focca_copy;
51d7b241e6Sjeremylt 
525fe0d4faSjeremylt   if (!ceed->QFunctionCreate) {
535fe0d4faSjeremylt     Ceed delegate;
54aefd8378Sjeremylt     ierr = CeedGetObjectDelegate(ceed, &delegate, "QFunction"); CeedChk(ierr);
555fe0d4faSjeremylt 
565fe0d4faSjeremylt     if (!delegate)
57d7b241e6Sjeremylt       return CeedError(ceed, 1, "Backend does not support QFunctionCreate");
585fe0d4faSjeremylt 
591dfeef1dSjeremylt     ierr = CeedQFunctionCreateInterior(delegate, vlength, f, focca, qf);
601dfeef1dSjeremylt     CeedChk(ierr);
615fe0d4faSjeremylt     return 0;
625fe0d4faSjeremylt   }
635fe0d4faSjeremylt 
64d7b241e6Sjeremylt   ierr = CeedCalloc(1,qf); CeedChk(ierr);
65d7b241e6Sjeremylt   (*qf)->ceed = ceed;
66d7b241e6Sjeremylt   ceed->refcount++;
67d7b241e6Sjeremylt   (*qf)->refcount = 1;
68d7b241e6Sjeremylt   (*qf)->vlength = vlength;
69d7b241e6Sjeremylt   (*qf)->function = f;
70d7b241e6Sjeremylt   ierr = CeedCalloc(strlen(focca)+1, &focca_copy); CeedChk(ierr);
71409ab9adSjeremylt   strncpy(focca_copy, focca, strlen(focca)+1);
72d7b241e6Sjeremylt   (*qf)->focca = focca_copy;
73fe2413ffSjeremylt   ierr = CeedCalloc(16, &(*qf)->inputfields); CeedChk(ierr);
74fe2413ffSjeremylt   ierr = CeedCalloc(16, &(*qf)->outputfields); CeedChk(ierr);
75d7b241e6Sjeremylt   ierr = ceed->QFunctionCreate(*qf); CeedChk(ierr);
76d7b241e6Sjeremylt   return 0;
77d7b241e6Sjeremylt }
78d7b241e6Sjeremylt 
79b11c1e72Sjeremylt /**
80a0a97fcfSJed Brown   @brief Set a CeedQFunction field, used by CeedQFunctionAddInput/Output
81b11c1e72Sjeremylt 
82b11c1e72Sjeremylt   @param f          CeedQFunctionField
83b11c1e72Sjeremylt   @param fieldname  Name of QFunction field
84b11c1e72Sjeremylt   @param ncomp      Number of components per quadrature node
85b11c1e72Sjeremylt   @param emode      \ref CEED_EVAL_NONE to use values directly,
86b11c1e72Sjeremylt                       \ref CEED_EVAL_INTERP to use interpolated values,
87b11c1e72Sjeremylt                       \ref CEED_EVAL_GRAD to use gradients.
88b11c1e72Sjeremylt 
89b11c1e72Sjeremylt   @return An error code: 0 - success, otherwise - failure
90dfdf5a53Sjeremylt 
91dfdf5a53Sjeremylt   @ref Developer
92b11c1e72Sjeremylt **/
93fe2413ffSjeremylt static int CeedQFunctionFieldSet(CeedQFunctionField *f,const char *fieldname,
94fe2413ffSjeremylt                                  CeedInt ncomp, CeedEvalMode emode) {
95d7b241e6Sjeremylt   size_t len = strlen(fieldname);
96d7b241e6Sjeremylt   char *tmp;
97fe2413ffSjeremylt   int ierr;
98fe2413ffSjeremylt   ierr = CeedCalloc(1,f); CeedChk(ierr);
99fe2413ffSjeremylt 
100fe2413ffSjeremylt   ierr = CeedCalloc(len+1, &tmp); CeedChk(ierr);
101d7b241e6Sjeremylt   memcpy(tmp, fieldname, len+1);
102fe2413ffSjeremylt   (*f)->fieldname = tmp;
103fe2413ffSjeremylt   (*f)->ncomp = ncomp;
104fe2413ffSjeremylt   (*f)->emode = emode;
105d7b241e6Sjeremylt   return 0;
106d7b241e6Sjeremylt }
107d7b241e6Sjeremylt 
108b11c1e72Sjeremylt /**
109a0a97fcfSJed Brown   @brief Add a CeedQFunction input
110b11c1e72Sjeremylt 
111b11c1e72Sjeremylt   @param qf         CeedQFunction
112b11c1e72Sjeremylt   @param fieldname  Name of QFunction field
113b11c1e72Sjeremylt   @param ncomp      Number of components per quadrature node
114b11c1e72Sjeremylt   @param emode      \ref CEED_EVAL_NONE to use values directly,
115b11c1e72Sjeremylt                       \ref CEED_EVAL_INTERP to use interpolated values,
116b11c1e72Sjeremylt                       \ref CEED_EVAL_GRAD to use gradients.
117b11c1e72Sjeremylt 
118b11c1e72Sjeremylt   @return An error code: 0 - success, otherwise - failure
119dfdf5a53Sjeremylt 
120dfdf5a53Sjeremylt   @ref Basic
121b11c1e72Sjeremylt **/
122d7b241e6Sjeremylt int CeedQFunctionAddInput(CeedQFunction qf, const char *fieldname,
123d7b241e6Sjeremylt                           CeedInt ncomp, CeedEvalMode emode) {
124fe2413ffSjeremylt   int ierr = CeedQFunctionFieldSet(&qf->inputfields[qf->numinputfields],
125fe2413ffSjeremylt                                    fieldname, ncomp, emode);
126fe2413ffSjeremylt   CeedChk(ierr);
127fe2413ffSjeremylt   qf->numinputfields++;
128d7b241e6Sjeremylt   return 0;
129d7b241e6Sjeremylt }
130d7b241e6Sjeremylt 
131b11c1e72Sjeremylt /**
132a0a97fcfSJed Brown   @brief Add a CeedQFunction output
133b11c1e72Sjeremylt 
134b11c1e72Sjeremylt   @param qf         CeedQFunction
135b11c1e72Sjeremylt   @param fieldname  Name of QFunction field
136b11c1e72Sjeremylt   @param ncomp      Number of components per quadrature node
137b11c1e72Sjeremylt   @param emode      \ref CEED_EVAL_NONE to use values directly,
138b11c1e72Sjeremylt                       \ref CEED_EVAL_INTERP to use interpolated values,
139b11c1e72Sjeremylt                       \ref CEED_EVAL_GRAD to use gradients.
140b11c1e72Sjeremylt 
141b11c1e72Sjeremylt   @return An error code: 0 - success, otherwise - failure
142dfdf5a53Sjeremylt 
143dfdf5a53Sjeremylt   @ref Basic
144b11c1e72Sjeremylt **/
145d7b241e6Sjeremylt int CeedQFunctionAddOutput(CeedQFunction qf, const char *fieldname,
146d7b241e6Sjeremylt                            CeedInt ncomp, CeedEvalMode emode) {
147d7b241e6Sjeremylt   if (emode == CEED_EVAL_WEIGHT)
148d7b241e6Sjeremylt     return CeedError(qf->ceed, 1,
1498c91a0c9SJeremy L Thompson                      "Cannot create QFunction output with CEED_EVAL_WEIGHT");
150fe2413ffSjeremylt   int ierr = CeedQFunctionFieldSet(&qf->outputfields[qf->numoutputfields],
151fe2413ffSjeremylt                                    fieldname, ncomp, emode);
152fe2413ffSjeremylt   CeedChk(ierr);
153fe2413ffSjeremylt   qf->numoutputfields++;
154d7b241e6Sjeremylt   return 0;
155d7b241e6Sjeremylt }
156d7b241e6Sjeremylt 
157dfdf5a53Sjeremylt /**
1584ce2993fSjeremylt   @brief Get the Ceed associated with a CeedQFunction
1594ce2993fSjeremylt 
1604ce2993fSjeremylt   @param qf              CeedQFunction
1614ce2993fSjeremylt   @param[out] ceed       Variable to store Ceed
1624ce2993fSjeremylt 
1634ce2993fSjeremylt   @return An error code: 0 - success, otherwise - failure
1644ce2993fSjeremylt 
16523617272Sjeremylt   @ref Advanced
1664ce2993fSjeremylt **/
1674ce2993fSjeremylt 
1684ce2993fSjeremylt int CeedQFunctionGetCeed(CeedQFunction qf, Ceed *ceed) {
1694ce2993fSjeremylt   *ceed = qf->ceed;
1704ce2993fSjeremylt   return 0;
1714ce2993fSjeremylt }
1724ce2993fSjeremylt 
1734ce2993fSjeremylt /**
1744ce2993fSjeremylt   @brief Get the vector length of a CeedQFunction
1754ce2993fSjeremylt 
1764ce2993fSjeremylt   @param qf              CeedQFunction
1774ce2993fSjeremylt   @param[out] veclength  Variable to store vector length
1784ce2993fSjeremylt 
1794ce2993fSjeremylt   @return An error code: 0 - success, otherwise - failure
1804ce2993fSjeremylt 
18123617272Sjeremylt   @ref Advanced
1824ce2993fSjeremylt **/
1834ce2993fSjeremylt 
1844ce2993fSjeremylt int CeedQFunctionGetVectorLength(CeedQFunction qf, CeedInt *vlength) {
1854ce2993fSjeremylt   *vlength = qf->vlength;
1864ce2993fSjeremylt   return 0;
1874ce2993fSjeremylt }
1884ce2993fSjeremylt 
1894ce2993fSjeremylt /**
190dfdf5a53Sjeremylt   @brief Get the number of inputs and outputs to a CeedQFunction
191dfdf5a53Sjeremylt 
192dfdf5a53Sjeremylt   @param qf              CeedQFunction
1934ce2993fSjeremylt   @param[out] numinput   Variable to store number of input fields
1944ce2993fSjeremylt   @param[out] numoutput  Variable to store number of output fields
195dfdf5a53Sjeremylt 
196dfdf5a53Sjeremylt   @return An error code: 0 - success, otherwise - failure
197dfdf5a53Sjeremylt 
19823617272Sjeremylt   @ref Advanced
199dfdf5a53Sjeremylt **/
200dfdf5a53Sjeremylt 
201d7b241e6Sjeremylt int CeedQFunctionGetNumArgs(CeedQFunction qf, CeedInt *numinput,
202d7b241e6Sjeremylt                             CeedInt *numoutput) {
2031a4ead9bSjeremylt   if (numinput) *numinput = qf->numinputfields;
2041a4ead9bSjeremylt   if (numoutput) *numoutput = qf->numoutputfields;
205d7b241e6Sjeremylt   return 0;
206d7b241e6Sjeremylt }
207d7b241e6Sjeremylt 
208d7b241e6Sjeremylt /**
2094ce2993fSjeremylt   @brief Get the FOCCA string for a CeedQFunction
2104ce2993fSjeremylt 
2114ce2993fSjeremylt   @param qf              CeedQFunction
2124ce2993fSjeremylt   @param[out] focca      Variable to store focca string
2134ce2993fSjeremylt 
2144ce2993fSjeremylt   @return An error code: 0 - success, otherwise - failure
2154ce2993fSjeremylt 
21623617272Sjeremylt   @ref Advanced
2174ce2993fSjeremylt **/
2184ce2993fSjeremylt 
2194ce2993fSjeremylt int CeedQFunctionGetFOCCA(CeedQFunction qf, char* *focca) {
2204ce2993fSjeremylt   *focca = (char *) qf->focca;
2214ce2993fSjeremylt   return 0;
2224ce2993fSjeremylt }
2234ce2993fSjeremylt 
2244ce2993fSjeremylt /**
225fe2413ffSjeremylt   @brief Get the User Function for a CeedQFunction
226fe2413ffSjeremylt 
227fe2413ffSjeremylt   @param qf              CeedQFunction
228fe2413ffSjeremylt   @param[out] f          Variable to store user function
229fe2413ffSjeremylt 
230fe2413ffSjeremylt   @return An error code: 0 - success, otherwise - failure
231fe2413ffSjeremylt 
232fe2413ffSjeremylt   @ref Advanced
233fe2413ffSjeremylt **/
234fe2413ffSjeremylt 
23528d161eeSjeremylt int CeedQFunctionGetUserFunction(CeedQFunction qf, int (**f)()) {
23628d161eeSjeremylt   *f = (int (*)())qf->function;
237fe2413ffSjeremylt   return 0;
238fe2413ffSjeremylt }
239fe2413ffSjeremylt 
240fe2413ffSjeremylt /**
2414ce2993fSjeremylt   @brief Get global context size for a CeedQFunction
2424ce2993fSjeremylt 
2434ce2993fSjeremylt   @param qf              CeedQFunction
2444ce2993fSjeremylt   @param[out] ctxsize    Variable to store size of context data values
2454ce2993fSjeremylt 
2464ce2993fSjeremylt   @return An error code: 0 - success, otherwise - failure
2474ce2993fSjeremylt 
24823617272Sjeremylt   @ref Advanced
2494ce2993fSjeremylt **/
2504ce2993fSjeremylt 
2514ce2993fSjeremylt int CeedQFunctionGetContextSize(CeedQFunction qf, size_t *ctxsize) {
252069aeabaSjeremylt   if (qf->fortranstatus) {
253069aeabaSjeremylt     fContext *fctx = qf->ctx;
254069aeabaSjeremylt     *ctxsize = fctx->innerctxsize;
255069aeabaSjeremylt   } else {
2564ce2993fSjeremylt     *ctxsize = qf->ctxsize;
257069aeabaSjeremylt   }
2584ce2993fSjeremylt   return 0;
2594ce2993fSjeremylt }
2604ce2993fSjeremylt 
2614ce2993fSjeremylt /**
2624ce2993fSjeremylt   @brief Get global context for a CeedQFunction
2634ce2993fSjeremylt 
2644ce2993fSjeremylt   @param qf              CeedQFunction
2654ce2993fSjeremylt   @param[out] ctx        Variable to store context data values
2664ce2993fSjeremylt 
2674ce2993fSjeremylt   @return An error code: 0 - success, otherwise - failure
2684ce2993fSjeremylt 
26923617272Sjeremylt   @ref Advanced
2704ce2993fSjeremylt **/
2714ce2993fSjeremylt 
2724ce2993fSjeremylt int CeedQFunctionGetContext(CeedQFunction qf, void* *ctx) {
2734ce2993fSjeremylt   *ctx = qf->ctx;
2744ce2993fSjeremylt   return 0;
2754ce2993fSjeremylt }
2764ce2993fSjeremylt 
2774ce2993fSjeremylt /**
278418fb8c2Sjeremylt   @brief Determine if Fortran interface was used
279418fb8c2Sjeremylt 
280418fb8c2Sjeremylt   @param qf                  CeedQFunction
281418fb8c2Sjeremylt   @param[out] fortranstatus  Variable to store Fortran status
282418fb8c2Sjeremylt 
283418fb8c2Sjeremylt   @return An error code: 0 - success, otherwise - failure
284418fb8c2Sjeremylt 
285418fb8c2Sjeremylt   @ref Advanced
286418fb8c2Sjeremylt **/
287418fb8c2Sjeremylt 
288418fb8c2Sjeremylt int CeedQFunctionGetFortranStatus(CeedQFunction qf, bool *fortranstatus) {
289418fb8c2Sjeremylt   *fortranstatus = qf->fortranstatus;
290418fb8c2Sjeremylt   return 0;
291418fb8c2Sjeremylt }
292418fb8c2Sjeremylt 
293418fb8c2Sjeremylt /**
29414922b2aSjeremylt   @brief Get true user context for a CeedQFunction
295069aeabaSjeremylt 
296069aeabaSjeremylt   @param qf              CeedQFunction
297069aeabaSjeremylt   @param[out] ctx        Variable to store context data values
298069aeabaSjeremylt 
299069aeabaSjeremylt   @return An error code: 0 - success, otherwise - failure
300069aeabaSjeremylt 
301069aeabaSjeremylt   @ref Advanced
302069aeabaSjeremylt **/
303069aeabaSjeremylt 
30414922b2aSjeremylt int CeedQFunctionGetInnerContext(CeedQFunction qf, void* *ctx) {
30514922b2aSjeremylt   if (qf->fortranstatus) {
306069aeabaSjeremylt     fContext *fctx = qf->ctx;
307069aeabaSjeremylt     *ctx = fctx->innerctx;
30814922b2aSjeremylt   } else {
30914922b2aSjeremylt     *ctx = qf->ctx;
31014922b2aSjeremylt   }
31114922b2aSjeremylt 
3129f0427d9SYohann 
313069aeabaSjeremylt   return 0;
314069aeabaSjeremylt }
315069aeabaSjeremylt 
316069aeabaSjeremylt /**
3174ce2993fSjeremylt   @brief Get backend data of a CeedQFunction
3184ce2993fSjeremylt 
3194ce2993fSjeremylt   @param qf              CeedQFunction
3204ce2993fSjeremylt   @param[out] data       Variable to store data
3214ce2993fSjeremylt 
3224ce2993fSjeremylt   @return An error code: 0 - success, otherwise - failure
3234ce2993fSjeremylt 
32423617272Sjeremylt   @ref Advanced
3254ce2993fSjeremylt **/
3264ce2993fSjeremylt 
3274ce2993fSjeremylt int CeedQFunctionGetData(CeedQFunction qf, void* *data) {
3284ce2993fSjeremylt   *data = qf->data;
3294ce2993fSjeremylt   return 0;
3304ce2993fSjeremylt }
3314ce2993fSjeremylt 
3324ce2993fSjeremylt /**
333fe2413ffSjeremylt   @brief Set backend data of a CeedQFunction
334fe2413ffSjeremylt 
335fe2413ffSjeremylt   @param[out] qf         CeedQFunction
336fe2413ffSjeremylt   @param data            Data to set
337fe2413ffSjeremylt 
338fe2413ffSjeremylt   @return An error code: 0 - success, otherwise - failure
339fe2413ffSjeremylt 
340fe2413ffSjeremylt   @ref Advanced
341fe2413ffSjeremylt **/
342fe2413ffSjeremylt 
343fe2413ffSjeremylt int CeedQFunctionSetData(CeedQFunction qf, void* *data) {
344fe2413ffSjeremylt   qf->data = *data;
345fe2413ffSjeremylt   return 0;
346fe2413ffSjeremylt }
347fe2413ffSjeremylt 
348fe2413ffSjeremylt /**
3494ce2993fSjeremylt   @brief Set global context for a CeedQFunction
350b11c1e72Sjeremylt 
351b11c1e72Sjeremylt   @param qf       CeedQFunction
352b11c1e72Sjeremylt   @param ctx      Context data to set
353b11c1e72Sjeremylt   @param ctxsize  Size of context data values
354b11c1e72Sjeremylt 
355b11c1e72Sjeremylt   @return An error code: 0 - success, otherwise - failure
356dfdf5a53Sjeremylt 
357dfdf5a53Sjeremylt   @ref Basic
358b11c1e72Sjeremylt **/
359d7b241e6Sjeremylt int CeedQFunctionSetContext(CeedQFunction qf, void *ctx, size_t ctxsize) {
360d7b241e6Sjeremylt   qf->ctx = ctx;
361d7b241e6Sjeremylt   qf->ctxsize = ctxsize;
362d7b241e6Sjeremylt   return 0;
363d7b241e6Sjeremylt }
364d7b241e6Sjeremylt 
365b11c1e72Sjeremylt /**
366b11c1e72Sjeremylt   @brief Apply the action of a CeedQFunction
367b11c1e72Sjeremylt 
368b11c1e72Sjeremylt   @param qf      CeedQFunction
369b11c1e72Sjeremylt   @param Q       Number of quadrature points
370b11c1e72Sjeremylt   @param[in] u   Array of input data arrays
371b11c1e72Sjeremylt   @param[out] v  Array of output data arrays
372b11c1e72Sjeremylt 
373b11c1e72Sjeremylt   @return An error code: 0 - success, otherwise - failure
374dfdf5a53Sjeremylt 
375dfdf5a53Sjeremylt   @ref Advanced
376b11c1e72Sjeremylt **/
377d7b241e6Sjeremylt int CeedQFunctionApply(CeedQFunction qf, CeedInt Q,
378aedaa0e5Sjeremylt                        CeedVector *u, CeedVector *v) {
379d7b241e6Sjeremylt   int ierr;
380d7b241e6Sjeremylt   if (!qf->Apply)
381d7b241e6Sjeremylt     return CeedError(qf->ceed, 1, "Backend does not support QFunctionApply");
382d7b241e6Sjeremylt   if (Q % qf->vlength)
383d7b241e6Sjeremylt     return CeedError(qf->ceed, 2,
384d7b241e6Sjeremylt                      "Number of quadrature points %d must be a multiple of %d",
385d7b241e6Sjeremylt                      Q, qf->vlength);
386d7b241e6Sjeremylt   ierr = qf->Apply(qf, Q, u, v); CeedChk(ierr);
387d7b241e6Sjeremylt   return 0;
388d7b241e6Sjeremylt }
389d7b241e6Sjeremylt 
390b11c1e72Sjeremylt /**
391d1bcdac9Sjeremylt   @brief Get the CeedQFunctionFields of a CeedQFunction
392d1bcdac9Sjeremylt 
393d1bcdac9Sjeremylt   @param qf                 CeedQFunction
394d1bcdac9Sjeremylt   @param[out] inputfields   Variable to store inputfields
395d1bcdac9Sjeremylt   @param[out] outputfields  Variable to store outputfields
396d1bcdac9Sjeremylt 
397d1bcdac9Sjeremylt   @return An error code: 0 - success, otherwise - failure
398d1bcdac9Sjeremylt 
399d1bcdac9Sjeremylt   @ref Advanced
400d1bcdac9Sjeremylt **/
401d1bcdac9Sjeremylt 
402d1bcdac9Sjeremylt int CeedQFunctionGetFields(CeedQFunction qf,
403d1bcdac9Sjeremylt                            CeedQFunctionField* *inputfields,
404d1bcdac9Sjeremylt                            CeedQFunctionField* *outputfields) {
405d1bcdac9Sjeremylt   if (inputfields) *inputfields = qf->inputfields;
406d1bcdac9Sjeremylt   if (outputfields) *outputfields = qf->outputfields;
407d1bcdac9Sjeremylt   return 0;
408d1bcdac9Sjeremylt }
409d1bcdac9Sjeremylt 
410d1bcdac9Sjeremylt /**
411fe2413ffSjeremylt   @brief Get the name of a CeedQFunctionField
412fe2413ffSjeremylt 
413fe2413ffSjeremylt   @param qffield         CeedQFunctionField
414fe2413ffSjeremylt   @param[out] fieldname  Variable to store the field name
415fe2413ffSjeremylt 
416fe2413ffSjeremylt   @return An error code: 0 - success, otherwise - failure
417fe2413ffSjeremylt 
418fe2413ffSjeremylt   @ref Advanced
419fe2413ffSjeremylt **/
420fe2413ffSjeremylt 
421fe2413ffSjeremylt int CeedQFunctionFieldGetName(CeedQFunctionField qffield,
422fe2413ffSjeremylt                               char* *fieldname) {
423fe2413ffSjeremylt   *fieldname = (char *)qffield->fieldname;
424fe2413ffSjeremylt   return 0;
425fe2413ffSjeremylt }
426fe2413ffSjeremylt 
427fe2413ffSjeremylt /**
428d1bcdac9Sjeremylt   @brief Get the number of components of a CeedQFunctionField
429d1bcdac9Sjeremylt 
430d1bcdac9Sjeremylt   @param qffield         CeedQFunctionField
431d1bcdac9Sjeremylt   @param[out] numcomp    Variable to store the number of components
432d1bcdac9Sjeremylt 
433d1bcdac9Sjeremylt   @return An error code: 0 - success, otherwise - failure
434d1bcdac9Sjeremylt 
435d1bcdac9Sjeremylt   @ref Advanced
436d1bcdac9Sjeremylt **/
437d1bcdac9Sjeremylt 
438d1bcdac9Sjeremylt int CeedQFunctionFieldGetNumComponents(CeedQFunctionField qffield,
439d1bcdac9Sjeremylt                                        CeedInt *numcomp) {
440fe2413ffSjeremylt   *numcomp = qffield->ncomp;
441d1bcdac9Sjeremylt   return 0;
442d1bcdac9Sjeremylt }
443d1bcdac9Sjeremylt 
444d1bcdac9Sjeremylt /**
445d1bcdac9Sjeremylt   @brief Get the CeedEvalMode of a CeedQFunctionField
446d1bcdac9Sjeremylt 
447d1bcdac9Sjeremylt   @param qffield         CeedQFunctionField
448d1bcdac9Sjeremylt   @param[out] vec        Variable to store the number of components
449d1bcdac9Sjeremylt 
450d1bcdac9Sjeremylt   @return An error code: 0 - success, otherwise - failure
451d1bcdac9Sjeremylt 
452d1bcdac9Sjeremylt   @ref Advanced
453d1bcdac9Sjeremylt **/
454d1bcdac9Sjeremylt 
455d1bcdac9Sjeremylt int CeedQFunctionFieldGetEvalMode(CeedQFunctionField qffield,
456d1bcdac9Sjeremylt                                   CeedEvalMode *emode) {
457fe2413ffSjeremylt   *emode = qffield->emode;
458d1bcdac9Sjeremylt   return 0;
459d1bcdac9Sjeremylt }
460d1bcdac9Sjeremylt 
461d1bcdac9Sjeremylt /**
462b11c1e72Sjeremylt   @brief Destroy a CeedQFunction
463b11c1e72Sjeremylt 
464b11c1e72Sjeremylt   @param qf CeedQFunction to destroy
465b11c1e72Sjeremylt 
466b11c1e72Sjeremylt   @return An error code: 0 - success, otherwise - failure
467dfdf5a53Sjeremylt 
468dfdf5a53Sjeremylt   @ref Basic
469b11c1e72Sjeremylt **/
470d7b241e6Sjeremylt int CeedQFunctionDestroy(CeedQFunction *qf) {
471d7b241e6Sjeremylt   int ierr;
472d7b241e6Sjeremylt 
473d7b241e6Sjeremylt   if (!*qf || --(*qf)->refcount > 0) return 0;
474fe2413ffSjeremylt   // Backend destroy
475d7b241e6Sjeremylt   if ((*qf)->Destroy) {
476d7b241e6Sjeremylt     ierr = (*qf)->Destroy(*qf); CeedChk(ierr);
477d7b241e6Sjeremylt   }
478fe2413ffSjeremylt   // Free fields
479fe2413ffSjeremylt   for (int i=0; i<(*qf)->numinputfields; i++) {
480fe2413ffSjeremylt     ierr = CeedFree(&(*(*qf)->inputfields[i]).fieldname); CeedChk(ierr);
481fe2413ffSjeremylt     ierr = CeedFree(&(*qf)->inputfields[i]); CeedChk(ierr);
482fe2413ffSjeremylt   }
483fe2413ffSjeremylt   for (int i=0; i<(*qf)->numoutputfields; i++) {
484fe2413ffSjeremylt     ierr = CeedFree(&(*(*qf)->outputfields[i]).fieldname); CeedChk(ierr);
485fe2413ffSjeremylt     ierr = CeedFree(&(*qf)->outputfields[i]); CeedChk(ierr);
486fe2413ffSjeremylt   }
487fe2413ffSjeremylt   ierr = CeedFree(&(*qf)->inputfields); CeedChk(ierr);
488fe2413ffSjeremylt   ierr = CeedFree(&(*qf)->outputfields); CeedChk(ierr);
489fe2413ffSjeremylt 
490d7b241e6Sjeremylt   ierr = CeedFree(&(*qf)->focca); CeedChk(ierr);
491d7b241e6Sjeremylt   ierr = CeedDestroy(&(*qf)->ceed); CeedChk(ierr);
492d7b241e6Sjeremylt   ierr = CeedFree(qf); CeedChk(ierr);
493d7b241e6Sjeremylt   return 0;
494d7b241e6Sjeremylt }
495d7b241e6Sjeremylt 
496d7b241e6Sjeremylt /// @}
497