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); 121*681d0ea7SJeremy L Thompson 122*681d0ea7SJeremy L Thompson CeedCall(CeedVectorDestroy(&vec)); 123*681d0ea7SJeremy 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)); 1511c66c397SJeremy L Thompson 1522b730f8bSJeremy L Thompson fprintf(stream, "%s %" CeedInt_FMT " elements with %" CeedInt_FMT " quadrature points each\n", pre, num_elem, num_qpts); 1532b730f8bSJeremy L Thompson fprintf(stream, "%s %" CeedInt_FMT " field%s\n", pre, total_fields, total_fields > 1 ? "s" : ""); 1541203703bSJeremy L Thompson fprintf(stream, "%s %" CeedInt_FMT " input field%s:\n", pre, num_input_fields, num_input_fields > 1 ? "s" : ""); 1551203703bSJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 1561203703bSJeremy L Thompson CeedCall(CeedOperatorFieldView(op_input_fields[i], qf_input_fields[i], i, sub, 1, stream)); 1577a982d89SJeremy L. Thompson } 1581203703bSJeremy L Thompson fprintf(stream, "%s %" CeedInt_FMT " output field%s:\n", pre, num_output_fields, num_output_fields > 1 ? "s" : ""); 1591203703bSJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 1601203703bSJeremy L Thompson CeedCall(CeedOperatorFieldView(op_output_fields[i], qf_output_fields[i], i, sub, 0, stream)); 1617a982d89SJeremy L. Thompson } 162e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 1637a982d89SJeremy L. Thompson } 1647a982d89SJeremy L. Thompson 165d99fa3c5SJeremy L Thompson /** 166*681d0ea7SJeremy L Thompson @brief Find the active input vector `CeedBasis` for a non-composite `CeedOperator`. 167*681d0ea7SJeremy L Thompson 168*681d0ea7SJeremy L Thompson Note: Caller is responsible for destroying the `active_basis` with @ref CeedBasisDestroy(). 169eaf62fffSJeremy L Thompson 170ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to find active `CeedBasis` for 171ca94c3ddSJeremy L Thompson @param[out] active_basis `CeedBasis` for active input vector or `NULL` for composite operator 172eaf62fffSJeremy L Thompson 173eaf62fffSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 174eaf62fffSJeremy L Thompson 175eaf62fffSJeremy L Thompson @ref Developer 176eaf62fffSJeremy L Thompson **/ 177eaf62fffSJeremy L Thompson int CeedOperatorGetActiveBasis(CeedOperator op, CeedBasis *active_basis) { 178506b1a0cSSebastian Grimberg CeedCall(CeedOperatorGetActiveBases(op, active_basis, NULL)); 179506b1a0cSSebastian Grimberg return CEED_ERROR_SUCCESS; 180506b1a0cSSebastian Grimberg } 181506b1a0cSSebastian Grimberg 182506b1a0cSSebastian Grimberg /** 183*681d0ea7SJeremy L Thompson @brief Find the active input and output vector `CeedBasis` for a non-composite `CeedOperator`. 184*681d0ea7SJeremy L Thompson 185*681d0ea7SJeremy L Thompson Note: Caller is responsible for destroying the bases with @ref CeedBasisDestroy(). 186506b1a0cSSebastian Grimberg 187ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to find active `CeedBasis` for 188ca94c3ddSJeremy L Thompson @param[out] active_input_basis `CeedBasis` for active input vector or `NULL` for composite operator 189ca94c3ddSJeremy L Thompson @param[out] active_output_basis `CeedBasis` for active output vector or `NULL` for composite operator 190506b1a0cSSebastian Grimberg 191506b1a0cSSebastian Grimberg @return An error code: 0 - success, otherwise - failure 192506b1a0cSSebastian Grimberg 193506b1a0cSSebastian Grimberg @ref Developer 194506b1a0cSSebastian Grimberg **/ 195506b1a0cSSebastian Grimberg int CeedOperatorGetActiveBases(CeedOperator op, CeedBasis *active_input_basis, CeedBasis *active_output_basis) { 1961203703bSJeremy L Thompson bool is_composite; 1971203703bSJeremy L Thompson CeedInt num_input_fields, num_output_fields; 1986aaed0edSJeremy L Thompson Ceed ceed; 1991203703bSJeremy L Thompson CeedOperatorField *op_input_fields, *op_output_fields; 2001c66c397SJeremy L Thompson 2016aaed0edSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 2021203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 2031203703bSJeremy L Thompson CeedCall(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields)); 2041203703bSJeremy L Thompson 205506b1a0cSSebastian Grimberg if (active_input_basis) { 206506b1a0cSSebastian Grimberg *active_input_basis = NULL; 2071203703bSJeremy L Thompson if (!is_composite) { 2081203703bSJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 2091203703bSJeremy L Thompson CeedVector vec; 2101203703bSJeremy L Thompson 2111203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(op_input_fields[i], &vec)); 2121203703bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 2131203703bSJeremy L Thompson CeedBasis basis; 2141203703bSJeremy L Thompson 2151203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetBasis(op_input_fields[i], &basis)); 2161203703bSJeremy L Thompson CeedCheck(!*active_input_basis || *active_input_basis == basis, ceed, CEED_ERROR_MINOR, "Multiple active input CeedBases found"); 217*681d0ea7SJeremy L Thompson if (!*active_input_basis) CeedCall(CeedBasisReferenceCopy(basis, active_input_basis)); 218*681d0ea7SJeremy L Thompson CeedCall(CeedBasisDestroy(&basis)); 219eaf62fffSJeremy L Thompson } 220*681d0ea7SJeremy L Thompson CeedCall(CeedVectorDestroy(&vec)); 2212b730f8bSJeremy L Thompson } 222506b1a0cSSebastian Grimberg CeedCheck(*active_input_basis, ceed, 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)); 2361203703bSJeremy L Thompson CeedCheck(!*active_output_basis || *active_output_basis == basis, ceed, CEED_ERROR_MINOR, "Multiple active output CeedBases found"); 237*681d0ea7SJeremy L Thompson if (!*active_output_basis) CeedCall(CeedBasisReferenceCopy(basis, active_output_basis)); 238*681d0ea7SJeremy L Thompson CeedCall(CeedBasisDestroy(&basis)); 239506b1a0cSSebastian Grimberg } 240*681d0ea7SJeremy L Thompson CeedCall(CeedVectorDestroy(&vec)); 241506b1a0cSSebastian Grimberg } 242506b1a0cSSebastian Grimberg CeedCheck(*active_output_basis, ceed, CEED_ERROR_INCOMPLETE, "No active output CeedBasis found"); 243506b1a0cSSebastian Grimberg } 244506b1a0cSSebastian Grimberg } 245eaf62fffSJeremy L Thompson return CEED_ERROR_SUCCESS; 246eaf62fffSJeremy L Thompson } 247eaf62fffSJeremy L Thompson 248eaf62fffSJeremy L Thompson /** 249*681d0ea7SJeremy L Thompson @brief Find the active vector `CeedElemRestriction` for a non-composite `CeedOperator`. 250*681d0ea7SJeremy L Thompson 251*681d0ea7SJeremy L Thompson Note: Caller is responsible for destroying the `active_rstr` with @ref CeedElemRestrictionDestroy(). 252e2f04181SAndrew T. Barker 253ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to find active `CeedElemRestriction` for 254ca94c3ddSJeremy L Thompson @param[out] active_rstr `CeedElemRestriction` for active input vector or NULL for composite operator 255e2f04181SAndrew T. Barker 256e2f04181SAndrew T. Barker @return An error code: 0 - success, otherwise - failure 257e2f04181SAndrew T. Barker 258e2f04181SAndrew T. Barker @ref Utility 259e2f04181SAndrew T. Barker **/ 2602b730f8bSJeremy L Thompson int CeedOperatorGetActiveElemRestriction(CeedOperator op, CeedElemRestriction *active_rstr) { 261506b1a0cSSebastian Grimberg CeedCall(CeedOperatorGetActiveElemRestrictions(op, active_rstr, NULL)); 262506b1a0cSSebastian Grimberg return CEED_ERROR_SUCCESS; 263506b1a0cSSebastian Grimberg } 264506b1a0cSSebastian Grimberg 265506b1a0cSSebastian Grimberg /** 266*681d0ea7SJeremy L Thompson @brief Find the active input and output vector `CeedElemRestriction` for a non-composite `CeedOperator`. 267*681d0ea7SJeremy L Thompson 268*681d0ea7SJeremy L Thompson Note: Caller is responsible for destroying the restrictions with @ref CeedElemRestrictionDestroy(). 269506b1a0cSSebastian Grimberg 270ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to find active `CeedElemRestriction` for 271ca94c3ddSJeremy L Thompson @param[out] active_input_rstr `CeedElemRestriction` for active input vector or NULL for composite operator 272ca94c3ddSJeremy L Thompson @param[out] active_output_rstr `CeedElemRestriction` for active output vector or NULL for composite operator 273506b1a0cSSebastian Grimberg 274506b1a0cSSebastian Grimberg @return An error code: 0 - success, otherwise - failure 275506b1a0cSSebastian Grimberg 276506b1a0cSSebastian Grimberg @ref Utility 277506b1a0cSSebastian Grimberg **/ 278506b1a0cSSebastian Grimberg int CeedOperatorGetActiveElemRestrictions(CeedOperator op, CeedElemRestriction *active_input_rstr, CeedElemRestriction *active_output_rstr) { 2791203703bSJeremy L Thompson bool is_composite; 2801203703bSJeremy L Thompson CeedInt num_input_fields, num_output_fields; 2816aaed0edSJeremy L Thompson Ceed ceed; 2821203703bSJeremy L Thompson CeedOperatorField *op_input_fields, *op_output_fields; 2831c66c397SJeremy L Thompson 2846aaed0edSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 2851203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 2861203703bSJeremy L Thompson CeedCall(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields)); 2871203703bSJeremy L Thompson 288506b1a0cSSebastian Grimberg if (active_input_rstr) { 289506b1a0cSSebastian Grimberg *active_input_rstr = NULL; 2901203703bSJeremy L Thompson if (!is_composite) { 2911203703bSJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 2921203703bSJeremy L Thompson CeedVector vec; 2931203703bSJeremy L Thompson 2941203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(op_input_fields[i], &vec)); 2951203703bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 2961203703bSJeremy L Thompson CeedElemRestriction rstr; 2971203703bSJeremy L Thompson 2981203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetElemRestriction(op_input_fields[i], &rstr)); 2991203703bSJeremy L Thompson CeedCheck(!*active_input_rstr || *active_input_rstr == rstr, ceed, CEED_ERROR_MINOR, "Multiple active input CeedElemRestrictions found"); 300*681d0ea7SJeremy L Thompson if (!*active_input_rstr) CeedCall(CeedElemRestrictionReferenceCopy(rstr, active_input_rstr)); 301*681d0ea7SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&rstr)); 302e2f04181SAndrew T. Barker } 303*681d0ea7SJeremy L Thompson CeedCall(CeedVectorDestroy(&vec)); 3042b730f8bSJeremy L Thompson } 305506b1a0cSSebastian Grimberg CeedCheck(*active_input_rstr, ceed, 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)); 3191203703bSJeremy L Thompson CeedCheck(!*active_output_rstr || *active_output_rstr == rstr, ceed, CEED_ERROR_MINOR, "Multiple active output CeedElemRestrictions found"); 320*681d0ea7SJeremy L Thompson if (!*active_output_rstr) CeedCall(CeedElemRestrictionReferenceCopy(rstr, active_output_rstr)); 321*681d0ea7SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&rstr)); 322506b1a0cSSebastian Grimberg } 323*681d0ea7SJeremy L Thompson CeedCall(CeedVectorDestroy(&vec)); 324506b1a0cSSebastian Grimberg } 325506b1a0cSSebastian Grimberg CeedCheck(*active_output_rstr, ceed, CEED_ERROR_INCOMPLETE, "No active output CeedElemRestriction found"); 326506b1a0cSSebastian Grimberg } 327506b1a0cSSebastian Grimberg } 328e2f04181SAndrew T. Barker return CEED_ERROR_SUCCESS; 329e2f04181SAndrew T. Barker } 330e2f04181SAndrew T. Barker 331d8dd9a91SJeremy L Thompson /** 332ca94c3ddSJeremy L Thompson @brief Set `CeedQFunctionContext` field values of the specified type. 3334385fb7fSSebastian Grimberg 334ca94c3ddSJeremy L Thompson For composite operators, the value is set in all sub-operator `CeedQFunctionContext` that have a matching `field_name`. 335ca94c3ddSJeremy 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. 336d8dd9a91SJeremy L Thompson 337ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 338ea61e9acSJeremy L Thompson @param[in] field_label Label of field to set 339ea61e9acSJeremy L Thompson @param[in] field_type Type of field to set 3402788fa27SJeremy L Thompson @param[in] values Values to set 341d8dd9a91SJeremy L Thompson 342d8dd9a91SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 343d8dd9a91SJeremy L Thompson 344d8dd9a91SJeremy L Thompson @ref User 345d8dd9a91SJeremy L Thompson **/ 3462788fa27SJeremy L Thompson static int CeedOperatorContextSetGeneric(CeedOperator op, CeedContextFieldLabel field_label, CeedContextFieldType field_type, void *values) { 3471c66c397SJeremy L Thompson bool is_composite = false; 3481203703bSJeremy L Thompson Ceed ceed; 3491c66c397SJeremy L Thompson 3501203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 3511203703bSJeremy L Thompson CeedCheck(field_label, ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label"); 3523668ca4bSJeremy L Thompson 3535ac9af79SJeremy L Thompson // Check if field_label and op correspond 3545ac9af79SJeremy L Thompson if (field_label->from_op) { 3555ac9af79SJeremy L Thompson CeedInt index = -1; 3565ac9af79SJeremy L Thompson 3575ac9af79SJeremy L Thompson for (CeedInt i = 0; i < op->num_context_labels; i++) { 3585ac9af79SJeremy L Thompson if (op->context_labels[i] == field_label) index = i; 3595ac9af79SJeremy L Thompson } 3601203703bSJeremy L Thompson CeedCheck(index != -1, ceed, CEED_ERROR_UNSUPPORTED, "ContextFieldLabel does not correspond to the operator"); 3615ac9af79SJeremy L Thompson } 3625ac9af79SJeremy L Thompson 3632b730f8bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 364d8dd9a91SJeremy L Thompson if (is_composite) { 365d8dd9a91SJeremy L Thompson CeedInt num_sub; 366d8dd9a91SJeremy L Thompson CeedOperator *sub_operators; 367d8dd9a91SJeremy L Thompson 368c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub)); 369c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 3701203703bSJeremy L Thompson CeedCheck(num_sub == field_label->num_sub_labels, ceed, CEED_ERROR_UNSUPPORTED, "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)); 378d8dd9a91SJeremy L Thompson // Try every sub-operator, ok if some sub-operators do not have field 3791203703bSJeremy L Thompson if (field_label->sub_labels[i] && ctx) { 3801203703bSJeremy L Thompson CeedCall(CeedQFunctionContextSetGeneric(ctx, field_label->sub_labels[i], field_type, values)); 381d8dd9a91SJeremy L Thompson } 382d8dd9a91SJeremy L Thompson } 383d8dd9a91SJeremy L Thompson } else { 3841203703bSJeremy L Thompson CeedQFunction qf; 3851203703bSJeremy L Thompson CeedQFunctionContext ctx; 3861203703bSJeremy L Thompson 3871203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 3881203703bSJeremy L Thompson CeedCall(CeedQFunctionGetContext(qf, &ctx)); 3891203703bSJeremy L Thompson CeedCheck(ctx, ceed, CEED_ERROR_UNSUPPORTED, "QFunction does not have context data"); 3901203703bSJeremy L Thompson CeedCall(CeedQFunctionContextSetGeneric(ctx, field_label, field_type, values)); 3912788fa27SJeremy L Thompson } 3926d95ab46SJeremy L Thompson CeedCall(CeedOperatorSetQFunctionAssemblyDataUpdateNeeded(op, true)); 3932788fa27SJeremy L Thompson return CEED_ERROR_SUCCESS; 3942788fa27SJeremy L Thompson } 3952788fa27SJeremy L Thompson 3962788fa27SJeremy L Thompson /** 397ca94c3ddSJeremy L Thompson @brief Get `CeedQFunctionContext` field values of the specified type, read-only. 3984385fb7fSSebastian Grimberg 399ca94c3ddSJeremy L Thompson For composite operators, the values retrieved are for the first sub-operator `CeedQFunctionContext` that have a matching `field_name`. 400ca94c3ddSJeremy 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. 4012788fa27SJeremy L Thompson 402ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 4032788fa27SJeremy L Thompson @param[in] field_label Label of field to set 4042788fa27SJeremy L Thompson @param[in] field_type Type of field to set 405c5d0f995SJed Brown @param[out] num_values Number of values of type `field_type` in array `values` 406c5d0f995SJed Brown @param[out] values Values in the label 4072788fa27SJeremy L Thompson 4082788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 4092788fa27SJeremy L Thompson 4102788fa27SJeremy L Thompson @ref User 4112788fa27SJeremy L Thompson **/ 4122788fa27SJeremy L Thompson static int CeedOperatorContextGetGenericRead(CeedOperator op, CeedContextFieldLabel field_label, CeedContextFieldType field_type, size_t *num_values, 4132788fa27SJeremy L Thompson void *values) { 4141c66c397SJeremy L Thompson bool is_composite = false; 4151203703bSJeremy L Thompson Ceed ceed; 4161c66c397SJeremy L Thompson 4171203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 4181203703bSJeremy L Thompson CeedCheck(field_label, ceed, 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 } 4306e536b99SJeremy L Thompson CeedCheck(index != -1, ceed, 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)); 4401203703bSJeremy L Thompson CeedCheck(num_sub == field_label->num_sub_labels, ceed, CEED_ERROR_UNSUPPORTED, "Composite operator modified after ContextFieldLabel created"); 4412788fa27SJeremy L Thompson 4422788fa27SJeremy L Thompson for (CeedInt i = 0; i < num_sub; i++) { 4431203703bSJeremy L Thompson CeedQFunction qf; 4441203703bSJeremy L Thompson CeedQFunctionContext ctx; 4451203703bSJeremy L Thompson 4461203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(sub_operators[i], &qf)); 4471203703bSJeremy L Thompson CeedCall(CeedQFunctionGetContext(qf, &ctx)); 4482788fa27SJeremy L Thompson // Try every sub-operator, ok if some sub-operators do not have field 4491203703bSJeremy L Thompson if (field_label->sub_labels[i] && ctx) { 4501203703bSJeremy L Thompson CeedCall(CeedQFunctionContextGetGenericRead(ctx, field_label->sub_labels[i], field_type, num_values, values)); 4512788fa27SJeremy L Thompson return CEED_ERROR_SUCCESS; 4522788fa27SJeremy L Thompson } 4532788fa27SJeremy L Thompson } 4542788fa27SJeremy L Thompson } else { 4551203703bSJeremy L Thompson CeedQFunction qf; 4561203703bSJeremy L Thompson CeedQFunctionContext ctx; 4571203703bSJeremy L Thompson 4581203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 4591203703bSJeremy L Thompson CeedCall(CeedQFunctionGetContext(qf, &ctx)); 4601203703bSJeremy L Thompson CeedCheck(ctx, ceed, CEED_ERROR_UNSUPPORTED, "QFunction does not have context data"); 4611203703bSJeremy L Thompson CeedCall(CeedQFunctionContextGetGenericRead(ctx, field_label, field_type, num_values, values)); 4622788fa27SJeremy L Thompson } 4632788fa27SJeremy L Thompson return CEED_ERROR_SUCCESS; 4642788fa27SJeremy L Thompson } 4652788fa27SJeremy L Thompson 4662788fa27SJeremy L Thompson /** 467ca94c3ddSJeremy L Thompson @brief Restore `CeedQFunctionContext` field values of the specified type, read-only. 4684385fb7fSSebastian Grimberg 469ca94c3ddSJeremy L Thompson For composite operators, the values restored are for the first sub-operator `CeedQFunctionContext` that have a matching `field_name`. 470ca94c3ddSJeremy 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. 4712788fa27SJeremy L Thompson 472ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 4732788fa27SJeremy L Thompson @param[in] field_label Label of field to set 4742788fa27SJeremy L Thompson @param[in] field_type Type of field to set 475c5d0f995SJed Brown @param[in] values Values array to restore 4762788fa27SJeremy L Thompson 4772788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 4782788fa27SJeremy L Thompson 4792788fa27SJeremy L Thompson @ref User 4802788fa27SJeremy L Thompson **/ 4812788fa27SJeremy L Thompson static int CeedOperatorContextRestoreGenericRead(CeedOperator op, CeedContextFieldLabel field_label, CeedContextFieldType field_type, void *values) { 4821c66c397SJeremy L Thompson bool is_composite = false; 4831203703bSJeremy L Thompson Ceed ceed; 4841c66c397SJeremy L Thompson 4851203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 4861203703bSJeremy L Thompson CeedCheck(field_label, ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label"); 4872788fa27SJeremy L Thompson 4885ac9af79SJeremy L Thompson // Check if field_label and op correspond 4895ac9af79SJeremy L Thompson if (field_label->from_op) { 4905ac9af79SJeremy L Thompson CeedInt index = -1; 4915ac9af79SJeremy L Thompson 4925ac9af79SJeremy L Thompson for (CeedInt i = 0; i < op->num_context_labels; i++) { 4935ac9af79SJeremy L Thompson if (op->context_labels[i] == field_label) index = i; 4945ac9af79SJeremy L Thompson } 4956e536b99SJeremy L Thompson CeedCheck(index != -1, ceed, CEED_ERROR_UNSUPPORTED, "ContextFieldLabel does not correspond to the operator"); 4965ac9af79SJeremy L Thompson } 4975ac9af79SJeremy L Thompson 4982788fa27SJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 4992788fa27SJeremy L Thompson if (is_composite) { 5002788fa27SJeremy L Thompson CeedInt num_sub; 5012788fa27SJeremy L Thompson CeedOperator *sub_operators; 5022788fa27SJeremy L Thompson 5032788fa27SJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub)); 5042788fa27SJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 5056e536b99SJeremy L Thompson CeedCheck(num_sub == field_label->num_sub_labels, ceed, CEED_ERROR_UNSUPPORTED, "Composite operator modified after ContextFieldLabel created"); 5062788fa27SJeremy L Thompson 5072788fa27SJeremy L Thompson for (CeedInt i = 0; i < num_sub; i++) { 5081203703bSJeremy L Thompson CeedQFunction qf; 5091203703bSJeremy L Thompson CeedQFunctionContext ctx; 5101203703bSJeremy L Thompson 5111203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(sub_operators[i], &qf)); 5121203703bSJeremy L Thompson CeedCall(CeedQFunctionGetContext(qf, &ctx)); 5132788fa27SJeremy L Thompson // Try every sub-operator, ok if some sub-operators do not have field 5141203703bSJeremy L Thompson if (field_label->sub_labels[i] && ctx) { 5151203703bSJeremy L Thompson CeedCall(CeedQFunctionContextRestoreGenericRead(ctx, field_label->sub_labels[i], field_type, values)); 5162788fa27SJeremy L Thompson return CEED_ERROR_SUCCESS; 5172788fa27SJeremy L Thompson } 5182788fa27SJeremy L Thompson } 5192788fa27SJeremy L Thompson } else { 5201203703bSJeremy L Thompson CeedQFunction qf; 5211203703bSJeremy L Thompson CeedQFunctionContext ctx; 5221203703bSJeremy L Thompson 5231203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 5241203703bSJeremy L Thompson CeedCall(CeedQFunctionGetContext(qf, &ctx)); 5251203703bSJeremy L Thompson CeedCheck(ctx, ceed, CEED_ERROR_UNSUPPORTED, "QFunction does not have context data"); 5261203703bSJeremy L Thompson CeedCall(CeedQFunctionContextRestoreGenericRead(ctx, field_label, field_type, values)); 527d8dd9a91SJeremy L Thompson } 528d8dd9a91SJeremy L Thompson return CEED_ERROR_SUCCESS; 529d8dd9a91SJeremy L Thompson } 530d8dd9a91SJeremy L Thompson 5317a982d89SJeremy L. Thompson /// @} 5327a982d89SJeremy L. Thompson 5337a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 5347a982d89SJeremy L. Thompson /// CeedOperator Backend API 5357a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 5367a982d89SJeremy L. Thompson /// @addtogroup CeedOperatorBackend 5377a982d89SJeremy L. Thompson /// @{ 5387a982d89SJeremy L. Thompson 5397a982d89SJeremy L. Thompson /** 540ca94c3ddSJeremy L Thompson @brief Get the number of arguments associated with a `CeedOperator` 5417a982d89SJeremy L. Thompson 542ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 543d1d35e2fSjeremylt @param[out] num_args Variable to store vector number of arguments 5447a982d89SJeremy L. Thompson 5457a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 5467a982d89SJeremy L. Thompson 5477a982d89SJeremy L. Thompson @ref Backend 5487a982d89SJeremy L. Thompson **/ 549d1d35e2fSjeremylt int CeedOperatorGetNumArgs(CeedOperator op, CeedInt *num_args) { 5501203703bSJeremy L Thompson bool is_composite; 5511203703bSJeremy L Thompson 5521203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 5536e536b99SJeremy L Thompson CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Not defined for composite operators"); 554d1d35e2fSjeremylt *num_args = op->num_fields; 555e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 5567a982d89SJeremy L. Thompson } 5577a982d89SJeremy L. Thompson 5587a982d89SJeremy L. Thompson /** 5599463e855SJeremy L Thompson @brief Get the tensor product status of all bases for a `CeedOperator`. 5609463e855SJeremy L Thompson 5619463e855SJeremy L Thompson `has_tensor_bases` is only set to `true` if every field uses a tensor-product basis. 5629463e855SJeremy L Thompson 5639463e855SJeremy L Thompson @param[in] op `CeedOperator` 5649463e855SJeremy L Thompson @param[out] has_tensor_bases Variable to store tensor bases status 5659463e855SJeremy L Thompson 5669463e855SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 5679463e855SJeremy L Thompson 5689463e855SJeremy L Thompson @ref Backend 5699463e855SJeremy L Thompson **/ 5709463e855SJeremy L Thompson int CeedOperatorHasTensorBases(CeedOperator op, bool *has_tensor_bases) { 5719463e855SJeremy L Thompson CeedInt num_inputs, num_outputs; 5729463e855SJeremy L Thompson CeedOperatorField *input_fields, *output_fields; 5739463e855SJeremy L Thompson 5749463e855SJeremy L Thompson CeedCall(CeedOperatorGetFields(op, &num_inputs, &input_fields, &num_outputs, &output_fields)); 5759463e855SJeremy L Thompson *has_tensor_bases = true; 5769463e855SJeremy L Thompson for (CeedInt i = 0; i < num_inputs; i++) { 5779463e855SJeremy L Thompson bool is_tensor; 5789463e855SJeremy L Thompson CeedBasis basis; 5799463e855SJeremy L Thompson 5809463e855SJeremy L Thompson CeedCall(CeedOperatorFieldGetBasis(input_fields[i], &basis)); 5819463e855SJeremy L Thompson if (basis != CEED_BASIS_NONE) { 5829463e855SJeremy L Thompson CeedCall(CeedBasisIsTensor(basis, &is_tensor)); 5839463e855SJeremy L Thompson *has_tensor_bases &= is_tensor; 5849463e855SJeremy L Thompson } 585*681d0ea7SJeremy L Thompson CeedCall(CeedBasisDestroy(&basis)); 5869463e855SJeremy L Thompson } 5879463e855SJeremy L Thompson for (CeedInt i = 0; i < num_outputs; i++) { 5889463e855SJeremy L Thompson bool is_tensor; 5899463e855SJeremy L Thompson CeedBasis basis; 5909463e855SJeremy L Thompson 5919463e855SJeremy L Thompson CeedCall(CeedOperatorFieldGetBasis(output_fields[i], &basis)); 5929463e855SJeremy L Thompson if (basis != CEED_BASIS_NONE) { 5939463e855SJeremy L Thompson CeedCall(CeedBasisIsTensor(basis, &is_tensor)); 5949463e855SJeremy L Thompson *has_tensor_bases &= is_tensor; 5959463e855SJeremy L Thompson } 596*681d0ea7SJeremy L Thompson CeedCall(CeedBasisDestroy(&basis)); 5979463e855SJeremy L Thompson } 5989463e855SJeremy L Thompson return CEED_ERROR_SUCCESS; 5999463e855SJeremy L Thompson } 6009463e855SJeremy L Thompson 6019463e855SJeremy L Thompson /** 6021203703bSJeremy L Thompson @brief Get a boolean value indicating if the `CeedOperator` is immutable 6031203703bSJeremy L Thompson 6041203703bSJeremy L Thompson @param[in] op `CeedOperator` 6051203703bSJeremy L Thompson @param[out] is_immutable Variable to store immutability status 6061203703bSJeremy L Thompson 6071203703bSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 6081203703bSJeremy L Thompson 6091203703bSJeremy L Thompson @ref Backend 6101203703bSJeremy L Thompson **/ 6111203703bSJeremy L Thompson int CeedOperatorIsImmutable(CeedOperator op, bool *is_immutable) { 6121203703bSJeremy L Thompson *is_immutable = op->is_immutable; 6131203703bSJeremy L Thompson return CEED_ERROR_SUCCESS; 6141203703bSJeremy L Thompson } 6151203703bSJeremy L Thompson 6161203703bSJeremy L Thompson /** 617ca94c3ddSJeremy L Thompson @brief Get the setup status of a `CeedOperator` 6187a982d89SJeremy L. Thompson 619ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 620d1d35e2fSjeremylt @param[out] is_setup_done Variable to store setup status 6217a982d89SJeremy L. Thompson 6227a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 6237a982d89SJeremy L. Thompson 6247a982d89SJeremy L. Thompson @ref Backend 6257a982d89SJeremy L. Thompson **/ 626d1d35e2fSjeremylt int CeedOperatorIsSetupDone(CeedOperator op, bool *is_setup_done) { 627f04ea552SJeremy L Thompson *is_setup_done = op->is_backend_setup; 628e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 6297a982d89SJeremy L. Thompson } 6307a982d89SJeremy L. Thompson 6317a982d89SJeremy L. Thompson /** 632ca94c3ddSJeremy L Thompson @brief Get the `CeedQFunction` associated with a `CeedOperator` 6337a982d89SJeremy L. Thompson 634ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 635ca94c3ddSJeremy L Thompson @param[out] qf Variable to store `CeedQFunction` 6367a982d89SJeremy L. Thompson 6377a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 6387a982d89SJeremy L. Thompson 6397a982d89SJeremy L. Thompson @ref Backend 6407a982d89SJeremy L. Thompson **/ 6417a982d89SJeremy L. Thompson int CeedOperatorGetQFunction(CeedOperator op, CeedQFunction *qf) { 6421203703bSJeremy L Thompson bool is_composite; 6431203703bSJeremy L Thompson 6441203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 6456e536b99SJeremy L Thompson CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Not defined for composite operator"); 6467a982d89SJeremy L. Thompson *qf = op->qf; 647e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 6487a982d89SJeremy L. Thompson } 6497a982d89SJeremy L. Thompson 6507a982d89SJeremy L. Thompson /** 651ca94c3ddSJeremy L Thompson @brief Get a boolean value indicating if the `CeedOperator` is composite 652c04a41a7SJeremy L Thompson 653ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 654d1d35e2fSjeremylt @param[out] is_composite Variable to store composite status 655c04a41a7SJeremy L Thompson 656c04a41a7SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 657c04a41a7SJeremy L Thompson 658c04a41a7SJeremy L Thompson @ref Backend 659c04a41a7SJeremy L Thompson **/ 660d1d35e2fSjeremylt int CeedOperatorIsComposite(CeedOperator op, bool *is_composite) { 661f04ea552SJeremy L Thompson *is_composite = op->is_composite; 662e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 663c04a41a7SJeremy L Thompson } 664c04a41a7SJeremy L Thompson 665c04a41a7SJeremy L Thompson /** 666ca94c3ddSJeremy L Thompson @brief Get the backend data of a `CeedOperator` 6677a982d89SJeremy L. Thompson 668ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 6697a982d89SJeremy L. Thompson @param[out] data Variable to store data 6707a982d89SJeremy L. Thompson 6717a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 6727a982d89SJeremy L. Thompson 6737a982d89SJeremy L. Thompson @ref Backend 6747a982d89SJeremy L. Thompson **/ 675777ff853SJeremy L Thompson int CeedOperatorGetData(CeedOperator op, void *data) { 676777ff853SJeremy L Thompson *(void **)data = op->data; 677e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 6787a982d89SJeremy L. Thompson } 6797a982d89SJeremy L. Thompson 6807a982d89SJeremy L. Thompson /** 681ca94c3ddSJeremy L Thompson @brief Set the backend data of a `CeedOperator` 6827a982d89SJeremy L. Thompson 683ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 684ea61e9acSJeremy L Thompson @param[in] data Data to set 6857a982d89SJeremy L. Thompson 6867a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 6877a982d89SJeremy L. Thompson 6887a982d89SJeremy L. Thompson @ref Backend 6897a982d89SJeremy L. Thompson **/ 690777ff853SJeremy L Thompson int CeedOperatorSetData(CeedOperator op, void *data) { 691777ff853SJeremy L Thompson op->data = data; 692e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 6937a982d89SJeremy L. Thompson } 6947a982d89SJeremy L. Thompson 6957a982d89SJeremy L. Thompson /** 696ca94c3ddSJeremy L Thompson @brief Increment the reference counter for a `CeedOperator` 69734359f16Sjeremylt 698ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` to increment the reference counter 69934359f16Sjeremylt 70034359f16Sjeremylt @return An error code: 0 - success, otherwise - failure 70134359f16Sjeremylt 70234359f16Sjeremylt @ref Backend 70334359f16Sjeremylt **/ 7049560d06aSjeremylt int CeedOperatorReference(CeedOperator op) { 70534359f16Sjeremylt op->ref_count++; 70634359f16Sjeremylt return CEED_ERROR_SUCCESS; 70734359f16Sjeremylt } 70834359f16Sjeremylt 70934359f16Sjeremylt /** 710ca94c3ddSJeremy L Thompson @brief Set the setup flag of a `CeedOperator` to `true` 7117a982d89SJeremy L. Thompson 712ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 7137a982d89SJeremy L. Thompson 7147a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 7157a982d89SJeremy L. Thompson 7167a982d89SJeremy L. Thompson @ref Backend 7177a982d89SJeremy L. Thompson **/ 7187a982d89SJeremy L. Thompson int CeedOperatorSetSetupDone(CeedOperator op) { 719f04ea552SJeremy L Thompson op->is_backend_setup = true; 720e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 7217a982d89SJeremy L. Thompson } 7227a982d89SJeremy L. Thompson 7237a982d89SJeremy L. Thompson /// @} 7247a982d89SJeremy L. Thompson 7257a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 7267a982d89SJeremy L. Thompson /// CeedOperator Public API 7277a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 7287a982d89SJeremy L. Thompson /// @addtogroup CeedOperatorUser 729dfdf5a53Sjeremylt /// @{ 730d7b241e6Sjeremylt 731d7b241e6Sjeremylt /** 732ca94c3ddSJeremy L Thompson @brief Create a `CeedOperator` and associate a `CeedQFunction`. 7334385fb7fSSebastian Grimberg 734ca94c3ddSJeremy L Thompson A `CeedBasis` and `CeedElemRestriction` can be associated with `CeedQFunction` fields with @ref CeedOperatorSetField(). 735d7b241e6Sjeremylt 736ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` object used to create the `CeedOperator` 737ca94c3ddSJeremy L Thompson @param[in] qf `CeedQFunction` defining the action of the operator at quadrature points 738ca94c3ddSJeremy L Thompson @param[in] dqf `CeedQFunction` defining the action of the Jacobian of `qf` (or @ref CEED_QFUNCTION_NONE) 739ca94c3ddSJeremy L Thompson @param[in] dqfT `CeedQFunction` defining the action of the transpose of the Jacobian of `qf` (or @ref CEED_QFUNCTION_NONE) 740ca94c3ddSJeremy L Thompson @param[out] op Address of the variable where the newly created `CeedOperator` will be stored 741b11c1e72Sjeremylt 742b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 743dfdf5a53Sjeremylt 7447a982d89SJeremy L. Thompson @ref User 745d7b241e6Sjeremylt */ 7462b730f8bSJeremy L Thompson int CeedOperatorCreate(Ceed ceed, CeedQFunction qf, CeedQFunction dqf, CeedQFunction dqfT, CeedOperator *op) { 7475fe0d4faSjeremylt if (!ceed->OperatorCreate) { 7485fe0d4faSjeremylt Ceed delegate; 7496574a04fSJeremy L Thompson 7502b730f8bSJeremy L Thompson CeedCall(CeedGetObjectDelegate(ceed, &delegate, "Operator")); 7511ef3a2a9SJeremy L Thompson CeedCheck(delegate, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not implement CeedOperatorCreate"); 7522b730f8bSJeremy L Thompson CeedCall(CeedOperatorCreate(delegate, qf, dqf, dqfT, op)); 753e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 7545fe0d4faSjeremylt } 7555fe0d4faSjeremylt 756ca94c3ddSJeremy L Thompson CeedCheck(qf && qf != CEED_QFUNCTION_NONE, ceed, CEED_ERROR_MINOR, "Operator must have a valid CeedQFunction."); 757db002c03SJeremy L Thompson 7582b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, op)); 759db002c03SJeremy L Thompson CeedCall(CeedReferenceCopy(ceed, &(*op)->ceed)); 760d1d35e2fSjeremylt (*op)->ref_count = 1; 7612b104005SJeremy L Thompson (*op)->input_size = -1; 7622b104005SJeremy L Thompson (*op)->output_size = -1; 763db002c03SJeremy L Thompson CeedCall(CeedQFunctionReferenceCopy(qf, &(*op)->qf)); 764db002c03SJeremy L Thompson if (dqf && dqf != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionReferenceCopy(dqf, &(*op)->dqf)); 765db002c03SJeremy L Thompson if (dqfT && dqfT != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionReferenceCopy(dqfT, &(*op)->dqfT)); 7662b730f8bSJeremy L Thompson CeedCall(CeedCalloc(CEED_FIELD_MAX, &(*op)->input_fields)); 7672b730f8bSJeremy L Thompson CeedCall(CeedCalloc(CEED_FIELD_MAX, &(*op)->output_fields)); 7682b730f8bSJeremy L Thompson CeedCall(ceed->OperatorCreate(*op)); 769e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 770d7b241e6Sjeremylt } 771d7b241e6Sjeremylt 772d7b241e6Sjeremylt /** 773ca94c3ddSJeremy L Thompson @brief Create a `CeedOperator` for evaluation at evaluation at arbitrary points in each element. 77448acf710SJeremy L Thompson 775ca94c3ddSJeremy L Thompson A `CeedBasis` and `CeedElemRestriction` can be associated with `CeedQFunction` fields with `CeedOperator` SetField. 776ca94c3ddSJeremy L Thompson The locations of each point are set with @ref CeedOperatorAtPointsSetPoints(). 77748acf710SJeremy L Thompson 778ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` object used to create the `CeedOperator` 779ca94c3ddSJeremy L Thompson @param[in] qf `CeedQFunction` defining the action of the operator at quadrature points 780ca94c3ddSJeremy L Thompson @param[in] dqf `CeedQFunction` defining the action of the Jacobian of @a qf (or @ref CEED_QFUNCTION_NONE) 781ca94c3ddSJeremy L Thompson @param[in] dqfT `CeedQFunction` defining the action of the transpose of the Jacobian of @a qf (or @ref CEED_QFUNCTION_NONE) 78248acf710SJeremy L Thompson @param[out] op Address of the variable where the newly created CeedOperator will be stored 78348acf710SJeremy L Thompson 78448acf710SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 78548acf710SJeremy L Thompson 78648acf710SJeremy L Thompson @ref User 78748acf710SJeremy L Thompson */ 78848acf710SJeremy L Thompson int CeedOperatorCreateAtPoints(Ceed ceed, CeedQFunction qf, CeedQFunction dqf, CeedQFunction dqfT, CeedOperator *op) { 78948acf710SJeremy L Thompson if (!ceed->OperatorCreateAtPoints) { 79048acf710SJeremy L Thompson Ceed delegate; 79148acf710SJeremy L Thompson 79248acf710SJeremy L Thompson CeedCall(CeedGetObjectDelegate(ceed, &delegate, "Operator")); 7931ef3a2a9SJeremy L Thompson CeedCheck(delegate, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not implement CeedOperatorCreateAtPoints"); 79448acf710SJeremy L Thompson CeedCall(CeedOperatorCreateAtPoints(delegate, qf, dqf, dqfT, op)); 79548acf710SJeremy L Thompson return CEED_ERROR_SUCCESS; 79648acf710SJeremy L Thompson } 79748acf710SJeremy L Thompson 798ca94c3ddSJeremy L Thompson CeedCheck(qf && qf != CEED_QFUNCTION_NONE, ceed, CEED_ERROR_MINOR, "Operator must have a valid CeedQFunction."); 79948acf710SJeremy L Thompson 80048acf710SJeremy L Thompson CeedCall(CeedCalloc(1, op)); 80148acf710SJeremy L Thompson CeedCall(CeedReferenceCopy(ceed, &(*op)->ceed)); 80248acf710SJeremy L Thompson (*op)->ref_count = 1; 80348acf710SJeremy L Thompson (*op)->is_at_points = true; 80448acf710SJeremy L Thompson (*op)->input_size = -1; 80548acf710SJeremy L Thompson (*op)->output_size = -1; 80648acf710SJeremy L Thompson CeedCall(CeedQFunctionReferenceCopy(qf, &(*op)->qf)); 80748acf710SJeremy L Thompson if (dqf && dqf != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionReferenceCopy(dqf, &(*op)->dqf)); 80848acf710SJeremy L Thompson if (dqfT && dqfT != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionReferenceCopy(dqfT, &(*op)->dqfT)); 80948acf710SJeremy L Thompson CeedCall(CeedCalloc(CEED_FIELD_MAX, &(*op)->input_fields)); 81048acf710SJeremy L Thompson CeedCall(CeedCalloc(CEED_FIELD_MAX, &(*op)->output_fields)); 81148acf710SJeremy L Thompson CeedCall(ceed->OperatorCreateAtPoints(*op)); 81248acf710SJeremy L Thompson return CEED_ERROR_SUCCESS; 81348acf710SJeremy L Thompson } 81448acf710SJeremy L Thompson 81548acf710SJeremy L Thompson /** 816ca94c3ddSJeremy L Thompson @brief Create a composite `CeedOperator` that composes the action of several `CeedOperator` 81752d6035fSJeremy L Thompson 818ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` object used to create the `CeedOperator` 819ca94c3ddSJeremy L Thompson @param[out] op Address of the variable where the newly created composite `CeedOperator` will be stored 82052d6035fSJeremy L Thompson 82152d6035fSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 82252d6035fSJeremy L Thompson 8237a982d89SJeremy L. Thompson @ref User 82452d6035fSJeremy L Thompson */ 82552d6035fSJeremy L Thompson int CeedCompositeOperatorCreate(Ceed ceed, CeedOperator *op) { 82652d6035fSJeremy L Thompson if (!ceed->CompositeOperatorCreate) { 82752d6035fSJeremy L Thompson Ceed delegate; 82852d6035fSJeremy L Thompson 8291c66c397SJeremy L Thompson CeedCall(CeedGetObjectDelegate(ceed, &delegate, "Operator")); 830250756a7Sjeremylt if (delegate) { 8312b730f8bSJeremy L Thompson CeedCall(CeedCompositeOperatorCreate(delegate, op)); 832e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 83352d6035fSJeremy L Thompson } 834250756a7Sjeremylt } 83552d6035fSJeremy L Thompson 8362b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, op)); 837db002c03SJeremy L Thompson CeedCall(CeedReferenceCopy(ceed, &(*op)->ceed)); 838996d9ab5SJed Brown (*op)->ref_count = 1; 839f04ea552SJeremy L Thompson (*op)->is_composite = true; 8402b730f8bSJeremy L Thompson CeedCall(CeedCalloc(CEED_COMPOSITE_MAX, &(*op)->sub_operators)); 8412b104005SJeremy L Thompson (*op)->input_size = -1; 8422b104005SJeremy L Thompson (*op)->output_size = -1; 843250756a7Sjeremylt 844db002c03SJeremy L Thompson if (ceed->CompositeOperatorCreate) CeedCall(ceed->CompositeOperatorCreate(*op)); 845e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 84652d6035fSJeremy L Thompson } 84752d6035fSJeremy L Thompson 84852d6035fSJeremy L Thompson /** 849ca94c3ddSJeremy L Thompson @brief Copy the pointer to a `CeedOperator`. 8504385fb7fSSebastian Grimberg 851ca94c3ddSJeremy L Thompson Both pointers should be destroyed with @ref CeedOperatorDestroy(). 852512bb800SJeremy L Thompson 853ca94c3ddSJeremy 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`. 854ca94c3ddSJeremy L Thompson This `CeedOperator` will be destroyed if `*op_copy` is the only reference to this `CeedOperator`. 8559560d06aSjeremylt 856ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to copy reference to 857ea61e9acSJeremy L Thompson @param[in,out] op_copy Variable to store copied reference 8589560d06aSjeremylt 8599560d06aSjeremylt @return An error code: 0 - success, otherwise - failure 8609560d06aSjeremylt 8619560d06aSjeremylt @ref User 8629560d06aSjeremylt **/ 8639560d06aSjeremylt int CeedOperatorReferenceCopy(CeedOperator op, CeedOperator *op_copy) { 8642b730f8bSJeremy L Thompson CeedCall(CeedOperatorReference(op)); 8652b730f8bSJeremy L Thompson CeedCall(CeedOperatorDestroy(op_copy)); 8669560d06aSjeremylt *op_copy = op; 8679560d06aSjeremylt return CEED_ERROR_SUCCESS; 8689560d06aSjeremylt } 8699560d06aSjeremylt 8709560d06aSjeremylt /** 871ca94c3ddSJeremy L Thompson @brief Provide a field to a `CeedOperator` for use by its `CeedQFunction`. 872d7b241e6Sjeremylt 873ca94c3ddSJeremy L Thompson This function is used to specify both active and passive fields to a `CeedOperator`. 874bafebce1SSebastian Grimberg For passive fields, a `CeedVector` `vec` must be provided. 875ea61e9acSJeremy L Thompson Passive fields can inputs or outputs (updated in-place when operator is applied). 876d7b241e6Sjeremylt 877ca94c3ddSJeremy L Thompson Active fields must be specified using this function, but their data (in a `CeedVector`) is passed in @ref CeedOperatorApply(). 878ca94c3ddSJeremy L Thompson There can be at most one active input `CeedVector` and at most one active output@ref CeedVector passed to @ref CeedOperatorApply(). 879d7b241e6Sjeremylt 880528a22edSJeremy L Thompson The number of quadrature points must agree across all points. 881bafebce1SSebastian Grimberg When using @ref CEED_BASIS_NONE, the number of quadrature points is determined by the element size of `rstr`. 882528a22edSJeremy L Thompson 883ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` on which to provide the field 884ca94c3ddSJeremy L Thompson @param[in] field_name Name of the field (to be matched with the name used by `CeedQFunction`) 885bafebce1SSebastian Grimberg @param[in] rstr `CeedElemRestriction` 886bafebce1SSebastian Grimberg @param[in] basis `CeedBasis` in which the field resides or @ref CEED_BASIS_NONE if collocated with quadrature points 887bafebce1SSebastian 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` 888b11c1e72Sjeremylt 889b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 890dfdf5a53Sjeremylt 8917a982d89SJeremy L. Thompson @ref User 892b11c1e72Sjeremylt **/ 893bafebce1SSebastian Grimberg int CeedOperatorSetField(CeedOperator op, const char *field_name, CeedElemRestriction rstr, CeedBasis basis, CeedVector vec) { 8941203703bSJeremy L Thompson bool is_input = true, is_at_points, is_composite, is_immutable; 8951203703bSJeremy L Thompson CeedInt num_elem = 0, num_qpts = 0, num_input_fields, num_output_fields; 8961203703bSJeremy L Thompson Ceed ceed; 8971203703bSJeremy L Thompson CeedQFunction qf; 8981203703bSJeremy L Thompson CeedQFunctionField qf_field, *qf_input_fields, *qf_output_fields; 8991c66c397SJeremy L Thompson CeedOperatorField *op_field; 9001c66c397SJeremy L Thompson 9011203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 9021203703bSJeremy L Thompson CeedCall(CeedOperatorIsAtPoints(op, &is_at_points)); 9031203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 9041203703bSJeremy L Thompson CeedCall(CeedOperatorIsImmutable(op, &is_immutable)); 9051203703bSJeremy L Thompson CeedCheck(!is_composite, ceed, CEED_ERROR_INCOMPATIBLE, "Cannot add field to composite operator."); 9061203703bSJeremy L Thompson CeedCheck(!is_immutable, ceed, CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable"); 9071203703bSJeremy L Thompson CeedCheck(rstr, ceed, CEED_ERROR_INCOMPATIBLE, "CeedElemRestriction rstr for field \"%s\" must be non-NULL.", field_name); 9081203703bSJeremy L Thompson CeedCheck(basis, ceed, CEED_ERROR_INCOMPATIBLE, "CeedBasis basis for field \"%s\" must be non-NULL.", field_name); 9091203703bSJeremy L Thompson CeedCheck(vec, ceed, CEED_ERROR_INCOMPATIBLE, "CeedVector vec for field \"%s\" must be non-NULL.", field_name); 91052d6035fSJeremy L Thompson 911bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionGetNumElements(rstr, &num_elem)); 9121203703bSJeremy L Thompson CeedCheck(rstr == CEED_ELEMRESTRICTION_NONE || !op->has_restriction || num_elem == op->num_elem, ceed, CEED_ERROR_DIMENSION, 913ca94c3ddSJeremy L Thompson "CeedElemRestriction with %" CeedInt_FMT " elements incompatible with prior %" CeedInt_FMT " elements", num_elem, op->num_elem); 9142c7e7413SJeremy L Thompson { 9152c7e7413SJeremy L Thompson CeedRestrictionType rstr_type; 9162c7e7413SJeremy L Thompson 917bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionGetType(rstr, &rstr_type)); 91848acf710SJeremy L Thompson if (rstr_type == CEED_RESTRICTION_POINTS) { 9191203703bSJeremy L Thompson CeedCheck(is_at_points, ceed, CEED_ERROR_UNSUPPORTED, "CeedElemRestriction AtPoints not supported for standard operator fields"); 9201203703bSJeremy L Thompson CeedCheck(basis == CEED_BASIS_NONE, ceed, CEED_ERROR_UNSUPPORTED, "CeedElemRestriction AtPoints must be used with CEED_BASIS_NONE"); 92148acf710SJeremy L Thompson if (!op->first_points_rstr) { 922bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionReferenceCopy(rstr, &op->first_points_rstr)); 92348acf710SJeremy L Thompson } else { 92448acf710SJeremy L Thompson bool are_compatible; 92548acf710SJeremy L Thompson 926bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionAtPointsAreCompatible(op->first_points_rstr, rstr, &are_compatible)); 9271203703bSJeremy L Thompson CeedCheck(are_compatible, ceed, CEED_ERROR_INCOMPATIBLE, 928ca94c3ddSJeremy L Thompson "CeedElemRestriction must have compatible offsets with previously set CeedElemRestriction"); 92948acf710SJeremy L Thompson } 93048acf710SJeremy L Thompson } 9312c7e7413SJeremy L Thompson } 932d7b241e6Sjeremylt 933bafebce1SSebastian Grimberg if (basis == CEED_BASIS_NONE) CeedCall(CeedElemRestrictionGetElementSize(rstr, &num_qpts)); 934bafebce1SSebastian Grimberg else CeedCall(CeedBasisGetNumQuadraturePoints(basis, &num_qpts)); 9351203703bSJeremy L Thompson CeedCheck(op->num_qpts == 0 || num_qpts == op->num_qpts, ceed, CEED_ERROR_DIMENSION, 936ca94c3ddSJeremy L Thompson "%s must correspond to the same number of quadrature points as previously added CeedBases. Found %" CeedInt_FMT 937528a22edSJeremy L Thompson " quadrature points but expected %" CeedInt_FMT " quadrature points.", 938bafebce1SSebastian Grimberg basis == CEED_BASIS_NONE ? "CeedElemRestriction" : "CeedBasis", num_qpts, op->num_qpts); 9391203703bSJeremy L Thompson 9401203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 9411203703bSJeremy L Thompson CeedCall(CeedQFunctionGetFields(qf, &num_input_fields, &qf_input_fields, &num_output_fields, &qf_output_fields)); 9421203703bSJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 9436f8994e9SJeremy L Thompson const char *qf_field_name; 9441203703bSJeremy L Thompson 9451203703bSJeremy L Thompson CeedCall(CeedQFunctionFieldGetName(qf_input_fields[i], &qf_field_name)); 9461203703bSJeremy L Thompson if (!strcmp(field_name, qf_field_name)) { 9471203703bSJeremy L Thompson qf_field = qf_input_fields[i]; 948d1d35e2fSjeremylt op_field = &op->input_fields[i]; 949d7b241e6Sjeremylt goto found; 950d7b241e6Sjeremylt } 951d7b241e6Sjeremylt } 9522b104005SJeremy L Thompson is_input = false; 9531203703bSJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 9546f8994e9SJeremy L Thompson const char *qf_field_name; 9551203703bSJeremy L Thompson 9561203703bSJeremy L Thompson CeedCall(CeedQFunctionFieldGetName(qf_output_fields[i], &qf_field_name)); 9571203703bSJeremy L Thompson if (!strcmp(field_name, qf_field_name)) { 9581203703bSJeremy L Thompson qf_field = qf_output_fields[i]; 959d1d35e2fSjeremylt op_field = &op->output_fields[i]; 960d7b241e6Sjeremylt goto found; 961d7b241e6Sjeremylt } 962d7b241e6Sjeremylt } 963c042f62fSJeremy L Thompson // LCOV_EXCL_START 9641203703bSJeremy L Thompson return CeedError(ceed, CEED_ERROR_INCOMPLETE, "CeedQFunction has no knowledge of field '%s'", field_name); 965c042f62fSJeremy L Thompson // LCOV_EXCL_STOP 966d7b241e6Sjeremylt found: 9671203703bSJeremy L Thompson CeedCall(CeedOperatorCheckField(ceed, qf_field, rstr, basis)); 9682b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, op_field)); 969e15f9bd0SJeremy L Thompson 970bafebce1SSebastian Grimberg if (vec == CEED_VECTOR_ACTIVE) { 9712b104005SJeremy L Thompson CeedSize l_size; 9721c66c397SJeremy L Thompson 973bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionGetLVectorSize(rstr, &l_size)); 9742b104005SJeremy L Thompson if (is_input) { 9752b104005SJeremy L Thompson if (op->input_size == -1) op->input_size = l_size; 9761203703bSJeremy L Thompson CeedCheck(l_size == op->input_size, ceed, CEED_ERROR_INCOMPATIBLE, 977249f8407SJeremy L Thompson "LVector size %" CeedSize_FMT " does not match previous size %" CeedSize_FMT "", l_size, op->input_size); 9782b104005SJeremy L Thompson } else { 9792b104005SJeremy L Thompson if (op->output_size == -1) op->output_size = l_size; 9801203703bSJeremy L Thompson CeedCheck(l_size == op->output_size, ceed, CEED_ERROR_INCOMPATIBLE, 981249f8407SJeremy L Thompson "LVector size %" CeedSize_FMT " does not match previous size %" CeedSize_FMT "", l_size, op->output_size); 9822b104005SJeremy L Thompson } 9832b730f8bSJeremy L Thompson } 9842b104005SJeremy L Thompson 985bafebce1SSebastian Grimberg CeedCall(CeedVectorReferenceCopy(vec, &(*op_field)->vec)); 986bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionReferenceCopy(rstr, &(*op_field)->elem_rstr)); 987bafebce1SSebastian Grimberg if (rstr != CEED_ELEMRESTRICTION_NONE && !op->has_restriction) { 988d1d35e2fSjeremylt op->num_elem = num_elem; 989d1d35e2fSjeremylt op->has_restriction = true; // Restriction set, but num_elem may be 0 990e15f9bd0SJeremy L Thompson } 991bafebce1SSebastian Grimberg CeedCall(CeedBasisReferenceCopy(basis, &(*op_field)->basis)); 9922a3ff1c9SZach Atkins if (op->num_qpts == 0 && !is_at_points) op->num_qpts = num_qpts; // no consistent number of qpts for OperatorAtPoints 993d1d35e2fSjeremylt op->num_fields += 1; 9942b730f8bSJeremy L Thompson CeedCall(CeedStringAllocCopy(field_name, (char **)&(*op_field)->field_name)); 995e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 996d7b241e6Sjeremylt } 997d7b241e6Sjeremylt 998d7b241e6Sjeremylt /** 999ca94c3ddSJeremy L Thompson @brief Get the `CeedOperator` Field of a `CeedOperator`. 100043bbe138SJeremy L Thompson 1001ca94c3ddSJeremy L Thompson Note: Calling this function asserts that setup is complete and sets the `CeedOperator` as immutable. 1002f04ea552SJeremy L Thompson 1003ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1004f74ec584SJeremy L Thompson @param[out] num_input_fields Variable to store number of input fields 1005ca94c3ddSJeremy L Thompson @param[out] input_fields Variable to store input fields 1006f74ec584SJeremy L Thompson @param[out] num_output_fields Variable to store number of output fields 1007ca94c3ddSJeremy L Thompson @param[out] output_fields Variable to store output fields 100843bbe138SJeremy L Thompson 100943bbe138SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 101043bbe138SJeremy L Thompson 1011e9b533fbSJeremy L Thompson @ref Advanced 101243bbe138SJeremy L Thompson **/ 10132b730f8bSJeremy L Thompson int CeedOperatorGetFields(CeedOperator op, CeedInt *num_input_fields, CeedOperatorField **input_fields, CeedInt *num_output_fields, 101443bbe138SJeremy L Thompson CeedOperatorField **output_fields) { 10151203703bSJeremy L Thompson bool is_composite; 10161203703bSJeremy L Thompson CeedQFunction qf; 10171203703bSJeremy L Thompson 10181203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 10196e536b99SJeremy L Thompson CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Not defined for composite operator"); 10202b730f8bSJeremy L Thompson CeedCall(CeedOperatorCheckReady(op)); 102143bbe138SJeremy L Thompson 10221203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 10231203703bSJeremy L Thompson CeedCall(CeedQFunctionGetFields(qf, num_input_fields, NULL, num_output_fields, NULL)); 102443bbe138SJeremy L Thompson if (input_fields) *input_fields = op->input_fields; 102543bbe138SJeremy L Thompson if (output_fields) *output_fields = op->output_fields; 102643bbe138SJeremy L Thompson return CEED_ERROR_SUCCESS; 102743bbe138SJeremy L Thompson } 102843bbe138SJeremy L Thompson 102943bbe138SJeremy L Thompson /** 1030ca94c3ddSJeremy L Thompson @brief Set the arbitrary points in each element for a `CeedOperator` at points. 103148acf710SJeremy L Thompson 1032ca94c3ddSJeremy L Thompson Note: Calling this function asserts that setup is complete and sets the `CeedOperator` as immutable. 103348acf710SJeremy L Thompson 1034ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` at points 1035ca94c3ddSJeremy L Thompson @param[in] rstr_points `CeedElemRestriction` for the coordinates of each point by element 1036ca94c3ddSJeremy L Thompson @param[in] point_coords `CeedVector` holding coordinates of each point 103748acf710SJeremy L Thompson 103848acf710SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 103948acf710SJeremy L Thompson 104048acf710SJeremy L Thompson @ref Advanced 104148acf710SJeremy L Thompson **/ 104248acf710SJeremy L Thompson int CeedOperatorAtPointsSetPoints(CeedOperator op, CeedElemRestriction rstr_points, CeedVector point_coords) { 10431203703bSJeremy L Thompson bool is_at_points, is_immutable; 10441203703bSJeremy L Thompson Ceed ceed; 10452a3ff1c9SZach Atkins 10461203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 10472a3ff1c9SZach Atkins CeedCall(CeedOperatorIsAtPoints(op, &is_at_points)); 10481203703bSJeremy L Thompson CeedCall(CeedOperatorIsImmutable(op, &is_immutable)); 10491203703bSJeremy L Thompson CeedCheck(is_at_points, ceed, CEED_ERROR_MINOR, "Only defined for operator at points"); 10501203703bSJeremy L Thompson CeedCheck(!is_immutable, ceed, CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable"); 105148acf710SJeremy L Thompson 105248acf710SJeremy L Thompson if (!op->first_points_rstr) { 105348acf710SJeremy L Thompson CeedCall(CeedElemRestrictionReferenceCopy(rstr_points, &op->first_points_rstr)); 105448acf710SJeremy L Thompson } else { 105548acf710SJeremy L Thompson bool are_compatible; 105648acf710SJeremy L Thompson 105748acf710SJeremy L Thompson CeedCall(CeedElemRestrictionAtPointsAreCompatible(op->first_points_rstr, rstr_points, &are_compatible)); 10581203703bSJeremy L Thompson CeedCheck(are_compatible, ceed, CEED_ERROR_INCOMPATIBLE, 1059ca94c3ddSJeremy L Thompson "CeedElemRestriction must have compatible offsets with previously set field CeedElemRestriction"); 106048acf710SJeremy L Thompson } 106148acf710SJeremy L Thompson 106248acf710SJeremy L Thompson CeedCall(CeedElemRestrictionReferenceCopy(rstr_points, &op->rstr_points)); 106348acf710SJeremy L Thompson CeedCall(CeedVectorReferenceCopy(point_coords, &op->point_coords)); 106448acf710SJeremy L Thompson return CEED_ERROR_SUCCESS; 106548acf710SJeremy L Thompson } 106648acf710SJeremy L Thompson 106748acf710SJeremy L Thompson /** 1068b594f9faSZach Atkins @brief Get a boolean value indicating if the `CeedOperator` was created with `CeedOperatorCreateAtPoints` 1069b594f9faSZach Atkins 1070b594f9faSZach Atkins @param[in] op `CeedOperator` 1071b594f9faSZach Atkins @param[out] is_at_points Variable to store at points status 1072b594f9faSZach Atkins 1073b594f9faSZach Atkins @return An error code: 0 - success, otherwise - failure 1074b594f9faSZach Atkins 1075b594f9faSZach Atkins @ref User 1076b594f9faSZach Atkins **/ 1077b594f9faSZach Atkins int CeedOperatorIsAtPoints(CeedOperator op, bool *is_at_points) { 1078b594f9faSZach Atkins *is_at_points = op->is_at_points; 1079b594f9faSZach Atkins return CEED_ERROR_SUCCESS; 1080b594f9faSZach Atkins } 1081b594f9faSZach Atkins 1082b594f9faSZach Atkins /** 1083ca94c3ddSJeremy L Thompson @brief Get the arbitrary points in each element for a `CeedOperator` at points. 108448acf710SJeremy L Thompson 1085ca94c3ddSJeremy L Thompson Note: Calling this function asserts that setup is complete and sets the `CeedOperator` as immutable. 108648acf710SJeremy L Thompson 1087ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` at points 1088ca94c3ddSJeremy L Thompson @param[out] rstr_points Variable to hold `CeedElemRestriction` for the coordinates of each point by element 1089ca94c3ddSJeremy L Thompson @param[out] point_coords Variable to hold `CeedVector` holding coordinates of each point 109048acf710SJeremy L Thompson 109148acf710SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 109248acf710SJeremy L Thompson 109348acf710SJeremy L Thompson @ref Advanced 109448acf710SJeremy L Thompson **/ 109548acf710SJeremy L Thompson int CeedOperatorAtPointsGetPoints(CeedOperator op, CeedElemRestriction *rstr_points, CeedVector *point_coords) { 10962a3ff1c9SZach Atkins bool is_at_points; 10972a3ff1c9SZach Atkins 10982a3ff1c9SZach Atkins CeedCall(CeedOperatorIsAtPoints(op, &is_at_points)); 10996e536b99SJeremy L Thompson CeedCheck(is_at_points, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Only defined for operator at points"); 110048acf710SJeremy L Thompson CeedCall(CeedOperatorCheckReady(op)); 110148acf710SJeremy L Thompson 110248acf710SJeremy L Thompson if (rstr_points) CeedCall(CeedElemRestrictionReferenceCopy(op->rstr_points, rstr_points)); 110348acf710SJeremy L Thompson if (point_coords) CeedCall(CeedVectorReferenceCopy(op->point_coords, point_coords)); 110448acf710SJeremy L Thompson return CEED_ERROR_SUCCESS; 110548acf710SJeremy L Thompson } 110648acf710SJeremy L Thompson 110748acf710SJeremy L Thompson /** 1108be9c6463SJeremy L Thompson @brief Get a `CeedOperator` Field of a `CeedOperator` from its name. 1109be9c6463SJeremy L Thompson 1110be9c6463SJeremy L Thompson `op_field` is set to `NULL` if the field is not found. 1111de5900adSJames Wright 1112ca94c3ddSJeremy L Thompson Note: Calling this function asserts that setup is complete and sets the `CeedOperator` as immutable. 1113de5900adSJames Wright 1114ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1115ca94c3ddSJeremy L Thompson @param[in] field_name Name of desired `CeedOperator` Field 1116ca94c3ddSJeremy L Thompson @param[out] op_field `CeedOperator` Field corresponding to the name 1117de5900adSJames Wright 1118de5900adSJames Wright @return An error code: 0 - success, otherwise - failure 1119de5900adSJames Wright 1120de5900adSJames Wright @ref Advanced 1121de5900adSJames Wright **/ 1122de5900adSJames Wright int CeedOperatorGetFieldByName(CeedOperator op, const char *field_name, CeedOperatorField *op_field) { 11236f8994e9SJeremy L Thompson const char *name; 1124de5900adSJames Wright CeedInt num_input_fields, num_output_fields; 1125de5900adSJames Wright CeedOperatorField *input_fields, *output_fields; 1126de5900adSJames Wright 1127be9c6463SJeremy L Thompson *op_field = NULL; 11281c66c397SJeremy L Thompson CeedCall(CeedOperatorGetFields(op, &num_input_fields, &input_fields, &num_output_fields, &output_fields)); 1129de5900adSJames Wright for (CeedInt i = 0; i < num_input_fields; i++) { 1130de5900adSJames Wright CeedCall(CeedOperatorFieldGetName(input_fields[i], &name)); 1131de5900adSJames Wright if (!strcmp(name, field_name)) { 1132de5900adSJames Wright *op_field = input_fields[i]; 1133de5900adSJames Wright return CEED_ERROR_SUCCESS; 1134de5900adSJames Wright } 1135de5900adSJames Wright } 1136de5900adSJames Wright for (CeedInt i = 0; i < num_output_fields; i++) { 1137de5900adSJames Wright CeedCall(CeedOperatorFieldGetName(output_fields[i], &name)); 1138de5900adSJames Wright if (!strcmp(name, field_name)) { 1139de5900adSJames Wright *op_field = output_fields[i]; 1140de5900adSJames Wright return CEED_ERROR_SUCCESS; 1141de5900adSJames Wright } 1142de5900adSJames Wright } 1143be9c6463SJeremy L Thompson return CEED_ERROR_SUCCESS; 1144de5900adSJames Wright } 1145de5900adSJames Wright 1146de5900adSJames Wright /** 1147ca94c3ddSJeremy L Thompson @brief Get the name of a `CeedOperator` Field 114828567f8fSJeremy L Thompson 1149ca94c3ddSJeremy L Thompson @param[in] op_field `CeedOperator` Field 115028567f8fSJeremy L Thompson @param[out] field_name Variable to store the field name 115128567f8fSJeremy L Thompson 115228567f8fSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 115328567f8fSJeremy L Thompson 1154e9b533fbSJeremy L Thompson @ref Advanced 115528567f8fSJeremy L Thompson **/ 11566f8994e9SJeremy L Thompson int CeedOperatorFieldGetName(CeedOperatorField op_field, const char **field_name) { 11576f8994e9SJeremy L Thompson *field_name = op_field->field_name; 115828567f8fSJeremy L Thompson return CEED_ERROR_SUCCESS; 115928567f8fSJeremy L Thompson } 116028567f8fSJeremy L Thompson 116128567f8fSJeremy L Thompson /** 1162*681d0ea7SJeremy L Thompson @brief Get the `CeedElemRestriction` of a `CeedOperator` Field. 1163*681d0ea7SJeremy L Thompson 1164*681d0ea7SJeremy L Thompson Note: Caller is responsible for destroying the `rstr` with @ref CeedElemRestrictionDestroy(). 116543bbe138SJeremy L Thompson 1166ca94c3ddSJeremy L Thompson @param[in] op_field `CeedOperator` Field 1167ca94c3ddSJeremy L Thompson @param[out] rstr Variable to store `CeedElemRestriction` 116843bbe138SJeremy L Thompson 116943bbe138SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 117043bbe138SJeremy L Thompson 1171e9b533fbSJeremy L Thompson @ref Advanced 117243bbe138SJeremy L Thompson **/ 11732b730f8bSJeremy L Thompson int CeedOperatorFieldGetElemRestriction(CeedOperatorField op_field, CeedElemRestriction *rstr) { 1174*681d0ea7SJeremy L Thompson *rstr = NULL; 1175*681d0ea7SJeremy L Thompson CeedCall(CeedElemRestrictionReferenceCopy(op_field->elem_rstr, rstr)); 117643bbe138SJeremy L Thompson return CEED_ERROR_SUCCESS; 117743bbe138SJeremy L Thompson } 117843bbe138SJeremy L Thompson 117943bbe138SJeremy L Thompson /** 1180*681d0ea7SJeremy L Thompson @brief Get the `CeedBasis` of a `CeedOperator` Field. 1181*681d0ea7SJeremy L Thompson 1182*681d0ea7SJeremy L Thompson Note: Caller is responsible for destroying the `basis` with @ref CeedBasisDestroy(). 118343bbe138SJeremy L Thompson 1184ca94c3ddSJeremy L Thompson @param[in] op_field `CeedOperator` Field 1185ca94c3ddSJeremy L Thompson @param[out] basis Variable to store `CeedBasis` 118643bbe138SJeremy L Thompson 118743bbe138SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 118843bbe138SJeremy L Thompson 1189e9b533fbSJeremy L Thompson @ref Advanced 119043bbe138SJeremy L Thompson **/ 119143bbe138SJeremy L Thompson int CeedOperatorFieldGetBasis(CeedOperatorField op_field, CeedBasis *basis) { 1192*681d0ea7SJeremy L Thompson *basis = NULL; 1193*681d0ea7SJeremy L Thompson CeedCall(CeedBasisReferenceCopy(op_field->basis, basis)); 119443bbe138SJeremy L Thompson return CEED_ERROR_SUCCESS; 119543bbe138SJeremy L Thompson } 119643bbe138SJeremy L Thompson 119743bbe138SJeremy L Thompson /** 1198*681d0ea7SJeremy L Thompson @brief Get the `CeedVector` of a `CeedOperator` Field. 1199*681d0ea7SJeremy L Thompson 1200*681d0ea7SJeremy L Thompson Note: Caller is responsible for destroying the `vec` with @ref CeedVectorDestroy(). 120143bbe138SJeremy L Thompson 1202ca94c3ddSJeremy L Thompson @param[in] op_field `CeedOperator` Field 1203ca94c3ddSJeremy L Thompson @param[out] vec Variable to store `CeedVector` 120443bbe138SJeremy L Thompson 120543bbe138SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 120643bbe138SJeremy L Thompson 1207e9b533fbSJeremy L Thompson @ref Advanced 120843bbe138SJeremy L Thompson **/ 120943bbe138SJeremy L Thompson int CeedOperatorFieldGetVector(CeedOperatorField op_field, CeedVector *vec) { 1210*681d0ea7SJeremy L Thompson *vec = NULL; 1211*681d0ea7SJeremy L Thompson CeedCall(CeedVectorReferenceCopy(op_field->vec, vec)); 121243bbe138SJeremy L Thompson return CEED_ERROR_SUCCESS; 121343bbe138SJeremy L Thompson } 121443bbe138SJeremy L Thompson 121543bbe138SJeremy L Thompson /** 1216ab747706SJeremy L Thompson @brief Get the data of a `CeedOperator` Field. 1217ab747706SJeremy L Thompson 1218*681d0ea7SJeremy L Thompson Any arguments set as `NULL` are ignored.. 1219*681d0ea7SJeremy L Thompson 1220*681d0ea7SJeremy L Thompson Note: Caller is responsible for destroying the `rstr`, `basis`, and `vec`. 1221ab747706SJeremy L Thompson 1222ab747706SJeremy L Thompson @param[in] op_field `CeedOperator` Field 1223ab747706SJeremy L Thompson @param[out] field_name Variable to store the field name 1224ab747706SJeremy L Thompson @param[out] rstr Variable to store `CeedElemRestriction` 1225ab747706SJeremy L Thompson @param[out] basis Variable to store `CeedBasis` 1226ab747706SJeremy L Thompson @param[out] vec Variable to store `CeedVector` 1227ab747706SJeremy L Thompson 1228ab747706SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1229ab747706SJeremy L Thompson 1230ab747706SJeremy L Thompson @ref Advanced 1231ab747706SJeremy L Thompson **/ 12326f8994e9SJeremy L Thompson int CeedOperatorFieldGetData(CeedOperatorField op_field, const char **field_name, CeedElemRestriction *rstr, CeedBasis *basis, CeedVector *vec) { 1233ab747706SJeremy L Thompson if (field_name) CeedCall(CeedOperatorFieldGetName(op_field, field_name)); 1234ab747706SJeremy L Thompson if (rstr) CeedCall(CeedOperatorFieldGetElemRestriction(op_field, rstr)); 1235ab747706SJeremy L Thompson if (basis) CeedCall(CeedOperatorFieldGetBasis(op_field, basis)); 1236ab747706SJeremy L Thompson if (vec) CeedCall(CeedOperatorFieldGetVector(op_field, vec)); 1237ab747706SJeremy L Thompson return CEED_ERROR_SUCCESS; 1238ab747706SJeremy L Thompson } 1239ab747706SJeremy L Thompson 1240ab747706SJeremy L Thompson /** 1241ca94c3ddSJeremy L Thompson @brief Add a sub-operator to a composite `CeedOperator` 1242288c0443SJeremy L Thompson 1243ca94c3ddSJeremy L Thompson @param[in,out] composite_op Composite `CeedOperator` 1244ca94c3ddSJeremy L Thompson @param[in] sub_op Sub-operator `CeedOperator` 124552d6035fSJeremy L Thompson 124652d6035fSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 124752d6035fSJeremy L Thompson 12487a982d89SJeremy L. Thompson @ref User 124952d6035fSJeremy L Thompson */ 12502b730f8bSJeremy L Thompson int CeedCompositeOperatorAddSub(CeedOperator composite_op, CeedOperator sub_op) { 12511203703bSJeremy L Thompson bool is_immutable; 12521203703bSJeremy L Thompson Ceed ceed; 12531203703bSJeremy L Thompson 12541203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(composite_op, &ceed)); 12551203703bSJeremy L Thompson CeedCheck(composite_op->is_composite, ceed, CEED_ERROR_MINOR, "CeedOperator is not a composite operator"); 12561203703bSJeremy L Thompson CeedCheck(composite_op->num_suboperators < CEED_COMPOSITE_MAX, ceed, CEED_ERROR_UNSUPPORTED, "Cannot add additional sub-operators"); 12571203703bSJeremy L Thompson CeedCall(CeedOperatorIsImmutable(composite_op, &is_immutable)); 12581203703bSJeremy L Thompson CeedCheck(!is_immutable, ceed, CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable"); 12592b730f8bSJeremy L Thompson 12602b730f8bSJeremy L Thompson { 12612b730f8bSJeremy L Thompson CeedSize input_size, output_size; 12621c66c397SJeremy L Thompson 12632b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetActiveVectorLengths(sub_op, &input_size, &output_size)); 12642b730f8bSJeremy L Thompson if (composite_op->input_size == -1) composite_op->input_size = input_size; 12652b730f8bSJeremy L Thompson if (composite_op->output_size == -1) composite_op->output_size = output_size; 12662b730f8bSJeremy L Thompson // Note, a size of -1 means no active vector restriction set, so no incompatibility 12671203703bSJeremy L Thompson CeedCheck((input_size == -1 || input_size == composite_op->input_size) && (output_size == -1 || output_size == composite_op->output_size), ceed, 12681203703bSJeremy L Thompson CEED_ERROR_MAJOR, 1269249f8407SJeremy L Thompson "Sub-operators must have compatible dimensions; composite operator of shape (%" CeedSize_FMT ", %" CeedSize_FMT 1270249f8407SJeremy L Thompson ") not compatible with sub-operator of " 1271249f8407SJeremy L Thompson "shape (%" CeedSize_FMT ", %" CeedSize_FMT ")", 12722b730f8bSJeremy L Thompson composite_op->input_size, composite_op->output_size, input_size, output_size); 12732b730f8bSJeremy L Thompson } 12742b730f8bSJeremy L Thompson 1275d1d35e2fSjeremylt composite_op->sub_operators[composite_op->num_suboperators] = sub_op; 12762b730f8bSJeremy L Thompson CeedCall(CeedOperatorReference(sub_op)); 1277d1d35e2fSjeremylt composite_op->num_suboperators++; 1278e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 127952d6035fSJeremy L Thompson } 128052d6035fSJeremy L Thompson 128152d6035fSJeremy L Thompson /** 1282ca94c3ddSJeremy L Thompson @brief Get the number of sub-operators associated with a `CeedOperator` 128375f0d5a4SJeremy L Thompson 1284ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1285ca94c3ddSJeremy L Thompson @param[out] num_suboperators Variable to store number of sub-operators 128675f0d5a4SJeremy L Thompson 128775f0d5a4SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 128875f0d5a4SJeremy L Thompson 128975f0d5a4SJeremy L Thompson @ref Backend 129075f0d5a4SJeremy L Thompson **/ 1291c6ebc35dSJeremy L Thompson int CeedCompositeOperatorGetNumSub(CeedOperator op, CeedInt *num_suboperators) { 12921203703bSJeremy L Thompson bool is_composite; 12931203703bSJeremy L Thompson 12941203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 12956e536b99SJeremy L Thompson CeedCheck(is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Only defined for a composite operator"); 129675f0d5a4SJeremy L Thompson *num_suboperators = op->num_suboperators; 129775f0d5a4SJeremy L Thompson return CEED_ERROR_SUCCESS; 129875f0d5a4SJeremy L Thompson } 129975f0d5a4SJeremy L Thompson 130075f0d5a4SJeremy L Thompson /** 1301ca94c3ddSJeremy L Thompson @brief Get the list of sub-operators associated with a `CeedOperator` 130275f0d5a4SJeremy L Thompson 1303ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1304ca94c3ddSJeremy L Thompson @param[out] sub_operators Variable to store list of sub-operators 130575f0d5a4SJeremy L Thompson 130675f0d5a4SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 130775f0d5a4SJeremy L Thompson 130875f0d5a4SJeremy L Thompson @ref Backend 130975f0d5a4SJeremy L Thompson **/ 1310c6ebc35dSJeremy L Thompson int CeedCompositeOperatorGetSubList(CeedOperator op, CeedOperator **sub_operators) { 13111203703bSJeremy L Thompson bool is_composite; 13121203703bSJeremy L Thompson 13131203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 13146e536b99SJeremy L Thompson CeedCheck(is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Only defined for a composite operator"); 131575f0d5a4SJeremy L Thompson *sub_operators = op->sub_operators; 131675f0d5a4SJeremy L Thompson return CEED_ERROR_SUCCESS; 131775f0d5a4SJeremy L Thompson } 131875f0d5a4SJeremy L Thompson 131975f0d5a4SJeremy L Thompson /** 1320ca94c3ddSJeremy L Thompson @brief Check if a `CeedOperator` is ready to be used. 13214db537f9SJeremy L Thompson 1322ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to check 13234db537f9SJeremy L Thompson 13244db537f9SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 13254db537f9SJeremy L Thompson 13264db537f9SJeremy L Thompson @ref User 13274db537f9SJeremy L Thompson **/ 13284db537f9SJeremy L Thompson int CeedOperatorCheckReady(CeedOperator op) { 13291203703bSJeremy L Thompson bool is_at_points, is_composite; 13304db537f9SJeremy L Thompson Ceed ceed; 13311203703bSJeremy L Thompson CeedQFunction qf = NULL; 13324db537f9SJeremy L Thompson 13332b730f8bSJeremy L Thompson if (op->is_interface_setup) return CEED_ERROR_SUCCESS; 13344db537f9SJeremy L Thompson 13351203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 13361203703bSJeremy L Thompson CeedCall(CeedOperatorIsAtPoints(op, &is_at_points)); 13371203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 13381203703bSJeremy L Thompson if (!is_composite) CeedCall(CeedOperatorGetQFunction(op, &qf)); 13391203703bSJeremy L Thompson if (is_composite) { 13401203703bSJeremy L Thompson CeedInt num_suboperators; 13411203703bSJeremy L Thompson 13421203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 13431203703bSJeremy L Thompson if (!num_suboperators) { 134443622462SJeremy L Thompson // Empty operator setup 134543622462SJeremy L Thompson op->input_size = 0; 134643622462SJeremy L Thompson op->output_size = 0; 134743622462SJeremy L Thompson } else { 13481203703bSJeremy L Thompson CeedOperator *sub_operators; 13491203703bSJeremy L Thompson 13501203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 13511203703bSJeremy L Thompson for (CeedInt i = 0; i < num_suboperators; i++) { 13521203703bSJeremy L Thompson CeedCall(CeedOperatorCheckReady(sub_operators[i])); 13534db537f9SJeremy L Thompson } 13542b104005SJeremy L Thompson // Sub-operators could be modified after adding to composite operator 13552b104005SJeremy L Thompson // Need to verify no lvec incompatibility from any changes 13562b104005SJeremy L Thompson CeedSize input_size, output_size; 13572b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetActiveVectorLengths(op, &input_size, &output_size)); 135843622462SJeremy L Thompson } 13594db537f9SJeremy L Thompson } else { 13601203703bSJeremy L Thompson CeedInt num_input_fields, num_output_fields; 13611203703bSJeremy L Thompson 13626574a04fSJeremy L Thompson CeedCheck(op->num_fields > 0, ceed, CEED_ERROR_INCOMPLETE, "No operator fields set"); 13631203703bSJeremy L Thompson CeedCall(CeedQFunctionGetFields(qf, &num_input_fields, NULL, &num_output_fields, NULL)); 13641203703bSJeremy L Thompson CeedCheck(op->num_fields == num_input_fields + num_output_fields, ceed, CEED_ERROR_INCOMPLETE, "Not all operator fields set"); 13656574a04fSJeremy L Thompson CeedCheck(op->has_restriction, ceed, CEED_ERROR_INCOMPLETE, "At least one restriction required"); 13662a3ff1c9SZach Atkins CeedCheck(op->num_qpts > 0 || is_at_points, ceed, CEED_ERROR_INCOMPLETE, 1367ca94c3ddSJeremy L Thompson "At least one non-collocated CeedBasis is required or the number of quadrature points must be set"); 13682b730f8bSJeremy L Thompson } 13694db537f9SJeremy L Thompson 13704db537f9SJeremy L Thompson // Flag as immutable and ready 13714db537f9SJeremy L Thompson op->is_interface_setup = true; 13721203703bSJeremy L Thompson if (qf && qf != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionSetImmutable(qf)); 13731203703bSJeremy L Thompson if (op->dqf && op->dqf != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionSetImmutable(op->dqf)); 13741203703bSJeremy L Thompson if (op->dqfT && op->dqfT != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionSetImmutable(op->dqfT)); 13754db537f9SJeremy L Thompson return CEED_ERROR_SUCCESS; 13764db537f9SJeremy L Thompson } 13774db537f9SJeremy L Thompson 13784db537f9SJeremy L Thompson /** 1379ca94c3ddSJeremy L Thompson @brief Get vector lengths for the active input and/or output `CeedVector` of a `CeedOperator`. 13804385fb7fSSebastian Grimberg 1381ca94c3ddSJeremy L Thompson Note: Lengths of `-1` indicate that the CeedOperator does not have an active input and/or output. 1382c9366a6bSJeremy L Thompson 1383ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1384ca94c3ddSJeremy L Thompson @param[out] input_size Variable to store active input vector length, or `NULL` 1385ca94c3ddSJeremy L Thompson @param[out] output_size Variable to store active output vector length, or `NULL` 1386c9366a6bSJeremy L Thompson 1387c9366a6bSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1388c9366a6bSJeremy L Thompson 1389c9366a6bSJeremy L Thompson @ref User 1390c9366a6bSJeremy L Thompson **/ 13912b730f8bSJeremy L Thompson int CeedOperatorGetActiveVectorLengths(CeedOperator op, CeedSize *input_size, CeedSize *output_size) { 1392c9366a6bSJeremy L Thompson bool is_composite; 1393c9366a6bSJeremy L Thompson 13942b104005SJeremy L Thompson if (input_size) *input_size = op->input_size; 13952b104005SJeremy L Thompson if (output_size) *output_size = op->output_size; 1396c9366a6bSJeremy L Thompson 13972b730f8bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 13982b104005SJeremy L Thompson if (is_composite && (op->input_size == -1 || op->output_size == -1)) { 13991203703bSJeremy L Thompson CeedInt num_suboperators; 14001203703bSJeremy L Thompson CeedOperator *sub_operators; 14011203703bSJeremy L Thompson 14021203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 14031203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 14041203703bSJeremy L Thompson for (CeedInt i = 0; i < num_suboperators; i++) { 1405c9366a6bSJeremy L Thompson CeedSize sub_input_size, sub_output_size; 14061c66c397SJeremy L Thompson 14071203703bSJeremy L Thompson CeedCall(CeedOperatorGetActiveVectorLengths(sub_operators[i], &sub_input_size, &sub_output_size)); 14082b104005SJeremy L Thompson if (op->input_size == -1) op->input_size = sub_input_size; 14092b104005SJeremy L Thompson if (op->output_size == -1) op->output_size = sub_output_size; 14102b104005SJeremy L Thompson // Note, a size of -1 means no active vector restriction set, so no incompatibility 14116e536b99SJeremy L Thompson CeedCheck((sub_input_size == -1 || sub_input_size == op->input_size) && (sub_output_size == -1 || sub_output_size == op->output_size), 14126e536b99SJeremy L Thompson CeedOperatorReturnCeed(op), CEED_ERROR_MAJOR, 1413249f8407SJeremy L Thompson "Sub-operators must have compatible dimensions; composite operator of shape (%" CeedSize_FMT ", %" CeedSize_FMT 1414249f8407SJeremy L Thompson ") not compatible with sub-operator of " 1415249f8407SJeremy L Thompson "shape (%" CeedSize_FMT ", %" CeedSize_FMT ")", 14162b104005SJeremy L Thompson op->input_size, op->output_size, input_size, output_size); 1417c9366a6bSJeremy L Thompson } 14182b730f8bSJeremy L Thompson } 1419c9366a6bSJeremy L Thompson return CEED_ERROR_SUCCESS; 1420c9366a6bSJeremy L Thompson } 1421c9366a6bSJeremy L Thompson 1422c9366a6bSJeremy L Thompson /** 1423ca94c3ddSJeremy L Thompson @brief Set reuse of `CeedQFunction` data in `CeedOperatorLinearAssemble*()` functions. 14244385fb7fSSebastian Grimberg 1425ca94c3ddSJeremy L Thompson When `reuse_assembly_data = false` (default), the `CeedQFunction` associated with this `CeedOperator` is re-assembled every time a `CeedOperatorLinearAssemble*()` function is called. 1426ca94c3ddSJeremy L Thompson When `reuse_assembly_data = true`, the `CeedQFunction` associated with this `CeedOperator` is reused between calls to @ref CeedOperatorSetQFunctionAssemblyDataUpdateNeeded(). 14278b919e6bSJeremy L Thompson 1428ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1429beecbf24SJeremy L Thompson @param[in] reuse_assembly_data Boolean flag setting assembly data reuse 14308b919e6bSJeremy L Thompson 14318b919e6bSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 14328b919e6bSJeremy L Thompson 14338b919e6bSJeremy L Thompson @ref Advanced 14348b919e6bSJeremy L Thompson **/ 14352b730f8bSJeremy L Thompson int CeedOperatorSetQFunctionAssemblyReuse(CeedOperator op, bool reuse_assembly_data) { 14368b919e6bSJeremy L Thompson bool is_composite; 14378b919e6bSJeremy L Thompson 14382b730f8bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 14398b919e6bSJeremy L Thompson if (is_composite) { 14408b919e6bSJeremy L Thompson for (CeedInt i = 0; i < op->num_suboperators; i++) { 14412b730f8bSJeremy L Thompson CeedCall(CeedOperatorSetQFunctionAssemblyReuse(op->sub_operators[i], reuse_assembly_data)); 14428b919e6bSJeremy L Thompson } 14438b919e6bSJeremy L Thompson } else { 14447d5185d7SSebastian Grimberg CeedQFunctionAssemblyData data; 14457d5185d7SSebastian Grimberg 14467d5185d7SSebastian Grimberg CeedCall(CeedOperatorGetQFunctionAssemblyData(op, &data)); 14477d5185d7SSebastian Grimberg CeedCall(CeedQFunctionAssemblyDataSetReuse(data, reuse_assembly_data)); 1448beecbf24SJeremy L Thompson } 1449beecbf24SJeremy L Thompson return CEED_ERROR_SUCCESS; 1450beecbf24SJeremy L Thompson } 1451beecbf24SJeremy L Thompson 1452beecbf24SJeremy L Thompson /** 1453ca94c3ddSJeremy L Thompson @brief Mark `CeedQFunction` data as updated and the `CeedQFunction` as requiring re-assembly. 1454beecbf24SJeremy L Thompson 1455ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 14566e15d496SJeremy L Thompson @param[in] needs_data_update Boolean flag setting assembly data reuse 1457beecbf24SJeremy L Thompson 1458beecbf24SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1459beecbf24SJeremy L Thompson 1460beecbf24SJeremy L Thompson @ref Advanced 1461beecbf24SJeremy L Thompson **/ 14622b730f8bSJeremy L Thompson int CeedOperatorSetQFunctionAssemblyDataUpdateNeeded(CeedOperator op, bool needs_data_update) { 1463beecbf24SJeremy L Thompson bool is_composite; 1464beecbf24SJeremy L Thompson 14652b730f8bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 1466beecbf24SJeremy L Thompson if (is_composite) { 14671203703bSJeremy L Thompson CeedInt num_suboperators; 14681203703bSJeremy L Thompson CeedOperator *sub_operators; 14691203703bSJeremy L Thompson 14701203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 14711203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 14721203703bSJeremy L Thompson for (CeedInt i = 0; i < num_suboperators; i++) { 14731203703bSJeremy L Thompson CeedCall(CeedOperatorSetQFunctionAssemblyDataUpdateNeeded(sub_operators[i], needs_data_update)); 1474beecbf24SJeremy L Thompson } 1475beecbf24SJeremy L Thompson } else { 14767d5185d7SSebastian Grimberg CeedQFunctionAssemblyData data; 14777d5185d7SSebastian Grimberg 14787d5185d7SSebastian Grimberg CeedCall(CeedOperatorGetQFunctionAssemblyData(op, &data)); 14797d5185d7SSebastian Grimberg CeedCall(CeedQFunctionAssemblyDataSetUpdateNeeded(data, needs_data_update)); 14808b919e6bSJeremy L Thompson } 14818b919e6bSJeremy L Thompson return CEED_ERROR_SUCCESS; 14828b919e6bSJeremy L Thompson } 14838b919e6bSJeremy L Thompson 14848b919e6bSJeremy L Thompson /** 1485ca94c3ddSJeremy L Thompson @brief Set name of `CeedOperator` for @ref CeedOperatorView() output 1486ea6b5821SJeremy L Thompson 1487ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 1488ea61e9acSJeremy L Thompson @param[in] name Name to set, or NULL to remove previously set name 1489ea6b5821SJeremy L Thompson 1490ea6b5821SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1491ea6b5821SJeremy L Thompson 1492ea6b5821SJeremy L Thompson @ref User 1493ea6b5821SJeremy L Thompson **/ 1494ea6b5821SJeremy L Thompson int CeedOperatorSetName(CeedOperator op, const char *name) { 1495ea6b5821SJeremy L Thompson char *name_copy; 1496ea6b5821SJeremy L Thompson size_t name_len = name ? strlen(name) : 0; 1497ea6b5821SJeremy L Thompson 14982b730f8bSJeremy L Thompson CeedCall(CeedFree(&op->name)); 1499ea6b5821SJeremy L Thompson if (name_len > 0) { 15002b730f8bSJeremy L Thompson CeedCall(CeedCalloc(name_len + 1, &name_copy)); 1501ea6b5821SJeremy L Thompson memcpy(name_copy, name, name_len); 1502ea6b5821SJeremy L Thompson op->name = name_copy; 1503ea6b5821SJeremy L Thompson } 1504ea6b5821SJeremy L Thompson return CEED_ERROR_SUCCESS; 1505ea6b5821SJeremy L Thompson } 1506ea6b5821SJeremy L Thompson 1507ea6b5821SJeremy L Thompson /** 1508935f026aSJeremy L Thompson @brief Core logic for viewing a `CeedOperator` 15097a982d89SJeremy L. Thompson 1510935f026aSJeremy L Thompson @param[in] op `CeedOperator` to view brief summary 1511ca94c3ddSJeremy L Thompson @param[in] stream Stream to write; typically `stdout` or a file 15128bf1b130SJames Wright @param[in] is_full Whether to write full operator view or terse 15137a982d89SJeremy L. Thompson 15147a982d89SJeremy L. Thompson @return Error code: 0 - success, otherwise - failure 15157a982d89SJeremy L. Thompson **/ 15168bf1b130SJames Wright static int CeedOperatorView_Core(CeedOperator op, FILE *stream, bool is_full) { 15171203703bSJeremy L Thompson bool has_name = op->name, is_composite; 15187a982d89SJeremy L. Thompson 15191203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 15201203703bSJeremy L Thompson if (is_composite) { 15211203703bSJeremy L Thompson CeedInt num_suboperators; 15221203703bSJeremy L Thompson CeedOperator *sub_operators; 15231203703bSJeremy L Thompson 15241203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 15251203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 15262b730f8bSJeremy L Thompson fprintf(stream, "Composite CeedOperator%s%s\n", has_name ? " - " : "", has_name ? op->name : ""); 15277a982d89SJeremy L. Thompson 15281203703bSJeremy L Thompson for (CeedInt i = 0; i < num_suboperators; i++) { 15291203703bSJeremy L Thompson has_name = sub_operators[i]->name; 1530935f026aSJeremy L Thompson fprintf(stream, " SubOperator %" CeedInt_FMT "%s%s%s\n", i, has_name ? " - " : "", has_name ? sub_operators[i]->name : "", is_full ? ":" : ""); 1531935f026aSJeremy L Thompson if (is_full) CeedCall(CeedOperatorSingleView(sub_operators[i], 1, stream)); 15327a982d89SJeremy L. Thompson } 15337a982d89SJeremy L. Thompson } else { 15342b730f8bSJeremy L Thompson fprintf(stream, "CeedOperator%s%s\n", has_name ? " - " : "", has_name ? op->name : ""); 1535935f026aSJeremy L Thompson if (is_full) CeedCall(CeedOperatorSingleView(op, 0, stream)); 15367a982d89SJeremy L. Thompson } 1537e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 15387a982d89SJeremy L. Thompson } 15393bd813ffSjeremylt 15403bd813ffSjeremylt /** 1541935f026aSJeremy L Thompson @brief View a `CeedOperator` 1542935f026aSJeremy L Thompson 1543935f026aSJeremy L Thompson @param[in] op `CeedOperator` to view 1544935f026aSJeremy L Thompson @param[in] stream Stream to write; typically `stdout` or a file 1545935f026aSJeremy L Thompson 1546935f026aSJeremy L Thompson @return Error code: 0 - success, otherwise - failure 1547935f026aSJeremy L Thompson 1548935f026aSJeremy L Thompson @ref User 1549935f026aSJeremy L Thompson **/ 1550935f026aSJeremy L Thompson int CeedOperatorView(CeedOperator op, FILE *stream) { 1551935f026aSJeremy L Thompson CeedCall(CeedOperatorView_Core(op, stream, true)); 1552935f026aSJeremy L Thompson return CEED_ERROR_SUCCESS; 1553935f026aSJeremy L Thompson } 1554935f026aSJeremy L Thompson 1555935f026aSJeremy L Thompson /** 1556935f026aSJeremy L Thompson @brief View a brief summary `CeedOperator` 1557935f026aSJeremy L Thompson 1558935f026aSJeremy L Thompson @param[in] op `CeedOperator` to view brief summary 1559935f026aSJeremy L Thompson @param[in] stream Stream to write; typically `stdout` or a file 1560935f026aSJeremy L Thompson 1561935f026aSJeremy L Thompson @return Error code: 0 - success, otherwise - failure 1562935f026aSJeremy L Thompson 1563935f026aSJeremy L Thompson @ref User 1564935f026aSJeremy L Thompson **/ 1565935f026aSJeremy L Thompson int CeedOperatorViewTerse(CeedOperator op, FILE *stream) { 1566935f026aSJeremy L Thompson CeedCall(CeedOperatorView_Core(op, stream, false)); 1567935f026aSJeremy L Thompson return CEED_ERROR_SUCCESS; 1568935f026aSJeremy L Thompson } 1569935f026aSJeremy L Thompson 1570935f026aSJeremy L Thompson /** 1571ca94c3ddSJeremy L Thompson @brief Get the `Ceed` associated with a `CeedOperator` 1572b7c9bbdaSJeremy L Thompson 1573ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1574ca94c3ddSJeremy L Thompson @param[out] ceed Variable to store `Ceed` 1575b7c9bbdaSJeremy L Thompson 1576b7c9bbdaSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1577b7c9bbdaSJeremy L Thompson 1578b7c9bbdaSJeremy L Thompson @ref Advanced 1579b7c9bbdaSJeremy L Thompson **/ 1580b7c9bbdaSJeremy L Thompson int CeedOperatorGetCeed(CeedOperator op, Ceed *ceed) { 15816e536b99SJeremy L Thompson *ceed = CeedOperatorReturnCeed(op); 1582b7c9bbdaSJeremy L Thompson return CEED_ERROR_SUCCESS; 1583b7c9bbdaSJeremy L Thompson } 1584b7c9bbdaSJeremy L Thompson 1585b7c9bbdaSJeremy L Thompson /** 15866e536b99SJeremy L Thompson @brief Return the `Ceed` associated with a `CeedOperator` 15876e536b99SJeremy L Thompson 15886e536b99SJeremy L Thompson @param[in] op `CeedOperator` 15896e536b99SJeremy L Thompson 15906e536b99SJeremy L Thompson @return `Ceed` associated with the `op` 15916e536b99SJeremy L Thompson 15926e536b99SJeremy L Thompson @ref Advanced 15936e536b99SJeremy L Thompson **/ 15946e536b99SJeremy L Thompson Ceed CeedOperatorReturnCeed(CeedOperator op) { return op->ceed; } 15956e536b99SJeremy L Thompson 15966e536b99SJeremy L Thompson /** 1597ca94c3ddSJeremy L Thompson @brief Get the number of elements associated with a `CeedOperator` 1598b7c9bbdaSJeremy L Thompson 1599ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1600b7c9bbdaSJeremy L Thompson @param[out] num_elem Variable to store number of elements 1601b7c9bbdaSJeremy L Thompson 1602b7c9bbdaSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1603b7c9bbdaSJeremy L Thompson 1604b7c9bbdaSJeremy L Thompson @ref Advanced 1605b7c9bbdaSJeremy L Thompson **/ 1606b7c9bbdaSJeremy L Thompson int CeedOperatorGetNumElements(CeedOperator op, CeedInt *num_elem) { 16071203703bSJeremy L Thompson bool is_composite; 16081203703bSJeremy L Thompson 16091203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 16106e536b99SJeremy L Thompson CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Not defined for composite operator"); 1611b7c9bbdaSJeremy L Thompson *num_elem = op->num_elem; 1612b7c9bbdaSJeremy L Thompson return CEED_ERROR_SUCCESS; 1613b7c9bbdaSJeremy L Thompson } 1614b7c9bbdaSJeremy L Thompson 1615b7c9bbdaSJeremy L Thompson /** 1616ca94c3ddSJeremy L Thompson @brief Get the number of quadrature points associated with a `CeedOperator` 1617b7c9bbdaSJeremy L Thompson 1618ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1619b7c9bbdaSJeremy L Thompson @param[out] num_qpts Variable to store vector number of quadrature points 1620b7c9bbdaSJeremy L Thompson 1621b7c9bbdaSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1622b7c9bbdaSJeremy L Thompson 1623b7c9bbdaSJeremy L Thompson @ref Advanced 1624b7c9bbdaSJeremy L Thompson **/ 1625b7c9bbdaSJeremy L Thompson int CeedOperatorGetNumQuadraturePoints(CeedOperator op, CeedInt *num_qpts) { 16261203703bSJeremy L Thompson bool is_composite; 16271203703bSJeremy L Thompson 16281203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 16296e536b99SJeremy L Thompson CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Not defined for composite operator"); 1630b7c9bbdaSJeremy L Thompson *num_qpts = op->num_qpts; 1631b7c9bbdaSJeremy L Thompson return CEED_ERROR_SUCCESS; 1632b7c9bbdaSJeremy L Thompson } 1633b7c9bbdaSJeremy L Thompson 1634b7c9bbdaSJeremy L Thompson /** 1635ca94c3ddSJeremy L Thompson @brief Estimate number of FLOPs required to apply `CeedOperator` on the active `CeedVector` 16366e15d496SJeremy L Thompson 1637ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to estimate FLOPs for 1638ea61e9acSJeremy L Thompson @param[out] flops Address of variable to hold FLOPs estimate 16396e15d496SJeremy L Thompson 16406e15d496SJeremy L Thompson @ref Backend 16416e15d496SJeremy L Thompson **/ 16429d36ca50SJeremy L Thompson int CeedOperatorGetFlopsEstimate(CeedOperator op, CeedSize *flops) { 16436e15d496SJeremy L Thompson bool is_composite; 16441c66c397SJeremy L Thompson 16452b730f8bSJeremy L Thompson CeedCall(CeedOperatorCheckReady(op)); 16466e15d496SJeremy L Thompson 16476e15d496SJeremy L Thompson *flops = 0; 16482b730f8bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 16496e15d496SJeremy L Thompson if (is_composite) { 16506e15d496SJeremy L Thompson CeedInt num_suboperators; 16511c66c397SJeremy L Thompson 1652c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 16536e15d496SJeremy L Thompson CeedOperator *sub_operators; 1654c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 16556e15d496SJeremy L Thompson 16566e15d496SJeremy L Thompson // FLOPs for each suboperator 16576e15d496SJeremy L Thompson for (CeedInt i = 0; i < num_suboperators; i++) { 16589d36ca50SJeremy L Thompson CeedSize suboperator_flops; 16591c66c397SJeremy L Thompson 16602b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetFlopsEstimate(sub_operators[i], &suboperator_flops)); 16616e15d496SJeremy L Thompson *flops += suboperator_flops; 16626e15d496SJeremy L Thompson } 16636e15d496SJeremy L Thompson } else { 16641c66c397SJeremy L Thompson CeedInt num_input_fields, num_output_fields, num_elem = 0; 16651203703bSJeremy L Thompson CeedQFunction qf; 16661203703bSJeremy L Thompson CeedQFunctionField *qf_input_fields, *qf_output_fields; 16671203703bSJeremy L Thompson CeedOperatorField *op_input_fields, *op_output_fields; 16681c66c397SJeremy L Thompson 16691203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 16701203703bSJeremy L Thompson CeedCall(CeedQFunctionGetFields(qf, &num_input_fields, &qf_input_fields, &num_output_fields, &qf_output_fields)); 16711203703bSJeremy L Thompson CeedCall(CeedOperatorGetFields(op, NULL, &op_input_fields, NULL, &op_output_fields)); 16722b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetNumElements(op, &num_elem)); 16734385fb7fSSebastian Grimberg 16746e15d496SJeremy L Thompson // Input FLOPs 16756e15d496SJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 16761203703bSJeremy L Thompson CeedVector vec; 16776e15d496SJeremy L Thompson 16781203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(op_input_fields[i], &vec)); 16791203703bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 16801203703bSJeremy L Thompson CeedEvalMode eval_mode; 16811203703bSJeremy L Thompson CeedSize rstr_flops, basis_flops; 16821203703bSJeremy L Thompson CeedElemRestriction rstr; 16831203703bSJeremy L Thompson CeedBasis basis; 16841203703bSJeremy L Thompson 16851203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetElemRestriction(op_input_fields[i], &rstr)); 16861203703bSJeremy L Thompson CeedCall(CeedElemRestrictionGetFlopsEstimate(rstr, CEED_NOTRANSPOSE, &rstr_flops)); 1687*681d0ea7SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&rstr)); 1688edb2538eSJeremy L Thompson *flops += rstr_flops; 16891203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetBasis(op_input_fields[i], &basis)); 16901203703bSJeremy L Thompson CeedCall(CeedQFunctionFieldGetEvalMode(qf_input_fields[i], &eval_mode)); 16911203703bSJeremy L Thompson CeedCall(CeedBasisGetFlopsEstimate(basis, CEED_NOTRANSPOSE, eval_mode, &basis_flops)); 1692*681d0ea7SJeremy L Thompson CeedCall(CeedBasisDestroy(&basis)); 16936e15d496SJeremy L Thompson *flops += basis_flops * num_elem; 16946e15d496SJeremy L Thompson } 1695*681d0ea7SJeremy L Thompson CeedCall(CeedVectorDestroy(&vec)); 16966e15d496SJeremy L Thompson } 16976e15d496SJeremy L Thompson // QF FLOPs 16981c66c397SJeremy L Thompson { 16999d36ca50SJeremy L Thompson CeedInt num_qpts; 17009d36ca50SJeremy L Thompson CeedSize qf_flops; 17011203703bSJeremy L Thompson CeedQFunction qf; 17021c66c397SJeremy L Thompson 17032b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetNumQuadraturePoints(op, &num_qpts)); 17041203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 17051203703bSJeremy L Thompson CeedCall(CeedQFunctionGetFlopsEstimate(qf, &qf_flops)); 17066e536b99SJeremy L Thompson CeedCheck(qf_flops > -1, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPLETE, 17076e536b99SJeremy L Thompson "Must set CeedQFunction FLOPs estimate with CeedQFunctionSetUserFlopsEstimate"); 17086e15d496SJeremy L Thompson *flops += num_elem * num_qpts * qf_flops; 17091c66c397SJeremy L Thompson } 17101c66c397SJeremy L Thompson 17116e15d496SJeremy L Thompson // Output FLOPs 17126e15d496SJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 17131203703bSJeremy L Thompson CeedVector vec; 17146e15d496SJeremy L Thompson 17151203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(op_output_fields[i], &vec)); 17161203703bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 17171203703bSJeremy L Thompson CeedEvalMode eval_mode; 17181203703bSJeremy L Thompson CeedSize rstr_flops, basis_flops; 17191203703bSJeremy L Thompson CeedElemRestriction rstr; 17201203703bSJeremy L Thompson CeedBasis basis; 17211203703bSJeremy L Thompson 17221203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetElemRestriction(op_output_fields[i], &rstr)); 17231203703bSJeremy L Thompson CeedCall(CeedElemRestrictionGetFlopsEstimate(rstr, CEED_TRANSPOSE, &rstr_flops)); 1724*681d0ea7SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&rstr)); 1725edb2538eSJeremy L Thompson *flops += rstr_flops; 17261203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetBasis(op_output_fields[i], &basis)); 17271203703bSJeremy L Thompson CeedCall(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode)); 17281203703bSJeremy L Thompson CeedCall(CeedBasisGetFlopsEstimate(basis, CEED_TRANSPOSE, eval_mode, &basis_flops)); 1729*681d0ea7SJeremy L Thompson CeedCall(CeedBasisDestroy(&basis)); 17306e15d496SJeremy L Thompson *flops += basis_flops * num_elem; 17316e15d496SJeremy L Thompson } 1732*681d0ea7SJeremy L Thompson CeedCall(CeedVectorDestroy(&vec)); 17336e15d496SJeremy L Thompson } 17346e15d496SJeremy L Thompson } 17356e15d496SJeremy L Thompson return CEED_ERROR_SUCCESS; 17366e15d496SJeremy L Thompson } 17376e15d496SJeremy L Thompson 17386e15d496SJeremy L Thompson /** 1739ca94c3ddSJeremy L Thompson @brief Get `CeedQFunction` global context for a `CeedOperator`. 17409fd66db6SSebastian Grimberg 1741ca94c3ddSJeremy L Thompson The caller is responsible for destroying `ctx` returned from this function via @ref CeedQFunctionContextDestroy(). 1742512bb800SJeremy L Thompson 1743ca94c3ddSJeremy 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`. 1744ca94c3ddSJeremy L Thompson This `CeedQFunctionContext` will be destroyed if `ctx` is the only reference to this `CeedQFunctionContext`. 17450126412dSJeremy L Thompson 1746ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1747ca94c3ddSJeremy L Thompson @param[out] ctx Variable to store `CeedQFunctionContext` 17480126412dSJeremy L Thompson 17490126412dSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 17500126412dSJeremy L Thompson 1751859c15bbSJames Wright @ref Advanced 17520126412dSJeremy L Thompson **/ 17530126412dSJeremy L Thompson int CeedOperatorGetContext(CeedOperator op, CeedQFunctionContext *ctx) { 17541203703bSJeremy L Thompson bool is_composite; 17551203703bSJeremy L Thompson CeedQFunction qf; 17561203703bSJeremy L Thompson CeedQFunctionContext qf_ctx; 17571203703bSJeremy L Thompson 17581203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 17596e536b99SJeremy L Thompson CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, "Cannot retrieve CeedQFunctionContext for composite operator"); 17601203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 17611203703bSJeremy L Thompson CeedCall(CeedQFunctionGetInnerContext(qf, &qf_ctx)); 17621203703bSJeremy L Thompson if (qf_ctx) CeedCall(CeedQFunctionContextReferenceCopy(qf_ctx, ctx)); 17630126412dSJeremy L Thompson return CEED_ERROR_SUCCESS; 17640126412dSJeremy L Thompson } 17650126412dSJeremy L Thompson 17660126412dSJeremy L Thompson /** 1767ca94c3ddSJeremy L Thompson @brief Get label for a registered `CeedQFunctionContext` field, or `NULL` if no field has been registered with this `field_name`. 17683668ca4bSJeremy L Thompson 1769ca94c3ddSJeremy L Thompson Fields are registered via `CeedQFunctionContextRegister*()` functions (eg. @ref CeedQFunctionContextRegisterDouble()). 1770859c15bbSJames Wright 1771ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 17723668ca4bSJeremy L Thompson @param[in] field_name Name of field to retrieve label 17733668ca4bSJeremy L Thompson @param[out] field_label Variable to field label 17743668ca4bSJeremy L Thompson 17753668ca4bSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 17763668ca4bSJeremy L Thompson 17773668ca4bSJeremy L Thompson @ref User 17783668ca4bSJeremy L Thompson **/ 177917b0d5c6SJeremy L Thompson int CeedOperatorGetContextFieldLabel(CeedOperator op, const char *field_name, CeedContextFieldLabel *field_label) { 17801c66c397SJeremy L Thompson bool is_composite, field_found = false; 17811c66c397SJeremy L Thompson 17822b730f8bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 17832b730f8bSJeremy L Thompson 17843668ca4bSJeremy L Thompson if (is_composite) { 1785a98a090bSJeremy L Thompson // Composite operator 1786a98a090bSJeremy L Thompson // -- Check if composite label already created 17873668ca4bSJeremy L Thompson for (CeedInt i = 0; i < op->num_context_labels; i++) { 17883668ca4bSJeremy L Thompson if (!strcmp(op->context_labels[i]->name, field_name)) { 17893668ca4bSJeremy L Thompson *field_label = op->context_labels[i]; 17903668ca4bSJeremy L Thompson return CEED_ERROR_SUCCESS; 17913668ca4bSJeremy L Thompson } 17923668ca4bSJeremy L Thompson } 17933668ca4bSJeremy L Thompson 1794a98a090bSJeremy L Thompson // -- Create composite label if needed 17953668ca4bSJeremy L Thompson CeedInt num_sub; 17963668ca4bSJeremy L Thompson CeedOperator *sub_operators; 17973668ca4bSJeremy L Thompson CeedContextFieldLabel new_field_label; 17983668ca4bSJeremy L Thompson 17992b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, &new_field_label)); 1800c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub)); 1801c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 18022b730f8bSJeremy L Thompson CeedCall(CeedCalloc(num_sub, &new_field_label->sub_labels)); 18033668ca4bSJeremy L Thompson new_field_label->num_sub_labels = num_sub; 18043668ca4bSJeremy L Thompson 18053668ca4bSJeremy L Thompson for (CeedInt i = 0; i < num_sub; i++) { 18063668ca4bSJeremy L Thompson if (sub_operators[i]->qf->ctx) { 18073668ca4bSJeremy L Thompson CeedContextFieldLabel new_field_label_i; 18081c66c397SJeremy L Thompson 18092b730f8bSJeremy L Thompson CeedCall(CeedQFunctionContextGetFieldLabel(sub_operators[i]->qf->ctx, field_name, &new_field_label_i)); 18103668ca4bSJeremy L Thompson if (new_field_label_i) { 1811a98a090bSJeremy L Thompson field_found = true; 18123668ca4bSJeremy L Thompson new_field_label->sub_labels[i] = new_field_label_i; 18133668ca4bSJeremy L Thompson new_field_label->name = new_field_label_i->name; 18143668ca4bSJeremy L Thompson new_field_label->description = new_field_label_i->description; 18152b730f8bSJeremy L Thompson if (new_field_label->type && new_field_label->type != new_field_label_i->type) { 18167bfe0f0eSJeremy L Thompson // LCOV_EXCL_START 18172b730f8bSJeremy L Thompson CeedCall(CeedFree(&new_field_label)); 18186e536b99SJeremy L Thompson return CeedError(CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, "Incompatible field types on sub-operator contexts. %s != %s", 18192b730f8bSJeremy L Thompson CeedContextFieldTypes[new_field_label->type], CeedContextFieldTypes[new_field_label_i->type]); 18207bfe0f0eSJeremy L Thompson // LCOV_EXCL_STOP 18217bfe0f0eSJeremy L Thompson } else { 18227bfe0f0eSJeremy L Thompson new_field_label->type = new_field_label_i->type; 18237bfe0f0eSJeremy L Thompson } 18242b730f8bSJeremy L Thompson if (new_field_label->num_values != 0 && new_field_label->num_values != new_field_label_i->num_values) { 18257bfe0f0eSJeremy L Thompson // LCOV_EXCL_START 18262b730f8bSJeremy L Thompson CeedCall(CeedFree(&new_field_label)); 18276e536b99SJeremy L Thompson return CeedError(CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, 18286e536b99SJeremy L Thompson "Incompatible field number of values on sub-operator contexts. %zu != %zu", new_field_label->num_values, 18296e536b99SJeremy L Thompson new_field_label_i->num_values); 18307bfe0f0eSJeremy L Thompson // LCOV_EXCL_STOP 18317bfe0f0eSJeremy L Thompson } else { 18327bfe0f0eSJeremy L Thompson new_field_label->num_values = new_field_label_i->num_values; 18337bfe0f0eSJeremy L Thompson } 18343668ca4bSJeremy L Thompson } 18353668ca4bSJeremy L Thompson } 18363668ca4bSJeremy L Thompson } 1837a98a090bSJeremy L Thompson // -- Cleanup if field was found 1838a98a090bSJeremy L Thompson if (field_found) { 1839a98a090bSJeremy L Thompson *field_label = new_field_label; 1840a98a090bSJeremy L Thompson } else { 18413668ca4bSJeremy L Thompson // LCOV_EXCL_START 18422b730f8bSJeremy L Thompson CeedCall(CeedFree(&new_field_label->sub_labels)); 18432b730f8bSJeremy L Thompson CeedCall(CeedFree(&new_field_label)); 18443668ca4bSJeremy L Thompson *field_label = NULL; 18453668ca4bSJeremy L Thompson // LCOV_EXCL_STOP 18465ac9af79SJeremy L Thompson } 18475ac9af79SJeremy L Thompson } else { 18481203703bSJeremy L Thompson CeedQFunction qf; 18491203703bSJeremy L Thompson CeedQFunctionContext ctx; 18501203703bSJeremy L Thompson 1851a98a090bSJeremy L Thompson // Single, non-composite operator 18521203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 18531203703bSJeremy L Thompson CeedCall(CeedQFunctionGetInnerContext(qf, &ctx)); 18541203703bSJeremy L Thompson if (ctx) { 18551203703bSJeremy L Thompson CeedCall(CeedQFunctionContextGetFieldLabel(ctx, field_name, field_label)); 1856a98a090bSJeremy L Thompson } else { 1857a98a090bSJeremy L Thompson *field_label = NULL; 1858a98a090bSJeremy L Thompson } 18595ac9af79SJeremy L Thompson } 18605ac9af79SJeremy L Thompson 18615ac9af79SJeremy L Thompson // Set label in operator 18625ac9af79SJeremy L Thompson if (*field_label) { 18635ac9af79SJeremy L Thompson (*field_label)->from_op = true; 18645ac9af79SJeremy L Thompson 18653668ca4bSJeremy L Thompson // Move new composite label to operator 18663668ca4bSJeremy L Thompson if (op->num_context_labels == 0) { 18672b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, &op->context_labels)); 18683668ca4bSJeremy L Thompson op->max_context_labels = 1; 18693668ca4bSJeremy L Thompson } else if (op->num_context_labels == op->max_context_labels) { 18702b730f8bSJeremy L Thompson CeedCall(CeedRealloc(2 * op->num_context_labels, &op->context_labels)); 18713668ca4bSJeremy L Thompson op->max_context_labels *= 2; 18723668ca4bSJeremy L Thompson } 18735ac9af79SJeremy L Thompson op->context_labels[op->num_context_labels] = *field_label; 18743668ca4bSJeremy L Thompson op->num_context_labels++; 18753668ca4bSJeremy L Thompson } 18763668ca4bSJeremy L Thompson return CEED_ERROR_SUCCESS; 18773668ca4bSJeremy L Thompson } 18783668ca4bSJeremy L Thompson 18793668ca4bSJeremy L Thompson /** 1880ca94c3ddSJeremy L Thompson @brief Set `CeedQFunctionContext` field holding double precision values. 18814385fb7fSSebastian Grimberg 1882ca94c3ddSJeremy L Thompson For composite operators, the values are set in all sub-operator `CeedQFunctionContext` that have a matching `field_name`. 1883d8dd9a91SJeremy L Thompson 1884ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 18852788fa27SJeremy L Thompson @param[in] field_label Label of field to set 1886ea61e9acSJeremy L Thompson @param[in] values Values to set 1887d8dd9a91SJeremy L Thompson 1888d8dd9a91SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1889d8dd9a91SJeremy L Thompson 1890d8dd9a91SJeremy L Thompson @ref User 1891d8dd9a91SJeremy L Thompson **/ 189217b0d5c6SJeremy L Thompson int CeedOperatorSetContextDouble(CeedOperator op, CeedContextFieldLabel field_label, double *values) { 18932b730f8bSJeremy L Thompson return CeedOperatorContextSetGeneric(op, field_label, CEED_CONTEXT_FIELD_DOUBLE, values); 1894d8dd9a91SJeremy L Thompson } 1895d8dd9a91SJeremy L Thompson 1896d8dd9a91SJeremy L Thompson /** 1897ca94c3ddSJeremy L Thompson @brief Get `CeedQFunctionContext` field holding double precision values, read-only. 18984385fb7fSSebastian Grimberg 1899ca94c3ddSJeremy L Thompson For composite operators, the values correspond to the first sub-operator `CeedQFunctionContext` that has a matching `field_name`. 19002788fa27SJeremy L Thompson 1901ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 19022788fa27SJeremy L Thompson @param[in] field_label Label of field to get 19032788fa27SJeremy L Thompson @param[out] num_values Number of values in the field label 19042788fa27SJeremy L Thompson @param[out] values Pointer to context values 19052788fa27SJeremy L Thompson 19062788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 19072788fa27SJeremy L Thompson 19082788fa27SJeremy L Thompson @ref User 19092788fa27SJeremy L Thompson **/ 191017b0d5c6SJeremy L Thompson int CeedOperatorGetContextDoubleRead(CeedOperator op, CeedContextFieldLabel field_label, size_t *num_values, const double **values) { 19112788fa27SJeremy L Thompson return CeedOperatorContextGetGenericRead(op, field_label, CEED_CONTEXT_FIELD_DOUBLE, num_values, values); 19122788fa27SJeremy L Thompson } 19132788fa27SJeremy L Thompson 19142788fa27SJeremy L Thompson /** 1915ca94c3ddSJeremy L Thompson @brief Restore `CeedQFunctionContext` field holding double precision values, read-only. 19162788fa27SJeremy L Thompson 1917ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 19182788fa27SJeremy L Thompson @param[in] field_label Label of field to restore 19192788fa27SJeremy L Thompson @param[out] values Pointer to context values 19202788fa27SJeremy L Thompson 19212788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 19222788fa27SJeremy L Thompson 19232788fa27SJeremy L Thompson @ref User 19242788fa27SJeremy L Thompson **/ 192517b0d5c6SJeremy L Thompson int CeedOperatorRestoreContextDoubleRead(CeedOperator op, CeedContextFieldLabel field_label, const double **values) { 19262788fa27SJeremy L Thompson return CeedOperatorContextRestoreGenericRead(op, field_label, CEED_CONTEXT_FIELD_DOUBLE, values); 19272788fa27SJeremy L Thompson } 19282788fa27SJeremy L Thompson 19292788fa27SJeremy L Thompson /** 1930ca94c3ddSJeremy L Thompson @brief Set `CeedQFunctionContext` field holding `int32` values. 19314385fb7fSSebastian Grimberg 1932ca94c3ddSJeremy L Thompson For composite operators, the values are set in all sub-operator `CeedQFunctionContext` that have a matching `field_name`. 1933d8dd9a91SJeremy L Thompson 1934ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 1935ea61e9acSJeremy L Thompson @param[in] field_label Label of field to set 1936ea61e9acSJeremy L Thompson @param[in] values Values to set 1937d8dd9a91SJeremy L Thompson 1938d8dd9a91SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1939d8dd9a91SJeremy L Thompson 1940d8dd9a91SJeremy L Thompson @ref User 1941d8dd9a91SJeremy L Thompson **/ 194223dbfd29SJeremy L Thompson int CeedOperatorSetContextInt32(CeedOperator op, CeedContextFieldLabel field_label, int32_t *values) { 19432b730f8bSJeremy L Thompson return CeedOperatorContextSetGeneric(op, field_label, CEED_CONTEXT_FIELD_INT32, values); 1944d8dd9a91SJeremy L Thompson } 1945d8dd9a91SJeremy L Thompson 1946d8dd9a91SJeremy L Thompson /** 1947ca94c3ddSJeremy L Thompson @brief Get `CeedQFunctionContext` field holding `int32` values, read-only. 19484385fb7fSSebastian Grimberg 1949ca94c3ddSJeremy L Thompson For composite operators, the values correspond to the first sub-operator `CeedQFunctionContext` that has a matching `field_name`. 19502788fa27SJeremy L Thompson 1951ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 19522788fa27SJeremy L Thompson @param[in] field_label Label of field to get 1953ca94c3ddSJeremy L Thompson @param[out] num_values Number of `int32` values in `values` 19542788fa27SJeremy L Thompson @param[out] values Pointer to context values 19552788fa27SJeremy L Thompson 19562788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 19572788fa27SJeremy L Thompson 19582788fa27SJeremy L Thompson @ref User 19592788fa27SJeremy L Thompson **/ 196023dbfd29SJeremy L Thompson int CeedOperatorGetContextInt32Read(CeedOperator op, CeedContextFieldLabel field_label, size_t *num_values, const int32_t **values) { 19612788fa27SJeremy L Thompson return CeedOperatorContextGetGenericRead(op, field_label, CEED_CONTEXT_FIELD_INT32, num_values, values); 19622788fa27SJeremy L Thompson } 19632788fa27SJeremy L Thompson 19642788fa27SJeremy L Thompson /** 1965ca94c3ddSJeremy L Thompson @brief Restore `CeedQFunctionContext` field holding `int32` values, read-only. 19662788fa27SJeremy L Thompson 1967ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 19682788fa27SJeremy L Thompson @param[in] field_label Label of field to get 19692788fa27SJeremy L Thompson @param[out] values Pointer to context values 19702788fa27SJeremy L Thompson 19712788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 19722788fa27SJeremy L Thompson 19732788fa27SJeremy L Thompson @ref User 19742788fa27SJeremy L Thompson **/ 197523dbfd29SJeremy L Thompson int CeedOperatorRestoreContextInt32Read(CeedOperator op, CeedContextFieldLabel field_label, const int32_t **values) { 19762788fa27SJeremy L Thompson return CeedOperatorContextRestoreGenericRead(op, field_label, CEED_CONTEXT_FIELD_INT32, values); 19772788fa27SJeremy L Thompson } 19782788fa27SJeremy L Thompson 19792788fa27SJeremy L Thompson /** 1980ca94c3ddSJeremy L Thompson @brief Set `CeedQFunctionContext` field holding boolean values. 19815b6ec284SJeremy L Thompson 1982ca94c3ddSJeremy L Thompson For composite operators, the values are set in all sub-operator `CeedQFunctionContext` that have a matching `field_name`. 19835b6ec284SJeremy L Thompson 1984ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 19855b6ec284SJeremy L Thompson @param[in] field_label Label of field to set 19865b6ec284SJeremy L Thompson @param[in] values Values to set 19875b6ec284SJeremy L Thompson 19885b6ec284SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 19895b6ec284SJeremy L Thompson 19905b6ec284SJeremy L Thompson @ref User 19915b6ec284SJeremy L Thompson **/ 19925b6ec284SJeremy L Thompson int CeedOperatorSetContextBoolean(CeedOperator op, CeedContextFieldLabel field_label, bool *values) { 19935b6ec284SJeremy L Thompson return CeedOperatorContextSetGeneric(op, field_label, CEED_CONTEXT_FIELD_BOOL, values); 19945b6ec284SJeremy L Thompson } 19955b6ec284SJeremy L Thompson 19965b6ec284SJeremy L Thompson /** 1997ca94c3ddSJeremy L Thompson @brief Get `CeedQFunctionContext` field holding boolean values, read-only. 19985b6ec284SJeremy L Thompson 1999ca94c3ddSJeremy L Thompson For composite operators, the values correspond to the first sub-operator `CeedQFunctionContext` that has a matching `field_name`. 20005b6ec284SJeremy L Thompson 2001ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 20025b6ec284SJeremy L Thompson @param[in] field_label Label of field to get 2003ca94c3ddSJeremy L Thompson @param[out] num_values Number of boolean values in `values` 20045b6ec284SJeremy L Thompson @param[out] values Pointer to context values 20055b6ec284SJeremy L Thompson 20065b6ec284SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 20075b6ec284SJeremy L Thompson 20085b6ec284SJeremy L Thompson @ref User 20095b6ec284SJeremy L Thompson **/ 20105b6ec284SJeremy L Thompson int CeedOperatorGetContextBooleanRead(CeedOperator op, CeedContextFieldLabel field_label, size_t *num_values, const bool **values) { 20115b6ec284SJeremy L Thompson return CeedOperatorContextGetGenericRead(op, field_label, CEED_CONTEXT_FIELD_BOOL, num_values, values); 20125b6ec284SJeremy L Thompson } 20135b6ec284SJeremy L Thompson 20145b6ec284SJeremy L Thompson /** 2015ca94c3ddSJeremy L Thompson @brief Restore `CeedQFunctionContext` field holding boolean values, read-only. 20165b6ec284SJeremy L Thompson 2017ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 20185b6ec284SJeremy L Thompson @param[in] field_label Label of field to get 20195b6ec284SJeremy L Thompson @param[out] values Pointer to context values 20205b6ec284SJeremy L Thompson 20215b6ec284SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 20225b6ec284SJeremy L Thompson 20235b6ec284SJeremy L Thompson @ref User 20245b6ec284SJeremy L Thompson **/ 20255b6ec284SJeremy L Thompson int CeedOperatorRestoreContextBooleanRead(CeedOperator op, CeedContextFieldLabel field_label, const bool **values) { 20265b6ec284SJeremy L Thompson return CeedOperatorContextRestoreGenericRead(op, field_label, CEED_CONTEXT_FIELD_BOOL, values); 20275b6ec284SJeremy L Thompson } 20285b6ec284SJeremy L Thompson 20295b6ec284SJeremy L Thompson /** 2030ca94c3ddSJeremy L Thompson @brief Apply `CeedOperator` to a `CeedVector`. 2031d7b241e6Sjeremylt 2032ea61e9acSJeremy L Thompson This computes the action of the operator on the specified (active) input, yielding its (active) output. 2033ca94c3ddSJeremy L Thompson All inputs and outputs must be specified using @ref CeedOperatorSetField(). 2034d7b241e6Sjeremylt 2035ca94c3ddSJeremy L Thompson Note: Calling this function asserts that setup is complete and sets the `CeedOperator` as immutable. 2036f04ea552SJeremy L Thompson 2037ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to apply 2038ca94c3ddSJeremy L Thompson @param[in] in `CeedVector` containing input state or @ref CEED_VECTOR_NONE if there are no active inputs 2039ca94c3ddSJeremy 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 2040ca94c3ddSJeremy L Thompson @param[in] request Address of @ref CeedRequest for non-blocking completion, else @ref CEED_REQUEST_IMMEDIATE 2041b11c1e72Sjeremylt 2042b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 2043dfdf5a53Sjeremylt 20447a982d89SJeremy L. Thompson @ref User 2045b11c1e72Sjeremylt **/ 20462b730f8bSJeremy L Thompson int CeedOperatorApply(CeedOperator op, CeedVector in, CeedVector out, CeedRequest *request) { 20471203703bSJeremy L Thompson bool is_composite; 20481203703bSJeremy L Thompson 20492b730f8bSJeremy L Thompson CeedCall(CeedOperatorCheckReady(op)); 2050d7b241e6Sjeremylt 20511203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 20521203703bSJeremy L Thompson if (is_composite) { 2053250756a7Sjeremylt // Composite Operator 2054250756a7Sjeremylt if (op->ApplyComposite) { 20552b730f8bSJeremy L Thompson CeedCall(op->ApplyComposite(op, in, out, request)); 2056250756a7Sjeremylt } else { 2057d1d35e2fSjeremylt CeedInt num_suboperators; 2058d1d35e2fSjeremylt CeedOperator *sub_operators; 20591c66c397SJeremy L Thompson 20601c66c397SJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 2061c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 2062250756a7Sjeremylt 2063250756a7Sjeremylt // Zero all output vectors 20643ca2b39bSJeremy L Thompson if (out != CEED_VECTOR_NONE) CeedCall(CeedVectorSetValue(out, 0.0)); 2065d1d35e2fSjeremylt for (CeedInt i = 0; i < num_suboperators; i++) { 20661203703bSJeremy L Thompson CeedInt num_output_fields; 20671203703bSJeremy L Thompson CeedOperatorField *output_fields; 20681c66c397SJeremy L Thompson 20691203703bSJeremy L Thompson CeedCall(CeedOperatorGetFields(sub_operators[i], NULL, NULL, &num_output_fields, &output_fields)); 20701203703bSJeremy L Thompson for (CeedInt j = 0; j < num_output_fields; j++) { 20711203703bSJeremy L Thompson CeedVector vec; 20721203703bSJeremy L Thompson 20731203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(output_fields[j], &vec)); 2074250756a7Sjeremylt if (vec != CEED_VECTOR_ACTIVE && vec != CEED_VECTOR_NONE) { 20752b730f8bSJeremy L Thompson CeedCall(CeedVectorSetValue(vec, 0.0)); 2076250756a7Sjeremylt } 2077*681d0ea7SJeremy L Thompson CeedCall(CeedVectorDestroy(&vec)); 2078250756a7Sjeremylt } 2079250756a7Sjeremylt } 2080250756a7Sjeremylt // Apply 2081f754c177SSebastian Grimberg for (CeedInt i = 0; i < num_suboperators; i++) { 2082f754c177SSebastian Grimberg CeedCall(CeedOperatorApplyAdd(sub_operators[i], in, out, request)); 2083cae8b89aSjeremylt } 2084cae8b89aSjeremylt } 20853ca2b39bSJeremy L Thompson } else { 20863ca2b39bSJeremy L Thompson // Standard Operator 20873ca2b39bSJeremy L Thompson if (op->Apply) { 20883ca2b39bSJeremy L Thompson CeedCall(op->Apply(op, in, out, request)); 20893ca2b39bSJeremy L Thompson } else { 20901203703bSJeremy L Thompson CeedInt num_output_fields; 20911203703bSJeremy L Thompson CeedOperatorField *output_fields; 20921203703bSJeremy L Thompson 20931203703bSJeremy L Thompson CeedCall(CeedOperatorGetFields(op, NULL, NULL, &num_output_fields, &output_fields)); 20943ca2b39bSJeremy L Thompson // Zero all output vectors 20951203703bSJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 2096*681d0ea7SJeremy L Thompson bool is_active; 20971203703bSJeremy L Thompson CeedVector vec; 20981c66c397SJeremy L Thompson 20991203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(output_fields[i], &vec)); 2100*681d0ea7SJeremy L Thompson is_active = vec == CEED_VECTOR_ACTIVE; 2101*681d0ea7SJeremy L Thompson if (is_active) vec = out; 21023ca2b39bSJeremy L Thompson if (vec != CEED_VECTOR_NONE) CeedCall(CeedVectorSetValue(vec, 0.0)); 2103*681d0ea7SJeremy L Thompson if (!is_active) CeedCall(CeedVectorDestroy(&vec)); 21043ca2b39bSJeremy L Thompson } 21053ca2b39bSJeremy L Thompson // Apply 21061203703bSJeremy L Thompson if (op->num_elem > 0) CeedCall(op->ApplyAdd(op, in, out, request)); 21073ca2b39bSJeremy L Thompson } 2108250756a7Sjeremylt } 2109e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 2110cae8b89aSjeremylt } 2111cae8b89aSjeremylt 2112cae8b89aSjeremylt /** 2113ca94c3ddSJeremy L Thompson @brief Apply `CeedOperator` to a `CeedVector` and add result to output `CeedVector`. 2114cae8b89aSjeremylt 2115ea61e9acSJeremy L Thompson This computes the action of the operator on the specified (active) input, yielding its (active) output. 2116ca94c3ddSJeremy L Thompson All inputs and outputs must be specified using @ref CeedOperatorSetField(). 2117cae8b89aSjeremylt 2118ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to apply 2119ca94c3ddSJeremy L Thompson @param[in] in `CeedVector` containing input state or @ref CEED_VECTOR_NONE if there are no active inputs 2120ca94c3ddSJeremy 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 2121ca94c3ddSJeremy L Thompson @param[in] request Address of @ref CeedRequest for non-blocking completion, else @ref CEED_REQUEST_IMMEDIATE 2122cae8b89aSjeremylt 2123cae8b89aSjeremylt @return An error code: 0 - success, otherwise - failure 2124cae8b89aSjeremylt 21257a982d89SJeremy L. Thompson @ref User 2126cae8b89aSjeremylt **/ 21272b730f8bSJeremy L Thompson int CeedOperatorApplyAdd(CeedOperator op, CeedVector in, CeedVector out, CeedRequest *request) { 21281203703bSJeremy L Thompson bool is_composite; 21291203703bSJeremy L Thompson 21302b730f8bSJeremy L Thompson CeedCall(CeedOperatorCheckReady(op)); 2131cae8b89aSjeremylt 21321203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 21331203703bSJeremy L Thompson if (is_composite) { 2134250756a7Sjeremylt // Composite Operator 2135250756a7Sjeremylt if (op->ApplyAddComposite) { 21362b730f8bSJeremy L Thompson CeedCall(op->ApplyAddComposite(op, in, out, request)); 2137cae8b89aSjeremylt } else { 2138d1d35e2fSjeremylt CeedInt num_suboperators; 2139d1d35e2fSjeremylt CeedOperator *sub_operators; 2140250756a7Sjeremylt 21411c66c397SJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 21421c66c397SJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 2143d1d35e2fSjeremylt for (CeedInt i = 0; i < num_suboperators; i++) { 21442b730f8bSJeremy L Thompson CeedCall(CeedOperatorApplyAdd(sub_operators[i], in, out, request)); 21451d7d2407SJeremy L Thompson } 2146250756a7Sjeremylt } 21471203703bSJeremy L Thompson } else if (op->num_elem > 0) { 21483ca2b39bSJeremy L Thompson // Standard Operator 21493ca2b39bSJeremy L Thompson CeedCall(op->ApplyAdd(op, in, out, request)); 2150250756a7Sjeremylt } 2151e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 2152d7b241e6Sjeremylt } 2153d7b241e6Sjeremylt 2154d7b241e6Sjeremylt /** 2155536b928cSSebastian Grimberg @brief Destroy temporary assembly data associated with a `CeedOperator` 2156536b928cSSebastian Grimberg 2157536b928cSSebastian Grimberg @param[in,out] op `CeedOperator` whose assembly data to destroy 2158536b928cSSebastian Grimberg 2159536b928cSSebastian Grimberg @return An error code: 0 - success, otherwise - failure 2160536b928cSSebastian Grimberg 2161536b928cSSebastian Grimberg @ref User 2162536b928cSSebastian Grimberg **/ 2163536b928cSSebastian Grimberg int CeedOperatorAssemblyDataStrip(CeedOperator op) { 2164536b928cSSebastian Grimberg bool is_composite; 2165536b928cSSebastian Grimberg 2166536b928cSSebastian Grimberg CeedCall(CeedQFunctionAssemblyDataDestroy(&op->qf_assembled)); 2167536b928cSSebastian Grimberg CeedCall(CeedOperatorAssemblyDataDestroy(&op->op_assembled)); 2168536b928cSSebastian Grimberg CeedCall(CeedOperatorIsComposite(op, &is_composite)); 2169536b928cSSebastian Grimberg if (is_composite) { 2170536b928cSSebastian Grimberg CeedInt num_suboperators; 2171536b928cSSebastian Grimberg CeedOperator *sub_operators; 2172536b928cSSebastian Grimberg 2173536b928cSSebastian Grimberg CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 2174536b928cSSebastian Grimberg CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 2175536b928cSSebastian Grimberg for (CeedInt i = 0; i < num_suboperators; i++) { 2176536b928cSSebastian Grimberg CeedCall(CeedQFunctionAssemblyDataDestroy(&sub_operators[i]->qf_assembled)); 2177536b928cSSebastian Grimberg CeedCall(CeedOperatorAssemblyDataDestroy(&sub_operators[i]->op_assembled)); 2178536b928cSSebastian Grimberg } 2179536b928cSSebastian Grimberg } 2180536b928cSSebastian Grimberg return CEED_ERROR_SUCCESS; 2181536b928cSSebastian Grimberg } 2182536b928cSSebastian Grimberg 2183536b928cSSebastian Grimberg /** 2184ca94c3ddSJeremy L Thompson @brief Destroy a `CeedOperator` 2185d7b241e6Sjeremylt 2186ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` to destroy 2187b11c1e72Sjeremylt 2188b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 2189dfdf5a53Sjeremylt 21907a982d89SJeremy L. Thompson @ref User 2191b11c1e72Sjeremylt **/ 2192d7b241e6Sjeremylt int CeedOperatorDestroy(CeedOperator *op) { 2193ad6481ceSJeremy L Thompson if (!*op || --(*op)->ref_count > 0) { 2194ad6481ceSJeremy L Thompson *op = NULL; 2195ad6481ceSJeremy L Thompson return CEED_ERROR_SUCCESS; 2196ad6481ceSJeremy L Thompson } 2197f883f0a5SSebastian Grimberg // Backend destroy 2198f883f0a5SSebastian Grimberg if ((*op)->Destroy) { 2199f883f0a5SSebastian Grimberg CeedCall((*op)->Destroy(*op)); 2200f883f0a5SSebastian Grimberg } 2201fe2413ffSjeremylt // Free fields 22022b730f8bSJeremy L Thompson for (CeedInt i = 0; i < (*op)->num_fields; i++) { 2203d1d35e2fSjeremylt if ((*op)->input_fields[i]) { 2204437c7c90SJeremy L Thompson if ((*op)->input_fields[i]->elem_rstr != CEED_ELEMRESTRICTION_NONE) { 2205437c7c90SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&(*op)->input_fields[i]->elem_rstr)); 220615910d16Sjeremylt } 2207356036faSJeremy L Thompson if ((*op)->input_fields[i]->basis != CEED_BASIS_NONE) { 22082b730f8bSJeremy L Thompson CeedCall(CeedBasisDestroy(&(*op)->input_fields[i]->basis)); 220971352a93Sjeremylt } 22102b730f8bSJeremy L Thompson if ((*op)->input_fields[i]->vec != CEED_VECTOR_ACTIVE && (*op)->input_fields[i]->vec != CEED_VECTOR_NONE) { 22112b730f8bSJeremy L Thompson CeedCall(CeedVectorDestroy(&(*op)->input_fields[i]->vec)); 221271352a93Sjeremylt } 22132b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->input_fields[i]->field_name)); 22142b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->input_fields[i])); 2215fe2413ffSjeremylt } 22162b730f8bSJeremy L Thompson } 22172b730f8bSJeremy L Thompson for (CeedInt i = 0; i < (*op)->num_fields; i++) { 2218d1d35e2fSjeremylt if ((*op)->output_fields[i]) { 2219437c7c90SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&(*op)->output_fields[i]->elem_rstr)); 2220356036faSJeremy L Thompson if ((*op)->output_fields[i]->basis != CEED_BASIS_NONE) { 22212b730f8bSJeremy L Thompson CeedCall(CeedBasisDestroy(&(*op)->output_fields[i]->basis)); 222271352a93Sjeremylt } 22232b730f8bSJeremy L Thompson if ((*op)->output_fields[i]->vec != CEED_VECTOR_ACTIVE && (*op)->output_fields[i]->vec != CEED_VECTOR_NONE) { 22242b730f8bSJeremy L Thompson CeedCall(CeedVectorDestroy(&(*op)->output_fields[i]->vec)); 222571352a93Sjeremylt } 22262b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->output_fields[i]->field_name)); 22272b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->output_fields[i])); 22282b730f8bSJeremy L Thompson } 2229fe2413ffSjeremylt } 2230f883f0a5SSebastian Grimberg CeedCall(CeedFree(&(*op)->input_fields)); 2231f883f0a5SSebastian Grimberg CeedCall(CeedFree(&(*op)->output_fields)); 2232f883f0a5SSebastian Grimberg // Destroy AtPoints data 223348acf710SJeremy L Thompson CeedCall(CeedVectorDestroy(&(*op)->point_coords)); 223448acf710SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&(*op)->rstr_points)); 223548acf710SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&(*op)->first_points_rstr)); 2236c6b536a8SSebastian Grimberg // Destroy assembly data (must happen before destroying sub_operators) 2237f883f0a5SSebastian Grimberg CeedCall(CeedOperatorAssemblyDataStrip(*op)); 2238d1d35e2fSjeremylt // Destroy sub_operators 22392b730f8bSJeremy L Thompson for (CeedInt i = 0; i < (*op)->num_suboperators; i++) { 2240d1d35e2fSjeremylt if ((*op)->sub_operators[i]) { 22412b730f8bSJeremy L Thompson CeedCall(CeedOperatorDestroy(&(*op)->sub_operators[i])); 224252d6035fSJeremy L Thompson } 22432b730f8bSJeremy L Thompson } 2244f883f0a5SSebastian Grimberg CeedCall(CeedFree(&(*op)->sub_operators)); 22452b730f8bSJeremy L Thompson CeedCall(CeedQFunctionDestroy(&(*op)->qf)); 22462b730f8bSJeremy L Thompson CeedCall(CeedQFunctionDestroy(&(*op)->dqf)); 22472b730f8bSJeremy L Thompson CeedCall(CeedQFunctionDestroy(&(*op)->dqfT)); 22483668ca4bSJeremy L Thompson // Destroy any composite labels 22495ac9af79SJeremy L Thompson if ((*op)->is_composite) { 22503668ca4bSJeremy L Thompson for (CeedInt i = 0; i < (*op)->num_context_labels; i++) { 22512b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->context_labels[i]->sub_labels)); 22522b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->context_labels[i])); 22533668ca4bSJeremy L Thompson } 22545ac9af79SJeremy L Thompson } 22552b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->context_labels)); 2256fe2413ffSjeremylt 22575107b09fSJeremy L Thompson // Destroy fallback 22582b730f8bSJeremy L Thompson CeedCall(CeedOperatorDestroy(&(*op)->op_fallback)); 22595107b09fSJeremy L Thompson 22602b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->name)); 2261f883f0a5SSebastian Grimberg CeedCall(CeedDestroy(&(*op)->ceed)); 22622b730f8bSJeremy L Thompson CeedCall(CeedFree(op)); 2263e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 2264d7b241e6Sjeremylt } 2265d7b241e6Sjeremylt 2266d7b241e6Sjeremylt /// @} 2267