xref: /libCEED/rust/libceed-sys/c-src/interface/ceed-operator.c (revision 75f0d5a43978d294e569c8e99a70cefd4b888bc4)
13d8e8822SJeremy L Thompson // Copyright (c) 2017-2022, 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.
3d7b241e6Sjeremylt //
43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
5d7b241e6Sjeremylt //
63d8e8822SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
7d7b241e6Sjeremylt 
83d576824SJeremy L Thompson #include <ceed-impl.h>
92b730f8bSJeremy L Thompson #include <ceed/backend.h>
102b730f8bSJeremy L Thompson #include <ceed/ceed.h>
113d576824SJeremy L Thompson #include <stdbool.h>
123d576824SJeremy L Thompson #include <stdio.h>
133d576824SJeremy L Thompson #include <string.h>
14d7b241e6Sjeremylt 
15dfdf5a53Sjeremylt /// @file
167a982d89SJeremy L. Thompson /// Implementation of CeedOperator interfaces
177a982d89SJeremy L. Thompson 
187a982d89SJeremy L. Thompson /// ----------------------------------------------------------------------------
197a982d89SJeremy L. Thompson /// CeedOperator Library Internal Functions
207a982d89SJeremy L. Thompson /// ----------------------------------------------------------------------------
217a982d89SJeremy L. Thompson /// @addtogroup CeedOperatorDeveloper
227a982d89SJeremy L. Thompson /// @{
237a982d89SJeremy L. Thompson 
247a982d89SJeremy L. Thompson /**
25e15f9bd0SJeremy L Thompson   @brief Check if a CeedOperator Field matches the QFunction Field
26e15f9bd0SJeremy L Thompson 
27e15f9bd0SJeremy L Thompson   @param[in] ceed     Ceed object for error handling
28d1d35e2fSjeremylt   @param[in] qf_field QFunction Field matching Operator Field
29e15f9bd0SJeremy L Thompson   @param[in] r        Operator Field ElemRestriction
30e15f9bd0SJeremy L Thompson   @param[in] b        Operator Field Basis
31e15f9bd0SJeremy L Thompson 
32e15f9bd0SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
33e15f9bd0SJeremy L Thompson 
34e15f9bd0SJeremy L Thompson   @ref Developer
35e15f9bd0SJeremy L Thompson **/
362b730f8bSJeremy L Thompson static int CeedOperatorCheckField(Ceed ceed, CeedQFunctionField qf_field, CeedElemRestriction r, CeedBasis b) {
37d1d35e2fSjeremylt   CeedEvalMode eval_mode = qf_field->eval_mode;
382b730f8bSJeremy L Thompson   CeedInt      dim = 1, num_comp = 1, Q_comp = 1, restr_num_comp = 1, size = qf_field->size;
392b730f8bSJeremy L Thompson 
40e15f9bd0SJeremy L Thompson   // Restriction
41e15f9bd0SJeremy L Thompson   if (r != CEED_ELEMRESTRICTION_NONE) {
42d1d35e2fSjeremylt     if (eval_mode == CEED_EVAL_WEIGHT) {
43e15f9bd0SJeremy L Thompson       // LCOV_EXCL_START
442b730f8bSJeremy L Thompson       return CeedError(ceed, CEED_ERROR_INCOMPATIBLE, "CEED_ELEMRESTRICTION_NONE should be used for a field with eval mode CEED_EVAL_WEIGHT");
45e15f9bd0SJeremy L Thompson       // LCOV_EXCL_STOP
46e15f9bd0SJeremy L Thompson     }
472b730f8bSJeremy L Thompson     CeedCall(CeedElemRestrictionGetNumComponents(r, &restr_num_comp));
48e1e9e29dSJed Brown   }
49d1d35e2fSjeremylt   if ((r == CEED_ELEMRESTRICTION_NONE) != (eval_mode == CEED_EVAL_WEIGHT)) {
50e1e9e29dSJed Brown     // LCOV_EXCL_START
512b730f8bSJeremy L Thompson     return CeedError(ceed, CEED_ERROR_INCOMPATIBLE, "CEED_ELEMRESTRICTION_NONE and CEED_EVAL_WEIGHT must be used together.");
52e1e9e29dSJed Brown     // LCOV_EXCL_STOP
53e1e9e29dSJed Brown   }
54e15f9bd0SJeremy L Thompson   // Basis
55e15f9bd0SJeremy L Thompson   if (b != CEED_BASIS_COLLOCATED) {
562b730f8bSJeremy L Thompson     if (eval_mode == CEED_EVAL_NONE) {
578229195eSjeremylt       // LCOV_EXCL_START
582b730f8bSJeremy L Thompson       return CeedError(ceed, CEED_ERROR_INCOMPATIBLE, "Field '%s' configured with CEED_EVAL_NONE must be used with CEED_BASIS_COLLOCATED",
59d1d35e2fSjeremylt                        qf_field->field_name);
6041bdf1c9SJeremy L Thompson       // LCOV_EXCL_STOP
612b730f8bSJeremy L Thompson     }
622b730f8bSJeremy L Thompson     CeedCall(CeedBasisGetDimension(b, &dim));
632b730f8bSJeremy L Thompson     CeedCall(CeedBasisGetNumComponents(b, &num_comp));
642b730f8bSJeremy L Thompson     CeedCall(CeedBasisGetNumQuadratureComponents(b, &Q_comp));
65d1d35e2fSjeremylt     if (r != CEED_ELEMRESTRICTION_NONE && restr_num_comp != num_comp) {
66e15f9bd0SJeremy L Thompson       // LCOV_EXCL_START
67e15f9bd0SJeremy L Thompson       return CeedError(ceed, CEED_ERROR_DIMENSION,
682b730f8bSJeremy L Thompson                        "Field '%s' of size %" CeedInt_FMT " and EvalMode %s: ElemRestriction has %" CeedInt_FMT
692b730f8bSJeremy L Thompson                        " components, but Basis has %" CeedInt_FMT " components",
702b730f8bSJeremy L Thompson                        qf_field->field_name, qf_field->size, CeedEvalModes[qf_field->eval_mode], restr_num_comp, num_comp);
71e15f9bd0SJeremy L Thompson       // LCOV_EXCL_STOP
72e15f9bd0SJeremy L Thompson     }
7341bdf1c9SJeremy L Thompson   } else if (eval_mode != CEED_EVAL_NONE) {
7441bdf1c9SJeremy L Thompson     // LCOV_EXCL_START
752b730f8bSJeremy L Thompson     return CeedError(ceed, CEED_ERROR_INCOMPATIBLE, "Field '%s' configured with %s cannot be used with CEED_BASIS_COLLOCATED", qf_field->field_name,
762b730f8bSJeremy L Thompson                      CeedEvalModes[eval_mode]);
7741bdf1c9SJeremy L Thompson     // LCOV_EXCL_STOP
78e15f9bd0SJeremy L Thompson   }
79e15f9bd0SJeremy L Thompson   // Field size
80d1d35e2fSjeremylt   switch (eval_mode) {
81e15f9bd0SJeremy L Thompson     case CEED_EVAL_NONE:
822b730f8bSJeremy L Thompson       if (size != restr_num_comp) {
83e15f9bd0SJeremy L Thompson         // LCOV_EXCL_START
84e15f9bd0SJeremy L Thompson         return CeedError(ceed, CEED_ERROR_DIMENSION,
852b730f8bSJeremy L Thompson                          "Field '%s' of size %" CeedInt_FMT " and EvalMode %s: ElemRestriction has " CeedInt_FMT " components", qf_field->field_name,
862b730f8bSJeremy L Thompson                          qf_field->size, CeedEvalModes[qf_field->eval_mode], restr_num_comp);
87e15f9bd0SJeremy L Thompson         // LCOV_EXCL_STOP
882b730f8bSJeremy L Thompson       }
89e15f9bd0SJeremy L Thompson       break;
90e15f9bd0SJeremy L Thompson     case CEED_EVAL_INTERP:
912b730f8bSJeremy L Thompson       if (size != num_comp * Q_comp) {
92e15f9bd0SJeremy L Thompson         // LCOV_EXCL_START
93e15f9bd0SJeremy L Thompson         return CeedError(ceed, CEED_ERROR_DIMENSION,
942b730f8bSJeremy L Thompson                          "Field '%s' of size %" CeedInt_FMT " and EvalMode %s: ElemRestriction/Basis has " CeedInt_FMT " components",
952b730f8bSJeremy L Thompson                          qf_field->field_name, qf_field->size, CeedEvalModes[qf_field->eval_mode], num_comp * Q_comp);
96e15f9bd0SJeremy L Thompson         // LCOV_EXCL_STOP
972b730f8bSJeremy L Thompson       }
98e15f9bd0SJeremy L Thompson       break;
99e15f9bd0SJeremy L Thompson     case CEED_EVAL_GRAD:
1002b730f8bSJeremy L Thompson       if (size != num_comp * dim) {
101e15f9bd0SJeremy L Thompson         // LCOV_EXCL_START
102e15f9bd0SJeremy L Thompson         return CeedError(ceed, CEED_ERROR_DIMENSION,
1032b730f8bSJeremy L Thompson                          "Field '%s' of size %" CeedInt_FMT " and EvalMode %s in %" CeedInt_FMT " dimensions: ElemRestriction/Basis has %" CeedInt_FMT
1042b730f8bSJeremy L Thompson                          " components",
1052b730f8bSJeremy L Thompson                          qf_field->field_name, qf_field->size, CeedEvalModes[qf_field->eval_mode], dim, num_comp);
106e15f9bd0SJeremy L Thompson         // LCOV_EXCL_STOP
1072b730f8bSJeremy L Thompson       }
108e15f9bd0SJeremy L Thompson       break;
109e15f9bd0SJeremy L Thompson     case CEED_EVAL_WEIGHT:
110d1d35e2fSjeremylt       // No additional checks required
111e15f9bd0SJeremy L Thompson       break;
112e15f9bd0SJeremy L Thompson     case CEED_EVAL_DIV:
1132b730f8bSJeremy L Thompson       if (size != num_comp) {
114a0c16c2cSrezgarshakeri         // LCOV_EXCL_START
115a0c16c2cSrezgarshakeri         return CeedError(ceed, CEED_ERROR_DIMENSION,
1162b730f8bSJeremy L Thompson                          "Field '%s' of size %" CeedInt_FMT " and EvalMode %s: ElemRestriction/Basis has " CeedInt_FMT " components",
1172b730f8bSJeremy L Thompson                          qf_field->field_name, qf_field->size, CeedEvalModes[qf_field->eval_mode], num_comp);
118a0c16c2cSrezgarshakeri         // LCOV_EXCL_STOP
1192b730f8bSJeremy L Thompson       }
120e15f9bd0SJeremy L Thompson       break;
121e15f9bd0SJeremy L Thompson     case CEED_EVAL_CURL:
122e15f9bd0SJeremy L Thompson       // Not implemented
123e15f9bd0SJeremy L Thompson       break;
124e15f9bd0SJeremy L Thompson   }
125e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
1267a982d89SJeremy L. Thompson }
1277a982d89SJeremy L. Thompson 
1287a982d89SJeremy L. Thompson /**
1297a982d89SJeremy L. Thompson   @brief View a field of a CeedOperator
1307a982d89SJeremy L. Thompson 
1317a982d89SJeremy L. Thompson   @param[in] field        Operator field to view
132d1d35e2fSjeremylt   @param[in] qf_field     QFunction field (carries field name)
133d1d35e2fSjeremylt   @param[in] field_number Number of field being viewed
1344c4400c7SValeria Barra   @param[in] sub          true indicates sub-operator, which increases indentation; false for top-level operator
135d1d35e2fSjeremylt   @param[in] input        true for an input field; false for output field
1367a982d89SJeremy L. Thompson   @param[in] stream       Stream to view to, e.g., stdout
1377a982d89SJeremy L. Thompson 
1387a982d89SJeremy L. Thompson   @return An error code: 0 - success, otherwise - failure
1397a982d89SJeremy L. Thompson 
1407a982d89SJeremy L. Thompson   @ref Utility
1417a982d89SJeremy L. Thompson **/
1422b730f8bSJeremy L Thompson static int CeedOperatorFieldView(CeedOperatorField field, CeedQFunctionField qf_field, CeedInt field_number, bool sub, bool input, FILE *stream) {
1437a982d89SJeremy L. Thompson   const char *pre    = sub ? "  " : "";
144d1d35e2fSjeremylt   const char *in_out = input ? "Input" : "Output";
1457a982d89SJeremy L. Thompson 
1462b730f8bSJeremy L Thompson   fprintf(stream,
1472b730f8bSJeremy L Thompson           "%s    %s field %" CeedInt_FMT
1482b730f8bSJeremy L Thompson           ":\n"
1497a982d89SJeremy L. Thompson           "%s      Name: \"%s\"\n",
150d1d35e2fSjeremylt           pre, in_out, field_number, pre, qf_field->field_name);
1517a982d89SJeremy L. Thompson 
152990fdeb6SJeremy L Thompson   fprintf(stream, "%s      Size: %" CeedInt_FMT "\n", pre, qf_field->size);
153f5ebfb90SJeremy L Thompson 
1542b730f8bSJeremy L Thompson   fprintf(stream, "%s      EvalMode: %s\n", pre, CeedEvalModes[qf_field->eval_mode]);
155f5ebfb90SJeremy L Thompson 
1562b730f8bSJeremy L Thompson   if (field->basis == CEED_BASIS_COLLOCATED) fprintf(stream, "%s      Collocated basis\n", pre);
1577a982d89SJeremy L. Thompson 
1582b730f8bSJeremy L Thompson   if (field->vec == CEED_VECTOR_ACTIVE) fprintf(stream, "%s      Active vector\n", pre);
1592b730f8bSJeremy L Thompson   else if (field->vec == CEED_VECTOR_NONE) fprintf(stream, "%s      No vector\n", pre);
160f5ebfb90SJeremy L Thompson 
161e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
1627a982d89SJeremy L. Thompson }
1637a982d89SJeremy L. Thompson 
1647a982d89SJeremy L. Thompson /**
1657a982d89SJeremy L. Thompson   @brief View a single CeedOperator
1667a982d89SJeremy L. Thompson 
1677a982d89SJeremy L. Thompson   @param[in] op     CeedOperator to view
1687a982d89SJeremy L. Thompson   @param[in] sub    Boolean flag for sub-operator
1697a982d89SJeremy L. Thompson   @param[in] stream Stream to write; typically stdout/stderr or a file
1707a982d89SJeremy L. Thompson 
1717a982d89SJeremy L. Thompson   @return Error code: 0 - success, otherwise - failure
1727a982d89SJeremy L. Thompson 
1737a982d89SJeremy L. Thompson   @ref Utility
1747a982d89SJeremy L. Thompson **/
1757a982d89SJeremy L. Thompson int CeedOperatorSingleView(CeedOperator op, bool sub, FILE *stream) {
1767a982d89SJeremy L. Thompson   const char *pre = sub ? "  " : "";
1777a982d89SJeremy L. Thompson 
178381e6593SJeremy L Thompson   CeedInt num_elem, num_qpts;
1792b730f8bSJeremy L Thompson   CeedCall(CeedOperatorGetNumElements(op, &num_elem));
1802b730f8bSJeremy L Thompson   CeedCall(CeedOperatorGetNumQuadraturePoints(op, &num_qpts));
181381e6593SJeremy L Thompson 
18278464608Sjeremylt   CeedInt total_fields = 0;
1832b730f8bSJeremy L Thompson   CeedCall(CeedOperatorGetNumArgs(op, &total_fields));
1842b730f8bSJeremy L Thompson   fprintf(stream, "%s  %" CeedInt_FMT " elements with %" CeedInt_FMT " quadrature points each\n", pre, num_elem, num_qpts);
1857a982d89SJeremy L. Thompson 
1862b730f8bSJeremy L Thompson   fprintf(stream, "%s  %" CeedInt_FMT " field%s\n", pre, total_fields, total_fields > 1 ? "s" : "");
1877a982d89SJeremy L. Thompson 
1882b730f8bSJeremy L Thompson   fprintf(stream, "%s  %" CeedInt_FMT " input field%s:\n", pre, op->qf->num_input_fields, op->qf->num_input_fields > 1 ? "s" : "");
189d1d35e2fSjeremylt   for (CeedInt i = 0; i < op->qf->num_input_fields; i++) {
1902b730f8bSJeremy L Thompson     CeedCall(CeedOperatorFieldView(op->input_fields[i], op->qf->input_fields[i], i, sub, 1, stream));
1917a982d89SJeremy L. Thompson   }
1927a982d89SJeremy L. Thompson 
1932b730f8bSJeremy L Thompson   fprintf(stream, "%s  %" CeedInt_FMT " output field%s:\n", pre, op->qf->num_output_fields, op->qf->num_output_fields > 1 ? "s" : "");
194d1d35e2fSjeremylt   for (CeedInt i = 0; i < op->qf->num_output_fields; i++) {
1952b730f8bSJeremy L Thompson     CeedCall(CeedOperatorFieldView(op->output_fields[i], op->qf->output_fields[i], i, sub, 0, stream));
1967a982d89SJeremy L. Thompson   }
197e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
1987a982d89SJeremy L. Thompson }
1997a982d89SJeremy L. Thompson 
200d99fa3c5SJeremy L Thompson /**
2010f60e0a8SJeremy L Thompson   @brief Find the active vector basis for a non-composite CeedOperator
202eaf62fffSJeremy L Thompson 
203eaf62fffSJeremy L Thompson   @param[in] op            CeedOperator to find active basis for
2040f60e0a8SJeremy L Thompson   @param[out] active_basis Basis for active input vector or NULL for composite operator
205eaf62fffSJeremy L Thompson 
206eaf62fffSJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
207eaf62fffSJeremy L Thompson 
208eaf62fffSJeremy L Thompson   @ ref Developer
209eaf62fffSJeremy L Thompson **/
210eaf62fffSJeremy L Thompson int CeedOperatorGetActiveBasis(CeedOperator op, CeedBasis *active_basis) {
211eaf62fffSJeremy L Thompson   *active_basis = NULL;
2120f60e0a8SJeremy L Thompson   if (op->is_composite) return CEED_ERROR_SUCCESS;
2132b730f8bSJeremy L Thompson   for (CeedInt i = 0; i < op->qf->num_input_fields; i++) {
214eaf62fffSJeremy L Thompson     if (op->input_fields[i]->vec == CEED_VECTOR_ACTIVE) {
215eaf62fffSJeremy L Thompson       *active_basis = op->input_fields[i]->basis;
216eaf62fffSJeremy L Thompson       break;
217eaf62fffSJeremy L Thompson     }
2182b730f8bSJeremy L Thompson   }
219eaf62fffSJeremy L Thompson 
220eaf62fffSJeremy L Thompson   if (!*active_basis) {
221eaf62fffSJeremy L Thompson     // LCOV_EXCL_START
222eaf62fffSJeremy L Thompson     Ceed ceed;
2232b730f8bSJeremy L Thompson 
2242b730f8bSJeremy L Thompson     CeedCall(CeedOperatorGetCeed(op, &ceed));
2252b730f8bSJeremy L Thompson     return CeedError(ceed, CEED_ERROR_MINOR, "No active CeedBasis found");
226eaf62fffSJeremy L Thompson     // LCOV_EXCL_STOP
227eaf62fffSJeremy L Thompson   }
228eaf62fffSJeremy L Thompson   return CEED_ERROR_SUCCESS;
229eaf62fffSJeremy L Thompson }
230eaf62fffSJeremy L Thompson 
231eaf62fffSJeremy L Thompson /**
2320f60e0a8SJeremy L Thompson   @brief Find the active vector ElemRestriction for a non-composite CeedOperator
233e2f04181SAndrew T. Barker 
234e2f04181SAndrew T. Barker   @param[in] op           CeedOperator to find active basis for
2350f60e0a8SJeremy L Thompson   @param[out] active_rstr ElemRestriction for active input vector or NULL for composite operator
236e2f04181SAndrew T. Barker 
237e2f04181SAndrew T. Barker   @return An error code: 0 - success, otherwise - failure
238e2f04181SAndrew T. Barker 
239e2f04181SAndrew T. Barker   @ref Utility
240e2f04181SAndrew T. Barker **/
2412b730f8bSJeremy L Thompson int CeedOperatorGetActiveElemRestriction(CeedOperator op, CeedElemRestriction *active_rstr) {
242d1d35e2fSjeremylt   *active_rstr = NULL;
2430f60e0a8SJeremy L Thompson   if (op->is_composite) return CEED_ERROR_SUCCESS;
2442b730f8bSJeremy L Thompson   for (CeedInt i = 0; i < op->qf->num_input_fields; i++) {
245d1d35e2fSjeremylt     if (op->input_fields[i]->vec == CEED_VECTOR_ACTIVE) {
246d1d35e2fSjeremylt       *active_rstr = op->input_fields[i]->elem_restr;
247e2f04181SAndrew T. Barker       break;
248e2f04181SAndrew T. Barker     }
2492b730f8bSJeremy L Thompson   }
250e2f04181SAndrew T. Barker 
251d1d35e2fSjeremylt   if (!*active_rstr) {
252e2f04181SAndrew T. Barker     // LCOV_EXCL_START
253e2f04181SAndrew T. Barker     Ceed ceed;
2542b730f8bSJeremy L Thompson 
2552b730f8bSJeremy L Thompson     CeedCall(CeedOperatorGetCeed(op, &ceed));
2562b730f8bSJeremy L Thompson     return CeedError(ceed, CEED_ERROR_INCOMPLETE, "No active CeedElemRestriction found");
257e2f04181SAndrew T. Barker     // LCOV_EXCL_STOP
258e2f04181SAndrew T. Barker   }
259e2f04181SAndrew T. Barker   return CEED_ERROR_SUCCESS;
260e2f04181SAndrew T. Barker }
261e2f04181SAndrew T. Barker 
262d8dd9a91SJeremy L Thompson /**
263d8dd9a91SJeremy L Thompson   @brief Set QFunctionContext field value of the specified type.
264ea61e9acSJeremy L Thompson            For composite operators, the value is set in all sub-operator QFunctionContexts that have a matching `field_name`.
265ea61e9acSJeremy L Thompson            A non-zero error code is returned for single operators that do not have a matching field of the same type or composite operators that do
266ea61e9acSJeremy L Thompson not have any field of a matching type.
267d8dd9a91SJeremy L Thompson 
268ea61e9acSJeremy L Thompson   @param[in,out] op          CeedOperator
269ea61e9acSJeremy L Thompson   @param[in]     field_label Label of field to set
270ea61e9acSJeremy L Thompson   @param[in]     field_type  Type of field to set
271ea61e9acSJeremy L Thompson   @param[in]     value       Value to set
272d8dd9a91SJeremy L Thompson 
273d8dd9a91SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
274d8dd9a91SJeremy L Thompson 
275d8dd9a91SJeremy L Thompson   @ref User
276d8dd9a91SJeremy L Thompson **/
2772b730f8bSJeremy L Thompson static int CeedOperatorContextSetGeneric(CeedOperator op, CeedContextFieldLabel field_label, CeedContextFieldType field_type, void *value) {
2782b730f8bSJeremy L Thompson   if (!field_label) {
2793668ca4bSJeremy L Thompson     // LCOV_EXCL_START
2802b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label");
2813668ca4bSJeremy L Thompson     // LCOV_EXCL_STOP
2822b730f8bSJeremy L Thompson   }
2833668ca4bSJeremy L Thompson 
2843668ca4bSJeremy L Thompson   bool is_composite = false;
2852b730f8bSJeremy L Thompson   CeedCall(CeedOperatorIsComposite(op, &is_composite));
286d8dd9a91SJeremy L Thompson   if (is_composite) {
287d8dd9a91SJeremy L Thompson     CeedInt       num_sub;
288d8dd9a91SJeremy L Thompson     CeedOperator *sub_operators;
289d8dd9a91SJeremy L Thompson 
2902b730f8bSJeremy L Thompson     CeedCall(CeedOperatorGetNumSub(op, &num_sub));
2912b730f8bSJeremy L Thompson     CeedCall(CeedOperatorGetSubList(op, &sub_operators));
2922b730f8bSJeremy L Thompson     if (num_sub != field_label->num_sub_labels) {
2933668ca4bSJeremy L Thompson       // LCOV_EXCL_START
2943668ca4bSJeremy L Thompson       return CeedError(op->ceed, CEED_ERROR_UNSUPPORTED,
2952b730f8bSJeremy L Thompson                        "ContextLabel does not correspond to composite operator. Use CeedOperatorGetContextFieldLabel().");
2963668ca4bSJeremy L Thompson       // LCOV_EXCL_STOP
2972b730f8bSJeremy L Thompson     }
298d8dd9a91SJeremy L Thompson 
299d8dd9a91SJeremy L Thompson     for (CeedInt i = 0; i < num_sub; i++) {
300d8dd9a91SJeremy L Thompson       // Try every sub-operator, ok if some sub-operators do not have field
3013668ca4bSJeremy L Thompson       if (field_label->sub_labels[i] && sub_operators[i]->qf->ctx) {
3022b730f8bSJeremy L Thompson         CeedCall(CeedQFunctionContextSetGeneric(sub_operators[i]->qf->ctx, field_label->sub_labels[i], field_type, value));
303d8dd9a91SJeremy L Thompson       }
304d8dd9a91SJeremy L Thompson     }
305d8dd9a91SJeremy L Thompson   } else {
3062b730f8bSJeremy L Thompson     if (!op->qf->ctx) {
307d8dd9a91SJeremy L Thompson       // LCOV_EXCL_START
3082b730f8bSJeremy L Thompson       return CeedError(op->ceed, CEED_ERROR_UNSUPPORTED, "QFunction does not have context data");
309d8dd9a91SJeremy L Thompson       // LCOV_EXCL_STOP
3102b730f8bSJeremy L Thompson     }
311d8dd9a91SJeremy L Thompson 
3122b730f8bSJeremy L Thompson     CeedCall(CeedQFunctionContextSetGeneric(op->qf->ctx, field_label, field_type, value));
313d8dd9a91SJeremy L Thompson   }
314d8dd9a91SJeremy L Thompson 
315d8dd9a91SJeremy L Thompson   return CEED_ERROR_SUCCESS;
316d8dd9a91SJeremy L Thompson }
317d8dd9a91SJeremy L Thompson 
3187a982d89SJeremy L. Thompson /// @}
3197a982d89SJeremy L. Thompson 
3207a982d89SJeremy L. Thompson /// ----------------------------------------------------------------------------
3217a982d89SJeremy L. Thompson /// CeedOperator Backend API
3227a982d89SJeremy L. Thompson /// ----------------------------------------------------------------------------
3237a982d89SJeremy L. Thompson /// @addtogroup CeedOperatorBackend
3247a982d89SJeremy L. Thompson /// @{
3257a982d89SJeremy L. Thompson 
3267a982d89SJeremy L. Thompson /**
3277a982d89SJeremy L. Thompson   @brief Get the number of arguments associated with a CeedOperator
3287a982d89SJeremy L. Thompson 
329ea61e9acSJeremy L Thompson   @param[in]  op        CeedOperator
330d1d35e2fSjeremylt   @param[out] num_args  Variable to store vector number of arguments
3317a982d89SJeremy L. Thompson 
3327a982d89SJeremy L. Thompson   @return An error code: 0 - success, otherwise - failure
3337a982d89SJeremy L. Thompson 
3347a982d89SJeremy L. Thompson   @ref Backend
3357a982d89SJeremy L. Thompson **/
3367a982d89SJeremy L. Thompson 
337d1d35e2fSjeremylt int CeedOperatorGetNumArgs(CeedOperator op, CeedInt *num_args) {
3382b730f8bSJeremy L Thompson   if (op->is_composite) {
3397a982d89SJeremy L. Thompson     // LCOV_EXCL_START
3402b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MINOR, "Not defined for composite operators");
3417a982d89SJeremy L. Thompson     // LCOV_EXCL_STOP
3422b730f8bSJeremy L Thompson   }
343d1d35e2fSjeremylt   *num_args = op->num_fields;
344e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
3457a982d89SJeremy L. Thompson }
3467a982d89SJeremy L. Thompson 
3477a982d89SJeremy L. Thompson /**
3487a982d89SJeremy L. Thompson   @brief Get the setup status of a CeedOperator
3497a982d89SJeremy L. Thompson 
350ea61e9acSJeremy L Thompson   @param[in]  op            CeedOperator
351d1d35e2fSjeremylt   @param[out] is_setup_done Variable to store setup status
3527a982d89SJeremy L. Thompson 
3537a982d89SJeremy L. Thompson   @return An error code: 0 - success, otherwise - failure
3547a982d89SJeremy L. Thompson 
3557a982d89SJeremy L. Thompson   @ref Backend
3567a982d89SJeremy L. Thompson **/
3577a982d89SJeremy L. Thompson 
358d1d35e2fSjeremylt int CeedOperatorIsSetupDone(CeedOperator op, bool *is_setup_done) {
359f04ea552SJeremy L Thompson   *is_setup_done = op->is_backend_setup;
360e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
3617a982d89SJeremy L. Thompson }
3627a982d89SJeremy L. Thompson 
3637a982d89SJeremy L. Thompson /**
3647a982d89SJeremy L. Thompson   @brief Get the QFunction associated with a CeedOperator
3657a982d89SJeremy L. Thompson 
366ea61e9acSJeremy L Thompson   @param[in]  op CeedOperator
3677a982d89SJeremy L. Thompson   @param[out] qf Variable to store QFunction
3687a982d89SJeremy L. Thompson 
3697a982d89SJeremy L. Thompson   @return An error code: 0 - success, otherwise - failure
3707a982d89SJeremy L. Thompson 
3717a982d89SJeremy L. Thompson   @ref Backend
3727a982d89SJeremy L. Thompson **/
3737a982d89SJeremy L. Thompson 
3747a982d89SJeremy L. Thompson int CeedOperatorGetQFunction(CeedOperator op, CeedQFunction *qf) {
3752b730f8bSJeremy L Thompson   if (op->is_composite) {
3767a982d89SJeremy L. Thompson     // LCOV_EXCL_START
3772b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MINOR, "Not defined for composite operator");
3787a982d89SJeremy L. Thompson     // LCOV_EXCL_STOP
3792b730f8bSJeremy L Thompson   }
3807a982d89SJeremy L. Thompson   *qf = op->qf;
381e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
3827a982d89SJeremy L. Thompson }
3837a982d89SJeremy L. Thompson 
3847a982d89SJeremy L. Thompson /**
385c04a41a7SJeremy L Thompson   @brief Get a boolean value indicating if the CeedOperator is composite
386c04a41a7SJeremy L Thompson 
387ea61e9acSJeremy L Thompson   @param[in]  op           CeedOperator
388d1d35e2fSjeremylt   @param[out] is_composite Variable to store composite status
389c04a41a7SJeremy L Thompson 
390c04a41a7SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
391c04a41a7SJeremy L Thompson 
392c04a41a7SJeremy L Thompson   @ref Backend
393c04a41a7SJeremy L Thompson **/
394c04a41a7SJeremy L Thompson 
395d1d35e2fSjeremylt int CeedOperatorIsComposite(CeedOperator op, bool *is_composite) {
396f04ea552SJeremy L Thompson   *is_composite = op->is_composite;
397e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
398c04a41a7SJeremy L Thompson }
399c04a41a7SJeremy L Thompson 
400c04a41a7SJeremy L Thompson /**
4017a982d89SJeremy L. Thompson   @brief Get the backend data of a CeedOperator
4027a982d89SJeremy L. Thompson 
403ea61e9acSJeremy L Thompson   @param[in]  op   CeedOperator
4047a982d89SJeremy L. Thompson   @param[out] data Variable to store data
4057a982d89SJeremy L. Thompson 
4067a982d89SJeremy L. Thompson   @return An error code: 0 - success, otherwise - failure
4077a982d89SJeremy L. Thompson 
4087a982d89SJeremy L. Thompson   @ref Backend
4097a982d89SJeremy L. Thompson **/
4107a982d89SJeremy L. Thompson 
411777ff853SJeremy L Thompson int CeedOperatorGetData(CeedOperator op, void *data) {
412777ff853SJeremy L Thompson   *(void **)data = op->data;
413e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
4147a982d89SJeremy L. Thompson }
4157a982d89SJeremy L. Thompson 
4167a982d89SJeremy L. Thompson /**
4177a982d89SJeremy L. Thompson   @brief Set the backend data of a CeedOperator
4187a982d89SJeremy L. Thompson 
419ea61e9acSJeremy L Thompson   @param[in,out] op   CeedOperator
420ea61e9acSJeremy L Thompson   @param[in]     data Data to set
4217a982d89SJeremy L. Thompson 
4227a982d89SJeremy L. Thompson   @return An error code: 0 - success, otherwise - failure
4237a982d89SJeremy L. Thompson 
4247a982d89SJeremy L. Thompson   @ref Backend
4257a982d89SJeremy L. Thompson **/
4267a982d89SJeremy L. Thompson 
427777ff853SJeremy L Thompson int CeedOperatorSetData(CeedOperator op, void *data) {
428777ff853SJeremy L Thompson   op->data = data;
429e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
4307a982d89SJeremy L. Thompson }
4317a982d89SJeremy L. Thompson 
4327a982d89SJeremy L. Thompson /**
43334359f16Sjeremylt   @brief Increment the reference counter for a CeedOperator
43434359f16Sjeremylt 
435ea61e9acSJeremy L Thompson   @param[in,out] op CeedOperator to increment the reference counter
43634359f16Sjeremylt 
43734359f16Sjeremylt   @return An error code: 0 - success, otherwise - failure
43834359f16Sjeremylt 
43934359f16Sjeremylt   @ref Backend
44034359f16Sjeremylt **/
4419560d06aSjeremylt int CeedOperatorReference(CeedOperator op) {
44234359f16Sjeremylt   op->ref_count++;
44334359f16Sjeremylt   return CEED_ERROR_SUCCESS;
44434359f16Sjeremylt }
44534359f16Sjeremylt 
44634359f16Sjeremylt /**
4477a982d89SJeremy L. Thompson   @brief Set the setup flag of a CeedOperator to True
4487a982d89SJeremy L. Thompson 
449ea61e9acSJeremy L Thompson   @param[in,out] op CeedOperator
4507a982d89SJeremy L. Thompson 
4517a982d89SJeremy L. Thompson   @return An error code: 0 - success, otherwise - failure
4527a982d89SJeremy L. Thompson 
4537a982d89SJeremy L. Thompson   @ref Backend
4547a982d89SJeremy L. Thompson **/
4557a982d89SJeremy L. Thompson 
4567a982d89SJeremy L. Thompson int CeedOperatorSetSetupDone(CeedOperator op) {
457f04ea552SJeremy L Thompson   op->is_backend_setup = true;
458e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
4597a982d89SJeremy L. Thompson }
4607a982d89SJeremy L. Thompson 
4617a982d89SJeremy L. Thompson /// @}
4627a982d89SJeremy L. Thompson 
4637a982d89SJeremy L. Thompson /// ----------------------------------------------------------------------------
4647a982d89SJeremy L. Thompson /// CeedOperator Public API
4657a982d89SJeremy L. Thompson /// ----------------------------------------------------------------------------
4667a982d89SJeremy L. Thompson /// @addtogroup CeedOperatorUser
467dfdf5a53Sjeremylt /// @{
468d7b241e6Sjeremylt 
469d7b241e6Sjeremylt /**
470ea61e9acSJeremy L Thompson   @brief Create a CeedOperator and associate a CeedQFunction.
471ea61e9acSJeremy L Thompson            A CeedBasis and CeedElemRestriction can be associated with CeedQFunction fields with \ref CeedOperatorSetField.
472d7b241e6Sjeremylt 
473ea61e9acSJeremy L Thompson   @param[in]  ceed Ceed object where the CeedOperator will be created
474ea61e9acSJeremy L Thompson   @param[in]  qf   QFunction defining the action of the operator at quadrature points
475ea61e9acSJeremy L Thompson   @param[in]  dqf  QFunction defining the action of the Jacobian of @a qf (or @ref CEED_QFUNCTION_NONE)
476ea61e9acSJeremy L Thompson   @param[in]  dqfT QFunction defining the action of the transpose of the Jacobian of @a qf (or @ref CEED_QFUNCTION_NONE)
477ea61e9acSJeremy L Thompson   @param[out] op   Address of the variable where the newly created CeedOperator will be stored
478b11c1e72Sjeremylt 
479b11c1e72Sjeremylt   @return An error code: 0 - success, otherwise - failure
480dfdf5a53Sjeremylt 
4817a982d89SJeremy L. Thompson   @ref User
482d7b241e6Sjeremylt  */
4832b730f8bSJeremy L Thompson int CeedOperatorCreate(Ceed ceed, CeedQFunction qf, CeedQFunction dqf, CeedQFunction dqfT, CeedOperator *op) {
4845fe0d4faSjeremylt   if (!ceed->OperatorCreate) {
4855fe0d4faSjeremylt     Ceed delegate;
4862b730f8bSJeremy L Thompson     CeedCall(CeedGetObjectDelegate(ceed, &delegate, "Operator"));
4875fe0d4faSjeremylt 
4882b730f8bSJeremy L Thompson     if (!delegate) {
489c042f62fSJeremy L Thompson       // LCOV_EXCL_START
4902b730f8bSJeremy L Thompson       return CeedError(ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support OperatorCreate");
491c042f62fSJeremy L Thompson       // LCOV_EXCL_STOP
4922b730f8bSJeremy L Thompson     }
4935fe0d4faSjeremylt 
4942b730f8bSJeremy L Thompson     CeedCall(CeedOperatorCreate(delegate, qf, dqf, dqfT, op));
495e15f9bd0SJeremy L Thompson     return CEED_ERROR_SUCCESS;
4965fe0d4faSjeremylt   }
4975fe0d4faSjeremylt 
4982b730f8bSJeremy L Thompson   if (!qf || qf == CEED_QFUNCTION_NONE) {
499b3b7035fSJeremy L Thompson     // LCOV_EXCL_START
5002b730f8bSJeremy L Thompson     return CeedError(ceed, CEED_ERROR_MINOR, "Operator must have a valid QFunction.");
501b3b7035fSJeremy L Thompson     // LCOV_EXCL_STOP
5022b730f8bSJeremy L Thompson   }
5032b730f8bSJeremy L Thompson   CeedCall(CeedCalloc(1, op));
504d7b241e6Sjeremylt   (*op)->ceed = ceed;
5052b730f8bSJeremy L Thompson   CeedCall(CeedReference(ceed));
506d1d35e2fSjeremylt   (*op)->ref_count   = 1;
507d7b241e6Sjeremylt   (*op)->qf          = qf;
5082b104005SJeremy L Thompson   (*op)->input_size  = -1;
5092b104005SJeremy L Thompson   (*op)->output_size = -1;
5102b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionReference(qf));
511442e7f0bSjeremylt   if (dqf && dqf != CEED_QFUNCTION_NONE) {
512d7b241e6Sjeremylt     (*op)->dqf = dqf;
5132b730f8bSJeremy L Thompson     CeedCall(CeedQFunctionReference(dqf));
514442e7f0bSjeremylt   }
515442e7f0bSjeremylt   if (dqfT && dqfT != CEED_QFUNCTION_NONE) {
516d7b241e6Sjeremylt     (*op)->dqfT = dqfT;
5172b730f8bSJeremy L Thompson     CeedCall(CeedQFunctionReference(dqfT));
518442e7f0bSjeremylt   }
5192b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionAssemblyDataCreate(ceed, &(*op)->qf_assembled));
5202b730f8bSJeremy L Thompson   CeedCall(CeedCalloc(CEED_FIELD_MAX, &(*op)->input_fields));
5212b730f8bSJeremy L Thompson   CeedCall(CeedCalloc(CEED_FIELD_MAX, &(*op)->output_fields));
5222b730f8bSJeremy L Thompson   CeedCall(ceed->OperatorCreate(*op));
523e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
524d7b241e6Sjeremylt }
525d7b241e6Sjeremylt 
526d7b241e6Sjeremylt /**
52752d6035fSJeremy L Thompson   @brief Create an operator that composes the action of several operators
52852d6035fSJeremy L Thompson 
529ea61e9acSJeremy L Thompson   @param[in]  ceed Ceed object where the CeedOperator will be created
530ea61e9acSJeremy L Thompson   @param[out] op   Address of the variable where the newly created Composite CeedOperator will be stored
53152d6035fSJeremy L Thompson 
53252d6035fSJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
53352d6035fSJeremy L Thompson 
5347a982d89SJeremy L. Thompson   @ref User
53552d6035fSJeremy L Thompson  */
53652d6035fSJeremy L Thompson int CeedCompositeOperatorCreate(Ceed ceed, CeedOperator *op) {
53752d6035fSJeremy L Thompson   if (!ceed->CompositeOperatorCreate) {
53852d6035fSJeremy L Thompson     Ceed delegate;
5392b730f8bSJeremy L Thompson     CeedCall(CeedGetObjectDelegate(ceed, &delegate, "Operator"));
54052d6035fSJeremy L Thompson 
541250756a7Sjeremylt     if (delegate) {
5422b730f8bSJeremy L Thompson       CeedCall(CeedCompositeOperatorCreate(delegate, op));
543e15f9bd0SJeremy L Thompson       return CEED_ERROR_SUCCESS;
54452d6035fSJeremy L Thompson     }
545250756a7Sjeremylt   }
54652d6035fSJeremy L Thompson 
5472b730f8bSJeremy L Thompson   CeedCall(CeedCalloc(1, op));
54852d6035fSJeremy L Thompson   (*op)->ceed = ceed;
5492b730f8bSJeremy L Thompson   CeedCall(CeedReference(ceed));
550996d9ab5SJed Brown   (*op)->ref_count    = 1;
551f04ea552SJeremy L Thompson   (*op)->is_composite = true;
5522b730f8bSJeremy L Thompson   CeedCall(CeedCalloc(CEED_COMPOSITE_MAX, &(*op)->sub_operators));
5532b104005SJeremy L Thompson   (*op)->input_size  = -1;
5542b104005SJeremy L Thompson   (*op)->output_size = -1;
555250756a7Sjeremylt 
556250756a7Sjeremylt   if (ceed->CompositeOperatorCreate) {
5572b730f8bSJeremy L Thompson     CeedCall(ceed->CompositeOperatorCreate(*op));
558250756a7Sjeremylt   }
559e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
56052d6035fSJeremy L Thompson }
56152d6035fSJeremy L Thompson 
56252d6035fSJeremy L Thompson /**
563ea61e9acSJeremy L Thompson   @brief Copy the pointer to a CeedOperator.
564ea61e9acSJeremy L Thompson            Both pointers should be destroyed with `CeedOperatorDestroy()`.
565ea61e9acSJeremy L Thompson            Note: If `*op_copy` is non-NULL, then it is assumed that `*op_copy` is a pointer to a CeedOperator.
566ea61e9acSJeremy L Thompson              This CeedOperator will be destroyed if `*op_copy` is the only reference to this CeedOperator.
5679560d06aSjeremylt 
568ea61e9acSJeremy L Thompson   @param[in]  op         CeedOperator to copy reference to
569ea61e9acSJeremy L Thompson   @param[in,out] op_copy Variable to store copied reference
5709560d06aSjeremylt 
5719560d06aSjeremylt   @return An error code: 0 - success, otherwise - failure
5729560d06aSjeremylt 
5739560d06aSjeremylt   @ref User
5749560d06aSjeremylt **/
5759560d06aSjeremylt int CeedOperatorReferenceCopy(CeedOperator op, CeedOperator *op_copy) {
5762b730f8bSJeremy L Thompson   CeedCall(CeedOperatorReference(op));
5772b730f8bSJeremy L Thompson   CeedCall(CeedOperatorDestroy(op_copy));
5789560d06aSjeremylt   *op_copy = op;
5799560d06aSjeremylt   return CEED_ERROR_SUCCESS;
5809560d06aSjeremylt }
5819560d06aSjeremylt 
5829560d06aSjeremylt /**
583ea61e9acSJeremy L Thompson   @brief Provide a field to a CeedOperator for use by its CeedQFunction.
584d7b241e6Sjeremylt 
585ea61e9acSJeremy L Thompson   This function is used to specify both active and passive fields to a CeedOperator.
586ea61e9acSJeremy L Thompson   For passive fields, a vector @arg v must be provided.
587ea61e9acSJeremy L Thompson   Passive fields can inputs or outputs (updated in-place when operator is applied).
588d7b241e6Sjeremylt 
589ea61e9acSJeremy L Thompson   Active fields must be specified using this function, but their data (in a CeedVector) is passed in CeedOperatorApply().
590ea61e9acSJeremy L Thompson   There can be at most one active input CeedVector and at most one active output CeedVector passed to CeedOperatorApply().
591d7b241e6Sjeremylt 
592ea61e9acSJeremy L Thompson   @param[in,out] op         CeedOperator on which to provide the field
593ea61e9acSJeremy L Thompson   @param[in]     field_name Name of the field (to be matched with the name used by CeedQFunction)
594ea61e9acSJeremy L Thompson   @param[in]     r          CeedElemRestriction
595ea61e9acSJeremy L Thompson   @param[in]     b          CeedBasis in which the field resides or @ref CEED_BASIS_COLLOCATED if collocated with quadrature points
596ea61e9acSJeremy L Thompson   @param[in]     v          CeedVector to be used by CeedOperator or @ref CEED_VECTOR_ACTIVE if field is active or @ref CEED_VECTOR_NONE if using @ref
597ea61e9acSJeremy L Thompson CEED_EVAL_WEIGHT in the QFunction
598b11c1e72Sjeremylt 
599b11c1e72Sjeremylt   @return An error code: 0 - success, otherwise - failure
600dfdf5a53Sjeremylt 
6017a982d89SJeremy L. Thompson   @ref User
602b11c1e72Sjeremylt **/
6032b730f8bSJeremy L Thompson int CeedOperatorSetField(CeedOperator op, const char *field_name, CeedElemRestriction r, CeedBasis b, CeedVector v) {
6042b730f8bSJeremy L Thompson   if (op->is_composite) {
605c042f62fSJeremy L Thompson     // LCOV_EXCL_START
6062b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_INCOMPATIBLE, "Cannot add field to composite operator.");
607c042f62fSJeremy L Thompson     // LCOV_EXCL_STOP
6082b730f8bSJeremy L Thompson   }
6092b730f8bSJeremy L Thompson   if (op->is_immutable) {
610f04ea552SJeremy L Thompson     // LCOV_EXCL_START
6112b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable");
612f04ea552SJeremy L Thompson     // LCOV_EXCL_STOP
6132b730f8bSJeremy L Thompson   }
6142b730f8bSJeremy L Thompson   if (!r) {
615c042f62fSJeremy L Thompson     // LCOV_EXCL_START
6162b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_INCOMPATIBLE, "ElemRestriction r for field \"%s\" must be non-NULL.", field_name);
617c042f62fSJeremy L Thompson     // LCOV_EXCL_STOP
6182b730f8bSJeremy L Thompson   }
6192b730f8bSJeremy L Thompson   if (!b) {
620c042f62fSJeremy L Thompson     // LCOV_EXCL_START
6212b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_INCOMPATIBLE, "Basis b for field \"%s\" must be non-NULL.", field_name);
622c042f62fSJeremy L Thompson     // LCOV_EXCL_STOP
6232b730f8bSJeremy L Thompson   }
6242b730f8bSJeremy L Thompson   if (!v) {
625c042f62fSJeremy L Thompson     // LCOV_EXCL_START
6262b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_INCOMPATIBLE, "Vector v for field \"%s\" must be non-NULL.", field_name);
627c042f62fSJeremy L Thompson     // LCOV_EXCL_STOP
6282b730f8bSJeremy L Thompson   }
62952d6035fSJeremy L Thompson 
630d1d35e2fSjeremylt   CeedInt num_elem;
6312b730f8bSJeremy L Thompson   CeedCall(CeedElemRestrictionGetNumElements(r, &num_elem));
6322b730f8bSJeremy L Thompson   if (r != CEED_ELEMRESTRICTION_NONE && op->has_restriction && op->num_elem != num_elem) {
633c042f62fSJeremy L Thompson     // LCOV_EXCL_START
634e15f9bd0SJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_DIMENSION,
6352b730f8bSJeremy L Thompson                      "ElemRestriction with %" CeedInt_FMT " elements incompatible with prior %" CeedInt_FMT " elements", num_elem, op->num_elem);
636c042f62fSJeremy L Thompson     // LCOV_EXCL_STOP
6372b730f8bSJeremy L Thompson   }
638d7b241e6Sjeremylt 
63978464608Sjeremylt   CeedInt num_qpts = 0;
640e15f9bd0SJeremy L Thompson   if (b != CEED_BASIS_COLLOCATED) {
6412b730f8bSJeremy L Thompson     CeedCall(CeedBasisGetNumQuadraturePoints(b, &num_qpts));
6422b730f8bSJeremy L Thompson     if (op->num_qpts && op->num_qpts != num_qpts) {
643c042f62fSJeremy L Thompson       // LCOV_EXCL_START
644e15f9bd0SJeremy L Thompson       return CeedError(op->ceed, CEED_ERROR_DIMENSION,
6452b730f8bSJeremy L Thompson                        "Basis with %" CeedInt_FMT " quadrature points incompatible with prior %" CeedInt_FMT " points", num_qpts, op->num_qpts);
646c042f62fSJeremy L Thompson       // LCOV_EXCL_STOP
647d7b241e6Sjeremylt     }
6482b730f8bSJeremy L Thompson   }
649d1d35e2fSjeremylt   CeedQFunctionField qf_field;
650d1d35e2fSjeremylt   CeedOperatorField *op_field;
6512b104005SJeremy L Thompson   bool               is_input = true;
652d1d35e2fSjeremylt   for (CeedInt i = 0; i < op->qf->num_input_fields; i++) {
653d1d35e2fSjeremylt     if (!strcmp(field_name, (*op->qf->input_fields[i]).field_name)) {
654d1d35e2fSjeremylt       qf_field = op->qf->input_fields[i];
655d1d35e2fSjeremylt       op_field = &op->input_fields[i];
656d7b241e6Sjeremylt       goto found;
657d7b241e6Sjeremylt     }
658d7b241e6Sjeremylt   }
6592b104005SJeremy L Thompson   is_input = false;
660d1d35e2fSjeremylt   for (CeedInt i = 0; i < op->qf->num_output_fields; i++) {
661d1d35e2fSjeremylt     if (!strcmp(field_name, (*op->qf->output_fields[i]).field_name)) {
662d1d35e2fSjeremylt       qf_field = op->qf->output_fields[i];
663d1d35e2fSjeremylt       op_field = &op->output_fields[i];
664d7b241e6Sjeremylt       goto found;
665d7b241e6Sjeremylt     }
666d7b241e6Sjeremylt   }
667c042f62fSJeremy L Thompson   // LCOV_EXCL_START
6682b730f8bSJeremy L Thompson   return CeedError(op->ceed, CEED_ERROR_INCOMPLETE, "QFunction has no knowledge of field '%s'", field_name);
669c042f62fSJeremy L Thompson   // LCOV_EXCL_STOP
670d7b241e6Sjeremylt found:
6712b730f8bSJeremy L Thompson   CeedCall(CeedOperatorCheckField(op->ceed, qf_field, r, b));
6722b730f8bSJeremy L Thompson   CeedCall(CeedCalloc(1, op_field));
673e15f9bd0SJeremy L Thompson 
6742b104005SJeremy L Thompson   if (v == CEED_VECTOR_ACTIVE) {
6752b104005SJeremy L Thompson     CeedSize l_size;
6762b730f8bSJeremy L Thompson     CeedCall(CeedElemRestrictionGetLVectorSize(r, &l_size));
6772b104005SJeremy L Thompson     if (is_input) {
6782b104005SJeremy L Thompson       if (op->input_size == -1) op->input_size = l_size;
6792b730f8bSJeremy L Thompson       if (l_size != op->input_size) {
6802b104005SJeremy L Thompson         // LCOV_EXCL_START
6812b730f8bSJeremy L Thompson         return CeedError(op->ceed, CEED_ERROR_INCOMPATIBLE, "LVector size %td does not match previous size %td", l_size, op->input_size);
6822b104005SJeremy L Thompson         // LCOV_EXCL_STOP
6832b730f8bSJeremy L Thompson       }
6842b104005SJeremy L Thompson     } else {
6852b104005SJeremy L Thompson       if (op->output_size == -1) op->output_size = l_size;
6862b730f8bSJeremy L Thompson       if (l_size != op->output_size) {
6872b104005SJeremy L Thompson         // LCOV_EXCL_START
6882b730f8bSJeremy L Thompson         return CeedError(op->ceed, CEED_ERROR_INCOMPATIBLE, "LVector size %td does not match previous size %td", l_size, op->output_size);
6892b104005SJeremy L Thompson         // LCOV_EXCL_STOP
6902b104005SJeremy L Thompson       }
6912b104005SJeremy L Thompson     }
6922b730f8bSJeremy L Thompson   }
6932b104005SJeremy L Thompson 
694d1d35e2fSjeremylt   (*op_field)->vec = v;
695e15f9bd0SJeremy L Thompson   if (v != CEED_VECTOR_ACTIVE && v != CEED_VECTOR_NONE) {
6962b730f8bSJeremy L Thompson     CeedCall(CeedVectorReference(v));
697e15f9bd0SJeremy L Thompson   }
698e15f9bd0SJeremy L Thompson 
699d1d35e2fSjeremylt   (*op_field)->elem_restr = r;
7002b730f8bSJeremy L Thompson   CeedCall(CeedElemRestrictionReference(r));
701e15f9bd0SJeremy L Thompson   if (r != CEED_ELEMRESTRICTION_NONE) {
702d1d35e2fSjeremylt     op->num_elem        = num_elem;
703d1d35e2fSjeremylt     op->has_restriction = true;  // Restriction set, but num_elem may be 0
704e15f9bd0SJeremy L Thompson   }
705d99fa3c5SJeremy L Thompson 
706d1d35e2fSjeremylt   (*op_field)->basis = b;
707e15f9bd0SJeremy L Thompson   if (b != CEED_BASIS_COLLOCATED) {
708cd4dfc48Sjeremylt     if (!op->num_qpts) {
7092b730f8bSJeremy L Thompson       CeedCall(CeedOperatorSetNumQuadraturePoints(op, num_qpts));
710cd4dfc48Sjeremylt     }
7112b730f8bSJeremy L Thompson     CeedCall(CeedBasisReference(b));
712e15f9bd0SJeremy L Thompson   }
713e15f9bd0SJeremy L Thompson 
714d1d35e2fSjeremylt   op->num_fields += 1;
7152b730f8bSJeremy L Thompson   CeedCall(CeedStringAllocCopy(field_name, (char **)&(*op_field)->field_name));
716e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
717d7b241e6Sjeremylt }
718d7b241e6Sjeremylt 
719d7b241e6Sjeremylt /**
72043bbe138SJeremy L Thompson   @brief Get the CeedOperatorFields of a CeedOperator
72143bbe138SJeremy L Thompson 
722ea61e9acSJeremy L Thompson   Note: Calling this function asserts that setup is complete and sets the CeedOperator as immutable.
723f04ea552SJeremy L Thompson 
724ea61e9acSJeremy L Thompson   @param[in]  op                CeedOperator
725f74ec584SJeremy L Thompson   @param[out] num_input_fields  Variable to store number of input fields
72643bbe138SJeremy L Thompson   @param[out] input_fields      Variable to store input_fields
727f74ec584SJeremy L Thompson   @param[out] num_output_fields Variable to store number of output fields
72843bbe138SJeremy L Thompson   @param[out] output_fields     Variable to store output_fields
72943bbe138SJeremy L Thompson 
73043bbe138SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
73143bbe138SJeremy L Thompson 
732e9b533fbSJeremy L Thompson   @ref Advanced
73343bbe138SJeremy L Thompson **/
7342b730f8bSJeremy L Thompson int CeedOperatorGetFields(CeedOperator op, CeedInt *num_input_fields, CeedOperatorField **input_fields, CeedInt *num_output_fields,
73543bbe138SJeremy L Thompson                           CeedOperatorField **output_fields) {
7362b730f8bSJeremy L Thompson   if (op->is_composite) {
73743bbe138SJeremy L Thompson     // LCOV_EXCL_START
7382b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MINOR, "Not defined for composite operator");
73943bbe138SJeremy L Thompson     // LCOV_EXCL_STOP
7402b730f8bSJeremy L Thompson   }
7412b730f8bSJeremy L Thompson   CeedCall(CeedOperatorCheckReady(op));
74243bbe138SJeremy L Thompson 
74343bbe138SJeremy L Thompson   if (num_input_fields) *num_input_fields = op->qf->num_input_fields;
74443bbe138SJeremy L Thompson   if (input_fields) *input_fields = op->input_fields;
74543bbe138SJeremy L Thompson   if (num_output_fields) *num_output_fields = op->qf->num_output_fields;
74643bbe138SJeremy L Thompson   if (output_fields) *output_fields = op->output_fields;
74743bbe138SJeremy L Thompson   return CEED_ERROR_SUCCESS;
74843bbe138SJeremy L Thompson }
74943bbe138SJeremy L Thompson 
75043bbe138SJeremy L Thompson /**
75128567f8fSJeremy L Thompson   @brief Get the name of a CeedOperatorField
75228567f8fSJeremy L Thompson 
753ea61e9acSJeremy L Thompson   @param[in]  op_field    CeedOperatorField
75428567f8fSJeremy L Thompson   @param[out] field_name  Variable to store the field name
75528567f8fSJeremy L Thompson 
75628567f8fSJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
75728567f8fSJeremy L Thompson 
758e9b533fbSJeremy L Thompson   @ref Advanced
75928567f8fSJeremy L Thompson **/
76028567f8fSJeremy L Thompson int CeedOperatorFieldGetName(CeedOperatorField op_field, char **field_name) {
76128567f8fSJeremy L Thompson   *field_name = (char *)op_field->field_name;
76228567f8fSJeremy L Thompson   return CEED_ERROR_SUCCESS;
76328567f8fSJeremy L Thompson }
76428567f8fSJeremy L Thompson 
76528567f8fSJeremy L Thompson /**
76643bbe138SJeremy L Thompson   @brief Get the CeedElemRestriction of a CeedOperatorField
76743bbe138SJeremy L Thompson 
768ea61e9acSJeremy L Thompson   @param[in]  op_field CeedOperatorField
76943bbe138SJeremy L Thompson   @param[out] rstr     Variable to store CeedElemRestriction
77043bbe138SJeremy L Thompson 
77143bbe138SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
77243bbe138SJeremy L Thompson 
773e9b533fbSJeremy L Thompson   @ref Advanced
77443bbe138SJeremy L Thompson **/
7752b730f8bSJeremy L Thompson int CeedOperatorFieldGetElemRestriction(CeedOperatorField op_field, CeedElemRestriction *rstr) {
77643bbe138SJeremy L Thompson   *rstr = op_field->elem_restr;
77743bbe138SJeremy L Thompson   return CEED_ERROR_SUCCESS;
77843bbe138SJeremy L Thompson }
77943bbe138SJeremy L Thompson 
78043bbe138SJeremy L Thompson /**
78143bbe138SJeremy L Thompson   @brief Get the CeedBasis of a CeedOperatorField
78243bbe138SJeremy L Thompson 
783ea61e9acSJeremy L Thompson   @param[in]  op_field CeedOperatorField
78443bbe138SJeremy L Thompson   @param[out] basis    Variable to store CeedBasis
78543bbe138SJeremy L Thompson 
78643bbe138SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
78743bbe138SJeremy L Thompson 
788e9b533fbSJeremy L Thompson   @ref Advanced
78943bbe138SJeremy L Thompson **/
79043bbe138SJeremy L Thompson int CeedOperatorFieldGetBasis(CeedOperatorField op_field, CeedBasis *basis) {
79143bbe138SJeremy L Thompson   *basis = op_field->basis;
79243bbe138SJeremy L Thompson   return CEED_ERROR_SUCCESS;
79343bbe138SJeremy L Thompson }
79443bbe138SJeremy L Thompson 
79543bbe138SJeremy L Thompson /**
79643bbe138SJeremy L Thompson   @brief Get the CeedVector of a CeedOperatorField
79743bbe138SJeremy L Thompson 
798ea61e9acSJeremy L Thompson   @param[in]  op_field CeedOperatorField
79943bbe138SJeremy L Thompson   @param[out] vec      Variable to store CeedVector
80043bbe138SJeremy L Thompson 
80143bbe138SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
80243bbe138SJeremy L Thompson 
803e9b533fbSJeremy L Thompson   @ref Advanced
80443bbe138SJeremy L Thompson **/
80543bbe138SJeremy L Thompson int CeedOperatorFieldGetVector(CeedOperatorField op_field, CeedVector *vec) {
80643bbe138SJeremy L Thompson   *vec = op_field->vec;
80743bbe138SJeremy L Thompson   return CEED_ERROR_SUCCESS;
80843bbe138SJeremy L Thompson }
80943bbe138SJeremy L Thompson 
81043bbe138SJeremy L Thompson /**
81152d6035fSJeremy L Thompson   @brief Add a sub-operator to a composite CeedOperator
812288c0443SJeremy L Thompson 
813ea61e9acSJeremy L Thompson   @param[in,out] composite_op Composite CeedOperator
814ea61e9acSJeremy L Thompson   @param[in]     sub_op       Sub-operator CeedOperator
81552d6035fSJeremy L Thompson 
81652d6035fSJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
81752d6035fSJeremy L Thompson 
8187a982d89SJeremy L. Thompson   @ref User
81952d6035fSJeremy L Thompson  */
8202b730f8bSJeremy L Thompson int CeedCompositeOperatorAddSub(CeedOperator composite_op, CeedOperator sub_op) {
8212b730f8bSJeremy L Thompson   if (!composite_op->is_composite) {
822c042f62fSJeremy L Thompson     // LCOV_EXCL_START
8232b730f8bSJeremy L Thompson     return CeedError(composite_op->ceed, CEED_ERROR_MINOR, "CeedOperator is not a composite operator");
8242b104005SJeremy L Thompson     // LCOV_EXCL_STOP
8252b104005SJeremy L Thompson   }
8262b104005SJeremy L Thompson 
8272b730f8bSJeremy L Thompson   if (composite_op->num_suboperators == CEED_COMPOSITE_MAX) {
8282b730f8bSJeremy L Thompson     // LCOV_EXCL_START
8292b730f8bSJeremy L Thompson     return CeedError(composite_op->ceed, CEED_ERROR_UNSUPPORTED, "Cannot add additional sub-operators");
8302b730f8bSJeremy L Thompson     // LCOV_EXCL_STOP
8312b730f8bSJeremy L Thompson   }
8322b730f8bSJeremy L Thompson   if (composite_op->is_immutable) {
8332b730f8bSJeremy L Thompson     // LCOV_EXCL_START
8342b730f8bSJeremy L Thompson     return CeedError(composite_op->ceed, CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable");
8352b730f8bSJeremy L Thompson     // LCOV_EXCL_STOP
8362b730f8bSJeremy L Thompson   }
8372b730f8bSJeremy L Thompson 
8382b730f8bSJeremy L Thompson   {
8392b730f8bSJeremy L Thompson     CeedSize input_size, output_size;
8402b730f8bSJeremy L Thompson     CeedCall(CeedOperatorGetActiveVectorLengths(sub_op, &input_size, &output_size));
8412b730f8bSJeremy L Thompson     if (composite_op->input_size == -1) composite_op->input_size = input_size;
8422b730f8bSJeremy L Thompson     if (composite_op->output_size == -1) composite_op->output_size = output_size;
8432b730f8bSJeremy L Thompson     // Note, a size of -1 means no active vector restriction set, so no incompatibility
8442b730f8bSJeremy L Thompson     if ((input_size != -1 && input_size != composite_op->input_size) || (output_size != -1 && output_size != composite_op->output_size)) {
8452b730f8bSJeremy L Thompson       // LCOV_EXCL_START
8462b730f8bSJeremy L Thompson       return CeedError(composite_op->ceed, CEED_ERROR_MAJOR,
8472b730f8bSJeremy L Thompson                        "Sub-operators must have compatible dimensions; composite operator of shape (%td, %td) not compatible with sub-operator of "
8482b730f8bSJeremy L Thompson                        "shape (%td, %td)",
8492b730f8bSJeremy L Thompson                        composite_op->input_size, composite_op->output_size, input_size, output_size);
8502b730f8bSJeremy L Thompson       // LCOV_EXCL_STOP
8512b730f8bSJeremy L Thompson     }
8522b730f8bSJeremy L Thompson   }
8532b730f8bSJeremy L Thompson 
854d1d35e2fSjeremylt   composite_op->sub_operators[composite_op->num_suboperators] = sub_op;
8552b730f8bSJeremy L Thompson   CeedCall(CeedOperatorReference(sub_op));
856d1d35e2fSjeremylt   composite_op->num_suboperators++;
857e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
85852d6035fSJeremy L Thompson }
85952d6035fSJeremy L Thompson 
86052d6035fSJeremy L Thompson /**
861*75f0d5a4SJeremy L Thompson   @brief Get the number of sub_operators associated with a CeedOperator
862*75f0d5a4SJeremy L Thompson 
863*75f0d5a4SJeremy L Thompson   @param[in]  op               CeedOperator
864*75f0d5a4SJeremy L Thompson   @param[out] num_suboperators Variable to store number of sub_operators
865*75f0d5a4SJeremy L Thompson 
866*75f0d5a4SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
867*75f0d5a4SJeremy L Thompson 
868*75f0d5a4SJeremy L Thompson   @ref Backend
869*75f0d5a4SJeremy L Thompson **/
870*75f0d5a4SJeremy L Thompson 
871*75f0d5a4SJeremy L Thompson int CeedOperatorGetNumSub(CeedOperator op, CeedInt *num_suboperators) {
872*75f0d5a4SJeremy L Thompson   if (!op->is_composite) {
873*75f0d5a4SJeremy L Thompson     // LCOV_EXCL_START
874*75f0d5a4SJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MINOR, "Not a composite operator");
875*75f0d5a4SJeremy L Thompson     // LCOV_EXCL_STOP
876*75f0d5a4SJeremy L Thompson   }
877*75f0d5a4SJeremy L Thompson   *num_suboperators = op->num_suboperators;
878*75f0d5a4SJeremy L Thompson   return CEED_ERROR_SUCCESS;
879*75f0d5a4SJeremy L Thompson }
880*75f0d5a4SJeremy L Thompson 
881*75f0d5a4SJeremy L Thompson /**
882*75f0d5a4SJeremy L Thompson   @brief Get the list of sub_operators associated with a CeedOperator
883*75f0d5a4SJeremy L Thompson 
884*75f0d5a4SJeremy L Thompson   @param op                  CeedOperator
885*75f0d5a4SJeremy L Thompson   @param[out] sub_operators  Variable to store list of sub_operators
886*75f0d5a4SJeremy L Thompson 
887*75f0d5a4SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
888*75f0d5a4SJeremy L Thompson 
889*75f0d5a4SJeremy L Thompson   @ref Backend
890*75f0d5a4SJeremy L Thompson **/
891*75f0d5a4SJeremy L Thompson 
892*75f0d5a4SJeremy L Thompson int CeedOperatorGetSubList(CeedOperator op, CeedOperator **sub_operators) {
893*75f0d5a4SJeremy L Thompson   if (!op->is_composite) {
894*75f0d5a4SJeremy L Thompson     // LCOV_EXCL_START
895*75f0d5a4SJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MINOR, "Not a composite operator");
896*75f0d5a4SJeremy L Thompson     // LCOV_EXCL_STOP
897*75f0d5a4SJeremy L Thompson   }
898*75f0d5a4SJeremy L Thompson   *sub_operators = op->sub_operators;
899*75f0d5a4SJeremy L Thompson   return CEED_ERROR_SUCCESS;
900*75f0d5a4SJeremy L Thompson }
901*75f0d5a4SJeremy L Thompson 
902*75f0d5a4SJeremy L Thompson /**
9034db537f9SJeremy L Thompson   @brief Check if a CeedOperator is ready to be used.
9044db537f9SJeremy L Thompson 
9054db537f9SJeremy L Thompson   @param[in] op CeedOperator to check
9064db537f9SJeremy L Thompson 
9074db537f9SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
9084db537f9SJeremy L Thompson 
9094db537f9SJeremy L Thompson   @ref User
9104db537f9SJeremy L Thompson **/
9114db537f9SJeremy L Thompson int CeedOperatorCheckReady(CeedOperator op) {
9124db537f9SJeremy L Thompson   Ceed ceed;
9132b730f8bSJeremy L Thompson   CeedCall(CeedOperatorGetCeed(op, &ceed));
9144db537f9SJeremy L Thompson 
9152b730f8bSJeremy L Thompson   if (op->is_interface_setup) return CEED_ERROR_SUCCESS;
9164db537f9SJeremy L Thompson 
9174db537f9SJeremy L Thompson   CeedQFunction qf = op->qf;
9184db537f9SJeremy L Thompson   if (op->is_composite) {
91943622462SJeremy L Thompson     if (!op->num_suboperators) {
92043622462SJeremy L Thompson       // Empty operator setup
92143622462SJeremy L Thompson       op->input_size  = 0;
92243622462SJeremy L Thompson       op->output_size = 0;
92343622462SJeremy L Thompson     } else {
9244db537f9SJeremy L Thompson       for (CeedInt i = 0; i < op->num_suboperators; i++) {
9252b730f8bSJeremy L Thompson         CeedCall(CeedOperatorCheckReady(op->sub_operators[i]));
9264db537f9SJeremy L Thompson       }
9272b104005SJeremy L Thompson       // Sub-operators could be modified after adding to composite operator
9282b104005SJeremy L Thompson       // Need to verify no lvec incompatibility from any changes
9292b104005SJeremy L Thompson       CeedSize input_size, output_size;
9302b730f8bSJeremy L Thompson       CeedCall(CeedOperatorGetActiveVectorLengths(op, &input_size, &output_size));
93143622462SJeremy L Thompson     }
9324db537f9SJeremy L Thompson   } else {
9332b730f8bSJeremy L Thompson     if (op->num_fields == 0) {
9344db537f9SJeremy L Thompson       // LCOV_EXCL_START
9354db537f9SJeremy L Thompson       return CeedError(ceed, CEED_ERROR_INCOMPLETE, "No operator fields set");
9364db537f9SJeremy L Thompson       // LCOV_EXCL_STOP
9372b730f8bSJeremy L Thompson     }
9382b730f8bSJeremy L Thompson     if (op->num_fields < qf->num_input_fields + qf->num_output_fields) {
9394db537f9SJeremy L Thompson       // LCOV_EXCL_START
9404db537f9SJeremy L Thompson       return CeedError(ceed, CEED_ERROR_INCOMPLETE, "Not all operator fields set");
9414db537f9SJeremy L Thompson       // LCOV_EXCL_STOP
9422b730f8bSJeremy L Thompson     }
9432b730f8bSJeremy L Thompson     if (!op->has_restriction) {
9444db537f9SJeremy L Thompson       // LCOV_EXCL_START
9452b730f8bSJeremy L Thompson       return CeedError(ceed, CEED_ERROR_INCOMPLETE, "At least one restriction required");
9464db537f9SJeremy L Thompson       // LCOV_EXCL_STOP
9472b730f8bSJeremy L Thompson     }
9482b730f8bSJeremy L Thompson     if (op->num_qpts == 0) {
9494db537f9SJeremy L Thompson       // LCOV_EXCL_START
9502b730f8bSJeremy L Thompson       return CeedError(ceed, CEED_ERROR_INCOMPLETE, "At least one non-collocated basis is required or the number of quadrature points must be set");
9514db537f9SJeremy L Thompson       // LCOV_EXCL_STOP
9524db537f9SJeremy L Thompson     }
9532b730f8bSJeremy L Thompson   }
9544db537f9SJeremy L Thompson 
9554db537f9SJeremy L Thompson   // Flag as immutable and ready
9564db537f9SJeremy L Thompson   op->is_interface_setup = true;
9572b730f8bSJeremy L Thompson   if (op->qf && op->qf != CEED_QFUNCTION_NONE) op->qf->is_immutable = true;
9582b730f8bSJeremy L Thompson   if (op->dqf && op->dqf != CEED_QFUNCTION_NONE) op->dqf->is_immutable = true;
9592b730f8bSJeremy L Thompson   if (op->dqfT && op->dqfT != CEED_QFUNCTION_NONE) op->dqfT->is_immutable = true;
9604db537f9SJeremy L Thompson   return CEED_ERROR_SUCCESS;
9614db537f9SJeremy L Thompson }
9624db537f9SJeremy L Thompson 
9634db537f9SJeremy L Thompson /**
964c9366a6bSJeremy L Thompson   @brief Get vector lengths for the active input and/or output vectors of a CeedOperator.
965ea61e9acSJeremy L Thompson            Note: Lengths of -1 indicate that the CeedOperator does not have an active input and/or output.
966c9366a6bSJeremy L Thompson 
967c9366a6bSJeremy L Thompson   @param[in]  op          CeedOperator
968c9366a6bSJeremy L Thompson   @param[out] input_size  Variable to store active input vector length, or NULL
969c9366a6bSJeremy L Thompson   @param[out] output_size Variable to store active output vector length, or NULL
970c9366a6bSJeremy L Thompson 
971c9366a6bSJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
972c9366a6bSJeremy L Thompson 
973c9366a6bSJeremy L Thompson   @ref User
974c9366a6bSJeremy L Thompson **/
9752b730f8bSJeremy L Thompson int CeedOperatorGetActiveVectorLengths(CeedOperator op, CeedSize *input_size, CeedSize *output_size) {
976c9366a6bSJeremy L Thompson   bool is_composite;
977c9366a6bSJeremy L Thompson 
9782b104005SJeremy L Thompson   if (input_size) *input_size = op->input_size;
9792b104005SJeremy L Thompson   if (output_size) *output_size = op->output_size;
980c9366a6bSJeremy L Thompson 
9812b730f8bSJeremy L Thompson   CeedCall(CeedOperatorIsComposite(op, &is_composite));
9822b104005SJeremy L Thompson   if (is_composite && (op->input_size == -1 || op->output_size == -1)) {
983c9366a6bSJeremy L Thompson     for (CeedInt i = 0; i < op->num_suboperators; i++) {
984c9366a6bSJeremy L Thompson       CeedSize sub_input_size, sub_output_size;
9852b730f8bSJeremy L Thompson       CeedCall(CeedOperatorGetActiveVectorLengths(op->sub_operators[i], &sub_input_size, &sub_output_size));
9862b104005SJeremy L Thompson       if (op->input_size == -1) op->input_size = sub_input_size;
9872b104005SJeremy L Thompson       if (op->output_size == -1) op->output_size = sub_output_size;
9882b104005SJeremy L Thompson       // Note, a size of -1 means no active vector restriction set, so no incompatibility
9892b730f8bSJeremy L Thompson       if ((sub_input_size != -1 && sub_input_size != op->input_size) || (sub_output_size != -1 && sub_output_size != op->output_size)) {
9902b104005SJeremy L Thompson         // LCOV_EXCL_START
9912b104005SJeremy L Thompson         return CeedError(op->ceed, CEED_ERROR_MAJOR,
9922b730f8bSJeremy L Thompson                          "Sub-operators must have compatible dimensions; composite operator of shape (%td, %td) not compatible with sub-operator of "
9932b730f8bSJeremy L Thompson                          "shape (%td, %td)",
9942b104005SJeremy L Thompson                          op->input_size, op->output_size, input_size, output_size);
9952b104005SJeremy L Thompson         // LCOV_EXCL_STOP
996c9366a6bSJeremy L Thompson       }
997c9366a6bSJeremy L Thompson     }
9982b730f8bSJeremy L Thompson   }
999c9366a6bSJeremy L Thompson 
1000c9366a6bSJeremy L Thompson   return CEED_ERROR_SUCCESS;
1001c9366a6bSJeremy L Thompson }
1002c9366a6bSJeremy L Thompson 
1003c9366a6bSJeremy L Thompson /**
1004beecbf24SJeremy L Thompson   @brief Set reuse of CeedQFunction data in CeedOperatorLinearAssemble* functions.
1005ea61e9acSJeremy L Thompson            When `reuse_assembly_data = false` (default), the CeedQFunction associated with this CeedOperator is re-assembled every time a
1006ea61e9acSJeremy L Thompson `CeedOperatorLinearAssemble*` function is called. When `reuse_assembly_data = true`, the CeedQFunction associated with this CeedOperator is reused
1007ea61e9acSJeremy L Thompson between calls to `CeedOperatorSetQFunctionAssemblyDataUpdated`.
10088b919e6bSJeremy L Thompson 
1009beecbf24SJeremy L Thompson   @param[in] op                  CeedOperator
1010beecbf24SJeremy L Thompson   @param[in] reuse_assembly_data Boolean flag setting assembly data reuse
10118b919e6bSJeremy L Thompson 
10128b919e6bSJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
10138b919e6bSJeremy L Thompson 
10148b919e6bSJeremy L Thompson   @ref Advanced
10158b919e6bSJeremy L Thompson **/
10162b730f8bSJeremy L Thompson int CeedOperatorSetQFunctionAssemblyReuse(CeedOperator op, bool reuse_assembly_data) {
10178b919e6bSJeremy L Thompson   bool is_composite;
10188b919e6bSJeremy L Thompson 
10192b730f8bSJeremy L Thompson   CeedCall(CeedOperatorIsComposite(op, &is_composite));
10208b919e6bSJeremy L Thompson   if (is_composite) {
10218b919e6bSJeremy L Thompson     for (CeedInt i = 0; i < op->num_suboperators; i++) {
10222b730f8bSJeremy L Thompson       CeedCall(CeedOperatorSetQFunctionAssemblyReuse(op->sub_operators[i], reuse_assembly_data));
10238b919e6bSJeremy L Thompson     }
10248b919e6bSJeremy L Thompson   } else {
10252b730f8bSJeremy L Thompson     CeedCall(CeedQFunctionAssemblyDataSetReuse(op->qf_assembled, reuse_assembly_data));
1026beecbf24SJeremy L Thompson   }
1027beecbf24SJeremy L Thompson 
1028beecbf24SJeremy L Thompson   return CEED_ERROR_SUCCESS;
1029beecbf24SJeremy L Thompson }
1030beecbf24SJeremy L Thompson 
1031beecbf24SJeremy L Thompson /**
1032beecbf24SJeremy L Thompson   @brief Mark CeedQFunction data as updated and the CeedQFunction as requiring re-assembly.
1033beecbf24SJeremy L Thompson 
1034beecbf24SJeremy L Thompson   @param[in] op                CeedOperator
10356e15d496SJeremy L Thompson   @param[in] needs_data_update Boolean flag setting assembly data reuse
1036beecbf24SJeremy L Thompson 
1037beecbf24SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
1038beecbf24SJeremy L Thompson 
1039beecbf24SJeremy L Thompson   @ref Advanced
1040beecbf24SJeremy L Thompson **/
10412b730f8bSJeremy L Thompson int CeedOperatorSetQFunctionAssemblyDataUpdateNeeded(CeedOperator op, bool needs_data_update) {
1042beecbf24SJeremy L Thompson   bool is_composite;
1043beecbf24SJeremy L Thompson 
10442b730f8bSJeremy L Thompson   CeedCall(CeedOperatorIsComposite(op, &is_composite));
1045beecbf24SJeremy L Thompson   if (is_composite) {
1046beecbf24SJeremy L Thompson     for (CeedInt i = 0; i < op->num_suboperators; i++) {
10472b730f8bSJeremy L Thompson       CeedCall(CeedOperatorSetQFunctionAssemblyDataUpdateNeeded(op->sub_operators[i], needs_data_update));
1048beecbf24SJeremy L Thompson     }
1049beecbf24SJeremy L Thompson   } else {
10502b730f8bSJeremy L Thompson     CeedCall(CeedQFunctionAssemblyDataSetUpdateNeeded(op->qf_assembled, needs_data_update));
10518b919e6bSJeremy L Thompson   }
10528b919e6bSJeremy L Thompson 
10538b919e6bSJeremy L Thompson   return CEED_ERROR_SUCCESS;
10548b919e6bSJeremy L Thompson }
10558b919e6bSJeremy L Thompson 
10568b919e6bSJeremy L Thompson /**
1057cd4dfc48Sjeremylt   @brief Set the number of quadrature points associated with a CeedOperator.
1058ea61e9acSJeremy L Thompson            This should be used when creating a CeedOperator where every field has a collocated basis.
1059ea61e9acSJeremy L Thompson            This function cannot be used for composite CeedOperators.
1060cd4dfc48Sjeremylt 
1061ea61e9acSJeremy L Thompson   @param[in,out] op       CeedOperator
1062ea61e9acSJeremy L Thompson   @param[in]     num_qpts Number of quadrature points to set
1063cd4dfc48Sjeremylt 
1064cd4dfc48Sjeremylt   @return An error code: 0 - success, otherwise - failure
1065cd4dfc48Sjeremylt 
1066e9b533fbSJeremy L Thompson   @ref Advanced
1067cd4dfc48Sjeremylt **/
1068cd4dfc48Sjeremylt int CeedOperatorSetNumQuadraturePoints(CeedOperator op, CeedInt num_qpts) {
10692b730f8bSJeremy L Thompson   if (op->is_composite) {
1070cd4dfc48Sjeremylt     // LCOV_EXCL_START
10712b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MINOR, "Not defined for composite operator");
1072cd4dfc48Sjeremylt     // LCOV_EXCL_STOP
10732b730f8bSJeremy L Thompson   }
10742b730f8bSJeremy L Thompson   if (op->num_qpts) {
1075cd4dfc48Sjeremylt     // LCOV_EXCL_START
10762b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MINOR, "Number of quadrature points already defined");
1077cd4dfc48Sjeremylt     // LCOV_EXCL_STOP
10782b730f8bSJeremy L Thompson   }
10792b730f8bSJeremy L Thompson   if (op->is_immutable) {
1080f04ea552SJeremy L Thompson     // LCOV_EXCL_START
10812b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable");
1082f04ea552SJeremy L Thompson     // LCOV_EXCL_STOP
10832b730f8bSJeremy L Thompson   }
1084cd4dfc48Sjeremylt   op->num_qpts = num_qpts;
1085cd4dfc48Sjeremylt   return CEED_ERROR_SUCCESS;
1086cd4dfc48Sjeremylt }
1087cd4dfc48Sjeremylt 
1088cd4dfc48Sjeremylt /**
1089ea6b5821SJeremy L Thompson   @brief Set name of CeedOperator for CeedOperatorView output
1090ea6b5821SJeremy L Thompson 
1091ea61e9acSJeremy L Thompson   @param[in,out] op   CeedOperator
1092ea61e9acSJeremy L Thompson   @param[in]     name Name to set, or NULL to remove previously set name
1093ea6b5821SJeremy L Thompson 
1094ea6b5821SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
1095ea6b5821SJeremy L Thompson 
1096ea6b5821SJeremy L Thompson   @ref User
1097ea6b5821SJeremy L Thompson **/
1098ea6b5821SJeremy L Thompson int CeedOperatorSetName(CeedOperator op, const char *name) {
1099ea6b5821SJeremy L Thompson   char  *name_copy;
1100ea6b5821SJeremy L Thompson   size_t name_len = name ? strlen(name) : 0;
1101ea6b5821SJeremy L Thompson 
11022b730f8bSJeremy L Thompson   CeedCall(CeedFree(&op->name));
1103ea6b5821SJeremy L Thompson   if (name_len > 0) {
11042b730f8bSJeremy L Thompson     CeedCall(CeedCalloc(name_len + 1, &name_copy));
1105ea6b5821SJeremy L Thompson     memcpy(name_copy, name, name_len);
1106ea6b5821SJeremy L Thompson     op->name = name_copy;
1107ea6b5821SJeremy L Thompson   }
1108ea6b5821SJeremy L Thompson 
1109ea6b5821SJeremy L Thompson   return CEED_ERROR_SUCCESS;
1110ea6b5821SJeremy L Thompson }
1111ea6b5821SJeremy L Thompson 
1112ea6b5821SJeremy L Thompson /**
11137a982d89SJeremy L. Thompson   @brief View a CeedOperator
11147a982d89SJeremy L. Thompson 
11157a982d89SJeremy L. Thompson   @param[in] op     CeedOperator to view
11167a982d89SJeremy L. Thompson   @param[in] stream Stream to write; typically stdout/stderr or a file
11177a982d89SJeremy L. Thompson 
11187a982d89SJeremy L. Thompson   @return Error code: 0 - success, otherwise - failure
11197a982d89SJeremy L. Thompson 
11207a982d89SJeremy L. Thompson   @ref User
11217a982d89SJeremy L. Thompson **/
11227a982d89SJeremy L. Thompson int CeedOperatorView(CeedOperator op, FILE *stream) {
1123ea6b5821SJeremy L Thompson   bool has_name = op->name;
11247a982d89SJeremy L. Thompson 
1125f04ea552SJeremy L Thompson   if (op->is_composite) {
11262b730f8bSJeremy L Thompson     fprintf(stream, "Composite CeedOperator%s%s\n", has_name ? " - " : "", has_name ? op->name : "");
11277a982d89SJeremy L. Thompson 
1128d1d35e2fSjeremylt     for (CeedInt i = 0; i < op->num_suboperators; i++) {
1129ea6b5821SJeremy L Thompson       has_name = op->sub_operators[i]->name;
11302b730f8bSJeremy L Thompson       fprintf(stream, "  SubOperator %" CeedInt_FMT "%s%s:\n", i, has_name ? " - " : "", has_name ? op->sub_operators[i]->name : "");
11312b730f8bSJeremy L Thompson       CeedCall(CeedOperatorSingleView(op->sub_operators[i], 1, stream));
11327a982d89SJeremy L. Thompson     }
11337a982d89SJeremy L. Thompson   } else {
11342b730f8bSJeremy L Thompson     fprintf(stream, "CeedOperator%s%s\n", has_name ? " - " : "", has_name ? op->name : "");
11352b730f8bSJeremy L Thompson     CeedCall(CeedOperatorSingleView(op, 0, stream));
11367a982d89SJeremy L. Thompson   }
1137e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
11387a982d89SJeremy L. Thompson }
11393bd813ffSjeremylt 
11403bd813ffSjeremylt /**
1141b7c9bbdaSJeremy L Thompson   @brief Get the Ceed associated with a CeedOperator
1142b7c9bbdaSJeremy L Thompson 
1143ea61e9acSJeremy L Thompson   @param[in]  op   CeedOperator
1144b7c9bbdaSJeremy L Thompson   @param[out] ceed Variable to store Ceed
1145b7c9bbdaSJeremy L Thompson 
1146b7c9bbdaSJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
1147b7c9bbdaSJeremy L Thompson 
1148b7c9bbdaSJeremy L Thompson   @ref Advanced
1149b7c9bbdaSJeremy L Thompson **/
1150b7c9bbdaSJeremy L Thompson int CeedOperatorGetCeed(CeedOperator op, Ceed *ceed) {
1151b7c9bbdaSJeremy L Thompson   *ceed = op->ceed;
1152b7c9bbdaSJeremy L Thompson   return CEED_ERROR_SUCCESS;
1153b7c9bbdaSJeremy L Thompson }
1154b7c9bbdaSJeremy L Thompson 
1155b7c9bbdaSJeremy L Thompson /**
1156b7c9bbdaSJeremy L Thompson   @brief Get the number of elements associated with a CeedOperator
1157b7c9bbdaSJeremy L Thompson 
1158ea61e9acSJeremy L Thompson   @param[in]  op       CeedOperator
1159b7c9bbdaSJeremy L Thompson   @param[out] num_elem Variable to store number of elements
1160b7c9bbdaSJeremy L Thompson 
1161b7c9bbdaSJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
1162b7c9bbdaSJeremy L Thompson 
1163b7c9bbdaSJeremy L Thompson   @ref Advanced
1164b7c9bbdaSJeremy L Thompson **/
1165b7c9bbdaSJeremy L Thompson int CeedOperatorGetNumElements(CeedOperator op, CeedInt *num_elem) {
11662b730f8bSJeremy L Thompson   if (op->is_composite) {
1167b7c9bbdaSJeremy L Thompson     // LCOV_EXCL_START
11682b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MINOR, "Not defined for composite operator");
1169b7c9bbdaSJeremy L Thompson     // LCOV_EXCL_STOP
11702b730f8bSJeremy L Thompson   }
1171b7c9bbdaSJeremy L Thompson   *num_elem = op->num_elem;
1172b7c9bbdaSJeremy L Thompson   return CEED_ERROR_SUCCESS;
1173b7c9bbdaSJeremy L Thompson }
1174b7c9bbdaSJeremy L Thompson 
1175b7c9bbdaSJeremy L Thompson /**
1176b7c9bbdaSJeremy L Thompson   @brief Get the number of quadrature points associated with a CeedOperator
1177b7c9bbdaSJeremy L Thompson 
1178ea61e9acSJeremy L Thompson   @param[in]  op       CeedOperator
1179b7c9bbdaSJeremy L Thompson   @param[out] num_qpts Variable to store vector number of quadrature points
1180b7c9bbdaSJeremy L Thompson 
1181b7c9bbdaSJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
1182b7c9bbdaSJeremy L Thompson 
1183b7c9bbdaSJeremy L Thompson   @ref Advanced
1184b7c9bbdaSJeremy L Thompson **/
1185b7c9bbdaSJeremy L Thompson int CeedOperatorGetNumQuadraturePoints(CeedOperator op, CeedInt *num_qpts) {
11862b730f8bSJeremy L Thompson   if (op->is_composite) {
1187b7c9bbdaSJeremy L Thompson     // LCOV_EXCL_START
11882b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MINOR, "Not defined for composite operator");
1189b7c9bbdaSJeremy L Thompson     // LCOV_EXCL_STOP
11902b730f8bSJeremy L Thompson   }
1191b7c9bbdaSJeremy L Thompson   *num_qpts = op->num_qpts;
1192b7c9bbdaSJeremy L Thompson   return CEED_ERROR_SUCCESS;
1193b7c9bbdaSJeremy L Thompson }
1194b7c9bbdaSJeremy L Thompson 
1195b7c9bbdaSJeremy L Thompson /**
11966e15d496SJeremy L Thompson   @brief Estimate number of FLOPs required to apply CeedOperator on the active vector
11976e15d496SJeremy L Thompson 
1198ea61e9acSJeremy L Thompson   @param[in]  op    CeedOperator to estimate FLOPs for
1199ea61e9acSJeremy L Thompson   @param[out] flops Address of variable to hold FLOPs estimate
12006e15d496SJeremy L Thompson 
12016e15d496SJeremy L Thompson   @ref Backend
12026e15d496SJeremy L Thompson **/
12039d36ca50SJeremy L Thompson int CeedOperatorGetFlopsEstimate(CeedOperator op, CeedSize *flops) {
12046e15d496SJeremy L Thompson   bool is_composite;
12052b730f8bSJeremy L Thompson   CeedCall(CeedOperatorCheckReady(op));
12066e15d496SJeremy L Thompson 
12076e15d496SJeremy L Thompson   *flops = 0;
12082b730f8bSJeremy L Thompson   CeedCall(CeedOperatorIsComposite(op, &is_composite));
12096e15d496SJeremy L Thompson   if (is_composite) {
12106e15d496SJeremy L Thompson     CeedInt num_suboperators;
12112b730f8bSJeremy L Thompson     CeedCall(CeedOperatorGetNumSub(op, &num_suboperators));
12126e15d496SJeremy L Thompson     CeedOperator *sub_operators;
12132b730f8bSJeremy L Thompson     CeedCall(CeedOperatorGetSubList(op, &sub_operators));
12146e15d496SJeremy L Thompson 
12156e15d496SJeremy L Thompson     // FLOPs for each suboperator
12166e15d496SJeremy L Thompson     for (CeedInt i = 0; i < num_suboperators; i++) {
12179d36ca50SJeremy L Thompson       CeedSize suboperator_flops;
12182b730f8bSJeremy L Thompson       CeedCall(CeedOperatorGetFlopsEstimate(sub_operators[i], &suboperator_flops));
12196e15d496SJeremy L Thompson       *flops += suboperator_flops;
12206e15d496SJeremy L Thompson     }
12216e15d496SJeremy L Thompson   } else {
12226e15d496SJeremy L Thompson     CeedInt            num_input_fields, num_output_fields;
12236e15d496SJeremy L Thompson     CeedOperatorField *input_fields, *output_fields;
12246e15d496SJeremy L Thompson 
12252b730f8bSJeremy L Thompson     CeedCall(CeedOperatorGetFields(op, &num_input_fields, &input_fields, &num_output_fields, &output_fields));
12266e15d496SJeremy L Thompson 
12276e15d496SJeremy L Thompson     CeedInt num_elem = 0;
12282b730f8bSJeremy L Thompson     CeedCall(CeedOperatorGetNumElements(op, &num_elem));
12296e15d496SJeremy L Thompson     // Input FLOPs
12306e15d496SJeremy L Thompson     for (CeedInt i = 0; i < num_input_fields; i++) {
12316e15d496SJeremy L Thompson       if (input_fields[i]->vec == CEED_VECTOR_ACTIVE) {
12329d36ca50SJeremy L Thompson         CeedSize restr_flops, basis_flops;
12336e15d496SJeremy L Thompson 
12342b730f8bSJeremy L Thompson         CeedCall(CeedElemRestrictionGetFlopsEstimate(input_fields[i]->elem_restr, CEED_NOTRANSPOSE, &restr_flops));
12356e15d496SJeremy L Thompson         *flops += restr_flops;
12362b730f8bSJeremy L Thompson         CeedCall(CeedBasisGetFlopsEstimate(input_fields[i]->basis, CEED_NOTRANSPOSE, op->qf->input_fields[i]->eval_mode, &basis_flops));
12376e15d496SJeremy L Thompson         *flops += basis_flops * num_elem;
12386e15d496SJeremy L Thompson       }
12396e15d496SJeremy L Thompson     }
12406e15d496SJeremy L Thompson     // QF FLOPs
12419d36ca50SJeremy L Thompson     CeedInt  num_qpts;
12429d36ca50SJeremy L Thompson     CeedSize qf_flops;
12432b730f8bSJeremy L Thompson     CeedCall(CeedOperatorGetNumQuadraturePoints(op, &num_qpts));
12442b730f8bSJeremy L Thompson     CeedCall(CeedQFunctionGetFlopsEstimate(op->qf, &qf_flops));
12456e15d496SJeremy L Thompson     *flops += num_elem * num_qpts * qf_flops;
12466e15d496SJeremy L Thompson     // Output FLOPs
12476e15d496SJeremy L Thompson     for (CeedInt i = 0; i < num_output_fields; i++) {
12486e15d496SJeremy L Thompson       if (output_fields[i]->vec == CEED_VECTOR_ACTIVE) {
12499d36ca50SJeremy L Thompson         CeedSize restr_flops, basis_flops;
12506e15d496SJeremy L Thompson 
12512b730f8bSJeremy L Thompson         CeedCall(CeedElemRestrictionGetFlopsEstimate(output_fields[i]->elem_restr, CEED_TRANSPOSE, &restr_flops));
12526e15d496SJeremy L Thompson         *flops += restr_flops;
12532b730f8bSJeremy L Thompson         CeedCall(CeedBasisGetFlopsEstimate(output_fields[i]->basis, CEED_TRANSPOSE, op->qf->output_fields[i]->eval_mode, &basis_flops));
12546e15d496SJeremy L Thompson         *flops += basis_flops * num_elem;
12556e15d496SJeremy L Thompson       }
12566e15d496SJeremy L Thompson     }
12576e15d496SJeremy L Thompson   }
12586e15d496SJeremy L Thompson 
12596e15d496SJeremy L Thompson   return CEED_ERROR_SUCCESS;
12606e15d496SJeremy L Thompson }
12616e15d496SJeremy L Thompson 
12626e15d496SJeremy L Thompson /**
1263ea61e9acSJeremy L Thompson   @brief Get label for a registered QFunctionContext field, or `NULL` if no field has been registered with this `field_name`.
12643668ca4bSJeremy L Thompson 
12653668ca4bSJeremy L Thompson   @param[in]  op          CeedOperator
12663668ca4bSJeremy L Thompson   @param[in]  field_name  Name of field to retrieve label
12673668ca4bSJeremy L Thompson   @param[out] field_label Variable to field label
12683668ca4bSJeremy L Thompson 
12693668ca4bSJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
12703668ca4bSJeremy L Thompson 
12713668ca4bSJeremy L Thompson   @ref User
12723668ca4bSJeremy L Thompson **/
12732b730f8bSJeremy L Thompson int CeedOperatorContextGetFieldLabel(CeedOperator op, const char *field_name, CeedContextFieldLabel *field_label) {
12743668ca4bSJeremy L Thompson   bool is_composite;
12752b730f8bSJeremy L Thompson   CeedCall(CeedOperatorIsComposite(op, &is_composite));
12762b730f8bSJeremy L Thompson 
12773668ca4bSJeremy L Thompson   if (is_composite) {
12783668ca4bSJeremy L Thompson     // Check if composite label already created
12793668ca4bSJeremy L Thompson     for (CeedInt i = 0; i < op->num_context_labels; i++) {
12803668ca4bSJeremy L Thompson       if (!strcmp(op->context_labels[i]->name, field_name)) {
12813668ca4bSJeremy L Thompson         *field_label = op->context_labels[i];
12823668ca4bSJeremy L Thompson         return CEED_ERROR_SUCCESS;
12833668ca4bSJeremy L Thompson       }
12843668ca4bSJeremy L Thompson     }
12853668ca4bSJeremy L Thompson 
12863668ca4bSJeremy L Thompson     // Create composite label if needed
12873668ca4bSJeremy L Thompson     CeedInt               num_sub;
12883668ca4bSJeremy L Thompson     CeedOperator         *sub_operators;
12893668ca4bSJeremy L Thompson     CeedContextFieldLabel new_field_label;
12903668ca4bSJeremy L Thompson 
12912b730f8bSJeremy L Thompson     CeedCall(CeedCalloc(1, &new_field_label));
12922b730f8bSJeremy L Thompson     CeedCall(CeedOperatorGetNumSub(op, &num_sub));
12932b730f8bSJeremy L Thompson     CeedCall(CeedOperatorGetSubList(op, &sub_operators));
12942b730f8bSJeremy L Thompson     CeedCall(CeedCalloc(num_sub, &new_field_label->sub_labels));
12953668ca4bSJeremy L Thompson     new_field_label->num_sub_labels = num_sub;
12963668ca4bSJeremy L Thompson 
12973668ca4bSJeremy L Thompson     bool label_found = false;
12983668ca4bSJeremy L Thompson     for (CeedInt i = 0; i < num_sub; i++) {
12993668ca4bSJeremy L Thompson       if (sub_operators[i]->qf->ctx) {
13003668ca4bSJeremy L Thompson         CeedContextFieldLabel new_field_label_i;
13012b730f8bSJeremy L Thompson         CeedCall(CeedQFunctionContextGetFieldLabel(sub_operators[i]->qf->ctx, field_name, &new_field_label_i));
13023668ca4bSJeremy L Thompson         if (new_field_label_i) {
13033668ca4bSJeremy L Thompson           label_found                    = true;
13043668ca4bSJeremy L Thompson           new_field_label->sub_labels[i] = new_field_label_i;
13053668ca4bSJeremy L Thompson           new_field_label->name          = new_field_label_i->name;
13063668ca4bSJeremy L Thompson           new_field_label->description   = new_field_label_i->description;
13072b730f8bSJeremy L Thompson           if (new_field_label->type && new_field_label->type != new_field_label_i->type) {
13087bfe0f0eSJeremy L Thompson             // LCOV_EXCL_START
13092b730f8bSJeremy L Thompson             CeedCall(CeedFree(&new_field_label));
13102b730f8bSJeremy L Thompson             return CeedError(op->ceed, CEED_ERROR_INCOMPATIBLE, "Incompatible field types on sub-operator contexts. %s != %s",
13112b730f8bSJeremy L Thompson                              CeedContextFieldTypes[new_field_label->type], CeedContextFieldTypes[new_field_label_i->type]);
13127bfe0f0eSJeremy L Thompson             // LCOV_EXCL_STOP
13137bfe0f0eSJeremy L Thompson           } else {
13147bfe0f0eSJeremy L Thompson             new_field_label->type = new_field_label_i->type;
13157bfe0f0eSJeremy L Thompson           }
13162b730f8bSJeremy L Thompson           if (new_field_label->num_values != 0 && new_field_label->num_values != new_field_label_i->num_values) {
13177bfe0f0eSJeremy L Thompson             // LCOV_EXCL_START
13182b730f8bSJeremy L Thompson             CeedCall(CeedFree(&new_field_label));
13192b730f8bSJeremy L Thompson             return CeedError(op->ceed, CEED_ERROR_INCOMPATIBLE, "Incompatible field number of values on sub-operator contexts. %ld != %ld",
13207bfe0f0eSJeremy L Thompson                              new_field_label->num_values, new_field_label_i->num_values);
13217bfe0f0eSJeremy L Thompson             // LCOV_EXCL_STOP
13227bfe0f0eSJeremy L Thompson           } else {
13237bfe0f0eSJeremy L Thompson             new_field_label->num_values = new_field_label_i->num_values;
13247bfe0f0eSJeremy L Thompson           }
13253668ca4bSJeremy L Thompson         }
13263668ca4bSJeremy L Thompson       }
13273668ca4bSJeremy L Thompson     }
13283668ca4bSJeremy L Thompson     if (!label_found) {
13293668ca4bSJeremy L Thompson       // LCOV_EXCL_START
13302b730f8bSJeremy L Thompson       CeedCall(CeedFree(&new_field_label->sub_labels));
13312b730f8bSJeremy L Thompson       CeedCall(CeedFree(&new_field_label));
13323668ca4bSJeremy L Thompson       *field_label = NULL;
13333668ca4bSJeremy L Thompson       // LCOV_EXCL_STOP
13343668ca4bSJeremy L Thompson     } else {
13353668ca4bSJeremy L Thompson       // Move new composite label to operator
13363668ca4bSJeremy L Thompson       if (op->num_context_labels == 0) {
13372b730f8bSJeremy L Thompson         CeedCall(CeedCalloc(1, &op->context_labels));
13383668ca4bSJeremy L Thompson         op->max_context_labels = 1;
13393668ca4bSJeremy L Thompson       } else if (op->num_context_labels == op->max_context_labels) {
13402b730f8bSJeremy L Thompson         CeedCall(CeedRealloc(2 * op->num_context_labels, &op->context_labels));
13413668ca4bSJeremy L Thompson         op->max_context_labels *= 2;
13423668ca4bSJeremy L Thompson       }
13433668ca4bSJeremy L Thompson       op->context_labels[op->num_context_labels] = new_field_label;
13443668ca4bSJeremy L Thompson       *field_label                               = new_field_label;
13453668ca4bSJeremy L Thompson       op->num_context_labels++;
13463668ca4bSJeremy L Thompson     }
13473668ca4bSJeremy L Thompson 
13483668ca4bSJeremy L Thompson     return CEED_ERROR_SUCCESS;
13493668ca4bSJeremy L Thompson   } else {
13503668ca4bSJeremy L Thompson     return CeedQFunctionContextGetFieldLabel(op->qf->ctx, field_name, field_label);
13513668ca4bSJeremy L Thompson   }
13523668ca4bSJeremy L Thompson }
13533668ca4bSJeremy L Thompson 
13543668ca4bSJeremy L Thompson /**
1355d8dd9a91SJeremy L Thompson   @brief Set QFunctionContext field holding a double precision value.
1356ea61e9acSJeremy L Thompson            For composite operators, the value is set in all sub-operator QFunctionContexts that have a matching `field_name`.
1357d8dd9a91SJeremy L Thompson 
1358ea61e9acSJeremy L Thompson   @param[in,out] op          CeedOperator
1359ea61e9acSJeremy L Thompson   @param[in]     field_label Label of field to register
1360ea61e9acSJeremy L Thompson   @param[in]     values      Values to set
1361d8dd9a91SJeremy L Thompson 
1362d8dd9a91SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
1363d8dd9a91SJeremy L Thompson 
1364d8dd9a91SJeremy L Thompson   @ref User
1365d8dd9a91SJeremy L Thompson **/
13662b730f8bSJeremy L Thompson int CeedOperatorContextSetDouble(CeedOperator op, CeedContextFieldLabel field_label, double *values) {
13672b730f8bSJeremy L Thompson   return CeedOperatorContextSetGeneric(op, field_label, CEED_CONTEXT_FIELD_DOUBLE, values);
1368d8dd9a91SJeremy L Thompson }
1369d8dd9a91SJeremy L Thompson 
1370d8dd9a91SJeremy L Thompson /**
1371d8dd9a91SJeremy L Thompson   @brief Set QFunctionContext field holding an int32 value.
1372ea61e9acSJeremy L Thompson            For composite operators, the value is set in all sub-operator QFunctionContexts that have a matching `field_name`.
1373d8dd9a91SJeremy L Thompson 
1374ea61e9acSJeremy L Thompson   @param[in,out] op          CeedOperator
1375ea61e9acSJeremy L Thompson   @param[in]     field_label Label of field to set
1376ea61e9acSJeremy L Thompson   @param[in]     values      Values to set
1377d8dd9a91SJeremy L Thompson 
1378d8dd9a91SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
1379d8dd9a91SJeremy L Thompson 
1380d8dd9a91SJeremy L Thompson   @ref User
1381d8dd9a91SJeremy L Thompson **/
13822b730f8bSJeremy L Thompson int CeedOperatorContextSetInt32(CeedOperator op, CeedContextFieldLabel field_label, int *values) {
13832b730f8bSJeremy L Thompson   return CeedOperatorContextSetGeneric(op, field_label, CEED_CONTEXT_FIELD_INT32, values);
1384d8dd9a91SJeremy L Thompson }
1385d8dd9a91SJeremy L Thompson 
1386d8dd9a91SJeremy L Thompson /**
13873bd813ffSjeremylt   @brief Apply CeedOperator to a vector
1388d7b241e6Sjeremylt 
1389ea61e9acSJeremy L Thompson   This computes the action of the operator on the specified (active) input, yielding its (active) output.
1390ea61e9acSJeremy L Thompson   All inputs and outputs must be specified using CeedOperatorSetField().
1391d7b241e6Sjeremylt 
1392ea61e9acSJeremy L Thompson   Note: Calling this function asserts that setup is complete and sets the CeedOperator as immutable.
1393f04ea552SJeremy L Thompson 
1394ea61e9acSJeremy L Thompson   @param[in]  op      CeedOperator to apply
1395ea61e9acSJeremy L Thompson   @param[in]  in      CeedVector containing input state or @ref CEED_VECTOR_NONE if there are no active inputs
1396ea61e9acSJeremy L Thompson   @param[out] out     CeedVector to store result of applying operator (must be distinct from @a in) or @ref CEED_VECTOR_NONE if there are no active
1397ea61e9acSJeremy L Thompson outputs
1398ea61e9acSJeremy L Thompson   @param[in]  request Address of CeedRequest for non-blocking completion, else @ref CEED_REQUEST_IMMEDIATE
1399b11c1e72Sjeremylt 
1400b11c1e72Sjeremylt   @return An error code: 0 - success, otherwise - failure
1401dfdf5a53Sjeremylt 
14027a982d89SJeremy L. Thompson   @ref User
1403b11c1e72Sjeremylt **/
14042b730f8bSJeremy L Thompson int CeedOperatorApply(CeedOperator op, CeedVector in, CeedVector out, CeedRequest *request) {
14052b730f8bSJeremy L Thompson   CeedCall(CeedOperatorCheckReady(op));
1406d7b241e6Sjeremylt 
1407d1d35e2fSjeremylt   if (op->num_elem) {
1408250756a7Sjeremylt     // Standard Operator
1409cae8b89aSjeremylt     if (op->Apply) {
14102b730f8bSJeremy L Thompson       CeedCall(op->Apply(op, in, out, request));
1411cae8b89aSjeremylt     } else {
1412cae8b89aSjeremylt       // Zero all output vectors
1413250756a7Sjeremylt       CeedQFunction qf = op->qf;
1414d1d35e2fSjeremylt       for (CeedInt i = 0; i < qf->num_output_fields; i++) {
1415d1d35e2fSjeremylt         CeedVector vec = op->output_fields[i]->vec;
14162b730f8bSJeremy L Thompson         if (vec == CEED_VECTOR_ACTIVE) vec = out;
1417cae8b89aSjeremylt         if (vec != CEED_VECTOR_NONE) {
14182b730f8bSJeremy L Thompson           CeedCall(CeedVectorSetValue(vec, 0.0));
1419cae8b89aSjeremylt         }
1420cae8b89aSjeremylt       }
1421250756a7Sjeremylt       // Apply
14222b730f8bSJeremy L Thompson       CeedCall(op->ApplyAdd(op, in, out, request));
1423250756a7Sjeremylt     }
1424f04ea552SJeremy L Thompson   } else if (op->is_composite) {
1425250756a7Sjeremylt     // Composite Operator
1426250756a7Sjeremylt     if (op->ApplyComposite) {
14272b730f8bSJeremy L Thompson       CeedCall(op->ApplyComposite(op, in, out, request));
1428250756a7Sjeremylt     } else {
1429d1d35e2fSjeremylt       CeedInt num_suboperators;
14302b730f8bSJeremy L Thompson       CeedCall(CeedOperatorGetNumSub(op, &num_suboperators));
1431d1d35e2fSjeremylt       CeedOperator *sub_operators;
14322b730f8bSJeremy L Thompson       CeedCall(CeedOperatorGetSubList(op, &sub_operators));
1433250756a7Sjeremylt 
1434250756a7Sjeremylt       // Zero all output vectors
1435250756a7Sjeremylt       if (out != CEED_VECTOR_NONE) {
14362b730f8bSJeremy L Thompson         CeedCall(CeedVectorSetValue(out, 0.0));
1437cae8b89aSjeremylt       }
1438d1d35e2fSjeremylt       for (CeedInt i = 0; i < num_suboperators; i++) {
1439d1d35e2fSjeremylt         for (CeedInt j = 0; j < sub_operators[i]->qf->num_output_fields; j++) {
1440d1d35e2fSjeremylt           CeedVector vec = sub_operators[i]->output_fields[j]->vec;
1441250756a7Sjeremylt           if (vec != CEED_VECTOR_ACTIVE && vec != CEED_VECTOR_NONE) {
14422b730f8bSJeremy L Thompson             CeedCall(CeedVectorSetValue(vec, 0.0));
1443250756a7Sjeremylt           }
1444250756a7Sjeremylt         }
1445250756a7Sjeremylt       }
1446250756a7Sjeremylt       // Apply
1447d1d35e2fSjeremylt       for (CeedInt i = 0; i < op->num_suboperators; i++) {
14482b730f8bSJeremy L Thompson         CeedCall(CeedOperatorApplyAdd(op->sub_operators[i], in, out, request));
1449cae8b89aSjeremylt       }
1450cae8b89aSjeremylt     }
1451250756a7Sjeremylt   }
1452e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
1453cae8b89aSjeremylt }
1454cae8b89aSjeremylt 
1455cae8b89aSjeremylt /**
1456cae8b89aSjeremylt   @brief Apply CeedOperator to a vector and add result to output vector
1457cae8b89aSjeremylt 
1458ea61e9acSJeremy L Thompson   This computes the action of the operator on the specified (active) input, yielding its (active) output.
1459ea61e9acSJeremy L Thompson   All inputs and outputs must be specified using CeedOperatorSetField().
1460cae8b89aSjeremylt 
1461ea61e9acSJeremy L Thompson   @param[in]  op      CeedOperator to apply
1462ea61e9acSJeremy L Thompson   @param[in]  in      CeedVector containing input state or NULL if there are no active inputs
1463ea61e9acSJeremy L Thompson   @param[out] out     CeedVector to sum in result of applying operator (must be distinct from @a in) or NULL if there are no active outputs
1464ea61e9acSJeremy L Thompson   @param[in]  request Address of CeedRequest for non-blocking completion, else @ref CEED_REQUEST_IMMEDIATE
1465cae8b89aSjeremylt 
1466cae8b89aSjeremylt   @return An error code: 0 - success, otherwise - failure
1467cae8b89aSjeremylt 
14687a982d89SJeremy L. Thompson   @ref User
1469cae8b89aSjeremylt **/
14702b730f8bSJeremy L Thompson int CeedOperatorApplyAdd(CeedOperator op, CeedVector in, CeedVector out, CeedRequest *request) {
14712b730f8bSJeremy L Thompson   CeedCall(CeedOperatorCheckReady(op));
1472cae8b89aSjeremylt 
1473d1d35e2fSjeremylt   if (op->num_elem) {
1474250756a7Sjeremylt     // Standard Operator
14752b730f8bSJeremy L Thompson     CeedCall(op->ApplyAdd(op, in, out, request));
1476f04ea552SJeremy L Thompson   } else if (op->is_composite) {
1477250756a7Sjeremylt     // Composite Operator
1478250756a7Sjeremylt     if (op->ApplyAddComposite) {
14792b730f8bSJeremy L Thompson       CeedCall(op->ApplyAddComposite(op, in, out, request));
1480cae8b89aSjeremylt     } else {
1481d1d35e2fSjeremylt       CeedInt num_suboperators;
14822b730f8bSJeremy L Thompson       CeedCall(CeedOperatorGetNumSub(op, &num_suboperators));
1483d1d35e2fSjeremylt       CeedOperator *sub_operators;
14842b730f8bSJeremy L Thompson       CeedCall(CeedOperatorGetSubList(op, &sub_operators));
1485250756a7Sjeremylt 
1486d1d35e2fSjeremylt       for (CeedInt i = 0; i < num_suboperators; i++) {
14872b730f8bSJeremy L Thompson         CeedCall(CeedOperatorApplyAdd(sub_operators[i], in, out, request));
14881d7d2407SJeremy L Thompson       }
1489250756a7Sjeremylt     }
1490250756a7Sjeremylt   }
1491e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
1492d7b241e6Sjeremylt }
1493d7b241e6Sjeremylt 
1494d7b241e6Sjeremylt /**
1495b11c1e72Sjeremylt   @brief Destroy a CeedOperator
1496d7b241e6Sjeremylt 
1497ea61e9acSJeremy L Thompson   @param[in,out] op CeedOperator to destroy
1498b11c1e72Sjeremylt 
1499b11c1e72Sjeremylt   @return An error code: 0 - success, otherwise - failure
1500dfdf5a53Sjeremylt 
15017a982d89SJeremy L. Thompson   @ref User
1502b11c1e72Sjeremylt **/
1503d7b241e6Sjeremylt int CeedOperatorDestroy(CeedOperator *op) {
1504d1d35e2fSjeremylt   if (!*op || --(*op)->ref_count > 0) return CEED_ERROR_SUCCESS;
15052b730f8bSJeremy L Thompson   if ((*op)->Destroy) CeedCall((*op)->Destroy(*op));
15062b730f8bSJeremy L Thompson   CeedCall(CeedDestroy(&(*op)->ceed));
1507fe2413ffSjeremylt   // Free fields
15082b730f8bSJeremy L Thompson   for (CeedInt i = 0; i < (*op)->num_fields; i++) {
1509d1d35e2fSjeremylt     if ((*op)->input_fields[i]) {
1510d1d35e2fSjeremylt       if ((*op)->input_fields[i]->elem_restr != CEED_ELEMRESTRICTION_NONE) {
15112b730f8bSJeremy L Thompson         CeedCall(CeedElemRestrictionDestroy(&(*op)->input_fields[i]->elem_restr));
151215910d16Sjeremylt       }
1513d1d35e2fSjeremylt       if ((*op)->input_fields[i]->basis != CEED_BASIS_COLLOCATED) {
15142b730f8bSJeremy L Thompson         CeedCall(CeedBasisDestroy(&(*op)->input_fields[i]->basis));
151571352a93Sjeremylt       }
15162b730f8bSJeremy L Thompson       if ((*op)->input_fields[i]->vec != CEED_VECTOR_ACTIVE && (*op)->input_fields[i]->vec != CEED_VECTOR_NONE) {
15172b730f8bSJeremy L Thompson         CeedCall(CeedVectorDestroy(&(*op)->input_fields[i]->vec));
151871352a93Sjeremylt       }
15192b730f8bSJeremy L Thompson       CeedCall(CeedFree(&(*op)->input_fields[i]->field_name));
15202b730f8bSJeremy L Thompson       CeedCall(CeedFree(&(*op)->input_fields[i]));
1521fe2413ffSjeremylt     }
15222b730f8bSJeremy L Thompson   }
15232b730f8bSJeremy L Thompson   for (CeedInt i = 0; i < (*op)->num_fields; i++) {
1524d1d35e2fSjeremylt     if ((*op)->output_fields[i]) {
15252b730f8bSJeremy L Thompson       CeedCall(CeedElemRestrictionDestroy(&(*op)->output_fields[i]->elem_restr));
1526d1d35e2fSjeremylt       if ((*op)->output_fields[i]->basis != CEED_BASIS_COLLOCATED) {
15272b730f8bSJeremy L Thompson         CeedCall(CeedBasisDestroy(&(*op)->output_fields[i]->basis));
152871352a93Sjeremylt       }
15292b730f8bSJeremy L Thompson       if ((*op)->output_fields[i]->vec != CEED_VECTOR_ACTIVE && (*op)->output_fields[i]->vec != CEED_VECTOR_NONE) {
15302b730f8bSJeremy L Thompson         CeedCall(CeedVectorDestroy(&(*op)->output_fields[i]->vec));
153171352a93Sjeremylt       }
15322b730f8bSJeremy L Thompson       CeedCall(CeedFree(&(*op)->output_fields[i]->field_name));
15332b730f8bSJeremy L Thompson       CeedCall(CeedFree(&(*op)->output_fields[i]));
15342b730f8bSJeremy L Thompson     }
1535fe2413ffSjeremylt   }
1536d1d35e2fSjeremylt   // Destroy sub_operators
15372b730f8bSJeremy L Thompson   for (CeedInt i = 0; i < (*op)->num_suboperators; i++) {
1538d1d35e2fSjeremylt     if ((*op)->sub_operators[i]) {
15392b730f8bSJeremy L Thompson       CeedCall(CeedOperatorDestroy(&(*op)->sub_operators[i]));
154052d6035fSJeremy L Thompson     }
15412b730f8bSJeremy L Thompson   }
15422b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionDestroy(&(*op)->qf));
15432b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionDestroy(&(*op)->dqf));
15442b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionDestroy(&(*op)->dqfT));
15453668ca4bSJeremy L Thompson   // Destroy any composite labels
15463668ca4bSJeremy L Thompson   for (CeedInt i = 0; i < (*op)->num_context_labels; i++) {
15472b730f8bSJeremy L Thompson     CeedCall(CeedFree(&(*op)->context_labels[i]->sub_labels));
15482b730f8bSJeremy L Thompson     CeedCall(CeedFree(&(*op)->context_labels[i]));
15493668ca4bSJeremy L Thompson   }
15502b730f8bSJeremy L Thompson   CeedCall(CeedFree(&(*op)->context_labels));
1551fe2413ffSjeremylt 
15525107b09fSJeremy L Thompson   // Destroy fallback
15532b730f8bSJeremy L Thompson   CeedCall(CeedOperatorDestroy(&(*op)->op_fallback));
15545107b09fSJeremy L Thompson 
1555ed9e99e6SJeremy L Thompson   // Destroy assembly data
15562b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionAssemblyDataDestroy(&(*op)->qf_assembled));
15572b730f8bSJeremy L Thompson   CeedCall(CeedOperatorAssemblyDataDestroy(&(*op)->op_assembled));
155870a7ffb3SJeremy L Thompson 
15592b730f8bSJeremy L Thompson   CeedCall(CeedFree(&(*op)->input_fields));
15602b730f8bSJeremy L Thompson   CeedCall(CeedFree(&(*op)->output_fields));
15612b730f8bSJeremy L Thompson   CeedCall(CeedFree(&(*op)->sub_operators));
15622b730f8bSJeremy L Thompson   CeedCall(CeedFree(&(*op)->name));
15632b730f8bSJeremy L Thompson   CeedCall(CeedFree(op));
1564e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
1565d7b241e6Sjeremylt }
1566d7b241e6Sjeremylt 
1567d7b241e6Sjeremylt /// @}
1568