16ea7c6c1SJed Brown // Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at 26ea7c6c1SJed Brown // the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights 36ea7c6c1SJed Brown // reserved. See files LICENSE and NOTICE for details. 46ea7c6c1SJed Brown // 56ea7c6c1SJed Brown // This file is part of CEED, a collection of benchmarks, miniapps, software 66ea7c6c1SJed Brown // libraries and APIs for efficient high-order finite element and spectral 76ea7c6c1SJed Brown // element discretizations for exascale applications. For more information and 86ea7c6c1SJed Brown // source code availability see http://github.com/ceed. 96ea7c6c1SJed Brown // 106ea7c6c1SJed Brown // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC, 116ea7c6c1SJed Brown // a collaborative effort of two U.S. Department of Energy organizations (Office 126ea7c6c1SJed Brown // of Science and the National Nuclear Security Administration) responsible for 136ea7c6c1SJed Brown // the planning and preparation of a capable exascale ecosystem, including 146ea7c6c1SJed Brown // software, applications, hardware, advanced system engineering and early 156ea7c6c1SJed Brown // testbed platforms, in support of the nation's exascale computing imperative. 166ea7c6c1SJed Brown 175d6bafb2Sjeremylt /// @file 185d6bafb2Sjeremylt /// Private header for frontend components of libCEED 196ea7c6c1SJed Brown #ifndef _ceed_impl_h 206ea7c6c1SJed Brown #define _ceed_impl_h 216ea7c6c1SJed Brown 226ea7c6c1SJed Brown #include <ceed.h> 232f86a920SJeremy L Thompson #include <ceed-backend.h> 24ff8ca64bSJed Brown #include <stdbool.h> 256ea7c6c1SJed Brown 267a982d89SJeremy L. Thompson /** @defgroup CeedUser Public API for Ceed 277a982d89SJeremy L. Thompson @ingroup Ceed 287a982d89SJeremy L. Thompson */ 297a982d89SJeremy L. Thompson /** @defgroup CeedBackend Backend API for Ceed 307a982d89SJeremy L. Thompson @ingroup Ceed 317a982d89SJeremy L. Thompson */ 327a982d89SJeremy L. Thompson /** @defgroup CeedDeveloper Internal library functions for Ceed 337a982d89SJeremy L. Thompson @ingroup Ceed 347a982d89SJeremy L. Thompson */ 357a982d89SJeremy L. Thompson /** @defgroup CeedVectorUser Public API for CeedVector 367a982d89SJeremy L. Thompson @ingroup CeedVector 377a982d89SJeremy L. Thompson */ 387a982d89SJeremy L. Thompson /** @defgroup CeedVectorBackend Backend API for CeedVector 397a982d89SJeremy L. Thompson @ingroup CeedVector 407a982d89SJeremy L. Thompson */ 417a982d89SJeremy L. Thompson /** @defgroup CeedVectorDeveloper Internal library functions for CeedVector 427a982d89SJeremy L. Thompson @ingroup CeedVector 437a982d89SJeremy L. Thompson */ 447a982d89SJeremy L. Thompson /** @defgroup CeedElemRestrictionUser Public API for CeedElemRestriction 457a982d89SJeremy L. Thompson @ingroup CeedElemRestriction 467a982d89SJeremy L. Thompson */ 477a982d89SJeremy L. Thompson /** @defgroup CeedElemRestrictionBackend Backend API for CeedElemRestriction 487a982d89SJeremy L. Thompson @ingroup CeedElemRestriction 497a982d89SJeremy L. Thompson */ 507a982d89SJeremy L. Thompson /** @defgroup CeedElemRestrictionDeveloper Internal library functions for CeedElemRestriction 517a982d89SJeremy L. Thompson @ingroup CeedElemRestriction 527a982d89SJeremy L. Thompson */ 537a982d89SJeremy L. Thompson /** @defgroup CeedBasisUser Public API for CeedBasis 547a982d89SJeremy L. Thompson @ingroup CeedBasis 557a982d89SJeremy L. Thompson */ 567a982d89SJeremy L. Thompson /** @defgroup CeedBasisBackend Backend API for CeedBasis 577a982d89SJeremy L. Thompson @ingroup CeedBasis 587a982d89SJeremy L. Thompson */ 597a982d89SJeremy L. Thompson /** @defgroup CeedBasisDeveloper Internal library functions for CeedBasis 607a982d89SJeremy L. Thompson @ingroup CeedBasis 617a982d89SJeremy L. Thompson */ 627a982d89SJeremy L. Thompson /** @defgroup CeedQFunctionUser Public API for CeedQFunction 637a982d89SJeremy L. Thompson @ingroup CeedQFunction 647a982d89SJeremy L. Thompson */ 657a982d89SJeremy L. Thompson /** @defgroup CeedQFunctionBackend Backend API for CeedQFunction 667a982d89SJeremy L. Thompson @ingroup CeedQFunction 677a982d89SJeremy L. Thompson */ 687a982d89SJeremy L. Thompson /** @defgroup CeedQFunctionDeveloper Internal library functions for CeedQFunction 697a982d89SJeremy L. Thompson @ingroup CeedQFunction 707a982d89SJeremy L. Thompson */ 717a982d89SJeremy L. Thompson /** @defgroup CeedOperatorUser Public API for CeedOperator 727a982d89SJeremy L. Thompson @ingroup CeedOperator 737a982d89SJeremy L. Thompson */ 747a982d89SJeremy L. Thompson /** @defgroup CeedOperatorBackend Backend API for CeedOperator 757a982d89SJeremy L. Thompson @ingroup CeedOperator 767a982d89SJeremy L. Thompson */ 777a982d89SJeremy L. Thompson /** @defgroup CeedOperatorDeveloper Internal library functions for CeedOperator 787a982d89SJeremy L. Thompson @ingroup CeedOperator 797a982d89SJeremy L. Thompson */ 807a982d89SJeremy L. Thompson 81fe2413ffSjeremylt // Lookup table field for backend functions 82fe2413ffSjeremylt typedef struct { 83fe2413ffSjeremylt const char *fname; 84fe2413ffSjeremylt size_t offset; 85fe2413ffSjeremylt } foffset; 86fe2413ffSjeremylt 87aefd8378Sjeremylt // Lookup table field for object delegates 88aefd8378Sjeremylt typedef struct { 89aefd8378Sjeremylt char *objname; 90aefd8378Sjeremylt Ceed delegate; 91aefd8378Sjeremylt } objdelegate; 92aefd8378Sjeremylt 936ea7c6c1SJed Brown struct Ceed_private { 94e07206deSjeremylt const char *resource; 955fe0d4faSjeremylt Ceed delegate; 962f86a920SJeremy L Thompson Ceed parent; 97aefd8378Sjeremylt objdelegate *objdelegates; 98aefd8378Sjeremylt int objdelegatecount; 995107b09fSJeremy L Thompson Ceed opfallbackceed, opfallbackparent; 1005107b09fSJeremy L Thompson const char *opfallbackresource; 1012f86a920SJeremy L Thompson int (*Error)(Ceed, const char *, int, const char *, int, const char *, 1022f86a920SJeremy L Thompson va_list); 103c907536fSjeremylt int (*GetPreferredMemType)(CeedMemType *); 1046ea7c6c1SJed Brown int (*Destroy)(Ceed); 105f8902d9eSjeremylt int (*VectorCreate)(CeedInt, CeedVector); 106667bc5fcSjeremylt int (*ElemRestrictionCreate)(CeedMemType, CeedCopyMode, 107667bc5fcSjeremylt const CeedInt *, CeedElemRestriction); 108667bc5fcSjeremylt int (*ElemRestrictionCreateBlocked)(CeedMemType, CeedCopyMode, 109667bc5fcSjeremylt const CeedInt *, CeedElemRestriction); 110667bc5fcSjeremylt int (*BasisCreateTensorH1)(CeedInt, CeedInt, CeedInt, const CeedScalar *, 1112f86a920SJeremy L Thompson const CeedScalar *, const CeedScalar *, 1122f86a920SJeremy L Thompson const CeedScalar *, CeedBasis); 113667bc5fcSjeremylt int (*BasisCreateH1)(CeedElemTopology, CeedInt, CeedInt, CeedInt, 114a8de75f0Sjeremylt const CeedScalar *, 1152f86a920SJeremy L Thompson const CeedScalar *, const CeedScalar *, 1162f86a920SJeremy L Thompson const CeedScalar *, CeedBasis); 117c71e1dcdSjeremylt int (*TensorContractCreate)(CeedBasis, CeedTensorContract); 1186ea7c6c1SJed Brown int (*QFunctionCreate)(CeedQFunction); 1196ea7c6c1SJed Brown int (*OperatorCreate)(CeedOperator); 12052d6035fSJeremy L Thompson int (*CompositeOperatorCreate)(CeedOperator); 12180061934SJed Brown int refcount; 1229525855cSJeremy L Thompson bool isDeterministic; 1236ea7c6c1SJed Brown void *data; 12460f9e2d6SJeremy L Thompson bool debug; 125477729cfSJeremy L Thompson char errmsg[CEED_MAX_RESOURCE_LEN]; 1266e79d475Sjeremylt foffset *foffsets; 1276ea7c6c1SJed Brown }; 1286ea7c6c1SJed Brown 1296ea7c6c1SJed Brown struct CeedVector_private { 1306ea7c6c1SJed Brown Ceed ceed; 1316ea7c6c1SJed Brown int (*SetArray)(CeedVector, CeedMemType, CeedCopyMode, CeedScalar *); 1322a1ab385Sjeremylt int (*SetValue)(CeedVector, CeedScalar); 13354540941SJeremy L Thompson int (*SyncArray)(CeedVector, CeedMemType); 1346a6c615bSJeremy L Thompson int (*TakeArray)(CeedVector, CeedMemType, CeedScalar **); 1356ea7c6c1SJed Brown int (*GetArray)(CeedVector, CeedMemType, CeedScalar **); 1366ea7c6c1SJed Brown int (*GetArrayRead)(CeedVector, CeedMemType, const CeedScalar **); 137f05116b9SJeremy L Thompson int (*RestoreArray)(CeedVector); 138f05116b9SJeremy L Thompson int (*RestoreArrayRead)(CeedVector); 139547d9b97Sjeremylt int (*Norm)(CeedVector, CeedNormType, CeedScalar *); 140*d99fa3c5SJeremy L Thompson int (*Reciprocal)(CeedVector); 1416ea7c6c1SJed Brown int (*Destroy)(CeedVector); 142540765feSJed Brown int refcount; 1436ea7c6c1SJed Brown CeedInt length; 14436ac90ebSjeremylt uint64_t state; 1452cd729eeSjeremylt uint64_t numreaders; 1466ea7c6c1SJed Brown void *data; 1476ea7c6c1SJed Brown }; 1486ea7c6c1SJed Brown 1496ea7c6c1SJed Brown struct CeedElemRestriction_private { 1506ea7c6c1SJed Brown Ceed ceed; 151074cb416Sjeremylt int (*Apply)(CeedElemRestriction, CeedTransposeMode, CeedVector, CeedVector, 152074cb416Sjeremylt CeedRequest *); 153074cb416Sjeremylt int (*ApplyBlock)(CeedElemRestriction, CeedInt, CeedTransposeMode, CeedVector, 154074cb416Sjeremylt CeedVector, CeedRequest *); 155bd33150aSjeremylt int (*GetOffsets)(CeedElemRestriction, CeedMemType, const CeedInt **); 1566ea7c6c1SJed Brown int (*Destroy)(CeedElemRestriction); 157675ef50dSJed Brown int refcount; 1586ea7c6c1SJed Brown CeedInt nelem; /* number of elements */ 1598795c945Sjeremylt CeedInt elemsize; /* number of nodes per element */ 160ff8ca64bSJed Brown CeedInt ncomp; /* number of components */ 161d979a051Sjeremylt CeedInt compstride; /* Component stride for L-vector ordering */ 162d979a051Sjeremylt CeedInt lsize; /* size of the L-vector, can be used for checking 163d979a051Sjeremylt for correct vector sizes */ 1644e35ef05Sjeremylt CeedInt blksize; /* number of elements in a batch */ 1654e35ef05Sjeremylt CeedInt nblk; /* number of blocks of elements */ 1667509a596Sjeremylt CeedInt *strides; /* strides between [nodes, components, elements] */ 16749fd234cSJeremy L Thompson CeedInt layout[3]; /* E-vector layout [nodes, components, elements] */ 168430758c8SJeremy L Thompson uint64_t numreaders; /* number of instances of offset read only access */ 1696ea7c6c1SJed Brown void *data; /* place for the backend to store any data */ 1706ea7c6c1SJed Brown }; 1716ea7c6c1SJed Brown 1726ea7c6c1SJed Brown struct CeedBasis_private { 1736ea7c6c1SJed Brown Ceed ceed; 1744b8bea3bSJed Brown int (*Apply)(CeedBasis, CeedInt, CeedTransposeMode, CeedEvalMode, 175aedaa0e5Sjeremylt CeedVector, CeedVector); 1766ea7c6c1SJed Brown int (*Destroy)(CeedBasis); 177c3725256SJed Brown int refcount; 178a8de75f0Sjeremylt bool tensorbasis; /* flag for tensor basis */ 1790f5de9e9Sjeremylt CeedInt dim; /* topological dimension */ 180*d99fa3c5SJeremy L Thompson CeedElemTopology topo; /* element topology */ 1810f5de9e9Sjeremylt CeedInt ncomp; /* number of field components (1 for scalar fields) */ 1820f5de9e9Sjeremylt CeedInt P1d; /* number of nodes in one dimension */ 1830f5de9e9Sjeremylt CeedInt Q1d; /* number of quadrature points in one dimension */ 184a8de75f0Sjeremylt CeedInt P; /* total number of nodes */ 185a8de75f0Sjeremylt CeedInt Q; /* total number of quadrature points */ 1860f5de9e9Sjeremylt CeedScalar *qref1d; /* Array of length Q1d holding the locations of 187a8d32208Sjeremylt quadrature points on the 1D reference 188a8d32208Sjeremylt element [-1, 1] */ 1890f5de9e9Sjeremylt CeedScalar *qweight1d; /* array of length Q1d holding the quadrature weights on 1900f5de9e9Sjeremylt the reference element */ 1914b8bea3bSJed Brown CeedScalar 19200f91b2bSjeremylt *interp; /* row-major matrix of shape [Q, P] expressing the values of 19300f91b2bSjeremylt nodal basis functions at quadrature points */ 19400f91b2bSjeremylt CeedScalar 1954b8bea3bSJed Brown *interp1d; /* row-major matrix of shape [Q1d, P1d] expressing the values of 1960f5de9e9Sjeremylt nodal basis functions at quadrature points */ 1974b8bea3bSJed Brown CeedScalar 198a8d32208Sjeremylt *grad; /* row-major matrix of shape [dim*Q, P] matrix expressing 199a8d32208Sjeremylt derivatives of nodal basis functions at quadrature points */ 20000f91b2bSjeremylt CeedScalar 201a8d32208Sjeremylt *grad1d; /* row-major matrix of shape [Q1d, P1d] matrix expressing 202a8d32208Sjeremylt derivatives of nodal basis functions at quadrature points */ 2032f86a920SJeremy L Thompson CeedTensorContract contract; /* tensor contraction object */ 204c01dd730Scamierjs void *data; /* place for the backend to store any data */ 2056ea7c6c1SJed Brown }; 2066ea7c6c1SJed Brown 2072f86a920SJeremy L Thompson struct CeedTensorContract_private { 2082f86a920SJeremy L Thompson Ceed ceed; 2092f86a920SJeremy L Thompson int (*Apply)(CeedTensorContract, CeedInt, CeedInt, CeedInt, CeedInt, 2102f86a920SJeremy L Thompson const CeedScalar *restrict, CeedTransposeMode, const CeedInt, 2112f86a920SJeremy L Thompson const CeedScalar *restrict, CeedScalar *restrict); 2122f86a920SJeremy L Thompson int (*Destroy)(CeedTensorContract); 2132f86a920SJeremy L Thompson int refcount; 2142f86a920SJeremy L Thompson void *data; 2152f86a920SJeremy L Thompson }; 2162f86a920SJeremy L Thompson 217d1bcdac9Sjeremylt struct CeedQFunctionField_private { 218ff8ca64bSJed Brown const char *fieldname; 2194d537eeaSYohann CeedInt size; 220ff8ca64bSJed Brown CeedEvalMode emode; 221ff8ca64bSJed Brown }; 222ff8ca64bSJed Brown 2236ea7c6c1SJed Brown struct CeedQFunction_private { 2246ea7c6c1SJed Brown Ceed ceed; 2252f86a920SJeremy L Thompson int (*Apply)(CeedQFunction, CeedInt, CeedVector *, CeedVector *); 2266ea7c6c1SJed Brown int (*Destroy)(CeedQFunction); 2272123d1aaSJed Brown int refcount; 228a8d32208Sjeremylt CeedInt vlength; /* Number of quadrature points must be padded to a 229a8d32208Sjeremylt multiple of vlength */ 230fe2413ffSjeremylt CeedQFunctionField *inputfields; 231fe2413ffSjeremylt CeedQFunctionField *outputfields; 232ff8ca64bSJed Brown CeedInt numinputfields, numoutputfields; 2339f0427d9SYohann CeedQFunctionUser function; 234288c0443SJeremy L Thompson const char *sourcepath; 235288c0443SJeremy L Thompson const char *qfname; 236418fb8c2Sjeremylt bool fortranstatus; 2370219ea01SJeremy L Thompson bool identity; 2386ea7c6c1SJed Brown void *ctx; /* user context for function */ 239*d99fa3c5SJeremy L Thompson void *ctx_allocated; 2406ea7c6c1SJed Brown size_t ctxsize; /* size of user context; may be used to copy to a device */ 241a8d32208Sjeremylt void *data; /* place for the backend to store any data */ 2426ea7c6c1SJed Brown }; 2436ea7c6c1SJed Brown 2441e35832bSjeremylt /// Struct to handle the context data to use the Fortran QFunction stub 2451e35832bSjeremylt /// @ingroup CeedQFunction 246069aeabaSjeremylt typedef struct { 2471e35832bSjeremylt CeedScalar *innerctx; 248069aeabaSjeremylt size_t innerctxsize; 249069aeabaSjeremylt void (*f)(void *ctx, int *nq, 250069aeabaSjeremylt const CeedScalar *u,const CeedScalar *u1, 251069aeabaSjeremylt const CeedScalar *u2,const CeedScalar *u3, 252069aeabaSjeremylt const CeedScalar *u4,const CeedScalar *u5, 253069aeabaSjeremylt const CeedScalar *u6,const CeedScalar *u7, 254069aeabaSjeremylt const CeedScalar *u8,const CeedScalar *u9, 255069aeabaSjeremylt const CeedScalar *u10,const CeedScalar *u11, 256069aeabaSjeremylt const CeedScalar *u12,const CeedScalar *u13, 257069aeabaSjeremylt const CeedScalar *u14,const CeedScalar *u15, 258069aeabaSjeremylt CeedScalar *v,CeedScalar *v1,CeedScalar *v2, 259069aeabaSjeremylt CeedScalar *v3,CeedScalar *v4,CeedScalar *v5, 260069aeabaSjeremylt CeedScalar *v6,CeedScalar *v7,CeedScalar *v8, 261069aeabaSjeremylt CeedScalar *v9, CeedScalar *v10,CeedScalar *v11, 262069aeabaSjeremylt CeedScalar *v12,CeedScalar *v13,CeedScalar *v14, 263069aeabaSjeremylt CeedScalar *v15, int *err); 264069aeabaSjeremylt } fContext; 265069aeabaSjeremylt 266d1bcdac9Sjeremylt struct CeedOperatorField_private { 267a8d32208Sjeremylt CeedElemRestriction Erestrict; /* Restriction from L-vector */ 268a8d32208Sjeremylt CeedBasis basis; /* Basis or CEED_BASIS_COLLOCATED for 269a8d32208Sjeremylt collocated fields */ 270a8d32208Sjeremylt CeedVector vec; /* State vector for passive fields or 271a8d32208Sjeremylt CEED_VECTOR_NONE for no vector */ 272*d99fa3c5SJeremy L Thompson const char *fieldname; /* matching QFunction field name */ 273ff8ca64bSJed Brown }; 274ff8ca64bSJed Brown 2756ea7c6c1SJed Brown struct CeedOperator_private { 2766ea7c6c1SJed Brown Ceed ceed; 2775107b09fSJeremy L Thompson CeedOperator opfallback; 2785107b09fSJeremy L Thompson CeedQFunction qffallback; 279c4da7380SJed Brown int refcount; 28080ac2e43SJeremy L Thompson int (*LinearAssembleQFunction)(CeedOperator, CeedVector *, 2811d102b48SJeremy L Thompson CeedElemRestriction *, CeedRequest *); 2822bba3ffaSJeremy L Thompson int (*LinearAssembleDiagonal)(CeedOperator, CeedVector, CeedRequest *); 2839e9210b8SJeremy L Thompson int (*LinearAssembleAddDiagonal)(CeedOperator, CeedVector, CeedRequest *); 2842bba3ffaSJeremy L Thompson int (*LinearAssemblePointBlockDiagonal)(CeedOperator, CeedVector, 285d965c7a7SJeremy L Thompson CeedRequest *); 2869e9210b8SJeremy L Thompson int (*LinearAssembleAddPointBlockDiagonal)(CeedOperator, CeedVector, 2879e9210b8SJeremy L Thompson CeedRequest *); 288713f43c3Sjeremylt int (*CreateFDMElementInverse)(CeedOperator, CeedOperator *, CeedRequest *); 289ff8ca64bSJed Brown int (*Apply)(CeedOperator, CeedVector, CeedVector, CeedRequest *); 290250756a7Sjeremylt int (*ApplyComposite)(CeedOperator, CeedVector, CeedVector, CeedRequest *); 291cae8b89aSjeremylt int (*ApplyAdd)(CeedOperator, CeedVector, CeedVector, CeedRequest *); 292250756a7Sjeremylt int (*ApplyAddComposite)(CeedOperator, CeedVector, CeedVector, CeedRequest *); 2936ea7c6c1SJed Brown int (*ApplyJacobian)(CeedOperator, CeedVector, CeedVector, CeedVector, 2946ea7c6c1SJed Brown CeedVector, CeedRequest *); 2956ea7c6c1SJed Brown int (*Destroy)(CeedOperator); 296fe2413ffSjeremylt CeedOperatorField *inputfields; 297fe2413ffSjeremylt CeedOperatorField *outputfields; 298ff8ca64bSJed Brown CeedInt numelements; /// Number of elements 299ff8ca64bSJed Brown CeedInt numqpoints; /// Number of quadrature points over all elements 300ef700c2cSjeremylt CeedInt nfields; /// Number of fields that have been set 3016ea7c6c1SJed Brown CeedQFunction qf; 3026ea7c6c1SJed Brown CeedQFunction dqf; 3036ea7c6c1SJed Brown CeedQFunction dqfT; 304ff8ca64bSJed Brown bool setupdone; 30552d6035fSJeremy L Thompson bool composite; 3062cb0afc5Sjeremylt bool hasrestriction; 30752d6035fSJeremy L Thompson CeedOperator *suboperators; 30852d6035fSJeremy L Thompson CeedInt numsub; 3096ea7c6c1SJed Brown void *data; 3106ea7c6c1SJed Brown }; 3116ea7c6c1SJed Brown 3126ea7c6c1SJed Brown #endif 313