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 FE-type operators acting on vectors 142 /// 143 /// Given an element restriction \f$E\f$, basis evaluator \f$B\f$, and 144 /// quadrature function\f$f\f$, a CeedOperator expresses operations of the form 145 /// $$ E^T B^T f(B E u) $$ 146 /// acting on the vector \f$u\f$. 147 /// @ingroup CeedOperatorUser 148 typedef struct CeedOperator_private *CeedOperator; 149 150 CEED_EXTERN int CeedInit(const char *resource, Ceed *ceed); 151 CEED_EXTERN int CeedGetResource(Ceed ceed, const char **resource); 152 CEED_EXTERN int CeedIsDeterministic(Ceed ceed, bool *isDeterministic); 153 CEED_EXTERN int CeedView(Ceed ceed, FILE *stream); 154 CEED_EXTERN int CeedDestroy(Ceed *ceed); 155 156 CEED_EXTERN int CeedErrorImpl(Ceed, const char *, int, const char *, int, 157 const char *, ...); 158 /// Raise an error on ceed object 159 /// 160 /// @param ceed Ceed library context or NULL 161 /// @param ecode Error code (int) 162 /// @param ... printf-style format string followed by arguments as needed 163 /// 164 /// @ingroup Ceed 165 /// @sa CeedSetErrorHandler() 166 #if defined(__clang__) 167 /// Use nonstandard ternary to convince the compiler/clang-tidy that this 168 /// function never returns zero. 169 # define CeedError(ceed, ecode, ...) \ 170 (CeedErrorImpl((ceed), __FILE__, __LINE__, __func__, (ecode), __VA_ARGS__) ?: (ecode)) 171 #else 172 # define CeedError(ceed, ecode, ...) \ 173 CeedErrorImpl((ceed), __FILE__, __LINE__, __func__, (ecode), __VA_ARGS__) ?: (ecode) 174 #endif 175 176 /// Ceed error handlers 177 CEED_EXTERN int CeedErrorReturn(Ceed, const char *, int, const char *, int, 178 const char *, va_list); 179 CEED_EXTERN int CeedErrorStore(Ceed, const char *, int, const char *, int, 180 const char *, va_list); 181 CEED_EXTERN int CeedErrorAbort(Ceed, const char *, int, const char *, int, 182 const char *, va_list); 183 CEED_EXTERN int CeedErrorExit(Ceed, const char *, int, const char *, int, 184 const char *, va_list); 185 CEED_EXTERN int CeedSetErrorHandler(Ceed ceed, 186 int (*eh)(Ceed, const char *, int, 187 const char *, int, const char *, 188 va_list)); 189 CEED_EXTERN int CeedGetErrorMessage(Ceed, const char **errmsg); 190 CEED_EXTERN int CeedResetErrorMessage(Ceed, const char **errmsg); 191 192 /// Specify memory type 193 /// 194 /// Many Ceed interfaces take or return pointers to memory. This enum is used to 195 /// specify where the memory being provided or requested must reside. 196 /// @ingroup Ceed 197 typedef enum { 198 /// Memory resides on the host 199 CEED_MEM_HOST, 200 /// Memory resides on a device (corresponding to \ref Ceed resource) 201 CEED_MEM_DEVICE, 202 } CeedMemType; 203 204 CEED_EXTERN const char *const CeedMemTypes[]; 205 206 CEED_EXTERN int CeedGetPreferredMemType(Ceed ceed, CeedMemType *type); 207 208 /// Conveys ownership status of arrays passed to Ceed interfaces. 209 /// @ingroup Ceed 210 typedef enum { 211 /// Implementation will copy the values and not store the passed pointer. 212 CEED_COPY_VALUES, 213 /// Implementation can use and modify the data provided by the user, but does 214 /// not take ownership. 215 CEED_USE_POINTER, 216 /// Implementation takes ownership of the pointer and will free using 217 /// CeedFree() when done using it. The user should not assume that the 218 /// pointer remains valid after ownership has been transferred. Note that 219 /// arrays allocated using C++ operator new or other allocators cannot 220 /// generally be freed using CeedFree(). CeedFree() is capable of freeing any 221 /// memory that can be freed using free(3). 222 CEED_OWN_POINTER, 223 } CeedCopyMode; 224 225 /// Denotes type of vector norm to be computed 226 /// @ingroup CeedVector 227 typedef enum { 228 /// L_1 norm: sum_i |x_i| 229 CEED_NORM_1, 230 /// L_2 norm: sqrt(sum_i |x_i|^2) 231 CEED_NORM_2, 232 /// L_Infinity norm: max_i |x_i| 233 CEED_NORM_MAX, 234 } CeedNormType; 235 236 CEED_EXTERN const char *const CeedCopyModes[]; 237 238 CEED_EXTERN int CeedVectorCreate(Ceed ceed, CeedInt len, CeedVector *vec); 239 CEED_EXTERN int CeedVectorSetArray(CeedVector vec, CeedMemType mtype, 240 CeedCopyMode cmode, CeedScalar *array); 241 CEED_EXTERN int CeedVectorSetValue(CeedVector vec, CeedScalar value); 242 CEED_EXTERN int CeedVectorSyncArray(CeedVector vec, CeedMemType mtype); 243 CEED_EXTERN int CeedVectorTakeArray(CeedVector vec, CeedMemType mtype, 244 CeedScalar **array); 245 CEED_EXTERN int CeedVectorGetArray(CeedVector vec, CeedMemType mtype, 246 CeedScalar **array); 247 CEED_EXTERN int CeedVectorGetArrayRead(CeedVector vec, CeedMemType mtype, 248 const CeedScalar **array); 249 CEED_EXTERN int CeedVectorRestoreArray(CeedVector vec, CeedScalar **array); 250 CEED_EXTERN int CeedVectorRestoreArrayRead(CeedVector vec, 251 const CeedScalar **array); 252 CEED_EXTERN int CeedVectorNorm(CeedVector vec, CeedNormType type, 253 CeedScalar *norm); 254 CEED_EXTERN int CeedVectorReciprocal(CeedVector vec); 255 CEED_EXTERN int CeedVectorView(CeedVector vec, const char *fpfmt, FILE *stream); 256 CEED_EXTERN int CeedVectorGetLength(CeedVector vec, CeedInt *length); 257 CEED_EXTERN int CeedVectorDestroy(CeedVector *vec); 258 259 CEED_EXTERN CeedRequest *const CEED_REQUEST_IMMEDIATE; 260 CEED_EXTERN CeedRequest *const CEED_REQUEST_ORDERED; 261 CEED_EXTERN int CeedRequestWait(CeedRequest *req); 262 263 /// Argument for CeedOperatorSetField that vector is collocated with 264 /// quadrature points, used with QFunction eval mode CEED_EVAL_NONE 265 /// or CEED_EVAL_INTERP only, not with CEED_EVAL_GRAD, CEED_EVAL_DIV, 266 /// or CEED_EVAL_CURL 267 /// @ingroup CeedBasis 268 CEED_EXTERN const CeedBasis CEED_BASIS_COLLOCATED; 269 270 /// Argument for CeedOperatorSetField to use active input or output 271 /// @ingroup CeedVector 272 CEED_EXTERN const CeedVector CEED_VECTOR_ACTIVE; 273 274 /// Argument for CeedOperatorSetField to use no vector, used with 275 /// qfunction input with eval mode CEED_EVAL_WEIGHT 276 /// @ingroup CeedVector 277 CEED_EXTERN const CeedVector CEED_VECTOR_NONE; 278 279 /// Argument for CeedOperatorSetField to use no ElemRestriction, only used with 280 /// eval mode CEED_EVAL_WEIGHT. 281 /// @ingroup CeedElemRestriction 282 CEED_EXTERN const CeedElemRestriction CEED_ELEMRESTRICTION_NONE; 283 284 /// Argument for CeedOperatorCreate that QFunction is not created by user. 285 /// Only used for QFunctions dqf and dqfT. If implemented, a backend may 286 /// attempt to provide the action of these QFunctions. 287 /// @ingroup CeedQFunction 288 CEED_EXTERN const CeedQFunction CEED_QFUNCTION_NONE; 289 290 /// Denotes whether a linear transformation or its transpose should be applied 291 /// @ingroup CeedBasis 292 typedef enum { 293 /// Apply the linear transformation 294 CEED_NOTRANSPOSE, 295 /// Apply the transpose 296 CEED_TRANSPOSE 297 } CeedTransposeMode; 298 299 CEED_EXTERN const char *const CeedTransposeModes[]; 300 301 /// Argument for CeedElemRestrictionCreateStrided that L-vector is in 302 /// the Ceed backend's preferred layout. This argument should only be used 303 /// with vectors created by a Ceed backend. 304 /// @ingroup CeedElemRestriction 305 CEED_EXTERN const CeedInt CEED_STRIDES_BACKEND[3]; 306 307 CEED_EXTERN int CeedElemRestrictionCreate(Ceed ceed, CeedInt nelem, 308 CeedInt elemsize, CeedInt ncomp, CeedInt compstride, CeedInt lsize, 309 CeedMemType mtype, CeedCopyMode cmode, const CeedInt *offsets, 310 CeedElemRestriction *rstr); 311 CEED_EXTERN int CeedElemRestrictionCreateStrided(Ceed ceed, 312 CeedInt nelem, CeedInt elemsize, CeedInt ncomp, CeedInt lsize, 313 const CeedInt strides[3], CeedElemRestriction *rstr); 314 CEED_EXTERN int CeedElemRestrictionCreateBlocked(Ceed ceed, CeedInt nelem, 315 CeedInt elemsize, CeedInt blksize, CeedInt ncomp, CeedInt compstride, 316 CeedInt lsize, CeedMemType mtype, CeedCopyMode cmode, 317 const CeedInt *offsets, CeedElemRestriction *rstr); 318 CEED_EXTERN int CeedElemRestrictionCreateBlockedStrided(Ceed ceed, 319 CeedInt nelem, CeedInt elemsize, CeedInt blksize, CeedInt ncomp, 320 CeedInt lsize, const CeedInt strides[3], CeedElemRestriction *rstr); 321 CEED_EXTERN int CeedElemRestrictionCreateVector(CeedElemRestriction rstr, 322 CeedVector *lvec, CeedVector *evec); 323 CEED_EXTERN int CeedElemRestrictionApply(CeedElemRestriction rstr, 324 CeedTransposeMode tmode, CeedVector u, CeedVector ru, CeedRequest *request); 325 CEED_EXTERN int CeedElemRestrictionApplyBlock(CeedElemRestriction rstr, 326 CeedInt block, CeedTransposeMode tmode, CeedVector u, CeedVector ru, 327 CeedRequest *request); 328 CEED_EXTERN int CeedElemRestrictionGetCompStride(CeedElemRestriction rstr, 329 CeedInt *compstride); 330 CEED_EXTERN int CeedElemRestrictionGetNumElements(CeedElemRestriction rstr, 331 CeedInt *numelem); 332 CEED_EXTERN int CeedElemRestrictionGetElementSize(CeedElemRestriction rstr, 333 CeedInt *elemsize); 334 CEED_EXTERN int CeedElemRestrictionGetLVectorSize(CeedElemRestriction rstr, 335 CeedInt *lsize); 336 CEED_EXTERN int CeedElemRestrictionGetNumComponents(CeedElemRestriction rstr, 337 CeedInt *numcomp); 338 CEED_EXTERN int CeedElemRestrictionGetNumBlocks(CeedElemRestriction rstr, 339 CeedInt *numblk); 340 CEED_EXTERN int CeedElemRestrictionGetBlockSize(CeedElemRestriction rstr, 341 CeedInt *blksize); 342 CEED_EXTERN int CeedElemRestrictionGetMultiplicity(CeedElemRestriction rstr, 343 CeedVector mult); 344 CEED_EXTERN int CeedElemRestrictionView(CeedElemRestriction rstr, FILE *stream); 345 CEED_EXTERN int CeedElemRestrictionDestroy(CeedElemRestriction *rstr); 346 347 // The formalism here is that we have the structure 348 // \int_\Omega v^T f_0(u, \nabla u, qdata) + (\nabla v)^T f_1(u, \nabla u, qdata) 349 // where gradients are with respect to the reference element. 350 351 /// Basis evaluation mode 352 /// 353 /// Modes can be bitwise ORed when passing to most functions. 354 /// @ingroup CeedBasis 355 typedef enum { 356 /// Perform no evaluation (either because there is no data or it is already at 357 /// quadrature points) 358 CEED_EVAL_NONE = 0, 359 /// Interpolate from nodes to quadrature points 360 CEED_EVAL_INTERP = 1, 361 /// Evaluate gradients at quadrature points from input in a nodal basis 362 CEED_EVAL_GRAD = 2, 363 /// Evaluate divergence at quadrature points from input in a nodal basis 364 CEED_EVAL_DIV = 4, 365 /// Evaluate curl at quadrature points from input in a nodal basis 366 CEED_EVAL_CURL = 8, 367 /// Using no input, evaluate quadrature weights on the reference element 368 CEED_EVAL_WEIGHT = 16, 369 } CeedEvalMode; 370 371 CEED_EXTERN const char *const CeedEvalModes[]; 372 373 /// Type of quadrature; also used for location of nodes 374 /// @ingroup CeedBasis 375 typedef enum { 376 /// Gauss-Legendre quadrature 377 CEED_GAUSS = 0, 378 /// Gauss-Legendre-Lobatto quadrature 379 CEED_GAUSS_LOBATTO = 1, 380 } CeedQuadMode; 381 382 CEED_EXTERN const char *const CeedQuadModes[]; 383 384 /// Type of basis shape to create non-tensor H1 element basis 385 /// 386 /// Dimension can be extracted with bitwise AND 387 /// (CeedElemTopology & 2**(dim + 2)) == TRUE 388 /// @ingroup CeedBasis 389 typedef enum { 390 /// Line 391 CEED_LINE = 1 << 16 | 0, 392 /// Triangle - 2D shape 393 CEED_TRIANGLE = 2 << 16 | 1, 394 /// Quadralateral - 2D shape 395 CEED_QUAD = 2 << 16 | 2, 396 /// Tetrahedron - 3D shape 397 CEED_TET = 3 << 16 | 3, 398 /// Pyramid - 3D shape 399 CEED_PYRAMID = 3 << 16 | 4, 400 /// Prism - 3D shape 401 CEED_PRISM = 3 << 16 | 5, 402 /// Hexehedron - 3D shape 403 CEED_HEX = 3 << 16 | 6, 404 } CeedElemTopology; 405 406 CEED_EXTERN const char *const CeedElemTopologies[]; 407 408 CEED_EXTERN int CeedBasisCreateTensorH1Lagrange(Ceed ceed, CeedInt dim, 409 CeedInt ncomp, CeedInt P, CeedInt Q, CeedQuadMode qmode, CeedBasis *basis); 410 CEED_EXTERN int CeedBasisCreateTensorH1(Ceed ceed, CeedInt dim, CeedInt ncomp, 411 CeedInt P1d, CeedInt Q1d, 412 const CeedScalar *interp1d, 413 const CeedScalar *grad1d, 414 const CeedScalar *qref1d, 415 const CeedScalar *qweight1d, 416 CeedBasis *basis); 417 CEED_EXTERN int CeedBasisCreateH1(Ceed ceed, CeedElemTopology topo, 418 CeedInt ncomp, 419 CeedInt nnodes, CeedInt nqpts, 420 const CeedScalar *interp, 421 const CeedScalar *grad, 422 const CeedScalar *qref, 423 const CeedScalar *qweight, CeedBasis *basis); 424 CEED_EXTERN int CeedBasisView(CeedBasis basis, FILE *stream); 425 CEED_EXTERN int CeedBasisApply(CeedBasis basis, CeedInt nelem, 426 CeedTransposeMode tmode, 427 CeedEvalMode emode, CeedVector u, CeedVector v); 428 CEED_EXTERN int CeedBasisGetDimension(CeedBasis basis, CeedInt *dim); 429 CEED_EXTERN int CeedBasisGetTopology(CeedBasis basis, CeedElemTopology *topo); 430 CEED_EXTERN int CeedBasisGetNumComponents(CeedBasis basis, CeedInt *numcomp); 431 CEED_EXTERN int CeedBasisGetNumNodes(CeedBasis basis, CeedInt *P); 432 CEED_EXTERN int CeedBasisGetNumNodes1D(CeedBasis basis, CeedInt *P1d); 433 CEED_EXTERN int CeedBasisGetNumQuadraturePoints(CeedBasis basis, CeedInt *Q); 434 CEED_EXTERN int CeedBasisGetNumQuadraturePoints1D(CeedBasis basis, 435 CeedInt *Q1d); 436 CEED_EXTERN int CeedBasisGetQRef(CeedBasis basis, const CeedScalar **qref); 437 CEED_EXTERN int CeedBasisGetQWeights(CeedBasis basis, 438 const CeedScalar **qweight); 439 CEED_EXTERN int CeedBasisGetInterp(CeedBasis basis, const CeedScalar **interp); 440 CEED_EXTERN int CeedBasisGetInterp1D(CeedBasis basis, 441 const CeedScalar **interp1d); 442 CEED_EXTERN int CeedBasisGetGrad(CeedBasis basis, const CeedScalar **grad); 443 CEED_EXTERN int CeedBasisGetGrad1D(CeedBasis basis, const CeedScalar **grad1d); 444 CEED_EXTERN int CeedBasisDestroy(CeedBasis *basis); 445 446 CEED_EXTERN int CeedGaussQuadrature(CeedInt Q, CeedScalar *qref1d, 447 CeedScalar *qweight1d); 448 CEED_EXTERN int CeedLobattoQuadrature(CeedInt Q, CeedScalar *qref1d, 449 CeedScalar *qweight1d); 450 CEED_EXTERN int CeedQRFactorization(Ceed ceed, CeedScalar *mat, CeedScalar *tau, 451 CeedInt m, CeedInt n); 452 CEED_EXTERN int CeedSymmetricSchurDecomposition(Ceed ceed, CeedScalar *mat, 453 CeedScalar *lambda, CeedInt n); 454 CEED_EXTERN int CeedSimultaneousDiagonalization(Ceed ceed, CeedScalar *matA, 455 CeedScalar *matB, CeedScalar *x, CeedScalar *lambda, CeedInt n); 456 457 /** Handle for the object describing the user CeedQFunction 458 459 @param ctx user-defined context set using CeedQFunctionSetContext() or NULL 460 461 @param Q number of quadrature points at which to evaluate 462 463 @param in array of pointers to each input argument in the order provided 464 by the user in CeedQFunctionAddInput(). Each array has shape 465 `[dim, ncomp, Q]` where `dim` is the geometric dimension for 466 \ref CEED_EVAL_GRAD (`dim=1` for \ref CEED_EVAL_INTERP) and 467 `ncomp` is the number of field components (`ncomp=1` for 468 scalar fields). This results in indexing the `i`th input at 469 quadrature point `j` as `in[i][(d*ncomp + c)*Q + j]`. 470 471 @param out array of pointers to each output array in the order provided 472 using CeedQFunctionAddOutput(). The shapes are as above for 473 \a in. 474 475 @return An error code: 0 - success, otherwise - failure 476 477 @ingroup CeedQFunction 478 **/ 479 typedef int (*CeedQFunctionUser)(void *ctx, const CeedInt Q, 480 const CeedScalar *const *in, 481 CeedScalar *const *out); 482 483 CEED_EXTERN int CeedQFunctionCreateInterior(Ceed ceed, CeedInt vlength, 484 CeedQFunctionUser f, const char *source, CeedQFunction *qf); 485 CEED_EXTERN int CeedQFunctionCreateInteriorByName(Ceed ceed, const char *name, 486 CeedQFunction *qf); 487 CEED_EXTERN int CeedQFunctionCreateIdentity(Ceed ceed, CeedInt size, 488 CeedEvalMode inmode, CeedEvalMode outmode, CeedQFunction *qf); 489 CEED_EXTERN int CeedQFunctionAddInput(CeedQFunction qf, const char *fieldname, 490 CeedInt size, CeedEvalMode emode); 491 CEED_EXTERN int CeedQFunctionAddOutput(CeedQFunction qf, const char *fieldname, 492 CeedInt size, CeedEvalMode emode); 493 CEED_EXTERN int CeedQFunctionSetContext(CeedQFunction qf, void *ctx, 494 size_t ctxsize); 495 CEED_EXTERN int CeedQFunctionView(CeedQFunction qf, FILE *stream); 496 CEED_EXTERN int CeedQFunctionApply(CeedQFunction qf, CeedInt Q, 497 CeedVector *u, CeedVector *v); 498 CEED_EXTERN int CeedQFunctionDestroy(CeedQFunction *qf); 499 500 CEED_EXTERN int CeedOperatorCreate(Ceed ceed, CeedQFunction qf, 501 CeedQFunction dqf, CeedQFunction dqfT, 502 CeedOperator *op); 503 CEED_EXTERN int CeedCompositeOperatorCreate(Ceed ceed, CeedOperator *op); 504 CEED_EXTERN int CeedOperatorSetField(CeedOperator op, const char *fieldname, 505 CeedElemRestriction r, CeedBasis b, 506 CeedVector v); 507 CEED_EXTERN int CeedCompositeOperatorAddSub(CeedOperator compositeop, 508 CeedOperator subop); 509 CEED_EXTERN int CeedOperatorLinearAssembleQFunction(CeedOperator op, 510 CeedVector *assembled, CeedElemRestriction *rstr, CeedRequest *request); 511 CEED_EXTERN int CeedOperatorLinearAssembleDiagonal(CeedOperator op, 512 CeedVector assembled, CeedRequest *request); 513 CEED_EXTERN int CeedOperatorLinearAssembleAddDiagonal(CeedOperator op, 514 CeedVector assembled, CeedRequest *request); 515 CEED_EXTERN int CeedOperatorLinearAssemblePointBlockDiagonal(CeedOperator op, 516 CeedVector assembled, CeedRequest *request); 517 CEED_EXTERN int CeedOperatorLinearAssembleAddPointBlockDiagonal(CeedOperator op, 518 CeedVector assembled, CeedRequest *request); 519 CEED_EXTERN int CeedOperatorMultigridLevelCreate(CeedOperator opFine, 520 CeedVector PMultFine, CeedElemRestriction rstrCoarse, CeedBasis basisCoarse, 521 CeedOperator *opCoarse, CeedOperator *opProlong, CeedOperator *opRestrict); 522 CEED_EXTERN int CeedOperatorMultigridLevelCreateTensorH1( 523 CeedOperator opFine, CeedVector PMultFine, CeedElemRestriction rstrCoarse, 524 CeedBasis basisCoarse, const CeedScalar *interpCtoF, CeedOperator *opCoarse, 525 CeedOperator *opProlong, CeedOperator *opRestrict); 526 CEED_EXTERN int CeedOperatorMultigridLevelCreateH1(CeedOperator opFine, 527 CeedVector PMultFine, CeedElemRestriction rstrCoarse, CeedBasis basisCoarse, 528 const CeedScalar *interpCtoF, CeedOperator *opCoarse, 529 CeedOperator *opProlong, CeedOperator *opRestrict); 530 CEED_EXTERN int CeedOperatorCreateFDMElementInverse(CeedOperator op, 531 CeedOperator *fdminv, CeedRequest *request); 532 CEED_EXTERN int CeedOperatorView(CeedOperator op, FILE *stream); 533 CEED_EXTERN int CeedOperatorApply(CeedOperator op, CeedVector in, 534 CeedVector out, CeedRequest *request); 535 CEED_EXTERN int CeedOperatorApplyAdd(CeedOperator op, CeedVector in, 536 CeedVector out, CeedRequest *request); 537 CEED_EXTERN int CeedOperatorDestroy(CeedOperator *op); 538 539 /** 540 @brief Return integer power 541 542 @param[in] base The base to exponentiate 543 @param[in] power The power to raise the base to 544 545 @return base^power 546 547 @ref Utility 548 **/ 549 static inline CeedInt CeedIntPow(CeedInt base, CeedInt power) { 550 CeedInt result = 1; 551 while (power) { 552 if (power & 1) result *= base; 553 power >>= 1; 554 base *= base; 555 } 556 return result; 557 } 558 559 /** 560 @brief Return minimum of two integers 561 562 @param[in] a The first integer to compare 563 @param[in] b The second integer to compare 564 565 @return The minimum of the two integers 566 567 @ref Utility 568 **/ 569 static inline CeedInt CeedIntMin(CeedInt a, CeedInt b) { return a < b ? a : b; } 570 571 /** 572 @brief Return maximum of two integers 573 574 @param[in] a The first integer to compare 575 @param[in] b The second integer to compare 576 577 @return The maximum of the two integers 578 579 @ref Utility 580 **/ 581 static inline CeedInt CeedIntMax(CeedInt a, CeedInt b) { return a > b ? a : b; } 582 583 #endif 584