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 /** 25ca94c3ddSJeremy L Thompson @brief Check if a `CeedOperator` Field matches the `CeedQFunction` Field 26e15f9bd0SJeremy L Thompson 27ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` object for error handling 28ca94c3ddSJeremy L Thompson @param[in] qf_field `CeedQFunction` Field matching `CeedOperator` Field 29bafebce1SSebastian Grimberg @param[in] rstr `CeedOperator` Field `CeedElemRestriction` 30bafebce1SSebastian Grimberg @param[in] basis `CeedOperator` Field `CeedBasis` 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 **/ 36bafebce1SSebastian Grimberg static int CeedOperatorCheckField(Ceed ceed, CeedQFunctionField qf_field, CeedElemRestriction rstr, CeedBasis basis) { 37*1203703bSJeremy L Thompson char *field_name; 38*1203703bSJeremy L Thompson CeedInt dim = 1, num_comp = 1, q_comp = 1, rstr_num_comp = 1, size; 39*1203703bSJeremy L Thompson CeedEvalMode eval_mode; 40*1203703bSJeremy L Thompson 41*1203703bSJeremy L Thompson // Field data 42*1203703bSJeremy L Thompson CeedCall(CeedQFunctionFieldGetName(qf_field, &field_name)); 43*1203703bSJeremy L Thompson CeedCall(CeedQFunctionFieldGetSize(qf_field, &size)); 44*1203703bSJeremy L Thompson CeedCall(CeedQFunctionFieldGetEvalMode(qf_field, &eval_mode)); 452b730f8bSJeremy L Thompson 46e15f9bd0SJeremy L Thompson // Restriction 47bafebce1SSebastian Grimberg CeedCheck((rstr == CEED_ELEMRESTRICTION_NONE) == (eval_mode == CEED_EVAL_WEIGHT), ceed, CEED_ERROR_INCOMPATIBLE, 486574a04fSJeremy L Thompson "CEED_ELEMRESTRICTION_NONE and CEED_EVAL_WEIGHT must be used together."); 49bafebce1SSebastian Grimberg if (rstr != CEED_ELEMRESTRICTION_NONE) { 50bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionGetNumComponents(rstr, &rstr_num_comp)); 51e1e9e29dSJed Brown } 52e15f9bd0SJeremy L Thompson // Basis 53bafebce1SSebastian Grimberg CeedCheck((basis == CEED_BASIS_NONE) == (eval_mode == CEED_EVAL_NONE), ceed, CEED_ERROR_INCOMPATIBLE, 54356036faSJeremy L Thompson "CEED_BASIS_NONE and CEED_EVAL_NONE must be used together."); 55bafebce1SSebastian Grimberg if (basis != CEED_BASIS_NONE) { 56bafebce1SSebastian Grimberg CeedCall(CeedBasisGetDimension(basis, &dim)); 57bafebce1SSebastian Grimberg CeedCall(CeedBasisGetNumComponents(basis, &num_comp)); 58bafebce1SSebastian Grimberg CeedCall(CeedBasisGetNumQuadratureComponents(basis, eval_mode, &q_comp)); 59bafebce1SSebastian Grimberg CeedCheck(rstr == CEED_ELEMRESTRICTION_NONE || rstr_num_comp == num_comp, ceed, CEED_ERROR_DIMENSION, 60ca94c3ddSJeremy L Thompson "Field '%s' of size %" CeedInt_FMT " and EvalMode %s: CeedElemRestriction has %" CeedInt_FMT 61ca94c3ddSJeremy L Thompson " components, but CeedBasis has %" CeedInt_FMT " components", 62*1203703bSJeremy L Thompson field_name, size, CeedEvalModes[eval_mode], rstr_num_comp, num_comp); 63e15f9bd0SJeremy L Thompson } 64e15f9bd0SJeremy L Thompson // Field size 65d1d35e2fSjeremylt switch (eval_mode) { 66e15f9bd0SJeremy L Thompson case CEED_EVAL_NONE: 67edb2538eSJeremy L Thompson CeedCheck(size == rstr_num_comp, ceed, CEED_ERROR_DIMENSION, 68*1203703bSJeremy L Thompson "Field '%s' of size %" CeedInt_FMT " and EvalMode %s: CeedElemRestriction has %" CeedInt_FMT " components", field_name, size, 69*1203703bSJeremy L Thompson CeedEvalModes[eval_mode], rstr_num_comp); 70e15f9bd0SJeremy L Thompson break; 71e15f9bd0SJeremy L Thompson case CEED_EVAL_INTERP: 72c4e3f59bSSebastian Grimberg case CEED_EVAL_GRAD: 73c4e3f59bSSebastian Grimberg case CEED_EVAL_DIV: 74c4e3f59bSSebastian Grimberg case CEED_EVAL_CURL: 756574a04fSJeremy L Thompson CeedCheck(size == num_comp * q_comp, ceed, CEED_ERROR_DIMENSION, 76*1203703bSJeremy L Thompson "Field '%s' of size %" CeedInt_FMT " and EvalMode %s: CeedElemRestriction/Basis has %" CeedInt_FMT " components", field_name, size, 77*1203703bSJeremy L Thompson CeedEvalModes[eval_mode], num_comp * q_comp); 78e15f9bd0SJeremy L Thompson break; 79e15f9bd0SJeremy L Thompson case CEED_EVAL_WEIGHT: 80d1d35e2fSjeremylt // No additional checks required 81e15f9bd0SJeremy L Thompson break; 82e15f9bd0SJeremy L Thompson } 83e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 847a982d89SJeremy L. Thompson } 857a982d89SJeremy L. Thompson 867a982d89SJeremy L. Thompson /** 87ca94c3ddSJeremy L Thompson @brief View a field of a `CeedOperator` 887a982d89SJeremy L. Thompson 89*1203703bSJeremy L Thompson @param[in] op_field `CeedOperator` Field to view 90ca94c3ddSJeremy L Thompson @param[in] qf_field `CeedQFunction` Field (carries field name) 91d1d35e2fSjeremylt @param[in] field_number Number of field being viewed 924c4400c7SValeria Barra @param[in] sub true indicates sub-operator, which increases indentation; false for top-level operator 93d1d35e2fSjeremylt @param[in] input true for an input field; false for output field 94ca94c3ddSJeremy L Thompson @param[in] stream Stream to view to, e.g., `stdout` 957a982d89SJeremy L. Thompson 967a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 977a982d89SJeremy L. Thompson 987a982d89SJeremy L. Thompson @ref Utility 997a982d89SJeremy L. Thompson **/ 100*1203703bSJeremy L Thompson static int CeedOperatorFieldView(CeedOperatorField op_field, CeedQFunctionField qf_field, CeedInt field_number, bool sub, bool input, FILE *stream) { 1017a982d89SJeremy L. Thompson const char *pre = sub ? " " : ""; 102d1d35e2fSjeremylt const char *in_out = input ? "Input" : "Output"; 103*1203703bSJeremy L Thompson char *field_name; 104*1203703bSJeremy L Thompson CeedInt size; 105*1203703bSJeremy L Thompson CeedEvalMode eval_mode; 106*1203703bSJeremy L Thompson CeedVector vec; 107*1203703bSJeremy L Thompson CeedBasis basis; 108*1203703bSJeremy L Thompson 109*1203703bSJeremy L Thompson // Field data 110*1203703bSJeremy L Thompson CeedCall(CeedQFunctionFieldGetName(qf_field, &field_name)); 111*1203703bSJeremy L Thompson CeedCall(CeedQFunctionFieldGetSize(qf_field, &size)); 112*1203703bSJeremy L Thompson CeedCall(CeedQFunctionFieldGetEvalMode(qf_field, &eval_mode)); 113*1203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(op_field, &vec)); 114*1203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetBasis(op_field, &basis)); 1157a982d89SJeremy L. Thompson 1162b730f8bSJeremy L Thompson fprintf(stream, 1172b730f8bSJeremy L Thompson "%s %s field %" CeedInt_FMT 1182b730f8bSJeremy L Thompson ":\n" 1197a982d89SJeremy L. Thompson "%s Name: \"%s\"\n", 120*1203703bSJeremy L Thompson pre, in_out, field_number, pre, field_name); 121*1203703bSJeremy L Thompson fprintf(stream, "%s Size: %" CeedInt_FMT "\n", pre, size); 122*1203703bSJeremy L Thompson fprintf(stream, "%s EvalMode: %s\n", pre, CeedEvalModes[eval_mode]); 123*1203703bSJeremy L Thompson if (basis == CEED_BASIS_NONE) fprintf(stream, "%s No basis\n", pre); 124*1203703bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) fprintf(stream, "%s Active vector\n", pre); 125*1203703bSJeremy L Thompson else if (vec == CEED_VECTOR_NONE) fprintf(stream, "%s No vector\n", pre); 126e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 1277a982d89SJeremy L. Thompson } 1287a982d89SJeremy L. Thompson 1297a982d89SJeremy L. Thompson /** 130ca94c3ddSJeremy L Thompson @brief View a single `CeedOperator` 1317a982d89SJeremy L. Thompson 132ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to view 1337a982d89SJeremy L. Thompson @param[in] sub Boolean flag for sub-operator 134ca94c3ddSJeremy L Thompson @param[in] stream Stream to write; typically `stdout` or a file 1357a982d89SJeremy L. Thompson 1367a982d89SJeremy L. Thompson @return Error code: 0 - success, otherwise - failure 1377a982d89SJeremy L. Thompson 1387a982d89SJeremy L. Thompson @ref Utility 1397a982d89SJeremy L. Thompson **/ 1407a982d89SJeremy L. Thompson int CeedOperatorSingleView(CeedOperator op, bool sub, FILE *stream) { 1417a982d89SJeremy L. Thompson const char *pre = sub ? " " : ""; 142*1203703bSJeremy L Thompson CeedInt num_elem, num_qpts, total_fields = 0, num_input_fields, num_output_fields; 143*1203703bSJeremy L Thompson CeedQFunction qf; 144*1203703bSJeremy L Thompson CeedQFunctionField *qf_input_fields, *qf_output_fields; 145*1203703bSJeremy L Thompson CeedOperatorField *op_input_fields, *op_output_fields; 1467a982d89SJeremy L. Thompson 1472b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetNumElements(op, &num_elem)); 1482b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetNumQuadraturePoints(op, &num_qpts)); 1492b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetNumArgs(op, &total_fields)); 150*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields)); 151*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 152*1203703bSJeremy L Thompson CeedCall(CeedQFunctionGetFields(qf, NULL, &qf_input_fields, NULL, &qf_output_fields)); 1531c66c397SJeremy L Thompson 1542b730f8bSJeremy L Thompson fprintf(stream, "%s %" CeedInt_FMT " elements with %" CeedInt_FMT " quadrature points each\n", pre, num_elem, num_qpts); 1552b730f8bSJeremy L Thompson fprintf(stream, "%s %" CeedInt_FMT " field%s\n", pre, total_fields, total_fields > 1 ? "s" : ""); 156*1203703bSJeremy L Thompson fprintf(stream, "%s %" CeedInt_FMT " input field%s:\n", pre, num_input_fields, num_input_fields > 1 ? "s" : ""); 157*1203703bSJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 158*1203703bSJeremy L Thompson CeedCall(CeedOperatorFieldView(op_input_fields[i], qf_input_fields[i], i, sub, 1, stream)); 1597a982d89SJeremy L. Thompson } 160*1203703bSJeremy L Thompson fprintf(stream, "%s %" CeedInt_FMT " output field%s:\n", pre, num_output_fields, num_output_fields > 1 ? "s" : ""); 161*1203703bSJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 162*1203703bSJeremy L Thompson CeedCall(CeedOperatorFieldView(op_output_fields[i], qf_output_fields[i], i, sub, 0, stream)); 1637a982d89SJeremy L. Thompson } 164e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 1657a982d89SJeremy L. Thompson } 1667a982d89SJeremy L. Thompson 167d99fa3c5SJeremy L Thompson /** 168ca94c3ddSJeremy L Thompson @brief Find the active input vector `CeedBasis` for a non-composite `CeedOperator` 169eaf62fffSJeremy L Thompson 170ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to find active `CeedBasis` for 171ca94c3ddSJeremy L Thompson @param[out] active_basis `CeedBasis` for active input vector or `NULL` for composite operator 172eaf62fffSJeremy L Thompson 173eaf62fffSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 174eaf62fffSJeremy L Thompson 175eaf62fffSJeremy L Thompson @ref Developer 176eaf62fffSJeremy L Thompson **/ 177eaf62fffSJeremy L Thompson int CeedOperatorGetActiveBasis(CeedOperator op, CeedBasis *active_basis) { 178506b1a0cSSebastian Grimberg CeedCall(CeedOperatorGetActiveBases(op, active_basis, NULL)); 179506b1a0cSSebastian Grimberg return CEED_ERROR_SUCCESS; 180506b1a0cSSebastian Grimberg } 181506b1a0cSSebastian Grimberg 182506b1a0cSSebastian Grimberg /** 183ca94c3ddSJeremy L Thompson @brief Find the active input and output vector `CeedBasis` for a non-composite `CeedOperator` 184506b1a0cSSebastian Grimberg 185ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to find active `CeedBasis` for 186ca94c3ddSJeremy L Thompson @param[out] active_input_basis `CeedBasis` for active input vector or `NULL` for composite operator 187ca94c3ddSJeremy L Thompson @param[out] active_output_basis `CeedBasis` for active output vector or `NULL` for composite operator 188506b1a0cSSebastian Grimberg 189506b1a0cSSebastian Grimberg @return An error code: 0 - success, otherwise - failure 190506b1a0cSSebastian Grimberg 191506b1a0cSSebastian Grimberg @ref Developer 192506b1a0cSSebastian Grimberg **/ 193506b1a0cSSebastian Grimberg int CeedOperatorGetActiveBases(CeedOperator op, CeedBasis *active_input_basis, CeedBasis *active_output_basis) { 194*1203703bSJeremy L Thompson bool is_composite; 195*1203703bSJeremy L Thompson CeedInt num_input_fields, num_output_fields; 1966aaed0edSJeremy L Thompson Ceed ceed; 197*1203703bSJeremy L Thompson CeedOperatorField *op_input_fields, *op_output_fields; 1981c66c397SJeremy L Thompson 1996aaed0edSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 200*1203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 201*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields)); 202*1203703bSJeremy L Thompson 203506b1a0cSSebastian Grimberg if (active_input_basis) { 204506b1a0cSSebastian Grimberg *active_input_basis = NULL; 205*1203703bSJeremy L Thompson if (!is_composite) { 206*1203703bSJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 207*1203703bSJeremy L Thompson CeedVector vec; 208*1203703bSJeremy L Thompson 209*1203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(op_input_fields[i], &vec)); 210*1203703bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 211*1203703bSJeremy L Thompson CeedBasis basis; 212*1203703bSJeremy L Thompson 213*1203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetBasis(op_input_fields[i], &basis)); 214*1203703bSJeremy L Thompson CeedCheck(!*active_input_basis || *active_input_basis == basis, ceed, CEED_ERROR_MINOR, "Multiple active input CeedBases found"); 215*1203703bSJeremy L Thompson *active_input_basis = basis; 216eaf62fffSJeremy L Thompson } 2172b730f8bSJeremy L Thompson } 218506b1a0cSSebastian Grimberg CeedCheck(*active_input_basis, ceed, CEED_ERROR_INCOMPLETE, "No active input CeedBasis found"); 219506b1a0cSSebastian Grimberg } 220506b1a0cSSebastian Grimberg } 221506b1a0cSSebastian Grimberg if (active_output_basis) { 222506b1a0cSSebastian Grimberg *active_output_basis = NULL; 223*1203703bSJeremy L Thompson if (!is_composite) { 224*1203703bSJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 225*1203703bSJeremy L Thompson CeedVector vec; 226*1203703bSJeremy L Thompson 227*1203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(op_output_fields[i], &vec)); 228*1203703bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 229*1203703bSJeremy L Thompson CeedBasis basis; 230*1203703bSJeremy L Thompson 231*1203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetBasis(op_output_fields[i], &basis)); 232*1203703bSJeremy L Thompson CeedCheck(!*active_output_basis || *active_output_basis == basis, ceed, CEED_ERROR_MINOR, "Multiple active output CeedBases found"); 233*1203703bSJeremy L Thompson *active_output_basis = basis; 234506b1a0cSSebastian Grimberg } 235506b1a0cSSebastian Grimberg } 236506b1a0cSSebastian Grimberg CeedCheck(*active_output_basis, ceed, CEED_ERROR_INCOMPLETE, "No active output CeedBasis found"); 237506b1a0cSSebastian Grimberg } 238506b1a0cSSebastian Grimberg } 239eaf62fffSJeremy L Thompson return CEED_ERROR_SUCCESS; 240eaf62fffSJeremy L Thompson } 241eaf62fffSJeremy L Thompson 242eaf62fffSJeremy L Thompson /** 243ca94c3ddSJeremy L Thompson @brief Find the active vector `CeedElemRestriction` for a non-composite `CeedOperator` 244e2f04181SAndrew T. Barker 245ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to find active `CeedElemRestriction` for 246ca94c3ddSJeremy L Thompson @param[out] active_rstr `CeedElemRestriction` for active input vector or NULL for composite operator 247e2f04181SAndrew T. Barker 248e2f04181SAndrew T. Barker @return An error code: 0 - success, otherwise - failure 249e2f04181SAndrew T. Barker 250e2f04181SAndrew T. Barker @ref Utility 251e2f04181SAndrew T. Barker **/ 2522b730f8bSJeremy L Thompson int CeedOperatorGetActiveElemRestriction(CeedOperator op, CeedElemRestriction *active_rstr) { 253506b1a0cSSebastian Grimberg CeedCall(CeedOperatorGetActiveElemRestrictions(op, active_rstr, NULL)); 254506b1a0cSSebastian Grimberg return CEED_ERROR_SUCCESS; 255506b1a0cSSebastian Grimberg } 256506b1a0cSSebastian Grimberg 257506b1a0cSSebastian Grimberg /** 258ca94c3ddSJeremy L Thompson @brief Find the active input and output vector `CeedElemRestriction` for a non-composite `CeedOperator` 259506b1a0cSSebastian Grimberg 260ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to find active `CeedElemRestriction` for 261ca94c3ddSJeremy L Thompson @param[out] active_input_rstr `CeedElemRestriction` for active input vector or NULL for composite operator 262ca94c3ddSJeremy L Thompson @param[out] active_output_rstr `CeedElemRestriction` for active output vector or NULL for composite operator 263506b1a0cSSebastian Grimberg 264506b1a0cSSebastian Grimberg @return An error code: 0 - success, otherwise - failure 265506b1a0cSSebastian Grimberg 266506b1a0cSSebastian Grimberg @ref Utility 267506b1a0cSSebastian Grimberg **/ 268506b1a0cSSebastian Grimberg int CeedOperatorGetActiveElemRestrictions(CeedOperator op, CeedElemRestriction *active_input_rstr, CeedElemRestriction *active_output_rstr) { 269*1203703bSJeremy L Thompson bool is_composite; 270*1203703bSJeremy L Thompson CeedInt num_input_fields, num_output_fields; 2716aaed0edSJeremy L Thompson Ceed ceed; 272*1203703bSJeremy L Thompson CeedOperatorField *op_input_fields, *op_output_fields; 2731c66c397SJeremy L Thompson 2746aaed0edSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 275*1203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 276*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields)); 277*1203703bSJeremy L Thompson 278506b1a0cSSebastian Grimberg if (active_input_rstr) { 279506b1a0cSSebastian Grimberg *active_input_rstr = NULL; 280*1203703bSJeremy L Thompson if (!is_composite) { 281*1203703bSJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 282*1203703bSJeremy L Thompson CeedVector vec; 283*1203703bSJeremy L Thompson 284*1203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(op_input_fields[i], &vec)); 285*1203703bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 286*1203703bSJeremy L Thompson CeedElemRestriction rstr; 287*1203703bSJeremy L Thompson 288*1203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetElemRestriction(op_input_fields[i], &rstr)); 289*1203703bSJeremy L Thompson CeedCheck(!*active_input_rstr || *active_input_rstr == rstr, ceed, CEED_ERROR_MINOR, "Multiple active input CeedElemRestrictions found"); 290*1203703bSJeremy L Thompson *active_input_rstr = rstr; 291e2f04181SAndrew T. Barker } 2922b730f8bSJeremy L Thompson } 293506b1a0cSSebastian Grimberg CeedCheck(*active_input_rstr, ceed, CEED_ERROR_INCOMPLETE, "No active input CeedElemRestriction found"); 294506b1a0cSSebastian Grimberg } 295506b1a0cSSebastian Grimberg } 296506b1a0cSSebastian Grimberg if (active_output_rstr) { 297506b1a0cSSebastian Grimberg *active_output_rstr = NULL; 298*1203703bSJeremy L Thompson if (!is_composite) { 299*1203703bSJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 300*1203703bSJeremy L Thompson CeedVector vec; 301*1203703bSJeremy L Thompson 302*1203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(op_output_fields[i], &vec)); 303*1203703bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 304*1203703bSJeremy L Thompson CeedElemRestriction rstr; 305*1203703bSJeremy L Thompson 306*1203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetElemRestriction(op_output_fields[i], &rstr)); 307*1203703bSJeremy L Thompson CeedCheck(!*active_output_rstr || *active_output_rstr == rstr, ceed, CEED_ERROR_MINOR, "Multiple active output CeedElemRestrictions found"); 308*1203703bSJeremy L Thompson *active_output_rstr = rstr; 309506b1a0cSSebastian Grimberg } 310506b1a0cSSebastian Grimberg } 311506b1a0cSSebastian Grimberg CeedCheck(*active_output_rstr, ceed, CEED_ERROR_INCOMPLETE, "No active output CeedElemRestriction found"); 312506b1a0cSSebastian Grimberg } 313506b1a0cSSebastian Grimberg } 314e2f04181SAndrew T. Barker return CEED_ERROR_SUCCESS; 315e2f04181SAndrew T. Barker } 316e2f04181SAndrew T. Barker 317d8dd9a91SJeremy L Thompson /** 318ca94c3ddSJeremy L Thompson @brief Set `CeedQFunctionContext` field values of the specified type. 3194385fb7fSSebastian Grimberg 320ca94c3ddSJeremy L Thompson For composite operators, the value is set in all sub-operator `CeedQFunctionContext` that have a matching `field_name`. 321ca94c3ddSJeremy 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 not have any field of a matching type. 322d8dd9a91SJeremy L Thompson 323ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 324ea61e9acSJeremy L Thompson @param[in] field_label Label of field to set 325ea61e9acSJeremy L Thompson @param[in] field_type Type of field to set 3262788fa27SJeremy L Thompson @param[in] values Values to set 327d8dd9a91SJeremy L Thompson 328d8dd9a91SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 329d8dd9a91SJeremy L Thompson 330d8dd9a91SJeremy L Thompson @ref User 331d8dd9a91SJeremy L Thompson **/ 3322788fa27SJeremy L Thompson static int CeedOperatorContextSetGeneric(CeedOperator op, CeedContextFieldLabel field_label, CeedContextFieldType field_type, void *values) { 3331c66c397SJeremy L Thompson bool is_composite = false; 334*1203703bSJeremy L Thompson Ceed ceed; 3351c66c397SJeremy L Thompson 336*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 337*1203703bSJeremy L Thompson CeedCheck(field_label, ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label"); 3383668ca4bSJeremy L Thompson 3395ac9af79SJeremy L Thompson // Check if field_label and op correspond 3405ac9af79SJeremy L Thompson if (field_label->from_op) { 3415ac9af79SJeremy L Thompson CeedInt index = -1; 3425ac9af79SJeremy L Thompson 3435ac9af79SJeremy L Thompson for (CeedInt i = 0; i < op->num_context_labels; i++) { 3445ac9af79SJeremy L Thompson if (op->context_labels[i] == field_label) index = i; 3455ac9af79SJeremy L Thompson } 346*1203703bSJeremy L Thompson CeedCheck(index != -1, ceed, CEED_ERROR_UNSUPPORTED, "ContextFieldLabel does not correspond to the operator"); 3475ac9af79SJeremy L Thompson } 3485ac9af79SJeremy L Thompson 3492b730f8bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 350d8dd9a91SJeremy L Thompson if (is_composite) { 351d8dd9a91SJeremy L Thompson CeedInt num_sub; 352d8dd9a91SJeremy L Thompson CeedOperator *sub_operators; 353d8dd9a91SJeremy L Thompson 354c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub)); 355c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 356*1203703bSJeremy L Thompson CeedCheck(num_sub == field_label->num_sub_labels, ceed, CEED_ERROR_UNSUPPORTED, "Composite operator modified after ContextFieldLabel created"); 357d8dd9a91SJeremy L Thompson 358d8dd9a91SJeremy L Thompson for (CeedInt i = 0; i < num_sub; i++) { 359*1203703bSJeremy L Thompson CeedQFunction qf; 360*1203703bSJeremy L Thompson CeedQFunctionContext ctx; 361*1203703bSJeremy L Thompson 362*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(sub_operators[i], &qf)); 363*1203703bSJeremy L Thompson CeedCall(CeedQFunctionGetContext(qf, &ctx)); 364d8dd9a91SJeremy L Thompson // Try every sub-operator, ok if some sub-operators do not have field 365*1203703bSJeremy L Thompson if (field_label->sub_labels[i] && ctx) { 366*1203703bSJeremy L Thompson CeedCall(CeedQFunctionContextSetGeneric(ctx, field_label->sub_labels[i], field_type, values)); 367d8dd9a91SJeremy L Thompson } 368d8dd9a91SJeremy L Thompson } 369d8dd9a91SJeremy L Thompson } else { 370*1203703bSJeremy L Thompson CeedQFunction qf; 371*1203703bSJeremy L Thompson CeedQFunctionContext ctx; 372*1203703bSJeremy L Thompson 373*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 374*1203703bSJeremy L Thompson CeedCall(CeedQFunctionGetContext(qf, &ctx)); 375*1203703bSJeremy L Thompson CeedCheck(ctx, ceed, CEED_ERROR_UNSUPPORTED, "QFunction does not have context data"); 376*1203703bSJeremy L Thompson CeedCall(CeedQFunctionContextSetGeneric(ctx, field_label, field_type, values)); 3772788fa27SJeremy L Thompson } 3786d95ab46SJeremy L Thompson CeedCall(CeedOperatorSetQFunctionAssemblyDataUpdateNeeded(op, true)); 3792788fa27SJeremy L Thompson return CEED_ERROR_SUCCESS; 3802788fa27SJeremy L Thompson } 3812788fa27SJeremy L Thompson 3822788fa27SJeremy L Thompson /** 383ca94c3ddSJeremy L Thompson @brief Get `CeedQFunctionContext` field values of the specified type, read-only. 3844385fb7fSSebastian Grimberg 385ca94c3ddSJeremy L Thompson For composite operators, the values retrieved are for the first sub-operator `CeedQFunctionContext` that have a matching `field_name`. 386ca94c3ddSJeremy 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 not have any field of a matching type. 3872788fa27SJeremy L Thompson 388ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 3892788fa27SJeremy L Thompson @param[in] field_label Label of field to set 3902788fa27SJeremy L Thompson @param[in] field_type Type of field to set 391c5d0f995SJed Brown @param[out] num_values Number of values of type `field_type` in array `values` 392c5d0f995SJed Brown @param[out] values Values in the label 3932788fa27SJeremy L Thompson 3942788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 3952788fa27SJeremy L Thompson 3962788fa27SJeremy L Thompson @ref User 3972788fa27SJeremy L Thompson **/ 3982788fa27SJeremy L Thompson static int CeedOperatorContextGetGenericRead(CeedOperator op, CeedContextFieldLabel field_label, CeedContextFieldType field_type, size_t *num_values, 3992788fa27SJeremy L Thompson void *values) { 4001c66c397SJeremy L Thompson bool is_composite = false; 401*1203703bSJeremy L Thompson Ceed ceed; 4021c66c397SJeremy L Thompson 403*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 404*1203703bSJeremy L Thompson CeedCheck(field_label, ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label"); 4052788fa27SJeremy L Thompson 4062788fa27SJeremy L Thompson *(void **)values = NULL; 4072788fa27SJeremy L Thompson *num_values = 0; 4082788fa27SJeremy L Thompson 4095ac9af79SJeremy L Thompson // Check if field_label and op correspond 4105ac9af79SJeremy L Thompson if (field_label->from_op) { 4115ac9af79SJeremy L Thompson CeedInt index = -1; 4125ac9af79SJeremy L Thompson 4135ac9af79SJeremy L Thompson for (CeedInt i = 0; i < op->num_context_labels; i++) { 4145ac9af79SJeremy L Thompson if (op->context_labels[i] == field_label) index = i; 4155ac9af79SJeremy L Thompson } 4166574a04fSJeremy L Thompson CeedCheck(index != -1, op->ceed, CEED_ERROR_UNSUPPORTED, "ContextFieldLabel does not correspond to the operator"); 4175ac9af79SJeremy L Thompson } 4185ac9af79SJeremy L Thompson 4192788fa27SJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 4202788fa27SJeremy L Thompson if (is_composite) { 4212788fa27SJeremy L Thompson CeedInt num_sub; 4222788fa27SJeremy L Thompson CeedOperator *sub_operators; 4232788fa27SJeremy L Thompson 4242788fa27SJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub)); 4252788fa27SJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 426*1203703bSJeremy L Thompson CeedCheck(num_sub == field_label->num_sub_labels, ceed, CEED_ERROR_UNSUPPORTED, "Composite operator modified after ContextFieldLabel created"); 4272788fa27SJeremy L Thompson 4282788fa27SJeremy L Thompson for (CeedInt i = 0; i < num_sub; i++) { 429*1203703bSJeremy L Thompson CeedQFunction qf; 430*1203703bSJeremy L Thompson CeedQFunctionContext ctx; 431*1203703bSJeremy L Thompson 432*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(sub_operators[i], &qf)); 433*1203703bSJeremy L Thompson CeedCall(CeedQFunctionGetContext(qf, &ctx)); 4342788fa27SJeremy L Thompson // Try every sub-operator, ok if some sub-operators do not have field 435*1203703bSJeremy L Thompson if (field_label->sub_labels[i] && ctx) { 436*1203703bSJeremy L Thompson CeedCall(CeedQFunctionContextGetGenericRead(ctx, field_label->sub_labels[i], field_type, num_values, values)); 4372788fa27SJeremy L Thompson return CEED_ERROR_SUCCESS; 4382788fa27SJeremy L Thompson } 4392788fa27SJeremy L Thompson } 4402788fa27SJeremy L Thompson } else { 441*1203703bSJeremy L Thompson CeedQFunction qf; 442*1203703bSJeremy L Thompson CeedQFunctionContext ctx; 443*1203703bSJeremy L Thompson 444*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 445*1203703bSJeremy L Thompson CeedCall(CeedQFunctionGetContext(qf, &ctx)); 446*1203703bSJeremy L Thompson CeedCheck(ctx, ceed, CEED_ERROR_UNSUPPORTED, "QFunction does not have context data"); 447*1203703bSJeremy L Thompson CeedCall(CeedQFunctionContextGetGenericRead(ctx, field_label, field_type, num_values, values)); 4482788fa27SJeremy L Thompson } 4492788fa27SJeremy L Thompson return CEED_ERROR_SUCCESS; 4502788fa27SJeremy L Thompson } 4512788fa27SJeremy L Thompson 4522788fa27SJeremy L Thompson /** 453ca94c3ddSJeremy L Thompson @brief Restore `CeedQFunctionContext` field values of the specified type, read-only. 4544385fb7fSSebastian Grimberg 455ca94c3ddSJeremy L Thompson For composite operators, the values restored are for the first sub-operator `CeedQFunctionContext` that have a matching `field_name`. 456ca94c3ddSJeremy 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 not have any field of a matching type. 4572788fa27SJeremy L Thompson 458ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 4592788fa27SJeremy L Thompson @param[in] field_label Label of field to set 4602788fa27SJeremy L Thompson @param[in] field_type Type of field to set 461c5d0f995SJed Brown @param[in] values Values array to restore 4622788fa27SJeremy L Thompson 4632788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 4642788fa27SJeremy L Thompson 4652788fa27SJeremy L Thompson @ref User 4662788fa27SJeremy L Thompson **/ 4672788fa27SJeremy L Thompson static int CeedOperatorContextRestoreGenericRead(CeedOperator op, CeedContextFieldLabel field_label, CeedContextFieldType field_type, void *values) { 4681c66c397SJeremy L Thompson bool is_composite = false; 469*1203703bSJeremy L Thompson Ceed ceed; 4701c66c397SJeremy L Thompson 471*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 472*1203703bSJeremy L Thompson CeedCheck(field_label, ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label"); 4732788fa27SJeremy L Thompson 4745ac9af79SJeremy L Thompson // Check if field_label and op correspond 4755ac9af79SJeremy L Thompson if (field_label->from_op) { 4765ac9af79SJeremy L Thompson CeedInt index = -1; 4775ac9af79SJeremy L Thompson 4785ac9af79SJeremy L Thompson for (CeedInt i = 0; i < op->num_context_labels; i++) { 4795ac9af79SJeremy L Thompson if (op->context_labels[i] == field_label) index = i; 4805ac9af79SJeremy L Thompson } 4816574a04fSJeremy L Thompson CeedCheck(index != -1, op->ceed, CEED_ERROR_UNSUPPORTED, "ContextFieldLabel does not correspond to the operator"); 4825ac9af79SJeremy L Thompson } 4835ac9af79SJeremy L Thompson 4842788fa27SJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 4852788fa27SJeremy L Thompson if (is_composite) { 4862788fa27SJeremy L Thompson CeedInt num_sub; 4872788fa27SJeremy L Thompson CeedOperator *sub_operators; 4882788fa27SJeremy L Thompson 4892788fa27SJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub)); 4902788fa27SJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 4916574a04fSJeremy L Thompson CeedCheck(num_sub == field_label->num_sub_labels, op->ceed, CEED_ERROR_UNSUPPORTED, 4926574a04fSJeremy L Thompson "Composite operator modified after ContextFieldLabel created"); 4932788fa27SJeremy L Thompson 4942788fa27SJeremy L Thompson for (CeedInt i = 0; i < num_sub; i++) { 495*1203703bSJeremy L Thompson CeedQFunction qf; 496*1203703bSJeremy L Thompson CeedQFunctionContext ctx; 497*1203703bSJeremy L Thompson 498*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(sub_operators[i], &qf)); 499*1203703bSJeremy L Thompson CeedCall(CeedQFunctionGetContext(qf, &ctx)); 5002788fa27SJeremy L Thompson // Try every sub-operator, ok if some sub-operators do not have field 501*1203703bSJeremy L Thompson if (field_label->sub_labels[i] && ctx) { 502*1203703bSJeremy L Thompson CeedCall(CeedQFunctionContextRestoreGenericRead(ctx, field_label->sub_labels[i], field_type, values)); 5032788fa27SJeremy L Thompson return CEED_ERROR_SUCCESS; 5042788fa27SJeremy L Thompson } 5052788fa27SJeremy L Thompson } 5062788fa27SJeremy L Thompson } else { 507*1203703bSJeremy L Thompson CeedQFunction qf; 508*1203703bSJeremy L Thompson CeedQFunctionContext ctx; 509*1203703bSJeremy L Thompson 510*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 511*1203703bSJeremy L Thompson CeedCall(CeedQFunctionGetContext(qf, &ctx)); 512*1203703bSJeremy L Thompson CeedCheck(ctx, ceed, CEED_ERROR_UNSUPPORTED, "QFunction does not have context data"); 513*1203703bSJeremy L Thompson CeedCall(CeedQFunctionContextRestoreGenericRead(ctx, field_label, field_type, values)); 514d8dd9a91SJeremy L Thompson } 515d8dd9a91SJeremy L Thompson return CEED_ERROR_SUCCESS; 516d8dd9a91SJeremy L Thompson } 517d8dd9a91SJeremy L Thompson 5187a982d89SJeremy L. Thompson /// @} 5197a982d89SJeremy L. Thompson 5207a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 5217a982d89SJeremy L. Thompson /// CeedOperator Backend API 5227a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 5237a982d89SJeremy L. Thompson /// @addtogroup CeedOperatorBackend 5247a982d89SJeremy L. Thompson /// @{ 5257a982d89SJeremy L. Thompson 5267a982d89SJeremy L. Thompson /** 527ca94c3ddSJeremy L Thompson @brief Get the number of arguments associated with a `CeedOperator` 5287a982d89SJeremy L. Thompson 529ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 530d1d35e2fSjeremylt @param[out] num_args Variable to store vector number of arguments 5317a982d89SJeremy L. Thompson 5327a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 5337a982d89SJeremy L. Thompson 5347a982d89SJeremy L. Thompson @ref Backend 5357a982d89SJeremy L. Thompson **/ 536d1d35e2fSjeremylt int CeedOperatorGetNumArgs(CeedOperator op, CeedInt *num_args) { 537*1203703bSJeremy L Thompson bool is_composite; 538*1203703bSJeremy L Thompson Ceed ceed; 539*1203703bSJeremy L Thompson 540*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 541*1203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 542*1203703bSJeremy L Thompson CeedCheck(!is_composite, ceed, CEED_ERROR_MINOR, "Not defined for composite operators"); 543d1d35e2fSjeremylt *num_args = op->num_fields; 544e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 5457a982d89SJeremy L. Thompson } 5467a982d89SJeremy L. Thompson 5477a982d89SJeremy L. Thompson /** 5489463e855SJeremy L Thompson @brief Get the tensor product status of all bases for a `CeedOperator`. 5499463e855SJeremy L Thompson 5509463e855SJeremy L Thompson `has_tensor_bases` is only set to `true` if every field uses a tensor-product basis. 5519463e855SJeremy L Thompson 5529463e855SJeremy L Thompson @param[in] op `CeedOperator` 5539463e855SJeremy L Thompson @param[out] has_tensor_bases Variable to store tensor bases status 5549463e855SJeremy L Thompson 5559463e855SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 5569463e855SJeremy L Thompson 5579463e855SJeremy L Thompson @ref Backend 5589463e855SJeremy L Thompson **/ 5599463e855SJeremy L Thompson int CeedOperatorHasTensorBases(CeedOperator op, bool *has_tensor_bases) { 5609463e855SJeremy L Thompson CeedInt num_inputs, num_outputs; 5619463e855SJeremy L Thompson CeedOperatorField *input_fields, *output_fields; 5629463e855SJeremy L Thompson 5639463e855SJeremy L Thompson CeedCall(CeedOperatorGetFields(op, &num_inputs, &input_fields, &num_outputs, &output_fields)); 5649463e855SJeremy L Thompson *has_tensor_bases = true; 5659463e855SJeremy L Thompson for (CeedInt i = 0; i < num_inputs; i++) { 5669463e855SJeremy L Thompson bool is_tensor; 5679463e855SJeremy L Thompson CeedBasis basis; 5689463e855SJeremy L Thompson 5699463e855SJeremy L Thompson CeedCall(CeedOperatorFieldGetBasis(input_fields[i], &basis)); 5709463e855SJeremy L Thompson if (basis != CEED_BASIS_NONE) { 5719463e855SJeremy L Thompson CeedCall(CeedBasisIsTensor(basis, &is_tensor)); 5729463e855SJeremy L Thompson *has_tensor_bases &= is_tensor; 5739463e855SJeremy L Thompson } 5749463e855SJeremy L Thompson } 5759463e855SJeremy L Thompson for (CeedInt i = 0; i < num_outputs; i++) { 5769463e855SJeremy L Thompson bool is_tensor; 5779463e855SJeremy L Thompson CeedBasis basis; 5789463e855SJeremy L Thompson 5799463e855SJeremy L Thompson CeedCall(CeedOperatorFieldGetBasis(output_fields[i], &basis)); 5809463e855SJeremy L Thompson if (basis != CEED_BASIS_NONE) { 5819463e855SJeremy L Thompson CeedCall(CeedBasisIsTensor(basis, &is_tensor)); 5829463e855SJeremy L Thompson *has_tensor_bases &= is_tensor; 5839463e855SJeremy L Thompson } 5849463e855SJeremy L Thompson } 5859463e855SJeremy L Thompson return CEED_ERROR_SUCCESS; 5869463e855SJeremy L Thompson } 5879463e855SJeremy L Thompson 5889463e855SJeremy L Thompson /** 589*1203703bSJeremy L Thompson @brief Get a boolean value indicating if the `CeedOperator` is immutable 590*1203703bSJeremy L Thompson 591*1203703bSJeremy L Thompson @param[in] op `CeedOperator` 592*1203703bSJeremy L Thompson @param[out] is_immutable Variable to store immutability status 593*1203703bSJeremy L Thompson 594*1203703bSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 595*1203703bSJeremy L Thompson 596*1203703bSJeremy L Thompson @ref Backend 597*1203703bSJeremy L Thompson **/ 598*1203703bSJeremy L Thompson int CeedOperatorIsImmutable(CeedOperator op, bool *is_immutable) { 599*1203703bSJeremy L Thompson *is_immutable = op->is_immutable; 600*1203703bSJeremy L Thompson return CEED_ERROR_SUCCESS; 601*1203703bSJeremy L Thompson } 602*1203703bSJeremy L Thompson 603*1203703bSJeremy L Thompson /** 604ca94c3ddSJeremy L Thompson @brief Get the setup status of a `CeedOperator` 6057a982d89SJeremy L. Thompson 606ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 607d1d35e2fSjeremylt @param[out] is_setup_done Variable to store setup status 6087a982d89SJeremy L. Thompson 6097a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 6107a982d89SJeremy L. Thompson 6117a982d89SJeremy L. Thompson @ref Backend 6127a982d89SJeremy L. Thompson **/ 613d1d35e2fSjeremylt int CeedOperatorIsSetupDone(CeedOperator op, bool *is_setup_done) { 614f04ea552SJeremy L Thompson *is_setup_done = op->is_backend_setup; 615e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 6167a982d89SJeremy L. Thompson } 6177a982d89SJeremy L. Thompson 6187a982d89SJeremy L. Thompson /** 619ca94c3ddSJeremy L Thompson @brief Get the `CeedQFunction` associated with a `CeedOperator` 6207a982d89SJeremy L. Thompson 621ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 622ca94c3ddSJeremy L Thompson @param[out] qf Variable to store `CeedQFunction` 6237a982d89SJeremy L. Thompson 6247a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 6257a982d89SJeremy L. Thompson 6267a982d89SJeremy L. Thompson @ref Backend 6277a982d89SJeremy L. Thompson **/ 6287a982d89SJeremy L. Thompson int CeedOperatorGetQFunction(CeedOperator op, CeedQFunction *qf) { 629*1203703bSJeremy L Thompson bool is_composite; 630*1203703bSJeremy L Thompson Ceed ceed; 631*1203703bSJeremy L Thompson 632*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 633*1203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 634*1203703bSJeremy L Thompson CeedCheck(!is_composite, ceed, CEED_ERROR_MINOR, "Not defined for composite operator"); 6357a982d89SJeremy L. Thompson *qf = op->qf; 636e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 6377a982d89SJeremy L. Thompson } 6387a982d89SJeremy L. Thompson 6397a982d89SJeremy L. Thompson /** 640ca94c3ddSJeremy L Thompson @brief Get a boolean value indicating if the `CeedOperator` is composite 641c04a41a7SJeremy L Thompson 642ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 643d1d35e2fSjeremylt @param[out] is_composite Variable to store composite status 644c04a41a7SJeremy L Thompson 645c04a41a7SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 646c04a41a7SJeremy L Thompson 647c04a41a7SJeremy L Thompson @ref Backend 648c04a41a7SJeremy L Thompson **/ 649d1d35e2fSjeremylt int CeedOperatorIsComposite(CeedOperator op, bool *is_composite) { 650f04ea552SJeremy L Thompson *is_composite = op->is_composite; 651e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 652c04a41a7SJeremy L Thompson } 653c04a41a7SJeremy L Thompson 654c04a41a7SJeremy L Thompson /** 655ca94c3ddSJeremy L Thompson @brief Get the backend data of a `CeedOperator` 6567a982d89SJeremy L. Thompson 657ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 6587a982d89SJeremy L. Thompson @param[out] data Variable to store data 6597a982d89SJeremy L. Thompson 6607a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 6617a982d89SJeremy L. Thompson 6627a982d89SJeremy L. Thompson @ref Backend 6637a982d89SJeremy L. Thompson **/ 664777ff853SJeremy L Thompson int CeedOperatorGetData(CeedOperator op, void *data) { 665777ff853SJeremy L Thompson *(void **)data = op->data; 666e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 6677a982d89SJeremy L. Thompson } 6687a982d89SJeremy L. Thompson 6697a982d89SJeremy L. Thompson /** 670ca94c3ddSJeremy L Thompson @brief Set the backend data of a `CeedOperator` 6717a982d89SJeremy L. Thompson 672ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 673ea61e9acSJeremy L Thompson @param[in] data Data to set 6747a982d89SJeremy L. Thompson 6757a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 6767a982d89SJeremy L. Thompson 6777a982d89SJeremy L. Thompson @ref Backend 6787a982d89SJeremy L. Thompson **/ 679777ff853SJeremy L Thompson int CeedOperatorSetData(CeedOperator op, void *data) { 680777ff853SJeremy L Thompson op->data = data; 681e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 6827a982d89SJeremy L. Thompson } 6837a982d89SJeremy L. Thompson 6847a982d89SJeremy L. Thompson /** 685ca94c3ddSJeremy L Thompson @brief Increment the reference counter for a `CeedOperator` 68634359f16Sjeremylt 687ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` to increment the reference counter 68834359f16Sjeremylt 68934359f16Sjeremylt @return An error code: 0 - success, otherwise - failure 69034359f16Sjeremylt 69134359f16Sjeremylt @ref Backend 69234359f16Sjeremylt **/ 6939560d06aSjeremylt int CeedOperatorReference(CeedOperator op) { 69434359f16Sjeremylt op->ref_count++; 69534359f16Sjeremylt return CEED_ERROR_SUCCESS; 69634359f16Sjeremylt } 69734359f16Sjeremylt 69834359f16Sjeremylt /** 699ca94c3ddSJeremy L Thompson @brief Set the setup flag of a `CeedOperator` to `true` 7007a982d89SJeremy L. Thompson 701ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 7027a982d89SJeremy L. Thompson 7037a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 7047a982d89SJeremy L. Thompson 7057a982d89SJeremy L. Thompson @ref Backend 7067a982d89SJeremy L. Thompson **/ 7077a982d89SJeremy L. Thompson int CeedOperatorSetSetupDone(CeedOperator op) { 708f04ea552SJeremy L Thompson op->is_backend_setup = true; 709e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 7107a982d89SJeremy L. Thompson } 7117a982d89SJeremy L. Thompson 7127a982d89SJeremy L. Thompson /// @} 7137a982d89SJeremy L. Thompson 7147a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 7157a982d89SJeremy L. Thompson /// CeedOperator Public API 7167a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 7177a982d89SJeremy L. Thompson /// @addtogroup CeedOperatorUser 718dfdf5a53Sjeremylt /// @{ 719d7b241e6Sjeremylt 720d7b241e6Sjeremylt /** 721ca94c3ddSJeremy L Thompson @brief Create a `CeedOperator` and associate a `CeedQFunction`. 7224385fb7fSSebastian Grimberg 723ca94c3ddSJeremy L Thompson A `CeedBasis` and `CeedElemRestriction` can be associated with `CeedQFunction` fields with @ref CeedOperatorSetField(). 724d7b241e6Sjeremylt 725ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` object used to create the `CeedOperator` 726ca94c3ddSJeremy L Thompson @param[in] qf `CeedQFunction` defining the action of the operator at quadrature points 727ca94c3ddSJeremy L Thompson @param[in] dqf `CeedQFunction` defining the action of the Jacobian of `qf` (or @ref CEED_QFUNCTION_NONE) 728ca94c3ddSJeremy L Thompson @param[in] dqfT `CeedQFunction` defining the action of the transpose of the Jacobian of `qf` (or @ref CEED_QFUNCTION_NONE) 729ca94c3ddSJeremy L Thompson @param[out] op Address of the variable where the newly created `CeedOperator` will be stored 730b11c1e72Sjeremylt 731b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 732dfdf5a53Sjeremylt 7337a982d89SJeremy L. Thompson @ref User 734d7b241e6Sjeremylt */ 7352b730f8bSJeremy L Thompson int CeedOperatorCreate(Ceed ceed, CeedQFunction qf, CeedQFunction dqf, CeedQFunction dqfT, CeedOperator *op) { 7365fe0d4faSjeremylt if (!ceed->OperatorCreate) { 7375fe0d4faSjeremylt Ceed delegate; 7386574a04fSJeremy L Thompson 7392b730f8bSJeremy L Thompson CeedCall(CeedGetObjectDelegate(ceed, &delegate, "Operator")); 740ca94c3ddSJeremy L Thompson CeedCheck(delegate, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support CeedOperatorCreate"); 7412b730f8bSJeremy L Thompson CeedCall(CeedOperatorCreate(delegate, qf, dqf, dqfT, op)); 742e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 7435fe0d4faSjeremylt } 7445fe0d4faSjeremylt 745ca94c3ddSJeremy L Thompson CeedCheck(qf && qf != CEED_QFUNCTION_NONE, ceed, CEED_ERROR_MINOR, "Operator must have a valid CeedQFunction."); 746db002c03SJeremy L Thompson 7472b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, op)); 748db002c03SJeremy L Thompson CeedCall(CeedReferenceCopy(ceed, &(*op)->ceed)); 749d1d35e2fSjeremylt (*op)->ref_count = 1; 7502b104005SJeremy L Thompson (*op)->input_size = -1; 7512b104005SJeremy L Thompson (*op)->output_size = -1; 752db002c03SJeremy L Thompson CeedCall(CeedQFunctionReferenceCopy(qf, &(*op)->qf)); 753db002c03SJeremy L Thompson if (dqf && dqf != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionReferenceCopy(dqf, &(*op)->dqf)); 754db002c03SJeremy L Thompson if (dqfT && dqfT != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionReferenceCopy(dqfT, &(*op)->dqfT)); 7552b730f8bSJeremy L Thompson CeedCall(CeedQFunctionAssemblyDataCreate(ceed, &(*op)->qf_assembled)); 7562b730f8bSJeremy L Thompson CeedCall(CeedCalloc(CEED_FIELD_MAX, &(*op)->input_fields)); 7572b730f8bSJeremy L Thompson CeedCall(CeedCalloc(CEED_FIELD_MAX, &(*op)->output_fields)); 7582b730f8bSJeremy L Thompson CeedCall(ceed->OperatorCreate(*op)); 759e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 760d7b241e6Sjeremylt } 761d7b241e6Sjeremylt 762d7b241e6Sjeremylt /** 763ca94c3ddSJeremy L Thompson @brief Create a `CeedOperator` for evaluation at evaluation at arbitrary points in each element. 76448acf710SJeremy L Thompson 765ca94c3ddSJeremy L Thompson A `CeedBasis` and `CeedElemRestriction` can be associated with `CeedQFunction` fields with `CeedOperator` SetField. 766ca94c3ddSJeremy L Thompson The locations of each point are set with @ref CeedOperatorAtPointsSetPoints(). 76748acf710SJeremy L Thompson 768ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` object used to create the `CeedOperator` 769ca94c3ddSJeremy L Thompson @param[in] qf `CeedQFunction` defining the action of the operator at quadrature points 770ca94c3ddSJeremy L Thompson @param[in] dqf `CeedQFunction` defining the action of the Jacobian of @a qf (or @ref CEED_QFUNCTION_NONE) 771ca94c3ddSJeremy L Thompson @param[in] dqfT `CeedQFunction` defining the action of the transpose of the Jacobian of @a qf (or @ref CEED_QFUNCTION_NONE) 77248acf710SJeremy L Thompson @param[out] op Address of the variable where the newly created CeedOperator will be stored 77348acf710SJeremy L Thompson 77448acf710SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 77548acf710SJeremy L Thompson 77648acf710SJeremy L Thompson @ref User 77748acf710SJeremy L Thompson */ 77848acf710SJeremy L Thompson int CeedOperatorCreateAtPoints(Ceed ceed, CeedQFunction qf, CeedQFunction dqf, CeedQFunction dqfT, CeedOperator *op) { 77948acf710SJeremy L Thompson if (!ceed->OperatorCreateAtPoints) { 78048acf710SJeremy L Thompson Ceed delegate; 78148acf710SJeremy L Thompson 78248acf710SJeremy L Thompson CeedCall(CeedGetObjectDelegate(ceed, &delegate, "Operator")); 783ca94c3ddSJeremy L Thompson CeedCheck(delegate, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support CeedOperatorCreateAtPoints"); 78448acf710SJeremy L Thompson CeedCall(CeedOperatorCreateAtPoints(delegate, qf, dqf, dqfT, op)); 78548acf710SJeremy L Thompson return CEED_ERROR_SUCCESS; 78648acf710SJeremy L Thompson } 78748acf710SJeremy L Thompson 788ca94c3ddSJeremy L Thompson CeedCheck(qf && qf != CEED_QFUNCTION_NONE, ceed, CEED_ERROR_MINOR, "Operator must have a valid CeedQFunction."); 78948acf710SJeremy L Thompson 79048acf710SJeremy L Thompson CeedCall(CeedCalloc(1, op)); 79148acf710SJeremy L Thompson CeedCall(CeedReferenceCopy(ceed, &(*op)->ceed)); 79248acf710SJeremy L Thompson (*op)->ref_count = 1; 79348acf710SJeremy L Thompson (*op)->is_at_points = true; 79448acf710SJeremy L Thompson (*op)->input_size = -1; 79548acf710SJeremy L Thompson (*op)->output_size = -1; 79648acf710SJeremy L Thompson CeedCall(CeedQFunctionReferenceCopy(qf, &(*op)->qf)); 79748acf710SJeremy L Thompson if (dqf && dqf != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionReferenceCopy(dqf, &(*op)->dqf)); 79848acf710SJeremy L Thompson if (dqfT && dqfT != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionReferenceCopy(dqfT, &(*op)->dqfT)); 79948acf710SJeremy L Thompson CeedCall(CeedQFunctionAssemblyDataCreate(ceed, &(*op)->qf_assembled)); 80048acf710SJeremy L Thompson CeedCall(CeedCalloc(CEED_FIELD_MAX, &(*op)->input_fields)); 80148acf710SJeremy L Thompson CeedCall(CeedCalloc(CEED_FIELD_MAX, &(*op)->output_fields)); 80248acf710SJeremy L Thompson CeedCall(ceed->OperatorCreateAtPoints(*op)); 80348acf710SJeremy L Thompson return CEED_ERROR_SUCCESS; 80448acf710SJeremy L Thompson } 80548acf710SJeremy L Thompson 80648acf710SJeremy L Thompson /** 807ca94c3ddSJeremy L Thompson @brief Create a composite `CeedOperator` that composes the action of several `CeedOperator` 80852d6035fSJeremy L Thompson 809ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` object used to create the `CeedOperator` 810ca94c3ddSJeremy L Thompson @param[out] op Address of the variable where the newly created composite `CeedOperator` will be stored 81152d6035fSJeremy L Thompson 81252d6035fSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 81352d6035fSJeremy L Thompson 8147a982d89SJeremy L. Thompson @ref User 81552d6035fSJeremy L Thompson */ 81652d6035fSJeremy L Thompson int CeedCompositeOperatorCreate(Ceed ceed, CeedOperator *op) { 81752d6035fSJeremy L Thompson if (!ceed->CompositeOperatorCreate) { 81852d6035fSJeremy L Thompson Ceed delegate; 81952d6035fSJeremy L Thompson 8201c66c397SJeremy L Thompson CeedCall(CeedGetObjectDelegate(ceed, &delegate, "Operator")); 821250756a7Sjeremylt if (delegate) { 8222b730f8bSJeremy L Thompson CeedCall(CeedCompositeOperatorCreate(delegate, op)); 823e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 82452d6035fSJeremy L Thompson } 825250756a7Sjeremylt } 82652d6035fSJeremy L Thompson 8272b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, op)); 828db002c03SJeremy L Thompson CeedCall(CeedReferenceCopy(ceed, &(*op)->ceed)); 829996d9ab5SJed Brown (*op)->ref_count = 1; 830f04ea552SJeremy L Thompson (*op)->is_composite = true; 8312b730f8bSJeremy L Thompson CeedCall(CeedCalloc(CEED_COMPOSITE_MAX, &(*op)->sub_operators)); 8322b104005SJeremy L Thompson (*op)->input_size = -1; 8332b104005SJeremy L Thompson (*op)->output_size = -1; 834250756a7Sjeremylt 835db002c03SJeremy L Thompson if (ceed->CompositeOperatorCreate) CeedCall(ceed->CompositeOperatorCreate(*op)); 836e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 83752d6035fSJeremy L Thompson } 83852d6035fSJeremy L Thompson 83952d6035fSJeremy L Thompson /** 840ca94c3ddSJeremy L Thompson @brief Copy the pointer to a `CeedOperator`. 8414385fb7fSSebastian Grimberg 842ca94c3ddSJeremy L Thompson Both pointers should be destroyed with @ref CeedOperatorDestroy(). 843512bb800SJeremy L Thompson 844ca94c3ddSJeremy 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`. 845ca94c3ddSJeremy L Thompson This `CeedOperator` will be destroyed if `*op_copy` is the only reference to this `CeedOperator`. 8469560d06aSjeremylt 847ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to copy reference to 848ea61e9acSJeremy L Thompson @param[in,out] op_copy Variable to store copied reference 8499560d06aSjeremylt 8509560d06aSjeremylt @return An error code: 0 - success, otherwise - failure 8519560d06aSjeremylt 8529560d06aSjeremylt @ref User 8539560d06aSjeremylt **/ 8549560d06aSjeremylt int CeedOperatorReferenceCopy(CeedOperator op, CeedOperator *op_copy) { 8552b730f8bSJeremy L Thompson CeedCall(CeedOperatorReference(op)); 8562b730f8bSJeremy L Thompson CeedCall(CeedOperatorDestroy(op_copy)); 8579560d06aSjeremylt *op_copy = op; 8589560d06aSjeremylt return CEED_ERROR_SUCCESS; 8599560d06aSjeremylt } 8609560d06aSjeremylt 8619560d06aSjeremylt /** 862ca94c3ddSJeremy L Thompson @brief Provide a field to a `CeedOperator` for use by its `CeedQFunction`. 863d7b241e6Sjeremylt 864ca94c3ddSJeremy L Thompson This function is used to specify both active and passive fields to a `CeedOperator`. 865bafebce1SSebastian Grimberg For passive fields, a `CeedVector` `vec` must be provided. 866ea61e9acSJeremy L Thompson Passive fields can inputs or outputs (updated in-place when operator is applied). 867d7b241e6Sjeremylt 868ca94c3ddSJeremy L Thompson Active fields must be specified using this function, but their data (in a `CeedVector`) is passed in @ref CeedOperatorApply(). 869ca94c3ddSJeremy L Thompson There can be at most one active input `CeedVector` and at most one active output@ref CeedVector passed to @ref CeedOperatorApply(). 870d7b241e6Sjeremylt 871528a22edSJeremy L Thompson The number of quadrature points must agree across all points. 872bafebce1SSebastian Grimberg When using @ref CEED_BASIS_NONE, the number of quadrature points is determined by the element size of `rstr`. 873528a22edSJeremy L Thompson 874ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` on which to provide the field 875ca94c3ddSJeremy L Thompson @param[in] field_name Name of the field (to be matched with the name used by `CeedQFunction`) 876bafebce1SSebastian Grimberg @param[in] rstr `CeedElemRestriction` 877bafebce1SSebastian Grimberg @param[in] basis `CeedBasis` in which the field resides or @ref CEED_BASIS_NONE if collocated with quadrature points 878bafebce1SSebastian Grimberg @param[in] vec `CeedVector` to be used by CeedOperator or @ref CEED_VECTOR_ACTIVE if field is active or @ref CEED_VECTOR_NONE if using @ref CEED_EVAL_WEIGHT in the `CeedQFunction` 879b11c1e72Sjeremylt 880b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 881dfdf5a53Sjeremylt 8827a982d89SJeremy L. Thompson @ref User 883b11c1e72Sjeremylt **/ 884bafebce1SSebastian Grimberg int CeedOperatorSetField(CeedOperator op, const char *field_name, CeedElemRestriction rstr, CeedBasis basis, CeedVector vec) { 885*1203703bSJeremy L Thompson bool is_input = true, is_at_points, is_composite, is_immutable; 886*1203703bSJeremy L Thompson CeedInt num_elem = 0, num_qpts = 0, num_input_fields, num_output_fields; 887*1203703bSJeremy L Thompson Ceed ceed; 888*1203703bSJeremy L Thompson CeedQFunction qf; 889*1203703bSJeremy L Thompson CeedQFunctionField qf_field, *qf_input_fields, *qf_output_fields; 8901c66c397SJeremy L Thompson CeedOperatorField *op_field; 8911c66c397SJeremy L Thompson 892*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 893*1203703bSJeremy L Thompson CeedCall(CeedOperatorIsAtPoints(op, &is_at_points)); 894*1203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 895*1203703bSJeremy L Thompson CeedCall(CeedOperatorIsImmutable(op, &is_immutable)); 896*1203703bSJeremy L Thompson CeedCheck(!is_composite, ceed, CEED_ERROR_INCOMPATIBLE, "Cannot add field to composite operator."); 897*1203703bSJeremy L Thompson CeedCheck(!is_immutable, ceed, CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable"); 898*1203703bSJeremy L Thompson CeedCheck(rstr, ceed, CEED_ERROR_INCOMPATIBLE, "CeedElemRestriction rstr for field \"%s\" must be non-NULL.", field_name); 899*1203703bSJeremy L Thompson CeedCheck(basis, ceed, CEED_ERROR_INCOMPATIBLE, "CeedBasis basis for field \"%s\" must be non-NULL.", field_name); 900*1203703bSJeremy L Thompson CeedCheck(vec, ceed, CEED_ERROR_INCOMPATIBLE, "CeedVector vec for field \"%s\" must be non-NULL.", field_name); 90152d6035fSJeremy L Thompson 902bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionGetNumElements(rstr, &num_elem)); 903*1203703bSJeremy L Thompson CeedCheck(rstr == CEED_ELEMRESTRICTION_NONE || !op->has_restriction || num_elem == op->num_elem, ceed, CEED_ERROR_DIMENSION, 904ca94c3ddSJeremy L Thompson "CeedElemRestriction with %" CeedInt_FMT " elements incompatible with prior %" CeedInt_FMT " elements", num_elem, op->num_elem); 9052c7e7413SJeremy L Thompson { 9062c7e7413SJeremy L Thompson CeedRestrictionType rstr_type; 9072c7e7413SJeremy L Thompson 908bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionGetType(rstr, &rstr_type)); 90948acf710SJeremy L Thompson if (rstr_type == CEED_RESTRICTION_POINTS) { 910*1203703bSJeremy L Thompson CeedCheck(is_at_points, ceed, CEED_ERROR_UNSUPPORTED, "CeedElemRestriction AtPoints not supported for standard operator fields"); 911*1203703bSJeremy L Thompson CeedCheck(basis == CEED_BASIS_NONE, ceed, CEED_ERROR_UNSUPPORTED, "CeedElemRestriction AtPoints must be used with CEED_BASIS_NONE"); 91248acf710SJeremy L Thompson if (!op->first_points_rstr) { 913bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionReferenceCopy(rstr, &op->first_points_rstr)); 91448acf710SJeremy L Thompson } else { 91548acf710SJeremy L Thompson bool are_compatible; 91648acf710SJeremy L Thompson 917bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionAtPointsAreCompatible(op->first_points_rstr, rstr, &are_compatible)); 918*1203703bSJeremy L Thompson CeedCheck(are_compatible, ceed, CEED_ERROR_INCOMPATIBLE, 919ca94c3ddSJeremy L Thompson "CeedElemRestriction must have compatible offsets with previously set CeedElemRestriction"); 92048acf710SJeremy L Thompson } 92148acf710SJeremy L Thompson } 9222c7e7413SJeremy L Thompson } 923d7b241e6Sjeremylt 924bafebce1SSebastian Grimberg if (basis == CEED_BASIS_NONE) CeedCall(CeedElemRestrictionGetElementSize(rstr, &num_qpts)); 925bafebce1SSebastian Grimberg else CeedCall(CeedBasisGetNumQuadraturePoints(basis, &num_qpts)); 926*1203703bSJeremy L Thompson CeedCheck(op->num_qpts == 0 || num_qpts == op->num_qpts, ceed, CEED_ERROR_DIMENSION, 927ca94c3ddSJeremy L Thompson "%s must correspond to the same number of quadrature points as previously added CeedBases. Found %" CeedInt_FMT 928528a22edSJeremy L Thompson " quadrature points but expected %" CeedInt_FMT " quadrature points.", 929bafebce1SSebastian Grimberg basis == CEED_BASIS_NONE ? "CeedElemRestriction" : "CeedBasis", num_qpts, op->num_qpts); 930*1203703bSJeremy L Thompson 931*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 932*1203703bSJeremy L Thompson CeedCall(CeedQFunctionGetFields(qf, &num_input_fields, &qf_input_fields, &num_output_fields, &qf_output_fields)); 933*1203703bSJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 934*1203703bSJeremy L Thompson char *qf_field_name; 935*1203703bSJeremy L Thompson 936*1203703bSJeremy L Thompson CeedCall(CeedQFunctionFieldGetName(qf_input_fields[i], &qf_field_name)); 937*1203703bSJeremy L Thompson if (!strcmp(field_name, qf_field_name)) { 938*1203703bSJeremy L Thompson qf_field = qf_input_fields[i]; 939d1d35e2fSjeremylt op_field = &op->input_fields[i]; 940d7b241e6Sjeremylt goto found; 941d7b241e6Sjeremylt } 942d7b241e6Sjeremylt } 9432b104005SJeremy L Thompson is_input = false; 944*1203703bSJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 945*1203703bSJeremy L Thompson char *qf_field_name; 946*1203703bSJeremy L Thompson 947*1203703bSJeremy L Thompson CeedCall(CeedQFunctionFieldGetName(qf_output_fields[i], &qf_field_name)); 948*1203703bSJeremy L Thompson if (!strcmp(field_name, qf_field_name)) { 949*1203703bSJeremy L Thompson qf_field = qf_output_fields[i]; 950d1d35e2fSjeremylt op_field = &op->output_fields[i]; 951d7b241e6Sjeremylt goto found; 952d7b241e6Sjeremylt } 953d7b241e6Sjeremylt } 954c042f62fSJeremy L Thompson // LCOV_EXCL_START 955*1203703bSJeremy L Thompson return CeedError(ceed, CEED_ERROR_INCOMPLETE, "CeedQFunction has no knowledge of field '%s'", field_name); 956c042f62fSJeremy L Thompson // LCOV_EXCL_STOP 957d7b241e6Sjeremylt found: 958*1203703bSJeremy L Thompson CeedCall(CeedOperatorCheckField(ceed, qf_field, rstr, basis)); 9592b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, op_field)); 960e15f9bd0SJeremy L Thompson 961bafebce1SSebastian Grimberg if (vec == CEED_VECTOR_ACTIVE) { 9622b104005SJeremy L Thompson CeedSize l_size; 9631c66c397SJeremy L Thompson 964bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionGetLVectorSize(rstr, &l_size)); 9652b104005SJeremy L Thompson if (is_input) { 9662b104005SJeremy L Thompson if (op->input_size == -1) op->input_size = l_size; 967*1203703bSJeremy L Thompson CeedCheck(l_size == op->input_size, ceed, CEED_ERROR_INCOMPATIBLE, 968249f8407SJeremy L Thompson "LVector size %" CeedSize_FMT " does not match previous size %" CeedSize_FMT "", l_size, op->input_size); 9692b104005SJeremy L Thompson } else { 9702b104005SJeremy L Thompson if (op->output_size == -1) op->output_size = l_size; 971*1203703bSJeremy L Thompson CeedCheck(l_size == op->output_size, ceed, CEED_ERROR_INCOMPATIBLE, 972249f8407SJeremy L Thompson "LVector size %" CeedSize_FMT " does not match previous size %" CeedSize_FMT "", l_size, op->output_size); 9732b104005SJeremy L Thompson } 9742b730f8bSJeremy L Thompson } 9752b104005SJeremy L Thompson 976bafebce1SSebastian Grimberg CeedCall(CeedVectorReferenceCopy(vec, &(*op_field)->vec)); 977bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionReferenceCopy(rstr, &(*op_field)->elem_rstr)); 978bafebce1SSebastian Grimberg if (rstr != CEED_ELEMRESTRICTION_NONE && !op->has_restriction) { 979d1d35e2fSjeremylt op->num_elem = num_elem; 980d1d35e2fSjeremylt op->has_restriction = true; // Restriction set, but num_elem may be 0 981e15f9bd0SJeremy L Thompson } 982bafebce1SSebastian Grimberg CeedCall(CeedBasisReferenceCopy(basis, &(*op_field)->basis)); 9832a3ff1c9SZach Atkins if (op->num_qpts == 0 && !is_at_points) op->num_qpts = num_qpts; // no consistent number of qpts for OperatorAtPoints 984d1d35e2fSjeremylt op->num_fields += 1; 9852b730f8bSJeremy L Thompson CeedCall(CeedStringAllocCopy(field_name, (char **)&(*op_field)->field_name)); 986e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 987d7b241e6Sjeremylt } 988d7b241e6Sjeremylt 989d7b241e6Sjeremylt /** 990ca94c3ddSJeremy L Thompson @brief Get the `CeedOperator` Field of a `CeedOperator`. 99143bbe138SJeremy L Thompson 992ca94c3ddSJeremy L Thompson Note: Calling this function asserts that setup is complete and sets the `CeedOperator` as immutable. 993f04ea552SJeremy L Thompson 994ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 995f74ec584SJeremy L Thompson @param[out] num_input_fields Variable to store number of input fields 996ca94c3ddSJeremy L Thompson @param[out] input_fields Variable to store input fields 997f74ec584SJeremy L Thompson @param[out] num_output_fields Variable to store number of output fields 998ca94c3ddSJeremy L Thompson @param[out] output_fields Variable to store output fields 99943bbe138SJeremy L Thompson 100043bbe138SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 100143bbe138SJeremy L Thompson 1002e9b533fbSJeremy L Thompson @ref Advanced 100343bbe138SJeremy L Thompson **/ 10042b730f8bSJeremy L Thompson int CeedOperatorGetFields(CeedOperator op, CeedInt *num_input_fields, CeedOperatorField **input_fields, CeedInt *num_output_fields, 100543bbe138SJeremy L Thompson CeedOperatorField **output_fields) { 1006*1203703bSJeremy L Thompson bool is_composite; 1007*1203703bSJeremy L Thompson Ceed ceed; 1008*1203703bSJeremy L Thompson CeedQFunction qf; 1009*1203703bSJeremy L Thompson 1010*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 1011*1203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 1012*1203703bSJeremy L Thompson CeedCheck(!is_composite, ceed, CEED_ERROR_MINOR, "Not defined for composite operator"); 10132b730f8bSJeremy L Thompson CeedCall(CeedOperatorCheckReady(op)); 101443bbe138SJeremy L Thompson 1015*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 1016*1203703bSJeremy L Thompson CeedCall(CeedQFunctionGetFields(qf, num_input_fields, NULL, num_output_fields, NULL)); 101743bbe138SJeremy L Thompson if (input_fields) *input_fields = op->input_fields; 101843bbe138SJeremy L Thompson if (output_fields) *output_fields = op->output_fields; 101943bbe138SJeremy L Thompson return CEED_ERROR_SUCCESS; 102043bbe138SJeremy L Thompson } 102143bbe138SJeremy L Thompson 102243bbe138SJeremy L Thompson /** 1023ca94c3ddSJeremy L Thompson @brief Set the arbitrary points in each element for a `CeedOperator` at points. 102448acf710SJeremy L Thompson 1025ca94c3ddSJeremy L Thompson Note: Calling this function asserts that setup is complete and sets the `CeedOperator` as immutable. 102648acf710SJeremy L Thompson 1027ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` at points 1028ca94c3ddSJeremy L Thompson @param[in] rstr_points `CeedElemRestriction` for the coordinates of each point by element 1029ca94c3ddSJeremy L Thompson @param[in] point_coords `CeedVector` holding coordinates of each point 103048acf710SJeremy L Thompson 103148acf710SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 103248acf710SJeremy L Thompson 103348acf710SJeremy L Thompson @ref Advanced 103448acf710SJeremy L Thompson **/ 103548acf710SJeremy L Thompson int CeedOperatorAtPointsSetPoints(CeedOperator op, CeedElemRestriction rstr_points, CeedVector point_coords) { 1036*1203703bSJeremy L Thompson bool is_at_points, is_immutable; 1037*1203703bSJeremy L Thompson Ceed ceed; 10382a3ff1c9SZach Atkins 1039*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 10402a3ff1c9SZach Atkins CeedCall(CeedOperatorIsAtPoints(op, &is_at_points)); 1041*1203703bSJeremy L Thompson CeedCall(CeedOperatorIsImmutable(op, &is_immutable)); 1042*1203703bSJeremy L Thompson CeedCheck(is_at_points, ceed, CEED_ERROR_MINOR, "Only defined for operator at points"); 1043*1203703bSJeremy L Thompson CeedCheck(!is_immutable, ceed, CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable"); 104448acf710SJeremy L Thompson 104548acf710SJeremy L Thompson if (!op->first_points_rstr) { 104648acf710SJeremy L Thompson CeedCall(CeedElemRestrictionReferenceCopy(rstr_points, &op->first_points_rstr)); 104748acf710SJeremy L Thompson } else { 104848acf710SJeremy L Thompson bool are_compatible; 104948acf710SJeremy L Thompson 105048acf710SJeremy L Thompson CeedCall(CeedElemRestrictionAtPointsAreCompatible(op->first_points_rstr, rstr_points, &are_compatible)); 1051*1203703bSJeremy L Thompson CeedCheck(are_compatible, ceed, CEED_ERROR_INCOMPATIBLE, 1052ca94c3ddSJeremy L Thompson "CeedElemRestriction must have compatible offsets with previously set field CeedElemRestriction"); 105348acf710SJeremy L Thompson } 105448acf710SJeremy L Thompson 105548acf710SJeremy L Thompson CeedCall(CeedElemRestrictionReferenceCopy(rstr_points, &op->rstr_points)); 105648acf710SJeremy L Thompson CeedCall(CeedVectorReferenceCopy(point_coords, &op->point_coords)); 105748acf710SJeremy L Thompson return CEED_ERROR_SUCCESS; 105848acf710SJeremy L Thompson } 105948acf710SJeremy L Thompson 106048acf710SJeremy L Thompson /** 1061b594f9faSZach Atkins @brief Get a boolean value indicating if the `CeedOperator` was created with `CeedOperatorCreateAtPoints` 1062b594f9faSZach Atkins 1063b594f9faSZach Atkins @param[in] op `CeedOperator` 1064b594f9faSZach Atkins @param[out] is_at_points Variable to store at points status 1065b594f9faSZach Atkins 1066b594f9faSZach Atkins @return An error code: 0 - success, otherwise - failure 1067b594f9faSZach Atkins 1068b594f9faSZach Atkins @ref User 1069b594f9faSZach Atkins **/ 1070b594f9faSZach Atkins int CeedOperatorIsAtPoints(CeedOperator op, bool *is_at_points) { 1071b594f9faSZach Atkins *is_at_points = op->is_at_points; 1072b594f9faSZach Atkins return CEED_ERROR_SUCCESS; 1073b594f9faSZach Atkins } 1074b594f9faSZach Atkins 1075b594f9faSZach Atkins /** 1076ca94c3ddSJeremy L Thompson @brief Get the arbitrary points in each element for a `CeedOperator` at points. 107748acf710SJeremy L Thompson 1078ca94c3ddSJeremy L Thompson Note: Calling this function asserts that setup is complete and sets the `CeedOperator` as immutable. 107948acf710SJeremy L Thompson 1080ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` at points 1081ca94c3ddSJeremy L Thompson @param[out] rstr_points Variable to hold `CeedElemRestriction` for the coordinates of each point by element 1082ca94c3ddSJeremy L Thompson @param[out] point_coords Variable to hold `CeedVector` holding coordinates of each point 108348acf710SJeremy L Thompson 108448acf710SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 108548acf710SJeremy L Thompson 108648acf710SJeremy L Thompson @ref Advanced 108748acf710SJeremy L Thompson **/ 108848acf710SJeremy L Thompson int CeedOperatorAtPointsGetPoints(CeedOperator op, CeedElemRestriction *rstr_points, CeedVector *point_coords) { 10892a3ff1c9SZach Atkins bool is_at_points; 1090*1203703bSJeremy L Thompson Ceed ceed; 10912a3ff1c9SZach Atkins 1092*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 10932a3ff1c9SZach Atkins CeedCall(CeedOperatorIsAtPoints(op, &is_at_points)); 1094*1203703bSJeremy L Thompson CeedCheck(is_at_points, ceed, CEED_ERROR_MINOR, "Only defined for operator at points"); 109548acf710SJeremy L Thompson CeedCall(CeedOperatorCheckReady(op)); 109648acf710SJeremy L Thompson 109748acf710SJeremy L Thompson if (rstr_points) CeedCall(CeedElemRestrictionReferenceCopy(op->rstr_points, rstr_points)); 109848acf710SJeremy L Thompson if (point_coords) CeedCall(CeedVectorReferenceCopy(op->point_coords, point_coords)); 109948acf710SJeremy L Thompson return CEED_ERROR_SUCCESS; 110048acf710SJeremy L Thompson } 110148acf710SJeremy L Thompson 110248acf710SJeremy L Thompson /** 1103be9c6463SJeremy L Thompson @brief Get a `CeedOperator` Field of a `CeedOperator` from its name. 1104be9c6463SJeremy L Thompson 1105be9c6463SJeremy L Thompson `op_field` is set to `NULL` if the field is not found. 1106de5900adSJames Wright 1107ca94c3ddSJeremy L Thompson Note: Calling this function asserts that setup is complete and sets the `CeedOperator` as immutable. 1108de5900adSJames Wright 1109ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1110ca94c3ddSJeremy L Thompson @param[in] field_name Name of desired `CeedOperator` Field 1111ca94c3ddSJeremy L Thompson @param[out] op_field `CeedOperator` Field corresponding to the name 1112de5900adSJames Wright 1113de5900adSJames Wright @return An error code: 0 - success, otherwise - failure 1114de5900adSJames Wright 1115de5900adSJames Wright @ref Advanced 1116de5900adSJames Wright **/ 1117de5900adSJames Wright int CeedOperatorGetFieldByName(CeedOperator op, const char *field_name, CeedOperatorField *op_field) { 11181c66c397SJeremy L Thompson char *name; 1119de5900adSJames Wright CeedInt num_input_fields, num_output_fields; 1120de5900adSJames Wright CeedOperatorField *input_fields, *output_fields; 1121de5900adSJames Wright 1122be9c6463SJeremy L Thompson *op_field = NULL; 11231c66c397SJeremy L Thompson CeedCall(CeedOperatorGetFields(op, &num_input_fields, &input_fields, &num_output_fields, &output_fields)); 1124de5900adSJames Wright for (CeedInt i = 0; i < num_input_fields; i++) { 1125de5900adSJames Wright CeedCall(CeedOperatorFieldGetName(input_fields[i], &name)); 1126de5900adSJames Wright if (!strcmp(name, field_name)) { 1127de5900adSJames Wright *op_field = input_fields[i]; 1128de5900adSJames Wright return CEED_ERROR_SUCCESS; 1129de5900adSJames Wright } 1130de5900adSJames Wright } 1131de5900adSJames Wright for (CeedInt i = 0; i < num_output_fields; i++) { 1132de5900adSJames Wright CeedCall(CeedOperatorFieldGetName(output_fields[i], &name)); 1133de5900adSJames Wright if (!strcmp(name, field_name)) { 1134de5900adSJames Wright *op_field = output_fields[i]; 1135de5900adSJames Wright return CEED_ERROR_SUCCESS; 1136de5900adSJames Wright } 1137de5900adSJames Wright } 1138be9c6463SJeremy L Thompson return CEED_ERROR_SUCCESS; 1139de5900adSJames Wright } 1140de5900adSJames Wright 1141de5900adSJames Wright /** 1142ca94c3ddSJeremy L Thompson @brief Get the name of a `CeedOperator` Field 114328567f8fSJeremy L Thompson 1144ca94c3ddSJeremy L Thompson @param[in] op_field `CeedOperator` Field 114528567f8fSJeremy L Thompson @param[out] field_name Variable to store the field name 114628567f8fSJeremy L Thompson 114728567f8fSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 114828567f8fSJeremy L Thompson 1149e9b533fbSJeremy L Thompson @ref Advanced 115028567f8fSJeremy L Thompson **/ 115128567f8fSJeremy L Thompson int CeedOperatorFieldGetName(CeedOperatorField op_field, char **field_name) { 115228567f8fSJeremy L Thompson *field_name = (char *)op_field->field_name; 115328567f8fSJeremy L Thompson return CEED_ERROR_SUCCESS; 115428567f8fSJeremy L Thompson } 115528567f8fSJeremy L Thompson 115628567f8fSJeremy L Thompson /** 1157ca94c3ddSJeremy L Thompson @brief Get the `CeedElemRestriction` of a `CeedOperator` Field 115843bbe138SJeremy L Thompson 1159ca94c3ddSJeremy L Thompson @param[in] op_field `CeedOperator` Field 1160ca94c3ddSJeremy L Thompson @param[out] rstr Variable to store `CeedElemRestriction` 116143bbe138SJeremy L Thompson 116243bbe138SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 116343bbe138SJeremy L Thompson 1164e9b533fbSJeremy L Thompson @ref Advanced 116543bbe138SJeremy L Thompson **/ 11662b730f8bSJeremy L Thompson int CeedOperatorFieldGetElemRestriction(CeedOperatorField op_field, CeedElemRestriction *rstr) { 1167437c7c90SJeremy L Thompson *rstr = op_field->elem_rstr; 116843bbe138SJeremy L Thompson return CEED_ERROR_SUCCESS; 116943bbe138SJeremy L Thompson } 117043bbe138SJeremy L Thompson 117143bbe138SJeremy L Thompson /** 1172ca94c3ddSJeremy L Thompson @brief Get the `CeedBasis` of a `CeedOperator` Field 117343bbe138SJeremy L Thompson 1174ca94c3ddSJeremy L Thompson @param[in] op_field `CeedOperator` Field 1175ca94c3ddSJeremy L Thompson @param[out] basis Variable to store `CeedBasis` 117643bbe138SJeremy L Thompson 117743bbe138SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 117843bbe138SJeremy L Thompson 1179e9b533fbSJeremy L Thompson @ref Advanced 118043bbe138SJeremy L Thompson **/ 118143bbe138SJeremy L Thompson int CeedOperatorFieldGetBasis(CeedOperatorField op_field, CeedBasis *basis) { 118243bbe138SJeremy L Thompson *basis = op_field->basis; 118343bbe138SJeremy L Thompson return CEED_ERROR_SUCCESS; 118443bbe138SJeremy L Thompson } 118543bbe138SJeremy L Thompson 118643bbe138SJeremy L Thompson /** 1187ca94c3ddSJeremy L Thompson @brief Get the `CeedVector` of a `CeedOperator` Field 118843bbe138SJeremy L Thompson 1189ca94c3ddSJeremy L Thompson @param[in] op_field `CeedOperator` Field 1190ca94c3ddSJeremy L Thompson @param[out] vec Variable to store `CeedVector` 119143bbe138SJeremy L Thompson 119243bbe138SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 119343bbe138SJeremy L Thompson 1194e9b533fbSJeremy L Thompson @ref Advanced 119543bbe138SJeremy L Thompson **/ 119643bbe138SJeremy L Thompson int CeedOperatorFieldGetVector(CeedOperatorField op_field, CeedVector *vec) { 119743bbe138SJeremy L Thompson *vec = op_field->vec; 119843bbe138SJeremy L Thompson return CEED_ERROR_SUCCESS; 119943bbe138SJeremy L Thompson } 120043bbe138SJeremy L Thompson 120143bbe138SJeremy L Thompson /** 1202ca94c3ddSJeremy L Thompson @brief Add a sub-operator to a composite `CeedOperator` 1203288c0443SJeremy L Thompson 1204ca94c3ddSJeremy L Thompson @param[in,out] composite_op Composite `CeedOperator` 1205ca94c3ddSJeremy L Thompson @param[in] sub_op Sub-operator `CeedOperator` 120652d6035fSJeremy L Thompson 120752d6035fSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 120852d6035fSJeremy L Thompson 12097a982d89SJeremy L. Thompson @ref User 121052d6035fSJeremy L Thompson */ 12112b730f8bSJeremy L Thompson int CeedCompositeOperatorAddSub(CeedOperator composite_op, CeedOperator sub_op) { 1212*1203703bSJeremy L Thompson bool is_immutable; 1213*1203703bSJeremy L Thompson Ceed ceed; 1214*1203703bSJeremy L Thompson 1215*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(composite_op, &ceed)); 1216*1203703bSJeremy L Thompson CeedCheck(composite_op->is_composite, ceed, CEED_ERROR_MINOR, "CeedOperator is not a composite operator"); 1217*1203703bSJeremy L Thompson CeedCheck(composite_op->num_suboperators < CEED_COMPOSITE_MAX, ceed, CEED_ERROR_UNSUPPORTED, "Cannot add additional sub-operators"); 1218*1203703bSJeremy L Thompson CeedCall(CeedOperatorIsImmutable(composite_op, &is_immutable)); 1219*1203703bSJeremy L Thompson CeedCheck(!is_immutable, ceed, CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable"); 12202b730f8bSJeremy L Thompson 12212b730f8bSJeremy L Thompson { 12222b730f8bSJeremy L Thompson CeedSize input_size, output_size; 12231c66c397SJeremy L Thompson 12242b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetActiveVectorLengths(sub_op, &input_size, &output_size)); 12252b730f8bSJeremy L Thompson if (composite_op->input_size == -1) composite_op->input_size = input_size; 12262b730f8bSJeremy L Thompson if (composite_op->output_size == -1) composite_op->output_size = output_size; 12272b730f8bSJeremy L Thompson // Note, a size of -1 means no active vector restriction set, so no incompatibility 1228*1203703bSJeremy L Thompson CeedCheck((input_size == -1 || input_size == composite_op->input_size) && (output_size == -1 || output_size == composite_op->output_size), ceed, 1229*1203703bSJeremy L Thompson CEED_ERROR_MAJOR, 1230249f8407SJeremy L Thompson "Sub-operators must have compatible dimensions; composite operator of shape (%" CeedSize_FMT ", %" CeedSize_FMT 1231249f8407SJeremy L Thompson ") not compatible with sub-operator of " 1232249f8407SJeremy L Thompson "shape (%" CeedSize_FMT ", %" CeedSize_FMT ")", 12332b730f8bSJeremy L Thompson composite_op->input_size, composite_op->output_size, input_size, output_size); 12342b730f8bSJeremy L Thompson } 12352b730f8bSJeremy L Thompson 1236d1d35e2fSjeremylt composite_op->sub_operators[composite_op->num_suboperators] = sub_op; 12372b730f8bSJeremy L Thompson CeedCall(CeedOperatorReference(sub_op)); 1238d1d35e2fSjeremylt composite_op->num_suboperators++; 1239e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 124052d6035fSJeremy L Thompson } 124152d6035fSJeremy L Thompson 124252d6035fSJeremy L Thompson /** 1243ca94c3ddSJeremy L Thompson @brief Get the number of sub-operators associated with a `CeedOperator` 124475f0d5a4SJeremy L Thompson 1245ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1246ca94c3ddSJeremy L Thompson @param[out] num_suboperators Variable to store number of sub-operators 124775f0d5a4SJeremy L Thompson 124875f0d5a4SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 124975f0d5a4SJeremy L Thompson 125075f0d5a4SJeremy L Thompson @ref Backend 125175f0d5a4SJeremy L Thompson **/ 1252c6ebc35dSJeremy L Thompson int CeedCompositeOperatorGetNumSub(CeedOperator op, CeedInt *num_suboperators) { 1253*1203703bSJeremy L Thompson bool is_composite; 1254*1203703bSJeremy L Thompson Ceed ceed; 1255*1203703bSJeremy L Thompson 1256*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 1257*1203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 1258*1203703bSJeremy L Thompson CeedCheck(is_composite, ceed, CEED_ERROR_MINOR, "Only defined for a composite operator"); 125975f0d5a4SJeremy L Thompson *num_suboperators = op->num_suboperators; 126075f0d5a4SJeremy L Thompson return CEED_ERROR_SUCCESS; 126175f0d5a4SJeremy L Thompson } 126275f0d5a4SJeremy L Thompson 126375f0d5a4SJeremy L Thompson /** 1264ca94c3ddSJeremy L Thompson @brief Get the list of sub-operators associated with a `CeedOperator` 126575f0d5a4SJeremy L Thompson 1266ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1267ca94c3ddSJeremy L Thompson @param[out] sub_operators Variable to store list of sub-operators 126875f0d5a4SJeremy L Thompson 126975f0d5a4SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 127075f0d5a4SJeremy L Thompson 127175f0d5a4SJeremy L Thompson @ref Backend 127275f0d5a4SJeremy L Thompson **/ 1273c6ebc35dSJeremy L Thompson int CeedCompositeOperatorGetSubList(CeedOperator op, CeedOperator **sub_operators) { 1274*1203703bSJeremy L Thompson bool is_composite; 1275*1203703bSJeremy L Thompson Ceed ceed; 1276*1203703bSJeremy L Thompson 1277*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 1278*1203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 1279*1203703bSJeremy L Thompson CeedCheck(is_composite, ceed, CEED_ERROR_MINOR, "Only defined for a composite operator"); 128075f0d5a4SJeremy L Thompson *sub_operators = op->sub_operators; 128175f0d5a4SJeremy L Thompson return CEED_ERROR_SUCCESS; 128275f0d5a4SJeremy L Thompson } 128375f0d5a4SJeremy L Thompson 128475f0d5a4SJeremy L Thompson /** 1285ca94c3ddSJeremy L Thompson @brief Check if a `CeedOperator` is ready to be used. 12864db537f9SJeremy L Thompson 1287ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to check 12884db537f9SJeremy L Thompson 12894db537f9SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 12904db537f9SJeremy L Thompson 12914db537f9SJeremy L Thompson @ref User 12924db537f9SJeremy L Thompson **/ 12934db537f9SJeremy L Thompson int CeedOperatorCheckReady(CeedOperator op) { 1294*1203703bSJeremy L Thompson bool is_at_points, is_composite; 12954db537f9SJeremy L Thompson Ceed ceed; 1296*1203703bSJeremy L Thompson CeedQFunction qf = NULL; 12974db537f9SJeremy L Thompson 12982b730f8bSJeremy L Thompson if (op->is_interface_setup) return CEED_ERROR_SUCCESS; 12994db537f9SJeremy L Thompson 1300*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 1301*1203703bSJeremy L Thompson CeedCall(CeedOperatorIsAtPoints(op, &is_at_points)); 1302*1203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 1303*1203703bSJeremy L Thompson if (!is_composite) CeedCall(CeedOperatorGetQFunction(op, &qf)); 1304*1203703bSJeremy L Thompson if (is_composite) { 1305*1203703bSJeremy L Thompson CeedInt num_suboperators; 1306*1203703bSJeremy L Thompson 1307*1203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 1308*1203703bSJeremy L Thompson if (!num_suboperators) { 130943622462SJeremy L Thompson // Empty operator setup 131043622462SJeremy L Thompson op->input_size = 0; 131143622462SJeremy L Thompson op->output_size = 0; 131243622462SJeremy L Thompson } else { 1313*1203703bSJeremy L Thompson CeedOperator *sub_operators; 1314*1203703bSJeremy L Thompson 1315*1203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 1316*1203703bSJeremy L Thompson for (CeedInt i = 0; i < num_suboperators; i++) { 1317*1203703bSJeremy L Thompson CeedCall(CeedOperatorCheckReady(sub_operators[i])); 13184db537f9SJeremy L Thompson } 13192b104005SJeremy L Thompson // Sub-operators could be modified after adding to composite operator 13202b104005SJeremy L Thompson // Need to verify no lvec incompatibility from any changes 13212b104005SJeremy L Thompson CeedSize input_size, output_size; 13222b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetActiveVectorLengths(op, &input_size, &output_size)); 132343622462SJeremy L Thompson } 13244db537f9SJeremy L Thompson } else { 1325*1203703bSJeremy L Thompson CeedInt num_input_fields, num_output_fields; 1326*1203703bSJeremy L Thompson 13276574a04fSJeremy L Thompson CeedCheck(op->num_fields > 0, ceed, CEED_ERROR_INCOMPLETE, "No operator fields set"); 1328*1203703bSJeremy L Thompson CeedCall(CeedQFunctionGetFields(qf, &num_input_fields, NULL, &num_output_fields, NULL)); 1329*1203703bSJeremy L Thompson CeedCheck(op->num_fields == num_input_fields + num_output_fields, ceed, CEED_ERROR_INCOMPLETE, "Not all operator fields set"); 13306574a04fSJeremy L Thompson CeedCheck(op->has_restriction, ceed, CEED_ERROR_INCOMPLETE, "At least one restriction required"); 13312a3ff1c9SZach Atkins CeedCheck(op->num_qpts > 0 || is_at_points, ceed, CEED_ERROR_INCOMPLETE, 1332ca94c3ddSJeremy L Thompson "At least one non-collocated CeedBasis is required or the number of quadrature points must be set"); 13332b730f8bSJeremy L Thompson } 13344db537f9SJeremy L Thompson 13354db537f9SJeremy L Thompson // Flag as immutable and ready 13364db537f9SJeremy L Thompson op->is_interface_setup = true; 1337*1203703bSJeremy L Thompson if (qf && qf != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionSetImmutable(qf)); 1338*1203703bSJeremy L Thompson if (op->dqf && op->dqf != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionSetImmutable(op->dqf)); 1339*1203703bSJeremy L Thompson if (op->dqfT && op->dqfT != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionSetImmutable(op->dqfT)); 13404db537f9SJeremy L Thompson return CEED_ERROR_SUCCESS; 13414db537f9SJeremy L Thompson } 13424db537f9SJeremy L Thompson 13434db537f9SJeremy L Thompson /** 1344ca94c3ddSJeremy L Thompson @brief Get vector lengths for the active input and/or output `CeedVector` of a `CeedOperator`. 13454385fb7fSSebastian Grimberg 1346ca94c3ddSJeremy L Thompson Note: Lengths of `-1` indicate that the CeedOperator does not have an active input and/or output. 1347c9366a6bSJeremy L Thompson 1348ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1349ca94c3ddSJeremy L Thompson @param[out] input_size Variable to store active input vector length, or `NULL` 1350ca94c3ddSJeremy L Thompson @param[out] output_size Variable to store active output vector length, or `NULL` 1351c9366a6bSJeremy L Thompson 1352c9366a6bSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1353c9366a6bSJeremy L Thompson 1354c9366a6bSJeremy L Thompson @ref User 1355c9366a6bSJeremy L Thompson **/ 13562b730f8bSJeremy L Thompson int CeedOperatorGetActiveVectorLengths(CeedOperator op, CeedSize *input_size, CeedSize *output_size) { 1357c9366a6bSJeremy L Thompson bool is_composite; 1358c9366a6bSJeremy L Thompson 13592b104005SJeremy L Thompson if (input_size) *input_size = op->input_size; 13602b104005SJeremy L Thompson if (output_size) *output_size = op->output_size; 1361c9366a6bSJeremy L Thompson 13622b730f8bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 13632b104005SJeremy L Thompson if (is_composite && (op->input_size == -1 || op->output_size == -1)) { 1364*1203703bSJeremy L Thompson CeedInt num_suboperators; 1365*1203703bSJeremy L Thompson CeedOperator *sub_operators; 1366*1203703bSJeremy L Thompson 1367*1203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 1368*1203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 1369*1203703bSJeremy L Thompson for (CeedInt i = 0; i < num_suboperators; i++) { 1370c9366a6bSJeremy L Thompson CeedSize sub_input_size, sub_output_size; 13711c66c397SJeremy L Thompson 1372*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetActiveVectorLengths(sub_operators[i], &sub_input_size, &sub_output_size)); 13732b104005SJeremy L Thompson if (op->input_size == -1) op->input_size = sub_input_size; 13742b104005SJeremy L Thompson if (op->output_size == -1) op->output_size = sub_output_size; 13752b104005SJeremy L Thompson // Note, a size of -1 means no active vector restriction set, so no incompatibility 13766574a04fSJeremy L Thompson CeedCheck((sub_input_size == -1 || sub_input_size == op->input_size) && (sub_output_size == -1 || sub_output_size == op->output_size), op->ceed, 13776574a04fSJeremy L Thompson CEED_ERROR_MAJOR, 1378249f8407SJeremy L Thompson "Sub-operators must have compatible dimensions; composite operator of shape (%" CeedSize_FMT ", %" CeedSize_FMT 1379249f8407SJeremy L Thompson ") not compatible with sub-operator of " 1380249f8407SJeremy L Thompson "shape (%" CeedSize_FMT ", %" CeedSize_FMT ")", 13812b104005SJeremy L Thompson op->input_size, op->output_size, input_size, output_size); 1382c9366a6bSJeremy L Thompson } 13832b730f8bSJeremy L Thompson } 1384c9366a6bSJeremy L Thompson return CEED_ERROR_SUCCESS; 1385c9366a6bSJeremy L Thompson } 1386c9366a6bSJeremy L Thompson 1387c9366a6bSJeremy L Thompson /** 1388ca94c3ddSJeremy L Thompson @brief Set reuse of `CeedQFunction` data in `CeedOperatorLinearAssemble*()` functions. 13894385fb7fSSebastian Grimberg 1390ca94c3ddSJeremy L Thompson When `reuse_assembly_data = false` (default), the `CeedQFunction` associated with this `CeedOperator` is re-assembled every time a `CeedOperatorLinearAssemble*()` function is called. 1391ca94c3ddSJeremy L Thompson When `reuse_assembly_data = true`, the `CeedQFunction` associated with this `CeedOperator` is reused between calls to @ref CeedOperatorSetQFunctionAssemblyDataUpdateNeeded(). 13928b919e6bSJeremy L Thompson 1393ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1394beecbf24SJeremy L Thompson @param[in] reuse_assembly_data Boolean flag setting assembly data reuse 13958b919e6bSJeremy L Thompson 13968b919e6bSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 13978b919e6bSJeremy L Thompson 13988b919e6bSJeremy L Thompson @ref Advanced 13998b919e6bSJeremy L Thompson **/ 14002b730f8bSJeremy L Thompson int CeedOperatorSetQFunctionAssemblyReuse(CeedOperator op, bool reuse_assembly_data) { 14018b919e6bSJeremy L Thompson bool is_composite; 14028b919e6bSJeremy L Thompson 14032b730f8bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 14048b919e6bSJeremy L Thompson if (is_composite) { 14058b919e6bSJeremy L Thompson for (CeedInt i = 0; i < op->num_suboperators; i++) { 14062b730f8bSJeremy L Thompson CeedCall(CeedOperatorSetQFunctionAssemblyReuse(op->sub_operators[i], reuse_assembly_data)); 14078b919e6bSJeremy L Thompson } 14088b919e6bSJeremy L Thompson } else { 14092b730f8bSJeremy L Thompson CeedCall(CeedQFunctionAssemblyDataSetReuse(op->qf_assembled, reuse_assembly_data)); 1410beecbf24SJeremy L Thompson } 1411beecbf24SJeremy L Thompson return CEED_ERROR_SUCCESS; 1412beecbf24SJeremy L Thompson } 1413beecbf24SJeremy L Thompson 1414beecbf24SJeremy L Thompson /** 1415ca94c3ddSJeremy L Thompson @brief Mark `CeedQFunction` data as updated and the `CeedQFunction` as requiring re-assembly. 1416beecbf24SJeremy L Thompson 1417ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 14186e15d496SJeremy L Thompson @param[in] needs_data_update Boolean flag setting assembly data reuse 1419beecbf24SJeremy L Thompson 1420beecbf24SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1421beecbf24SJeremy L Thompson 1422beecbf24SJeremy L Thompson @ref Advanced 1423beecbf24SJeremy L Thompson **/ 14242b730f8bSJeremy L Thompson int CeedOperatorSetQFunctionAssemblyDataUpdateNeeded(CeedOperator op, bool needs_data_update) { 1425beecbf24SJeremy L Thompson bool is_composite; 1426beecbf24SJeremy L Thompson 14272b730f8bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 1428beecbf24SJeremy L Thompson if (is_composite) { 1429*1203703bSJeremy L Thompson CeedInt num_suboperators; 1430*1203703bSJeremy L Thompson CeedOperator *sub_operators; 1431*1203703bSJeremy L Thompson 1432*1203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 1433*1203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 1434*1203703bSJeremy L Thompson for (CeedInt i = 0; i < num_suboperators; i++) { 1435*1203703bSJeremy L Thompson CeedCall(CeedOperatorSetQFunctionAssemblyDataUpdateNeeded(sub_operators[i], needs_data_update)); 1436beecbf24SJeremy L Thompson } 1437beecbf24SJeremy L Thompson } else { 14382b730f8bSJeremy L Thompson CeedCall(CeedQFunctionAssemblyDataSetUpdateNeeded(op->qf_assembled, needs_data_update)); 14398b919e6bSJeremy L Thompson } 14408b919e6bSJeremy L Thompson return CEED_ERROR_SUCCESS; 14418b919e6bSJeremy L Thompson } 14428b919e6bSJeremy L Thompson 14438b919e6bSJeremy L Thompson /** 1444ca94c3ddSJeremy L Thompson @brief Set name of `CeedOperator` for @ref CeedOperatorView() output 1445ea6b5821SJeremy L Thompson 1446ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 1447ea61e9acSJeremy L Thompson @param[in] name Name to set, or NULL to remove previously set name 1448ea6b5821SJeremy L Thompson 1449ea6b5821SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1450ea6b5821SJeremy L Thompson 1451ea6b5821SJeremy L Thompson @ref User 1452ea6b5821SJeremy L Thompson **/ 1453ea6b5821SJeremy L Thompson int CeedOperatorSetName(CeedOperator op, const char *name) { 1454ea6b5821SJeremy L Thompson char *name_copy; 1455ea6b5821SJeremy L Thompson size_t name_len = name ? strlen(name) : 0; 1456ea6b5821SJeremy L Thompson 14572b730f8bSJeremy L Thompson CeedCall(CeedFree(&op->name)); 1458ea6b5821SJeremy L Thompson if (name_len > 0) { 14592b730f8bSJeremy L Thompson CeedCall(CeedCalloc(name_len + 1, &name_copy)); 1460ea6b5821SJeremy L Thompson memcpy(name_copy, name, name_len); 1461ea6b5821SJeremy L Thompson op->name = name_copy; 1462ea6b5821SJeremy L Thompson } 1463ea6b5821SJeremy L Thompson return CEED_ERROR_SUCCESS; 1464ea6b5821SJeremy L Thompson } 1465ea6b5821SJeremy L Thompson 1466ea6b5821SJeremy L Thompson /** 1467ca94c3ddSJeremy L Thompson @brief View a `CeedOperator` 14687a982d89SJeremy L. Thompson 1469ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to view 1470ca94c3ddSJeremy L Thompson @param[in] stream Stream to write; typically `stdout` or a file 14717a982d89SJeremy L. Thompson 14727a982d89SJeremy L. Thompson @return Error code: 0 - success, otherwise - failure 14737a982d89SJeremy L. Thompson 14747a982d89SJeremy L. Thompson @ref User 14757a982d89SJeremy L. Thompson **/ 14767a982d89SJeremy L. Thompson int CeedOperatorView(CeedOperator op, FILE *stream) { 1477*1203703bSJeremy L Thompson bool has_name = op->name, is_composite; 14787a982d89SJeremy L. Thompson 1479*1203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 1480*1203703bSJeremy L Thompson if (is_composite) { 1481*1203703bSJeremy L Thompson CeedInt num_suboperators; 1482*1203703bSJeremy L Thompson CeedOperator *sub_operators; 1483*1203703bSJeremy L Thompson 1484*1203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 1485*1203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 14862b730f8bSJeremy L Thompson fprintf(stream, "Composite CeedOperator%s%s\n", has_name ? " - " : "", has_name ? op->name : ""); 14877a982d89SJeremy L. Thompson 1488*1203703bSJeremy L Thompson for (CeedInt i = 0; i < num_suboperators; i++) { 1489*1203703bSJeremy L Thompson has_name = sub_operators[i]->name; 1490*1203703bSJeremy L Thompson fprintf(stream, " SubOperator %" CeedInt_FMT "%s%s:\n", i, has_name ? " - " : "", has_name ? sub_operators[i]->name : ""); 1491*1203703bSJeremy L Thompson CeedCall(CeedOperatorSingleView(sub_operators[i], 1, stream)); 14927a982d89SJeremy L. Thompson } 14937a982d89SJeremy L. Thompson } else { 14942b730f8bSJeremy L Thompson fprintf(stream, "CeedOperator%s%s\n", has_name ? " - " : "", has_name ? op->name : ""); 14952b730f8bSJeremy L Thompson CeedCall(CeedOperatorSingleView(op, 0, stream)); 14967a982d89SJeremy L. Thompson } 1497e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 14987a982d89SJeremy L. Thompson } 14993bd813ffSjeremylt 15003bd813ffSjeremylt /** 1501ca94c3ddSJeremy L Thompson @brief Get the `Ceed` associated with a `CeedOperator` 1502b7c9bbdaSJeremy L Thompson 1503ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1504ca94c3ddSJeremy L Thompson @param[out] ceed Variable to store `Ceed` 1505b7c9bbdaSJeremy L Thompson 1506b7c9bbdaSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1507b7c9bbdaSJeremy L Thompson 1508b7c9bbdaSJeremy L Thompson @ref Advanced 1509b7c9bbdaSJeremy L Thompson **/ 1510b7c9bbdaSJeremy L Thompson int CeedOperatorGetCeed(CeedOperator op, Ceed *ceed) { 1511b7c9bbdaSJeremy L Thompson *ceed = op->ceed; 1512b7c9bbdaSJeremy L Thompson return CEED_ERROR_SUCCESS; 1513b7c9bbdaSJeremy L Thompson } 1514b7c9bbdaSJeremy L Thompson 1515b7c9bbdaSJeremy L Thompson /** 1516ca94c3ddSJeremy L Thompson @brief Get the number of elements associated with a `CeedOperator` 1517b7c9bbdaSJeremy L Thompson 1518ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1519b7c9bbdaSJeremy L Thompson @param[out] num_elem Variable to store number of elements 1520b7c9bbdaSJeremy L Thompson 1521b7c9bbdaSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1522b7c9bbdaSJeremy L Thompson 1523b7c9bbdaSJeremy L Thompson @ref Advanced 1524b7c9bbdaSJeremy L Thompson **/ 1525b7c9bbdaSJeremy L Thompson int CeedOperatorGetNumElements(CeedOperator op, CeedInt *num_elem) { 1526*1203703bSJeremy L Thompson bool is_composite; 1527*1203703bSJeremy L Thompson Ceed ceed; 1528*1203703bSJeremy L Thompson 1529*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 1530*1203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 1531*1203703bSJeremy L Thompson CeedCheck(!is_composite, ceed, CEED_ERROR_MINOR, "Not defined for composite operator"); 1532b7c9bbdaSJeremy L Thompson *num_elem = op->num_elem; 1533b7c9bbdaSJeremy L Thompson return CEED_ERROR_SUCCESS; 1534b7c9bbdaSJeremy L Thompson } 1535b7c9bbdaSJeremy L Thompson 1536b7c9bbdaSJeremy L Thompson /** 1537ca94c3ddSJeremy L Thompson @brief Get the number of quadrature points associated with a `CeedOperator` 1538b7c9bbdaSJeremy L Thompson 1539ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1540b7c9bbdaSJeremy L Thompson @param[out] num_qpts Variable to store vector number of quadrature points 1541b7c9bbdaSJeremy L Thompson 1542b7c9bbdaSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1543b7c9bbdaSJeremy L Thompson 1544b7c9bbdaSJeremy L Thompson @ref Advanced 1545b7c9bbdaSJeremy L Thompson **/ 1546b7c9bbdaSJeremy L Thompson int CeedOperatorGetNumQuadraturePoints(CeedOperator op, CeedInt *num_qpts) { 1547*1203703bSJeremy L Thompson bool is_composite; 1548*1203703bSJeremy L Thompson Ceed ceed; 1549*1203703bSJeremy L Thompson 1550*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 1551*1203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 1552*1203703bSJeremy L Thompson CeedCheck(!is_composite, ceed, CEED_ERROR_MINOR, "Not defined for composite operator"); 1553b7c9bbdaSJeremy L Thompson *num_qpts = op->num_qpts; 1554b7c9bbdaSJeremy L Thompson return CEED_ERROR_SUCCESS; 1555b7c9bbdaSJeremy L Thompson } 1556b7c9bbdaSJeremy L Thompson 1557b7c9bbdaSJeremy L Thompson /** 1558ca94c3ddSJeremy L Thompson @brief Estimate number of FLOPs required to apply `CeedOperator` on the active `CeedVector` 15596e15d496SJeremy L Thompson 1560ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to estimate FLOPs for 1561ea61e9acSJeremy L Thompson @param[out] flops Address of variable to hold FLOPs estimate 15626e15d496SJeremy L Thompson 15636e15d496SJeremy L Thompson @ref Backend 15646e15d496SJeremy L Thompson **/ 15659d36ca50SJeremy L Thompson int CeedOperatorGetFlopsEstimate(CeedOperator op, CeedSize *flops) { 15666e15d496SJeremy L Thompson bool is_composite; 15671c66c397SJeremy L Thompson 15682b730f8bSJeremy L Thompson CeedCall(CeedOperatorCheckReady(op)); 15696e15d496SJeremy L Thompson 15706e15d496SJeremy L Thompson *flops = 0; 15712b730f8bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 15726e15d496SJeremy L Thompson if (is_composite) { 15736e15d496SJeremy L Thompson CeedInt num_suboperators; 15741c66c397SJeremy L Thompson 1575c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 15766e15d496SJeremy L Thompson CeedOperator *sub_operators; 1577c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 15786e15d496SJeremy L Thompson 15796e15d496SJeremy L Thompson // FLOPs for each suboperator 15806e15d496SJeremy L Thompson for (CeedInt i = 0; i < num_suboperators; i++) { 15819d36ca50SJeremy L Thompson CeedSize suboperator_flops; 15821c66c397SJeremy L Thompson 15832b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetFlopsEstimate(sub_operators[i], &suboperator_flops)); 15846e15d496SJeremy L Thompson *flops += suboperator_flops; 15856e15d496SJeremy L Thompson } 15866e15d496SJeremy L Thompson } else { 15871c66c397SJeremy L Thompson CeedInt num_input_fields, num_output_fields, num_elem = 0; 1588*1203703bSJeremy L Thompson CeedQFunction qf; 1589*1203703bSJeremy L Thompson CeedQFunctionField *qf_input_fields, *qf_output_fields; 1590*1203703bSJeremy L Thompson CeedOperatorField *op_input_fields, *op_output_fields; 15911c66c397SJeremy L Thompson 1592*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 1593*1203703bSJeremy L Thompson CeedCall(CeedQFunctionGetFields(qf, &num_input_fields, &qf_input_fields, &num_output_fields, &qf_output_fields)); 1594*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetFields(op, NULL, &op_input_fields, NULL, &op_output_fields)); 15952b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetNumElements(op, &num_elem)); 15964385fb7fSSebastian Grimberg 15976e15d496SJeremy L Thompson // Input FLOPs 15986e15d496SJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 1599*1203703bSJeremy L Thompson CeedVector vec; 16006e15d496SJeremy L Thompson 1601*1203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(op_input_fields[i], &vec)); 1602*1203703bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 1603*1203703bSJeremy L Thompson CeedEvalMode eval_mode; 1604*1203703bSJeremy L Thompson CeedSize rstr_flops, basis_flops; 1605*1203703bSJeremy L Thompson CeedElemRestriction rstr; 1606*1203703bSJeremy L Thompson CeedBasis basis; 1607*1203703bSJeremy L Thompson 1608*1203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetElemRestriction(op_input_fields[i], &rstr)); 1609*1203703bSJeremy L Thompson CeedCall(CeedElemRestrictionGetFlopsEstimate(rstr, CEED_NOTRANSPOSE, &rstr_flops)); 1610edb2538eSJeremy L Thompson *flops += rstr_flops; 1611*1203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetBasis(op_input_fields[i], &basis)); 1612*1203703bSJeremy L Thompson CeedCall(CeedQFunctionFieldGetEvalMode(qf_input_fields[i], &eval_mode)); 1613*1203703bSJeremy L Thompson CeedCall(CeedBasisGetFlopsEstimate(basis, CEED_NOTRANSPOSE, eval_mode, &basis_flops)); 16146e15d496SJeremy L Thompson *flops += basis_flops * num_elem; 16156e15d496SJeremy L Thompson } 16166e15d496SJeremy L Thompson } 16176e15d496SJeremy L Thompson // QF FLOPs 16181c66c397SJeremy L Thompson { 16199d36ca50SJeremy L Thompson CeedInt num_qpts; 16209d36ca50SJeremy L Thompson CeedSize qf_flops; 1621*1203703bSJeremy L Thompson Ceed ceed; 1622*1203703bSJeremy L Thompson CeedQFunction qf; 16231c66c397SJeremy L Thompson 16242b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetNumQuadraturePoints(op, &num_qpts)); 1625*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 1626*1203703bSJeremy L Thompson CeedCall(CeedQFunctionGetFlopsEstimate(qf, &qf_flops)); 1627*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 1628*1203703bSJeremy L Thompson CeedCheck(qf_flops > -1, ceed, CEED_ERROR_INCOMPLETE, "Must set CeedQFunction FLOPs estimate with CeedQFunctionSetUserFlopsEstimate"); 16296e15d496SJeremy L Thompson *flops += num_elem * num_qpts * qf_flops; 16301c66c397SJeremy L Thompson } 16311c66c397SJeremy L Thompson 16326e15d496SJeremy L Thompson // Output FLOPs 16336e15d496SJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 1634*1203703bSJeremy L Thompson CeedVector vec; 16356e15d496SJeremy L Thompson 1636*1203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(op_output_fields[i], &vec)); 1637*1203703bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 1638*1203703bSJeremy L Thompson CeedEvalMode eval_mode; 1639*1203703bSJeremy L Thompson CeedSize rstr_flops, basis_flops; 1640*1203703bSJeremy L Thompson CeedElemRestriction rstr; 1641*1203703bSJeremy L Thompson CeedBasis basis; 1642*1203703bSJeremy L Thompson 1643*1203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetElemRestriction(op_output_fields[i], &rstr)); 1644*1203703bSJeremy L Thompson CeedCall(CeedElemRestrictionGetFlopsEstimate(rstr, CEED_TRANSPOSE, &rstr_flops)); 1645edb2538eSJeremy L Thompson *flops += rstr_flops; 1646*1203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetBasis(op_output_fields[i], &basis)); 1647*1203703bSJeremy L Thompson CeedCall(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode)); 1648*1203703bSJeremy L Thompson CeedCall(CeedBasisGetFlopsEstimate(basis, CEED_TRANSPOSE, eval_mode, &basis_flops)); 16496e15d496SJeremy L Thompson *flops += basis_flops * num_elem; 16506e15d496SJeremy L Thompson } 16516e15d496SJeremy L Thompson } 16526e15d496SJeremy L Thompson } 16536e15d496SJeremy L Thompson return CEED_ERROR_SUCCESS; 16546e15d496SJeremy L Thompson } 16556e15d496SJeremy L Thompson 16566e15d496SJeremy L Thompson /** 1657ca94c3ddSJeremy L Thompson @brief Get `CeedQFunction` global context for a `CeedOperator`. 16589fd66db6SSebastian Grimberg 1659ca94c3ddSJeremy L Thompson The caller is responsible for destroying `ctx` returned from this function via @ref CeedQFunctionContextDestroy(). 1660512bb800SJeremy L Thompson 1661ca94c3ddSJeremy 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 `CeedQFunctionContext`. 1662ca94c3ddSJeremy L Thompson This `CeedQFunctionContext` will be destroyed if `ctx` is the only reference to this `CeedQFunctionContext`. 16630126412dSJeremy L Thompson 1664ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1665ca94c3ddSJeremy L Thompson @param[out] ctx Variable to store `CeedQFunctionContext` 16660126412dSJeremy L Thompson 16670126412dSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 16680126412dSJeremy L Thompson 1669859c15bbSJames Wright @ref Advanced 16700126412dSJeremy L Thompson **/ 16710126412dSJeremy L Thompson int CeedOperatorGetContext(CeedOperator op, CeedQFunctionContext *ctx) { 1672*1203703bSJeremy L Thompson bool is_composite; 1673*1203703bSJeremy L Thompson Ceed ceed; 1674*1203703bSJeremy L Thompson CeedQFunction qf; 1675*1203703bSJeremy L Thompson CeedQFunctionContext qf_ctx; 1676*1203703bSJeremy L Thompson 1677*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 1678*1203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 1679*1203703bSJeremy L Thompson CeedCheck(!is_composite, ceed, CEED_ERROR_INCOMPATIBLE, "Cannot retrieve CeedQFunctionContext for composite operator"); 1680*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 1681*1203703bSJeremy L Thompson CeedCall(CeedQFunctionGetInnerContext(qf, &qf_ctx)); 1682*1203703bSJeremy L Thompson if (qf_ctx) CeedCall(CeedQFunctionContextReferenceCopy(qf_ctx, ctx)); 16830126412dSJeremy L Thompson return CEED_ERROR_SUCCESS; 16840126412dSJeremy L Thompson } 16850126412dSJeremy L Thompson 16860126412dSJeremy L Thompson /** 1687ca94c3ddSJeremy L Thompson @brief Get label for a registered `CeedQFunctionContext` field, or `NULL` if no field has been registered with this `field_name`. 16883668ca4bSJeremy L Thompson 1689ca94c3ddSJeremy L Thompson Fields are registered via `CeedQFunctionContextRegister*()` functions (eg. @ref CeedQFunctionContextRegisterDouble()). 1690859c15bbSJames Wright 1691ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 16923668ca4bSJeremy L Thompson @param[in] field_name Name of field to retrieve label 16933668ca4bSJeremy L Thompson @param[out] field_label Variable to field label 16943668ca4bSJeremy L Thompson 16953668ca4bSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 16963668ca4bSJeremy L Thompson 16973668ca4bSJeremy L Thompson @ref User 16983668ca4bSJeremy L Thompson **/ 169917b0d5c6SJeremy L Thompson int CeedOperatorGetContextFieldLabel(CeedOperator op, const char *field_name, CeedContextFieldLabel *field_label) { 17001c66c397SJeremy L Thompson bool is_composite, field_found = false; 17011c66c397SJeremy L Thompson 17022b730f8bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 17032b730f8bSJeremy L Thompson 17043668ca4bSJeremy L Thompson if (is_composite) { 1705a98a090bSJeremy L Thompson // Composite operator 1706a98a090bSJeremy L Thompson // -- Check if composite label already created 17073668ca4bSJeremy L Thompson for (CeedInt i = 0; i < op->num_context_labels; i++) { 17083668ca4bSJeremy L Thompson if (!strcmp(op->context_labels[i]->name, field_name)) { 17093668ca4bSJeremy L Thompson *field_label = op->context_labels[i]; 17103668ca4bSJeremy L Thompson return CEED_ERROR_SUCCESS; 17113668ca4bSJeremy L Thompson } 17123668ca4bSJeremy L Thompson } 17133668ca4bSJeremy L Thompson 1714a98a090bSJeremy L Thompson // -- Create composite label if needed 17153668ca4bSJeremy L Thompson CeedInt num_sub; 17163668ca4bSJeremy L Thompson CeedOperator *sub_operators; 17173668ca4bSJeremy L Thompson CeedContextFieldLabel new_field_label; 17183668ca4bSJeremy L Thompson 17192b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, &new_field_label)); 1720c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub)); 1721c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 17222b730f8bSJeremy L Thompson CeedCall(CeedCalloc(num_sub, &new_field_label->sub_labels)); 17233668ca4bSJeremy L Thompson new_field_label->num_sub_labels = num_sub; 17243668ca4bSJeremy L Thompson 17253668ca4bSJeremy L Thompson for (CeedInt i = 0; i < num_sub; i++) { 17263668ca4bSJeremy L Thompson if (sub_operators[i]->qf->ctx) { 17273668ca4bSJeremy L Thompson CeedContextFieldLabel new_field_label_i; 17281c66c397SJeremy L Thompson 17292b730f8bSJeremy L Thompson CeedCall(CeedQFunctionContextGetFieldLabel(sub_operators[i]->qf->ctx, field_name, &new_field_label_i)); 17303668ca4bSJeremy L Thompson if (new_field_label_i) { 1731a98a090bSJeremy L Thompson field_found = true; 17323668ca4bSJeremy L Thompson new_field_label->sub_labels[i] = new_field_label_i; 17333668ca4bSJeremy L Thompson new_field_label->name = new_field_label_i->name; 17343668ca4bSJeremy L Thompson new_field_label->description = new_field_label_i->description; 17352b730f8bSJeremy L Thompson if (new_field_label->type && new_field_label->type != new_field_label_i->type) { 17367bfe0f0eSJeremy L Thompson // LCOV_EXCL_START 17372b730f8bSJeremy L Thompson CeedCall(CeedFree(&new_field_label)); 17382b730f8bSJeremy L Thompson return CeedError(op->ceed, CEED_ERROR_INCOMPATIBLE, "Incompatible field types on sub-operator contexts. %s != %s", 17392b730f8bSJeremy L Thompson CeedContextFieldTypes[new_field_label->type], CeedContextFieldTypes[new_field_label_i->type]); 17407bfe0f0eSJeremy L Thompson // LCOV_EXCL_STOP 17417bfe0f0eSJeremy L Thompson } else { 17427bfe0f0eSJeremy L Thompson new_field_label->type = new_field_label_i->type; 17437bfe0f0eSJeremy L Thompson } 17442b730f8bSJeremy L Thompson if (new_field_label->num_values != 0 && new_field_label->num_values != new_field_label_i->num_values) { 17457bfe0f0eSJeremy L Thompson // LCOV_EXCL_START 1746*1203703bSJeremy L Thompson Ceed ceed; 1747*1203703bSJeremy L Thompson 17482b730f8bSJeremy L Thompson CeedCall(CeedFree(&new_field_label)); 1749*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 1750*1203703bSJeremy L Thompson return CeedError(ceed, CEED_ERROR_INCOMPATIBLE, "Incompatible field number of values on sub-operator contexts. %zu != %zu", 17517bfe0f0eSJeremy L Thompson new_field_label->num_values, new_field_label_i->num_values); 17527bfe0f0eSJeremy L Thompson // LCOV_EXCL_STOP 17537bfe0f0eSJeremy L Thompson } else { 17547bfe0f0eSJeremy L Thompson new_field_label->num_values = new_field_label_i->num_values; 17557bfe0f0eSJeremy L Thompson } 17563668ca4bSJeremy L Thompson } 17573668ca4bSJeremy L Thompson } 17583668ca4bSJeremy L Thompson } 1759a98a090bSJeremy L Thompson // -- Cleanup if field was found 1760a98a090bSJeremy L Thompson if (field_found) { 1761a98a090bSJeremy L Thompson *field_label = new_field_label; 1762a98a090bSJeremy L Thompson } else { 17633668ca4bSJeremy L Thompson // LCOV_EXCL_START 17642b730f8bSJeremy L Thompson CeedCall(CeedFree(&new_field_label->sub_labels)); 17652b730f8bSJeremy L Thompson CeedCall(CeedFree(&new_field_label)); 17663668ca4bSJeremy L Thompson *field_label = NULL; 17673668ca4bSJeremy L Thompson // LCOV_EXCL_STOP 17685ac9af79SJeremy L Thompson } 17695ac9af79SJeremy L Thompson } else { 1770*1203703bSJeremy L Thompson CeedQFunction qf; 1771*1203703bSJeremy L Thompson CeedQFunctionContext ctx; 1772*1203703bSJeremy L Thompson 1773a98a090bSJeremy L Thompson // Single, non-composite operator 1774*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 1775*1203703bSJeremy L Thompson CeedCall(CeedQFunctionGetInnerContext(qf, &ctx)); 1776*1203703bSJeremy L Thompson if (ctx) { 1777*1203703bSJeremy L Thompson CeedCall(CeedQFunctionContextGetFieldLabel(ctx, field_name, field_label)); 1778a98a090bSJeremy L Thompson } else { 1779a98a090bSJeremy L Thompson *field_label = NULL; 1780a98a090bSJeremy L Thompson } 17815ac9af79SJeremy L Thompson } 17825ac9af79SJeremy L Thompson 17835ac9af79SJeremy L Thompson // Set label in operator 17845ac9af79SJeremy L Thompson if (*field_label) { 17855ac9af79SJeremy L Thompson (*field_label)->from_op = true; 17865ac9af79SJeremy L Thompson 17873668ca4bSJeremy L Thompson // Move new composite label to operator 17883668ca4bSJeremy L Thompson if (op->num_context_labels == 0) { 17892b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, &op->context_labels)); 17903668ca4bSJeremy L Thompson op->max_context_labels = 1; 17913668ca4bSJeremy L Thompson } else if (op->num_context_labels == op->max_context_labels) { 17922b730f8bSJeremy L Thompson CeedCall(CeedRealloc(2 * op->num_context_labels, &op->context_labels)); 17933668ca4bSJeremy L Thompson op->max_context_labels *= 2; 17943668ca4bSJeremy L Thompson } 17955ac9af79SJeremy L Thompson op->context_labels[op->num_context_labels] = *field_label; 17963668ca4bSJeremy L Thompson op->num_context_labels++; 17973668ca4bSJeremy L Thompson } 17983668ca4bSJeremy L Thompson return CEED_ERROR_SUCCESS; 17993668ca4bSJeremy L Thompson } 18003668ca4bSJeremy L Thompson 18013668ca4bSJeremy L Thompson /** 1802ca94c3ddSJeremy L Thompson @brief Set `CeedQFunctionContext` field holding double precision values. 18034385fb7fSSebastian Grimberg 1804ca94c3ddSJeremy L Thompson For composite operators, the values are set in all sub-operator `CeedQFunctionContext` that have a matching `field_name`. 1805d8dd9a91SJeremy L Thompson 1806ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 18072788fa27SJeremy L Thompson @param[in] field_label Label of field to set 1808ea61e9acSJeremy L Thompson @param[in] values Values to set 1809d8dd9a91SJeremy L Thompson 1810d8dd9a91SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1811d8dd9a91SJeremy L Thompson 1812d8dd9a91SJeremy L Thompson @ref User 1813d8dd9a91SJeremy L Thompson **/ 181417b0d5c6SJeremy L Thompson int CeedOperatorSetContextDouble(CeedOperator op, CeedContextFieldLabel field_label, double *values) { 18152b730f8bSJeremy L Thompson return CeedOperatorContextSetGeneric(op, field_label, CEED_CONTEXT_FIELD_DOUBLE, values); 1816d8dd9a91SJeremy L Thompson } 1817d8dd9a91SJeremy L Thompson 1818d8dd9a91SJeremy L Thompson /** 1819ca94c3ddSJeremy L Thompson @brief Get `CeedQFunctionContext` field holding double precision values, read-only. 18204385fb7fSSebastian Grimberg 1821ca94c3ddSJeremy L Thompson For composite operators, the values correspond to the first sub-operator `CeedQFunctionContext` that has a matching `field_name`. 18222788fa27SJeremy L Thompson 1823ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 18242788fa27SJeremy L Thompson @param[in] field_label Label of field to get 18252788fa27SJeremy L Thompson @param[out] num_values Number of values in the field label 18262788fa27SJeremy L Thompson @param[out] values Pointer to context values 18272788fa27SJeremy L Thompson 18282788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 18292788fa27SJeremy L Thompson 18302788fa27SJeremy L Thompson @ref User 18312788fa27SJeremy L Thompson **/ 183217b0d5c6SJeremy L Thompson int CeedOperatorGetContextDoubleRead(CeedOperator op, CeedContextFieldLabel field_label, size_t *num_values, const double **values) { 18332788fa27SJeremy L Thompson return CeedOperatorContextGetGenericRead(op, field_label, CEED_CONTEXT_FIELD_DOUBLE, num_values, values); 18342788fa27SJeremy L Thompson } 18352788fa27SJeremy L Thompson 18362788fa27SJeremy L Thompson /** 1837ca94c3ddSJeremy L Thompson @brief Restore `CeedQFunctionContext` field holding double precision values, read-only. 18382788fa27SJeremy L Thompson 1839ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 18402788fa27SJeremy L Thompson @param[in] field_label Label of field to restore 18412788fa27SJeremy L Thompson @param[out] values Pointer to context values 18422788fa27SJeremy L Thompson 18432788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 18442788fa27SJeremy L Thompson 18452788fa27SJeremy L Thompson @ref User 18462788fa27SJeremy L Thompson **/ 184717b0d5c6SJeremy L Thompson int CeedOperatorRestoreContextDoubleRead(CeedOperator op, CeedContextFieldLabel field_label, const double **values) { 18482788fa27SJeremy L Thompson return CeedOperatorContextRestoreGenericRead(op, field_label, CEED_CONTEXT_FIELD_DOUBLE, values); 18492788fa27SJeremy L Thompson } 18502788fa27SJeremy L Thompson 18512788fa27SJeremy L Thompson /** 1852ca94c3ddSJeremy L Thompson @brief Set `CeedQFunctionContext` field holding `int32` values. 18534385fb7fSSebastian Grimberg 1854ca94c3ddSJeremy L Thompson For composite operators, the values are set in all sub-operator `CeedQFunctionContext` that have a matching `field_name`. 1855d8dd9a91SJeremy L Thompson 1856ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 1857ea61e9acSJeremy L Thompson @param[in] field_label Label of field to set 1858ea61e9acSJeremy L Thompson @param[in] values Values to set 1859d8dd9a91SJeremy L Thompson 1860d8dd9a91SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1861d8dd9a91SJeremy L Thompson 1862d8dd9a91SJeremy L Thompson @ref User 1863d8dd9a91SJeremy L Thompson **/ 186423dbfd29SJeremy L Thompson int CeedOperatorSetContextInt32(CeedOperator op, CeedContextFieldLabel field_label, int32_t *values) { 18652b730f8bSJeremy L Thompson return CeedOperatorContextSetGeneric(op, field_label, CEED_CONTEXT_FIELD_INT32, values); 1866d8dd9a91SJeremy L Thompson } 1867d8dd9a91SJeremy L Thompson 1868d8dd9a91SJeremy L Thompson /** 1869ca94c3ddSJeremy L Thompson @brief Get `CeedQFunctionContext` field holding `int32` values, read-only. 18704385fb7fSSebastian Grimberg 1871ca94c3ddSJeremy L Thompson For composite operators, the values correspond to the first sub-operator `CeedQFunctionContext` that has a matching `field_name`. 18722788fa27SJeremy L Thompson 1873ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 18742788fa27SJeremy L Thompson @param[in] field_label Label of field to get 1875ca94c3ddSJeremy L Thompson @param[out] num_values Number of `int32` values in `values` 18762788fa27SJeremy L Thompson @param[out] values Pointer to context values 18772788fa27SJeremy L Thompson 18782788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 18792788fa27SJeremy L Thompson 18802788fa27SJeremy L Thompson @ref User 18812788fa27SJeremy L Thompson **/ 188223dbfd29SJeremy L Thompson int CeedOperatorGetContextInt32Read(CeedOperator op, CeedContextFieldLabel field_label, size_t *num_values, const int32_t **values) { 18832788fa27SJeremy L Thompson return CeedOperatorContextGetGenericRead(op, field_label, CEED_CONTEXT_FIELD_INT32, num_values, values); 18842788fa27SJeremy L Thompson } 18852788fa27SJeremy L Thompson 18862788fa27SJeremy L Thompson /** 1887ca94c3ddSJeremy L Thompson @brief Restore `CeedQFunctionContext` field holding `int32` values, read-only. 18882788fa27SJeremy L Thompson 1889ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 18902788fa27SJeremy L Thompson @param[in] field_label Label of field to get 18912788fa27SJeremy L Thompson @param[out] values Pointer to context values 18922788fa27SJeremy L Thompson 18932788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 18942788fa27SJeremy L Thompson 18952788fa27SJeremy L Thompson @ref User 18962788fa27SJeremy L Thompson **/ 189723dbfd29SJeremy L Thompson int CeedOperatorRestoreContextInt32Read(CeedOperator op, CeedContextFieldLabel field_label, const int32_t **values) { 18982788fa27SJeremy L Thompson return CeedOperatorContextRestoreGenericRead(op, field_label, CEED_CONTEXT_FIELD_INT32, values); 18992788fa27SJeremy L Thompson } 19002788fa27SJeremy L Thompson 19012788fa27SJeremy L Thompson /** 1902ca94c3ddSJeremy L Thompson @brief Set `CeedQFunctionContext` field holding boolean values. 19035b6ec284SJeremy L Thompson 1904ca94c3ddSJeremy L Thompson For composite operators, the values are set in all sub-operator `CeedQFunctionContext` that have a matching `field_name`. 19055b6ec284SJeremy L Thompson 1906ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 19075b6ec284SJeremy L Thompson @param[in] field_label Label of field to set 19085b6ec284SJeremy L Thompson @param[in] values Values to set 19095b6ec284SJeremy L Thompson 19105b6ec284SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 19115b6ec284SJeremy L Thompson 19125b6ec284SJeremy L Thompson @ref User 19135b6ec284SJeremy L Thompson **/ 19145b6ec284SJeremy L Thompson int CeedOperatorSetContextBoolean(CeedOperator op, CeedContextFieldLabel field_label, bool *values) { 19155b6ec284SJeremy L Thompson return CeedOperatorContextSetGeneric(op, field_label, CEED_CONTEXT_FIELD_BOOL, values); 19165b6ec284SJeremy L Thompson } 19175b6ec284SJeremy L Thompson 19185b6ec284SJeremy L Thompson /** 1919ca94c3ddSJeremy L Thompson @brief Get `CeedQFunctionContext` field holding boolean values, read-only. 19205b6ec284SJeremy L Thompson 1921ca94c3ddSJeremy L Thompson For composite operators, the values correspond to the first sub-operator `CeedQFunctionContext` that has a matching `field_name`. 19225b6ec284SJeremy L Thompson 1923ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 19245b6ec284SJeremy L Thompson @param[in] field_label Label of field to get 1925ca94c3ddSJeremy L Thompson @param[out] num_values Number of boolean values in `values` 19265b6ec284SJeremy L Thompson @param[out] values Pointer to context values 19275b6ec284SJeremy L Thompson 19285b6ec284SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 19295b6ec284SJeremy L Thompson 19305b6ec284SJeremy L Thompson @ref User 19315b6ec284SJeremy L Thompson **/ 19325b6ec284SJeremy L Thompson int CeedOperatorGetContextBooleanRead(CeedOperator op, CeedContextFieldLabel field_label, size_t *num_values, const bool **values) { 19335b6ec284SJeremy L Thompson return CeedOperatorContextGetGenericRead(op, field_label, CEED_CONTEXT_FIELD_BOOL, num_values, values); 19345b6ec284SJeremy L Thompson } 19355b6ec284SJeremy L Thompson 19365b6ec284SJeremy L Thompson /** 1937ca94c3ddSJeremy L Thompson @brief Restore `CeedQFunctionContext` field holding boolean values, read-only. 19385b6ec284SJeremy L Thompson 1939ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 19405b6ec284SJeremy L Thompson @param[in] field_label Label of field to get 19415b6ec284SJeremy L Thompson @param[out] values Pointer to context values 19425b6ec284SJeremy L Thompson 19435b6ec284SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 19445b6ec284SJeremy L Thompson 19455b6ec284SJeremy L Thompson @ref User 19465b6ec284SJeremy L Thompson **/ 19475b6ec284SJeremy L Thompson int CeedOperatorRestoreContextBooleanRead(CeedOperator op, CeedContextFieldLabel field_label, const bool **values) { 19485b6ec284SJeremy L Thompson return CeedOperatorContextRestoreGenericRead(op, field_label, CEED_CONTEXT_FIELD_BOOL, values); 19495b6ec284SJeremy L Thompson } 19505b6ec284SJeremy L Thompson 19515b6ec284SJeremy L Thompson /** 1952ca94c3ddSJeremy L Thompson @brief Apply `CeedOperator` to a `CeedVector`. 1953d7b241e6Sjeremylt 1954ea61e9acSJeremy L Thompson This computes the action of the operator on the specified (active) input, yielding its (active) output. 1955ca94c3ddSJeremy L Thompson All inputs and outputs must be specified using @ref CeedOperatorSetField(). 1956d7b241e6Sjeremylt 1957ca94c3ddSJeremy L Thompson Note: Calling this function asserts that setup is complete and sets the `CeedOperator` as immutable. 1958f04ea552SJeremy L Thompson 1959ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to apply 1960ca94c3ddSJeremy L Thompson @param[in] in `CeedVector` containing input state or @ref CEED_VECTOR_NONE if there are no active inputs 1961ca94c3ddSJeremy L Thompson @param[out] out `CeedVector` to store result of applying operator (must be distinct from `in`) or @ref CEED_VECTOR_NONE if there are no active outputs 1962ca94c3ddSJeremy L Thompson @param[in] request Address of @ref CeedRequest for non-blocking completion, else @ref CEED_REQUEST_IMMEDIATE 1963b11c1e72Sjeremylt 1964b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 1965dfdf5a53Sjeremylt 19667a982d89SJeremy L. Thompson @ref User 1967b11c1e72Sjeremylt **/ 19682b730f8bSJeremy L Thompson int CeedOperatorApply(CeedOperator op, CeedVector in, CeedVector out, CeedRequest *request) { 1969*1203703bSJeremy L Thompson bool is_composite; 1970*1203703bSJeremy L Thompson 19712b730f8bSJeremy L Thompson CeedCall(CeedOperatorCheckReady(op)); 1972d7b241e6Sjeremylt 1973*1203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 1974*1203703bSJeremy L Thompson if (is_composite) { 1975250756a7Sjeremylt // Composite Operator 1976250756a7Sjeremylt if (op->ApplyComposite) { 19772b730f8bSJeremy L Thompson CeedCall(op->ApplyComposite(op, in, out, request)); 1978250756a7Sjeremylt } else { 1979d1d35e2fSjeremylt CeedInt num_suboperators; 1980d1d35e2fSjeremylt CeedOperator *sub_operators; 19811c66c397SJeremy L Thompson 19821c66c397SJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 1983c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 1984250756a7Sjeremylt 1985250756a7Sjeremylt // Zero all output vectors 19863ca2b39bSJeremy L Thompson if (out != CEED_VECTOR_NONE) CeedCall(CeedVectorSetValue(out, 0.0)); 1987d1d35e2fSjeremylt for (CeedInt i = 0; i < num_suboperators; i++) { 1988*1203703bSJeremy L Thompson CeedInt num_output_fields; 1989*1203703bSJeremy L Thompson CeedOperatorField *output_fields; 19901c66c397SJeremy L Thompson 1991*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetFields(sub_operators[i], NULL, NULL, &num_output_fields, &output_fields)); 1992*1203703bSJeremy L Thompson for (CeedInt j = 0; j < num_output_fields; j++) { 1993*1203703bSJeremy L Thompson CeedVector vec; 1994*1203703bSJeremy L Thompson 1995*1203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(output_fields[j], &vec)); 1996250756a7Sjeremylt if (vec != CEED_VECTOR_ACTIVE && vec != CEED_VECTOR_NONE) { 19972b730f8bSJeremy L Thompson CeedCall(CeedVectorSetValue(vec, 0.0)); 1998250756a7Sjeremylt } 1999250756a7Sjeremylt } 2000250756a7Sjeremylt } 2001250756a7Sjeremylt // Apply 2002f754c177SSebastian Grimberg for (CeedInt i = 0; i < num_suboperators; i++) { 2003f754c177SSebastian Grimberg CeedCall(CeedOperatorApplyAdd(sub_operators[i], in, out, request)); 2004cae8b89aSjeremylt } 2005cae8b89aSjeremylt } 20063ca2b39bSJeremy L Thompson } else { 20073ca2b39bSJeremy L Thompson // Standard Operator 20083ca2b39bSJeremy L Thompson if (op->Apply) { 20093ca2b39bSJeremy L Thompson CeedCall(op->Apply(op, in, out, request)); 20103ca2b39bSJeremy L Thompson } else { 2011*1203703bSJeremy L Thompson CeedInt num_output_fields; 2012*1203703bSJeremy L Thompson CeedOperatorField *output_fields; 2013*1203703bSJeremy L Thompson 2014*1203703bSJeremy L Thompson CeedCall(CeedOperatorGetFields(op, NULL, NULL, &num_output_fields, &output_fields)); 20153ca2b39bSJeremy L Thompson // Zero all output vectors 2016*1203703bSJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 2017*1203703bSJeremy L Thompson CeedVector vec; 20181c66c397SJeremy L Thompson 2019*1203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(output_fields[i], &vec)); 20203ca2b39bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) vec = out; 20213ca2b39bSJeremy L Thompson if (vec != CEED_VECTOR_NONE) CeedCall(CeedVectorSetValue(vec, 0.0)); 20223ca2b39bSJeremy L Thompson } 20233ca2b39bSJeremy L Thompson // Apply 2024*1203703bSJeremy L Thompson if (op->num_elem > 0) CeedCall(op->ApplyAdd(op, in, out, request)); 20253ca2b39bSJeremy L Thompson } 2026250756a7Sjeremylt } 2027e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 2028cae8b89aSjeremylt } 2029cae8b89aSjeremylt 2030cae8b89aSjeremylt /** 2031ca94c3ddSJeremy L Thompson @brief Apply `CeedOperator` to a `CeedVector` and add result to output `CeedVector`. 2032cae8b89aSjeremylt 2033ea61e9acSJeremy L Thompson This computes the action of the operator on the specified (active) input, yielding its (active) output. 2034ca94c3ddSJeremy L Thompson All inputs and outputs must be specified using @ref CeedOperatorSetField(). 2035cae8b89aSjeremylt 2036ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to apply 2037ca94c3ddSJeremy L Thompson @param[in] in `CeedVector` containing input state or @ref CEED_VECTOR_NONE if there are no active inputs 2038ca94c3ddSJeremy L Thompson @param[out] out `CeedVector` to sum in result of applying operator (must be distinct from `in`) or @ref CEED_VECTOR_NONE if there are no active outputs 2039ca94c3ddSJeremy L Thompson @param[in] request Address of @ref CeedRequest for non-blocking completion, else @ref CEED_REQUEST_IMMEDIATE 2040cae8b89aSjeremylt 2041cae8b89aSjeremylt @return An error code: 0 - success, otherwise - failure 2042cae8b89aSjeremylt 20437a982d89SJeremy L. Thompson @ref User 2044cae8b89aSjeremylt **/ 20452b730f8bSJeremy L Thompson int CeedOperatorApplyAdd(CeedOperator op, CeedVector in, CeedVector out, CeedRequest *request) { 2046*1203703bSJeremy L Thompson bool is_composite; 2047*1203703bSJeremy L Thompson 20482b730f8bSJeremy L Thompson CeedCall(CeedOperatorCheckReady(op)); 2049cae8b89aSjeremylt 2050*1203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 2051*1203703bSJeremy L Thompson if (is_composite) { 2052250756a7Sjeremylt // Composite Operator 2053250756a7Sjeremylt if (op->ApplyAddComposite) { 20542b730f8bSJeremy L Thompson CeedCall(op->ApplyAddComposite(op, in, out, request)); 2055cae8b89aSjeremylt } else { 2056d1d35e2fSjeremylt CeedInt num_suboperators; 2057d1d35e2fSjeremylt CeedOperator *sub_operators; 2058250756a7Sjeremylt 20591c66c397SJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 20601c66c397SJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 2061d1d35e2fSjeremylt for (CeedInt i = 0; i < num_suboperators; i++) { 20622b730f8bSJeremy L Thompson CeedCall(CeedOperatorApplyAdd(sub_operators[i], in, out, request)); 20631d7d2407SJeremy L Thompson } 2064250756a7Sjeremylt } 2065*1203703bSJeremy L Thompson } else if (op->num_elem > 0) { 20663ca2b39bSJeremy L Thompson // Standard Operator 20673ca2b39bSJeremy L Thompson CeedCall(op->ApplyAdd(op, in, out, request)); 2068250756a7Sjeremylt } 2069e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 2070d7b241e6Sjeremylt } 2071d7b241e6Sjeremylt 2072d7b241e6Sjeremylt /** 2073ca94c3ddSJeremy L Thompson @brief Destroy a `CeedOperator` 2074d7b241e6Sjeremylt 2075ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` to destroy 2076b11c1e72Sjeremylt 2077b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 2078dfdf5a53Sjeremylt 20797a982d89SJeremy L. Thompson @ref User 2080b11c1e72Sjeremylt **/ 2081d7b241e6Sjeremylt int CeedOperatorDestroy(CeedOperator *op) { 2082ad6481ceSJeremy L Thompson if (!*op || --(*op)->ref_count > 0) { 2083ad6481ceSJeremy L Thompson *op = NULL; 2084ad6481ceSJeremy L Thompson return CEED_ERROR_SUCCESS; 2085ad6481ceSJeremy L Thompson } 20862b730f8bSJeremy L Thompson if ((*op)->Destroy) CeedCall((*op)->Destroy(*op)); 20872b730f8bSJeremy L Thompson CeedCall(CeedDestroy(&(*op)->ceed)); 2088fe2413ffSjeremylt // Free fields 20892b730f8bSJeremy L Thompson for (CeedInt i = 0; i < (*op)->num_fields; i++) { 2090d1d35e2fSjeremylt if ((*op)->input_fields[i]) { 2091437c7c90SJeremy L Thompson if ((*op)->input_fields[i]->elem_rstr != CEED_ELEMRESTRICTION_NONE) { 2092437c7c90SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&(*op)->input_fields[i]->elem_rstr)); 209315910d16Sjeremylt } 2094356036faSJeremy L Thompson if ((*op)->input_fields[i]->basis != CEED_BASIS_NONE) { 20952b730f8bSJeremy L Thompson CeedCall(CeedBasisDestroy(&(*op)->input_fields[i]->basis)); 209671352a93Sjeremylt } 20972b730f8bSJeremy L Thompson if ((*op)->input_fields[i]->vec != CEED_VECTOR_ACTIVE && (*op)->input_fields[i]->vec != CEED_VECTOR_NONE) { 20982b730f8bSJeremy L Thompson CeedCall(CeedVectorDestroy(&(*op)->input_fields[i]->vec)); 209971352a93Sjeremylt } 21002b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->input_fields[i]->field_name)); 21012b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->input_fields[i])); 2102fe2413ffSjeremylt } 21032b730f8bSJeremy L Thompson } 21042b730f8bSJeremy L Thompson for (CeedInt i = 0; i < (*op)->num_fields; i++) { 2105d1d35e2fSjeremylt if ((*op)->output_fields[i]) { 2106437c7c90SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&(*op)->output_fields[i]->elem_rstr)); 2107356036faSJeremy L Thompson if ((*op)->output_fields[i]->basis != CEED_BASIS_NONE) { 21082b730f8bSJeremy L Thompson CeedCall(CeedBasisDestroy(&(*op)->output_fields[i]->basis)); 210971352a93Sjeremylt } 21102b730f8bSJeremy L Thompson if ((*op)->output_fields[i]->vec != CEED_VECTOR_ACTIVE && (*op)->output_fields[i]->vec != CEED_VECTOR_NONE) { 21112b730f8bSJeremy L Thompson CeedCall(CeedVectorDestroy(&(*op)->output_fields[i]->vec)); 211271352a93Sjeremylt } 21132b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->output_fields[i]->field_name)); 21142b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->output_fields[i])); 21152b730f8bSJeremy L Thompson } 2116fe2413ffSjeremylt } 211748acf710SJeremy L Thompson // AtPoints data 211848acf710SJeremy L Thompson CeedCall(CeedVectorDestroy(&(*op)->point_coords)); 211948acf710SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&(*op)->rstr_points)); 212048acf710SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&(*op)->first_points_rstr)); 2121d1d35e2fSjeremylt // Destroy sub_operators 21222b730f8bSJeremy L Thompson for (CeedInt i = 0; i < (*op)->num_suboperators; i++) { 2123d1d35e2fSjeremylt if ((*op)->sub_operators[i]) { 21242b730f8bSJeremy L Thompson CeedCall(CeedOperatorDestroy(&(*op)->sub_operators[i])); 212552d6035fSJeremy L Thompson } 21262b730f8bSJeremy L Thompson } 21272b730f8bSJeremy L Thompson CeedCall(CeedQFunctionDestroy(&(*op)->qf)); 21282b730f8bSJeremy L Thompson CeedCall(CeedQFunctionDestroy(&(*op)->dqf)); 21292b730f8bSJeremy L Thompson CeedCall(CeedQFunctionDestroy(&(*op)->dqfT)); 21303668ca4bSJeremy L Thompson // Destroy any composite labels 21315ac9af79SJeremy L Thompson if ((*op)->is_composite) { 21323668ca4bSJeremy L Thompson for (CeedInt i = 0; i < (*op)->num_context_labels; i++) { 21332b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->context_labels[i]->sub_labels)); 21342b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->context_labels[i])); 21353668ca4bSJeremy L Thompson } 21365ac9af79SJeremy L Thompson } 21372b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->context_labels)); 2138fe2413ffSjeremylt 21395107b09fSJeremy L Thompson // Destroy fallback 21402b730f8bSJeremy L Thompson CeedCall(CeedOperatorDestroy(&(*op)->op_fallback)); 21415107b09fSJeremy L Thompson 2142ed9e99e6SJeremy L Thompson // Destroy assembly data 21432b730f8bSJeremy L Thompson CeedCall(CeedQFunctionAssemblyDataDestroy(&(*op)->qf_assembled)); 21442b730f8bSJeremy L Thompson CeedCall(CeedOperatorAssemblyDataDestroy(&(*op)->op_assembled)); 214570a7ffb3SJeremy L Thompson 21462b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->input_fields)); 21472b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->output_fields)); 21482b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->sub_operators)); 21492b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->name)); 21502b730f8bSJeremy L Thompson CeedCall(CeedFree(op)); 2151e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 2152d7b241e6Sjeremylt } 2153d7b241e6Sjeremylt 2154d7b241e6Sjeremylt /// @} 2155