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