xref: /libCEED/include/ceed-impl.h (revision 9f0427d99e9674f1e08f64878fc1ceefe3e53022)
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>
23ff8ca64bSJed Brown #include <stdbool.h>
246ea7c6c1SJed Brown 
256ea7c6c1SJed Brown #define CEED_INTERN CEED_EXTERN __attribute__((visibility ("hidden")))
266ea7c6c1SJed Brown 
276ea7c6c1SJed Brown #define CEED_MAX_RESOURCE_LEN 1024
286ea7c6c1SJed Brown #define CEED_ALIGN 64
2928d161eeSjeremylt #define CEED_NUM_BACKEND_FUNCTIONS 25
306ea7c6c1SJed Brown 
31fe2413ffSjeremylt // Lookup table field for backend functions
32fe2413ffSjeremylt typedef struct {
33fe2413ffSjeremylt   const char *fname;
34fe2413ffSjeremylt   size_t offset;
35fe2413ffSjeremylt } foffset;
36fe2413ffSjeremylt 
376ea7c6c1SJed Brown struct Ceed_private {
385fe0d4faSjeremylt   Ceed delegate;
396ea7c6c1SJed Brown   int (*Error)(Ceed, const char *, int, const char *, int, const char *, va_list);
406ea7c6c1SJed Brown   int (*Destroy)(Ceed);
41667bc5fcSjeremylt   int (*VecCreate)(CeedInt, CeedVector);
42667bc5fcSjeremylt   int (*ElemRestrictionCreate)(CeedMemType, CeedCopyMode,
43667bc5fcSjeremylt                                const CeedInt *, CeedElemRestriction);
44667bc5fcSjeremylt   int (*ElemRestrictionCreateBlocked)(CeedMemType, CeedCopyMode,
45667bc5fcSjeremylt                                       const CeedInt *, CeedElemRestriction);
46667bc5fcSjeremylt   int (*BasisCreateTensorH1)(CeedInt, CeedInt, CeedInt, const CeedScalar *,
476ea7c6c1SJed Brown                              const CeedScalar *, const CeedScalar *, const CeedScalar *, CeedBasis);
48667bc5fcSjeremylt   int (*BasisCreateH1)(CeedElemTopology, CeedInt, CeedInt, CeedInt,
49a8de75f0Sjeremylt                        const CeedScalar *,
50a8de75f0Sjeremylt                        const CeedScalar *, const CeedScalar *, const CeedScalar *, CeedBasis);
516ea7c6c1SJed Brown   int (*QFunctionCreate)(CeedQFunction);
526ea7c6c1SJed Brown   int (*OperatorCreate)(CeedOperator);
5380061934SJed Brown   int refcount;
546ea7c6c1SJed Brown   void *data;
5528d161eeSjeremylt   foffset foffsets[CEED_NUM_BACKEND_FUNCTIONS];
566ea7c6c1SJed Brown };
576ea7c6c1SJed Brown 
586ea7c6c1SJed Brown struct CeedVector_private {
596ea7c6c1SJed Brown   Ceed ceed;
606ea7c6c1SJed Brown   int (*SetArray)(CeedVector, CeedMemType, CeedCopyMode, CeedScalar *);
612a1ab385Sjeremylt   int (*SetValue)(CeedVector, CeedScalar);
626ea7c6c1SJed Brown   int (*GetArray)(CeedVector, CeedMemType, CeedScalar **);
636ea7c6c1SJed Brown   int (*GetArrayRead)(CeedVector, CeedMemType, const CeedScalar **);
646ea7c6c1SJed Brown   int (*RestoreArray)(CeedVector, CeedScalar **);
656ea7c6c1SJed Brown   int (*RestoreArrayRead)(CeedVector, const CeedScalar **);
666ea7c6c1SJed Brown   int (*Destroy)(CeedVector);
67540765feSJed Brown   int refcount;
686ea7c6c1SJed Brown   CeedInt length;
6936ac90ebSjeremylt   uint64_t state;
702cd729eeSjeremylt   uint64_t numreaders;
716ea7c6c1SJed Brown   void *data;
726ea7c6c1SJed Brown };
736ea7c6c1SJed Brown 
746ea7c6c1SJed Brown struct CeedElemRestriction_private {
756ea7c6c1SJed Brown   Ceed ceed;
76ff8ca64bSJed Brown   int (*Apply)(CeedElemRestriction, CeedTransposeMode, CeedTransposeMode,
776ea7c6c1SJed Brown                CeedVector, CeedVector, CeedRequest *);
786ea7c6c1SJed Brown   int (*Destroy)(CeedElemRestriction);
79675ef50dSJed Brown   int refcount;
806ea7c6c1SJed Brown   CeedInt nelem;    /* number of elements */
816ea7c6c1SJed Brown   CeedInt elemsize; /* number of dofs per element */
826ea7c6c1SJed Brown   CeedInt ndof;     /* size of the L-vector, can be used for checking for
836ea7c6c1SJed Brown                       correct vector sizes */
84ff8ca64bSJed Brown   CeedInt ncomp;    /* number of components */
854e35ef05Sjeremylt   CeedInt blksize;  /* number of elements in a batch */
864e35ef05Sjeremylt   CeedInt nblk;     /* number of blocks of elements */
876ea7c6c1SJed Brown   void *data;       /* place for the backend to store any data */
886ea7c6c1SJed Brown };
896ea7c6c1SJed Brown 
906ea7c6c1SJed Brown struct CeedBasis_private {
916ea7c6c1SJed Brown   Ceed ceed;
924b8bea3bSJed Brown   int (*Apply)(CeedBasis, CeedInt, CeedTransposeMode, CeedEvalMode,
93aedaa0e5Sjeremylt                CeedVector, CeedVector);
946ea7c6c1SJed Brown   int (*Destroy)(CeedBasis);
95c3725256SJed Brown   int refcount;
96a8de75f0Sjeremylt   bool tensorbasis;      /* flag for tensor basis */
970f5de9e9Sjeremylt   CeedInt dim;           /* topological dimension */
980f5de9e9Sjeremylt   CeedInt ncomp;         /* number of field components (1 for scalar fields) */
990f5de9e9Sjeremylt   CeedInt P1d;           /* number of nodes in one dimension */
1000f5de9e9Sjeremylt   CeedInt Q1d;           /* number of quadrature points in one dimension */
101a8de75f0Sjeremylt   CeedInt P;             /* total number of nodes */
102a8de75f0Sjeremylt   CeedInt Q;             /* total number of quadrature points */
1030f5de9e9Sjeremylt   CeedScalar *qref1d;    /* Array of length Q1d holding the locations of
1040f5de9e9Sjeremylt                             quadrature points on the 1D reference element [-1, 1] */
1050f5de9e9Sjeremylt   CeedScalar *qweight1d; /* array of length Q1d holding the quadrature weights on
1060f5de9e9Sjeremylt                             the reference element */
1074b8bea3bSJed Brown   CeedScalar
1084b8bea3bSJed Brown   *interp1d;  /* row-major matrix of shape [Q1d, P1d] expressing the values of
1090f5de9e9Sjeremylt                             nodal basis functions at quadrature points */
1104b8bea3bSJed Brown   CeedScalar
1114b8bea3bSJed Brown   *grad1d;    /* row-major matrix of shape [Q1d, P1d] matrix expressing derivatives of
1120f5de9e9Sjeremylt                             nodal basis functions at quadrature points */
113c01dd730Scamierjs   void *data;            /* place for the backend to store any data */
1146ea7c6c1SJed Brown };
1156ea7c6c1SJed Brown 
116d1bcdac9Sjeremylt struct CeedQFunctionField_private {
117ff8ca64bSJed Brown   const char *fieldname;
118ff8ca64bSJed Brown   CeedInt ncomp;
119ff8ca64bSJed Brown   CeedEvalMode emode;
120ff8ca64bSJed Brown };
121ff8ca64bSJed Brown 
1226ea7c6c1SJed Brown struct CeedQFunction_private {
1236ea7c6c1SJed Brown   Ceed ceed;
124aedaa0e5Sjeremylt   int (*Apply)(CeedQFunction, CeedInt, CeedVector *,
125aedaa0e5Sjeremylt                CeedVector *);
1266ea7c6c1SJed Brown   int (*Destroy)(CeedQFunction);
1272123d1aaSJed Brown   int refcount;
1286ea7c6c1SJed Brown   CeedInt vlength;    // Number of quadrature points must be padded to a multiple of vlength
129fe2413ffSjeremylt   CeedQFunctionField *inputfields;
130fe2413ffSjeremylt   CeedQFunctionField *outputfields;
131ff8ca64bSJed Brown   CeedInt numinputfields, numoutputfields;
132*9f0427d9SYohann   CeedQFunctionUser function;
1336ea7c6c1SJed Brown   const char *focca;
134418fb8c2Sjeremylt   bool fortranstatus;
1356ea7c6c1SJed Brown   void *ctx;      /* user context for function */
1366ea7c6c1SJed Brown   size_t ctxsize; /* size of user context; may be used to copy to a device */
1376ea7c6c1SJed Brown   void *data;     /* backend data */
1386ea7c6c1SJed Brown };
1396ea7c6c1SJed Brown 
1401e35832bSjeremylt /// Struct to handle the context data to use the Fortran QFunction stub
1411e35832bSjeremylt /// @ingroup CeedQFunction
142069aeabaSjeremylt typedef struct {
1431e35832bSjeremylt   CeedScalar *innerctx;
144069aeabaSjeremylt   size_t innerctxsize;
145069aeabaSjeremylt   void (*f)(void *ctx, int *nq,
146069aeabaSjeremylt             const CeedScalar *u,const CeedScalar *u1,
147069aeabaSjeremylt             const CeedScalar *u2,const CeedScalar *u3,
148069aeabaSjeremylt             const CeedScalar *u4,const CeedScalar *u5,
149069aeabaSjeremylt             const CeedScalar *u6,const CeedScalar *u7,
150069aeabaSjeremylt             const CeedScalar *u8,const CeedScalar *u9,
151069aeabaSjeremylt             const CeedScalar *u10,const CeedScalar *u11,
152069aeabaSjeremylt             const CeedScalar *u12,const CeedScalar *u13,
153069aeabaSjeremylt             const CeedScalar *u14,const CeedScalar *u15,
154069aeabaSjeremylt             CeedScalar *v,CeedScalar *v1,CeedScalar *v2,
155069aeabaSjeremylt             CeedScalar *v3,CeedScalar *v4,CeedScalar *v5,
156069aeabaSjeremylt             CeedScalar *v6,CeedScalar *v7,CeedScalar *v8,
157069aeabaSjeremylt             CeedScalar *v9, CeedScalar *v10,CeedScalar *v11,
158069aeabaSjeremylt             CeedScalar *v12,CeedScalar *v13,CeedScalar *v14,
159069aeabaSjeremylt             CeedScalar *v15, int *err);
160069aeabaSjeremylt } fContext;
161069aeabaSjeremylt 
162d1bcdac9Sjeremylt struct CeedOperatorField_private {
163ff8ca64bSJed Brown   CeedElemRestriction Erestrict; /// Restriction from L-vector or NULL if identity
1644dccadb6Sjeremylt   CeedTransposeMode lmode;       /// Transpose mode for lvector ordering
165ff8ca64bSJed Brown   CeedBasis basis;               /// Basis or NULL for collocated fields
1664b8bea3bSJed Brown   CeedVector
1674b8bea3bSJed Brown   vec;                /// State vector for passive fields, NULL for active fields
168ff8ca64bSJed Brown };
169ff8ca64bSJed Brown 
1706ea7c6c1SJed Brown struct CeedOperator_private {
1716ea7c6c1SJed Brown   Ceed ceed;
172c4da7380SJed Brown   int refcount;
173ff8ca64bSJed Brown   int (*Apply)(CeedOperator, CeedVector, CeedVector, CeedRequest *);
1746ea7c6c1SJed Brown   int (*ApplyJacobian)(CeedOperator, CeedVector, CeedVector, CeedVector,
1756ea7c6c1SJed Brown                        CeedVector, CeedRequest *);
1766ea7c6c1SJed Brown   int (*Destroy)(CeedOperator);
177fe2413ffSjeremylt   CeedOperatorField *inputfields;
178fe2413ffSjeremylt   CeedOperatorField *outputfields;
179ff8ca64bSJed Brown   CeedInt numelements; /// Number of elements
180ff8ca64bSJed Brown   CeedInt numqpoints;  /// Number of quadrature points over all elements
181ef700c2cSjeremylt   CeedInt nfields;     /// Number of fields that have been set
1826ea7c6c1SJed Brown   CeedQFunction qf;
1836ea7c6c1SJed Brown   CeedQFunction dqf;
1846ea7c6c1SJed Brown   CeedQFunction dqfT;
185ff8ca64bSJed Brown   bool setupdone;
1866ea7c6c1SJed Brown   void *data;
1876ea7c6c1SJed Brown };
1886ea7c6c1SJed Brown 
189d863ab9bSjeremylt CEED_INTERN int CeedErrorReturn(Ceed, const char *, int, const char *, int,
190d863ab9bSjeremylt                                 const char *, va_list);
191d863ab9bSjeremylt CEED_INTERN int CeedErrorAbort(Ceed, const char *, int, const char *, int,
192d863ab9bSjeremylt                                const char *, va_list);
193d863ab9bSjeremylt CEED_INTERN int CeedErrorExit(Ceed, const char *, int, const char *, int,
194d863ab9bSjeremylt                               const char *, va_list);
195d863ab9bSjeremylt CEED_INTERN int CeedSetErrorHandler(Ceed ceed,
196d863ab9bSjeremylt                                     int (eh)(Ceed, const char *, int, const char *,
197d863ab9bSjeremylt                                         int, const char *, va_list));
198d863ab9bSjeremylt 
1996ea7c6c1SJed Brown #endif
200