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 CeedVectorAXPY(CeedVector y, CeedScalar alpha, CeedVector x); 325 CEED_EXTERN int CeedVectorPointwiseMult(CeedVector w, CeedVector x, CeedVector y); 326 CEED_EXTERN int CeedVectorReciprocal(CeedVector vec); 327 CEED_EXTERN int CeedVectorView(CeedVector vec, const char *fp_fmt, FILE *stream); 328 CEED_EXTERN int CeedVectorGetLength(CeedVector vec, CeedInt *length); 329 CEED_EXTERN int CeedVectorDestroy(CeedVector *vec); 330 331 CEED_EXTERN CeedRequest *const CEED_REQUEST_IMMEDIATE; 332 CEED_EXTERN CeedRequest *const CEED_REQUEST_ORDERED; 333 CEED_EXTERN int CeedRequestWait(CeedRequest *req); 334 335 /// Argument for CeedOperatorSetField that vector is collocated with 336 /// quadrature points, used with QFunction eval mode CEED_EVAL_NONE 337 /// or CEED_EVAL_INTERP only, not with CEED_EVAL_GRAD, CEED_EVAL_DIV, 338 /// or CEED_EVAL_CURL 339 /// @ingroup CeedBasis 340 CEED_EXTERN const CeedBasis CEED_BASIS_COLLOCATED; 341 342 /// Argument for CeedOperatorSetField to use active input or output 343 /// @ingroup CeedVector 344 CEED_EXTERN const CeedVector CEED_VECTOR_ACTIVE; 345 346 /// Argument for CeedOperatorSetField to use no vector, used with 347 /// qfunction input with eval mode CEED_EVAL_WEIGHT 348 /// @ingroup CeedVector 349 CEED_EXTERN const CeedVector CEED_VECTOR_NONE; 350 351 /// Argument for CeedOperatorSetField to use no ElemRestriction, only used with 352 /// eval mode CEED_EVAL_WEIGHT. 353 /// @ingroup CeedElemRestriction 354 CEED_EXTERN const CeedElemRestriction CEED_ELEMRESTRICTION_NONE; 355 356 /// Argument for CeedOperatorCreate that QFunction is not created by user. 357 /// Only used for QFunctions dqf and dqfT. If implemented, a backend may 358 /// attempt to provide the action of these QFunctions. 359 /// @ingroup CeedQFunction 360 CEED_EXTERN const CeedQFunction CEED_QFUNCTION_NONE; 361 362 /// Denotes whether a linear transformation or its transpose should be applied 363 /// @ingroup CeedBasis 364 typedef enum { 365 /// Apply the linear transformation 366 CEED_NOTRANSPOSE, 367 /// Apply the transpose 368 CEED_TRANSPOSE 369 } CeedTransposeMode; 370 371 CEED_EXTERN const char *const CeedTransposeModes[]; 372 373 /// Argument for CeedElemRestrictionCreateStrided that L-vector is in 374 /// the Ceed backend's preferred layout. This argument should only be used 375 /// with vectors created by a Ceed backend. 376 /// @ingroup CeedElemRestriction 377 CEED_EXTERN const CeedInt CEED_STRIDES_BACKEND[3]; 378 379 CEED_EXTERN int CeedElemRestrictionCreate(Ceed ceed, CeedInt num_elem, 380 CeedInt elem_size, CeedInt num_comp, CeedInt comp_stride, CeedInt l_size, 381 CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *offsets, 382 CeedElemRestriction *rstr); 383 CEED_EXTERN int CeedElemRestrictionCreateStrided(Ceed ceed, 384 CeedInt num_elem, CeedInt elem_size, CeedInt num_comp, CeedInt l_size, 385 const CeedInt strides[3], CeedElemRestriction *rstr); 386 CEED_EXTERN int CeedElemRestrictionCreateBlocked(Ceed ceed, CeedInt num_elem, 387 CeedInt elem_size, CeedInt blk_size, CeedInt num_comp, CeedInt comp_stride, 388 CeedInt l_size, CeedMemType mem_type, CeedCopyMode copy_mode, 389 const CeedInt *offsets, CeedElemRestriction *rstr); 390 CEED_EXTERN int CeedElemRestrictionCreateBlockedStrided(Ceed ceed, 391 CeedInt num_elem, CeedInt elem_size, CeedInt blk_size, CeedInt num_comp, 392 CeedInt l_size, const CeedInt strides[3], CeedElemRestriction *rstr); 393 CEED_EXTERN int CeedElemRestrictionReferenceCopy(CeedElemRestriction rstr, 394 CeedElemRestriction *rstr_copy); 395 CEED_EXTERN int CeedElemRestrictionCreateVector(CeedElemRestriction rstr, 396 CeedVector *lvec, CeedVector *evec); 397 CEED_EXTERN int CeedElemRestrictionApply(CeedElemRestriction rstr, 398 CeedTransposeMode t_mode, CeedVector u, CeedVector ru, CeedRequest *request); 399 CEED_EXTERN int CeedElemRestrictionApplyBlock(CeedElemRestriction rstr, 400 CeedInt block, CeedTransposeMode t_mode, CeedVector u, CeedVector ru, 401 CeedRequest *request); 402 CEED_EXTERN int CeedElemRestrictionGetCompStride(CeedElemRestriction rstr, 403 CeedInt *comp_stride); 404 CEED_EXTERN int CeedElemRestrictionGetNumElements(CeedElemRestriction rstr, 405 CeedInt *num_elem); 406 CEED_EXTERN int CeedElemRestrictionGetElementSize(CeedElemRestriction rstr, 407 CeedInt *elem_size); 408 CEED_EXTERN int CeedElemRestrictionGetLVectorSize(CeedElemRestriction rstr, 409 CeedInt *l_size); 410 CEED_EXTERN int CeedElemRestrictionGetNumComponents(CeedElemRestriction rstr, 411 CeedInt *num_comp); 412 CEED_EXTERN int CeedElemRestrictionGetNumBlocks(CeedElemRestriction rstr, 413 CeedInt *num_blk); 414 CEED_EXTERN int CeedElemRestrictionGetBlockSize(CeedElemRestriction rstr, 415 CeedInt *blk_size); 416 CEED_EXTERN int CeedElemRestrictionGetMultiplicity(CeedElemRestriction rstr, 417 CeedVector mult); 418 CEED_EXTERN int CeedElemRestrictionView(CeedElemRestriction rstr, FILE *stream); 419 CEED_EXTERN int CeedElemRestrictionDestroy(CeedElemRestriction *rstr); 420 421 // The formalism here is that we have the structure 422 // \int_\Omega v^T f_0(u, \nabla u, qdata) + (\nabla v)^T f_1(u, \nabla u, qdata) 423 // where gradients are with respect to the reference element. 424 425 /// Basis evaluation mode 426 /// 427 /// Modes can be bitwise ORed when passing to most functions. 428 /// @ingroup CeedBasis 429 typedef enum { 430 /// Perform no evaluation (either because there is no data or it is already at 431 /// quadrature points) 432 CEED_EVAL_NONE = 0, 433 /// Interpolate from nodes to quadrature points 434 CEED_EVAL_INTERP = 1, 435 /// Evaluate gradients at quadrature points from input in a nodal basis 436 CEED_EVAL_GRAD = 2, 437 /// Evaluate divergence at quadrature points from input in a nodal basis 438 CEED_EVAL_DIV = 4, 439 /// Evaluate curl at quadrature points from input in a nodal basis 440 CEED_EVAL_CURL = 8, 441 /// Using no input, evaluate quadrature weights on the reference element 442 CEED_EVAL_WEIGHT = 16, 443 } CeedEvalMode; 444 445 CEED_EXTERN const char *const CeedEvalModes[]; 446 447 /// Type of quadrature; also used for location of nodes 448 /// @ingroup CeedBasis 449 typedef enum { 450 /// Gauss-Legendre quadrature 451 CEED_GAUSS = 0, 452 /// Gauss-Legendre-Lobatto quadrature 453 CEED_GAUSS_LOBATTO = 1, 454 } CeedQuadMode; 455 456 CEED_EXTERN const char *const CeedQuadModes[]; 457 458 /// Type of basis shape to create non-tensor H1 element basis 459 /// 460 /// Dimension can be extracted with bitwise AND 461 /// (CeedElemTopology & 2**(dim + 2)) == TRUE 462 /// @ingroup CeedBasis 463 typedef enum { 464 /// Line 465 CEED_LINE = 1 << 16 | 0, 466 /// Triangle - 2D shape 467 CEED_TRIANGLE = 2 << 16 | 1, 468 /// Quadralateral - 2D shape 469 CEED_QUAD = 2 << 16 | 2, 470 /// Tetrahedron - 3D shape 471 CEED_TET = 3 << 16 | 3, 472 /// Pyramid - 3D shape 473 CEED_PYRAMID = 3 << 16 | 4, 474 /// Prism - 3D shape 475 CEED_PRISM = 3 << 16 | 5, 476 /// Hexehedron - 3D shape 477 CEED_HEX = 3 << 16 | 6, 478 } CeedElemTopology; 479 480 CEED_EXTERN const char *const CeedElemTopologies[]; 481 482 CEED_EXTERN int CeedBasisCreateTensorH1Lagrange(Ceed ceed, CeedInt dim, 483 CeedInt num_comp, CeedInt P, CeedInt Q, CeedQuadMode quad_mode, CeedBasis *basis); 484 CEED_EXTERN int CeedBasisCreateTensorH1(Ceed ceed, CeedInt dim, CeedInt num_comp, 485 CeedInt P_1d, CeedInt Q_1d, 486 const CeedScalar *interp_1d, 487 const CeedScalar *grad_1d, 488 const CeedScalar *q_ref_1d, 489 const CeedScalar *q_weight_1d, 490 CeedBasis *basis); 491 CEED_EXTERN int CeedBasisCreateH1(Ceed ceed, CeedElemTopology topo, 492 CeedInt num_comp, 493 CeedInt num_nodes, CeedInt nqpts, 494 const CeedScalar *interp, 495 const CeedScalar *grad, 496 const CeedScalar *q_ref, 497 const CeedScalar *q_weights, CeedBasis *basis); 498 CEED_EXTERN int CeedBasisReferenceCopy(CeedBasis basis, CeedBasis *basis_copy); 499 CEED_EXTERN int CeedBasisView(CeedBasis basis, FILE *stream); 500 CEED_EXTERN int CeedBasisApply(CeedBasis basis, CeedInt num_elem, 501 CeedTransposeMode t_mode, 502 CeedEvalMode eval_mode, CeedVector u, CeedVector v); 503 CEED_EXTERN int CeedBasisGetDimension(CeedBasis basis, CeedInt *dim); 504 CEED_EXTERN int CeedBasisGetTopology(CeedBasis basis, CeedElemTopology *topo); 505 CEED_EXTERN int CeedBasisGetNumComponents(CeedBasis basis, CeedInt *num_comp); 506 CEED_EXTERN int CeedBasisGetNumNodes(CeedBasis basis, CeedInt *P); 507 CEED_EXTERN int CeedBasisGetNumNodes1D(CeedBasis basis, CeedInt *P_1d); 508 CEED_EXTERN int CeedBasisGetNumQuadraturePoints(CeedBasis basis, CeedInt *Q); 509 CEED_EXTERN int CeedBasisGetNumQuadraturePoints1D(CeedBasis basis, 510 CeedInt *Q_1d); 511 CEED_EXTERN int CeedBasisGetQRef(CeedBasis basis, const CeedScalar **q_ref); 512 CEED_EXTERN int CeedBasisGetQWeights(CeedBasis basis, 513 const CeedScalar **q_weights); 514 CEED_EXTERN int CeedBasisGetInterp(CeedBasis basis, const CeedScalar **interp); 515 CEED_EXTERN int CeedBasisGetInterp1D(CeedBasis basis, 516 const CeedScalar **interp_1d); 517 CEED_EXTERN int CeedBasisGetGrad(CeedBasis basis, const CeedScalar **grad); 518 CEED_EXTERN int CeedBasisGetGrad1D(CeedBasis basis, const CeedScalar **grad_1d); 519 CEED_EXTERN int CeedBasisDestroy(CeedBasis *basis); 520 521 CEED_EXTERN int CeedGaussQuadrature(CeedInt Q, CeedScalar *q_ref_1d, 522 CeedScalar *q_weight_1d); 523 CEED_EXTERN int CeedLobattoQuadrature(CeedInt Q, CeedScalar *q_ref_1d, 524 CeedScalar *q_weight_1d); 525 CEED_EXTERN int CeedQRFactorization(Ceed ceed, CeedScalar *mat, CeedScalar *tau, 526 CeedInt m, CeedInt n); 527 CEED_EXTERN int CeedSymmetricSchurDecomposition(Ceed ceed, CeedScalar *mat, 528 CeedScalar *lambda, CeedInt n); 529 CEED_EXTERN int CeedSimultaneousDiagonalization(Ceed ceed, CeedScalar *mat_A, 530 CeedScalar *mat_B, CeedScalar *x, CeedScalar *lambda, CeedInt n); 531 532 /** Handle for the object describing the user CeedQFunction 533 534 @param ctx user-defined context set using CeedQFunctionSetContext() or NULL 535 536 @param Q number of quadrature points at which to evaluate 537 538 @param in array of pointers to each input argument in the order provided 539 by the user in CeedQFunctionAddInput(). Each array has shape 540 `[dim, num_comp, Q]` where `dim` is the geometric dimension for 541 \ref CEED_EVAL_GRAD (`dim=1` for \ref CEED_EVAL_INTERP) and 542 `num_comp` is the number of field components (`num_comp=1` for 543 scalar fields). This results in indexing the `i`th input at 544 quadrature point `j` as `in[i][(d*num_comp + c)*Q + j]`. 545 546 @param out array of pointers to each output array in the order provided 547 using CeedQFunctionAddOutput(). The shapes are as above for 548 \a in. 549 550 @return An error code: 0 - success, otherwise - failure 551 552 @ingroup CeedQFunction 553 **/ 554 typedef int (*CeedQFunctionUser)(void *ctx, const CeedInt Q, 555 const CeedScalar *const *in, 556 CeedScalar *const *out); 557 558 CEED_EXTERN int CeedQFunctionCreateInterior(Ceed ceed, CeedInt vec_length, 559 CeedQFunctionUser f, const char *source, CeedQFunction *qf); 560 CEED_EXTERN int CeedQFunctionCreateInteriorByName(Ceed ceed, const char *name, 561 CeedQFunction *qf); 562 CEED_EXTERN int CeedQFunctionCreateIdentity(Ceed ceed, CeedInt size, 563 CeedEvalMode in_mode, CeedEvalMode out_mode, CeedQFunction *qf); 564 CEED_EXTERN int CeedQFunctionReferenceCopy(CeedQFunction qf, CeedQFunction *qf_copy); 565 CEED_EXTERN int CeedQFunctionAddInput(CeedQFunction qf, const char *field_name, 566 CeedInt size, CeedEvalMode eval_mode); 567 CEED_EXTERN int CeedQFunctionAddOutput(CeedQFunction qf, const char *field_name, 568 CeedInt size, CeedEvalMode eval_mode); 569 CEED_EXTERN int CeedQFunctionSetContext(CeedQFunction qf, 570 CeedQFunctionContext ctx); 571 CEED_EXTERN int CeedQFunctionView(CeedQFunction qf, FILE *stream); 572 CEED_EXTERN int CeedQFunctionApply(CeedQFunction qf, CeedInt Q, 573 CeedVector *u, CeedVector *v); 574 CEED_EXTERN int CeedQFunctionDestroy(CeedQFunction *qf); 575 576 CEED_EXTERN int CeedQFunctionContextCreate(Ceed ceed, 577 CeedQFunctionContext *ctx); 578 CEED_EXTERN int CeedQFunctionContextReferenceCopy(CeedQFunctionContext ctx, 579 CeedQFunctionContext *ctx_copy); 580 CEED_EXTERN int CeedQFunctionContextSetData(CeedQFunctionContext ctx, 581 CeedMemType mem_type, CeedCopyMode copy_mode, size_t size, void *data); 582 CEED_EXTERN int CeedQFunctionContextGetData(CeedQFunctionContext ctx, 583 CeedMemType mem_type, 584 void *data); 585 CEED_EXTERN int CeedQFunctionContextRestoreData(CeedQFunctionContext ctx, 586 void *data); 587 CEED_EXTERN int CeedQFunctionContextView(CeedQFunctionContext ctx, 588 FILE *stream); 589 CEED_EXTERN int CeedQFunctionContextDestroy(CeedQFunctionContext *ctx); 590 591 CEED_EXTERN int CeedOperatorCreate(Ceed ceed, CeedQFunction qf, 592 CeedQFunction dqf, CeedQFunction dqfT, 593 CeedOperator *op); 594 CEED_EXTERN int CeedCompositeOperatorCreate(Ceed ceed, CeedOperator *op); 595 CEED_EXTERN int CeedOperatorReferenceCopy(CeedOperator op, CeedOperator *op_copy); 596 CEED_EXTERN int CeedOperatorSetField(CeedOperator op, const char *field_name, 597 CeedElemRestriction r, CeedBasis b, 598 CeedVector v); 599 CEED_EXTERN int CeedCompositeOperatorAddSub(CeedOperator composite_op, 600 CeedOperator sub_op); 601 CEED_EXTERN int CeedOperatorLinearAssembleQFunction(CeedOperator op, 602 CeedVector *assembled, CeedElemRestriction *rstr, CeedRequest *request); 603 CEED_EXTERN int CeedOperatorLinearAssembleDiagonal(CeedOperator op, 604 CeedVector assembled, CeedRequest *request); 605 CEED_EXTERN int CeedOperatorLinearAssembleAddDiagonal(CeedOperator op, 606 CeedVector assembled, CeedRequest *request); 607 CEED_EXTERN int CeedOperatorLinearAssemblePointBlockDiagonal(CeedOperator op, 608 CeedVector assembled, CeedRequest *request); 609 CEED_EXTERN int CeedOperatorLinearAssembleAddPointBlockDiagonal(CeedOperator op, 610 CeedVector assembled, CeedRequest *request); 611 CEED_EXTERN int CeedOperatorLinearAssembleSymbolic(CeedOperator op, 612 CeedInt *num_entries, CeedInt **rows, CeedInt **cols); 613 CEED_EXTERN int CeedOperatorLinearAssemble(CeedOperator op, CeedVector values); 614 CEED_EXTERN int CeedOperatorMultigridLevelCreate(CeedOperator op_fine, 615 CeedVector p_mult_fine, CeedElemRestriction rstr_coarse, CeedBasis basis_coarse, 616 CeedOperator *op_coarse, CeedOperator *op_prolong, CeedOperator *op_restrict); 617 CEED_EXTERN int CeedOperatorMultigridLevelCreateTensorH1( 618 CeedOperator op_fine, CeedVector p_mult_fine, CeedElemRestriction rstr_coarse, 619 CeedBasis basis_coarse, const CeedScalar *interp_c_to_f, CeedOperator *op_coarse, 620 CeedOperator *op_prolong, CeedOperator *op_restrict); 621 CEED_EXTERN int CeedOperatorMultigridLevelCreateH1(CeedOperator op_fine, 622 CeedVector p_mult_fine, CeedElemRestriction rstr_coarse, CeedBasis basis_coarse, 623 const CeedScalar *interp_c_to_f, CeedOperator *op_coarse, 624 CeedOperator *op_prolong, CeedOperator *op_restrict); 625 CEED_EXTERN int CeedOperatorCreateFDMElementInverse(CeedOperator op, 626 CeedOperator *fdm_inv, CeedRequest *request); 627 CEED_EXTERN int CeedOperatorSetNumQuadraturePoints(CeedOperator op, CeedInt num_qpts); 628 CEED_EXTERN int CeedOperatorView(CeedOperator op, FILE *stream); 629 CEED_EXTERN int CeedOperatorApply(CeedOperator op, CeedVector in, 630 CeedVector out, CeedRequest *request); 631 CEED_EXTERN int CeedOperatorApplyAdd(CeedOperator op, CeedVector in, 632 CeedVector out, CeedRequest *request); 633 CEED_EXTERN int CeedOperatorDestroy(CeedOperator *op); 634 635 /** 636 @brief Return integer power 637 638 @param[in] base The base to exponentiate 639 @param[in] power The power to raise the base to 640 641 @return base^power 642 643 @ref Utility 644 **/ 645 static inline CeedInt CeedIntPow(CeedInt base, CeedInt power) { 646 CeedInt result = 1; 647 while (power) { 648 if (power & 1) result *= base; 649 power >>= 1; 650 base *= base; 651 } 652 return result; 653 } 654 655 /** 656 @brief Return minimum of two integers 657 658 @param[in] a The first integer to compare 659 @param[in] b The second integer to compare 660 661 @return The minimum of the two integers 662 663 @ref Utility 664 **/ 665 static inline CeedInt CeedIntMin(CeedInt a, CeedInt b) { return a < b ? a : b; } 666 667 /** 668 @brief Return maximum of two integers 669 670 @param[in] a The first integer to compare 671 @param[in] b The second integer to compare 672 673 @return The maximum of the two integers 674 675 @ref Utility 676 **/ 677 static inline CeedInt CeedIntMax(CeedInt a, CeedInt b) { return a > b ? a : b; } 678 679 // Used to ensure initialization before CeedInit() 680 CEED_EXTERN int CeedRegisterAll(void); 681 // Used to ensure initialization before CeedQFunctionCreate*() 682 CEED_EXTERN int CeedQFunctionRegisterAll(void); 683 684 #endif 685