15aed82e4SJeremy L Thompson // Copyright (c) 2017-2024, 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) { 376f8994e9SJeremy L Thompson const char *field_name; 381203703bSJeremy L Thompson CeedInt dim = 1, num_comp = 1, q_comp = 1, rstr_num_comp = 1, size; 391203703bSJeremy L Thompson CeedEvalMode eval_mode; 401203703bSJeremy L Thompson 411203703bSJeremy L Thompson // Field data 42ab747706SJeremy L Thompson CeedCall(CeedQFunctionFieldGetData(qf_field, &field_name, &size, &eval_mode)); 432b730f8bSJeremy L Thompson 44e15f9bd0SJeremy L Thompson // Restriction 45bafebce1SSebastian Grimberg CeedCheck((rstr == CEED_ELEMRESTRICTION_NONE) == (eval_mode == CEED_EVAL_WEIGHT), ceed, CEED_ERROR_INCOMPATIBLE, 466574a04fSJeremy L Thompson "CEED_ELEMRESTRICTION_NONE and CEED_EVAL_WEIGHT must be used together."); 47bafebce1SSebastian Grimberg if (rstr != CEED_ELEMRESTRICTION_NONE) { 48bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionGetNumComponents(rstr, &rstr_num_comp)); 49e1e9e29dSJed Brown } 50e15f9bd0SJeremy L Thompson // Basis 51bafebce1SSebastian Grimberg CeedCheck((basis == CEED_BASIS_NONE) == (eval_mode == CEED_EVAL_NONE), ceed, CEED_ERROR_INCOMPATIBLE, 52356036faSJeremy L Thompson "CEED_BASIS_NONE and CEED_EVAL_NONE must be used together."); 53bafebce1SSebastian Grimberg if (basis != CEED_BASIS_NONE) { 54bafebce1SSebastian Grimberg CeedCall(CeedBasisGetDimension(basis, &dim)); 55bafebce1SSebastian Grimberg CeedCall(CeedBasisGetNumComponents(basis, &num_comp)); 56bafebce1SSebastian Grimberg CeedCall(CeedBasisGetNumQuadratureComponents(basis, eval_mode, &q_comp)); 57bafebce1SSebastian Grimberg CeedCheck(rstr == CEED_ELEMRESTRICTION_NONE || rstr_num_comp == num_comp, ceed, CEED_ERROR_DIMENSION, 58ca94c3ddSJeremy L Thompson "Field '%s' of size %" CeedInt_FMT " and EvalMode %s: CeedElemRestriction has %" CeedInt_FMT 59ca94c3ddSJeremy L Thompson " components, but CeedBasis has %" CeedInt_FMT " components", 601203703bSJeremy L Thompson field_name, size, CeedEvalModes[eval_mode], rstr_num_comp, num_comp); 61e15f9bd0SJeremy L Thompson } 62e15f9bd0SJeremy L Thompson // Field size 63d1d35e2fSjeremylt switch (eval_mode) { 64e15f9bd0SJeremy L Thompson case CEED_EVAL_NONE: 65edb2538eSJeremy L Thompson CeedCheck(size == rstr_num_comp, ceed, CEED_ERROR_DIMENSION, 661203703bSJeremy L Thompson "Field '%s' of size %" CeedInt_FMT " and EvalMode %s: CeedElemRestriction has %" CeedInt_FMT " components", field_name, size, 671203703bSJeremy L Thompson CeedEvalModes[eval_mode], rstr_num_comp); 68e15f9bd0SJeremy L Thompson break; 69e15f9bd0SJeremy L Thompson case CEED_EVAL_INTERP: 70c4e3f59bSSebastian Grimberg case CEED_EVAL_GRAD: 71c4e3f59bSSebastian Grimberg case CEED_EVAL_DIV: 72c4e3f59bSSebastian Grimberg case CEED_EVAL_CURL: 736574a04fSJeremy L Thompson CeedCheck(size == num_comp * q_comp, ceed, CEED_ERROR_DIMENSION, 741203703bSJeremy L Thompson "Field '%s' of size %" CeedInt_FMT " and EvalMode %s: CeedElemRestriction/Basis has %" CeedInt_FMT " components", field_name, size, 751203703bSJeremy L Thompson CeedEvalModes[eval_mode], num_comp * q_comp); 76e15f9bd0SJeremy L Thompson break; 77e15f9bd0SJeremy L Thompson case CEED_EVAL_WEIGHT: 78d1d35e2fSjeremylt // No additional checks required 79e15f9bd0SJeremy L Thompson break; 80e15f9bd0SJeremy L Thompson } 81e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 827a982d89SJeremy L. Thompson } 837a982d89SJeremy L. Thompson 847a982d89SJeremy L. Thompson /** 85ca94c3ddSJeremy L Thompson @brief View a field of a `CeedOperator` 867a982d89SJeremy L. Thompson 871203703bSJeremy L Thompson @param[in] op_field `CeedOperator` Field to view 88ca94c3ddSJeremy L Thompson @param[in] qf_field `CeedQFunction` Field (carries field name) 89d1d35e2fSjeremylt @param[in] field_number Number of field being viewed 904c4400c7SValeria Barra @param[in] sub true indicates sub-operator, which increases indentation; false for top-level operator 91d1d35e2fSjeremylt @param[in] input true for an input field; false for output field 92ca94c3ddSJeremy L Thompson @param[in] stream Stream to view to, e.g., `stdout` 937a982d89SJeremy L. Thompson 947a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 957a982d89SJeremy L. Thompson 967a982d89SJeremy L. Thompson @ref Utility 977a982d89SJeremy L. Thompson **/ 981203703bSJeremy L Thompson static int CeedOperatorFieldView(CeedOperatorField op_field, CeedQFunctionField qf_field, CeedInt field_number, bool sub, bool input, FILE *stream) { 997a982d89SJeremy L. Thompson const char *pre = sub ? " " : ""; 100d1d35e2fSjeremylt const char *in_out = input ? "Input" : "Output"; 1016f8994e9SJeremy L Thompson const char *field_name; 1021203703bSJeremy L Thompson CeedInt size; 1031203703bSJeremy L Thompson CeedEvalMode eval_mode; 1041203703bSJeremy L Thompson CeedVector vec; 1051203703bSJeremy L Thompson CeedBasis basis; 1061203703bSJeremy L Thompson 1071203703bSJeremy L Thompson // Field data 108ab747706SJeremy L Thompson CeedCall(CeedQFunctionFieldGetData(qf_field, &field_name, &size, &eval_mode)); 109ab747706SJeremy L Thompson CeedCall(CeedOperatorFieldGetData(op_field, NULL, NULL, &basis, &vec)); 1107a982d89SJeremy L. Thompson 1112b730f8bSJeremy L Thompson fprintf(stream, 1122b730f8bSJeremy L Thompson "%s %s field %" CeedInt_FMT 1132b730f8bSJeremy L Thompson ":\n" 1147a982d89SJeremy L. Thompson "%s Name: \"%s\"\n", 1151203703bSJeremy L Thompson pre, in_out, field_number, pre, field_name); 1161203703bSJeremy L Thompson fprintf(stream, "%s Size: %" CeedInt_FMT "\n", pre, size); 1171203703bSJeremy L Thompson fprintf(stream, "%s EvalMode: %s\n", pre, CeedEvalModes[eval_mode]); 1181203703bSJeremy L Thompson if (basis == CEED_BASIS_NONE) fprintf(stream, "%s No basis\n", pre); 1191203703bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) fprintf(stream, "%s Active vector\n", pre); 1201203703bSJeremy L Thompson else if (vec == CEED_VECTOR_NONE) fprintf(stream, "%s No vector\n", pre); 121681d0ea7SJeremy L Thompson 122681d0ea7SJeremy L Thompson CeedCall(CeedVectorDestroy(&vec)); 123681d0ea7SJeremy L Thompson CeedCall(CeedBasisDestroy(&basis)); 124e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 1257a982d89SJeremy L. Thompson } 1267a982d89SJeremy L. Thompson 1277a982d89SJeremy L. Thompson /** 128ca94c3ddSJeremy L Thompson @brief View a single `CeedOperator` 1297a982d89SJeremy L. Thompson 130ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to view 1317a982d89SJeremy L. Thompson @param[in] sub Boolean flag for sub-operator 132ca94c3ddSJeremy L Thompson @param[in] stream Stream to write; typically `stdout` or a file 1337a982d89SJeremy L. Thompson 1347a982d89SJeremy L. Thompson @return Error code: 0 - success, otherwise - failure 1357a982d89SJeremy L. Thompson 1367a982d89SJeremy L. Thompson @ref Utility 1377a982d89SJeremy L. Thompson **/ 1387a982d89SJeremy L. Thompson int CeedOperatorSingleView(CeedOperator op, bool sub, FILE *stream) { 1397a982d89SJeremy L. Thompson const char *pre = sub ? " " : ""; 1401203703bSJeremy L Thompson CeedInt num_elem, num_qpts, total_fields = 0, num_input_fields, num_output_fields; 1411203703bSJeremy L Thompson CeedQFunction qf; 1421203703bSJeremy L Thompson CeedQFunctionField *qf_input_fields, *qf_output_fields; 1431203703bSJeremy L Thompson CeedOperatorField *op_input_fields, *op_output_fields; 1447a982d89SJeremy L. Thompson 1452b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetNumElements(op, &num_elem)); 1462b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetNumQuadraturePoints(op, &num_qpts)); 1472b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetNumArgs(op, &total_fields)); 1481203703bSJeremy L Thompson CeedCall(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields)); 1491203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 1501203703bSJeremy L Thompson CeedCall(CeedQFunctionGetFields(qf, NULL, &qf_input_fields, NULL, &qf_output_fields)); 151c11e12f4SJeremy L Thompson CeedCall(CeedQFunctionDestroy(&qf)); 1521c66c397SJeremy L Thompson 1532b730f8bSJeremy L Thompson fprintf(stream, "%s %" CeedInt_FMT " elements with %" CeedInt_FMT " quadrature points each\n", pre, num_elem, num_qpts); 1542b730f8bSJeremy L Thompson fprintf(stream, "%s %" CeedInt_FMT " field%s\n", pre, total_fields, total_fields > 1 ? "s" : ""); 1551203703bSJeremy L Thompson fprintf(stream, "%s %" CeedInt_FMT " input field%s:\n", pre, num_input_fields, num_input_fields > 1 ? "s" : ""); 1561203703bSJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 1571203703bSJeremy L Thompson CeedCall(CeedOperatorFieldView(op_input_fields[i], qf_input_fields[i], i, sub, 1, stream)); 1587a982d89SJeremy L. Thompson } 1591203703bSJeremy L Thompson fprintf(stream, "%s %" CeedInt_FMT " output field%s:\n", pre, num_output_fields, num_output_fields > 1 ? "s" : ""); 1601203703bSJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 1611203703bSJeremy L Thompson CeedCall(CeedOperatorFieldView(op_output_fields[i], qf_output_fields[i], i, sub, 0, stream)); 1627a982d89SJeremy L. Thompson } 163e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 1647a982d89SJeremy L. Thompson } 1657a982d89SJeremy L. Thompson 166d99fa3c5SJeremy L Thompson /** 167681d0ea7SJeremy L Thompson @brief Find the active input vector `CeedBasis` for a non-composite `CeedOperator`. 168681d0ea7SJeremy L Thompson 169681d0ea7SJeremy L Thompson Note: Caller is responsible for destroying the `active_basis` with @ref CeedBasisDestroy(). 170eaf62fffSJeremy L Thompson 171ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to find active `CeedBasis` for 172ca94c3ddSJeremy L Thompson @param[out] active_basis `CeedBasis` for active input vector or `NULL` for composite operator 173eaf62fffSJeremy L Thompson 174eaf62fffSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 175eaf62fffSJeremy L Thompson 176eaf62fffSJeremy L Thompson @ref Developer 177eaf62fffSJeremy L Thompson **/ 178eaf62fffSJeremy L Thompson int CeedOperatorGetActiveBasis(CeedOperator op, CeedBasis *active_basis) { 179506b1a0cSSebastian Grimberg CeedCall(CeedOperatorGetActiveBases(op, active_basis, NULL)); 180506b1a0cSSebastian Grimberg return CEED_ERROR_SUCCESS; 181506b1a0cSSebastian Grimberg } 182506b1a0cSSebastian Grimberg 183506b1a0cSSebastian Grimberg /** 184681d0ea7SJeremy L Thompson @brief Find the active input and output vector `CeedBasis` for a non-composite `CeedOperator`. 185681d0ea7SJeremy L Thompson 186681d0ea7SJeremy L Thompson Note: Caller is responsible for destroying the bases with @ref CeedBasisDestroy(). 187506b1a0cSSebastian Grimberg 188ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to find active `CeedBasis` for 189ca94c3ddSJeremy L Thompson @param[out] active_input_basis `CeedBasis` for active input vector or `NULL` for composite operator 190ca94c3ddSJeremy L Thompson @param[out] active_output_basis `CeedBasis` for active output vector or `NULL` for composite operator 191506b1a0cSSebastian Grimberg 192506b1a0cSSebastian Grimberg @return An error code: 0 - success, otherwise - failure 193506b1a0cSSebastian Grimberg 194506b1a0cSSebastian Grimberg @ref Developer 195506b1a0cSSebastian Grimberg **/ 196506b1a0cSSebastian Grimberg int CeedOperatorGetActiveBases(CeedOperator op, CeedBasis *active_input_basis, CeedBasis *active_output_basis) { 1971203703bSJeremy L Thompson bool is_composite; 1981203703bSJeremy L Thompson CeedInt num_input_fields, num_output_fields; 1991203703bSJeremy L Thompson CeedOperatorField *op_input_fields, *op_output_fields; 2001c66c397SJeremy L Thompson 2011203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 2021203703bSJeremy L Thompson CeedCall(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields)); 2031203703bSJeremy L Thompson 204506b1a0cSSebastian Grimberg if (active_input_basis) { 205506b1a0cSSebastian Grimberg *active_input_basis = NULL; 2061203703bSJeremy L Thompson if (!is_composite) { 2071203703bSJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 2081203703bSJeremy L Thompson CeedVector vec; 2091203703bSJeremy L Thompson 2101203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(op_input_fields[i], &vec)); 2111203703bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 2121203703bSJeremy L Thompson CeedBasis basis; 2131203703bSJeremy L Thompson 2141203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetBasis(op_input_fields[i], &basis)); 2159bc66399SJeremy L Thompson CeedCheck(!*active_input_basis || *active_input_basis == basis, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, 2169bc66399SJeremy L Thompson "Multiple active input CeedBases found"); 217681d0ea7SJeremy L Thompson if (!*active_input_basis) CeedCall(CeedBasisReferenceCopy(basis, active_input_basis)); 218681d0ea7SJeremy L Thompson CeedCall(CeedBasisDestroy(&basis)); 219eaf62fffSJeremy L Thompson } 220681d0ea7SJeremy L Thompson CeedCall(CeedVectorDestroy(&vec)); 2212b730f8bSJeremy L Thompson } 2229bc66399SJeremy L Thompson CeedCheck(*active_input_basis, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPLETE, "No active input CeedBasis found"); 223506b1a0cSSebastian Grimberg } 224506b1a0cSSebastian Grimberg } 225506b1a0cSSebastian Grimberg if (active_output_basis) { 226506b1a0cSSebastian Grimberg *active_output_basis = NULL; 2271203703bSJeremy L Thompson if (!is_composite) { 2281203703bSJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 2291203703bSJeremy L Thompson CeedVector vec; 2301203703bSJeremy L Thompson 2311203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(op_output_fields[i], &vec)); 2321203703bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 2331203703bSJeremy L Thompson CeedBasis basis; 2341203703bSJeremy L Thompson 2351203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetBasis(op_output_fields[i], &basis)); 2369bc66399SJeremy L Thompson CeedCheck(!*active_output_basis || *active_output_basis == basis, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, 2379bc66399SJeremy L Thompson "Multiple active output CeedBases found"); 238681d0ea7SJeremy L Thompson if (!*active_output_basis) CeedCall(CeedBasisReferenceCopy(basis, active_output_basis)); 239681d0ea7SJeremy L Thompson CeedCall(CeedBasisDestroy(&basis)); 240506b1a0cSSebastian Grimberg } 241681d0ea7SJeremy L Thompson CeedCall(CeedVectorDestroy(&vec)); 242506b1a0cSSebastian Grimberg } 2439bc66399SJeremy L Thompson CeedCheck(*active_output_basis, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPLETE, "No active output CeedBasis found"); 244506b1a0cSSebastian Grimberg } 245506b1a0cSSebastian Grimberg } 246eaf62fffSJeremy L Thompson return CEED_ERROR_SUCCESS; 247eaf62fffSJeremy L Thompson } 248eaf62fffSJeremy L Thompson 249eaf62fffSJeremy L Thompson /** 250681d0ea7SJeremy L Thompson @brief Find the active vector `CeedElemRestriction` for a non-composite `CeedOperator`. 251681d0ea7SJeremy L Thompson 252681d0ea7SJeremy L Thompson Note: Caller is responsible for destroying the `active_rstr` with @ref CeedElemRestrictionDestroy(). 253e2f04181SAndrew T. Barker 254ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to find active `CeedElemRestriction` for 255ca94c3ddSJeremy L Thompson @param[out] active_rstr `CeedElemRestriction` for active input vector or NULL for composite operator 256e2f04181SAndrew T. Barker 257e2f04181SAndrew T. Barker @return An error code: 0 - success, otherwise - failure 258e2f04181SAndrew T. Barker 259e2f04181SAndrew T. Barker @ref Utility 260e2f04181SAndrew T. Barker **/ 2612b730f8bSJeremy L Thompson int CeedOperatorGetActiveElemRestriction(CeedOperator op, CeedElemRestriction *active_rstr) { 262506b1a0cSSebastian Grimberg CeedCall(CeedOperatorGetActiveElemRestrictions(op, active_rstr, NULL)); 263506b1a0cSSebastian Grimberg return CEED_ERROR_SUCCESS; 264506b1a0cSSebastian Grimberg } 265506b1a0cSSebastian Grimberg 266506b1a0cSSebastian Grimberg /** 267681d0ea7SJeremy L Thompson @brief Find the active input and output vector `CeedElemRestriction` for a non-composite `CeedOperator`. 268681d0ea7SJeremy L Thompson 269681d0ea7SJeremy L Thompson Note: Caller is responsible for destroying the restrictions with @ref CeedElemRestrictionDestroy(). 270506b1a0cSSebastian Grimberg 271ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to find active `CeedElemRestriction` for 272ca94c3ddSJeremy L Thompson @param[out] active_input_rstr `CeedElemRestriction` for active input vector or NULL for composite operator 273ca94c3ddSJeremy L Thompson @param[out] active_output_rstr `CeedElemRestriction` for active output vector or NULL for composite operator 274506b1a0cSSebastian Grimberg 275506b1a0cSSebastian Grimberg @return An error code: 0 - success, otherwise - failure 276506b1a0cSSebastian Grimberg 277506b1a0cSSebastian Grimberg @ref Utility 278506b1a0cSSebastian Grimberg **/ 279506b1a0cSSebastian Grimberg int CeedOperatorGetActiveElemRestrictions(CeedOperator op, CeedElemRestriction *active_input_rstr, CeedElemRestriction *active_output_rstr) { 2801203703bSJeremy L Thompson bool is_composite; 2811203703bSJeremy L Thompson CeedInt num_input_fields, num_output_fields; 2821203703bSJeremy L Thompson CeedOperatorField *op_input_fields, *op_output_fields; 2831c66c397SJeremy L Thompson 2841203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 2851203703bSJeremy L Thompson CeedCall(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields)); 2861203703bSJeremy L Thompson 287506b1a0cSSebastian Grimberg if (active_input_rstr) { 288506b1a0cSSebastian Grimberg *active_input_rstr = NULL; 2891203703bSJeremy L Thompson if (!is_composite) { 2901203703bSJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 2911203703bSJeremy L Thompson CeedVector vec; 2921203703bSJeremy L Thompson 2931203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(op_input_fields[i], &vec)); 2941203703bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 2951203703bSJeremy L Thompson CeedElemRestriction rstr; 2961203703bSJeremy L Thompson 2971203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetElemRestriction(op_input_fields[i], &rstr)); 2989bc66399SJeremy L Thompson CeedCheck(!*active_input_rstr || *active_input_rstr == rstr, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, 2999bc66399SJeremy L Thompson "Multiple active input CeedElemRestrictions found"); 300681d0ea7SJeremy L Thompson if (!*active_input_rstr) CeedCall(CeedElemRestrictionReferenceCopy(rstr, active_input_rstr)); 301681d0ea7SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&rstr)); 302e2f04181SAndrew T. Barker } 303681d0ea7SJeremy L Thompson CeedCall(CeedVectorDestroy(&vec)); 3042b730f8bSJeremy L Thompson } 3059bc66399SJeremy L Thompson CeedCheck(*active_input_rstr, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPLETE, "No active input CeedElemRestriction found"); 306506b1a0cSSebastian Grimberg } 307506b1a0cSSebastian Grimberg } 308506b1a0cSSebastian Grimberg if (active_output_rstr) { 309506b1a0cSSebastian Grimberg *active_output_rstr = NULL; 3101203703bSJeremy L Thompson if (!is_composite) { 3111203703bSJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 3121203703bSJeremy L Thompson CeedVector vec; 3131203703bSJeremy L Thompson 3141203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(op_output_fields[i], &vec)); 3151203703bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 3161203703bSJeremy L Thompson CeedElemRestriction rstr; 3171203703bSJeremy L Thompson 3181203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetElemRestriction(op_output_fields[i], &rstr)); 3199bc66399SJeremy L Thompson CeedCheck(!*active_output_rstr || *active_output_rstr == rstr, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, 3209bc66399SJeremy L Thompson "Multiple active output CeedElemRestrictions found"); 321681d0ea7SJeremy L Thompson if (!*active_output_rstr) CeedCall(CeedElemRestrictionReferenceCopy(rstr, active_output_rstr)); 322681d0ea7SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&rstr)); 323506b1a0cSSebastian Grimberg } 324681d0ea7SJeremy L Thompson CeedCall(CeedVectorDestroy(&vec)); 325506b1a0cSSebastian Grimberg } 3269bc66399SJeremy L Thompson CeedCheck(*active_output_rstr, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPLETE, "No active output CeedElemRestriction found"); 327506b1a0cSSebastian Grimberg } 328506b1a0cSSebastian Grimberg } 329e2f04181SAndrew T. Barker return CEED_ERROR_SUCCESS; 330e2f04181SAndrew T. Barker } 331e2f04181SAndrew T. Barker 332d8dd9a91SJeremy L Thompson /** 333ca94c3ddSJeremy L Thompson @brief Set `CeedQFunctionContext` field values of the specified type. 3344385fb7fSSebastian Grimberg 335ca94c3ddSJeremy L Thompson For composite operators, the value is set in all sub-operator `CeedQFunctionContext` that have a matching `field_name`. 336ca94c3ddSJeremy 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. 337d8dd9a91SJeremy L Thompson 338ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 339ea61e9acSJeremy L Thompson @param[in] field_label Label of field to set 340ea61e9acSJeremy L Thompson @param[in] field_type Type of field to set 3412788fa27SJeremy L Thompson @param[in] values Values to set 342d8dd9a91SJeremy L Thompson 343d8dd9a91SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 344d8dd9a91SJeremy L Thompson 345d8dd9a91SJeremy L Thompson @ref User 346d8dd9a91SJeremy L Thompson **/ 3472788fa27SJeremy L Thompson static int CeedOperatorContextSetGeneric(CeedOperator op, CeedContextFieldLabel field_label, CeedContextFieldType field_type, void *values) { 3481c66c397SJeremy L Thompson bool is_composite = false; 3491c66c397SJeremy L Thompson 3509bc66399SJeremy L Thompson CeedCheck(field_label, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "Invalid field label"); 3513668ca4bSJeremy L Thompson 3525ac9af79SJeremy L Thompson // Check if field_label and op correspond 3535ac9af79SJeremy L Thompson if (field_label->from_op) { 3545ac9af79SJeremy L Thompson CeedInt index = -1; 3555ac9af79SJeremy L Thompson 3565ac9af79SJeremy L Thompson for (CeedInt i = 0; i < op->num_context_labels; i++) { 3575ac9af79SJeremy L Thompson if (op->context_labels[i] == field_label) index = i; 3585ac9af79SJeremy L Thompson } 3599bc66399SJeremy L Thompson CeedCheck(index != -1, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "ContextFieldLabel does not correspond to the operator"); 3605ac9af79SJeremy L Thompson } 3615ac9af79SJeremy L Thompson 3622b730f8bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 363d8dd9a91SJeremy L Thompson if (is_composite) { 364d8dd9a91SJeremy L Thompson CeedInt num_sub; 365d8dd9a91SJeremy L Thompson CeedOperator *sub_operators; 366d8dd9a91SJeremy L Thompson 367c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub)); 368c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 3699bc66399SJeremy L Thompson CeedCheck(num_sub == field_label->num_sub_labels, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, 3709bc66399SJeremy L Thompson "Composite operator modified after ContextFieldLabel created"); 371d8dd9a91SJeremy L Thompson 372d8dd9a91SJeremy L Thompson for (CeedInt i = 0; i < num_sub; i++) { 3731203703bSJeremy L Thompson CeedQFunctionContext ctx; 3741203703bSJeremy L Thompson 375*1485364cSJeremy L Thompson CeedCall(CeedOperatorGetContext(sub_operators[i], &ctx)); 376d8dd9a91SJeremy L Thompson // Try every sub-operator, ok if some sub-operators do not have field 377*1485364cSJeremy L Thompson if (ctx && field_label->sub_labels[i]) { 3781203703bSJeremy L Thompson CeedCall(CeedQFunctionContextSetGeneric(ctx, field_label->sub_labels[i], field_type, values)); 379d8dd9a91SJeremy L Thompson } 380*1485364cSJeremy L Thompson CeedCall(CeedQFunctionContextDestroy(&ctx)); 381d8dd9a91SJeremy L Thompson } 382d8dd9a91SJeremy L Thompson } else { 3831203703bSJeremy L Thompson CeedQFunctionContext ctx; 3841203703bSJeremy L Thompson 385*1485364cSJeremy L Thompson CeedCall(CeedOperatorGetContext(op, &ctx)); 3869bc66399SJeremy L Thompson CeedCheck(ctx, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "QFunction does not have context data"); 3871203703bSJeremy L Thompson CeedCall(CeedQFunctionContextSetGeneric(ctx, field_label, field_type, values)); 388*1485364cSJeremy L Thompson CeedCall(CeedQFunctionContextDestroy(&ctx)); 3892788fa27SJeremy L Thompson } 3906d95ab46SJeremy L Thompson CeedCall(CeedOperatorSetQFunctionAssemblyDataUpdateNeeded(op, true)); 3912788fa27SJeremy L Thompson return CEED_ERROR_SUCCESS; 3922788fa27SJeremy L Thompson } 3932788fa27SJeremy L Thompson 3942788fa27SJeremy L Thompson /** 395ca94c3ddSJeremy L Thompson @brief Get `CeedQFunctionContext` field values of the specified type, read-only. 3964385fb7fSSebastian Grimberg 397ca94c3ddSJeremy L Thompson For composite operators, the values retrieved are for the first sub-operator `CeedQFunctionContext` that have a matching `field_name`. 398ca94c3ddSJeremy 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. 3992788fa27SJeremy L Thompson 400ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 4012788fa27SJeremy L Thompson @param[in] field_label Label of field to set 4022788fa27SJeremy L Thompson @param[in] field_type Type of field to set 403c5d0f995SJed Brown @param[out] num_values Number of values of type `field_type` in array `values` 404c5d0f995SJed Brown @param[out] values Values in the label 4052788fa27SJeremy L Thompson 4062788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 4072788fa27SJeremy L Thompson 4082788fa27SJeremy L Thompson @ref User 4092788fa27SJeremy L Thompson **/ 4102788fa27SJeremy L Thompson static int CeedOperatorContextGetGenericRead(CeedOperator op, CeedContextFieldLabel field_label, CeedContextFieldType field_type, size_t *num_values, 4112788fa27SJeremy L Thompson void *values) { 4121c66c397SJeremy L Thompson bool is_composite = false; 4131c66c397SJeremy L Thompson 4149bc66399SJeremy L Thompson CeedCheck(field_label, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "Invalid field label"); 4152788fa27SJeremy L Thompson 4162788fa27SJeremy L Thompson *(void **)values = NULL; 4172788fa27SJeremy L Thompson *num_values = 0; 4182788fa27SJeremy L Thompson 4195ac9af79SJeremy L Thompson // Check if field_label and op correspond 4205ac9af79SJeremy L Thompson if (field_label->from_op) { 4215ac9af79SJeremy L Thompson CeedInt index = -1; 4225ac9af79SJeremy L Thompson 4235ac9af79SJeremy L Thompson for (CeedInt i = 0; i < op->num_context_labels; i++) { 4245ac9af79SJeremy L Thompson if (op->context_labels[i] == field_label) index = i; 4255ac9af79SJeremy L Thompson } 4269bc66399SJeremy L Thompson CeedCheck(index != -1, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "ContextFieldLabel does not correspond to the operator"); 4275ac9af79SJeremy L Thompson } 4285ac9af79SJeremy L Thompson 4292788fa27SJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 4302788fa27SJeremy L Thompson if (is_composite) { 4312788fa27SJeremy L Thompson CeedInt num_sub; 4322788fa27SJeremy L Thompson CeedOperator *sub_operators; 4332788fa27SJeremy L Thompson 4342788fa27SJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub)); 4352788fa27SJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 4369bc66399SJeremy L Thompson CeedCheck(num_sub == field_label->num_sub_labels, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, 4379bc66399SJeremy L Thompson "Composite operator modified after ContextFieldLabel created"); 4382788fa27SJeremy L Thompson 4392788fa27SJeremy L Thompson for (CeedInt i = 0; i < num_sub; i++) { 4401203703bSJeremy L Thompson CeedQFunctionContext ctx; 4411203703bSJeremy L Thompson 442*1485364cSJeremy L Thompson CeedCall(CeedOperatorGetContext(sub_operators[i], &ctx)); 4432788fa27SJeremy L Thompson // Try every sub-operator, ok if some sub-operators do not have field 444*1485364cSJeremy L Thompson if (ctx && field_label->sub_labels[i]) { 4451203703bSJeremy L Thompson CeedCall(CeedQFunctionContextGetGenericRead(ctx, field_label->sub_labels[i], field_type, num_values, values)); 446*1485364cSJeremy L Thompson CeedCall(CeedQFunctionContextDestroy(&ctx)); 4472788fa27SJeremy L Thompson return CEED_ERROR_SUCCESS; 4482788fa27SJeremy L Thompson } 449*1485364cSJeremy L Thompson CeedCall(CeedQFunctionContextDestroy(&ctx)); 4502788fa27SJeremy L Thompson } 4512788fa27SJeremy L Thompson } else { 4521203703bSJeremy L Thompson CeedQFunctionContext ctx; 4531203703bSJeremy L Thompson 454*1485364cSJeremy L Thompson CeedCall(CeedOperatorGetContext(op, &ctx)); 4559bc66399SJeremy L Thompson CeedCheck(ctx, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "QFunction does not have context data"); 4561203703bSJeremy L Thompson CeedCall(CeedQFunctionContextGetGenericRead(ctx, field_label, field_type, num_values, values)); 457*1485364cSJeremy L Thompson CeedCall(CeedQFunctionContextDestroy(&ctx)); 4582788fa27SJeremy L Thompson } 4592788fa27SJeremy L Thompson return CEED_ERROR_SUCCESS; 4602788fa27SJeremy L Thompson } 4612788fa27SJeremy L Thompson 4622788fa27SJeremy L Thompson /** 463ca94c3ddSJeremy L Thompson @brief Restore `CeedQFunctionContext` field values of the specified type, read-only. 4644385fb7fSSebastian Grimberg 465ca94c3ddSJeremy L Thompson For composite operators, the values restored are for the first sub-operator `CeedQFunctionContext` that have a matching `field_name`. 466ca94c3ddSJeremy 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. 4672788fa27SJeremy L Thompson 468ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 4692788fa27SJeremy L Thompson @param[in] field_label Label of field to set 4702788fa27SJeremy L Thompson @param[in] field_type Type of field to set 471c5d0f995SJed Brown @param[in] values Values array to restore 4722788fa27SJeremy L Thompson 4732788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 4742788fa27SJeremy L Thompson 4752788fa27SJeremy L Thompson @ref User 4762788fa27SJeremy L Thompson **/ 4772788fa27SJeremy L Thompson static int CeedOperatorContextRestoreGenericRead(CeedOperator op, CeedContextFieldLabel field_label, CeedContextFieldType field_type, void *values) { 4781c66c397SJeremy L Thompson bool is_composite = false; 4791c66c397SJeremy L Thompson 4809bc66399SJeremy L Thompson CeedCheck(field_label, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "Invalid field label"); 4812788fa27SJeremy L Thompson 4825ac9af79SJeremy L Thompson // Check if field_label and op correspond 4835ac9af79SJeremy L Thompson if (field_label->from_op) { 4845ac9af79SJeremy L Thompson CeedInt index = -1; 4855ac9af79SJeremy L Thompson 4865ac9af79SJeremy L Thompson for (CeedInt i = 0; i < op->num_context_labels; i++) { 4875ac9af79SJeremy L Thompson if (op->context_labels[i] == field_label) index = i; 4885ac9af79SJeremy L Thompson } 4899bc66399SJeremy L Thompson CeedCheck(index != -1, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "ContextFieldLabel does not correspond to the operator"); 4905ac9af79SJeremy L Thompson } 4915ac9af79SJeremy L Thompson 4922788fa27SJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 4932788fa27SJeremy L Thompson if (is_composite) { 4942788fa27SJeremy L Thompson CeedInt num_sub; 4952788fa27SJeremy L Thompson CeedOperator *sub_operators; 4962788fa27SJeremy L Thompson 4972788fa27SJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub)); 4982788fa27SJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 4999bc66399SJeremy L Thompson CeedCheck(num_sub == field_label->num_sub_labels, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, 5009bc66399SJeremy L Thompson "Composite operator modified after ContextFieldLabel created"); 5012788fa27SJeremy L Thompson 5022788fa27SJeremy L Thompson for (CeedInt i = 0; i < num_sub; i++) { 5031203703bSJeremy L Thompson CeedQFunctionContext ctx; 5041203703bSJeremy L Thompson 505*1485364cSJeremy L Thompson CeedCall(CeedOperatorGetContext(sub_operators[i], &ctx)); 5062788fa27SJeremy L Thompson // Try every sub-operator, ok if some sub-operators do not have field 507*1485364cSJeremy L Thompson if (ctx && field_label->sub_labels[i]) { 5081203703bSJeremy L Thompson CeedCall(CeedQFunctionContextRestoreGenericRead(ctx, field_label->sub_labels[i], field_type, values)); 509*1485364cSJeremy L Thompson CeedCall(CeedQFunctionContextDestroy(&ctx)); 5102788fa27SJeremy L Thompson return CEED_ERROR_SUCCESS; 5112788fa27SJeremy L Thompson } 512*1485364cSJeremy L Thompson CeedCall(CeedQFunctionContextDestroy(&ctx)); 5132788fa27SJeremy L Thompson } 5142788fa27SJeremy L Thompson } else { 5151203703bSJeremy L Thompson CeedQFunctionContext ctx; 5161203703bSJeremy L Thompson 517*1485364cSJeremy L Thompson CeedCall(CeedOperatorGetContext(op, &ctx)); 5189bc66399SJeremy L Thompson CeedCheck(ctx, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "QFunction does not have context data"); 5191203703bSJeremy L Thompson CeedCall(CeedQFunctionContextRestoreGenericRead(ctx, field_label, field_type, values)); 520*1485364cSJeremy L Thompson CeedCall(CeedQFunctionContextDestroy(&ctx)); 521d8dd9a91SJeremy L Thompson } 522d8dd9a91SJeremy L Thompson return CEED_ERROR_SUCCESS; 523d8dd9a91SJeremy L Thompson } 524d8dd9a91SJeremy L Thompson 5257a982d89SJeremy L. Thompson /// @} 5267a982d89SJeremy L. Thompson 5277a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 5287a982d89SJeremy L. Thompson /// CeedOperator Backend API 5297a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 5307a982d89SJeremy L. Thompson /// @addtogroup CeedOperatorBackend 5317a982d89SJeremy L. Thompson /// @{ 5327a982d89SJeremy L. Thompson 5337a982d89SJeremy L. Thompson /** 534ca94c3ddSJeremy L Thompson @brief Get the number of arguments associated with a `CeedOperator` 5357a982d89SJeremy L. Thompson 536ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 537d1d35e2fSjeremylt @param[out] num_args Variable to store vector number of arguments 5387a982d89SJeremy L. Thompson 5397a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 5407a982d89SJeremy L. Thompson 5417a982d89SJeremy L. Thompson @ref Backend 5427a982d89SJeremy L. Thompson **/ 543d1d35e2fSjeremylt int CeedOperatorGetNumArgs(CeedOperator op, CeedInt *num_args) { 5441203703bSJeremy L Thompson bool is_composite; 5451203703bSJeremy L Thompson 5461203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 5476e536b99SJeremy L Thompson CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Not defined for composite operators"); 548d1d35e2fSjeremylt *num_args = op->num_fields; 549e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 5507a982d89SJeremy L. Thompson } 5517a982d89SJeremy L. Thompson 5527a982d89SJeremy L. Thompson /** 5539463e855SJeremy L Thompson @brief Get the tensor product status of all bases for a `CeedOperator`. 5549463e855SJeremy L Thompson 5559463e855SJeremy L Thompson `has_tensor_bases` is only set to `true` if every field uses a tensor-product basis. 5569463e855SJeremy L Thompson 5579463e855SJeremy L Thompson @param[in] op `CeedOperator` 5589463e855SJeremy L Thompson @param[out] has_tensor_bases Variable to store tensor bases status 5599463e855SJeremy L Thompson 5609463e855SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 5619463e855SJeremy L Thompson 5629463e855SJeremy L Thompson @ref Backend 5639463e855SJeremy L Thompson **/ 5649463e855SJeremy L Thompson int CeedOperatorHasTensorBases(CeedOperator op, bool *has_tensor_bases) { 5659463e855SJeremy L Thompson CeedInt num_inputs, num_outputs; 5669463e855SJeremy L Thompson CeedOperatorField *input_fields, *output_fields; 5679463e855SJeremy L Thompson 5689463e855SJeremy L Thompson CeedCall(CeedOperatorGetFields(op, &num_inputs, &input_fields, &num_outputs, &output_fields)); 5699463e855SJeremy L Thompson *has_tensor_bases = true; 5709463e855SJeremy L Thompson for (CeedInt i = 0; i < num_inputs; i++) { 5719463e855SJeremy L Thompson bool is_tensor; 5729463e855SJeremy L Thompson CeedBasis basis; 5739463e855SJeremy L Thompson 5749463e855SJeremy L Thompson CeedCall(CeedOperatorFieldGetBasis(input_fields[i], &basis)); 5759463e855SJeremy L Thompson if (basis != CEED_BASIS_NONE) { 5769463e855SJeremy L Thompson CeedCall(CeedBasisIsTensor(basis, &is_tensor)); 5779463e855SJeremy L Thompson *has_tensor_bases &= is_tensor; 5789463e855SJeremy L Thompson } 579681d0ea7SJeremy L Thompson CeedCall(CeedBasisDestroy(&basis)); 5809463e855SJeremy L Thompson } 5819463e855SJeremy L Thompson for (CeedInt i = 0; i < num_outputs; i++) { 5829463e855SJeremy L Thompson bool is_tensor; 5839463e855SJeremy L Thompson CeedBasis basis; 5849463e855SJeremy L Thompson 5859463e855SJeremy L Thompson CeedCall(CeedOperatorFieldGetBasis(output_fields[i], &basis)); 5869463e855SJeremy L Thompson if (basis != CEED_BASIS_NONE) { 5879463e855SJeremy L Thompson CeedCall(CeedBasisIsTensor(basis, &is_tensor)); 5889463e855SJeremy L Thompson *has_tensor_bases &= is_tensor; 5899463e855SJeremy L Thompson } 590681d0ea7SJeremy L Thompson CeedCall(CeedBasisDestroy(&basis)); 5919463e855SJeremy L Thompson } 5929463e855SJeremy L Thompson return CEED_ERROR_SUCCESS; 5939463e855SJeremy L Thompson } 5949463e855SJeremy L Thompson 5959463e855SJeremy L Thompson /** 5961203703bSJeremy L Thompson @brief Get a boolean value indicating if the `CeedOperator` is immutable 5971203703bSJeremy L Thompson 5981203703bSJeremy L Thompson @param[in] op `CeedOperator` 5991203703bSJeremy L Thompson @param[out] is_immutable Variable to store immutability status 6001203703bSJeremy L Thompson 6011203703bSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 6021203703bSJeremy L Thompson 6031203703bSJeremy L Thompson @ref Backend 6041203703bSJeremy L Thompson **/ 6051203703bSJeremy L Thompson int CeedOperatorIsImmutable(CeedOperator op, bool *is_immutable) { 6061203703bSJeremy L Thompson *is_immutable = op->is_immutable; 6071203703bSJeremy L Thompson return CEED_ERROR_SUCCESS; 6081203703bSJeremy L Thompson } 6091203703bSJeremy L Thompson 6101203703bSJeremy L Thompson /** 611ca94c3ddSJeremy L Thompson @brief Get the setup status of a `CeedOperator` 6127a982d89SJeremy L. Thompson 613ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 614d1d35e2fSjeremylt @param[out] is_setup_done Variable to store setup status 6157a982d89SJeremy L. Thompson 6167a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 6177a982d89SJeremy L. Thompson 6187a982d89SJeremy L. Thompson @ref Backend 6197a982d89SJeremy L. Thompson **/ 620d1d35e2fSjeremylt int CeedOperatorIsSetupDone(CeedOperator op, bool *is_setup_done) { 621f04ea552SJeremy L Thompson *is_setup_done = op->is_backend_setup; 622e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 6237a982d89SJeremy L. Thompson } 6247a982d89SJeremy L. Thompson 6257a982d89SJeremy L. Thompson /** 626ca94c3ddSJeremy L Thompson @brief Get the `CeedQFunction` associated with a `CeedOperator` 6277a982d89SJeremy L. Thompson 628ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 629ca94c3ddSJeremy L Thompson @param[out] qf Variable to store `CeedQFunction` 6307a982d89SJeremy L. Thompson 6317a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 6327a982d89SJeremy L. Thompson 6337a982d89SJeremy L. Thompson @ref Backend 6347a982d89SJeremy L. Thompson **/ 6357a982d89SJeremy L. Thompson int CeedOperatorGetQFunction(CeedOperator op, CeedQFunction *qf) { 6361203703bSJeremy L Thompson bool is_composite; 6371203703bSJeremy L Thompson 6381203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 6396e536b99SJeremy L Thompson CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Not defined for composite operator"); 640c11e12f4SJeremy L Thompson *qf = NULL; 641c11e12f4SJeremy L Thompson CeedCall(CeedQFunctionReferenceCopy(op->qf, qf)); 642e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 6437a982d89SJeremy L. Thompson } 6447a982d89SJeremy L. Thompson 6457a982d89SJeremy L. Thompson /** 646ca94c3ddSJeremy L Thompson @brief Get a boolean value indicating if the `CeedOperator` is composite 647c04a41a7SJeremy L Thompson 648ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 649d1d35e2fSjeremylt @param[out] is_composite Variable to store composite status 650c04a41a7SJeremy L Thompson 651c04a41a7SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 652c04a41a7SJeremy L Thompson 653c04a41a7SJeremy L Thompson @ref Backend 654c04a41a7SJeremy L Thompson **/ 655d1d35e2fSjeremylt int CeedOperatorIsComposite(CeedOperator op, bool *is_composite) { 656f04ea552SJeremy L Thompson *is_composite = op->is_composite; 657e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 658c04a41a7SJeremy L Thompson } 659c04a41a7SJeremy L Thompson 660c04a41a7SJeremy L Thompson /** 661ca94c3ddSJeremy L Thompson @brief Get the backend data of a `CeedOperator` 6627a982d89SJeremy L. Thompson 663ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 6647a982d89SJeremy L. Thompson @param[out] data Variable to store data 6657a982d89SJeremy L. Thompson 6667a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 6677a982d89SJeremy L. Thompson 6687a982d89SJeremy L. Thompson @ref Backend 6697a982d89SJeremy L. Thompson **/ 670777ff853SJeremy L Thompson int CeedOperatorGetData(CeedOperator op, void *data) { 671777ff853SJeremy L Thompson *(void **)data = op->data; 672e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 6737a982d89SJeremy L. Thompson } 6747a982d89SJeremy L. Thompson 6757a982d89SJeremy L. Thompson /** 676ca94c3ddSJeremy L Thompson @brief Set the backend data of a `CeedOperator` 6777a982d89SJeremy L. Thompson 678ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 679ea61e9acSJeremy L Thompson @param[in] data Data to set 6807a982d89SJeremy L. Thompson 6817a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 6827a982d89SJeremy L. Thompson 6837a982d89SJeremy L. Thompson @ref Backend 6847a982d89SJeremy L. Thompson **/ 685777ff853SJeremy L Thompson int CeedOperatorSetData(CeedOperator op, void *data) { 686777ff853SJeremy L Thompson op->data = data; 687e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 6887a982d89SJeremy L. Thompson } 6897a982d89SJeremy L. Thompson 6907a982d89SJeremy L. Thompson /** 691ca94c3ddSJeremy L Thompson @brief Increment the reference counter for a `CeedOperator` 69234359f16Sjeremylt 693ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` to increment the reference counter 69434359f16Sjeremylt 69534359f16Sjeremylt @return An error code: 0 - success, otherwise - failure 69634359f16Sjeremylt 69734359f16Sjeremylt @ref Backend 69834359f16Sjeremylt **/ 6999560d06aSjeremylt int CeedOperatorReference(CeedOperator op) { 70034359f16Sjeremylt op->ref_count++; 70134359f16Sjeremylt return CEED_ERROR_SUCCESS; 70234359f16Sjeremylt } 70334359f16Sjeremylt 70434359f16Sjeremylt /** 705ca94c3ddSJeremy L Thompson @brief Set the setup flag of a `CeedOperator` to `true` 7067a982d89SJeremy L. Thompson 707ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 7087a982d89SJeremy L. Thompson 7097a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 7107a982d89SJeremy L. Thompson 7117a982d89SJeremy L. Thompson @ref Backend 7127a982d89SJeremy L. Thompson **/ 7137a982d89SJeremy L. Thompson int CeedOperatorSetSetupDone(CeedOperator op) { 714f04ea552SJeremy L Thompson op->is_backend_setup = true; 715e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 7167a982d89SJeremy L. Thompson } 7177a982d89SJeremy L. Thompson 7187a982d89SJeremy L. Thompson /// @} 7197a982d89SJeremy L. Thompson 7207a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 7217a982d89SJeremy L. Thompson /// CeedOperator Public API 7227a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 7237a982d89SJeremy L. Thompson /// @addtogroup CeedOperatorUser 724dfdf5a53Sjeremylt /// @{ 725d7b241e6Sjeremylt 726d7b241e6Sjeremylt /** 727ca94c3ddSJeremy L Thompson @brief Create a `CeedOperator` and associate a `CeedQFunction`. 7284385fb7fSSebastian Grimberg 729ca94c3ddSJeremy L Thompson A `CeedBasis` and `CeedElemRestriction` can be associated with `CeedQFunction` fields with @ref CeedOperatorSetField(). 730d7b241e6Sjeremylt 731ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` object used to create the `CeedOperator` 732ca94c3ddSJeremy L Thompson @param[in] qf `CeedQFunction` defining the action of the operator at quadrature points 733ca94c3ddSJeremy L Thompson @param[in] dqf `CeedQFunction` defining the action of the Jacobian of `qf` (or @ref CEED_QFUNCTION_NONE) 734ca94c3ddSJeremy L Thompson @param[in] dqfT `CeedQFunction` defining the action of the transpose of the Jacobian of `qf` (or @ref CEED_QFUNCTION_NONE) 735ca94c3ddSJeremy L Thompson @param[out] op Address of the variable where the newly created `CeedOperator` will be stored 736b11c1e72Sjeremylt 737b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 738dfdf5a53Sjeremylt 7397a982d89SJeremy L. Thompson @ref User 740d7b241e6Sjeremylt */ 7412b730f8bSJeremy L Thompson int CeedOperatorCreate(Ceed ceed, CeedQFunction qf, CeedQFunction dqf, CeedQFunction dqfT, CeedOperator *op) { 7425fe0d4faSjeremylt if (!ceed->OperatorCreate) { 7435fe0d4faSjeremylt Ceed delegate; 7446574a04fSJeremy L Thompson 7452b730f8bSJeremy L Thompson CeedCall(CeedGetObjectDelegate(ceed, &delegate, "Operator")); 7461ef3a2a9SJeremy L Thompson CeedCheck(delegate, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not implement CeedOperatorCreate"); 7472b730f8bSJeremy L Thompson CeedCall(CeedOperatorCreate(delegate, qf, dqf, dqfT, op)); 7489bc66399SJeremy L Thompson CeedCall(CeedDestroy(&delegate)); 749e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 7505fe0d4faSjeremylt } 7515fe0d4faSjeremylt 752ca94c3ddSJeremy L Thompson CeedCheck(qf && qf != CEED_QFUNCTION_NONE, ceed, CEED_ERROR_MINOR, "Operator must have a valid CeedQFunction."); 753db002c03SJeremy L Thompson 7542b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, op)); 755db002c03SJeremy L Thompson CeedCall(CeedReferenceCopy(ceed, &(*op)->ceed)); 756d1d35e2fSjeremylt (*op)->ref_count = 1; 7572b104005SJeremy L Thompson (*op)->input_size = -1; 7582b104005SJeremy L Thompson (*op)->output_size = -1; 759db002c03SJeremy L Thompson CeedCall(CeedQFunctionReferenceCopy(qf, &(*op)->qf)); 760db002c03SJeremy L Thompson if (dqf && dqf != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionReferenceCopy(dqf, &(*op)->dqf)); 761db002c03SJeremy L Thompson if (dqfT && dqfT != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionReferenceCopy(dqfT, &(*op)->dqfT)); 7622b730f8bSJeremy L Thompson CeedCall(CeedCalloc(CEED_FIELD_MAX, &(*op)->input_fields)); 7632b730f8bSJeremy L Thompson CeedCall(CeedCalloc(CEED_FIELD_MAX, &(*op)->output_fields)); 7642b730f8bSJeremy L Thompson CeedCall(ceed->OperatorCreate(*op)); 765e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 766d7b241e6Sjeremylt } 767d7b241e6Sjeremylt 768d7b241e6Sjeremylt /** 769ca94c3ddSJeremy L Thompson @brief Create a `CeedOperator` for evaluation at evaluation at arbitrary points in each element. 77048acf710SJeremy L Thompson 771ca94c3ddSJeremy L Thompson A `CeedBasis` and `CeedElemRestriction` can be associated with `CeedQFunction` fields with `CeedOperator` SetField. 772ca94c3ddSJeremy L Thompson The locations of each point are set with @ref CeedOperatorAtPointsSetPoints(). 77348acf710SJeremy L Thompson 774ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` object used to create the `CeedOperator` 775ca94c3ddSJeremy L Thompson @param[in] qf `CeedQFunction` defining the action of the operator at quadrature points 776ca94c3ddSJeremy L Thompson @param[in] dqf `CeedQFunction` defining the action of the Jacobian of @a qf (or @ref CEED_QFUNCTION_NONE) 777ca94c3ddSJeremy L Thompson @param[in] dqfT `CeedQFunction` defining the action of the transpose of the Jacobian of @a qf (or @ref CEED_QFUNCTION_NONE) 77848acf710SJeremy L Thompson @param[out] op Address of the variable where the newly created CeedOperator will be stored 77948acf710SJeremy L Thompson 78048acf710SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 78148acf710SJeremy L Thompson 78248acf710SJeremy L Thompson @ref User 78348acf710SJeremy L Thompson */ 78448acf710SJeremy L Thompson int CeedOperatorCreateAtPoints(Ceed ceed, CeedQFunction qf, CeedQFunction dqf, CeedQFunction dqfT, CeedOperator *op) { 78548acf710SJeremy L Thompson if (!ceed->OperatorCreateAtPoints) { 78648acf710SJeremy L Thompson Ceed delegate; 78748acf710SJeremy L Thompson 78848acf710SJeremy L Thompson CeedCall(CeedGetObjectDelegate(ceed, &delegate, "Operator")); 7891ef3a2a9SJeremy L Thompson CeedCheck(delegate, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not implement CeedOperatorCreateAtPoints"); 79048acf710SJeremy L Thompson CeedCall(CeedOperatorCreateAtPoints(delegate, qf, dqf, dqfT, op)); 7919bc66399SJeremy L Thompson CeedCall(CeedDestroy(&delegate)); 79248acf710SJeremy L Thompson return CEED_ERROR_SUCCESS; 79348acf710SJeremy L Thompson } 79448acf710SJeremy L Thompson 795ca94c3ddSJeremy L Thompson CeedCheck(qf && qf != CEED_QFUNCTION_NONE, ceed, CEED_ERROR_MINOR, "Operator must have a valid CeedQFunction."); 79648acf710SJeremy L Thompson 79748acf710SJeremy L Thompson CeedCall(CeedCalloc(1, op)); 79848acf710SJeremy L Thompson CeedCall(CeedReferenceCopy(ceed, &(*op)->ceed)); 79948acf710SJeremy L Thompson (*op)->ref_count = 1; 80048acf710SJeremy L Thompson (*op)->is_at_points = true; 80148acf710SJeremy L Thompson (*op)->input_size = -1; 80248acf710SJeremy L Thompson (*op)->output_size = -1; 80348acf710SJeremy L Thompson CeedCall(CeedQFunctionReferenceCopy(qf, &(*op)->qf)); 80448acf710SJeremy L Thompson if (dqf && dqf != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionReferenceCopy(dqf, &(*op)->dqf)); 80548acf710SJeremy L Thompson if (dqfT && dqfT != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionReferenceCopy(dqfT, &(*op)->dqfT)); 80648acf710SJeremy L Thompson CeedCall(CeedCalloc(CEED_FIELD_MAX, &(*op)->input_fields)); 80748acf710SJeremy L Thompson CeedCall(CeedCalloc(CEED_FIELD_MAX, &(*op)->output_fields)); 80848acf710SJeremy L Thompson CeedCall(ceed->OperatorCreateAtPoints(*op)); 80948acf710SJeremy L Thompson return CEED_ERROR_SUCCESS; 81048acf710SJeremy L Thompson } 81148acf710SJeremy L Thompson 81248acf710SJeremy L Thompson /** 813ca94c3ddSJeremy L Thompson @brief Create a composite `CeedOperator` that composes the action of several `CeedOperator` 81452d6035fSJeremy L Thompson 815ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` object used to create the `CeedOperator` 816ca94c3ddSJeremy L Thompson @param[out] op Address of the variable where the newly created composite `CeedOperator` will be stored 81752d6035fSJeremy L Thompson 81852d6035fSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 81952d6035fSJeremy L Thompson 8207a982d89SJeremy L. Thompson @ref User 82152d6035fSJeremy L Thompson */ 82252d6035fSJeremy L Thompson int CeedCompositeOperatorCreate(Ceed ceed, CeedOperator *op) { 82352d6035fSJeremy L Thompson if (!ceed->CompositeOperatorCreate) { 82452d6035fSJeremy L Thompson Ceed delegate; 82552d6035fSJeremy L Thompson 8261c66c397SJeremy L Thompson CeedCall(CeedGetObjectDelegate(ceed, &delegate, "Operator")); 827250756a7Sjeremylt if (delegate) { 8282b730f8bSJeremy L Thompson CeedCall(CeedCompositeOperatorCreate(delegate, op)); 8299bc66399SJeremy L Thompson CeedCall(CeedDestroy(&delegate)); 830e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 83152d6035fSJeremy L Thompson } 832250756a7Sjeremylt } 83352d6035fSJeremy L Thompson 8342b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, op)); 835db002c03SJeremy L Thompson CeedCall(CeedReferenceCopy(ceed, &(*op)->ceed)); 836996d9ab5SJed Brown (*op)->ref_count = 1; 837f04ea552SJeremy L Thompson (*op)->is_composite = true; 8382b730f8bSJeremy L Thompson CeedCall(CeedCalloc(CEED_COMPOSITE_MAX, &(*op)->sub_operators)); 8392b104005SJeremy L Thompson (*op)->input_size = -1; 8402b104005SJeremy L Thompson (*op)->output_size = -1; 841250756a7Sjeremylt 842db002c03SJeremy L Thompson if (ceed->CompositeOperatorCreate) CeedCall(ceed->CompositeOperatorCreate(*op)); 843e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 84452d6035fSJeremy L Thompson } 84552d6035fSJeremy L Thompson 84652d6035fSJeremy L Thompson /** 847ca94c3ddSJeremy L Thompson @brief Copy the pointer to a `CeedOperator`. 8484385fb7fSSebastian Grimberg 849ca94c3ddSJeremy L Thompson Both pointers should be destroyed with @ref CeedOperatorDestroy(). 850512bb800SJeremy L Thompson 851ca94c3ddSJeremy 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`. 852ca94c3ddSJeremy L Thompson This `CeedOperator` will be destroyed if `*op_copy` is the only reference to this `CeedOperator`. 8539560d06aSjeremylt 854ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to copy reference to 855ea61e9acSJeremy L Thompson @param[in,out] op_copy Variable to store copied reference 8569560d06aSjeremylt 8579560d06aSjeremylt @return An error code: 0 - success, otherwise - failure 8589560d06aSjeremylt 8599560d06aSjeremylt @ref User 8609560d06aSjeremylt **/ 8619560d06aSjeremylt int CeedOperatorReferenceCopy(CeedOperator op, CeedOperator *op_copy) { 8622b730f8bSJeremy L Thompson CeedCall(CeedOperatorReference(op)); 8632b730f8bSJeremy L Thompson CeedCall(CeedOperatorDestroy(op_copy)); 8649560d06aSjeremylt *op_copy = op; 8659560d06aSjeremylt return CEED_ERROR_SUCCESS; 8669560d06aSjeremylt } 8679560d06aSjeremylt 8689560d06aSjeremylt /** 869ca94c3ddSJeremy L Thompson @brief Provide a field to a `CeedOperator` for use by its `CeedQFunction`. 870d7b241e6Sjeremylt 871ca94c3ddSJeremy L Thompson This function is used to specify both active and passive fields to a `CeedOperator`. 872bafebce1SSebastian Grimberg For passive fields, a `CeedVector` `vec` must be provided. 873ea61e9acSJeremy L Thompson Passive fields can inputs or outputs (updated in-place when operator is applied). 874d7b241e6Sjeremylt 875ca94c3ddSJeremy L Thompson Active fields must be specified using this function, but their data (in a `CeedVector`) is passed in @ref CeedOperatorApply(). 876ca94c3ddSJeremy L Thompson There can be at most one active input `CeedVector` and at most one active output@ref CeedVector passed to @ref CeedOperatorApply(). 877d7b241e6Sjeremylt 878528a22edSJeremy L Thompson The number of quadrature points must agree across all points. 879bafebce1SSebastian Grimberg When using @ref CEED_BASIS_NONE, the number of quadrature points is determined by the element size of `rstr`. 880528a22edSJeremy L Thompson 881ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` on which to provide the field 882ca94c3ddSJeremy L Thompson @param[in] field_name Name of the field (to be matched with the name used by `CeedQFunction`) 883bafebce1SSebastian Grimberg @param[in] rstr `CeedElemRestriction` 884bafebce1SSebastian Grimberg @param[in] basis `CeedBasis` in which the field resides or @ref CEED_BASIS_NONE if collocated with quadrature points 885bafebce1SSebastian 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` 886b11c1e72Sjeremylt 887b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 888dfdf5a53Sjeremylt 8897a982d89SJeremy L. Thompson @ref User 890b11c1e72Sjeremylt **/ 891bafebce1SSebastian Grimberg int CeedOperatorSetField(CeedOperator op, const char *field_name, CeedElemRestriction rstr, CeedBasis basis, CeedVector vec) { 8921203703bSJeremy L Thompson bool is_input = true, is_at_points, is_composite, is_immutable; 8931203703bSJeremy L Thompson CeedInt num_elem = 0, num_qpts = 0, num_input_fields, num_output_fields; 8941203703bSJeremy L Thompson CeedQFunction qf; 8951203703bSJeremy L Thompson CeedQFunctionField qf_field, *qf_input_fields, *qf_output_fields; 8961c66c397SJeremy L Thompson CeedOperatorField *op_field; 8971c66c397SJeremy L Thompson 8981203703bSJeremy L Thompson CeedCall(CeedOperatorIsAtPoints(op, &is_at_points)); 8991203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 9001203703bSJeremy L Thompson CeedCall(CeedOperatorIsImmutable(op, &is_immutable)); 9019bc66399SJeremy L Thompson CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, "Cannot add field to composite operator."); 9029bc66399SJeremy L Thompson CeedCheck(!is_immutable, CeedOperatorReturnCeed(op), CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable"); 9039bc66399SJeremy L Thompson CeedCheck(rstr, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, "CeedElemRestriction rstr for field \"%s\" must be non-NULL.", field_name); 9049bc66399SJeremy L Thompson CeedCheck(basis, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, "CeedBasis basis for field \"%s\" must be non-NULL.", field_name); 9059bc66399SJeremy L Thompson CeedCheck(vec, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, "CeedVector vec for field \"%s\" must be non-NULL.", field_name); 90652d6035fSJeremy L Thompson 907bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionGetNumElements(rstr, &num_elem)); 9089bc66399SJeremy L Thompson CeedCheck(rstr == CEED_ELEMRESTRICTION_NONE || !op->has_restriction || num_elem == op->num_elem, CeedOperatorReturnCeed(op), CEED_ERROR_DIMENSION, 909ca94c3ddSJeremy L Thompson "CeedElemRestriction with %" CeedInt_FMT " elements incompatible with prior %" CeedInt_FMT " elements", num_elem, op->num_elem); 9102c7e7413SJeremy L Thompson { 9112c7e7413SJeremy L Thompson CeedRestrictionType rstr_type; 9122c7e7413SJeremy L Thompson 913bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionGetType(rstr, &rstr_type)); 91448acf710SJeremy L Thompson if (rstr_type == CEED_RESTRICTION_POINTS) { 9159bc66399SJeremy L Thompson CeedCheck(is_at_points, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, 9169bc66399SJeremy L Thompson "CeedElemRestriction AtPoints not supported for standard operator fields"); 9179bc66399SJeremy L Thompson CeedCheck(basis == CEED_BASIS_NONE, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, 9189bc66399SJeremy L Thompson "CeedElemRestriction AtPoints must be used with CEED_BASIS_NONE"); 91948acf710SJeremy L Thompson if (!op->first_points_rstr) { 920bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionReferenceCopy(rstr, &op->first_points_rstr)); 92148acf710SJeremy L Thompson } else { 92248acf710SJeremy L Thompson bool are_compatible; 92348acf710SJeremy L Thompson 924bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionAtPointsAreCompatible(op->first_points_rstr, rstr, &are_compatible)); 9259bc66399SJeremy L Thompson CeedCheck(are_compatible, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, 926ca94c3ddSJeremy L Thompson "CeedElemRestriction must have compatible offsets with previously set CeedElemRestriction"); 92748acf710SJeremy L Thompson } 92848acf710SJeremy L Thompson } 9292c7e7413SJeremy L Thompson } 930d7b241e6Sjeremylt 931bafebce1SSebastian Grimberg if (basis == CEED_BASIS_NONE) CeedCall(CeedElemRestrictionGetElementSize(rstr, &num_qpts)); 932bafebce1SSebastian Grimberg else CeedCall(CeedBasisGetNumQuadraturePoints(basis, &num_qpts)); 9339bc66399SJeremy L Thompson CeedCheck(op->num_qpts == 0 || num_qpts == op->num_qpts, CeedOperatorReturnCeed(op), CEED_ERROR_DIMENSION, 934ca94c3ddSJeremy L Thompson "%s must correspond to the same number of quadrature points as previously added CeedBases. Found %" CeedInt_FMT 935528a22edSJeremy L Thompson " quadrature points but expected %" CeedInt_FMT " quadrature points.", 936bafebce1SSebastian Grimberg basis == CEED_BASIS_NONE ? "CeedElemRestriction" : "CeedBasis", num_qpts, op->num_qpts); 9371203703bSJeremy L Thompson 9381203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 9391203703bSJeremy L Thompson CeedCall(CeedQFunctionGetFields(qf, &num_input_fields, &qf_input_fields, &num_output_fields, &qf_output_fields)); 940c11e12f4SJeremy L Thompson CeedCall(CeedQFunctionDestroy(&qf)); 9411203703bSJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 9426f8994e9SJeremy L Thompson const char *qf_field_name; 9431203703bSJeremy L Thompson 9441203703bSJeremy L Thompson CeedCall(CeedQFunctionFieldGetName(qf_input_fields[i], &qf_field_name)); 9451203703bSJeremy L Thompson if (!strcmp(field_name, qf_field_name)) { 9461203703bSJeremy L Thompson qf_field = qf_input_fields[i]; 947d1d35e2fSjeremylt op_field = &op->input_fields[i]; 948d7b241e6Sjeremylt goto found; 949d7b241e6Sjeremylt } 950d7b241e6Sjeremylt } 9512b104005SJeremy L Thompson is_input = false; 9521203703bSJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 9536f8994e9SJeremy L Thompson const char *qf_field_name; 9541203703bSJeremy L Thompson 9551203703bSJeremy L Thompson CeedCall(CeedQFunctionFieldGetName(qf_output_fields[i], &qf_field_name)); 9561203703bSJeremy L Thompson if (!strcmp(field_name, qf_field_name)) { 9571203703bSJeremy L Thompson qf_field = qf_output_fields[i]; 958d1d35e2fSjeremylt op_field = &op->output_fields[i]; 959d7b241e6Sjeremylt goto found; 960d7b241e6Sjeremylt } 961d7b241e6Sjeremylt } 962c042f62fSJeremy L Thompson // LCOV_EXCL_START 9639bc66399SJeremy L Thompson return CeedError(CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPLETE, "CeedQFunction has no knowledge of field '%s'", field_name); 964c042f62fSJeremy L Thompson // LCOV_EXCL_STOP 965d7b241e6Sjeremylt found: 9669bc66399SJeremy L Thompson CeedCall(CeedOperatorCheckField(CeedOperatorReturnCeed(op), qf_field, rstr, basis)); 9672b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, op_field)); 968e15f9bd0SJeremy L Thompson 969bafebce1SSebastian Grimberg if (vec == CEED_VECTOR_ACTIVE) { 9702b104005SJeremy L Thompson CeedSize l_size; 9711c66c397SJeremy L Thompson 972bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionGetLVectorSize(rstr, &l_size)); 9732b104005SJeremy L Thompson if (is_input) { 9742b104005SJeremy L Thompson if (op->input_size == -1) op->input_size = l_size; 9759bc66399SJeremy L Thompson CeedCheck(l_size == op->input_size, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, 976249f8407SJeremy L Thompson "LVector size %" CeedSize_FMT " does not match previous size %" CeedSize_FMT "", l_size, op->input_size); 9772b104005SJeremy L Thompson } else { 9782b104005SJeremy L Thompson if (op->output_size == -1) op->output_size = l_size; 9799bc66399SJeremy L Thompson CeedCheck(l_size == op->output_size, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, 980249f8407SJeremy L Thompson "LVector size %" CeedSize_FMT " does not match previous size %" CeedSize_FMT "", l_size, op->output_size); 9812b104005SJeremy L Thompson } 9822b730f8bSJeremy L Thompson } 9832b104005SJeremy L Thompson 984bafebce1SSebastian Grimberg CeedCall(CeedVectorReferenceCopy(vec, &(*op_field)->vec)); 985bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionReferenceCopy(rstr, &(*op_field)->elem_rstr)); 986bafebce1SSebastian Grimberg if (rstr != CEED_ELEMRESTRICTION_NONE && !op->has_restriction) { 987d1d35e2fSjeremylt op->num_elem = num_elem; 988d1d35e2fSjeremylt op->has_restriction = true; // Restriction set, but num_elem may be 0 989e15f9bd0SJeremy L Thompson } 990bafebce1SSebastian Grimberg CeedCall(CeedBasisReferenceCopy(basis, &(*op_field)->basis)); 9912a3ff1c9SZach Atkins if (op->num_qpts == 0 && !is_at_points) op->num_qpts = num_qpts; // no consistent number of qpts for OperatorAtPoints 992d1d35e2fSjeremylt op->num_fields += 1; 9932b730f8bSJeremy L Thompson CeedCall(CeedStringAllocCopy(field_name, (char **)&(*op_field)->field_name)); 994e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 995d7b241e6Sjeremylt } 996d7b241e6Sjeremylt 997d7b241e6Sjeremylt /** 998ca94c3ddSJeremy L Thompson @brief Get the `CeedOperator` Field of a `CeedOperator`. 99943bbe138SJeremy L Thompson 1000ca94c3ddSJeremy L Thompson Note: Calling this function asserts that setup is complete and sets the `CeedOperator` as immutable. 1001f04ea552SJeremy L Thompson 1002ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1003f74ec584SJeremy L Thompson @param[out] num_input_fields Variable to store number of input fields 1004ca94c3ddSJeremy L Thompson @param[out] input_fields Variable to store input fields 1005f74ec584SJeremy L Thompson @param[out] num_output_fields Variable to store number of output fields 1006ca94c3ddSJeremy L Thompson @param[out] output_fields Variable to store output fields 100743bbe138SJeremy L Thompson 100843bbe138SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 100943bbe138SJeremy L Thompson 1010e9b533fbSJeremy L Thompson @ref Advanced 101143bbe138SJeremy L Thompson **/ 10122b730f8bSJeremy L Thompson int CeedOperatorGetFields(CeedOperator op, CeedInt *num_input_fields, CeedOperatorField **input_fields, CeedInt *num_output_fields, 101343bbe138SJeremy L Thompson CeedOperatorField **output_fields) { 10141203703bSJeremy L Thompson bool is_composite; 10151203703bSJeremy L Thompson CeedQFunction qf; 10161203703bSJeremy L Thompson 10171203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 10186e536b99SJeremy L Thompson CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Not defined for composite operator"); 10192b730f8bSJeremy L Thompson CeedCall(CeedOperatorCheckReady(op)); 102043bbe138SJeremy L Thompson 10211203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 10221203703bSJeremy L Thompson CeedCall(CeedQFunctionGetFields(qf, num_input_fields, NULL, num_output_fields, NULL)); 1023c11e12f4SJeremy L Thompson CeedCall(CeedQFunctionDestroy(&qf)); 102443bbe138SJeremy L Thompson if (input_fields) *input_fields = op->input_fields; 102543bbe138SJeremy L Thompson if (output_fields) *output_fields = op->output_fields; 102643bbe138SJeremy L Thompson return CEED_ERROR_SUCCESS; 102743bbe138SJeremy L Thompson } 102843bbe138SJeremy L Thompson 102943bbe138SJeremy L Thompson /** 1030ca94c3ddSJeremy L Thompson @brief Set the arbitrary points in each element for a `CeedOperator` at points. 103148acf710SJeremy L Thompson 1032ca94c3ddSJeremy L Thompson Note: Calling this function asserts that setup is complete and sets the `CeedOperator` as immutable. 103348acf710SJeremy L Thompson 1034ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` at points 1035ca94c3ddSJeremy L Thompson @param[in] rstr_points `CeedElemRestriction` for the coordinates of each point by element 1036ca94c3ddSJeremy L Thompson @param[in] point_coords `CeedVector` holding coordinates of each point 103748acf710SJeremy L Thompson 103848acf710SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 103948acf710SJeremy L Thompson 104048acf710SJeremy L Thompson @ref Advanced 104148acf710SJeremy L Thompson **/ 104248acf710SJeremy L Thompson int CeedOperatorAtPointsSetPoints(CeedOperator op, CeedElemRestriction rstr_points, CeedVector point_coords) { 10431203703bSJeremy L Thompson bool is_at_points, is_immutable; 10442a3ff1c9SZach Atkins 10452a3ff1c9SZach Atkins CeedCall(CeedOperatorIsAtPoints(op, &is_at_points)); 10461203703bSJeremy L Thompson CeedCall(CeedOperatorIsImmutable(op, &is_immutable)); 10479bc66399SJeremy L Thompson CeedCheck(is_at_points, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Only defined for operator at points"); 10489bc66399SJeremy L Thompson CeedCheck(!is_immutable, CeedOperatorReturnCeed(op), CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable"); 104948acf710SJeremy L Thompson 105048acf710SJeremy L Thompson if (!op->first_points_rstr) { 105148acf710SJeremy L Thompson CeedCall(CeedElemRestrictionReferenceCopy(rstr_points, &op->first_points_rstr)); 105248acf710SJeremy L Thompson } else { 105348acf710SJeremy L Thompson bool are_compatible; 105448acf710SJeremy L Thompson 105548acf710SJeremy L Thompson CeedCall(CeedElemRestrictionAtPointsAreCompatible(op->first_points_rstr, rstr_points, &are_compatible)); 10569bc66399SJeremy L Thompson CeedCheck(are_compatible, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, 1057ca94c3ddSJeremy L Thompson "CeedElemRestriction must have compatible offsets with previously set field CeedElemRestriction"); 105848acf710SJeremy L Thompson } 105948acf710SJeremy L Thompson 106048acf710SJeremy L Thompson CeedCall(CeedElemRestrictionReferenceCopy(rstr_points, &op->rstr_points)); 106148acf710SJeremy L Thompson CeedCall(CeedVectorReferenceCopy(point_coords, &op->point_coords)); 106248acf710SJeremy L Thompson return CEED_ERROR_SUCCESS; 106348acf710SJeremy L Thompson } 106448acf710SJeremy L Thompson 106548acf710SJeremy L Thompson /** 1066b594f9faSZach Atkins @brief Get a boolean value indicating if the `CeedOperator` was created with `CeedOperatorCreateAtPoints` 1067b594f9faSZach Atkins 1068b594f9faSZach Atkins @param[in] op `CeedOperator` 1069b594f9faSZach Atkins @param[out] is_at_points Variable to store at points status 1070b594f9faSZach Atkins 1071b594f9faSZach Atkins @return An error code: 0 - success, otherwise - failure 1072b594f9faSZach Atkins 1073b594f9faSZach Atkins @ref User 1074b594f9faSZach Atkins **/ 1075b594f9faSZach Atkins int CeedOperatorIsAtPoints(CeedOperator op, bool *is_at_points) { 1076b594f9faSZach Atkins *is_at_points = op->is_at_points; 1077b594f9faSZach Atkins return CEED_ERROR_SUCCESS; 1078b594f9faSZach Atkins } 1079b594f9faSZach Atkins 1080b594f9faSZach Atkins /** 1081ca94c3ddSJeremy L Thompson @brief Get the arbitrary points in each element for a `CeedOperator` at points. 108248acf710SJeremy L Thompson 1083ca94c3ddSJeremy L Thompson Note: Calling this function asserts that setup is complete and sets the `CeedOperator` as immutable. 108448acf710SJeremy L Thompson 1085ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` at points 1086ca94c3ddSJeremy L Thompson @param[out] rstr_points Variable to hold `CeedElemRestriction` for the coordinates of each point by element 1087ca94c3ddSJeremy L Thompson @param[out] point_coords Variable to hold `CeedVector` holding coordinates of each point 108848acf710SJeremy L Thompson 108948acf710SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 109048acf710SJeremy L Thompson 109148acf710SJeremy L Thompson @ref Advanced 109248acf710SJeremy L Thompson **/ 109348acf710SJeremy L Thompson int CeedOperatorAtPointsGetPoints(CeedOperator op, CeedElemRestriction *rstr_points, CeedVector *point_coords) { 10942a3ff1c9SZach Atkins bool is_at_points; 10952a3ff1c9SZach Atkins 10962a3ff1c9SZach Atkins CeedCall(CeedOperatorIsAtPoints(op, &is_at_points)); 10976e536b99SJeremy L Thompson CeedCheck(is_at_points, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Only defined for operator at points"); 109848acf710SJeremy L Thompson CeedCall(CeedOperatorCheckReady(op)); 109948acf710SJeremy L Thompson 110048acf710SJeremy L Thompson if (rstr_points) CeedCall(CeedElemRestrictionReferenceCopy(op->rstr_points, rstr_points)); 110148acf710SJeremy L Thompson if (point_coords) CeedCall(CeedVectorReferenceCopy(op->point_coords, point_coords)); 110248acf710SJeremy L Thompson return CEED_ERROR_SUCCESS; 110348acf710SJeremy L Thompson } 110448acf710SJeremy L Thompson 110548acf710SJeremy L Thompson /** 1106be9c6463SJeremy L Thompson @brief Get a `CeedOperator` Field of a `CeedOperator` from its name. 1107be9c6463SJeremy L Thompson 1108be9c6463SJeremy L Thompson `op_field` is set to `NULL` if the field is not found. 1109de5900adSJames Wright 1110ca94c3ddSJeremy L Thompson Note: Calling this function asserts that setup is complete and sets the `CeedOperator` as immutable. 1111de5900adSJames Wright 1112ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1113ca94c3ddSJeremy L Thompson @param[in] field_name Name of desired `CeedOperator` Field 1114ca94c3ddSJeremy L Thompson @param[out] op_field `CeedOperator` Field corresponding to the name 1115de5900adSJames Wright 1116de5900adSJames Wright @return An error code: 0 - success, otherwise - failure 1117de5900adSJames Wright 1118de5900adSJames Wright @ref Advanced 1119de5900adSJames Wright **/ 1120de5900adSJames Wright int CeedOperatorGetFieldByName(CeedOperator op, const char *field_name, CeedOperatorField *op_field) { 11216f8994e9SJeremy L Thompson const char *name; 1122de5900adSJames Wright CeedInt num_input_fields, num_output_fields; 1123de5900adSJames Wright CeedOperatorField *input_fields, *output_fields; 1124de5900adSJames Wright 1125be9c6463SJeremy L Thompson *op_field = NULL; 11261c66c397SJeremy L Thompson CeedCall(CeedOperatorGetFields(op, &num_input_fields, &input_fields, &num_output_fields, &output_fields)); 1127de5900adSJames Wright for (CeedInt i = 0; i < num_input_fields; i++) { 1128de5900adSJames Wright CeedCall(CeedOperatorFieldGetName(input_fields[i], &name)); 1129de5900adSJames Wright if (!strcmp(name, field_name)) { 1130de5900adSJames Wright *op_field = input_fields[i]; 1131de5900adSJames Wright return CEED_ERROR_SUCCESS; 1132de5900adSJames Wright } 1133de5900adSJames Wright } 1134de5900adSJames Wright for (CeedInt i = 0; i < num_output_fields; i++) { 1135de5900adSJames Wright CeedCall(CeedOperatorFieldGetName(output_fields[i], &name)); 1136de5900adSJames Wright if (!strcmp(name, field_name)) { 1137de5900adSJames Wright *op_field = output_fields[i]; 1138de5900adSJames Wright return CEED_ERROR_SUCCESS; 1139de5900adSJames Wright } 1140de5900adSJames Wright } 1141be9c6463SJeremy L Thompson return CEED_ERROR_SUCCESS; 1142de5900adSJames Wright } 1143de5900adSJames Wright 1144de5900adSJames Wright /** 1145ca94c3ddSJeremy L Thompson @brief Get the name of a `CeedOperator` Field 114628567f8fSJeremy L Thompson 1147ca94c3ddSJeremy L Thompson @param[in] op_field `CeedOperator` Field 114828567f8fSJeremy L Thompson @param[out] field_name Variable to store the field name 114928567f8fSJeremy L Thompson 115028567f8fSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 115128567f8fSJeremy L Thompson 1152e9b533fbSJeremy L Thompson @ref Advanced 115328567f8fSJeremy L Thompson **/ 11546f8994e9SJeremy L Thompson int CeedOperatorFieldGetName(CeedOperatorField op_field, const char **field_name) { 11556f8994e9SJeremy L Thompson *field_name = op_field->field_name; 115628567f8fSJeremy L Thompson return CEED_ERROR_SUCCESS; 115728567f8fSJeremy L Thompson } 115828567f8fSJeremy L Thompson 115928567f8fSJeremy L Thompson /** 1160681d0ea7SJeremy L Thompson @brief Get the `CeedElemRestriction` of a `CeedOperator` Field. 1161681d0ea7SJeremy L Thompson 1162681d0ea7SJeremy L Thompson Note: Caller is responsible for destroying the `rstr` with @ref CeedElemRestrictionDestroy(). 116343bbe138SJeremy L Thompson 1164ca94c3ddSJeremy L Thompson @param[in] op_field `CeedOperator` Field 1165ca94c3ddSJeremy L Thompson @param[out] rstr Variable to store `CeedElemRestriction` 116643bbe138SJeremy L Thompson 116743bbe138SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 116843bbe138SJeremy L Thompson 1169e9b533fbSJeremy L Thompson @ref Advanced 117043bbe138SJeremy L Thompson **/ 11712b730f8bSJeremy L Thompson int CeedOperatorFieldGetElemRestriction(CeedOperatorField op_field, CeedElemRestriction *rstr) { 1172681d0ea7SJeremy L Thompson *rstr = NULL; 1173681d0ea7SJeremy L Thompson CeedCall(CeedElemRestrictionReferenceCopy(op_field->elem_rstr, rstr)); 117443bbe138SJeremy L Thompson return CEED_ERROR_SUCCESS; 117543bbe138SJeremy L Thompson } 117643bbe138SJeremy L Thompson 117743bbe138SJeremy L Thompson /** 1178681d0ea7SJeremy L Thompson @brief Get the `CeedBasis` of a `CeedOperator` Field. 1179681d0ea7SJeremy L Thompson 1180681d0ea7SJeremy L Thompson Note: Caller is responsible for destroying the `basis` with @ref CeedBasisDestroy(). 118143bbe138SJeremy L Thompson 1182ca94c3ddSJeremy L Thompson @param[in] op_field `CeedOperator` Field 1183ca94c3ddSJeremy L Thompson @param[out] basis Variable to store `CeedBasis` 118443bbe138SJeremy L Thompson 118543bbe138SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 118643bbe138SJeremy L Thompson 1187e9b533fbSJeremy L Thompson @ref Advanced 118843bbe138SJeremy L Thompson **/ 118943bbe138SJeremy L Thompson int CeedOperatorFieldGetBasis(CeedOperatorField op_field, CeedBasis *basis) { 1190681d0ea7SJeremy L Thompson *basis = NULL; 1191681d0ea7SJeremy L Thompson CeedCall(CeedBasisReferenceCopy(op_field->basis, basis)); 119243bbe138SJeremy L Thompson return CEED_ERROR_SUCCESS; 119343bbe138SJeremy L Thompson } 119443bbe138SJeremy L Thompson 119543bbe138SJeremy L Thompson /** 1196681d0ea7SJeremy L Thompson @brief Get the `CeedVector` of a `CeedOperator` Field. 1197681d0ea7SJeremy L Thompson 1198681d0ea7SJeremy L Thompson Note: Caller is responsible for destroying the `vec` with @ref CeedVectorDestroy(). 119943bbe138SJeremy L Thompson 1200ca94c3ddSJeremy L Thompson @param[in] op_field `CeedOperator` Field 1201ca94c3ddSJeremy L Thompson @param[out] vec Variable to store `CeedVector` 120243bbe138SJeremy L Thompson 120343bbe138SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 120443bbe138SJeremy L Thompson 1205e9b533fbSJeremy L Thompson @ref Advanced 120643bbe138SJeremy L Thompson **/ 120743bbe138SJeremy L Thompson int CeedOperatorFieldGetVector(CeedOperatorField op_field, CeedVector *vec) { 1208681d0ea7SJeremy L Thompson *vec = NULL; 1209681d0ea7SJeremy L Thompson CeedCall(CeedVectorReferenceCopy(op_field->vec, vec)); 121043bbe138SJeremy L Thompson return CEED_ERROR_SUCCESS; 121143bbe138SJeremy L Thompson } 121243bbe138SJeremy L Thompson 121343bbe138SJeremy L Thompson /** 1214ab747706SJeremy L Thompson @brief Get the data of a `CeedOperator` Field. 1215ab747706SJeremy L Thompson 1216681d0ea7SJeremy L Thompson Any arguments set as `NULL` are ignored.. 1217681d0ea7SJeremy L Thompson 1218681d0ea7SJeremy L Thompson Note: Caller is responsible for destroying the `rstr`, `basis`, and `vec`. 1219ab747706SJeremy L Thompson 1220ab747706SJeremy L Thompson @param[in] op_field `CeedOperator` Field 1221ab747706SJeremy L Thompson @param[out] field_name Variable to store the field name 1222ab747706SJeremy L Thompson @param[out] rstr Variable to store `CeedElemRestriction` 1223ab747706SJeremy L Thompson @param[out] basis Variable to store `CeedBasis` 1224ab747706SJeremy L Thompson @param[out] vec Variable to store `CeedVector` 1225ab747706SJeremy L Thompson 1226ab747706SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1227ab747706SJeremy L Thompson 1228ab747706SJeremy L Thompson @ref Advanced 1229ab747706SJeremy L Thompson **/ 12306f8994e9SJeremy L Thompson int CeedOperatorFieldGetData(CeedOperatorField op_field, const char **field_name, CeedElemRestriction *rstr, CeedBasis *basis, CeedVector *vec) { 1231ab747706SJeremy L Thompson if (field_name) CeedCall(CeedOperatorFieldGetName(op_field, field_name)); 1232ab747706SJeremy L Thompson if (rstr) CeedCall(CeedOperatorFieldGetElemRestriction(op_field, rstr)); 1233ab747706SJeremy L Thompson if (basis) CeedCall(CeedOperatorFieldGetBasis(op_field, basis)); 1234ab747706SJeremy L Thompson if (vec) CeedCall(CeedOperatorFieldGetVector(op_field, vec)); 1235ab747706SJeremy L Thompson return CEED_ERROR_SUCCESS; 1236ab747706SJeremy L Thompson } 1237ab747706SJeremy L Thompson 1238ab747706SJeremy L Thompson /** 1239ca94c3ddSJeremy L Thompson @brief Add a sub-operator to a composite `CeedOperator` 1240288c0443SJeremy L Thompson 1241ca94c3ddSJeremy L Thompson @param[in,out] composite_op Composite `CeedOperator` 1242ca94c3ddSJeremy L Thompson @param[in] sub_op Sub-operator `CeedOperator` 124352d6035fSJeremy L Thompson 124452d6035fSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 124552d6035fSJeremy L Thompson 12467a982d89SJeremy L. Thompson @ref User 124752d6035fSJeremy L Thompson */ 12482b730f8bSJeremy L Thompson int CeedCompositeOperatorAddSub(CeedOperator composite_op, CeedOperator sub_op) { 12491203703bSJeremy L Thompson bool is_immutable; 12501203703bSJeremy L Thompson 12519bc66399SJeremy L Thompson CeedCheck(composite_op->is_composite, CeedOperatorReturnCeed(composite_op), CEED_ERROR_MINOR, "CeedOperator is not a composite operator"); 12529bc66399SJeremy L Thompson CeedCheck(composite_op->num_suboperators < CEED_COMPOSITE_MAX, CeedOperatorReturnCeed(composite_op), CEED_ERROR_UNSUPPORTED, 12539bc66399SJeremy L Thompson "Cannot add additional sub-operators"); 12541203703bSJeremy L Thompson CeedCall(CeedOperatorIsImmutable(composite_op, &is_immutable)); 12559bc66399SJeremy L Thompson CeedCheck(!is_immutable, CeedOperatorReturnCeed(composite_op), CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable"); 12562b730f8bSJeremy L Thompson 12572b730f8bSJeremy L Thompson { 12582b730f8bSJeremy L Thompson CeedSize input_size, output_size; 12591c66c397SJeremy L Thompson 12602b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetActiveVectorLengths(sub_op, &input_size, &output_size)); 12612b730f8bSJeremy L Thompson if (composite_op->input_size == -1) composite_op->input_size = input_size; 12622b730f8bSJeremy L Thompson if (composite_op->output_size == -1) composite_op->output_size = output_size; 12632b730f8bSJeremy L Thompson // Note, a size of -1 means no active vector restriction set, so no incompatibility 12649bc66399SJeremy L Thompson CeedCheck((input_size == -1 || input_size == composite_op->input_size) && (output_size == -1 || output_size == composite_op->output_size), 12659bc66399SJeremy L Thompson CeedOperatorReturnCeed(composite_op), CEED_ERROR_MAJOR, 1266249f8407SJeremy L Thompson "Sub-operators must have compatible dimensions; composite operator of shape (%" CeedSize_FMT ", %" CeedSize_FMT 1267249f8407SJeremy L Thompson ") not compatible with sub-operator of " 1268249f8407SJeremy L Thompson "shape (%" CeedSize_FMT ", %" CeedSize_FMT ")", 12692b730f8bSJeremy L Thompson composite_op->input_size, composite_op->output_size, input_size, output_size); 12702b730f8bSJeremy L Thompson } 12712b730f8bSJeremy L Thompson 1272d1d35e2fSjeremylt composite_op->sub_operators[composite_op->num_suboperators] = sub_op; 12732b730f8bSJeremy L Thompson CeedCall(CeedOperatorReference(sub_op)); 1274d1d35e2fSjeremylt composite_op->num_suboperators++; 1275e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 127652d6035fSJeremy L Thompson } 127752d6035fSJeremy L Thompson 127852d6035fSJeremy L Thompson /** 1279ca94c3ddSJeremy L Thompson @brief Get the number of sub-operators associated with a `CeedOperator` 128075f0d5a4SJeremy L Thompson 1281ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1282ca94c3ddSJeremy L Thompson @param[out] num_suboperators Variable to store number of sub-operators 128375f0d5a4SJeremy L Thompson 128475f0d5a4SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 128575f0d5a4SJeremy L Thompson 128675f0d5a4SJeremy L Thompson @ref Backend 128775f0d5a4SJeremy L Thompson **/ 1288c6ebc35dSJeremy L Thompson int CeedCompositeOperatorGetNumSub(CeedOperator op, CeedInt *num_suboperators) { 12891203703bSJeremy L Thompson bool is_composite; 12901203703bSJeremy L Thompson 12911203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 12926e536b99SJeremy L Thompson CeedCheck(is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Only defined for a composite operator"); 129375f0d5a4SJeremy L Thompson *num_suboperators = op->num_suboperators; 129475f0d5a4SJeremy L Thompson return CEED_ERROR_SUCCESS; 129575f0d5a4SJeremy L Thompson } 129675f0d5a4SJeremy L Thompson 129775f0d5a4SJeremy L Thompson /** 1298ca94c3ddSJeremy L Thompson @brief Get the list of sub-operators associated with a `CeedOperator` 129975f0d5a4SJeremy L Thompson 1300ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1301ca94c3ddSJeremy L Thompson @param[out] sub_operators Variable to store list of sub-operators 130275f0d5a4SJeremy L Thompson 130375f0d5a4SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 130475f0d5a4SJeremy L Thompson 130575f0d5a4SJeremy L Thompson @ref Backend 130675f0d5a4SJeremy L Thompson **/ 1307c6ebc35dSJeremy L Thompson int CeedCompositeOperatorGetSubList(CeedOperator op, CeedOperator **sub_operators) { 13081203703bSJeremy L Thompson bool is_composite; 13091203703bSJeremy L Thompson 13101203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 13116e536b99SJeremy L Thompson CeedCheck(is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Only defined for a composite operator"); 131275f0d5a4SJeremy L Thompson *sub_operators = op->sub_operators; 131375f0d5a4SJeremy L Thompson return CEED_ERROR_SUCCESS; 131475f0d5a4SJeremy L Thompson } 131575f0d5a4SJeremy L Thompson 131675f0d5a4SJeremy L Thompson /** 13178a297abdSJames Wright @brief Get a sub `CeedOperator` of a composite `CeedOperator` from its name. 13188a297abdSJames Wright 13198a297abdSJames Wright `sub_op` is set to `NULL` if the sub operator is not found. 13208a297abdSJames Wright 13218a297abdSJames Wright Note: Calling this function asserts that setup is complete and sets the `CeedOperator` as immutable. 13228a297abdSJames Wright 13238a297abdSJames Wright @param[in] op Composite `CeedOperator` 13248a297abdSJames Wright @param[in] op_name Name of desired sub `CeedOperator` 13258a297abdSJames Wright @param[out] sub_op Sub `CeedOperator` corresponding to the name 13268a297abdSJames Wright 13278a297abdSJames Wright @return An error code: 0 - success, otherwise - failure 13288a297abdSJames Wright 13298a297abdSJames Wright @ref Advanced 13308a297abdSJames Wright **/ 13318a297abdSJames Wright int CeedCompositeOperatorGetSubByName(CeedOperator op, const char *op_name, CeedOperator *sub_op) { 13328a297abdSJames Wright bool is_composite; 13338a297abdSJames Wright CeedInt num_sub_ops; 13348a297abdSJames Wright CeedOperator *sub_ops; 13358a297abdSJames Wright 13368a297abdSJames Wright CeedCall(CeedOperatorIsComposite(op, &is_composite)); 13378a297abdSJames Wright CeedCheck(is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Only defined for a composite operator"); 13388a297abdSJames Wright *sub_op = NULL; 13398a297abdSJames Wright CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub_ops)); 13408a297abdSJames Wright CeedCall(CeedCompositeOperatorGetSubList(op, &sub_ops)); 13418a297abdSJames Wright for (CeedInt i = 0; i < num_sub_ops; i++) { 13428a297abdSJames Wright if (sub_ops[i]->name && !strcmp(op_name, sub_ops[i]->name)) { 13438a297abdSJames Wright *sub_op = sub_ops[i]; 13448a297abdSJames Wright return CEED_ERROR_SUCCESS; 13458a297abdSJames Wright } 13468a297abdSJames Wright } 13478a297abdSJames Wright return CEED_ERROR_SUCCESS; 13488a297abdSJames Wright } 13498a297abdSJames Wright 13508a297abdSJames Wright /** 1351ca94c3ddSJeremy L Thompson @brief Check if a `CeedOperator` is ready to be used. 13524db537f9SJeremy L Thompson 1353ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to check 13544db537f9SJeremy L Thompson 13554db537f9SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 13564db537f9SJeremy L Thompson 13574db537f9SJeremy L Thompson @ref User 13584db537f9SJeremy L Thompson **/ 13594db537f9SJeremy L Thompson int CeedOperatorCheckReady(CeedOperator op) { 13601203703bSJeremy L Thompson bool is_at_points, is_composite; 13611203703bSJeremy L Thompson CeedQFunction qf = NULL; 13624db537f9SJeremy L Thompson 13632b730f8bSJeremy L Thompson if (op->is_interface_setup) return CEED_ERROR_SUCCESS; 13644db537f9SJeremy L Thompson 13651203703bSJeremy L Thompson CeedCall(CeedOperatorIsAtPoints(op, &is_at_points)); 13661203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 13671203703bSJeremy L Thompson if (!is_composite) CeedCall(CeedOperatorGetQFunction(op, &qf)); 13681203703bSJeremy L Thompson if (is_composite) { 13691203703bSJeremy L Thompson CeedInt num_suboperators; 13701203703bSJeremy L Thompson 13711203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 13721203703bSJeremy L Thompson if (!num_suboperators) { 137343622462SJeremy L Thompson // Empty operator setup 137443622462SJeremy L Thompson op->input_size = 0; 137543622462SJeremy L Thompson op->output_size = 0; 137643622462SJeremy L Thompson } else { 13771203703bSJeremy L Thompson CeedOperator *sub_operators; 13781203703bSJeremy L Thompson 13791203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 13801203703bSJeremy L Thompson for (CeedInt i = 0; i < num_suboperators; i++) { 13811203703bSJeremy L Thompson CeedCall(CeedOperatorCheckReady(sub_operators[i])); 13824db537f9SJeremy L Thompson } 13832b104005SJeremy L Thompson // Sub-operators could be modified after adding to composite operator 13842b104005SJeremy L Thompson // Need to verify no lvec incompatibility from any changes 13852b104005SJeremy L Thompson CeedSize input_size, output_size; 13862b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetActiveVectorLengths(op, &input_size, &output_size)); 138743622462SJeremy L Thompson } 13884db537f9SJeremy L Thompson } else { 13891203703bSJeremy L Thompson CeedInt num_input_fields, num_output_fields; 13901203703bSJeremy L Thompson 13919bc66399SJeremy L Thompson CeedCheck(op->num_fields > 0, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPLETE, "No operator fields set"); 13921203703bSJeremy L Thompson CeedCall(CeedQFunctionGetFields(qf, &num_input_fields, NULL, &num_output_fields, NULL)); 13939bc66399SJeremy L Thompson CeedCheck(op->num_fields == num_input_fields + num_output_fields, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPLETE, 13949bc66399SJeremy L Thompson "Not all operator fields set"); 13959bc66399SJeremy L Thompson CeedCheck(op->has_restriction, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPLETE, "At least one restriction required"); 13969bc66399SJeremy L Thompson CeedCheck(op->num_qpts > 0 || is_at_points, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPLETE, 1397ca94c3ddSJeremy L Thompson "At least one non-collocated CeedBasis is required or the number of quadrature points must be set"); 13982b730f8bSJeremy L Thompson } 13994db537f9SJeremy L Thompson 14004db537f9SJeremy L Thompson // Flag as immutable and ready 14014db537f9SJeremy L Thompson op->is_interface_setup = true; 14021203703bSJeremy L Thompson if (qf && qf != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionSetImmutable(qf)); 1403c11e12f4SJeremy L Thompson CeedCall(CeedQFunctionDestroy(&qf)); 14041203703bSJeremy L Thompson if (op->dqf && op->dqf != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionSetImmutable(op->dqf)); 14051203703bSJeremy L Thompson if (op->dqfT && op->dqfT != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionSetImmutable(op->dqfT)); 14064db537f9SJeremy L Thompson return CEED_ERROR_SUCCESS; 14074db537f9SJeremy L Thompson } 14084db537f9SJeremy L Thompson 14094db537f9SJeremy L Thompson /** 1410ca94c3ddSJeremy L Thompson @brief Get vector lengths for the active input and/or output `CeedVector` of a `CeedOperator`. 14114385fb7fSSebastian Grimberg 1412ca94c3ddSJeremy L Thompson Note: Lengths of `-1` indicate that the CeedOperator does not have an active input and/or output. 1413c9366a6bSJeremy L Thompson 1414ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1415ca94c3ddSJeremy L Thompson @param[out] input_size Variable to store active input vector length, or `NULL` 1416ca94c3ddSJeremy L Thompson @param[out] output_size Variable to store active output vector length, or `NULL` 1417c9366a6bSJeremy L Thompson 1418c9366a6bSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1419c9366a6bSJeremy L Thompson 1420c9366a6bSJeremy L Thompson @ref User 1421c9366a6bSJeremy L Thompson **/ 14222b730f8bSJeremy L Thompson int CeedOperatorGetActiveVectorLengths(CeedOperator op, CeedSize *input_size, CeedSize *output_size) { 1423c9366a6bSJeremy L Thompson bool is_composite; 1424c9366a6bSJeremy L Thompson 14252b104005SJeremy L Thompson if (input_size) *input_size = op->input_size; 14262b104005SJeremy L Thompson if (output_size) *output_size = op->output_size; 1427c9366a6bSJeremy L Thompson 14282b730f8bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 14292b104005SJeremy L Thompson if (is_composite && (op->input_size == -1 || op->output_size == -1)) { 14301203703bSJeremy L Thompson CeedInt num_suboperators; 14311203703bSJeremy L Thompson CeedOperator *sub_operators; 14321203703bSJeremy L Thompson 14331203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 14341203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 14351203703bSJeremy L Thompson for (CeedInt i = 0; i < num_suboperators; i++) { 1436c9366a6bSJeremy L Thompson CeedSize sub_input_size, sub_output_size; 14371c66c397SJeremy L Thompson 14381203703bSJeremy L Thompson CeedCall(CeedOperatorGetActiveVectorLengths(sub_operators[i], &sub_input_size, &sub_output_size)); 14392b104005SJeremy L Thompson if (op->input_size == -1) op->input_size = sub_input_size; 14402b104005SJeremy L Thompson if (op->output_size == -1) op->output_size = sub_output_size; 14412b104005SJeremy L Thompson // Note, a size of -1 means no active vector restriction set, so no incompatibility 14426e536b99SJeremy L Thompson CeedCheck((sub_input_size == -1 || sub_input_size == op->input_size) && (sub_output_size == -1 || sub_output_size == op->output_size), 14436e536b99SJeremy L Thompson CeedOperatorReturnCeed(op), CEED_ERROR_MAJOR, 1444249f8407SJeremy L Thompson "Sub-operators must have compatible dimensions; composite operator of shape (%" CeedSize_FMT ", %" CeedSize_FMT 1445249f8407SJeremy L Thompson ") not compatible with sub-operator of " 1446249f8407SJeremy L Thompson "shape (%" CeedSize_FMT ", %" CeedSize_FMT ")", 14472b104005SJeremy L Thompson op->input_size, op->output_size, input_size, output_size); 1448c9366a6bSJeremy L Thompson } 14492b730f8bSJeremy L Thompson } 1450c9366a6bSJeremy L Thompson return CEED_ERROR_SUCCESS; 1451c9366a6bSJeremy L Thompson } 1452c9366a6bSJeremy L Thompson 1453c9366a6bSJeremy L Thompson /** 1454ca94c3ddSJeremy L Thompson @brief Set reuse of `CeedQFunction` data in `CeedOperatorLinearAssemble*()` functions. 14554385fb7fSSebastian Grimberg 1456ca94c3ddSJeremy L Thompson When `reuse_assembly_data = false` (default), the `CeedQFunction` associated with this `CeedOperator` is re-assembled every time a `CeedOperatorLinearAssemble*()` function is called. 1457ca94c3ddSJeremy L Thompson When `reuse_assembly_data = true`, the `CeedQFunction` associated with this `CeedOperator` is reused between calls to @ref CeedOperatorSetQFunctionAssemblyDataUpdateNeeded(). 14588b919e6bSJeremy L Thompson 1459ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1460beecbf24SJeremy L Thompson @param[in] reuse_assembly_data Boolean flag setting assembly data reuse 14618b919e6bSJeremy L Thompson 14628b919e6bSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 14638b919e6bSJeremy L Thompson 14648b919e6bSJeremy L Thompson @ref Advanced 14658b919e6bSJeremy L Thompson **/ 14662b730f8bSJeremy L Thompson int CeedOperatorSetQFunctionAssemblyReuse(CeedOperator op, bool reuse_assembly_data) { 14678b919e6bSJeremy L Thompson bool is_composite; 14688b919e6bSJeremy L Thompson 14692b730f8bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 14708b919e6bSJeremy L Thompson if (is_composite) { 14718b919e6bSJeremy L Thompson for (CeedInt i = 0; i < op->num_suboperators; i++) { 14722b730f8bSJeremy L Thompson CeedCall(CeedOperatorSetQFunctionAssemblyReuse(op->sub_operators[i], reuse_assembly_data)); 14738b919e6bSJeremy L Thompson } 14748b919e6bSJeremy L Thompson } else { 14757d5185d7SSebastian Grimberg CeedQFunctionAssemblyData data; 14767d5185d7SSebastian Grimberg 14777d5185d7SSebastian Grimberg CeedCall(CeedOperatorGetQFunctionAssemblyData(op, &data)); 14787d5185d7SSebastian Grimberg CeedCall(CeedQFunctionAssemblyDataSetReuse(data, reuse_assembly_data)); 1479beecbf24SJeremy L Thompson } 1480beecbf24SJeremy L Thompson return CEED_ERROR_SUCCESS; 1481beecbf24SJeremy L Thompson } 1482beecbf24SJeremy L Thompson 1483beecbf24SJeremy L Thompson /** 1484ca94c3ddSJeremy L Thompson @brief Mark `CeedQFunction` data as updated and the `CeedQFunction` as requiring re-assembly. 1485beecbf24SJeremy L Thompson 1486ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 14876e15d496SJeremy L Thompson @param[in] needs_data_update Boolean flag setting assembly data reuse 1488beecbf24SJeremy L Thompson 1489beecbf24SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1490beecbf24SJeremy L Thompson 1491beecbf24SJeremy L Thompson @ref Advanced 1492beecbf24SJeremy L Thompson **/ 14932b730f8bSJeremy L Thompson int CeedOperatorSetQFunctionAssemblyDataUpdateNeeded(CeedOperator op, bool needs_data_update) { 1494beecbf24SJeremy L Thompson bool is_composite; 1495beecbf24SJeremy L Thompson 14962b730f8bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 1497beecbf24SJeremy L Thompson if (is_composite) { 14981203703bSJeremy L Thompson CeedInt num_suboperators; 14991203703bSJeremy L Thompson CeedOperator *sub_operators; 15001203703bSJeremy L Thompson 15011203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 15021203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 15031203703bSJeremy L Thompson for (CeedInt i = 0; i < num_suboperators; i++) { 15041203703bSJeremy L Thompson CeedCall(CeedOperatorSetQFunctionAssemblyDataUpdateNeeded(sub_operators[i], needs_data_update)); 1505beecbf24SJeremy L Thompson } 1506beecbf24SJeremy L Thompson } else { 15077d5185d7SSebastian Grimberg CeedQFunctionAssemblyData data; 15087d5185d7SSebastian Grimberg 15097d5185d7SSebastian Grimberg CeedCall(CeedOperatorGetQFunctionAssemblyData(op, &data)); 15107d5185d7SSebastian Grimberg CeedCall(CeedQFunctionAssemblyDataSetUpdateNeeded(data, needs_data_update)); 15118b919e6bSJeremy L Thompson } 15128b919e6bSJeremy L Thompson return CEED_ERROR_SUCCESS; 15138b919e6bSJeremy L Thompson } 15148b919e6bSJeremy L Thompson 15158b919e6bSJeremy L Thompson /** 1516ca94c3ddSJeremy L Thompson @brief Set name of `CeedOperator` for @ref CeedOperatorView() output 1517ea6b5821SJeremy L Thompson 1518ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 1519ea61e9acSJeremy L Thompson @param[in] name Name to set, or NULL to remove previously set name 1520ea6b5821SJeremy L Thompson 1521ea6b5821SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1522ea6b5821SJeremy L Thompson 1523ea6b5821SJeremy L Thompson @ref User 1524ea6b5821SJeremy L Thompson **/ 1525ea6b5821SJeremy L Thompson int CeedOperatorSetName(CeedOperator op, const char *name) { 1526ea6b5821SJeremy L Thompson char *name_copy; 1527ea6b5821SJeremy L Thompson size_t name_len = name ? strlen(name) : 0; 1528ea6b5821SJeremy L Thompson 15292b730f8bSJeremy L Thompson CeedCall(CeedFree(&op->name)); 1530ea6b5821SJeremy L Thompson if (name_len > 0) { 15312b730f8bSJeremy L Thompson CeedCall(CeedCalloc(name_len + 1, &name_copy)); 1532ea6b5821SJeremy L Thompson memcpy(name_copy, name, name_len); 1533ea6b5821SJeremy L Thompson op->name = name_copy; 1534ea6b5821SJeremy L Thompson } 1535ea6b5821SJeremy L Thompson return CEED_ERROR_SUCCESS; 1536ea6b5821SJeremy L Thompson } 1537ea6b5821SJeremy L Thompson 1538ea6b5821SJeremy L Thompson /** 1539935f026aSJeremy L Thompson @brief Core logic for viewing a `CeedOperator` 15407a982d89SJeremy L. Thompson 1541935f026aSJeremy L Thompson @param[in] op `CeedOperator` to view brief summary 1542ca94c3ddSJeremy L Thompson @param[in] stream Stream to write; typically `stdout` or a file 15438bf1b130SJames Wright @param[in] is_full Whether to write full operator view or terse 15447a982d89SJeremy L. Thompson 15457a982d89SJeremy L. Thompson @return Error code: 0 - success, otherwise - failure 15467a982d89SJeremy L. Thompson **/ 15478bf1b130SJames Wright static int CeedOperatorView_Core(CeedOperator op, FILE *stream, bool is_full) { 15481203703bSJeremy L Thompson bool has_name = op->name, is_composite; 15497a982d89SJeremy L. Thompson 15501203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 15511203703bSJeremy L Thompson if (is_composite) { 15521203703bSJeremy L Thompson CeedInt num_suboperators; 15531203703bSJeremy L Thompson CeedOperator *sub_operators; 15541203703bSJeremy L Thompson 15551203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 15561203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 15572b730f8bSJeremy L Thompson fprintf(stream, "Composite CeedOperator%s%s\n", has_name ? " - " : "", has_name ? op->name : ""); 15587a982d89SJeremy L. Thompson 15591203703bSJeremy L Thompson for (CeedInt i = 0; i < num_suboperators; i++) { 15601203703bSJeremy L Thompson has_name = sub_operators[i]->name; 1561935f026aSJeremy L Thompson fprintf(stream, " SubOperator %" CeedInt_FMT "%s%s%s\n", i, has_name ? " - " : "", has_name ? sub_operators[i]->name : "", is_full ? ":" : ""); 1562935f026aSJeremy L Thompson if (is_full) CeedCall(CeedOperatorSingleView(sub_operators[i], 1, stream)); 15637a982d89SJeremy L. Thompson } 15647a982d89SJeremy L. Thompson } else { 15652b730f8bSJeremy L Thompson fprintf(stream, "CeedOperator%s%s\n", has_name ? " - " : "", has_name ? op->name : ""); 1566935f026aSJeremy L Thompson if (is_full) CeedCall(CeedOperatorSingleView(op, 0, stream)); 15677a982d89SJeremy L. Thompson } 1568e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 15697a982d89SJeremy L. Thompson } 15703bd813ffSjeremylt 15713bd813ffSjeremylt /** 1572935f026aSJeremy L Thompson @brief View a `CeedOperator` 1573935f026aSJeremy L Thompson 1574935f026aSJeremy L Thompson @param[in] op `CeedOperator` to view 1575935f026aSJeremy L Thompson @param[in] stream Stream to write; typically `stdout` or a file 1576935f026aSJeremy L Thompson 1577935f026aSJeremy L Thompson @return Error code: 0 - success, otherwise - failure 1578935f026aSJeremy L Thompson 1579935f026aSJeremy L Thompson @ref User 1580935f026aSJeremy L Thompson **/ 1581935f026aSJeremy L Thompson int CeedOperatorView(CeedOperator op, FILE *stream) { 1582935f026aSJeremy L Thompson CeedCall(CeedOperatorView_Core(op, stream, true)); 1583935f026aSJeremy L Thompson return CEED_ERROR_SUCCESS; 1584935f026aSJeremy L Thompson } 1585935f026aSJeremy L Thompson 1586935f026aSJeremy L Thompson /** 1587935f026aSJeremy L Thompson @brief View a brief summary `CeedOperator` 1588935f026aSJeremy L Thompson 1589935f026aSJeremy L Thompson @param[in] op `CeedOperator` to view brief summary 1590935f026aSJeremy L Thompson @param[in] stream Stream to write; typically `stdout` or a file 1591935f026aSJeremy L Thompson 1592935f026aSJeremy L Thompson @return Error code: 0 - success, otherwise - failure 1593935f026aSJeremy L Thompson 1594935f026aSJeremy L Thompson @ref User 1595935f026aSJeremy L Thompson **/ 1596935f026aSJeremy L Thompson int CeedOperatorViewTerse(CeedOperator op, FILE *stream) { 1597935f026aSJeremy L Thompson CeedCall(CeedOperatorView_Core(op, stream, false)); 1598935f026aSJeremy L Thompson return CEED_ERROR_SUCCESS; 1599935f026aSJeremy L Thompson } 1600935f026aSJeremy L Thompson 1601935f026aSJeremy L Thompson /** 1602ca94c3ddSJeremy L Thompson @brief Get the `Ceed` associated with a `CeedOperator` 1603b7c9bbdaSJeremy L Thompson 1604ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1605ca94c3ddSJeremy L Thompson @param[out] ceed Variable to store `Ceed` 1606b7c9bbdaSJeremy L Thompson 1607b7c9bbdaSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1608b7c9bbdaSJeremy L Thompson 1609b7c9bbdaSJeremy L Thompson @ref Advanced 1610b7c9bbdaSJeremy L Thompson **/ 1611b7c9bbdaSJeremy L Thompson int CeedOperatorGetCeed(CeedOperator op, Ceed *ceed) { 16129bc66399SJeremy L Thompson *ceed = NULL; 16139bc66399SJeremy L Thompson CeedCall(CeedReferenceCopy(CeedOperatorReturnCeed(op), ceed)); 1614b7c9bbdaSJeremy L Thompson return CEED_ERROR_SUCCESS; 1615b7c9bbdaSJeremy L Thompson } 1616b7c9bbdaSJeremy L Thompson 1617b7c9bbdaSJeremy L Thompson /** 16186e536b99SJeremy L Thompson @brief Return the `Ceed` associated with a `CeedOperator` 16196e536b99SJeremy L Thompson 16206e536b99SJeremy L Thompson @param[in] op `CeedOperator` 16216e536b99SJeremy L Thompson 16226e536b99SJeremy L Thompson @return `Ceed` associated with the `op` 16236e536b99SJeremy L Thompson 16246e536b99SJeremy L Thompson @ref Advanced 16256e536b99SJeremy L Thompson **/ 16266e536b99SJeremy L Thompson Ceed CeedOperatorReturnCeed(CeedOperator op) { return op->ceed; } 16276e536b99SJeremy L Thompson 16286e536b99SJeremy L Thompson /** 1629ca94c3ddSJeremy L Thompson @brief Get the number of elements associated with a `CeedOperator` 1630b7c9bbdaSJeremy L Thompson 1631ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1632b7c9bbdaSJeremy L Thompson @param[out] num_elem Variable to store number of elements 1633b7c9bbdaSJeremy L Thompson 1634b7c9bbdaSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1635b7c9bbdaSJeremy L Thompson 1636b7c9bbdaSJeremy L Thompson @ref Advanced 1637b7c9bbdaSJeremy L Thompson **/ 1638b7c9bbdaSJeremy L Thompson int CeedOperatorGetNumElements(CeedOperator op, CeedInt *num_elem) { 16391203703bSJeremy L Thompson bool is_composite; 16401203703bSJeremy L Thompson 16411203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 16426e536b99SJeremy L Thompson CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Not defined for composite operator"); 1643b7c9bbdaSJeremy L Thompson *num_elem = op->num_elem; 1644b7c9bbdaSJeremy L Thompson return CEED_ERROR_SUCCESS; 1645b7c9bbdaSJeremy L Thompson } 1646b7c9bbdaSJeremy L Thompson 1647b7c9bbdaSJeremy L Thompson /** 1648ca94c3ddSJeremy L Thompson @brief Get the number of quadrature points associated with a `CeedOperator` 1649b7c9bbdaSJeremy L Thompson 1650ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1651b7c9bbdaSJeremy L Thompson @param[out] num_qpts Variable to store vector number of quadrature points 1652b7c9bbdaSJeremy L Thompson 1653b7c9bbdaSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1654b7c9bbdaSJeremy L Thompson 1655b7c9bbdaSJeremy L Thompson @ref Advanced 1656b7c9bbdaSJeremy L Thompson **/ 1657b7c9bbdaSJeremy L Thompson int CeedOperatorGetNumQuadraturePoints(CeedOperator op, CeedInt *num_qpts) { 16581203703bSJeremy L Thompson bool is_composite; 16591203703bSJeremy L Thompson 16601203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 16616e536b99SJeremy L Thompson CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Not defined for composite operator"); 1662b7c9bbdaSJeremy L Thompson *num_qpts = op->num_qpts; 1663b7c9bbdaSJeremy L Thompson return CEED_ERROR_SUCCESS; 1664b7c9bbdaSJeremy L Thompson } 1665b7c9bbdaSJeremy L Thompson 1666b7c9bbdaSJeremy L Thompson /** 1667ca94c3ddSJeremy L Thompson @brief Estimate number of FLOPs required to apply `CeedOperator` on the active `CeedVector` 16686e15d496SJeremy L Thompson 1669ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to estimate FLOPs for 1670ea61e9acSJeremy L Thompson @param[out] flops Address of variable to hold FLOPs estimate 16716e15d496SJeremy L Thompson 16726e15d496SJeremy L Thompson @ref Backend 16736e15d496SJeremy L Thompson **/ 16749d36ca50SJeremy L Thompson int CeedOperatorGetFlopsEstimate(CeedOperator op, CeedSize *flops) { 16756e15d496SJeremy L Thompson bool is_composite; 16761c66c397SJeremy L Thompson 16772b730f8bSJeremy L Thompson CeedCall(CeedOperatorCheckReady(op)); 16786e15d496SJeremy L Thompson 16796e15d496SJeremy L Thompson *flops = 0; 16802b730f8bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 16816e15d496SJeremy L Thompson if (is_composite) { 16826e15d496SJeremy L Thompson CeedInt num_suboperators; 16831c66c397SJeremy L Thompson 1684c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 16856e15d496SJeremy L Thompson CeedOperator *sub_operators; 1686c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 16876e15d496SJeremy L Thompson 16886e15d496SJeremy L Thompson // FLOPs for each suboperator 16896e15d496SJeremy L Thompson for (CeedInt i = 0; i < num_suboperators; i++) { 16909d36ca50SJeremy L Thompson CeedSize suboperator_flops; 16911c66c397SJeremy L Thompson 16922b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetFlopsEstimate(sub_operators[i], &suboperator_flops)); 16936e15d496SJeremy L Thompson *flops += suboperator_flops; 16946e15d496SJeremy L Thompson } 16956e15d496SJeremy L Thompson } else { 16961c66c397SJeremy L Thompson CeedInt num_input_fields, num_output_fields, num_elem = 0; 16971203703bSJeremy L Thompson CeedQFunction qf; 16981203703bSJeremy L Thompson CeedQFunctionField *qf_input_fields, *qf_output_fields; 16991203703bSJeremy L Thompson CeedOperatorField *op_input_fields, *op_output_fields; 17001c66c397SJeremy L Thompson 17011203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 17021203703bSJeremy L Thompson CeedCall(CeedQFunctionGetFields(qf, &num_input_fields, &qf_input_fields, &num_output_fields, &qf_output_fields)); 1703c11e12f4SJeremy L Thompson CeedCall(CeedQFunctionDestroy(&qf)); 17041203703bSJeremy L Thompson CeedCall(CeedOperatorGetFields(op, NULL, &op_input_fields, NULL, &op_output_fields)); 17052b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetNumElements(op, &num_elem)); 17064385fb7fSSebastian Grimberg 17076e15d496SJeremy L Thompson // Input FLOPs 17086e15d496SJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 17091203703bSJeremy L Thompson CeedVector vec; 17106e15d496SJeremy L Thompson 17111203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(op_input_fields[i], &vec)); 17121203703bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 17131203703bSJeremy L Thompson CeedEvalMode eval_mode; 17141203703bSJeremy L Thompson CeedSize rstr_flops, basis_flops; 17151203703bSJeremy L Thompson CeedElemRestriction rstr; 17161203703bSJeremy L Thompson CeedBasis basis; 17171203703bSJeremy L Thompson 17181203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetElemRestriction(op_input_fields[i], &rstr)); 17191203703bSJeremy L Thompson CeedCall(CeedElemRestrictionGetFlopsEstimate(rstr, CEED_NOTRANSPOSE, &rstr_flops)); 1720681d0ea7SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&rstr)); 1721edb2538eSJeremy L Thompson *flops += rstr_flops; 17221203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetBasis(op_input_fields[i], &basis)); 17231203703bSJeremy L Thompson CeedCall(CeedQFunctionFieldGetEvalMode(qf_input_fields[i], &eval_mode)); 17241203703bSJeremy L Thompson CeedCall(CeedBasisGetFlopsEstimate(basis, CEED_NOTRANSPOSE, eval_mode, &basis_flops)); 1725681d0ea7SJeremy L Thompson CeedCall(CeedBasisDestroy(&basis)); 17266e15d496SJeremy L Thompson *flops += basis_flops * num_elem; 17276e15d496SJeremy L Thompson } 1728681d0ea7SJeremy L Thompson CeedCall(CeedVectorDestroy(&vec)); 17296e15d496SJeremy L Thompson } 17306e15d496SJeremy L Thompson // QF FLOPs 17311c66c397SJeremy L Thompson { 17329d36ca50SJeremy L Thompson CeedInt num_qpts; 17339d36ca50SJeremy L Thompson CeedSize qf_flops; 17341203703bSJeremy L Thompson CeedQFunction qf; 17351c66c397SJeremy L Thompson 17362b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetNumQuadraturePoints(op, &num_qpts)); 17371203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 17381203703bSJeremy L Thompson CeedCall(CeedQFunctionGetFlopsEstimate(qf, &qf_flops)); 1739c11e12f4SJeremy L Thompson CeedCall(CeedQFunctionDestroy(&qf)); 17406e536b99SJeremy L Thompson CeedCheck(qf_flops > -1, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPLETE, 17416e536b99SJeremy L Thompson "Must set CeedQFunction FLOPs estimate with CeedQFunctionSetUserFlopsEstimate"); 17426e15d496SJeremy L Thompson *flops += num_elem * num_qpts * qf_flops; 17431c66c397SJeremy L Thompson } 17441c66c397SJeremy L Thompson 17456e15d496SJeremy L Thompson // Output FLOPs 17466e15d496SJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 17471203703bSJeremy L Thompson CeedVector vec; 17486e15d496SJeremy L Thompson 17491203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(op_output_fields[i], &vec)); 17501203703bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 17511203703bSJeremy L Thompson CeedEvalMode eval_mode; 17521203703bSJeremy L Thompson CeedSize rstr_flops, basis_flops; 17531203703bSJeremy L Thompson CeedElemRestriction rstr; 17541203703bSJeremy L Thompson CeedBasis basis; 17551203703bSJeremy L Thompson 17561203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetElemRestriction(op_output_fields[i], &rstr)); 17571203703bSJeremy L Thompson CeedCall(CeedElemRestrictionGetFlopsEstimate(rstr, CEED_TRANSPOSE, &rstr_flops)); 1758681d0ea7SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&rstr)); 1759edb2538eSJeremy L Thompson *flops += rstr_flops; 17601203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetBasis(op_output_fields[i], &basis)); 17611203703bSJeremy L Thompson CeedCall(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode)); 17621203703bSJeremy L Thompson CeedCall(CeedBasisGetFlopsEstimate(basis, CEED_TRANSPOSE, eval_mode, &basis_flops)); 1763681d0ea7SJeremy L Thompson CeedCall(CeedBasisDestroy(&basis)); 17646e15d496SJeremy L Thompson *flops += basis_flops * num_elem; 17656e15d496SJeremy L Thompson } 1766681d0ea7SJeremy L Thompson CeedCall(CeedVectorDestroy(&vec)); 17676e15d496SJeremy L Thompson } 17686e15d496SJeremy L Thompson } 17696e15d496SJeremy L Thompson return CEED_ERROR_SUCCESS; 17706e15d496SJeremy L Thompson } 17716e15d496SJeremy L Thompson 17726e15d496SJeremy L Thompson /** 1773ca94c3ddSJeremy L Thompson @brief Get `CeedQFunction` global context for a `CeedOperator`. 17749fd66db6SSebastian Grimberg 1775ca94c3ddSJeremy L Thompson The caller is responsible for destroying `ctx` returned from this function via @ref CeedQFunctionContextDestroy(). 1776512bb800SJeremy L Thompson 1777ca94c3ddSJeremy 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`. 1778ca94c3ddSJeremy L Thompson This `CeedQFunctionContext` will be destroyed if `ctx` is the only reference to this `CeedQFunctionContext`. 17790126412dSJeremy L Thompson 1780ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1781ca94c3ddSJeremy L Thompson @param[out] ctx Variable to store `CeedQFunctionContext` 17820126412dSJeremy L Thompson 17830126412dSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 17840126412dSJeremy L Thompson 1785859c15bbSJames Wright @ref Advanced 17860126412dSJeremy L Thompson **/ 17870126412dSJeremy L Thompson int CeedOperatorGetContext(CeedOperator op, CeedQFunctionContext *ctx) { 17881203703bSJeremy L Thompson bool is_composite; 17891203703bSJeremy L Thompson CeedQFunction qf; 17901203703bSJeremy L Thompson CeedQFunctionContext qf_ctx; 17911203703bSJeremy L Thompson 17921203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 17936e536b99SJeremy L Thompson CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, "Cannot retrieve CeedQFunctionContext for composite operator"); 17941203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 17951203703bSJeremy L Thompson CeedCall(CeedQFunctionGetInnerContext(qf, &qf_ctx)); 1796c11e12f4SJeremy L Thompson CeedCall(CeedQFunctionDestroy(&qf)); 1797*1485364cSJeremy L Thompson *ctx = NULL; 17981203703bSJeremy L Thompson if (qf_ctx) CeedCall(CeedQFunctionContextReferenceCopy(qf_ctx, ctx)); 17990126412dSJeremy L Thompson return CEED_ERROR_SUCCESS; 18000126412dSJeremy L Thompson } 18010126412dSJeremy L Thompson 18020126412dSJeremy L Thompson /** 1803ca94c3ddSJeremy L Thompson @brief Get label for a registered `CeedQFunctionContext` field, or `NULL` if no field has been registered with this `field_name`. 18043668ca4bSJeremy L Thompson 1805ca94c3ddSJeremy L Thompson Fields are registered via `CeedQFunctionContextRegister*()` functions (eg. @ref CeedQFunctionContextRegisterDouble()). 1806859c15bbSJames Wright 1807ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 18083668ca4bSJeremy L Thompson @param[in] field_name Name of field to retrieve label 18093668ca4bSJeremy L Thompson @param[out] field_label Variable to field label 18103668ca4bSJeremy L Thompson 18113668ca4bSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 18123668ca4bSJeremy L Thompson 18133668ca4bSJeremy L Thompson @ref User 18143668ca4bSJeremy L Thompson **/ 181517b0d5c6SJeremy L Thompson int CeedOperatorGetContextFieldLabel(CeedOperator op, const char *field_name, CeedContextFieldLabel *field_label) { 18161c66c397SJeremy L Thompson bool is_composite, field_found = false; 18171c66c397SJeremy L Thompson 18182b730f8bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 18192b730f8bSJeremy L Thompson 18203668ca4bSJeremy L Thompson if (is_composite) { 1821a98a090bSJeremy L Thompson // Composite operator 1822a98a090bSJeremy L Thompson // -- Check if composite label already created 18233668ca4bSJeremy L Thompson for (CeedInt i = 0; i < op->num_context_labels; i++) { 18243668ca4bSJeremy L Thompson if (!strcmp(op->context_labels[i]->name, field_name)) { 18253668ca4bSJeremy L Thompson *field_label = op->context_labels[i]; 18263668ca4bSJeremy L Thompson return CEED_ERROR_SUCCESS; 18273668ca4bSJeremy L Thompson } 18283668ca4bSJeremy L Thompson } 18293668ca4bSJeremy L Thompson 1830a98a090bSJeremy L Thompson // -- Create composite label if needed 18313668ca4bSJeremy L Thompson CeedInt num_sub; 18323668ca4bSJeremy L Thompson CeedOperator *sub_operators; 18333668ca4bSJeremy L Thompson CeedContextFieldLabel new_field_label; 18343668ca4bSJeremy L Thompson 18352b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, &new_field_label)); 1836c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub)); 1837c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 18382b730f8bSJeremy L Thompson CeedCall(CeedCalloc(num_sub, &new_field_label->sub_labels)); 18393668ca4bSJeremy L Thompson new_field_label->num_sub_labels = num_sub; 18403668ca4bSJeremy L Thompson 18413668ca4bSJeremy L Thompson for (CeedInt i = 0; i < num_sub; i++) { 18423668ca4bSJeremy L Thompson if (sub_operators[i]->qf->ctx) { 18433668ca4bSJeremy L Thompson CeedContextFieldLabel new_field_label_i; 18441c66c397SJeremy L Thompson 18452b730f8bSJeremy L Thompson CeedCall(CeedQFunctionContextGetFieldLabel(sub_operators[i]->qf->ctx, field_name, &new_field_label_i)); 18463668ca4bSJeremy L Thompson if (new_field_label_i) { 1847a98a090bSJeremy L Thompson field_found = true; 18483668ca4bSJeremy L Thompson new_field_label->sub_labels[i] = new_field_label_i; 18493668ca4bSJeremy L Thompson new_field_label->name = new_field_label_i->name; 18503668ca4bSJeremy L Thompson new_field_label->description = new_field_label_i->description; 18512b730f8bSJeremy L Thompson if (new_field_label->type && new_field_label->type != new_field_label_i->type) { 18527bfe0f0eSJeremy L Thompson // LCOV_EXCL_START 18532b730f8bSJeremy L Thompson CeedCall(CeedFree(&new_field_label)); 18546e536b99SJeremy L Thompson return CeedError(CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, "Incompatible field types on sub-operator contexts. %s != %s", 18552b730f8bSJeremy L Thompson CeedContextFieldTypes[new_field_label->type], CeedContextFieldTypes[new_field_label_i->type]); 18567bfe0f0eSJeremy L Thompson // LCOV_EXCL_STOP 18577bfe0f0eSJeremy L Thompson } else { 18587bfe0f0eSJeremy L Thompson new_field_label->type = new_field_label_i->type; 18597bfe0f0eSJeremy L Thompson } 18602b730f8bSJeremy L Thompson if (new_field_label->num_values != 0 && new_field_label->num_values != new_field_label_i->num_values) { 18617bfe0f0eSJeremy L Thompson // LCOV_EXCL_START 18622b730f8bSJeremy L Thompson CeedCall(CeedFree(&new_field_label)); 18636e536b99SJeremy L Thompson return CeedError(CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, 18646e536b99SJeremy L Thompson "Incompatible field number of values on sub-operator contexts. %zu != %zu", new_field_label->num_values, 18656e536b99SJeremy L Thompson new_field_label_i->num_values); 18667bfe0f0eSJeremy L Thompson // LCOV_EXCL_STOP 18677bfe0f0eSJeremy L Thompson } else { 18687bfe0f0eSJeremy L Thompson new_field_label->num_values = new_field_label_i->num_values; 18697bfe0f0eSJeremy L Thompson } 18703668ca4bSJeremy L Thompson } 18713668ca4bSJeremy L Thompson } 18723668ca4bSJeremy L Thompson } 1873a98a090bSJeremy L Thompson // -- Cleanup if field was found 1874a98a090bSJeremy L Thompson if (field_found) { 1875a98a090bSJeremy L Thompson *field_label = new_field_label; 1876a98a090bSJeremy L Thompson } else { 18773668ca4bSJeremy L Thompson // LCOV_EXCL_START 18782b730f8bSJeremy L Thompson CeedCall(CeedFree(&new_field_label->sub_labels)); 18792b730f8bSJeremy L Thompson CeedCall(CeedFree(&new_field_label)); 18803668ca4bSJeremy L Thompson *field_label = NULL; 18813668ca4bSJeremy L Thompson // LCOV_EXCL_STOP 18825ac9af79SJeremy L Thompson } 18835ac9af79SJeremy L Thompson } else { 18841203703bSJeremy L Thompson CeedQFunction qf; 18851203703bSJeremy L Thompson CeedQFunctionContext ctx; 18861203703bSJeremy L Thompson 1887a98a090bSJeremy L Thompson // Single, non-composite operator 18881203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 18891203703bSJeremy L Thompson CeedCall(CeedQFunctionGetInnerContext(qf, &ctx)); 1890c11e12f4SJeremy L Thompson CeedCall(CeedQFunctionDestroy(&qf)); 18911203703bSJeremy L Thompson if (ctx) { 18921203703bSJeremy L Thompson CeedCall(CeedQFunctionContextGetFieldLabel(ctx, field_name, field_label)); 1893a98a090bSJeremy L Thompson } else { 1894a98a090bSJeremy L Thompson *field_label = NULL; 1895a98a090bSJeremy L Thompson } 18965ac9af79SJeremy L Thompson } 18975ac9af79SJeremy L Thompson 18985ac9af79SJeremy L Thompson // Set label in operator 18995ac9af79SJeremy L Thompson if (*field_label) { 19005ac9af79SJeremy L Thompson (*field_label)->from_op = true; 19015ac9af79SJeremy L Thompson 19023668ca4bSJeremy L Thompson // Move new composite label to operator 19033668ca4bSJeremy L Thompson if (op->num_context_labels == 0) { 19042b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, &op->context_labels)); 19053668ca4bSJeremy L Thompson op->max_context_labels = 1; 19063668ca4bSJeremy L Thompson } else if (op->num_context_labels == op->max_context_labels) { 19072b730f8bSJeremy L Thompson CeedCall(CeedRealloc(2 * op->num_context_labels, &op->context_labels)); 19083668ca4bSJeremy L Thompson op->max_context_labels *= 2; 19093668ca4bSJeremy L Thompson } 19105ac9af79SJeremy L Thompson op->context_labels[op->num_context_labels] = *field_label; 19113668ca4bSJeremy L Thompson op->num_context_labels++; 19123668ca4bSJeremy L Thompson } 19133668ca4bSJeremy L Thompson return CEED_ERROR_SUCCESS; 19143668ca4bSJeremy L Thompson } 19153668ca4bSJeremy L Thompson 19163668ca4bSJeremy L Thompson /** 1917ca94c3ddSJeremy L Thompson @brief Set `CeedQFunctionContext` field holding double precision values. 19184385fb7fSSebastian Grimberg 1919ca94c3ddSJeremy L Thompson For composite operators, the values are set in all sub-operator `CeedQFunctionContext` that have a matching `field_name`. 1920d8dd9a91SJeremy L Thompson 1921ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 19222788fa27SJeremy L Thompson @param[in] field_label Label of field to set 1923ea61e9acSJeremy L Thompson @param[in] values Values to set 1924d8dd9a91SJeremy L Thompson 1925d8dd9a91SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1926d8dd9a91SJeremy L Thompson 1927d8dd9a91SJeremy L Thompson @ref User 1928d8dd9a91SJeremy L Thompson **/ 192917b0d5c6SJeremy L Thompson int CeedOperatorSetContextDouble(CeedOperator op, CeedContextFieldLabel field_label, double *values) { 19302b730f8bSJeremy L Thompson return CeedOperatorContextSetGeneric(op, field_label, CEED_CONTEXT_FIELD_DOUBLE, values); 1931d8dd9a91SJeremy L Thompson } 1932d8dd9a91SJeremy L Thompson 1933d8dd9a91SJeremy L Thompson /** 1934ca94c3ddSJeremy L Thompson @brief Get `CeedQFunctionContext` field holding double precision values, read-only. 19354385fb7fSSebastian Grimberg 1936ca94c3ddSJeremy L Thompson For composite operators, the values correspond to the first sub-operator `CeedQFunctionContext` that has a matching `field_name`. 19372788fa27SJeremy L Thompson 1938ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 19392788fa27SJeremy L Thompson @param[in] field_label Label of field to get 19402788fa27SJeremy L Thompson @param[out] num_values Number of values in the field label 19412788fa27SJeremy L Thompson @param[out] values Pointer to context values 19422788fa27SJeremy L Thompson 19432788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 19442788fa27SJeremy L Thompson 19452788fa27SJeremy L Thompson @ref User 19462788fa27SJeremy L Thompson **/ 194717b0d5c6SJeremy L Thompson int CeedOperatorGetContextDoubleRead(CeedOperator op, CeedContextFieldLabel field_label, size_t *num_values, const double **values) { 19482788fa27SJeremy L Thompson return CeedOperatorContextGetGenericRead(op, field_label, CEED_CONTEXT_FIELD_DOUBLE, num_values, values); 19492788fa27SJeremy L Thompson } 19502788fa27SJeremy L Thompson 19512788fa27SJeremy L Thompson /** 1952ca94c3ddSJeremy L Thompson @brief Restore `CeedQFunctionContext` field holding double precision values, read-only. 19532788fa27SJeremy L Thompson 1954ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 19552788fa27SJeremy L Thompson @param[in] field_label Label of field to restore 19562788fa27SJeremy L Thompson @param[out] values Pointer to context values 19572788fa27SJeremy L Thompson 19582788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 19592788fa27SJeremy L Thompson 19602788fa27SJeremy L Thompson @ref User 19612788fa27SJeremy L Thompson **/ 196217b0d5c6SJeremy L Thompson int CeedOperatorRestoreContextDoubleRead(CeedOperator op, CeedContextFieldLabel field_label, const double **values) { 19632788fa27SJeremy L Thompson return CeedOperatorContextRestoreGenericRead(op, field_label, CEED_CONTEXT_FIELD_DOUBLE, values); 19642788fa27SJeremy L Thompson } 19652788fa27SJeremy L Thompson 19662788fa27SJeremy L Thompson /** 1967ca94c3ddSJeremy L Thompson @brief Set `CeedQFunctionContext` field holding `int32` values. 19684385fb7fSSebastian Grimberg 1969ca94c3ddSJeremy L Thompson For composite operators, the values are set in all sub-operator `CeedQFunctionContext` that have a matching `field_name`. 1970d8dd9a91SJeremy L Thompson 1971ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 1972ea61e9acSJeremy L Thompson @param[in] field_label Label of field to set 1973ea61e9acSJeremy L Thompson @param[in] values Values to set 1974d8dd9a91SJeremy L Thompson 1975d8dd9a91SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1976d8dd9a91SJeremy L Thompson 1977d8dd9a91SJeremy L Thompson @ref User 1978d8dd9a91SJeremy L Thompson **/ 197923dbfd29SJeremy L Thompson int CeedOperatorSetContextInt32(CeedOperator op, CeedContextFieldLabel field_label, int32_t *values) { 19802b730f8bSJeremy L Thompson return CeedOperatorContextSetGeneric(op, field_label, CEED_CONTEXT_FIELD_INT32, values); 1981d8dd9a91SJeremy L Thompson } 1982d8dd9a91SJeremy L Thompson 1983d8dd9a91SJeremy L Thompson /** 1984ca94c3ddSJeremy L Thompson @brief Get `CeedQFunctionContext` field holding `int32` values, read-only. 19854385fb7fSSebastian Grimberg 1986ca94c3ddSJeremy L Thompson For composite operators, the values correspond to the first sub-operator `CeedQFunctionContext` that has a matching `field_name`. 19872788fa27SJeremy L Thompson 1988ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 19892788fa27SJeremy L Thompson @param[in] field_label Label of field to get 1990ca94c3ddSJeremy L Thompson @param[out] num_values Number of `int32` values in `values` 19912788fa27SJeremy L Thompson @param[out] values Pointer to context values 19922788fa27SJeremy L Thompson 19932788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 19942788fa27SJeremy L Thompson 19952788fa27SJeremy L Thompson @ref User 19962788fa27SJeremy L Thompson **/ 199723dbfd29SJeremy L Thompson int CeedOperatorGetContextInt32Read(CeedOperator op, CeedContextFieldLabel field_label, size_t *num_values, const int32_t **values) { 19982788fa27SJeremy L Thompson return CeedOperatorContextGetGenericRead(op, field_label, CEED_CONTEXT_FIELD_INT32, num_values, values); 19992788fa27SJeremy L Thompson } 20002788fa27SJeremy L Thompson 20012788fa27SJeremy L Thompson /** 2002ca94c3ddSJeremy L Thompson @brief Restore `CeedQFunctionContext` field holding `int32` values, read-only. 20032788fa27SJeremy L Thompson 2004ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 20052788fa27SJeremy L Thompson @param[in] field_label Label of field to get 20062788fa27SJeremy L Thompson @param[out] values Pointer to context values 20072788fa27SJeremy L Thompson 20082788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 20092788fa27SJeremy L Thompson 20102788fa27SJeremy L Thompson @ref User 20112788fa27SJeremy L Thompson **/ 201223dbfd29SJeremy L Thompson int CeedOperatorRestoreContextInt32Read(CeedOperator op, CeedContextFieldLabel field_label, const int32_t **values) { 20132788fa27SJeremy L Thompson return CeedOperatorContextRestoreGenericRead(op, field_label, CEED_CONTEXT_FIELD_INT32, values); 20142788fa27SJeremy L Thompson } 20152788fa27SJeremy L Thompson 20162788fa27SJeremy L Thompson /** 2017ca94c3ddSJeremy L Thompson @brief Set `CeedQFunctionContext` field holding boolean values. 20185b6ec284SJeremy L Thompson 2019ca94c3ddSJeremy L Thompson For composite operators, the values are set in all sub-operator `CeedQFunctionContext` that have a matching `field_name`. 20205b6ec284SJeremy L Thompson 2021ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 20225b6ec284SJeremy L Thompson @param[in] field_label Label of field to set 20235b6ec284SJeremy L Thompson @param[in] values Values to set 20245b6ec284SJeremy L Thompson 20255b6ec284SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 20265b6ec284SJeremy L Thompson 20275b6ec284SJeremy L Thompson @ref User 20285b6ec284SJeremy L Thompson **/ 20295b6ec284SJeremy L Thompson int CeedOperatorSetContextBoolean(CeedOperator op, CeedContextFieldLabel field_label, bool *values) { 20305b6ec284SJeremy L Thompson return CeedOperatorContextSetGeneric(op, field_label, CEED_CONTEXT_FIELD_BOOL, values); 20315b6ec284SJeremy L Thompson } 20325b6ec284SJeremy L Thompson 20335b6ec284SJeremy L Thompson /** 2034ca94c3ddSJeremy L Thompson @brief Get `CeedQFunctionContext` field holding boolean values, read-only. 20355b6ec284SJeremy L Thompson 2036ca94c3ddSJeremy L Thompson For composite operators, the values correspond to the first sub-operator `CeedQFunctionContext` that has a matching `field_name`. 20375b6ec284SJeremy L Thompson 2038ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 20395b6ec284SJeremy L Thompson @param[in] field_label Label of field to get 2040ca94c3ddSJeremy L Thompson @param[out] num_values Number of boolean values in `values` 20415b6ec284SJeremy L Thompson @param[out] values Pointer to context values 20425b6ec284SJeremy L Thompson 20435b6ec284SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 20445b6ec284SJeremy L Thompson 20455b6ec284SJeremy L Thompson @ref User 20465b6ec284SJeremy L Thompson **/ 20475b6ec284SJeremy L Thompson int CeedOperatorGetContextBooleanRead(CeedOperator op, CeedContextFieldLabel field_label, size_t *num_values, const bool **values) { 20485b6ec284SJeremy L Thompson return CeedOperatorContextGetGenericRead(op, field_label, CEED_CONTEXT_FIELD_BOOL, num_values, values); 20495b6ec284SJeremy L Thompson } 20505b6ec284SJeremy L Thompson 20515b6ec284SJeremy L Thompson /** 2052ca94c3ddSJeremy L Thompson @brief Restore `CeedQFunctionContext` field holding boolean values, read-only. 20535b6ec284SJeremy L Thompson 2054ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 20555b6ec284SJeremy L Thompson @param[in] field_label Label of field to get 20565b6ec284SJeremy L Thompson @param[out] values Pointer to context values 20575b6ec284SJeremy L Thompson 20585b6ec284SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 20595b6ec284SJeremy L Thompson 20605b6ec284SJeremy L Thompson @ref User 20615b6ec284SJeremy L Thompson **/ 20625b6ec284SJeremy L Thompson int CeedOperatorRestoreContextBooleanRead(CeedOperator op, CeedContextFieldLabel field_label, const bool **values) { 20635b6ec284SJeremy L Thompson return CeedOperatorContextRestoreGenericRead(op, field_label, CEED_CONTEXT_FIELD_BOOL, values); 20645b6ec284SJeremy L Thompson } 20655b6ec284SJeremy L Thompson 20665b6ec284SJeremy L Thompson /** 2067ca94c3ddSJeremy L Thompson @brief Apply `CeedOperator` to a `CeedVector`. 2068d7b241e6Sjeremylt 2069ea61e9acSJeremy L Thompson This computes the action of the operator on the specified (active) input, yielding its (active) output. 2070ca94c3ddSJeremy L Thompson All inputs and outputs must be specified using @ref CeedOperatorSetField(). 2071d7b241e6Sjeremylt 2072ca94c3ddSJeremy L Thompson Note: Calling this function asserts that setup is complete and sets the `CeedOperator` as immutable. 2073f04ea552SJeremy L Thompson 2074ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to apply 2075ca94c3ddSJeremy L Thompson @param[in] in `CeedVector` containing input state or @ref CEED_VECTOR_NONE if there are no active inputs 2076ca94c3ddSJeremy 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 2077ca94c3ddSJeremy L Thompson @param[in] request Address of @ref CeedRequest for non-blocking completion, else @ref CEED_REQUEST_IMMEDIATE 2078b11c1e72Sjeremylt 2079b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 2080dfdf5a53Sjeremylt 20817a982d89SJeremy L. Thompson @ref User 2082b11c1e72Sjeremylt **/ 20832b730f8bSJeremy L Thompson int CeedOperatorApply(CeedOperator op, CeedVector in, CeedVector out, CeedRequest *request) { 20841203703bSJeremy L Thompson bool is_composite; 20851203703bSJeremy L Thompson 20862b730f8bSJeremy L Thompson CeedCall(CeedOperatorCheckReady(op)); 2087d7b241e6Sjeremylt 20881203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 20891203703bSJeremy L Thompson if (is_composite) { 2090250756a7Sjeremylt // Composite Operator 2091250756a7Sjeremylt if (op->ApplyComposite) { 20922b730f8bSJeremy L Thompson CeedCall(op->ApplyComposite(op, in, out, request)); 2093250756a7Sjeremylt } else { 2094d1d35e2fSjeremylt CeedInt num_suboperators; 2095d1d35e2fSjeremylt CeedOperator *sub_operators; 20961c66c397SJeremy L Thompson 20971c66c397SJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 2098c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 2099250756a7Sjeremylt 2100250756a7Sjeremylt // Zero all output vectors 21013ca2b39bSJeremy L Thompson if (out != CEED_VECTOR_NONE) CeedCall(CeedVectorSetValue(out, 0.0)); 2102d1d35e2fSjeremylt for (CeedInt i = 0; i < num_suboperators; i++) { 21031203703bSJeremy L Thompson CeedInt num_output_fields; 21041203703bSJeremy L Thompson CeedOperatorField *output_fields; 21051c66c397SJeremy L Thompson 21061203703bSJeremy L Thompson CeedCall(CeedOperatorGetFields(sub_operators[i], NULL, NULL, &num_output_fields, &output_fields)); 21071203703bSJeremy L Thompson for (CeedInt j = 0; j < num_output_fields; j++) { 21081203703bSJeremy L Thompson CeedVector vec; 21091203703bSJeremy L Thompson 21101203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(output_fields[j], &vec)); 2111250756a7Sjeremylt if (vec != CEED_VECTOR_ACTIVE && vec != CEED_VECTOR_NONE) { 21122b730f8bSJeremy L Thompson CeedCall(CeedVectorSetValue(vec, 0.0)); 2113250756a7Sjeremylt } 2114681d0ea7SJeremy L Thompson CeedCall(CeedVectorDestroy(&vec)); 2115250756a7Sjeremylt } 2116250756a7Sjeremylt } 2117250756a7Sjeremylt // Apply 2118f754c177SSebastian Grimberg for (CeedInt i = 0; i < num_suboperators; i++) { 2119f754c177SSebastian Grimberg CeedCall(CeedOperatorApplyAdd(sub_operators[i], in, out, request)); 2120cae8b89aSjeremylt } 2121cae8b89aSjeremylt } 21223ca2b39bSJeremy L Thompson } else { 21233ca2b39bSJeremy L Thompson // Standard Operator 21243ca2b39bSJeremy L Thompson if (op->Apply) { 21253ca2b39bSJeremy L Thompson CeedCall(op->Apply(op, in, out, request)); 21263ca2b39bSJeremy L Thompson } else { 21271203703bSJeremy L Thompson CeedInt num_output_fields; 21281203703bSJeremy L Thompson CeedOperatorField *output_fields; 21291203703bSJeremy L Thompson 21301203703bSJeremy L Thompson CeedCall(CeedOperatorGetFields(op, NULL, NULL, &num_output_fields, &output_fields)); 21313ca2b39bSJeremy L Thompson // Zero all output vectors 21321203703bSJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 2133681d0ea7SJeremy L Thompson bool is_active; 21341203703bSJeremy L Thompson CeedVector vec; 21351c66c397SJeremy L Thompson 21361203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(output_fields[i], &vec)); 2137681d0ea7SJeremy L Thompson is_active = vec == CEED_VECTOR_ACTIVE; 2138681d0ea7SJeremy L Thompson if (is_active) vec = out; 21393ca2b39bSJeremy L Thompson if (vec != CEED_VECTOR_NONE) CeedCall(CeedVectorSetValue(vec, 0.0)); 2140681d0ea7SJeremy L Thompson if (!is_active) CeedCall(CeedVectorDestroy(&vec)); 21413ca2b39bSJeremy L Thompson } 21423ca2b39bSJeremy L Thompson // Apply 21431203703bSJeremy L Thompson if (op->num_elem > 0) CeedCall(op->ApplyAdd(op, in, out, request)); 21443ca2b39bSJeremy L Thompson } 2145250756a7Sjeremylt } 2146e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 2147cae8b89aSjeremylt } 2148cae8b89aSjeremylt 2149cae8b89aSjeremylt /** 2150ca94c3ddSJeremy L Thompson @brief Apply `CeedOperator` to a `CeedVector` and add result to output `CeedVector`. 2151cae8b89aSjeremylt 2152ea61e9acSJeremy L Thompson This computes the action of the operator on the specified (active) input, yielding its (active) output. 2153ca94c3ddSJeremy L Thompson All inputs and outputs must be specified using @ref CeedOperatorSetField(). 2154cae8b89aSjeremylt 2155ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to apply 2156ca94c3ddSJeremy L Thompson @param[in] in `CeedVector` containing input state or @ref CEED_VECTOR_NONE if there are no active inputs 2157ca94c3ddSJeremy 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 2158ca94c3ddSJeremy L Thompson @param[in] request Address of @ref CeedRequest for non-blocking completion, else @ref CEED_REQUEST_IMMEDIATE 2159cae8b89aSjeremylt 2160cae8b89aSjeremylt @return An error code: 0 - success, otherwise - failure 2161cae8b89aSjeremylt 21627a982d89SJeremy L. Thompson @ref User 2163cae8b89aSjeremylt **/ 21642b730f8bSJeremy L Thompson int CeedOperatorApplyAdd(CeedOperator op, CeedVector in, CeedVector out, CeedRequest *request) { 21651203703bSJeremy L Thompson bool is_composite; 21661203703bSJeremy L Thompson 21672b730f8bSJeremy L Thompson CeedCall(CeedOperatorCheckReady(op)); 2168cae8b89aSjeremylt 21691203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 21701203703bSJeremy L Thompson if (is_composite) { 2171250756a7Sjeremylt // Composite Operator 2172250756a7Sjeremylt if (op->ApplyAddComposite) { 21732b730f8bSJeremy L Thompson CeedCall(op->ApplyAddComposite(op, in, out, request)); 2174cae8b89aSjeremylt } else { 2175d1d35e2fSjeremylt CeedInt num_suboperators; 2176d1d35e2fSjeremylt CeedOperator *sub_operators; 2177250756a7Sjeremylt 21781c66c397SJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 21791c66c397SJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 2180d1d35e2fSjeremylt for (CeedInt i = 0; i < num_suboperators; i++) { 21812b730f8bSJeremy L Thompson CeedCall(CeedOperatorApplyAdd(sub_operators[i], in, out, request)); 21821d7d2407SJeremy L Thompson } 2183250756a7Sjeremylt } 21841203703bSJeremy L Thompson } else if (op->num_elem > 0) { 21853ca2b39bSJeremy L Thompson // Standard Operator 21863ca2b39bSJeremy L Thompson CeedCall(op->ApplyAdd(op, in, out, request)); 2187250756a7Sjeremylt } 2188e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 2189d7b241e6Sjeremylt } 2190d7b241e6Sjeremylt 2191d7b241e6Sjeremylt /** 2192536b928cSSebastian Grimberg @brief Destroy temporary assembly data associated with a `CeedOperator` 2193536b928cSSebastian Grimberg 2194536b928cSSebastian Grimberg @param[in,out] op `CeedOperator` whose assembly data to destroy 2195536b928cSSebastian Grimberg 2196536b928cSSebastian Grimberg @return An error code: 0 - success, otherwise - failure 2197536b928cSSebastian Grimberg 2198536b928cSSebastian Grimberg @ref User 2199536b928cSSebastian Grimberg **/ 2200536b928cSSebastian Grimberg int CeedOperatorAssemblyDataStrip(CeedOperator op) { 2201536b928cSSebastian Grimberg bool is_composite; 2202536b928cSSebastian Grimberg 2203536b928cSSebastian Grimberg CeedCall(CeedQFunctionAssemblyDataDestroy(&op->qf_assembled)); 2204536b928cSSebastian Grimberg CeedCall(CeedOperatorAssemblyDataDestroy(&op->op_assembled)); 2205536b928cSSebastian Grimberg CeedCall(CeedOperatorIsComposite(op, &is_composite)); 2206536b928cSSebastian Grimberg if (is_composite) { 2207536b928cSSebastian Grimberg CeedInt num_suboperators; 2208536b928cSSebastian Grimberg CeedOperator *sub_operators; 2209536b928cSSebastian Grimberg 2210536b928cSSebastian Grimberg CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 2211536b928cSSebastian Grimberg CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 2212536b928cSSebastian Grimberg for (CeedInt i = 0; i < num_suboperators; i++) { 2213536b928cSSebastian Grimberg CeedCall(CeedQFunctionAssemblyDataDestroy(&sub_operators[i]->qf_assembled)); 2214536b928cSSebastian Grimberg CeedCall(CeedOperatorAssemblyDataDestroy(&sub_operators[i]->op_assembled)); 2215536b928cSSebastian Grimberg } 2216536b928cSSebastian Grimberg } 2217536b928cSSebastian Grimberg return CEED_ERROR_SUCCESS; 2218536b928cSSebastian Grimberg } 2219536b928cSSebastian Grimberg 2220536b928cSSebastian Grimberg /** 2221ca94c3ddSJeremy L Thompson @brief Destroy a `CeedOperator` 2222d7b241e6Sjeremylt 2223ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` to destroy 2224b11c1e72Sjeremylt 2225b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 2226dfdf5a53Sjeremylt 22277a982d89SJeremy L. Thompson @ref User 2228b11c1e72Sjeremylt **/ 2229d7b241e6Sjeremylt int CeedOperatorDestroy(CeedOperator *op) { 2230ad6481ceSJeremy L Thompson if (!*op || --(*op)->ref_count > 0) { 2231ad6481ceSJeremy L Thompson *op = NULL; 2232ad6481ceSJeremy L Thompson return CEED_ERROR_SUCCESS; 2233ad6481ceSJeremy L Thompson } 2234f883f0a5SSebastian Grimberg // Backend destroy 2235f883f0a5SSebastian Grimberg if ((*op)->Destroy) { 2236f883f0a5SSebastian Grimberg CeedCall((*op)->Destroy(*op)); 2237f883f0a5SSebastian Grimberg } 2238fe2413ffSjeremylt // Free fields 22392b730f8bSJeremy L Thompson for (CeedInt i = 0; i < (*op)->num_fields; i++) { 2240d1d35e2fSjeremylt if ((*op)->input_fields[i]) { 2241437c7c90SJeremy L Thompson if ((*op)->input_fields[i]->elem_rstr != CEED_ELEMRESTRICTION_NONE) { 2242437c7c90SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&(*op)->input_fields[i]->elem_rstr)); 224315910d16Sjeremylt } 2244356036faSJeremy L Thompson if ((*op)->input_fields[i]->basis != CEED_BASIS_NONE) { 22452b730f8bSJeremy L Thompson CeedCall(CeedBasisDestroy(&(*op)->input_fields[i]->basis)); 224671352a93Sjeremylt } 22472b730f8bSJeremy L Thompson if ((*op)->input_fields[i]->vec != CEED_VECTOR_ACTIVE && (*op)->input_fields[i]->vec != CEED_VECTOR_NONE) { 22482b730f8bSJeremy L Thompson CeedCall(CeedVectorDestroy(&(*op)->input_fields[i]->vec)); 224971352a93Sjeremylt } 22502b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->input_fields[i]->field_name)); 22512b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->input_fields[i])); 2252fe2413ffSjeremylt } 22532b730f8bSJeremy L Thompson } 22542b730f8bSJeremy L Thompson for (CeedInt i = 0; i < (*op)->num_fields; i++) { 2255d1d35e2fSjeremylt if ((*op)->output_fields[i]) { 2256437c7c90SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&(*op)->output_fields[i]->elem_rstr)); 2257356036faSJeremy L Thompson if ((*op)->output_fields[i]->basis != CEED_BASIS_NONE) { 22582b730f8bSJeremy L Thompson CeedCall(CeedBasisDestroy(&(*op)->output_fields[i]->basis)); 225971352a93Sjeremylt } 22602b730f8bSJeremy L Thompson if ((*op)->output_fields[i]->vec != CEED_VECTOR_ACTIVE && (*op)->output_fields[i]->vec != CEED_VECTOR_NONE) { 22612b730f8bSJeremy L Thompson CeedCall(CeedVectorDestroy(&(*op)->output_fields[i]->vec)); 226271352a93Sjeremylt } 22632b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->output_fields[i]->field_name)); 22642b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->output_fields[i])); 22652b730f8bSJeremy L Thompson } 2266fe2413ffSjeremylt } 2267f883f0a5SSebastian Grimberg CeedCall(CeedFree(&(*op)->input_fields)); 2268f883f0a5SSebastian Grimberg CeedCall(CeedFree(&(*op)->output_fields)); 2269f883f0a5SSebastian Grimberg // Destroy AtPoints data 227048acf710SJeremy L Thompson CeedCall(CeedVectorDestroy(&(*op)->point_coords)); 227148acf710SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&(*op)->rstr_points)); 227248acf710SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&(*op)->first_points_rstr)); 2273c6b536a8SSebastian Grimberg // Destroy assembly data (must happen before destroying sub_operators) 2274f883f0a5SSebastian Grimberg CeedCall(CeedOperatorAssemblyDataStrip(*op)); 2275d1d35e2fSjeremylt // Destroy sub_operators 22762b730f8bSJeremy L Thompson for (CeedInt i = 0; i < (*op)->num_suboperators; i++) { 2277d1d35e2fSjeremylt if ((*op)->sub_operators[i]) { 22782b730f8bSJeremy L Thompson CeedCall(CeedOperatorDestroy(&(*op)->sub_operators[i])); 227952d6035fSJeremy L Thompson } 22802b730f8bSJeremy L Thompson } 2281f883f0a5SSebastian Grimberg CeedCall(CeedFree(&(*op)->sub_operators)); 22822b730f8bSJeremy L Thompson CeedCall(CeedQFunctionDestroy(&(*op)->qf)); 22832b730f8bSJeremy L Thompson CeedCall(CeedQFunctionDestroy(&(*op)->dqf)); 22842b730f8bSJeremy L Thompson CeedCall(CeedQFunctionDestroy(&(*op)->dqfT)); 22853668ca4bSJeremy L Thompson // Destroy any composite labels 22865ac9af79SJeremy L Thompson if ((*op)->is_composite) { 22873668ca4bSJeremy L Thompson for (CeedInt i = 0; i < (*op)->num_context_labels; i++) { 22882b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->context_labels[i]->sub_labels)); 22892b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->context_labels[i])); 22903668ca4bSJeremy L Thompson } 22915ac9af79SJeremy L Thompson } 22922b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->context_labels)); 2293fe2413ffSjeremylt 22945107b09fSJeremy L Thompson // Destroy fallback 22952b730f8bSJeremy L Thompson CeedCall(CeedOperatorDestroy(&(*op)->op_fallback)); 22965107b09fSJeremy L Thompson 22972b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->name)); 2298f883f0a5SSebastian Grimberg CeedCall(CeedDestroy(&(*op)->ceed)); 22992b730f8bSJeremy L Thompson CeedCall(CeedFree(op)); 2300e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 2301d7b241e6Sjeremylt } 2302d7b241e6Sjeremylt 2303d7b241e6Sjeremylt /// @} 2304