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 #include <stdbool.h> 22 23 #define CEED_INTERN CEED_EXTERN __attribute__((visibility ("hidden"))) 24 25 #define CEED_MAX_RESOURCE_LEN 1024 26 #define CEED_ALIGN 64 27 28 struct Ceed_private { 29 int (*Error)(Ceed, const char *, int, const char *, int, const char *, va_list); 30 int (*Destroy)(Ceed); 31 int (*VecCreate)(Ceed, CeedInt, CeedVector); 32 int (*ElemRestrictionCreate)(CeedElemRestriction, CeedMemType, CeedCopyMode, 33 const CeedInt *); 34 int (*BasisCreateTensorH1)(Ceed, CeedInt, CeedInt, CeedInt, const CeedScalar *, 35 const CeedScalar *, const CeedScalar *, const CeedScalar *, CeedBasis); 36 int (*QFunctionCreate)(CeedQFunction); 37 int (*OperatorCreate)(CeedOperator); 38 int refcount; 39 void *data; 40 }; 41 42 /* In the next 3 functions, p has to be the address of a pointer type, i.e. p 43 has to be a pointer to a pointer. */ 44 CEED_INTERN int CeedMallocArray(size_t n, size_t unit, void *p); 45 CEED_INTERN int CeedCallocArray(size_t n, size_t unit, void *p); 46 CEED_INTERN int CeedReallocArray(size_t n, size_t unit, void *p); 47 CEED_INTERN int CeedFree(void *p); 48 49 #define CeedChk(ierr) do { if (ierr) return ierr; } while (0) 50 /* Note that CeedMalloc and CeedCalloc will, generally, return pointers with 51 different memory alignments: CeedMalloc returns pointers aligned at 52 CEED_ALIGN bytes, while CeedCalloc uses the alignment of calloc. */ 53 #define CeedMalloc(n, p) CeedMallocArray((n), sizeof(**(p)), p) 54 #define CeedCalloc(n, p) CeedCallocArray((n), sizeof(**(p)), p) 55 #define CeedRealloc(n, p) CeedReallocArray((n), sizeof(**(p)), p) 56 57 struct CeedVector_private { 58 Ceed ceed; 59 int (*SetArray)(CeedVector, CeedMemType, CeedCopyMode, CeedScalar *); 60 int (*GetArray)(CeedVector, CeedMemType, CeedScalar **); 61 int (*GetArrayRead)(CeedVector, CeedMemType, const CeedScalar **); 62 int (*RestoreArray)(CeedVector, CeedScalar **); 63 int (*RestoreArrayRead)(CeedVector, const CeedScalar **); 64 int (*Destroy)(CeedVector); 65 int refcount; 66 CeedInt length; 67 void *data; 68 }; 69 70 struct CeedElemRestriction_private { 71 Ceed ceed; 72 int (*Apply)(CeedElemRestriction, CeedTransposeMode, CeedTransposeMode, 73 CeedVector, CeedVector, CeedRequest *); 74 int (*Destroy)(CeedElemRestriction); 75 int refcount; 76 CeedInt nelem; /* number of elements */ 77 CeedInt elemsize; /* number of dofs per element */ 78 CeedInt ndof; /* size of the L-vector, can be used for checking for 79 correct vector sizes */ 80 CeedInt ncomp; /* number of components */ 81 void *data; /* place for the backend to store any data */ 82 }; 83 84 struct CeedBasis_private { 85 Ceed ceed; 86 int (*Apply)(CeedBasis, CeedTransposeMode, CeedEvalMode, const CeedScalar *, 87 CeedScalar *); 88 int (*Destroy)(CeedBasis); 89 int refcount; 90 CeedInt dim; 91 CeedInt ndof; 92 CeedInt P1d; 93 CeedInt Q1d; 94 CeedScalar *qref1d; 95 CeedScalar *qweight1d; 96 CeedScalar *interp1d; 97 CeedScalar *grad1d; 98 void *data; /* place for the backend to store any data */ 99 }; 100 101 struct CeedQFunctionField { 102 const char *fieldname; 103 CeedInt ncomp; 104 CeedEvalMode emode; 105 }; 106 107 struct CeedQFunction_private { 108 Ceed ceed; 109 int (*Apply)(CeedQFunction, CeedInt, const CeedScalar *const *, 110 CeedScalar *const *); 111 int (*Destroy)(CeedQFunction); 112 int refcount; 113 CeedInt vlength; // Number of quadrature points must be padded to a multiple of vlength 114 struct CeedQFunctionField inputfields[16]; 115 struct CeedQFunctionField outputfields[16]; 116 CeedInt numinputfields, numoutputfields; 117 int (*function)(void*, CeedInt, const CeedScalar *const*, CeedScalar *const*); 118 const char *focca; 119 void *ctx; /* user context for function */ 120 size_t ctxsize; /* size of user context; may be used to copy to a device */ 121 void *data; /* backend data */ 122 }; 123 124 struct CeedOperatorField { 125 CeedElemRestriction Erestrict; /// Restriction from L-vector or NULL if identity 126 CeedBasis basis; /// Basis or NULL for collocated fields 127 CeedVector vec; /// State vector for passive fields, NULL for active fields 128 }; 129 130 struct CeedOperator_private { 131 Ceed ceed; 132 int refcount; 133 int (*Apply)(CeedOperator, CeedVector, CeedVector, CeedRequest *); 134 int (*ApplyJacobian)(CeedOperator, CeedVector, CeedVector, CeedVector, 135 CeedVector, CeedRequest *); 136 int (*GetQData)(CeedOperator, CeedVector *); 137 int (*Destroy)(CeedOperator); 138 struct CeedOperatorField inputfields[16]; 139 struct CeedOperatorField outputfields[16]; 140 CeedInt numelements; /// Number of elements 141 CeedInt numqpoints; /// Number of quadrature points over all elements 142 CeedQFunction qf; 143 CeedQFunction dqf; 144 CeedQFunction dqfT; 145 bool setupdone; 146 void *data; 147 }; 148 149 #endif 150