xref: /libCEED/include/ceed-impl.h (revision 80061934f505945b50e49b2407c4f3b8bd88463d)
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 #ifndef _ceed_impl_h
18 #define _ceed_impl_h
19 
20 #include <ceed.h>
21 
22 #define CEED_INTERN CEED_EXTERN __attribute__((visibility ("hidden")))
23 
24 #define CEED_MAX_RESOURCE_LEN 1024
25 #define CEED_ALIGN 64
26 
27 struct Ceed_private {
28   int (*Error)(Ceed, const char *, int, const char *, int, const char *, va_list);
29   int (*Destroy)(Ceed);
30   int (*VecCreate)(Ceed, CeedInt, CeedVector);
31   int (*ElemRestrictionCreate)(CeedElemRestriction, CeedMemType, CeedCopyMode,
32                                const CeedInt *);
33   int (*BasisCreateTensorH1)(Ceed, CeedInt, CeedInt, CeedInt, const CeedScalar *,
34                              const CeedScalar *, const CeedScalar *, const CeedScalar *, CeedBasis);
35   int (*QFunctionCreate)(CeedQFunction);
36   int (*OperatorCreate)(CeedOperator);
37   int refcount;
38   void *data;
39 };
40 
41 /* In the next 3 functions, p has to be the address of a pointer type, i.e. p
42    has to be a pointer to a pointer. */
43 CEED_INTERN int CeedMallocArray(size_t n, size_t unit, void *p);
44 CEED_INTERN int CeedCallocArray(size_t n, size_t unit, void *p);
45 CEED_INTERN int CeedReallocArray(size_t n, size_t unit, void *p);
46 CEED_INTERN int CeedFree(void *p);
47 
48 #define CeedChk(ierr) do { if (ierr) return ierr; } while (0)
49 /* Note that CeedMalloc and CeedCalloc will, generally, return pointers with
50    different memory alignments: CeedMalloc returns pointers aligned at
51    CEED_ALIGN bytes, while CeedCalloc uses the alignment of calloc. */
52 #define CeedMalloc(n, p) CeedMallocArray((n), sizeof(**(p)), p)
53 #define CeedCalloc(n, p) CeedCallocArray((n), sizeof(**(p)), p)
54 #define CeedRealloc(n, p) CeedReallocArray((n), sizeof(**(p)), p)
55 
56 struct CeedVector_private {
57   Ceed ceed;
58   int (*SetArray)(CeedVector, CeedMemType, CeedCopyMode, CeedScalar *);
59   int (*GetArray)(CeedVector, CeedMemType, CeedScalar **);
60   int (*GetArrayRead)(CeedVector, CeedMemType, const CeedScalar **);
61   int (*RestoreArray)(CeedVector, CeedScalar **);
62   int (*RestoreArrayRead)(CeedVector, const CeedScalar **);
63   int (*Destroy)(CeedVector);
64   CeedInt length;
65   void *data;
66 };
67 
68 struct CeedElemRestriction_private {
69   Ceed ceed;
70   int (*Apply)(CeedElemRestriction, CeedTransposeMode, CeedInt, CeedTransposeMode,
71                CeedVector, CeedVector, CeedRequest *);
72   int (*Destroy)(CeedElemRestriction);
73   CeedInt nelem;    /* number of elements */
74   CeedInt elemsize; /* number of dofs per element */
75   CeedInt ndof;     /* size of the L-vector, can be used for checking for
76                        correct vector sizes */
77   void *data;       /* place for the backend to store any data */
78 };
79 
80 struct CeedBasis_private {
81   Ceed ceed;
82   int (*Apply)(CeedBasis, CeedTransposeMode, CeedEvalMode, const CeedScalar *,
83                CeedScalar *);
84   int (*Destroy)(CeedBasis);
85   CeedInt dim;
86   CeedInt ndof;
87   CeedInt P1d;
88   CeedInt Q1d;
89   CeedScalar *qref1d;
90   CeedScalar *qweight1d;
91   CeedScalar *interp1d;
92   CeedScalar *grad1d;
93   void *data;       /* place for the backend to store any data */
94 };
95 
96 /* FIXME: The number of in-fields and out-fields may be different? */
97 /* FIXME: Shouldn't inmode and outmode be per-in-field and per-out-field,
98    respectively? */
99 struct CeedQFunction_private {
100   Ceed ceed;
101   int (*Apply)(CeedQFunction, void *, CeedInt, const CeedScalar *const *,
102                CeedScalar *const *);
103   int (*Destroy)(CeedQFunction);
104   CeedInt vlength;    // Number of quadrature points must be padded to a multiple of vlength
105   CeedInt nfields;
106   size_t qdatasize;   // Number of bytes of qdata per quadrature point
107   CeedEvalMode inmode, outmode;
108   int (*function)(void *, void *, CeedInt, const CeedScalar *const *,
109                   CeedScalar *const *);
110   const char *focca;
111   void *ctx;      /* user context for function */
112   size_t ctxsize; /* size of user context; may be used to copy to a device */
113   void *data;     /* backend data */
114 };
115 
116 struct CeedOperator_private {
117   Ceed ceed;
118   int (*Apply)(CeedOperator, CeedVector, CeedVector, CeedVector, CeedRequest *);
119   int (*ApplyJacobian)(CeedOperator, CeedVector, CeedVector, CeedVector,
120                        CeedVector, CeedRequest *);
121   int (*GetQData)(CeedOperator, CeedVector *);
122   int (*Destroy)(CeedOperator);
123   CeedElemRestriction Erestrict;
124   CeedBasis basis;
125   CeedQFunction qf;
126   CeedQFunction dqf;
127   CeedQFunction dqfT;
128   void *data;
129 };
130 
131 #endif
132