1 // Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at 2 // the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights 3 // reserved. See files LICENSE and NOTICE for details. 4 // 5 // This file is part of CEED, a collection of benchmarks, miniapps, software 6 // libraries and APIs for efficient high-order finite element and spectral 7 // element discretizations for exascale applications. For more information and 8 // source code availability see http://github.com/ceed. 9 // 10 // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC, 11 // a collaborative effort of two U.S. Department of Energy organizations (Office 12 // of Science and the National Nuclear Security Administration) responsible for 13 // the planning and preparation of a capable exascale ecosystem, including 14 // software, applications, hardware, advanced system engineering and early 15 // testbed platforms, in support of the nation's exascale computing imperative. 16 17 #include <ceed-impl.h> 18 #include <ceed-backend.h> 19 #include <string.h> 20 #include <limits.h> 21 22 /// @file 23 /// Implementation of public CeedQFunction interfaces 24 25 /// @cond DOXYGEN_SKIP 26 static struct CeedQFunction_private ceed_qfunction_none; 27 /// @endcond 28 29 /// @addtogroup CeedQFunctionUser 30 /// @{ 31 32 // Indicate that no QFunction is provided by the user 33 const CeedQFunction CEED_QFUNCTION_NONE = &ceed_qfunction_none; 34 35 /// @} 36 37 /// @cond DOXYGEN_SKIP 38 static struct { 39 char name[CEED_MAX_RESOURCE_LEN]; 40 char source[CEED_MAX_RESOURCE_LEN]; 41 CeedInt vlength; 42 CeedQFunctionUser f; 43 int (*init)(Ceed ceed, const char *name, CeedQFunction qf); 44 } qfunctions[1024]; 45 static size_t num_qfunctions; 46 /// @endcond 47 48 /// ---------------------------------------------------------------------------- 49 /// CeedQFunction Library Internal Functions 50 /// ---------------------------------------------------------------------------- 51 /// @addtogroup CeedQFunctionDeveloper 52 /// @{ 53 54 /** 55 @brief Register a gallery QFunction 56 57 @param name Name for this backend to respond to 58 @param source Absolute path to source of QFunction, 59 "\path\CEED_DIR\gallery\folder\file.h:function_name" 60 @param vlength Vector length. Caller must ensure that number of quadrature 61 points is a multiple of vlength. 62 @param f Function pointer to evaluate action at quadrature points. 63 See \ref CeedQFunctionUser. 64 @param init Initialization function called by CeedQFunctionInit() when the 65 QFunction is selected. 66 67 @return An error code: 0 - success, otherwise - failure 68 69 @ref Developer 70 **/ 71 int CeedQFunctionRegister(const char *name, const char *source, 72 CeedInt vlength, CeedQFunctionUser f, 73 int (*init)(Ceed, const char *, CeedQFunction)) { 74 if (num_qfunctions >= sizeof(qfunctions) / sizeof(qfunctions[0])) 75 // LCOV_EXCL_START 76 return CeedError(NULL, 1, "Too many gallery QFunctions"); 77 // LCOV_EXCL_STOP 78 79 strncpy(qfunctions[num_qfunctions].name, name, CEED_MAX_RESOURCE_LEN); 80 qfunctions[num_qfunctions].name[CEED_MAX_RESOURCE_LEN-1] = 0; 81 strncpy(qfunctions[num_qfunctions].source, source, CEED_MAX_RESOURCE_LEN); 82 qfunctions[num_qfunctions].source[CEED_MAX_RESOURCE_LEN-1] = 0; 83 qfunctions[num_qfunctions].vlength = vlength; 84 qfunctions[num_qfunctions].f = f; 85 qfunctions[num_qfunctions].init = init; 86 num_qfunctions++; 87 return 0; 88 } 89 90 /** 91 @brief Set a CeedQFunction field, used by CeedQFunctionAddInput/Output 92 93 @param f CeedQFunctionField 94 @param fieldname Name of QFunction field 95 @param size Size of QFunction field, (ncomp * dim) for @ref CEED_EVAL_GRAD or 96 (ncomp * 1) for @ref CEED_EVAL_NONE, @ref CEED_EVAL_INTERP, and @ref CEED_EVAL_WEIGHT 97 @param emode \ref CEED_EVAL_NONE to use values directly, 98 \ref CEED_EVAL_INTERP to use interpolated values, 99 \ref CEED_EVAL_GRAD to use gradients, 100 \ref CEED_EVAL_WEIGHT to use quadrature weights. 101 102 @return An error code: 0 - success, otherwise - failure 103 104 @ref Developer 105 **/ 106 static int CeedQFunctionFieldSet(CeedQFunctionField *f,const char *fieldname, 107 CeedInt size, CeedEvalMode emode) { 108 size_t len = strlen(fieldname); 109 char *tmp; 110 int ierr; 111 ierr = CeedCalloc(1,f); CeedChk(ierr); 112 113 ierr = CeedCalloc(len+1, &tmp); CeedChk(ierr); 114 memcpy(tmp, fieldname, len+1); 115 (*f)->fieldname = tmp; 116 (*f)->size = size; 117 (*f)->emode = emode; 118 return 0; 119 } 120 121 /** 122 @brief View a field of a CeedQFunction 123 124 @param[in] field QFunction field to view 125 @param[in] fieldnumber Number of field being viewed 126 @param[in] in true for input field, false for output 127 @param[in] stream Stream to view to, e.g., stdout 128 129 @return An error code: 0 - success, otherwise - failure 130 131 @ref Utility 132 **/ 133 static int CeedQFunctionFieldView(CeedQFunctionField field, CeedInt fieldnumber, 134 bool in, FILE *stream) { 135 const char *inout = in ? "Input" : "Output"; 136 fprintf(stream, " %s Field [%d]:\n" 137 " Name: \"%s\"\n" 138 " Size: %d\n" 139 " EvalMode: \"%s\"\n", 140 inout, fieldnumber, field->fieldname, field->size, 141 CeedEvalModes[field->emode]); 142 143 return 0; 144 } 145 146 147 /** 148 @brief Set flag to determine if Fortran interface is used 149 150 @param qf CeedQFunction 151 @param status Boolean value to set as Fortran status 152 153 @return An error code: 0 - success, otherwise - failure 154 155 @ref Backend 156 **/ 157 int CeedQFunctionSetFortranStatus(CeedQFunction qf, bool status) { 158 qf->fortranstatus = status; 159 return 0; 160 } 161 162 /// @} 163 164 /// ---------------------------------------------------------------------------- 165 /// CeedQFunction Backend API 166 /// ---------------------------------------------------------------------------- 167 /// @addtogroup CeedQFunctionBackend 168 /// @{ 169 170 /** 171 @brief Get the Ceed associated with a CeedQFunction 172 173 @param qf CeedQFunction 174 @param[out] ceed Variable to store Ceed 175 176 @return An error code: 0 - success, otherwise - failure 177 178 @ref Backend 179 **/ 180 int CeedQFunctionGetCeed(CeedQFunction qf, Ceed *ceed) { 181 *ceed = qf->ceed; 182 return 0; 183 } 184 185 /** 186 @brief Get the vector length of a CeedQFunction 187 188 @param qf CeedQFunction 189 @param[out] vlength Variable to store vector length 190 191 @return An error code: 0 - success, otherwise - failure 192 193 @ref Backend 194 **/ 195 int CeedQFunctionGetVectorLength(CeedQFunction qf, CeedInt *vlength) { 196 *vlength = qf->vlength; 197 return 0; 198 } 199 200 /** 201 @brief Get the number of inputs and outputs to a CeedQFunction 202 203 @param qf CeedQFunction 204 @param[out] numinput Variable to store number of input fields 205 @param[out] numoutput Variable to store number of output fields 206 207 @return An error code: 0 - success, otherwise - failure 208 209 @ref Backend 210 **/ 211 int CeedQFunctionGetNumArgs(CeedQFunction qf, CeedInt *numinput, 212 CeedInt *numoutput) { 213 if (numinput) *numinput = qf->numinputfields; 214 if (numoutput) *numoutput = qf->numoutputfields; 215 return 0; 216 } 217 218 /** 219 @brief Get the source path string for a CeedQFunction 220 221 @param qf CeedQFunction 222 @param[out] source Variable to store source path string 223 224 @return An error code: 0 - success, otherwise - failure 225 226 @ref Backend 227 **/ 228 int CeedQFunctionGetSourcePath(CeedQFunction qf, char **source) { 229 *source = (char *) qf->sourcepath; 230 return 0; 231 } 232 233 /** 234 @brief Get the User Function for a CeedQFunction 235 236 @param qf CeedQFunction 237 @param[out] f Variable to store user function 238 239 @return An error code: 0 - success, otherwise - failure 240 241 @ref Backend 242 **/ 243 int CeedQFunctionGetUserFunction(CeedQFunction qf, CeedQFunctionUser *f) { 244 *f = qf->function; 245 return 0; 246 } 247 248 /** 249 @brief Get global context for a CeedQFunction. 250 Note: For QFunctions from the Fortran interface, this 251 function will return the Fortran context 252 CeedQFunctionContext. 253 254 @param qf CeedQFunction 255 @param[out] ctx Variable to store CeedQFunctionContext 256 257 @return An error code: 0 - success, otherwise - failure 258 259 @ref Backend 260 **/ 261 int CeedQFunctionGetContext(CeedQFunction qf, CeedQFunctionContext *ctx) { 262 *ctx = qf->ctx; 263 return 0; 264 } 265 266 /** 267 @brief Get true user context for a CeedQFunction 268 Note: For all QFunctions this function will return the user 269 CeedQFunctionContext and not interface context 270 CeedQFunctionContext, if any such object exists. 271 272 @param qf CeedQFunction 273 @param[out] ctx Variable to store CeedQFunctionContext 274 275 @return An error code: 0 - success, otherwise - failure 276 @ref Backend 277 **/ 278 int CeedQFunctionGetInnerContext(CeedQFunction qf, CeedQFunctionContext *ctx) { 279 int ierr; 280 if (qf->fortranstatus) { 281 CeedFortranContext fctx = NULL; 282 ierr = CeedQFunctionContextGetData(qf->ctx, CEED_MEM_HOST, &fctx); 283 CeedChk(ierr); 284 *ctx = fctx->innerctx; 285 ierr = CeedQFunctionContextRestoreData(qf->ctx, (void *)&fctx); CeedChk(ierr); 286 } else { 287 *ctx = qf->ctx; 288 } 289 290 291 return 0; 292 } 293 294 /** 295 @brief Determine if QFunction is identity 296 297 @param qf CeedQFunction 298 @param[out] isidentity Variable to store identity status 299 300 @return An error code: 0 - success, otherwise - failure 301 302 @ref Backend 303 **/ 304 int CeedQFunctionIsIdentity(CeedQFunction qf, bool *isidentity) { 305 *isidentity = qf->identity; 306 return 0; 307 } 308 309 /** 310 @brief Get backend data of a CeedQFunction 311 312 @param qf CeedQFunction 313 @param[out] data Variable to store data 314 315 @return An error code: 0 - success, otherwise - failure 316 317 @ref Backend 318 **/ 319 int CeedQFunctionGetData(CeedQFunction qf, void *data) { 320 *(void **)data = qf->data; 321 return 0; 322 } 323 324 /** 325 @brief Set backend data of a CeedQFunction 326 327 @param[out] qf CeedQFunction 328 @param data Data to set 329 330 @return An error code: 0 - success, otherwise - failure 331 332 @ref Backend 333 **/ 334 int CeedQFunctionSetData(CeedQFunction qf, void *data) { 335 qf->data = data; 336 return 0; 337 } 338 339 /** 340 @brief Get the CeedQFunctionFields of a CeedQFunction 341 342 @param qf CeedQFunction 343 @param[out] inputfields Variable to store inputfields 344 @param[out] outputfields Variable to store outputfields 345 346 @return An error code: 0 - success, otherwise - failure 347 348 @ref Backend 349 **/ 350 int CeedQFunctionGetFields(CeedQFunction qf, CeedQFunctionField **inputfields, 351 CeedQFunctionField **outputfields) { 352 if (inputfields) 353 *inputfields = qf->inputfields; 354 if (outputfields) 355 *outputfields = qf->outputfields; 356 return 0; 357 } 358 359 /** 360 @brief Get the name of a CeedQFunctionField 361 362 @param qffield CeedQFunctionField 363 @param[out] fieldname Variable to store the field name 364 365 @return An error code: 0 - success, otherwise - failure 366 367 @ref Backend 368 **/ 369 int CeedQFunctionFieldGetName(CeedQFunctionField qffield, char **fieldname) { 370 *fieldname = (char *)qffield->fieldname; 371 return 0; 372 } 373 374 /** 375 @brief Get the number of components of a CeedQFunctionField 376 377 @param qffield CeedQFunctionField 378 @param[out] size Variable to store the size of the field 379 380 @return An error code: 0 - success, otherwise - failure 381 382 @ref Backend 383 **/ 384 int CeedQFunctionFieldGetSize(CeedQFunctionField qffield, CeedInt *size) { 385 *size = qffield->size; 386 return 0; 387 } 388 389 /** 390 @brief Get the CeedEvalMode of a CeedQFunctionField 391 392 @param qffield CeedQFunctionField 393 @param[out] emode Variable to store the field evaluation mode 394 395 @return An error code: 0 - success, otherwise - failure 396 397 @ref Backend 398 **/ 399 int CeedQFunctionFieldGetEvalMode(CeedQFunctionField qffield, 400 CeedEvalMode *emode) { 401 *emode = qffield->emode; 402 return 0; 403 } 404 405 /// @} 406 407 /// ---------------------------------------------------------------------------- 408 /// CeedQFunction Public API 409 /// ---------------------------------------------------------------------------- 410 /// @addtogroup CeedQFunctionUser 411 /// @{ 412 413 /** 414 @brief Create a CeedQFunction for evaluating interior (volumetric) terms. 415 416 @param ceed A Ceed object where the CeedQFunction will be created 417 @param vlength Vector length. Caller must ensure that number of quadrature 418 points is a multiple of vlength. 419 @param f Function pointer to evaluate action at quadrature points. 420 See \ref CeedQFunctionUser. 421 @param source Absolute path to source of QFunction, 422 "\abs_path\file.h:function_name". 423 For support across all backends, this source must only 424 contain constructs supported by C99, C++11, and CUDA. 425 @param[out] qf Address of the variable where the newly created 426 CeedQFunction will be stored 427 428 @return An error code: 0 - success, otherwise - failure 429 430 See \ref CeedQFunctionUser for details on the call-back function @a f's 431 arguments. 432 433 @ref User 434 **/ 435 int CeedQFunctionCreateInterior(Ceed ceed, CeedInt vlength, CeedQFunctionUser f, 436 const char *source, CeedQFunction *qf) { 437 int ierr; 438 char *source_copy; 439 440 if (!ceed->QFunctionCreate) { 441 Ceed delegate; 442 ierr = CeedGetObjectDelegate(ceed, &delegate, "QFunction"); CeedChk(ierr); 443 444 if (!delegate) 445 // LCOV_EXCL_START 446 return CeedError(ceed, 1, "Backend does not support QFunctionCreate"); 447 // LCOV_EXCL_STOP 448 449 ierr = CeedQFunctionCreateInterior(delegate, vlength, f, source, qf); 450 CeedChk(ierr); 451 return 0; 452 } 453 454 ierr = CeedCalloc(1, qf); CeedChk(ierr); 455 (*qf)->ceed = ceed; 456 ceed->refcount++; 457 (*qf)->refcount = 1; 458 (*qf)->vlength = vlength; 459 (*qf)->identity = 0; 460 (*qf)->function = f; 461 size_t slen = strlen(source) + 1; 462 ierr = CeedMalloc(slen, &source_copy); CeedChk(ierr); 463 memcpy(source_copy, source, slen); 464 (*qf)->sourcepath = source_copy; 465 ierr = CeedCalloc(16, &(*qf)->inputfields); CeedChk(ierr); 466 ierr = CeedCalloc(16, &(*qf)->outputfields); CeedChk(ierr); 467 ierr = ceed->QFunctionCreate(*qf); CeedChk(ierr); 468 return 0; 469 } 470 471 /** 472 @brief Create a CeedQFunction for evaluating interior (volumetric) terms by name. 473 474 @param ceed A Ceed object where the CeedQFunction will be created 475 @param name Name of QFunction to use from gallery 476 @param[out] qf Address of the variable where the newly created 477 CeedQFunction will be stored 478 479 @return An error code: 0 - success, otherwise - failure 480 481 @ref User 482 **/ 483 int CeedQFunctionCreateInteriorByName(Ceed ceed, const char *name, 484 CeedQFunction *qf) { 485 int ierr; 486 size_t matchlen = 0, matchidx = UINT_MAX; 487 char *name_copy; 488 489 ierr = CeedQFunctionRegisterAll(); CeedChk(ierr); 490 // Find matching backend 491 if (!name) return CeedError(ceed, 1, "No QFunction name provided"); 492 for (size_t i=0; i<num_qfunctions; i++) { 493 size_t n; 494 const char *currname = qfunctions[i].name; 495 for (n = 0; currname[n] && currname[n] == name[n]; n++) {} 496 if (n > matchlen) { 497 matchlen = n; 498 matchidx = i; 499 } 500 } 501 if (!matchlen) 502 // LCOV_EXCL_START 503 return CeedError(ceed, 1, "No suitable gallery QFunction"); 504 // LCOV_EXCL_STOP 505 506 // Create QFunction 507 ierr = CeedQFunctionCreateInterior(ceed, qfunctions[matchidx].vlength, 508 qfunctions[matchidx].f, 509 qfunctions[matchidx].source, qf); 510 CeedChk(ierr); 511 512 // QFunction specific setup 513 ierr = qfunctions[matchidx].init(ceed, name, *qf); CeedChk(ierr); 514 515 // Copy name 516 size_t slen = strlen(name) + 1; 517 ierr = CeedMalloc(slen, &name_copy); CeedChk(ierr); 518 memcpy(name_copy, name, slen); 519 (*qf)->qfname = name_copy; 520 521 return 0; 522 } 523 524 /** 525 @brief Create an identity CeedQFunction. Inputs are written into outputs in 526 the order given. This is useful for CeedOperators that can be 527 represented with only the action of a CeedRestriction and CeedBasis, 528 such as restriction and prolongation operators for p-multigrid. 529 Backends may optimize CeedOperators with this CeedQFunction to avoid 530 the copy of input data to output fields by using the same memory 531 location for both. 532 533 @param ceed A Ceed object where the CeedQFunction will be created 534 @param[in] size Size of the qfunction fields 535 @param[in] inmode CeedEvalMode for input to CeedQFunction 536 @param[in] outmode CeedEvalMode for output to CeedQFunction 537 @param[out] qf Address of the variable where the newly created 538 CeedQFunction will be stored 539 540 @return An error code: 0 - success, otherwise - failure 541 542 @ref User 543 **/ 544 int CeedQFunctionCreateIdentity(Ceed ceed, CeedInt size, CeedEvalMode inmode, 545 CeedEvalMode outmode, CeedQFunction *qf) { 546 int ierr; 547 548 if (inmode == CEED_EVAL_NONE && outmode == CEED_EVAL_NONE) 549 // LCOV_EXCL_START 550 return CeedError(ceed, 1, "CEED_EVAL_NONE for a both the input and " 551 "output does not make sense with an identity QFunction"); 552 // LCOV_EXCL_STOP 553 554 ierr = CeedQFunctionCreateInteriorByName(ceed, "Identity", qf); CeedChk(ierr); 555 ierr = CeedQFunctionAddInput(*qf, "input", size, inmode); CeedChk(ierr); 556 ierr = CeedQFunctionAddOutput(*qf, "output", size, outmode); CeedChk(ierr); 557 558 (*qf)->identity = 1; 559 CeedInt *sizeData; 560 ierr = CeedCalloc(1, &sizeData); CeedChk(ierr); 561 sizeData[0] = size; 562 CeedQFunctionContext ctx; 563 ierr = CeedQFunctionContextCreate(ceed, &ctx); CeedChk(ierr); 564 ierr = CeedQFunctionContextSetData(ctx, CEED_MEM_HOST, CEED_OWN_POINTER, 565 sizeof(*sizeData), (void *)sizeData); 566 CeedChk(ierr); 567 ierr = CeedQFunctionSetContext(*qf, ctx); CeedChk(ierr); 568 ierr = CeedQFunctionContextDestroy(&ctx); CeedChk(ierr); 569 570 return 0; 571 } 572 573 /** 574 @brief Add a CeedQFunction input 575 576 @param qf CeedQFunction 577 @param fieldname Name of QFunction field 578 @param size Size of QFunction field, (ncomp * dim) for @ref CEED_EVAL_GRAD or 579 (ncomp * 1) for @ref CEED_EVAL_NONE and @ref CEED_EVAL_INTERP 580 @param emode \ref CEED_EVAL_NONE to use values directly, 581 \ref CEED_EVAL_INTERP to use interpolated values, 582 \ref CEED_EVAL_GRAD to use gradients. 583 584 @return An error code: 0 - success, otherwise - failure 585 586 @ref User 587 **/ 588 int CeedQFunctionAddInput(CeedQFunction qf, const char *fieldname, CeedInt size, 589 CeedEvalMode emode) { 590 int ierr = CeedQFunctionFieldSet(&qf->inputfields[qf->numinputfields], 591 fieldname, size, emode); 592 CeedChk(ierr); 593 qf->numinputfields++; 594 return 0; 595 } 596 597 /** 598 @brief Add a CeedQFunction output 599 600 @param qf CeedQFunction 601 @param fieldname Name of QFunction field 602 @param size Size of QFunction field, (ncomp * dim) for @ref CEED_EVAL_GRAD or 603 (ncomp * 1) for @ref CEED_EVAL_NONE and @ref CEED_EVAL_INTERP 604 @param emode \ref CEED_EVAL_NONE to use values directly, 605 \ref CEED_EVAL_INTERP to use interpolated values, 606 \ref CEED_EVAL_GRAD to use gradients. 607 608 @return An error code: 0 - success, otherwise - failure 609 610 @ref User 611 **/ 612 int CeedQFunctionAddOutput(CeedQFunction qf, const char *fieldname, 613 CeedInt size, CeedEvalMode emode) { 614 if (emode == CEED_EVAL_WEIGHT) 615 // LCOV_EXCL_START 616 return CeedError(qf->ceed, 1, "Cannot create QFunction output with " 617 "CEED_EVAL_WEIGHT"); 618 // LCOV_EXCL_STOP 619 int ierr = CeedQFunctionFieldSet(&qf->outputfields[qf->numoutputfields], 620 fieldname, size, emode); 621 CeedChk(ierr); 622 qf->numoutputfields++; 623 return 0; 624 } 625 626 /** 627 @brief Set global context for a CeedQFunction 628 629 @param qf CeedQFunction 630 @param ctx Context data to set 631 632 @return An error code: 0 - success, otherwise - failure 633 634 @ref User 635 **/ 636 int CeedQFunctionSetContext(CeedQFunction qf, CeedQFunctionContext ctx) { 637 qf->ctx = ctx; 638 ctx->refcount++; 639 return 0; 640 } 641 642 /** 643 @brief View a CeedQFunction 644 645 @param[in] qf CeedQFunction to view 646 @param[in] stream Stream to write; typically stdout/stderr or a file 647 648 @return Error code: 0 - success, otherwise - failure 649 650 @ref User 651 **/ 652 int CeedQFunctionView(CeedQFunction qf, FILE *stream) { 653 int ierr; 654 655 fprintf(stream, "%sCeedQFunction %s\n", 656 qf->qfname ? "Gallery " : "User ", qf->qfname ? qf->qfname : ""); 657 658 fprintf(stream, " %d Input Field%s:\n", qf->numinputfields, 659 qf->numinputfields>1 ? "s" : ""); 660 for (CeedInt i=0; i<qf->numinputfields; i++) { 661 ierr = CeedQFunctionFieldView(qf->inputfields[i], i, 1, stream); 662 CeedChk(ierr); 663 } 664 665 fprintf(stream, " %d Output Field%s:\n", qf->numoutputfields, 666 qf->numoutputfields>1 ? "s" : ""); 667 for (CeedInt i=0; i<qf->numoutputfields; i++) { 668 ierr = CeedQFunctionFieldView(qf->outputfields[i], i, 0, stream); 669 CeedChk(ierr); 670 } 671 return 0; 672 } 673 674 /** 675 @brief Apply the action of a CeedQFunction 676 677 @param qf CeedQFunction 678 @param Q Number of quadrature points 679 @param[in] u Array of input CeedVectors 680 @param[out] v Array of output CeedVectors 681 682 @return An error code: 0 - success, otherwise - failure 683 684 @ref User 685 **/ 686 int CeedQFunctionApply(CeedQFunction qf, CeedInt Q, 687 CeedVector *u, CeedVector *v) { 688 int ierr; 689 if (!qf->Apply) 690 // LCOV_EXCL_START 691 return CeedError(qf->ceed, 1, "Backend does not support QFunctionApply"); 692 // LCOV_EXCL_STOP 693 if (Q % qf->vlength) 694 // LCOV_EXCL_START 695 return CeedError(qf->ceed, 2, "Number of quadrature points %d must be a " 696 "multiple of %d", Q, qf->vlength); 697 // LCOV_EXCL_STOP 698 ierr = qf->Apply(qf, Q, u, v); CeedChk(ierr); 699 return 0; 700 } 701 702 /** 703 @brief Destroy a CeedQFunction 704 705 @param qf CeedQFunction to destroy 706 707 @return An error code: 0 - success, otherwise - failure 708 709 @ref User 710 **/ 711 int CeedQFunctionDestroy(CeedQFunction *qf) { 712 int ierr; 713 714 if (!*qf || --(*qf)->refcount > 0) return 0; 715 // Backend destroy 716 if ((*qf)->Destroy) { 717 ierr = (*qf)->Destroy(*qf); CeedChk(ierr); 718 } 719 // Free fields 720 for (int i=0; i<(*qf)->numinputfields; i++) { 721 ierr = CeedFree(&(*(*qf)->inputfields[i]).fieldname); CeedChk(ierr); 722 ierr = CeedFree(&(*qf)->inputfields[i]); CeedChk(ierr); 723 } 724 for (int i=0; i<(*qf)->numoutputfields; i++) { 725 ierr = CeedFree(&(*(*qf)->outputfields[i]).fieldname); CeedChk(ierr); 726 ierr = CeedFree(&(*qf)->outputfields[i]); CeedChk(ierr); 727 } 728 ierr = CeedFree(&(*qf)->inputfields); CeedChk(ierr); 729 ierr = CeedFree(&(*qf)->outputfields); CeedChk(ierr); 730 731 // User context data object 732 ierr = CeedQFunctionContextDestroy(&(*qf)->ctx); CeedChk(ierr); 733 734 ierr = CeedFree(&(*qf)->sourcepath); CeedChk(ierr); 735 ierr = CeedFree(&(*qf)->qfname); CeedChk(ierr); 736 ierr = CeedDestroy(&(*qf)->ceed); CeedChk(ierr); 737 ierr = CeedFree(qf); CeedChk(ierr); 738 return 0; 739 } 740 741 /// @} 742