xref: /libCEED/rust/libceed-sys/c-src/interface/ceed-operator.c (revision 953dad2757b613360cba1966d29607e83defc328)
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,
85*953dad27SJames Wright                          "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,
94*953dad27SJames Wright                          "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,
116*953dad27SJames Wright                          "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) {
2116aaed0edSJeremy L Thompson   Ceed ceed;
2126aaed0edSJeremy L Thompson   CeedCall(CeedOperatorGetCeed(op, &ceed));
2136aaed0edSJeremy L Thompson 
214eaf62fffSJeremy L Thompson   *active_basis = NULL;
2150f60e0a8SJeremy L Thompson   if (op->is_composite) return CEED_ERROR_SUCCESS;
2162b730f8bSJeremy L Thompson   for (CeedInt i = 0; i < op->qf->num_input_fields; i++) {
217eaf62fffSJeremy L Thompson     if (op->input_fields[i]->vec == CEED_VECTOR_ACTIVE) {
2186aaed0edSJeremy L Thompson       if (*active_basis && *active_basis != op->input_fields[i]->basis) {
2196aaed0edSJeremy L Thompson         // LCOV_EXCL_START
2206aaed0edSJeremy L Thompson         return CeedError(ceed, CEED_ERROR_MINOR, "Multiple active CeedBases found");
2216aaed0edSJeremy L Thompson         // LCOV_EXCL_STOP
2226aaed0edSJeremy L Thompson       }
223eaf62fffSJeremy L Thompson       *active_basis = op->input_fields[i]->basis;
224eaf62fffSJeremy L Thompson       break;
225eaf62fffSJeremy L Thompson     }
2262b730f8bSJeremy L Thompson   }
227eaf62fffSJeremy L Thompson 
228eaf62fffSJeremy L Thompson   if (!*active_basis) {
229eaf62fffSJeremy L Thompson     // LCOV_EXCL_START
2306aaed0edSJeremy L Thompson     return CeedError(ceed, CEED_ERROR_INCOMPLETE, "No active CeedBasis found");
231eaf62fffSJeremy L Thompson     // LCOV_EXCL_STOP
232eaf62fffSJeremy L Thompson   }
233eaf62fffSJeremy L Thompson   return CEED_ERROR_SUCCESS;
234eaf62fffSJeremy L Thompson }
235eaf62fffSJeremy L Thompson 
236eaf62fffSJeremy L Thompson /**
2370f60e0a8SJeremy L Thompson   @brief Find the active vector ElemRestriction for a non-composite CeedOperator
238e2f04181SAndrew T. Barker 
239e2f04181SAndrew T. Barker   @param[in] op           CeedOperator to find active basis for
2400f60e0a8SJeremy L Thompson   @param[out] active_rstr ElemRestriction for active input vector or NULL for composite operator
241e2f04181SAndrew T. Barker 
242e2f04181SAndrew T. Barker   @return An error code: 0 - success, otherwise - failure
243e2f04181SAndrew T. Barker 
244e2f04181SAndrew T. Barker   @ref Utility
245e2f04181SAndrew T. Barker **/
2462b730f8bSJeremy L Thompson int CeedOperatorGetActiveElemRestriction(CeedOperator op, CeedElemRestriction *active_rstr) {
2476aaed0edSJeremy L Thompson   Ceed ceed;
2486aaed0edSJeremy L Thompson   CeedCall(CeedOperatorGetCeed(op, &ceed));
2496aaed0edSJeremy L Thompson 
250d1d35e2fSjeremylt   *active_rstr = NULL;
2510f60e0a8SJeremy L Thompson   if (op->is_composite) return CEED_ERROR_SUCCESS;
2522b730f8bSJeremy L Thompson   for (CeedInt i = 0; i < op->qf->num_input_fields; i++) {
253d1d35e2fSjeremylt     if (op->input_fields[i]->vec == CEED_VECTOR_ACTIVE) {
2546aaed0edSJeremy L Thompson       if (*active_rstr && *active_rstr != op->input_fields[i]->elem_restr) {
2556aaed0edSJeremy L Thompson         // LCOV_EXCL_START
2566aaed0edSJeremy L Thompson         return CeedError(ceed, CEED_ERROR_MINOR, "Multiple active CeedElemRestrictions found");
2576aaed0edSJeremy L Thompson         // LCOV_EXCL_STOP
2586aaed0edSJeremy L Thompson       }
259d1d35e2fSjeremylt       *active_rstr = op->input_fields[i]->elem_restr;
260e2f04181SAndrew T. Barker       break;
261e2f04181SAndrew T. Barker     }
2622b730f8bSJeremy L Thompson   }
263e2f04181SAndrew T. Barker 
264d1d35e2fSjeremylt   if (!*active_rstr) {
265e2f04181SAndrew T. Barker     // LCOV_EXCL_START
2662b730f8bSJeremy L Thompson     return CeedError(ceed, CEED_ERROR_INCOMPLETE, "No active CeedElemRestriction found");
267e2f04181SAndrew T. Barker     // LCOV_EXCL_STOP
268e2f04181SAndrew T. Barker   }
269e2f04181SAndrew T. Barker   return CEED_ERROR_SUCCESS;
270e2f04181SAndrew T. Barker }
271e2f04181SAndrew T. Barker 
272d8dd9a91SJeremy L Thompson /**
273d8dd9a91SJeremy L Thompson   @brief Set QFunctionContext field value of the specified type.
274ea61e9acSJeremy L Thompson            For composite operators, the value is set in all sub-operator QFunctionContexts that have a matching `field_name`.
275ea61e9acSJeremy 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
276ea61e9acSJeremy L Thompson not have any field of a matching type.
277d8dd9a91SJeremy L Thompson 
278ea61e9acSJeremy L Thompson   @param[in,out] op          CeedOperator
279ea61e9acSJeremy L Thompson   @param[in]     field_label Label of field to set
280ea61e9acSJeremy L Thompson   @param[in]     field_type  Type of field to set
281ea61e9acSJeremy L Thompson   @param[in]     value       Value to set
282d8dd9a91SJeremy L Thompson 
283d8dd9a91SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
284d8dd9a91SJeremy L Thompson 
285d8dd9a91SJeremy L Thompson   @ref User
286d8dd9a91SJeremy L Thompson **/
2872b730f8bSJeremy L Thompson static int CeedOperatorContextSetGeneric(CeedOperator op, CeedContextFieldLabel field_label, CeedContextFieldType field_type, void *value) {
2882b730f8bSJeremy L Thompson   if (!field_label) {
2893668ca4bSJeremy L Thompson     // LCOV_EXCL_START
2902b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label");
2913668ca4bSJeremy L Thompson     // LCOV_EXCL_STOP
2922b730f8bSJeremy L Thompson   }
2933668ca4bSJeremy L Thompson 
2943668ca4bSJeremy L Thompson   bool is_composite = false;
2952b730f8bSJeremy L Thompson   CeedCall(CeedOperatorIsComposite(op, &is_composite));
296d8dd9a91SJeremy L Thompson   if (is_composite) {
297d8dd9a91SJeremy L Thompson     CeedInt       num_sub;
298d8dd9a91SJeremy L Thompson     CeedOperator *sub_operators;
299d8dd9a91SJeremy L Thompson 
300c6ebc35dSJeremy L Thompson     CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub));
301c6ebc35dSJeremy L Thompson     CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators));
3022b730f8bSJeremy L Thompson     if (num_sub != field_label->num_sub_labels) {
3033668ca4bSJeremy L Thompson       // LCOV_EXCL_START
3043668ca4bSJeremy L Thompson       return CeedError(op->ceed, CEED_ERROR_UNSUPPORTED,
3052b730f8bSJeremy L Thompson                        "ContextLabel does not correspond to composite operator. Use CeedOperatorGetContextFieldLabel().");
3063668ca4bSJeremy L Thompson       // LCOV_EXCL_STOP
3072b730f8bSJeremy L Thompson     }
308d8dd9a91SJeremy L Thompson 
309d8dd9a91SJeremy L Thompson     for (CeedInt i = 0; i < num_sub; i++) {
310d8dd9a91SJeremy L Thompson       // Try every sub-operator, ok if some sub-operators do not have field
3113668ca4bSJeremy L Thompson       if (field_label->sub_labels[i] && sub_operators[i]->qf->ctx) {
3122b730f8bSJeremy L Thompson         CeedCall(CeedQFunctionContextSetGeneric(sub_operators[i]->qf->ctx, field_label->sub_labels[i], field_type, value));
313d8dd9a91SJeremy L Thompson       }
314d8dd9a91SJeremy L Thompson     }
315d8dd9a91SJeremy L Thompson   } else {
3162b730f8bSJeremy L Thompson     if (!op->qf->ctx) {
317d8dd9a91SJeremy L Thompson       // LCOV_EXCL_START
3182b730f8bSJeremy L Thompson       return CeedError(op->ceed, CEED_ERROR_UNSUPPORTED, "QFunction does not have context data");
319d8dd9a91SJeremy L Thompson       // LCOV_EXCL_STOP
3202b730f8bSJeremy L Thompson     }
321d8dd9a91SJeremy L Thompson 
3222b730f8bSJeremy L Thompson     CeedCall(CeedQFunctionContextSetGeneric(op->qf->ctx, field_label, field_type, value));
323d8dd9a91SJeremy L Thompson   }
324d8dd9a91SJeremy L Thompson 
325d8dd9a91SJeremy L Thompson   return CEED_ERROR_SUCCESS;
326d8dd9a91SJeremy L Thompson }
327d8dd9a91SJeremy L Thompson 
3287a982d89SJeremy L. Thompson /// @}
3297a982d89SJeremy L. Thompson 
3307a982d89SJeremy L. Thompson /// ----------------------------------------------------------------------------
3317a982d89SJeremy L. Thompson /// CeedOperator Backend API
3327a982d89SJeremy L. Thompson /// ----------------------------------------------------------------------------
3337a982d89SJeremy L. Thompson /// @addtogroup CeedOperatorBackend
3347a982d89SJeremy L. Thompson /// @{
3357a982d89SJeremy L. Thompson 
3367a982d89SJeremy L. Thompson /**
3377a982d89SJeremy L. Thompson   @brief Get the number of arguments associated with a CeedOperator
3387a982d89SJeremy L. Thompson 
339ea61e9acSJeremy L Thompson   @param[in]  op        CeedOperator
340d1d35e2fSjeremylt   @param[out] num_args  Variable to store vector number of arguments
3417a982d89SJeremy L. Thompson 
3427a982d89SJeremy L. Thompson   @return An error code: 0 - success, otherwise - failure
3437a982d89SJeremy L. Thompson 
3447a982d89SJeremy L. Thompson   @ref Backend
3457a982d89SJeremy L. Thompson **/
3467a982d89SJeremy L. Thompson 
347d1d35e2fSjeremylt int CeedOperatorGetNumArgs(CeedOperator op, CeedInt *num_args) {
3482b730f8bSJeremy L Thompson   if (op->is_composite) {
3497a982d89SJeremy L. Thompson     // LCOV_EXCL_START
3502b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MINOR, "Not defined for composite operators");
3517a982d89SJeremy L. Thompson     // LCOV_EXCL_STOP
3522b730f8bSJeremy L Thompson   }
353d1d35e2fSjeremylt   *num_args = op->num_fields;
354e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
3557a982d89SJeremy L. Thompson }
3567a982d89SJeremy L. Thompson 
3577a982d89SJeremy L. Thompson /**
3587a982d89SJeremy L. Thompson   @brief Get the setup status of a CeedOperator
3597a982d89SJeremy L. Thompson 
360ea61e9acSJeremy L Thompson   @param[in]  op            CeedOperator
361d1d35e2fSjeremylt   @param[out] is_setup_done Variable to store setup status
3627a982d89SJeremy L. Thompson 
3637a982d89SJeremy L. Thompson   @return An error code: 0 - success, otherwise - failure
3647a982d89SJeremy L. Thompson 
3657a982d89SJeremy L. Thompson   @ref Backend
3667a982d89SJeremy L. Thompson **/
3677a982d89SJeremy L. Thompson 
368d1d35e2fSjeremylt int CeedOperatorIsSetupDone(CeedOperator op, bool *is_setup_done) {
369f04ea552SJeremy L Thompson   *is_setup_done = op->is_backend_setup;
370e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
3717a982d89SJeremy L. Thompson }
3727a982d89SJeremy L. Thompson 
3737a982d89SJeremy L. Thompson /**
3747a982d89SJeremy L. Thompson   @brief Get the QFunction associated with a CeedOperator
3757a982d89SJeremy L. Thompson 
376ea61e9acSJeremy L Thompson   @param[in]  op CeedOperator
3777a982d89SJeremy L. Thompson   @param[out] qf Variable to store QFunction
3787a982d89SJeremy L. Thompson 
3797a982d89SJeremy L. Thompson   @return An error code: 0 - success, otherwise - failure
3807a982d89SJeremy L. Thompson 
3817a982d89SJeremy L. Thompson   @ref Backend
3827a982d89SJeremy L. Thompson **/
3837a982d89SJeremy L. Thompson 
3847a982d89SJeremy L. Thompson int CeedOperatorGetQFunction(CeedOperator op, CeedQFunction *qf) {
3852b730f8bSJeremy L Thompson   if (op->is_composite) {
3867a982d89SJeremy L. Thompson     // LCOV_EXCL_START
3872b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MINOR, "Not defined for composite operator");
3887a982d89SJeremy L. Thompson     // LCOV_EXCL_STOP
3892b730f8bSJeremy L Thompson   }
3907a982d89SJeremy L. Thompson   *qf = op->qf;
391e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
3927a982d89SJeremy L. Thompson }
3937a982d89SJeremy L. Thompson 
3947a982d89SJeremy L. Thompson /**
395c04a41a7SJeremy L Thompson   @brief Get a boolean value indicating if the CeedOperator is composite
396c04a41a7SJeremy L Thompson 
397ea61e9acSJeremy L Thompson   @param[in]  op           CeedOperator
398d1d35e2fSjeremylt   @param[out] is_composite Variable to store composite status
399c04a41a7SJeremy L Thompson 
400c04a41a7SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
401c04a41a7SJeremy L Thompson 
402c04a41a7SJeremy L Thompson   @ref Backend
403c04a41a7SJeremy L Thompson **/
404c04a41a7SJeremy L Thompson 
405d1d35e2fSjeremylt int CeedOperatorIsComposite(CeedOperator op, bool *is_composite) {
406f04ea552SJeremy L Thompson   *is_composite = op->is_composite;
407e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
408c04a41a7SJeremy L Thompson }
409c04a41a7SJeremy L Thompson 
410c04a41a7SJeremy L Thompson /**
4117a982d89SJeremy L. Thompson   @brief Get the backend data of a CeedOperator
4127a982d89SJeremy L. Thompson 
413ea61e9acSJeremy L Thompson   @param[in]  op   CeedOperator
4147a982d89SJeremy L. Thompson   @param[out] data Variable to store data
4157a982d89SJeremy L. Thompson 
4167a982d89SJeremy L. Thompson   @return An error code: 0 - success, otherwise - failure
4177a982d89SJeremy L. Thompson 
4187a982d89SJeremy L. Thompson   @ref Backend
4197a982d89SJeremy L. Thompson **/
4207a982d89SJeremy L. Thompson 
421777ff853SJeremy L Thompson int CeedOperatorGetData(CeedOperator op, void *data) {
422777ff853SJeremy L Thompson   *(void **)data = op->data;
423e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
4247a982d89SJeremy L. Thompson }
4257a982d89SJeremy L. Thompson 
4267a982d89SJeremy L. Thompson /**
4277a982d89SJeremy L. Thompson   @brief Set the backend data of a CeedOperator
4287a982d89SJeremy L. Thompson 
429ea61e9acSJeremy L Thompson   @param[in,out] op   CeedOperator
430ea61e9acSJeremy L Thompson   @param[in]     data Data to set
4317a982d89SJeremy L. Thompson 
4327a982d89SJeremy L. Thompson   @return An error code: 0 - success, otherwise - failure
4337a982d89SJeremy L. Thompson 
4347a982d89SJeremy L. Thompson   @ref Backend
4357a982d89SJeremy L. Thompson **/
4367a982d89SJeremy L. Thompson 
437777ff853SJeremy L Thompson int CeedOperatorSetData(CeedOperator op, void *data) {
438777ff853SJeremy L Thompson   op->data = data;
439e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
4407a982d89SJeremy L. Thompson }
4417a982d89SJeremy L. Thompson 
4427a982d89SJeremy L. Thompson /**
44334359f16Sjeremylt   @brief Increment the reference counter for a CeedOperator
44434359f16Sjeremylt 
445ea61e9acSJeremy L Thompson   @param[in,out] op CeedOperator to increment the reference counter
44634359f16Sjeremylt 
44734359f16Sjeremylt   @return An error code: 0 - success, otherwise - failure
44834359f16Sjeremylt 
44934359f16Sjeremylt   @ref Backend
45034359f16Sjeremylt **/
4519560d06aSjeremylt int CeedOperatorReference(CeedOperator op) {
45234359f16Sjeremylt   op->ref_count++;
45334359f16Sjeremylt   return CEED_ERROR_SUCCESS;
45434359f16Sjeremylt }
45534359f16Sjeremylt 
45634359f16Sjeremylt /**
4577a982d89SJeremy L. Thompson   @brief Set the setup flag of a CeedOperator to True
4587a982d89SJeremy L. Thompson 
459ea61e9acSJeremy L Thompson   @param[in,out] op CeedOperator
4607a982d89SJeremy L. Thompson 
4617a982d89SJeremy L. Thompson   @return An error code: 0 - success, otherwise - failure
4627a982d89SJeremy L. Thompson 
4637a982d89SJeremy L. Thompson   @ref Backend
4647a982d89SJeremy L. Thompson **/
4657a982d89SJeremy L. Thompson 
4667a982d89SJeremy L. Thompson int CeedOperatorSetSetupDone(CeedOperator op) {
467f04ea552SJeremy L Thompson   op->is_backend_setup = true;
468e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
4697a982d89SJeremy L. Thompson }
4707a982d89SJeremy L. Thompson 
4717a982d89SJeremy L. Thompson /// @}
4727a982d89SJeremy L. Thompson 
4737a982d89SJeremy L. Thompson /// ----------------------------------------------------------------------------
4747a982d89SJeremy L. Thompson /// CeedOperator Public API
4757a982d89SJeremy L. Thompson /// ----------------------------------------------------------------------------
4767a982d89SJeremy L. Thompson /// @addtogroup CeedOperatorUser
477dfdf5a53Sjeremylt /// @{
478d7b241e6Sjeremylt 
479d7b241e6Sjeremylt /**
480ea61e9acSJeremy L Thompson   @brief Create a CeedOperator and associate a CeedQFunction.
481ea61e9acSJeremy L Thompson            A CeedBasis and CeedElemRestriction can be associated with CeedQFunction fields with \ref CeedOperatorSetField.
482d7b241e6Sjeremylt 
483ea61e9acSJeremy L Thompson   @param[in]  ceed Ceed object where the CeedOperator will be created
484ea61e9acSJeremy L Thompson   @param[in]  qf   QFunction defining the action of the operator at quadrature points
485ea61e9acSJeremy L Thompson   @param[in]  dqf  QFunction defining the action of the Jacobian of @a qf (or @ref CEED_QFUNCTION_NONE)
486ea61e9acSJeremy L Thompson   @param[in]  dqfT QFunction defining the action of the transpose of the Jacobian of @a qf (or @ref CEED_QFUNCTION_NONE)
487ea61e9acSJeremy L Thompson   @param[out] op   Address of the variable where the newly created CeedOperator will be stored
488b11c1e72Sjeremylt 
489b11c1e72Sjeremylt   @return An error code: 0 - success, otherwise - failure
490dfdf5a53Sjeremylt 
4917a982d89SJeremy L. Thompson   @ref User
492d7b241e6Sjeremylt  */
4932b730f8bSJeremy L Thompson int CeedOperatorCreate(Ceed ceed, CeedQFunction qf, CeedQFunction dqf, CeedQFunction dqfT, CeedOperator *op) {
4945fe0d4faSjeremylt   if (!ceed->OperatorCreate) {
4955fe0d4faSjeremylt     Ceed delegate;
4962b730f8bSJeremy L Thompson     CeedCall(CeedGetObjectDelegate(ceed, &delegate, "Operator"));
4975fe0d4faSjeremylt 
4982b730f8bSJeremy L Thompson     if (!delegate) {
499c042f62fSJeremy L Thompson       // LCOV_EXCL_START
5002b730f8bSJeremy L Thompson       return CeedError(ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support OperatorCreate");
501c042f62fSJeremy L Thompson       // LCOV_EXCL_STOP
5022b730f8bSJeremy L Thompson     }
5035fe0d4faSjeremylt 
5042b730f8bSJeremy L Thompson     CeedCall(CeedOperatorCreate(delegate, qf, dqf, dqfT, op));
505e15f9bd0SJeremy L Thompson     return CEED_ERROR_SUCCESS;
5065fe0d4faSjeremylt   }
5075fe0d4faSjeremylt 
5082b730f8bSJeremy L Thompson   if (!qf || qf == CEED_QFUNCTION_NONE) {
509b3b7035fSJeremy L Thompson     // LCOV_EXCL_START
5102b730f8bSJeremy L Thompson     return CeedError(ceed, CEED_ERROR_MINOR, "Operator must have a valid QFunction.");
511b3b7035fSJeremy L Thompson     // LCOV_EXCL_STOP
5122b730f8bSJeremy L Thompson   }
5132b730f8bSJeremy L Thompson   CeedCall(CeedCalloc(1, op));
514d7b241e6Sjeremylt   (*op)->ceed = ceed;
5152b730f8bSJeremy L Thompson   CeedCall(CeedReference(ceed));
516d1d35e2fSjeremylt   (*op)->ref_count   = 1;
517d7b241e6Sjeremylt   (*op)->qf          = qf;
5182b104005SJeremy L Thompson   (*op)->input_size  = -1;
5192b104005SJeremy L Thompson   (*op)->output_size = -1;
5202b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionReference(qf));
521442e7f0bSjeremylt   if (dqf && dqf != CEED_QFUNCTION_NONE) {
522d7b241e6Sjeremylt     (*op)->dqf = dqf;
5232b730f8bSJeremy L Thompson     CeedCall(CeedQFunctionReference(dqf));
524442e7f0bSjeremylt   }
525442e7f0bSjeremylt   if (dqfT && dqfT != CEED_QFUNCTION_NONE) {
526d7b241e6Sjeremylt     (*op)->dqfT = dqfT;
5272b730f8bSJeremy L Thompson     CeedCall(CeedQFunctionReference(dqfT));
528442e7f0bSjeremylt   }
5292b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionAssemblyDataCreate(ceed, &(*op)->qf_assembled));
5302b730f8bSJeremy L Thompson   CeedCall(CeedCalloc(CEED_FIELD_MAX, &(*op)->input_fields));
5312b730f8bSJeremy L Thompson   CeedCall(CeedCalloc(CEED_FIELD_MAX, &(*op)->output_fields));
5322b730f8bSJeremy L Thompson   CeedCall(ceed->OperatorCreate(*op));
533e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
534d7b241e6Sjeremylt }
535d7b241e6Sjeremylt 
536d7b241e6Sjeremylt /**
53752d6035fSJeremy L Thompson   @brief Create an operator that composes the action of several operators
53852d6035fSJeremy L Thompson 
539ea61e9acSJeremy L Thompson   @param[in]  ceed Ceed object where the CeedOperator will be created
540ea61e9acSJeremy L Thompson   @param[out] op   Address of the variable where the newly created Composite CeedOperator will be stored
54152d6035fSJeremy L Thompson 
54252d6035fSJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
54352d6035fSJeremy L Thompson 
5447a982d89SJeremy L. Thompson   @ref User
54552d6035fSJeremy L Thompson  */
54652d6035fSJeremy L Thompson int CeedCompositeOperatorCreate(Ceed ceed, CeedOperator *op) {
54752d6035fSJeremy L Thompson   if (!ceed->CompositeOperatorCreate) {
54852d6035fSJeremy L Thompson     Ceed delegate;
5492b730f8bSJeremy L Thompson     CeedCall(CeedGetObjectDelegate(ceed, &delegate, "Operator"));
55052d6035fSJeremy L Thompson 
551250756a7Sjeremylt     if (delegate) {
5522b730f8bSJeremy L Thompson       CeedCall(CeedCompositeOperatorCreate(delegate, op));
553e15f9bd0SJeremy L Thompson       return CEED_ERROR_SUCCESS;
55452d6035fSJeremy L Thompson     }
555250756a7Sjeremylt   }
55652d6035fSJeremy L Thompson 
5572b730f8bSJeremy L Thompson   CeedCall(CeedCalloc(1, op));
55852d6035fSJeremy L Thompson   (*op)->ceed = ceed;
5592b730f8bSJeremy L Thompson   CeedCall(CeedReference(ceed));
560996d9ab5SJed Brown   (*op)->ref_count    = 1;
561f04ea552SJeremy L Thompson   (*op)->is_composite = true;
5622b730f8bSJeremy L Thompson   CeedCall(CeedCalloc(CEED_COMPOSITE_MAX, &(*op)->sub_operators));
5632b104005SJeremy L Thompson   (*op)->input_size  = -1;
5642b104005SJeremy L Thompson   (*op)->output_size = -1;
565250756a7Sjeremylt 
566250756a7Sjeremylt   if (ceed->CompositeOperatorCreate) {
5672b730f8bSJeremy L Thompson     CeedCall(ceed->CompositeOperatorCreate(*op));
568250756a7Sjeremylt   }
569e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
57052d6035fSJeremy L Thompson }
57152d6035fSJeremy L Thompson 
57252d6035fSJeremy L Thompson /**
573ea61e9acSJeremy L Thompson   @brief Copy the pointer to a CeedOperator.
574ea61e9acSJeremy L Thompson            Both pointers should be destroyed with `CeedOperatorDestroy()`.
575ea61e9acSJeremy L Thompson            Note: If `*op_copy` is non-NULL, then it is assumed that `*op_copy` is a pointer to a CeedOperator.
576ea61e9acSJeremy L Thompson              This CeedOperator will be destroyed if `*op_copy` is the only reference to this CeedOperator.
5779560d06aSjeremylt 
578ea61e9acSJeremy L Thompson   @param[in]  op         CeedOperator to copy reference to
579ea61e9acSJeremy L Thompson   @param[in,out] op_copy Variable to store copied reference
5809560d06aSjeremylt 
5819560d06aSjeremylt   @return An error code: 0 - success, otherwise - failure
5829560d06aSjeremylt 
5839560d06aSjeremylt   @ref User
5849560d06aSjeremylt **/
5859560d06aSjeremylt int CeedOperatorReferenceCopy(CeedOperator op, CeedOperator *op_copy) {
5862b730f8bSJeremy L Thompson   CeedCall(CeedOperatorReference(op));
5872b730f8bSJeremy L Thompson   CeedCall(CeedOperatorDestroy(op_copy));
5889560d06aSjeremylt   *op_copy = op;
5899560d06aSjeremylt   return CEED_ERROR_SUCCESS;
5909560d06aSjeremylt }
5919560d06aSjeremylt 
5929560d06aSjeremylt /**
593ea61e9acSJeremy L Thompson   @brief Provide a field to a CeedOperator for use by its CeedQFunction.
594d7b241e6Sjeremylt 
595ea61e9acSJeremy L Thompson   This function is used to specify both active and passive fields to a CeedOperator.
596ea61e9acSJeremy L Thompson   For passive fields, a vector @arg v must be provided.
597ea61e9acSJeremy L Thompson   Passive fields can inputs or outputs (updated in-place when operator is applied).
598d7b241e6Sjeremylt 
599ea61e9acSJeremy L Thompson   Active fields must be specified using this function, but their data (in a CeedVector) is passed in CeedOperatorApply().
600ea61e9acSJeremy L Thompson   There can be at most one active input CeedVector and at most one active output CeedVector passed to CeedOperatorApply().
601d7b241e6Sjeremylt 
602ea61e9acSJeremy L Thompson   @param[in,out] op         CeedOperator on which to provide the field
603ea61e9acSJeremy L Thompson   @param[in]     field_name Name of the field (to be matched with the name used by CeedQFunction)
604ea61e9acSJeremy L Thompson   @param[in]     r          CeedElemRestriction
605ea61e9acSJeremy L Thompson   @param[in]     b          CeedBasis in which the field resides or @ref CEED_BASIS_COLLOCATED if collocated with quadrature points
606ea61e9acSJeremy 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
607ea61e9acSJeremy L Thompson CEED_EVAL_WEIGHT in the QFunction
608b11c1e72Sjeremylt 
609b11c1e72Sjeremylt   @return An error code: 0 - success, otherwise - failure
610dfdf5a53Sjeremylt 
6117a982d89SJeremy L. Thompson   @ref User
612b11c1e72Sjeremylt **/
6132b730f8bSJeremy L Thompson int CeedOperatorSetField(CeedOperator op, const char *field_name, CeedElemRestriction r, CeedBasis b, CeedVector v) {
6142b730f8bSJeremy L Thompson   if (op->is_composite) {
615c042f62fSJeremy L Thompson     // LCOV_EXCL_START
6162b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_INCOMPATIBLE, "Cannot add field to composite operator.");
617c042f62fSJeremy L Thompson     // LCOV_EXCL_STOP
6182b730f8bSJeremy L Thompson   }
6192b730f8bSJeremy L Thompson   if (op->is_immutable) {
620f04ea552SJeremy L Thompson     // LCOV_EXCL_START
6212b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable");
622f04ea552SJeremy L Thompson     // LCOV_EXCL_STOP
6232b730f8bSJeremy L Thompson   }
6242b730f8bSJeremy L Thompson   if (!r) {
625c042f62fSJeremy L Thompson     // LCOV_EXCL_START
6262b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_INCOMPATIBLE, "ElemRestriction r for field \"%s\" must be non-NULL.", field_name);
627c042f62fSJeremy L Thompson     // LCOV_EXCL_STOP
6282b730f8bSJeremy L Thompson   }
6292b730f8bSJeremy L Thompson   if (!b) {
630c042f62fSJeremy L Thompson     // LCOV_EXCL_START
6312b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_INCOMPATIBLE, "Basis b for field \"%s\" must be non-NULL.", field_name);
632c042f62fSJeremy L Thompson     // LCOV_EXCL_STOP
6332b730f8bSJeremy L Thompson   }
6342b730f8bSJeremy L Thompson   if (!v) {
635c042f62fSJeremy L Thompson     // LCOV_EXCL_START
6362b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_INCOMPATIBLE, "Vector v for field \"%s\" must be non-NULL.", field_name);
637c042f62fSJeremy L Thompson     // LCOV_EXCL_STOP
6382b730f8bSJeremy L Thompson   }
63952d6035fSJeremy L Thompson 
640d1d35e2fSjeremylt   CeedInt num_elem;
6412b730f8bSJeremy L Thompson   CeedCall(CeedElemRestrictionGetNumElements(r, &num_elem));
6422b730f8bSJeremy L Thompson   if (r != CEED_ELEMRESTRICTION_NONE && op->has_restriction && op->num_elem != num_elem) {
643c042f62fSJeremy L Thompson     // LCOV_EXCL_START
644e15f9bd0SJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_DIMENSION,
6452b730f8bSJeremy L Thompson                      "ElemRestriction with %" CeedInt_FMT " elements incompatible with prior %" CeedInt_FMT " elements", num_elem, op->num_elem);
646c042f62fSJeremy L Thompson     // LCOV_EXCL_STOP
6472b730f8bSJeremy L Thompson   }
648d7b241e6Sjeremylt 
64978464608Sjeremylt   CeedInt num_qpts = 0;
650e15f9bd0SJeremy L Thompson   if (b != CEED_BASIS_COLLOCATED) {
6512b730f8bSJeremy L Thompson     CeedCall(CeedBasisGetNumQuadraturePoints(b, &num_qpts));
6522b730f8bSJeremy L Thompson     if (op->num_qpts && op->num_qpts != num_qpts) {
653c042f62fSJeremy L Thompson       // LCOV_EXCL_START
654e15f9bd0SJeremy L Thompson       return CeedError(op->ceed, CEED_ERROR_DIMENSION,
6552b730f8bSJeremy L Thompson                        "Basis with %" CeedInt_FMT " quadrature points incompatible with prior %" CeedInt_FMT " points", num_qpts, op->num_qpts);
656c042f62fSJeremy L Thompson       // LCOV_EXCL_STOP
657d7b241e6Sjeremylt     }
6582b730f8bSJeremy L Thompson   }
659d1d35e2fSjeremylt   CeedQFunctionField qf_field;
660d1d35e2fSjeremylt   CeedOperatorField *op_field;
6612b104005SJeremy L Thompson   bool               is_input = true;
662d1d35e2fSjeremylt   for (CeedInt i = 0; i < op->qf->num_input_fields; i++) {
663d1d35e2fSjeremylt     if (!strcmp(field_name, (*op->qf->input_fields[i]).field_name)) {
664d1d35e2fSjeremylt       qf_field = op->qf->input_fields[i];
665d1d35e2fSjeremylt       op_field = &op->input_fields[i];
666d7b241e6Sjeremylt       goto found;
667d7b241e6Sjeremylt     }
668d7b241e6Sjeremylt   }
6692b104005SJeremy L Thompson   is_input = false;
670d1d35e2fSjeremylt   for (CeedInt i = 0; i < op->qf->num_output_fields; i++) {
671d1d35e2fSjeremylt     if (!strcmp(field_name, (*op->qf->output_fields[i]).field_name)) {
672d1d35e2fSjeremylt       qf_field = op->qf->output_fields[i];
673d1d35e2fSjeremylt       op_field = &op->output_fields[i];
674d7b241e6Sjeremylt       goto found;
675d7b241e6Sjeremylt     }
676d7b241e6Sjeremylt   }
677c042f62fSJeremy L Thompson   // LCOV_EXCL_START
6782b730f8bSJeremy L Thompson   return CeedError(op->ceed, CEED_ERROR_INCOMPLETE, "QFunction has no knowledge of field '%s'", field_name);
679c042f62fSJeremy L Thompson   // LCOV_EXCL_STOP
680d7b241e6Sjeremylt found:
6812b730f8bSJeremy L Thompson   CeedCall(CeedOperatorCheckField(op->ceed, qf_field, r, b));
6822b730f8bSJeremy L Thompson   CeedCall(CeedCalloc(1, op_field));
683e15f9bd0SJeremy L Thompson 
6842b104005SJeremy L Thompson   if (v == CEED_VECTOR_ACTIVE) {
6852b104005SJeremy L Thompson     CeedSize l_size;
6862b730f8bSJeremy L Thompson     CeedCall(CeedElemRestrictionGetLVectorSize(r, &l_size));
6872b104005SJeremy L Thompson     if (is_input) {
6882b104005SJeremy L Thompson       if (op->input_size == -1) op->input_size = l_size;
6892b730f8bSJeremy L Thompson       if (l_size != op->input_size) {
6902b104005SJeremy L Thompson         // LCOV_EXCL_START
6912b730f8bSJeremy L Thompson         return CeedError(op->ceed, CEED_ERROR_INCOMPATIBLE, "LVector size %td does not match previous size %td", l_size, op->input_size);
6922b104005SJeremy L Thompson         // LCOV_EXCL_STOP
6932b730f8bSJeremy L Thompson       }
6942b104005SJeremy L Thompson     } else {
6952b104005SJeremy L Thompson       if (op->output_size == -1) op->output_size = l_size;
6962b730f8bSJeremy L Thompson       if (l_size != op->output_size) {
6972b104005SJeremy L Thompson         // LCOV_EXCL_START
6982b730f8bSJeremy L Thompson         return CeedError(op->ceed, CEED_ERROR_INCOMPATIBLE, "LVector size %td does not match previous size %td", l_size, op->output_size);
6992b104005SJeremy L Thompson         // LCOV_EXCL_STOP
7002b104005SJeremy L Thompson       }
7012b104005SJeremy L Thompson     }
7022b730f8bSJeremy L Thompson   }
7032b104005SJeremy L Thompson 
704d1d35e2fSjeremylt   (*op_field)->vec = v;
705e15f9bd0SJeremy L Thompson   if (v != CEED_VECTOR_ACTIVE && v != CEED_VECTOR_NONE) {
7062b730f8bSJeremy L Thompson     CeedCall(CeedVectorReference(v));
707e15f9bd0SJeremy L Thompson   }
708e15f9bd0SJeremy L Thompson 
709d1d35e2fSjeremylt   (*op_field)->elem_restr = r;
7102b730f8bSJeremy L Thompson   CeedCall(CeedElemRestrictionReference(r));
711e15f9bd0SJeremy L Thompson   if (r != CEED_ELEMRESTRICTION_NONE) {
712d1d35e2fSjeremylt     op->num_elem        = num_elem;
713d1d35e2fSjeremylt     op->has_restriction = true;  // Restriction set, but num_elem may be 0
714e15f9bd0SJeremy L Thompson   }
715d99fa3c5SJeremy L Thompson 
716d1d35e2fSjeremylt   (*op_field)->basis = b;
717e15f9bd0SJeremy L Thompson   if (b != CEED_BASIS_COLLOCATED) {
718cd4dfc48Sjeremylt     if (!op->num_qpts) {
7192b730f8bSJeremy L Thompson       CeedCall(CeedOperatorSetNumQuadraturePoints(op, num_qpts));
720cd4dfc48Sjeremylt     }
7212b730f8bSJeremy L Thompson     CeedCall(CeedBasisReference(b));
722e15f9bd0SJeremy L Thompson   }
723e15f9bd0SJeremy L Thompson 
724d1d35e2fSjeremylt   op->num_fields += 1;
7252b730f8bSJeremy L Thompson   CeedCall(CeedStringAllocCopy(field_name, (char **)&(*op_field)->field_name));
726e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
727d7b241e6Sjeremylt }
728d7b241e6Sjeremylt 
729d7b241e6Sjeremylt /**
73043bbe138SJeremy L Thompson   @brief Get the CeedOperatorFields of a CeedOperator
73143bbe138SJeremy L Thompson 
732ea61e9acSJeremy L Thompson   Note: Calling this function asserts that setup is complete and sets the CeedOperator as immutable.
733f04ea552SJeremy L Thompson 
734ea61e9acSJeremy L Thompson   @param[in]  op                CeedOperator
735f74ec584SJeremy L Thompson   @param[out] num_input_fields  Variable to store number of input fields
73643bbe138SJeremy L Thompson   @param[out] input_fields      Variable to store input_fields
737f74ec584SJeremy L Thompson   @param[out] num_output_fields Variable to store number of output fields
73843bbe138SJeremy L Thompson   @param[out] output_fields     Variable to store output_fields
73943bbe138SJeremy L Thompson 
74043bbe138SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
74143bbe138SJeremy L Thompson 
742e9b533fbSJeremy L Thompson   @ref Advanced
74343bbe138SJeremy L Thompson **/
7442b730f8bSJeremy L Thompson int CeedOperatorGetFields(CeedOperator op, CeedInt *num_input_fields, CeedOperatorField **input_fields, CeedInt *num_output_fields,
74543bbe138SJeremy L Thompson                           CeedOperatorField **output_fields) {
7462b730f8bSJeremy L Thompson   if (op->is_composite) {
74743bbe138SJeremy L Thompson     // LCOV_EXCL_START
7482b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MINOR, "Not defined for composite operator");
74943bbe138SJeremy L Thompson     // LCOV_EXCL_STOP
7502b730f8bSJeremy L Thompson   }
7512b730f8bSJeremy L Thompson   CeedCall(CeedOperatorCheckReady(op));
75243bbe138SJeremy L Thompson 
75343bbe138SJeremy L Thompson   if (num_input_fields) *num_input_fields = op->qf->num_input_fields;
75443bbe138SJeremy L Thompson   if (input_fields) *input_fields = op->input_fields;
75543bbe138SJeremy L Thompson   if (num_output_fields) *num_output_fields = op->qf->num_output_fields;
75643bbe138SJeremy L Thompson   if (output_fields) *output_fields = op->output_fields;
75743bbe138SJeremy L Thompson   return CEED_ERROR_SUCCESS;
75843bbe138SJeremy L Thompson }
75943bbe138SJeremy L Thompson 
76043bbe138SJeremy L Thompson /**
76128567f8fSJeremy L Thompson   @brief Get the name of a CeedOperatorField
76228567f8fSJeremy L Thompson 
763ea61e9acSJeremy L Thompson   @param[in]  op_field    CeedOperatorField
76428567f8fSJeremy L Thompson   @param[out] field_name  Variable to store the field name
76528567f8fSJeremy L Thompson 
76628567f8fSJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
76728567f8fSJeremy L Thompson 
768e9b533fbSJeremy L Thompson   @ref Advanced
76928567f8fSJeremy L Thompson **/
77028567f8fSJeremy L Thompson int CeedOperatorFieldGetName(CeedOperatorField op_field, char **field_name) {
77128567f8fSJeremy L Thompson   *field_name = (char *)op_field->field_name;
77228567f8fSJeremy L Thompson   return CEED_ERROR_SUCCESS;
77328567f8fSJeremy L Thompson }
77428567f8fSJeremy L Thompson 
77528567f8fSJeremy L Thompson /**
77643bbe138SJeremy L Thompson   @brief Get the CeedElemRestriction of a CeedOperatorField
77743bbe138SJeremy L Thompson 
778ea61e9acSJeremy L Thompson   @param[in]  op_field CeedOperatorField
77943bbe138SJeremy L Thompson   @param[out] rstr     Variable to store CeedElemRestriction
78043bbe138SJeremy L Thompson 
78143bbe138SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
78243bbe138SJeremy L Thompson 
783e9b533fbSJeremy L Thompson   @ref Advanced
78443bbe138SJeremy L Thompson **/
7852b730f8bSJeremy L Thompson int CeedOperatorFieldGetElemRestriction(CeedOperatorField op_field, CeedElemRestriction *rstr) {
78643bbe138SJeremy L Thompson   *rstr = op_field->elem_restr;
78743bbe138SJeremy L Thompson   return CEED_ERROR_SUCCESS;
78843bbe138SJeremy L Thompson }
78943bbe138SJeremy L Thompson 
79043bbe138SJeremy L Thompson /**
79143bbe138SJeremy L Thompson   @brief Get the CeedBasis of a CeedOperatorField
79243bbe138SJeremy L Thompson 
793ea61e9acSJeremy L Thompson   @param[in]  op_field CeedOperatorField
79443bbe138SJeremy L Thompson   @param[out] basis    Variable to store CeedBasis
79543bbe138SJeremy L Thompson 
79643bbe138SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
79743bbe138SJeremy L Thompson 
798e9b533fbSJeremy L Thompson   @ref Advanced
79943bbe138SJeremy L Thompson **/
80043bbe138SJeremy L Thompson int CeedOperatorFieldGetBasis(CeedOperatorField op_field, CeedBasis *basis) {
80143bbe138SJeremy L Thompson   *basis = op_field->basis;
80243bbe138SJeremy L Thompson   return CEED_ERROR_SUCCESS;
80343bbe138SJeremy L Thompson }
80443bbe138SJeremy L Thompson 
80543bbe138SJeremy L Thompson /**
80643bbe138SJeremy L Thompson   @brief Get the CeedVector of a CeedOperatorField
80743bbe138SJeremy L Thompson 
808ea61e9acSJeremy L Thompson   @param[in]  op_field CeedOperatorField
80943bbe138SJeremy L Thompson   @param[out] vec      Variable to store CeedVector
81043bbe138SJeremy L Thompson 
81143bbe138SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
81243bbe138SJeremy L Thompson 
813e9b533fbSJeremy L Thompson   @ref Advanced
81443bbe138SJeremy L Thompson **/
81543bbe138SJeremy L Thompson int CeedOperatorFieldGetVector(CeedOperatorField op_field, CeedVector *vec) {
81643bbe138SJeremy L Thompson   *vec = op_field->vec;
81743bbe138SJeremy L Thompson   return CEED_ERROR_SUCCESS;
81843bbe138SJeremy L Thompson }
81943bbe138SJeremy L Thompson 
82043bbe138SJeremy L Thompson /**
82152d6035fSJeremy L Thompson   @brief Add a sub-operator to a composite CeedOperator
822288c0443SJeremy L Thompson 
823ea61e9acSJeremy L Thompson   @param[in,out] composite_op Composite CeedOperator
824ea61e9acSJeremy L Thompson   @param[in]     sub_op       Sub-operator CeedOperator
82552d6035fSJeremy L Thompson 
82652d6035fSJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
82752d6035fSJeremy L Thompson 
8287a982d89SJeremy L. Thompson   @ref User
82952d6035fSJeremy L Thompson  */
8302b730f8bSJeremy L Thompson int CeedCompositeOperatorAddSub(CeedOperator composite_op, CeedOperator sub_op) {
8312b730f8bSJeremy L Thompson   if (!composite_op->is_composite) {
832c042f62fSJeremy L Thompson     // LCOV_EXCL_START
8332b730f8bSJeremy L Thompson     return CeedError(composite_op->ceed, CEED_ERROR_MINOR, "CeedOperator is not a composite operator");
8342b104005SJeremy L Thompson     // LCOV_EXCL_STOP
8352b104005SJeremy L Thompson   }
8362b104005SJeremy L Thompson 
8372b730f8bSJeremy L Thompson   if (composite_op->num_suboperators == CEED_COMPOSITE_MAX) {
8382b730f8bSJeremy L Thompson     // LCOV_EXCL_START
8392b730f8bSJeremy L Thompson     return CeedError(composite_op->ceed, CEED_ERROR_UNSUPPORTED, "Cannot add additional sub-operators");
8402b730f8bSJeremy L Thompson     // LCOV_EXCL_STOP
8412b730f8bSJeremy L Thompson   }
8422b730f8bSJeremy L Thompson   if (composite_op->is_immutable) {
8432b730f8bSJeremy L Thompson     // LCOV_EXCL_START
8442b730f8bSJeremy L Thompson     return CeedError(composite_op->ceed, CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable");
8452b730f8bSJeremy L Thompson     // LCOV_EXCL_STOP
8462b730f8bSJeremy L Thompson   }
8472b730f8bSJeremy L Thompson 
8482b730f8bSJeremy L Thompson   {
8492b730f8bSJeremy L Thompson     CeedSize input_size, output_size;
8502b730f8bSJeremy L Thompson     CeedCall(CeedOperatorGetActiveVectorLengths(sub_op, &input_size, &output_size));
8512b730f8bSJeremy L Thompson     if (composite_op->input_size == -1) composite_op->input_size = input_size;
8522b730f8bSJeremy L Thompson     if (composite_op->output_size == -1) composite_op->output_size = output_size;
8532b730f8bSJeremy L Thompson     // Note, a size of -1 means no active vector restriction set, so no incompatibility
8542b730f8bSJeremy L Thompson     if ((input_size != -1 && input_size != composite_op->input_size) || (output_size != -1 && output_size != composite_op->output_size)) {
8552b730f8bSJeremy L Thompson       // LCOV_EXCL_START
8562b730f8bSJeremy L Thompson       return CeedError(composite_op->ceed, CEED_ERROR_MAJOR,
8572b730f8bSJeremy L Thompson                        "Sub-operators must have compatible dimensions; composite operator of shape (%td, %td) not compatible with sub-operator of "
8582b730f8bSJeremy L Thompson                        "shape (%td, %td)",
8592b730f8bSJeremy L Thompson                        composite_op->input_size, composite_op->output_size, input_size, output_size);
8602b730f8bSJeremy L Thompson       // LCOV_EXCL_STOP
8612b730f8bSJeremy L Thompson     }
8622b730f8bSJeremy L Thompson   }
8632b730f8bSJeremy L Thompson 
864d1d35e2fSjeremylt   composite_op->sub_operators[composite_op->num_suboperators] = sub_op;
8652b730f8bSJeremy L Thompson   CeedCall(CeedOperatorReference(sub_op));
866d1d35e2fSjeremylt   composite_op->num_suboperators++;
867e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
86852d6035fSJeremy L Thompson }
86952d6035fSJeremy L Thompson 
87052d6035fSJeremy L Thompson /**
87175f0d5a4SJeremy L Thompson   @brief Get the number of sub_operators associated with a CeedOperator
87275f0d5a4SJeremy L Thompson 
87375f0d5a4SJeremy L Thompson   @param[in]  op               CeedOperator
87475f0d5a4SJeremy L Thompson   @param[out] num_suboperators Variable to store number of sub_operators
87575f0d5a4SJeremy L Thompson 
87675f0d5a4SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
87775f0d5a4SJeremy L Thompson 
87875f0d5a4SJeremy L Thompson   @ref Backend
87975f0d5a4SJeremy L Thompson **/
88075f0d5a4SJeremy L Thompson 
881c6ebc35dSJeremy L Thompson int CeedCompositeOperatorGetNumSub(CeedOperator op, CeedInt *num_suboperators) {
88275f0d5a4SJeremy L Thompson   if (!op->is_composite) {
88375f0d5a4SJeremy L Thompson     // LCOV_EXCL_START
88475f0d5a4SJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MINOR, "Not a composite operator");
88575f0d5a4SJeremy L Thompson     // LCOV_EXCL_STOP
88675f0d5a4SJeremy L Thompson   }
88775f0d5a4SJeremy L Thompson   *num_suboperators = op->num_suboperators;
88875f0d5a4SJeremy L Thompson   return CEED_ERROR_SUCCESS;
88975f0d5a4SJeremy L Thompson }
89075f0d5a4SJeremy L Thompson 
89175f0d5a4SJeremy L Thompson /**
89275f0d5a4SJeremy L Thompson   @brief Get the list of sub_operators associated with a CeedOperator
89375f0d5a4SJeremy L Thompson 
89475f0d5a4SJeremy L Thompson   @param op                  CeedOperator
89575f0d5a4SJeremy L Thompson   @param[out] sub_operators  Variable to store list of sub_operators
89675f0d5a4SJeremy L Thompson 
89775f0d5a4SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
89875f0d5a4SJeremy L Thompson 
89975f0d5a4SJeremy L Thompson   @ref Backend
90075f0d5a4SJeremy L Thompson **/
90175f0d5a4SJeremy L Thompson 
902c6ebc35dSJeremy L Thompson int CeedCompositeOperatorGetSubList(CeedOperator op, CeedOperator **sub_operators) {
90375f0d5a4SJeremy L Thompson   if (!op->is_composite) {
90475f0d5a4SJeremy L Thompson     // LCOV_EXCL_START
90575f0d5a4SJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MINOR, "Not a composite operator");
90675f0d5a4SJeremy L Thompson     // LCOV_EXCL_STOP
90775f0d5a4SJeremy L Thompson   }
90875f0d5a4SJeremy L Thompson   *sub_operators = op->sub_operators;
90975f0d5a4SJeremy L Thompson   return CEED_ERROR_SUCCESS;
91075f0d5a4SJeremy L Thompson }
91175f0d5a4SJeremy L Thompson 
91275f0d5a4SJeremy L Thompson /**
9134db537f9SJeremy L Thompson   @brief Check if a CeedOperator is ready to be used.
9144db537f9SJeremy L Thompson 
9154db537f9SJeremy L Thompson   @param[in] op CeedOperator to check
9164db537f9SJeremy L Thompson 
9174db537f9SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
9184db537f9SJeremy L Thompson 
9194db537f9SJeremy L Thompson   @ref User
9204db537f9SJeremy L Thompson **/
9214db537f9SJeremy L Thompson int CeedOperatorCheckReady(CeedOperator op) {
9224db537f9SJeremy L Thompson   Ceed ceed;
9232b730f8bSJeremy L Thompson   CeedCall(CeedOperatorGetCeed(op, &ceed));
9244db537f9SJeremy L Thompson 
9252b730f8bSJeremy L Thompson   if (op->is_interface_setup) return CEED_ERROR_SUCCESS;
9264db537f9SJeremy L Thompson 
9274db537f9SJeremy L Thompson   CeedQFunction qf = op->qf;
9284db537f9SJeremy L Thompson   if (op->is_composite) {
92943622462SJeremy L Thompson     if (!op->num_suboperators) {
93043622462SJeremy L Thompson       // Empty operator setup
93143622462SJeremy L Thompson       op->input_size  = 0;
93243622462SJeremy L Thompson       op->output_size = 0;
93343622462SJeremy L Thompson     } else {
9344db537f9SJeremy L Thompson       for (CeedInt i = 0; i < op->num_suboperators; i++) {
9352b730f8bSJeremy L Thompson         CeedCall(CeedOperatorCheckReady(op->sub_operators[i]));
9364db537f9SJeremy L Thompson       }
9372b104005SJeremy L Thompson       // Sub-operators could be modified after adding to composite operator
9382b104005SJeremy L Thompson       // Need to verify no lvec incompatibility from any changes
9392b104005SJeremy L Thompson       CeedSize input_size, output_size;
9402b730f8bSJeremy L Thompson       CeedCall(CeedOperatorGetActiveVectorLengths(op, &input_size, &output_size));
94143622462SJeremy L Thompson     }
9424db537f9SJeremy L Thompson   } else {
9432b730f8bSJeremy L Thompson     if (op->num_fields == 0) {
9444db537f9SJeremy L Thompson       // LCOV_EXCL_START
9454db537f9SJeremy L Thompson       return CeedError(ceed, CEED_ERROR_INCOMPLETE, "No operator fields set");
9464db537f9SJeremy L Thompson       // LCOV_EXCL_STOP
9472b730f8bSJeremy L Thompson     }
9482b730f8bSJeremy L Thompson     if (op->num_fields < qf->num_input_fields + qf->num_output_fields) {
9494db537f9SJeremy L Thompson       // LCOV_EXCL_START
9504db537f9SJeremy L Thompson       return CeedError(ceed, CEED_ERROR_INCOMPLETE, "Not all operator fields set");
9514db537f9SJeremy L Thompson       // LCOV_EXCL_STOP
9522b730f8bSJeremy L Thompson     }
9532b730f8bSJeremy L Thompson     if (!op->has_restriction) {
9544db537f9SJeremy L Thompson       // LCOV_EXCL_START
9552b730f8bSJeremy L Thompson       return CeedError(ceed, CEED_ERROR_INCOMPLETE, "At least one restriction required");
9564db537f9SJeremy L Thompson       // LCOV_EXCL_STOP
9572b730f8bSJeremy L Thompson     }
9582b730f8bSJeremy L Thompson     if (op->num_qpts == 0) {
9594db537f9SJeremy L Thompson       // LCOV_EXCL_START
9602b730f8bSJeremy 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");
9614db537f9SJeremy L Thompson       // LCOV_EXCL_STOP
9624db537f9SJeremy L Thompson     }
9632b730f8bSJeremy L Thompson   }
9644db537f9SJeremy L Thompson 
9654db537f9SJeremy L Thompson   // Flag as immutable and ready
9664db537f9SJeremy L Thompson   op->is_interface_setup = true;
9672b730f8bSJeremy L Thompson   if (op->qf && op->qf != CEED_QFUNCTION_NONE) op->qf->is_immutable = true;
9682b730f8bSJeremy L Thompson   if (op->dqf && op->dqf != CEED_QFUNCTION_NONE) op->dqf->is_immutable = true;
9692b730f8bSJeremy L Thompson   if (op->dqfT && op->dqfT != CEED_QFUNCTION_NONE) op->dqfT->is_immutable = true;
9704db537f9SJeremy L Thompson   return CEED_ERROR_SUCCESS;
9714db537f9SJeremy L Thompson }
9724db537f9SJeremy L Thompson 
9734db537f9SJeremy L Thompson /**
974c9366a6bSJeremy L Thompson   @brief Get vector lengths for the active input and/or output vectors of a CeedOperator.
975ea61e9acSJeremy L Thompson            Note: Lengths of -1 indicate that the CeedOperator does not have an active input and/or output.
976c9366a6bSJeremy L Thompson 
977c9366a6bSJeremy L Thompson   @param[in]  op          CeedOperator
978c9366a6bSJeremy L Thompson   @param[out] input_size  Variable to store active input vector length, or NULL
979c9366a6bSJeremy L Thompson   @param[out] output_size Variable to store active output vector length, or NULL
980c9366a6bSJeremy L Thompson 
981c9366a6bSJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
982c9366a6bSJeremy L Thompson 
983c9366a6bSJeremy L Thompson   @ref User
984c9366a6bSJeremy L Thompson **/
9852b730f8bSJeremy L Thompson int CeedOperatorGetActiveVectorLengths(CeedOperator op, CeedSize *input_size, CeedSize *output_size) {
986c9366a6bSJeremy L Thompson   bool is_composite;
987c9366a6bSJeremy L Thompson 
9882b104005SJeremy L Thompson   if (input_size) *input_size = op->input_size;
9892b104005SJeremy L Thompson   if (output_size) *output_size = op->output_size;
990c9366a6bSJeremy L Thompson 
9912b730f8bSJeremy L Thompson   CeedCall(CeedOperatorIsComposite(op, &is_composite));
9922b104005SJeremy L Thompson   if (is_composite && (op->input_size == -1 || op->output_size == -1)) {
993c9366a6bSJeremy L Thompson     for (CeedInt i = 0; i < op->num_suboperators; i++) {
994c9366a6bSJeremy L Thompson       CeedSize sub_input_size, sub_output_size;
9952b730f8bSJeremy L Thompson       CeedCall(CeedOperatorGetActiveVectorLengths(op->sub_operators[i], &sub_input_size, &sub_output_size));
9962b104005SJeremy L Thompson       if (op->input_size == -1) op->input_size = sub_input_size;
9972b104005SJeremy L Thompson       if (op->output_size == -1) op->output_size = sub_output_size;
9982b104005SJeremy L Thompson       // Note, a size of -1 means no active vector restriction set, so no incompatibility
9992b730f8bSJeremy L Thompson       if ((sub_input_size != -1 && sub_input_size != op->input_size) || (sub_output_size != -1 && sub_output_size != op->output_size)) {
10002b104005SJeremy L Thompson         // LCOV_EXCL_START
10012b104005SJeremy L Thompson         return CeedError(op->ceed, CEED_ERROR_MAJOR,
10022b730f8bSJeremy L Thompson                          "Sub-operators must have compatible dimensions; composite operator of shape (%td, %td) not compatible with sub-operator of "
10032b730f8bSJeremy L Thompson                          "shape (%td, %td)",
10042b104005SJeremy L Thompson                          op->input_size, op->output_size, input_size, output_size);
10052b104005SJeremy L Thompson         // LCOV_EXCL_STOP
1006c9366a6bSJeremy L Thompson       }
1007c9366a6bSJeremy L Thompson     }
10082b730f8bSJeremy L Thompson   }
1009c9366a6bSJeremy L Thompson 
1010c9366a6bSJeremy L Thompson   return CEED_ERROR_SUCCESS;
1011c9366a6bSJeremy L Thompson }
1012c9366a6bSJeremy L Thompson 
1013c9366a6bSJeremy L Thompson /**
1014beecbf24SJeremy L Thompson   @brief Set reuse of CeedQFunction data in CeedOperatorLinearAssemble* functions.
1015ea61e9acSJeremy L Thompson            When `reuse_assembly_data = false` (default), the CeedQFunction associated with this CeedOperator is re-assembled every time a
1016ea61e9acSJeremy L Thompson `CeedOperatorLinearAssemble*` function is called. When `reuse_assembly_data = true`, the CeedQFunction associated with this CeedOperator is reused
1017ea61e9acSJeremy L Thompson between calls to `CeedOperatorSetQFunctionAssemblyDataUpdated`.
10188b919e6bSJeremy L Thompson 
1019beecbf24SJeremy L Thompson   @param[in] op                  CeedOperator
1020beecbf24SJeremy L Thompson   @param[in] reuse_assembly_data Boolean flag setting assembly data reuse
10218b919e6bSJeremy L Thompson 
10228b919e6bSJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
10238b919e6bSJeremy L Thompson 
10248b919e6bSJeremy L Thompson   @ref Advanced
10258b919e6bSJeremy L Thompson **/
10262b730f8bSJeremy L Thompson int CeedOperatorSetQFunctionAssemblyReuse(CeedOperator op, bool reuse_assembly_data) {
10278b919e6bSJeremy L Thompson   bool is_composite;
10288b919e6bSJeremy L Thompson 
10292b730f8bSJeremy L Thompson   CeedCall(CeedOperatorIsComposite(op, &is_composite));
10308b919e6bSJeremy L Thompson   if (is_composite) {
10318b919e6bSJeremy L Thompson     for (CeedInt i = 0; i < op->num_suboperators; i++) {
10322b730f8bSJeremy L Thompson       CeedCall(CeedOperatorSetQFunctionAssemblyReuse(op->sub_operators[i], reuse_assembly_data));
10338b919e6bSJeremy L Thompson     }
10348b919e6bSJeremy L Thompson   } else {
10352b730f8bSJeremy L Thompson     CeedCall(CeedQFunctionAssemblyDataSetReuse(op->qf_assembled, reuse_assembly_data));
1036beecbf24SJeremy L Thompson   }
1037beecbf24SJeremy L Thompson 
1038beecbf24SJeremy L Thompson   return CEED_ERROR_SUCCESS;
1039beecbf24SJeremy L Thompson }
1040beecbf24SJeremy L Thompson 
1041beecbf24SJeremy L Thompson /**
1042beecbf24SJeremy L Thompson   @brief Mark CeedQFunction data as updated and the CeedQFunction as requiring re-assembly.
1043beecbf24SJeremy L Thompson 
1044beecbf24SJeremy L Thompson   @param[in] op                CeedOperator
10456e15d496SJeremy L Thompson   @param[in] needs_data_update Boolean flag setting assembly data reuse
1046beecbf24SJeremy L Thompson 
1047beecbf24SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
1048beecbf24SJeremy L Thompson 
1049beecbf24SJeremy L Thompson   @ref Advanced
1050beecbf24SJeremy L Thompson **/
10512b730f8bSJeremy L Thompson int CeedOperatorSetQFunctionAssemblyDataUpdateNeeded(CeedOperator op, bool needs_data_update) {
1052beecbf24SJeremy L Thompson   bool is_composite;
1053beecbf24SJeremy L Thompson 
10542b730f8bSJeremy L Thompson   CeedCall(CeedOperatorIsComposite(op, &is_composite));
1055beecbf24SJeremy L Thompson   if (is_composite) {
1056beecbf24SJeremy L Thompson     for (CeedInt i = 0; i < op->num_suboperators; i++) {
10572b730f8bSJeremy L Thompson       CeedCall(CeedOperatorSetQFunctionAssemblyDataUpdateNeeded(op->sub_operators[i], needs_data_update));
1058beecbf24SJeremy L Thompson     }
1059beecbf24SJeremy L Thompson   } else {
10602b730f8bSJeremy L Thompson     CeedCall(CeedQFunctionAssemblyDataSetUpdateNeeded(op->qf_assembled, needs_data_update));
10618b919e6bSJeremy L Thompson   }
10628b919e6bSJeremy L Thompson 
10638b919e6bSJeremy L Thompson   return CEED_ERROR_SUCCESS;
10648b919e6bSJeremy L Thompson }
10658b919e6bSJeremy L Thompson 
10668b919e6bSJeremy L Thompson /**
1067cd4dfc48Sjeremylt   @brief Set the number of quadrature points associated with a CeedOperator.
1068ea61e9acSJeremy L Thompson            This should be used when creating a CeedOperator where every field has a collocated basis.
1069ea61e9acSJeremy L Thompson            This function cannot be used for composite CeedOperators.
1070cd4dfc48Sjeremylt 
1071ea61e9acSJeremy L Thompson   @param[in,out] op       CeedOperator
1072ea61e9acSJeremy L Thompson   @param[in]     num_qpts Number of quadrature points to set
1073cd4dfc48Sjeremylt 
1074cd4dfc48Sjeremylt   @return An error code: 0 - success, otherwise - failure
1075cd4dfc48Sjeremylt 
1076e9b533fbSJeremy L Thompson   @ref Advanced
1077cd4dfc48Sjeremylt **/
1078cd4dfc48Sjeremylt int CeedOperatorSetNumQuadraturePoints(CeedOperator op, CeedInt num_qpts) {
10792b730f8bSJeremy L Thompson   if (op->is_composite) {
1080cd4dfc48Sjeremylt     // LCOV_EXCL_START
10812b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MINOR, "Not defined for composite operator");
1082cd4dfc48Sjeremylt     // LCOV_EXCL_STOP
10832b730f8bSJeremy L Thompson   }
10842b730f8bSJeremy L Thompson   if (op->num_qpts) {
1085cd4dfc48Sjeremylt     // LCOV_EXCL_START
10862b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MINOR, "Number of quadrature points already defined");
1087cd4dfc48Sjeremylt     // LCOV_EXCL_STOP
10882b730f8bSJeremy L Thompson   }
10892b730f8bSJeremy L Thompson   if (op->is_immutable) {
1090f04ea552SJeremy L Thompson     // LCOV_EXCL_START
10912b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable");
1092f04ea552SJeremy L Thompson     // LCOV_EXCL_STOP
10932b730f8bSJeremy L Thompson   }
1094cd4dfc48Sjeremylt   op->num_qpts = num_qpts;
1095cd4dfc48Sjeremylt   return CEED_ERROR_SUCCESS;
1096cd4dfc48Sjeremylt }
1097cd4dfc48Sjeremylt 
1098cd4dfc48Sjeremylt /**
1099ea6b5821SJeremy L Thompson   @brief Set name of CeedOperator for CeedOperatorView output
1100ea6b5821SJeremy L Thompson 
1101ea61e9acSJeremy L Thompson   @param[in,out] op   CeedOperator
1102ea61e9acSJeremy L Thompson   @param[in]     name Name to set, or NULL to remove previously set name
1103ea6b5821SJeremy L Thompson 
1104ea6b5821SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
1105ea6b5821SJeremy L Thompson 
1106ea6b5821SJeremy L Thompson   @ref User
1107ea6b5821SJeremy L Thompson **/
1108ea6b5821SJeremy L Thompson int CeedOperatorSetName(CeedOperator op, const char *name) {
1109ea6b5821SJeremy L Thompson   char  *name_copy;
1110ea6b5821SJeremy L Thompson   size_t name_len = name ? strlen(name) : 0;
1111ea6b5821SJeremy L Thompson 
11122b730f8bSJeremy L Thompson   CeedCall(CeedFree(&op->name));
1113ea6b5821SJeremy L Thompson   if (name_len > 0) {
11142b730f8bSJeremy L Thompson     CeedCall(CeedCalloc(name_len + 1, &name_copy));
1115ea6b5821SJeremy L Thompson     memcpy(name_copy, name, name_len);
1116ea6b5821SJeremy L Thompson     op->name = name_copy;
1117ea6b5821SJeremy L Thompson   }
1118ea6b5821SJeremy L Thompson 
1119ea6b5821SJeremy L Thompson   return CEED_ERROR_SUCCESS;
1120ea6b5821SJeremy L Thompson }
1121ea6b5821SJeremy L Thompson 
1122ea6b5821SJeremy L Thompson /**
11237a982d89SJeremy L. Thompson   @brief View a CeedOperator
11247a982d89SJeremy L. Thompson 
11257a982d89SJeremy L. Thompson   @param[in] op     CeedOperator to view
11267a982d89SJeremy L. Thompson   @param[in] stream Stream to write; typically stdout/stderr or a file
11277a982d89SJeremy L. Thompson 
11287a982d89SJeremy L. Thompson   @return Error code: 0 - success, otherwise - failure
11297a982d89SJeremy L. Thompson 
11307a982d89SJeremy L. Thompson   @ref User
11317a982d89SJeremy L. Thompson **/
11327a982d89SJeremy L. Thompson int CeedOperatorView(CeedOperator op, FILE *stream) {
1133ea6b5821SJeremy L Thompson   bool has_name = op->name;
11347a982d89SJeremy L. Thompson 
1135f04ea552SJeremy L Thompson   if (op->is_composite) {
11362b730f8bSJeremy L Thompson     fprintf(stream, "Composite CeedOperator%s%s\n", has_name ? " - " : "", has_name ? op->name : "");
11377a982d89SJeremy L. Thompson 
1138d1d35e2fSjeremylt     for (CeedInt i = 0; i < op->num_suboperators; i++) {
1139ea6b5821SJeremy L Thompson       has_name = op->sub_operators[i]->name;
11402b730f8bSJeremy L Thompson       fprintf(stream, "  SubOperator %" CeedInt_FMT "%s%s:\n", i, has_name ? " - " : "", has_name ? op->sub_operators[i]->name : "");
11412b730f8bSJeremy L Thompson       CeedCall(CeedOperatorSingleView(op->sub_operators[i], 1, stream));
11427a982d89SJeremy L. Thompson     }
11437a982d89SJeremy L. Thompson   } else {
11442b730f8bSJeremy L Thompson     fprintf(stream, "CeedOperator%s%s\n", has_name ? " - " : "", has_name ? op->name : "");
11452b730f8bSJeremy L Thompson     CeedCall(CeedOperatorSingleView(op, 0, stream));
11467a982d89SJeremy L. Thompson   }
1147e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
11487a982d89SJeremy L. Thompson }
11493bd813ffSjeremylt 
11503bd813ffSjeremylt /**
1151b7c9bbdaSJeremy L Thompson   @brief Get the Ceed associated with a CeedOperator
1152b7c9bbdaSJeremy L Thompson 
1153ea61e9acSJeremy L Thompson   @param[in]  op   CeedOperator
1154b7c9bbdaSJeremy L Thompson   @param[out] ceed Variable to store Ceed
1155b7c9bbdaSJeremy L Thompson 
1156b7c9bbdaSJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
1157b7c9bbdaSJeremy L Thompson 
1158b7c9bbdaSJeremy L Thompson   @ref Advanced
1159b7c9bbdaSJeremy L Thompson **/
1160b7c9bbdaSJeremy L Thompson int CeedOperatorGetCeed(CeedOperator op, Ceed *ceed) {
1161b7c9bbdaSJeremy L Thompson   *ceed = op->ceed;
1162b7c9bbdaSJeremy L Thompson   return CEED_ERROR_SUCCESS;
1163b7c9bbdaSJeremy L Thompson }
1164b7c9bbdaSJeremy L Thompson 
1165b7c9bbdaSJeremy L Thompson /**
1166b7c9bbdaSJeremy L Thompson   @brief Get the number of elements associated with a CeedOperator
1167b7c9bbdaSJeremy L Thompson 
1168ea61e9acSJeremy L Thompson   @param[in]  op       CeedOperator
1169b7c9bbdaSJeremy L Thompson   @param[out] num_elem Variable to store number of elements
1170b7c9bbdaSJeremy L Thompson 
1171b7c9bbdaSJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
1172b7c9bbdaSJeremy L Thompson 
1173b7c9bbdaSJeremy L Thompson   @ref Advanced
1174b7c9bbdaSJeremy L Thompson **/
1175b7c9bbdaSJeremy L Thompson int CeedOperatorGetNumElements(CeedOperator op, CeedInt *num_elem) {
11762b730f8bSJeremy L Thompson   if (op->is_composite) {
1177b7c9bbdaSJeremy L Thompson     // LCOV_EXCL_START
11782b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MINOR, "Not defined for composite operator");
1179b7c9bbdaSJeremy L Thompson     // LCOV_EXCL_STOP
11802b730f8bSJeremy L Thompson   }
1181b7c9bbdaSJeremy L Thompson   *num_elem = op->num_elem;
1182b7c9bbdaSJeremy L Thompson   return CEED_ERROR_SUCCESS;
1183b7c9bbdaSJeremy L Thompson }
1184b7c9bbdaSJeremy L Thompson 
1185b7c9bbdaSJeremy L Thompson /**
1186b7c9bbdaSJeremy L Thompson   @brief Get the number of quadrature points associated with a CeedOperator
1187b7c9bbdaSJeremy L Thompson 
1188ea61e9acSJeremy L Thompson   @param[in]  op       CeedOperator
1189b7c9bbdaSJeremy L Thompson   @param[out] num_qpts Variable to store vector number of quadrature points
1190b7c9bbdaSJeremy L Thompson 
1191b7c9bbdaSJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
1192b7c9bbdaSJeremy L Thompson 
1193b7c9bbdaSJeremy L Thompson   @ref Advanced
1194b7c9bbdaSJeremy L Thompson **/
1195b7c9bbdaSJeremy L Thompson int CeedOperatorGetNumQuadraturePoints(CeedOperator op, CeedInt *num_qpts) {
11962b730f8bSJeremy L Thompson   if (op->is_composite) {
1197b7c9bbdaSJeremy L Thompson     // LCOV_EXCL_START
11982b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MINOR, "Not defined for composite operator");
1199b7c9bbdaSJeremy L Thompson     // LCOV_EXCL_STOP
12002b730f8bSJeremy L Thompson   }
1201b7c9bbdaSJeremy L Thompson   *num_qpts = op->num_qpts;
1202b7c9bbdaSJeremy L Thompson   return CEED_ERROR_SUCCESS;
1203b7c9bbdaSJeremy L Thompson }
1204b7c9bbdaSJeremy L Thompson 
1205b7c9bbdaSJeremy L Thompson /**
12066e15d496SJeremy L Thompson   @brief Estimate number of FLOPs required to apply CeedOperator on the active vector
12076e15d496SJeremy L Thompson 
1208ea61e9acSJeremy L Thompson   @param[in]  op    CeedOperator to estimate FLOPs for
1209ea61e9acSJeremy L Thompson   @param[out] flops Address of variable to hold FLOPs estimate
12106e15d496SJeremy L Thompson 
12116e15d496SJeremy L Thompson   @ref Backend
12126e15d496SJeremy L Thompson **/
12139d36ca50SJeremy L Thompson int CeedOperatorGetFlopsEstimate(CeedOperator op, CeedSize *flops) {
12146e15d496SJeremy L Thompson   bool is_composite;
12152b730f8bSJeremy L Thompson   CeedCall(CeedOperatorCheckReady(op));
12166e15d496SJeremy L Thompson 
12176e15d496SJeremy L Thompson   *flops = 0;
12182b730f8bSJeremy L Thompson   CeedCall(CeedOperatorIsComposite(op, &is_composite));
12196e15d496SJeremy L Thompson   if (is_composite) {
12206e15d496SJeremy L Thompson     CeedInt num_suboperators;
1221c6ebc35dSJeremy L Thompson     CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators));
12226e15d496SJeremy L Thompson     CeedOperator *sub_operators;
1223c6ebc35dSJeremy L Thompson     CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators));
12246e15d496SJeremy L Thompson 
12256e15d496SJeremy L Thompson     // FLOPs for each suboperator
12266e15d496SJeremy L Thompson     for (CeedInt i = 0; i < num_suboperators; i++) {
12279d36ca50SJeremy L Thompson       CeedSize suboperator_flops;
12282b730f8bSJeremy L Thompson       CeedCall(CeedOperatorGetFlopsEstimate(sub_operators[i], &suboperator_flops));
12296e15d496SJeremy L Thompson       *flops += suboperator_flops;
12306e15d496SJeremy L Thompson     }
12316e15d496SJeremy L Thompson   } else {
12326e15d496SJeremy L Thompson     CeedInt            num_input_fields, num_output_fields;
12336e15d496SJeremy L Thompson     CeedOperatorField *input_fields, *output_fields;
12346e15d496SJeremy L Thompson 
12352b730f8bSJeremy L Thompson     CeedCall(CeedOperatorGetFields(op, &num_input_fields, &input_fields, &num_output_fields, &output_fields));
12366e15d496SJeremy L Thompson 
12376e15d496SJeremy L Thompson     CeedInt num_elem = 0;
12382b730f8bSJeremy L Thompson     CeedCall(CeedOperatorGetNumElements(op, &num_elem));
12396e15d496SJeremy L Thompson     // Input FLOPs
12406e15d496SJeremy L Thompson     for (CeedInt i = 0; i < num_input_fields; i++) {
12416e15d496SJeremy L Thompson       if (input_fields[i]->vec == CEED_VECTOR_ACTIVE) {
12429d36ca50SJeremy L Thompson         CeedSize restr_flops, basis_flops;
12436e15d496SJeremy L Thompson 
12442b730f8bSJeremy L Thompson         CeedCall(CeedElemRestrictionGetFlopsEstimate(input_fields[i]->elem_restr, CEED_NOTRANSPOSE, &restr_flops));
12456e15d496SJeremy L Thompson         *flops += restr_flops;
12462b730f8bSJeremy L Thompson         CeedCall(CeedBasisGetFlopsEstimate(input_fields[i]->basis, CEED_NOTRANSPOSE, op->qf->input_fields[i]->eval_mode, &basis_flops));
12476e15d496SJeremy L Thompson         *flops += basis_flops * num_elem;
12486e15d496SJeremy L Thompson       }
12496e15d496SJeremy L Thompson     }
12506e15d496SJeremy L Thompson     // QF FLOPs
12519d36ca50SJeremy L Thompson     CeedInt  num_qpts;
12529d36ca50SJeremy L Thompson     CeedSize qf_flops;
12532b730f8bSJeremy L Thompson     CeedCall(CeedOperatorGetNumQuadraturePoints(op, &num_qpts));
12542b730f8bSJeremy L Thompson     CeedCall(CeedQFunctionGetFlopsEstimate(op->qf, &qf_flops));
12556e15d496SJeremy L Thompson     *flops += num_elem * num_qpts * qf_flops;
12566e15d496SJeremy L Thompson     // Output FLOPs
12576e15d496SJeremy L Thompson     for (CeedInt i = 0; i < num_output_fields; i++) {
12586e15d496SJeremy L Thompson       if (output_fields[i]->vec == CEED_VECTOR_ACTIVE) {
12599d36ca50SJeremy L Thompson         CeedSize restr_flops, basis_flops;
12606e15d496SJeremy L Thompson 
12612b730f8bSJeremy L Thompson         CeedCall(CeedElemRestrictionGetFlopsEstimate(output_fields[i]->elem_restr, CEED_TRANSPOSE, &restr_flops));
12626e15d496SJeremy L Thompson         *flops += restr_flops;
12632b730f8bSJeremy L Thompson         CeedCall(CeedBasisGetFlopsEstimate(output_fields[i]->basis, CEED_TRANSPOSE, op->qf->output_fields[i]->eval_mode, &basis_flops));
12646e15d496SJeremy L Thompson         *flops += basis_flops * num_elem;
12656e15d496SJeremy L Thompson       }
12666e15d496SJeremy L Thompson     }
12676e15d496SJeremy L Thompson   }
12686e15d496SJeremy L Thompson 
12696e15d496SJeremy L Thompson   return CEED_ERROR_SUCCESS;
12706e15d496SJeremy L Thompson }
12716e15d496SJeremy L Thompson 
12726e15d496SJeremy L Thompson /**
1273ea61e9acSJeremy L Thompson   @brief Get label for a registered QFunctionContext field, or `NULL` if no field has been registered with this `field_name`.
12743668ca4bSJeremy L Thompson 
12753668ca4bSJeremy L Thompson   @param[in]  op          CeedOperator
12763668ca4bSJeremy L Thompson   @param[in]  field_name  Name of field to retrieve label
12773668ca4bSJeremy L Thompson   @param[out] field_label Variable to field label
12783668ca4bSJeremy L Thompson 
12793668ca4bSJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
12803668ca4bSJeremy L Thompson 
12813668ca4bSJeremy L Thompson   @ref User
12823668ca4bSJeremy L Thompson **/
12832b730f8bSJeremy L Thompson int CeedOperatorContextGetFieldLabel(CeedOperator op, const char *field_name, CeedContextFieldLabel *field_label) {
12843668ca4bSJeremy L Thompson   bool is_composite;
12852b730f8bSJeremy L Thompson   CeedCall(CeedOperatorIsComposite(op, &is_composite));
12862b730f8bSJeremy L Thompson 
12873668ca4bSJeremy L Thompson   if (is_composite) {
12883668ca4bSJeremy L Thompson     // Check if composite label already created
12893668ca4bSJeremy L Thompson     for (CeedInt i = 0; i < op->num_context_labels; i++) {
12903668ca4bSJeremy L Thompson       if (!strcmp(op->context_labels[i]->name, field_name)) {
12913668ca4bSJeremy L Thompson         *field_label = op->context_labels[i];
12923668ca4bSJeremy L Thompson         return CEED_ERROR_SUCCESS;
12933668ca4bSJeremy L Thompson       }
12943668ca4bSJeremy L Thompson     }
12953668ca4bSJeremy L Thompson 
12963668ca4bSJeremy L Thompson     // Create composite label if needed
12973668ca4bSJeremy L Thompson     CeedInt               num_sub;
12983668ca4bSJeremy L Thompson     CeedOperator         *sub_operators;
12993668ca4bSJeremy L Thompson     CeedContextFieldLabel new_field_label;
13003668ca4bSJeremy L Thompson 
13012b730f8bSJeremy L Thompson     CeedCall(CeedCalloc(1, &new_field_label));
1302c6ebc35dSJeremy L Thompson     CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub));
1303c6ebc35dSJeremy L Thompson     CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators));
13042b730f8bSJeremy L Thompson     CeedCall(CeedCalloc(num_sub, &new_field_label->sub_labels));
13053668ca4bSJeremy L Thompson     new_field_label->num_sub_labels = num_sub;
13063668ca4bSJeremy L Thompson 
13073668ca4bSJeremy L Thompson     bool label_found = false;
13083668ca4bSJeremy L Thompson     for (CeedInt i = 0; i < num_sub; i++) {
13093668ca4bSJeremy L Thompson       if (sub_operators[i]->qf->ctx) {
13103668ca4bSJeremy L Thompson         CeedContextFieldLabel new_field_label_i;
13112b730f8bSJeremy L Thompson         CeedCall(CeedQFunctionContextGetFieldLabel(sub_operators[i]->qf->ctx, field_name, &new_field_label_i));
13123668ca4bSJeremy L Thompson         if (new_field_label_i) {
13133668ca4bSJeremy L Thompson           label_found                    = true;
13143668ca4bSJeremy L Thompson           new_field_label->sub_labels[i] = new_field_label_i;
13153668ca4bSJeremy L Thompson           new_field_label->name          = new_field_label_i->name;
13163668ca4bSJeremy L Thompson           new_field_label->description   = new_field_label_i->description;
13172b730f8bSJeremy L Thompson           if (new_field_label->type && new_field_label->type != new_field_label_i->type) {
13187bfe0f0eSJeremy L Thompson             // LCOV_EXCL_START
13192b730f8bSJeremy L Thompson             CeedCall(CeedFree(&new_field_label));
13202b730f8bSJeremy L Thompson             return CeedError(op->ceed, CEED_ERROR_INCOMPATIBLE, "Incompatible field types on sub-operator contexts. %s != %s",
13212b730f8bSJeremy L Thompson                              CeedContextFieldTypes[new_field_label->type], CeedContextFieldTypes[new_field_label_i->type]);
13227bfe0f0eSJeremy L Thompson             // LCOV_EXCL_STOP
13237bfe0f0eSJeremy L Thompson           } else {
13247bfe0f0eSJeremy L Thompson             new_field_label->type = new_field_label_i->type;
13257bfe0f0eSJeremy L Thompson           }
13262b730f8bSJeremy L Thompson           if (new_field_label->num_values != 0 && new_field_label->num_values != new_field_label_i->num_values) {
13277bfe0f0eSJeremy L Thompson             // LCOV_EXCL_START
13282b730f8bSJeremy L Thompson             CeedCall(CeedFree(&new_field_label));
13292b730f8bSJeremy L Thompson             return CeedError(op->ceed, CEED_ERROR_INCOMPATIBLE, "Incompatible field number of values on sub-operator contexts. %ld != %ld",
13307bfe0f0eSJeremy L Thompson                              new_field_label->num_values, new_field_label_i->num_values);
13317bfe0f0eSJeremy L Thompson             // LCOV_EXCL_STOP
13327bfe0f0eSJeremy L Thompson           } else {
13337bfe0f0eSJeremy L Thompson             new_field_label->num_values = new_field_label_i->num_values;
13347bfe0f0eSJeremy L Thompson           }
13353668ca4bSJeremy L Thompson         }
13363668ca4bSJeremy L Thompson       }
13373668ca4bSJeremy L Thompson     }
13383668ca4bSJeremy L Thompson     if (!label_found) {
13393668ca4bSJeremy L Thompson       // LCOV_EXCL_START
13402b730f8bSJeremy L Thompson       CeedCall(CeedFree(&new_field_label->sub_labels));
13412b730f8bSJeremy L Thompson       CeedCall(CeedFree(&new_field_label));
13423668ca4bSJeremy L Thompson       *field_label = NULL;
13433668ca4bSJeremy L Thompson       // LCOV_EXCL_STOP
13443668ca4bSJeremy L Thompson     } else {
13453668ca4bSJeremy L Thompson       // Move new composite label to operator
13463668ca4bSJeremy L Thompson       if (op->num_context_labels == 0) {
13472b730f8bSJeremy L Thompson         CeedCall(CeedCalloc(1, &op->context_labels));
13483668ca4bSJeremy L Thompson         op->max_context_labels = 1;
13493668ca4bSJeremy L Thompson       } else if (op->num_context_labels == op->max_context_labels) {
13502b730f8bSJeremy L Thompson         CeedCall(CeedRealloc(2 * op->num_context_labels, &op->context_labels));
13513668ca4bSJeremy L Thompson         op->max_context_labels *= 2;
13523668ca4bSJeremy L Thompson       }
13533668ca4bSJeremy L Thompson       op->context_labels[op->num_context_labels] = new_field_label;
13543668ca4bSJeremy L Thompson       *field_label                               = new_field_label;
13553668ca4bSJeremy L Thompson       op->num_context_labels++;
13563668ca4bSJeremy L Thompson     }
13573668ca4bSJeremy L Thompson 
13583668ca4bSJeremy L Thompson     return CEED_ERROR_SUCCESS;
13593668ca4bSJeremy L Thompson   } else {
13603668ca4bSJeremy L Thompson     return CeedQFunctionContextGetFieldLabel(op->qf->ctx, field_name, field_label);
13613668ca4bSJeremy L Thompson   }
13623668ca4bSJeremy L Thompson }
13633668ca4bSJeremy L Thompson 
13643668ca4bSJeremy L Thompson /**
1365d8dd9a91SJeremy L Thompson   @brief Set QFunctionContext field holding a double precision value.
1366ea61e9acSJeremy L Thompson            For composite operators, the value is set in all sub-operator QFunctionContexts that have a matching `field_name`.
1367d8dd9a91SJeremy L Thompson 
1368ea61e9acSJeremy L Thompson   @param[in,out] op          CeedOperator
1369ea61e9acSJeremy L Thompson   @param[in]     field_label Label of field to register
1370ea61e9acSJeremy L Thompson   @param[in]     values      Values to set
1371d8dd9a91SJeremy L Thompson 
1372d8dd9a91SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
1373d8dd9a91SJeremy L Thompson 
1374d8dd9a91SJeremy L Thompson   @ref User
1375d8dd9a91SJeremy L Thompson **/
13762b730f8bSJeremy L Thompson int CeedOperatorContextSetDouble(CeedOperator op, CeedContextFieldLabel field_label, double *values) {
13772b730f8bSJeremy L Thompson   return CeedOperatorContextSetGeneric(op, field_label, CEED_CONTEXT_FIELD_DOUBLE, values);
1378d8dd9a91SJeremy L Thompson }
1379d8dd9a91SJeremy L Thompson 
1380d8dd9a91SJeremy L Thompson /**
1381d8dd9a91SJeremy L Thompson   @brief Set QFunctionContext field holding an int32 value.
1382ea61e9acSJeremy L Thompson            For composite operators, the value is set in all sub-operator QFunctionContexts that have a matching `field_name`.
1383d8dd9a91SJeremy L Thompson 
1384ea61e9acSJeremy L Thompson   @param[in,out] op          CeedOperator
1385ea61e9acSJeremy L Thompson   @param[in]     field_label Label of field to set
1386ea61e9acSJeremy L Thompson   @param[in]     values      Values to set
1387d8dd9a91SJeremy L Thompson 
1388d8dd9a91SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
1389d8dd9a91SJeremy L Thompson 
1390d8dd9a91SJeremy L Thompson   @ref User
1391d8dd9a91SJeremy L Thompson **/
13922b730f8bSJeremy L Thompson int CeedOperatorContextSetInt32(CeedOperator op, CeedContextFieldLabel field_label, int *values) {
13932b730f8bSJeremy L Thompson   return CeedOperatorContextSetGeneric(op, field_label, CEED_CONTEXT_FIELD_INT32, values);
1394d8dd9a91SJeremy L Thompson }
1395d8dd9a91SJeremy L Thompson 
1396d8dd9a91SJeremy L Thompson /**
13973bd813ffSjeremylt   @brief Apply CeedOperator to a vector
1398d7b241e6Sjeremylt 
1399ea61e9acSJeremy L Thompson   This computes the action of the operator on the specified (active) input, yielding its (active) output.
1400ea61e9acSJeremy L Thompson   All inputs and outputs must be specified using CeedOperatorSetField().
1401d7b241e6Sjeremylt 
1402ea61e9acSJeremy L Thompson   Note: Calling this function asserts that setup is complete and sets the CeedOperator as immutable.
1403f04ea552SJeremy L Thompson 
1404ea61e9acSJeremy L Thompson   @param[in]  op      CeedOperator to apply
1405ea61e9acSJeremy L Thompson   @param[in]  in      CeedVector containing input state or @ref CEED_VECTOR_NONE if there are no active inputs
1406ea61e9acSJeremy 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
1407ea61e9acSJeremy L Thompson outputs
1408ea61e9acSJeremy L Thompson   @param[in]  request Address of CeedRequest for non-blocking completion, else @ref CEED_REQUEST_IMMEDIATE
1409b11c1e72Sjeremylt 
1410b11c1e72Sjeremylt   @return An error code: 0 - success, otherwise - failure
1411dfdf5a53Sjeremylt 
14127a982d89SJeremy L. Thompson   @ref User
1413b11c1e72Sjeremylt **/
14142b730f8bSJeremy L Thompson int CeedOperatorApply(CeedOperator op, CeedVector in, CeedVector out, CeedRequest *request) {
14152b730f8bSJeremy L Thompson   CeedCall(CeedOperatorCheckReady(op));
1416d7b241e6Sjeremylt 
1417d1d35e2fSjeremylt   if (op->num_elem) {
1418250756a7Sjeremylt     // Standard Operator
1419cae8b89aSjeremylt     if (op->Apply) {
14202b730f8bSJeremy L Thompson       CeedCall(op->Apply(op, in, out, request));
1421cae8b89aSjeremylt     } else {
1422cae8b89aSjeremylt       // Zero all output vectors
1423250756a7Sjeremylt       CeedQFunction qf = op->qf;
1424d1d35e2fSjeremylt       for (CeedInt i = 0; i < qf->num_output_fields; i++) {
1425d1d35e2fSjeremylt         CeedVector vec = op->output_fields[i]->vec;
14262b730f8bSJeremy L Thompson         if (vec == CEED_VECTOR_ACTIVE) vec = out;
1427cae8b89aSjeremylt         if (vec != CEED_VECTOR_NONE) {
14282b730f8bSJeremy L Thompson           CeedCall(CeedVectorSetValue(vec, 0.0));
1429cae8b89aSjeremylt         }
1430cae8b89aSjeremylt       }
1431250756a7Sjeremylt       // Apply
14322b730f8bSJeremy L Thompson       CeedCall(op->ApplyAdd(op, in, out, request));
1433250756a7Sjeremylt     }
1434f04ea552SJeremy L Thompson   } else if (op->is_composite) {
1435250756a7Sjeremylt     // Composite Operator
1436250756a7Sjeremylt     if (op->ApplyComposite) {
14372b730f8bSJeremy L Thompson       CeedCall(op->ApplyComposite(op, in, out, request));
1438250756a7Sjeremylt     } else {
1439d1d35e2fSjeremylt       CeedInt num_suboperators;
1440c6ebc35dSJeremy L Thompson       CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators));
1441d1d35e2fSjeremylt       CeedOperator *sub_operators;
1442c6ebc35dSJeremy L Thompson       CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators));
1443250756a7Sjeremylt 
1444250756a7Sjeremylt       // Zero all output vectors
1445250756a7Sjeremylt       if (out != CEED_VECTOR_NONE) {
14462b730f8bSJeremy L Thompson         CeedCall(CeedVectorSetValue(out, 0.0));
1447cae8b89aSjeremylt       }
1448d1d35e2fSjeremylt       for (CeedInt i = 0; i < num_suboperators; i++) {
1449d1d35e2fSjeremylt         for (CeedInt j = 0; j < sub_operators[i]->qf->num_output_fields; j++) {
1450d1d35e2fSjeremylt           CeedVector vec = sub_operators[i]->output_fields[j]->vec;
1451250756a7Sjeremylt           if (vec != CEED_VECTOR_ACTIVE && vec != CEED_VECTOR_NONE) {
14522b730f8bSJeremy L Thompson             CeedCall(CeedVectorSetValue(vec, 0.0));
1453250756a7Sjeremylt           }
1454250756a7Sjeremylt         }
1455250756a7Sjeremylt       }
1456250756a7Sjeremylt       // Apply
1457d1d35e2fSjeremylt       for (CeedInt i = 0; i < op->num_suboperators; i++) {
14582b730f8bSJeremy L Thompson         CeedCall(CeedOperatorApplyAdd(op->sub_operators[i], in, out, request));
1459cae8b89aSjeremylt       }
1460cae8b89aSjeremylt     }
1461250756a7Sjeremylt   }
1462e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
1463cae8b89aSjeremylt }
1464cae8b89aSjeremylt 
1465cae8b89aSjeremylt /**
1466cae8b89aSjeremylt   @brief Apply CeedOperator to a vector and add result to output vector
1467cae8b89aSjeremylt 
1468ea61e9acSJeremy L Thompson   This computes the action of the operator on the specified (active) input, yielding its (active) output.
1469ea61e9acSJeremy L Thompson   All inputs and outputs must be specified using CeedOperatorSetField().
1470cae8b89aSjeremylt 
1471ea61e9acSJeremy L Thompson   @param[in]  op      CeedOperator to apply
1472ea61e9acSJeremy L Thompson   @param[in]  in      CeedVector containing input state or NULL if there are no active inputs
1473ea61e9acSJeremy 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
1474ea61e9acSJeremy L Thompson   @param[in]  request Address of CeedRequest for non-blocking completion, else @ref CEED_REQUEST_IMMEDIATE
1475cae8b89aSjeremylt 
1476cae8b89aSjeremylt   @return An error code: 0 - success, otherwise - failure
1477cae8b89aSjeremylt 
14787a982d89SJeremy L. Thompson   @ref User
1479cae8b89aSjeremylt **/
14802b730f8bSJeremy L Thompson int CeedOperatorApplyAdd(CeedOperator op, CeedVector in, CeedVector out, CeedRequest *request) {
14812b730f8bSJeremy L Thompson   CeedCall(CeedOperatorCheckReady(op));
1482cae8b89aSjeremylt 
1483d1d35e2fSjeremylt   if (op->num_elem) {
1484250756a7Sjeremylt     // Standard Operator
14852b730f8bSJeremy L Thompson     CeedCall(op->ApplyAdd(op, in, out, request));
1486f04ea552SJeremy L Thompson   } else if (op->is_composite) {
1487250756a7Sjeremylt     // Composite Operator
1488250756a7Sjeremylt     if (op->ApplyAddComposite) {
14892b730f8bSJeremy L Thompson       CeedCall(op->ApplyAddComposite(op, in, out, request));
1490cae8b89aSjeremylt     } else {
1491d1d35e2fSjeremylt       CeedInt num_suboperators;
1492c6ebc35dSJeremy L Thompson       CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators));
1493d1d35e2fSjeremylt       CeedOperator *sub_operators;
1494c6ebc35dSJeremy L Thompson       CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators));
1495250756a7Sjeremylt 
1496d1d35e2fSjeremylt       for (CeedInt i = 0; i < num_suboperators; i++) {
14972b730f8bSJeremy L Thompson         CeedCall(CeedOperatorApplyAdd(sub_operators[i], in, out, request));
14981d7d2407SJeremy L Thompson       }
1499250756a7Sjeremylt     }
1500250756a7Sjeremylt   }
1501e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
1502d7b241e6Sjeremylt }
1503d7b241e6Sjeremylt 
1504d7b241e6Sjeremylt /**
1505b11c1e72Sjeremylt   @brief Destroy a CeedOperator
1506d7b241e6Sjeremylt 
1507ea61e9acSJeremy L Thompson   @param[in,out] op CeedOperator to destroy
1508b11c1e72Sjeremylt 
1509b11c1e72Sjeremylt   @return An error code: 0 - success, otherwise - failure
1510dfdf5a53Sjeremylt 
15117a982d89SJeremy L. Thompson   @ref User
1512b11c1e72Sjeremylt **/
1513d7b241e6Sjeremylt int CeedOperatorDestroy(CeedOperator *op) {
1514d1d35e2fSjeremylt   if (!*op || --(*op)->ref_count > 0) return CEED_ERROR_SUCCESS;
15152b730f8bSJeremy L Thompson   if ((*op)->Destroy) CeedCall((*op)->Destroy(*op));
15162b730f8bSJeremy L Thompson   CeedCall(CeedDestroy(&(*op)->ceed));
1517fe2413ffSjeremylt   // Free fields
15182b730f8bSJeremy L Thompson   for (CeedInt i = 0; i < (*op)->num_fields; i++) {
1519d1d35e2fSjeremylt     if ((*op)->input_fields[i]) {
1520d1d35e2fSjeremylt       if ((*op)->input_fields[i]->elem_restr != CEED_ELEMRESTRICTION_NONE) {
15212b730f8bSJeremy L Thompson         CeedCall(CeedElemRestrictionDestroy(&(*op)->input_fields[i]->elem_restr));
152215910d16Sjeremylt       }
1523d1d35e2fSjeremylt       if ((*op)->input_fields[i]->basis != CEED_BASIS_COLLOCATED) {
15242b730f8bSJeremy L Thompson         CeedCall(CeedBasisDestroy(&(*op)->input_fields[i]->basis));
152571352a93Sjeremylt       }
15262b730f8bSJeremy L Thompson       if ((*op)->input_fields[i]->vec != CEED_VECTOR_ACTIVE && (*op)->input_fields[i]->vec != CEED_VECTOR_NONE) {
15272b730f8bSJeremy L Thompson         CeedCall(CeedVectorDestroy(&(*op)->input_fields[i]->vec));
152871352a93Sjeremylt       }
15292b730f8bSJeremy L Thompson       CeedCall(CeedFree(&(*op)->input_fields[i]->field_name));
15302b730f8bSJeremy L Thompson       CeedCall(CeedFree(&(*op)->input_fields[i]));
1531fe2413ffSjeremylt     }
15322b730f8bSJeremy L Thompson   }
15332b730f8bSJeremy L Thompson   for (CeedInt i = 0; i < (*op)->num_fields; i++) {
1534d1d35e2fSjeremylt     if ((*op)->output_fields[i]) {
15352b730f8bSJeremy L Thompson       CeedCall(CeedElemRestrictionDestroy(&(*op)->output_fields[i]->elem_restr));
1536d1d35e2fSjeremylt       if ((*op)->output_fields[i]->basis != CEED_BASIS_COLLOCATED) {
15372b730f8bSJeremy L Thompson         CeedCall(CeedBasisDestroy(&(*op)->output_fields[i]->basis));
153871352a93Sjeremylt       }
15392b730f8bSJeremy L Thompson       if ((*op)->output_fields[i]->vec != CEED_VECTOR_ACTIVE && (*op)->output_fields[i]->vec != CEED_VECTOR_NONE) {
15402b730f8bSJeremy L Thompson         CeedCall(CeedVectorDestroy(&(*op)->output_fields[i]->vec));
154171352a93Sjeremylt       }
15422b730f8bSJeremy L Thompson       CeedCall(CeedFree(&(*op)->output_fields[i]->field_name));
15432b730f8bSJeremy L Thompson       CeedCall(CeedFree(&(*op)->output_fields[i]));
15442b730f8bSJeremy L Thompson     }
1545fe2413ffSjeremylt   }
1546d1d35e2fSjeremylt   // Destroy sub_operators
15472b730f8bSJeremy L Thompson   for (CeedInt i = 0; i < (*op)->num_suboperators; i++) {
1548d1d35e2fSjeremylt     if ((*op)->sub_operators[i]) {
15492b730f8bSJeremy L Thompson       CeedCall(CeedOperatorDestroy(&(*op)->sub_operators[i]));
155052d6035fSJeremy L Thompson     }
15512b730f8bSJeremy L Thompson   }
15522b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionDestroy(&(*op)->qf));
15532b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionDestroy(&(*op)->dqf));
15542b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionDestroy(&(*op)->dqfT));
15553668ca4bSJeremy L Thompson   // Destroy any composite labels
15563668ca4bSJeremy L Thompson   for (CeedInt i = 0; i < (*op)->num_context_labels; i++) {
15572b730f8bSJeremy L Thompson     CeedCall(CeedFree(&(*op)->context_labels[i]->sub_labels));
15582b730f8bSJeremy L Thompson     CeedCall(CeedFree(&(*op)->context_labels[i]));
15593668ca4bSJeremy L Thompson   }
15602b730f8bSJeremy L Thompson   CeedCall(CeedFree(&(*op)->context_labels));
1561fe2413ffSjeremylt 
15625107b09fSJeremy L Thompson   // Destroy fallback
15632b730f8bSJeremy L Thompson   CeedCall(CeedOperatorDestroy(&(*op)->op_fallback));
15645107b09fSJeremy L Thompson 
1565ed9e99e6SJeremy L Thompson   // Destroy assembly data
15662b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionAssemblyDataDestroy(&(*op)->qf_assembled));
15672b730f8bSJeremy L Thompson   CeedCall(CeedOperatorAssemblyDataDestroy(&(*op)->op_assembled));
156870a7ffb3SJeremy L Thompson 
15692b730f8bSJeremy L Thompson   CeedCall(CeedFree(&(*op)->input_fields));
15702b730f8bSJeremy L Thompson   CeedCall(CeedFree(&(*op)->output_fields));
15712b730f8bSJeremy L Thompson   CeedCall(CeedFree(&(*op)->sub_operators));
15722b730f8bSJeremy L Thompson   CeedCall(CeedFree(&(*op)->name));
15732b730f8bSJeremy L Thompson   CeedCall(CeedFree(op));
1574e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
1575d7b241e6Sjeremylt }
1576d7b241e6Sjeremylt 
1577d7b241e6Sjeremylt /// @}
1578