xref: /libCEED/include/ceed.h (revision 25118b5f4f2ec4a800d461101d711b68900b0d81)
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) &&__INTEL_COMPILER >= 900
88 #    define CeedPragmaSIMD _Pragma("simd")
89 #  elif defined(__GNUC__) && __GNUC__ >= 5
90 #    define CeedPragmaSIMD _Pragma("GCC ivdep")
91 #  elif defined(_OPENMP) && _OPENMP >= 201307 // OpenMP-4.0 (July, 2013)
92 #    define CeedPragmaSIMD _Pragma("omp simd")
93 #  else
94 #    define CeedPragmaSIMD
95 #  endif
96 #endif
97 
98 #include <assert.h>
99 #include <stdint.h>
100 #include <stddef.h>
101 #include <stdarg.h>
102 #include <stdio.h>
103 #include <stdbool.h>
104 
105 /// Integer type, used for indexing
106 /// @ingroup Ceed
107 typedef int32_t CeedInt;
108 /// Scalar (floating point) type
109 /// @ingroup Ceed
110 typedef double CeedScalar;
111 
112 /// Library context created by CeedInit()
113 /// @ingroup CeedUser
114 typedef struct Ceed_private *Ceed;
115 /// Non-blocking Ceed interfaces return a CeedRequest.
116 /// To perform an operation immediately, pass \ref CEED_REQUEST_IMMEDIATE instead.
117 /// @ingroup CeedUser
118 typedef struct CeedRequest_private *CeedRequest;
119 /// Handle for vectors over the field \ref CeedScalar
120 /// @ingroup CeedVectorUser
121 typedef struct CeedVector_private *CeedVector;
122 /// Handle for object describing restriction to elements
123 /// @ingroup CeedElemRestrictionUser
124 typedef struct CeedElemRestriction_private *CeedElemRestriction;
125 /// Handle for object describing discrete finite element evaluations
126 /// @ingroup CeedBasisUser
127 typedef struct CeedBasis_private *CeedBasis;
128 /// Handle for object describing functions evaluated independently at quadrature points
129 /// @ingroup CeedQFunctionUser
130 typedef struct CeedQFunction_private *CeedQFunction;
131 /// Handle for object describing FE-type operators acting on vectors
132 ///
133 /// Given an element restriction \f$E\f$, basis evaluator \f$B\f$, and
134 ///   quadrature function\f$f\f$, a CeedOperator expresses operations of the form
135 ///   $$ E^T B^T f(B E u) $$
136 ///   acting on the vector \f$u\f$.
137 /// @ingroup CeedOperatorUser
138 typedef struct CeedOperator_private *CeedOperator;
139 
140 CEED_EXTERN int CeedInit(const char *resource, Ceed *ceed);
141 CEED_EXTERN int CeedGetResource(Ceed ceed, const char **resource);
142 CEED_EXTERN int CeedView(Ceed ceed, FILE *stream);
143 CEED_EXTERN int CeedDestroy(Ceed *ceed);
144 
145 CEED_EXTERN int CeedErrorImpl(Ceed, const char *, int, const char *, int,
146                               const char *, ...);
147 /// Raise an error on ceed object
148 ///
149 /// @param ceed Ceed library context or NULL
150 /// @param ecode Error code (int)
151 /// @param ... printf-style format string followed by arguments as needed
152 ///
153 /// @ingroup Ceed
154 /// @sa CeedSetErrorHandler()
155 #if defined(__clang__)
156 /// Use nonstandard ternary to convince the compiler/clang-tidy that this
157 /// function never returns zero.
158 #  define CeedError(ceed, ecode, ...)                                     \
159   (CeedErrorImpl((ceed), __FILE__, __LINE__, __func__, (ecode), __VA_ARGS__) ?: (ecode))
160 #else
161 #  define CeedError(ceed, ecode, ...)                                     \
162   CeedErrorImpl((ceed), __FILE__, __LINE__, __func__, (ecode), __VA_ARGS__) ?: (ecode)
163 #endif
164 /// Specify memory type
165 ///
166 /// Many Ceed interfaces take or return pointers to memory.  This enum is used to
167 /// specify where the memory being provided or requested must reside.
168 /// @ingroup Ceed
169 typedef enum {
170   /// Memory resides on the host
171   CEED_MEM_HOST,
172   /// Memory resides on a device (corresponding to \ref Ceed resource)
173   CEED_MEM_DEVICE,
174 } CeedMemType;
175 
176 CEED_EXTERN const char *const CeedMemTypes[];
177 
178 CEED_EXTERN int CeedGetPreferredMemType(Ceed ceed, CeedMemType *type);
179 
180 /// Conveys ownership status of arrays passed to Ceed interfaces.
181 /// @ingroup Ceed
182 typedef enum {
183   /// Implementation will copy the values and not store the passed pointer.
184   CEED_COPY_VALUES,
185   /// Implementation can use and modify the data provided by the user, but does
186   /// not take ownership.
187   CEED_USE_POINTER,
188   /// Implementation takes ownership of the pointer and will free using
189   /// CeedFree() when done using it.  The user should not assume that the
190   /// pointer remains valid after ownership has been transferred.  Note that
191   /// arrays allocated using C++ operator new or other allocators cannot
192   /// generally be freed using CeedFree().  CeedFree() is capable of freeing any
193   /// memory that can be freed using free(3).
194   CEED_OWN_POINTER,
195 } CeedCopyMode;
196 
197 /// Denotes type of vector norm to be computed
198 /// @ingroup CeedVector
199 typedef enum {
200   /// L_1 norm: sum_i |x_i|
201   CEED_NORM_1,
202   /// L_2 norm: sqrt(sum_i |x_i|^2)
203   CEED_NORM_2,
204   /// L_Infinity norm: max_i |x_i|
205   CEED_NORM_MAX,
206 } CeedNormType;
207 
208 CEED_EXTERN const char *const CeedCopyModes[];
209 
210 CEED_EXTERN int CeedVectorCreate(Ceed ceed, CeedInt len, CeedVector *vec);
211 CEED_EXTERN int CeedVectorSetArray(CeedVector vec, CeedMemType mtype,
212                                    CeedCopyMode cmode, CeedScalar *array);
213 CEED_EXTERN int CeedVectorSetValue(CeedVector vec, CeedScalar value);
214 CEED_EXTERN int CeedVectorSyncArray(CeedVector vec, CeedMemType mtype);
215 CEED_EXTERN int CeedVectorGetArray(CeedVector vec, CeedMemType mtype,
216                                    CeedScalar **array);
217 CEED_EXTERN int CeedVectorGetArrayRead(CeedVector vec, CeedMemType mtype,
218                                        const CeedScalar **array);
219 CEED_EXTERN int CeedVectorRestoreArray(CeedVector vec, CeedScalar **array);
220 CEED_EXTERN int CeedVectorRestoreArrayRead(CeedVector vec,
221     const CeedScalar **array);
222 CEED_EXTERN int CeedVectorNorm(CeedVector vec, CeedNormType type,
223                                CeedScalar *norm);
224 CEED_EXTERN int CeedVectorView(CeedVector vec, const char *fpfmt, FILE *stream);
225 CEED_EXTERN int CeedVectorGetLength(CeedVector vec, CeedInt *length);
226 CEED_EXTERN int CeedVectorDestroy(CeedVector *vec);
227 
228 CEED_EXTERN CeedRequest *const CEED_REQUEST_IMMEDIATE;
229 CEED_EXTERN CeedRequest *const CEED_REQUEST_ORDERED;
230 CEED_EXTERN int CeedRequestWait(CeedRequest *req);
231 
232 /// Argument for CeedOperatorSetField that vector is collocated with
233 /// quadrature points, used with QFunction eval mode CEED_EVAL_NONE
234 /// or CEED_EVAL_INTERP only, not with CEED_EVAL_GRAD, CEED_EVAL_DIV,
235 /// or CEED_EVAL_CURL
236 /// @ingroup CeedBasis
237 CEED_EXTERN const CeedBasis CEED_BASIS_COLLOCATED;
238 
239 /// Argument for CeedOperatorSetField to use active input or output
240 /// @ingroup CeedVector
241 CEED_EXTERN const CeedVector CEED_VECTOR_ACTIVE;
242 
243 /// Argument for CeedOperatorSetField to use no vector, used with
244 /// qfunction input with eval mode CEED_EVAL_WEIGHT
245 /// @ingroup CeedVector
246 CEED_EXTERN const CeedVector CEED_VECTOR_NONE;
247 
248 /// Argument for CeedOperatorSetField to use no ElemRestriction, only used with
249 /// eval mode CEED_EVAL_WEIGHT.
250 /// @ingroup CeedElemRestriction
251 CEED_EXTERN const CeedElemRestriction CEED_ELEMRESTRICTION_NONE;
252 
253 /// Argument for CeedOperatorCreate that QFunction is not created by user.
254 /// Only used for QFunctions dqf and dqfT. If implemented, a backend may
255 /// attempt to provide the action of these QFunctions.
256 /// @ingroup CeedQFunction
257 CEED_EXTERN const CeedQFunction CEED_QFUNCTION_NONE;
258 
259 /// Denotes whether a linear transformation or its transpose should be applied
260 /// @ingroup CeedBasis
261 typedef enum {
262   /// Apply the linear transformation
263   CEED_NOTRANSPOSE,
264   /// Apply the transpose
265   CEED_TRANSPOSE
266 } CeedTransposeMode;
267 
268 CEED_EXTERN const char *const CeedTransposeModes[];
269 
270 /// Denotes whether a L-vector is ordered [component, node] or [node, component]
271 ///   with the right-most index being contiguous in memory
272 /// @ingroup CeedElemRestriction
273 typedef enum {
274   /// L-vector data is not interlaced, ordered [component, node]
275   CEED_NONINTERLACED,
276   /// L-vector data is interlaced, ordered [node, component]
277   CEED_INTERLACED
278 } CeedInterlaceMode;
279 
280 CEED_EXTERN const char *const CeedInterlaceModes[];
281 
282 /// Argument for CeedElemRestrictionCreateStrided that L-vector is in
283 /// the Ceed backend's preferred layout. This argument should only be used
284 /// with vectors created by a Ceed backend.
285 /// @ingroup CeedElemRestriction
286 CEED_EXTERN const CeedInt CEED_STRIDES_BACKEND[3];
287 
288 CEED_EXTERN int CeedElemRestrictionCreate(Ceed ceed, CeedInterlaceMode imode,
289     CeedInt nelem, CeedInt elemsize, CeedInt nnodes, CeedInt ncomp,
290     CeedMemType mtype, CeedCopyMode cmode, const CeedInt *indices,
291     CeedElemRestriction *rstr);
292 CEED_EXTERN int CeedElemRestrictionCreateBlocked(Ceed ceed,
293     CeedInterlaceMode imode, CeedInt nelem, CeedInt elemsize, CeedInt blksize,
294     CeedInt nnodes, CeedInt ncomp, CeedMemType mtype, CeedCopyMode cmode,
295     const CeedInt *indices, CeedElemRestriction *rstr);
296 CEED_EXTERN int CeedElemRestrictionCreateStrided(Ceed ceed,
297     CeedInt nelem, CeedInt elemsize, CeedInt nnodes, CeedInt ncomp,
298     const CeedInt strides[3], CeedElemRestriction *rstr);
299 CEED_EXTERN int CeedElemRestrictionCreateBlockedStrided(Ceed ceed,
300     CeedInt nelem, CeedInt elemsize, CeedInt blksize, CeedInt nnodes,
301     CeedInt ncomp, const CeedInt strides[3], CeedElemRestriction *rstr);
302 CEED_EXTERN int CeedElemRestrictionCreateVector(CeedElemRestriction rstr,
303     CeedVector *lvec, CeedVector *evec);
304 CEED_EXTERN int CeedElemRestrictionApply(CeedElemRestriction rstr,
305     CeedTransposeMode tmode, CeedVector u, CeedVector ru, CeedRequest *request);
306 CEED_EXTERN int CeedElemRestrictionApplyBlock(CeedElemRestriction rstr,
307     CeedInt block, CeedTransposeMode tmode, CeedVector u, CeedVector ru,
308     CeedRequest *request);
309 CEED_EXTERN int CeedElemRestrictionGetIMode(CeedElemRestriction rstr,
310     CeedInterlaceMode *Imode);
311 CEED_EXTERN int CeedElemRestrictionGetNumElements(CeedElemRestriction rstr,
312     CeedInt *numelem);
313 CEED_EXTERN int CeedElemRestrictionGetElementSize(CeedElemRestriction rstr,
314     CeedInt *elemsize);
315 CEED_EXTERN int CeedElemRestrictionGetNumNodes(CeedElemRestriction rstr,
316     CeedInt *numnodes);
317 CEED_EXTERN int CeedElemRestrictionGetNumComponents(CeedElemRestriction rstr,
318     CeedInt *numcomp);
319 CEED_EXTERN int CeedElemRestrictionGetNumBlocks(CeedElemRestriction rstr,
320     CeedInt *numblk);
321 CEED_EXTERN int CeedElemRestrictionGetBlockSize(CeedElemRestriction rstr,
322     CeedInt *blksize);
323 CEED_EXTERN int CeedElemRestrictionGetMultiplicity(CeedElemRestriction rstr,
324     CeedVector mult);
325 CEED_EXTERN int CeedElemRestrictionView(CeedElemRestriction rstr, FILE *stream);
326 CEED_EXTERN int CeedElemRestrictionDestroy(CeedElemRestriction *rstr);
327 
328 // The formalism here is that we have the structure
329 //  \int_\Omega v^T f_0(u, \nabla u, qdata) + (\nabla v)^T f_1(u, \nabla u, qdata)
330 // where gradients are with respect to the reference element.
331 
332 /// Basis evaluation mode
333 ///
334 /// Modes can be bitwise ORed when passing to most functions.
335 /// @ingroup CeedBasis
336 typedef enum {
337   /// Perform no evaluation (either because there is no data or it is already at
338   /// quadrature points)
339   CEED_EVAL_NONE   = 0,
340   /// Interpolate from nodes to quadrature points
341   CEED_EVAL_INTERP = 1,
342   /// Evaluate gradients at quadrature points from input in a nodal basis
343   CEED_EVAL_GRAD   = 2,
344   /// Evaluate divergence at quadrature points from input in a nodal basis
345   CEED_EVAL_DIV    = 4,
346   /// Evaluate curl at quadrature points from input in a nodal basis
347   CEED_EVAL_CURL   = 8,
348   /// Using no input, evaluate quadrature weights on the reference element
349   CEED_EVAL_WEIGHT = 16,
350 } CeedEvalMode;
351 
352 CEED_EXTERN const char *const CeedEvalModes[];
353 
354 /// Type of quadrature; also used for location of nodes
355 /// @ingroup CeedBasis
356 typedef enum {
357   /// Gauss-Legendre quadrature
358   CEED_GAUSS = 0,
359   /// Gauss-Legendre-Lobatto quadrature
360   CEED_GAUSS_LOBATTO = 1,
361 } CeedQuadMode;
362 
363 CEED_EXTERN const char *const CeedQuadModes[];
364 
365 /// Type of basis shape to create non-tensor H1 element basis
366 ///
367 /// Dimension can be extracted with bitwise AND
368 /// (CeedElemTopology & 2**(dim + 2)) == TRUE
369 /// @ingroup CeedBasis
370 typedef enum {
371   /// Line
372   CEED_LINE = 1 << 16 | 0,
373   /// Triangle - 2D shape
374   CEED_TRIANGLE = 2 << 16 | 1,
375   /// Quadralateral - 2D shape
376   CEED_QUAD = 2 << 16 | 2,
377   /// Tetrahedron - 3D shape
378   CEED_TET = 3 << 16 | 3,
379   /// Pyramid - 3D shape
380   CEED_PYRAMID = 3 << 16 | 4,
381   /// Prism - 3D shape
382   CEED_PRISM = 3 << 16 | 5,
383   /// Hexehedron - 3D shape
384   CEED_HEX = 3 << 16 | 6,
385 } CeedElemTopology;
386 
387 CEED_EXTERN const char *const CeedElemTopologies[];
388 
389 CEED_EXTERN int CeedBasisCreateTensorH1Lagrange(Ceed ceed, CeedInt dim,
390     CeedInt ncomp, CeedInt P, CeedInt Q, CeedQuadMode qmode, CeedBasis *basis);
391 CEED_EXTERN int CeedBasisCreateTensorH1(Ceed ceed, CeedInt dim, CeedInt ncomp,
392                                         CeedInt P1d, CeedInt Q1d,
393                                         const CeedScalar *interp1d,
394                                         const CeedScalar *grad1d,
395                                         const CeedScalar *qref1d,
396                                         const CeedScalar *qweight1d,
397                                         CeedBasis *basis);
398 CEED_EXTERN int CeedBasisCreateH1(Ceed ceed, CeedElemTopology topo,
399                                   CeedInt ncomp,
400                                   CeedInt nnodes, CeedInt nqpts,
401                                   const CeedScalar *interp,
402                                   const CeedScalar *grad,
403                                   const CeedScalar *qref,
404                                   const CeedScalar *qweight, CeedBasis *basis);
405 CEED_EXTERN int CeedBasisView(CeedBasis basis, FILE *stream);
406 CEED_EXTERN int CeedBasisGetNumNodes(CeedBasis basis, CeedInt *P);
407 CEED_EXTERN int CeedBasisGetNumQuadraturePoints(CeedBasis basis, CeedInt *Q);
408 CEED_EXTERN int CeedBasisApply(CeedBasis basis, CeedInt nelem,
409                                CeedTransposeMode tmode,
410                                CeedEvalMode emode, CeedVector u, CeedVector v);
411 CEED_EXTERN int CeedBasisDestroy(CeedBasis *basis);
412 
413 CEED_EXTERN int CeedGaussQuadrature(CeedInt Q, CeedScalar *qref1d,
414                                     CeedScalar *qweight1d);
415 CEED_EXTERN int CeedLobattoQuadrature(CeedInt Q, CeedScalar *qref1d,
416                                       CeedScalar *qweight1d);
417 CEED_EXTERN int CeedQRFactorization(Ceed ceed, CeedScalar *mat, CeedScalar *tau,
418                                     CeedInt m, CeedInt n);
419 CEED_EXTERN int CeedSymmetricSchurDecomposition(Ceed ceed, CeedScalar *mat,
420     CeedScalar *lambda, CeedInt n);
421 CEED_EXTERN int CeedSimultaneousDiagonalization(Ceed ceed, CeedScalar *matA,
422     CeedScalar *matB, CeedScalar *x, CeedScalar *lambda, CeedInt n);
423 
424 /** Handle for the object describing the user CeedQFunction
425 
426  @param ctx user-defined context set using CeedQFunctionSetContext() or NULL
427 
428  @param Q   number of quadrature points at which to evaluate
429 
430  @param in  array of pointers to each input argument in the order provided
431               by the user in CeedQFunctionAddInput().  Each array has shape
432               `[dim, ncomp, Q]` where `dim` is the geometric dimension for
433               \ref CEED_EVAL_GRAD (`dim=1` for \ref CEED_EVAL_INTERP) and
434               `ncomp` is the number of field components (`ncomp=1` for
435               scalar fields).  This results in indexing the `i`th input at
436               quadrature point `j` as `in[i][(d*ncomp + c)*Q + j]`.
437 
438  @param out array of pointers to each output array in the order provided
439               using CeedQFunctionAddOutput().  The shapes are as above for
440               \a in.
441 
442  @return An error code: 0 - success, otherwise - failure
443 
444  @ingroup CeedQFunction
445 **/
446 typedef int (*CeedQFunctionUser)(void *ctx, const CeedInt Q,
447                                  const CeedScalar *const *in,
448                                  CeedScalar *const *out);
449 
450 CEED_EXTERN int CeedQFunctionCreateInterior(Ceed ceed, CeedInt vlength,
451     CeedQFunctionUser f, const char *source, CeedQFunction *qf);
452 CEED_EXTERN int CeedQFunctionCreateInteriorByName(Ceed ceed, const char *name,
453     CeedQFunction *qf);
454 CEED_EXTERN int CeedQFunctionCreateIdentity(Ceed ceed, CeedInt size,
455     CeedEvalMode inmode, CeedEvalMode outmode, CeedQFunction *qf);
456 CEED_EXTERN int CeedQFunctionAddInput(CeedQFunction qf, const char *fieldname,
457                                       CeedInt size, CeedEvalMode emode);
458 CEED_EXTERN int CeedQFunctionAddOutput(CeedQFunction qf, const char *fieldname,
459                                        CeedInt size, CeedEvalMode emode);
460 CEED_EXTERN int CeedQFunctionSetContext(CeedQFunction qf, void *ctx,
461                                         size_t ctxsize);
462 CEED_EXTERN int CeedQFunctionView(CeedQFunction qf, FILE *stream);
463 CEED_EXTERN int CeedQFunctionApply(CeedQFunction qf, CeedInt Q,
464                                    CeedVector *u, CeedVector *v);
465 CEED_EXTERN int CeedQFunctionDestroy(CeedQFunction *qf);
466 
467 CEED_EXTERN int CeedOperatorCreate(Ceed ceed, CeedQFunction qf,
468                                    CeedQFunction dqf, CeedQFunction dqfT,
469                                    CeedOperator *op);
470 CEED_EXTERN int CeedCompositeOperatorCreate(Ceed ceed, CeedOperator *op);
471 CEED_EXTERN int CeedOperatorSetField(CeedOperator op, const char *fieldname,
472                                      CeedElemRestriction r, CeedBasis b,
473                                      CeedVector v);
474 CEED_EXTERN int CeedCompositeOperatorAddSub(CeedOperator compositeop,
475     CeedOperator subop);
476 CEED_EXTERN int CeedOperatorAssembleLinearQFunction(CeedOperator op,
477     CeedVector *assembled, CeedElemRestriction *rstr, CeedRequest *request);
478 CEED_EXTERN int CeedOperatorAssembleLinearDiagonal(CeedOperator op,
479     CeedVector *assembled, CeedRequest *request);
480 CEED_EXTERN int CeedOperatorCreateFDMElementInverse(CeedOperator op,
481     CeedOperator *fdminv, CeedRequest *request);
482 CEED_EXTERN int CeedOperatorView(CeedOperator op, FILE *stream);
483 CEED_EXTERN int CeedOperatorApply(CeedOperator op, CeedVector in,
484                                   CeedVector out, CeedRequest *request);
485 CEED_EXTERN int CeedOperatorApplyAdd(CeedOperator op, CeedVector in,
486                                      CeedVector out, CeedRequest *request);
487 CEED_EXTERN int CeedOperatorDestroy(CeedOperator *op);
488 
489 /**
490   @brief Return integer power
491 
492   @param[in] base   The base to exponentiate
493   @param[in] power  The power to raise the base to
494 
495   @return base^power
496 
497   @ref Utility
498 **/
499 static inline CeedInt CeedIntPow(CeedInt base, CeedInt power) {
500   CeedInt result = 1;
501   while (power) {
502     if (power & 1) result *= base;
503     power >>= 1;
504     base *= base;
505   }
506   return result;
507 }
508 
509 /**
510   @brief Return minimum of two integers
511 
512   @param[in] a  The first integer to compare
513   @param[in] b  The second integer to compare
514 
515   @return The minimum of the two integers
516 
517   @ref Utility
518 **/
519 static inline CeedInt CeedIntMin(CeedInt a, CeedInt b) { return a < b ? a : b; }
520 
521 #endif
522