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 /** @defgroup CeedUser Public API for Ceed 27 @ingroup Ceed 28 */ 29 /** @defgroup CeedBackend Backend API for Ceed 30 @ingroup Ceed 31 */ 32 /** @defgroup CeedDeveloper Internal library functions for Ceed 33 @ingroup Ceed 34 */ 35 /** @defgroup CeedVectorUser Public API for CeedVector 36 @ingroup CeedVector 37 */ 38 /** @defgroup CeedVectorBackend Backend API for CeedVector 39 @ingroup CeedVector 40 */ 41 /** @defgroup CeedVectorDeveloper Internal library functions for CeedVector 42 @ingroup CeedVector 43 */ 44 /** @defgroup CeedElemRestrictionUser Public API for CeedElemRestriction 45 @ingroup CeedElemRestriction 46 */ 47 /** @defgroup CeedElemRestrictionBackend Backend API for CeedElemRestriction 48 @ingroup CeedElemRestriction 49 */ 50 /** @defgroup CeedElemRestrictionDeveloper Internal library functions for CeedElemRestriction 51 @ingroup CeedElemRestriction 52 */ 53 /** @defgroup CeedBasisUser Public API for CeedBasis 54 @ingroup CeedBasis 55 */ 56 /** @defgroup CeedBasisBackend Backend API for CeedBasis 57 @ingroup CeedBasis 58 */ 59 /** @defgroup CeedBasisDeveloper Internal library functions for CeedBasis 60 @ingroup CeedBasis 61 */ 62 /** @defgroup CeedQFunctionUser Public API for CeedQFunction 63 @ingroup CeedQFunction 64 */ 65 /** @defgroup CeedQFunctionBackend Backend API for CeedQFunction 66 @ingroup CeedQFunction 67 */ 68 /** @defgroup CeedQFunctionDeveloper Internal library functions for CeedQFunction 69 @ingroup CeedQFunction 70 */ 71 /** @defgroup CeedOperatorUser Public API for CeedOperator 72 @ingroup CeedOperator 73 */ 74 /** @defgroup CeedOperatorBackend Backend API for CeedOperator 75 @ingroup CeedOperator 76 */ 77 /** @defgroup CeedOperatorDeveloper Internal library functions for CeedOperator 78 @ingroup CeedOperator 79 */ 80 81 // Lookup table field for backend functions 82 typedef struct { 83 const char *fname; 84 size_t offset; 85 } foffset; 86 87 // Lookup table field for object delegates 88 typedef struct { 89 char *objname; 90 Ceed delegate; 91 } objdelegate; 92 93 struct Ceed_private { 94 const char *resource; 95 Ceed delegate; 96 Ceed parent; 97 objdelegate *objdelegates; 98 int objdelegatecount; 99 Ceed opfallbackceed, opfallbackparent; 100 const char *opfallbackresource; 101 int (*Error)(Ceed, const char *, int, const char *, int, const char *, 102 va_list); 103 int (*GetPreferredMemType)(CeedMemType *); 104 int (*Destroy)(Ceed); 105 int (*VectorCreate)(CeedInt, CeedVector); 106 int (*ElemRestrictionCreate)(CeedMemType, CeedCopyMode, 107 const CeedInt *, CeedElemRestriction); 108 int (*ElemRestrictionCreateBlocked)(CeedMemType, CeedCopyMode, 109 const CeedInt *, CeedElemRestriction); 110 int (*BasisCreateTensorH1)(CeedInt, CeedInt, CeedInt, const CeedScalar *, 111 const CeedScalar *, const CeedScalar *, 112 const CeedScalar *, CeedBasis); 113 int (*BasisCreateH1)(CeedElemTopology, CeedInt, CeedInt, CeedInt, 114 const CeedScalar *, 115 const CeedScalar *, const CeedScalar *, 116 const CeedScalar *, CeedBasis); 117 int (*TensorContractCreate)(CeedBasis, CeedTensorContract); 118 int (*QFunctionCreate)(CeedQFunction); 119 int (*OperatorCreate)(CeedOperator); 120 int (*CompositeOperatorCreate)(CeedOperator); 121 int refcount; 122 void *data; 123 foffset *foffsets; 124 }; 125 126 struct CeedVector_private { 127 Ceed ceed; 128 int (*SetArray)(CeedVector, CeedMemType, CeedCopyMode, CeedScalar *); 129 int (*SetValue)(CeedVector, CeedScalar); 130 int (*SyncArray)(CeedVector, CeedMemType); 131 int (*GetArray)(CeedVector, CeedMemType, CeedScalar **); 132 int (*GetArrayRead)(CeedVector, CeedMemType, const CeedScalar **); 133 int (*RestoreArray)(CeedVector); 134 int (*RestoreArrayRead)(CeedVector); 135 int (*Norm)(CeedVector, CeedNormType, CeedScalar *); 136 int (*Destroy)(CeedVector); 137 int refcount; 138 CeedInt length; 139 uint64_t state; 140 uint64_t numreaders; 141 void *data; 142 }; 143 144 struct CeedElemRestriction_private { 145 Ceed ceed; 146 int (*Apply)(CeedElemRestriction, CeedTransposeMode, CeedVector, CeedVector, 147 CeedRequest *); 148 int (*ApplyBlock)(CeedElemRestriction, CeedInt, CeedTransposeMode, CeedVector, 149 CeedVector, CeedRequest *); 150 int (*GetOffsets)(CeedElemRestriction, CeedMemType, const CeedInt **); 151 int (*Destroy)(CeedElemRestriction); 152 int refcount; 153 CeedInt nelem; /* number of elements */ 154 CeedInt elemsize; /* number of nodes per element */ 155 CeedInt ncomp; /* number of components */ 156 CeedInt compstride; /* Component stride for L-vector ordering */ 157 CeedInt lsize; /* size of the L-vector, can be used for checking 158 for correct vector sizes */ 159 CeedInt blksize; /* number of elements in a batch */ 160 CeedInt nblk; /* number of blocks of elements */ 161 CeedInt *strides; /* strides between [nodes, components, elements] */ 162 CeedInt layout[3]; /* E-vector layout [nodes, components, elements] */ 163 uint64_t numreaders; /* number of instances of offset read only access */ 164 void *data; /* place for the backend to store any data */ 165 }; 166 167 struct CeedBasis_private { 168 Ceed ceed; 169 int (*Apply)(CeedBasis, CeedInt, CeedTransposeMode, CeedEvalMode, 170 CeedVector, CeedVector); 171 int (*Destroy)(CeedBasis); 172 int refcount; 173 bool tensorbasis; /* flag for tensor basis */ 174 CeedInt dim; /* topological dimension */ 175 CeedInt ncomp; /* number of field components (1 for scalar fields) */ 176 CeedInt P1d; /* number of nodes in one dimension */ 177 CeedInt Q1d; /* number of quadrature points in one dimension */ 178 CeedInt P; /* total number of nodes */ 179 CeedInt Q; /* total number of quadrature points */ 180 CeedScalar *qref1d; /* Array of length Q1d holding the locations of 181 quadrature points on the 1D reference 182 element [-1, 1] */ 183 CeedScalar *qweight1d; /* array of length Q1d holding the quadrature weights on 184 the reference element */ 185 CeedScalar 186 *interp; /* row-major matrix of shape [Q, P] expressing the values of 187 nodal basis functions at quadrature points */ 188 CeedScalar 189 *interp1d; /* row-major matrix of shape [Q1d, P1d] expressing the values of 190 nodal basis functions at quadrature points */ 191 CeedScalar 192 *grad; /* row-major matrix of shape [dim*Q, P] matrix expressing 193 derivatives of nodal basis functions at quadrature points */ 194 CeedScalar 195 *grad1d; /* row-major matrix of shape [Q1d, P1d] matrix expressing 196 derivatives of nodal basis functions at quadrature points */ 197 CeedTensorContract contract; /* tensor contraction object */ 198 void *data; /* place for the backend to store any data */ 199 }; 200 201 struct CeedTensorContract_private { 202 Ceed ceed; 203 int (*Apply)(CeedTensorContract, CeedInt, CeedInt, CeedInt, CeedInt, 204 const CeedScalar *restrict, CeedTransposeMode, const CeedInt, 205 const CeedScalar *restrict, CeedScalar *restrict); 206 int (*Destroy)(CeedTensorContract); 207 int refcount; 208 void *data; 209 }; 210 211 struct CeedQFunctionField_private { 212 const char *fieldname; 213 CeedInt size; 214 CeedEvalMode emode; 215 }; 216 217 struct CeedQFunction_private { 218 Ceed ceed; 219 int (*Apply)(CeedQFunction, CeedInt, CeedVector *, CeedVector *); 220 int (*Destroy)(CeedQFunction); 221 int refcount; 222 CeedInt vlength; /* Number of quadrature points must be padded to a 223 multiple of vlength */ 224 CeedQFunctionField *inputfields; 225 CeedQFunctionField *outputfields; 226 CeedInt numinputfields, numoutputfields; 227 CeedQFunctionUser function; 228 const char *sourcepath; 229 const char *qfname; 230 bool fortranstatus; 231 bool identity; 232 void *ctx; /* user context for function */ 233 size_t ctxsize; /* size of user context; may be used to copy to a device */ 234 void *data; /* place for the backend to store any data */ 235 }; 236 237 /// Struct to handle the context data to use the Fortran QFunction stub 238 /// @ingroup CeedQFunction 239 typedef struct { 240 CeedScalar *innerctx; 241 size_t innerctxsize; 242 void (*f)(void *ctx, int *nq, 243 const CeedScalar *u,const CeedScalar *u1, 244 const CeedScalar *u2,const CeedScalar *u3, 245 const CeedScalar *u4,const CeedScalar *u5, 246 const CeedScalar *u6,const CeedScalar *u7, 247 const CeedScalar *u8,const CeedScalar *u9, 248 const CeedScalar *u10,const CeedScalar *u11, 249 const CeedScalar *u12,const CeedScalar *u13, 250 const CeedScalar *u14,const CeedScalar *u15, 251 CeedScalar *v,CeedScalar *v1,CeedScalar *v2, 252 CeedScalar *v3,CeedScalar *v4,CeedScalar *v5, 253 CeedScalar *v6,CeedScalar *v7,CeedScalar *v8, 254 CeedScalar *v9, CeedScalar *v10,CeedScalar *v11, 255 CeedScalar *v12,CeedScalar *v13,CeedScalar *v14, 256 CeedScalar *v15, int *err); 257 } fContext; 258 259 struct CeedOperatorField_private { 260 CeedElemRestriction Erestrict; /* Restriction from L-vector */ 261 CeedBasis basis; /* Basis or CEED_BASIS_COLLOCATED for 262 collocated fields */ 263 CeedVector vec; /* State vector for passive fields or 264 CEED_VECTOR_NONE for no vector */ 265 }; 266 267 struct CeedOperator_private { 268 Ceed ceed; 269 CeedOperator opfallback; 270 CeedQFunction qffallback; 271 int refcount; 272 int (*LinearAssembleQFunction)(CeedOperator, CeedVector *, 273 CeedElemRestriction *, CeedRequest *); 274 int (*LinearAssembleDiagonal)(CeedOperator, CeedVector, CeedRequest *); 275 int (*LinearAssembleAddDiagonal)(CeedOperator, CeedVector, CeedRequest *); 276 int (*LinearAssemblePointBlockDiagonal)(CeedOperator, CeedVector, 277 CeedRequest *); 278 int (*LinearAssembleAddPointBlockDiagonal)(CeedOperator, CeedVector, 279 CeedRequest *); 280 int (*CreateFDMElementInverse)(CeedOperator, CeedOperator *, CeedRequest *); 281 int (*Apply)(CeedOperator, CeedVector, CeedVector, CeedRequest *); 282 int (*ApplyComposite)(CeedOperator, CeedVector, CeedVector, CeedRequest *); 283 int (*ApplyAdd)(CeedOperator, CeedVector, CeedVector, CeedRequest *); 284 int (*ApplyAddComposite)(CeedOperator, CeedVector, CeedVector, CeedRequest *); 285 int (*ApplyJacobian)(CeedOperator, CeedVector, CeedVector, CeedVector, 286 CeedVector, CeedRequest *); 287 int (*Destroy)(CeedOperator); 288 CeedOperatorField *inputfields; 289 CeedOperatorField *outputfields; 290 CeedInt numelements; /// Number of elements 291 CeedInt numqpoints; /// Number of quadrature points over all elements 292 CeedInt nfields; /// Number of fields that have been set 293 CeedQFunction qf; 294 CeedQFunction dqf; 295 CeedQFunction dqfT; 296 bool setupdone; 297 bool composite; 298 bool hasrestriction; 299 CeedOperator *suboperators; 300 CeedInt numsub; 301 void *data; 302 }; 303 304 CEED_INTERN int CeedErrorReturn(Ceed, const char *, int, const char *, int, 305 const char *, va_list); 306 CEED_INTERN int CeedErrorAbort(Ceed, const char *, int, const char *, int, 307 const char *, va_list); 308 CEED_INTERN int CeedErrorExit(Ceed, const char *, int, const char *, int, 309 const char *, va_list); 310 CEED_INTERN int CeedSetErrorHandler(Ceed ceed, 311 int (*eh)(Ceed, const char *, int, 312 const char *, int, const char *, 313 va_list)); 314 315 #endif 316