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