xref: /libCEED/interface/ceed-operator.c (revision 5ac9af79824b80047f0ad5edb72ebbe0eb874548)
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>
949aac155SJeremy L Thompson #include <ceed.h>
102b730f8bSJeremy L Thompson #include <ceed/backend.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,
85953dad27SJames 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,
94953dad27SJames 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,
116953dad27SJames 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     }
2252b730f8bSJeremy L Thompson   }
226eaf62fffSJeremy L Thompson 
227eaf62fffSJeremy L Thompson   if (!*active_basis) {
228eaf62fffSJeremy L Thompson     // LCOV_EXCL_START
2296aaed0edSJeremy L Thompson     return CeedError(ceed, CEED_ERROR_INCOMPLETE, "No active CeedBasis found");
230eaf62fffSJeremy L Thompson     // LCOV_EXCL_STOP
231eaf62fffSJeremy L Thompson   }
232eaf62fffSJeremy L Thompson   return CEED_ERROR_SUCCESS;
233eaf62fffSJeremy L Thompson }
234eaf62fffSJeremy L Thompson 
235eaf62fffSJeremy L Thompson /**
2360f60e0a8SJeremy L Thompson   @brief Find the active vector ElemRestriction for a non-composite CeedOperator
237e2f04181SAndrew T. Barker 
238e2f04181SAndrew T. Barker   @param[in] op           CeedOperator to find active basis for
2390f60e0a8SJeremy L Thompson   @param[out] active_rstr ElemRestriction for active input vector or NULL for composite operator
240e2f04181SAndrew T. Barker 
241e2f04181SAndrew T. Barker   @return An error code: 0 - success, otherwise - failure
242e2f04181SAndrew T. Barker 
243e2f04181SAndrew T. Barker   @ref Utility
244e2f04181SAndrew T. Barker **/
2452b730f8bSJeremy L Thompson int CeedOperatorGetActiveElemRestriction(CeedOperator op, CeedElemRestriction *active_rstr) {
2466aaed0edSJeremy L Thompson   Ceed ceed;
2476aaed0edSJeremy L Thompson   CeedCall(CeedOperatorGetCeed(op, &ceed));
2486aaed0edSJeremy L Thompson 
249d1d35e2fSjeremylt   *active_rstr = NULL;
2500f60e0a8SJeremy L Thompson   if (op->is_composite) return CEED_ERROR_SUCCESS;
2512b730f8bSJeremy L Thompson   for (CeedInt i = 0; i < op->qf->num_input_fields; i++) {
252d1d35e2fSjeremylt     if (op->input_fields[i]->vec == CEED_VECTOR_ACTIVE) {
253437c7c90SJeremy L Thompson       if (*active_rstr && *active_rstr != op->input_fields[i]->elem_rstr) {
2546aaed0edSJeremy L Thompson         // LCOV_EXCL_START
2556aaed0edSJeremy L Thompson         return CeedError(ceed, CEED_ERROR_MINOR, "Multiple active CeedElemRestrictions found");
2566aaed0edSJeremy L Thompson         // LCOV_EXCL_STOP
2576aaed0edSJeremy L Thompson       }
258437c7c90SJeremy L Thompson       *active_rstr = op->input_fields[i]->elem_rstr;
259e2f04181SAndrew T. Barker     }
2602b730f8bSJeremy L Thompson   }
261e2f04181SAndrew T. Barker 
262d1d35e2fSjeremylt   if (!*active_rstr) {
263e2f04181SAndrew T. Barker     // LCOV_EXCL_START
2642b730f8bSJeremy L Thompson     return CeedError(ceed, CEED_ERROR_INCOMPLETE, "No active CeedElemRestriction found");
265e2f04181SAndrew T. Barker     // LCOV_EXCL_STOP
266e2f04181SAndrew T. Barker   }
267e2f04181SAndrew T. Barker   return CEED_ERROR_SUCCESS;
268e2f04181SAndrew T. Barker }
269e2f04181SAndrew T. Barker 
270d8dd9a91SJeremy L Thompson /**
2712788fa27SJeremy L Thompson   @brief Set QFunctionContext field values of the specified type.
272ea61e9acSJeremy L Thompson            For composite operators, the value is set in all sub-operator QFunctionContexts that have a matching `field_name`.
273ea61e9acSJeremy 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
274ea61e9acSJeremy L Thompson not have any field of a matching type.
275d8dd9a91SJeremy L Thompson 
276ea61e9acSJeremy L Thompson   @param[in,out] op          CeedOperator
277ea61e9acSJeremy L Thompson   @param[in]     field_label Label of field to set
278ea61e9acSJeremy L Thompson   @param[in]     field_type  Type of field to set
2792788fa27SJeremy L Thompson   @param[in]     values      Values to set
280d8dd9a91SJeremy L Thompson 
281d8dd9a91SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
282d8dd9a91SJeremy L Thompson 
283d8dd9a91SJeremy L Thompson   @ref User
284d8dd9a91SJeremy L Thompson **/
2852788fa27SJeremy L Thompson static int CeedOperatorContextSetGeneric(CeedOperator op, CeedContextFieldLabel field_label, CeedContextFieldType field_type, void *values) {
2862b730f8bSJeremy L Thompson   if (!field_label) {
2873668ca4bSJeremy L Thompson     // LCOV_EXCL_START
2882b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label");
2893668ca4bSJeremy L Thompson     // LCOV_EXCL_STOP
2902b730f8bSJeremy L Thompson   }
2913668ca4bSJeremy L Thompson 
292*5ac9af79SJeremy L Thompson   // Check if field_label and op correspond
293*5ac9af79SJeremy L Thompson   if (field_label->from_op) {
294*5ac9af79SJeremy L Thompson     CeedInt index = -1;
295*5ac9af79SJeremy L Thompson 
296*5ac9af79SJeremy L Thompson     for (CeedInt i = 0; i < op->num_context_labels; i++) {
297*5ac9af79SJeremy L Thompson       if (op->context_labels[i] == field_label) index = i;
298*5ac9af79SJeremy L Thompson     }
299*5ac9af79SJeremy L Thompson     if (index == -1) {
300*5ac9af79SJeremy L Thompson       // LCOV_EXCL_START
301*5ac9af79SJeremy L Thompson       return CeedError(op->ceed, CEED_ERROR_UNSUPPORTED, "ContextFieldLabel does not correspond to the operator");
302*5ac9af79SJeremy L Thompson       // LCOV_EXCL_STOP
303*5ac9af79SJeremy L Thompson     }
304*5ac9af79SJeremy L Thompson   }
305*5ac9af79SJeremy L Thompson 
3063668ca4bSJeremy L Thompson   bool is_composite = false;
3072b730f8bSJeremy L Thompson   CeedCall(CeedOperatorIsComposite(op, &is_composite));
308d8dd9a91SJeremy L Thompson   if (is_composite) {
309d8dd9a91SJeremy L Thompson     CeedInt       num_sub;
310d8dd9a91SJeremy L Thompson     CeedOperator *sub_operators;
311d8dd9a91SJeremy L Thompson 
312c6ebc35dSJeremy L Thompson     CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub));
313c6ebc35dSJeremy L Thompson     CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators));
3142b730f8bSJeremy L Thompson     if (num_sub != field_label->num_sub_labels) {
3153668ca4bSJeremy L Thompson       // LCOV_EXCL_START
316*5ac9af79SJeremy L Thompson       CeedError(op->ceed, CEED_ERROR_UNSUPPORTED, "Composite operator modified after ContextFieldLabel created");
3173668ca4bSJeremy L Thompson       // LCOV_EXCL_STOP
3182b730f8bSJeremy L Thompson     }
319d8dd9a91SJeremy L Thompson 
320d8dd9a91SJeremy L Thompson     for (CeedInt i = 0; i < num_sub; i++) {
321d8dd9a91SJeremy L Thompson       // Try every sub-operator, ok if some sub-operators do not have field
3223668ca4bSJeremy L Thompson       if (field_label->sub_labels[i] && sub_operators[i]->qf->ctx) {
3232788fa27SJeremy L Thompson         CeedCall(CeedQFunctionContextSetGeneric(sub_operators[i]->qf->ctx, field_label->sub_labels[i], field_type, values));
324d8dd9a91SJeremy L Thompson       }
325d8dd9a91SJeremy L Thompson     }
326d8dd9a91SJeremy L Thompson   } else {
3272b730f8bSJeremy L Thompson     if (!op->qf->ctx) {
328d8dd9a91SJeremy L Thompson       // LCOV_EXCL_START
3292b730f8bSJeremy L Thompson       return CeedError(op->ceed, CEED_ERROR_UNSUPPORTED, "QFunction does not have context data");
330d8dd9a91SJeremy L Thompson       // LCOV_EXCL_STOP
3312b730f8bSJeremy L Thompson     }
332d8dd9a91SJeremy L Thompson 
3332788fa27SJeremy L Thompson     CeedCall(CeedQFunctionContextSetGeneric(op->qf->ctx, field_label, field_type, values));
3342788fa27SJeremy L Thompson   }
3352788fa27SJeremy L Thompson 
3362788fa27SJeremy L Thompson   return CEED_ERROR_SUCCESS;
3372788fa27SJeremy L Thompson }
3382788fa27SJeremy L Thompson 
3392788fa27SJeremy L Thompson /**
3402788fa27SJeremy L Thompson   @brief Get QFunctionContext field values of the specified type, read-only.
3412788fa27SJeremy L Thompson            For composite operators, the values retrieved are for the first sub-operator QFunctionContext that have a matching `field_name`.
342*5ac9af79SJeremy 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
343*5ac9af79SJeremy L Thompson            do not have any field of a matching type.
3442788fa27SJeremy L Thompson 
3452788fa27SJeremy L Thompson   @param[in,out] op          CeedOperator
3462788fa27SJeremy L Thompson   @param[in]     field_label Label of field to set
3472788fa27SJeremy L Thompson   @param[in]     field_type  Type of field to set
348c5d0f995SJed Brown   @param[out]    num_values  Number of values of type `field_type` in array `values`
349c5d0f995SJed Brown   @param[out]    values      Values in the label
3502788fa27SJeremy L Thompson 
3512788fa27SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
3522788fa27SJeremy L Thompson 
3532788fa27SJeremy L Thompson   @ref User
3542788fa27SJeremy L Thompson **/
3552788fa27SJeremy L Thompson static int CeedOperatorContextGetGenericRead(CeedOperator op, CeedContextFieldLabel field_label, CeedContextFieldType field_type, size_t *num_values,
3562788fa27SJeremy L Thompson                                              void *values) {
3572788fa27SJeremy L Thompson   if (!field_label) {
3582788fa27SJeremy L Thompson     // LCOV_EXCL_START
3592788fa27SJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label");
3602788fa27SJeremy L Thompson     // LCOV_EXCL_STOP
3612788fa27SJeremy L Thompson   }
3622788fa27SJeremy L Thompson 
3632788fa27SJeremy L Thompson   *(void **)values = NULL;
3642788fa27SJeremy L Thompson   *num_values      = 0;
3652788fa27SJeremy L Thompson 
366*5ac9af79SJeremy L Thompson   // Check if field_label and op correspond
367*5ac9af79SJeremy L Thompson   if (field_label->from_op) {
368*5ac9af79SJeremy L Thompson     CeedInt index = -1;
369*5ac9af79SJeremy L Thompson 
370*5ac9af79SJeremy L Thompson     for (CeedInt i = 0; i < op->num_context_labels; i++) {
371*5ac9af79SJeremy L Thompson       if (op->context_labels[i] == field_label) index = i;
372*5ac9af79SJeremy L Thompson     }
373*5ac9af79SJeremy L Thompson     if (index == -1) {
374*5ac9af79SJeremy L Thompson       // LCOV_EXCL_START
375*5ac9af79SJeremy L Thompson       return CeedError(op->ceed, CEED_ERROR_UNSUPPORTED, "ContextFieldLabel does not correspond to the operator");
376*5ac9af79SJeremy L Thompson       // LCOV_EXCL_STOP
377*5ac9af79SJeremy L Thompson     }
378*5ac9af79SJeremy L Thompson   }
379*5ac9af79SJeremy L Thompson 
3802788fa27SJeremy L Thompson   bool is_composite = false;
3812788fa27SJeremy L Thompson   CeedCall(CeedOperatorIsComposite(op, &is_composite));
3822788fa27SJeremy L Thompson   if (is_composite) {
3832788fa27SJeremy L Thompson     CeedInt       num_sub;
3842788fa27SJeremy L Thompson     CeedOperator *sub_operators;
3852788fa27SJeremy L Thompson 
3862788fa27SJeremy L Thompson     CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub));
3872788fa27SJeremy L Thompson     CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators));
3882788fa27SJeremy L Thompson     if (num_sub != field_label->num_sub_labels) {
3892788fa27SJeremy L Thompson       // LCOV_EXCL_START
390*5ac9af79SJeremy L Thompson       return CeedError(op->ceed, CEED_ERROR_UNSUPPORTED, "Composite operator modified after ContextFieldLabel created");
3912788fa27SJeremy L Thompson       // LCOV_EXCL_STOP
3922788fa27SJeremy L Thompson     }
3932788fa27SJeremy L Thompson 
3942788fa27SJeremy L Thompson     for (CeedInt i = 0; i < num_sub; i++) {
3952788fa27SJeremy L Thompson       // Try every sub-operator, ok if some sub-operators do not have field
3962788fa27SJeremy L Thompson       if (field_label->sub_labels[i] && sub_operators[i]->qf->ctx) {
3972788fa27SJeremy L Thompson         CeedCall(CeedQFunctionContextGetGenericRead(sub_operators[i]->qf->ctx, field_label->sub_labels[i], field_type, num_values, values));
3982788fa27SJeremy L Thompson         return CEED_ERROR_SUCCESS;
3992788fa27SJeremy L Thompson       }
4002788fa27SJeremy L Thompson     }
4012788fa27SJeremy L Thompson   } else {
4022788fa27SJeremy L Thompson     if (!op->qf->ctx) {
4032788fa27SJeremy L Thompson       // LCOV_EXCL_START
4042788fa27SJeremy L Thompson       return CeedError(op->ceed, CEED_ERROR_UNSUPPORTED, "QFunction does not have context data");
4052788fa27SJeremy L Thompson       // LCOV_EXCL_STOP
4062788fa27SJeremy L Thompson     }
4072788fa27SJeremy L Thompson 
4082788fa27SJeremy L Thompson     CeedCall(CeedQFunctionContextGetGenericRead(op->qf->ctx, field_label, field_type, num_values, values));
4092788fa27SJeremy L Thompson   }
4102788fa27SJeremy L Thompson 
4112788fa27SJeremy L Thompson   return CEED_ERROR_SUCCESS;
4122788fa27SJeremy L Thompson }
4132788fa27SJeremy L Thompson 
4142788fa27SJeremy L Thompson /**
4152788fa27SJeremy L Thompson   @brief Restore QFunctionContext field values of the specified type, read-only.
4162788fa27SJeremy L Thompson            For composite operators, the values restored are for the first sub-operator QFunctionContext that have a matching `field_name`.
417*5ac9af79SJeremy 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
418*5ac9af79SJeremy L Thompson            that do not have any field of a matching type.
4192788fa27SJeremy L Thompson 
4202788fa27SJeremy L Thompson   @param[in,out] op          CeedOperator
4212788fa27SJeremy L Thompson   @param[in]     field_label Label of field to set
4222788fa27SJeremy L Thompson   @param[in]     field_type  Type of field to set
423c5d0f995SJed Brown   @param[in]     values      Values array to restore
4242788fa27SJeremy L Thompson 
4252788fa27SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
4262788fa27SJeremy L Thompson 
4272788fa27SJeremy L Thompson   @ref User
4282788fa27SJeremy L Thompson **/
4292788fa27SJeremy L Thompson static int CeedOperatorContextRestoreGenericRead(CeedOperator op, CeedContextFieldLabel field_label, CeedContextFieldType field_type, void *values) {
4302788fa27SJeremy L Thompson   if (!field_label) {
4312788fa27SJeremy L Thompson     // LCOV_EXCL_START
4322788fa27SJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label");
4332788fa27SJeremy L Thompson     // LCOV_EXCL_STOP
4342788fa27SJeremy L Thompson   }
4352788fa27SJeremy L Thompson 
436*5ac9af79SJeremy L Thompson   // Check if field_label and op correspond
437*5ac9af79SJeremy L Thompson   if (field_label->from_op) {
438*5ac9af79SJeremy L Thompson     CeedInt index = -1;
439*5ac9af79SJeremy L Thompson 
440*5ac9af79SJeremy L Thompson     for (CeedInt i = 0; i < op->num_context_labels; i++) {
441*5ac9af79SJeremy L Thompson       if (op->context_labels[i] == field_label) index = i;
442*5ac9af79SJeremy L Thompson     }
443*5ac9af79SJeremy L Thompson     if (index == -1) {
444*5ac9af79SJeremy L Thompson       // LCOV_EXCL_START
445*5ac9af79SJeremy L Thompson       return CeedError(op->ceed, CEED_ERROR_UNSUPPORTED, "ContextFieldLabel does not correspond to the operator");
446*5ac9af79SJeremy L Thompson       // LCOV_EXCL_STOP
447*5ac9af79SJeremy L Thompson     }
448*5ac9af79SJeremy L Thompson   }
449*5ac9af79SJeremy L Thompson 
4502788fa27SJeremy L Thompson   bool is_composite = false;
4512788fa27SJeremy L Thompson   CeedCall(CeedOperatorIsComposite(op, &is_composite));
4522788fa27SJeremy L Thompson   if (is_composite) {
4532788fa27SJeremy L Thompson     CeedInt       num_sub;
4542788fa27SJeremy L Thompson     CeedOperator *sub_operators;
4552788fa27SJeremy L Thompson 
4562788fa27SJeremy L Thompson     CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub));
4572788fa27SJeremy L Thompson     CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators));
4582788fa27SJeremy L Thompson     if (num_sub != field_label->num_sub_labels) {
4592788fa27SJeremy L Thompson       // LCOV_EXCL_START
460*5ac9af79SJeremy L Thompson       return CeedError(op->ceed, CEED_ERROR_UNSUPPORTED, "Composite operator modified after ContextFieldLabel created");
4612788fa27SJeremy L Thompson       // LCOV_EXCL_STOP
4622788fa27SJeremy L Thompson     }
4632788fa27SJeremy L Thompson 
4642788fa27SJeremy L Thompson     for (CeedInt i = 0; i < num_sub; i++) {
4652788fa27SJeremy L Thompson       // Try every sub-operator, ok if some sub-operators do not have field
4662788fa27SJeremy L Thompson       if (field_label->sub_labels[i] && sub_operators[i]->qf->ctx) {
4672788fa27SJeremy L Thompson         CeedCall(CeedQFunctionContextRestoreGenericRead(sub_operators[i]->qf->ctx, field_label->sub_labels[i], field_type, values));
4682788fa27SJeremy L Thompson         return CEED_ERROR_SUCCESS;
4692788fa27SJeremy L Thompson       }
4702788fa27SJeremy L Thompson     }
4712788fa27SJeremy L Thompson   } else {
4722788fa27SJeremy L Thompson     if (!op->qf->ctx) {
4732788fa27SJeremy L Thompson       // LCOV_EXCL_START
4742788fa27SJeremy L Thompson       return CeedError(op->ceed, CEED_ERROR_UNSUPPORTED, "QFunction does not have context data");
4752788fa27SJeremy L Thompson       // LCOV_EXCL_STOP
4762788fa27SJeremy L Thompson     }
4772788fa27SJeremy L Thompson 
4782788fa27SJeremy L Thompson     CeedCall(CeedQFunctionContextRestoreGenericRead(op->qf->ctx, field_label, field_type, values));
479d8dd9a91SJeremy L Thompson   }
480d8dd9a91SJeremy L Thompson 
481d8dd9a91SJeremy L Thompson   return CEED_ERROR_SUCCESS;
482d8dd9a91SJeremy L Thompson }
483d8dd9a91SJeremy L Thompson 
4847a982d89SJeremy L. Thompson /// @}
4857a982d89SJeremy L. Thompson 
4867a982d89SJeremy L. Thompson /// ----------------------------------------------------------------------------
4877a982d89SJeremy L. Thompson /// CeedOperator Backend API
4887a982d89SJeremy L. Thompson /// ----------------------------------------------------------------------------
4897a982d89SJeremy L. Thompson /// @addtogroup CeedOperatorBackend
4907a982d89SJeremy L. Thompson /// @{
4917a982d89SJeremy L. Thompson 
4927a982d89SJeremy L. Thompson /**
4937a982d89SJeremy L. Thompson   @brief Get the number of arguments associated with a CeedOperator
4947a982d89SJeremy L. Thompson 
495ea61e9acSJeremy L Thompson   @param[in]  op        CeedOperator
496d1d35e2fSjeremylt   @param[out] num_args  Variable to store vector number of arguments
4977a982d89SJeremy L. Thompson 
4987a982d89SJeremy L. Thompson   @return An error code: 0 - success, otherwise - failure
4997a982d89SJeremy L. Thompson 
5007a982d89SJeremy L. Thompson   @ref Backend
5017a982d89SJeremy L. Thompson **/
5027a982d89SJeremy L. Thompson 
503d1d35e2fSjeremylt int CeedOperatorGetNumArgs(CeedOperator op, CeedInt *num_args) {
5042b730f8bSJeremy L Thompson   if (op->is_composite) {
5057a982d89SJeremy L. Thompson     // LCOV_EXCL_START
5062b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MINOR, "Not defined for composite operators");
5077a982d89SJeremy L. Thompson     // LCOV_EXCL_STOP
5082b730f8bSJeremy L Thompson   }
509d1d35e2fSjeremylt   *num_args = op->num_fields;
510e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
5117a982d89SJeremy L. Thompson }
5127a982d89SJeremy L. Thompson 
5137a982d89SJeremy L. Thompson /**
5147a982d89SJeremy L. Thompson   @brief Get the setup status of a CeedOperator
5157a982d89SJeremy L. Thompson 
516ea61e9acSJeremy L Thompson   @param[in]  op            CeedOperator
517d1d35e2fSjeremylt   @param[out] is_setup_done Variable to store setup status
5187a982d89SJeremy L. Thompson 
5197a982d89SJeremy L. Thompson   @return An error code: 0 - success, otherwise - failure
5207a982d89SJeremy L. Thompson 
5217a982d89SJeremy L. Thompson   @ref Backend
5227a982d89SJeremy L. Thompson **/
5237a982d89SJeremy L. Thompson 
524d1d35e2fSjeremylt int CeedOperatorIsSetupDone(CeedOperator op, bool *is_setup_done) {
525f04ea552SJeremy L Thompson   *is_setup_done = op->is_backend_setup;
526e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
5277a982d89SJeremy L. Thompson }
5287a982d89SJeremy L. Thompson 
5297a982d89SJeremy L. Thompson /**
5307a982d89SJeremy L. Thompson   @brief Get the QFunction associated with a CeedOperator
5317a982d89SJeremy L. Thompson 
532ea61e9acSJeremy L Thompson   @param[in]  op CeedOperator
5337a982d89SJeremy L. Thompson   @param[out] qf Variable to store QFunction
5347a982d89SJeremy L. Thompson 
5357a982d89SJeremy L. Thompson   @return An error code: 0 - success, otherwise - failure
5367a982d89SJeremy L. Thompson 
5377a982d89SJeremy L. Thompson   @ref Backend
5387a982d89SJeremy L. Thompson **/
5397a982d89SJeremy L. Thompson 
5407a982d89SJeremy L. Thompson int CeedOperatorGetQFunction(CeedOperator op, CeedQFunction *qf) {
5412b730f8bSJeremy L Thompson   if (op->is_composite) {
5427a982d89SJeremy L. Thompson     // LCOV_EXCL_START
5432b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MINOR, "Not defined for composite operator");
5447a982d89SJeremy L. Thompson     // LCOV_EXCL_STOP
5452b730f8bSJeremy L Thompson   }
5467a982d89SJeremy L. Thompson   *qf = op->qf;
547e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
5487a982d89SJeremy L. Thompson }
5497a982d89SJeremy L. Thompson 
5507a982d89SJeremy L. Thompson /**
551c04a41a7SJeremy L Thompson   @brief Get a boolean value indicating if the CeedOperator is composite
552c04a41a7SJeremy L Thompson 
553ea61e9acSJeremy L Thompson   @param[in]  op           CeedOperator
554d1d35e2fSjeremylt   @param[out] is_composite Variable to store composite status
555c04a41a7SJeremy L Thompson 
556c04a41a7SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
557c04a41a7SJeremy L Thompson 
558c04a41a7SJeremy L Thompson   @ref Backend
559c04a41a7SJeremy L Thompson **/
560c04a41a7SJeremy L Thompson 
561d1d35e2fSjeremylt int CeedOperatorIsComposite(CeedOperator op, bool *is_composite) {
562f04ea552SJeremy L Thompson   *is_composite = op->is_composite;
563e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
564c04a41a7SJeremy L Thompson }
565c04a41a7SJeremy L Thompson 
566c04a41a7SJeremy L Thompson /**
5677a982d89SJeremy L. Thompson   @brief Get the backend data of a CeedOperator
5687a982d89SJeremy L. Thompson 
569ea61e9acSJeremy L Thompson   @param[in]  op   CeedOperator
5707a982d89SJeremy L. Thompson   @param[out] data Variable to store data
5717a982d89SJeremy L. Thompson 
5727a982d89SJeremy L. Thompson   @return An error code: 0 - success, otherwise - failure
5737a982d89SJeremy L. Thompson 
5747a982d89SJeremy L. Thompson   @ref Backend
5757a982d89SJeremy L. Thompson **/
5767a982d89SJeremy L. Thompson 
577777ff853SJeremy L Thompson int CeedOperatorGetData(CeedOperator op, void *data) {
578777ff853SJeremy L Thompson   *(void **)data = op->data;
579e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
5807a982d89SJeremy L. Thompson }
5817a982d89SJeremy L. Thompson 
5827a982d89SJeremy L. Thompson /**
5837a982d89SJeremy L. Thompson   @brief Set the backend data of a CeedOperator
5847a982d89SJeremy L. Thompson 
585ea61e9acSJeremy L Thompson   @param[in,out] op   CeedOperator
586ea61e9acSJeremy L Thompson   @param[in]     data Data to set
5877a982d89SJeremy L. Thompson 
5887a982d89SJeremy L. Thompson   @return An error code: 0 - success, otherwise - failure
5897a982d89SJeremy L. Thompson 
5907a982d89SJeremy L. Thompson   @ref Backend
5917a982d89SJeremy L. Thompson **/
5927a982d89SJeremy L. Thompson 
593777ff853SJeremy L Thompson int CeedOperatorSetData(CeedOperator op, void *data) {
594777ff853SJeremy L Thompson   op->data = data;
595e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
5967a982d89SJeremy L. Thompson }
5977a982d89SJeremy L. Thompson 
5987a982d89SJeremy L. Thompson /**
59934359f16Sjeremylt   @brief Increment the reference counter for a CeedOperator
60034359f16Sjeremylt 
601ea61e9acSJeremy L Thompson   @param[in,out] op CeedOperator to increment the reference counter
60234359f16Sjeremylt 
60334359f16Sjeremylt   @return An error code: 0 - success, otherwise - failure
60434359f16Sjeremylt 
60534359f16Sjeremylt   @ref Backend
60634359f16Sjeremylt **/
6079560d06aSjeremylt int CeedOperatorReference(CeedOperator op) {
60834359f16Sjeremylt   op->ref_count++;
60934359f16Sjeremylt   return CEED_ERROR_SUCCESS;
61034359f16Sjeremylt }
61134359f16Sjeremylt 
61234359f16Sjeremylt /**
6137a982d89SJeremy L. Thompson   @brief Set the setup flag of a CeedOperator to True
6147a982d89SJeremy L. Thompson 
615ea61e9acSJeremy L Thompson   @param[in,out] op CeedOperator
6167a982d89SJeremy L. Thompson 
6177a982d89SJeremy L. Thompson   @return An error code: 0 - success, otherwise - failure
6187a982d89SJeremy L. Thompson 
6197a982d89SJeremy L. Thompson   @ref Backend
6207a982d89SJeremy L. Thompson **/
6217a982d89SJeremy L. Thompson 
6227a982d89SJeremy L. Thompson int CeedOperatorSetSetupDone(CeedOperator op) {
623f04ea552SJeremy L Thompson   op->is_backend_setup = true;
624e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
6257a982d89SJeremy L. Thompson }
6267a982d89SJeremy L. Thompson 
6277a982d89SJeremy L. Thompson /// @}
6287a982d89SJeremy L. Thompson 
6297a982d89SJeremy L. Thompson /// ----------------------------------------------------------------------------
6307a982d89SJeremy L. Thompson /// CeedOperator Public API
6317a982d89SJeremy L. Thompson /// ----------------------------------------------------------------------------
6327a982d89SJeremy L. Thompson /// @addtogroup CeedOperatorUser
633dfdf5a53Sjeremylt /// @{
634d7b241e6Sjeremylt 
635d7b241e6Sjeremylt /**
636ea61e9acSJeremy L Thompson   @brief Create a CeedOperator and associate a CeedQFunction.
637ea61e9acSJeremy L Thompson            A CeedBasis and CeedElemRestriction can be associated with CeedQFunction fields with \ref CeedOperatorSetField.
638d7b241e6Sjeremylt 
639ea61e9acSJeremy L Thompson   @param[in]  ceed Ceed object where the CeedOperator will be created
640ea61e9acSJeremy L Thompson   @param[in]  qf   QFunction defining the action of the operator at quadrature points
641ea61e9acSJeremy L Thompson   @param[in]  dqf  QFunction defining the action of the Jacobian of @a qf (or @ref CEED_QFUNCTION_NONE)
642ea61e9acSJeremy L Thompson   @param[in]  dqfT QFunction defining the action of the transpose of the Jacobian of @a qf (or @ref CEED_QFUNCTION_NONE)
643ea61e9acSJeremy L Thompson   @param[out] op   Address of the variable where the newly created CeedOperator will be stored
644b11c1e72Sjeremylt 
645b11c1e72Sjeremylt   @return An error code: 0 - success, otherwise - failure
646dfdf5a53Sjeremylt 
6477a982d89SJeremy L. Thompson   @ref User
648d7b241e6Sjeremylt  */
6492b730f8bSJeremy L Thompson int CeedOperatorCreate(Ceed ceed, CeedQFunction qf, CeedQFunction dqf, CeedQFunction dqfT, CeedOperator *op) {
6505fe0d4faSjeremylt   if (!ceed->OperatorCreate) {
6515fe0d4faSjeremylt     Ceed delegate;
6522b730f8bSJeremy L Thompson     CeedCall(CeedGetObjectDelegate(ceed, &delegate, "Operator"));
6535fe0d4faSjeremylt 
6542b730f8bSJeremy L Thompson     if (!delegate) {
655c042f62fSJeremy L Thompson       // LCOV_EXCL_START
6562b730f8bSJeremy L Thompson       return CeedError(ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support OperatorCreate");
657c042f62fSJeremy L Thompson       // LCOV_EXCL_STOP
6582b730f8bSJeremy L Thompson     }
6595fe0d4faSjeremylt 
6602b730f8bSJeremy L Thompson     CeedCall(CeedOperatorCreate(delegate, qf, dqf, dqfT, op));
661e15f9bd0SJeremy L Thompson     return CEED_ERROR_SUCCESS;
6625fe0d4faSjeremylt   }
6635fe0d4faSjeremylt 
6642b730f8bSJeremy L Thompson   if (!qf || qf == CEED_QFUNCTION_NONE) {
665b3b7035fSJeremy L Thompson     // LCOV_EXCL_START
6662b730f8bSJeremy L Thompson     return CeedError(ceed, CEED_ERROR_MINOR, "Operator must have a valid QFunction.");
667b3b7035fSJeremy L Thompson     // LCOV_EXCL_STOP
6682b730f8bSJeremy L Thompson   }
6692b730f8bSJeremy L Thompson   CeedCall(CeedCalloc(1, op));
670d7b241e6Sjeremylt   (*op)->ceed = ceed;
6712b730f8bSJeremy L Thompson   CeedCall(CeedReference(ceed));
672d1d35e2fSjeremylt   (*op)->ref_count   = 1;
673d7b241e6Sjeremylt   (*op)->qf          = qf;
6742b104005SJeremy L Thompson   (*op)->input_size  = -1;
6752b104005SJeremy L Thompson   (*op)->output_size = -1;
6762b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionReference(qf));
677442e7f0bSjeremylt   if (dqf && dqf != CEED_QFUNCTION_NONE) {
678d7b241e6Sjeremylt     (*op)->dqf = dqf;
6792b730f8bSJeremy L Thompson     CeedCall(CeedQFunctionReference(dqf));
680442e7f0bSjeremylt   }
681442e7f0bSjeremylt   if (dqfT && dqfT != CEED_QFUNCTION_NONE) {
682d7b241e6Sjeremylt     (*op)->dqfT = dqfT;
6832b730f8bSJeremy L Thompson     CeedCall(CeedQFunctionReference(dqfT));
684442e7f0bSjeremylt   }
6852b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionAssemblyDataCreate(ceed, &(*op)->qf_assembled));
6862b730f8bSJeremy L Thompson   CeedCall(CeedCalloc(CEED_FIELD_MAX, &(*op)->input_fields));
6872b730f8bSJeremy L Thompson   CeedCall(CeedCalloc(CEED_FIELD_MAX, &(*op)->output_fields));
6882b730f8bSJeremy L Thompson   CeedCall(ceed->OperatorCreate(*op));
689e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
690d7b241e6Sjeremylt }
691d7b241e6Sjeremylt 
692d7b241e6Sjeremylt /**
69352d6035fSJeremy L Thompson   @brief Create an operator that composes the action of several operators
69452d6035fSJeremy L Thompson 
695ea61e9acSJeremy L Thompson   @param[in]  ceed Ceed object where the CeedOperator will be created
696ea61e9acSJeremy L Thompson   @param[out] op   Address of the variable where the newly created Composite CeedOperator will be stored
69752d6035fSJeremy L Thompson 
69852d6035fSJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
69952d6035fSJeremy L Thompson 
7007a982d89SJeremy L. Thompson   @ref User
70152d6035fSJeremy L Thompson  */
70252d6035fSJeremy L Thompson int CeedCompositeOperatorCreate(Ceed ceed, CeedOperator *op) {
70352d6035fSJeremy L Thompson   if (!ceed->CompositeOperatorCreate) {
70452d6035fSJeremy L Thompson     Ceed delegate;
7052b730f8bSJeremy L Thompson     CeedCall(CeedGetObjectDelegate(ceed, &delegate, "Operator"));
70652d6035fSJeremy L Thompson 
707250756a7Sjeremylt     if (delegate) {
7082b730f8bSJeremy L Thompson       CeedCall(CeedCompositeOperatorCreate(delegate, op));
709e15f9bd0SJeremy L Thompson       return CEED_ERROR_SUCCESS;
71052d6035fSJeremy L Thompson     }
711250756a7Sjeremylt   }
71252d6035fSJeremy L Thompson 
7132b730f8bSJeremy L Thompson   CeedCall(CeedCalloc(1, op));
71452d6035fSJeremy L Thompson   (*op)->ceed = ceed;
7152b730f8bSJeremy L Thompson   CeedCall(CeedReference(ceed));
716996d9ab5SJed Brown   (*op)->ref_count    = 1;
717f04ea552SJeremy L Thompson   (*op)->is_composite = true;
7182b730f8bSJeremy L Thompson   CeedCall(CeedCalloc(CEED_COMPOSITE_MAX, &(*op)->sub_operators));
7192b104005SJeremy L Thompson   (*op)->input_size  = -1;
7202b104005SJeremy L Thompson   (*op)->output_size = -1;
721250756a7Sjeremylt 
722250756a7Sjeremylt   if (ceed->CompositeOperatorCreate) {
7232b730f8bSJeremy L Thompson     CeedCall(ceed->CompositeOperatorCreate(*op));
724250756a7Sjeremylt   }
725e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
72652d6035fSJeremy L Thompson }
72752d6035fSJeremy L Thompson 
72852d6035fSJeremy L Thompson /**
729ea61e9acSJeremy L Thompson   @brief Copy the pointer to a CeedOperator.
730ea61e9acSJeremy L Thompson            Both pointers should be destroyed with `CeedOperatorDestroy()`.
731512bb800SJeremy L Thompson 
732512bb800SJeremy L Thompson            Note: If the value of `op_copy` passed to this function is non-NULL, then it is assumed that `op_copy` is a pointer to a CeedOperator.
733512bb800SJeremy L Thompson              This CeedOperator will be destroyed if `op_copy` is the only reference to this CeedOperator.
7349560d06aSjeremylt 
735ea61e9acSJeremy L Thompson   @param[in]  op         CeedOperator to copy reference to
736ea61e9acSJeremy L Thompson   @param[in,out] op_copy Variable to store copied reference
7379560d06aSjeremylt 
7389560d06aSjeremylt   @return An error code: 0 - success, otherwise - failure
7399560d06aSjeremylt 
7409560d06aSjeremylt   @ref User
7419560d06aSjeremylt **/
7429560d06aSjeremylt int CeedOperatorReferenceCopy(CeedOperator op, CeedOperator *op_copy) {
7432b730f8bSJeremy L Thompson   CeedCall(CeedOperatorReference(op));
7442b730f8bSJeremy L Thompson   CeedCall(CeedOperatorDestroy(op_copy));
7459560d06aSjeremylt   *op_copy = op;
7469560d06aSjeremylt   return CEED_ERROR_SUCCESS;
7479560d06aSjeremylt }
7489560d06aSjeremylt 
7499560d06aSjeremylt /**
750ea61e9acSJeremy L Thompson   @brief Provide a field to a CeedOperator for use by its CeedQFunction.
751d7b241e6Sjeremylt 
752ea61e9acSJeremy L Thompson   This function is used to specify both active and passive fields to a CeedOperator.
753ea61e9acSJeremy L Thompson   For passive fields, a vector @arg v must be provided.
754ea61e9acSJeremy L Thompson   Passive fields can inputs or outputs (updated in-place when operator is applied).
755d7b241e6Sjeremylt 
756ea61e9acSJeremy L Thompson   Active fields must be specified using this function, but their data (in a CeedVector) is passed in CeedOperatorApply().
757ea61e9acSJeremy L Thompson   There can be at most one active input CeedVector and at most one active output CeedVector passed to CeedOperatorApply().
758d7b241e6Sjeremylt 
759ea61e9acSJeremy L Thompson   @param[in,out] op         CeedOperator on which to provide the field
760ea61e9acSJeremy L Thompson   @param[in]     field_name Name of the field (to be matched with the name used by CeedQFunction)
761ea61e9acSJeremy L Thompson   @param[in]     r          CeedElemRestriction
762ea61e9acSJeremy L Thompson   @param[in]     b          CeedBasis in which the field resides or @ref CEED_BASIS_COLLOCATED if collocated with quadrature points
763*5ac9af79SJeremy 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
764*5ac9af79SJeremy L Thompson                               if using @ref CEED_EVAL_WEIGHT in the QFunction
765b11c1e72Sjeremylt 
766b11c1e72Sjeremylt   @return An error code: 0 - success, otherwise - failure
767dfdf5a53Sjeremylt 
7687a982d89SJeremy L. Thompson   @ref User
769b11c1e72Sjeremylt **/
7702b730f8bSJeremy L Thompson int CeedOperatorSetField(CeedOperator op, const char *field_name, CeedElemRestriction r, CeedBasis b, CeedVector v) {
7712b730f8bSJeremy L Thompson   if (op->is_composite) {
772c042f62fSJeremy L Thompson     // LCOV_EXCL_START
7732b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_INCOMPATIBLE, "Cannot add field to composite operator.");
774c042f62fSJeremy L Thompson     // LCOV_EXCL_STOP
7752b730f8bSJeremy L Thompson   }
7762b730f8bSJeremy L Thompson   if (op->is_immutable) {
777f04ea552SJeremy L Thompson     // LCOV_EXCL_START
7782b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable");
779f04ea552SJeremy L Thompson     // LCOV_EXCL_STOP
7802b730f8bSJeremy L Thompson   }
7812b730f8bSJeremy L Thompson   if (!r) {
782c042f62fSJeremy L Thompson     // LCOV_EXCL_START
7832b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_INCOMPATIBLE, "ElemRestriction r for field \"%s\" must be non-NULL.", field_name);
784c042f62fSJeremy L Thompson     // LCOV_EXCL_STOP
7852b730f8bSJeremy L Thompson   }
7862b730f8bSJeremy L Thompson   if (!b) {
787c042f62fSJeremy L Thompson     // LCOV_EXCL_START
7882b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_INCOMPATIBLE, "Basis b for field \"%s\" must be non-NULL.", field_name);
789c042f62fSJeremy L Thompson     // LCOV_EXCL_STOP
7902b730f8bSJeremy L Thompson   }
7912b730f8bSJeremy L Thompson   if (!v) {
792c042f62fSJeremy L Thompson     // LCOV_EXCL_START
7932b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_INCOMPATIBLE, "Vector v for field \"%s\" must be non-NULL.", field_name);
794c042f62fSJeremy L Thompson     // LCOV_EXCL_STOP
7952b730f8bSJeremy L Thompson   }
79652d6035fSJeremy L Thompson 
797d1d35e2fSjeremylt   CeedInt num_elem;
7982b730f8bSJeremy L Thompson   CeedCall(CeedElemRestrictionGetNumElements(r, &num_elem));
7992b730f8bSJeremy L Thompson   if (r != CEED_ELEMRESTRICTION_NONE && op->has_restriction && op->num_elem != num_elem) {
800c042f62fSJeremy L Thompson     // LCOV_EXCL_START
801e15f9bd0SJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_DIMENSION,
8022b730f8bSJeremy L Thompson                      "ElemRestriction with %" CeedInt_FMT " elements incompatible with prior %" CeedInt_FMT " elements", num_elem, op->num_elem);
803c042f62fSJeremy L Thompson     // LCOV_EXCL_STOP
8042b730f8bSJeremy L Thompson   }
805d7b241e6Sjeremylt 
80678464608Sjeremylt   CeedInt num_qpts = 0;
807e15f9bd0SJeremy L Thompson   if (b != CEED_BASIS_COLLOCATED) {
8082b730f8bSJeremy L Thompson     CeedCall(CeedBasisGetNumQuadraturePoints(b, &num_qpts));
8092b730f8bSJeremy L Thompson     if (op->num_qpts && op->num_qpts != num_qpts) {
810c042f62fSJeremy L Thompson       // LCOV_EXCL_START
811e15f9bd0SJeremy L Thompson       return CeedError(op->ceed, CEED_ERROR_DIMENSION,
8122b730f8bSJeremy L Thompson                        "Basis with %" CeedInt_FMT " quadrature points incompatible with prior %" CeedInt_FMT " points", num_qpts, op->num_qpts);
813c042f62fSJeremy L Thompson       // LCOV_EXCL_STOP
814d7b241e6Sjeremylt     }
8152b730f8bSJeremy L Thompson   }
816d1d35e2fSjeremylt   CeedQFunctionField qf_field;
817d1d35e2fSjeremylt   CeedOperatorField *op_field;
8182b104005SJeremy L Thompson   bool               is_input = true;
819d1d35e2fSjeremylt   for (CeedInt i = 0; i < op->qf->num_input_fields; i++) {
820d1d35e2fSjeremylt     if (!strcmp(field_name, (*op->qf->input_fields[i]).field_name)) {
821d1d35e2fSjeremylt       qf_field = op->qf->input_fields[i];
822d1d35e2fSjeremylt       op_field = &op->input_fields[i];
823d7b241e6Sjeremylt       goto found;
824d7b241e6Sjeremylt     }
825d7b241e6Sjeremylt   }
8262b104005SJeremy L Thompson   is_input = false;
827d1d35e2fSjeremylt   for (CeedInt i = 0; i < op->qf->num_output_fields; i++) {
828d1d35e2fSjeremylt     if (!strcmp(field_name, (*op->qf->output_fields[i]).field_name)) {
829d1d35e2fSjeremylt       qf_field = op->qf->output_fields[i];
830d1d35e2fSjeremylt       op_field = &op->output_fields[i];
831d7b241e6Sjeremylt       goto found;
832d7b241e6Sjeremylt     }
833d7b241e6Sjeremylt   }
834c042f62fSJeremy L Thompson   // LCOV_EXCL_START
8352b730f8bSJeremy L Thompson   return CeedError(op->ceed, CEED_ERROR_INCOMPLETE, "QFunction has no knowledge of field '%s'", field_name);
836c042f62fSJeremy L Thompson   // LCOV_EXCL_STOP
837d7b241e6Sjeremylt found:
8382b730f8bSJeremy L Thompson   CeedCall(CeedOperatorCheckField(op->ceed, qf_field, r, b));
8392b730f8bSJeremy L Thompson   CeedCall(CeedCalloc(1, op_field));
840e15f9bd0SJeremy L Thompson 
8412b104005SJeremy L Thompson   if (v == CEED_VECTOR_ACTIVE) {
8422b104005SJeremy L Thompson     CeedSize l_size;
8432b730f8bSJeremy L Thompson     CeedCall(CeedElemRestrictionGetLVectorSize(r, &l_size));
8442b104005SJeremy L Thompson     if (is_input) {
8452b104005SJeremy L Thompson       if (op->input_size == -1) op->input_size = l_size;
8462b730f8bSJeremy L Thompson       if (l_size != op->input_size) {
8472b104005SJeremy L Thompson         // LCOV_EXCL_START
8482b730f8bSJeremy L Thompson         return CeedError(op->ceed, CEED_ERROR_INCOMPATIBLE, "LVector size %td does not match previous size %td", l_size, op->input_size);
8492b104005SJeremy L Thompson         // LCOV_EXCL_STOP
8502b730f8bSJeremy L Thompson       }
8512b104005SJeremy L Thompson     } else {
8522b104005SJeremy L Thompson       if (op->output_size == -1) op->output_size = l_size;
8532b730f8bSJeremy L Thompson       if (l_size != op->output_size) {
8542b104005SJeremy L Thompson         // LCOV_EXCL_START
8552b730f8bSJeremy L Thompson         return CeedError(op->ceed, CEED_ERROR_INCOMPATIBLE, "LVector size %td does not match previous size %td", l_size, op->output_size);
8562b104005SJeremy L Thompson         // LCOV_EXCL_STOP
8572b104005SJeremy L Thompson       }
8582b104005SJeremy L Thompson     }
8592b730f8bSJeremy L Thompson   }
8602b104005SJeremy L Thompson 
861d1d35e2fSjeremylt   (*op_field)->vec = v;
862e15f9bd0SJeremy L Thompson   if (v != CEED_VECTOR_ACTIVE && v != CEED_VECTOR_NONE) {
8632b730f8bSJeremy L Thompson     CeedCall(CeedVectorReference(v));
864e15f9bd0SJeremy L Thompson   }
865e15f9bd0SJeremy L Thompson 
866437c7c90SJeremy L Thompson   (*op_field)->elem_rstr = r;
8672b730f8bSJeremy L Thompson   CeedCall(CeedElemRestrictionReference(r));
868e15f9bd0SJeremy L Thompson   if (r != CEED_ELEMRESTRICTION_NONE) {
869d1d35e2fSjeremylt     op->num_elem        = num_elem;
870d1d35e2fSjeremylt     op->has_restriction = true;  // Restriction set, but num_elem may be 0
871e15f9bd0SJeremy L Thompson   }
872d99fa3c5SJeremy L Thompson 
873d1d35e2fSjeremylt   (*op_field)->basis = b;
874e15f9bd0SJeremy L Thompson   if (b != CEED_BASIS_COLLOCATED) {
875cd4dfc48Sjeremylt     if (!op->num_qpts) {
8762b730f8bSJeremy L Thompson       CeedCall(CeedOperatorSetNumQuadraturePoints(op, num_qpts));
877cd4dfc48Sjeremylt     }
8782b730f8bSJeremy L Thompson     CeedCall(CeedBasisReference(b));
879e15f9bd0SJeremy L Thompson   }
880e15f9bd0SJeremy L Thompson 
881d1d35e2fSjeremylt   op->num_fields += 1;
8822b730f8bSJeremy L Thompson   CeedCall(CeedStringAllocCopy(field_name, (char **)&(*op_field)->field_name));
883e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
884d7b241e6Sjeremylt }
885d7b241e6Sjeremylt 
886d7b241e6Sjeremylt /**
88743bbe138SJeremy L Thompson   @brief Get the CeedOperatorFields of a CeedOperator
88843bbe138SJeremy L Thompson 
889ea61e9acSJeremy L Thompson   Note: Calling this function asserts that setup is complete and sets the CeedOperator as immutable.
890f04ea552SJeremy L Thompson 
891ea61e9acSJeremy L Thompson   @param[in]  op                CeedOperator
892f74ec584SJeremy L Thompson   @param[out] num_input_fields  Variable to store number of input fields
89343bbe138SJeremy L Thompson   @param[out] input_fields      Variable to store input_fields
894f74ec584SJeremy L Thompson   @param[out] num_output_fields Variable to store number of output fields
89543bbe138SJeremy L Thompson   @param[out] output_fields     Variable to store output_fields
89643bbe138SJeremy L Thompson 
89743bbe138SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
89843bbe138SJeremy L Thompson 
899e9b533fbSJeremy L Thompson   @ref Advanced
90043bbe138SJeremy L Thompson **/
9012b730f8bSJeremy L Thompson int CeedOperatorGetFields(CeedOperator op, CeedInt *num_input_fields, CeedOperatorField **input_fields, CeedInt *num_output_fields,
90243bbe138SJeremy L Thompson                           CeedOperatorField **output_fields) {
9032b730f8bSJeremy L Thompson   if (op->is_composite) {
90443bbe138SJeremy L Thompson     // LCOV_EXCL_START
9052b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MINOR, "Not defined for composite operator");
90643bbe138SJeremy L Thompson     // LCOV_EXCL_STOP
9072b730f8bSJeremy L Thompson   }
9082b730f8bSJeremy L Thompson   CeedCall(CeedOperatorCheckReady(op));
90943bbe138SJeremy L Thompson 
91043bbe138SJeremy L Thompson   if (num_input_fields) *num_input_fields = op->qf->num_input_fields;
91143bbe138SJeremy L Thompson   if (input_fields) *input_fields = op->input_fields;
91243bbe138SJeremy L Thompson   if (num_output_fields) *num_output_fields = op->qf->num_output_fields;
91343bbe138SJeremy L Thompson   if (output_fields) *output_fields = op->output_fields;
91443bbe138SJeremy L Thompson   return CEED_ERROR_SUCCESS;
91543bbe138SJeremy L Thompson }
91643bbe138SJeremy L Thompson 
91743bbe138SJeremy L Thompson /**
918de5900adSJames Wright   @brief Get a CeedOperatorField of an CeedOperator from its name
919de5900adSJames Wright 
920de5900adSJames Wright   Note: Calling this function asserts that setup is complete and sets the CeedOperator as immutable.
921de5900adSJames Wright 
922de5900adSJames Wright   @param[in]  op         CeedOperator
923de5900adSJames Wright   @param[in]  field_name Name of desired CeedOperatorField
924de5900adSJames Wright   @param[out] op_field   CeedOperatorField corresponding to the name
925de5900adSJames Wright 
926de5900adSJames Wright   @return An error code: 0 - success, otherwise - failure
927de5900adSJames Wright 
928de5900adSJames Wright   @ref Advanced
929de5900adSJames Wright **/
930de5900adSJames Wright int CeedOperatorGetFieldByName(CeedOperator op, const char *field_name, CeedOperatorField *op_field) {
931de5900adSJames Wright   CeedInt            num_input_fields, num_output_fields;
932de5900adSJames Wright   CeedOperatorField *input_fields, *output_fields;
933de5900adSJames Wright   char              *name;
934de5900adSJames Wright   CeedCall(CeedOperatorGetFields(op, &num_input_fields, &input_fields, &num_output_fields, &output_fields));
935de5900adSJames Wright 
936de5900adSJames Wright   for (CeedInt i = 0; i < num_input_fields; i++) {
937de5900adSJames Wright     CeedCall(CeedOperatorFieldGetName(input_fields[i], &name));
938de5900adSJames Wright     if (!strcmp(name, field_name)) {
939de5900adSJames Wright       *op_field = input_fields[i];
940de5900adSJames Wright       return CEED_ERROR_SUCCESS;
941de5900adSJames Wright     }
942de5900adSJames Wright   }
943de5900adSJames Wright 
944de5900adSJames Wright   for (CeedInt i = 0; i < num_output_fields; i++) {
945de5900adSJames Wright     CeedCall(CeedOperatorFieldGetName(output_fields[i], &name));
946de5900adSJames Wright     if (!strcmp(name, field_name)) {
947de5900adSJames Wright       *op_field = output_fields[i];
948de5900adSJames Wright       return CEED_ERROR_SUCCESS;
949de5900adSJames Wright     }
950de5900adSJames Wright   }
951de5900adSJames Wright 
952de5900adSJames Wright   bool has_name = op->name;
953de5900adSJames Wright   // LCOV_EXCL_START
954de5900adSJames Wright   return CeedError(op->ceed, CEED_ERROR_MINOR, "The field \"%s\" not found in CeedOperator%s%s%s.\n", field_name, has_name ? " \"" : "",
955de5900adSJames Wright                    has_name ? op->name : "", has_name ? "\"" : "");
956de5900adSJames Wright   // LCOV_EXCL_STOP
957de5900adSJames Wright }
958de5900adSJames Wright 
959de5900adSJames Wright /**
96028567f8fSJeremy L Thompson   @brief Get the name of a CeedOperatorField
96128567f8fSJeremy L Thompson 
962ea61e9acSJeremy L Thompson   @param[in]  op_field    CeedOperatorField
96328567f8fSJeremy L Thompson   @param[out] field_name  Variable to store the field name
96428567f8fSJeremy L Thompson 
96528567f8fSJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
96628567f8fSJeremy L Thompson 
967e9b533fbSJeremy L Thompson   @ref Advanced
96828567f8fSJeremy L Thompson **/
96928567f8fSJeremy L Thompson int CeedOperatorFieldGetName(CeedOperatorField op_field, char **field_name) {
97028567f8fSJeremy L Thompson   *field_name = (char *)op_field->field_name;
97128567f8fSJeremy L Thompson   return CEED_ERROR_SUCCESS;
97228567f8fSJeremy L Thompson }
97328567f8fSJeremy L Thompson 
97428567f8fSJeremy L Thompson /**
97543bbe138SJeremy L Thompson   @brief Get the CeedElemRestriction of a CeedOperatorField
97643bbe138SJeremy L Thompson 
977ea61e9acSJeremy L Thompson   @param[in]  op_field CeedOperatorField
97843bbe138SJeremy L Thompson   @param[out] rstr     Variable to store CeedElemRestriction
97943bbe138SJeremy L Thompson 
98043bbe138SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
98143bbe138SJeremy L Thompson 
982e9b533fbSJeremy L Thompson   @ref Advanced
98343bbe138SJeremy L Thompson **/
9842b730f8bSJeremy L Thompson int CeedOperatorFieldGetElemRestriction(CeedOperatorField op_field, CeedElemRestriction *rstr) {
985437c7c90SJeremy L Thompson   *rstr = op_field->elem_rstr;
98643bbe138SJeremy L Thompson   return CEED_ERROR_SUCCESS;
98743bbe138SJeremy L Thompson }
98843bbe138SJeremy L Thompson 
98943bbe138SJeremy L Thompson /**
99043bbe138SJeremy L Thompson   @brief Get the CeedBasis of a CeedOperatorField
99143bbe138SJeremy L Thompson 
992ea61e9acSJeremy L Thompson   @param[in]  op_field CeedOperatorField
99343bbe138SJeremy L Thompson   @param[out] basis    Variable to store CeedBasis
99443bbe138SJeremy L Thompson 
99543bbe138SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
99643bbe138SJeremy L Thompson 
997e9b533fbSJeremy L Thompson   @ref Advanced
99843bbe138SJeremy L Thompson **/
99943bbe138SJeremy L Thompson int CeedOperatorFieldGetBasis(CeedOperatorField op_field, CeedBasis *basis) {
100043bbe138SJeremy L Thompson   *basis = op_field->basis;
100143bbe138SJeremy L Thompson   return CEED_ERROR_SUCCESS;
100243bbe138SJeremy L Thompson }
100343bbe138SJeremy L Thompson 
100443bbe138SJeremy L Thompson /**
100543bbe138SJeremy L Thompson   @brief Get the CeedVector of a CeedOperatorField
100643bbe138SJeremy L Thompson 
1007ea61e9acSJeremy L Thompson   @param[in]  op_field CeedOperatorField
100843bbe138SJeremy L Thompson   @param[out] vec      Variable to store CeedVector
100943bbe138SJeremy L Thompson 
101043bbe138SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
101143bbe138SJeremy L Thompson 
1012e9b533fbSJeremy L Thompson   @ref Advanced
101343bbe138SJeremy L Thompson **/
101443bbe138SJeremy L Thompson int CeedOperatorFieldGetVector(CeedOperatorField op_field, CeedVector *vec) {
101543bbe138SJeremy L Thompson   *vec = op_field->vec;
101643bbe138SJeremy L Thompson   return CEED_ERROR_SUCCESS;
101743bbe138SJeremy L Thompson }
101843bbe138SJeremy L Thompson 
101943bbe138SJeremy L Thompson /**
102052d6035fSJeremy L Thompson   @brief Add a sub-operator to a composite CeedOperator
1021288c0443SJeremy L Thompson 
1022ea61e9acSJeremy L Thompson   @param[in,out] composite_op Composite CeedOperator
1023ea61e9acSJeremy L Thompson   @param[in]     sub_op       Sub-operator CeedOperator
102452d6035fSJeremy L Thompson 
102552d6035fSJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
102652d6035fSJeremy L Thompson 
10277a982d89SJeremy L. Thompson   @ref User
102852d6035fSJeremy L Thompson  */
10292b730f8bSJeremy L Thompson int CeedCompositeOperatorAddSub(CeedOperator composite_op, CeedOperator sub_op) {
10302b730f8bSJeremy L Thompson   if (!composite_op->is_composite) {
1031c042f62fSJeremy L Thompson     // LCOV_EXCL_START
10322b730f8bSJeremy L Thompson     return CeedError(composite_op->ceed, CEED_ERROR_MINOR, "CeedOperator is not a composite operator");
10332b104005SJeremy L Thompson     // LCOV_EXCL_STOP
10342b104005SJeremy L Thompson   }
10352b104005SJeremy L Thompson 
10362b730f8bSJeremy L Thompson   if (composite_op->num_suboperators == CEED_COMPOSITE_MAX) {
10372b730f8bSJeremy L Thompson     // LCOV_EXCL_START
10382b730f8bSJeremy L Thompson     return CeedError(composite_op->ceed, CEED_ERROR_UNSUPPORTED, "Cannot add additional sub-operators");
10392b730f8bSJeremy L Thompson     // LCOV_EXCL_STOP
10402b730f8bSJeremy L Thompson   }
10412b730f8bSJeremy L Thompson   if (composite_op->is_immutable) {
10422b730f8bSJeremy L Thompson     // LCOV_EXCL_START
10432b730f8bSJeremy L Thompson     return CeedError(composite_op->ceed, CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable");
10442b730f8bSJeremy L Thompson     // LCOV_EXCL_STOP
10452b730f8bSJeremy L Thompson   }
10462b730f8bSJeremy L Thompson 
10472b730f8bSJeremy L Thompson   {
10482b730f8bSJeremy L Thompson     CeedSize input_size, output_size;
10492b730f8bSJeremy L Thompson     CeedCall(CeedOperatorGetActiveVectorLengths(sub_op, &input_size, &output_size));
10502b730f8bSJeremy L Thompson     if (composite_op->input_size == -1) composite_op->input_size = input_size;
10512b730f8bSJeremy L Thompson     if (composite_op->output_size == -1) composite_op->output_size = output_size;
10522b730f8bSJeremy L Thompson     // Note, a size of -1 means no active vector restriction set, so no incompatibility
10532b730f8bSJeremy L Thompson     if ((input_size != -1 && input_size != composite_op->input_size) || (output_size != -1 && output_size != composite_op->output_size)) {
10542b730f8bSJeremy L Thompson       // LCOV_EXCL_START
10552b730f8bSJeremy L Thompson       return CeedError(composite_op->ceed, CEED_ERROR_MAJOR,
10562b730f8bSJeremy L Thompson                        "Sub-operators must have compatible dimensions; composite operator of shape (%td, %td) not compatible with sub-operator of "
10572b730f8bSJeremy L Thompson                        "shape (%td, %td)",
10582b730f8bSJeremy L Thompson                        composite_op->input_size, composite_op->output_size, input_size, output_size);
10592b730f8bSJeremy L Thompson       // LCOV_EXCL_STOP
10602b730f8bSJeremy L Thompson     }
10612b730f8bSJeremy L Thompson   }
10622b730f8bSJeremy L Thompson 
1063d1d35e2fSjeremylt   composite_op->sub_operators[composite_op->num_suboperators] = sub_op;
10642b730f8bSJeremy L Thompson   CeedCall(CeedOperatorReference(sub_op));
1065d1d35e2fSjeremylt   composite_op->num_suboperators++;
1066e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
106752d6035fSJeremy L Thompson }
106852d6035fSJeremy L Thompson 
106952d6035fSJeremy L Thompson /**
107075f0d5a4SJeremy L Thompson   @brief Get the number of sub_operators associated with a CeedOperator
107175f0d5a4SJeremy L Thompson 
107275f0d5a4SJeremy L Thompson   @param[in]  op               CeedOperator
107375f0d5a4SJeremy L Thompson   @param[out] num_suboperators Variable to store number of sub_operators
107475f0d5a4SJeremy L Thompson 
107575f0d5a4SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
107675f0d5a4SJeremy L Thompson 
107775f0d5a4SJeremy L Thompson   @ref Backend
107875f0d5a4SJeremy L Thompson **/
107975f0d5a4SJeremy L Thompson 
1080c6ebc35dSJeremy L Thompson int CeedCompositeOperatorGetNumSub(CeedOperator op, CeedInt *num_suboperators) {
108175f0d5a4SJeremy L Thompson   if (!op->is_composite) {
108275f0d5a4SJeremy L Thompson     // LCOV_EXCL_START
108375f0d5a4SJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MINOR, "Not a composite operator");
108475f0d5a4SJeremy L Thompson     // LCOV_EXCL_STOP
108575f0d5a4SJeremy L Thompson   }
108675f0d5a4SJeremy L Thompson   *num_suboperators = op->num_suboperators;
108775f0d5a4SJeremy L Thompson   return CEED_ERROR_SUCCESS;
108875f0d5a4SJeremy L Thompson }
108975f0d5a4SJeremy L Thompson 
109075f0d5a4SJeremy L Thompson /**
109175f0d5a4SJeremy L Thompson   @brief Get the list of sub_operators associated with a CeedOperator
109275f0d5a4SJeremy L Thompson 
109375f0d5a4SJeremy L Thompson   @param op                  CeedOperator
109475f0d5a4SJeremy L Thompson   @param[out] sub_operators  Variable to store list of sub_operators
109575f0d5a4SJeremy L Thompson 
109675f0d5a4SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
109775f0d5a4SJeremy L Thompson 
109875f0d5a4SJeremy L Thompson   @ref Backend
109975f0d5a4SJeremy L Thompson **/
110075f0d5a4SJeremy L Thompson 
1101c6ebc35dSJeremy L Thompson int CeedCompositeOperatorGetSubList(CeedOperator op, CeedOperator **sub_operators) {
110275f0d5a4SJeremy L Thompson   if (!op->is_composite) {
110375f0d5a4SJeremy L Thompson     // LCOV_EXCL_START
110475f0d5a4SJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MINOR, "Not a composite operator");
110575f0d5a4SJeremy L Thompson     // LCOV_EXCL_STOP
110675f0d5a4SJeremy L Thompson   }
110775f0d5a4SJeremy L Thompson   *sub_operators = op->sub_operators;
110875f0d5a4SJeremy L Thompson   return CEED_ERROR_SUCCESS;
110975f0d5a4SJeremy L Thompson }
111075f0d5a4SJeremy L Thompson 
111175f0d5a4SJeremy L Thompson /**
11124db537f9SJeremy L Thompson   @brief Check if a CeedOperator is ready to be used.
11134db537f9SJeremy L Thompson 
11144db537f9SJeremy L Thompson   @param[in] op CeedOperator to check
11154db537f9SJeremy L Thompson 
11164db537f9SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
11174db537f9SJeremy L Thompson 
11184db537f9SJeremy L Thompson   @ref User
11194db537f9SJeremy L Thompson **/
11204db537f9SJeremy L Thompson int CeedOperatorCheckReady(CeedOperator op) {
11214db537f9SJeremy L Thompson   Ceed ceed;
11222b730f8bSJeremy L Thompson   CeedCall(CeedOperatorGetCeed(op, &ceed));
11234db537f9SJeremy L Thompson 
11242b730f8bSJeremy L Thompson   if (op->is_interface_setup) return CEED_ERROR_SUCCESS;
11254db537f9SJeremy L Thompson 
11264db537f9SJeremy L Thompson   CeedQFunction qf = op->qf;
11274db537f9SJeremy L Thompson   if (op->is_composite) {
112843622462SJeremy L Thompson     if (!op->num_suboperators) {
112943622462SJeremy L Thompson       // Empty operator setup
113043622462SJeremy L Thompson       op->input_size  = 0;
113143622462SJeremy L Thompson       op->output_size = 0;
113243622462SJeremy L Thompson     } else {
11334db537f9SJeremy L Thompson       for (CeedInt i = 0; i < op->num_suboperators; i++) {
11342b730f8bSJeremy L Thompson         CeedCall(CeedOperatorCheckReady(op->sub_operators[i]));
11354db537f9SJeremy L Thompson       }
11362b104005SJeremy L Thompson       // Sub-operators could be modified after adding to composite operator
11372b104005SJeremy L Thompson       // Need to verify no lvec incompatibility from any changes
11382b104005SJeremy L Thompson       CeedSize input_size, output_size;
11392b730f8bSJeremy L Thompson       CeedCall(CeedOperatorGetActiveVectorLengths(op, &input_size, &output_size));
114043622462SJeremy L Thompson     }
11414db537f9SJeremy L Thompson   } else {
11422b730f8bSJeremy L Thompson     if (op->num_fields == 0) {
11434db537f9SJeremy L Thompson       // LCOV_EXCL_START
11444db537f9SJeremy L Thompson       return CeedError(ceed, CEED_ERROR_INCOMPLETE, "No operator fields set");
11454db537f9SJeremy L Thompson       // LCOV_EXCL_STOP
11462b730f8bSJeremy L Thompson     }
11472b730f8bSJeremy L Thompson     if (op->num_fields < qf->num_input_fields + qf->num_output_fields) {
11484db537f9SJeremy L Thompson       // LCOV_EXCL_START
11494db537f9SJeremy L Thompson       return CeedError(ceed, CEED_ERROR_INCOMPLETE, "Not all operator fields set");
11504db537f9SJeremy L Thompson       // LCOV_EXCL_STOP
11512b730f8bSJeremy L Thompson     }
11522b730f8bSJeremy L Thompson     if (!op->has_restriction) {
11534db537f9SJeremy L Thompson       // LCOV_EXCL_START
11542b730f8bSJeremy L Thompson       return CeedError(ceed, CEED_ERROR_INCOMPLETE, "At least one restriction required");
11554db537f9SJeremy L Thompson       // LCOV_EXCL_STOP
11562b730f8bSJeremy L Thompson     }
11572b730f8bSJeremy L Thompson     if (op->num_qpts == 0) {
11584db537f9SJeremy L Thompson       // LCOV_EXCL_START
11592b730f8bSJeremy 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");
11604db537f9SJeremy L Thompson       // LCOV_EXCL_STOP
11614db537f9SJeremy L Thompson     }
11622b730f8bSJeremy L Thompson   }
11634db537f9SJeremy L Thompson 
11644db537f9SJeremy L Thompson   // Flag as immutable and ready
11654db537f9SJeremy L Thompson   op->is_interface_setup = true;
11662b730f8bSJeremy L Thompson   if (op->qf && op->qf != CEED_QFUNCTION_NONE) op->qf->is_immutable = true;
11672b730f8bSJeremy L Thompson   if (op->dqf && op->dqf != CEED_QFUNCTION_NONE) op->dqf->is_immutable = true;
11682b730f8bSJeremy L Thompson   if (op->dqfT && op->dqfT != CEED_QFUNCTION_NONE) op->dqfT->is_immutable = true;
11694db537f9SJeremy L Thompson   return CEED_ERROR_SUCCESS;
11704db537f9SJeremy L Thompson }
11714db537f9SJeremy L Thompson 
11724db537f9SJeremy L Thompson /**
1173c9366a6bSJeremy L Thompson   @brief Get vector lengths for the active input and/or output vectors of a CeedOperator.
1174ea61e9acSJeremy L Thompson            Note: Lengths of -1 indicate that the CeedOperator does not have an active input and/or output.
1175c9366a6bSJeremy L Thompson 
1176c9366a6bSJeremy L Thompson   @param[in]  op          CeedOperator
1177c9366a6bSJeremy L Thompson   @param[out] input_size  Variable to store active input vector length, or NULL
1178c9366a6bSJeremy L Thompson   @param[out] output_size Variable to store active output vector length, or NULL
1179c9366a6bSJeremy L Thompson 
1180c9366a6bSJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
1181c9366a6bSJeremy L Thompson 
1182c9366a6bSJeremy L Thompson   @ref User
1183c9366a6bSJeremy L Thompson **/
11842b730f8bSJeremy L Thompson int CeedOperatorGetActiveVectorLengths(CeedOperator op, CeedSize *input_size, CeedSize *output_size) {
1185c9366a6bSJeremy L Thompson   bool is_composite;
1186c9366a6bSJeremy L Thompson 
11872b104005SJeremy L Thompson   if (input_size) *input_size = op->input_size;
11882b104005SJeremy L Thompson   if (output_size) *output_size = op->output_size;
1189c9366a6bSJeremy L Thompson 
11902b730f8bSJeremy L Thompson   CeedCall(CeedOperatorIsComposite(op, &is_composite));
11912b104005SJeremy L Thompson   if (is_composite && (op->input_size == -1 || op->output_size == -1)) {
1192c9366a6bSJeremy L Thompson     for (CeedInt i = 0; i < op->num_suboperators; i++) {
1193c9366a6bSJeremy L Thompson       CeedSize sub_input_size, sub_output_size;
11942b730f8bSJeremy L Thompson       CeedCall(CeedOperatorGetActiveVectorLengths(op->sub_operators[i], &sub_input_size, &sub_output_size));
11952b104005SJeremy L Thompson       if (op->input_size == -1) op->input_size = sub_input_size;
11962b104005SJeremy L Thompson       if (op->output_size == -1) op->output_size = sub_output_size;
11972b104005SJeremy L Thompson       // Note, a size of -1 means no active vector restriction set, so no incompatibility
11982b730f8bSJeremy L Thompson       if ((sub_input_size != -1 && sub_input_size != op->input_size) || (sub_output_size != -1 && sub_output_size != op->output_size)) {
11992b104005SJeremy L Thompson         // LCOV_EXCL_START
12002b104005SJeremy L Thompson         return CeedError(op->ceed, CEED_ERROR_MAJOR,
12012b730f8bSJeremy L Thompson                          "Sub-operators must have compatible dimensions; composite operator of shape (%td, %td) not compatible with sub-operator of "
12022b730f8bSJeremy L Thompson                          "shape (%td, %td)",
12032b104005SJeremy L Thompson                          op->input_size, op->output_size, input_size, output_size);
12042b104005SJeremy L Thompson         // LCOV_EXCL_STOP
1205c9366a6bSJeremy L Thompson       }
1206c9366a6bSJeremy L Thompson     }
12072b730f8bSJeremy L Thompson   }
1208c9366a6bSJeremy L Thompson 
1209c9366a6bSJeremy L Thompson   return CEED_ERROR_SUCCESS;
1210c9366a6bSJeremy L Thompson }
1211c9366a6bSJeremy L Thompson 
1212c9366a6bSJeremy L Thompson /**
1213beecbf24SJeremy L Thompson   @brief Set reuse of CeedQFunction data in CeedOperatorLinearAssemble* functions.
1214ea61e9acSJeremy L Thompson            When `reuse_assembly_data = false` (default), the CeedQFunction associated with this CeedOperator is re-assembled every time a
1215ea61e9acSJeremy L Thompson `CeedOperatorLinearAssemble*` function is called. When `reuse_assembly_data = true`, the CeedQFunction associated with this CeedOperator is reused
1216ea61e9acSJeremy L Thompson between calls to `CeedOperatorSetQFunctionAssemblyDataUpdated`.
12178b919e6bSJeremy L Thompson 
1218beecbf24SJeremy L Thompson   @param[in] op                  CeedOperator
1219beecbf24SJeremy L Thompson   @param[in] reuse_assembly_data Boolean flag setting assembly data reuse
12208b919e6bSJeremy L Thompson 
12218b919e6bSJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
12228b919e6bSJeremy L Thompson 
12238b919e6bSJeremy L Thompson   @ref Advanced
12248b919e6bSJeremy L Thompson **/
12252b730f8bSJeremy L Thompson int CeedOperatorSetQFunctionAssemblyReuse(CeedOperator op, bool reuse_assembly_data) {
12268b919e6bSJeremy L Thompson   bool is_composite;
12278b919e6bSJeremy L Thompson 
12282b730f8bSJeremy L Thompson   CeedCall(CeedOperatorIsComposite(op, &is_composite));
12298b919e6bSJeremy L Thompson   if (is_composite) {
12308b919e6bSJeremy L Thompson     for (CeedInt i = 0; i < op->num_suboperators; i++) {
12312b730f8bSJeremy L Thompson       CeedCall(CeedOperatorSetQFunctionAssemblyReuse(op->sub_operators[i], reuse_assembly_data));
12328b919e6bSJeremy L Thompson     }
12338b919e6bSJeremy L Thompson   } else {
12342b730f8bSJeremy L Thompson     CeedCall(CeedQFunctionAssemblyDataSetReuse(op->qf_assembled, reuse_assembly_data));
1235beecbf24SJeremy L Thompson   }
1236beecbf24SJeremy L Thompson 
1237beecbf24SJeremy L Thompson   return CEED_ERROR_SUCCESS;
1238beecbf24SJeremy L Thompson }
1239beecbf24SJeremy L Thompson 
1240beecbf24SJeremy L Thompson /**
1241beecbf24SJeremy L Thompson   @brief Mark CeedQFunction data as updated and the CeedQFunction as requiring re-assembly.
1242beecbf24SJeremy L Thompson 
1243beecbf24SJeremy L Thompson   @param[in] op                CeedOperator
12446e15d496SJeremy L Thompson   @param[in] needs_data_update Boolean flag setting assembly data reuse
1245beecbf24SJeremy L Thompson 
1246beecbf24SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
1247beecbf24SJeremy L Thompson 
1248beecbf24SJeremy L Thompson   @ref Advanced
1249beecbf24SJeremy L Thompson **/
12502b730f8bSJeremy L Thompson int CeedOperatorSetQFunctionAssemblyDataUpdateNeeded(CeedOperator op, bool needs_data_update) {
1251beecbf24SJeremy L Thompson   bool is_composite;
1252beecbf24SJeremy L Thompson 
12532b730f8bSJeremy L Thompson   CeedCall(CeedOperatorIsComposite(op, &is_composite));
1254beecbf24SJeremy L Thompson   if (is_composite) {
1255beecbf24SJeremy L Thompson     for (CeedInt i = 0; i < op->num_suboperators; i++) {
12562b730f8bSJeremy L Thompson       CeedCall(CeedOperatorSetQFunctionAssemblyDataUpdateNeeded(op->sub_operators[i], needs_data_update));
1257beecbf24SJeremy L Thompson     }
1258beecbf24SJeremy L Thompson   } else {
12592b730f8bSJeremy L Thompson     CeedCall(CeedQFunctionAssemblyDataSetUpdateNeeded(op->qf_assembled, needs_data_update));
12608b919e6bSJeremy L Thompson   }
12618b919e6bSJeremy L Thompson 
12628b919e6bSJeremy L Thompson   return CEED_ERROR_SUCCESS;
12638b919e6bSJeremy L Thompson }
12648b919e6bSJeremy L Thompson 
12658b919e6bSJeremy L Thompson /**
1266cd4dfc48Sjeremylt   @brief Set the number of quadrature points associated with a CeedOperator.
1267ea61e9acSJeremy L Thompson            This should be used when creating a CeedOperator where every field has a collocated basis.
1268ea61e9acSJeremy L Thompson            This function cannot be used for composite CeedOperators.
1269cd4dfc48Sjeremylt 
1270ea61e9acSJeremy L Thompson   @param[in,out] op       CeedOperator
1271ea61e9acSJeremy L Thompson   @param[in]     num_qpts Number of quadrature points to set
1272cd4dfc48Sjeremylt 
1273cd4dfc48Sjeremylt   @return An error code: 0 - success, otherwise - failure
1274cd4dfc48Sjeremylt 
1275e9b533fbSJeremy L Thompson   @ref Advanced
1276cd4dfc48Sjeremylt **/
1277cd4dfc48Sjeremylt int CeedOperatorSetNumQuadraturePoints(CeedOperator op, CeedInt num_qpts) {
12782b730f8bSJeremy L Thompson   if (op->is_composite) {
1279cd4dfc48Sjeremylt     // LCOV_EXCL_START
12802b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MINOR, "Not defined for composite operator");
1281cd4dfc48Sjeremylt     // LCOV_EXCL_STOP
12822b730f8bSJeremy L Thompson   }
12832b730f8bSJeremy L Thompson   if (op->num_qpts) {
1284cd4dfc48Sjeremylt     // LCOV_EXCL_START
12852b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MINOR, "Number of quadrature points already defined");
1286cd4dfc48Sjeremylt     // LCOV_EXCL_STOP
12872b730f8bSJeremy L Thompson   }
12882b730f8bSJeremy L Thompson   if (op->is_immutable) {
1289f04ea552SJeremy L Thompson     // LCOV_EXCL_START
12902b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable");
1291f04ea552SJeremy L Thompson     // LCOV_EXCL_STOP
12922b730f8bSJeremy L Thompson   }
1293cd4dfc48Sjeremylt   op->num_qpts = num_qpts;
1294cd4dfc48Sjeremylt   return CEED_ERROR_SUCCESS;
1295cd4dfc48Sjeremylt }
1296cd4dfc48Sjeremylt 
1297cd4dfc48Sjeremylt /**
1298ea6b5821SJeremy L Thompson   @brief Set name of CeedOperator for CeedOperatorView output
1299ea6b5821SJeremy L Thompson 
1300ea61e9acSJeremy L Thompson   @param[in,out] op   CeedOperator
1301ea61e9acSJeremy L Thompson   @param[in]     name Name to set, or NULL to remove previously set name
1302ea6b5821SJeremy L Thompson 
1303ea6b5821SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
1304ea6b5821SJeremy L Thompson 
1305ea6b5821SJeremy L Thompson   @ref User
1306ea6b5821SJeremy L Thompson **/
1307ea6b5821SJeremy L Thompson int CeedOperatorSetName(CeedOperator op, const char *name) {
1308ea6b5821SJeremy L Thompson   char  *name_copy;
1309ea6b5821SJeremy L Thompson   size_t name_len = name ? strlen(name) : 0;
1310ea6b5821SJeremy L Thompson 
13112b730f8bSJeremy L Thompson   CeedCall(CeedFree(&op->name));
1312ea6b5821SJeremy L Thompson   if (name_len > 0) {
13132b730f8bSJeremy L Thompson     CeedCall(CeedCalloc(name_len + 1, &name_copy));
1314ea6b5821SJeremy L Thompson     memcpy(name_copy, name, name_len);
1315ea6b5821SJeremy L Thompson     op->name = name_copy;
1316ea6b5821SJeremy L Thompson   }
1317ea6b5821SJeremy L Thompson 
1318ea6b5821SJeremy L Thompson   return CEED_ERROR_SUCCESS;
1319ea6b5821SJeremy L Thompson }
1320ea6b5821SJeremy L Thompson 
1321ea6b5821SJeremy L Thompson /**
13227a982d89SJeremy L. Thompson   @brief View a CeedOperator
13237a982d89SJeremy L. Thompson 
13247a982d89SJeremy L. Thompson   @param[in] op     CeedOperator to view
13257a982d89SJeremy L. Thompson   @param[in] stream Stream to write; typically stdout/stderr or a file
13267a982d89SJeremy L. Thompson 
13277a982d89SJeremy L. Thompson   @return Error code: 0 - success, otherwise - failure
13287a982d89SJeremy L. Thompson 
13297a982d89SJeremy L. Thompson   @ref User
13307a982d89SJeremy L. Thompson **/
13317a982d89SJeremy L. Thompson int CeedOperatorView(CeedOperator op, FILE *stream) {
1332ea6b5821SJeremy L Thompson   bool has_name = op->name;
13337a982d89SJeremy L. Thompson 
1334f04ea552SJeremy L Thompson   if (op->is_composite) {
13352b730f8bSJeremy L Thompson     fprintf(stream, "Composite CeedOperator%s%s\n", has_name ? " - " : "", has_name ? op->name : "");
13367a982d89SJeremy L. Thompson 
1337d1d35e2fSjeremylt     for (CeedInt i = 0; i < op->num_suboperators; i++) {
1338ea6b5821SJeremy L Thompson       has_name = op->sub_operators[i]->name;
13392b730f8bSJeremy L Thompson       fprintf(stream, "  SubOperator %" CeedInt_FMT "%s%s:\n", i, has_name ? " - " : "", has_name ? op->sub_operators[i]->name : "");
13402b730f8bSJeremy L Thompson       CeedCall(CeedOperatorSingleView(op->sub_operators[i], 1, stream));
13417a982d89SJeremy L. Thompson     }
13427a982d89SJeremy L. Thompson   } else {
13432b730f8bSJeremy L Thompson     fprintf(stream, "CeedOperator%s%s\n", has_name ? " - " : "", has_name ? op->name : "");
13442b730f8bSJeremy L Thompson     CeedCall(CeedOperatorSingleView(op, 0, stream));
13457a982d89SJeremy L. Thompson   }
1346e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
13477a982d89SJeremy L. Thompson }
13483bd813ffSjeremylt 
13493bd813ffSjeremylt /**
1350b7c9bbdaSJeremy L Thompson   @brief Get the Ceed associated with a CeedOperator
1351b7c9bbdaSJeremy L Thompson 
1352ea61e9acSJeremy L Thompson   @param[in]  op   CeedOperator
1353b7c9bbdaSJeremy L Thompson   @param[out] ceed Variable to store Ceed
1354b7c9bbdaSJeremy L Thompson 
1355b7c9bbdaSJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
1356b7c9bbdaSJeremy L Thompson 
1357b7c9bbdaSJeremy L Thompson   @ref Advanced
1358b7c9bbdaSJeremy L Thompson **/
1359b7c9bbdaSJeremy L Thompson int CeedOperatorGetCeed(CeedOperator op, Ceed *ceed) {
1360b7c9bbdaSJeremy L Thompson   *ceed = op->ceed;
1361b7c9bbdaSJeremy L Thompson   return CEED_ERROR_SUCCESS;
1362b7c9bbdaSJeremy L Thompson }
1363b7c9bbdaSJeremy L Thompson 
1364b7c9bbdaSJeremy L Thompson /**
1365b7c9bbdaSJeremy L Thompson   @brief Get the number of elements associated with a CeedOperator
1366b7c9bbdaSJeremy L Thompson 
1367ea61e9acSJeremy L Thompson   @param[in]  op       CeedOperator
1368b7c9bbdaSJeremy L Thompson   @param[out] num_elem Variable to store number of elements
1369b7c9bbdaSJeremy L Thompson 
1370b7c9bbdaSJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
1371b7c9bbdaSJeremy L Thompson 
1372b7c9bbdaSJeremy L Thompson   @ref Advanced
1373b7c9bbdaSJeremy L Thompson **/
1374b7c9bbdaSJeremy L Thompson int CeedOperatorGetNumElements(CeedOperator op, CeedInt *num_elem) {
13752b730f8bSJeremy L Thompson   if (op->is_composite) {
1376b7c9bbdaSJeremy L Thompson     // LCOV_EXCL_START
13772b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MINOR, "Not defined for composite operator");
1378b7c9bbdaSJeremy L Thompson     // LCOV_EXCL_STOP
13792b730f8bSJeremy L Thompson   }
1380b7c9bbdaSJeremy L Thompson   *num_elem = op->num_elem;
1381b7c9bbdaSJeremy L Thompson   return CEED_ERROR_SUCCESS;
1382b7c9bbdaSJeremy L Thompson }
1383b7c9bbdaSJeremy L Thompson 
1384b7c9bbdaSJeremy L Thompson /**
1385b7c9bbdaSJeremy L Thompson   @brief Get the number of quadrature points associated with a CeedOperator
1386b7c9bbdaSJeremy L Thompson 
1387ea61e9acSJeremy L Thompson   @param[in]  op       CeedOperator
1388b7c9bbdaSJeremy L Thompson   @param[out] num_qpts Variable to store vector number of quadrature points
1389b7c9bbdaSJeremy L Thompson 
1390b7c9bbdaSJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
1391b7c9bbdaSJeremy L Thompson 
1392b7c9bbdaSJeremy L Thompson   @ref Advanced
1393b7c9bbdaSJeremy L Thompson **/
1394b7c9bbdaSJeremy L Thompson int CeedOperatorGetNumQuadraturePoints(CeedOperator op, CeedInt *num_qpts) {
13952b730f8bSJeremy L Thompson   if (op->is_composite) {
1396b7c9bbdaSJeremy L Thompson     // LCOV_EXCL_START
13972b730f8bSJeremy L Thompson     return CeedError(op->ceed, CEED_ERROR_MINOR, "Not defined for composite operator");
1398b7c9bbdaSJeremy L Thompson     // LCOV_EXCL_STOP
13992b730f8bSJeremy L Thompson   }
1400b7c9bbdaSJeremy L Thompson   *num_qpts = op->num_qpts;
1401b7c9bbdaSJeremy L Thompson   return CEED_ERROR_SUCCESS;
1402b7c9bbdaSJeremy L Thompson }
1403b7c9bbdaSJeremy L Thompson 
1404b7c9bbdaSJeremy L Thompson /**
14056e15d496SJeremy L Thompson   @brief Estimate number of FLOPs required to apply CeedOperator on the active vector
14066e15d496SJeremy L Thompson 
1407ea61e9acSJeremy L Thompson   @param[in]  op    CeedOperator to estimate FLOPs for
1408ea61e9acSJeremy L Thompson   @param[out] flops Address of variable to hold FLOPs estimate
14096e15d496SJeremy L Thompson 
14106e15d496SJeremy L Thompson   @ref Backend
14116e15d496SJeremy L Thompson **/
14129d36ca50SJeremy L Thompson int CeedOperatorGetFlopsEstimate(CeedOperator op, CeedSize *flops) {
14136e15d496SJeremy L Thompson   bool is_composite;
14142b730f8bSJeremy L Thompson   CeedCall(CeedOperatorCheckReady(op));
14156e15d496SJeremy L Thompson 
14166e15d496SJeremy L Thompson   *flops = 0;
14172b730f8bSJeremy L Thompson   CeedCall(CeedOperatorIsComposite(op, &is_composite));
14186e15d496SJeremy L Thompson   if (is_composite) {
14196e15d496SJeremy L Thompson     CeedInt num_suboperators;
1420c6ebc35dSJeremy L Thompson     CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators));
14216e15d496SJeremy L Thompson     CeedOperator *sub_operators;
1422c6ebc35dSJeremy L Thompson     CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators));
14236e15d496SJeremy L Thompson 
14246e15d496SJeremy L Thompson     // FLOPs for each suboperator
14256e15d496SJeremy L Thompson     for (CeedInt i = 0; i < num_suboperators; i++) {
14269d36ca50SJeremy L Thompson       CeedSize suboperator_flops;
14272b730f8bSJeremy L Thompson       CeedCall(CeedOperatorGetFlopsEstimate(sub_operators[i], &suboperator_flops));
14286e15d496SJeremy L Thompson       *flops += suboperator_flops;
14296e15d496SJeremy L Thompson     }
14306e15d496SJeremy L Thompson   } else {
14316e15d496SJeremy L Thompson     CeedInt            num_input_fields, num_output_fields;
14326e15d496SJeremy L Thompson     CeedOperatorField *input_fields, *output_fields;
14336e15d496SJeremy L Thompson 
14342b730f8bSJeremy L Thompson     CeedCall(CeedOperatorGetFields(op, &num_input_fields, &input_fields, &num_output_fields, &output_fields));
14356e15d496SJeremy L Thompson 
14366e15d496SJeremy L Thompson     CeedInt num_elem = 0;
14372b730f8bSJeremy L Thompson     CeedCall(CeedOperatorGetNumElements(op, &num_elem));
14386e15d496SJeremy L Thompson     // Input FLOPs
14396e15d496SJeremy L Thompson     for (CeedInt i = 0; i < num_input_fields; i++) {
14406e15d496SJeremy L Thompson       if (input_fields[i]->vec == CEED_VECTOR_ACTIVE) {
14419d36ca50SJeremy L Thompson         CeedSize restr_flops, basis_flops;
14426e15d496SJeremy L Thompson 
1443437c7c90SJeremy L Thompson         CeedCall(CeedElemRestrictionGetFlopsEstimate(input_fields[i]->elem_rstr, CEED_NOTRANSPOSE, &restr_flops));
14446e15d496SJeremy L Thompson         *flops += restr_flops;
14452b730f8bSJeremy L Thompson         CeedCall(CeedBasisGetFlopsEstimate(input_fields[i]->basis, CEED_NOTRANSPOSE, op->qf->input_fields[i]->eval_mode, &basis_flops));
14466e15d496SJeremy L Thompson         *flops += basis_flops * num_elem;
14476e15d496SJeremy L Thompson       }
14486e15d496SJeremy L Thompson     }
14496e15d496SJeremy L Thompson     // QF FLOPs
14509d36ca50SJeremy L Thompson     CeedInt  num_qpts;
14519d36ca50SJeremy L Thompson     CeedSize qf_flops;
14522b730f8bSJeremy L Thompson     CeedCall(CeedOperatorGetNumQuadraturePoints(op, &num_qpts));
14532b730f8bSJeremy L Thompson     CeedCall(CeedQFunctionGetFlopsEstimate(op->qf, &qf_flops));
14546e15d496SJeremy L Thompson     *flops += num_elem * num_qpts * qf_flops;
14556e15d496SJeremy L Thompson     // Output FLOPs
14566e15d496SJeremy L Thompson     for (CeedInt i = 0; i < num_output_fields; i++) {
14576e15d496SJeremy L Thompson       if (output_fields[i]->vec == CEED_VECTOR_ACTIVE) {
14589d36ca50SJeremy L Thompson         CeedSize restr_flops, basis_flops;
14596e15d496SJeremy L Thompson 
1460437c7c90SJeremy L Thompson         CeedCall(CeedElemRestrictionGetFlopsEstimate(output_fields[i]->elem_rstr, CEED_TRANSPOSE, &restr_flops));
14616e15d496SJeremy L Thompson         *flops += restr_flops;
14622b730f8bSJeremy L Thompson         CeedCall(CeedBasisGetFlopsEstimate(output_fields[i]->basis, CEED_TRANSPOSE, op->qf->output_fields[i]->eval_mode, &basis_flops));
14636e15d496SJeremy L Thompson         *flops += basis_flops * num_elem;
14646e15d496SJeremy L Thompson       }
14656e15d496SJeremy L Thompson     }
14666e15d496SJeremy L Thompson   }
14676e15d496SJeremy L Thompson 
14686e15d496SJeremy L Thompson   return CEED_ERROR_SUCCESS;
14696e15d496SJeremy L Thompson }
14706e15d496SJeremy L Thompson 
14716e15d496SJeremy L Thompson /**
14720126412dSJeremy L Thompson   @brief Get CeedQFunction global context for a CeedOperator.
1473512bb800SJeremy L Thompson            The caller is responsible for destroying `ctx` returned from this function via `CeedQFunctionContextDestroy()`.
1474512bb800SJeremy L Thompson 
1475512bb800SJeremy L Thompson            Note: If the value of `ctx` passed into this function is non-NULL, then it is assumed that `ctx` is a pointer to a
14760126412dSJeremy L Thompson              CeedQFunctionContext. This CeedQFunctionContext will be destroyed if `ctx` is the only reference to this CeedQFunctionContext.
14770126412dSJeremy L Thompson 
1478859c15bbSJames Wright   @param[in]  op  CeedOperator
14790126412dSJeremy L Thompson   @param[out] ctx Variable to store CeedQFunctionContext
14800126412dSJeremy L Thompson 
14810126412dSJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
14820126412dSJeremy L Thompson 
1483859c15bbSJames Wright   @ref Advanced
14840126412dSJeremy L Thompson **/
14850126412dSJeremy L Thompson int CeedOperatorGetContext(CeedOperator op, CeedQFunctionContext *ctx) {
14860126412dSJeremy L Thompson   bool is_composite;
14870126412dSJeremy L Thompson 
14880126412dSJeremy L Thompson   CeedCall(CeedOperatorIsComposite(op, &is_composite));
14890126412dSJeremy L Thompson   if (is_composite) return CeedError(op->ceed, CEED_ERROR_INCOMPATIBLE, "Cannot retrieve QFunctionContext for composite operator");
14900126412dSJeremy L Thompson 
14910126412dSJeremy L Thompson   if (op->qf->ctx) CeedCall(CeedQFunctionContextReferenceCopy(op->qf->ctx, ctx));
14920126412dSJeremy L Thompson   else *ctx = NULL;
14930126412dSJeremy L Thompson   return CEED_ERROR_SUCCESS;
14940126412dSJeremy L Thompson }
14950126412dSJeremy L Thompson 
14960126412dSJeremy L Thompson /**
1497ea61e9acSJeremy L Thompson   @brief Get label for a registered QFunctionContext field, or `NULL` if no field has been registered with this `field_name`.
14983668ca4bSJeremy L Thompson 
1499859c15bbSJames Wright   Fields are registered via `CeedQFunctionContextRegister*()` functions (eg. `CeedQFunctionContextRegisterDouble()`).
1500859c15bbSJames Wright 
15013668ca4bSJeremy L Thompson   @param[in]  op          CeedOperator
15023668ca4bSJeremy L Thompson   @param[in]  field_name  Name of field to retrieve label
15033668ca4bSJeremy L Thompson   @param[out] field_label Variable to field label
15043668ca4bSJeremy L Thompson 
15053668ca4bSJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
15063668ca4bSJeremy L Thompson 
15073668ca4bSJeremy L Thompson   @ref User
15083668ca4bSJeremy L Thompson **/
150917b0d5c6SJeremy L Thompson int CeedOperatorGetContextFieldLabel(CeedOperator op, const char *field_name, CeedContextFieldLabel *field_label) {
15103668ca4bSJeremy L Thompson   bool is_composite;
15112b730f8bSJeremy L Thompson   CeedCall(CeedOperatorIsComposite(op, &is_composite));
15122b730f8bSJeremy L Thompson 
15133668ca4bSJeremy L Thompson   if (is_composite) {
15143668ca4bSJeremy L Thompson     // Check if composite label already created
15153668ca4bSJeremy L Thompson     for (CeedInt i = 0; i < op->num_context_labels; i++) {
15163668ca4bSJeremy L Thompson       if (!strcmp(op->context_labels[i]->name, field_name)) {
15173668ca4bSJeremy L Thompson         *field_label = op->context_labels[i];
15183668ca4bSJeremy L Thompson         return CEED_ERROR_SUCCESS;
15193668ca4bSJeremy L Thompson       }
15203668ca4bSJeremy L Thompson     }
15213668ca4bSJeremy L Thompson 
15223668ca4bSJeremy L Thompson     // Create composite label if needed
15233668ca4bSJeremy L Thompson     CeedInt               num_sub;
15243668ca4bSJeremy L Thompson     CeedOperator         *sub_operators;
15253668ca4bSJeremy L Thompson     CeedContextFieldLabel new_field_label;
15263668ca4bSJeremy L Thompson 
15272b730f8bSJeremy L Thompson     CeedCall(CeedCalloc(1, &new_field_label));
1528c6ebc35dSJeremy L Thompson     CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub));
1529c6ebc35dSJeremy L Thompson     CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators));
15302b730f8bSJeremy L Thompson     CeedCall(CeedCalloc(num_sub, &new_field_label->sub_labels));
15313668ca4bSJeremy L Thompson     new_field_label->num_sub_labels = num_sub;
15323668ca4bSJeremy L Thompson 
15333668ca4bSJeremy L Thompson     bool label_found = false;
15343668ca4bSJeremy L Thompson     for (CeedInt i = 0; i < num_sub; i++) {
15353668ca4bSJeremy L Thompson       if (sub_operators[i]->qf->ctx) {
15363668ca4bSJeremy L Thompson         CeedContextFieldLabel new_field_label_i;
15372b730f8bSJeremy L Thompson         CeedCall(CeedQFunctionContextGetFieldLabel(sub_operators[i]->qf->ctx, field_name, &new_field_label_i));
15383668ca4bSJeremy L Thompson         if (new_field_label_i) {
15393668ca4bSJeremy L Thompson           label_found                    = true;
15403668ca4bSJeremy L Thompson           new_field_label->sub_labels[i] = new_field_label_i;
15413668ca4bSJeremy L Thompson           new_field_label->name          = new_field_label_i->name;
15423668ca4bSJeremy L Thompson           new_field_label->description   = new_field_label_i->description;
15432b730f8bSJeremy L Thompson           if (new_field_label->type && new_field_label->type != new_field_label_i->type) {
15447bfe0f0eSJeremy L Thompson             // LCOV_EXCL_START
15452b730f8bSJeremy L Thompson             CeedCall(CeedFree(&new_field_label));
15462b730f8bSJeremy L Thompson             return CeedError(op->ceed, CEED_ERROR_INCOMPATIBLE, "Incompatible field types on sub-operator contexts. %s != %s",
15472b730f8bSJeremy L Thompson                              CeedContextFieldTypes[new_field_label->type], CeedContextFieldTypes[new_field_label_i->type]);
15487bfe0f0eSJeremy L Thompson             // LCOV_EXCL_STOP
15497bfe0f0eSJeremy L Thompson           } else {
15507bfe0f0eSJeremy L Thompson             new_field_label->type = new_field_label_i->type;
15517bfe0f0eSJeremy L Thompson           }
15522b730f8bSJeremy L Thompson           if (new_field_label->num_values != 0 && new_field_label->num_values != new_field_label_i->num_values) {
15537bfe0f0eSJeremy L Thompson             // LCOV_EXCL_START
15542b730f8bSJeremy L Thompson             CeedCall(CeedFree(&new_field_label));
15552b730f8bSJeremy L Thompson             return CeedError(op->ceed, CEED_ERROR_INCOMPATIBLE, "Incompatible field number of values on sub-operator contexts. %ld != %ld",
15567bfe0f0eSJeremy L Thompson                              new_field_label->num_values, new_field_label_i->num_values);
15577bfe0f0eSJeremy L Thompson             // LCOV_EXCL_STOP
15587bfe0f0eSJeremy L Thompson           } else {
15597bfe0f0eSJeremy L Thompson             new_field_label->num_values = new_field_label_i->num_values;
15607bfe0f0eSJeremy L Thompson           }
15613668ca4bSJeremy L Thompson         }
15623668ca4bSJeremy L Thompson       }
15633668ca4bSJeremy L Thompson     }
15643668ca4bSJeremy L Thompson     if (!label_found) {
15653668ca4bSJeremy L Thompson       // LCOV_EXCL_START
15662b730f8bSJeremy L Thompson       CeedCall(CeedFree(&new_field_label->sub_labels));
15672b730f8bSJeremy L Thompson       CeedCall(CeedFree(&new_field_label));
15683668ca4bSJeremy L Thompson       *field_label = NULL;
15693668ca4bSJeremy L Thompson       // LCOV_EXCL_STOP
15703668ca4bSJeremy L Thompson     } else {
1571*5ac9af79SJeremy L Thompson       *field_label = new_field_label;
1572*5ac9af79SJeremy L Thompson     }
1573*5ac9af79SJeremy L Thompson   } else {
1574*5ac9af79SJeremy L Thompson     CeedCall(CeedQFunctionContextGetFieldLabel(op->qf->ctx, field_name, field_label));
1575*5ac9af79SJeremy L Thompson   }
1576*5ac9af79SJeremy L Thompson 
1577*5ac9af79SJeremy L Thompson   // Set label in operator
1578*5ac9af79SJeremy L Thompson   if (*field_label) {
1579*5ac9af79SJeremy L Thompson     (*field_label)->from_op = true;
1580*5ac9af79SJeremy L Thompson 
15813668ca4bSJeremy L Thompson     // Move new composite label to operator
15823668ca4bSJeremy L Thompson     if (op->num_context_labels == 0) {
15832b730f8bSJeremy L Thompson       CeedCall(CeedCalloc(1, &op->context_labels));
15843668ca4bSJeremy L Thompson       op->max_context_labels = 1;
15853668ca4bSJeremy L Thompson     } else if (op->num_context_labels == op->max_context_labels) {
15862b730f8bSJeremy L Thompson       CeedCall(CeedRealloc(2 * op->num_context_labels, &op->context_labels));
15873668ca4bSJeremy L Thompson       op->max_context_labels *= 2;
15883668ca4bSJeremy L Thompson     }
1589*5ac9af79SJeremy L Thompson     op->context_labels[op->num_context_labels] = *field_label;
15903668ca4bSJeremy L Thompson     op->num_context_labels++;
15913668ca4bSJeremy L Thompson   }
15923668ca4bSJeremy L Thompson 
15933668ca4bSJeremy L Thompson   return CEED_ERROR_SUCCESS;
15943668ca4bSJeremy L Thompson }
15953668ca4bSJeremy L Thompson 
15963668ca4bSJeremy L Thompson /**
15972788fa27SJeremy L Thompson   @brief Set QFunctionContext field holding double precision values.
15982788fa27SJeremy L Thompson            For composite operators, the values are set in all sub-operator QFunctionContexts that have a matching `field_name`.
1599d8dd9a91SJeremy L Thompson 
1600ea61e9acSJeremy L Thompson   @param[in,out] op          CeedOperator
16012788fa27SJeremy L Thompson   @param[in]     field_label Label of field to set
1602ea61e9acSJeremy L Thompson   @param[in]     values      Values to set
1603d8dd9a91SJeremy L Thompson 
1604d8dd9a91SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
1605d8dd9a91SJeremy L Thompson 
1606d8dd9a91SJeremy L Thompson   @ref User
1607d8dd9a91SJeremy L Thompson **/
160817b0d5c6SJeremy L Thompson int CeedOperatorSetContextDouble(CeedOperator op, CeedContextFieldLabel field_label, double *values) {
16092b730f8bSJeremy L Thompson   return CeedOperatorContextSetGeneric(op, field_label, CEED_CONTEXT_FIELD_DOUBLE, values);
1610d8dd9a91SJeremy L Thompson }
1611d8dd9a91SJeremy L Thompson 
1612d8dd9a91SJeremy L Thompson /**
16132788fa27SJeremy L Thompson   @brief Get QFunctionContext field holding double precision values, read-only.
16142788fa27SJeremy L Thompson            For composite operators, the values correspond to the first sub-operator QFunctionContexts that has a matching `field_name`.
16152788fa27SJeremy L Thompson 
16162788fa27SJeremy L Thompson   @param[in]  op          CeedOperator
16172788fa27SJeremy L Thompson   @param[in]  field_label Label of field to get
16182788fa27SJeremy L Thompson   @param[out] num_values  Number of values in the field label
16192788fa27SJeremy L Thompson   @param[out] values      Pointer to context values
16202788fa27SJeremy L Thompson 
16212788fa27SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
16222788fa27SJeremy L Thompson 
16232788fa27SJeremy L Thompson   @ref User
16242788fa27SJeremy L Thompson **/
162517b0d5c6SJeremy L Thompson int CeedOperatorGetContextDoubleRead(CeedOperator op, CeedContextFieldLabel field_label, size_t *num_values, const double **values) {
16262788fa27SJeremy L Thompson   return CeedOperatorContextGetGenericRead(op, field_label, CEED_CONTEXT_FIELD_DOUBLE, num_values, values);
16272788fa27SJeremy L Thompson }
16282788fa27SJeremy L Thompson 
16292788fa27SJeremy L Thompson /**
16302788fa27SJeremy L Thompson   @brief Restore QFunctionContext field holding double precision values, read-only.
16312788fa27SJeremy L Thompson 
16322788fa27SJeremy L Thompson   @param[in]  op          CeedOperator
16332788fa27SJeremy L Thompson   @param[in]  field_label Label of field to restore
16342788fa27SJeremy L Thompson   @param[out] values      Pointer to context values
16352788fa27SJeremy L Thompson 
16362788fa27SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
16372788fa27SJeremy L Thompson 
16382788fa27SJeremy L Thompson   @ref User
16392788fa27SJeremy L Thompson **/
164017b0d5c6SJeremy L Thompson int CeedOperatorRestoreContextDoubleRead(CeedOperator op, CeedContextFieldLabel field_label, const double **values) {
16412788fa27SJeremy L Thompson   return CeedOperatorContextRestoreGenericRead(op, field_label, CEED_CONTEXT_FIELD_DOUBLE, values);
16422788fa27SJeremy L Thompson }
16432788fa27SJeremy L Thompson 
16442788fa27SJeremy L Thompson /**
16452788fa27SJeremy L Thompson   @brief Set QFunctionContext field holding int32 values.
16462788fa27SJeremy L Thompson            For composite operators, the values are set in all sub-operator QFunctionContexts that have a matching `field_name`.
1647d8dd9a91SJeremy L Thompson 
1648ea61e9acSJeremy L Thompson   @param[in,out] op          CeedOperator
1649ea61e9acSJeremy L Thompson   @param[in]     field_label Label of field to set
1650ea61e9acSJeremy L Thompson   @param[in]     values      Values to set
1651d8dd9a91SJeremy L Thompson 
1652d8dd9a91SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
1653d8dd9a91SJeremy L Thompson 
1654d8dd9a91SJeremy L Thompson   @ref User
1655d8dd9a91SJeremy L Thompson **/
165617b0d5c6SJeremy L Thompson int CeedOperatorSetContextInt32(CeedOperator op, CeedContextFieldLabel field_label, int *values) {
16572b730f8bSJeremy L Thompson   return CeedOperatorContextSetGeneric(op, field_label, CEED_CONTEXT_FIELD_INT32, values);
1658d8dd9a91SJeremy L Thompson }
1659d8dd9a91SJeremy L Thompson 
1660d8dd9a91SJeremy L Thompson /**
16612788fa27SJeremy L Thompson   @brief Get QFunctionContext field holding int32 values, read-only.
16622788fa27SJeremy L Thompson            For composite operators, the values correspond to the first sub-operator QFunctionContexts that has a matching `field_name`.
16632788fa27SJeremy L Thompson 
16642788fa27SJeremy L Thompson   @param[in]  op          CeedOperator
16652788fa27SJeremy L Thompson   @param[in]  field_label Label of field to get
1666c5d0f995SJed Brown   @param[out] num_values  Number of int32 values in `values`
16672788fa27SJeremy L Thompson   @param[out] values      Pointer to context values
16682788fa27SJeremy L Thompson 
16692788fa27SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
16702788fa27SJeremy L Thompson 
16712788fa27SJeremy L Thompson   @ref User
16722788fa27SJeremy L Thompson **/
167317b0d5c6SJeremy L Thompson int CeedOperatorGetContextInt32Read(CeedOperator op, CeedContextFieldLabel field_label, size_t *num_values, const int **values) {
16742788fa27SJeremy L Thompson   return CeedOperatorContextGetGenericRead(op, field_label, CEED_CONTEXT_FIELD_INT32, num_values, values);
16752788fa27SJeremy L Thompson }
16762788fa27SJeremy L Thompson 
16772788fa27SJeremy L Thompson /**
16782788fa27SJeremy L Thompson   @brief Restore QFunctionContext field holding int32 values, read-only.
16792788fa27SJeremy L Thompson 
16802788fa27SJeremy L Thompson   @param[in]  op          CeedOperator
16812788fa27SJeremy L Thompson   @param[in]  field_label Label of field to get
16822788fa27SJeremy L Thompson   @param[out] values      Pointer to context values
16832788fa27SJeremy L Thompson 
16842788fa27SJeremy L Thompson   @return An error code: 0 - success, otherwise - failure
16852788fa27SJeremy L Thompson 
16862788fa27SJeremy L Thompson   @ref User
16872788fa27SJeremy L Thompson **/
168817b0d5c6SJeremy L Thompson int CeedOperatorRestoreContextInt32Read(CeedOperator op, CeedContextFieldLabel field_label, const int **values) {
16892788fa27SJeremy L Thompson   return CeedOperatorContextRestoreGenericRead(op, field_label, CEED_CONTEXT_FIELD_INT32, values);
16902788fa27SJeremy L Thompson }
16912788fa27SJeremy L Thompson 
16922788fa27SJeremy L Thompson /**
16933bd813ffSjeremylt   @brief Apply CeedOperator to a vector
1694d7b241e6Sjeremylt 
1695ea61e9acSJeremy L Thompson   This computes the action of the operator on the specified (active) input, yielding its (active) output.
1696ea61e9acSJeremy L Thompson   All inputs and outputs must be specified using CeedOperatorSetField().
1697d7b241e6Sjeremylt 
1698ea61e9acSJeremy L Thompson   Note: Calling this function asserts that setup is complete and sets the CeedOperator as immutable.
1699f04ea552SJeremy L Thompson 
1700ea61e9acSJeremy L Thompson   @param[in]  op      CeedOperator to apply
1701ea61e9acSJeremy L Thompson   @param[in]  in      CeedVector containing input state or @ref CEED_VECTOR_NONE if there are no active inputs
1702*5ac9af79SJeremy 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
1703*5ac9af79SJeremy L Thompson active outputs
1704ea61e9acSJeremy L Thompson   @param[in]  request Address of CeedRequest for non-blocking completion, else @ref CEED_REQUEST_IMMEDIATE
1705b11c1e72Sjeremylt 
1706b11c1e72Sjeremylt   @return An error code: 0 - success, otherwise - failure
1707dfdf5a53Sjeremylt 
17087a982d89SJeremy L. Thompson   @ref User
1709b11c1e72Sjeremylt **/
17102b730f8bSJeremy L Thompson int CeedOperatorApply(CeedOperator op, CeedVector in, CeedVector out, CeedRequest *request) {
17112b730f8bSJeremy L Thompson   CeedCall(CeedOperatorCheckReady(op));
1712d7b241e6Sjeremylt 
1713d1d35e2fSjeremylt   if (op->num_elem) {
1714250756a7Sjeremylt     // Standard Operator
1715cae8b89aSjeremylt     if (op->Apply) {
17162b730f8bSJeremy L Thompson       CeedCall(op->Apply(op, in, out, request));
1717cae8b89aSjeremylt     } else {
1718cae8b89aSjeremylt       // Zero all output vectors
1719250756a7Sjeremylt       CeedQFunction qf = op->qf;
1720d1d35e2fSjeremylt       for (CeedInt i = 0; i < qf->num_output_fields; i++) {
1721d1d35e2fSjeremylt         CeedVector vec = op->output_fields[i]->vec;
17222b730f8bSJeremy L Thompson         if (vec == CEED_VECTOR_ACTIVE) vec = out;
1723cae8b89aSjeremylt         if (vec != CEED_VECTOR_NONE) {
17242b730f8bSJeremy L Thompson           CeedCall(CeedVectorSetValue(vec, 0.0));
1725cae8b89aSjeremylt         }
1726cae8b89aSjeremylt       }
1727250756a7Sjeremylt       // Apply
17282b730f8bSJeremy L Thompson       CeedCall(op->ApplyAdd(op, in, out, request));
1729250756a7Sjeremylt     }
1730f04ea552SJeremy L Thompson   } else if (op->is_composite) {
1731250756a7Sjeremylt     // Composite Operator
1732250756a7Sjeremylt     if (op->ApplyComposite) {
17332b730f8bSJeremy L Thompson       CeedCall(op->ApplyComposite(op, in, out, request));
1734250756a7Sjeremylt     } else {
1735d1d35e2fSjeremylt       CeedInt num_suboperators;
1736c6ebc35dSJeremy L Thompson       CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators));
1737d1d35e2fSjeremylt       CeedOperator *sub_operators;
1738c6ebc35dSJeremy L Thompson       CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators));
1739250756a7Sjeremylt 
1740250756a7Sjeremylt       // Zero all output vectors
1741250756a7Sjeremylt       if (out != CEED_VECTOR_NONE) {
17422b730f8bSJeremy L Thompson         CeedCall(CeedVectorSetValue(out, 0.0));
1743cae8b89aSjeremylt       }
1744d1d35e2fSjeremylt       for (CeedInt i = 0; i < num_suboperators; i++) {
1745d1d35e2fSjeremylt         for (CeedInt j = 0; j < sub_operators[i]->qf->num_output_fields; j++) {
1746d1d35e2fSjeremylt           CeedVector vec = sub_operators[i]->output_fields[j]->vec;
1747250756a7Sjeremylt           if (vec != CEED_VECTOR_ACTIVE && vec != CEED_VECTOR_NONE) {
17482b730f8bSJeremy L Thompson             CeedCall(CeedVectorSetValue(vec, 0.0));
1749250756a7Sjeremylt           }
1750250756a7Sjeremylt         }
1751250756a7Sjeremylt       }
1752250756a7Sjeremylt       // Apply
1753d1d35e2fSjeremylt       for (CeedInt i = 0; i < op->num_suboperators; i++) {
17542b730f8bSJeremy L Thompson         CeedCall(CeedOperatorApplyAdd(op->sub_operators[i], in, out, request));
1755cae8b89aSjeremylt       }
1756cae8b89aSjeremylt     }
1757250756a7Sjeremylt   }
1758e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
1759cae8b89aSjeremylt }
1760cae8b89aSjeremylt 
1761cae8b89aSjeremylt /**
1762cae8b89aSjeremylt   @brief Apply CeedOperator to a vector and add result to output vector
1763cae8b89aSjeremylt 
1764ea61e9acSJeremy L Thompson   This computes the action of the operator on the specified (active) input, yielding its (active) output.
1765ea61e9acSJeremy L Thompson   All inputs and outputs must be specified using CeedOperatorSetField().
1766cae8b89aSjeremylt 
1767ea61e9acSJeremy L Thompson   @param[in]  op      CeedOperator to apply
1768ea61e9acSJeremy L Thompson   @param[in]  in      CeedVector containing input state or NULL if there are no active inputs
1769ea61e9acSJeremy 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
1770ea61e9acSJeremy L Thompson   @param[in]  request Address of CeedRequest for non-blocking completion, else @ref CEED_REQUEST_IMMEDIATE
1771cae8b89aSjeremylt 
1772cae8b89aSjeremylt   @return An error code: 0 - success, otherwise - failure
1773cae8b89aSjeremylt 
17747a982d89SJeremy L. Thompson   @ref User
1775cae8b89aSjeremylt **/
17762b730f8bSJeremy L Thompson int CeedOperatorApplyAdd(CeedOperator op, CeedVector in, CeedVector out, CeedRequest *request) {
17772b730f8bSJeremy L Thompson   CeedCall(CeedOperatorCheckReady(op));
1778cae8b89aSjeremylt 
1779d1d35e2fSjeremylt   if (op->num_elem) {
1780250756a7Sjeremylt     // Standard Operator
17812b730f8bSJeremy L Thompson     CeedCall(op->ApplyAdd(op, in, out, request));
1782f04ea552SJeremy L Thompson   } else if (op->is_composite) {
1783250756a7Sjeremylt     // Composite Operator
1784250756a7Sjeremylt     if (op->ApplyAddComposite) {
17852b730f8bSJeremy L Thompson       CeedCall(op->ApplyAddComposite(op, in, out, request));
1786cae8b89aSjeremylt     } else {
1787d1d35e2fSjeremylt       CeedInt num_suboperators;
1788c6ebc35dSJeremy L Thompson       CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators));
1789d1d35e2fSjeremylt       CeedOperator *sub_operators;
1790c6ebc35dSJeremy L Thompson       CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators));
1791250756a7Sjeremylt 
1792d1d35e2fSjeremylt       for (CeedInt i = 0; i < num_suboperators; i++) {
17932b730f8bSJeremy L Thompson         CeedCall(CeedOperatorApplyAdd(sub_operators[i], in, out, request));
17941d7d2407SJeremy L Thompson       }
1795250756a7Sjeremylt     }
1796250756a7Sjeremylt   }
1797e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
1798d7b241e6Sjeremylt }
1799d7b241e6Sjeremylt 
1800d7b241e6Sjeremylt /**
1801b11c1e72Sjeremylt   @brief Destroy a CeedOperator
1802d7b241e6Sjeremylt 
1803ea61e9acSJeremy L Thompson   @param[in,out] op CeedOperator to destroy
1804b11c1e72Sjeremylt 
1805b11c1e72Sjeremylt   @return An error code: 0 - success, otherwise - failure
1806dfdf5a53Sjeremylt 
18077a982d89SJeremy L. Thompson   @ref User
1808b11c1e72Sjeremylt **/
1809d7b241e6Sjeremylt int CeedOperatorDestroy(CeedOperator *op) {
1810ad6481ceSJeremy L Thompson   if (!*op || --(*op)->ref_count > 0) {
1811ad6481ceSJeremy L Thompson     *op = NULL;
1812ad6481ceSJeremy L Thompson     return CEED_ERROR_SUCCESS;
1813ad6481ceSJeremy L Thompson   }
18142b730f8bSJeremy L Thompson   if ((*op)->Destroy) CeedCall((*op)->Destroy(*op));
18152b730f8bSJeremy L Thompson   CeedCall(CeedDestroy(&(*op)->ceed));
1816fe2413ffSjeremylt   // Free fields
18172b730f8bSJeremy L Thompson   for (CeedInt i = 0; i < (*op)->num_fields; i++) {
1818d1d35e2fSjeremylt     if ((*op)->input_fields[i]) {
1819437c7c90SJeremy L Thompson       if ((*op)->input_fields[i]->elem_rstr != CEED_ELEMRESTRICTION_NONE) {
1820437c7c90SJeremy L Thompson         CeedCall(CeedElemRestrictionDestroy(&(*op)->input_fields[i]->elem_rstr));
182115910d16Sjeremylt       }
1822d1d35e2fSjeremylt       if ((*op)->input_fields[i]->basis != CEED_BASIS_COLLOCATED) {
18232b730f8bSJeremy L Thompson         CeedCall(CeedBasisDestroy(&(*op)->input_fields[i]->basis));
182471352a93Sjeremylt       }
18252b730f8bSJeremy L Thompson       if ((*op)->input_fields[i]->vec != CEED_VECTOR_ACTIVE && (*op)->input_fields[i]->vec != CEED_VECTOR_NONE) {
18262b730f8bSJeremy L Thompson         CeedCall(CeedVectorDestroy(&(*op)->input_fields[i]->vec));
182771352a93Sjeremylt       }
18282b730f8bSJeremy L Thompson       CeedCall(CeedFree(&(*op)->input_fields[i]->field_name));
18292b730f8bSJeremy L Thompson       CeedCall(CeedFree(&(*op)->input_fields[i]));
1830fe2413ffSjeremylt     }
18312b730f8bSJeremy L Thompson   }
18322b730f8bSJeremy L Thompson   for (CeedInt i = 0; i < (*op)->num_fields; i++) {
1833d1d35e2fSjeremylt     if ((*op)->output_fields[i]) {
1834437c7c90SJeremy L Thompson       CeedCall(CeedElemRestrictionDestroy(&(*op)->output_fields[i]->elem_rstr));
1835d1d35e2fSjeremylt       if ((*op)->output_fields[i]->basis != CEED_BASIS_COLLOCATED) {
18362b730f8bSJeremy L Thompson         CeedCall(CeedBasisDestroy(&(*op)->output_fields[i]->basis));
183771352a93Sjeremylt       }
18382b730f8bSJeremy L Thompson       if ((*op)->output_fields[i]->vec != CEED_VECTOR_ACTIVE && (*op)->output_fields[i]->vec != CEED_VECTOR_NONE) {
18392b730f8bSJeremy L Thompson         CeedCall(CeedVectorDestroy(&(*op)->output_fields[i]->vec));
184071352a93Sjeremylt       }
18412b730f8bSJeremy L Thompson       CeedCall(CeedFree(&(*op)->output_fields[i]->field_name));
18422b730f8bSJeremy L Thompson       CeedCall(CeedFree(&(*op)->output_fields[i]));
18432b730f8bSJeremy L Thompson     }
1844fe2413ffSjeremylt   }
1845d1d35e2fSjeremylt   // Destroy sub_operators
18462b730f8bSJeremy L Thompson   for (CeedInt i = 0; i < (*op)->num_suboperators; i++) {
1847d1d35e2fSjeremylt     if ((*op)->sub_operators[i]) {
18482b730f8bSJeremy L Thompson       CeedCall(CeedOperatorDestroy(&(*op)->sub_operators[i]));
184952d6035fSJeremy L Thompson     }
18502b730f8bSJeremy L Thompson   }
18512b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionDestroy(&(*op)->qf));
18522b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionDestroy(&(*op)->dqf));
18532b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionDestroy(&(*op)->dqfT));
18543668ca4bSJeremy L Thompson   // Destroy any composite labels
1855*5ac9af79SJeremy L Thompson   if ((*op)->is_composite) {
18563668ca4bSJeremy L Thompson     for (CeedInt i = 0; i < (*op)->num_context_labels; i++) {
18572b730f8bSJeremy L Thompson       CeedCall(CeedFree(&(*op)->context_labels[i]->sub_labels));
18582b730f8bSJeremy L Thompson       CeedCall(CeedFree(&(*op)->context_labels[i]));
18593668ca4bSJeremy L Thompson     }
1860*5ac9af79SJeremy L Thompson   }
18612b730f8bSJeremy L Thompson   CeedCall(CeedFree(&(*op)->context_labels));
1862fe2413ffSjeremylt 
18635107b09fSJeremy L Thompson   // Destroy fallback
18642b730f8bSJeremy L Thompson   CeedCall(CeedOperatorDestroy(&(*op)->op_fallback));
18655107b09fSJeremy L Thompson 
1866ed9e99e6SJeremy L Thompson   // Destroy assembly data
18672b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionAssemblyDataDestroy(&(*op)->qf_assembled));
18682b730f8bSJeremy L Thompson   CeedCall(CeedOperatorAssemblyDataDestroy(&(*op)->op_assembled));
186970a7ffb3SJeremy L Thompson 
18702b730f8bSJeremy L Thompson   CeedCall(CeedFree(&(*op)->input_fields));
18712b730f8bSJeremy L Thompson   CeedCall(CeedFree(&(*op)->output_fields));
18722b730f8bSJeremy L Thompson   CeedCall(CeedFree(&(*op)->sub_operators));
18732b730f8bSJeremy L Thompson   CeedCall(CeedFree(&(*op)->name));
18742b730f8bSJeremy L Thompson   CeedCall(CeedFree(op));
1875e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
1876d7b241e6Sjeremylt }
1877d7b241e6Sjeremylt 
1878d7b241e6Sjeremylt /// @}
1879