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> 20288c0443SJeremy L Thompson #include <limits.h> 21288c0443SJeremy L Thompson 227a982d89SJeremy L. Thompson /// @file 237a982d89SJeremy L. Thompson /// Implementation of public CeedQFunction interfaces 247a982d89SJeremy L. Thompson 25288c0443SJeremy L Thompson /// @cond DOXYGEN_SKIP 26442e7f0bSjeremylt static struct CeedQFunction_private ceed_qfunction_none; 27442e7f0bSjeremylt /// @endcond 28442e7f0bSjeremylt 297a982d89SJeremy L. Thompson /// @addtogroup CeedQFunctionUser 307a982d89SJeremy L. Thompson /// @{ 317a982d89SJeremy L. Thompson 327a982d89SJeremy L. Thompson // Indicate that no QFunction is provided by the user 337a982d89SJeremy L. Thompson const CeedQFunction CEED_QFUNCTION_NONE = &ceed_qfunction_none; 347a982d89SJeremy L. Thompson 357a982d89SJeremy L. Thompson /// @} 367a982d89SJeremy L. Thompson 37442e7f0bSjeremylt /// @cond DOXYGEN_SKIP 38288c0443SJeremy L Thompson static struct { 39288c0443SJeremy L Thompson char name[CEED_MAX_RESOURCE_LEN]; 40288c0443SJeremy L Thompson char source[CEED_MAX_RESOURCE_LEN]; 41288c0443SJeremy L Thompson CeedInt vlength; 42288c0443SJeremy L Thompson CeedQFunctionUser f; 43288c0443SJeremy L Thompson int (*init)(Ceed ceed, const char *name, CeedQFunction qf); 44288c0443SJeremy L Thompson } qfunctions[1024]; 45288c0443SJeremy L Thompson static size_t num_qfunctions; 46288c0443SJeremy L Thompson /// @endcond 47d7b241e6Sjeremylt 48777ff853SJeremy L Thompson /// ---------------------------------------------------------------------------- 49777ff853SJeremy L Thompson /// CeedQFunction Library Internal Functions 50777ff853SJeremy L Thompson /// ---------------------------------------------------------------------------- 51777ff853SJeremy L Thompson /// @addtogroup CeedQFunctionDeveloper 52777ff853SJeremy L Thompson /// @{ 53777ff853SJeremy L Thompson 54b11c1e72Sjeremylt /** 55288c0443SJeremy L Thompson @brief Register a gallery QFunction 56288c0443SJeremy L Thompson 57288c0443SJeremy L Thompson @param name Name for this backend to respond to 581176cc3aSJeremy L Thompson @param source Absolute path to source of QFunction, 591176cc3aSJeremy L Thompson "\path\CEED_DIR\gallery\folder\file.h:function_name" 60288c0443SJeremy L Thompson @param vlength Vector length. Caller must ensure that number of quadrature 61288c0443SJeremy L Thompson points is a multiple of vlength. 62288c0443SJeremy L Thompson @param f Function pointer to evaluate action at quadrature points. 63288c0443SJeremy L Thompson See \ref CeedQFunctionUser. 64288c0443SJeremy L Thompson @param init Initialization function called by CeedQFunctionInit() when the 65288c0443SJeremy L Thompson QFunction is selected. 66288c0443SJeremy L Thompson 67288c0443SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 68288c0443SJeremy L Thompson 697a982d89SJeremy L. Thompson @ref Developer 70288c0443SJeremy L Thompson **/ 71288c0443SJeremy L Thompson int CeedQFunctionRegister(const char *name, const char *source, 72288c0443SJeremy L Thompson CeedInt vlength, CeedQFunctionUser f, 73288c0443SJeremy L Thompson int (*init)(Ceed, const char *, CeedQFunction)) { 74c042f62fSJeremy L Thompson if (num_qfunctions >= sizeof(qfunctions) / sizeof(qfunctions[0])) 75c042f62fSJeremy L Thompson // LCOV_EXCL_START 76288c0443SJeremy L Thompson return CeedError(NULL, 1, "Too many gallery QFunctions"); 77c042f62fSJeremy L Thompson // LCOV_EXCL_STOP 78c042f62fSJeremy L Thompson 79288c0443SJeremy L Thompson strncpy(qfunctions[num_qfunctions].name, name, CEED_MAX_RESOURCE_LEN); 80288c0443SJeremy L Thompson qfunctions[num_qfunctions].name[CEED_MAX_RESOURCE_LEN-1] = 0; 81288c0443SJeremy L Thompson strncpy(qfunctions[num_qfunctions].source, source, CEED_MAX_RESOURCE_LEN); 82288c0443SJeremy L Thompson qfunctions[num_qfunctions].source[CEED_MAX_RESOURCE_LEN-1] = 0; 83288c0443SJeremy L Thompson qfunctions[num_qfunctions].vlength = vlength; 84288c0443SJeremy L Thompson qfunctions[num_qfunctions].f = f; 85288c0443SJeremy L Thompson qfunctions[num_qfunctions].init = init; 86288c0443SJeremy L Thompson num_qfunctions++; 87288c0443SJeremy L Thompson return 0; 88288c0443SJeremy L Thompson } 89288c0443SJeremy L Thompson 90288c0443SJeremy L Thompson /** 917a982d89SJeremy L. Thompson @brief Set a CeedQFunction field, used by CeedQFunctionAddInput/Output 927a982d89SJeremy L. Thompson 937a982d89SJeremy L. Thompson @param f CeedQFunctionField 947a982d89SJeremy L. Thompson @param fieldname Name of QFunction field 954cc79fe7SJed Brown @param size Size of QFunction field, (ncomp * dim) for @ref CEED_EVAL_GRAD or 964cc79fe7SJed Brown (ncomp * 1) for @ref CEED_EVAL_NONE, @ref CEED_EVAL_INTERP, and @ref CEED_EVAL_WEIGHT 977a982d89SJeremy L. Thompson @param emode \ref CEED_EVAL_NONE to use values directly, 987a982d89SJeremy L. Thompson \ref CEED_EVAL_INTERP to use interpolated values, 997a982d89SJeremy L. Thompson \ref CEED_EVAL_GRAD to use gradients, 1007a982d89SJeremy L. Thompson \ref CEED_EVAL_WEIGHT to use quadrature weights. 1017a982d89SJeremy L. Thompson 1027a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 1037a982d89SJeremy L. Thompson 1047a982d89SJeremy L. Thompson @ref Developer 1057a982d89SJeremy L. Thompson **/ 1067a982d89SJeremy L. Thompson static int CeedQFunctionFieldSet(CeedQFunctionField *f,const char *fieldname, 1077a982d89SJeremy L. Thompson CeedInt size, CeedEvalMode emode) { 1087a982d89SJeremy L. Thompson size_t len = strlen(fieldname); 1097a982d89SJeremy L. Thompson char *tmp; 1107a982d89SJeremy L. Thompson int ierr; 1117a982d89SJeremy L. Thompson ierr = CeedCalloc(1,f); CeedChk(ierr); 1127a982d89SJeremy L. Thompson 1137a982d89SJeremy L. Thompson ierr = CeedCalloc(len+1, &tmp); CeedChk(ierr); 1147a982d89SJeremy L. Thompson memcpy(tmp, fieldname, len+1); 1157a982d89SJeremy L. Thompson (*f)->fieldname = tmp; 1167a982d89SJeremy L. Thompson (*f)->size = size; 1177a982d89SJeremy L. Thompson (*f)->emode = emode; 1187a982d89SJeremy L. Thompson return 0; 1197a982d89SJeremy L. Thompson } 1207a982d89SJeremy L. Thompson 1217a982d89SJeremy L. Thompson /** 1227a982d89SJeremy L. Thompson @brief View a field of a CeedQFunction 1237a982d89SJeremy L. Thompson 1247a982d89SJeremy L. Thompson @param[in] field QFunction field to view 1257a982d89SJeremy L. Thompson @param[in] fieldnumber Number of field being viewed 1264c4400c7SValeria Barra @param[in] in true for input field, false for output 1277a982d89SJeremy L. Thompson @param[in] stream Stream to view to, e.g., stdout 1287a982d89SJeremy L. Thompson 1297a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 1307a982d89SJeremy L. Thompson 1317a982d89SJeremy L. Thompson @ref Utility 1327a982d89SJeremy L. Thompson **/ 1337a982d89SJeremy L. Thompson static int CeedQFunctionFieldView(CeedQFunctionField field, CeedInt fieldnumber, 1347a982d89SJeremy L. Thompson bool in, FILE *stream) { 1357a982d89SJeremy L. Thompson const char *inout = in ? "Input" : "Output"; 1367a982d89SJeremy L. Thompson fprintf(stream, " %s Field [%d]:\n" 1377a982d89SJeremy L. Thompson " Name: \"%s\"\n" 1387a982d89SJeremy L. Thompson " Size: %d\n" 1397a982d89SJeremy L. Thompson " EvalMode: \"%s\"\n", 1407a982d89SJeremy L. Thompson inout, fieldnumber, field->fieldname, field->size, 1417a982d89SJeremy L. Thompson CeedEvalModes[field->emode]); 1427a982d89SJeremy L. Thompson 1437a982d89SJeremy L. Thompson return 0; 1447a982d89SJeremy L. Thompson } 1457a982d89SJeremy L. Thompson 146777ff853SJeremy L Thompson 147777ff853SJeremy L Thompson /** 148777ff853SJeremy L Thompson @brief Set flag to determine if Fortran interface is used 149777ff853SJeremy L Thompson 150777ff853SJeremy L Thompson @param qf CeedQFunction 151777ff853SJeremy L Thompson @param status Boolean value to set as Fortran status 152777ff853SJeremy L Thompson 153777ff853SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 154777ff853SJeremy L Thompson 155777ff853SJeremy L Thompson @ref Backend 156777ff853SJeremy L Thompson **/ 157777ff853SJeremy L Thompson int CeedQFunctionSetFortranStatus(CeedQFunction qf, bool status) { 158777ff853SJeremy L Thompson qf->fortranstatus = status; 159777ff853SJeremy L Thompson return 0; 160777ff853SJeremy L Thompson } 161777ff853SJeremy L Thompson 1627a982d89SJeremy L. Thompson /// @} 1637a982d89SJeremy L. Thompson 1647a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 1657a982d89SJeremy L. Thompson /// CeedQFunction Backend API 1667a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 1677a982d89SJeremy L. Thompson /// @addtogroup CeedQFunctionBackend 1687a982d89SJeremy L. Thompson /// @{ 1697a982d89SJeremy L. Thompson 1707a982d89SJeremy L. Thompson /** 1717a982d89SJeremy L. Thompson @brief Get the Ceed associated with a CeedQFunction 1727a982d89SJeremy L. Thompson 1737a982d89SJeremy L. Thompson @param qf CeedQFunction 1747a982d89SJeremy L. Thompson @param[out] ceed Variable to store Ceed 1757a982d89SJeremy L. Thompson 1767a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 1777a982d89SJeremy L. Thompson 1787a982d89SJeremy L. Thompson @ref Backend 1797a982d89SJeremy L. Thompson **/ 1807a982d89SJeremy L. Thompson int CeedQFunctionGetCeed(CeedQFunction qf, Ceed *ceed) { 1817a982d89SJeremy L. Thompson *ceed = qf->ceed; 1827a982d89SJeremy L. Thompson return 0; 1837a982d89SJeremy L. Thompson } 1847a982d89SJeremy L. Thompson 1857a982d89SJeremy L. Thompson /** 1867a982d89SJeremy L. Thompson @brief Get the vector length of a CeedQFunction 1877a982d89SJeremy L. Thompson 1887a982d89SJeremy L. Thompson @param qf CeedQFunction 1897a982d89SJeremy L. Thompson @param[out] vlength Variable to store vector length 1907a982d89SJeremy L. Thompson 1917a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 1927a982d89SJeremy L. Thompson 1937a982d89SJeremy L. Thompson @ref Backend 1947a982d89SJeremy L. Thompson **/ 1957a982d89SJeremy L. Thompson int CeedQFunctionGetVectorLength(CeedQFunction qf, CeedInt *vlength) { 1967a982d89SJeremy L. Thompson *vlength = qf->vlength; 1977a982d89SJeremy L. Thompson return 0; 1987a982d89SJeremy L. Thompson } 1997a982d89SJeremy L. Thompson 2007a982d89SJeremy L. Thompson /** 2017a982d89SJeremy L. Thompson @brief Get the number of inputs and outputs to a CeedQFunction 2027a982d89SJeremy L. Thompson 2037a982d89SJeremy L. Thompson @param qf CeedQFunction 2047a982d89SJeremy L. Thompson @param[out] numinput Variable to store number of input fields 2057a982d89SJeremy L. Thompson @param[out] numoutput Variable to store number of output fields 2067a982d89SJeremy L. Thompson 2077a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 2087a982d89SJeremy L. Thompson 2097a982d89SJeremy L. Thompson @ref Backend 2107a982d89SJeremy L. Thompson **/ 2117a982d89SJeremy L. Thompson int CeedQFunctionGetNumArgs(CeedQFunction qf, CeedInt *numinput, 2127a982d89SJeremy L. Thompson CeedInt *numoutput) { 2137a982d89SJeremy L. Thompson if (numinput) *numinput = qf->numinputfields; 2147a982d89SJeremy L. Thompson if (numoutput) *numoutput = qf->numoutputfields; 2157a982d89SJeremy L. Thompson return 0; 2167a982d89SJeremy L. Thompson } 2177a982d89SJeremy L. Thompson 2187a982d89SJeremy L. Thompson /** 2197a982d89SJeremy L. Thompson @brief Get the source path string for a CeedQFunction 2207a982d89SJeremy L. Thompson 2217a982d89SJeremy L. Thompson @param qf CeedQFunction 2227a982d89SJeremy L. Thompson @param[out] source Variable to store source path string 2237a982d89SJeremy L. Thompson 2247a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 2257a982d89SJeremy L. Thompson 2267a982d89SJeremy L. Thompson @ref Backend 2277a982d89SJeremy L. Thompson **/ 2287a982d89SJeremy L. Thompson int CeedQFunctionGetSourcePath(CeedQFunction qf, char **source) { 2297a982d89SJeremy L. Thompson *source = (char *) qf->sourcepath; 2307a982d89SJeremy L. Thompson return 0; 2317a982d89SJeremy L. Thompson } 2327a982d89SJeremy L. Thompson 2337a982d89SJeremy L. Thompson /** 2347a982d89SJeremy L. Thompson @brief Get the User Function for a CeedQFunction 2357a982d89SJeremy L. Thompson 2367a982d89SJeremy L. Thompson @param qf CeedQFunction 2377a982d89SJeremy L. Thompson @param[out] f Variable to store user function 2387a982d89SJeremy L. Thompson 2397a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 2407a982d89SJeremy L. Thompson 2417a982d89SJeremy L. Thompson @ref Backend 2427a982d89SJeremy L. Thompson **/ 2437a982d89SJeremy L. Thompson int CeedQFunctionGetUserFunction(CeedQFunction qf, CeedQFunctionUser *f) { 2447a982d89SJeremy L. Thompson *f = qf->function; 2457a982d89SJeremy L. Thompson return 0; 2467a982d89SJeremy L. Thompson } 2477a982d89SJeremy L. Thompson 2487a982d89SJeremy L. Thompson /** 249777ff853SJeremy L Thompson @brief Get global context for a CeedQFunction. 250777ff853SJeremy L Thompson Note: For QFunctions from the Fortran interface, this 251777ff853SJeremy L Thompson function will return the Fortran context 252777ff853SJeremy L Thompson CeedQFunctionContext. 2537a982d89SJeremy L. Thompson 2547a982d89SJeremy L. Thompson @param qf CeedQFunction 255777ff853SJeremy L Thompson @param[out] ctx Variable to store CeedQFunctionContext 2567a982d89SJeremy L. Thompson 2577a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 2587a982d89SJeremy L. Thompson 2597a982d89SJeremy L. Thompson @ref Backend 2607a982d89SJeremy L. Thompson **/ 261777ff853SJeremy L Thompson int CeedQFunctionGetContext(CeedQFunction qf, CeedQFunctionContext *ctx) { 2627a982d89SJeremy L. Thompson *ctx = qf->ctx; 2637a982d89SJeremy L. Thompson return 0; 2647a982d89SJeremy L. Thompson } 2657a982d89SJeremy L. Thompson 2667a982d89SJeremy L. Thompson /** 2677a982d89SJeremy L. Thompson @brief Get true user context for a CeedQFunction 268777ff853SJeremy L Thompson Note: For all QFunctions this function will return the user 269777ff853SJeremy L Thompson CeedQFunctionContext and not interface context 270777ff853SJeremy L Thompson CeedQFunctionContext, if any such object exists. 2717a982d89SJeremy L. Thompson 2727a982d89SJeremy L. Thompson @param qf CeedQFunction 273777ff853SJeremy L Thompson @param[out] ctx Variable to store CeedQFunctionContext 2747a982d89SJeremy L. Thompson 2757a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 2767a982d89SJeremy L. Thompson @ref Backend 2777a982d89SJeremy L. Thompson **/ 278777ff853SJeremy L Thompson int CeedQFunctionGetInnerContext(CeedQFunction qf, CeedQFunctionContext *ctx) { 279777ff853SJeremy L Thompson int ierr; 2807a982d89SJeremy L. Thompson if (qf->fortranstatus) { 281777ff853SJeremy L Thompson CeedFortranContext fctx = NULL; 282777ff853SJeremy L Thompson ierr = CeedQFunctionContextGetData(qf->ctx, CEED_MEM_HOST, &fctx); 283777ff853SJeremy L Thompson CeedChk(ierr); 2847a982d89SJeremy L. Thompson *ctx = fctx->innerctx; 285777ff853SJeremy L Thompson ierr = CeedQFunctionContextRestoreData(qf->ctx, (void *)&fctx); CeedChk(ierr); 2867a982d89SJeremy L. Thompson } else { 2877a982d89SJeremy L. Thompson *ctx = qf->ctx; 2887a982d89SJeremy L. Thompson } 2897a982d89SJeremy L. Thompson 2907a982d89SJeremy L. Thompson 2917a982d89SJeremy L. Thompson return 0; 2927a982d89SJeremy L. Thompson } 2937a982d89SJeremy L. Thompson 2947a982d89SJeremy L. Thompson /** 2957a982d89SJeremy L. Thompson @brief Determine if QFunction is identity 2967a982d89SJeremy L. Thompson 2977a982d89SJeremy L. Thompson @param qf CeedQFunction 298fd364f38SJeremy L Thompson @param[out] isidentity Variable to store identity status 2997a982d89SJeremy L. Thompson 3007a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 3017a982d89SJeremy L. Thompson 3027a982d89SJeremy L. Thompson @ref Backend 3037a982d89SJeremy L. Thompson **/ 304fd364f38SJeremy L Thompson int CeedQFunctionIsIdentity(CeedQFunction qf, bool *isidentity) { 305fd364f38SJeremy L Thompson *isidentity = qf->identity; 3067a982d89SJeremy L. Thompson return 0; 3077a982d89SJeremy L. Thompson } 3087a982d89SJeremy L. Thompson 3097a982d89SJeremy L. Thompson /** 3107a982d89SJeremy L. Thompson @brief Get backend data of a CeedQFunction 3117a982d89SJeremy L. Thompson 3127a982d89SJeremy L. Thompson @param qf CeedQFunction 3137a982d89SJeremy L. Thompson @param[out] data Variable to store data 3147a982d89SJeremy L. Thompson 3157a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 3167a982d89SJeremy L. Thompson 3177a982d89SJeremy L. Thompson @ref Backend 3187a982d89SJeremy L. Thompson **/ 319777ff853SJeremy L Thompson int CeedQFunctionGetData(CeedQFunction qf, void *data) { 320777ff853SJeremy L Thompson *(void **)data = qf->data; 3217a982d89SJeremy L. Thompson return 0; 3227a982d89SJeremy L. Thompson } 3237a982d89SJeremy L. Thompson 3247a982d89SJeremy L. Thompson /** 3257a982d89SJeremy L. Thompson @brief Set backend data of a CeedQFunction 3267a982d89SJeremy L. Thompson 3277a982d89SJeremy L. Thompson @param[out] qf CeedQFunction 3287a982d89SJeremy L. Thompson @param data Data to set 3297a982d89SJeremy L. Thompson 3307a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 3317a982d89SJeremy L. Thompson 3327a982d89SJeremy L. Thompson @ref Backend 3337a982d89SJeremy L. Thompson **/ 334777ff853SJeremy L Thompson int CeedQFunctionSetData(CeedQFunction qf, void *data) { 335777ff853SJeremy L Thompson qf->data = data; 3367a982d89SJeremy L. Thompson return 0; 3377a982d89SJeremy L. Thompson } 3387a982d89SJeremy L. Thompson 3397a982d89SJeremy L. Thompson /** 3407a982d89SJeremy L. Thompson @brief Get the CeedQFunctionFields of a CeedQFunction 3417a982d89SJeremy L. Thompson 3427a982d89SJeremy L. Thompson @param qf CeedQFunction 3437a982d89SJeremy L. Thompson @param[out] inputfields Variable to store inputfields 3447a982d89SJeremy L. Thompson @param[out] outputfields Variable to store outputfields 3457a982d89SJeremy L. Thompson 3467a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 3477a982d89SJeremy L. Thompson 3487a982d89SJeremy L. Thompson @ref Backend 3497a982d89SJeremy L. Thompson **/ 3507a982d89SJeremy L. Thompson int CeedQFunctionGetFields(CeedQFunction qf, CeedQFunctionField **inputfields, 3517a982d89SJeremy L. Thompson CeedQFunctionField **outputfields) { 3527a982d89SJeremy L. Thompson if (inputfields) 3537a982d89SJeremy L. Thompson *inputfields = qf->inputfields; 3547a982d89SJeremy L. Thompson if (outputfields) 3557a982d89SJeremy L. Thompson *outputfields = qf->outputfields; 3567a982d89SJeremy L. Thompson return 0; 3577a982d89SJeremy L. Thompson } 3587a982d89SJeremy L. Thompson 3597a982d89SJeremy L. Thompson /** 3607a982d89SJeremy L. Thompson @brief Get the name of a CeedQFunctionField 3617a982d89SJeremy L. Thompson 3627a982d89SJeremy L. Thompson @param qffield CeedQFunctionField 3637a982d89SJeremy L. Thompson @param[out] fieldname Variable to store the field name 3647a982d89SJeremy L. Thompson 3657a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 3667a982d89SJeremy L. Thompson 3677a982d89SJeremy L. Thompson @ref Backend 3687a982d89SJeremy L. Thompson **/ 3697a982d89SJeremy L. Thompson int CeedQFunctionFieldGetName(CeedQFunctionField qffield, char **fieldname) { 3707a982d89SJeremy L. Thompson *fieldname = (char *)qffield->fieldname; 3717a982d89SJeremy L. Thompson return 0; 3727a982d89SJeremy L. Thompson } 3737a982d89SJeremy L. Thompson 3747a982d89SJeremy L. Thompson /** 3757a982d89SJeremy L. Thompson @brief Get the number of components of a CeedQFunctionField 3767a982d89SJeremy L. Thompson 3777a982d89SJeremy L. Thompson @param qffield CeedQFunctionField 3787a982d89SJeremy L. Thompson @param[out] size Variable to store the size of the field 3797a982d89SJeremy L. Thompson 3807a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 3817a982d89SJeremy L. Thompson 3827a982d89SJeremy L. Thompson @ref Backend 3837a982d89SJeremy L. Thompson **/ 3847a982d89SJeremy L. Thompson int CeedQFunctionFieldGetSize(CeedQFunctionField qffield, CeedInt *size) { 3857a982d89SJeremy L. Thompson *size = qffield->size; 3867a982d89SJeremy L. Thompson return 0; 3877a982d89SJeremy L. Thompson } 3887a982d89SJeremy L. Thompson 3897a982d89SJeremy L. Thompson /** 3907a982d89SJeremy L. Thompson @brief Get the CeedEvalMode of a CeedQFunctionField 3917a982d89SJeremy L. Thompson 3927a982d89SJeremy L. Thompson @param qffield CeedQFunctionField 3937a982d89SJeremy L. Thompson @param[out] emode Variable to store the field evaluation mode 3947a982d89SJeremy L. Thompson 3957a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 3967a982d89SJeremy L. Thompson 3977a982d89SJeremy L. Thompson @ref Backend 3987a982d89SJeremy L. Thompson **/ 3997a982d89SJeremy L. Thompson int CeedQFunctionFieldGetEvalMode(CeedQFunctionField qffield, 4007a982d89SJeremy L. Thompson CeedEvalMode *emode) { 4017a982d89SJeremy L. Thompson *emode = qffield->emode; 4027a982d89SJeremy L. Thompson return 0; 4037a982d89SJeremy L. Thompson } 4047a982d89SJeremy L. Thompson 4057a982d89SJeremy L. Thompson /// @} 4067a982d89SJeremy L. Thompson 4077a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 4087a982d89SJeremy L. Thompson /// CeedQFunction Public API 4097a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 4107a982d89SJeremy L. Thompson /// @addtogroup CeedQFunctionUser 4117a982d89SJeremy L. Thompson /// @{ 4127a982d89SJeremy L. Thompson 4137a982d89SJeremy L. Thompson /** 4147a982d89SJeremy L. Thompson @brief Create a CeedQFunction for evaluating interior (volumetric) terms. 4157a982d89SJeremy L. Thompson 4167a982d89SJeremy L. Thompson @param ceed A Ceed object where the CeedQFunction will be created 4177a982d89SJeremy L. Thompson @param vlength Vector length. Caller must ensure that number of quadrature 4187a982d89SJeremy L. Thompson points is a multiple of vlength. 4197a982d89SJeremy L. Thompson @param f Function pointer to evaluate action at quadrature points. 4207a982d89SJeremy L. Thompson See \ref CeedQFunctionUser. 4217a982d89SJeremy L. Thompson @param source Absolute path to source of QFunction, 422c8d5b03cSJeremy L Thompson "\abs_path\file.h:function_name". 423c8d5b03cSJeremy L Thompson For support across all backends, this source must only 424c8d5b03cSJeremy L Thompson contain constructs supported by C99, C++11, and CUDA. 4257a982d89SJeremy L. Thompson @param[out] qf Address of the variable where the newly created 4267a982d89SJeremy L. Thompson CeedQFunction will be stored 4277a982d89SJeremy L. Thompson 4287a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 4297a982d89SJeremy L. Thompson 4307a982d89SJeremy L. Thompson See \ref CeedQFunctionUser for details on the call-back function @a f's 4317a982d89SJeremy L. Thompson arguments. 4327a982d89SJeremy L. Thompson 4337a982d89SJeremy L. Thompson @ref User 4347a982d89SJeremy L. Thompson **/ 4357a982d89SJeremy L. Thompson int CeedQFunctionCreateInterior(Ceed ceed, CeedInt vlength, CeedQFunctionUser f, 4367a982d89SJeremy L. Thompson const char *source, CeedQFunction *qf) { 4377a982d89SJeremy L. Thompson int ierr; 4387a982d89SJeremy L. Thompson char *source_copy; 4397a982d89SJeremy L. Thompson 4407a982d89SJeremy L. Thompson if (!ceed->QFunctionCreate) { 4417a982d89SJeremy L. Thompson Ceed delegate; 4427a982d89SJeremy L. Thompson ierr = CeedGetObjectDelegate(ceed, &delegate, "QFunction"); CeedChk(ierr); 4437a982d89SJeremy L. Thompson 4447a982d89SJeremy L. Thompson if (!delegate) 4457a982d89SJeremy L. Thompson // LCOV_EXCL_START 4467a982d89SJeremy L. Thompson return CeedError(ceed, 1, "Backend does not support QFunctionCreate"); 4477a982d89SJeremy L. Thompson // LCOV_EXCL_STOP 4487a982d89SJeremy L. Thompson 4497a982d89SJeremy L. Thompson ierr = CeedQFunctionCreateInterior(delegate, vlength, f, source, qf); 4507a982d89SJeremy L. Thompson CeedChk(ierr); 4517a982d89SJeremy L. Thompson return 0; 4527a982d89SJeremy L. Thompson } 4537a982d89SJeremy L. Thompson 4547a982d89SJeremy L. Thompson ierr = CeedCalloc(1, qf); CeedChk(ierr); 4557a982d89SJeremy L. Thompson (*qf)->ceed = ceed; 4567a982d89SJeremy L. Thompson ceed->refcount++; 4577a982d89SJeremy L. Thompson (*qf)->refcount = 1; 4587a982d89SJeremy L. Thompson (*qf)->vlength = vlength; 4597a982d89SJeremy L. Thompson (*qf)->identity = 0; 4607a982d89SJeremy L. Thompson (*qf)->function = f; 4617a982d89SJeremy L. Thompson size_t slen = strlen(source) + 1; 4627a982d89SJeremy L. Thompson ierr = CeedMalloc(slen, &source_copy); CeedChk(ierr); 4637a982d89SJeremy L. Thompson memcpy(source_copy, source, slen); 4647a982d89SJeremy L. Thompson (*qf)->sourcepath = source_copy; 4657a982d89SJeremy L. Thompson ierr = CeedCalloc(16, &(*qf)->inputfields); CeedChk(ierr); 4667a982d89SJeremy L. Thompson ierr = CeedCalloc(16, &(*qf)->outputfields); CeedChk(ierr); 4677a982d89SJeremy L. Thompson ierr = ceed->QFunctionCreate(*qf); CeedChk(ierr); 4687a982d89SJeremy L. Thompson return 0; 4697a982d89SJeremy L. Thompson } 4707a982d89SJeremy L. Thompson 4717a982d89SJeremy L. Thompson /** 472288c0443SJeremy L Thompson @brief Create a CeedQFunction for evaluating interior (volumetric) terms by name. 473288c0443SJeremy L Thompson 474288c0443SJeremy L Thompson @param ceed A Ceed object where the CeedQFunction will be created 475288c0443SJeremy L Thompson @param name Name of QFunction to use from gallery 476288c0443SJeremy L Thompson @param[out] qf Address of the variable where the newly created 477288c0443SJeremy L Thompson CeedQFunction will be stored 478288c0443SJeremy L Thompson 479288c0443SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 480288c0443SJeremy L Thompson 4817a982d89SJeremy L. Thompson @ref User 482288c0443SJeremy L Thompson **/ 483288c0443SJeremy L Thompson int CeedQFunctionCreateInteriorByName(Ceed ceed, const char *name, 484288c0443SJeremy L Thompson CeedQFunction *qf) { 485288c0443SJeremy L Thompson int ierr; 486288c0443SJeremy L Thompson size_t matchlen = 0, matchidx = UINT_MAX; 48775affc3bSjeremylt char *name_copy; 488288c0443SJeremy L Thompson 489288c0443SJeremy L Thompson // Find matching backend 490*278f913bSWill Pazner if (!name) return CeedError(ceed, 1, "No QFunction name provided"); 491288c0443SJeremy L Thompson for (size_t i=0; i<num_qfunctions; i++) { 492288c0443SJeremy L Thompson size_t n; 493288c0443SJeremy L Thompson const char *currname = qfunctions[i].name; 494288c0443SJeremy L Thompson for (n = 0; currname[n] && currname[n] == name[n]; n++) {} 495288c0443SJeremy L Thompson if (n > matchlen) { 496288c0443SJeremy L Thompson matchlen = n; 497288c0443SJeremy L Thompson matchidx = i; 498288c0443SJeremy L Thompson } 499288c0443SJeremy L Thompson } 5001d102b48SJeremy L Thompson if (!matchlen) 501138d4072Sjeremylt // LCOV_EXCL_START 502*278f913bSWill Pazner return CeedError(ceed, 1, "No suitable gallery QFunction"); 503138d4072Sjeremylt // LCOV_EXCL_STOP 504288c0443SJeremy L Thompson 505288c0443SJeremy L Thompson // Create QFunction 506288c0443SJeremy L Thompson ierr = CeedQFunctionCreateInterior(ceed, qfunctions[matchidx].vlength, 507288c0443SJeremy L Thompson qfunctions[matchidx].f, 508288c0443SJeremy L Thompson qfunctions[matchidx].source, qf); 509288c0443SJeremy L Thompson CeedChk(ierr); 510288c0443SJeremy L Thompson 511288c0443SJeremy L Thompson // QFunction specific setup 512288c0443SJeremy L Thompson ierr = qfunctions[matchidx].init(ceed, name, *qf); CeedChk(ierr); 513288c0443SJeremy L Thompson 51475affc3bSjeremylt // Copy name 51575affc3bSjeremylt size_t slen = strlen(name) + 1; 51675affc3bSjeremylt ierr = CeedMalloc(slen, &name_copy); CeedChk(ierr); 51775affc3bSjeremylt memcpy(name_copy, name, slen); 51875affc3bSjeremylt (*qf)->qfname = name_copy; 51975affc3bSjeremylt 520288c0443SJeremy L Thompson return 0; 521288c0443SJeremy L Thompson } 522288c0443SJeremy L Thompson 523288c0443SJeremy L Thompson /** 5240219ea01SJeremy L Thompson @brief Create an identity CeedQFunction. Inputs are written into outputs in 5250219ea01SJeremy L Thompson the order given. This is useful for CeedOperators that can be 5260219ea01SJeremy L Thompson represented with only the action of a CeedRestriction and CeedBasis, 5270219ea01SJeremy L Thompson such as restriction and prolongation operators for p-multigrid. 5280219ea01SJeremy L Thompson Backends may optimize CeedOperators with this CeedQFunction to avoid 5290219ea01SJeremy L Thompson the copy of input data to output fields by using the same memory 5300219ea01SJeremy L Thompson location for both. 5310219ea01SJeremy L Thompson 5320219ea01SJeremy L Thompson @param ceed A Ceed object where the CeedQFunction will be created 53360f77c51Sjeremylt @param[in] size Size of the qfunction fields 53460f77c51Sjeremylt @param[in] inmode CeedEvalMode for input to CeedQFunction 53560f77c51Sjeremylt @param[in] outmode CeedEvalMode for output to CeedQFunction 5360219ea01SJeremy L Thompson @param[out] qf Address of the variable where the newly created 5370219ea01SJeremy L Thompson CeedQFunction will be stored 5380219ea01SJeremy L Thompson 5390219ea01SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 5400219ea01SJeremy L Thompson 5417a982d89SJeremy L. Thompson @ref User 5420219ea01SJeremy L Thompson **/ 54360f77c51Sjeremylt int CeedQFunctionCreateIdentity(Ceed ceed, CeedInt size, CeedEvalMode inmode, 54460f77c51Sjeremylt CeedEvalMode outmode, CeedQFunction *qf) { 5450219ea01SJeremy L Thompson int ierr; 5460219ea01SJeremy L Thompson 54760f77c51Sjeremylt if (inmode == CEED_EVAL_NONE && outmode == CEED_EVAL_NONE) 54860f77c51Sjeremylt // LCOV_EXCL_START 54960f77c51Sjeremylt return CeedError(ceed, 1, "CEED_EVAL_NONE for a both the input and " 55060f77c51Sjeremylt "output does not make sense with an identity QFunction"); 55160f77c51Sjeremylt // LCOV_EXCL_STOP 55260f77c51Sjeremylt 5530219ea01SJeremy L Thompson ierr = CeedQFunctionCreateInteriorByName(ceed, "Identity", qf); CeedChk(ierr); 5541dfeea39SJeremy L Thompson ierr = CeedQFunctionAddInput(*qf, "input", size, inmode); CeedChk(ierr); 5551dfeea39SJeremy L Thompson ierr = CeedQFunctionAddOutput(*qf, "output", size, outmode); CeedChk(ierr); 5560219ea01SJeremy L Thompson 5570219ea01SJeremy L Thompson (*qf)->identity = 1; 558777ff853SJeremy L Thompson CeedInt *sizeData; 559777ff853SJeremy L Thompson ierr = CeedCalloc(1, &sizeData); CeedChk(ierr); 560777ff853SJeremy L Thompson sizeData[0] = size; 561777ff853SJeremy L Thompson CeedQFunctionContext ctx; 562777ff853SJeremy L Thompson ierr = CeedQFunctionContextCreate(ceed, &ctx); CeedChk(ierr); 563777ff853SJeremy L Thompson ierr = CeedQFunctionContextSetData(ctx, CEED_MEM_HOST, CEED_OWN_POINTER, 564777ff853SJeremy L Thompson sizeof(*sizeData), (void *)sizeData); 565777ff853SJeremy L Thompson CeedChk(ierr); 566777ff853SJeremy L Thompson ierr = CeedQFunctionSetContext(*qf, ctx); CeedChk(ierr); 567777ff853SJeremy L Thompson ierr = CeedQFunctionContextDestroy(&ctx); CeedChk(ierr); 5680219ea01SJeremy L Thompson 5690219ea01SJeremy L Thompson return 0; 5700219ea01SJeremy L Thompson } 5710219ea01SJeremy L Thompson 5720219ea01SJeremy L Thompson /** 573a0a97fcfSJed Brown @brief Add a CeedQFunction input 574b11c1e72Sjeremylt 575b11c1e72Sjeremylt @param qf CeedQFunction 576b11c1e72Sjeremylt @param fieldname Name of QFunction field 5774cc79fe7SJed Brown @param size Size of QFunction field, (ncomp * dim) for @ref CEED_EVAL_GRAD or 5784cc79fe7SJed Brown (ncomp * 1) for @ref CEED_EVAL_NONE and @ref CEED_EVAL_INTERP 579b11c1e72Sjeremylt @param emode \ref CEED_EVAL_NONE to use values directly, 580b11c1e72Sjeremylt \ref CEED_EVAL_INTERP to use interpolated values, 581b11c1e72Sjeremylt \ref CEED_EVAL_GRAD to use gradients. 582b11c1e72Sjeremylt 583b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 584dfdf5a53Sjeremylt 5857a982d89SJeremy L. Thompson @ref User 586b11c1e72Sjeremylt **/ 5871d102b48SJeremy L Thompson int CeedQFunctionAddInput(CeedQFunction qf, const char *fieldname, CeedInt size, 5881d102b48SJeremy L Thompson CeedEvalMode emode) { 589fe2413ffSjeremylt int ierr = CeedQFunctionFieldSet(&qf->inputfields[qf->numinputfields], 5904d537eeaSYohann fieldname, size, emode); 591fe2413ffSjeremylt CeedChk(ierr); 592fe2413ffSjeremylt qf->numinputfields++; 593d7b241e6Sjeremylt return 0; 594d7b241e6Sjeremylt } 595d7b241e6Sjeremylt 596b11c1e72Sjeremylt /** 597a0a97fcfSJed Brown @brief Add a CeedQFunction output 598b11c1e72Sjeremylt 599b11c1e72Sjeremylt @param qf CeedQFunction 600b11c1e72Sjeremylt @param fieldname Name of QFunction field 6014cc79fe7SJed Brown @param size Size of QFunction field, (ncomp * dim) for @ref CEED_EVAL_GRAD or 6024cc79fe7SJed Brown (ncomp * 1) for @ref CEED_EVAL_NONE and @ref CEED_EVAL_INTERP 603b11c1e72Sjeremylt @param emode \ref CEED_EVAL_NONE to use values directly, 604b11c1e72Sjeremylt \ref CEED_EVAL_INTERP to use interpolated values, 605b11c1e72Sjeremylt \ref CEED_EVAL_GRAD to use gradients. 606b11c1e72Sjeremylt 607b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 608dfdf5a53Sjeremylt 6097a982d89SJeremy L. Thompson @ref User 610b11c1e72Sjeremylt **/ 611d7b241e6Sjeremylt int CeedQFunctionAddOutput(CeedQFunction qf, const char *fieldname, 6124d537eeaSYohann CeedInt size, CeedEvalMode emode) { 613d7b241e6Sjeremylt if (emode == CEED_EVAL_WEIGHT) 614c042f62fSJeremy L Thompson // LCOV_EXCL_START 6151d102b48SJeremy L Thompson return CeedError(qf->ceed, 1, "Cannot create QFunction output with " 6161d102b48SJeremy L Thompson "CEED_EVAL_WEIGHT"); 617c042f62fSJeremy L Thompson // LCOV_EXCL_STOP 618fe2413ffSjeremylt int ierr = CeedQFunctionFieldSet(&qf->outputfields[qf->numoutputfields], 6194d537eeaSYohann fieldname, size, emode); 620fe2413ffSjeremylt CeedChk(ierr); 621fe2413ffSjeremylt qf->numoutputfields++; 622d7b241e6Sjeremylt return 0; 623d7b241e6Sjeremylt } 624d7b241e6Sjeremylt 625dfdf5a53Sjeremylt /** 6264ce2993fSjeremylt @brief Set global context for a CeedQFunction 627b11c1e72Sjeremylt 628b11c1e72Sjeremylt @param qf CeedQFunction 629b11c1e72Sjeremylt @param ctx Context data to set 630b11c1e72Sjeremylt 631b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 632dfdf5a53Sjeremylt 6337a982d89SJeremy L. Thompson @ref User 634b11c1e72Sjeremylt **/ 635777ff853SJeremy L Thompson int CeedQFunctionSetContext(CeedQFunction qf, CeedQFunctionContext ctx) { 636d7b241e6Sjeremylt qf->ctx = ctx; 637777ff853SJeremy L Thompson ctx->refcount++; 638d7b241e6Sjeremylt return 0; 639d7b241e6Sjeremylt } 640d7b241e6Sjeremylt 641b11c1e72Sjeremylt /** 64275affc3bSjeremylt @brief View a CeedQFunction 64375affc3bSjeremylt 64475affc3bSjeremylt @param[in] qf CeedQFunction to view 64575affc3bSjeremylt @param[in] stream Stream to write; typically stdout/stderr or a file 64675affc3bSjeremylt 64775affc3bSjeremylt @return Error code: 0 - success, otherwise - failure 64875affc3bSjeremylt 6497a982d89SJeremy L. Thompson @ref User 65075affc3bSjeremylt **/ 65175affc3bSjeremylt int CeedQFunctionView(CeedQFunction qf, FILE *stream) { 65275affc3bSjeremylt int ierr; 65375affc3bSjeremylt 65475affc3bSjeremylt fprintf(stream, "%sCeedQFunction %s\n", 65575affc3bSjeremylt qf->qfname ? "Gallery " : "User ", qf->qfname ? qf->qfname : ""); 65675affc3bSjeremylt 6572da88da5Sjeremylt fprintf(stream, " %d Input Field%s:\n", qf->numinputfields, 65875affc3bSjeremylt qf->numinputfields>1 ? "s" : ""); 65975affc3bSjeremylt for (CeedInt i=0; i<qf->numinputfields; i++) { 6602da88da5Sjeremylt ierr = CeedQFunctionFieldView(qf->inputfields[i], i, 1, stream); 6612da88da5Sjeremylt CeedChk(ierr); 66275affc3bSjeremylt } 66375affc3bSjeremylt 6642da88da5Sjeremylt fprintf(stream, " %d Output Field%s:\n", qf->numoutputfields, 66575affc3bSjeremylt qf->numoutputfields>1 ? "s" : ""); 66675affc3bSjeremylt for (CeedInt i=0; i<qf->numoutputfields; i++) { 6672da88da5Sjeremylt ierr = CeedQFunctionFieldView(qf->outputfields[i], i, 0, stream); 66875affc3bSjeremylt CeedChk(ierr); 66975affc3bSjeremylt } 67075affc3bSjeremylt return 0; 67175affc3bSjeremylt } 67275affc3bSjeremylt 67375affc3bSjeremylt /** 674b11c1e72Sjeremylt @brief Apply the action of a CeedQFunction 675b11c1e72Sjeremylt 676b11c1e72Sjeremylt @param qf CeedQFunction 677b11c1e72Sjeremylt @param Q Number of quadrature points 67834138859Sjeremylt @param[in] u Array of input CeedVectors 67934138859Sjeremylt @param[out] v Array of output CeedVectors 680b11c1e72Sjeremylt 681b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 682dfdf5a53Sjeremylt 6837a982d89SJeremy L. Thompson @ref User 684b11c1e72Sjeremylt **/ 685d7b241e6Sjeremylt int CeedQFunctionApply(CeedQFunction qf, CeedInt Q, 686aedaa0e5Sjeremylt CeedVector *u, CeedVector *v) { 687d7b241e6Sjeremylt int ierr; 688d7b241e6Sjeremylt if (!qf->Apply) 689c042f62fSJeremy L Thompson // LCOV_EXCL_START 690d7b241e6Sjeremylt return CeedError(qf->ceed, 1, "Backend does not support QFunctionApply"); 691c042f62fSJeremy L Thompson // LCOV_EXCL_STOP 692d7b241e6Sjeremylt if (Q % qf->vlength) 693c042f62fSJeremy L Thompson // LCOV_EXCL_START 6941d102b48SJeremy L Thompson return CeedError(qf->ceed, 2, "Number of quadrature points %d must be a " 6951d102b48SJeremy L Thompson "multiple of %d", Q, qf->vlength); 696c042f62fSJeremy L Thompson // LCOV_EXCL_STOP 697d7b241e6Sjeremylt ierr = qf->Apply(qf, Q, u, v); CeedChk(ierr); 698d7b241e6Sjeremylt return 0; 699d7b241e6Sjeremylt } 700d7b241e6Sjeremylt 701b11c1e72Sjeremylt /** 702b11c1e72Sjeremylt @brief Destroy a CeedQFunction 703b11c1e72Sjeremylt 704b11c1e72Sjeremylt @param qf CeedQFunction to destroy 705b11c1e72Sjeremylt 706b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 707dfdf5a53Sjeremylt 7087a982d89SJeremy L. Thompson @ref User 709b11c1e72Sjeremylt **/ 710d7b241e6Sjeremylt int CeedQFunctionDestroy(CeedQFunction *qf) { 711d7b241e6Sjeremylt int ierr; 712d7b241e6Sjeremylt 713752c3701SJeremy L Thompson if (!*qf || --(*qf)->refcount > 0) return 0; 714fe2413ffSjeremylt // Backend destroy 715d7b241e6Sjeremylt if ((*qf)->Destroy) { 716d7b241e6Sjeremylt ierr = (*qf)->Destroy(*qf); CeedChk(ierr); 717d7b241e6Sjeremylt } 718fe2413ffSjeremylt // Free fields 719fe2413ffSjeremylt for (int i=0; i<(*qf)->numinputfields; i++) { 720fe2413ffSjeremylt ierr = CeedFree(&(*(*qf)->inputfields[i]).fieldname); CeedChk(ierr); 721fe2413ffSjeremylt ierr = CeedFree(&(*qf)->inputfields[i]); CeedChk(ierr); 722fe2413ffSjeremylt } 723fe2413ffSjeremylt for (int i=0; i<(*qf)->numoutputfields; i++) { 724fe2413ffSjeremylt ierr = CeedFree(&(*(*qf)->outputfields[i]).fieldname); CeedChk(ierr); 725fe2413ffSjeremylt ierr = CeedFree(&(*qf)->outputfields[i]); CeedChk(ierr); 726fe2413ffSjeremylt } 727fe2413ffSjeremylt ierr = CeedFree(&(*qf)->inputfields); CeedChk(ierr); 728fe2413ffSjeremylt ierr = CeedFree(&(*qf)->outputfields); CeedChk(ierr); 729777ff853SJeremy L Thompson 730777ff853SJeremy L Thompson // User context data object 731777ff853SJeremy L Thompson ierr = CeedQFunctionContextDestroy(&(*qf)->ctx); CeedChk(ierr); 732fe2413ffSjeremylt 733288c0443SJeremy L Thompson ierr = CeedFree(&(*qf)->sourcepath); CeedChk(ierr); 73475affc3bSjeremylt ierr = CeedFree(&(*qf)->qfname); CeedChk(ierr); 735d7b241e6Sjeremylt ierr = CeedDestroy(&(*qf)->ceed); CeedChk(ierr); 736d7b241e6Sjeremylt ierr = CeedFree(qf); CeedChk(ierr); 737d7b241e6Sjeremylt return 0; 738d7b241e6Sjeremylt } 739d7b241e6Sjeremylt 740d7b241e6Sjeremylt /// @} 741