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)); 151*c11e12f4SJeremy 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 CeedQFunction qf; 3741203703bSJeremy L Thompson CeedQFunctionContext ctx; 3751203703bSJeremy L Thompson 3761203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(sub_operators[i], &qf)); 3771203703bSJeremy L Thompson CeedCall(CeedQFunctionGetContext(qf, &ctx)); 378*c11e12f4SJeremy L Thompson CeedCall(CeedQFunctionDestroy(&qf)); 379d8dd9a91SJeremy L Thompson // Try every sub-operator, ok if some sub-operators do not have field 3801203703bSJeremy L Thompson if (field_label->sub_labels[i] && ctx) { 3811203703bSJeremy L Thompson CeedCall(CeedQFunctionContextSetGeneric(ctx, field_label->sub_labels[i], field_type, values)); 382d8dd9a91SJeremy L Thompson } 383d8dd9a91SJeremy L Thompson } 384d8dd9a91SJeremy L Thompson } else { 3851203703bSJeremy L Thompson CeedQFunction qf; 3861203703bSJeremy L Thompson CeedQFunctionContext ctx; 3871203703bSJeremy L Thompson 3881203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 3891203703bSJeremy L Thompson CeedCall(CeedQFunctionGetContext(qf, &ctx)); 390*c11e12f4SJeremy L Thompson CeedCall(CeedQFunctionDestroy(&qf)); 3919bc66399SJeremy L Thompson CeedCheck(ctx, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "QFunction does not have context data"); 3921203703bSJeremy L Thompson CeedCall(CeedQFunctionContextSetGeneric(ctx, field_label, field_type, values)); 3932788fa27SJeremy L Thompson } 3946d95ab46SJeremy L Thompson CeedCall(CeedOperatorSetQFunctionAssemblyDataUpdateNeeded(op, true)); 3952788fa27SJeremy L Thompson return CEED_ERROR_SUCCESS; 3962788fa27SJeremy L Thompson } 3972788fa27SJeremy L Thompson 3982788fa27SJeremy L Thompson /** 399ca94c3ddSJeremy L Thompson @brief Get `CeedQFunctionContext` field values of the specified type, read-only. 4004385fb7fSSebastian Grimberg 401ca94c3ddSJeremy L Thompson For composite operators, the values retrieved are for the first sub-operator `CeedQFunctionContext` that have a matching `field_name`. 402ca94c3ddSJeremy 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. 4032788fa27SJeremy L Thompson 404ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 4052788fa27SJeremy L Thompson @param[in] field_label Label of field to set 4062788fa27SJeremy L Thompson @param[in] field_type Type of field to set 407c5d0f995SJed Brown @param[out] num_values Number of values of type `field_type` in array `values` 408c5d0f995SJed Brown @param[out] values Values in the label 4092788fa27SJeremy L Thompson 4102788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 4112788fa27SJeremy L Thompson 4122788fa27SJeremy L Thompson @ref User 4132788fa27SJeremy L Thompson **/ 4142788fa27SJeremy L Thompson static int CeedOperatorContextGetGenericRead(CeedOperator op, CeedContextFieldLabel field_label, CeedContextFieldType field_type, size_t *num_values, 4152788fa27SJeremy L Thompson void *values) { 4161c66c397SJeremy L Thompson bool is_composite = false; 4171c66c397SJeremy L Thompson 4189bc66399SJeremy L Thompson CeedCheck(field_label, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "Invalid field label"); 4192788fa27SJeremy L Thompson 4202788fa27SJeremy L Thompson *(void **)values = NULL; 4212788fa27SJeremy L Thompson *num_values = 0; 4222788fa27SJeremy L Thompson 4235ac9af79SJeremy L Thompson // Check if field_label and op correspond 4245ac9af79SJeremy L Thompson if (field_label->from_op) { 4255ac9af79SJeremy L Thompson CeedInt index = -1; 4265ac9af79SJeremy L Thompson 4275ac9af79SJeremy L Thompson for (CeedInt i = 0; i < op->num_context_labels; i++) { 4285ac9af79SJeremy L Thompson if (op->context_labels[i] == field_label) index = i; 4295ac9af79SJeremy L Thompson } 4309bc66399SJeremy L Thompson CeedCheck(index != -1, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "ContextFieldLabel does not correspond to the operator"); 4315ac9af79SJeremy L Thompson } 4325ac9af79SJeremy L Thompson 4332788fa27SJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 4342788fa27SJeremy L Thompson if (is_composite) { 4352788fa27SJeremy L Thompson CeedInt num_sub; 4362788fa27SJeremy L Thompson CeedOperator *sub_operators; 4372788fa27SJeremy L Thompson 4382788fa27SJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub)); 4392788fa27SJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 4409bc66399SJeremy L Thompson CeedCheck(num_sub == field_label->num_sub_labels, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, 4419bc66399SJeremy L Thompson "Composite operator modified after ContextFieldLabel created"); 4422788fa27SJeremy L Thompson 4432788fa27SJeremy L Thompson for (CeedInt i = 0; i < num_sub; i++) { 4441203703bSJeremy L Thompson CeedQFunction qf; 4451203703bSJeremy L Thompson CeedQFunctionContext ctx; 4461203703bSJeremy L Thompson 4471203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(sub_operators[i], &qf)); 4481203703bSJeremy L Thompson CeedCall(CeedQFunctionGetContext(qf, &ctx)); 449*c11e12f4SJeremy L Thompson CeedCall(CeedQFunctionDestroy(&qf)); 4502788fa27SJeremy L Thompson // Try every sub-operator, ok if some sub-operators do not have field 4511203703bSJeremy L Thompson if (field_label->sub_labels[i] && ctx) { 4521203703bSJeremy L Thompson CeedCall(CeedQFunctionContextGetGenericRead(ctx, field_label->sub_labels[i], field_type, num_values, values)); 4532788fa27SJeremy L Thompson return CEED_ERROR_SUCCESS; 4542788fa27SJeremy L Thompson } 4552788fa27SJeremy L Thompson } 4562788fa27SJeremy L Thompson } else { 4571203703bSJeremy L Thompson CeedQFunction qf; 4581203703bSJeremy L Thompson CeedQFunctionContext ctx; 4591203703bSJeremy L Thompson 4601203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 4611203703bSJeremy L Thompson CeedCall(CeedQFunctionGetContext(qf, &ctx)); 462*c11e12f4SJeremy L Thompson CeedCall(CeedQFunctionDestroy(&qf)); 4639bc66399SJeremy L Thompson CeedCheck(ctx, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "QFunction does not have context data"); 4641203703bSJeremy L Thompson CeedCall(CeedQFunctionContextGetGenericRead(ctx, field_label, field_type, num_values, values)); 4652788fa27SJeremy L Thompson } 4662788fa27SJeremy L Thompson return CEED_ERROR_SUCCESS; 4672788fa27SJeremy L Thompson } 4682788fa27SJeremy L Thompson 4692788fa27SJeremy L Thompson /** 470ca94c3ddSJeremy L Thompson @brief Restore `CeedQFunctionContext` field values of the specified type, read-only. 4714385fb7fSSebastian Grimberg 472ca94c3ddSJeremy L Thompson For composite operators, the values restored are for the first sub-operator `CeedQFunctionContext` that have a matching `field_name`. 473ca94c3ddSJeremy 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. 4742788fa27SJeremy L Thompson 475ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 4762788fa27SJeremy L Thompson @param[in] field_label Label of field to set 4772788fa27SJeremy L Thompson @param[in] field_type Type of field to set 478c5d0f995SJed Brown @param[in] values Values array to restore 4792788fa27SJeremy L Thompson 4802788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 4812788fa27SJeremy L Thompson 4822788fa27SJeremy L Thompson @ref User 4832788fa27SJeremy L Thompson **/ 4842788fa27SJeremy L Thompson static int CeedOperatorContextRestoreGenericRead(CeedOperator op, CeedContextFieldLabel field_label, CeedContextFieldType field_type, void *values) { 4851c66c397SJeremy L Thompson bool is_composite = false; 4861c66c397SJeremy L Thompson 4879bc66399SJeremy L Thompson CeedCheck(field_label, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "Invalid field label"); 4882788fa27SJeremy L Thompson 4895ac9af79SJeremy L Thompson // Check if field_label and op correspond 4905ac9af79SJeremy L Thompson if (field_label->from_op) { 4915ac9af79SJeremy L Thompson CeedInt index = -1; 4925ac9af79SJeremy L Thompson 4935ac9af79SJeremy L Thompson for (CeedInt i = 0; i < op->num_context_labels; i++) { 4945ac9af79SJeremy L Thompson if (op->context_labels[i] == field_label) index = i; 4955ac9af79SJeremy L Thompson } 4969bc66399SJeremy L Thompson CeedCheck(index != -1, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "ContextFieldLabel does not correspond to the operator"); 4975ac9af79SJeremy L Thompson } 4985ac9af79SJeremy L Thompson 4992788fa27SJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 5002788fa27SJeremy L Thompson if (is_composite) { 5012788fa27SJeremy L Thompson CeedInt num_sub; 5022788fa27SJeremy L Thompson CeedOperator *sub_operators; 5032788fa27SJeremy L Thompson 5042788fa27SJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub)); 5052788fa27SJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 5069bc66399SJeremy L Thompson CeedCheck(num_sub == field_label->num_sub_labels, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, 5079bc66399SJeremy L Thompson "Composite operator modified after ContextFieldLabel created"); 5082788fa27SJeremy L Thompson 5092788fa27SJeremy L Thompson for (CeedInt i = 0; i < num_sub; i++) { 5101203703bSJeremy L Thompson CeedQFunction qf; 5111203703bSJeremy L Thompson CeedQFunctionContext ctx; 5121203703bSJeremy L Thompson 5131203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(sub_operators[i], &qf)); 5141203703bSJeremy L Thompson CeedCall(CeedQFunctionGetContext(qf, &ctx)); 515*c11e12f4SJeremy L Thompson CeedCall(CeedQFunctionDestroy(&qf)); 5162788fa27SJeremy L Thompson // Try every sub-operator, ok if some sub-operators do not have field 5171203703bSJeremy L Thompson if (field_label->sub_labels[i] && ctx) { 5181203703bSJeremy L Thompson CeedCall(CeedQFunctionContextRestoreGenericRead(ctx, field_label->sub_labels[i], field_type, values)); 5192788fa27SJeremy L Thompson return CEED_ERROR_SUCCESS; 5202788fa27SJeremy L Thompson } 5212788fa27SJeremy L Thompson } 5222788fa27SJeremy L Thompson } else { 5231203703bSJeremy L Thompson CeedQFunction qf; 5241203703bSJeremy L Thompson CeedQFunctionContext ctx; 5251203703bSJeremy L Thompson 5261203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 5271203703bSJeremy L Thompson CeedCall(CeedQFunctionGetContext(qf, &ctx)); 528*c11e12f4SJeremy L Thompson CeedCall(CeedQFunctionDestroy(&qf)); 5299bc66399SJeremy L Thompson CeedCheck(ctx, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "QFunction does not have context data"); 5301203703bSJeremy L Thompson CeedCall(CeedQFunctionContextRestoreGenericRead(ctx, field_label, field_type, values)); 531d8dd9a91SJeremy L Thompson } 532d8dd9a91SJeremy L Thompson return CEED_ERROR_SUCCESS; 533d8dd9a91SJeremy L Thompson } 534d8dd9a91SJeremy L Thompson 5357a982d89SJeremy L. Thompson /// @} 5367a982d89SJeremy L. Thompson 5377a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 5387a982d89SJeremy L. Thompson /// CeedOperator Backend API 5397a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 5407a982d89SJeremy L. Thompson /// @addtogroup CeedOperatorBackend 5417a982d89SJeremy L. Thompson /// @{ 5427a982d89SJeremy L. Thompson 5437a982d89SJeremy L. Thompson /** 544ca94c3ddSJeremy L Thompson @brief Get the number of arguments associated with a `CeedOperator` 5457a982d89SJeremy L. Thompson 546ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 547d1d35e2fSjeremylt @param[out] num_args Variable to store vector number of arguments 5487a982d89SJeremy L. Thompson 5497a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 5507a982d89SJeremy L. Thompson 5517a982d89SJeremy L. Thompson @ref Backend 5527a982d89SJeremy L. Thompson **/ 553d1d35e2fSjeremylt int CeedOperatorGetNumArgs(CeedOperator op, CeedInt *num_args) { 5541203703bSJeremy L Thompson bool is_composite; 5551203703bSJeremy L Thompson 5561203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 5576e536b99SJeremy L Thompson CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Not defined for composite operators"); 558d1d35e2fSjeremylt *num_args = op->num_fields; 559e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 5607a982d89SJeremy L. Thompson } 5617a982d89SJeremy L. Thompson 5627a982d89SJeremy L. Thompson /** 5639463e855SJeremy L Thompson @brief Get the tensor product status of all bases for a `CeedOperator`. 5649463e855SJeremy L Thompson 5659463e855SJeremy L Thompson `has_tensor_bases` is only set to `true` if every field uses a tensor-product basis. 5669463e855SJeremy L Thompson 5679463e855SJeremy L Thompson @param[in] op `CeedOperator` 5689463e855SJeremy L Thompson @param[out] has_tensor_bases Variable to store tensor bases status 5699463e855SJeremy L Thompson 5709463e855SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 5719463e855SJeremy L Thompson 5729463e855SJeremy L Thompson @ref Backend 5739463e855SJeremy L Thompson **/ 5749463e855SJeremy L Thompson int CeedOperatorHasTensorBases(CeedOperator op, bool *has_tensor_bases) { 5759463e855SJeremy L Thompson CeedInt num_inputs, num_outputs; 5769463e855SJeremy L Thompson CeedOperatorField *input_fields, *output_fields; 5779463e855SJeremy L Thompson 5789463e855SJeremy L Thompson CeedCall(CeedOperatorGetFields(op, &num_inputs, &input_fields, &num_outputs, &output_fields)); 5799463e855SJeremy L Thompson *has_tensor_bases = true; 5809463e855SJeremy L Thompson for (CeedInt i = 0; i < num_inputs; i++) { 5819463e855SJeremy L Thompson bool is_tensor; 5829463e855SJeremy L Thompson CeedBasis basis; 5839463e855SJeremy L Thompson 5849463e855SJeremy L Thompson CeedCall(CeedOperatorFieldGetBasis(input_fields[i], &basis)); 5859463e855SJeremy L Thompson if (basis != CEED_BASIS_NONE) { 5869463e855SJeremy L Thompson CeedCall(CeedBasisIsTensor(basis, &is_tensor)); 5879463e855SJeremy L Thompson *has_tensor_bases &= is_tensor; 5889463e855SJeremy L Thompson } 589681d0ea7SJeremy L Thompson CeedCall(CeedBasisDestroy(&basis)); 5909463e855SJeremy L Thompson } 5919463e855SJeremy L Thompson for (CeedInt i = 0; i < num_outputs; i++) { 5929463e855SJeremy L Thompson bool is_tensor; 5939463e855SJeremy L Thompson CeedBasis basis; 5949463e855SJeremy L Thompson 5959463e855SJeremy L Thompson CeedCall(CeedOperatorFieldGetBasis(output_fields[i], &basis)); 5969463e855SJeremy L Thompson if (basis != CEED_BASIS_NONE) { 5979463e855SJeremy L Thompson CeedCall(CeedBasisIsTensor(basis, &is_tensor)); 5989463e855SJeremy L Thompson *has_tensor_bases &= is_tensor; 5999463e855SJeremy L Thompson } 600681d0ea7SJeremy L Thompson CeedCall(CeedBasisDestroy(&basis)); 6019463e855SJeremy L Thompson } 6029463e855SJeremy L Thompson return CEED_ERROR_SUCCESS; 6039463e855SJeremy L Thompson } 6049463e855SJeremy L Thompson 6059463e855SJeremy L Thompson /** 6061203703bSJeremy L Thompson @brief Get a boolean value indicating if the `CeedOperator` is immutable 6071203703bSJeremy L Thompson 6081203703bSJeremy L Thompson @param[in] op `CeedOperator` 6091203703bSJeremy L Thompson @param[out] is_immutable Variable to store immutability status 6101203703bSJeremy L Thompson 6111203703bSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 6121203703bSJeremy L Thompson 6131203703bSJeremy L Thompson @ref Backend 6141203703bSJeremy L Thompson **/ 6151203703bSJeremy L Thompson int CeedOperatorIsImmutable(CeedOperator op, bool *is_immutable) { 6161203703bSJeremy L Thompson *is_immutable = op->is_immutable; 6171203703bSJeremy L Thompson return CEED_ERROR_SUCCESS; 6181203703bSJeremy L Thompson } 6191203703bSJeremy L Thompson 6201203703bSJeremy L Thompson /** 621ca94c3ddSJeremy L Thompson @brief Get the setup status of a `CeedOperator` 6227a982d89SJeremy L. Thompson 623ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 624d1d35e2fSjeremylt @param[out] is_setup_done Variable to store setup status 6257a982d89SJeremy L. Thompson 6267a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 6277a982d89SJeremy L. Thompson 6287a982d89SJeremy L. Thompson @ref Backend 6297a982d89SJeremy L. Thompson **/ 630d1d35e2fSjeremylt int CeedOperatorIsSetupDone(CeedOperator op, bool *is_setup_done) { 631f04ea552SJeremy L Thompson *is_setup_done = op->is_backend_setup; 632e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 6337a982d89SJeremy L. Thompson } 6347a982d89SJeremy L. Thompson 6357a982d89SJeremy L. Thompson /** 636ca94c3ddSJeremy L Thompson @brief Get the `CeedQFunction` associated with a `CeedOperator` 6377a982d89SJeremy L. Thompson 638ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 639ca94c3ddSJeremy L Thompson @param[out] qf Variable to store `CeedQFunction` 6407a982d89SJeremy L. Thompson 6417a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 6427a982d89SJeremy L. Thompson 6437a982d89SJeremy L. Thompson @ref Backend 6447a982d89SJeremy L. Thompson **/ 6457a982d89SJeremy L. Thompson int CeedOperatorGetQFunction(CeedOperator op, CeedQFunction *qf) { 6461203703bSJeremy L Thompson bool is_composite; 6471203703bSJeremy L Thompson 6481203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 6496e536b99SJeremy L Thompson CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Not defined for composite operator"); 650*c11e12f4SJeremy L Thompson *qf = NULL; 651*c11e12f4SJeremy L Thompson CeedCall(CeedQFunctionReferenceCopy(op->qf, qf)); 652e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 6537a982d89SJeremy L. Thompson } 6547a982d89SJeremy L. Thompson 6557a982d89SJeremy L. Thompson /** 656ca94c3ddSJeremy L Thompson @brief Get a boolean value indicating if the `CeedOperator` is composite 657c04a41a7SJeremy L Thompson 658ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 659d1d35e2fSjeremylt @param[out] is_composite Variable to store composite status 660c04a41a7SJeremy L Thompson 661c04a41a7SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 662c04a41a7SJeremy L Thompson 663c04a41a7SJeremy L Thompson @ref Backend 664c04a41a7SJeremy L Thompson **/ 665d1d35e2fSjeremylt int CeedOperatorIsComposite(CeedOperator op, bool *is_composite) { 666f04ea552SJeremy L Thompson *is_composite = op->is_composite; 667e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 668c04a41a7SJeremy L Thompson } 669c04a41a7SJeremy L Thompson 670c04a41a7SJeremy L Thompson /** 671ca94c3ddSJeremy L Thompson @brief Get the backend data of a `CeedOperator` 6727a982d89SJeremy L. Thompson 673ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 6747a982d89SJeremy L. Thompson @param[out] data Variable to store data 6757a982d89SJeremy L. Thompson 6767a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 6777a982d89SJeremy L. Thompson 6787a982d89SJeremy L. Thompson @ref Backend 6797a982d89SJeremy L. Thompson **/ 680777ff853SJeremy L Thompson int CeedOperatorGetData(CeedOperator op, void *data) { 681777ff853SJeremy L Thompson *(void **)data = op->data; 682e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 6837a982d89SJeremy L. Thompson } 6847a982d89SJeremy L. Thompson 6857a982d89SJeremy L. Thompson /** 686ca94c3ddSJeremy L Thompson @brief Set the backend data of a `CeedOperator` 6877a982d89SJeremy L. Thompson 688ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 689ea61e9acSJeremy L Thompson @param[in] data Data to set 6907a982d89SJeremy L. Thompson 6917a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 6927a982d89SJeremy L. Thompson 6937a982d89SJeremy L. Thompson @ref Backend 6947a982d89SJeremy L. Thompson **/ 695777ff853SJeremy L Thompson int CeedOperatorSetData(CeedOperator op, void *data) { 696777ff853SJeremy L Thompson op->data = data; 697e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 6987a982d89SJeremy L. Thompson } 6997a982d89SJeremy L. Thompson 7007a982d89SJeremy L. Thompson /** 701ca94c3ddSJeremy L Thompson @brief Increment the reference counter for a `CeedOperator` 70234359f16Sjeremylt 703ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` to increment the reference counter 70434359f16Sjeremylt 70534359f16Sjeremylt @return An error code: 0 - success, otherwise - failure 70634359f16Sjeremylt 70734359f16Sjeremylt @ref Backend 70834359f16Sjeremylt **/ 7099560d06aSjeremylt int CeedOperatorReference(CeedOperator op) { 71034359f16Sjeremylt op->ref_count++; 71134359f16Sjeremylt return CEED_ERROR_SUCCESS; 71234359f16Sjeremylt } 71334359f16Sjeremylt 71434359f16Sjeremylt /** 715ca94c3ddSJeremy L Thompson @brief Set the setup flag of a `CeedOperator` to `true` 7167a982d89SJeremy L. Thompson 717ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 7187a982d89SJeremy L. Thompson 7197a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 7207a982d89SJeremy L. Thompson 7217a982d89SJeremy L. Thompson @ref Backend 7227a982d89SJeremy L. Thompson **/ 7237a982d89SJeremy L. Thompson int CeedOperatorSetSetupDone(CeedOperator op) { 724f04ea552SJeremy L Thompson op->is_backend_setup = true; 725e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 7267a982d89SJeremy L. Thompson } 7277a982d89SJeremy L. Thompson 7287a982d89SJeremy L. Thompson /// @} 7297a982d89SJeremy L. Thompson 7307a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 7317a982d89SJeremy L. Thompson /// CeedOperator Public API 7327a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 7337a982d89SJeremy L. Thompson /// @addtogroup CeedOperatorUser 734dfdf5a53Sjeremylt /// @{ 735d7b241e6Sjeremylt 736d7b241e6Sjeremylt /** 737ca94c3ddSJeremy L Thompson @brief Create a `CeedOperator` and associate a `CeedQFunction`. 7384385fb7fSSebastian Grimberg 739ca94c3ddSJeremy L Thompson A `CeedBasis` and `CeedElemRestriction` can be associated with `CeedQFunction` fields with @ref CeedOperatorSetField(). 740d7b241e6Sjeremylt 741ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` object used to create the `CeedOperator` 742ca94c3ddSJeremy L Thompson @param[in] qf `CeedQFunction` defining the action of the operator at quadrature points 743ca94c3ddSJeremy L Thompson @param[in] dqf `CeedQFunction` defining the action of the Jacobian of `qf` (or @ref CEED_QFUNCTION_NONE) 744ca94c3ddSJeremy L Thompson @param[in] dqfT `CeedQFunction` defining the action of the transpose of the Jacobian of `qf` (or @ref CEED_QFUNCTION_NONE) 745ca94c3ddSJeremy L Thompson @param[out] op Address of the variable where the newly created `CeedOperator` will be stored 746b11c1e72Sjeremylt 747b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 748dfdf5a53Sjeremylt 7497a982d89SJeremy L. Thompson @ref User 750d7b241e6Sjeremylt */ 7512b730f8bSJeremy L Thompson int CeedOperatorCreate(Ceed ceed, CeedQFunction qf, CeedQFunction dqf, CeedQFunction dqfT, CeedOperator *op) { 7525fe0d4faSjeremylt if (!ceed->OperatorCreate) { 7535fe0d4faSjeremylt Ceed delegate; 7546574a04fSJeremy L Thompson 7552b730f8bSJeremy L Thompson CeedCall(CeedGetObjectDelegate(ceed, &delegate, "Operator")); 7561ef3a2a9SJeremy L Thompson CeedCheck(delegate, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not implement CeedOperatorCreate"); 7572b730f8bSJeremy L Thompson CeedCall(CeedOperatorCreate(delegate, qf, dqf, dqfT, op)); 7589bc66399SJeremy L Thompson CeedCall(CeedDestroy(&delegate)); 759e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 7605fe0d4faSjeremylt } 7615fe0d4faSjeremylt 762ca94c3ddSJeremy L Thompson CeedCheck(qf && qf != CEED_QFUNCTION_NONE, ceed, CEED_ERROR_MINOR, "Operator must have a valid CeedQFunction."); 763db002c03SJeremy L Thompson 7642b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, op)); 765db002c03SJeremy L Thompson CeedCall(CeedReferenceCopy(ceed, &(*op)->ceed)); 766d1d35e2fSjeremylt (*op)->ref_count = 1; 7672b104005SJeremy L Thompson (*op)->input_size = -1; 7682b104005SJeremy L Thompson (*op)->output_size = -1; 769db002c03SJeremy L Thompson CeedCall(CeedQFunctionReferenceCopy(qf, &(*op)->qf)); 770db002c03SJeremy L Thompson if (dqf && dqf != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionReferenceCopy(dqf, &(*op)->dqf)); 771db002c03SJeremy L Thompson if (dqfT && dqfT != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionReferenceCopy(dqfT, &(*op)->dqfT)); 7722b730f8bSJeremy L Thompson CeedCall(CeedCalloc(CEED_FIELD_MAX, &(*op)->input_fields)); 7732b730f8bSJeremy L Thompson CeedCall(CeedCalloc(CEED_FIELD_MAX, &(*op)->output_fields)); 7742b730f8bSJeremy L Thompson CeedCall(ceed->OperatorCreate(*op)); 775e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 776d7b241e6Sjeremylt } 777d7b241e6Sjeremylt 778d7b241e6Sjeremylt /** 779ca94c3ddSJeremy L Thompson @brief Create a `CeedOperator` for evaluation at evaluation at arbitrary points in each element. 78048acf710SJeremy L Thompson 781ca94c3ddSJeremy L Thompson A `CeedBasis` and `CeedElemRestriction` can be associated with `CeedQFunction` fields with `CeedOperator` SetField. 782ca94c3ddSJeremy L Thompson The locations of each point are set with @ref CeedOperatorAtPointsSetPoints(). 78348acf710SJeremy L Thompson 784ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` object used to create the `CeedOperator` 785ca94c3ddSJeremy L Thompson @param[in] qf `CeedQFunction` defining the action of the operator at quadrature points 786ca94c3ddSJeremy L Thompson @param[in] dqf `CeedQFunction` defining the action of the Jacobian of @a qf (or @ref CEED_QFUNCTION_NONE) 787ca94c3ddSJeremy L Thompson @param[in] dqfT `CeedQFunction` defining the action of the transpose of the Jacobian of @a qf (or @ref CEED_QFUNCTION_NONE) 78848acf710SJeremy L Thompson @param[out] op Address of the variable where the newly created CeedOperator will be stored 78948acf710SJeremy L Thompson 79048acf710SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 79148acf710SJeremy L Thompson 79248acf710SJeremy L Thompson @ref User 79348acf710SJeremy L Thompson */ 79448acf710SJeremy L Thompson int CeedOperatorCreateAtPoints(Ceed ceed, CeedQFunction qf, CeedQFunction dqf, CeedQFunction dqfT, CeedOperator *op) { 79548acf710SJeremy L Thompson if (!ceed->OperatorCreateAtPoints) { 79648acf710SJeremy L Thompson Ceed delegate; 79748acf710SJeremy L Thompson 79848acf710SJeremy L Thompson CeedCall(CeedGetObjectDelegate(ceed, &delegate, "Operator")); 7991ef3a2a9SJeremy L Thompson CeedCheck(delegate, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not implement CeedOperatorCreateAtPoints"); 80048acf710SJeremy L Thompson CeedCall(CeedOperatorCreateAtPoints(delegate, qf, dqf, dqfT, op)); 8019bc66399SJeremy L Thompson CeedCall(CeedDestroy(&delegate)); 80248acf710SJeremy L Thompson return CEED_ERROR_SUCCESS; 80348acf710SJeremy L Thompson } 80448acf710SJeremy L Thompson 805ca94c3ddSJeremy L Thompson CeedCheck(qf && qf != CEED_QFUNCTION_NONE, ceed, CEED_ERROR_MINOR, "Operator must have a valid CeedQFunction."); 80648acf710SJeremy L Thompson 80748acf710SJeremy L Thompson CeedCall(CeedCalloc(1, op)); 80848acf710SJeremy L Thompson CeedCall(CeedReferenceCopy(ceed, &(*op)->ceed)); 80948acf710SJeremy L Thompson (*op)->ref_count = 1; 81048acf710SJeremy L Thompson (*op)->is_at_points = true; 81148acf710SJeremy L Thompson (*op)->input_size = -1; 81248acf710SJeremy L Thompson (*op)->output_size = -1; 81348acf710SJeremy L Thompson CeedCall(CeedQFunctionReferenceCopy(qf, &(*op)->qf)); 81448acf710SJeremy L Thompson if (dqf && dqf != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionReferenceCopy(dqf, &(*op)->dqf)); 81548acf710SJeremy L Thompson if (dqfT && dqfT != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionReferenceCopy(dqfT, &(*op)->dqfT)); 81648acf710SJeremy L Thompson CeedCall(CeedCalloc(CEED_FIELD_MAX, &(*op)->input_fields)); 81748acf710SJeremy L Thompson CeedCall(CeedCalloc(CEED_FIELD_MAX, &(*op)->output_fields)); 81848acf710SJeremy L Thompson CeedCall(ceed->OperatorCreateAtPoints(*op)); 81948acf710SJeremy L Thompson return CEED_ERROR_SUCCESS; 82048acf710SJeremy L Thompson } 82148acf710SJeremy L Thompson 82248acf710SJeremy L Thompson /** 823ca94c3ddSJeremy L Thompson @brief Create a composite `CeedOperator` that composes the action of several `CeedOperator` 82452d6035fSJeremy L Thompson 825ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` object used to create the `CeedOperator` 826ca94c3ddSJeremy L Thompson @param[out] op Address of the variable where the newly created composite `CeedOperator` will be stored 82752d6035fSJeremy L Thompson 82852d6035fSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 82952d6035fSJeremy L Thompson 8307a982d89SJeremy L. Thompson @ref User 83152d6035fSJeremy L Thompson */ 83252d6035fSJeremy L Thompson int CeedCompositeOperatorCreate(Ceed ceed, CeedOperator *op) { 83352d6035fSJeremy L Thompson if (!ceed->CompositeOperatorCreate) { 83452d6035fSJeremy L Thompson Ceed delegate; 83552d6035fSJeremy L Thompson 8361c66c397SJeremy L Thompson CeedCall(CeedGetObjectDelegate(ceed, &delegate, "Operator")); 837250756a7Sjeremylt if (delegate) { 8382b730f8bSJeremy L Thompson CeedCall(CeedCompositeOperatorCreate(delegate, op)); 8399bc66399SJeremy L Thompson CeedCall(CeedDestroy(&delegate)); 840e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 84152d6035fSJeremy L Thompson } 842250756a7Sjeremylt } 84352d6035fSJeremy L Thompson 8442b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, op)); 845db002c03SJeremy L Thompson CeedCall(CeedReferenceCopy(ceed, &(*op)->ceed)); 846996d9ab5SJed Brown (*op)->ref_count = 1; 847f04ea552SJeremy L Thompson (*op)->is_composite = true; 8482b730f8bSJeremy L Thompson CeedCall(CeedCalloc(CEED_COMPOSITE_MAX, &(*op)->sub_operators)); 8492b104005SJeremy L Thompson (*op)->input_size = -1; 8502b104005SJeremy L Thompson (*op)->output_size = -1; 851250756a7Sjeremylt 852db002c03SJeremy L Thompson if (ceed->CompositeOperatorCreate) CeedCall(ceed->CompositeOperatorCreate(*op)); 853e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 85452d6035fSJeremy L Thompson } 85552d6035fSJeremy L Thompson 85652d6035fSJeremy L Thompson /** 857ca94c3ddSJeremy L Thompson @brief Copy the pointer to a `CeedOperator`. 8584385fb7fSSebastian Grimberg 859ca94c3ddSJeremy L Thompson Both pointers should be destroyed with @ref CeedOperatorDestroy(). 860512bb800SJeremy L Thompson 861ca94c3ddSJeremy 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`. 862ca94c3ddSJeremy L Thompson This `CeedOperator` will be destroyed if `*op_copy` is the only reference to this `CeedOperator`. 8639560d06aSjeremylt 864ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to copy reference to 865ea61e9acSJeremy L Thompson @param[in,out] op_copy Variable to store copied reference 8669560d06aSjeremylt 8679560d06aSjeremylt @return An error code: 0 - success, otherwise - failure 8689560d06aSjeremylt 8699560d06aSjeremylt @ref User 8709560d06aSjeremylt **/ 8719560d06aSjeremylt int CeedOperatorReferenceCopy(CeedOperator op, CeedOperator *op_copy) { 8722b730f8bSJeremy L Thompson CeedCall(CeedOperatorReference(op)); 8732b730f8bSJeremy L Thompson CeedCall(CeedOperatorDestroy(op_copy)); 8749560d06aSjeremylt *op_copy = op; 8759560d06aSjeremylt return CEED_ERROR_SUCCESS; 8769560d06aSjeremylt } 8779560d06aSjeremylt 8789560d06aSjeremylt /** 879ca94c3ddSJeremy L Thompson @brief Provide a field to a `CeedOperator` for use by its `CeedQFunction`. 880d7b241e6Sjeremylt 881ca94c3ddSJeremy L Thompson This function is used to specify both active and passive fields to a `CeedOperator`. 882bafebce1SSebastian Grimberg For passive fields, a `CeedVector` `vec` must be provided. 883ea61e9acSJeremy L Thompson Passive fields can inputs or outputs (updated in-place when operator is applied). 884d7b241e6Sjeremylt 885ca94c3ddSJeremy L Thompson Active fields must be specified using this function, but their data (in a `CeedVector`) is passed in @ref CeedOperatorApply(). 886ca94c3ddSJeremy L Thompson There can be at most one active input `CeedVector` and at most one active output@ref CeedVector passed to @ref CeedOperatorApply(). 887d7b241e6Sjeremylt 888528a22edSJeremy L Thompson The number of quadrature points must agree across all points. 889bafebce1SSebastian Grimberg When using @ref CEED_BASIS_NONE, the number of quadrature points is determined by the element size of `rstr`. 890528a22edSJeremy L Thompson 891ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` on which to provide the field 892ca94c3ddSJeremy L Thompson @param[in] field_name Name of the field (to be matched with the name used by `CeedQFunction`) 893bafebce1SSebastian Grimberg @param[in] rstr `CeedElemRestriction` 894bafebce1SSebastian Grimberg @param[in] basis `CeedBasis` in which the field resides or @ref CEED_BASIS_NONE if collocated with quadrature points 895bafebce1SSebastian 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` 896b11c1e72Sjeremylt 897b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 898dfdf5a53Sjeremylt 8997a982d89SJeremy L. Thompson @ref User 900b11c1e72Sjeremylt **/ 901bafebce1SSebastian Grimberg int CeedOperatorSetField(CeedOperator op, const char *field_name, CeedElemRestriction rstr, CeedBasis basis, CeedVector vec) { 9021203703bSJeremy L Thompson bool is_input = true, is_at_points, is_composite, is_immutable; 9031203703bSJeremy L Thompson CeedInt num_elem = 0, num_qpts = 0, num_input_fields, num_output_fields; 9041203703bSJeremy L Thompson CeedQFunction qf; 9051203703bSJeremy L Thompson CeedQFunctionField qf_field, *qf_input_fields, *qf_output_fields; 9061c66c397SJeremy L Thompson CeedOperatorField *op_field; 9071c66c397SJeremy L Thompson 9081203703bSJeremy L Thompson CeedCall(CeedOperatorIsAtPoints(op, &is_at_points)); 9091203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 9101203703bSJeremy L Thompson CeedCall(CeedOperatorIsImmutable(op, &is_immutable)); 9119bc66399SJeremy L Thompson CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, "Cannot add field to composite operator."); 9129bc66399SJeremy L Thompson CeedCheck(!is_immutable, CeedOperatorReturnCeed(op), CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable"); 9139bc66399SJeremy L Thompson CeedCheck(rstr, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, "CeedElemRestriction rstr for field \"%s\" must be non-NULL.", field_name); 9149bc66399SJeremy L Thompson CeedCheck(basis, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, "CeedBasis basis for field \"%s\" must be non-NULL.", field_name); 9159bc66399SJeremy L Thompson CeedCheck(vec, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, "CeedVector vec for field \"%s\" must be non-NULL.", field_name); 91652d6035fSJeremy L Thompson 917bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionGetNumElements(rstr, &num_elem)); 9189bc66399SJeremy L Thompson CeedCheck(rstr == CEED_ELEMRESTRICTION_NONE || !op->has_restriction || num_elem == op->num_elem, CeedOperatorReturnCeed(op), CEED_ERROR_DIMENSION, 919ca94c3ddSJeremy L Thompson "CeedElemRestriction with %" CeedInt_FMT " elements incompatible with prior %" CeedInt_FMT " elements", num_elem, op->num_elem); 9202c7e7413SJeremy L Thompson { 9212c7e7413SJeremy L Thompson CeedRestrictionType rstr_type; 9222c7e7413SJeremy L Thompson 923bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionGetType(rstr, &rstr_type)); 92448acf710SJeremy L Thompson if (rstr_type == CEED_RESTRICTION_POINTS) { 9259bc66399SJeremy L Thompson CeedCheck(is_at_points, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, 9269bc66399SJeremy L Thompson "CeedElemRestriction AtPoints not supported for standard operator fields"); 9279bc66399SJeremy L Thompson CeedCheck(basis == CEED_BASIS_NONE, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, 9289bc66399SJeremy L Thompson "CeedElemRestriction AtPoints must be used with CEED_BASIS_NONE"); 92948acf710SJeremy L Thompson if (!op->first_points_rstr) { 930bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionReferenceCopy(rstr, &op->first_points_rstr)); 93148acf710SJeremy L Thompson } else { 93248acf710SJeremy L Thompson bool are_compatible; 93348acf710SJeremy L Thompson 934bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionAtPointsAreCompatible(op->first_points_rstr, rstr, &are_compatible)); 9359bc66399SJeremy L Thompson CeedCheck(are_compatible, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, 936ca94c3ddSJeremy L Thompson "CeedElemRestriction must have compatible offsets with previously set CeedElemRestriction"); 93748acf710SJeremy L Thompson } 93848acf710SJeremy L Thompson } 9392c7e7413SJeremy L Thompson } 940d7b241e6Sjeremylt 941bafebce1SSebastian Grimberg if (basis == CEED_BASIS_NONE) CeedCall(CeedElemRestrictionGetElementSize(rstr, &num_qpts)); 942bafebce1SSebastian Grimberg else CeedCall(CeedBasisGetNumQuadraturePoints(basis, &num_qpts)); 9439bc66399SJeremy L Thompson CeedCheck(op->num_qpts == 0 || num_qpts == op->num_qpts, CeedOperatorReturnCeed(op), CEED_ERROR_DIMENSION, 944ca94c3ddSJeremy L Thompson "%s must correspond to the same number of quadrature points as previously added CeedBases. Found %" CeedInt_FMT 945528a22edSJeremy L Thompson " quadrature points but expected %" CeedInt_FMT " quadrature points.", 946bafebce1SSebastian Grimberg basis == CEED_BASIS_NONE ? "CeedElemRestriction" : "CeedBasis", num_qpts, op->num_qpts); 9471203703bSJeremy L Thompson 9481203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 9491203703bSJeremy L Thompson CeedCall(CeedQFunctionGetFields(qf, &num_input_fields, &qf_input_fields, &num_output_fields, &qf_output_fields)); 950*c11e12f4SJeremy L Thompson CeedCall(CeedQFunctionDestroy(&qf)); 9511203703bSJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 9526f8994e9SJeremy L Thompson const char *qf_field_name; 9531203703bSJeremy L Thompson 9541203703bSJeremy L Thompson CeedCall(CeedQFunctionFieldGetName(qf_input_fields[i], &qf_field_name)); 9551203703bSJeremy L Thompson if (!strcmp(field_name, qf_field_name)) { 9561203703bSJeremy L Thompson qf_field = qf_input_fields[i]; 957d1d35e2fSjeremylt op_field = &op->input_fields[i]; 958d7b241e6Sjeremylt goto found; 959d7b241e6Sjeremylt } 960d7b241e6Sjeremylt } 9612b104005SJeremy L Thompson is_input = false; 9621203703bSJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 9636f8994e9SJeremy L Thompson const char *qf_field_name; 9641203703bSJeremy L Thompson 9651203703bSJeremy L Thompson CeedCall(CeedQFunctionFieldGetName(qf_output_fields[i], &qf_field_name)); 9661203703bSJeremy L Thompson if (!strcmp(field_name, qf_field_name)) { 9671203703bSJeremy L Thompson qf_field = qf_output_fields[i]; 968d1d35e2fSjeremylt op_field = &op->output_fields[i]; 969d7b241e6Sjeremylt goto found; 970d7b241e6Sjeremylt } 971d7b241e6Sjeremylt } 972c042f62fSJeremy L Thompson // LCOV_EXCL_START 9739bc66399SJeremy L Thompson return CeedError(CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPLETE, "CeedQFunction has no knowledge of field '%s'", field_name); 974c042f62fSJeremy L Thompson // LCOV_EXCL_STOP 975d7b241e6Sjeremylt found: 9769bc66399SJeremy L Thompson CeedCall(CeedOperatorCheckField(CeedOperatorReturnCeed(op), qf_field, rstr, basis)); 9772b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, op_field)); 978e15f9bd0SJeremy L Thompson 979bafebce1SSebastian Grimberg if (vec == CEED_VECTOR_ACTIVE) { 9802b104005SJeremy L Thompson CeedSize l_size; 9811c66c397SJeremy L Thompson 982bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionGetLVectorSize(rstr, &l_size)); 9832b104005SJeremy L Thompson if (is_input) { 9842b104005SJeremy L Thompson if (op->input_size == -1) op->input_size = l_size; 9859bc66399SJeremy L Thompson CeedCheck(l_size == op->input_size, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, 986249f8407SJeremy L Thompson "LVector size %" CeedSize_FMT " does not match previous size %" CeedSize_FMT "", l_size, op->input_size); 9872b104005SJeremy L Thompson } else { 9882b104005SJeremy L Thompson if (op->output_size == -1) op->output_size = l_size; 9899bc66399SJeremy L Thompson CeedCheck(l_size == op->output_size, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, 990249f8407SJeremy L Thompson "LVector size %" CeedSize_FMT " does not match previous size %" CeedSize_FMT "", l_size, op->output_size); 9912b104005SJeremy L Thompson } 9922b730f8bSJeremy L Thompson } 9932b104005SJeremy L Thompson 994bafebce1SSebastian Grimberg CeedCall(CeedVectorReferenceCopy(vec, &(*op_field)->vec)); 995bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionReferenceCopy(rstr, &(*op_field)->elem_rstr)); 996bafebce1SSebastian Grimberg if (rstr != CEED_ELEMRESTRICTION_NONE && !op->has_restriction) { 997d1d35e2fSjeremylt op->num_elem = num_elem; 998d1d35e2fSjeremylt op->has_restriction = true; // Restriction set, but num_elem may be 0 999e15f9bd0SJeremy L Thompson } 1000bafebce1SSebastian Grimberg CeedCall(CeedBasisReferenceCopy(basis, &(*op_field)->basis)); 10012a3ff1c9SZach Atkins if (op->num_qpts == 0 && !is_at_points) op->num_qpts = num_qpts; // no consistent number of qpts for OperatorAtPoints 1002d1d35e2fSjeremylt op->num_fields += 1; 10032b730f8bSJeremy L Thompson CeedCall(CeedStringAllocCopy(field_name, (char **)&(*op_field)->field_name)); 1004e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 1005d7b241e6Sjeremylt } 1006d7b241e6Sjeremylt 1007d7b241e6Sjeremylt /** 1008ca94c3ddSJeremy L Thompson @brief Get the `CeedOperator` Field of a `CeedOperator`. 100943bbe138SJeremy L Thompson 1010ca94c3ddSJeremy L Thompson Note: Calling this function asserts that setup is complete and sets the `CeedOperator` as immutable. 1011f04ea552SJeremy L Thompson 1012ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1013f74ec584SJeremy L Thompson @param[out] num_input_fields Variable to store number of input fields 1014ca94c3ddSJeremy L Thompson @param[out] input_fields Variable to store input fields 1015f74ec584SJeremy L Thompson @param[out] num_output_fields Variable to store number of output fields 1016ca94c3ddSJeremy L Thompson @param[out] output_fields Variable to store output fields 101743bbe138SJeremy L Thompson 101843bbe138SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 101943bbe138SJeremy L Thompson 1020e9b533fbSJeremy L Thompson @ref Advanced 102143bbe138SJeremy L Thompson **/ 10222b730f8bSJeremy L Thompson int CeedOperatorGetFields(CeedOperator op, CeedInt *num_input_fields, CeedOperatorField **input_fields, CeedInt *num_output_fields, 102343bbe138SJeremy L Thompson CeedOperatorField **output_fields) { 10241203703bSJeremy L Thompson bool is_composite; 10251203703bSJeremy L Thompson CeedQFunction qf; 10261203703bSJeremy L Thompson 10271203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 10286e536b99SJeremy L Thompson CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Not defined for composite operator"); 10292b730f8bSJeremy L Thompson CeedCall(CeedOperatorCheckReady(op)); 103043bbe138SJeremy L Thompson 10311203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 10321203703bSJeremy L Thompson CeedCall(CeedQFunctionGetFields(qf, num_input_fields, NULL, num_output_fields, NULL)); 1033*c11e12f4SJeremy L Thompson CeedCall(CeedQFunctionDestroy(&qf)); 103443bbe138SJeremy L Thompson if (input_fields) *input_fields = op->input_fields; 103543bbe138SJeremy L Thompson if (output_fields) *output_fields = op->output_fields; 103643bbe138SJeremy L Thompson return CEED_ERROR_SUCCESS; 103743bbe138SJeremy L Thompson } 103843bbe138SJeremy L Thompson 103943bbe138SJeremy L Thompson /** 1040ca94c3ddSJeremy L Thompson @brief Set the arbitrary points in each element for a `CeedOperator` at points. 104148acf710SJeremy L Thompson 1042ca94c3ddSJeremy L Thompson Note: Calling this function asserts that setup is complete and sets the `CeedOperator` as immutable. 104348acf710SJeremy L Thompson 1044ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` at points 1045ca94c3ddSJeremy L Thompson @param[in] rstr_points `CeedElemRestriction` for the coordinates of each point by element 1046ca94c3ddSJeremy L Thompson @param[in] point_coords `CeedVector` holding coordinates of each point 104748acf710SJeremy L Thompson 104848acf710SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 104948acf710SJeremy L Thompson 105048acf710SJeremy L Thompson @ref Advanced 105148acf710SJeremy L Thompson **/ 105248acf710SJeremy L Thompson int CeedOperatorAtPointsSetPoints(CeedOperator op, CeedElemRestriction rstr_points, CeedVector point_coords) { 10531203703bSJeremy L Thompson bool is_at_points, is_immutable; 10542a3ff1c9SZach Atkins 10552a3ff1c9SZach Atkins CeedCall(CeedOperatorIsAtPoints(op, &is_at_points)); 10561203703bSJeremy L Thompson CeedCall(CeedOperatorIsImmutable(op, &is_immutable)); 10579bc66399SJeremy L Thompson CeedCheck(is_at_points, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Only defined for operator at points"); 10589bc66399SJeremy L Thompson CeedCheck(!is_immutable, CeedOperatorReturnCeed(op), CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable"); 105948acf710SJeremy L Thompson 106048acf710SJeremy L Thompson if (!op->first_points_rstr) { 106148acf710SJeremy L Thompson CeedCall(CeedElemRestrictionReferenceCopy(rstr_points, &op->first_points_rstr)); 106248acf710SJeremy L Thompson } else { 106348acf710SJeremy L Thompson bool are_compatible; 106448acf710SJeremy L Thompson 106548acf710SJeremy L Thompson CeedCall(CeedElemRestrictionAtPointsAreCompatible(op->first_points_rstr, rstr_points, &are_compatible)); 10669bc66399SJeremy L Thompson CeedCheck(are_compatible, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, 1067ca94c3ddSJeremy L Thompson "CeedElemRestriction must have compatible offsets with previously set field CeedElemRestriction"); 106848acf710SJeremy L Thompson } 106948acf710SJeremy L Thompson 107048acf710SJeremy L Thompson CeedCall(CeedElemRestrictionReferenceCopy(rstr_points, &op->rstr_points)); 107148acf710SJeremy L Thompson CeedCall(CeedVectorReferenceCopy(point_coords, &op->point_coords)); 107248acf710SJeremy L Thompson return CEED_ERROR_SUCCESS; 107348acf710SJeremy L Thompson } 107448acf710SJeremy L Thompson 107548acf710SJeremy L Thompson /** 1076b594f9faSZach Atkins @brief Get a boolean value indicating if the `CeedOperator` was created with `CeedOperatorCreateAtPoints` 1077b594f9faSZach Atkins 1078b594f9faSZach Atkins @param[in] op `CeedOperator` 1079b594f9faSZach Atkins @param[out] is_at_points Variable to store at points status 1080b594f9faSZach Atkins 1081b594f9faSZach Atkins @return An error code: 0 - success, otherwise - failure 1082b594f9faSZach Atkins 1083b594f9faSZach Atkins @ref User 1084b594f9faSZach Atkins **/ 1085b594f9faSZach Atkins int CeedOperatorIsAtPoints(CeedOperator op, bool *is_at_points) { 1086b594f9faSZach Atkins *is_at_points = op->is_at_points; 1087b594f9faSZach Atkins return CEED_ERROR_SUCCESS; 1088b594f9faSZach Atkins } 1089b594f9faSZach Atkins 1090b594f9faSZach Atkins /** 1091ca94c3ddSJeremy L Thompson @brief Get the arbitrary points in each element for a `CeedOperator` at points. 109248acf710SJeremy L Thompson 1093ca94c3ddSJeremy L Thompson Note: Calling this function asserts that setup is complete and sets the `CeedOperator` as immutable. 109448acf710SJeremy L Thompson 1095ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` at points 1096ca94c3ddSJeremy L Thompson @param[out] rstr_points Variable to hold `CeedElemRestriction` for the coordinates of each point by element 1097ca94c3ddSJeremy L Thompson @param[out] point_coords Variable to hold `CeedVector` holding coordinates of each point 109848acf710SJeremy L Thompson 109948acf710SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 110048acf710SJeremy L Thompson 110148acf710SJeremy L Thompson @ref Advanced 110248acf710SJeremy L Thompson **/ 110348acf710SJeremy L Thompson int CeedOperatorAtPointsGetPoints(CeedOperator op, CeedElemRestriction *rstr_points, CeedVector *point_coords) { 11042a3ff1c9SZach Atkins bool is_at_points; 11052a3ff1c9SZach Atkins 11062a3ff1c9SZach Atkins CeedCall(CeedOperatorIsAtPoints(op, &is_at_points)); 11076e536b99SJeremy L Thompson CeedCheck(is_at_points, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Only defined for operator at points"); 110848acf710SJeremy L Thompson CeedCall(CeedOperatorCheckReady(op)); 110948acf710SJeremy L Thompson 111048acf710SJeremy L Thompson if (rstr_points) CeedCall(CeedElemRestrictionReferenceCopy(op->rstr_points, rstr_points)); 111148acf710SJeremy L Thompson if (point_coords) CeedCall(CeedVectorReferenceCopy(op->point_coords, point_coords)); 111248acf710SJeremy L Thompson return CEED_ERROR_SUCCESS; 111348acf710SJeremy L Thompson } 111448acf710SJeremy L Thompson 111548acf710SJeremy L Thompson /** 1116be9c6463SJeremy L Thompson @brief Get a `CeedOperator` Field of a `CeedOperator` from its name. 1117be9c6463SJeremy L Thompson 1118be9c6463SJeremy L Thompson `op_field` is set to `NULL` if the field is not found. 1119de5900adSJames Wright 1120ca94c3ddSJeremy L Thompson Note: Calling this function asserts that setup is complete and sets the `CeedOperator` as immutable. 1121de5900adSJames Wright 1122ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1123ca94c3ddSJeremy L Thompson @param[in] field_name Name of desired `CeedOperator` Field 1124ca94c3ddSJeremy L Thompson @param[out] op_field `CeedOperator` Field corresponding to the name 1125de5900adSJames Wright 1126de5900adSJames Wright @return An error code: 0 - success, otherwise - failure 1127de5900adSJames Wright 1128de5900adSJames Wright @ref Advanced 1129de5900adSJames Wright **/ 1130de5900adSJames Wright int CeedOperatorGetFieldByName(CeedOperator op, const char *field_name, CeedOperatorField *op_field) { 11316f8994e9SJeremy L Thompson const char *name; 1132de5900adSJames Wright CeedInt num_input_fields, num_output_fields; 1133de5900adSJames Wright CeedOperatorField *input_fields, *output_fields; 1134de5900adSJames Wright 1135be9c6463SJeremy L Thompson *op_field = NULL; 11361c66c397SJeremy L Thompson CeedCall(CeedOperatorGetFields(op, &num_input_fields, &input_fields, &num_output_fields, &output_fields)); 1137de5900adSJames Wright for (CeedInt i = 0; i < num_input_fields; i++) { 1138de5900adSJames Wright CeedCall(CeedOperatorFieldGetName(input_fields[i], &name)); 1139de5900adSJames Wright if (!strcmp(name, field_name)) { 1140de5900adSJames Wright *op_field = input_fields[i]; 1141de5900adSJames Wright return CEED_ERROR_SUCCESS; 1142de5900adSJames Wright } 1143de5900adSJames Wright } 1144de5900adSJames Wright for (CeedInt i = 0; i < num_output_fields; i++) { 1145de5900adSJames Wright CeedCall(CeedOperatorFieldGetName(output_fields[i], &name)); 1146de5900adSJames Wright if (!strcmp(name, field_name)) { 1147de5900adSJames Wright *op_field = output_fields[i]; 1148de5900adSJames Wright return CEED_ERROR_SUCCESS; 1149de5900adSJames Wright } 1150de5900adSJames Wright } 1151be9c6463SJeremy L Thompson return CEED_ERROR_SUCCESS; 1152de5900adSJames Wright } 1153de5900adSJames Wright 1154de5900adSJames Wright /** 1155ca94c3ddSJeremy L Thompson @brief Get the name of a `CeedOperator` Field 115628567f8fSJeremy L Thompson 1157ca94c3ddSJeremy L Thompson @param[in] op_field `CeedOperator` Field 115828567f8fSJeremy L Thompson @param[out] field_name Variable to store the field name 115928567f8fSJeremy L Thompson 116028567f8fSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 116128567f8fSJeremy L Thompson 1162e9b533fbSJeremy L Thompson @ref Advanced 116328567f8fSJeremy L Thompson **/ 11646f8994e9SJeremy L Thompson int CeedOperatorFieldGetName(CeedOperatorField op_field, const char **field_name) { 11656f8994e9SJeremy L Thompson *field_name = op_field->field_name; 116628567f8fSJeremy L Thompson return CEED_ERROR_SUCCESS; 116728567f8fSJeremy L Thompson } 116828567f8fSJeremy L Thompson 116928567f8fSJeremy L Thompson /** 1170681d0ea7SJeremy L Thompson @brief Get the `CeedElemRestriction` of a `CeedOperator` Field. 1171681d0ea7SJeremy L Thompson 1172681d0ea7SJeremy L Thompson Note: Caller is responsible for destroying the `rstr` with @ref CeedElemRestrictionDestroy(). 117343bbe138SJeremy L Thompson 1174ca94c3ddSJeremy L Thompson @param[in] op_field `CeedOperator` Field 1175ca94c3ddSJeremy L Thompson @param[out] rstr Variable to store `CeedElemRestriction` 117643bbe138SJeremy L Thompson 117743bbe138SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 117843bbe138SJeremy L Thompson 1179e9b533fbSJeremy L Thompson @ref Advanced 118043bbe138SJeremy L Thompson **/ 11812b730f8bSJeremy L Thompson int CeedOperatorFieldGetElemRestriction(CeedOperatorField op_field, CeedElemRestriction *rstr) { 1182681d0ea7SJeremy L Thompson *rstr = NULL; 1183681d0ea7SJeremy L Thompson CeedCall(CeedElemRestrictionReferenceCopy(op_field->elem_rstr, rstr)); 118443bbe138SJeremy L Thompson return CEED_ERROR_SUCCESS; 118543bbe138SJeremy L Thompson } 118643bbe138SJeremy L Thompson 118743bbe138SJeremy L Thompson /** 1188681d0ea7SJeremy L Thompson @brief Get the `CeedBasis` of a `CeedOperator` Field. 1189681d0ea7SJeremy L Thompson 1190681d0ea7SJeremy L Thompson Note: Caller is responsible for destroying the `basis` with @ref CeedBasisDestroy(). 119143bbe138SJeremy L Thompson 1192ca94c3ddSJeremy L Thompson @param[in] op_field `CeedOperator` Field 1193ca94c3ddSJeremy L Thompson @param[out] basis Variable to store `CeedBasis` 119443bbe138SJeremy L Thompson 119543bbe138SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 119643bbe138SJeremy L Thompson 1197e9b533fbSJeremy L Thompson @ref Advanced 119843bbe138SJeremy L Thompson **/ 119943bbe138SJeremy L Thompson int CeedOperatorFieldGetBasis(CeedOperatorField op_field, CeedBasis *basis) { 1200681d0ea7SJeremy L Thompson *basis = NULL; 1201681d0ea7SJeremy L Thompson CeedCall(CeedBasisReferenceCopy(op_field->basis, basis)); 120243bbe138SJeremy L Thompson return CEED_ERROR_SUCCESS; 120343bbe138SJeremy L Thompson } 120443bbe138SJeremy L Thompson 120543bbe138SJeremy L Thompson /** 1206681d0ea7SJeremy L Thompson @brief Get the `CeedVector` of a `CeedOperator` Field. 1207681d0ea7SJeremy L Thompson 1208681d0ea7SJeremy L Thompson Note: Caller is responsible for destroying the `vec` with @ref CeedVectorDestroy(). 120943bbe138SJeremy L Thompson 1210ca94c3ddSJeremy L Thompson @param[in] op_field `CeedOperator` Field 1211ca94c3ddSJeremy L Thompson @param[out] vec Variable to store `CeedVector` 121243bbe138SJeremy L Thompson 121343bbe138SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 121443bbe138SJeremy L Thompson 1215e9b533fbSJeremy L Thompson @ref Advanced 121643bbe138SJeremy L Thompson **/ 121743bbe138SJeremy L Thompson int CeedOperatorFieldGetVector(CeedOperatorField op_field, CeedVector *vec) { 1218681d0ea7SJeremy L Thompson *vec = NULL; 1219681d0ea7SJeremy L Thompson CeedCall(CeedVectorReferenceCopy(op_field->vec, vec)); 122043bbe138SJeremy L Thompson return CEED_ERROR_SUCCESS; 122143bbe138SJeremy L Thompson } 122243bbe138SJeremy L Thompson 122343bbe138SJeremy L Thompson /** 1224ab747706SJeremy L Thompson @brief Get the data of a `CeedOperator` Field. 1225ab747706SJeremy L Thompson 1226681d0ea7SJeremy L Thompson Any arguments set as `NULL` are ignored.. 1227681d0ea7SJeremy L Thompson 1228681d0ea7SJeremy L Thompson Note: Caller is responsible for destroying the `rstr`, `basis`, and `vec`. 1229ab747706SJeremy L Thompson 1230ab747706SJeremy L Thompson @param[in] op_field `CeedOperator` Field 1231ab747706SJeremy L Thompson @param[out] field_name Variable to store the field name 1232ab747706SJeremy L Thompson @param[out] rstr Variable to store `CeedElemRestriction` 1233ab747706SJeremy L Thompson @param[out] basis Variable to store `CeedBasis` 1234ab747706SJeremy L Thompson @param[out] vec Variable to store `CeedVector` 1235ab747706SJeremy L Thompson 1236ab747706SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1237ab747706SJeremy L Thompson 1238ab747706SJeremy L Thompson @ref Advanced 1239ab747706SJeremy L Thompson **/ 12406f8994e9SJeremy L Thompson int CeedOperatorFieldGetData(CeedOperatorField op_field, const char **field_name, CeedElemRestriction *rstr, CeedBasis *basis, CeedVector *vec) { 1241ab747706SJeremy L Thompson if (field_name) CeedCall(CeedOperatorFieldGetName(op_field, field_name)); 1242ab747706SJeremy L Thompson if (rstr) CeedCall(CeedOperatorFieldGetElemRestriction(op_field, rstr)); 1243ab747706SJeremy L Thompson if (basis) CeedCall(CeedOperatorFieldGetBasis(op_field, basis)); 1244ab747706SJeremy L Thompson if (vec) CeedCall(CeedOperatorFieldGetVector(op_field, vec)); 1245ab747706SJeremy L Thompson return CEED_ERROR_SUCCESS; 1246ab747706SJeremy L Thompson } 1247ab747706SJeremy L Thompson 1248ab747706SJeremy L Thompson /** 1249ca94c3ddSJeremy L Thompson @brief Add a sub-operator to a composite `CeedOperator` 1250288c0443SJeremy L Thompson 1251ca94c3ddSJeremy L Thompson @param[in,out] composite_op Composite `CeedOperator` 1252ca94c3ddSJeremy L Thompson @param[in] sub_op Sub-operator `CeedOperator` 125352d6035fSJeremy L Thompson 125452d6035fSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 125552d6035fSJeremy L Thompson 12567a982d89SJeremy L. Thompson @ref User 125752d6035fSJeremy L Thompson */ 12582b730f8bSJeremy L Thompson int CeedCompositeOperatorAddSub(CeedOperator composite_op, CeedOperator sub_op) { 12591203703bSJeremy L Thompson bool is_immutable; 12601203703bSJeremy L Thompson 12619bc66399SJeremy L Thompson CeedCheck(composite_op->is_composite, CeedOperatorReturnCeed(composite_op), CEED_ERROR_MINOR, "CeedOperator is not a composite operator"); 12629bc66399SJeremy L Thompson CeedCheck(composite_op->num_suboperators < CEED_COMPOSITE_MAX, CeedOperatorReturnCeed(composite_op), CEED_ERROR_UNSUPPORTED, 12639bc66399SJeremy L Thompson "Cannot add additional sub-operators"); 12641203703bSJeremy L Thompson CeedCall(CeedOperatorIsImmutable(composite_op, &is_immutable)); 12659bc66399SJeremy L Thompson CeedCheck(!is_immutable, CeedOperatorReturnCeed(composite_op), CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable"); 12662b730f8bSJeremy L Thompson 12672b730f8bSJeremy L Thompson { 12682b730f8bSJeremy L Thompson CeedSize input_size, output_size; 12691c66c397SJeremy L Thompson 12702b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetActiveVectorLengths(sub_op, &input_size, &output_size)); 12712b730f8bSJeremy L Thompson if (composite_op->input_size == -1) composite_op->input_size = input_size; 12722b730f8bSJeremy L Thompson if (composite_op->output_size == -1) composite_op->output_size = output_size; 12732b730f8bSJeremy L Thompson // Note, a size of -1 means no active vector restriction set, so no incompatibility 12749bc66399SJeremy L Thompson CeedCheck((input_size == -1 || input_size == composite_op->input_size) && (output_size == -1 || output_size == composite_op->output_size), 12759bc66399SJeremy L Thompson CeedOperatorReturnCeed(composite_op), CEED_ERROR_MAJOR, 1276249f8407SJeremy L Thompson "Sub-operators must have compatible dimensions; composite operator of shape (%" CeedSize_FMT ", %" CeedSize_FMT 1277249f8407SJeremy L Thompson ") not compatible with sub-operator of " 1278249f8407SJeremy L Thompson "shape (%" CeedSize_FMT ", %" CeedSize_FMT ")", 12792b730f8bSJeremy L Thompson composite_op->input_size, composite_op->output_size, input_size, output_size); 12802b730f8bSJeremy L Thompson } 12812b730f8bSJeremy L Thompson 1282d1d35e2fSjeremylt composite_op->sub_operators[composite_op->num_suboperators] = sub_op; 12832b730f8bSJeremy L Thompson CeedCall(CeedOperatorReference(sub_op)); 1284d1d35e2fSjeremylt composite_op->num_suboperators++; 1285e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 128652d6035fSJeremy L Thompson } 128752d6035fSJeremy L Thompson 128852d6035fSJeremy L Thompson /** 1289ca94c3ddSJeremy L Thompson @brief Get the number of sub-operators associated with a `CeedOperator` 129075f0d5a4SJeremy L Thompson 1291ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1292ca94c3ddSJeremy L Thompson @param[out] num_suboperators Variable to store number of sub-operators 129375f0d5a4SJeremy L Thompson 129475f0d5a4SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 129575f0d5a4SJeremy L Thompson 129675f0d5a4SJeremy L Thompson @ref Backend 129775f0d5a4SJeremy L Thompson **/ 1298c6ebc35dSJeremy L Thompson int CeedCompositeOperatorGetNumSub(CeedOperator op, CeedInt *num_suboperators) { 12991203703bSJeremy L Thompson bool is_composite; 13001203703bSJeremy L Thompson 13011203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 13026e536b99SJeremy L Thompson CeedCheck(is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Only defined for a composite operator"); 130375f0d5a4SJeremy L Thompson *num_suboperators = op->num_suboperators; 130475f0d5a4SJeremy L Thompson return CEED_ERROR_SUCCESS; 130575f0d5a4SJeremy L Thompson } 130675f0d5a4SJeremy L Thompson 130775f0d5a4SJeremy L Thompson /** 1308ca94c3ddSJeremy L Thompson @brief Get the list of sub-operators associated with a `CeedOperator` 130975f0d5a4SJeremy L Thompson 1310ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1311ca94c3ddSJeremy L Thompson @param[out] sub_operators Variable to store list of sub-operators 131275f0d5a4SJeremy L Thompson 131375f0d5a4SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 131475f0d5a4SJeremy L Thompson 131575f0d5a4SJeremy L Thompson @ref Backend 131675f0d5a4SJeremy L Thompson **/ 1317c6ebc35dSJeremy L Thompson int CeedCompositeOperatorGetSubList(CeedOperator op, CeedOperator **sub_operators) { 13181203703bSJeremy L Thompson bool is_composite; 13191203703bSJeremy L Thompson 13201203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 13216e536b99SJeremy L Thompson CeedCheck(is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Only defined for a composite operator"); 132275f0d5a4SJeremy L Thompson *sub_operators = op->sub_operators; 132375f0d5a4SJeremy L Thompson return CEED_ERROR_SUCCESS; 132475f0d5a4SJeremy L Thompson } 132575f0d5a4SJeremy L Thompson 132675f0d5a4SJeremy L Thompson /** 13278a297abdSJames Wright @brief Get a sub `CeedOperator` of a composite `CeedOperator` from its name. 13288a297abdSJames Wright 13298a297abdSJames Wright `sub_op` is set to `NULL` if the sub operator is not found. 13308a297abdSJames Wright 13318a297abdSJames Wright Note: Calling this function asserts that setup is complete and sets the `CeedOperator` as immutable. 13328a297abdSJames Wright 13338a297abdSJames Wright @param[in] op Composite `CeedOperator` 13348a297abdSJames Wright @param[in] op_name Name of desired sub `CeedOperator` 13358a297abdSJames Wright @param[out] sub_op Sub `CeedOperator` corresponding to the name 13368a297abdSJames Wright 13378a297abdSJames Wright @return An error code: 0 - success, otherwise - failure 13388a297abdSJames Wright 13398a297abdSJames Wright @ref Advanced 13408a297abdSJames Wright **/ 13418a297abdSJames Wright int CeedCompositeOperatorGetSubByName(CeedOperator op, const char *op_name, CeedOperator *sub_op) { 13428a297abdSJames Wright bool is_composite; 13438a297abdSJames Wright CeedInt num_sub_ops; 13448a297abdSJames Wright CeedOperator *sub_ops; 13458a297abdSJames Wright 13468a297abdSJames Wright CeedCall(CeedOperatorIsComposite(op, &is_composite)); 13478a297abdSJames Wright CeedCheck(is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Only defined for a composite operator"); 13488a297abdSJames Wright *sub_op = NULL; 13498a297abdSJames Wright CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub_ops)); 13508a297abdSJames Wright CeedCall(CeedCompositeOperatorGetSubList(op, &sub_ops)); 13518a297abdSJames Wright for (CeedInt i = 0; i < num_sub_ops; i++) { 13528a297abdSJames Wright if (sub_ops[i]->name && !strcmp(op_name, sub_ops[i]->name)) { 13538a297abdSJames Wright *sub_op = sub_ops[i]; 13548a297abdSJames Wright return CEED_ERROR_SUCCESS; 13558a297abdSJames Wright } 13568a297abdSJames Wright } 13578a297abdSJames Wright return CEED_ERROR_SUCCESS; 13588a297abdSJames Wright } 13598a297abdSJames Wright 13608a297abdSJames Wright /** 1361ca94c3ddSJeremy L Thompson @brief Check if a `CeedOperator` is ready to be used. 13624db537f9SJeremy L Thompson 1363ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to check 13644db537f9SJeremy L Thompson 13654db537f9SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 13664db537f9SJeremy L Thompson 13674db537f9SJeremy L Thompson @ref User 13684db537f9SJeremy L Thompson **/ 13694db537f9SJeremy L Thompson int CeedOperatorCheckReady(CeedOperator op) { 13701203703bSJeremy L Thompson bool is_at_points, is_composite; 13711203703bSJeremy L Thompson CeedQFunction qf = NULL; 13724db537f9SJeremy L Thompson 13732b730f8bSJeremy L Thompson if (op->is_interface_setup) return CEED_ERROR_SUCCESS; 13744db537f9SJeremy L Thompson 13751203703bSJeremy L Thompson CeedCall(CeedOperatorIsAtPoints(op, &is_at_points)); 13761203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 13771203703bSJeremy L Thompson if (!is_composite) CeedCall(CeedOperatorGetQFunction(op, &qf)); 13781203703bSJeremy L Thompson if (is_composite) { 13791203703bSJeremy L Thompson CeedInt num_suboperators; 13801203703bSJeremy L Thompson 13811203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 13821203703bSJeremy L Thompson if (!num_suboperators) { 138343622462SJeremy L Thompson // Empty operator setup 138443622462SJeremy L Thompson op->input_size = 0; 138543622462SJeremy L Thompson op->output_size = 0; 138643622462SJeremy L Thompson } else { 13871203703bSJeremy L Thompson CeedOperator *sub_operators; 13881203703bSJeremy L Thompson 13891203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 13901203703bSJeremy L Thompson for (CeedInt i = 0; i < num_suboperators; i++) { 13911203703bSJeremy L Thompson CeedCall(CeedOperatorCheckReady(sub_operators[i])); 13924db537f9SJeremy L Thompson } 13932b104005SJeremy L Thompson // Sub-operators could be modified after adding to composite operator 13942b104005SJeremy L Thompson // Need to verify no lvec incompatibility from any changes 13952b104005SJeremy L Thompson CeedSize input_size, output_size; 13962b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetActiveVectorLengths(op, &input_size, &output_size)); 139743622462SJeremy L Thompson } 13984db537f9SJeremy L Thompson } else { 13991203703bSJeremy L Thompson CeedInt num_input_fields, num_output_fields; 14001203703bSJeremy L Thompson 14019bc66399SJeremy L Thompson CeedCheck(op->num_fields > 0, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPLETE, "No operator fields set"); 14021203703bSJeremy L Thompson CeedCall(CeedQFunctionGetFields(qf, &num_input_fields, NULL, &num_output_fields, NULL)); 14039bc66399SJeremy L Thompson CeedCheck(op->num_fields == num_input_fields + num_output_fields, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPLETE, 14049bc66399SJeremy L Thompson "Not all operator fields set"); 14059bc66399SJeremy L Thompson CeedCheck(op->has_restriction, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPLETE, "At least one restriction required"); 14069bc66399SJeremy L Thompson CeedCheck(op->num_qpts > 0 || is_at_points, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPLETE, 1407ca94c3ddSJeremy L Thompson "At least one non-collocated CeedBasis is required or the number of quadrature points must be set"); 14082b730f8bSJeremy L Thompson } 14094db537f9SJeremy L Thompson 14104db537f9SJeremy L Thompson // Flag as immutable and ready 14114db537f9SJeremy L Thompson op->is_interface_setup = true; 14121203703bSJeremy L Thompson if (qf && qf != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionSetImmutable(qf)); 1413*c11e12f4SJeremy L Thompson CeedCall(CeedQFunctionDestroy(&qf)); 14141203703bSJeremy L Thompson if (op->dqf && op->dqf != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionSetImmutable(op->dqf)); 14151203703bSJeremy L Thompson if (op->dqfT && op->dqfT != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionSetImmutable(op->dqfT)); 14164db537f9SJeremy L Thompson return CEED_ERROR_SUCCESS; 14174db537f9SJeremy L Thompson } 14184db537f9SJeremy L Thompson 14194db537f9SJeremy L Thompson /** 1420ca94c3ddSJeremy L Thompson @brief Get vector lengths for the active input and/or output `CeedVector` of a `CeedOperator`. 14214385fb7fSSebastian Grimberg 1422ca94c3ddSJeremy L Thompson Note: Lengths of `-1` indicate that the CeedOperator does not have an active input and/or output. 1423c9366a6bSJeremy L Thompson 1424ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1425ca94c3ddSJeremy L Thompson @param[out] input_size Variable to store active input vector length, or `NULL` 1426ca94c3ddSJeremy L Thompson @param[out] output_size Variable to store active output vector length, or `NULL` 1427c9366a6bSJeremy L Thompson 1428c9366a6bSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1429c9366a6bSJeremy L Thompson 1430c9366a6bSJeremy L Thompson @ref User 1431c9366a6bSJeremy L Thompson **/ 14322b730f8bSJeremy L Thompson int CeedOperatorGetActiveVectorLengths(CeedOperator op, CeedSize *input_size, CeedSize *output_size) { 1433c9366a6bSJeremy L Thompson bool is_composite; 1434c9366a6bSJeremy L Thompson 14352b104005SJeremy L Thompson if (input_size) *input_size = op->input_size; 14362b104005SJeremy L Thompson if (output_size) *output_size = op->output_size; 1437c9366a6bSJeremy L Thompson 14382b730f8bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 14392b104005SJeremy L Thompson if (is_composite && (op->input_size == -1 || op->output_size == -1)) { 14401203703bSJeremy L Thompson CeedInt num_suboperators; 14411203703bSJeremy L Thompson CeedOperator *sub_operators; 14421203703bSJeremy L Thompson 14431203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 14441203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 14451203703bSJeremy L Thompson for (CeedInt i = 0; i < num_suboperators; i++) { 1446c9366a6bSJeremy L Thompson CeedSize sub_input_size, sub_output_size; 14471c66c397SJeremy L Thompson 14481203703bSJeremy L Thompson CeedCall(CeedOperatorGetActiveVectorLengths(sub_operators[i], &sub_input_size, &sub_output_size)); 14492b104005SJeremy L Thompson if (op->input_size == -1) op->input_size = sub_input_size; 14502b104005SJeremy L Thompson if (op->output_size == -1) op->output_size = sub_output_size; 14512b104005SJeremy L Thompson // Note, a size of -1 means no active vector restriction set, so no incompatibility 14526e536b99SJeremy L Thompson CeedCheck((sub_input_size == -1 || sub_input_size == op->input_size) && (sub_output_size == -1 || sub_output_size == op->output_size), 14536e536b99SJeremy L Thompson CeedOperatorReturnCeed(op), CEED_ERROR_MAJOR, 1454249f8407SJeremy L Thompson "Sub-operators must have compatible dimensions; composite operator of shape (%" CeedSize_FMT ", %" CeedSize_FMT 1455249f8407SJeremy L Thompson ") not compatible with sub-operator of " 1456249f8407SJeremy L Thompson "shape (%" CeedSize_FMT ", %" CeedSize_FMT ")", 14572b104005SJeremy L Thompson op->input_size, op->output_size, input_size, output_size); 1458c9366a6bSJeremy L Thompson } 14592b730f8bSJeremy L Thompson } 1460c9366a6bSJeremy L Thompson return CEED_ERROR_SUCCESS; 1461c9366a6bSJeremy L Thompson } 1462c9366a6bSJeremy L Thompson 1463c9366a6bSJeremy L Thompson /** 1464ca94c3ddSJeremy L Thompson @brief Set reuse of `CeedQFunction` data in `CeedOperatorLinearAssemble*()` functions. 14654385fb7fSSebastian Grimberg 1466ca94c3ddSJeremy L Thompson When `reuse_assembly_data = false` (default), the `CeedQFunction` associated with this `CeedOperator` is re-assembled every time a `CeedOperatorLinearAssemble*()` function is called. 1467ca94c3ddSJeremy L Thompson When `reuse_assembly_data = true`, the `CeedQFunction` associated with this `CeedOperator` is reused between calls to @ref CeedOperatorSetQFunctionAssemblyDataUpdateNeeded(). 14688b919e6bSJeremy L Thompson 1469ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1470beecbf24SJeremy L Thompson @param[in] reuse_assembly_data Boolean flag setting assembly data reuse 14718b919e6bSJeremy L Thompson 14728b919e6bSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 14738b919e6bSJeremy L Thompson 14748b919e6bSJeremy L Thompson @ref Advanced 14758b919e6bSJeremy L Thompson **/ 14762b730f8bSJeremy L Thompson int CeedOperatorSetQFunctionAssemblyReuse(CeedOperator op, bool reuse_assembly_data) { 14778b919e6bSJeremy L Thompson bool is_composite; 14788b919e6bSJeremy L Thompson 14792b730f8bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 14808b919e6bSJeremy L Thompson if (is_composite) { 14818b919e6bSJeremy L Thompson for (CeedInt i = 0; i < op->num_suboperators; i++) { 14822b730f8bSJeremy L Thompson CeedCall(CeedOperatorSetQFunctionAssemblyReuse(op->sub_operators[i], reuse_assembly_data)); 14838b919e6bSJeremy L Thompson } 14848b919e6bSJeremy L Thompson } else { 14857d5185d7SSebastian Grimberg CeedQFunctionAssemblyData data; 14867d5185d7SSebastian Grimberg 14877d5185d7SSebastian Grimberg CeedCall(CeedOperatorGetQFunctionAssemblyData(op, &data)); 14887d5185d7SSebastian Grimberg CeedCall(CeedQFunctionAssemblyDataSetReuse(data, reuse_assembly_data)); 1489beecbf24SJeremy L Thompson } 1490beecbf24SJeremy L Thompson return CEED_ERROR_SUCCESS; 1491beecbf24SJeremy L Thompson } 1492beecbf24SJeremy L Thompson 1493beecbf24SJeremy L Thompson /** 1494ca94c3ddSJeremy L Thompson @brief Mark `CeedQFunction` data as updated and the `CeedQFunction` as requiring re-assembly. 1495beecbf24SJeremy L Thompson 1496ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 14976e15d496SJeremy L Thompson @param[in] needs_data_update Boolean flag setting assembly data reuse 1498beecbf24SJeremy L Thompson 1499beecbf24SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1500beecbf24SJeremy L Thompson 1501beecbf24SJeremy L Thompson @ref Advanced 1502beecbf24SJeremy L Thompson **/ 15032b730f8bSJeremy L Thompson int CeedOperatorSetQFunctionAssemblyDataUpdateNeeded(CeedOperator op, bool needs_data_update) { 1504beecbf24SJeremy L Thompson bool is_composite; 1505beecbf24SJeremy L Thompson 15062b730f8bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 1507beecbf24SJeremy L Thompson if (is_composite) { 15081203703bSJeremy L Thompson CeedInt num_suboperators; 15091203703bSJeremy L Thompson CeedOperator *sub_operators; 15101203703bSJeremy L Thompson 15111203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 15121203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 15131203703bSJeremy L Thompson for (CeedInt i = 0; i < num_suboperators; i++) { 15141203703bSJeremy L Thompson CeedCall(CeedOperatorSetQFunctionAssemblyDataUpdateNeeded(sub_operators[i], needs_data_update)); 1515beecbf24SJeremy L Thompson } 1516beecbf24SJeremy L Thompson } else { 15177d5185d7SSebastian Grimberg CeedQFunctionAssemblyData data; 15187d5185d7SSebastian Grimberg 15197d5185d7SSebastian Grimberg CeedCall(CeedOperatorGetQFunctionAssemblyData(op, &data)); 15207d5185d7SSebastian Grimberg CeedCall(CeedQFunctionAssemblyDataSetUpdateNeeded(data, needs_data_update)); 15218b919e6bSJeremy L Thompson } 15228b919e6bSJeremy L Thompson return CEED_ERROR_SUCCESS; 15238b919e6bSJeremy L Thompson } 15248b919e6bSJeremy L Thompson 15258b919e6bSJeremy L Thompson /** 1526ca94c3ddSJeremy L Thompson @brief Set name of `CeedOperator` for @ref CeedOperatorView() output 1527ea6b5821SJeremy L Thompson 1528ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 1529ea61e9acSJeremy L Thompson @param[in] name Name to set, or NULL to remove previously set name 1530ea6b5821SJeremy L Thompson 1531ea6b5821SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1532ea6b5821SJeremy L Thompson 1533ea6b5821SJeremy L Thompson @ref User 1534ea6b5821SJeremy L Thompson **/ 1535ea6b5821SJeremy L Thompson int CeedOperatorSetName(CeedOperator op, const char *name) { 1536ea6b5821SJeremy L Thompson char *name_copy; 1537ea6b5821SJeremy L Thompson size_t name_len = name ? strlen(name) : 0; 1538ea6b5821SJeremy L Thompson 15392b730f8bSJeremy L Thompson CeedCall(CeedFree(&op->name)); 1540ea6b5821SJeremy L Thompson if (name_len > 0) { 15412b730f8bSJeremy L Thompson CeedCall(CeedCalloc(name_len + 1, &name_copy)); 1542ea6b5821SJeremy L Thompson memcpy(name_copy, name, name_len); 1543ea6b5821SJeremy L Thompson op->name = name_copy; 1544ea6b5821SJeremy L Thompson } 1545ea6b5821SJeremy L Thompson return CEED_ERROR_SUCCESS; 1546ea6b5821SJeremy L Thompson } 1547ea6b5821SJeremy L Thompson 1548ea6b5821SJeremy L Thompson /** 1549935f026aSJeremy L Thompson @brief Core logic for viewing a `CeedOperator` 15507a982d89SJeremy L. Thompson 1551935f026aSJeremy L Thompson @param[in] op `CeedOperator` to view brief summary 1552ca94c3ddSJeremy L Thompson @param[in] stream Stream to write; typically `stdout` or a file 15538bf1b130SJames Wright @param[in] is_full Whether to write full operator view or terse 15547a982d89SJeremy L. Thompson 15557a982d89SJeremy L. Thompson @return Error code: 0 - success, otherwise - failure 15567a982d89SJeremy L. Thompson **/ 15578bf1b130SJames Wright static int CeedOperatorView_Core(CeedOperator op, FILE *stream, bool is_full) { 15581203703bSJeremy L Thompson bool has_name = op->name, is_composite; 15597a982d89SJeremy L. Thompson 15601203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 15611203703bSJeremy L Thompson if (is_composite) { 15621203703bSJeremy L Thompson CeedInt num_suboperators; 15631203703bSJeremy L Thompson CeedOperator *sub_operators; 15641203703bSJeremy L Thompson 15651203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 15661203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 15672b730f8bSJeremy L Thompson fprintf(stream, "Composite CeedOperator%s%s\n", has_name ? " - " : "", has_name ? op->name : ""); 15687a982d89SJeremy L. Thompson 15691203703bSJeremy L Thompson for (CeedInt i = 0; i < num_suboperators; i++) { 15701203703bSJeremy L Thompson has_name = sub_operators[i]->name; 1571935f026aSJeremy L Thompson fprintf(stream, " SubOperator %" CeedInt_FMT "%s%s%s\n", i, has_name ? " - " : "", has_name ? sub_operators[i]->name : "", is_full ? ":" : ""); 1572935f026aSJeremy L Thompson if (is_full) CeedCall(CeedOperatorSingleView(sub_operators[i], 1, stream)); 15737a982d89SJeremy L. Thompson } 15747a982d89SJeremy L. Thompson } else { 15752b730f8bSJeremy L Thompson fprintf(stream, "CeedOperator%s%s\n", has_name ? " - " : "", has_name ? op->name : ""); 1576935f026aSJeremy L Thompson if (is_full) CeedCall(CeedOperatorSingleView(op, 0, stream)); 15777a982d89SJeremy L. Thompson } 1578e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 15797a982d89SJeremy L. Thompson } 15803bd813ffSjeremylt 15813bd813ffSjeremylt /** 1582935f026aSJeremy L Thompson @brief View a `CeedOperator` 1583935f026aSJeremy L Thompson 1584935f026aSJeremy L Thompson @param[in] op `CeedOperator` to view 1585935f026aSJeremy L Thompson @param[in] stream Stream to write; typically `stdout` or a file 1586935f026aSJeremy L Thompson 1587935f026aSJeremy L Thompson @return Error code: 0 - success, otherwise - failure 1588935f026aSJeremy L Thompson 1589935f026aSJeremy L Thompson @ref User 1590935f026aSJeremy L Thompson **/ 1591935f026aSJeremy L Thompson int CeedOperatorView(CeedOperator op, FILE *stream) { 1592935f026aSJeremy L Thompson CeedCall(CeedOperatorView_Core(op, stream, true)); 1593935f026aSJeremy L Thompson return CEED_ERROR_SUCCESS; 1594935f026aSJeremy L Thompson } 1595935f026aSJeremy L Thompson 1596935f026aSJeremy L Thompson /** 1597935f026aSJeremy L Thompson @brief View a brief summary `CeedOperator` 1598935f026aSJeremy L Thompson 1599935f026aSJeremy L Thompson @param[in] op `CeedOperator` to view brief summary 1600935f026aSJeremy L Thompson @param[in] stream Stream to write; typically `stdout` or a file 1601935f026aSJeremy L Thompson 1602935f026aSJeremy L Thompson @return Error code: 0 - success, otherwise - failure 1603935f026aSJeremy L Thompson 1604935f026aSJeremy L Thompson @ref User 1605935f026aSJeremy L Thompson **/ 1606935f026aSJeremy L Thompson int CeedOperatorViewTerse(CeedOperator op, FILE *stream) { 1607935f026aSJeremy L Thompson CeedCall(CeedOperatorView_Core(op, stream, false)); 1608935f026aSJeremy L Thompson return CEED_ERROR_SUCCESS; 1609935f026aSJeremy L Thompson } 1610935f026aSJeremy L Thompson 1611935f026aSJeremy L Thompson /** 1612ca94c3ddSJeremy L Thompson @brief Get the `Ceed` associated with a `CeedOperator` 1613b7c9bbdaSJeremy L Thompson 1614ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1615ca94c3ddSJeremy L Thompson @param[out] ceed Variable to store `Ceed` 1616b7c9bbdaSJeremy L Thompson 1617b7c9bbdaSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1618b7c9bbdaSJeremy L Thompson 1619b7c9bbdaSJeremy L Thompson @ref Advanced 1620b7c9bbdaSJeremy L Thompson **/ 1621b7c9bbdaSJeremy L Thompson int CeedOperatorGetCeed(CeedOperator op, Ceed *ceed) { 16229bc66399SJeremy L Thompson *ceed = NULL; 16239bc66399SJeremy L Thompson CeedCall(CeedReferenceCopy(CeedOperatorReturnCeed(op), ceed)); 1624b7c9bbdaSJeremy L Thompson return CEED_ERROR_SUCCESS; 1625b7c9bbdaSJeremy L Thompson } 1626b7c9bbdaSJeremy L Thompson 1627b7c9bbdaSJeremy L Thompson /** 16286e536b99SJeremy L Thompson @brief Return the `Ceed` associated with a `CeedOperator` 16296e536b99SJeremy L Thompson 16306e536b99SJeremy L Thompson @param[in] op `CeedOperator` 16316e536b99SJeremy L Thompson 16326e536b99SJeremy L Thompson @return `Ceed` associated with the `op` 16336e536b99SJeremy L Thompson 16346e536b99SJeremy L Thompson @ref Advanced 16356e536b99SJeremy L Thompson **/ 16366e536b99SJeremy L Thompson Ceed CeedOperatorReturnCeed(CeedOperator op) { return op->ceed; } 16376e536b99SJeremy L Thompson 16386e536b99SJeremy L Thompson /** 1639ca94c3ddSJeremy L Thompson @brief Get the number of elements associated with a `CeedOperator` 1640b7c9bbdaSJeremy L Thompson 1641ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1642b7c9bbdaSJeremy L Thompson @param[out] num_elem Variable to store number of elements 1643b7c9bbdaSJeremy L Thompson 1644b7c9bbdaSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1645b7c9bbdaSJeremy L Thompson 1646b7c9bbdaSJeremy L Thompson @ref Advanced 1647b7c9bbdaSJeremy L Thompson **/ 1648b7c9bbdaSJeremy L Thompson int CeedOperatorGetNumElements(CeedOperator op, CeedInt *num_elem) { 16491203703bSJeremy L Thompson bool is_composite; 16501203703bSJeremy L Thompson 16511203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 16526e536b99SJeremy L Thompson CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Not defined for composite operator"); 1653b7c9bbdaSJeremy L Thompson *num_elem = op->num_elem; 1654b7c9bbdaSJeremy L Thompson return CEED_ERROR_SUCCESS; 1655b7c9bbdaSJeremy L Thompson } 1656b7c9bbdaSJeremy L Thompson 1657b7c9bbdaSJeremy L Thompson /** 1658ca94c3ddSJeremy L Thompson @brief Get the number of quadrature points associated with a `CeedOperator` 1659b7c9bbdaSJeremy L Thompson 1660ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1661b7c9bbdaSJeremy L Thompson @param[out] num_qpts Variable to store vector number of quadrature points 1662b7c9bbdaSJeremy L Thompson 1663b7c9bbdaSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1664b7c9bbdaSJeremy L Thompson 1665b7c9bbdaSJeremy L Thompson @ref Advanced 1666b7c9bbdaSJeremy L Thompson **/ 1667b7c9bbdaSJeremy L Thompson int CeedOperatorGetNumQuadraturePoints(CeedOperator op, CeedInt *num_qpts) { 16681203703bSJeremy L Thompson bool is_composite; 16691203703bSJeremy L Thompson 16701203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 16716e536b99SJeremy L Thompson CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Not defined for composite operator"); 1672b7c9bbdaSJeremy L Thompson *num_qpts = op->num_qpts; 1673b7c9bbdaSJeremy L Thompson return CEED_ERROR_SUCCESS; 1674b7c9bbdaSJeremy L Thompson } 1675b7c9bbdaSJeremy L Thompson 1676b7c9bbdaSJeremy L Thompson /** 1677ca94c3ddSJeremy L Thompson @brief Estimate number of FLOPs required to apply `CeedOperator` on the active `CeedVector` 16786e15d496SJeremy L Thompson 1679ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to estimate FLOPs for 1680ea61e9acSJeremy L Thompson @param[out] flops Address of variable to hold FLOPs estimate 16816e15d496SJeremy L Thompson 16826e15d496SJeremy L Thompson @ref Backend 16836e15d496SJeremy L Thompson **/ 16849d36ca50SJeremy L Thompson int CeedOperatorGetFlopsEstimate(CeedOperator op, CeedSize *flops) { 16856e15d496SJeremy L Thompson bool is_composite; 16861c66c397SJeremy L Thompson 16872b730f8bSJeremy L Thompson CeedCall(CeedOperatorCheckReady(op)); 16886e15d496SJeremy L Thompson 16896e15d496SJeremy L Thompson *flops = 0; 16902b730f8bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 16916e15d496SJeremy L Thompson if (is_composite) { 16926e15d496SJeremy L Thompson CeedInt num_suboperators; 16931c66c397SJeremy L Thompson 1694c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 16956e15d496SJeremy L Thompson CeedOperator *sub_operators; 1696c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 16976e15d496SJeremy L Thompson 16986e15d496SJeremy L Thompson // FLOPs for each suboperator 16996e15d496SJeremy L Thompson for (CeedInt i = 0; i < num_suboperators; i++) { 17009d36ca50SJeremy L Thompson CeedSize suboperator_flops; 17011c66c397SJeremy L Thompson 17022b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetFlopsEstimate(sub_operators[i], &suboperator_flops)); 17036e15d496SJeremy L Thompson *flops += suboperator_flops; 17046e15d496SJeremy L Thompson } 17056e15d496SJeremy L Thompson } else { 17061c66c397SJeremy L Thompson CeedInt num_input_fields, num_output_fields, num_elem = 0; 17071203703bSJeremy L Thompson CeedQFunction qf; 17081203703bSJeremy L Thompson CeedQFunctionField *qf_input_fields, *qf_output_fields; 17091203703bSJeremy L Thompson CeedOperatorField *op_input_fields, *op_output_fields; 17101c66c397SJeremy L Thompson 17111203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 17121203703bSJeremy L Thompson CeedCall(CeedQFunctionGetFields(qf, &num_input_fields, &qf_input_fields, &num_output_fields, &qf_output_fields)); 1713*c11e12f4SJeremy L Thompson CeedCall(CeedQFunctionDestroy(&qf)); 17141203703bSJeremy L Thompson CeedCall(CeedOperatorGetFields(op, NULL, &op_input_fields, NULL, &op_output_fields)); 17152b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetNumElements(op, &num_elem)); 17164385fb7fSSebastian Grimberg 17176e15d496SJeremy L Thompson // Input FLOPs 17186e15d496SJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 17191203703bSJeremy L Thompson CeedVector vec; 17206e15d496SJeremy L Thompson 17211203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(op_input_fields[i], &vec)); 17221203703bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 17231203703bSJeremy L Thompson CeedEvalMode eval_mode; 17241203703bSJeremy L Thompson CeedSize rstr_flops, basis_flops; 17251203703bSJeremy L Thompson CeedElemRestriction rstr; 17261203703bSJeremy L Thompson CeedBasis basis; 17271203703bSJeremy L Thompson 17281203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetElemRestriction(op_input_fields[i], &rstr)); 17291203703bSJeremy L Thompson CeedCall(CeedElemRestrictionGetFlopsEstimate(rstr, CEED_NOTRANSPOSE, &rstr_flops)); 1730681d0ea7SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&rstr)); 1731edb2538eSJeremy L Thompson *flops += rstr_flops; 17321203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetBasis(op_input_fields[i], &basis)); 17331203703bSJeremy L Thompson CeedCall(CeedQFunctionFieldGetEvalMode(qf_input_fields[i], &eval_mode)); 17341203703bSJeremy L Thompson CeedCall(CeedBasisGetFlopsEstimate(basis, CEED_NOTRANSPOSE, eval_mode, &basis_flops)); 1735681d0ea7SJeremy L Thompson CeedCall(CeedBasisDestroy(&basis)); 17366e15d496SJeremy L Thompson *flops += basis_flops * num_elem; 17376e15d496SJeremy L Thompson } 1738681d0ea7SJeremy L Thompson CeedCall(CeedVectorDestroy(&vec)); 17396e15d496SJeremy L Thompson } 17406e15d496SJeremy L Thompson // QF FLOPs 17411c66c397SJeremy L Thompson { 17429d36ca50SJeremy L Thompson CeedInt num_qpts; 17439d36ca50SJeremy L Thompson CeedSize qf_flops; 17441203703bSJeremy L Thompson CeedQFunction qf; 17451c66c397SJeremy L Thompson 17462b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetNumQuadraturePoints(op, &num_qpts)); 17471203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 17481203703bSJeremy L Thompson CeedCall(CeedQFunctionGetFlopsEstimate(qf, &qf_flops)); 1749*c11e12f4SJeremy L Thompson CeedCall(CeedQFunctionDestroy(&qf)); 17506e536b99SJeremy L Thompson CeedCheck(qf_flops > -1, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPLETE, 17516e536b99SJeremy L Thompson "Must set CeedQFunction FLOPs estimate with CeedQFunctionSetUserFlopsEstimate"); 17526e15d496SJeremy L Thompson *flops += num_elem * num_qpts * qf_flops; 17531c66c397SJeremy L Thompson } 17541c66c397SJeremy L Thompson 17556e15d496SJeremy L Thompson // Output FLOPs 17566e15d496SJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 17571203703bSJeremy L Thompson CeedVector vec; 17586e15d496SJeremy L Thompson 17591203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(op_output_fields[i], &vec)); 17601203703bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 17611203703bSJeremy L Thompson CeedEvalMode eval_mode; 17621203703bSJeremy L Thompson CeedSize rstr_flops, basis_flops; 17631203703bSJeremy L Thompson CeedElemRestriction rstr; 17641203703bSJeremy L Thompson CeedBasis basis; 17651203703bSJeremy L Thompson 17661203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetElemRestriction(op_output_fields[i], &rstr)); 17671203703bSJeremy L Thompson CeedCall(CeedElemRestrictionGetFlopsEstimate(rstr, CEED_TRANSPOSE, &rstr_flops)); 1768681d0ea7SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&rstr)); 1769edb2538eSJeremy L Thompson *flops += rstr_flops; 17701203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetBasis(op_output_fields[i], &basis)); 17711203703bSJeremy L Thompson CeedCall(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode)); 17721203703bSJeremy L Thompson CeedCall(CeedBasisGetFlopsEstimate(basis, CEED_TRANSPOSE, eval_mode, &basis_flops)); 1773681d0ea7SJeremy L Thompson CeedCall(CeedBasisDestroy(&basis)); 17746e15d496SJeremy L Thompson *flops += basis_flops * num_elem; 17756e15d496SJeremy L Thompson } 1776681d0ea7SJeremy L Thompson CeedCall(CeedVectorDestroy(&vec)); 17776e15d496SJeremy L Thompson } 17786e15d496SJeremy L Thompson } 17796e15d496SJeremy L Thompson return CEED_ERROR_SUCCESS; 17806e15d496SJeremy L Thompson } 17816e15d496SJeremy L Thompson 17826e15d496SJeremy L Thompson /** 1783ca94c3ddSJeremy L Thompson @brief Get `CeedQFunction` global context for a `CeedOperator`. 17849fd66db6SSebastian Grimberg 1785ca94c3ddSJeremy L Thompson The caller is responsible for destroying `ctx` returned from this function via @ref CeedQFunctionContextDestroy(). 1786512bb800SJeremy L Thompson 1787ca94c3ddSJeremy 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`. 1788ca94c3ddSJeremy L Thompson This `CeedQFunctionContext` will be destroyed if `ctx` is the only reference to this `CeedQFunctionContext`. 17890126412dSJeremy L Thompson 1790ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1791ca94c3ddSJeremy L Thompson @param[out] ctx Variable to store `CeedQFunctionContext` 17920126412dSJeremy L Thompson 17930126412dSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 17940126412dSJeremy L Thompson 1795859c15bbSJames Wright @ref Advanced 17960126412dSJeremy L Thompson **/ 17970126412dSJeremy L Thompson int CeedOperatorGetContext(CeedOperator op, CeedQFunctionContext *ctx) { 17981203703bSJeremy L Thompson bool is_composite; 17991203703bSJeremy L Thompson CeedQFunction qf; 18001203703bSJeremy L Thompson CeedQFunctionContext qf_ctx; 18011203703bSJeremy L Thompson 18021203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 18036e536b99SJeremy L Thompson CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, "Cannot retrieve CeedQFunctionContext for composite operator"); 18041203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 18051203703bSJeremy L Thompson CeedCall(CeedQFunctionGetInnerContext(qf, &qf_ctx)); 1806*c11e12f4SJeremy L Thompson CeedCall(CeedQFunctionDestroy(&qf)); 18071203703bSJeremy L Thompson if (qf_ctx) CeedCall(CeedQFunctionContextReferenceCopy(qf_ctx, ctx)); 18080126412dSJeremy L Thompson return CEED_ERROR_SUCCESS; 18090126412dSJeremy L Thompson } 18100126412dSJeremy L Thompson 18110126412dSJeremy L Thompson /** 1812ca94c3ddSJeremy L Thompson @brief Get label for a registered `CeedQFunctionContext` field, or `NULL` if no field has been registered with this `field_name`. 18133668ca4bSJeremy L Thompson 1814ca94c3ddSJeremy L Thompson Fields are registered via `CeedQFunctionContextRegister*()` functions (eg. @ref CeedQFunctionContextRegisterDouble()). 1815859c15bbSJames Wright 1816ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 18173668ca4bSJeremy L Thompson @param[in] field_name Name of field to retrieve label 18183668ca4bSJeremy L Thompson @param[out] field_label Variable to field label 18193668ca4bSJeremy L Thompson 18203668ca4bSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 18213668ca4bSJeremy L Thompson 18223668ca4bSJeremy L Thompson @ref User 18233668ca4bSJeremy L Thompson **/ 182417b0d5c6SJeremy L Thompson int CeedOperatorGetContextFieldLabel(CeedOperator op, const char *field_name, CeedContextFieldLabel *field_label) { 18251c66c397SJeremy L Thompson bool is_composite, field_found = false; 18261c66c397SJeremy L Thompson 18272b730f8bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 18282b730f8bSJeremy L Thompson 18293668ca4bSJeremy L Thompson if (is_composite) { 1830a98a090bSJeremy L Thompson // Composite operator 1831a98a090bSJeremy L Thompson // -- Check if composite label already created 18323668ca4bSJeremy L Thompson for (CeedInt i = 0; i < op->num_context_labels; i++) { 18333668ca4bSJeremy L Thompson if (!strcmp(op->context_labels[i]->name, field_name)) { 18343668ca4bSJeremy L Thompson *field_label = op->context_labels[i]; 18353668ca4bSJeremy L Thompson return CEED_ERROR_SUCCESS; 18363668ca4bSJeremy L Thompson } 18373668ca4bSJeremy L Thompson } 18383668ca4bSJeremy L Thompson 1839a98a090bSJeremy L Thompson // -- Create composite label if needed 18403668ca4bSJeremy L Thompson CeedInt num_sub; 18413668ca4bSJeremy L Thompson CeedOperator *sub_operators; 18423668ca4bSJeremy L Thompson CeedContextFieldLabel new_field_label; 18433668ca4bSJeremy L Thompson 18442b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, &new_field_label)); 1845c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub)); 1846c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 18472b730f8bSJeremy L Thompson CeedCall(CeedCalloc(num_sub, &new_field_label->sub_labels)); 18483668ca4bSJeremy L Thompson new_field_label->num_sub_labels = num_sub; 18493668ca4bSJeremy L Thompson 18503668ca4bSJeremy L Thompson for (CeedInt i = 0; i < num_sub; i++) { 18513668ca4bSJeremy L Thompson if (sub_operators[i]->qf->ctx) { 18523668ca4bSJeremy L Thompson CeedContextFieldLabel new_field_label_i; 18531c66c397SJeremy L Thompson 18542b730f8bSJeremy L Thompson CeedCall(CeedQFunctionContextGetFieldLabel(sub_operators[i]->qf->ctx, field_name, &new_field_label_i)); 18553668ca4bSJeremy L Thompson if (new_field_label_i) { 1856a98a090bSJeremy L Thompson field_found = true; 18573668ca4bSJeremy L Thompson new_field_label->sub_labels[i] = new_field_label_i; 18583668ca4bSJeremy L Thompson new_field_label->name = new_field_label_i->name; 18593668ca4bSJeremy L Thompson new_field_label->description = new_field_label_i->description; 18602b730f8bSJeremy L Thompson if (new_field_label->type && new_field_label->type != new_field_label_i->type) { 18617bfe0f0eSJeremy L Thompson // LCOV_EXCL_START 18622b730f8bSJeremy L Thompson CeedCall(CeedFree(&new_field_label)); 18636e536b99SJeremy L Thompson return CeedError(CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, "Incompatible field types on sub-operator contexts. %s != %s", 18642b730f8bSJeremy L Thompson CeedContextFieldTypes[new_field_label->type], CeedContextFieldTypes[new_field_label_i->type]); 18657bfe0f0eSJeremy L Thompson // LCOV_EXCL_STOP 18667bfe0f0eSJeremy L Thompson } else { 18677bfe0f0eSJeremy L Thompson new_field_label->type = new_field_label_i->type; 18687bfe0f0eSJeremy L Thompson } 18692b730f8bSJeremy L Thompson if (new_field_label->num_values != 0 && new_field_label->num_values != new_field_label_i->num_values) { 18707bfe0f0eSJeremy L Thompson // LCOV_EXCL_START 18712b730f8bSJeremy L Thompson CeedCall(CeedFree(&new_field_label)); 18726e536b99SJeremy L Thompson return CeedError(CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, 18736e536b99SJeremy L Thompson "Incompatible field number of values on sub-operator contexts. %zu != %zu", new_field_label->num_values, 18746e536b99SJeremy L Thompson new_field_label_i->num_values); 18757bfe0f0eSJeremy L Thompson // LCOV_EXCL_STOP 18767bfe0f0eSJeremy L Thompson } else { 18777bfe0f0eSJeremy L Thompson new_field_label->num_values = new_field_label_i->num_values; 18787bfe0f0eSJeremy L Thompson } 18793668ca4bSJeremy L Thompson } 18803668ca4bSJeremy L Thompson } 18813668ca4bSJeremy L Thompson } 1882a98a090bSJeremy L Thompson // -- Cleanup if field was found 1883a98a090bSJeremy L Thompson if (field_found) { 1884a98a090bSJeremy L Thompson *field_label = new_field_label; 1885a98a090bSJeremy L Thompson } else { 18863668ca4bSJeremy L Thompson // LCOV_EXCL_START 18872b730f8bSJeremy L Thompson CeedCall(CeedFree(&new_field_label->sub_labels)); 18882b730f8bSJeremy L Thompson CeedCall(CeedFree(&new_field_label)); 18893668ca4bSJeremy L Thompson *field_label = NULL; 18903668ca4bSJeremy L Thompson // LCOV_EXCL_STOP 18915ac9af79SJeremy L Thompson } 18925ac9af79SJeremy L Thompson } else { 18931203703bSJeremy L Thompson CeedQFunction qf; 18941203703bSJeremy L Thompson CeedQFunctionContext ctx; 18951203703bSJeremy L Thompson 1896a98a090bSJeremy L Thompson // Single, non-composite operator 18971203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 18981203703bSJeremy L Thompson CeedCall(CeedQFunctionGetInnerContext(qf, &ctx)); 1899*c11e12f4SJeremy L Thompson CeedCall(CeedQFunctionDestroy(&qf)); 19001203703bSJeremy L Thompson if (ctx) { 19011203703bSJeremy L Thompson CeedCall(CeedQFunctionContextGetFieldLabel(ctx, field_name, field_label)); 1902a98a090bSJeremy L Thompson } else { 1903a98a090bSJeremy L Thompson *field_label = NULL; 1904a98a090bSJeremy L Thompson } 19055ac9af79SJeremy L Thompson } 19065ac9af79SJeremy L Thompson 19075ac9af79SJeremy L Thompson // Set label in operator 19085ac9af79SJeremy L Thompson if (*field_label) { 19095ac9af79SJeremy L Thompson (*field_label)->from_op = true; 19105ac9af79SJeremy L Thompson 19113668ca4bSJeremy L Thompson // Move new composite label to operator 19123668ca4bSJeremy L Thompson if (op->num_context_labels == 0) { 19132b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, &op->context_labels)); 19143668ca4bSJeremy L Thompson op->max_context_labels = 1; 19153668ca4bSJeremy L Thompson } else if (op->num_context_labels == op->max_context_labels) { 19162b730f8bSJeremy L Thompson CeedCall(CeedRealloc(2 * op->num_context_labels, &op->context_labels)); 19173668ca4bSJeremy L Thompson op->max_context_labels *= 2; 19183668ca4bSJeremy L Thompson } 19195ac9af79SJeremy L Thompson op->context_labels[op->num_context_labels] = *field_label; 19203668ca4bSJeremy L Thompson op->num_context_labels++; 19213668ca4bSJeremy L Thompson } 19223668ca4bSJeremy L Thompson return CEED_ERROR_SUCCESS; 19233668ca4bSJeremy L Thompson } 19243668ca4bSJeremy L Thompson 19253668ca4bSJeremy L Thompson /** 1926ca94c3ddSJeremy L Thompson @brief Set `CeedQFunctionContext` field holding double precision values. 19274385fb7fSSebastian Grimberg 1928ca94c3ddSJeremy L Thompson For composite operators, the values are set in all sub-operator `CeedQFunctionContext` that have a matching `field_name`. 1929d8dd9a91SJeremy L Thompson 1930ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 19312788fa27SJeremy L Thompson @param[in] field_label Label of field to set 1932ea61e9acSJeremy L Thompson @param[in] values Values to set 1933d8dd9a91SJeremy L Thompson 1934d8dd9a91SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1935d8dd9a91SJeremy L Thompson 1936d8dd9a91SJeremy L Thompson @ref User 1937d8dd9a91SJeremy L Thompson **/ 193817b0d5c6SJeremy L Thompson int CeedOperatorSetContextDouble(CeedOperator op, CeedContextFieldLabel field_label, double *values) { 19392b730f8bSJeremy L Thompson return CeedOperatorContextSetGeneric(op, field_label, CEED_CONTEXT_FIELD_DOUBLE, values); 1940d8dd9a91SJeremy L Thompson } 1941d8dd9a91SJeremy L Thompson 1942d8dd9a91SJeremy L Thompson /** 1943ca94c3ddSJeremy L Thompson @brief Get `CeedQFunctionContext` field holding double precision values, read-only. 19444385fb7fSSebastian Grimberg 1945ca94c3ddSJeremy L Thompson For composite operators, the values correspond to the first sub-operator `CeedQFunctionContext` that has a matching `field_name`. 19462788fa27SJeremy L Thompson 1947ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 19482788fa27SJeremy L Thompson @param[in] field_label Label of field to get 19492788fa27SJeremy L Thompson @param[out] num_values Number of values in the field label 19502788fa27SJeremy L Thompson @param[out] values Pointer to context values 19512788fa27SJeremy L Thompson 19522788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 19532788fa27SJeremy L Thompson 19542788fa27SJeremy L Thompson @ref User 19552788fa27SJeremy L Thompson **/ 195617b0d5c6SJeremy L Thompson int CeedOperatorGetContextDoubleRead(CeedOperator op, CeedContextFieldLabel field_label, size_t *num_values, const double **values) { 19572788fa27SJeremy L Thompson return CeedOperatorContextGetGenericRead(op, field_label, CEED_CONTEXT_FIELD_DOUBLE, num_values, values); 19582788fa27SJeremy L Thompson } 19592788fa27SJeremy L Thompson 19602788fa27SJeremy L Thompson /** 1961ca94c3ddSJeremy L Thompson @brief Restore `CeedQFunctionContext` field holding double precision values, read-only. 19622788fa27SJeremy L Thompson 1963ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 19642788fa27SJeremy L Thompson @param[in] field_label Label of field to restore 19652788fa27SJeremy L Thompson @param[out] values Pointer to context values 19662788fa27SJeremy L Thompson 19672788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 19682788fa27SJeremy L Thompson 19692788fa27SJeremy L Thompson @ref User 19702788fa27SJeremy L Thompson **/ 197117b0d5c6SJeremy L Thompson int CeedOperatorRestoreContextDoubleRead(CeedOperator op, CeedContextFieldLabel field_label, const double **values) { 19722788fa27SJeremy L Thompson return CeedOperatorContextRestoreGenericRead(op, field_label, CEED_CONTEXT_FIELD_DOUBLE, values); 19732788fa27SJeremy L Thompson } 19742788fa27SJeremy L Thompson 19752788fa27SJeremy L Thompson /** 1976ca94c3ddSJeremy L Thompson @brief Set `CeedQFunctionContext` field holding `int32` values. 19774385fb7fSSebastian Grimberg 1978ca94c3ddSJeremy L Thompson For composite operators, the values are set in all sub-operator `CeedQFunctionContext` that have a matching `field_name`. 1979d8dd9a91SJeremy L Thompson 1980ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 1981ea61e9acSJeremy L Thompson @param[in] field_label Label of field to set 1982ea61e9acSJeremy L Thompson @param[in] values Values to set 1983d8dd9a91SJeremy L Thompson 1984d8dd9a91SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1985d8dd9a91SJeremy L Thompson 1986d8dd9a91SJeremy L Thompson @ref User 1987d8dd9a91SJeremy L Thompson **/ 198823dbfd29SJeremy L Thompson int CeedOperatorSetContextInt32(CeedOperator op, CeedContextFieldLabel field_label, int32_t *values) { 19892b730f8bSJeremy L Thompson return CeedOperatorContextSetGeneric(op, field_label, CEED_CONTEXT_FIELD_INT32, values); 1990d8dd9a91SJeremy L Thompson } 1991d8dd9a91SJeremy L Thompson 1992d8dd9a91SJeremy L Thompson /** 1993ca94c3ddSJeremy L Thompson @brief Get `CeedQFunctionContext` field holding `int32` values, read-only. 19944385fb7fSSebastian Grimberg 1995ca94c3ddSJeremy L Thompson For composite operators, the values correspond to the first sub-operator `CeedQFunctionContext` that has a matching `field_name`. 19962788fa27SJeremy L Thompson 1997ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 19982788fa27SJeremy L Thompson @param[in] field_label Label of field to get 1999ca94c3ddSJeremy L Thompson @param[out] num_values Number of `int32` values in `values` 20002788fa27SJeremy L Thompson @param[out] values Pointer to context values 20012788fa27SJeremy L Thompson 20022788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 20032788fa27SJeremy L Thompson 20042788fa27SJeremy L Thompson @ref User 20052788fa27SJeremy L Thompson **/ 200623dbfd29SJeremy L Thompson int CeedOperatorGetContextInt32Read(CeedOperator op, CeedContextFieldLabel field_label, size_t *num_values, const int32_t **values) { 20072788fa27SJeremy L Thompson return CeedOperatorContextGetGenericRead(op, field_label, CEED_CONTEXT_FIELD_INT32, num_values, values); 20082788fa27SJeremy L Thompson } 20092788fa27SJeremy L Thompson 20102788fa27SJeremy L Thompson /** 2011ca94c3ddSJeremy L Thompson @brief Restore `CeedQFunctionContext` field holding `int32` values, read-only. 20122788fa27SJeremy L Thompson 2013ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 20142788fa27SJeremy L Thompson @param[in] field_label Label of field to get 20152788fa27SJeremy L Thompson @param[out] values Pointer to context values 20162788fa27SJeremy L Thompson 20172788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 20182788fa27SJeremy L Thompson 20192788fa27SJeremy L Thompson @ref User 20202788fa27SJeremy L Thompson **/ 202123dbfd29SJeremy L Thompson int CeedOperatorRestoreContextInt32Read(CeedOperator op, CeedContextFieldLabel field_label, const int32_t **values) { 20222788fa27SJeremy L Thompson return CeedOperatorContextRestoreGenericRead(op, field_label, CEED_CONTEXT_FIELD_INT32, values); 20232788fa27SJeremy L Thompson } 20242788fa27SJeremy L Thompson 20252788fa27SJeremy L Thompson /** 2026ca94c3ddSJeremy L Thompson @brief Set `CeedQFunctionContext` field holding boolean values. 20275b6ec284SJeremy L Thompson 2028ca94c3ddSJeremy L Thompson For composite operators, the values are set in all sub-operator `CeedQFunctionContext` that have a matching `field_name`. 20295b6ec284SJeremy L Thompson 2030ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 20315b6ec284SJeremy L Thompson @param[in] field_label Label of field to set 20325b6ec284SJeremy L Thompson @param[in] values Values to set 20335b6ec284SJeremy L Thompson 20345b6ec284SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 20355b6ec284SJeremy L Thompson 20365b6ec284SJeremy L Thompson @ref User 20375b6ec284SJeremy L Thompson **/ 20385b6ec284SJeremy L Thompson int CeedOperatorSetContextBoolean(CeedOperator op, CeedContextFieldLabel field_label, bool *values) { 20395b6ec284SJeremy L Thompson return CeedOperatorContextSetGeneric(op, field_label, CEED_CONTEXT_FIELD_BOOL, values); 20405b6ec284SJeremy L Thompson } 20415b6ec284SJeremy L Thompson 20425b6ec284SJeremy L Thompson /** 2043ca94c3ddSJeremy L Thompson @brief Get `CeedQFunctionContext` field holding boolean values, read-only. 20445b6ec284SJeremy L Thompson 2045ca94c3ddSJeremy L Thompson For composite operators, the values correspond to the first sub-operator `CeedQFunctionContext` that has a matching `field_name`. 20465b6ec284SJeremy L Thompson 2047ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 20485b6ec284SJeremy L Thompson @param[in] field_label Label of field to get 2049ca94c3ddSJeremy L Thompson @param[out] num_values Number of boolean values in `values` 20505b6ec284SJeremy L Thompson @param[out] values Pointer to context values 20515b6ec284SJeremy L Thompson 20525b6ec284SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 20535b6ec284SJeremy L Thompson 20545b6ec284SJeremy L Thompson @ref User 20555b6ec284SJeremy L Thompson **/ 20565b6ec284SJeremy L Thompson int CeedOperatorGetContextBooleanRead(CeedOperator op, CeedContextFieldLabel field_label, size_t *num_values, const bool **values) { 20575b6ec284SJeremy L Thompson return CeedOperatorContextGetGenericRead(op, field_label, CEED_CONTEXT_FIELD_BOOL, num_values, values); 20585b6ec284SJeremy L Thompson } 20595b6ec284SJeremy L Thompson 20605b6ec284SJeremy L Thompson /** 2061ca94c3ddSJeremy L Thompson @brief Restore `CeedQFunctionContext` field holding boolean values, read-only. 20625b6ec284SJeremy L Thompson 2063ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 20645b6ec284SJeremy L Thompson @param[in] field_label Label of field to get 20655b6ec284SJeremy L Thompson @param[out] values Pointer to context values 20665b6ec284SJeremy L Thompson 20675b6ec284SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 20685b6ec284SJeremy L Thompson 20695b6ec284SJeremy L Thompson @ref User 20705b6ec284SJeremy L Thompson **/ 20715b6ec284SJeremy L Thompson int CeedOperatorRestoreContextBooleanRead(CeedOperator op, CeedContextFieldLabel field_label, const bool **values) { 20725b6ec284SJeremy L Thompson return CeedOperatorContextRestoreGenericRead(op, field_label, CEED_CONTEXT_FIELD_BOOL, values); 20735b6ec284SJeremy L Thompson } 20745b6ec284SJeremy L Thompson 20755b6ec284SJeremy L Thompson /** 2076ca94c3ddSJeremy L Thompson @brief Apply `CeedOperator` to a `CeedVector`. 2077d7b241e6Sjeremylt 2078ea61e9acSJeremy L Thompson This computes the action of the operator on the specified (active) input, yielding its (active) output. 2079ca94c3ddSJeremy L Thompson All inputs and outputs must be specified using @ref CeedOperatorSetField(). 2080d7b241e6Sjeremylt 2081ca94c3ddSJeremy L Thompson Note: Calling this function asserts that setup is complete and sets the `CeedOperator` as immutable. 2082f04ea552SJeremy L Thompson 2083ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to apply 2084ca94c3ddSJeremy L Thompson @param[in] in `CeedVector` containing input state or @ref CEED_VECTOR_NONE if there are no active inputs 2085ca94c3ddSJeremy 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 2086ca94c3ddSJeremy L Thompson @param[in] request Address of @ref CeedRequest for non-blocking completion, else @ref CEED_REQUEST_IMMEDIATE 2087b11c1e72Sjeremylt 2088b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 2089dfdf5a53Sjeremylt 20907a982d89SJeremy L. Thompson @ref User 2091b11c1e72Sjeremylt **/ 20922b730f8bSJeremy L Thompson int CeedOperatorApply(CeedOperator op, CeedVector in, CeedVector out, CeedRequest *request) { 20931203703bSJeremy L Thompson bool is_composite; 20941203703bSJeremy L Thompson 20952b730f8bSJeremy L Thompson CeedCall(CeedOperatorCheckReady(op)); 2096d7b241e6Sjeremylt 20971203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 20981203703bSJeremy L Thompson if (is_composite) { 2099250756a7Sjeremylt // Composite Operator 2100250756a7Sjeremylt if (op->ApplyComposite) { 21012b730f8bSJeremy L Thompson CeedCall(op->ApplyComposite(op, in, out, request)); 2102250756a7Sjeremylt } else { 2103d1d35e2fSjeremylt CeedInt num_suboperators; 2104d1d35e2fSjeremylt CeedOperator *sub_operators; 21051c66c397SJeremy L Thompson 21061c66c397SJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 2107c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 2108250756a7Sjeremylt 2109250756a7Sjeremylt // Zero all output vectors 21103ca2b39bSJeremy L Thompson if (out != CEED_VECTOR_NONE) CeedCall(CeedVectorSetValue(out, 0.0)); 2111d1d35e2fSjeremylt for (CeedInt i = 0; i < num_suboperators; i++) { 21121203703bSJeremy L Thompson CeedInt num_output_fields; 21131203703bSJeremy L Thompson CeedOperatorField *output_fields; 21141c66c397SJeremy L Thompson 21151203703bSJeremy L Thompson CeedCall(CeedOperatorGetFields(sub_operators[i], NULL, NULL, &num_output_fields, &output_fields)); 21161203703bSJeremy L Thompson for (CeedInt j = 0; j < num_output_fields; j++) { 21171203703bSJeremy L Thompson CeedVector vec; 21181203703bSJeremy L Thompson 21191203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(output_fields[j], &vec)); 2120250756a7Sjeremylt if (vec != CEED_VECTOR_ACTIVE && vec != CEED_VECTOR_NONE) { 21212b730f8bSJeremy L Thompson CeedCall(CeedVectorSetValue(vec, 0.0)); 2122250756a7Sjeremylt } 2123681d0ea7SJeremy L Thompson CeedCall(CeedVectorDestroy(&vec)); 2124250756a7Sjeremylt } 2125250756a7Sjeremylt } 2126250756a7Sjeremylt // Apply 2127f754c177SSebastian Grimberg for (CeedInt i = 0; i < num_suboperators; i++) { 2128f754c177SSebastian Grimberg CeedCall(CeedOperatorApplyAdd(sub_operators[i], in, out, request)); 2129cae8b89aSjeremylt } 2130cae8b89aSjeremylt } 21313ca2b39bSJeremy L Thompson } else { 21323ca2b39bSJeremy L Thompson // Standard Operator 21333ca2b39bSJeremy L Thompson if (op->Apply) { 21343ca2b39bSJeremy L Thompson CeedCall(op->Apply(op, in, out, request)); 21353ca2b39bSJeremy L Thompson } else { 21361203703bSJeremy L Thompson CeedInt num_output_fields; 21371203703bSJeremy L Thompson CeedOperatorField *output_fields; 21381203703bSJeremy L Thompson 21391203703bSJeremy L Thompson CeedCall(CeedOperatorGetFields(op, NULL, NULL, &num_output_fields, &output_fields)); 21403ca2b39bSJeremy L Thompson // Zero all output vectors 21411203703bSJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 2142681d0ea7SJeremy L Thompson bool is_active; 21431203703bSJeremy L Thompson CeedVector vec; 21441c66c397SJeremy L Thompson 21451203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(output_fields[i], &vec)); 2146681d0ea7SJeremy L Thompson is_active = vec == CEED_VECTOR_ACTIVE; 2147681d0ea7SJeremy L Thompson if (is_active) vec = out; 21483ca2b39bSJeremy L Thompson if (vec != CEED_VECTOR_NONE) CeedCall(CeedVectorSetValue(vec, 0.0)); 2149681d0ea7SJeremy L Thompson if (!is_active) CeedCall(CeedVectorDestroy(&vec)); 21503ca2b39bSJeremy L Thompson } 21513ca2b39bSJeremy L Thompson // Apply 21521203703bSJeremy L Thompson if (op->num_elem > 0) CeedCall(op->ApplyAdd(op, in, out, request)); 21533ca2b39bSJeremy L Thompson } 2154250756a7Sjeremylt } 2155e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 2156cae8b89aSjeremylt } 2157cae8b89aSjeremylt 2158cae8b89aSjeremylt /** 2159ca94c3ddSJeremy L Thompson @brief Apply `CeedOperator` to a `CeedVector` and add result to output `CeedVector`. 2160cae8b89aSjeremylt 2161ea61e9acSJeremy L Thompson This computes the action of the operator on the specified (active) input, yielding its (active) output. 2162ca94c3ddSJeremy L Thompson All inputs and outputs must be specified using @ref CeedOperatorSetField(). 2163cae8b89aSjeremylt 2164ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to apply 2165ca94c3ddSJeremy L Thompson @param[in] in `CeedVector` containing input state or @ref CEED_VECTOR_NONE if there are no active inputs 2166ca94c3ddSJeremy 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 2167ca94c3ddSJeremy L Thompson @param[in] request Address of @ref CeedRequest for non-blocking completion, else @ref CEED_REQUEST_IMMEDIATE 2168cae8b89aSjeremylt 2169cae8b89aSjeremylt @return An error code: 0 - success, otherwise - failure 2170cae8b89aSjeremylt 21717a982d89SJeremy L. Thompson @ref User 2172cae8b89aSjeremylt **/ 21732b730f8bSJeremy L Thompson int CeedOperatorApplyAdd(CeedOperator op, CeedVector in, CeedVector out, CeedRequest *request) { 21741203703bSJeremy L Thompson bool is_composite; 21751203703bSJeremy L Thompson 21762b730f8bSJeremy L Thompson CeedCall(CeedOperatorCheckReady(op)); 2177cae8b89aSjeremylt 21781203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 21791203703bSJeremy L Thompson if (is_composite) { 2180250756a7Sjeremylt // Composite Operator 2181250756a7Sjeremylt if (op->ApplyAddComposite) { 21822b730f8bSJeremy L Thompson CeedCall(op->ApplyAddComposite(op, in, out, request)); 2183cae8b89aSjeremylt } else { 2184d1d35e2fSjeremylt CeedInt num_suboperators; 2185d1d35e2fSjeremylt CeedOperator *sub_operators; 2186250756a7Sjeremylt 21871c66c397SJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 21881c66c397SJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 2189d1d35e2fSjeremylt for (CeedInt i = 0; i < num_suboperators; i++) { 21902b730f8bSJeremy L Thompson CeedCall(CeedOperatorApplyAdd(sub_operators[i], in, out, request)); 21911d7d2407SJeremy L Thompson } 2192250756a7Sjeremylt } 21931203703bSJeremy L Thompson } else if (op->num_elem > 0) { 21943ca2b39bSJeremy L Thompson // Standard Operator 21953ca2b39bSJeremy L Thompson CeedCall(op->ApplyAdd(op, in, out, request)); 2196250756a7Sjeremylt } 2197e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 2198d7b241e6Sjeremylt } 2199d7b241e6Sjeremylt 2200d7b241e6Sjeremylt /** 2201536b928cSSebastian Grimberg @brief Destroy temporary assembly data associated with a `CeedOperator` 2202536b928cSSebastian Grimberg 2203536b928cSSebastian Grimberg @param[in,out] op `CeedOperator` whose assembly data to destroy 2204536b928cSSebastian Grimberg 2205536b928cSSebastian Grimberg @return An error code: 0 - success, otherwise - failure 2206536b928cSSebastian Grimberg 2207536b928cSSebastian Grimberg @ref User 2208536b928cSSebastian Grimberg **/ 2209536b928cSSebastian Grimberg int CeedOperatorAssemblyDataStrip(CeedOperator op) { 2210536b928cSSebastian Grimberg bool is_composite; 2211536b928cSSebastian Grimberg 2212536b928cSSebastian Grimberg CeedCall(CeedQFunctionAssemblyDataDestroy(&op->qf_assembled)); 2213536b928cSSebastian Grimberg CeedCall(CeedOperatorAssemblyDataDestroy(&op->op_assembled)); 2214536b928cSSebastian Grimberg CeedCall(CeedOperatorIsComposite(op, &is_composite)); 2215536b928cSSebastian Grimberg if (is_composite) { 2216536b928cSSebastian Grimberg CeedInt num_suboperators; 2217536b928cSSebastian Grimberg CeedOperator *sub_operators; 2218536b928cSSebastian Grimberg 2219536b928cSSebastian Grimberg CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 2220536b928cSSebastian Grimberg CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 2221536b928cSSebastian Grimberg for (CeedInt i = 0; i < num_suboperators; i++) { 2222536b928cSSebastian Grimberg CeedCall(CeedQFunctionAssemblyDataDestroy(&sub_operators[i]->qf_assembled)); 2223536b928cSSebastian Grimberg CeedCall(CeedOperatorAssemblyDataDestroy(&sub_operators[i]->op_assembled)); 2224536b928cSSebastian Grimberg } 2225536b928cSSebastian Grimberg } 2226536b928cSSebastian Grimberg return CEED_ERROR_SUCCESS; 2227536b928cSSebastian Grimberg } 2228536b928cSSebastian Grimberg 2229536b928cSSebastian Grimberg /** 2230ca94c3ddSJeremy L Thompson @brief Destroy a `CeedOperator` 2231d7b241e6Sjeremylt 2232ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` to destroy 2233b11c1e72Sjeremylt 2234b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 2235dfdf5a53Sjeremylt 22367a982d89SJeremy L. Thompson @ref User 2237b11c1e72Sjeremylt **/ 2238d7b241e6Sjeremylt int CeedOperatorDestroy(CeedOperator *op) { 2239ad6481ceSJeremy L Thompson if (!*op || --(*op)->ref_count > 0) { 2240ad6481ceSJeremy L Thompson *op = NULL; 2241ad6481ceSJeremy L Thompson return CEED_ERROR_SUCCESS; 2242ad6481ceSJeremy L Thompson } 2243f883f0a5SSebastian Grimberg // Backend destroy 2244f883f0a5SSebastian Grimberg if ((*op)->Destroy) { 2245f883f0a5SSebastian Grimberg CeedCall((*op)->Destroy(*op)); 2246f883f0a5SSebastian Grimberg } 2247fe2413ffSjeremylt // Free fields 22482b730f8bSJeremy L Thompson for (CeedInt i = 0; i < (*op)->num_fields; i++) { 2249d1d35e2fSjeremylt if ((*op)->input_fields[i]) { 2250437c7c90SJeremy L Thompson if ((*op)->input_fields[i]->elem_rstr != CEED_ELEMRESTRICTION_NONE) { 2251437c7c90SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&(*op)->input_fields[i]->elem_rstr)); 225215910d16Sjeremylt } 2253356036faSJeremy L Thompson if ((*op)->input_fields[i]->basis != CEED_BASIS_NONE) { 22542b730f8bSJeremy L Thompson CeedCall(CeedBasisDestroy(&(*op)->input_fields[i]->basis)); 225571352a93Sjeremylt } 22562b730f8bSJeremy L Thompson if ((*op)->input_fields[i]->vec != CEED_VECTOR_ACTIVE && (*op)->input_fields[i]->vec != CEED_VECTOR_NONE) { 22572b730f8bSJeremy L Thompson CeedCall(CeedVectorDestroy(&(*op)->input_fields[i]->vec)); 225871352a93Sjeremylt } 22592b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->input_fields[i]->field_name)); 22602b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->input_fields[i])); 2261fe2413ffSjeremylt } 22622b730f8bSJeremy L Thompson } 22632b730f8bSJeremy L Thompson for (CeedInt i = 0; i < (*op)->num_fields; i++) { 2264d1d35e2fSjeremylt if ((*op)->output_fields[i]) { 2265437c7c90SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&(*op)->output_fields[i]->elem_rstr)); 2266356036faSJeremy L Thompson if ((*op)->output_fields[i]->basis != CEED_BASIS_NONE) { 22672b730f8bSJeremy L Thompson CeedCall(CeedBasisDestroy(&(*op)->output_fields[i]->basis)); 226871352a93Sjeremylt } 22692b730f8bSJeremy L Thompson if ((*op)->output_fields[i]->vec != CEED_VECTOR_ACTIVE && (*op)->output_fields[i]->vec != CEED_VECTOR_NONE) { 22702b730f8bSJeremy L Thompson CeedCall(CeedVectorDestroy(&(*op)->output_fields[i]->vec)); 227171352a93Sjeremylt } 22722b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->output_fields[i]->field_name)); 22732b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->output_fields[i])); 22742b730f8bSJeremy L Thompson } 2275fe2413ffSjeremylt } 2276f883f0a5SSebastian Grimberg CeedCall(CeedFree(&(*op)->input_fields)); 2277f883f0a5SSebastian Grimberg CeedCall(CeedFree(&(*op)->output_fields)); 2278f883f0a5SSebastian Grimberg // Destroy AtPoints data 227948acf710SJeremy L Thompson CeedCall(CeedVectorDestroy(&(*op)->point_coords)); 228048acf710SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&(*op)->rstr_points)); 228148acf710SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&(*op)->first_points_rstr)); 2282c6b536a8SSebastian Grimberg // Destroy assembly data (must happen before destroying sub_operators) 2283f883f0a5SSebastian Grimberg CeedCall(CeedOperatorAssemblyDataStrip(*op)); 2284d1d35e2fSjeremylt // Destroy sub_operators 22852b730f8bSJeremy L Thompson for (CeedInt i = 0; i < (*op)->num_suboperators; i++) { 2286d1d35e2fSjeremylt if ((*op)->sub_operators[i]) { 22872b730f8bSJeremy L Thompson CeedCall(CeedOperatorDestroy(&(*op)->sub_operators[i])); 228852d6035fSJeremy L Thompson } 22892b730f8bSJeremy L Thompson } 2290f883f0a5SSebastian Grimberg CeedCall(CeedFree(&(*op)->sub_operators)); 22912b730f8bSJeremy L Thompson CeedCall(CeedQFunctionDestroy(&(*op)->qf)); 22922b730f8bSJeremy L Thompson CeedCall(CeedQFunctionDestroy(&(*op)->dqf)); 22932b730f8bSJeremy L Thompson CeedCall(CeedQFunctionDestroy(&(*op)->dqfT)); 22943668ca4bSJeremy L Thompson // Destroy any composite labels 22955ac9af79SJeremy L Thompson if ((*op)->is_composite) { 22963668ca4bSJeremy L Thompson for (CeedInt i = 0; i < (*op)->num_context_labels; i++) { 22972b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->context_labels[i]->sub_labels)); 22982b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->context_labels[i])); 22993668ca4bSJeremy L Thompson } 23005ac9af79SJeremy L Thompson } 23012b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->context_labels)); 2302fe2413ffSjeremylt 23035107b09fSJeremy L Thompson // Destroy fallback 23042b730f8bSJeremy L Thompson CeedCall(CeedOperatorDestroy(&(*op)->op_fallback)); 23055107b09fSJeremy L Thompson 23062b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->name)); 2307f883f0a5SSebastian Grimberg CeedCall(CeedDestroy(&(*op)->ceed)); 23082b730f8bSJeremy L Thompson CeedCall(CeedFree(op)); 2309e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 2310d7b241e6Sjeremylt } 2311d7b241e6Sjeremylt 2312d7b241e6Sjeremylt /// @} 2313