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 <assert.h> 109 #include <stdint.h> 110 #include <stddef.h> 111 #include <stdarg.h> 112 #include <stdio.h> 113 #include <stdbool.h> 114 115 /// Integer type, used for indexing 116 /// @ingroup Ceed 117 typedef int32_t CeedInt; 118 /// Scalar (floating point) type 119 /// @ingroup Ceed 120 typedef double CeedScalar; 121 122 /// Library context created by CeedInit() 123 /// @ingroup CeedUser 124 typedef struct Ceed_private *Ceed; 125 /// Non-blocking Ceed interfaces return a CeedRequest. 126 /// To perform an operation immediately, pass \ref CEED_REQUEST_IMMEDIATE instead. 127 /// @ingroup CeedUser 128 typedef struct CeedRequest_private *CeedRequest; 129 /// Handle for vectors over the field \ref CeedScalar 130 /// @ingroup CeedVectorUser 131 typedef struct CeedVector_private *CeedVector; 132 /// Handle for object describing restriction to elements 133 /// @ingroup CeedElemRestrictionUser 134 typedef struct CeedElemRestriction_private *CeedElemRestriction; 135 /// Handle for object describing discrete finite element evaluations 136 /// @ingroup CeedBasisUser 137 typedef struct CeedBasis_private *CeedBasis; 138 /// Handle for object describing functions evaluated independently at quadrature points 139 /// @ingroup CeedQFunctionUser 140 typedef struct CeedQFunction_private *CeedQFunction; 141 /// Handle for object describing context data for CeedQFunctions 142 /// @ingroup CeedQFunctionUser 143 typedef struct CeedQFunctionContext_private *CeedQFunctionContext; 144 /// Handle for object describing FE-type operators acting on vectors 145 /// 146 /// Given an element restriction \f$E\f$, basis evaluator \f$B\f$, and 147 /// quadrature function\f$f\f$, a CeedOperator expresses operations of the form 148 /// $$ E^T B^T f(B E u) $$ 149 /// acting on the vector \f$u\f$. 150 /// @ingroup CeedOperatorUser 151 typedef struct CeedOperator_private *CeedOperator; 152 153 CEED_EXTERN int CeedInit(const char *resource, Ceed *ceed); 154 CEED_EXTERN int CeedGetResource(Ceed ceed, const char **resource); 155 CEED_EXTERN int CeedIsDeterministic(Ceed ceed, bool *isDeterministic); 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 CEED_EXTERN int CeedSetErrorHandler(Ceed ceed, 189 int (*eh)(Ceed, const char *, int, 190 const char *, int, const char *, 191 va_list *)); 192 CEED_EXTERN int CeedGetErrorMessage(Ceed, const char **errmsg); 193 CEED_EXTERN int CeedResetErrorMessage(Ceed, const char **errmsg); 194 195 /// libCEED library version numbering 196 /// @ingroup Ceed 197 #define CEED_VERSION_MAJOR 0 198 #define CEED_VERSION_MINOR 7 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 /// Specify memory type 231 /// 232 /// Many Ceed interfaces take or return pointers to memory. This enum is used to 233 /// specify where the memory being provided or requested must reside. 234 /// @ingroup Ceed 235 typedef enum { 236 /// Memory resides on the host 237 CEED_MEM_HOST, 238 /// Memory resides on a device (corresponding to \ref Ceed resource) 239 CEED_MEM_DEVICE, 240 } CeedMemType; 241 242 CEED_EXTERN const char *const CeedMemTypes[]; 243 244 CEED_EXTERN int CeedGetPreferredMemType(Ceed ceed, CeedMemType *type); 245 246 /// Conveys ownership status of arrays passed to Ceed interfaces. 247 /// @ingroup Ceed 248 typedef enum { 249 /// Implementation will copy the values and not store the passed pointer. 250 CEED_COPY_VALUES, 251 /// Implementation can use and modify the data provided by the user, but does 252 /// not take ownership. 253 CEED_USE_POINTER, 254 /// Implementation takes ownership of the pointer and will free using 255 /// CeedFree() when done using it. The user should not assume that the 256 /// pointer remains valid after ownership has been transferred. Note that 257 /// arrays allocated using C++ operator new or other allocators cannot 258 /// generally be freed using CeedFree(). CeedFree() is capable of freeing any 259 /// memory that can be freed using free(3). 260 CEED_OWN_POINTER, 261 } CeedCopyMode; 262 263 /// Denotes type of vector norm to be computed 264 /// @ingroup CeedVector 265 typedef enum { 266 /// L_1 norm: sum_i |x_i| 267 CEED_NORM_1, 268 /// L_2 norm: sqrt(sum_i |x_i|^2) 269 CEED_NORM_2, 270 /// L_Infinity norm: max_i |x_i| 271 CEED_NORM_MAX, 272 } CeedNormType; 273 274 CEED_EXTERN const char *const CeedCopyModes[]; 275 276 CEED_EXTERN int CeedVectorCreate(Ceed ceed, CeedInt len, CeedVector *vec); 277 CEED_EXTERN int CeedVectorSetArray(CeedVector vec, CeedMemType mtype, 278 CeedCopyMode cmode, CeedScalar *array); 279 CEED_EXTERN int CeedVectorSetValue(CeedVector vec, CeedScalar value); 280 CEED_EXTERN int CeedVectorSyncArray(CeedVector vec, CeedMemType mtype); 281 CEED_EXTERN int CeedVectorTakeArray(CeedVector vec, CeedMemType mtype, 282 CeedScalar **array); 283 CEED_EXTERN int CeedVectorGetArray(CeedVector vec, CeedMemType mtype, 284 CeedScalar **array); 285 CEED_EXTERN int CeedVectorGetArrayRead(CeedVector vec, CeedMemType mtype, 286 const CeedScalar **array); 287 CEED_EXTERN int CeedVectorRestoreArray(CeedVector vec, CeedScalar **array); 288 CEED_EXTERN int CeedVectorRestoreArrayRead(CeedVector vec, 289 const CeedScalar **array); 290 CEED_EXTERN int CeedVectorNorm(CeedVector vec, CeedNormType type, 291 CeedScalar *norm); 292 CEED_EXTERN int CeedVectorReciprocal(CeedVector vec); 293 CEED_EXTERN int CeedVectorView(CeedVector vec, const char *fpfmt, FILE *stream); 294 CEED_EXTERN int CeedVectorGetLength(CeedVector vec, CeedInt *length); 295 CEED_EXTERN int CeedVectorDestroy(CeedVector *vec); 296 297 CEED_EXTERN CeedRequest *const CEED_REQUEST_IMMEDIATE; 298 CEED_EXTERN CeedRequest *const CEED_REQUEST_ORDERED; 299 CEED_EXTERN int CeedRequestWait(CeedRequest *req); 300 301 /// Argument for CeedOperatorSetField that vector is collocated with 302 /// quadrature points, used with QFunction eval mode CEED_EVAL_NONE 303 /// or CEED_EVAL_INTERP only, not with CEED_EVAL_GRAD, CEED_EVAL_DIV, 304 /// or CEED_EVAL_CURL 305 /// @ingroup CeedBasis 306 CEED_EXTERN const CeedBasis CEED_BASIS_COLLOCATED; 307 308 /// Argument for CeedOperatorSetField to use active input or output 309 /// @ingroup CeedVector 310 CEED_EXTERN const CeedVector CEED_VECTOR_ACTIVE; 311 312 /// Argument for CeedOperatorSetField to use no vector, used with 313 /// qfunction input with eval mode CEED_EVAL_WEIGHT 314 /// @ingroup CeedVector 315 CEED_EXTERN const CeedVector CEED_VECTOR_NONE; 316 317 /// Argument for CeedOperatorSetField to use no ElemRestriction, only used with 318 /// eval mode CEED_EVAL_WEIGHT. 319 /// @ingroup CeedElemRestriction 320 CEED_EXTERN const CeedElemRestriction CEED_ELEMRESTRICTION_NONE; 321 322 /// Argument for CeedOperatorCreate that QFunction is not created by user. 323 /// Only used for QFunctions dqf and dqfT. If implemented, a backend may 324 /// attempt to provide the action of these QFunctions. 325 /// @ingroup CeedQFunction 326 CEED_EXTERN const CeedQFunction CEED_QFUNCTION_NONE; 327 328 /// Denotes whether a linear transformation or its transpose should be applied 329 /// @ingroup CeedBasis 330 typedef enum { 331 /// Apply the linear transformation 332 CEED_NOTRANSPOSE, 333 /// Apply the transpose 334 CEED_TRANSPOSE 335 } CeedTransposeMode; 336 337 CEED_EXTERN const char *const CeedTransposeModes[]; 338 339 /// Argument for CeedElemRestrictionCreateStrided that L-vector is in 340 /// the Ceed backend's preferred layout. This argument should only be used 341 /// with vectors created by a Ceed backend. 342 /// @ingroup CeedElemRestriction 343 CEED_EXTERN const CeedInt CEED_STRIDES_BACKEND[3]; 344 345 CEED_EXTERN int CeedElemRestrictionCreate(Ceed ceed, CeedInt nelem, 346 CeedInt elemsize, CeedInt ncomp, CeedInt compstride, CeedInt lsize, 347 CeedMemType mtype, CeedCopyMode cmode, const CeedInt *offsets, 348 CeedElemRestriction *rstr); 349 CEED_EXTERN int CeedElemRestrictionCreateStrided(Ceed ceed, 350 CeedInt nelem, CeedInt elemsize, CeedInt ncomp, CeedInt lsize, 351 const CeedInt strides[3], CeedElemRestriction *rstr); 352 CEED_EXTERN int CeedElemRestrictionCreateBlocked(Ceed ceed, CeedInt nelem, 353 CeedInt elemsize, CeedInt blksize, CeedInt ncomp, CeedInt compstride, 354 CeedInt lsize, CeedMemType mtype, CeedCopyMode cmode, 355 const CeedInt *offsets, CeedElemRestriction *rstr); 356 CEED_EXTERN int CeedElemRestrictionCreateBlockedStrided(Ceed ceed, 357 CeedInt nelem, CeedInt elemsize, CeedInt blksize, CeedInt ncomp, 358 CeedInt lsize, const CeedInt strides[3], CeedElemRestriction *rstr); 359 CEED_EXTERN int CeedElemRestrictionCreateVector(CeedElemRestriction rstr, 360 CeedVector *lvec, CeedVector *evec); 361 CEED_EXTERN int CeedElemRestrictionApply(CeedElemRestriction rstr, 362 CeedTransposeMode tmode, CeedVector u, CeedVector ru, CeedRequest *request); 363 CEED_EXTERN int CeedElemRestrictionApplyBlock(CeedElemRestriction rstr, 364 CeedInt block, CeedTransposeMode tmode, CeedVector u, CeedVector ru, 365 CeedRequest *request); 366 CEED_EXTERN int CeedElemRestrictionGetCompStride(CeedElemRestriction rstr, 367 CeedInt *compstride); 368 CEED_EXTERN int CeedElemRestrictionGetNumElements(CeedElemRestriction rstr, 369 CeedInt *numelem); 370 CEED_EXTERN int CeedElemRestrictionGetElementSize(CeedElemRestriction rstr, 371 CeedInt *elemsize); 372 CEED_EXTERN int CeedElemRestrictionGetLVectorSize(CeedElemRestriction rstr, 373 CeedInt *lsize); 374 CEED_EXTERN int CeedElemRestrictionGetNumComponents(CeedElemRestriction rstr, 375 CeedInt *numcomp); 376 CEED_EXTERN int CeedElemRestrictionGetNumBlocks(CeedElemRestriction rstr, 377 CeedInt *numblk); 378 CEED_EXTERN int CeedElemRestrictionGetBlockSize(CeedElemRestriction rstr, 379 CeedInt *blksize); 380 CEED_EXTERN int CeedElemRestrictionGetMultiplicity(CeedElemRestriction rstr, 381 CeedVector mult); 382 CEED_EXTERN int CeedElemRestrictionView(CeedElemRestriction rstr, FILE *stream); 383 CEED_EXTERN int CeedElemRestrictionDestroy(CeedElemRestriction *rstr); 384 385 // The formalism here is that we have the structure 386 // \int_\Omega v^T f_0(u, \nabla u, qdata) + (\nabla v)^T f_1(u, \nabla u, qdata) 387 // where gradients are with respect to the reference element. 388 389 /// Basis evaluation mode 390 /// 391 /// Modes can be bitwise ORed when passing to most functions. 392 /// @ingroup CeedBasis 393 typedef enum { 394 /// Perform no evaluation (either because there is no data or it is already at 395 /// quadrature points) 396 CEED_EVAL_NONE = 0, 397 /// Interpolate from nodes to quadrature points 398 CEED_EVAL_INTERP = 1, 399 /// Evaluate gradients at quadrature points from input in a nodal basis 400 CEED_EVAL_GRAD = 2, 401 /// Evaluate divergence at quadrature points from input in a nodal basis 402 CEED_EVAL_DIV = 4, 403 /// Evaluate curl at quadrature points from input in a nodal basis 404 CEED_EVAL_CURL = 8, 405 /// Using no input, evaluate quadrature weights on the reference element 406 CEED_EVAL_WEIGHT = 16, 407 } CeedEvalMode; 408 409 CEED_EXTERN const char *const CeedEvalModes[]; 410 411 /// Type of quadrature; also used for location of nodes 412 /// @ingroup CeedBasis 413 typedef enum { 414 /// Gauss-Legendre quadrature 415 CEED_GAUSS = 0, 416 /// Gauss-Legendre-Lobatto quadrature 417 CEED_GAUSS_LOBATTO = 1, 418 } CeedQuadMode; 419 420 CEED_EXTERN const char *const CeedQuadModes[]; 421 422 /// Type of basis shape to create non-tensor H1 element basis 423 /// 424 /// Dimension can be extracted with bitwise AND 425 /// (CeedElemTopology & 2**(dim + 2)) == TRUE 426 /// @ingroup CeedBasis 427 typedef enum { 428 /// Line 429 CEED_LINE = 1 << 16 | 0, 430 /// Triangle - 2D shape 431 CEED_TRIANGLE = 2 << 16 | 1, 432 /// Quadralateral - 2D shape 433 CEED_QUAD = 2 << 16 | 2, 434 /// Tetrahedron - 3D shape 435 CEED_TET = 3 << 16 | 3, 436 /// Pyramid - 3D shape 437 CEED_PYRAMID = 3 << 16 | 4, 438 /// Prism - 3D shape 439 CEED_PRISM = 3 << 16 | 5, 440 /// Hexehedron - 3D shape 441 CEED_HEX = 3 << 16 | 6, 442 } CeedElemTopology; 443 444 CEED_EXTERN const char *const CeedElemTopologies[]; 445 446 CEED_EXTERN int CeedBasisCreateTensorH1Lagrange(Ceed ceed, CeedInt dim, 447 CeedInt ncomp, CeedInt P, CeedInt Q, CeedQuadMode qmode, CeedBasis *basis); 448 CEED_EXTERN int CeedBasisCreateTensorH1(Ceed ceed, CeedInt dim, CeedInt ncomp, 449 CeedInt P1d, CeedInt Q1d, 450 const CeedScalar *interp1d, 451 const CeedScalar *grad1d, 452 const CeedScalar *qref1d, 453 const CeedScalar *qweight1d, 454 CeedBasis *basis); 455 CEED_EXTERN int CeedBasisCreateH1(Ceed ceed, CeedElemTopology topo, 456 CeedInt ncomp, 457 CeedInt nnodes, CeedInt nqpts, 458 const CeedScalar *interp, 459 const CeedScalar *grad, 460 const CeedScalar *qref, 461 const CeedScalar *qweight, CeedBasis *basis); 462 CEED_EXTERN int CeedBasisView(CeedBasis basis, FILE *stream); 463 CEED_EXTERN int CeedBasisApply(CeedBasis basis, CeedInt nelem, 464 CeedTransposeMode tmode, 465 CeedEvalMode emode, CeedVector u, CeedVector v); 466 CEED_EXTERN int CeedBasisGetDimension(CeedBasis basis, CeedInt *dim); 467 CEED_EXTERN int CeedBasisGetTopology(CeedBasis basis, CeedElemTopology *topo); 468 CEED_EXTERN int CeedBasisGetNumComponents(CeedBasis basis, CeedInt *numcomp); 469 CEED_EXTERN int CeedBasisGetNumNodes(CeedBasis basis, CeedInt *P); 470 CEED_EXTERN int CeedBasisGetNumNodes1D(CeedBasis basis, CeedInt *P1d); 471 CEED_EXTERN int CeedBasisGetNumQuadraturePoints(CeedBasis basis, CeedInt *Q); 472 CEED_EXTERN int CeedBasisGetNumQuadraturePoints1D(CeedBasis basis, 473 CeedInt *Q1d); 474 CEED_EXTERN int CeedBasisGetQRef(CeedBasis basis, const CeedScalar **qref); 475 CEED_EXTERN int CeedBasisGetQWeights(CeedBasis basis, 476 const CeedScalar **qweight); 477 CEED_EXTERN int CeedBasisGetInterp(CeedBasis basis, const CeedScalar **interp); 478 CEED_EXTERN int CeedBasisGetInterp1D(CeedBasis basis, 479 const CeedScalar **interp1d); 480 CEED_EXTERN int CeedBasisGetGrad(CeedBasis basis, const CeedScalar **grad); 481 CEED_EXTERN int CeedBasisGetGrad1D(CeedBasis basis, const CeedScalar **grad1d); 482 CEED_EXTERN int CeedBasisDestroy(CeedBasis *basis); 483 484 CEED_EXTERN int CeedGaussQuadrature(CeedInt Q, CeedScalar *qref1d, 485 CeedScalar *qweight1d); 486 CEED_EXTERN int CeedLobattoQuadrature(CeedInt Q, CeedScalar *qref1d, 487 CeedScalar *qweight1d); 488 CEED_EXTERN int CeedQRFactorization(Ceed ceed, CeedScalar *mat, CeedScalar *tau, 489 CeedInt m, CeedInt n); 490 CEED_EXTERN int CeedSymmetricSchurDecomposition(Ceed ceed, CeedScalar *mat, 491 CeedScalar *lambda, CeedInt n); 492 CEED_EXTERN int CeedSimultaneousDiagonalization(Ceed ceed, CeedScalar *matA, 493 CeedScalar *matB, CeedScalar *x, CeedScalar *lambda, CeedInt n); 494 495 /** Handle for the object describing the user CeedQFunction 496 497 @param ctx user-defined context set using CeedQFunctionSetContext() or NULL 498 499 @param Q number of quadrature points at which to evaluate 500 501 @param in array of pointers to each input argument in the order provided 502 by the user in CeedQFunctionAddInput(). Each array has shape 503 `[dim, ncomp, Q]` where `dim` is the geometric dimension for 504 \ref CEED_EVAL_GRAD (`dim=1` for \ref CEED_EVAL_INTERP) and 505 `ncomp` is the number of field components (`ncomp=1` for 506 scalar fields). This results in indexing the `i`th input at 507 quadrature point `j` as `in[i][(d*ncomp + c)*Q + j]`. 508 509 @param out array of pointers to each output array in the order provided 510 using CeedQFunctionAddOutput(). The shapes are as above for 511 \a in. 512 513 @return An error code: 0 - success, otherwise - failure 514 515 @ingroup CeedQFunction 516 **/ 517 typedef int (*CeedQFunctionUser)(void *ctx, const CeedInt Q, 518 const CeedScalar *const *in, 519 CeedScalar *const *out); 520 521 CEED_EXTERN int CeedQFunctionCreateInterior(Ceed ceed, CeedInt vlength, 522 CeedQFunctionUser f, const char *source, CeedQFunction *qf); 523 CEED_EXTERN int CeedQFunctionCreateInteriorByName(Ceed ceed, const char *name, 524 CeedQFunction *qf); 525 CEED_EXTERN int CeedQFunctionCreateIdentity(Ceed ceed, CeedInt size, 526 CeedEvalMode inmode, CeedEvalMode outmode, CeedQFunction *qf); 527 CEED_EXTERN int CeedQFunctionAddInput(CeedQFunction qf, const char *fieldname, 528 CeedInt size, CeedEvalMode emode); 529 CEED_EXTERN int CeedQFunctionAddOutput(CeedQFunction qf, const char *fieldname, 530 CeedInt size, CeedEvalMode emode); 531 CEED_EXTERN int CeedQFunctionSetContext(CeedQFunction qf, 532 CeedQFunctionContext ctx); 533 CEED_EXTERN int CeedQFunctionView(CeedQFunction qf, FILE *stream); 534 CEED_EXTERN int CeedQFunctionApply(CeedQFunction qf, CeedInt Q, 535 CeedVector *u, CeedVector *v); 536 CEED_EXTERN int CeedQFunctionDestroy(CeedQFunction *qf); 537 538 CEED_EXTERN int CeedQFunctionContextCreate(Ceed ceed, 539 CeedQFunctionContext *ctx); 540 CEED_EXTERN int CeedQFunctionContextSetData(CeedQFunctionContext ctx, 541 CeedMemType mtype, CeedCopyMode cmode, size_t size, void *data); 542 CEED_EXTERN int CeedQFunctionContextGetData(CeedQFunctionContext ctx, 543 CeedMemType mtype, 544 void *data); 545 CEED_EXTERN int CeedQFunctionContextRestoreData(CeedQFunctionContext ctx, 546 void *data); 547 CEED_EXTERN int CeedQFunctionContextView(CeedQFunctionContext ctx, 548 FILE *stream); 549 CEED_EXTERN int CeedQFunctionContextDestroy(CeedQFunctionContext *ctx); 550 551 CEED_EXTERN int CeedOperatorCreate(Ceed ceed, CeedQFunction qf, 552 CeedQFunction dqf, CeedQFunction dqfT, 553 CeedOperator *op); 554 CEED_EXTERN int CeedCompositeOperatorCreate(Ceed ceed, CeedOperator *op); 555 CEED_EXTERN int CeedOperatorSetField(CeedOperator op, const char *fieldname, 556 CeedElemRestriction r, CeedBasis b, 557 CeedVector v); 558 CEED_EXTERN int CeedCompositeOperatorAddSub(CeedOperator compositeop, 559 CeedOperator subop); 560 CEED_EXTERN int CeedOperatorLinearAssembleQFunction(CeedOperator op, 561 CeedVector *assembled, CeedElemRestriction *rstr, CeedRequest *request); 562 CEED_EXTERN int CeedOperatorLinearAssembleDiagonal(CeedOperator op, 563 CeedVector assembled, CeedRequest *request); 564 CEED_EXTERN int CeedOperatorLinearAssembleAddDiagonal(CeedOperator op, 565 CeedVector assembled, CeedRequest *request); 566 CEED_EXTERN int CeedOperatorLinearAssemblePointBlockDiagonal(CeedOperator op, 567 CeedVector assembled, CeedRequest *request); 568 CEED_EXTERN int CeedOperatorLinearAssembleAddPointBlockDiagonal(CeedOperator op, 569 CeedVector assembled, CeedRequest *request); 570 CEED_EXTERN int CeedOperatorMultigridLevelCreate(CeedOperator opFine, 571 CeedVector PMultFine, CeedElemRestriction rstrCoarse, CeedBasis basisCoarse, 572 CeedOperator *opCoarse, CeedOperator *opProlong, CeedOperator *opRestrict); 573 CEED_EXTERN int CeedOperatorMultigridLevelCreateTensorH1( 574 CeedOperator opFine, CeedVector PMultFine, CeedElemRestriction rstrCoarse, 575 CeedBasis basisCoarse, const CeedScalar *interpCtoF, CeedOperator *opCoarse, 576 CeedOperator *opProlong, CeedOperator *opRestrict); 577 CEED_EXTERN int CeedOperatorMultigridLevelCreateH1(CeedOperator opFine, 578 CeedVector PMultFine, CeedElemRestriction rstrCoarse, CeedBasis basisCoarse, 579 const CeedScalar *interpCtoF, CeedOperator *opCoarse, 580 CeedOperator *opProlong, CeedOperator *opRestrict); 581 CEED_EXTERN int CeedOperatorCreateFDMElementInverse(CeedOperator op, 582 CeedOperator *fdminv, CeedRequest *request); 583 CEED_EXTERN int CeedOperatorView(CeedOperator op, FILE *stream); 584 CEED_EXTERN int CeedOperatorApply(CeedOperator op, CeedVector in, 585 CeedVector out, CeedRequest *request); 586 CEED_EXTERN int CeedOperatorApplyAdd(CeedOperator op, CeedVector in, 587 CeedVector out, CeedRequest *request); 588 CEED_EXTERN int CeedOperatorDestroy(CeedOperator *op); 589 590 /** 591 @brief Return integer power 592 593 @param[in] base The base to exponentiate 594 @param[in] power The power to raise the base to 595 596 @return base^power 597 598 @ref Utility 599 **/ 600 static inline CeedInt CeedIntPow(CeedInt base, CeedInt power) { 601 CeedInt result = 1; 602 while (power) { 603 if (power & 1) result *= base; 604 power >>= 1; 605 base *= base; 606 } 607 return result; 608 } 609 610 /** 611 @brief Return minimum of two integers 612 613 @param[in] a The first integer to compare 614 @param[in] b The second integer to compare 615 616 @return The minimum of the two integers 617 618 @ref Utility 619 **/ 620 static inline CeedInt CeedIntMin(CeedInt a, CeedInt b) { return a < b ? a : b; } 621 622 /** 623 @brief Return maximum of two integers 624 625 @param[in] a The first integer to compare 626 @param[in] b The second integer to compare 627 628 @return The maximum of the two integers 629 630 @ref Utility 631 **/ 632 static inline CeedInt CeedIntMax(CeedInt a, CeedInt b) { return a > b ? a : b; } 633 634 // Used to ensure initialization before CeedInit() 635 CEED_EXTERN int CeedRegisterAll(void); 636 // Used to ensure initialization before CeedQFunctionCreate*() 637 CEED_EXTERN int CeedQFunctionRegisterAll(void); 638 639 #endif 640