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 /// @file 18 /// Public header for user and utility components of libCEED 19 #ifndef _ceed_h 20 #define _ceed_h 21 22 /// @defgroup Ceed Ceed: core components 23 /// @defgroup CeedVector CeedVector: storing and manipulating vectors 24 /// @defgroup CeedElemRestriction CeedElemRestriction: restriction from local vectors to elements 25 /// @defgroup CeedBasis CeedBasis: fully discrete finite element-like objects 26 /// @defgroup CeedQFunction CeedQFunction: independent operations at quadrature points 27 /// @defgroup CeedOperator CeedOperator: composed FE-type operations on vectors 28 /// 29 /// @page FunctionCategories libCEED: Types of Functions 30 /// libCEED provides three different header files depending upon the type of 31 /// functions a user requires. 32 /// @section Utility Utility Functions 33 /// These functions are intended general utilities that may be useful to 34 /// libCEED developers and users. These functions can generally be found in 35 /// "ceed.h". 36 /// @section User User Functions 37 /// These functions are intended to be used by general users of libCEED 38 /// and can generally be found in "ceed.h". 39 /// @section Advanced Advanced Functions 40 /// These functions are intended to be used by advanced users of libCEED 41 /// and can generally be found in "ceed.h". 42 /// @section Backend Backend Developer Functions 43 /// These functions are intended to be used by backend developers of 44 /// libCEED and can generally be found in "ceed-backend.h". 45 /// @section Developer Library Developer Functions 46 /// These functions are intended to be used by library developers of 47 /// libCEED and can generally be found in "ceed-impl.h". 48 49 /** 50 CEED_EXTERN is used in this header to denote all publicly visible symbols. 51 52 No other file should declare publicly visible symbols, thus it should never be 53 used outside ceed.h. 54 */ 55 #ifdef __cplusplus 56 # define CEED_EXTERN extern "C" 57 #else 58 # define CEED_EXTERN extern 59 #endif 60 61 /** 62 @ingroup CeedQFunction 63 This macro populates the correct function annotations for User QFunction 64 source for code generation backends or populates default values for CPU 65 backends. It also creates a variable `name_loc` populated with the correct 66 source path for creating the respective User QFunction. 67 **/ 68 #ifndef CEED_QFUNCTION 69 #define CEED_QFUNCTION(name) \ 70 static const char name ## _loc[] = __FILE__ ":" #name; \ 71 static int name 72 #endif 73 74 /** 75 @ingroup CeedQFunction 76 This macro populates the correct function annotations for User QFunction 77 helper function source for code generation backends or populates default 78 values for CPU backends. 79 **/ 80 #ifndef CEED_QFUNCTION_HELPER 81 #define CEED_QFUNCTION_HELPER static inline 82 #endif 83 84 /** 85 @ingroup CeedQFunction 86 Using VLA syntax to reshape User QFunction inputs and outputs can make 87 user code more readable. VLA is a C99 feature that is not supported by 88 the C++ dialect used by CUDA. This macro allows users to use the VLA 89 syntax with the CUDA backends. 90 **/ 91 #ifndef CEED_Q_VLA 92 # define CEED_Q_VLA Q 93 #endif 94 95 /** 96 @ingroup Ceed 97 This macro provides the appropriate SIMD Pragma for the compilation 98 environment. Code generation backends may redefine this macro, as needed. 99 **/ 100 #ifndef CeedPragmaSIMD 101 # if defined(__INTEL_COMPILER) 102 # define CeedPragmaSIMD _Pragma("vector") 103 // Cannot use Intel pragma ivdep because it miscompiles unpacking symmetric tensors, as in 104 // Poisson2DApply, where the SIMD loop body contains temporaries such as the following. 105 // 106 // const CeedScalar dXdxdXdxT[2][2] = {{qd[i+0*Q], qd[i+2*Q]}, 107 // {qd[i+2*Q], qd[i+1*Q]}}; 108 // for (int j=0; j<2; j++) 109 // vg[i+j*Q] = (du[0] * dXdxdXdxT[0][j] + du[1] * dXdxdXdxT[1][j]); 110 // 111 // Miscompilation with pragma ivdep observed with icc (ICC) 19.0.5.281 20190815 112 // at -O2 and above. 113 # elif defined(__GNUC__) && __GNUC__ >= 5 114 # define CeedPragmaSIMD _Pragma("GCC ivdep") 115 # elif defined(_OPENMP) && _OPENMP >= 201307 // OpenMP-4.0 (July, 2013) 116 # define CeedPragmaSIMD _Pragma("omp simd") 117 # else 118 # define CeedPragmaSIMD 119 # endif 120 #endif 121 122 #include <stdarg.h> 123 #include <stdbool.h> 124 #include <stddef.h> 125 #include <stdint.h> 126 #include <stdio.h> 127 128 /// Integer type, used for indexing 129 /// @ingroup Ceed 130 typedef int32_t CeedInt; 131 132 /// Integer type, used array sizes 133 /// @ingroup Ceed 134 typedef ptrdiff_t CeedSize; 135 136 /// Scalar (floating point) types 137 /// 138 /// @ingroup Ceed 139 typedef enum { 140 /// Single precision 141 CEED_SCALAR_FP32, 142 /// Double precision 143 CEED_SCALAR_FP64 144 } CeedScalarType; 145 /// Base scalar type for the library to use: change which header is 146 /// included to change the precision. 147 #include "ceed-f64.h" 148 149 /// Library context created by CeedInit() 150 /// @ingroup CeedUser 151 typedef struct Ceed_private *Ceed; 152 /// Non-blocking Ceed interfaces return a CeedRequest. 153 /// To perform an operation immediately, pass \ref CEED_REQUEST_IMMEDIATE instead. 154 /// @ingroup CeedUser 155 typedef struct CeedRequest_private *CeedRequest; 156 /// Handle for vectors over the field \ref CeedScalar 157 /// @ingroup CeedVectorUser 158 typedef struct CeedVector_private *CeedVector; 159 /// Handle for object describing restriction to elements 160 /// @ingroup CeedElemRestrictionUser 161 typedef struct CeedElemRestriction_private *CeedElemRestriction; 162 /// Handle for object describing discrete finite element evaluations 163 /// @ingroup CeedBasisUser 164 typedef struct CeedBasis_private *CeedBasis; 165 /// Handle for object describing CeedQFunction fields 166 /// @ingroup CeedQFunctionBackend 167 typedef struct CeedQFunctionField_private *CeedQFunctionField; 168 /// Handle for object describing functions evaluated independently at quadrature points 169 /// @ingroup CeedQFunctionUser 170 typedef struct CeedQFunction_private *CeedQFunction; 171 /// Handle for object describing CeedOperator fields 172 /// @ingroup CeedOperatorBackend 173 typedef struct CeedOperatorField_private *CeedOperatorField; 174 /// Handle for object describing context data for CeedQFunctions 175 /// @ingroup CeedQFunctionUser 176 typedef struct CeedQFunctionContext_private *CeedQFunctionContext; 177 /// Handle for object describing registered fields for CeedQFunctionContext 178 /// @ingroup CeedQFunctionUser 179 typedef struct CeedContextFieldLabel_private *CeedContextFieldLabel; 180 /// Handle for object describing FE-type operators acting on vectors 181 /// 182 /// Given an element restriction \f$E\f$, basis evaluator \f$B\f$, and 183 /// quadrature function\f$f\f$, a CeedOperator expresses operations of the form 184 /// $$ E^T B^T f(B E u) $$ 185 /// acting on the vector \f$u\f$. 186 /// @ingroup CeedOperatorUser 187 typedef struct CeedOperator_private *CeedOperator; 188 189 CEED_EXTERN int CeedRegistryGetList(size_t *n, char ***const resources, CeedInt **array); 190 CEED_EXTERN int CeedInit(const char *resource, Ceed *ceed); 191 CEED_EXTERN int CeedReferenceCopy(Ceed ceed, Ceed *ceed_copy); 192 CEED_EXTERN int CeedGetResource(Ceed ceed, const char **resource); 193 CEED_EXTERN int CeedIsDeterministic(Ceed ceed, bool *is_deterministic); 194 CEED_EXTERN int CeedView(Ceed ceed, FILE *stream); 195 CEED_EXTERN int CeedDestroy(Ceed *ceed); 196 197 CEED_EXTERN int CeedErrorImpl(Ceed, const char *, int, const char *, int, 198 const char *, ...); 199 /// Raise an error on ceed object 200 /// 201 /// @param ceed Ceed library context or NULL 202 /// @param ecode Error code (int) 203 /// @param ... printf-style format string followed by arguments as needed 204 /// 205 /// @ingroup Ceed 206 /// @sa CeedSetErrorHandler() 207 #if defined(__clang__) 208 /// Use nonstandard ternary to convince the compiler/clang-tidy that this 209 /// function never returns zero. 210 # define CeedError(ceed, ecode, ...) \ 211 (CeedErrorImpl((ceed), __FILE__, __LINE__, __func__, (ecode), __VA_ARGS__), (ecode)) 212 #else 213 # define CeedError(ceed, ecode, ...) \ 214 CeedErrorImpl((ceed), __FILE__, __LINE__, __func__, (ecode), __VA_ARGS__) ?: (ecode) 215 #endif 216 217 /// Ceed error handlers 218 CEED_EXTERN int CeedErrorReturn(Ceed, const char *, int, const char *, int, 219 const char *, va_list *); 220 CEED_EXTERN int CeedErrorStore(Ceed, const char *, int, const char *, int, 221 const char *, va_list *); 222 CEED_EXTERN int CeedErrorAbort(Ceed, const char *, int, const char *, int, 223 const char *, va_list *); 224 CEED_EXTERN int CeedErrorExit(Ceed, const char *, int, const char *, int, 225 const char *, va_list *); 226 typedef int (*CeedErrorHandler)(Ceed, const char *, int, 227 const char *, int, const char *, 228 va_list *); 229 CEED_EXTERN int CeedSetErrorHandler(Ceed ceed, CeedErrorHandler eh); 230 CEED_EXTERN int CeedGetErrorMessage(Ceed, const char **err_msg); 231 CEED_EXTERN int CeedResetErrorMessage(Ceed, const char **err_msg); 232 233 /// libCEED library version numbering 234 /// @ingroup Ceed 235 #define CEED_VERSION_MAJOR 0 236 #define CEED_VERSION_MINOR 9 237 #define CEED_VERSION_PATCH 0 238 #define CEED_VERSION_RELEASE false 239 240 /// Compile-time check that the the current library version is at least as 241 /// recent as the specified version. This macro is typically used in 242 /// @code 243 /// #if CEED_VERSION_GE(0, 8, 0) 244 /// code path that needs at least 0.8.0 245 /// #else 246 /// fallback code for older versions 247 /// #endif 248 /// @endcode 249 /// 250 /// A non-release version always compares as positive infinity. 251 /// 252 /// @param major Major version 253 /// @param minor Minor version 254 /// @param patch Patch (subminor) version 255 /// 256 /// @ingroup Ceed 257 /// @sa CeedGetVersion() 258 #define CEED_VERSION_GE(major, minor, patch) \ 259 (!CEED_VERSION_RELEASE || \ 260 (CEED_VERSION_MAJOR > major || \ 261 (CEED_VERSION_MAJOR == major && \ 262 (CEED_VERSION_MINOR > minor || \ 263 (CEED_VERSION_MINOR == minor && CEED_VERSION_PATCH >= patch))))) 264 265 CEED_EXTERN int CeedGetVersion(int *major, int *minor, int *patch, 266 bool *release); 267 268 CEED_EXTERN int CeedGetScalarType(CeedScalarType *scalar_type); 269 270 /// Ceed Errors 271 /// 272 /// This enum is used to specify the type of error returned by a function. 273 /// A zero error code is success, negative error codes indicate terminal errors 274 /// and positive error codes indicate nonterminal errors. With nonterminal errors 275 /// the object state has not been modifiend, but with terminal errors the object 276 /// data is likely modified or corrupted. 277 /// @ingroup Ceed 278 typedef enum { 279 /// Success error code 280 CEED_ERROR_SUCCESS = 0, 281 /// Minor error, generic 282 CEED_ERROR_MINOR = 1, 283 /// Minor error, dimension mismatch in inputs 284 CEED_ERROR_DIMENSION = 2, 285 /// Minor error, incomplete object setup 286 CEED_ERROR_INCOMPLETE = 3, 287 /// Minor error, incompatible arguments/configuration 288 CEED_ERROR_INCOMPATIBLE = 4, 289 /// Minor error, access lock problem 290 CEED_ERROR_ACCESS = 5, 291 /// Major error, generic 292 CEED_ERROR_MAJOR = -1, 293 /// Major error, internal backend error 294 CEED_ERROR_BACKEND = -2, 295 /// Major error, operation unsupported by current backend 296 CEED_ERROR_UNSUPPORTED = -3, 297 } CeedErrorType; 298 CEED_EXTERN const char *const *CeedErrorTypes; 299 300 /// Specify memory type 301 /// 302 /// Many Ceed interfaces take or return pointers to memory. This enum is used to 303 /// specify where the memory being provided or requested must reside. 304 /// @ingroup Ceed 305 typedef enum { 306 /// Memory resides on the host 307 CEED_MEM_HOST, 308 /// Memory resides on a device (corresponding to \ref Ceed resource) 309 CEED_MEM_DEVICE, 310 } CeedMemType; 311 CEED_EXTERN const char *const CeedMemTypes[]; 312 313 CEED_EXTERN int CeedGetPreferredMemType(Ceed ceed, CeedMemType *type); 314 315 /// Conveys ownership status of arrays passed to Ceed interfaces. 316 /// @ingroup Ceed 317 typedef enum { 318 /// Implementation will copy the values and not store the passed pointer. 319 CEED_COPY_VALUES, 320 /// Implementation can use and modify the data provided by the user, but does 321 /// not take ownership. 322 CEED_USE_POINTER, 323 /// Implementation takes ownership of the pointer and will free using 324 /// CeedFree() when done using it. The user should not assume that the 325 /// pointer remains valid after ownership has been transferred. Note that 326 /// arrays allocated using C++ operator new or other allocators cannot 327 /// generally be freed using CeedFree(). CeedFree() is capable of freeing any 328 /// memory that can be freed using free(3). 329 CEED_OWN_POINTER, 330 } CeedCopyMode; 331 CEED_EXTERN const char *const CeedCopyModes[]; 332 333 /// Denotes type of vector norm to be computed 334 /// @ingroup CeedVector 335 typedef enum { 336 /// L_1 norm: sum_i |x_i| 337 CEED_NORM_1, 338 /// L_2 norm: sqrt(sum_i |x_i|^2) 339 CEED_NORM_2, 340 /// L_Infinity norm: max_i |x_i| 341 CEED_NORM_MAX, 342 } CeedNormType; 343 344 CEED_EXTERN int CeedVectorCreate(Ceed ceed, CeedSize len, CeedVector *vec); 345 CEED_EXTERN int CeedVectorReferenceCopy(CeedVector vec, CeedVector *vec_copy); 346 CEED_EXTERN int CeedVectorSetArray(CeedVector vec, CeedMemType mem_type, 347 CeedCopyMode copy_mode, CeedScalar *array); 348 CEED_EXTERN int CeedVectorSetValue(CeedVector vec, CeedScalar value); 349 CEED_EXTERN int CeedVectorSyncArray(CeedVector vec, CeedMemType mem_type); 350 CEED_EXTERN int CeedVectorTakeArray(CeedVector vec, CeedMemType mem_type, 351 CeedScalar **array); 352 CEED_EXTERN int CeedVectorGetArray(CeedVector vec, CeedMemType mem_type, 353 CeedScalar **array); 354 CEED_EXTERN int CeedVectorGetArrayRead(CeedVector vec, CeedMemType mem_type, 355 const CeedScalar **array); 356 CEED_EXTERN int CeedVectorGetArrayWrite(CeedVector vec, CeedMemType mem_type, 357 CeedScalar **array); 358 CEED_EXTERN int CeedVectorRestoreArray(CeedVector vec, CeedScalar **array); 359 CEED_EXTERN int CeedVectorRestoreArrayRead(CeedVector vec, 360 const CeedScalar **array); 361 CEED_EXTERN int CeedVectorNorm(CeedVector vec, CeedNormType type, 362 CeedScalar *norm); 363 CEED_EXTERN int CeedVectorScale(CeedVector x, CeedScalar alpha); 364 CEED_EXTERN int CeedVectorAXPY(CeedVector y, CeedScalar alpha, CeedVector x); 365 CEED_EXTERN int CeedVectorPointwiseMult(CeedVector w, CeedVector x, CeedVector y); 366 CEED_EXTERN int CeedVectorReciprocal(CeedVector vec); 367 CEED_EXTERN int CeedVectorView(CeedVector vec, const char *fp_fmt, FILE *stream); 368 CEED_EXTERN int CeedVectorGetCeed(CeedVector vec, Ceed *ceed); 369 CEED_EXTERN int CeedVectorGetLength(CeedVector vec, CeedSize *length); 370 CEED_EXTERN int CeedVectorDestroy(CeedVector *vec); 371 372 CEED_EXTERN CeedRequest *const CEED_REQUEST_IMMEDIATE; 373 CEED_EXTERN CeedRequest *const CEED_REQUEST_ORDERED; 374 CEED_EXTERN int CeedRequestWait(CeedRequest *req); 375 376 /// Argument for CeedOperatorSetField that vector is collocated with 377 /// quadrature points, used with QFunction eval mode CEED_EVAL_NONE 378 /// or CEED_EVAL_INTERP only, not with CEED_EVAL_GRAD, CEED_EVAL_DIV, 379 /// or CEED_EVAL_CURL 380 /// @ingroup CeedBasis 381 CEED_EXTERN const CeedBasis CEED_BASIS_COLLOCATED; 382 383 /// Argument for CeedOperatorSetField to use active input or output 384 /// @ingroup CeedVector 385 CEED_EXTERN const CeedVector CEED_VECTOR_ACTIVE; 386 387 /// Argument for CeedOperatorSetField to use no vector, used with 388 /// qfunction input with eval mode CEED_EVAL_WEIGHT 389 /// @ingroup CeedVector 390 CEED_EXTERN const CeedVector CEED_VECTOR_NONE; 391 392 /// Argument for CeedOperatorSetField to use no ElemRestriction, only used with 393 /// eval mode CEED_EVAL_WEIGHT. 394 /// @ingroup CeedElemRestriction 395 CEED_EXTERN const CeedElemRestriction CEED_ELEMRESTRICTION_NONE; 396 397 /// Argument for CeedOperatorCreate that QFunction is not created by user. 398 /// Only used for QFunctions dqf and dqfT. If implemented, a backend may 399 /// attempt to provide the action of these QFunctions. 400 /// @ingroup CeedQFunction 401 CEED_EXTERN const CeedQFunction CEED_QFUNCTION_NONE; 402 403 /// Denotes whether a linear transformation or its transpose should be applied 404 /// @ingroup CeedBasis 405 typedef enum { 406 /// Apply the linear transformation 407 CEED_NOTRANSPOSE, 408 /// Apply the transpose 409 CEED_TRANSPOSE 410 } CeedTransposeMode; 411 CEED_EXTERN const char *const CeedTransposeModes[]; 412 413 /// Argument for CeedElemRestrictionCreateStrided that L-vector is in 414 /// the Ceed backend's preferred layout. This argument should only be used 415 /// with vectors created by a Ceed backend. 416 /// @ingroup CeedElemRestriction 417 CEED_EXTERN const CeedInt CEED_STRIDES_BACKEND[3]; 418 419 CEED_EXTERN int CeedElemRestrictionCreate(Ceed ceed, CeedInt num_elem, 420 CeedInt elem_size, CeedInt num_comp, CeedInt comp_stride, CeedSize l_size, 421 CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *offsets, 422 CeedElemRestriction *rstr); 423 CEED_EXTERN int CeedElemRestrictionCreateOriented(Ceed ceed, CeedInt num_elem, 424 CeedInt elem_size, CeedInt num_comp, CeedInt comp_stride, CeedSize l_size, 425 CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *offsets, 426 const bool *orient, CeedElemRestriction *rstr); 427 CEED_EXTERN int CeedElemRestrictionCreateStrided(Ceed ceed, 428 CeedInt num_elem, CeedInt elem_size, CeedInt num_comp, CeedSize l_size, 429 const CeedInt strides[3], CeedElemRestriction *rstr); 430 CEED_EXTERN int CeedElemRestrictionCreateBlocked(Ceed ceed, CeedInt num_elem, 431 CeedInt elem_size, CeedInt blk_size, CeedInt num_comp, CeedInt comp_stride, 432 CeedSize l_size, CeedMemType mem_type, CeedCopyMode copy_mode, 433 const CeedInt *offsets, CeedElemRestriction *rstr); 434 CEED_EXTERN int CeedElemRestrictionCreateBlockedStrided(Ceed ceed, 435 CeedInt num_elem, CeedInt elem_size, CeedInt blk_size, CeedInt num_comp, 436 CeedSize l_size, const CeedInt strides[3], CeedElemRestriction *rstr); 437 CEED_EXTERN int CeedElemRestrictionReferenceCopy(CeedElemRestriction rstr, 438 CeedElemRestriction *rstr_copy); 439 CEED_EXTERN int CeedElemRestrictionCreateVector(CeedElemRestriction rstr, 440 CeedVector *lvec, CeedVector *evec); 441 CEED_EXTERN int CeedElemRestrictionApply(CeedElemRestriction rstr, 442 CeedTransposeMode t_mode, CeedVector u, CeedVector ru, CeedRequest *request); 443 CEED_EXTERN int CeedElemRestrictionApplyBlock(CeedElemRestriction rstr, 444 CeedInt block, CeedTransposeMode t_mode, CeedVector u, CeedVector ru, 445 CeedRequest *request); 446 CEED_EXTERN int CeedElemRestrictionGetCeed(CeedElemRestriction rstr, 447 Ceed *ceed); 448 CEED_EXTERN int CeedElemRestrictionGetCompStride(CeedElemRestriction rstr, 449 CeedInt *comp_stride); 450 CEED_EXTERN int CeedElemRestrictionGetNumElements(CeedElemRestriction rstr, 451 CeedInt *num_elem); 452 CEED_EXTERN int CeedElemRestrictionGetElementSize(CeedElemRestriction rstr, 453 CeedInt *elem_size); 454 CEED_EXTERN int CeedElemRestrictionGetLVectorSize(CeedElemRestriction rstr, 455 CeedSize *l_size); 456 CEED_EXTERN int CeedElemRestrictionGetNumComponents(CeedElemRestriction rstr, 457 CeedInt *num_comp); 458 CEED_EXTERN int CeedElemRestrictionGetNumBlocks(CeedElemRestriction rstr, 459 CeedInt *num_blk); 460 CEED_EXTERN int CeedElemRestrictionGetBlockSize(CeedElemRestriction rstr, 461 CeedInt *blk_size); 462 CEED_EXTERN int CeedElemRestrictionGetMultiplicity(CeedElemRestriction rstr, 463 CeedVector mult); 464 CEED_EXTERN int CeedElemRestrictionView(CeedElemRestriction rstr, FILE *stream); 465 CEED_EXTERN int CeedElemRestrictionDestroy(CeedElemRestriction *rstr); 466 467 // The formalism here is that we have the structure 468 // \int_\Omega v^T f_0(u, \nabla u, qdata) + (\nabla v)^T f_1(u, \nabla u, qdata) 469 // where gradients are with respect to the reference element. 470 471 /// Basis evaluation mode 472 /// 473 /// Modes can be bitwise ORed when passing to most functions. 474 /// @ingroup CeedBasis 475 typedef enum { 476 /// Perform no evaluation (either because there is no data or it is already at 477 /// quadrature points) 478 CEED_EVAL_NONE = 0, 479 /// Interpolate from nodes to quadrature points 480 CEED_EVAL_INTERP = 1, 481 /// Evaluate gradients at quadrature points from input in a nodal basis 482 CEED_EVAL_GRAD = 2, 483 /// Evaluate divergence at quadrature points from input in a nodal basis 484 CEED_EVAL_DIV = 4, 485 /// Evaluate curl at quadrature points from input in a nodal basis 486 CEED_EVAL_CURL = 8, 487 /// Using no input, evaluate quadrature weights on the reference element 488 CEED_EVAL_WEIGHT = 16, 489 } CeedEvalMode; 490 CEED_EXTERN const char *const CeedEvalModes[]; 491 492 /// Type of quadrature; also used for location of nodes 493 /// @ingroup CeedBasis 494 typedef enum { 495 /// Gauss-Legendre quadrature 496 CEED_GAUSS = 0, 497 /// Gauss-Legendre-Lobatto quadrature 498 CEED_GAUSS_LOBATTO = 1, 499 } CeedQuadMode; 500 CEED_EXTERN const char *const CeedQuadModes[]; 501 502 /// Type of basis shape to create non-tensor H1 element basis 503 /// 504 /// Dimension can be extracted with bitwise AND 505 /// (CeedElemTopology & 2**(dim + 2)) == TRUE 506 /// @ingroup CeedBasis 507 typedef enum { 508 /// Line 509 CEED_TOPOLOGY_LINE = 1 << 16 | 0, 510 /// Triangle - 2D shape 511 CEED_TOPOLOGY_TRIANGLE = 2 << 16 | 1, 512 /// Quadralateral - 2D shape 513 CEED_TOPOLOGY_QUAD = 2 << 16 | 2, 514 /// Tetrahedron - 3D shape 515 CEED_TOPOLOGY_TET = 3 << 16 | 3, 516 /// Pyramid - 3D shape 517 CEED_TOPOLOGY_PYRAMID = 3 << 16 | 4, 518 /// Prism - 3D shape 519 CEED_TOPOLOGY_PRISM = 3 << 16 | 5, 520 /// Hexehedron - 3D shape 521 CEED_TOPOLOGY_HEX = 3 << 16 | 6, 522 } CeedElemTopology; 523 CEED_EXTERN const char *const CeedElemTopologies[]; 524 525 CEED_EXTERN int CeedBasisCreateTensorH1Lagrange(Ceed ceed, CeedInt dim, 526 CeedInt num_comp, CeedInt P, CeedInt Q, CeedQuadMode quad_mode, CeedBasis *basis); 527 CEED_EXTERN int CeedBasisCreateTensorH1(Ceed ceed, CeedInt dim, CeedInt num_comp, 528 CeedInt P_1d, CeedInt Q_1d, 529 const CeedScalar *interp_1d, 530 const CeedScalar *grad_1d, 531 const CeedScalar *q_ref_1d, 532 const CeedScalar *q_weight_1d, 533 CeedBasis *basis); 534 CEED_EXTERN int CeedBasisCreateH1(Ceed ceed, CeedElemTopology topo, 535 CeedInt num_comp, 536 CeedInt num_nodes, CeedInt nqpts, 537 const CeedScalar *interp, 538 const CeedScalar *grad, 539 const CeedScalar *q_ref, 540 const CeedScalar *q_weights, CeedBasis *basis); 541 CEED_EXTERN int CeedBasisCreateHdiv(Ceed ceed, CeedElemTopology topo, 542 CeedInt num_comp, 543 CeedInt num_nodes, CeedInt nqpts, 544 const CeedScalar *interp, 545 const CeedScalar *div, 546 const CeedScalar *q_ref, 547 const CeedScalar *q_weights, CeedBasis *basis); 548 CEED_EXTERN int CeedBasisReferenceCopy(CeedBasis basis, CeedBasis *basis_copy); 549 CEED_EXTERN int CeedBasisView(CeedBasis basis, FILE *stream); 550 CEED_EXTERN int CeedBasisApply(CeedBasis basis, CeedInt num_elem, 551 CeedTransposeMode t_mode, 552 CeedEvalMode eval_mode, CeedVector u, CeedVector v); 553 CEED_EXTERN int CeedBasisGetCeed(CeedBasis basis, Ceed *ceed); 554 CEED_EXTERN int CeedBasisGetDimension(CeedBasis basis, CeedInt *dim); 555 CEED_EXTERN int CeedBasisGetTopology(CeedBasis basis, CeedElemTopology *topo); 556 CEED_EXTERN int CeedBasisGetNumQuadratureComponents(CeedBasis basis, CeedInt *Q_comp); 557 CEED_EXTERN int CeedBasisGetNumComponents(CeedBasis basis, CeedInt *num_comp); 558 CEED_EXTERN int CeedBasisGetNumNodes(CeedBasis basis, CeedInt *P); 559 CEED_EXTERN int CeedBasisGetNumNodes1D(CeedBasis basis, CeedInt *P_1d); 560 CEED_EXTERN int CeedBasisGetNumQuadraturePoints(CeedBasis basis, CeedInt *Q); 561 CEED_EXTERN int CeedBasisGetNumQuadraturePoints1D(CeedBasis basis, 562 CeedInt *Q_1d); 563 CEED_EXTERN int CeedBasisGetQRef(CeedBasis basis, const CeedScalar **q_ref); 564 CEED_EXTERN int CeedBasisGetQWeights(CeedBasis basis, 565 const CeedScalar **q_weights); 566 CEED_EXTERN int CeedBasisGetInterp(CeedBasis basis, const CeedScalar **interp); 567 CEED_EXTERN int CeedBasisGetInterp1D(CeedBasis basis, 568 const CeedScalar **interp_1d); 569 CEED_EXTERN int CeedBasisGetGrad(CeedBasis basis, const CeedScalar **grad); 570 CEED_EXTERN int CeedBasisGetGrad1D(CeedBasis basis, const CeedScalar **grad_1d); 571 CEED_EXTERN int CeedBasisGetDiv(CeedBasis basis, const CeedScalar **div); 572 CEED_EXTERN int CeedBasisDestroy(CeedBasis *basis); 573 574 CEED_EXTERN int CeedGaussQuadrature(CeedInt Q, CeedScalar *q_ref_1d, 575 CeedScalar *q_weight_1d); 576 CEED_EXTERN int CeedLobattoQuadrature(CeedInt Q, CeedScalar *q_ref_1d, 577 CeedScalar *q_weight_1d); 578 CEED_EXTERN int CeedQRFactorization(Ceed ceed, CeedScalar *mat, CeedScalar *tau, 579 CeedInt m, CeedInt n); 580 CEED_EXTERN int CeedSymmetricSchurDecomposition(Ceed ceed, CeedScalar *mat, 581 CeedScalar *lambda, CeedInt n); 582 CEED_EXTERN int CeedSimultaneousDiagonalization(Ceed ceed, CeedScalar *mat_A, 583 CeedScalar *mat_B, CeedScalar *x, CeedScalar *lambda, CeedInt n); 584 585 /** Handle for the user provided CeedQFunction callback function 586 587 @param[in,out] ctx User-defined context set using CeedQFunctionSetContext() or NULL 588 @param[in] Q Number of quadrature points at which to evaluate 589 @param[in] in Array of pointers to each input argument in the order provided 590 by the user in CeedQFunctionAddInput(). Each array has shape 591 `[dim, num_comp, Q]` where `dim` is the geometric dimension for 592 \ref CEED_EVAL_GRAD (`dim=1` for \ref CEED_EVAL_INTERP) and 593 `num_comp` is the number of field components (`num_comp=1` for 594 scalar fields). This results in indexing the `i`th input at 595 quadrature point `j` as `in[i][(d*num_comp + c)*Q + j]`. 596 @param[out] out Array of pointers to each output array in the order provided 597 using CeedQFunctionAddOutput(). The shapes are as above for 598 \a in. 599 600 @return An error code: 0 - success, otherwise - failure 601 602 @ingroup CeedQFunction 603 **/ 604 typedef int (*CeedQFunctionUser)(void *ctx, const CeedInt Q, 605 const CeedScalar *const *in, 606 CeedScalar *const *out); 607 608 CEED_EXTERN int CeedQFunctionCreateInterior(Ceed ceed, CeedInt vec_length, 609 CeedQFunctionUser f, const char *source, CeedQFunction *qf); 610 CEED_EXTERN int CeedQFunctionCreateInteriorByName(Ceed ceed, const char *name, 611 CeedQFunction *qf); 612 CEED_EXTERN int CeedQFunctionCreateIdentity(Ceed ceed, CeedInt size, 613 CeedEvalMode in_mode, CeedEvalMode out_mode, CeedQFunction *qf); 614 CEED_EXTERN int CeedQFunctionReferenceCopy(CeedQFunction qf, CeedQFunction *qf_copy); 615 CEED_EXTERN int CeedQFunctionAddInput(CeedQFunction qf, const char *field_name, 616 CeedInt size, CeedEvalMode eval_mode); 617 CEED_EXTERN int CeedQFunctionAddOutput(CeedQFunction qf, const char *field_name, 618 CeedInt size, CeedEvalMode eval_mode); 619 CEED_EXTERN int CeedQFunctionGetFields(CeedQFunction qf, 620 CeedInt *num_input_fields, 621 CeedQFunctionField **input_fields, 622 CeedInt *num_output_fields, 623 CeedQFunctionField **output_fields); 624 CEED_EXTERN int CeedQFunctionSetContext(CeedQFunction qf, 625 CeedQFunctionContext ctx); 626 CEED_EXTERN int CeedQFunctionSetContextWritable(CeedQFunction qf, bool is_writable); 627 CEED_EXTERN int CeedQFunctionView(CeedQFunction qf, FILE *stream); 628 CEED_EXTERN int CeedQFunctionGetCeed(CeedQFunction qf, Ceed *ceed); 629 CEED_EXTERN int CeedQFunctionApply(CeedQFunction qf, CeedInt Q, 630 CeedVector *u, CeedVector *v); 631 CEED_EXTERN int CeedQFunctionDestroy(CeedQFunction *qf); 632 633 CEED_EXTERN int CeedQFunctionFieldGetName(CeedQFunctionField qf_field, 634 char **field_name); 635 CEED_EXTERN int CeedQFunctionFieldGetSize(CeedQFunctionField qf_field, 636 CeedInt *size); 637 CEED_EXTERN int CeedQFunctionFieldGetEvalMode(CeedQFunctionField qf_field, 638 CeedEvalMode *eval_mode); 639 640 /// Denotes type of data stored in a CeedQFunctionContext field 641 /// @ingroup CeedQFunction 642 typedef enum { 643 /// Double precision value 644 CEED_CONTEXT_FIELD_DOUBLE = 1, 645 /// 32 bit integer value 646 CEED_CONTEXT_FIELD_INT32 = 2, 647 } CeedContextFieldType; 648 CEED_EXTERN const char *const CeedContextFieldTypes[]; 649 650 CEED_EXTERN int CeedQFunctionContextCreate(Ceed ceed, 651 CeedQFunctionContext *ctx); 652 CEED_EXTERN int CeedQFunctionContextReferenceCopy(CeedQFunctionContext ctx, 653 CeedQFunctionContext *ctx_copy); 654 CEED_EXTERN int CeedQFunctionContextSetData(CeedQFunctionContext ctx, 655 CeedMemType mem_type, CeedCopyMode copy_mode, size_t size, void *data); 656 CEED_EXTERN int CeedQFunctionContextTakeData(CeedQFunctionContext ctx, 657 CeedMemType mem_type, void *data); 658 CEED_EXTERN int CeedQFunctionContextGetData(CeedQFunctionContext ctx, 659 CeedMemType mem_type, void *data); 660 CEED_EXTERN int CeedQFunctionContextGetDataRead(CeedQFunctionContext ctx, 661 CeedMemType mem_type, void *data); 662 CEED_EXTERN int CeedQFunctionContextRestoreData(CeedQFunctionContext ctx, 663 void *data); 664 CEED_EXTERN int CeedQFunctionContextRestoreDataRead(CeedQFunctionContext ctx, 665 void *data); 666 CEED_EXTERN int CeedQFunctionContextRegisterDouble(CeedQFunctionContext ctx, 667 const char *field_name, size_t field_offset, size_t num_values, 668 const char *field_description); 669 CEED_EXTERN int CeedQFunctionContextRegisterInt32(CeedQFunctionContext ctx, 670 const char *field_name, size_t field_offset, size_t num_values, 671 const char *field_description); 672 CEED_EXTERN int CeedQFunctionContextGetFieldLabel(CeedQFunctionContext ctx, 673 const char *field_name, CeedContextFieldLabel *field_label); 674 CEED_EXTERN int CeedQFunctionContextGetAllFieldLabels(CeedQFunctionContext ctx, 675 const CeedContextFieldLabel **field_labels, CeedInt *num_fields); 676 CEED_EXTERN int CeedContextFieldLabelGetDescription(CeedContextFieldLabel label, 677 const char **field_name, const char **field_description, size_t *num_values, 678 CeedContextFieldType *field_type); 679 CEED_EXTERN int CeedQFunctionContextSetDouble(CeedQFunctionContext ctx, 680 CeedContextFieldLabel field_label, double *values); 681 CEED_EXTERN int CeedQFunctionContextSetInt32(CeedQFunctionContext ctx, 682 CeedContextFieldLabel field_label, int *values); 683 CEED_EXTERN int CeedQFunctionContextGetContextSize(CeedQFunctionContext ctx, 684 size_t *ctx_size); 685 CEED_EXTERN int CeedQFunctionContextView(CeedQFunctionContext ctx, 686 FILE *stream); 687 CEED_EXTERN int CeedQFunctionContextDestroy(CeedQFunctionContext *ctx); 688 689 CEED_EXTERN int CeedOperatorCreate(Ceed ceed, CeedQFunction qf, 690 CeedQFunction dqf, CeedQFunction dqfT, 691 CeedOperator *op); 692 CEED_EXTERN int CeedCompositeOperatorCreate(Ceed ceed, CeedOperator *op); 693 CEED_EXTERN int CeedOperatorReferenceCopy(CeedOperator op, CeedOperator *op_copy); 694 CEED_EXTERN int CeedOperatorSetField(CeedOperator op, const char *field_name, 695 CeedElemRestriction r, CeedBasis b, 696 CeedVector v); 697 CEED_EXTERN int CeedOperatorGetFields(CeedOperator op, 698 CeedInt *num_input_fields, 699 CeedOperatorField **input_fields, 700 CeedInt *num_output_fields, 701 CeedOperatorField **output_fields); 702 CEED_EXTERN int CeedCompositeOperatorAddSub(CeedOperator composite_op, 703 CeedOperator sub_op); 704 CEED_EXTERN int CeedOperatorCheckReady(CeedOperator op); 705 CEED_EXTERN int CeedOperatorLinearAssembleQFunction(CeedOperator op, 706 CeedVector *assembled, CeedElemRestriction *rstr, CeedRequest *request); 707 CEED_EXTERN int CeedOperatorLinearAssembleQFunctionBuildOrUpdate(CeedOperator op, 708 CeedVector *assembled, CeedElemRestriction *rstr, CeedRequest *request); 709 CEED_EXTERN int CeedOperatorLinearAssembleDiagonal(CeedOperator op, 710 CeedVector assembled, CeedRequest *request); 711 CEED_EXTERN int CeedOperatorLinearAssembleAddDiagonal(CeedOperator op, 712 CeedVector assembled, CeedRequest *request); 713 CEED_EXTERN int CeedOperatorLinearAssemblePointBlockDiagonal(CeedOperator op, 714 CeedVector assembled, CeedRequest *request); 715 CEED_EXTERN int CeedOperatorLinearAssembleAddPointBlockDiagonal(CeedOperator op, 716 CeedVector assembled, CeedRequest *request); 717 CEED_EXTERN int CeedOperatorLinearAssembleSymbolic(CeedOperator op, 718 CeedSize *num_entries, CeedInt **rows, CeedInt **cols); 719 CEED_EXTERN int CeedOperatorLinearAssemble(CeedOperator op, CeedVector values); 720 CEED_EXTERN int CeedOperatorMultigridLevelCreate(CeedOperator op_fine, 721 CeedVector p_mult_fine, CeedElemRestriction rstr_coarse, CeedBasis basis_coarse, 722 CeedOperator *op_coarse, CeedOperator *op_prolong, CeedOperator *op_restrict); 723 CEED_EXTERN int CeedOperatorMultigridLevelCreateTensorH1( 724 CeedOperator op_fine, CeedVector p_mult_fine, CeedElemRestriction rstr_coarse, 725 CeedBasis basis_coarse, const CeedScalar *interp_c_to_f, CeedOperator *op_coarse, 726 CeedOperator *op_prolong, CeedOperator *op_restrict); 727 CEED_EXTERN int CeedOperatorMultigridLevelCreateH1(CeedOperator op_fine, 728 CeedVector p_mult_fine, CeedElemRestriction rstr_coarse, CeedBasis basis_coarse, 729 const CeedScalar *interp_c_to_f, CeedOperator *op_coarse, 730 CeedOperator *op_prolong, CeedOperator *op_restrict); 731 CEED_EXTERN int CeedOperatorCreateFDMElementInverse(CeedOperator op, 732 CeedOperator *fdm_inv, CeedRequest *request); 733 CEED_EXTERN int CeedOperatorSetNumQuadraturePoints(CeedOperator op, CeedInt num_qpts); 734 CEED_EXTERN int CeedOperatorView(CeedOperator op, FILE *stream); 735 CEED_EXTERN int CeedOperatorGetCeed(CeedOperator op, Ceed *ceed); 736 CEED_EXTERN int CeedOperatorGetNumElements(CeedOperator op, CeedInt *num_elem); 737 CEED_EXTERN int CeedOperatorGetNumQuadraturePoints(CeedOperator op, 738 CeedInt *num_qpts); 739 CEED_EXTERN int CeedOperatorContextGetFieldLabel(CeedOperator op, 740 const char *field_name, CeedContextFieldLabel *field_label); 741 CEED_EXTERN int CeedOperatorContextSetDouble(CeedOperator op, 742 CeedContextFieldLabel field_label, double *values); 743 CEED_EXTERN int CeedOperatorContextSetInt32(CeedOperator op, 744 CeedContextFieldLabel field_label, int *values); 745 CEED_EXTERN int CeedOperatorApply(CeedOperator op, CeedVector in, 746 CeedVector out, CeedRequest *request); 747 CEED_EXTERN int CeedOperatorApplyAdd(CeedOperator op, CeedVector in, 748 CeedVector out, CeedRequest *request); 749 CEED_EXTERN int CeedOperatorDestroy(CeedOperator *op); 750 751 CEED_EXTERN int CeedOperatorFieldGetName(CeedOperatorField op_field, 752 char **field_name); 753 CEED_EXTERN int CeedOperatorFieldGetElemRestriction(CeedOperatorField op_field, 754 CeedElemRestriction *rstr); 755 CEED_EXTERN int CeedOperatorFieldGetBasis(CeedOperatorField op_field, 756 CeedBasis *basis); 757 CEED_EXTERN int CeedOperatorFieldGetVector(CeedOperatorField op_field, 758 CeedVector *vec); 759 760 /** 761 @brief Return integer power 762 763 @param[in] base The base to exponentiate 764 @param[in] power The power to raise the base to 765 766 @return base^power 767 768 @ref Utility 769 **/ 770 static inline CeedInt CeedIntPow(CeedInt base, CeedInt power) { 771 CeedInt result = 1; 772 while (power) { 773 if (power & 1) result *= base; 774 power >>= 1; 775 base *= base; 776 } 777 return result; 778 } 779 780 /** 781 @brief Return minimum of two integers 782 783 @param[in] a The first integer to compare 784 @param[in] b The second integer to compare 785 786 @return The minimum of the two integers 787 788 @ref Utility 789 **/ 790 static inline CeedInt CeedIntMin(CeedInt a, CeedInt b) { return a < b ? a : b; } 791 792 /** 793 @brief Return maximum of two integers 794 795 @param[in] a The first integer to compare 796 @param[in] b The second integer to compare 797 798 @return The maximum of the two integers 799 800 @ref Utility 801 **/ 802 static inline CeedInt CeedIntMax(CeedInt a, CeedInt b) { return a > b ? a : b; } 803 804 // Used to ensure initialization before CeedInit() 805 CEED_EXTERN int CeedRegisterAll(void); 806 // Used to ensure initialization before CeedQFunctionCreate*() 807 CEED_EXTERN int CeedQFunctionRegisterAll(void); 808 809 #endif 810