xref: /libCEED/include/ceed-impl.h (revision 55ae60f998a3874cb1e4ab7010140b9e0d103903)
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 /// Private header for frontend components of libCEED
19 #ifndef _ceed_impl_h
20 #define _ceed_impl_h
21 
22 #include <ceed.h>
23 #include <ceed-backend.h>
24 #include <stdbool.h>
25 
26 #define CEED_INTERN CEED_EXTERN __attribute__((visibility ("hidden")))
27 
28 #define CEED_MAX_RESOURCE_LEN 1024
29 #define CEED_ALIGN 64
30 
31 #define CEED_NUM_BACKEND_FUNCTIONS 29
32 #define CEED_COMPOSITE_MAX 16
33 
34 // Lookup table field for backend functions
35 typedef struct {
36   const char *fname;
37   size_t offset;
38 } foffset;
39 
40 struct Ceed_private {
41   Ceed delegate;
42   Ceed parent;
43   int (*Error)(Ceed, const char *, int, const char *, int, const char *,
44                va_list);
45   int (*Destroy)(Ceed);
46   int (*VecCreate)(CeedInt, CeedVector);
47   int (*ElemRestrictionCreate)(CeedMemType, CeedCopyMode,
48                                const CeedInt *, CeedElemRestriction);
49   int (*ElemRestrictionCreateBlocked)(CeedMemType, CeedCopyMode,
50                                       const CeedInt *, CeedElemRestriction);
51   int (*BasisCreateTensorH1)(CeedInt, CeedInt, CeedInt, const CeedScalar *,
52                              const CeedScalar *, const CeedScalar *,
53                              const CeedScalar *, CeedBasis);
54   int (*BasisCreateH1)(CeedElemTopology, CeedInt, CeedInt, CeedInt,
55                        const CeedScalar *,
56                        const CeedScalar *, const CeedScalar *,
57                        const CeedScalar *, CeedBasis);
58   int (*TensorContractCreate)(CeedTensorContract);
59   int (*QFunctionCreate)(CeedQFunction);
60   int (*OperatorCreate)(CeedOperator);
61   int (*CompositeOperatorCreate)(CeedOperator);
62   int refcount;
63   void *data;
64   foffset foffsets[CEED_NUM_BACKEND_FUNCTIONS];
65 };
66 
67 struct CeedVector_private {
68   Ceed ceed;
69   int (*SetArray)(CeedVector, CeedMemType, CeedCopyMode, CeedScalar *);
70   int (*SetValue)(CeedVector, CeedScalar);
71   int (*GetArray)(CeedVector, CeedMemType, CeedScalar **);
72   int (*GetArrayRead)(CeedVector, CeedMemType, const CeedScalar **);
73   int (*RestoreArray)(CeedVector);
74   int (*RestoreArrayRead)(CeedVector);
75   int (*Destroy)(CeedVector);
76   int refcount;
77   CeedInt length;
78   uint64_t state;
79   uint64_t numreaders;
80   void *data;
81 };
82 
83 struct CeedElemRestriction_private {
84   Ceed ceed;
85   int (*Apply)(CeedElemRestriction, CeedTransposeMode, CeedTransposeMode,
86                CeedVector, CeedVector, CeedRequest *);
87   int (*Destroy)(CeedElemRestriction);
88   int refcount;
89   CeedInt nelem;    /* number of elements */
90   CeedInt elemsize; /* number of dofs per element */
91   CeedInt ndof;     /* size of the L-vector, can be used for checking for
92                       correct vector sizes */
93   CeedInt ncomp;    /* number of components */
94   CeedInt blksize;  /* number of elements in a batch */
95   CeedInt nblk;     /* number of blocks of elements */
96   void *data;       /* place for the backend to store any data */
97 };
98 
99 struct CeedBasis_private {
100   Ceed ceed;
101   int (*Apply)(CeedBasis, CeedInt, CeedTransposeMode, CeedEvalMode,
102                CeedVector, CeedVector);
103   int (*Destroy)(CeedBasis);
104   int refcount;
105   bool tensorbasis;      /* flag for tensor basis */
106   CeedInt dim;           /* topological dimension */
107   CeedInt ncomp;         /* number of field components (1 for scalar fields) */
108   CeedInt P1d;           /* number of nodes in one dimension */
109   CeedInt Q1d;           /* number of quadrature points in one dimension */
110   CeedInt P;             /* total number of nodes */
111   CeedInt Q;             /* total number of quadrature points */
112   CeedScalar *qref1d;    /* Array of length Q1d holding the locations of
113                             quadrature points on the 1D reference element [-1, 1] */
114   CeedScalar *qweight1d; /* array of length Q1d holding the quadrature weights on
115                             the reference element */
116   CeedScalar
117   *interp1d;  /* row-major matrix of shape [Q1d, P1d] expressing the values of
118                             nodal basis functions at quadrature points */
119   CeedScalar
120   *grad1d;    /* row-major matrix of shape [Q1d, P1d] matrix expressing derivatives of
121                             nodal basis functions at quadrature points */
122   CeedTensorContract contract; /* tensor contraction object */
123   void *data;            /* place for the backend to store any data */
124 };
125 
126 struct CeedTensorContract_private {
127   Ceed ceed;
128   int (*Apply)(CeedTensorContract, CeedInt, CeedInt, CeedInt, CeedInt,
129                const CeedScalar *restrict, CeedTransposeMode, const CeedInt,
130                const CeedScalar *restrict, CeedScalar *restrict);
131   int (*Destroy)(CeedTensorContract);
132   int refcount;
133   void *data;
134 };
135 
136 struct CeedQFunctionField_private {
137   const char *fieldname;
138   CeedInt ncomp;
139   CeedEvalMode emode;
140 };
141 
142 struct CeedQFunction_private {
143   Ceed ceed;
144   int (*Apply)(CeedQFunction, CeedInt, CeedVector *, CeedVector *);
145   int (*Destroy)(CeedQFunction);
146   int refcount;
147   CeedInt vlength;    // Number of quadrature points must be padded to a multiple of vlength
148   CeedQFunctionField *inputfields;
149   CeedQFunctionField *outputfields;
150   CeedInt numinputfields, numoutputfields;
151   CeedQFunctionUser function;
152   const char *focca;
153   bool fortranstatus;
154   void *ctx;      /* user context for function */
155   size_t ctxsize; /* size of user context; may be used to copy to a device */
156   void *data;     /* backend data */
157 };
158 
159 /// Struct to handle the context data to use the Fortran QFunction stub
160 /// @ingroup CeedQFunction
161 typedef struct {
162   CeedScalar *innerctx;
163   size_t innerctxsize;
164   void (*f)(void *ctx, int *nq,
165             const CeedScalar *u,const CeedScalar *u1,
166             const CeedScalar *u2,const CeedScalar *u3,
167             const CeedScalar *u4,const CeedScalar *u5,
168             const CeedScalar *u6,const CeedScalar *u7,
169             const CeedScalar *u8,const CeedScalar *u9,
170             const CeedScalar *u10,const CeedScalar *u11,
171             const CeedScalar *u12,const CeedScalar *u13,
172             const CeedScalar *u14,const CeedScalar *u15,
173             CeedScalar *v,CeedScalar *v1,CeedScalar *v2,
174             CeedScalar *v3,CeedScalar *v4,CeedScalar *v5,
175             CeedScalar *v6,CeedScalar *v7,CeedScalar *v8,
176             CeedScalar *v9, CeedScalar *v10,CeedScalar *v11,
177             CeedScalar *v12,CeedScalar *v13,CeedScalar *v14,
178             CeedScalar *v15, int *err);
179 } fContext;
180 
181 struct CeedOperatorField_private {
182   CeedElemRestriction Erestrict; /// Restriction from L-vector or NULL if identity
183   CeedTransposeMode lmode;       /// Transpose mode for lvector ordering
184   CeedBasis basis;               /// Basis or NULL for collocated fields
185   CeedVector
186   vec;                /// State vector for passive fields, NULL for active fields
187 };
188 
189 struct CeedOperator_private {
190   Ceed ceed;
191   int refcount;
192   int (*Apply)(CeedOperator, CeedVector, CeedVector, CeedRequest *);
193   int (*ApplyJacobian)(CeedOperator, CeedVector, CeedVector, CeedVector,
194                        CeedVector, CeedRequest *);
195   int (*Destroy)(CeedOperator);
196   CeedOperatorField *inputfields;
197   CeedOperatorField *outputfields;
198   CeedInt numelements; /// Number of elements
199   CeedInt numqpoints;  /// Number of quadrature points over all elements
200   CeedInt nfields;     /// Number of fields that have been set
201   CeedQFunction qf;
202   CeedQFunction dqf;
203   CeedQFunction dqfT;
204   bool setupdone;
205   bool composite;
206   CeedOperator *suboperators;
207   CeedInt numsub;
208   void *data;
209 };
210 
211 CEED_INTERN int CeedErrorReturn(Ceed, const char *, int, const char *, int,
212                                 const char *, va_list);
213 CEED_INTERN int CeedErrorAbort(Ceed, const char *, int, const char *, int,
214                                const char *, va_list);
215 CEED_INTERN int CeedErrorExit(Ceed, const char *, int, const char *, int,
216                               const char *, va_list);
217 CEED_INTERN int CeedSetErrorHandler(Ceed ceed,
218                                     int (eh)(Ceed, const char *, int,
219                                         const char *, int, const char *,
220                                         va_list));
221 
222 #endif
223