13d8e8822SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. 23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3d7b241e6Sjeremylt // 43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause 5d7b241e6Sjeremylt // 63d8e8822SJeremy L Thompson // This file is part of CEED: http://github.com/ceed 7d7b241e6Sjeremylt 83d576824SJeremy L Thompson #include <ceed-impl.h> 92b730f8bSJeremy L Thompson #include <ceed/backend.h> 102b730f8bSJeremy L Thompson #include <ceed/ceed.h> 112b730f8bSJeremy L Thompson #include <ceed/jit-tools.h> 12288c0443SJeremy L Thompson #include <limits.h> 133d576824SJeremy L Thompson #include <stdbool.h> 143d576824SJeremy L Thompson #include <stdio.h> 1543e1b16fSJeremy L Thompson #include <stdlib.h> 163d576824SJeremy L Thompson #include <string.h> 17288c0443SJeremy L Thompson 187a982d89SJeremy L. Thompson /// @file 197a982d89SJeremy L. Thompson /// Implementation of public CeedQFunction interfaces 207a982d89SJeremy L. Thompson 21288c0443SJeremy L Thompson /// @cond DOXYGEN_SKIP 22442e7f0bSjeremylt static struct CeedQFunction_private ceed_qfunction_none; 23442e7f0bSjeremylt /// @endcond 24442e7f0bSjeremylt 257a982d89SJeremy L. Thompson /// @addtogroup CeedQFunctionUser 267a982d89SJeremy L. Thompson /// @{ 277a982d89SJeremy L. Thompson 287a982d89SJeremy L. Thompson // Indicate that no QFunction is provided by the user 297a982d89SJeremy L. Thompson const CeedQFunction CEED_QFUNCTION_NONE = &ceed_qfunction_none; 307a982d89SJeremy L. Thompson 317a982d89SJeremy L. Thompson /// @} 327a982d89SJeremy L. Thompson 33442e7f0bSjeremylt /// @cond DOXYGEN_SKIP 34288c0443SJeremy L Thompson static struct { 35288c0443SJeremy L Thompson char name[CEED_MAX_RESOURCE_LEN]; 36288c0443SJeremy L Thompson char source[CEED_MAX_RESOURCE_LEN]; 37d1d35e2fSjeremylt CeedInt vec_length; 38288c0443SJeremy L Thompson CeedQFunctionUser f; 39288c0443SJeremy L Thompson int (*init)(Ceed ceed, const char *name, CeedQFunction qf); 40d1d35e2fSjeremylt } gallery_qfunctions[1024]; 41288c0443SJeremy L Thompson static size_t num_qfunctions; 42288c0443SJeremy L Thompson /// @endcond 43d7b241e6Sjeremylt 44777ff853SJeremy L Thompson /// ---------------------------------------------------------------------------- 45777ff853SJeremy L Thompson /// CeedQFunction Library Internal Functions 46777ff853SJeremy L Thompson /// ---------------------------------------------------------------------------- 47777ff853SJeremy L Thompson /// @addtogroup CeedQFunctionDeveloper 48777ff853SJeremy L Thompson /// @{ 49777ff853SJeremy L Thompson 50b11c1e72Sjeremylt /** 51288c0443SJeremy L Thompson @brief Register a gallery QFunction 52288c0443SJeremy L Thompson 53*ea61e9acSJeremy L Thompson @param[in] name Name for this backend to respond to 54*ea61e9acSJeremy L Thompson @param[in] source Absolute path to source of QFunction, "\path\CEED_DIR\gallery\folder\file.h:function_name" 55*ea61e9acSJeremy L Thompson @param[in] vec_length Vector length. Caller must ensure that number of quadrature points is a multiple of vec_length. 56*ea61e9acSJeremy L Thompson @param[in] f Function pointer to evaluate action at quadrature points. 57288c0443SJeremy L Thompson See \ref CeedQFunctionUser. 58*ea61e9acSJeremy L Thompson @param[in] init Initialization function called by CeedQFunctionInit() when the QFunction is selected. 59288c0443SJeremy L Thompson 60288c0443SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 61288c0443SJeremy L Thompson 627a982d89SJeremy L. Thompson @ref Developer 63288c0443SJeremy L Thompson **/ 642b730f8bSJeremy L Thompson int CeedQFunctionRegister(const char *name, const char *source, CeedInt vec_length, CeedQFunctionUser f, 65288c0443SJeremy L Thompson int (*init)(Ceed, const char *, CeedQFunction)) { 662b730f8bSJeremy L Thompson if (num_qfunctions >= sizeof(gallery_qfunctions) / sizeof(gallery_qfunctions[0])) { 67c042f62fSJeremy L Thompson // LCOV_EXCL_START 68e15f9bd0SJeremy L Thompson return CeedError(NULL, CEED_ERROR_MAJOR, "Too many gallery QFunctions"); 69c042f62fSJeremy L Thompson // LCOV_EXCL_STOP 702b730f8bSJeremy L Thompson } 71c042f62fSJeremy L Thompson 728ccf1006SJeremy L Thompson CeedDebugEnv("Gallery Register: %s", name); 738ccf1006SJeremy L Thompson 746eb0d8b4SJeremy L Thompson const char *relative_file_path; 752b730f8bSJeremy L Thompson CeedCall(CeedGetJitRelativePath(source, &relative_file_path)); 766eb0d8b4SJeremy L Thompson 77d1d35e2fSjeremylt strncpy(gallery_qfunctions[num_qfunctions].name, name, CEED_MAX_RESOURCE_LEN); 78d1d35e2fSjeremylt gallery_qfunctions[num_qfunctions].name[CEED_MAX_RESOURCE_LEN - 1] = 0; 792b730f8bSJeremy L Thompson strncpy(gallery_qfunctions[num_qfunctions].source, relative_file_path, CEED_MAX_RESOURCE_LEN); 80d1d35e2fSjeremylt gallery_qfunctions[num_qfunctions].source[CEED_MAX_RESOURCE_LEN - 1] = 0; 81d1d35e2fSjeremylt gallery_qfunctions[num_qfunctions].vec_length = vec_length; 82d1d35e2fSjeremylt gallery_qfunctions[num_qfunctions].f = f; 83d1d35e2fSjeremylt gallery_qfunctions[num_qfunctions].init = init; 84288c0443SJeremy L Thompson num_qfunctions++; 85e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 86288c0443SJeremy L Thompson } 87288c0443SJeremy L Thompson 88288c0443SJeremy L Thompson /** 897a982d89SJeremy L. Thompson @brief Set a CeedQFunction field, used by CeedQFunctionAddInput/Output 907a982d89SJeremy L. Thompson 91*ea61e9acSJeremy L Thompson @param[out] f CeedQFunctionField 92*ea61e9acSJeremy L Thompson @param[in] field_name Name of QFunction field 93*ea61e9acSJeremy L Thompson @param[in] size Size of QFunction field, (num_comp * dim) for @ref CEED_EVAL_GRAD or (num_comp * 1) for @ref CEED_EVAL_NONE, @ref 94*ea61e9acSJeremy L Thompson CEED_EVAL_INTERP, and @ref CEED_EVAL_WEIGHT 95*ea61e9acSJeremy L Thompson @param[in] eval_mode \ref CEED_EVAL_NONE to use values directly, 967a982d89SJeremy L. Thompson \ref CEED_EVAL_INTERP to use interpolated values, 977a982d89SJeremy L. Thompson \ref CEED_EVAL_GRAD to use gradients, 987a982d89SJeremy L. Thompson \ref CEED_EVAL_WEIGHT to use quadrature weights. 997a982d89SJeremy L. Thompson 1007a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 1017a982d89SJeremy L. Thompson 1027a982d89SJeremy L. Thompson @ref Developer 1037a982d89SJeremy L. Thompson **/ 1042b730f8bSJeremy L Thompson static int CeedQFunctionFieldSet(CeedQFunctionField *f, const char *field_name, CeedInt size, CeedEvalMode eval_mode) { 1052b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, f)); 1062b730f8bSJeremy L Thompson CeedCall(CeedStringAllocCopy(field_name, (char **)&(*f)->field_name)); 1077a982d89SJeremy L. Thompson (*f)->size = size; 108d1d35e2fSjeremylt (*f)->eval_mode = eval_mode; 109e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 1107a982d89SJeremy L. Thompson } 1117a982d89SJeremy L. Thompson 1127a982d89SJeremy L. Thompson /** 1137a982d89SJeremy L. Thompson @brief View a field of a CeedQFunction 1147a982d89SJeremy L. Thompson 1157a982d89SJeremy L. Thompson @param[in] field QFunction field to view 116d1d35e2fSjeremylt @param[in] field_number Number of field being viewed 1174c4400c7SValeria Barra @param[in] in true for input field, false for output 1187a982d89SJeremy L. Thompson @param[in] stream Stream to view to, e.g., stdout 1197a982d89SJeremy L. Thompson 1207a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 1217a982d89SJeremy L. Thompson 1227a982d89SJeremy L. Thompson @ref Utility 1237a982d89SJeremy L. Thompson **/ 1242b730f8bSJeremy L Thompson static int CeedQFunctionFieldView(CeedQFunctionField field, CeedInt field_number, bool in, FILE *stream) { 1257a982d89SJeremy L. Thompson const char *inout = in ? "Input" : "Output"; 1268229195eSjeremylt char *field_name; 1272b730f8bSJeremy L Thompson CeedCall(CeedQFunctionFieldGetName(field, &field_name)); 1288229195eSjeremylt CeedInt size; 1292b730f8bSJeremy L Thompson CeedCall(CeedQFunctionFieldGetSize(field, &size)); 1308229195eSjeremylt CeedEvalMode eval_mode; 1312b730f8bSJeremy L Thompson CeedCall(CeedQFunctionFieldGetEvalMode(field, &eval_mode)); 1322b730f8bSJeremy L Thompson fprintf(stream, 1332b730f8bSJeremy L Thompson " %s field %" CeedInt_FMT 1342b730f8bSJeremy L Thompson ":\n" 1357a982d89SJeremy L. Thompson " Name: \"%s\"\n" 1362b730f8bSJeremy L Thompson " Size: %" CeedInt_FMT 1372b730f8bSJeremy L Thompson "\n" 1387a982d89SJeremy L. Thompson " EvalMode: \"%s\"\n", 1398229195eSjeremylt inout, field_number, field_name, size, CeedEvalModes[eval_mode]); 140e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 1417a982d89SJeremy L. Thompson } 1427a982d89SJeremy L. Thompson 143777ff853SJeremy L Thompson /** 144777ff853SJeremy L Thompson @brief Set flag to determine if Fortran interface is used 145777ff853SJeremy L Thompson 146*ea61e9acSJeremy L Thompson @param[in,out] qf CeedQFunction 147*ea61e9acSJeremy L Thompson @param[in] status Boolean value to set as Fortran status 148777ff853SJeremy L Thompson 149777ff853SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 150777ff853SJeremy L Thompson 151777ff853SJeremy L Thompson @ref Backend 152777ff853SJeremy L Thompson **/ 153777ff853SJeremy L Thompson int CeedQFunctionSetFortranStatus(CeedQFunction qf, bool status) { 154f04ea552SJeremy L Thompson qf->is_fortran = status; 155e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 156777ff853SJeremy L Thompson } 157777ff853SJeremy L Thompson 1587a982d89SJeremy L. Thompson /// @} 1597a982d89SJeremy L. Thompson 1607a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 1617a982d89SJeremy L. Thompson /// CeedQFunction Backend API 1627a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 1637a982d89SJeremy L. Thompson /// @addtogroup CeedQFunctionBackend 1647a982d89SJeremy L. Thompson /// @{ 1657a982d89SJeremy L. Thompson 1667a982d89SJeremy L. Thompson /** 1677a982d89SJeremy L. Thompson @brief Get the vector length of a CeedQFunction 1687a982d89SJeremy L. Thompson 169*ea61e9acSJeremy L Thompson @param[in] qf CeedQFunction 170d1d35e2fSjeremylt @param[out] vec_length Variable to store vector length 1717a982d89SJeremy L. Thompson 1727a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 1737a982d89SJeremy L. Thompson 1747a982d89SJeremy L. Thompson @ref Backend 1757a982d89SJeremy L. Thompson **/ 176d1d35e2fSjeremylt int CeedQFunctionGetVectorLength(CeedQFunction qf, CeedInt *vec_length) { 177d1d35e2fSjeremylt *vec_length = qf->vec_length; 178e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 1797a982d89SJeremy L. Thompson } 1807a982d89SJeremy L. Thompson 1817a982d89SJeremy L. Thompson /** 1827a982d89SJeremy L. Thompson @brief Get the number of inputs and outputs to a CeedQFunction 1837a982d89SJeremy L. Thompson 184*ea61e9acSJeremy L Thompson @param[in] qf CeedQFunction 185d1d35e2fSjeremylt @param[out] num_input Variable to store number of input fields 186d1d35e2fSjeremylt @param[out] num_output Variable to store number of output fields 1877a982d89SJeremy L. Thompson 1887a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 1897a982d89SJeremy L. Thompson 1907a982d89SJeremy L. Thompson @ref Backend 1917a982d89SJeremy L. Thompson **/ 1922b730f8bSJeremy L Thompson int CeedQFunctionGetNumArgs(CeedQFunction qf, CeedInt *num_input, CeedInt *num_output) { 193d1d35e2fSjeremylt if (num_input) *num_input = qf->num_input_fields; 194d1d35e2fSjeremylt if (num_output) *num_output = qf->num_output_fields; 195e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 1967a982d89SJeremy L. Thompson } 1977a982d89SJeremy L. Thompson 1987a982d89SJeremy L. Thompson /** 19943e1b16fSJeremy L Thompson @brief Get the name of the user function for a CeedQFunction 2007a982d89SJeremy L. Thompson 201*ea61e9acSJeremy L Thompson @param[in] qf CeedQFunction 20243e1b16fSJeremy L Thompson @param[out] kernel_name Variable to store source path string 2037a982d89SJeremy L. Thompson 2047a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 2057a982d89SJeremy L. Thompson 2067a982d89SJeremy L. Thompson @ref Backend 2077a982d89SJeremy L. Thompson **/ 20843e1b16fSJeremy L Thompson int CeedQFunctionGetKernelName(CeedQFunction qf, char **kernel_name) { 209ca5eadf8SJeremy L Thompson if (!qf->kernel_name) { 210ca5eadf8SJeremy L Thompson Ceed ceed; 211ca5eadf8SJeremy L Thompson char *kernel_name_copy; 2122b730f8bSJeremy L Thompson CeedCall(CeedQFunctionGetCeed(qf, &ceed)); 213ca5eadf8SJeremy L Thompson 214ca5eadf8SJeremy L Thompson if (qf->user_source) { 215ca5eadf8SJeremy L Thompson const char *kernel_name = strrchr(qf->user_source, ':') + 1; 216ca5eadf8SJeremy L Thompson size_t kernel_name_len = strlen(kernel_name); 217ca5eadf8SJeremy L Thompson 2182b730f8bSJeremy L Thompson CeedCall(CeedCalloc(kernel_name_len + 1, &kernel_name_copy)); 219ca5eadf8SJeremy L Thompson memcpy(kernel_name_copy, kernel_name, kernel_name_len); 220ca5eadf8SJeremy L Thompson } else { 2212b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, &kernel_name_copy)); 222ca5eadf8SJeremy L Thompson } 223ca5eadf8SJeremy L Thompson qf->kernel_name = kernel_name_copy; 224ca5eadf8SJeremy L Thompson } 225ca5eadf8SJeremy L Thompson 22643e1b16fSJeremy L Thompson *kernel_name = (char *)qf->kernel_name; 22743e1b16fSJeremy L Thompson return CEED_ERROR_SUCCESS; 22843e1b16fSJeremy L Thompson } 22943e1b16fSJeremy L Thompson 23043e1b16fSJeremy L Thompson /** 23143e1b16fSJeremy L Thompson @brief Get the source path string for a CeedQFunction 23243e1b16fSJeremy L Thompson 233*ea61e9acSJeremy L Thompson @param[in] qf CeedQFunction 23443e1b16fSJeremy L Thompson @param[out] source_path Variable to store source path string 23543e1b16fSJeremy L Thompson 23643e1b16fSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 23743e1b16fSJeremy L Thompson 23843e1b16fSJeremy L Thompson @ref Backend 23943e1b16fSJeremy L Thompson **/ 24043e1b16fSJeremy L Thompson int CeedQFunctionGetSourcePath(CeedQFunction qf, char **source_path) { 241ca5eadf8SJeremy L Thompson if (!qf->source_path && qf->user_source) { 242ca5eadf8SJeremy L Thompson Ceed ceed; 243ca5eadf8SJeremy L Thompson bool is_absolute_path; 244ca5eadf8SJeremy L Thompson char *absolute_path, *source_path_copy; 245ca5eadf8SJeremy L Thompson const char *kernel_name = strrchr(qf->user_source, ':') + 1; 246ca5eadf8SJeremy L Thompson size_t kernel_name_len = strlen(kernel_name); 247ca5eadf8SJeremy L Thompson 2482b730f8bSJeremy L Thompson CeedCall(CeedQFunctionGetCeed(qf, &ceed)); 249ca5eadf8SJeremy L Thompson 2502b730f8bSJeremy L Thompson CeedCall(CeedCheckFilePath(ceed, qf->user_source, &is_absolute_path)); 251ca5eadf8SJeremy L Thompson if (is_absolute_path) { 252ca5eadf8SJeremy L Thompson absolute_path = (char *)qf->user_source; 253ca5eadf8SJeremy L Thompson } else { 2542b730f8bSJeremy L Thompson CeedCall(CeedGetJitAbsolutePath(ceed, qf->user_source, &absolute_path)); 255ca5eadf8SJeremy L Thompson } 256ca5eadf8SJeremy L Thompson 257ca5eadf8SJeremy L Thompson size_t source_len = strlen(absolute_path) - kernel_name_len - 1; 2582b730f8bSJeremy L Thompson CeedCall(CeedCalloc(source_len + 1, &source_path_copy)); 259ca5eadf8SJeremy L Thompson memcpy(source_path_copy, absolute_path, source_len); 260ca5eadf8SJeremy L Thompson qf->source_path = source_path_copy; 261ca5eadf8SJeremy L Thompson 2622b730f8bSJeremy L Thompson if (!is_absolute_path) CeedCall(CeedFree(&absolute_path)); 263ca5eadf8SJeremy L Thompson } 264ca5eadf8SJeremy L Thompson 26543e1b16fSJeremy L Thompson *source_path = (char *)qf->source_path; 266e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 2677a982d89SJeremy L. Thompson } 2687a982d89SJeremy L. Thompson 2697a982d89SJeremy L. Thompson /** 270*ea61e9acSJeremy L Thompson @brief Initialize and load QFunction source file into string buffer, including full text of local files in place of `#include "local.h"`. 2713d3250a0SJeremy L Thompson The `buffer` is set to `NULL` if there is no QFunction source file. 2723d3250a0SJeremy L Thompson Note: Caller is responsible for freeing the string buffer with `CeedFree()`. 2733d3250a0SJeremy L Thompson 274*ea61e9acSJeremy L Thompson @param[in] qf CeedQFunction 275f74ec584SJeremy L Thompson @param[out] source_buffer String buffer for source file contents 2763d3250a0SJeremy L Thompson 2773d3250a0SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 2783d3250a0SJeremy L Thompson 2793d3250a0SJeremy L Thompson @ref Backend 2803d3250a0SJeremy L Thompson **/ 2813d3250a0SJeremy L Thompson int CeedQFunctionLoadSourceToBuffer(CeedQFunction qf, char **source_buffer) { 2823d3250a0SJeremy L Thompson char *source_path; 2833d3250a0SJeremy L Thompson 2842b730f8bSJeremy L Thompson CeedCall(CeedQFunctionGetSourcePath(qf, &source_path)); 2853d3250a0SJeremy L Thompson *source_buffer = NULL; 2863d3250a0SJeremy L Thompson if (source_path) { 2872b730f8bSJeremy L Thompson CeedCall(CeedLoadSourceToBuffer(qf->ceed, source_path, source_buffer)); 2883d3250a0SJeremy L Thompson } 2893d3250a0SJeremy L Thompson 2903d3250a0SJeremy L Thompson return CEED_ERROR_SUCCESS; 2913d3250a0SJeremy L Thompson } 2923d3250a0SJeremy L Thompson 2933d3250a0SJeremy L Thompson /** 2947a982d89SJeremy L. Thompson @brief Get the User Function for a CeedQFunction 2957a982d89SJeremy L. Thompson 296*ea61e9acSJeremy L Thompson @param[in] qf CeedQFunction 2977a982d89SJeremy L. Thompson @param[out] f Variable to store user function 2987a982d89SJeremy L. Thompson 2997a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 3007a982d89SJeremy L. Thompson 3017a982d89SJeremy L. Thompson @ref Backend 3027a982d89SJeremy L. Thompson **/ 3037a982d89SJeremy L. Thompson int CeedQFunctionGetUserFunction(CeedQFunction qf, CeedQFunctionUser *f) { 3047a982d89SJeremy L. Thompson *f = qf->function; 305e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 3067a982d89SJeremy L. Thompson } 3077a982d89SJeremy L. Thompson 3087a982d89SJeremy L. Thompson /** 309777ff853SJeremy L Thompson @brief Get global context for a CeedQFunction. 310*ea61e9acSJeremy L Thompson Note: For QFunctions from the Fortran interface, this function will return the Fortran context CeedQFunctionContext. 3117a982d89SJeremy L. Thompson 312*ea61e9acSJeremy L Thompson @param[in] qf CeedQFunction 313777ff853SJeremy L Thompson @param[out] ctx Variable to store CeedQFunctionContext 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 CeedQFunctionGetContext(CeedQFunction qf, CeedQFunctionContext *ctx) { 3207a982d89SJeremy L. Thompson *ctx = qf->ctx; 321e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 3227a982d89SJeremy L. Thompson } 3237a982d89SJeremy L. Thompson 3247a982d89SJeremy L. Thompson /** 325441428dfSJeremy L Thompson @brief Get context data of a CeedQFunction 326441428dfSJeremy L Thompson 327*ea61e9acSJeremy L Thompson @param[in] qf CeedQFunction 328*ea61e9acSJeremy L Thompson @param[in] mem_type Memory type on which to access the data. 329*ea61e9acSJeremy L Thompson If the backend uses a different memory type, this will perform a copy. 330441428dfSJeremy L Thompson @param[out] data Data on memory type mem_type 331441428dfSJeremy L Thompson 332441428dfSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 333441428dfSJeremy L Thompson 334441428dfSJeremy L Thompson @ref Backend 335441428dfSJeremy L Thompson **/ 3362b730f8bSJeremy L Thompson int CeedQFunctionGetContextData(CeedQFunction qf, CeedMemType mem_type, void *data) { 337441428dfSJeremy L Thompson bool is_writable; 338441428dfSJeremy L Thompson CeedQFunctionContext ctx; 339441428dfSJeremy L Thompson 3402b730f8bSJeremy L Thompson CeedCall(CeedQFunctionGetContext(qf, &ctx)); 341441428dfSJeremy L Thompson if (ctx) { 3422b730f8bSJeremy L Thompson CeedCall(CeedQFunctionIsContextWritable(qf, &is_writable)); 343441428dfSJeremy L Thompson if (is_writable) { 3442b730f8bSJeremy L Thompson CeedCall(CeedQFunctionContextGetData(ctx, mem_type, data)); 345441428dfSJeremy L Thompson } else { 3462b730f8bSJeremy L Thompson CeedCall(CeedQFunctionContextGetDataRead(ctx, mem_type, data)); 347441428dfSJeremy L Thompson } 348441428dfSJeremy L Thompson } else { 349441428dfSJeremy L Thompson *(void **)data = NULL; 350441428dfSJeremy L Thompson } 351441428dfSJeremy L Thompson return CEED_ERROR_SUCCESS; 352441428dfSJeremy L Thompson } 353441428dfSJeremy L Thompson 354441428dfSJeremy L Thompson /** 355441428dfSJeremy L Thompson @brief Restore context data of a CeedQFunction 356441428dfSJeremy L Thompson 357*ea61e9acSJeremy L Thompson @param[in] qf CeedQFunction 358*ea61e9acSJeremy L Thompson @param[in,out] data Data to restore 359441428dfSJeremy L Thompson 360441428dfSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 361441428dfSJeremy L Thompson 362441428dfSJeremy L Thompson @ref Backend 363441428dfSJeremy L Thompson **/ 364441428dfSJeremy L Thompson int CeedQFunctionRestoreContextData(CeedQFunction qf, void *data) { 365441428dfSJeremy L Thompson bool is_writable; 366441428dfSJeremy L Thompson CeedQFunctionContext ctx; 367441428dfSJeremy L Thompson 3682b730f8bSJeremy L Thompson CeedCall(CeedQFunctionGetContext(qf, &ctx)); 369441428dfSJeremy L Thompson if (ctx) { 3702b730f8bSJeremy L Thompson CeedCall(CeedQFunctionIsContextWritable(qf, &is_writable)); 371441428dfSJeremy L Thompson if (is_writable) { 3722b730f8bSJeremy L Thompson CeedCall(CeedQFunctionContextRestoreData(ctx, data)); 373441428dfSJeremy L Thompson } else { 3742b730f8bSJeremy L Thompson CeedCall(CeedQFunctionContextRestoreDataRead(ctx, data)); 375441428dfSJeremy L Thompson } 376441428dfSJeremy L Thompson } 377441428dfSJeremy L Thompson return CEED_ERROR_SUCCESS; 378441428dfSJeremy L Thompson } 379441428dfSJeremy L Thompson 380441428dfSJeremy L Thompson /** 3817a982d89SJeremy L. Thompson @brief Get true user context for a CeedQFunction 382*ea61e9acSJeremy L Thompson Note: For all QFunctions this function will return the user CeedQFunctionContext and not interface context CeedQFunctionContext, if any 383*ea61e9acSJeremy L Thompson such object exists. 3847a982d89SJeremy L. Thompson 385*ea61e9acSJeremy L Thompson @param[in] qf CeedQFunction 386777ff853SJeremy L Thompson @param[out] ctx Variable to store CeedQFunctionContext 3877a982d89SJeremy L. Thompson 3887a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 3897a982d89SJeremy L. Thompson @ref Backend 3907a982d89SJeremy L. Thompson **/ 391777ff853SJeremy L Thompson int CeedQFunctionGetInnerContext(CeedQFunction qf, CeedQFunctionContext *ctx) { 392f04ea552SJeremy L Thompson if (qf->is_fortran) { 393d1d35e2fSjeremylt CeedFortranContext fortran_ctx = NULL; 3942b730f8bSJeremy L Thompson CeedCall(CeedQFunctionContextGetData(qf->ctx, CEED_MEM_HOST, &fortran_ctx)); 3958cb0412aSJeremy L Thompson *ctx = fortran_ctx->inner_ctx; 3962b730f8bSJeremy L Thompson CeedCall(CeedQFunctionContextRestoreData(qf->ctx, (void *)&fortran_ctx)); 3977a982d89SJeremy L. Thompson } else { 3987a982d89SJeremy L. Thompson *ctx = qf->ctx; 3997a982d89SJeremy L. Thompson } 400e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 4017a982d89SJeremy L. Thompson } 4027a982d89SJeremy L. Thompson 4037a982d89SJeremy L. Thompson /** 404441428dfSJeremy L Thompson @brief Get inner context data of a CeedQFunction 405441428dfSJeremy L Thompson 406*ea61e9acSJeremy L Thompson @param[in] qf CeedQFunction 407*ea61e9acSJeremy L Thompson @param[in] mem_type Memory type on which to access the data. 408*ea61e9acSJeremy L Thompson If the backend uses a different memory type, this will perform a copy. 409441428dfSJeremy L Thompson @param[out] data Data on memory type mem_type 410441428dfSJeremy L Thompson 411441428dfSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 412441428dfSJeremy L Thompson 413441428dfSJeremy L Thompson @ref Backend 414441428dfSJeremy L Thompson **/ 4152b730f8bSJeremy L Thompson int CeedQFunctionGetInnerContextData(CeedQFunction qf, CeedMemType mem_type, void *data) { 416441428dfSJeremy L Thompson bool is_writable; 417441428dfSJeremy L Thompson CeedQFunctionContext ctx; 418441428dfSJeremy L Thompson 4192b730f8bSJeremy L Thompson CeedCall(CeedQFunctionGetInnerContext(qf, &ctx)); 420441428dfSJeremy L Thompson if (ctx) { 4212b730f8bSJeremy L Thompson CeedCall(CeedQFunctionIsContextWritable(qf, &is_writable)); 422441428dfSJeremy L Thompson if (is_writable) { 4232b730f8bSJeremy L Thompson CeedCall(CeedQFunctionContextGetData(ctx, mem_type, data)); 424441428dfSJeremy L Thompson } else { 4252b730f8bSJeremy L Thompson CeedCall(CeedQFunctionContextGetDataRead(ctx, mem_type, data)); 426441428dfSJeremy L Thompson } 427441428dfSJeremy L Thompson } else { 428441428dfSJeremy L Thompson *(void **)data = NULL; 429441428dfSJeremy L Thompson } 430441428dfSJeremy L Thompson return CEED_ERROR_SUCCESS; 431441428dfSJeremy L Thompson } 432441428dfSJeremy L Thompson 433441428dfSJeremy L Thompson /** 434441428dfSJeremy L Thompson @brief Restore inner context data of a CeedQFunction 435441428dfSJeremy L Thompson 436*ea61e9acSJeremy L Thompson @param[in] qf CeedQFunction 437*ea61e9acSJeremy L Thompson @param[in,out] data Data to restore 438441428dfSJeremy L Thompson 439441428dfSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 440441428dfSJeremy L Thompson 441441428dfSJeremy L Thompson @ref Backend 442441428dfSJeremy L Thompson **/ 443441428dfSJeremy L Thompson int CeedQFunctionRestoreInnerContextData(CeedQFunction qf, void *data) { 444441428dfSJeremy L Thompson bool is_writable; 445441428dfSJeremy L Thompson CeedQFunctionContext ctx; 446441428dfSJeremy L Thompson 4472b730f8bSJeremy L Thompson CeedCall(CeedQFunctionGetInnerContext(qf, &ctx)); 448441428dfSJeremy L Thompson if (ctx) { 4492b730f8bSJeremy L Thompson CeedCall(CeedQFunctionIsContextWritable(qf, &is_writable)); 450441428dfSJeremy L Thompson if (is_writable) { 4512b730f8bSJeremy L Thompson CeedCall(CeedQFunctionContextRestoreData(ctx, data)); 452441428dfSJeremy L Thompson } else { 4532b730f8bSJeremy L Thompson CeedCall(CeedQFunctionContextRestoreDataRead(ctx, data)); 454441428dfSJeremy L Thompson } 455441428dfSJeremy L Thompson } 456441428dfSJeremy L Thompson return CEED_ERROR_SUCCESS; 457441428dfSJeremy L Thompson } 458441428dfSJeremy L Thompson 459441428dfSJeremy L Thompson /** 4607a982d89SJeremy L. Thompson @brief Determine if QFunction is identity 4617a982d89SJeremy L. Thompson 462*ea61e9acSJeremy L Thompson @param[in] qf CeedQFunction 463d1d35e2fSjeremylt @param[out] is_identity Variable to store identity status 4647a982d89SJeremy L. Thompson 4657a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 4667a982d89SJeremy L. Thompson 4677a982d89SJeremy L. Thompson @ref Backend 4687a982d89SJeremy L. Thompson **/ 469d1d35e2fSjeremylt int CeedQFunctionIsIdentity(CeedQFunction qf, bool *is_identity) { 470f04ea552SJeremy L Thompson *is_identity = qf->is_identity; 471e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 4727a982d89SJeremy L. Thompson } 4737a982d89SJeremy L. Thompson 4747a982d89SJeremy L. Thompson /** 475441428dfSJeremy L Thompson @brief Determine if QFunctionContext is writable 476441428dfSJeremy L Thompson 477*ea61e9acSJeremy L Thompson @param[in] qf CeedQFunction 478*ea61e9acSJeremy L Thompson @param[out] is_writable Variable to store context writeable status 479441428dfSJeremy L Thompson 480441428dfSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 481441428dfSJeremy L Thompson 482441428dfSJeremy L Thompson @ref Backend 483441428dfSJeremy L Thompson **/ 484441428dfSJeremy L Thompson int CeedQFunctionIsContextWritable(CeedQFunction qf, bool *is_writable) { 485441428dfSJeremy L Thompson *is_writable = qf->is_context_writable; 486441428dfSJeremy L Thompson return CEED_ERROR_SUCCESS; 487441428dfSJeremy L Thompson } 488441428dfSJeremy L Thompson 489441428dfSJeremy L Thompson /** 4907a982d89SJeremy L. Thompson @brief Get backend data of a CeedQFunction 4917a982d89SJeremy L. Thompson 492*ea61e9acSJeremy L Thompson @param[in] qf CeedQFunction 4937a982d89SJeremy L. Thompson @param[out] data Variable to store data 4947a982d89SJeremy L. Thompson 4957a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 4967a982d89SJeremy L. Thompson 4977a982d89SJeremy L. Thompson @ref Backend 4987a982d89SJeremy L. Thompson **/ 499777ff853SJeremy L Thompson int CeedQFunctionGetData(CeedQFunction qf, void *data) { 500777ff853SJeremy L Thompson *(void **)data = qf->data; 501e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 5027a982d89SJeremy L. Thompson } 5037a982d89SJeremy L. Thompson 5047a982d89SJeremy L. Thompson /** 5057a982d89SJeremy L. Thompson @brief Set backend data of a CeedQFunction 5067a982d89SJeremy L. Thompson 507*ea61e9acSJeremy L Thompson @param[in,out] qf CeedQFunction 508*ea61e9acSJeremy L Thompson @param[in] data Data to set 5097a982d89SJeremy L. Thompson 5107a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 5117a982d89SJeremy L. Thompson 5127a982d89SJeremy L. Thompson @ref Backend 5137a982d89SJeremy L. Thompson **/ 514777ff853SJeremy L Thompson int CeedQFunctionSetData(CeedQFunction qf, void *data) { 515777ff853SJeremy L Thompson qf->data = data; 516e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 5177a982d89SJeremy L. Thompson } 5187a982d89SJeremy L. Thompson 5197a982d89SJeremy L. Thompson /** 52034359f16Sjeremylt @brief Increment the reference counter for a CeedQFunction 52134359f16Sjeremylt 522*ea61e9acSJeremy L Thompson @param[in,out] qf CeedQFunction to increment the reference counter 52334359f16Sjeremylt 52434359f16Sjeremylt @return An error code: 0 - success, otherwise - failure 52534359f16Sjeremylt 52634359f16Sjeremylt @ref Backend 52734359f16Sjeremylt **/ 5289560d06aSjeremylt int CeedQFunctionReference(CeedQFunction qf) { 52934359f16Sjeremylt qf->ref_count++; 53034359f16Sjeremylt return CEED_ERROR_SUCCESS; 53134359f16Sjeremylt } 53234359f16Sjeremylt 5336e15d496SJeremy L Thompson /** 5346e15d496SJeremy L Thompson @brief Estimate number of FLOPs per quadrature required to apply QFunction 5356e15d496SJeremy L Thompson 536*ea61e9acSJeremy L Thompson @param[in] qf QFunction to estimate FLOPs for 537*ea61e9acSJeremy L Thompson @param[out] flops Address of variable to hold FLOPs estimate 5386e15d496SJeremy L Thompson 5396e15d496SJeremy L Thompson @ref Backend 5406e15d496SJeremy L Thompson **/ 5419d36ca50SJeremy L Thompson int CeedQFunctionGetFlopsEstimate(CeedQFunction qf, CeedSize *flops) { 5422b730f8bSJeremy L Thompson if (qf->user_flop_estimate == -1) { 5436e15d496SJeremy L Thompson // LCOV_EXCL_START 5442b730f8bSJeremy L Thompson return CeedError(qf->ceed, CEED_ERROR_INCOMPLETE, "Must set FLOPs estimate with CeedQFunctionSetUserFlopsEstimate"); 5456e15d496SJeremy L Thompson // LCOV_EXCL_STOP 5462b730f8bSJeremy L Thompson } 5476e15d496SJeremy L Thompson *flops = qf->user_flop_estimate; 5486e15d496SJeremy L Thompson return CEED_ERROR_SUCCESS; 5496e15d496SJeremy L Thompson } 5506e15d496SJeremy L Thompson 5517a982d89SJeremy L. Thompson /// @} 5527a982d89SJeremy L. Thompson 5537a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 5547a982d89SJeremy L. Thompson /// CeedQFunction Public API 5557a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 5567a982d89SJeremy L. Thompson /// @addtogroup CeedQFunctionUser 5577a982d89SJeremy L. Thompson /// @{ 5587a982d89SJeremy L. Thompson 5597a982d89SJeremy L. Thompson /** 5607a982d89SJeremy L. Thompson @brief Create a CeedQFunction for evaluating interior (volumetric) terms. 5617a982d89SJeremy L. Thompson 562*ea61e9acSJeremy L Thompson @param[in] ceed Ceed object where the CeedQFunction will be created 563*ea61e9acSJeremy L Thompson @param[in] vec_length Vector length. Caller must ensure that number of quadrature points is a multiple of vec_length. 564*ea61e9acSJeremy L Thompson @param[in] f Function pointer to evaluate action at quadrature points. 5657a982d89SJeremy L. Thompson See \ref CeedQFunctionUser. 566*ea61e9acSJeremy L Thompson @param[in] source Absolute path to source of QFunction, "\abs_path\file.h:function_name". 567*ea61e9acSJeremy L Thompson For support across all backends, this source must only contain constructs supported by C99, C++11, and CUDA. 568*ea61e9acSJeremy L Thompson @param[out] qf Address of the variable where the newly created CeedQFunction will be stored 5697a982d89SJeremy L. Thompson 5707a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 5717a982d89SJeremy L. Thompson 572*ea61e9acSJeremy L Thompson See \ref CeedQFunctionUser for details on the call-back function @a f's arguments. 5737a982d89SJeremy L. Thompson 5747a982d89SJeremy L. Thompson @ref User 5757a982d89SJeremy L. Thompson **/ 5762b730f8bSJeremy L Thompson int CeedQFunctionCreateInterior(Ceed ceed, CeedInt vec_length, CeedQFunctionUser f, const char *source, CeedQFunction *qf) { 577ca5eadf8SJeremy L Thompson char *user_source_copy; 5787a982d89SJeremy L. Thompson 5797a982d89SJeremy L. Thompson if (!ceed->QFunctionCreate) { 5807a982d89SJeremy L. Thompson Ceed delegate; 5812b730f8bSJeremy L Thompson CeedCall(CeedGetObjectDelegate(ceed, &delegate, "QFunction")); 5827a982d89SJeremy L. Thompson 5832b730f8bSJeremy L Thompson if (!delegate) { 5847a982d89SJeremy L. Thompson // LCOV_EXCL_START 5852b730f8bSJeremy L Thompson return CeedError(ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support QFunctionCreate"); 5867a982d89SJeremy L. Thompson // LCOV_EXCL_STOP 5872b730f8bSJeremy L Thompson } 5887a982d89SJeremy L. Thompson 5892b730f8bSJeremy L Thompson CeedCall(CeedQFunctionCreateInterior(delegate, vec_length, f, source, qf)); 590e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 5917a982d89SJeremy L. Thompson } 5927a982d89SJeremy L. Thompson 5932b730f8bSJeremy L Thompson if (strlen(source) && !strrchr(source, ':')) { 59443e1b16fSJeremy L Thompson // LCOV_EXCL_START 59543e1b16fSJeremy L Thompson return CeedError(ceed, CEED_ERROR_INCOMPLETE, 5962b730f8bSJeremy L Thompson "Provided path to source does not include function name. Provided: \"%s\"\nRequired: \"\\abs_path\\file.h:function_name\"", 59743e1b16fSJeremy L Thompson source); 59843e1b16fSJeremy L Thompson // LCOV_EXCL_STOP 5992b730f8bSJeremy L Thompson } 60043e1b16fSJeremy L Thompson 6012b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, qf)); 6027a982d89SJeremy L. Thompson (*qf)->ceed = ceed; 6032b730f8bSJeremy L Thompson CeedCall(CeedReference(ceed)); 604d1d35e2fSjeremylt (*qf)->ref_count = 1; 605d1d35e2fSjeremylt (*qf)->vec_length = vec_length; 606f04ea552SJeremy L Thompson (*qf)->is_identity = false; 607441428dfSJeremy L Thompson (*qf)->is_context_writable = true; 6087a982d89SJeremy L. Thompson (*qf)->function = f; 6096e15d496SJeremy L Thompson (*qf)->user_flop_estimate = -1; 61043e1b16fSJeremy L Thompson if (strlen(source)) { 611ca5eadf8SJeremy L Thompson size_t user_source_len = strlen(source); 612ee5a26f2SJeremy L Thompson 6132b730f8bSJeremy L Thompson CeedCall(CeedCalloc(user_source_len + 1, &user_source_copy)); 614ca5eadf8SJeremy L Thompson memcpy(user_source_copy, source, user_source_len); 615ca5eadf8SJeremy L Thompson (*qf)->user_source = user_source_copy; 61643e1b16fSJeremy L Thompson } 6172b730f8bSJeremy L Thompson CeedCall(CeedCalloc(CEED_FIELD_MAX, &(*qf)->input_fields)); 6182b730f8bSJeremy L Thompson CeedCall(CeedCalloc(CEED_FIELD_MAX, &(*qf)->output_fields)); 6192b730f8bSJeremy L Thompson CeedCall(ceed->QFunctionCreate(*qf)); 620e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 6217a982d89SJeremy L. Thompson } 6227a982d89SJeremy L. Thompson 6237a982d89SJeremy L. Thompson /** 624288c0443SJeremy L Thompson @brief Create a CeedQFunction for evaluating interior (volumetric) terms by name. 625288c0443SJeremy L Thompson 626*ea61e9acSJeremy L Thompson @param[in] ceed Ceed object where the CeedQFunction will be created 627*ea61e9acSJeremy L Thompson @param[in] name Name of QFunction to use from gallery 628*ea61e9acSJeremy L Thompson @param[out] qf Address of the variable where the newly created CeedQFunction will be stored 629288c0443SJeremy L Thompson 630288c0443SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 631288c0443SJeremy L Thompson 6327a982d89SJeremy L. Thompson @ref User 633288c0443SJeremy L Thompson **/ 6342b730f8bSJeremy L Thompson int CeedQFunctionCreateInteriorByName(Ceed ceed, const char *name, CeedQFunction *qf) { 635f7e22acaSJeremy L Thompson size_t match_len = 0, match_index = UINT_MAX; 636288c0443SJeremy L Thompson 6372b730f8bSJeremy L Thompson CeedCall(CeedQFunctionRegisterAll()); 638288c0443SJeremy L Thompson // Find matching backend 6392b730f8bSJeremy L Thompson if (!name) return CeedError(ceed, CEED_ERROR_INCOMPLETE, "No QFunction name provided"); 640288c0443SJeremy L Thompson for (size_t i = 0; i < num_qfunctions; i++) { 641288c0443SJeremy L Thompson size_t n; 642d1d35e2fSjeremylt const char *curr_name = gallery_qfunctions[i].name; 6432b730f8bSJeremy L Thompson for (n = 0; curr_name[n] && curr_name[n] == name[n]; n++) { 6442b730f8bSJeremy L Thompson } 645d1d35e2fSjeremylt if (n > match_len) { 646d1d35e2fSjeremylt match_len = n; 647f7e22acaSJeremy L Thompson match_index = i; 648288c0443SJeremy L Thompson } 649288c0443SJeremy L Thompson } 6502b730f8bSJeremy L Thompson if (!match_len) { 651138d4072Sjeremylt // LCOV_EXCL_START 652e15f9bd0SJeremy L Thompson return CeedError(ceed, CEED_ERROR_UNSUPPORTED, "No suitable gallery QFunction"); 653138d4072Sjeremylt // LCOV_EXCL_STOP 6542b730f8bSJeremy L Thompson } 655288c0443SJeremy L Thompson 656288c0443SJeremy L Thompson // Create QFunction 6572b730f8bSJeremy L Thompson CeedCall(CeedQFunctionCreateInterior(ceed, gallery_qfunctions[match_index].vec_length, gallery_qfunctions[match_index].f, 6582b730f8bSJeremy L Thompson gallery_qfunctions[match_index].source, qf)); 659288c0443SJeremy L Thompson 660288c0443SJeremy L Thompson // QFunction specific setup 6612b730f8bSJeremy L Thompson CeedCall(gallery_qfunctions[match_index].init(ceed, name, *qf)); 662288c0443SJeremy L Thompson 66375affc3bSjeremylt // Copy name 6642b730f8bSJeremy L Thompson CeedCall(CeedStringAllocCopy(name, (char **)&(*qf)->gallery_name)); 66543e1b16fSJeremy L Thompson (*qf)->is_gallery = true; 666e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 667288c0443SJeremy L Thompson } 668288c0443SJeremy L Thompson 669288c0443SJeremy L Thompson /** 670*ea61e9acSJeremy L Thompson @brief Create an identity CeedQFunction. 671*ea61e9acSJeremy L Thompson Inputs are written into outputs in the order given. 672*ea61e9acSJeremy L Thompson This is useful for CeedOperators that can be represented with only the action of a CeedRestriction and CeedBasis, such as restriction and 673*ea61e9acSJeremy L Thompson prolongation operators for p-multigrid. Backends may optimize CeedOperators with this CeedQFunction to avoid the copy of input data to output fields 674*ea61e9acSJeremy L Thompson by using the same memory location for both. 6750219ea01SJeremy L Thompson 676*ea61e9acSJeremy L Thompson @param[in] ceed Ceed object where the CeedQFunction will be created 677d1d35e2fSjeremylt @param[in] size Size of the QFunction fields 678d1d35e2fSjeremylt @param[in] in_mode CeedEvalMode for input to CeedQFunction 679d1d35e2fSjeremylt @param[in] out_mode CeedEvalMode for output to CeedQFunction 680*ea61e9acSJeremy L Thompson @param[out] qf Address of the variable where the newly created CeedQFunction will be stored 6810219ea01SJeremy L Thompson 6820219ea01SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 6830219ea01SJeremy L Thompson 6847a982d89SJeremy L. Thompson @ref User 6850219ea01SJeremy L Thompson **/ 6862b730f8bSJeremy L Thompson int CeedQFunctionCreateIdentity(Ceed ceed, CeedInt size, CeedEvalMode in_mode, CeedEvalMode out_mode, CeedQFunction *qf) { 6872b730f8bSJeremy L Thompson CeedCall(CeedQFunctionCreateInteriorByName(ceed, "Identity", qf)); 6882b730f8bSJeremy L Thompson CeedCall(CeedQFunctionAddInput(*qf, "input", size, in_mode)); 6892b730f8bSJeremy L Thompson CeedCall(CeedQFunctionAddOutput(*qf, "output", size, out_mode)); 6900219ea01SJeremy L Thompson 691f04ea552SJeremy L Thompson (*qf)->is_identity = true; 692547dbd6fSJeremy L Thompson 693777ff853SJeremy L Thompson CeedQFunctionContext ctx; 6943668ca4bSJeremy L Thompson CeedContextFieldLabel size_label; 6952b730f8bSJeremy L Thompson CeedCall(CeedQFunctionGetContext(*qf, &ctx)); 6962b730f8bSJeremy L Thompson CeedCall(CeedQFunctionContextGetFieldLabel(ctx, "size", &size_label)); 6972b730f8bSJeremy L Thompson CeedCall(CeedQFunctionContextSetInt32(ctx, size_label, &size)); 698547dbd6fSJeremy L Thompson 699e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 7000219ea01SJeremy L Thompson } 7010219ea01SJeremy L Thompson 7020219ea01SJeremy L Thompson /** 703*ea61e9acSJeremy L Thompson @brief Copy the pointer to a CeedQFunction. 704*ea61e9acSJeremy L Thompson Both pointers should be destroyed with `CeedQFunctionDestroy()`. 705*ea61e9acSJeremy L Thompson Note: If `*qf_copy` is non-NULL, then it is assumed that `*qf_copy` is a pointer to a CeedQFunction. 706*ea61e9acSJeremy L Thompson This CeedQFunction will be destroyed if `*qf_copy` is the only reference to this CeedQFunction. 7079560d06aSjeremylt 708*ea61e9acSJeremy L Thompson @param[in] qf CeedQFunction to copy reference to 7099560d06aSjeremylt @param[out] qf_copy Variable to store copied reference 7109560d06aSjeremylt 7119560d06aSjeremylt @return An error code: 0 - success, otherwise - failure 7129560d06aSjeremylt 7139560d06aSjeremylt @ref User 7149560d06aSjeremylt **/ 7159560d06aSjeremylt int CeedQFunctionReferenceCopy(CeedQFunction qf, CeedQFunction *qf_copy) { 7162b730f8bSJeremy L Thompson CeedCall(CeedQFunctionReference(qf)); 7172b730f8bSJeremy L Thompson CeedCall(CeedQFunctionDestroy(qf_copy)); 7189560d06aSjeremylt *qf_copy = qf; 7199560d06aSjeremylt return CEED_ERROR_SUCCESS; 7209560d06aSjeremylt } 7219560d06aSjeremylt 7229560d06aSjeremylt /** 723a0a97fcfSJed Brown @brief Add a CeedQFunction input 724b11c1e72Sjeremylt 725*ea61e9acSJeremy L Thompson @param[in,out] qf CeedQFunction 726*ea61e9acSJeremy L Thompson @param[in] field_name Name of QFunction field 727*ea61e9acSJeremy L Thompson @param[in] size Size of QFunction field, (num_comp * dim) for @ref CEED_EVAL_GRAD or (num_comp * 1) for @ref CEED_EVAL_NONE and @ref 728*ea61e9acSJeremy L Thompson CEED_EVAL_INTERP 729*ea61e9acSJeremy L Thompson @param[in] eval_mode \ref CEED_EVAL_NONE to use values directly, 730b11c1e72Sjeremylt \ref CEED_EVAL_INTERP to use interpolated values, 731b11c1e72Sjeremylt \ref CEED_EVAL_GRAD to use gradients. 732b11c1e72Sjeremylt 733b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 734dfdf5a53Sjeremylt 7357a982d89SJeremy L. Thompson @ref User 736b11c1e72Sjeremylt **/ 7372b730f8bSJeremy L Thompson int CeedQFunctionAddInput(CeedQFunction qf, const char *field_name, CeedInt size, CeedEvalMode eval_mode) { 7382b730f8bSJeremy L Thompson if (qf->is_immutable) { 739e15f9bd0SJeremy L Thompson // LCOV_EXCL_START 7402b730f8bSJeremy L Thompson return CeedError(qf->ceed, CEED_ERROR_MAJOR, "QFunction cannot be changed after set as immutable"); 741e15f9bd0SJeremy L Thompson // LCOV_EXCL_STOP 7422b730f8bSJeremy L Thompson } 7432b730f8bSJeremy L Thompson if ((eval_mode == CEED_EVAL_WEIGHT) && (size != 1)) { 744e15f9bd0SJeremy L Thompson // LCOV_EXCL_START 7452b730f8bSJeremy L Thompson return CeedError(qf->ceed, CEED_ERROR_DIMENSION, "CEED_EVAL_WEIGHT should have size 1"); 746e15f9bd0SJeremy L Thompson // LCOV_EXCL_STOP 7472b730f8bSJeremy L Thompson } 7482b730f8bSJeremy L Thompson CeedCall(CeedQFunctionFieldSet(&qf->input_fields[qf->num_input_fields], field_name, size, eval_mode)); 749d1d35e2fSjeremylt qf->num_input_fields++; 750e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 751d7b241e6Sjeremylt } 752d7b241e6Sjeremylt 753b11c1e72Sjeremylt /** 754a0a97fcfSJed Brown @brief Add a CeedQFunction output 755b11c1e72Sjeremylt 756*ea61e9acSJeremy L Thompson @param[in,out] qf CeedQFunction 757*ea61e9acSJeremy L Thompson @param[in] field_name Name of QFunction field 758*ea61e9acSJeremy L Thompson @param[in] size Size of QFunction field, (num_comp * dim) for @ref CEED_EVAL_GRAD or (num_comp * 1) for @ref CEED_EVAL_NONE and @ref 759*ea61e9acSJeremy L Thompson CEED_EVAL_INTERP 760*ea61e9acSJeremy L Thompson @param[in] eval_mode \ref CEED_EVAL_NONE to use values directly, 761b11c1e72Sjeremylt \ref CEED_EVAL_INTERP to use interpolated values, 762b11c1e72Sjeremylt \ref CEED_EVAL_GRAD to use gradients. 763b11c1e72Sjeremylt 764b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 765dfdf5a53Sjeremylt 7667a982d89SJeremy L. Thompson @ref User 767b11c1e72Sjeremylt **/ 7682b730f8bSJeremy L Thompson int CeedQFunctionAddOutput(CeedQFunction qf, const char *field_name, CeedInt size, CeedEvalMode eval_mode) { 7692b730f8bSJeremy L Thompson if (qf->is_immutable) { 770e15f9bd0SJeremy L Thompson // LCOV_EXCL_START 7712b730f8bSJeremy L Thompson return CeedError(qf->ceed, CEED_ERROR_MAJOR, "QFunction cannot be changed after set as immutable"); 772e15f9bd0SJeremy L Thompson // LCOV_EXCL_STOP 7732b730f8bSJeremy L Thompson } 7742b730f8bSJeremy L Thompson if (eval_mode == CEED_EVAL_WEIGHT) { 775c042f62fSJeremy L Thompson // LCOV_EXCL_START 7762b730f8bSJeremy L Thompson return CeedError(qf->ceed, CEED_ERROR_DIMENSION, "Cannot create QFunction output with CEED_EVAL_WEIGHT"); 777c042f62fSJeremy L Thompson // LCOV_EXCL_STOP 7782b730f8bSJeremy L Thompson } 7792b730f8bSJeremy L Thompson CeedCall(CeedQFunctionFieldSet(&qf->output_fields[qf->num_output_fields], field_name, size, eval_mode)); 780d1d35e2fSjeremylt qf->num_output_fields++; 781e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 782d7b241e6Sjeremylt } 783d7b241e6Sjeremylt 784dfdf5a53Sjeremylt /** 78543bbe138SJeremy L Thompson @brief Get the CeedQFunctionFields of a CeedQFunction 78643bbe138SJeremy L Thompson 787*ea61e9acSJeremy L Thompson Note: Calling this function asserts that setup is complete and sets the CeedQFunction as immutable. 788f04ea552SJeremy L Thompson 789*ea61e9acSJeremy L Thompson @param[in] qf CeedQFunction 790f74ec584SJeremy L Thompson @param[out] num_input_fields Variable to store number of input fields 791f74ec584SJeremy L Thompson @param[out] input_fields Variable to store input fields 792f74ec584SJeremy L Thompson @param[out] num_output_fields Variable to store number of output fields 793f74ec584SJeremy L Thompson @param[out] output_fields Variable to store output fields 79443bbe138SJeremy L Thompson 79543bbe138SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 79643bbe138SJeremy L Thompson 797e9b533fbSJeremy L Thompson @ref Advanced 79843bbe138SJeremy L Thompson **/ 7992b730f8bSJeremy L Thompson int CeedQFunctionGetFields(CeedQFunction qf, CeedInt *num_input_fields, CeedQFunctionField **input_fields, CeedInt *num_output_fields, 80043bbe138SJeremy L Thompson CeedQFunctionField **output_fields) { 801f04ea552SJeremy L Thompson qf->is_immutable = true; 80243bbe138SJeremy L Thompson if (num_input_fields) *num_input_fields = qf->num_input_fields; 80343bbe138SJeremy L Thompson if (input_fields) *input_fields = qf->input_fields; 80443bbe138SJeremy L Thompson if (num_output_fields) *num_output_fields = qf->num_output_fields; 80543bbe138SJeremy L Thompson if (output_fields) *output_fields = qf->output_fields; 80643bbe138SJeremy L Thompson return CEED_ERROR_SUCCESS; 80743bbe138SJeremy L Thompson } 80843bbe138SJeremy L Thompson 80943bbe138SJeremy L Thompson /** 81043bbe138SJeremy L Thompson @brief Get the name of a CeedQFunctionField 81143bbe138SJeremy L Thompson 812*ea61e9acSJeremy L Thompson @param[in] qf_field CeedQFunctionField 81343bbe138SJeremy L Thompson @param[out] field_name Variable to store the field name 81443bbe138SJeremy L Thompson 81543bbe138SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 81643bbe138SJeremy L Thompson 817e9b533fbSJeremy L Thompson @ref Advanced 81843bbe138SJeremy L Thompson **/ 81943bbe138SJeremy L Thompson int CeedQFunctionFieldGetName(CeedQFunctionField qf_field, char **field_name) { 82043bbe138SJeremy L Thompson *field_name = (char *)qf_field->field_name; 82143bbe138SJeremy L Thompson return CEED_ERROR_SUCCESS; 82243bbe138SJeremy L Thompson } 82343bbe138SJeremy L Thompson 82443bbe138SJeremy L Thompson /** 82543bbe138SJeremy L Thompson @brief Get the number of components of a CeedQFunctionField 82643bbe138SJeremy L Thompson 827*ea61e9acSJeremy L Thompson @param[in] qf_field CeedQFunctionField 82843bbe138SJeremy L Thompson @param[out] size Variable to store the size of the field 82943bbe138SJeremy L Thompson 83043bbe138SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 83143bbe138SJeremy L Thompson 832e9b533fbSJeremy L Thompson @ref Advanced 83343bbe138SJeremy L Thompson **/ 83443bbe138SJeremy L Thompson int CeedQFunctionFieldGetSize(CeedQFunctionField qf_field, CeedInt *size) { 83543bbe138SJeremy L Thompson *size = qf_field->size; 83643bbe138SJeremy L Thompson return CEED_ERROR_SUCCESS; 83743bbe138SJeremy L Thompson } 83843bbe138SJeremy L Thompson 83943bbe138SJeremy L Thompson /** 84043bbe138SJeremy L Thompson @brief Get the CeedEvalMode of a CeedQFunctionField 84143bbe138SJeremy L Thompson 842*ea61e9acSJeremy L Thompson @param[in] qf_field CeedQFunctionField 84343bbe138SJeremy L Thompson @param[out] eval_mode Variable to store the field evaluation mode 84443bbe138SJeremy L Thompson 84543bbe138SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 84643bbe138SJeremy L Thompson 847e9b533fbSJeremy L Thompson @ref Advanced 84843bbe138SJeremy L Thompson **/ 8492b730f8bSJeremy L Thompson int CeedQFunctionFieldGetEvalMode(CeedQFunctionField qf_field, CeedEvalMode *eval_mode) { 85043bbe138SJeremy L Thompson *eval_mode = qf_field->eval_mode; 85143bbe138SJeremy L Thompson return CEED_ERROR_SUCCESS; 85243bbe138SJeremy L Thompson } 85343bbe138SJeremy L Thompson 85443bbe138SJeremy L Thompson /** 8554ce2993fSjeremylt @brief Set global context for a CeedQFunction 856b11c1e72Sjeremylt 857*ea61e9acSJeremy L Thompson @param[in,out] qf CeedQFunction 858*ea61e9acSJeremy L Thompson @param[in] ctx Context data to set 859b11c1e72Sjeremylt 860b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 861dfdf5a53Sjeremylt 8627a982d89SJeremy L. Thompson @ref User 863b11c1e72Sjeremylt **/ 864777ff853SJeremy L Thompson int CeedQFunctionSetContext(CeedQFunction qf, CeedQFunctionContext ctx) { 8652b730f8bSJeremy L Thompson CeedCall(CeedQFunctionContextDestroy(&qf->ctx)); 866d7b241e6Sjeremylt qf->ctx = ctx; 8679e77b9c8SJeremy L Thompson if (ctx) { 8682b730f8bSJeremy L Thompson CeedCall(CeedQFunctionContextReference(ctx)); 8699e77b9c8SJeremy L Thompson } 870e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 871d7b241e6Sjeremylt } 872d7b241e6Sjeremylt 873b11c1e72Sjeremylt /** 874441428dfSJeremy L Thompson @brief Set writability of CeedQFunctionContext when calling the `CeedQFunctionUser`. 875441428dfSJeremy L Thompson The default value is 'is_writable == true'. 876441428dfSJeremy L Thompson 877*ea61e9acSJeremy L Thompson Setting `is_writable == true` indicates the `CeedQFunctionUser` writes into the CeedQFunctionContextData and requires memory syncronization 878441428dfSJeremy L Thompson after calling `CeedQFunctionApply()`. 879441428dfSJeremy L Thompson 880*ea61e9acSJeremy L Thompson Setting 'is_writable == false' asserts that `CeedQFunctionUser` does not modify the CeedQFunctionContextData. 881*ea61e9acSJeremy L Thompson Violating this assertion may lead to inconsistent data. 882441428dfSJeremy L Thompson 883441428dfSJeremy L Thompson Setting `is_writable == false` may offer a performance improvement on GPU backends. 884441428dfSJeremy L Thompson 885*ea61e9acSJeremy L Thompson @param[in,out] qf CeedQFunction 886*ea61e9acSJeremy L Thompson @param[in] is_writable Writability status 887441428dfSJeremy L Thompson 888441428dfSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 889441428dfSJeremy L Thompson 890441428dfSJeremy L Thompson @ref User 891441428dfSJeremy L Thompson **/ 892441428dfSJeremy L Thompson int CeedQFunctionSetContextWritable(CeedQFunction qf, bool is_writable) { 893441428dfSJeremy L Thompson qf->is_context_writable = is_writable; 894441428dfSJeremy L Thompson return CEED_ERROR_SUCCESS; 895441428dfSJeremy L Thompson } 896441428dfSJeremy L Thompson 897441428dfSJeremy L Thompson /** 8986e15d496SJeremy L Thompson @brief Set estimated number of FLOPs per quadrature required to apply QFunction 8996e15d496SJeremy L Thompson 900*ea61e9acSJeremy L Thompson @param[in] qf QFunction to estimate FLOPs for 901*ea61e9acSJeremy L Thompson @param[out] flops FLOPs per quadrature point estimate 9026e15d496SJeremy L Thompson 9036e15d496SJeremy L Thompson @ref Backend 9046e15d496SJeremy L Thompson **/ 9059d36ca50SJeremy L Thompson int CeedQFunctionSetUserFlopsEstimate(CeedQFunction qf, CeedSize flops) { 9062b730f8bSJeremy L Thompson if (flops < 0) { 9076e15d496SJeremy L Thompson // LCOV_EXCL_START 9082b730f8bSJeremy L Thompson return CeedError(qf->ceed, CEED_ERROR_INCOMPATIBLE, "Must set non-negative FLOPs estimate"); 9096e15d496SJeremy L Thompson // LCOV_EXCL_STOP 9102b730f8bSJeremy L Thompson } 9116e15d496SJeremy L Thompson qf->user_flop_estimate = flops; 9126e15d496SJeremy L Thompson return CEED_ERROR_SUCCESS; 9136e15d496SJeremy L Thompson } 9146e15d496SJeremy L Thompson 9156e15d496SJeremy L Thompson /** 91675affc3bSjeremylt @brief View a CeedQFunction 91775affc3bSjeremylt 91875affc3bSjeremylt @param[in] qf CeedQFunction to view 91975affc3bSjeremylt @param[in] stream Stream to write; typically stdout/stderr or a file 92075affc3bSjeremylt 92175affc3bSjeremylt @return Error code: 0 - success, otherwise - failure 92275affc3bSjeremylt 9237a982d89SJeremy L. Thompson @ref User 92475affc3bSjeremylt **/ 92575affc3bSjeremylt int CeedQFunctionView(CeedQFunction qf, FILE *stream) { 926ca5eadf8SJeremy L Thompson char *kernel_name; 92775affc3bSjeremylt 9282b730f8bSJeremy L Thompson CeedCall(CeedQFunctionGetKernelName(qf, &kernel_name)); 9292b730f8bSJeremy L Thompson fprintf(stream, "%sCeedQFunction - %s\n", qf->is_gallery ? "Gallery " : "User ", qf->is_gallery ? qf->gallery_name : kernel_name); 93075affc3bSjeremylt 9312b730f8bSJeremy L Thompson fprintf(stream, " %" CeedInt_FMT " input field%s:\n", qf->num_input_fields, qf->num_input_fields > 1 ? "s" : ""); 932d1d35e2fSjeremylt for (CeedInt i = 0; i < qf->num_input_fields; i++) { 9332b730f8bSJeremy L Thompson CeedCall(CeedQFunctionFieldView(qf->input_fields[i], i, 1, stream)); 93475affc3bSjeremylt } 93575affc3bSjeremylt 9362b730f8bSJeremy L Thompson fprintf(stream, " %" CeedInt_FMT " output field%s:\n", qf->num_output_fields, qf->num_output_fields > 1 ? "s" : ""); 937d1d35e2fSjeremylt for (CeedInt i = 0; i < qf->num_output_fields; i++) { 9382b730f8bSJeremy L Thompson CeedCall(CeedQFunctionFieldView(qf->output_fields[i], i, 0, stream)); 93975affc3bSjeremylt } 940e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 94175affc3bSjeremylt } 94275affc3bSjeremylt 94375affc3bSjeremylt /** 944b7c9bbdaSJeremy L Thompson @brief Get the Ceed associated with a CeedQFunction 945b7c9bbdaSJeremy L Thompson 946*ea61e9acSJeremy L Thompson @param[in] qf CeedQFunction 947b7c9bbdaSJeremy L Thompson @param[out] ceed Variable to store Ceed 948b7c9bbdaSJeremy L Thompson 949b7c9bbdaSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 950b7c9bbdaSJeremy L Thompson 951b7c9bbdaSJeremy L Thompson @ref Advanced 952b7c9bbdaSJeremy L Thompson **/ 953b7c9bbdaSJeremy L Thompson int CeedQFunctionGetCeed(CeedQFunction qf, Ceed *ceed) { 954b7c9bbdaSJeremy L Thompson *ceed = qf->ceed; 955b7c9bbdaSJeremy L Thompson return CEED_ERROR_SUCCESS; 956b7c9bbdaSJeremy L Thompson } 957b7c9bbdaSJeremy L Thompson 958b7c9bbdaSJeremy L Thompson /** 959b11c1e72Sjeremylt @brief Apply the action of a CeedQFunction 960b11c1e72Sjeremylt 961*ea61e9acSJeremy L Thompson Note: Calling this function asserts that setup is complete and sets the CeedQFunction as immutable. 962f04ea552SJeremy L Thompson 963*ea61e9acSJeremy L Thompson @param[in] qf CeedQFunction 964*ea61e9acSJeremy L Thompson @param[in] Q Number of quadrature points 96534138859Sjeremylt @param[in] u Array of input CeedVectors 96634138859Sjeremylt @param[out] v Array of output CeedVectors 967b11c1e72Sjeremylt 968b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 969dfdf5a53Sjeremylt 9707a982d89SJeremy L. Thompson @ref User 971b11c1e72Sjeremylt **/ 9722b730f8bSJeremy L Thompson int CeedQFunctionApply(CeedQFunction qf, CeedInt Q, CeedVector *u, CeedVector *v) { 9732b730f8bSJeremy L Thompson if (!qf->Apply) { 974c042f62fSJeremy L Thompson // LCOV_EXCL_START 9752b730f8bSJeremy L Thompson return CeedError(qf->ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support QFunctionApply"); 976c042f62fSJeremy L Thompson // LCOV_EXCL_STOP 9772b730f8bSJeremy L Thompson } 9782b730f8bSJeremy L Thompson if (Q % qf->vec_length) { 979c042f62fSJeremy L Thompson // LCOV_EXCL_START 9802b730f8bSJeremy L Thompson return CeedError(qf->ceed, CEED_ERROR_DIMENSION, "Number of quadrature points %" CeedInt_FMT " must be a multiple of %" CeedInt_FMT, Q, 9812b730f8bSJeremy L Thompson qf->vec_length); 982c042f62fSJeremy L Thompson // LCOV_EXCL_STOP 9832b730f8bSJeremy L Thompson } 984f04ea552SJeremy L Thompson qf->is_immutable = true; 9852b730f8bSJeremy L Thompson CeedCall(qf->Apply(qf, Q, u, v)); 986e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 987d7b241e6Sjeremylt } 988d7b241e6Sjeremylt 989b11c1e72Sjeremylt /** 990b11c1e72Sjeremylt @brief Destroy a CeedQFunction 991b11c1e72Sjeremylt 992*ea61e9acSJeremy L Thompson @param[in,out] qf CeedQFunction to destroy 993b11c1e72Sjeremylt 994b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 995dfdf5a53Sjeremylt 9967a982d89SJeremy L. Thompson @ref User 997b11c1e72Sjeremylt **/ 998d7b241e6Sjeremylt int CeedQFunctionDestroy(CeedQFunction *qf) { 999d1d35e2fSjeremylt if (!*qf || --(*qf)->ref_count > 0) return CEED_ERROR_SUCCESS; 1000fe2413ffSjeremylt // Backend destroy 1001d7b241e6Sjeremylt if ((*qf)->Destroy) { 10022b730f8bSJeremy L Thompson CeedCall((*qf)->Destroy(*qf)); 1003d7b241e6Sjeremylt } 1004fe2413ffSjeremylt // Free fields 100592ae7e47SJeremy L Thompson for (CeedInt i = 0; i < (*qf)->num_input_fields; i++) { 10062b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*(*qf)->input_fields[i]).field_name)); 10072b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*qf)->input_fields[i])); 1008fe2413ffSjeremylt } 100992ae7e47SJeremy L Thompson for (CeedInt i = 0; i < (*qf)->num_output_fields; i++) { 10102b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*(*qf)->output_fields[i]).field_name)); 10112b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*qf)->output_fields[i])); 1012fe2413ffSjeremylt } 10132b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*qf)->input_fields)); 10142b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*qf)->output_fields)); 1015777ff853SJeremy L Thompson 1016777ff853SJeremy L Thompson // User context data object 10172b730f8bSJeremy L Thompson CeedCall(CeedQFunctionContextDestroy(&(*qf)->ctx)); 1018fe2413ffSjeremylt 10192b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*qf)->user_source)); 10202b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*qf)->source_path)); 10212b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*qf)->gallery_name)); 10222b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*qf)->kernel_name)); 10232b730f8bSJeremy L Thompson CeedCall(CeedDestroy(&(*qf)->ceed)); 10242b730f8bSJeremy L Thompson CeedCall(CeedFree(qf)); 1025e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 1026d7b241e6Sjeremylt } 1027d7b241e6Sjeremylt 1028d7b241e6Sjeremylt /// @} 1029