xref: /libCEED/include/ceed-impl.h (revision 7a982d89c751e293e39d23a7c44a161cef1fcd06)
16ea7c6c1SJed Brown // Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at
26ea7c6c1SJed Brown // the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights
36ea7c6c1SJed Brown // reserved. See files LICENSE and NOTICE for details.
46ea7c6c1SJed Brown //
56ea7c6c1SJed Brown // This file is part of CEED, a collection of benchmarks, miniapps, software
66ea7c6c1SJed Brown // libraries and APIs for efficient high-order finite element and spectral
76ea7c6c1SJed Brown // element discretizations for exascale applications. For more information and
86ea7c6c1SJed Brown // source code availability see http://github.com/ceed.
96ea7c6c1SJed Brown //
106ea7c6c1SJed Brown // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
116ea7c6c1SJed Brown // a collaborative effort of two U.S. Department of Energy organizations (Office
126ea7c6c1SJed Brown // of Science and the National Nuclear Security Administration) responsible for
136ea7c6c1SJed Brown // the planning and preparation of a capable exascale ecosystem, including
146ea7c6c1SJed Brown // software, applications, hardware, advanced system engineering and early
156ea7c6c1SJed Brown // testbed platforms, in support of the nation's exascale computing imperative.
166ea7c6c1SJed Brown 
175d6bafb2Sjeremylt /// @file
185d6bafb2Sjeremylt /// Private header for frontend components of libCEED
196ea7c6c1SJed Brown #ifndef _ceed_impl_h
206ea7c6c1SJed Brown #define _ceed_impl_h
216ea7c6c1SJed Brown 
226ea7c6c1SJed Brown #include <ceed.h>
232f86a920SJeremy L Thompson #include <ceed-backend.h>
24ff8ca64bSJed Brown #include <stdbool.h>
256ea7c6c1SJed Brown 
26*7a982d89SJeremy L. Thompson /** @defgroup CeedUser Public API for Ceed
27*7a982d89SJeremy L. Thompson     @ingroup Ceed
28*7a982d89SJeremy L. Thompson */
29*7a982d89SJeremy L. Thompson /** @defgroup CeedBackend Backend API for Ceed
30*7a982d89SJeremy L. Thompson     @ingroup Ceed
31*7a982d89SJeremy L. Thompson */
32*7a982d89SJeremy L. Thompson /** @defgroup CeedDeveloper Internal library functions for Ceed
33*7a982d89SJeremy L. Thompson     @ingroup Ceed
34*7a982d89SJeremy L. Thompson */
35*7a982d89SJeremy L. Thompson /** @defgroup CeedVectorUser Public API for CeedVector
36*7a982d89SJeremy L. Thompson     @ingroup CeedVector
37*7a982d89SJeremy L. Thompson */
38*7a982d89SJeremy L. Thompson /** @defgroup CeedVectorBackend Backend API for CeedVector
39*7a982d89SJeremy L. Thompson     @ingroup CeedVector
40*7a982d89SJeremy L. Thompson */
41*7a982d89SJeremy L. Thompson /** @defgroup CeedVectorDeveloper Internal library functions for CeedVector
42*7a982d89SJeremy L. Thompson     @ingroup CeedVector
43*7a982d89SJeremy L. Thompson */
44*7a982d89SJeremy L. Thompson /** @defgroup CeedElemRestrictionUser Public API for CeedElemRestriction
45*7a982d89SJeremy L. Thompson     @ingroup CeedElemRestriction
46*7a982d89SJeremy L. Thompson */
47*7a982d89SJeremy L. Thompson /** @defgroup CeedElemRestrictionBackend Backend API for CeedElemRestriction
48*7a982d89SJeremy L. Thompson     @ingroup CeedElemRestriction
49*7a982d89SJeremy L. Thompson */
50*7a982d89SJeremy L. Thompson /** @defgroup CeedElemRestrictionDeveloper Internal library functions for CeedElemRestriction
51*7a982d89SJeremy L. Thompson     @ingroup CeedElemRestriction
52*7a982d89SJeremy L. Thompson */
53*7a982d89SJeremy L. Thompson /** @defgroup CeedBasisUser Public API for CeedBasis
54*7a982d89SJeremy L. Thompson     @ingroup CeedBasis
55*7a982d89SJeremy L. Thompson */
56*7a982d89SJeremy L. Thompson /** @defgroup CeedBasisBackend Backend API for CeedBasis
57*7a982d89SJeremy L. Thompson     @ingroup CeedBasis
58*7a982d89SJeremy L. Thompson */
59*7a982d89SJeremy L. Thompson /** @defgroup CeedBasisDeveloper Internal library functions for CeedBasis
60*7a982d89SJeremy L. Thompson     @ingroup CeedBasis
61*7a982d89SJeremy L. Thompson */
62*7a982d89SJeremy L. Thompson /** @defgroup CeedQFunctionUser Public API for CeedQFunction
63*7a982d89SJeremy L. Thompson     @ingroup CeedQFunction
64*7a982d89SJeremy L. Thompson */
65*7a982d89SJeremy L. Thompson /** @defgroup CeedQFunctionBackend Backend API for CeedQFunction
66*7a982d89SJeremy L. Thompson     @ingroup CeedQFunction
67*7a982d89SJeremy L. Thompson */
68*7a982d89SJeremy L. Thompson /** @defgroup CeedQFunctionDeveloper Internal library functions for CeedQFunction
69*7a982d89SJeremy L. Thompson     @ingroup CeedQFunction
70*7a982d89SJeremy L. Thompson */
71*7a982d89SJeremy L. Thompson /** @defgroup CeedOperatorUser Public API for CeedOperator
72*7a982d89SJeremy L. Thompson     @ingroup CeedOperator
73*7a982d89SJeremy L. Thompson */
74*7a982d89SJeremy L. Thompson /** @defgroup CeedOperatorBackend Backend API for CeedOperator
75*7a982d89SJeremy L. Thompson     @ingroup CeedOperator
76*7a982d89SJeremy L. Thompson */
77*7a982d89SJeremy L. Thompson /** @defgroup CeedOperatorDeveloper Internal library functions for CeedOperator
78*7a982d89SJeremy L. Thompson     @ingroup CeedOperator
79*7a982d89SJeremy L. Thompson */
80*7a982d89SJeremy L. Thompson 
81fe2413ffSjeremylt // Lookup table field for backend functions
82fe2413ffSjeremylt typedef struct {
83fe2413ffSjeremylt   const char *fname;
84fe2413ffSjeremylt   size_t offset;
85fe2413ffSjeremylt } foffset;
86fe2413ffSjeremylt 
87aefd8378Sjeremylt // Lookup table field for object delegates
88aefd8378Sjeremylt typedef struct {
89aefd8378Sjeremylt   char *objname;
90aefd8378Sjeremylt   Ceed delegate;
91aefd8378Sjeremylt } objdelegate;
92aefd8378Sjeremylt 
936ea7c6c1SJed Brown struct Ceed_private {
94e07206deSjeremylt   const char *resource;
955fe0d4faSjeremylt   Ceed delegate;
962f86a920SJeremy L Thompson   Ceed parent;
97aefd8378Sjeremylt   objdelegate *objdelegates;
98aefd8378Sjeremylt   int objdelegatecount;
995107b09fSJeremy L Thompson   Ceed opfallbackceed, opfallbackparent;
1005107b09fSJeremy L Thompson   const char *opfallbackresource;
1012f86a920SJeremy L Thompson   int (*Error)(Ceed, const char *, int, const char *, int, const char *,
1022f86a920SJeremy L Thompson                va_list);
103c907536fSjeremylt   int (*GetPreferredMemType)(CeedMemType *);
1046ea7c6c1SJed Brown   int (*Destroy)(Ceed);
105f8902d9eSjeremylt   int (*VectorCreate)(CeedInt, CeedVector);
106667bc5fcSjeremylt   int (*ElemRestrictionCreate)(CeedMemType, CeedCopyMode,
107667bc5fcSjeremylt                                const CeedInt *, CeedElemRestriction);
108667bc5fcSjeremylt   int (*ElemRestrictionCreateBlocked)(CeedMemType, CeedCopyMode,
109667bc5fcSjeremylt                                       const CeedInt *, CeedElemRestriction);
110667bc5fcSjeremylt   int (*BasisCreateTensorH1)(CeedInt, CeedInt, CeedInt, const CeedScalar *,
1112f86a920SJeremy L Thompson                              const CeedScalar *, const CeedScalar *,
1122f86a920SJeremy L Thompson                              const CeedScalar *, CeedBasis);
113667bc5fcSjeremylt   int (*BasisCreateH1)(CeedElemTopology, CeedInt, CeedInt, CeedInt,
114a8de75f0Sjeremylt                        const CeedScalar *,
1152f86a920SJeremy L Thompson                        const CeedScalar *, const CeedScalar *,
1162f86a920SJeremy L Thompson                        const CeedScalar *, CeedBasis);
117c71e1dcdSjeremylt   int (*TensorContractCreate)(CeedBasis, CeedTensorContract);
1186ea7c6c1SJed Brown   int (*QFunctionCreate)(CeedQFunction);
1196ea7c6c1SJed Brown   int (*OperatorCreate)(CeedOperator);
12052d6035fSJeremy L Thompson   int (*CompositeOperatorCreate)(CeedOperator);
12180061934SJed Brown   int refcount;
1226ea7c6c1SJed Brown   void *data;
1236e79d475Sjeremylt   foffset *foffsets;
1246ea7c6c1SJed Brown };
1256ea7c6c1SJed Brown 
1266ea7c6c1SJed Brown struct CeedVector_private {
1276ea7c6c1SJed Brown   Ceed ceed;
1286ea7c6c1SJed Brown   int (*SetArray)(CeedVector, CeedMemType, CeedCopyMode, CeedScalar *);
1292a1ab385Sjeremylt   int (*SetValue)(CeedVector, CeedScalar);
13054540941SJeremy L Thompson   int (*SyncArray)(CeedVector, CeedMemType);
1316ea7c6c1SJed Brown   int (*GetArray)(CeedVector, CeedMemType, CeedScalar **);
1326ea7c6c1SJed Brown   int (*GetArrayRead)(CeedVector, CeedMemType, const CeedScalar **);
133f05116b9SJeremy L Thompson   int (*RestoreArray)(CeedVector);
134f05116b9SJeremy L Thompson   int (*RestoreArrayRead)(CeedVector);
135547d9b97Sjeremylt   int (*Norm)(CeedVector, CeedNormType, CeedScalar *);
1366ea7c6c1SJed Brown   int (*Destroy)(CeedVector);
137540765feSJed Brown   int refcount;
1386ea7c6c1SJed Brown   CeedInt length;
13936ac90ebSjeremylt   uint64_t state;
1402cd729eeSjeremylt   uint64_t numreaders;
1416ea7c6c1SJed Brown   void *data;
1426ea7c6c1SJed Brown };
1436ea7c6c1SJed Brown 
1446ea7c6c1SJed Brown struct CeedElemRestriction_private {
1456ea7c6c1SJed Brown   Ceed ceed;
146074cb416Sjeremylt   int (*Apply)(CeedElemRestriction, CeedTransposeMode, CeedVector, CeedVector,
147074cb416Sjeremylt                CeedRequest *);
148074cb416Sjeremylt   int (*ApplyBlock)(CeedElemRestriction, CeedInt, CeedTransposeMode, CeedVector,
149074cb416Sjeremylt                     CeedVector, CeedRequest *);
1506ea7c6c1SJed Brown   int (*Destroy)(CeedElemRestriction);
151675ef50dSJed Brown   int refcount;
15261dbc9d2Sjeremylt   CeedInterlaceMode imode;  /* Interlacing mode for L-vector ordering */
1536ea7c6c1SJed Brown   CeedInt nelem;            /* number of elements */
1548795c945Sjeremylt   CeedInt elemsize;         /* number of nodes per element */
155a8d32208Sjeremylt   CeedInt nnodes;           /* size of the L-vector, can be used for checking
156a8d32208Sjeremylt                                  for correct vector sizes */
157ff8ca64bSJed Brown   CeedInt ncomp;            /* number of components */
1584e35ef05Sjeremylt   CeedInt blksize;          /* number of elements in a batch */
1594e35ef05Sjeremylt   CeedInt nblk;             /* number of blocks of elements */
1607509a596Sjeremylt   CeedInt *strides;         /* strides between [nodes, components, elements] */
1616ea7c6c1SJed Brown   void *data;               /* place for the backend to store any data */
1626ea7c6c1SJed Brown };
1636ea7c6c1SJed Brown 
1646ea7c6c1SJed Brown struct CeedBasis_private {
1656ea7c6c1SJed Brown   Ceed ceed;
1664b8bea3bSJed Brown   int (*Apply)(CeedBasis, CeedInt, CeedTransposeMode, CeedEvalMode,
167aedaa0e5Sjeremylt                CeedVector, CeedVector);
1686ea7c6c1SJed Brown   int (*Destroy)(CeedBasis);
169c3725256SJed Brown   int refcount;
170a8de75f0Sjeremylt   bool tensorbasis;      /* flag for tensor basis */
1710f5de9e9Sjeremylt   CeedInt dim;           /* topological dimension */
1720f5de9e9Sjeremylt   CeedInt ncomp;         /* number of field components (1 for scalar fields) */
1730f5de9e9Sjeremylt   CeedInt P1d;           /* number of nodes in one dimension */
1740f5de9e9Sjeremylt   CeedInt Q1d;           /* number of quadrature points in one dimension */
175a8de75f0Sjeremylt   CeedInt P;             /* total number of nodes */
176a8de75f0Sjeremylt   CeedInt Q;             /* total number of quadrature points */
1770f5de9e9Sjeremylt   CeedScalar *qref1d;    /* Array of length Q1d holding the locations of
178a8d32208Sjeremylt                               quadrature points on the 1D reference
179a8d32208Sjeremylt                               element [-1, 1] */
1800f5de9e9Sjeremylt   CeedScalar *qweight1d; /* array of length Q1d holding the quadrature weights on
1810f5de9e9Sjeremylt                               the reference element */
1824b8bea3bSJed Brown   CeedScalar
18300f91b2bSjeremylt   *interp;    /* row-major matrix of shape [Q, P] expressing the values of
18400f91b2bSjeremylt                    nodal basis functions at quadrature points */
18500f91b2bSjeremylt   CeedScalar
1864b8bea3bSJed Brown   *interp1d;  /* row-major matrix of shape [Q1d, P1d] expressing the values of
1870f5de9e9Sjeremylt                    nodal basis functions at quadrature points */
1884b8bea3bSJed Brown   CeedScalar
189a8d32208Sjeremylt   *grad;      /* row-major matrix of shape [dim*Q, P] matrix expressing
190a8d32208Sjeremylt                    derivatives of nodal basis functions at quadrature points */
19100f91b2bSjeremylt   CeedScalar
192a8d32208Sjeremylt   *grad1d;    /* row-major matrix of shape [Q1d, P1d] matrix expressing
193a8d32208Sjeremylt                    derivatives of nodal basis functions at quadrature points */
1942f86a920SJeremy L Thompson   CeedTensorContract contract; /* tensor contraction object */
195c01dd730Scamierjs   void *data;                  /* place for the backend to store any data */
1966ea7c6c1SJed Brown };
1976ea7c6c1SJed Brown 
1982f86a920SJeremy L Thompson struct CeedTensorContract_private {
1992f86a920SJeremy L Thompson   Ceed ceed;
2002f86a920SJeremy L Thompson   int (*Apply)(CeedTensorContract, CeedInt, CeedInt, CeedInt, CeedInt,
2012f86a920SJeremy L Thompson                const CeedScalar *restrict, CeedTransposeMode, const CeedInt,
2022f86a920SJeremy L Thompson                const CeedScalar *restrict, CeedScalar *restrict);
2032f86a920SJeremy L Thompson   int (*Destroy)(CeedTensorContract);
2042f86a920SJeremy L Thompson   int refcount;
2052f86a920SJeremy L Thompson   void *data;
2062f86a920SJeremy L Thompson };
2072f86a920SJeremy L Thompson 
208d1bcdac9Sjeremylt struct CeedQFunctionField_private {
209ff8ca64bSJed Brown   const char *fieldname;
2104d537eeaSYohann   CeedInt size;
211ff8ca64bSJed Brown   CeedEvalMode emode;
212ff8ca64bSJed Brown };
213ff8ca64bSJed Brown 
2146ea7c6c1SJed Brown struct CeedQFunction_private {
2156ea7c6c1SJed Brown   Ceed ceed;
2162f86a920SJeremy L Thompson   int (*Apply)(CeedQFunction, CeedInt, CeedVector *, CeedVector *);
2176ea7c6c1SJed Brown   int (*Destroy)(CeedQFunction);
2182123d1aaSJed Brown   int refcount;
219a8d32208Sjeremylt   CeedInt vlength;    /* Number of quadrature points must be padded to a
220a8d32208Sjeremylt                            multiple of vlength */
221fe2413ffSjeremylt   CeedQFunctionField *inputfields;
222fe2413ffSjeremylt   CeedQFunctionField *outputfields;
223ff8ca64bSJed Brown   CeedInt numinputfields, numoutputfields;
2249f0427d9SYohann   CeedQFunctionUser function;
225288c0443SJeremy L Thompson   const char *sourcepath;
226288c0443SJeremy L Thompson   const char *qfname;
227418fb8c2Sjeremylt   bool fortranstatus;
2280219ea01SJeremy L Thompson   bool identity;
2296ea7c6c1SJed Brown   void *ctx;      /* user context for function */
2306ea7c6c1SJed Brown   size_t ctxsize; /* size of user context; may be used to copy to a device */
231a8d32208Sjeremylt   void *data;     /* place for the backend to store any data */
2326ea7c6c1SJed Brown };
2336ea7c6c1SJed Brown 
2341e35832bSjeremylt /// Struct to handle the context data to use the Fortran QFunction stub
2351e35832bSjeremylt /// @ingroup CeedQFunction
236069aeabaSjeremylt typedef struct {
2371e35832bSjeremylt   CeedScalar *innerctx;
238069aeabaSjeremylt   size_t innerctxsize;
239069aeabaSjeremylt   void (*f)(void *ctx, int *nq,
240069aeabaSjeremylt             const CeedScalar *u,const CeedScalar *u1,
241069aeabaSjeremylt             const CeedScalar *u2,const CeedScalar *u3,
242069aeabaSjeremylt             const CeedScalar *u4,const CeedScalar *u5,
243069aeabaSjeremylt             const CeedScalar *u6,const CeedScalar *u7,
244069aeabaSjeremylt             const CeedScalar *u8,const CeedScalar *u9,
245069aeabaSjeremylt             const CeedScalar *u10,const CeedScalar *u11,
246069aeabaSjeremylt             const CeedScalar *u12,const CeedScalar *u13,
247069aeabaSjeremylt             const CeedScalar *u14,const CeedScalar *u15,
248069aeabaSjeremylt             CeedScalar *v,CeedScalar *v1,CeedScalar *v2,
249069aeabaSjeremylt             CeedScalar *v3,CeedScalar *v4,CeedScalar *v5,
250069aeabaSjeremylt             CeedScalar *v6,CeedScalar *v7,CeedScalar *v8,
251069aeabaSjeremylt             CeedScalar *v9, CeedScalar *v10,CeedScalar *v11,
252069aeabaSjeremylt             CeedScalar *v12,CeedScalar *v13,CeedScalar *v14,
253069aeabaSjeremylt             CeedScalar *v15, int *err);
254069aeabaSjeremylt } fContext;
255069aeabaSjeremylt 
256d1bcdac9Sjeremylt struct CeedOperatorField_private {
257a8d32208Sjeremylt   CeedElemRestriction Erestrict; /* Restriction from L-vector */
258a8d32208Sjeremylt   CeedBasis basis;               /* Basis or CEED_BASIS_COLLOCATED for
259a8d32208Sjeremylt                                       collocated fields */
260a8d32208Sjeremylt   CeedVector vec;                /* State vector for passive fields or
261a8d32208Sjeremylt                                       CEED_VECTOR_NONE for no vector */
262ff8ca64bSJed Brown };
263ff8ca64bSJed Brown 
2646ea7c6c1SJed Brown struct CeedOperator_private {
2656ea7c6c1SJed Brown   Ceed ceed;
2665107b09fSJeremy L Thompson   CeedOperator opfallback;
2675107b09fSJeremy L Thompson   CeedQFunction qffallback;
268c4da7380SJed Brown   int refcount;
2691d102b48SJeremy L Thompson   int (*AssembleLinearQFunction)(CeedOperator, CeedVector *,
2701d102b48SJeremy L Thompson                                  CeedElemRestriction *, CeedRequest *);
271b7ec98d8SJeremy L Thompson   int (*AssembleLinearDiagonal)(CeedOperator, CeedVector *, CeedRequest *);
272713f43c3Sjeremylt   int (*CreateFDMElementInverse)(CeedOperator, CeedOperator *, CeedRequest *);
273ff8ca64bSJed Brown   int (*Apply)(CeedOperator, CeedVector, CeedVector, CeedRequest *);
274250756a7Sjeremylt   int (*ApplyComposite)(CeedOperator, CeedVector, CeedVector, CeedRequest *);
275cae8b89aSjeremylt   int (*ApplyAdd)(CeedOperator, CeedVector, CeedVector, CeedRequest *);
276250756a7Sjeremylt   int (*ApplyAddComposite)(CeedOperator, CeedVector, CeedVector, CeedRequest *);
2776ea7c6c1SJed Brown   int (*ApplyJacobian)(CeedOperator, CeedVector, CeedVector, CeedVector,
2786ea7c6c1SJed Brown                        CeedVector, CeedRequest *);
2796ea7c6c1SJed Brown   int (*Destroy)(CeedOperator);
280fe2413ffSjeremylt   CeedOperatorField *inputfields;
281fe2413ffSjeremylt   CeedOperatorField *outputfields;
282ff8ca64bSJed Brown   CeedInt numelements; /// Number of elements
283ff8ca64bSJed Brown   CeedInt numqpoints;  /// Number of quadrature points over all elements
284ef700c2cSjeremylt   CeedInt nfields;     /// Number of fields that have been set
2856ea7c6c1SJed Brown   CeedQFunction qf;
2866ea7c6c1SJed Brown   CeedQFunction dqf;
2876ea7c6c1SJed Brown   CeedQFunction dqfT;
288ff8ca64bSJed Brown   bool setupdone;
28952d6035fSJeremy L Thompson   bool composite;
2902cb0afc5Sjeremylt   bool hasrestriction;
29152d6035fSJeremy L Thompson   CeedOperator *suboperators;
29252d6035fSJeremy L Thompson   CeedInt numsub;
2936ea7c6c1SJed Brown   void *data;
2946ea7c6c1SJed Brown };
2956ea7c6c1SJed Brown 
296d863ab9bSjeremylt CEED_INTERN int CeedErrorReturn(Ceed, const char *, int, const char *, int,
297d863ab9bSjeremylt                                 const char *, va_list);
298d863ab9bSjeremylt CEED_INTERN int CeedErrorAbort(Ceed, const char *, int, const char *, int,
299d863ab9bSjeremylt                                const char *, va_list);
300d863ab9bSjeremylt CEED_INTERN int CeedErrorExit(Ceed, const char *, int, const char *, int,
301d863ab9bSjeremylt                               const char *, va_list);
302d863ab9bSjeremylt CEED_INTERN int CeedSetErrorHandler(Ceed ceed,
303*7a982d89SJeremy L. Thompson                                     int (*eh)(Ceed, const char *, int,
3042f86a920SJeremy L Thompson                                         const char *, int, const char *,
3052f86a920SJeremy L Thompson                                         va_list));
306d863ab9bSjeremylt 
3076ea7c6c1SJed Brown #endif
308