xref: /honee/include/petsc-ceed.h (revision 8a8cb6e06ce4728cc6d80ca92f8de31da49852e5)
1*ae2b091fSJames Wright // SPDX-FileCopyrightText: Copyright (c) 2017-2024, HONEE contributors.
2*ae2b091fSJames Wright // SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause
340d80af1SJames Wright #pragma once
440d80af1SJames Wright 
540d80af1SJames Wright #include <petscsys.h>
640d80af1SJames Wright 
740d80af1SJames Wright #if defined(__clang_analyzer__)
840d80af1SJames Wright #define PETSC_CEED_EXTERN extern
940d80af1SJames Wright #elif defined(__cplusplus)
1040d80af1SJames Wright #define PETSC_CEED_EXTERN extern "C"
1140d80af1SJames Wright #else
1240d80af1SJames Wright #define PETSC_CEED_EXTERN extern
1340d80af1SJames Wright #endif
1440d80af1SJames Wright 
1540d80af1SJames Wright #if defined(__clang_analyzer__)
1640d80af1SJames Wright #define PETSC_CEED_INTERN
1740d80af1SJames Wright #else
1840d80af1SJames Wright #define PETSC_CEED_INTERN PETSC_CEED_EXTERN __attribute__((visibility("hidden")))
1940d80af1SJames Wright #endif
2040d80af1SJames Wright 
2140d80af1SJames Wright /**
2240d80af1SJames Wright   @brief Calls a libCEED function and then checks the resulting error code.
2340d80af1SJames Wright   If the error code is non-zero, then a PETSc error is set with the libCEED error message.
2440d80af1SJames Wright **/
2540d80af1SJames Wright #ifndef PetscCallCeed
2640d80af1SJames Wright #define PetscCallCeed(ceed_, ...)                                   \
2740d80af1SJames Wright   do {                                                              \
2840d80af1SJames Wright     int ierr_q_;                                                    \
2940d80af1SJames Wright     PetscStackUpdateLine;                                           \
3040d80af1SJames Wright     ierr_q_ = __VA_ARGS__;                                          \
3140d80af1SJames Wright     if (PetscUnlikely(ierr_q_ != CEED_ERROR_SUCCESS)) {             \
3240d80af1SJames Wright       const char *error_message;                                    \
3340d80af1SJames Wright       CeedGetErrorMessage(ceed_, &error_message);                   \
3440d80af1SJames Wright       SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, "%s", error_message); \
3540d80af1SJames Wright     }                                                               \
3640d80af1SJames Wright   } while (0)
3740d80af1SJames Wright #endif
38