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