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 <stdbool.h> 24 25 #define CEED_INTERN CEED_EXTERN __attribute__((visibility ("hidden"))) 26 27 #define CEED_MAX_RESOURCE_LEN 1024 28 #define CEED_ALIGN 64 29 30 struct Ceed_private { 31 Ceed delegate; 32 int (*Error)(Ceed, const char *, int, const char *, int, const char *, va_list); 33 int (*Destroy)(Ceed); 34 int (*VecCreate)(CeedInt, CeedVector); 35 int (*ElemRestrictionCreate)(CeedMemType, CeedCopyMode, 36 const CeedInt *, CeedElemRestriction); 37 int (*ElemRestrictionCreateBlocked)(CeedMemType, CeedCopyMode, 38 const CeedInt *, CeedElemRestriction); 39 int (*BasisCreateTensorH1)(CeedInt, CeedInt, CeedInt, const CeedScalar *, 40 const CeedScalar *, const CeedScalar *, const CeedScalar *, CeedBasis); 41 int (*BasisCreateH1)(CeedElemTopology, CeedInt, CeedInt, CeedInt, 42 const CeedScalar *, 43 const CeedScalar *, const CeedScalar *, const CeedScalar *, CeedBasis); 44 int (*QFunctionCreate)(CeedQFunction); 45 int (*OperatorCreate)(CeedOperator); 46 int refcount; 47 void *data; 48 }; 49 50 struct CeedVector_private { 51 Ceed ceed; 52 int (*SetArray)(CeedVector, CeedMemType, CeedCopyMode, CeedScalar *); 53 int (*SetValue)(CeedVector, CeedScalar); 54 int (*GetArray)(CeedVector, CeedMemType, CeedScalar **); 55 int (*GetArrayRead)(CeedVector, CeedMemType, const CeedScalar **); 56 int (*RestoreArray)(CeedVector, CeedScalar **); 57 int (*RestoreArrayRead)(CeedVector, const CeedScalar **); 58 int (*Destroy)(CeedVector); 59 int refcount; 60 CeedInt length; 61 uint64_t state; 62 uint64_t numreaders; 63 void *data; 64 }; 65 66 struct CeedElemRestriction_private { 67 Ceed ceed; 68 int (*Apply)(CeedElemRestriction, CeedTransposeMode, CeedTransposeMode, 69 CeedVector, CeedVector, CeedRequest *); 70 int (*Destroy)(CeedElemRestriction); 71 int refcount; 72 CeedInt nelem; /* number of elements */ 73 CeedInt elemsize; /* number of dofs per element */ 74 CeedInt ndof; /* size of the L-vector, can be used for checking for 75 correct vector sizes */ 76 CeedInt ncomp; /* number of components */ 77 CeedInt blksize; /* number of elements in a batch */ 78 CeedInt nblk; /* number of blocks of elements */ 79 void *data; /* place for the backend to store any data */ 80 }; 81 82 struct CeedBasis_private { 83 Ceed ceed; 84 int (*Apply)(CeedBasis, CeedInt, CeedTransposeMode, CeedEvalMode, 85 const CeedScalar *, 86 CeedScalar *); 87 int (*Destroy)(CeedBasis); 88 int refcount; 89 bool tensorbasis; /* flag for tensor basis */ 90 CeedInt dim; /* topological dimension */ 91 CeedInt ncomp; /* number of field components (1 for scalar fields) */ 92 CeedInt P1d; /* number of nodes in one dimension */ 93 CeedInt Q1d; /* number of quadrature points in one dimension */ 94 CeedInt P; /* total number of nodes */ 95 CeedInt Q; /* total number of quadrature points */ 96 CeedScalar *qref1d; /* Array of length Q1d holding the locations of 97 quadrature points on the 1D reference element [-1, 1] */ 98 CeedScalar *qweight1d; /* array of length Q1d holding the quadrature weights on 99 the reference element */ 100 CeedScalar 101 *interp1d; /* row-major matrix of shape [Q1d, P1d] expressing the values of 102 nodal basis functions at quadrature points */ 103 CeedScalar 104 *grad1d; /* row-major matrix of shape [Q1d, P1d] matrix expressing derivatives of 105 nodal basis functions at quadrature points */ 106 void *data; /* place for the backend to store any data */ 107 }; 108 109 struct CeedQFunctionField_private { 110 const char *fieldname; 111 CeedInt ncomp; 112 CeedEvalMode emode; 113 }; 114 115 struct CeedQFunction_private { 116 Ceed ceed; 117 int (*Apply)(CeedQFunction, CeedInt, const CeedScalar *const *, 118 CeedScalar *const *); 119 int (*Destroy)(CeedQFunction); 120 int refcount; 121 CeedInt vlength; // Number of quadrature points must be padded to a multiple of vlength 122 CeedQFunctionField inputfields[16]; 123 CeedQFunctionField outputfields[16]; 124 CeedInt numinputfields, numoutputfields; 125 int (*function)(void*, CeedInt, const CeedScalar *const*, CeedScalar *const*); 126 const char *focca; 127 void *ctx; /* user context for function */ 128 size_t ctxsize; /* size of user context; may be used to copy to a device */ 129 void *data; /* backend data */ 130 }; 131 132 struct CeedOperatorField_private { 133 CeedElemRestriction Erestrict; /// Restriction from L-vector or NULL if identity 134 CeedTransposeMode lmode; /// Transpose mode for lvector ordering 135 CeedBasis basis; /// Basis or NULL for collocated fields 136 CeedVector 137 vec; /// State vector for passive fields, NULL for active fields 138 }; 139 140 struct CeedOperator_private { 141 Ceed ceed; 142 int refcount; 143 int (*Apply)(CeedOperator, CeedVector, CeedVector, CeedRequest *); 144 int (*ApplyJacobian)(CeedOperator, CeedVector, CeedVector, CeedVector, 145 CeedVector, CeedRequest *); 146 int (*GetQData)(CeedOperator, CeedVector *); 147 int (*Destroy)(CeedOperator); 148 CeedOperatorField inputfields[16]; 149 CeedOperatorField outputfields[16]; 150 CeedInt numelements; /// Number of elements 151 CeedInt numqpoints; /// Number of quadrature points over all elements 152 CeedInt nfields; /// Number of fields that have been set 153 CeedQFunction qf; 154 CeedQFunction dqf; 155 CeedQFunction dqfT; 156 bool setupdone; 157 void *data; 158 }; 159 160 CEED_INTERN int CeedErrorReturn(Ceed, const char *, int, const char *, int, 161 const char *, va_list); 162 CEED_INTERN int CeedErrorAbort(Ceed, const char *, int, const char *, int, 163 const char *, va_list); 164 CEED_INTERN int CeedErrorExit(Ceed, const char *, int, const char *, int, 165 const char *, va_list); 166 CEED_INTERN int CeedSetErrorHandler(Ceed ceed, 167 int (eh)(Ceed, const char *, int, const char *, 168 int, const char *, va_list)); 169 170 #endif 171