| ceed-qfunctioncontext.c (dbf4d22165e3b79901b5e167984006ae5ea5b1f4) | ceed-qfunctioncontext.c (3668ca4b583f336c0c2dcc810e26e2ac50a514b8) |
|---|---|
| 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. --- 31 unchanged lines hidden (view full) --- 40 @return An error code: 0 - success, otherwise - failure 41 42 @ref Developer 43**/ 44int CeedQFunctionContextGetFieldIndex(CeedQFunctionContext ctx, 45 const char *field_name, CeedInt *field_index) { 46 *field_index = -1; 47 for (CeedInt i=0; i<ctx->num_fields; i++) | 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. --- 31 unchanged lines hidden (view full) --- 40 @return An error code: 0 - success, otherwise - failure 41 42 @ref Developer 43**/ 44int CeedQFunctionContextGetFieldIndex(CeedQFunctionContext ctx, 45 const char *field_name, CeedInt *field_index) { 46 *field_index = -1; 47 for (CeedInt i=0; i<ctx->num_fields; i++) |
| 48 if (!strcmp(ctx->field_descriptions[i].name, field_name)) | 48 if (!strcmp(ctx->field_labels[i]->name, field_name)) |
| 49 *field_index = i; 50 return CEED_ERROR_SUCCESS; 51} 52 53/** 54 @brief Common function for registering QFunctionContext fields 55 56 @param ctx CeedQFunctionContext --- 22 unchanged lines hidden (view full) --- 79 // LCOV_EXCL_START 80 return CeedError(ctx->ceed, CEED_ERROR_UNSUPPORTED, 81 "QFunctionContext field with name \"%s\" already registered", 82 field_name); 83 // LCOV_EXCL_STOP 84 85 // Allocate space for field data 86 if (ctx->num_fields == 0) { | 49 *field_index = i; 50 return CEED_ERROR_SUCCESS; 51} 52 53/** 54 @brief Common function for registering QFunctionContext fields 55 56 @param ctx CeedQFunctionContext --- 22 unchanged lines hidden (view full) --- 79 // LCOV_EXCL_START 80 return CeedError(ctx->ceed, CEED_ERROR_UNSUPPORTED, 81 "QFunctionContext field with name \"%s\" already registered", 82 field_name); 83 // LCOV_EXCL_STOP 84 85 // Allocate space for field data 86 if (ctx->num_fields == 0) { |
| 87 ierr = CeedCalloc(1, &ctx->field_descriptions); CeedChk(ierr); | 87 ierr = CeedCalloc(1, &ctx->field_labels); CeedChk(ierr); |
| 88 ctx->max_fields = 1; 89 } else if (ctx->num_fields == ctx->max_fields) { | 88 ctx->max_fields = 1; 89 } else if (ctx->num_fields == ctx->max_fields) { |
| 90 ierr = CeedRealloc(2*ctx->max_fields, &ctx->field_descriptions); | 90 ierr = CeedRealloc(2*ctx->max_fields, &ctx->field_labels); |
| 91 CeedChk(ierr); 92 ctx->max_fields *= 2; 93 } | 91 CeedChk(ierr); 92 ctx->max_fields *= 2; 93 } |
| 94 ierr = CeedCalloc(1, &ctx->field_labels[ctx->num_fields]); CeedChk(ierr); |
|
| 94 95 // Copy field data 96 ierr = CeedStringAllocCopy(field_name, | 95 96 // Copy field data 97 ierr = CeedStringAllocCopy(field_name, |
| 97 (char **)&ctx->field_descriptions[ctx->num_fields].name); | 98 (char **)&ctx->field_labels[ctx->num_fields]->name); |
| 98 CeedChk(ierr); 99 ierr = CeedStringAllocCopy(field_description, | 99 CeedChk(ierr); 100 ierr = CeedStringAllocCopy(field_description, |
| 100 (char **)&ctx->field_descriptions[ctx->num_fields].description); | 101 (char **)&ctx->field_labels[ctx->num_fields]->description); |
| 101 CeedChk(ierr); | 102 CeedChk(ierr); |
| 102 ctx->field_descriptions[ctx->num_fields].type = field_type; 103 ctx->field_descriptions[ctx->num_fields].offset = field_offset; 104 ctx->field_descriptions[ctx->num_fields].size = field_size; | 103 ctx->field_labels[ctx->num_fields]->type = field_type; 104 ctx->field_labels[ctx->num_fields]->offset = field_offset; 105 ctx->field_labels[ctx->num_fields]->size = field_size; |
| 105 ctx->num_fields++; 106 return CEED_ERROR_SUCCESS; 107} 108 109/// @} 110 111/// ---------------------------------------------------------------------------- 112/// CeedQFunctionContext Backend API --- 112 unchanged lines hidden (view full) --- 225int CeedQFunctionContextSetBackendData(CeedQFunctionContext ctx, void *data) { 226 ctx->data = data; 227 return CEED_ERROR_SUCCESS; 228} 229 230/** 231 @brief Set QFunctionContext field 232 | 106 ctx->num_fields++; 107 return CEED_ERROR_SUCCESS; 108} 109 110/// @} 111 112/// ---------------------------------------------------------------------------- 113/// CeedQFunctionContext Backend API --- 112 unchanged lines hidden (view full) --- 226int CeedQFunctionContextSetBackendData(CeedQFunctionContext ctx, void *data) { 227 ctx->data = data; 228 return CEED_ERROR_SUCCESS; 229} 230 231/** 232 @brief Set QFunctionContext field 233 |
| 233 @param ctx CeedQFunctionContext 234 @param field_name Name of field to set 235 @param field_type Type of field to set 236 @param is_set Boolean flag if value was set 237 @param value Value to set | 234 @param ctx CeedQFunctionContext 235 @param field_label Label of field to set 236 @param field_type Type of field to set 237 @param value Value to set |
| 238 239 @return An error code: 0 - success, otherwise - failure 240 241 @ref User 242**/ 243int CeedQFunctionContextSetGeneric(CeedQFunctionContext ctx, | 238 239 @return An error code: 0 - success, otherwise - failure 240 241 @ref User 242**/ 243int CeedQFunctionContextSetGeneric(CeedQFunctionContext ctx, |
| 244 const char *field_name, | 244 CeedContextFieldLabel field_label, |
| 245 CeedContextFieldType field_type, | 245 CeedContextFieldType field_type, |
| 246 bool *is_set, void *value) { | 246 void *value) { |
| 247 int ierr; 248 | 247 int ierr; 248 |
| 249 // Check field index 250 *is_set = false; 251 CeedInt field_index = -1; 252 ierr = CeedQFunctionContextGetFieldIndex(ctx, field_name, &field_index); 253 CeedChk(ierr); 254 if (field_index == -1) 255 return CEED_ERROR_SUCCESS; 256 257 if (ctx->field_descriptions[field_index].type != field_type) | 249 // Check field type 250 if (field_label->type != field_type) |
| 258 // LCOV_EXCL_START 259 return CeedError(ctx->ceed, CEED_ERROR_UNSUPPORTED, 260 "QFunctionContext field with name \"%s\" registered as %s, " | 251 // LCOV_EXCL_START 252 return CeedError(ctx->ceed, CEED_ERROR_UNSUPPORTED, 253 "QFunctionContext field with name \"%s\" registered as %s, " |
| 261 "not registered as %s", field_name, 262 CeedContextFieldTypes[ctx->field_descriptions[field_index].type], | 254 "not registered as %s", field_label->name, 255 CeedContextFieldTypes[field_label->type], |
| 263 CeedContextFieldTypes[field_type]); 264 // LCOV_EXCL_STOP 265 266 char *data; 267 ierr = CeedQFunctionContextGetData(ctx, CEED_MEM_HOST, &data); CeedChk(ierr); | 256 CeedContextFieldTypes[field_type]); 257 // LCOV_EXCL_STOP 258 259 char *data; 260 ierr = CeedQFunctionContextGetData(ctx, CEED_MEM_HOST, &data); CeedChk(ierr); |
| 268 memcpy(&data[ctx->field_descriptions[field_index].offset], value, 269 ctx->field_descriptions[field_index].size); | 261 memcpy(&data[field_label->offset], value, field_label->size); |
| 270 ierr = CeedQFunctionContextRestoreData(ctx, &data); CeedChk(ierr); | 262 ierr = CeedQFunctionContextRestoreData(ctx, &data); CeedChk(ierr); |
| 271 *is_set = true; | |
| 272 273 return CEED_ERROR_SUCCESS; 274} 275 276/** 277 @brief Increment the reference counter for a CeedQFunctionContext 278 279 @param ctx CeedQFunctionContext to increment the reference counter --- 280 unchanged lines hidden (view full) --- 560int CeedQFunctionContextRegisterInt32(CeedQFunctionContext ctx, 561 const char *field_name, size_t field_offset, 562 const char *field_description) { 563 return CeedQFunctionContextRegisterGeneric(ctx, field_name, field_offset, 564 field_description, CEED_CONTEXT_FIELD_INT32, sizeof(int)); 565} 566 567/** | 263 264 return CEED_ERROR_SUCCESS; 265} 266 267/** 268 @brief Increment the reference counter for a CeedQFunctionContext 269 270 @param ctx CeedQFunctionContext to increment the reference counter --- 280 unchanged lines hidden (view full) --- 551int CeedQFunctionContextRegisterInt32(CeedQFunctionContext ctx, 552 const char *field_name, size_t field_offset, 553 const char *field_description) { 554 return CeedQFunctionContextRegisterGeneric(ctx, field_name, field_offset, 555 field_description, CEED_CONTEXT_FIELD_INT32, sizeof(int)); 556} 557 558/** |
| 568 @brief Get descriptions for registered QFunctionContext fields | 559 @brief Get labels for all registered QFunctionContext fields |
| 569 | 560 |
| 570 @param ctx CeedQFunctionContext 571 @param[out] field_descriptions Variable to hold array of field descriptions 572 @param[out] num_fields Length of field descriptions array | 561 @param ctx CeedQFunctionContext 562 @param[out] field_labels Variable to hold array of field labels 563 @param[out] num_fields Length of field descriptions array |
| 573 574 @return An error code: 0 - success, otherwise - failure 575 576 @ref User 577**/ | 564 565 @return An error code: 0 - success, otherwise - failure 566 567 @ref User 568**/ |
| 578int CeedQFunctionContextGetFieldDescriptions(CeedQFunctionContext ctx, 579 const CeedQFunctionContextFieldDescription **field_descriptions, 580 CeedInt *num_fields) { 581 *field_descriptions = ctx->field_descriptions; | 569int CeedQFunctionContextGetAllFieldLabels(CeedQFunctionContext ctx, 570 const CeedContextFieldLabel **field_labels, CeedInt *num_fields) { 571 *field_labels = ctx->field_labels; |
| 582 *num_fields = ctx->num_fields; 583 return CEED_ERROR_SUCCESS; 584} 585 586/** | 572 *num_fields = ctx->num_fields; 573 return CEED_ERROR_SUCCESS; 574} 575 576/** |
| 577 @brief Get label for a registered QFunctionContext field, or `NULL` if no 578 field has been registered with this `field_name` 579 580 @param[in] ctx CeedQFunctionContext 581 @param[in] field_name Name of field to retrieve label 582 @param[out] field_label Variable to field label 583 584 @return An error code: 0 - success, otherwise - failure 585 586 @ref User 587**/ 588int CeedQFunctionContextGetFieldLabel(CeedQFunctionContext ctx, 589 const char *field_name, CeedContextFieldLabel *field_label) { 590 int ierr; 591 592 CeedInt field_index; 593 ierr = CeedQFunctionContextGetFieldIndex(ctx, field_name, &field_index); 594 CeedChk(ierr); 595 596 if (field_index != -1) { 597 *field_label = ctx->field_labels[field_index]; 598 } else { 599 *field_label = NULL; 600 } 601 602 return CEED_ERROR_SUCCESS; 603} 604 605/** |
|
| 587 @brief Set QFunctionContext field holding a double precision value 588 | 606 @brief Set QFunctionContext field holding a double precision value 607 |
| 589 @param ctx CeedQFunctionContext 590 @param field_name Name of field to register 591 @param value Value to set | 608 @param ctx CeedQFunctionContext 609 @param field_label Label for field to register 610 @param value Value to set |
| 592 593 @return An error code: 0 - success, otherwise - failure 594 595 @ref User 596**/ 597int CeedQFunctionContextSetDouble(CeedQFunctionContext ctx, | 611 612 @return An error code: 0 - success, otherwise - failure 613 614 @ref User 615**/ 616int CeedQFunctionContextSetDouble(CeedQFunctionContext ctx, |
| 598 const char *field_name, double value) { | 617 CeedContextFieldLabel field_label, double value) { |
| 599 int ierr; | 618 int ierr; |
| 600 bool is_set = false; | |
| 601 | 619 |
| 602 ierr = CeedQFunctionContextSetGeneric(ctx, field_name, 603 CEED_CONTEXT_FIELD_DOUBLE, 604 &is_set, &value); CeedChk(ierr); 605 if (!is_set) | 620 if (!field_label) |
| 606 // LCOV_EXCL_START 607 return CeedError(ctx->ceed, CEED_ERROR_UNSUPPORTED, | 621 // LCOV_EXCL_START 622 return CeedError(ctx->ceed, CEED_ERROR_UNSUPPORTED, |
| 608 "QFunctionContext field with name \"%s\" not registered", 609 field_name); | 623 "Invalid field label"); |
| 610 // LCOV_EXCL_STOP 611 | 624 // LCOV_EXCL_STOP 625 |
| 626 ierr = CeedQFunctionContextSetGeneric(ctx, field_label, 627 CEED_CONTEXT_FIELD_DOUBLE, 628 &value); CeedChk(ierr); 629 |
|
| 612 return CEED_ERROR_SUCCESS; 613} 614 615/** 616 @brief Set QFunctionContext field holding an int32 value 617 | 630 return CEED_ERROR_SUCCESS; 631} 632 633/** 634 @brief Set QFunctionContext field holding an int32 value 635 |
| 618 @param ctx CeedQFunctionContext 619 @param field_name Name of field to set 620 @param value Value to set | 636 @param ctx CeedQFunctionContext 637 @param field_label Label for field to register 638 @param value Value to set |
| 621 622 @return An error code: 0 - success, otherwise - failure 623 624 @ref User 625**/ 626int CeedQFunctionContextSetInt32(CeedQFunctionContext ctx, | 639 640 @return An error code: 0 - success, otherwise - failure 641 642 @ref User 643**/ 644int CeedQFunctionContextSetInt32(CeedQFunctionContext ctx, |
| 627 const char *field_name, int value) { | 645 CeedContextFieldLabel field_label, int value) { |
| 628 int ierr; | 646 int ierr; |
| 629 bool is_set = false; | |
| 630 | 647 |
| 631 ierr = CeedQFunctionContextSetGeneric(ctx, field_name, 632 CEED_CONTEXT_FIELD_INT32, 633 &is_set, &value); CeedChk(ierr); 634 if (!is_set) | 648 if (!field_label) |
| 635 // LCOV_EXCL_START 636 return CeedError(ctx->ceed, CEED_ERROR_UNSUPPORTED, | 649 // LCOV_EXCL_START 650 return CeedError(ctx->ceed, CEED_ERROR_UNSUPPORTED, |
| 637 "QFunctionContext field with name \"%s\" not registered", 638 field_name); | 651 "Invalid field label"); |
| 639 // LCOV_EXCL_STOP 640 | 652 // LCOV_EXCL_STOP 653 |
| 654 ierr = CeedQFunctionContextSetGeneric(ctx, field_label, 655 CEED_CONTEXT_FIELD_INT32, 656 &value); CeedChk(ierr); 657 |
|
| 641 return CEED_ERROR_SUCCESS; 642} 643 644/** 645 @brief Get data size for a Context 646 647 @param ctx CeedQFunctionContext 648 @param[out] ctx_size Variable to store size of context data values --- 17 unchanged lines hidden (view full) --- 666 667 @return An error code: 0 - success, otherwise - failure 668 669 @ref User 670**/ 671int CeedQFunctionContextView(CeedQFunctionContext ctx, FILE *stream) { 672 fprintf(stream, "CeedQFunctionContext\n"); 673 fprintf(stream, " Context Data Size: %ld\n", ctx->ctx_size); | 658 return CEED_ERROR_SUCCESS; 659} 660 661/** 662 @brief Get data size for a Context 663 664 @param ctx CeedQFunctionContext 665 @param[out] ctx_size Variable to store size of context data values --- 17 unchanged lines hidden (view full) --- 683 684 @return An error code: 0 - success, otherwise - failure 685 686 @ref User 687**/ 688int CeedQFunctionContextView(CeedQFunctionContext ctx, FILE *stream) { 689 fprintf(stream, "CeedQFunctionContext\n"); 690 fprintf(stream, " Context Data Size: %ld\n", ctx->ctx_size); |
| 691 for (CeedInt i = 0; i < ctx->num_fields; i++) { 692 // LCOV_EXCL_START 693 fprintf(stream, " Labeled %s field: %s\n", 694 CeedContextFieldTypes[ctx->field_labels[i]->type], 695 ctx->field_labels[i]->name); 696 // LCOV_EXCL_STOP 697 } |
|
| 674 return CEED_ERROR_SUCCESS; 675} 676 677/** 678 @brief Destroy a CeedQFunctionContext 679 680 @param ctx CeedQFunctionContext to destroy 681 --- 13 unchanged lines hidden (view full) --- 695 "Cannot destroy CeedQFunctionContext, the access " 696 "lock is in use"); 697 // LCOV_EXCL_STOP 698 699 if ((*ctx)->Destroy) { 700 ierr = (*ctx)->Destroy(*ctx); CeedChk(ierr); 701 } 702 for (CeedInt i=0; i<(*ctx)->num_fields; i++) { | 698 return CEED_ERROR_SUCCESS; 699} 700 701/** 702 @brief Destroy a CeedQFunctionContext 703 704 @param ctx CeedQFunctionContext to destroy 705 --- 13 unchanged lines hidden (view full) --- 719 "Cannot destroy CeedQFunctionContext, the access " 720 "lock is in use"); 721 // LCOV_EXCL_STOP 722 723 if ((*ctx)->Destroy) { 724 ierr = (*ctx)->Destroy(*ctx); CeedChk(ierr); 725 } 726 for (CeedInt i=0; i<(*ctx)->num_fields; i++) { |
| 703 ierr = CeedFree(&(*ctx)->field_descriptions[i].name); CeedChk(ierr); 704 ierr = CeedFree(&(*ctx)->field_descriptions[i].description); CeedChk(ierr); | 727 ierr = CeedFree(&(*ctx)->field_labels[i]->name); CeedChk(ierr); 728 ierr = CeedFree(&(*ctx)->field_labels[i]->description); CeedChk(ierr); 729 ierr = CeedFree(&(*ctx)->field_labels[i]); CeedChk(ierr); |
| 705 } | 730 } |
| 706 ierr = CeedFree(&(*ctx)->field_descriptions); CeedChk(ierr); | 731 ierr = CeedFree(&(*ctx)->field_labels); CeedChk(ierr); |
| 707 ierr = CeedDestroy(&(*ctx)->ceed); CeedChk(ierr); 708 ierr = CeedFree(ctx); CeedChk(ierr); 709 710 return CEED_ERROR_SUCCESS; 711} 712 713/// @} | 732 ierr = CeedDestroy(&(*ctx)->ceed); CeedChk(ierr); 733 ierr = CeedFree(ctx); CeedChk(ierr); 734 735 return CEED_ERROR_SUCCESS; 736} 737 738/// @} |