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