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