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; /* 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 CeedScalar *qref1d; /* Array of length Q1d holding the locations of 95 quadrature points on the 1D reference element [-1, 1] */ 96 CeedScalar *qweight1d; /* array of length Q1d holding the quadrature weights on 97 the reference element */ 98 CeedScalar *interp1d; /* row-major Q1d × P1d matrix expressing the values of 99 nodal basis functions at quadrature points */ 100 CeedScalar *grad1d; /* row-major Q1d × P1d matrix expressing derivatives of 101 nodal basis functions at quadrature points */ 102 void *data; /* place for the backend to store any data */ 103 }; 104 105 struct CeedQFunctionField { 106 const char *fieldname; 107 CeedInt ncomp; 108 CeedEvalMode emode; 109 }; 110 111 struct CeedQFunction_private { 112 Ceed ceed; 113 int (*Apply)(CeedQFunction, CeedInt, const CeedScalar *const *, 114 CeedScalar *const *); 115 int (*Destroy)(CeedQFunction); 116 int refcount; 117 CeedInt vlength; // Number of quadrature points must be padded to a multiple of vlength 118 struct CeedQFunctionField inputfields[16]; 119 struct CeedQFunctionField outputfields[16]; 120 CeedInt numinputfields, numoutputfields; 121 int (*function)(void*, CeedInt, const CeedScalar *const*, CeedScalar *const*); 122 const char *focca; 123 void *ctx; /* user context for function */ 124 size_t ctxsize; /* size of user context; may be used to copy to a device */ 125 void *data; /* backend data */ 126 }; 127 128 struct CeedOperatorField { 129 CeedElemRestriction Erestrict; /// Restriction from L-vector or NULL if identity 130 CeedBasis basis; /// Basis or NULL for collocated fields 131 CeedVector vec; /// State vector for passive fields, NULL for active fields 132 }; 133 134 struct CeedOperator_private { 135 Ceed ceed; 136 int refcount; 137 int (*Apply)(CeedOperator, CeedVector, CeedVector, CeedRequest *); 138 int (*ApplyJacobian)(CeedOperator, CeedVector, CeedVector, CeedVector, 139 CeedVector, CeedRequest *); 140 int (*GetQData)(CeedOperator, CeedVector *); 141 int (*Destroy)(CeedOperator); 142 struct CeedOperatorField inputfields[16]; 143 struct CeedOperatorField outputfields[16]; 144 CeedInt numelements; /// Number of elements 145 CeedInt numqpoints; /// Number of quadrature points over all elements 146 CeedInt nfields; /// Number of fields that have been set 147 CeedQFunction qf; 148 CeedQFunction dqf; 149 CeedQFunction dqfT; 150 bool setupdone; 151 void *data; 152 }; 153 154 #endif 155