xref: /libCEED/rust/libceed-sys/c-src/include/ceed-impl.h (revision 2027fb9d13fe34211738d8539f90542a9801ae2c)
1d275d636SJeremy L Thompson // Copyright (c) 2017-2025, Lawrence Livermore National Security, LLC and other CEED contributors.
23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
36ea7c6c1SJed Brown //
43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
56ea7c6c1SJed Brown //
63d8e8822SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
76ea7c6c1SJed Brown 
85d6bafb2Sjeremylt /// @file
95d6bafb2Sjeremylt /// Private header for frontend components of libCEED
10a844dea2SJeremy L Thompson #pragma once
116ea7c6c1SJed Brown 
1249aac155SJeremy L Thompson #include <ceed.h>
13ec3da8bcSJed Brown #include <ceed/backend.h>
14ff8ca64bSJed Brown #include <stdbool.h>
156ea7c6c1SJed Brown 
162b730f8bSJeremy L Thompson CEED_INTERN const char *CeedJitSourceRootDefault;
17032e71eaSJeremy L Thompson 
187a982d89SJeremy L. Thompson /** @defgroup CeedUser Public API for Ceed
197a982d89SJeremy L. Thompson     @ingroup Ceed
207a982d89SJeremy L. Thompson */
217a982d89SJeremy L. Thompson /** @defgroup CeedBackend Backend API for Ceed
227a982d89SJeremy L. Thompson     @ingroup Ceed
237a982d89SJeremy L. Thompson */
247a982d89SJeremy L. Thompson /** @defgroup CeedDeveloper Internal library functions for Ceed
257a982d89SJeremy L. Thompson     @ingroup Ceed
267a982d89SJeremy L. Thompson */
277a982d89SJeremy L. Thompson /** @defgroup CeedVectorUser Public API for CeedVector
287a982d89SJeremy L. Thompson     @ingroup CeedVector
297a982d89SJeremy L. Thompson */
307a982d89SJeremy L. Thompson /** @defgroup CeedVectorBackend Backend API for CeedVector
317a982d89SJeremy L. Thompson     @ingroup CeedVector
327a982d89SJeremy L. Thompson */
337a982d89SJeremy L. Thompson /** @defgroup CeedVectorDeveloper Internal library functions for CeedVector
347a982d89SJeremy L. Thompson     @ingroup CeedVector
357a982d89SJeremy L. Thompson */
367a982d89SJeremy L. Thompson /** @defgroup CeedElemRestrictionUser Public API for CeedElemRestriction
377a982d89SJeremy L. Thompson     @ingroup CeedElemRestriction
387a982d89SJeremy L. Thompson */
397a982d89SJeremy L. Thompson /** @defgroup CeedElemRestrictionBackend Backend API for CeedElemRestriction
407a982d89SJeremy L. Thompson     @ingroup CeedElemRestriction
417a982d89SJeremy L. Thompson */
427a982d89SJeremy L. Thompson /** @defgroup CeedElemRestrictionDeveloper Internal library functions for CeedElemRestriction
437a982d89SJeremy L. Thompson     @ingroup CeedElemRestriction
447a982d89SJeremy L. Thompson */
457a982d89SJeremy L. Thompson /** @defgroup CeedBasisUser Public API for CeedBasis
467a982d89SJeremy L. Thompson     @ingroup CeedBasis
477a982d89SJeremy L. Thompson */
487a982d89SJeremy L. Thompson /** @defgroup CeedBasisBackend Backend API for CeedBasis
497a982d89SJeremy L. Thompson     @ingroup CeedBasis
507a982d89SJeremy L. Thompson */
517a982d89SJeremy L. Thompson /** @defgroup CeedBasisDeveloper Internal library functions for CeedBasis
527a982d89SJeremy L. Thompson     @ingroup CeedBasis
537a982d89SJeremy L. Thompson */
547a982d89SJeremy L. Thompson /** @defgroup CeedQFunctionUser Public API for CeedQFunction
557a982d89SJeremy L. Thompson     @ingroup CeedQFunction
567a982d89SJeremy L. Thompson */
577a982d89SJeremy L. Thompson /** @defgroup CeedQFunctionBackend Backend API for CeedQFunction
587a982d89SJeremy L. Thompson     @ingroup CeedQFunction
597a982d89SJeremy L. Thompson */
607a982d89SJeremy L. Thompson /** @defgroup CeedQFunctionDeveloper Internal library functions for CeedQFunction
617a982d89SJeremy L. Thompson     @ingroup CeedQFunction
627a982d89SJeremy L. Thompson */
637a982d89SJeremy L. Thompson /** @defgroup CeedOperatorUser Public API for CeedOperator
647a982d89SJeremy L. Thompson     @ingroup CeedOperator
657a982d89SJeremy L. Thompson */
667a982d89SJeremy L. Thompson /** @defgroup CeedOperatorBackend Backend API for CeedOperator
677a982d89SJeremy L. Thompson     @ingroup CeedOperator
687a982d89SJeremy L. Thompson */
697a982d89SJeremy L. Thompson /** @defgroup CeedOperatorDeveloper Internal library functions for CeedOperator
707a982d89SJeremy L. Thompson     @ingroup CeedOperator
717a982d89SJeremy L. Thompson */
727a982d89SJeremy L. Thompson 
73fe2413ffSjeremylt // Lookup table field for backend functions
74fe2413ffSjeremylt typedef struct {
75d1d35e2fSjeremylt   const char *func_name;
76fe2413ffSjeremylt   size_t      offset;
77d1d35e2fSjeremylt } FOffset;
78fe2413ffSjeremylt 
79aefd8378Sjeremylt // Lookup table field for object delegates
80aefd8378Sjeremylt typedef struct {
81d1d35e2fSjeremylt   char *obj_name;
82aefd8378Sjeremylt   Ceed  delegate;
83d1d35e2fSjeremylt } ObjDelegate;
84aefd8378Sjeremylt 
8573501bfeSJeremy L Thompson // Work vector tracking
8673501bfeSJeremy L Thompson typedef struct CeedWorkVectors_private *CeedWorkVectors;
8773501bfeSJeremy L Thompson struct CeedWorkVectors_private {
8873501bfeSJeremy L Thompson   CeedInt     num_vecs, max_vecs;
8973501bfeSJeremy L Thompson   bool       *is_in_use;
9073501bfeSJeremy L Thompson   CeedVector *vecs;
9173501bfeSJeremy L Thompson };
9273501bfeSJeremy L Thompson 
936ea7c6c1SJed Brown struct Ceed_private {
94e07206deSjeremylt   const char  *resource;
955fe0d4faSjeremylt   Ceed         delegate;
962f86a920SJeremy L Thompson   Ceed         parent;
97d1d35e2fSjeremylt   ObjDelegate *obj_delegates;
98d1d35e2fSjeremylt   int          obj_delegate_count;
9973b5a3bfSZach Atkins   Ceed         op_fallback_ceed;
100ee5a26f2SJeremy L Thompson   char       **jit_source_roots;
101*2027fb9dSSirAlienTheGreat   char       **rust_source_roots;
102*2027fb9dSSirAlienTheGreat   CeedInt      num_rust_source_roots, max_rust_source_roots, num_rust_source_roots_readers;
103aeb3a72dSJeremy L Thompson   CeedInt      num_jit_source_roots, max_jit_source_roots, num_jit_source_roots_readers;
104*2027fb9dSSirAlienTheGreat   bool         cuda_compile_with_clang;
1054753b775SJeremy L Thompson   char       **jit_defines;
106aeb3a72dSJeremy L Thompson   CeedInt      num_jit_defines, max_jit_defines, num_jit_defines_readers;
1072b730f8bSJeremy L Thompson   int (*Error)(Ceed, const char *, int, const char *, int, const char *, va_list *);
1085ae360d4SJeremy L Thompson   int (*SetStream)(Ceed, void *);
109c907536fSjeremylt   int (*GetPreferredMemType)(CeedMemType *);
1106ea7c6c1SJed Brown   int (*Destroy)(Ceed);
1111f9221feSJeremy L Thompson   int (*VectorCreate)(CeedSize, CeedVector);
1120c73c039SSebastian Grimberg   int (*ElemRestrictionCreate)(CeedMemType, CeedCopyMode, const CeedInt *, const bool *, const CeedInt8 *, CeedElemRestriction);
1133ac8f562SJeremy L Thompson   int (*ElemRestrictionCreateAtPoints)(CeedMemType, CeedCopyMode, const CeedInt *, const bool *, const CeedInt8 *, CeedElemRestriction);
1140c73c039SSebastian Grimberg   int (*ElemRestrictionCreateBlocked)(CeedMemType, CeedCopyMode, const CeedInt *, const bool *, const CeedInt8 *, CeedElemRestriction);
1152b730f8bSJeremy L Thompson   int (*BasisCreateTensorH1)(CeedInt, CeedInt, CeedInt, const CeedScalar *, const CeedScalar *, const CeedScalar *, const CeedScalar *, CeedBasis);
1162b730f8bSJeremy L Thompson   int (*BasisCreateH1)(CeedElemTopology, CeedInt, CeedInt, CeedInt, const CeedScalar *, const CeedScalar *, const CeedScalar *, const CeedScalar *,
1172b730f8bSJeremy L Thompson                        CeedBasis);
1182b730f8bSJeremy L Thompson   int (*BasisCreateHdiv)(CeedElemTopology, CeedInt, CeedInt, CeedInt, const CeedScalar *, const CeedScalar *, const CeedScalar *, const CeedScalar *,
1192b730f8bSJeremy L Thompson                          CeedBasis);
120c4e3f59bSSebastian Grimberg   int (*BasisCreateHcurl)(CeedElemTopology, CeedInt, CeedInt, CeedInt, const CeedScalar *, const CeedScalar *, const CeedScalar *, const CeedScalar *,
121c4e3f59bSSebastian Grimberg                           CeedBasis);
122a71faab1SSebastian Grimberg   int (*TensorContractCreate)(CeedTensorContract);
1236ea7c6c1SJed Brown   int (*QFunctionCreate)(CeedQFunction);
124777ff853SJeremy L Thompson   int (*QFunctionContextCreate)(CeedQFunctionContext);
1256ea7c6c1SJed Brown   int (*OperatorCreate)(CeedOperator);
12648acf710SJeremy L Thompson   int (*OperatorCreateAtPoints)(CeedOperator);
12752d6035fSJeremy L Thompson   int (*CompositeOperatorCreate)(CeedOperator);
128d1d35e2fSjeremylt   int             ref_count;
1296ea7c6c1SJed Brown   void           *data;
1303f21f6b1SJeremy L Thompson   bool            is_debug;
1313f21f6b1SJeremy L Thompson   bool            is_deterministic;
132d1d35e2fSjeremylt   char            err_msg[CEED_MAX_RESOURCE_LEN];
133d1d35e2fSjeremylt   FOffset        *f_offsets;
13473501bfeSJeremy L Thompson   CeedWorkVectors work_vectors;
1356ea7c6c1SJed Brown };
1366ea7c6c1SJed Brown 
1376ea7c6c1SJed Brown struct CeedVector_private {
1386ea7c6c1SJed Brown   Ceed ceed;
1399c774eddSJeremy L Thompson   int (*HasValidArray)(CeedVector, bool *);
1409c774eddSJeremy L Thompson   int (*HasBorrowedArrayOfType)(CeedVector, CeedMemType, bool *);
141832a6d73SJeremy L Thompson   int (*CopyStrided)(CeedVector, CeedSize, CeedSize, CeedSize, CeedVector);
1426ea7c6c1SJed Brown   int (*SetArray)(CeedVector, CeedMemType, CeedCopyMode, CeedScalar *);
1432a1ab385Sjeremylt   int (*SetValue)(CeedVector, CeedScalar);
144ff90b007SJeremy L Thompson   int (*SetValueStrided)(CeedVector, CeedSize, CeedSize, CeedSize, CeedScalar);
14554540941SJeremy L Thompson   int (*SyncArray)(CeedVector, CeedMemType);
1466a6c615bSJeremy L Thompson   int (*TakeArray)(CeedVector, CeedMemType, CeedScalar **);
1476ea7c6c1SJed Brown   int (*GetArray)(CeedVector, CeedMemType, CeedScalar **);
1486ea7c6c1SJed Brown   int (*GetArrayRead)(CeedVector, CeedMemType, const CeedScalar **);
1499c774eddSJeremy L Thompson   int (*GetArrayWrite)(CeedVector, CeedMemType, CeedScalar **);
150f05116b9SJeremy L Thompson   int (*RestoreArray)(CeedVector);
151f05116b9SJeremy L Thompson   int (*RestoreArrayRead)(CeedVector);
152547d9b97Sjeremylt   int (*Norm)(CeedVector, CeedNormType, CeedScalar *);
153e0dd3b27Sjeremylt   int (*Scale)(CeedVector, CeedScalar);
1540f7fd0f8Sjeremylt   int (*AXPY)(CeedVector, CeedScalar, CeedVector);
1555fb68f37SKaren (Ren) Stengel   int (*AXPBY)(CeedVector, CeedScalar, CeedScalar, CeedVector);
1560f7fd0f8Sjeremylt   int (*PointwiseMult)(CeedVector, CeedVector, CeedVector);
157d99fa3c5SJeremy L Thompson   int (*Reciprocal)(CeedVector);
1586ea7c6c1SJed Brown   int (*Destroy)(CeedVector);
159d1d35e2fSjeremylt   int      ref_count;
160d2643443SJeremy L Thompson   CeedSize length;
16136ac90ebSjeremylt   uint64_t state;
162d1d35e2fSjeremylt   uint64_t num_readers;
1636ea7c6c1SJed Brown   void    *data;
1646ea7c6c1SJed Brown };
1656ea7c6c1SJed Brown 
1666ea7c6c1SJed Brown struct CeedElemRestriction_private {
1676ea7c6c1SJed Brown   Ceed                ceed;
1687c1dbaffSSebastian Grimberg   CeedElemRestriction rstr_base;
1692b730f8bSJeremy L Thompson   int (*Apply)(CeedElemRestriction, CeedTransposeMode, CeedVector, CeedVector, CeedRequest *);
170f30b1135SSebastian Grimberg   int (*ApplyUnsigned)(CeedElemRestriction, CeedTransposeMode, CeedVector, CeedVector, CeedRequest *);
1717c1dbaffSSebastian Grimberg   int (*ApplyUnoriented)(CeedElemRestriction, CeedTransposeMode, CeedVector, CeedVector, CeedRequest *);
17205fa913cSJeremy L Thompson   int (*ApplyAtPointsInElement)(CeedElemRestriction, CeedInt, CeedTransposeMode, CeedVector, CeedVector, CeedRequest *);
1732b730f8bSJeremy L Thompson   int (*ApplyBlock)(CeedElemRestriction, CeedInt, CeedTransposeMode, CeedVector, CeedVector, CeedRequest *);
17419605835SJeremy L Thompson   int (*GetAtPointsElementOffset)(CeedElemRestriction, CeedInt, CeedSize *);
175bd33150aSjeremylt   int (*GetOffsets)(CeedElemRestriction, CeedMemType, const CeedInt **);
17677d1c127SSebastian Grimberg   int (*GetOrientations)(CeedElemRestriction, CeedMemType, const bool **);
1770c73c039SSebastian Grimberg   int (*GetCurlOrientations)(CeedElemRestriction, CeedMemType, const CeedInt8 **);
1786ea7c6c1SJed Brown   int (*Destroy)(CeedElemRestriction);
179d1d35e2fSjeremylt   int      ref_count;
180d1d35e2fSjeremylt   CeedInt  num_elem;    /* number of elements */
181d1d35e2fSjeremylt   CeedInt  elem_size;   /* number of nodes per element */
1823ac8f562SJeremy L Thompson   CeedInt  num_points;  /* number of points, for points restriction */
183d1d35e2fSjeremylt   CeedInt  num_comp;    /* number of components */
184d1d35e2fSjeremylt   CeedInt  comp_stride; /* Component stride for L-vector ordering */
185ea61e9acSJeremy L Thompson   CeedSize l_size;      /* size of the L-vector, can be used for checking for correct vector sizes */
18605fa913cSJeremy L Thompson   CeedSize e_size;      /* minimum size of the E-vector, can be used for checking for correct vector sizes */
187e7f679fcSJeremy L Thompson   CeedInt  block_size;  /* number of elements in a batch */
188e7f679fcSJeremy L Thompson   CeedInt  num_block;   /* number of blocks of elements */
1897509a596Sjeremylt   CeedInt *strides;     /* strides between [nodes, components, elements] */
19022eb1385SJeremy L Thompson   CeedInt  l_layout[3]; /* L-vector layout [nodes, components, elements] */
19122eb1385SJeremy L Thompson   CeedInt  e_layout[3]; /* E-vector layout [nodes, components, elements] */
192fcbe8c06SSebastian Grimberg   CeedRestrictionType
193fcbe8c06SSebastian Grimberg            rstr_type;   /* initialized in element restriction constructor for default, oriented, curl-oriented, or strided element restriction */
194d1d35e2fSjeremylt   uint64_t num_readers; /* number of instances of offset read only access */
1956ea7c6c1SJed Brown   void    *data;        /* place for the backend to store any data */
1966ea7c6c1SJed Brown };
1976ea7c6c1SJed Brown 
1986ea7c6c1SJed Brown struct CeedBasis_private {
1996ea7c6c1SJed Brown   Ceed ceed;
2002b730f8bSJeremy L Thompson   int (*Apply)(CeedBasis, CeedInt, CeedTransposeMode, CeedEvalMode, CeedVector, CeedVector);
201db2becc9SJeremy L Thompson   int (*ApplyAdd)(CeedBasis, CeedInt, CeedTransposeMode, CeedEvalMode, CeedVector, CeedVector);
202fc0f7cc6SJeremy L Thompson   int (*ApplyAtPoints)(CeedBasis, CeedInt, const CeedInt *, CeedTransposeMode, CeedEvalMode, CeedVector, CeedVector, CeedVector);
203db2becc9SJeremy L Thompson   int (*ApplyAddAtPoints)(CeedBasis, CeedInt, const CeedInt *, CeedTransposeMode, CeedEvalMode, CeedVector, CeedVector, CeedVector);
2046ea7c6c1SJed Brown   int (*Destroy)(CeedBasis);
205d1d35e2fSjeremylt   int                ref_count;
2066402da51SJeremy L Thompson   bool               is_tensor_basis; /* flag for tensor basis */
2070f5de9e9Sjeremylt   CeedInt            dim;             /* topological dimension */
208d99fa3c5SJeremy L Thompson   CeedElemTopology   topo;            /* element topology */
209d1d35e2fSjeremylt   CeedInt            num_comp;        /* number of field components (1 for scalar fields) */
210d1d35e2fSjeremylt   CeedInt            P_1d;            /* number of nodes in one dimension */
211d1d35e2fSjeremylt   CeedInt            Q_1d;            /* number of quadrature points in one dimension */
212a8de75f0Sjeremylt   CeedInt            P;               /* total number of nodes */
213a8de75f0Sjeremylt   CeedInt            Q;               /* total number of quadrature points */
214c4e3f59bSSebastian Grimberg   CeedFESpace        fe_space;        /* initialized in basis constructor with 1, 2, 3 for H^1, H(div), and H(curl) FE space */
2152f86a920SJeremy L Thompson   CeedTensorContract contract;        /* tensor contraction object */
216c4e3f59bSSebastian Grimberg   CeedScalar        *q_ref_1d;        /* array of length Q1d holding the locations of quadrature points on the 1D reference element [-1, 1] */
217c4e3f59bSSebastian Grimberg   CeedScalar        *q_weight_1d;     /* array of length Q1d holding the quadrature weights on the reference element */
218c4e3f59bSSebastian Grimberg   CeedScalar *interp; /* row-major matrix of shape [Q, P] or [dim * Q, P] expressing the values of nodal basis functions or vector basis functions at
219c4e3f59bSSebastian Grimberg                          quadrature points */
220c4e3f59bSSebastian Grimberg   CeedScalar *interp_1d; /* row-major matrix of shape [Q1d, P1d] expressing the values of nodal basis functions at quadrature points */
221c4e3f59bSSebastian Grimberg   CeedScalar *grad;      /* row-major matrix of shape [dim * Q, P] matrix expressing derivatives of nodal basis functions at quadrature points */
222c4e3f59bSSebastian Grimberg   CeedScalar *grad_1d;   /* row-major matrix of shape [Q1d, P1d] matrix expressing derivatives of nodal basis functions at quadrature points */
223c4e3f59bSSebastian Grimberg   CeedScalar *div; /* row-major matrix of shape [Q, P] expressing the divergence of basis functions at quadrature points for H(div) discretizations */
224c4e3f59bSSebastian Grimberg   CeedScalar *curl; /* row-major matrix of shape [curl_dim * Q, P], curl_dim = 1 if dim < 3 else dim, expressing the curl of basis functions at
225c4e3f59bSSebastian Grimberg                        quadrature points for H(curl) discretizations */
226c8c3fa7dSJeremy L Thompson   CeedVector  vec_chebyshev;
227c8c3fa7dSJeremy L Thompson   CeedBasis   basis_chebyshev; /* basis interpolating from nodes to Chebyshev polynomial coefficients */
228c01dd730Scamierjs   void       *data;            /* place for the backend to store any data */
2296ea7c6c1SJed Brown };
2306ea7c6c1SJed Brown 
2312f86a920SJeremy L Thompson struct CeedTensorContract_private {
2322f86a920SJeremy L Thompson   Ceed ceed;
2332b730f8bSJeremy L Thompson   int (*Apply)(CeedTensorContract, CeedInt, CeedInt, CeedInt, CeedInt, const CeedScalar *restrict, CeedTransposeMode, const CeedInt,
2342f86a920SJeremy L Thompson                const CeedScalar *restrict, CeedScalar *restrict);
2352f86a920SJeremy L Thompson   int (*Destroy)(CeedTensorContract);
236d1d35e2fSjeremylt   int   ref_count;
2372f86a920SJeremy L Thompson   void *data;
2382f86a920SJeremy L Thompson };
2392f86a920SJeremy L Thompson 
240d1bcdac9Sjeremylt struct CeedQFunctionField_private {
241d1d35e2fSjeremylt   const char  *field_name;
2424d537eeaSYohann   CeedInt      size;
243d1d35e2fSjeremylt   CeedEvalMode eval_mode;
244ff8ca64bSJed Brown };
245ff8ca64bSJed Brown 
2466ea7c6c1SJed Brown struct CeedQFunction_private {
2476ea7c6c1SJed Brown   Ceed ceed;
2482f86a920SJeremy L Thompson   int (*Apply)(CeedQFunction, CeedInt, CeedVector *, CeedVector *);
2498c84ac63Sjeremylt   int (*SetCUDAUserFunction)(CeedQFunction, void *);
2508c84ac63Sjeremylt   int (*SetHIPUserFunction)(CeedQFunction, void *);
2516ea7c6c1SJed Brown   int (*Destroy)(CeedQFunction);
252d1d35e2fSjeremylt   int                  ref_count;
253ea61e9acSJeremy L Thompson   CeedInt              vec_length; /* Number of quadrature points must be padded to a multiple of vec_length */
254d1d35e2fSjeremylt   CeedQFunctionField  *input_fields;
255d1d35e2fSjeremylt   CeedQFunctionField  *output_fields;
256d1d35e2fSjeremylt   CeedInt              num_input_fields, num_output_fields;
2579f0427d9SYohann   CeedQFunctionUser    function;
2586e15d496SJeremy L Thompson   CeedInt              user_flop_estimate;
259ca5eadf8SJeremy L Thompson   const char          *user_source;
260d1d35e2fSjeremylt   const char          *source_path;
26143e1b16fSJeremy L Thompson   const char          *kernel_name;
26243e1b16fSJeremy L Thompson   const char          *gallery_name;
26343e1b16fSJeremy L Thompson   bool                 is_gallery;
264f04ea552SJeremy L Thompson   bool                 is_identity;
265f04ea552SJeremy L Thompson   bool                 is_fortran;
266f04ea552SJeremy L Thompson   bool                 is_immutable;
267441428dfSJeremy L Thompson   bool                 is_context_writable;
268777ff853SJeremy L Thompson   CeedQFunctionContext ctx;  /* user context for function */
269a8d32208Sjeremylt   void                *data; /* place for the backend to store any data */
2706ea7c6c1SJed Brown };
2716ea7c6c1SJed Brown 
272777ff853SJeremy L Thompson struct CeedQFunctionContext_private {
273777ff853SJeremy L Thompson   Ceed ceed;
274d1d35e2fSjeremylt   int  ref_count;
2759c774eddSJeremy L Thompson   int (*HasValidData)(CeedQFunctionContext, bool *);
2769c774eddSJeremy L Thompson   int (*HasBorrowedDataOfType)(CeedQFunctionContext, CeedMemType, bool *);
277777ff853SJeremy L Thompson   int (*SetData)(CeedQFunctionContext, CeedMemType, CeedCopyMode, void *);
278891038deSjeremylt   int (*TakeData)(CeedQFunctionContext, CeedMemType, void *);
279777ff853SJeremy L Thompson   int (*GetData)(CeedQFunctionContext, CeedMemType, void *);
28028bfd0b7SJeremy L Thompson   int (*GetDataRead)(CeedQFunctionContext, CeedMemType, void *);
281777ff853SJeremy L Thompson   int (*RestoreData)(CeedQFunctionContext);
28228bfd0b7SJeremy L Thompson   int (*RestoreDataRead)(CeedQFunctionContext);
2832e64a2b9SJeremy L Thompson   int (*DataDestroy)(CeedQFunctionContext);
284777ff853SJeremy L Thompson   int (*Destroy)(CeedQFunctionContext);
2852790b72bSJeremy L Thompson   CeedQFunctionContextDataDestroyUser data_destroy_function;
2862790b72bSJeremy L Thompson   CeedMemType                         data_destroy_mem_type;
287cdf32b93SJeremy L Thompson   CeedInt                             num_fields;
288cdf32b93SJeremy L Thompson   CeedInt                             max_fields;
2893668ca4bSJeremy L Thompson   CeedContextFieldLabel              *field_labels;
290777ff853SJeremy L Thompson   uint64_t                            state;
29128bfd0b7SJeremy L Thompson   uint64_t                            num_readers;
292d1d35e2fSjeremylt   size_t                              ctx_size;
293777ff853SJeremy L Thompson   void                               *data;
294777ff853SJeremy L Thompson };
295777ff853SJeremy L Thompson 
2961e35832bSjeremylt /// Struct to handle the context data to use the Fortran QFunction stub
2971e35832bSjeremylt /// @ingroup CeedQFunction
298777ff853SJeremy L Thompson struct CeedFortranContext_private {
2998cb0412aSJeremy L Thompson   CeedQFunctionContext inner_ctx;
3002b730f8bSJeremy L Thompson   void (*f)(void *ctx, int *nq, const CeedScalar *u, const CeedScalar *u1, const CeedScalar *u2, const CeedScalar *u3, const CeedScalar *u4,
3012b730f8bSJeremy L Thompson             const CeedScalar *u5, const CeedScalar *u6, const CeedScalar *u7, const CeedScalar *u8, const CeedScalar *u9, const CeedScalar *u10,
3022b730f8bSJeremy L Thompson             const CeedScalar *u11, const CeedScalar *u12, const CeedScalar *u13, const CeedScalar *u14, const CeedScalar *u15, CeedScalar *v,
3032b730f8bSJeremy L Thompson             CeedScalar *v1, CeedScalar *v2, CeedScalar *v3, CeedScalar *v4, CeedScalar *v5, CeedScalar *v6, CeedScalar *v7, CeedScalar *v8,
3042b730f8bSJeremy L Thompson             CeedScalar *v9, CeedScalar *v10, CeedScalar *v11, CeedScalar *v12, CeedScalar *v13, CeedScalar *v14, CeedScalar *v15, int *err);
305777ff853SJeremy L Thompson };
306777ff853SJeremy L Thompson typedef struct CeedFortranContext_private *CeedFortranContext;
307069aeabaSjeremylt 
3083668ca4bSJeremy L Thompson struct CeedContextFieldLabel_private {
3093668ca4bSJeremy L Thompson   const char            *name;
3103668ca4bSJeremy L Thompson   const char            *description;
3113668ca4bSJeremy L Thompson   CeedContextFieldType   type;
3123668ca4bSJeremy L Thompson   size_t                 size;
3137bfe0f0eSJeremy L Thompson   size_t                 num_values;
3143668ca4bSJeremy L Thompson   size_t                 offset;
3153668ca4bSJeremy L Thompson   CeedInt                num_sub_labels;
3163668ca4bSJeremy L Thompson   CeedContextFieldLabel *sub_labels;
3175ac9af79SJeremy L Thompson   bool                   from_op;
3183668ca4bSJeremy L Thompson };
3193668ca4bSJeremy L Thompson 
320d1bcdac9Sjeremylt struct CeedOperatorField_private {
321437c7c90SJeremy L Thompson   CeedElemRestriction elem_rstr;  /* Restriction from L-vector */
322356036faSJeremy L Thompson   CeedBasis           basis;      /* Basis or CEED_BASIS_NONE for collocated fields */
323ea61e9acSJeremy L Thompson   CeedVector          vec;        /* State vector for passive fields or CEED_VECTOR_NONE for no vector */
324d1d35e2fSjeremylt   const char         *field_name; /* matching QFunction field name */
325ff8ca64bSJed Brown };
326ff8ca64bSJed Brown 
327480fae85SJeremy L Thompson struct CeedQFunctionAssemblyData_private {
328480fae85SJeremy L Thompson   Ceed                ceed;
329480fae85SJeremy L Thompson   int                 ref_count;
330480fae85SJeremy L Thompson   bool                is_setup;
331beecbf24SJeremy L Thompson   bool                reuse_data;
332beecbf24SJeremy L Thompson   bool                needs_data_update;
333480fae85SJeremy L Thompson   CeedVector          vec;
334480fae85SJeremy L Thompson   CeedElemRestriction rstr;
335480fae85SJeremy L Thompson };
336480fae85SJeremy L Thompson 
337ed9e99e6SJeremy L Thompson struct CeedOperatorAssemblyData_private {
338ed9e99e6SJeremy L Thompson   Ceed                 ceed;
339506b1a0cSSebastian Grimberg   CeedInt              num_active_bases_in, num_active_bases_out;
340506b1a0cSSebastian Grimberg   CeedBasis           *active_bases_in, *active_bases_out;
341506b1a0cSSebastian Grimberg   CeedElemRestriction *active_elem_rstrs_in, *active_elem_rstrs_out;
342437c7c90SJeremy L Thompson   CeedInt             *num_eval_modes_in, *num_eval_modes_out;
343437c7c90SJeremy L Thompson   CeedEvalMode       **eval_modes_in, **eval_modes_out;
344437c7c90SJeremy L Thompson   CeedScalar         **assembled_bases_in, **assembled_bases_out;
345437c7c90SJeremy L Thompson   CeedSize           **eval_mode_offsets_in, **eval_mode_offsets_out, num_output_components;
346ed9e99e6SJeremy L Thompson };
347ed9e99e6SJeremy L Thompson 
3486ea7c6c1SJed Brown struct CeedOperator_private {
3496ea7c6c1SJed Brown   Ceed         ceed;
350b05f7e9fSJeremy L Thompson   CeedOperator op_fallback, op_fallback_parent;
351d1d35e2fSjeremylt   int          ref_count;
3522b730f8bSJeremy L Thompson   int (*LinearAssembleQFunction)(CeedOperator, CeedVector *, CeedElemRestriction *, CeedRequest *);
3532b730f8bSJeremy L Thompson   int (*LinearAssembleQFunctionUpdate)(CeedOperator, CeedVector, CeedElemRestriction, CeedRequest *);
3542bba3ffaSJeremy L Thompson   int (*LinearAssembleDiagonal)(CeedOperator, CeedVector, CeedRequest *);
3559e9210b8SJeremy L Thompson   int (*LinearAssembleAddDiagonal)(CeedOperator, CeedVector, CeedRequest *);
3562b730f8bSJeremy L Thompson   int (*LinearAssemblePointBlockDiagonal)(CeedOperator, CeedVector, CeedRequest *);
3572b730f8bSJeremy L Thompson   int (*LinearAssembleAddPointBlockDiagonal)(CeedOperator, CeedVector, CeedRequest *);
3582b730f8bSJeremy L Thompson   int (*LinearAssembleSymbolic)(CeedOperator, CeedSize *, CeedInt **, CeedInt **);
359e2f04181SAndrew T. Barker   int (*LinearAssemble)(CeedOperator, CeedVector);
360cefa2673SJeremy L Thompson   int (*LinearAssembleSingle)(CeedOperator, CeedInt, CeedVector);
361713f43c3Sjeremylt   int (*CreateFDMElementInverse)(CeedOperator, CeedOperator *, CeedRequest *);
362ff8ca64bSJed Brown   int (*Apply)(CeedOperator, CeedVector, CeedVector, CeedRequest *);
363250756a7Sjeremylt   int (*ApplyComposite)(CeedOperator, CeedVector, CeedVector, CeedRequest *);
364cae8b89aSjeremylt   int (*ApplyAdd)(CeedOperator, CeedVector, CeedVector, CeedRequest *);
365250756a7Sjeremylt   int (*ApplyAddComposite)(CeedOperator, CeedVector, CeedVector, CeedRequest *);
3662b730f8bSJeremy L Thompson   int (*ApplyJacobian)(CeedOperator, CeedVector, CeedVector, CeedVector, CeedVector, CeedRequest *);
3676ea7c6c1SJed Brown   int (*Destroy)(CeedOperator);
368d1d35e2fSjeremylt   CeedOperatorField        *input_fields;
369d1d35e2fSjeremylt   CeedOperatorField        *output_fields;
3702b104005SJeremy L Thompson   CeedSize                  input_size, output_size;
371d1d35e2fSjeremylt   CeedInt                   num_elem;   /* Number of elements */
372d1d35e2fSjeremylt   CeedInt                   num_qpts;   /* Number of quadrature points over all elements */
373d1d35e2fSjeremylt   CeedInt                   num_fields; /* Number of fields that have been set */
3746ea7c6c1SJed Brown   CeedQFunction             qf;
3756ea7c6c1SJed Brown   CeedQFunction             dqf;
3766ea7c6c1SJed Brown   CeedQFunction             dqfT;
377ea6b5821SJeremy L Thompson   const char               *name;
378f04ea552SJeremy L Thompson   bool                      is_immutable;
379f04ea552SJeremy L Thompson   bool                      is_interface_setup;
380f04ea552SJeremy L Thompson   bool                      is_backend_setup;
381f04ea552SJeremy L Thompson   bool                      is_composite;
38248acf710SJeremy L Thompson   bool                      is_at_points;
383d1d35e2fSjeremylt   bool                      has_restriction;
384480fae85SJeremy L Thompson   CeedQFunctionAssemblyData qf_assembled;
385ed9e99e6SJeremy L Thompson   CeedOperatorAssemblyData  op_assembled;
386d1d35e2fSjeremylt   CeedOperator             *sub_operators;
387d1d35e2fSjeremylt   CeedInt                   num_suboperators;
3886ea7c6c1SJed Brown   void                     *data;
3893668ca4bSJeremy L Thompson   CeedInt                   num_context_labels;
3903668ca4bSJeremy L Thompson   CeedInt                   max_context_labels;
3913668ca4bSJeremy L Thompson   CeedContextFieldLabel    *context_labels;
39248acf710SJeremy L Thompson   CeedElemRestriction       rstr_points, first_points_rstr;
39348acf710SJeremy L Thompson   CeedVector                point_coords;
3946ea7c6c1SJed Brown };
395