ceed-qfunction.c (43bbe138142266535c178bdafdc3d62b34a54607) ceed-qfunction.c (f04ea552c0bc984e9734ef5cac4fa0e4550ba0f1)
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.

--- 151 unchanged lines hidden (view full) ---

160 @param qf CeedQFunction
161 @param status Boolean value to set as Fortran status
162
163 @return An error code: 0 - success, otherwise - failure
164
165 @ref Backend
166**/
167int CeedQFunctionSetFortranStatus(CeedQFunction qf, bool status) {
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.

--- 151 unchanged lines hidden (view full) ---

160 @param qf CeedQFunction
161 @param status Boolean value to set as Fortran status
162
163 @return An error code: 0 - success, otherwise - failure
164
165 @ref Backend
166**/
167int CeedQFunctionSetFortranStatus(CeedQFunction qf, bool status) {
168 qf->fortran_status = status;
168 qf->is_fortran = status;
169 return CEED_ERROR_SUCCESS;
170}
171
172/// @}
173
174/// ----------------------------------------------------------------------------
175/// CeedQFunction Backend API
176/// ----------------------------------------------------------------------------

--- 105 unchanged lines hidden (view full) ---

282 @param qf CeedQFunction
283 @param[out] ctx Variable to store CeedQFunctionContext
284
285 @return An error code: 0 - success, otherwise - failure
286 @ref Backend
287**/
288int CeedQFunctionGetInnerContext(CeedQFunction qf, CeedQFunctionContext *ctx) {
289 int ierr;
169 return CEED_ERROR_SUCCESS;
170}
171
172/// @}
173
174/// ----------------------------------------------------------------------------
175/// CeedQFunction Backend API
176/// ----------------------------------------------------------------------------

--- 105 unchanged lines hidden (view full) ---

282 @param qf CeedQFunction
283 @param[out] ctx Variable to store CeedQFunctionContext
284
285 @return An error code: 0 - success, otherwise - failure
286 @ref Backend
287**/
288int CeedQFunctionGetInnerContext(CeedQFunction qf, CeedQFunctionContext *ctx) {
289 int ierr;
290 if (qf->fortran_status) {
290 if (qf->is_fortran) {
291 CeedFortranContext fortran_ctx = NULL;
292 ierr = CeedQFunctionContextGetData(qf->ctx, CEED_MEM_HOST, &fortran_ctx);
293 CeedChk(ierr);
294 *ctx = fortran_ctx->innerctx;
295 ierr = CeedQFunctionContextRestoreData(qf->ctx, (void *)&fortran_ctx);
296 CeedChk(ierr);
297 } else {
298 *ctx = qf->ctx;

--- 7 unchanged lines hidden (view full) ---

306 @param qf CeedQFunction
307 @param[out] is_identity Variable to store identity status
308
309 @return An error code: 0 - success, otherwise - failure
310
311 @ref Backend
312**/
313int CeedQFunctionIsIdentity(CeedQFunction qf, bool *is_identity) {
291 CeedFortranContext fortran_ctx = NULL;
292 ierr = CeedQFunctionContextGetData(qf->ctx, CEED_MEM_HOST, &fortran_ctx);
293 CeedChk(ierr);
294 *ctx = fortran_ctx->innerctx;
295 ierr = CeedQFunctionContextRestoreData(qf->ctx, (void *)&fortran_ctx);
296 CeedChk(ierr);
297 } else {
298 *ctx = qf->ctx;

--- 7 unchanged lines hidden (view full) ---

306 @param qf CeedQFunction
307 @param[out] is_identity Variable to store identity status
308
309 @return An error code: 0 - success, otherwise - failure
310
311 @ref Backend
312**/
313int CeedQFunctionIsIdentity(CeedQFunction qf, bool *is_identity) {
314 *is_identity = qf->identity;
314 *is_identity = qf->is_identity;
315 return CEED_ERROR_SUCCESS;
316}
317
318/**
319 @brief Get backend data of a CeedQFunction
320
321 @param qf CeedQFunction
322 @param[out] data Variable to store data

--- 87 unchanged lines hidden (view full) ---

410 return CEED_ERROR_SUCCESS;
411 }
412
413 ierr = CeedCalloc(1, qf); CeedChk(ierr);
414 (*qf)->ceed = ceed;
415 ierr = CeedReference(ceed); CeedChk(ierr);
416 (*qf)->ref_count = 1;
417 (*qf)->vec_length = vec_length;
315 return CEED_ERROR_SUCCESS;
316}
317
318/**
319 @brief Get backend data of a CeedQFunction
320
321 @param qf CeedQFunction
322 @param[out] data Variable to store data

--- 87 unchanged lines hidden (view full) ---

410 return CEED_ERROR_SUCCESS;
411 }
412
413 ierr = CeedCalloc(1, qf); CeedChk(ierr);
414 (*qf)->ceed = ceed;
415 ierr = CeedReference(ceed); CeedChk(ierr);
416 (*qf)->ref_count = 1;
417 (*qf)->vec_length = vec_length;
418 (*qf)->identity = 0;
418 (*qf)->is_identity = false;
419 (*qf)->function = f;
420 size_t slen = strlen(source) + 1;
421 ierr = CeedMalloc(slen, &source_copy); CeedChk(ierr);
422 memcpy(source_copy, source, slen);
423 (*qf)->source_path = source_copy;
424 ierr = CeedCalloc(16, &(*qf)->input_fields); CeedChk(ierr);
425 ierr = CeedCalloc(16, &(*qf)->output_fields); CeedChk(ierr);
426 ierr = ceed->QFunctionCreate(*qf); CeedChk(ierr);

--- 77 unchanged lines hidden (view full) ---

504int CeedQFunctionCreateIdentity(Ceed ceed, CeedInt size, CeedEvalMode in_mode,
505 CeedEvalMode out_mode, CeedQFunction *qf) {
506 int ierr;
507
508 ierr = CeedQFunctionCreateInteriorByName(ceed, "Identity", qf); CeedChk(ierr);
509 ierr = CeedQFunctionAddInput(*qf, "input", size, in_mode); CeedChk(ierr);
510 ierr = CeedQFunctionAddOutput(*qf, "output", size, out_mode); CeedChk(ierr);
511
419 (*qf)->function = f;
420 size_t slen = strlen(source) + 1;
421 ierr = CeedMalloc(slen, &source_copy); CeedChk(ierr);
422 memcpy(source_copy, source, slen);
423 (*qf)->source_path = source_copy;
424 ierr = CeedCalloc(16, &(*qf)->input_fields); CeedChk(ierr);
425 ierr = CeedCalloc(16, &(*qf)->output_fields); CeedChk(ierr);
426 ierr = ceed->QFunctionCreate(*qf); CeedChk(ierr);

--- 77 unchanged lines hidden (view full) ---

504int CeedQFunctionCreateIdentity(Ceed ceed, CeedInt size, CeedEvalMode in_mode,
505 CeedEvalMode out_mode, CeedQFunction *qf) {
506 int ierr;
507
508 ierr = CeedQFunctionCreateInteriorByName(ceed, "Identity", qf); CeedChk(ierr);
509 ierr = CeedQFunctionAddInput(*qf, "input", size, in_mode); CeedChk(ierr);
510 ierr = CeedQFunctionAddOutput(*qf, "output", size, out_mode); CeedChk(ierr);
511
512 (*qf)->identity = 1;
512 (*qf)->is_identity = true;
513 CeedInt *size_data;
514 ierr = CeedCalloc(1, &size_data); CeedChk(ierr);
515 size_data[0] = size;
516 CeedQFunctionContext ctx;
517 ierr = CeedQFunctionContextCreate(ceed, &ctx); CeedChk(ierr);
518 ierr = CeedQFunctionContextSetData(ctx, CEED_MEM_HOST, CEED_OWN_POINTER,
519 sizeof(*size_data), (void *)size_data);
520 CeedChk(ierr);

--- 39 unchanged lines hidden (view full) ---

560
561 @return An error code: 0 - success, otherwise - failure
562
563 @ref User
564**/
565int CeedQFunctionAddInput(CeedQFunction qf, const char *field_name,
566 CeedInt size,
567 CeedEvalMode eval_mode) {
513 CeedInt *size_data;
514 ierr = CeedCalloc(1, &size_data); CeedChk(ierr);
515 size_data[0] = size;
516 CeedQFunctionContext ctx;
517 ierr = CeedQFunctionContextCreate(ceed, &ctx); CeedChk(ierr);
518 ierr = CeedQFunctionContextSetData(ctx, CEED_MEM_HOST, CEED_OWN_POINTER,
519 sizeof(*size_data), (void *)size_data);
520 CeedChk(ierr);

--- 39 unchanged lines hidden (view full) ---

560
561 @return An error code: 0 - success, otherwise - failure
562
563 @ref User
564**/
565int CeedQFunctionAddInput(CeedQFunction qf, const char *field_name,
566 CeedInt size,
567 CeedEvalMode eval_mode) {
568 if (qf->operators_set)
568 if (qf->is_immutable)
569 // LCOV_EXCL_START
570 return CeedError(qf->ceed, CEED_ERROR_MAJOR,
569 // LCOV_EXCL_START
570 return CeedError(qf->ceed, CEED_ERROR_MAJOR,
571 "QFunction cannot be changed when in use by an operator");
571 "QFunction cannot be changed after set as immutable");
572 // LCOV_EXCL_STOP
573 if ((eval_mode == CEED_EVAL_WEIGHT) && (size != 1))
574 // LCOV_EXCL_START
575 return CeedError(qf->ceed, CEED_ERROR_DIMENSION,
576 "CEED_EVAL_WEIGHT should have size 1");
577 // LCOV_EXCL_STOP
578 int ierr = CeedQFunctionFieldSet(&qf->input_fields[qf->num_input_fields],
579 field_name, size, eval_mode);

--- 14 unchanged lines hidden (view full) ---

594 \ref CEED_EVAL_GRAD to use gradients.
595
596 @return An error code: 0 - success, otherwise - failure
597
598 @ref User
599**/
600int CeedQFunctionAddOutput(CeedQFunction qf, const char *field_name,
601 CeedInt size, CeedEvalMode eval_mode) {
572 // LCOV_EXCL_STOP
573 if ((eval_mode == CEED_EVAL_WEIGHT) && (size != 1))
574 // LCOV_EXCL_START
575 return CeedError(qf->ceed, CEED_ERROR_DIMENSION,
576 "CEED_EVAL_WEIGHT should have size 1");
577 // LCOV_EXCL_STOP
578 int ierr = CeedQFunctionFieldSet(&qf->input_fields[qf->num_input_fields],
579 field_name, size, eval_mode);

--- 14 unchanged lines hidden (view full) ---

594 \ref CEED_EVAL_GRAD to use gradients.
595
596 @return An error code: 0 - success, otherwise - failure
597
598 @ref User
599**/
600int CeedQFunctionAddOutput(CeedQFunction qf, const char *field_name,
601 CeedInt size, CeedEvalMode eval_mode) {
602 if (qf->operators_set)
602 if (qf->is_immutable)
603 // LCOV_EXCL_START
604 return CeedError(qf->ceed, CEED_ERROR_MAJOR,
603 // LCOV_EXCL_START
604 return CeedError(qf->ceed, CEED_ERROR_MAJOR,
605 "QFunction cannot be changed when in use by an operator");
605 "QFunction cannot be changed after set as immutable");
606 // LCOV_EXCL_STOP
607 if (eval_mode == CEED_EVAL_WEIGHT)
608 // LCOV_EXCL_START
609 return CeedError(qf->ceed, CEED_ERROR_DIMENSION,
610 "Cannot create QFunction output with "
611 "CEED_EVAL_WEIGHT");
612 // LCOV_EXCL_STOP
613 int ierr = CeedQFunctionFieldSet(&qf->output_fields[qf->num_output_fields],
614 field_name, size, eval_mode);
615 CeedChk(ierr);
616 qf->num_output_fields++;
617 return CEED_ERROR_SUCCESS;
618}
619
620/**
621 @brief Get the CeedQFunctionFields of a CeedQFunction
622
606 // LCOV_EXCL_STOP
607 if (eval_mode == CEED_EVAL_WEIGHT)
608 // LCOV_EXCL_START
609 return CeedError(qf->ceed, CEED_ERROR_DIMENSION,
610 "Cannot create QFunction output with "
611 "CEED_EVAL_WEIGHT");
612 // LCOV_EXCL_STOP
613 int ierr = CeedQFunctionFieldSet(&qf->output_fields[qf->num_output_fields],
614 field_name, size, eval_mode);
615 CeedChk(ierr);
616 qf->num_output_fields++;
617 return CEED_ERROR_SUCCESS;
618}
619
620/**
621 @brief Get the CeedQFunctionFields of a CeedQFunction
622
623 Note: Calling this function asserts that setup is complete
624 and sets the CeedQFunction as immutable.
625
623 @param qf CeedQFunction
624 @param[out] input_fields Variable to store input_fields
625 @param[out] output_fields Variable to store output_fields
626
627 @return An error code: 0 - success, otherwise - failure
628
629 @ref Backend
630**/
631int CeedQFunctionGetFields(CeedQFunction qf, CeedInt *num_input_fields,
632 CeedQFunctionField **input_fields,
633 CeedInt *num_output_fields,
634 CeedQFunctionField **output_fields) {
626 @param qf CeedQFunction
627 @param[out] input_fields Variable to store input_fields
628 @param[out] output_fields Variable to store output_fields
629
630 @return An error code: 0 - success, otherwise - failure
631
632 @ref Backend
633**/
634int CeedQFunctionGetFields(CeedQFunction qf, CeedInt *num_input_fields,
635 CeedQFunctionField **input_fields,
636 CeedInt *num_output_fields,
637 CeedQFunctionField **output_fields) {
638 qf->is_immutable = true;
635 if (num_input_fields) *num_input_fields = qf->num_input_fields;
636 if (input_fields) *input_fields = qf->input_fields;
637 if (num_output_fields) *num_output_fields = qf->num_output_fields;
638 if (output_fields) *output_fields = qf->output_fields;
639 return CEED_ERROR_SUCCESS;
640}
641
642/**

--- 89 unchanged lines hidden (view full) ---

732 CeedChk(ierr);
733 }
734 return CEED_ERROR_SUCCESS;
735}
736
737/**
738 @brief Apply the action of a CeedQFunction
739
639 if (num_input_fields) *num_input_fields = qf->num_input_fields;
640 if (input_fields) *input_fields = qf->input_fields;
641 if (num_output_fields) *num_output_fields = qf->num_output_fields;
642 if (output_fields) *output_fields = qf->output_fields;
643 return CEED_ERROR_SUCCESS;
644}
645
646/**

--- 89 unchanged lines hidden (view full) ---

736 CeedChk(ierr);
737 }
738 return CEED_ERROR_SUCCESS;
739}
740
741/**
742 @brief Apply the action of a CeedQFunction
743
744 Note: Calling this function asserts that setup is complete
745 and sets the CeedQFunction as immutable.
746
740 @param qf CeedQFunction
741 @param Q Number of quadrature points
742 @param[in] u Array of input CeedVectors
743 @param[out] v Array of output CeedVectors
744
745 @return An error code: 0 - success, otherwise - failure
746
747 @ref User

--- 7 unchanged lines hidden (view full) ---

755 "Backend does not support QFunctionApply");
756 // LCOV_EXCL_STOP
757 if (Q % qf->vec_length)
758 // LCOV_EXCL_START
759 return CeedError(qf->ceed, CEED_ERROR_DIMENSION,
760 "Number of quadrature points %d must be a "
761 "multiple of %d", Q, qf->vec_length);
762 // LCOV_EXCL_STOP
747 @param qf CeedQFunction
748 @param Q Number of quadrature points
749 @param[in] u Array of input CeedVectors
750 @param[out] v Array of output CeedVectors
751
752 @return An error code: 0 - success, otherwise - failure
753
754 @ref User

--- 7 unchanged lines hidden (view full) ---

762 "Backend does not support QFunctionApply");
763 // LCOV_EXCL_STOP
764 if (Q % qf->vec_length)
765 // LCOV_EXCL_START
766 return CeedError(qf->ceed, CEED_ERROR_DIMENSION,
767 "Number of quadrature points %d must be a "
768 "multiple of %d", Q, qf->vec_length);
769 // LCOV_EXCL_STOP
770 qf->is_immutable = true;
763 ierr = qf->Apply(qf, Q, u, v); CeedChk(ierr);
764 return CEED_ERROR_SUCCESS;
765}
766
767/**
768 @brief Destroy a CeedQFunction
769
770 @param qf CeedQFunction to destroy

--- 36 unchanged lines hidden ---
771 ierr = qf->Apply(qf, Q, u, v); CeedChk(ierr);
772 return CEED_ERROR_SUCCESS;
773}
774
775/**
776 @brief Destroy a CeedQFunction
777
778 @param qf CeedQFunction to destroy

--- 36 unchanged lines hidden ---