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); 121e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 1227a982d89SJeremy L. Thompson } 1237a982d89SJeremy L. Thompson 1247a982d89SJeremy L. Thompson /** 125ca94c3ddSJeremy L Thompson @brief View a single `CeedOperator` 1267a982d89SJeremy L. Thompson 127ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to view 1287a982d89SJeremy L. Thompson @param[in] sub Boolean flag for sub-operator 129ca94c3ddSJeremy L Thompson @param[in] stream Stream to write; typically `stdout` or a file 1307a982d89SJeremy L. Thompson 1317a982d89SJeremy L. Thompson @return Error code: 0 - success, otherwise - failure 1327a982d89SJeremy L. Thompson 1337a982d89SJeremy L. Thompson @ref Utility 1347a982d89SJeremy L. Thompson **/ 1357a982d89SJeremy L. Thompson int CeedOperatorSingleView(CeedOperator op, bool sub, FILE *stream) { 1367a982d89SJeremy L. Thompson const char *pre = sub ? " " : ""; 1371203703bSJeremy L Thompson CeedInt num_elem, num_qpts, total_fields = 0, num_input_fields, num_output_fields; 1381203703bSJeremy L Thompson CeedQFunction qf; 1391203703bSJeremy L Thompson CeedQFunctionField *qf_input_fields, *qf_output_fields; 1401203703bSJeremy L Thompson CeedOperatorField *op_input_fields, *op_output_fields; 1417a982d89SJeremy L. Thompson 1422b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetNumElements(op, &num_elem)); 1432b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetNumQuadraturePoints(op, &num_qpts)); 1442b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetNumArgs(op, &total_fields)); 1451203703bSJeremy L Thompson CeedCall(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields)); 1461203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 1471203703bSJeremy L Thompson CeedCall(CeedQFunctionGetFields(qf, NULL, &qf_input_fields, NULL, &qf_output_fields)); 1481c66c397SJeremy L Thompson 1492b730f8bSJeremy L Thompson fprintf(stream, "%s %" CeedInt_FMT " elements with %" CeedInt_FMT " quadrature points each\n", pre, num_elem, num_qpts); 1502b730f8bSJeremy L Thompson fprintf(stream, "%s %" CeedInt_FMT " field%s\n", pre, total_fields, total_fields > 1 ? "s" : ""); 1511203703bSJeremy L Thompson fprintf(stream, "%s %" CeedInt_FMT " input field%s:\n", pre, num_input_fields, num_input_fields > 1 ? "s" : ""); 1521203703bSJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 1531203703bSJeremy L Thompson CeedCall(CeedOperatorFieldView(op_input_fields[i], qf_input_fields[i], i, sub, 1, stream)); 1547a982d89SJeremy L. Thompson } 1551203703bSJeremy L Thompson fprintf(stream, "%s %" CeedInt_FMT " output field%s:\n", pre, num_output_fields, num_output_fields > 1 ? "s" : ""); 1561203703bSJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 1571203703bSJeremy L Thompson CeedCall(CeedOperatorFieldView(op_output_fields[i], qf_output_fields[i], i, sub, 0, stream)); 1587a982d89SJeremy L. Thompson } 159e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 1607a982d89SJeremy L. Thompson } 1617a982d89SJeremy L. Thompson 162d99fa3c5SJeremy L Thompson /** 163ca94c3ddSJeremy L Thompson @brief Find the active input vector `CeedBasis` for a non-composite `CeedOperator` 164eaf62fffSJeremy L Thompson 165ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to find active `CeedBasis` for 166ca94c3ddSJeremy L Thompson @param[out] active_basis `CeedBasis` for active input vector or `NULL` for composite operator 167eaf62fffSJeremy L Thompson 168eaf62fffSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 169eaf62fffSJeremy L Thompson 170eaf62fffSJeremy L Thompson @ref Developer 171eaf62fffSJeremy L Thompson **/ 172eaf62fffSJeremy L Thompson int CeedOperatorGetActiveBasis(CeedOperator op, CeedBasis *active_basis) { 173506b1a0cSSebastian Grimberg CeedCall(CeedOperatorGetActiveBases(op, active_basis, NULL)); 174506b1a0cSSebastian Grimberg return CEED_ERROR_SUCCESS; 175506b1a0cSSebastian Grimberg } 176506b1a0cSSebastian Grimberg 177506b1a0cSSebastian Grimberg /** 178ca94c3ddSJeremy L Thompson @brief Find the active input and output vector `CeedBasis` for a non-composite `CeedOperator` 179506b1a0cSSebastian Grimberg 180ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to find active `CeedBasis` for 181ca94c3ddSJeremy L Thompson @param[out] active_input_basis `CeedBasis` for active input vector or `NULL` for composite operator 182ca94c3ddSJeremy L Thompson @param[out] active_output_basis `CeedBasis` for active output vector or `NULL` for composite operator 183506b1a0cSSebastian Grimberg 184506b1a0cSSebastian Grimberg @return An error code: 0 - success, otherwise - failure 185506b1a0cSSebastian Grimberg 186506b1a0cSSebastian Grimberg @ref Developer 187506b1a0cSSebastian Grimberg **/ 188506b1a0cSSebastian Grimberg int CeedOperatorGetActiveBases(CeedOperator op, CeedBasis *active_input_basis, CeedBasis *active_output_basis) { 1891203703bSJeremy L Thompson bool is_composite; 1901203703bSJeremy L Thompson CeedInt num_input_fields, num_output_fields; 1916aaed0edSJeremy L Thompson Ceed ceed; 1921203703bSJeremy L Thompson CeedOperatorField *op_input_fields, *op_output_fields; 1931c66c397SJeremy L Thompson 1946aaed0edSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 1951203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 1961203703bSJeremy L Thompson CeedCall(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields)); 1971203703bSJeremy L Thompson 198506b1a0cSSebastian Grimberg if (active_input_basis) { 199506b1a0cSSebastian Grimberg *active_input_basis = NULL; 2001203703bSJeremy L Thompson if (!is_composite) { 2011203703bSJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 2021203703bSJeremy L Thompson CeedVector vec; 2031203703bSJeremy L Thompson 2041203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(op_input_fields[i], &vec)); 2051203703bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 2061203703bSJeremy L Thompson CeedBasis basis; 2071203703bSJeremy L Thompson 2081203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetBasis(op_input_fields[i], &basis)); 2091203703bSJeremy L Thompson CeedCheck(!*active_input_basis || *active_input_basis == basis, ceed, CEED_ERROR_MINOR, "Multiple active input CeedBases found"); 2101203703bSJeremy L Thompson *active_input_basis = basis; 211eaf62fffSJeremy L Thompson } 2122b730f8bSJeremy L Thompson } 213506b1a0cSSebastian Grimberg CeedCheck(*active_input_basis, ceed, CEED_ERROR_INCOMPLETE, "No active input CeedBasis found"); 214506b1a0cSSebastian Grimberg } 215506b1a0cSSebastian Grimberg } 216506b1a0cSSebastian Grimberg if (active_output_basis) { 217506b1a0cSSebastian Grimberg *active_output_basis = NULL; 2181203703bSJeremy L Thompson if (!is_composite) { 2191203703bSJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 2201203703bSJeremy L Thompson CeedVector vec; 2211203703bSJeremy L Thompson 2221203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(op_output_fields[i], &vec)); 2231203703bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 2241203703bSJeremy L Thompson CeedBasis basis; 2251203703bSJeremy L Thompson 2261203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetBasis(op_output_fields[i], &basis)); 2271203703bSJeremy L Thompson CeedCheck(!*active_output_basis || *active_output_basis == basis, ceed, CEED_ERROR_MINOR, "Multiple active output CeedBases found"); 2281203703bSJeremy L Thompson *active_output_basis = basis; 229506b1a0cSSebastian Grimberg } 230506b1a0cSSebastian Grimberg } 231506b1a0cSSebastian Grimberg CeedCheck(*active_output_basis, ceed, CEED_ERROR_INCOMPLETE, "No active output CeedBasis found"); 232506b1a0cSSebastian Grimberg } 233506b1a0cSSebastian Grimberg } 234eaf62fffSJeremy L Thompson return CEED_ERROR_SUCCESS; 235eaf62fffSJeremy L Thompson } 236eaf62fffSJeremy L Thompson 237eaf62fffSJeremy L Thompson /** 238ca94c3ddSJeremy L Thompson @brief Find the active vector `CeedElemRestriction` for a non-composite `CeedOperator` 239e2f04181SAndrew T. Barker 240ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to find active `CeedElemRestriction` for 241ca94c3ddSJeremy L Thompson @param[out] active_rstr `CeedElemRestriction` for active input vector or NULL for composite operator 242e2f04181SAndrew T. Barker 243e2f04181SAndrew T. Barker @return An error code: 0 - success, otherwise - failure 244e2f04181SAndrew T. Barker 245e2f04181SAndrew T. Barker @ref Utility 246e2f04181SAndrew T. Barker **/ 2472b730f8bSJeremy L Thompson int CeedOperatorGetActiveElemRestriction(CeedOperator op, CeedElemRestriction *active_rstr) { 248506b1a0cSSebastian Grimberg CeedCall(CeedOperatorGetActiveElemRestrictions(op, active_rstr, NULL)); 249506b1a0cSSebastian Grimberg return CEED_ERROR_SUCCESS; 250506b1a0cSSebastian Grimberg } 251506b1a0cSSebastian Grimberg 252506b1a0cSSebastian Grimberg /** 253ca94c3ddSJeremy L Thompson @brief Find the active input and output vector `CeedElemRestriction` for a non-composite `CeedOperator` 254506b1a0cSSebastian Grimberg 255ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to find active `CeedElemRestriction` for 256ca94c3ddSJeremy L Thompson @param[out] active_input_rstr `CeedElemRestriction` for active input vector or NULL for composite operator 257ca94c3ddSJeremy L Thompson @param[out] active_output_rstr `CeedElemRestriction` for active output vector or NULL for composite operator 258506b1a0cSSebastian Grimberg 259506b1a0cSSebastian Grimberg @return An error code: 0 - success, otherwise - failure 260506b1a0cSSebastian Grimberg 261506b1a0cSSebastian Grimberg @ref Utility 262506b1a0cSSebastian Grimberg **/ 263506b1a0cSSebastian Grimberg int CeedOperatorGetActiveElemRestrictions(CeedOperator op, CeedElemRestriction *active_input_rstr, CeedElemRestriction *active_output_rstr) { 2641203703bSJeremy L Thompson bool is_composite; 2651203703bSJeremy L Thompson CeedInt num_input_fields, num_output_fields; 2666aaed0edSJeremy L Thompson Ceed ceed; 2671203703bSJeremy L Thompson CeedOperatorField *op_input_fields, *op_output_fields; 2681c66c397SJeremy L Thompson 2696aaed0edSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 2701203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 2711203703bSJeremy L Thompson CeedCall(CeedOperatorGetFields(op, &num_input_fields, &op_input_fields, &num_output_fields, &op_output_fields)); 2721203703bSJeremy L Thompson 273506b1a0cSSebastian Grimberg if (active_input_rstr) { 274506b1a0cSSebastian Grimberg *active_input_rstr = NULL; 2751203703bSJeremy L Thompson if (!is_composite) { 2761203703bSJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 2771203703bSJeremy L Thompson CeedVector vec; 2781203703bSJeremy L Thompson 2791203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(op_input_fields[i], &vec)); 2801203703bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 2811203703bSJeremy L Thompson CeedElemRestriction rstr; 2821203703bSJeremy L Thompson 2831203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetElemRestriction(op_input_fields[i], &rstr)); 2841203703bSJeremy L Thompson CeedCheck(!*active_input_rstr || *active_input_rstr == rstr, ceed, CEED_ERROR_MINOR, "Multiple active input CeedElemRestrictions found"); 2851203703bSJeremy L Thompson *active_input_rstr = rstr; 286e2f04181SAndrew T. Barker } 2872b730f8bSJeremy L Thompson } 288506b1a0cSSebastian Grimberg CeedCheck(*active_input_rstr, ceed, CEED_ERROR_INCOMPLETE, "No active input CeedElemRestriction found"); 289506b1a0cSSebastian Grimberg } 290506b1a0cSSebastian Grimberg } 291506b1a0cSSebastian Grimberg if (active_output_rstr) { 292506b1a0cSSebastian Grimberg *active_output_rstr = NULL; 2931203703bSJeremy L Thompson if (!is_composite) { 2941203703bSJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 2951203703bSJeremy L Thompson CeedVector vec; 2961203703bSJeremy L Thompson 2971203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(op_output_fields[i], &vec)); 2981203703bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 2991203703bSJeremy L Thompson CeedElemRestriction rstr; 3001203703bSJeremy L Thompson 3011203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetElemRestriction(op_output_fields[i], &rstr)); 3021203703bSJeremy L Thompson CeedCheck(!*active_output_rstr || *active_output_rstr == rstr, ceed, CEED_ERROR_MINOR, "Multiple active output CeedElemRestrictions found"); 3031203703bSJeremy L Thompson *active_output_rstr = rstr; 304506b1a0cSSebastian Grimberg } 305506b1a0cSSebastian Grimberg } 306506b1a0cSSebastian Grimberg CeedCheck(*active_output_rstr, ceed, CEED_ERROR_INCOMPLETE, "No active output CeedElemRestriction found"); 307506b1a0cSSebastian Grimberg } 308506b1a0cSSebastian Grimberg } 309e2f04181SAndrew T. Barker return CEED_ERROR_SUCCESS; 310e2f04181SAndrew T. Barker } 311e2f04181SAndrew T. Barker 312d8dd9a91SJeremy L Thompson /** 313ca94c3ddSJeremy L Thompson @brief Set `CeedQFunctionContext` field values of the specified type. 3144385fb7fSSebastian Grimberg 315ca94c3ddSJeremy L Thompson For composite operators, the value is set in all sub-operator `CeedQFunctionContext` that have a matching `field_name`. 316ca94c3ddSJeremy 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. 317d8dd9a91SJeremy L Thompson 318ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 319ea61e9acSJeremy L Thompson @param[in] field_label Label of field to set 320ea61e9acSJeremy L Thompson @param[in] field_type Type of field to set 3212788fa27SJeremy L Thompson @param[in] values Values to set 322d8dd9a91SJeremy L Thompson 323d8dd9a91SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 324d8dd9a91SJeremy L Thompson 325d8dd9a91SJeremy L Thompson @ref User 326d8dd9a91SJeremy L Thompson **/ 3272788fa27SJeremy L Thompson static int CeedOperatorContextSetGeneric(CeedOperator op, CeedContextFieldLabel field_label, CeedContextFieldType field_type, void *values) { 3281c66c397SJeremy L Thompson bool is_composite = false; 3291203703bSJeremy L Thompson Ceed ceed; 3301c66c397SJeremy L Thompson 3311203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 3321203703bSJeremy L Thompson CeedCheck(field_label, ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label"); 3333668ca4bSJeremy L Thompson 3345ac9af79SJeremy L Thompson // Check if field_label and op correspond 3355ac9af79SJeremy L Thompson if (field_label->from_op) { 3365ac9af79SJeremy L Thompson CeedInt index = -1; 3375ac9af79SJeremy L Thompson 3385ac9af79SJeremy L Thompson for (CeedInt i = 0; i < op->num_context_labels; i++) { 3395ac9af79SJeremy L Thompson if (op->context_labels[i] == field_label) index = i; 3405ac9af79SJeremy L Thompson } 3411203703bSJeremy L Thompson CeedCheck(index != -1, ceed, CEED_ERROR_UNSUPPORTED, "ContextFieldLabel does not correspond to the operator"); 3425ac9af79SJeremy L Thompson } 3435ac9af79SJeremy L Thompson 3442b730f8bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 345d8dd9a91SJeremy L Thompson if (is_composite) { 346d8dd9a91SJeremy L Thompson CeedInt num_sub; 347d8dd9a91SJeremy L Thompson CeedOperator *sub_operators; 348d8dd9a91SJeremy L Thompson 349c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub)); 350c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 3511203703bSJeremy L Thompson CeedCheck(num_sub == field_label->num_sub_labels, ceed, CEED_ERROR_UNSUPPORTED, "Composite operator modified after ContextFieldLabel created"); 352d8dd9a91SJeremy L Thompson 353d8dd9a91SJeremy L Thompson for (CeedInt i = 0; i < num_sub; i++) { 3541203703bSJeremy L Thompson CeedQFunction qf; 3551203703bSJeremy L Thompson CeedQFunctionContext ctx; 3561203703bSJeremy L Thompson 3571203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(sub_operators[i], &qf)); 3581203703bSJeremy L Thompson CeedCall(CeedQFunctionGetContext(qf, &ctx)); 359d8dd9a91SJeremy L Thompson // Try every sub-operator, ok if some sub-operators do not have field 3601203703bSJeremy L Thompson if (field_label->sub_labels[i] && ctx) { 3611203703bSJeremy L Thompson CeedCall(CeedQFunctionContextSetGeneric(ctx, field_label->sub_labels[i], field_type, values)); 362d8dd9a91SJeremy L Thompson } 363d8dd9a91SJeremy L Thompson } 364d8dd9a91SJeremy L Thompson } else { 3651203703bSJeremy L Thompson CeedQFunction qf; 3661203703bSJeremy L Thompson CeedQFunctionContext ctx; 3671203703bSJeremy L Thompson 3681203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 3691203703bSJeremy L Thompson CeedCall(CeedQFunctionGetContext(qf, &ctx)); 3701203703bSJeremy L Thompson CeedCheck(ctx, ceed, CEED_ERROR_UNSUPPORTED, "QFunction does not have context data"); 3711203703bSJeremy L Thompson CeedCall(CeedQFunctionContextSetGeneric(ctx, field_label, field_type, values)); 3722788fa27SJeremy L Thompson } 3736d95ab46SJeremy L Thompson CeedCall(CeedOperatorSetQFunctionAssemblyDataUpdateNeeded(op, true)); 3742788fa27SJeremy L Thompson return CEED_ERROR_SUCCESS; 3752788fa27SJeremy L Thompson } 3762788fa27SJeremy L Thompson 3772788fa27SJeremy L Thompson /** 378ca94c3ddSJeremy L Thompson @brief Get `CeedQFunctionContext` field values of the specified type, read-only. 3794385fb7fSSebastian Grimberg 380ca94c3ddSJeremy L Thompson For composite operators, the values retrieved are for the first sub-operator `CeedQFunctionContext` that have a matching `field_name`. 381ca94c3ddSJeremy 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. 3822788fa27SJeremy L Thompson 383ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 3842788fa27SJeremy L Thompson @param[in] field_label Label of field to set 3852788fa27SJeremy L Thompson @param[in] field_type Type of field to set 386c5d0f995SJed Brown @param[out] num_values Number of values of type `field_type` in array `values` 387c5d0f995SJed Brown @param[out] values Values in the label 3882788fa27SJeremy L Thompson 3892788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 3902788fa27SJeremy L Thompson 3912788fa27SJeremy L Thompson @ref User 3922788fa27SJeremy L Thompson **/ 3932788fa27SJeremy L Thompson static int CeedOperatorContextGetGenericRead(CeedOperator op, CeedContextFieldLabel field_label, CeedContextFieldType field_type, size_t *num_values, 3942788fa27SJeremy L Thompson void *values) { 3951c66c397SJeremy L Thompson bool is_composite = false; 3961203703bSJeremy L Thompson Ceed ceed; 3971c66c397SJeremy L Thompson 3981203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 3991203703bSJeremy L Thompson CeedCheck(field_label, ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label"); 4002788fa27SJeremy L Thompson 4012788fa27SJeremy L Thompson *(void **)values = NULL; 4022788fa27SJeremy L Thompson *num_values = 0; 4032788fa27SJeremy L Thompson 4045ac9af79SJeremy L Thompson // Check if field_label and op correspond 4055ac9af79SJeremy L Thompson if (field_label->from_op) { 4065ac9af79SJeremy L Thompson CeedInt index = -1; 4075ac9af79SJeremy L Thompson 4085ac9af79SJeremy L Thompson for (CeedInt i = 0; i < op->num_context_labels; i++) { 4095ac9af79SJeremy L Thompson if (op->context_labels[i] == field_label) index = i; 4105ac9af79SJeremy L Thompson } 4116e536b99SJeremy L Thompson CeedCheck(index != -1, ceed, CEED_ERROR_UNSUPPORTED, "ContextFieldLabel does not correspond to the operator"); 4125ac9af79SJeremy L Thompson } 4135ac9af79SJeremy L Thompson 4142788fa27SJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 4152788fa27SJeremy L Thompson if (is_composite) { 4162788fa27SJeremy L Thompson CeedInt num_sub; 4172788fa27SJeremy L Thompson CeedOperator *sub_operators; 4182788fa27SJeremy L Thompson 4192788fa27SJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub)); 4202788fa27SJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 4211203703bSJeremy L Thompson CeedCheck(num_sub == field_label->num_sub_labels, ceed, CEED_ERROR_UNSUPPORTED, "Composite operator modified after ContextFieldLabel created"); 4222788fa27SJeremy L Thompson 4232788fa27SJeremy L Thompson for (CeedInt i = 0; i < num_sub; i++) { 4241203703bSJeremy L Thompson CeedQFunction qf; 4251203703bSJeremy L Thompson CeedQFunctionContext ctx; 4261203703bSJeremy L Thompson 4271203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(sub_operators[i], &qf)); 4281203703bSJeremy L Thompson CeedCall(CeedQFunctionGetContext(qf, &ctx)); 4292788fa27SJeremy L Thompson // Try every sub-operator, ok if some sub-operators do not have field 4301203703bSJeremy L Thompson if (field_label->sub_labels[i] && ctx) { 4311203703bSJeremy L Thompson CeedCall(CeedQFunctionContextGetGenericRead(ctx, field_label->sub_labels[i], field_type, num_values, values)); 4322788fa27SJeremy L Thompson return CEED_ERROR_SUCCESS; 4332788fa27SJeremy L Thompson } 4342788fa27SJeremy L Thompson } 4352788fa27SJeremy L Thompson } else { 4361203703bSJeremy L Thompson CeedQFunction qf; 4371203703bSJeremy L Thompson CeedQFunctionContext ctx; 4381203703bSJeremy L Thompson 4391203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 4401203703bSJeremy L Thompson CeedCall(CeedQFunctionGetContext(qf, &ctx)); 4411203703bSJeremy L Thompson CeedCheck(ctx, ceed, CEED_ERROR_UNSUPPORTED, "QFunction does not have context data"); 4421203703bSJeremy L Thompson CeedCall(CeedQFunctionContextGetGenericRead(ctx, field_label, field_type, num_values, values)); 4432788fa27SJeremy L Thompson } 4442788fa27SJeremy L Thompson return CEED_ERROR_SUCCESS; 4452788fa27SJeremy L Thompson } 4462788fa27SJeremy L Thompson 4472788fa27SJeremy L Thompson /** 448ca94c3ddSJeremy L Thompson @brief Restore `CeedQFunctionContext` field values of the specified type, read-only. 4494385fb7fSSebastian Grimberg 450ca94c3ddSJeremy L Thompson For composite operators, the values restored are for the first sub-operator `CeedQFunctionContext` that have a matching `field_name`. 451ca94c3ddSJeremy 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. 4522788fa27SJeremy L Thompson 453ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 4542788fa27SJeremy L Thompson @param[in] field_label Label of field to set 4552788fa27SJeremy L Thompson @param[in] field_type Type of field to set 456c5d0f995SJed Brown @param[in] values Values array to restore 4572788fa27SJeremy L Thompson 4582788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 4592788fa27SJeremy L Thompson 4602788fa27SJeremy L Thompson @ref User 4612788fa27SJeremy L Thompson **/ 4622788fa27SJeremy L Thompson static int CeedOperatorContextRestoreGenericRead(CeedOperator op, CeedContextFieldLabel field_label, CeedContextFieldType field_type, void *values) { 4631c66c397SJeremy L Thompson bool is_composite = false; 4641203703bSJeremy L Thompson Ceed ceed; 4651c66c397SJeremy L Thompson 4661203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 4671203703bSJeremy L Thompson CeedCheck(field_label, ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label"); 4682788fa27SJeremy L Thompson 4695ac9af79SJeremy L Thompson // Check if field_label and op correspond 4705ac9af79SJeremy L Thompson if (field_label->from_op) { 4715ac9af79SJeremy L Thompson CeedInt index = -1; 4725ac9af79SJeremy L Thompson 4735ac9af79SJeremy L Thompson for (CeedInt i = 0; i < op->num_context_labels; i++) { 4745ac9af79SJeremy L Thompson if (op->context_labels[i] == field_label) index = i; 4755ac9af79SJeremy L Thompson } 4766e536b99SJeremy L Thompson CeedCheck(index != -1, ceed, CEED_ERROR_UNSUPPORTED, "ContextFieldLabel does not correspond to the operator"); 4775ac9af79SJeremy L Thompson } 4785ac9af79SJeremy L Thompson 4792788fa27SJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 4802788fa27SJeremy L Thompson if (is_composite) { 4812788fa27SJeremy L Thompson CeedInt num_sub; 4822788fa27SJeremy L Thompson CeedOperator *sub_operators; 4832788fa27SJeremy L Thompson 4842788fa27SJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub)); 4852788fa27SJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 4866e536b99SJeremy L Thompson CeedCheck(num_sub == field_label->num_sub_labels, ceed, CEED_ERROR_UNSUPPORTED, "Composite operator modified after ContextFieldLabel created"); 4872788fa27SJeremy L Thompson 4882788fa27SJeremy L Thompson for (CeedInt i = 0; i < num_sub; i++) { 4891203703bSJeremy L Thompson CeedQFunction qf; 4901203703bSJeremy L Thompson CeedQFunctionContext ctx; 4911203703bSJeremy L Thompson 4921203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(sub_operators[i], &qf)); 4931203703bSJeremy L Thompson CeedCall(CeedQFunctionGetContext(qf, &ctx)); 4942788fa27SJeremy L Thompson // Try every sub-operator, ok if some sub-operators do not have field 4951203703bSJeremy L Thompson if (field_label->sub_labels[i] && ctx) { 4961203703bSJeremy L Thompson CeedCall(CeedQFunctionContextRestoreGenericRead(ctx, field_label->sub_labels[i], field_type, values)); 4972788fa27SJeremy L Thompson return CEED_ERROR_SUCCESS; 4982788fa27SJeremy L Thompson } 4992788fa27SJeremy L Thompson } 5002788fa27SJeremy L Thompson } else { 5011203703bSJeremy L Thompson CeedQFunction qf; 5021203703bSJeremy L Thompson CeedQFunctionContext ctx; 5031203703bSJeremy L Thompson 5041203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 5051203703bSJeremy L Thompson CeedCall(CeedQFunctionGetContext(qf, &ctx)); 5061203703bSJeremy L Thompson CeedCheck(ctx, ceed, CEED_ERROR_UNSUPPORTED, "QFunction does not have context data"); 5071203703bSJeremy L Thompson CeedCall(CeedQFunctionContextRestoreGenericRead(ctx, field_label, field_type, values)); 508d8dd9a91SJeremy L Thompson } 509d8dd9a91SJeremy L Thompson return CEED_ERROR_SUCCESS; 510d8dd9a91SJeremy L Thompson } 511d8dd9a91SJeremy L Thompson 5127a982d89SJeremy L. Thompson /// @} 5137a982d89SJeremy L. Thompson 5147a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 5157a982d89SJeremy L. Thompson /// CeedOperator Backend API 5167a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 5177a982d89SJeremy L. Thompson /// @addtogroup CeedOperatorBackend 5187a982d89SJeremy L. Thompson /// @{ 5197a982d89SJeremy L. Thompson 5207a982d89SJeremy L. Thompson /** 521ca94c3ddSJeremy L Thompson @brief Get the number of arguments associated with a `CeedOperator` 5227a982d89SJeremy L. Thompson 523ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 524d1d35e2fSjeremylt @param[out] num_args Variable to store vector number of arguments 5257a982d89SJeremy L. Thompson 5267a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 5277a982d89SJeremy L. Thompson 5287a982d89SJeremy L. Thompson @ref Backend 5297a982d89SJeremy L. Thompson **/ 530d1d35e2fSjeremylt int CeedOperatorGetNumArgs(CeedOperator op, CeedInt *num_args) { 5311203703bSJeremy L Thompson bool is_composite; 5321203703bSJeremy L Thompson 5331203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 5346e536b99SJeremy L Thompson CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Not defined for composite operators"); 535d1d35e2fSjeremylt *num_args = op->num_fields; 536e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 5377a982d89SJeremy L. Thompson } 5387a982d89SJeremy L. Thompson 5397a982d89SJeremy L. Thompson /** 5409463e855SJeremy L Thompson @brief Get the tensor product status of all bases for a `CeedOperator`. 5419463e855SJeremy L Thompson 5429463e855SJeremy L Thompson `has_tensor_bases` is only set to `true` if every field uses a tensor-product basis. 5439463e855SJeremy L Thompson 5449463e855SJeremy L Thompson @param[in] op `CeedOperator` 5459463e855SJeremy L Thompson @param[out] has_tensor_bases Variable to store tensor bases status 5469463e855SJeremy L Thompson 5479463e855SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 5489463e855SJeremy L Thompson 5499463e855SJeremy L Thompson @ref Backend 5509463e855SJeremy L Thompson **/ 5519463e855SJeremy L Thompson int CeedOperatorHasTensorBases(CeedOperator op, bool *has_tensor_bases) { 5529463e855SJeremy L Thompson CeedInt num_inputs, num_outputs; 5539463e855SJeremy L Thompson CeedOperatorField *input_fields, *output_fields; 5549463e855SJeremy L Thompson 5559463e855SJeremy L Thompson CeedCall(CeedOperatorGetFields(op, &num_inputs, &input_fields, &num_outputs, &output_fields)); 5569463e855SJeremy L Thompson *has_tensor_bases = true; 5579463e855SJeremy L Thompson for (CeedInt i = 0; i < num_inputs; i++) { 5589463e855SJeremy L Thompson bool is_tensor; 5599463e855SJeremy L Thompson CeedBasis basis; 5609463e855SJeremy L Thompson 5619463e855SJeremy L Thompson CeedCall(CeedOperatorFieldGetBasis(input_fields[i], &basis)); 5629463e855SJeremy L Thompson if (basis != CEED_BASIS_NONE) { 5639463e855SJeremy L Thompson CeedCall(CeedBasisIsTensor(basis, &is_tensor)); 5649463e855SJeremy L Thompson *has_tensor_bases &= is_tensor; 5659463e855SJeremy L Thompson } 5669463e855SJeremy L Thompson } 5679463e855SJeremy L Thompson for (CeedInt i = 0; i < num_outputs; i++) { 5689463e855SJeremy L Thompson bool is_tensor; 5699463e855SJeremy L Thompson CeedBasis basis; 5709463e855SJeremy L Thompson 5719463e855SJeremy L Thompson CeedCall(CeedOperatorFieldGetBasis(output_fields[i], &basis)); 5729463e855SJeremy L Thompson if (basis != CEED_BASIS_NONE) { 5739463e855SJeremy L Thompson CeedCall(CeedBasisIsTensor(basis, &is_tensor)); 5749463e855SJeremy L Thompson *has_tensor_bases &= is_tensor; 5759463e855SJeremy L Thompson } 5769463e855SJeremy L Thompson } 5779463e855SJeremy L Thompson return CEED_ERROR_SUCCESS; 5789463e855SJeremy L Thompson } 5799463e855SJeremy L Thompson 5809463e855SJeremy L Thompson /** 5811203703bSJeremy L Thompson @brief Get a boolean value indicating if the `CeedOperator` is immutable 5821203703bSJeremy L Thompson 5831203703bSJeremy L Thompson @param[in] op `CeedOperator` 5841203703bSJeremy L Thompson @param[out] is_immutable Variable to store immutability status 5851203703bSJeremy L Thompson 5861203703bSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 5871203703bSJeremy L Thompson 5881203703bSJeremy L Thompson @ref Backend 5891203703bSJeremy L Thompson **/ 5901203703bSJeremy L Thompson int CeedOperatorIsImmutable(CeedOperator op, bool *is_immutable) { 5911203703bSJeremy L Thompson *is_immutable = op->is_immutable; 5921203703bSJeremy L Thompson return CEED_ERROR_SUCCESS; 5931203703bSJeremy L Thompson } 5941203703bSJeremy L Thompson 5951203703bSJeremy L Thompson /** 596ca94c3ddSJeremy L Thompson @brief Get the setup status of a `CeedOperator` 5977a982d89SJeremy L. Thompson 598ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 599d1d35e2fSjeremylt @param[out] is_setup_done Variable to store setup status 6007a982d89SJeremy L. Thompson 6017a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 6027a982d89SJeremy L. Thompson 6037a982d89SJeremy L. Thompson @ref Backend 6047a982d89SJeremy L. Thompson **/ 605d1d35e2fSjeremylt int CeedOperatorIsSetupDone(CeedOperator op, bool *is_setup_done) { 606f04ea552SJeremy L Thompson *is_setup_done = op->is_backend_setup; 607e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 6087a982d89SJeremy L. Thompson } 6097a982d89SJeremy L. Thompson 6107a982d89SJeremy L. Thompson /** 611ca94c3ddSJeremy L Thompson @brief Get the `CeedQFunction` associated with a `CeedOperator` 6127a982d89SJeremy L. Thompson 613ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 614ca94c3ddSJeremy L Thompson @param[out] qf Variable to store `CeedQFunction` 6157a982d89SJeremy L. Thompson 6167a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 6177a982d89SJeremy L. Thompson 6187a982d89SJeremy L. Thompson @ref Backend 6197a982d89SJeremy L. Thompson **/ 6207a982d89SJeremy L. Thompson int CeedOperatorGetQFunction(CeedOperator op, CeedQFunction *qf) { 6211203703bSJeremy L Thompson bool is_composite; 6221203703bSJeremy L Thompson 6231203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 6246e536b99SJeremy L Thompson CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Not defined for composite operator"); 6257a982d89SJeremy L. Thompson *qf = op->qf; 626e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 6277a982d89SJeremy L. Thompson } 6287a982d89SJeremy L. Thompson 6297a982d89SJeremy L. Thompson /** 630ca94c3ddSJeremy L Thompson @brief Get a boolean value indicating if the `CeedOperator` is composite 631c04a41a7SJeremy L Thompson 632ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 633d1d35e2fSjeremylt @param[out] is_composite Variable to store composite status 634c04a41a7SJeremy L Thompson 635c04a41a7SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 636c04a41a7SJeremy L Thompson 637c04a41a7SJeremy L Thompson @ref Backend 638c04a41a7SJeremy L Thompson **/ 639d1d35e2fSjeremylt int CeedOperatorIsComposite(CeedOperator op, bool *is_composite) { 640f04ea552SJeremy L Thompson *is_composite = op->is_composite; 641e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 642c04a41a7SJeremy L Thompson } 643c04a41a7SJeremy L Thompson 644c04a41a7SJeremy L Thompson /** 645ca94c3ddSJeremy L Thompson @brief Get the backend data of a `CeedOperator` 6467a982d89SJeremy L. Thompson 647ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 6487a982d89SJeremy L. Thompson @param[out] data Variable to store data 6497a982d89SJeremy L. Thompson 6507a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 6517a982d89SJeremy L. Thompson 6527a982d89SJeremy L. Thompson @ref Backend 6537a982d89SJeremy L. Thompson **/ 654777ff853SJeremy L Thompson int CeedOperatorGetData(CeedOperator op, void *data) { 655777ff853SJeremy L Thompson *(void **)data = op->data; 656e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 6577a982d89SJeremy L. Thompson } 6587a982d89SJeremy L. Thompson 6597a982d89SJeremy L. Thompson /** 660ca94c3ddSJeremy L Thompson @brief Set the backend data of a `CeedOperator` 6617a982d89SJeremy L. Thompson 662ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 663ea61e9acSJeremy L Thompson @param[in] data Data to set 6647a982d89SJeremy L. Thompson 6657a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 6667a982d89SJeremy L. Thompson 6677a982d89SJeremy L. Thompson @ref Backend 6687a982d89SJeremy L. Thompson **/ 669777ff853SJeremy L Thompson int CeedOperatorSetData(CeedOperator op, void *data) { 670777ff853SJeremy L Thompson op->data = data; 671e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 6727a982d89SJeremy L. Thompson } 6737a982d89SJeremy L. Thompson 6747a982d89SJeremy L. Thompson /** 675ca94c3ddSJeremy L Thompson @brief Increment the reference counter for a `CeedOperator` 67634359f16Sjeremylt 677ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` to increment the reference counter 67834359f16Sjeremylt 67934359f16Sjeremylt @return An error code: 0 - success, otherwise - failure 68034359f16Sjeremylt 68134359f16Sjeremylt @ref Backend 68234359f16Sjeremylt **/ 6839560d06aSjeremylt int CeedOperatorReference(CeedOperator op) { 68434359f16Sjeremylt op->ref_count++; 68534359f16Sjeremylt return CEED_ERROR_SUCCESS; 68634359f16Sjeremylt } 68734359f16Sjeremylt 68834359f16Sjeremylt /** 689ca94c3ddSJeremy L Thompson @brief Set the setup flag of a `CeedOperator` to `true` 6907a982d89SJeremy L. Thompson 691ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 6927a982d89SJeremy L. Thompson 6937a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 6947a982d89SJeremy L. Thompson 6957a982d89SJeremy L. Thompson @ref Backend 6967a982d89SJeremy L. Thompson **/ 6977a982d89SJeremy L. Thompson int CeedOperatorSetSetupDone(CeedOperator op) { 698f04ea552SJeremy L Thompson op->is_backend_setup = true; 699e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 7007a982d89SJeremy L. Thompson } 7017a982d89SJeremy L. Thompson 7027a982d89SJeremy L. Thompson /// @} 7037a982d89SJeremy L. Thompson 7047a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 7057a982d89SJeremy L. Thompson /// CeedOperator Public API 7067a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 7077a982d89SJeremy L. Thompson /// @addtogroup CeedOperatorUser 708dfdf5a53Sjeremylt /// @{ 709d7b241e6Sjeremylt 710d7b241e6Sjeremylt /** 711ca94c3ddSJeremy L Thompson @brief Create a `CeedOperator` and associate a `CeedQFunction`. 7124385fb7fSSebastian Grimberg 713ca94c3ddSJeremy L Thompson A `CeedBasis` and `CeedElemRestriction` can be associated with `CeedQFunction` fields with @ref CeedOperatorSetField(). 714d7b241e6Sjeremylt 715ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` object used to create the `CeedOperator` 716ca94c3ddSJeremy L Thompson @param[in] qf `CeedQFunction` defining the action of the operator at quadrature points 717ca94c3ddSJeremy L Thompson @param[in] dqf `CeedQFunction` defining the action of the Jacobian of `qf` (or @ref CEED_QFUNCTION_NONE) 718ca94c3ddSJeremy L Thompson @param[in] dqfT `CeedQFunction` defining the action of the transpose of the Jacobian of `qf` (or @ref CEED_QFUNCTION_NONE) 719ca94c3ddSJeremy L Thompson @param[out] op Address of the variable where the newly created `CeedOperator` will be stored 720b11c1e72Sjeremylt 721b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 722dfdf5a53Sjeremylt 7237a982d89SJeremy L. Thompson @ref User 724d7b241e6Sjeremylt */ 7252b730f8bSJeremy L Thompson int CeedOperatorCreate(Ceed ceed, CeedQFunction qf, CeedQFunction dqf, CeedQFunction dqfT, CeedOperator *op) { 7265fe0d4faSjeremylt if (!ceed->OperatorCreate) { 7275fe0d4faSjeremylt Ceed delegate; 7286574a04fSJeremy L Thompson 7292b730f8bSJeremy L Thompson CeedCall(CeedGetObjectDelegate(ceed, &delegate, "Operator")); 7301ef3a2a9SJeremy L Thompson CeedCheck(delegate, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not implement CeedOperatorCreate"); 7312b730f8bSJeremy L Thompson CeedCall(CeedOperatorCreate(delegate, qf, dqf, dqfT, op)); 732e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 7335fe0d4faSjeremylt } 7345fe0d4faSjeremylt 735ca94c3ddSJeremy L Thompson CeedCheck(qf && qf != CEED_QFUNCTION_NONE, ceed, CEED_ERROR_MINOR, "Operator must have a valid CeedQFunction."); 736db002c03SJeremy L Thompson 7372b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, op)); 738db002c03SJeremy L Thompson CeedCall(CeedReferenceCopy(ceed, &(*op)->ceed)); 739d1d35e2fSjeremylt (*op)->ref_count = 1; 7402b104005SJeremy L Thompson (*op)->input_size = -1; 7412b104005SJeremy L Thompson (*op)->output_size = -1; 742db002c03SJeremy L Thompson CeedCall(CeedQFunctionReferenceCopy(qf, &(*op)->qf)); 743db002c03SJeremy L Thompson if (dqf && dqf != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionReferenceCopy(dqf, &(*op)->dqf)); 744db002c03SJeremy L Thompson if (dqfT && dqfT != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionReferenceCopy(dqfT, &(*op)->dqfT)); 7452b730f8bSJeremy L Thompson CeedCall(CeedCalloc(CEED_FIELD_MAX, &(*op)->input_fields)); 7462b730f8bSJeremy L Thompson CeedCall(CeedCalloc(CEED_FIELD_MAX, &(*op)->output_fields)); 7472b730f8bSJeremy L Thompson CeedCall(ceed->OperatorCreate(*op)); 748e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 749d7b241e6Sjeremylt } 750d7b241e6Sjeremylt 751d7b241e6Sjeremylt /** 752ca94c3ddSJeremy L Thompson @brief Create a `CeedOperator` for evaluation at evaluation at arbitrary points in each element. 75348acf710SJeremy L Thompson 754ca94c3ddSJeremy L Thompson A `CeedBasis` and `CeedElemRestriction` can be associated with `CeedQFunction` fields with `CeedOperator` SetField. 755ca94c3ddSJeremy L Thompson The locations of each point are set with @ref CeedOperatorAtPointsSetPoints(). 75648acf710SJeremy L Thompson 757ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` object used to create the `CeedOperator` 758ca94c3ddSJeremy L Thompson @param[in] qf `CeedQFunction` defining the action of the operator at quadrature points 759ca94c3ddSJeremy L Thompson @param[in] dqf `CeedQFunction` defining the action of the Jacobian of @a qf (or @ref CEED_QFUNCTION_NONE) 760ca94c3ddSJeremy L Thompson @param[in] dqfT `CeedQFunction` defining the action of the transpose of the Jacobian of @a qf (or @ref CEED_QFUNCTION_NONE) 76148acf710SJeremy L Thompson @param[out] op Address of the variable where the newly created CeedOperator will be stored 76248acf710SJeremy L Thompson 76348acf710SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 76448acf710SJeremy L Thompson 76548acf710SJeremy L Thompson @ref User 76648acf710SJeremy L Thompson */ 76748acf710SJeremy L Thompson int CeedOperatorCreateAtPoints(Ceed ceed, CeedQFunction qf, CeedQFunction dqf, CeedQFunction dqfT, CeedOperator *op) { 76848acf710SJeremy L Thompson if (!ceed->OperatorCreateAtPoints) { 76948acf710SJeremy L Thompson Ceed delegate; 77048acf710SJeremy L Thompson 77148acf710SJeremy L Thompson CeedCall(CeedGetObjectDelegate(ceed, &delegate, "Operator")); 7721ef3a2a9SJeremy L Thompson CeedCheck(delegate, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not implement CeedOperatorCreateAtPoints"); 77348acf710SJeremy L Thompson CeedCall(CeedOperatorCreateAtPoints(delegate, qf, dqf, dqfT, op)); 77448acf710SJeremy L Thompson return CEED_ERROR_SUCCESS; 77548acf710SJeremy L Thompson } 77648acf710SJeremy L Thompson 777ca94c3ddSJeremy L Thompson CeedCheck(qf && qf != CEED_QFUNCTION_NONE, ceed, CEED_ERROR_MINOR, "Operator must have a valid CeedQFunction."); 77848acf710SJeremy L Thompson 77948acf710SJeremy L Thompson CeedCall(CeedCalloc(1, op)); 78048acf710SJeremy L Thompson CeedCall(CeedReferenceCopy(ceed, &(*op)->ceed)); 78148acf710SJeremy L Thompson (*op)->ref_count = 1; 78248acf710SJeremy L Thompson (*op)->is_at_points = true; 78348acf710SJeremy L Thompson (*op)->input_size = -1; 78448acf710SJeremy L Thompson (*op)->output_size = -1; 78548acf710SJeremy L Thompson CeedCall(CeedQFunctionReferenceCopy(qf, &(*op)->qf)); 78648acf710SJeremy L Thompson if (dqf && dqf != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionReferenceCopy(dqf, &(*op)->dqf)); 78748acf710SJeremy L Thompson if (dqfT && dqfT != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionReferenceCopy(dqfT, &(*op)->dqfT)); 78848acf710SJeremy L Thompson CeedCall(CeedCalloc(CEED_FIELD_MAX, &(*op)->input_fields)); 78948acf710SJeremy L Thompson CeedCall(CeedCalloc(CEED_FIELD_MAX, &(*op)->output_fields)); 79048acf710SJeremy L Thompson CeedCall(ceed->OperatorCreateAtPoints(*op)); 79148acf710SJeremy L Thompson return CEED_ERROR_SUCCESS; 79248acf710SJeremy L Thompson } 79348acf710SJeremy L Thompson 79448acf710SJeremy L Thompson /** 795ca94c3ddSJeremy L Thompson @brief Create a composite `CeedOperator` that composes the action of several `CeedOperator` 79652d6035fSJeremy L Thompson 797ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` object used to create the `CeedOperator` 798ca94c3ddSJeremy L Thompson @param[out] op Address of the variable where the newly created composite `CeedOperator` will be stored 79952d6035fSJeremy L Thompson 80052d6035fSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 80152d6035fSJeremy L Thompson 8027a982d89SJeremy L. Thompson @ref User 80352d6035fSJeremy L Thompson */ 80452d6035fSJeremy L Thompson int CeedCompositeOperatorCreate(Ceed ceed, CeedOperator *op) { 80552d6035fSJeremy L Thompson if (!ceed->CompositeOperatorCreate) { 80652d6035fSJeremy L Thompson Ceed delegate; 80752d6035fSJeremy L Thompson 8081c66c397SJeremy L Thompson CeedCall(CeedGetObjectDelegate(ceed, &delegate, "Operator")); 809250756a7Sjeremylt if (delegate) { 8102b730f8bSJeremy L Thompson CeedCall(CeedCompositeOperatorCreate(delegate, op)); 811e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 81252d6035fSJeremy L Thompson } 813250756a7Sjeremylt } 81452d6035fSJeremy L Thompson 8152b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, op)); 816db002c03SJeremy L Thompson CeedCall(CeedReferenceCopy(ceed, &(*op)->ceed)); 817996d9ab5SJed Brown (*op)->ref_count = 1; 818f04ea552SJeremy L Thompson (*op)->is_composite = true; 8192b730f8bSJeremy L Thompson CeedCall(CeedCalloc(CEED_COMPOSITE_MAX, &(*op)->sub_operators)); 8202b104005SJeremy L Thompson (*op)->input_size = -1; 8212b104005SJeremy L Thompson (*op)->output_size = -1; 822250756a7Sjeremylt 823db002c03SJeremy L Thompson if (ceed->CompositeOperatorCreate) CeedCall(ceed->CompositeOperatorCreate(*op)); 824e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 82552d6035fSJeremy L Thompson } 82652d6035fSJeremy L Thompson 82752d6035fSJeremy L Thompson /** 828ca94c3ddSJeremy L Thompson @brief Copy the pointer to a `CeedOperator`. 8294385fb7fSSebastian Grimberg 830ca94c3ddSJeremy L Thompson Both pointers should be destroyed with @ref CeedOperatorDestroy(). 831512bb800SJeremy L Thompson 832ca94c3ddSJeremy 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`. 833ca94c3ddSJeremy L Thompson This `CeedOperator` will be destroyed if `*op_copy` is the only reference to this `CeedOperator`. 8349560d06aSjeremylt 835ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to copy reference to 836ea61e9acSJeremy L Thompson @param[in,out] op_copy Variable to store copied reference 8379560d06aSjeremylt 8389560d06aSjeremylt @return An error code: 0 - success, otherwise - failure 8399560d06aSjeremylt 8409560d06aSjeremylt @ref User 8419560d06aSjeremylt **/ 8429560d06aSjeremylt int CeedOperatorReferenceCopy(CeedOperator op, CeedOperator *op_copy) { 8432b730f8bSJeremy L Thompson CeedCall(CeedOperatorReference(op)); 8442b730f8bSJeremy L Thompson CeedCall(CeedOperatorDestroy(op_copy)); 8459560d06aSjeremylt *op_copy = op; 8469560d06aSjeremylt return CEED_ERROR_SUCCESS; 8479560d06aSjeremylt } 8489560d06aSjeremylt 8499560d06aSjeremylt /** 850ca94c3ddSJeremy L Thompson @brief Provide a field to a `CeedOperator` for use by its `CeedQFunction`. 851d7b241e6Sjeremylt 852ca94c3ddSJeremy L Thompson This function is used to specify both active and passive fields to a `CeedOperator`. 853bafebce1SSebastian Grimberg For passive fields, a `CeedVector` `vec` must be provided. 854ea61e9acSJeremy L Thompson Passive fields can inputs or outputs (updated in-place when operator is applied). 855d7b241e6Sjeremylt 856ca94c3ddSJeremy L Thompson Active fields must be specified using this function, but their data (in a `CeedVector`) is passed in @ref CeedOperatorApply(). 857ca94c3ddSJeremy L Thompson There can be at most one active input `CeedVector` and at most one active output@ref CeedVector passed to @ref CeedOperatorApply(). 858d7b241e6Sjeremylt 859528a22edSJeremy L Thompson The number of quadrature points must agree across all points. 860bafebce1SSebastian Grimberg When using @ref CEED_BASIS_NONE, the number of quadrature points is determined by the element size of `rstr`. 861528a22edSJeremy L Thompson 862ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` on which to provide the field 863ca94c3ddSJeremy L Thompson @param[in] field_name Name of the field (to be matched with the name used by `CeedQFunction`) 864bafebce1SSebastian Grimberg @param[in] rstr `CeedElemRestriction` 865bafebce1SSebastian Grimberg @param[in] basis `CeedBasis` in which the field resides or @ref CEED_BASIS_NONE if collocated with quadrature points 866bafebce1SSebastian 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` 867b11c1e72Sjeremylt 868b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 869dfdf5a53Sjeremylt 8707a982d89SJeremy L. Thompson @ref User 871b11c1e72Sjeremylt **/ 872bafebce1SSebastian Grimberg int CeedOperatorSetField(CeedOperator op, const char *field_name, CeedElemRestriction rstr, CeedBasis basis, CeedVector vec) { 8731203703bSJeremy L Thompson bool is_input = true, is_at_points, is_composite, is_immutable; 8741203703bSJeremy L Thompson CeedInt num_elem = 0, num_qpts = 0, num_input_fields, num_output_fields; 8751203703bSJeremy L Thompson Ceed ceed; 8761203703bSJeremy L Thompson CeedQFunction qf; 8771203703bSJeremy L Thompson CeedQFunctionField qf_field, *qf_input_fields, *qf_output_fields; 8781c66c397SJeremy L Thompson CeedOperatorField *op_field; 8791c66c397SJeremy L Thompson 8801203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 8811203703bSJeremy L Thompson CeedCall(CeedOperatorIsAtPoints(op, &is_at_points)); 8821203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 8831203703bSJeremy L Thompson CeedCall(CeedOperatorIsImmutable(op, &is_immutable)); 8841203703bSJeremy L Thompson CeedCheck(!is_composite, ceed, CEED_ERROR_INCOMPATIBLE, "Cannot add field to composite operator."); 8851203703bSJeremy L Thompson CeedCheck(!is_immutable, ceed, CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable"); 8861203703bSJeremy L Thompson CeedCheck(rstr, ceed, CEED_ERROR_INCOMPATIBLE, "CeedElemRestriction rstr for field \"%s\" must be non-NULL.", field_name); 8871203703bSJeremy L Thompson CeedCheck(basis, ceed, CEED_ERROR_INCOMPATIBLE, "CeedBasis basis for field \"%s\" must be non-NULL.", field_name); 8881203703bSJeremy L Thompson CeedCheck(vec, ceed, CEED_ERROR_INCOMPATIBLE, "CeedVector vec for field \"%s\" must be non-NULL.", field_name); 88952d6035fSJeremy L Thompson 890bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionGetNumElements(rstr, &num_elem)); 8911203703bSJeremy L Thompson CeedCheck(rstr == CEED_ELEMRESTRICTION_NONE || !op->has_restriction || num_elem == op->num_elem, ceed, CEED_ERROR_DIMENSION, 892ca94c3ddSJeremy L Thompson "CeedElemRestriction with %" CeedInt_FMT " elements incompatible with prior %" CeedInt_FMT " elements", num_elem, op->num_elem); 8932c7e7413SJeremy L Thompson { 8942c7e7413SJeremy L Thompson CeedRestrictionType rstr_type; 8952c7e7413SJeremy L Thompson 896bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionGetType(rstr, &rstr_type)); 89748acf710SJeremy L Thompson if (rstr_type == CEED_RESTRICTION_POINTS) { 8981203703bSJeremy L Thompson CeedCheck(is_at_points, ceed, CEED_ERROR_UNSUPPORTED, "CeedElemRestriction AtPoints not supported for standard operator fields"); 8991203703bSJeremy L Thompson CeedCheck(basis == CEED_BASIS_NONE, ceed, CEED_ERROR_UNSUPPORTED, "CeedElemRestriction AtPoints must be used with CEED_BASIS_NONE"); 90048acf710SJeremy L Thompson if (!op->first_points_rstr) { 901bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionReferenceCopy(rstr, &op->first_points_rstr)); 90248acf710SJeremy L Thompson } else { 90348acf710SJeremy L Thompson bool are_compatible; 90448acf710SJeremy L Thompson 905bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionAtPointsAreCompatible(op->first_points_rstr, rstr, &are_compatible)); 9061203703bSJeremy L Thompson CeedCheck(are_compatible, ceed, CEED_ERROR_INCOMPATIBLE, 907ca94c3ddSJeremy L Thompson "CeedElemRestriction must have compatible offsets with previously set CeedElemRestriction"); 90848acf710SJeremy L Thompson } 90948acf710SJeremy L Thompson } 9102c7e7413SJeremy L Thompson } 911d7b241e6Sjeremylt 912bafebce1SSebastian Grimberg if (basis == CEED_BASIS_NONE) CeedCall(CeedElemRestrictionGetElementSize(rstr, &num_qpts)); 913bafebce1SSebastian Grimberg else CeedCall(CeedBasisGetNumQuadraturePoints(basis, &num_qpts)); 9141203703bSJeremy L Thompson CeedCheck(op->num_qpts == 0 || num_qpts == op->num_qpts, ceed, CEED_ERROR_DIMENSION, 915ca94c3ddSJeremy L Thompson "%s must correspond to the same number of quadrature points as previously added CeedBases. Found %" CeedInt_FMT 916528a22edSJeremy L Thompson " quadrature points but expected %" CeedInt_FMT " quadrature points.", 917bafebce1SSebastian Grimberg basis == CEED_BASIS_NONE ? "CeedElemRestriction" : "CeedBasis", num_qpts, op->num_qpts); 9181203703bSJeremy L Thompson 9191203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 9201203703bSJeremy L Thompson CeedCall(CeedQFunctionGetFields(qf, &num_input_fields, &qf_input_fields, &num_output_fields, &qf_output_fields)); 9211203703bSJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 9226f8994e9SJeremy L Thompson const char *qf_field_name; 9231203703bSJeremy L Thompson 9241203703bSJeremy L Thompson CeedCall(CeedQFunctionFieldGetName(qf_input_fields[i], &qf_field_name)); 9251203703bSJeremy L Thompson if (!strcmp(field_name, qf_field_name)) { 9261203703bSJeremy L Thompson qf_field = qf_input_fields[i]; 927d1d35e2fSjeremylt op_field = &op->input_fields[i]; 928d7b241e6Sjeremylt goto found; 929d7b241e6Sjeremylt } 930d7b241e6Sjeremylt } 9312b104005SJeremy L Thompson is_input = false; 9321203703bSJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 9336f8994e9SJeremy L Thompson const char *qf_field_name; 9341203703bSJeremy L Thompson 9351203703bSJeremy L Thompson CeedCall(CeedQFunctionFieldGetName(qf_output_fields[i], &qf_field_name)); 9361203703bSJeremy L Thompson if (!strcmp(field_name, qf_field_name)) { 9371203703bSJeremy L Thompson qf_field = qf_output_fields[i]; 938d1d35e2fSjeremylt op_field = &op->output_fields[i]; 939d7b241e6Sjeremylt goto found; 940d7b241e6Sjeremylt } 941d7b241e6Sjeremylt } 942c042f62fSJeremy L Thompson // LCOV_EXCL_START 9431203703bSJeremy L Thompson return CeedError(ceed, CEED_ERROR_INCOMPLETE, "CeedQFunction has no knowledge of field '%s'", field_name); 944c042f62fSJeremy L Thompson // LCOV_EXCL_STOP 945d7b241e6Sjeremylt found: 9461203703bSJeremy L Thompson CeedCall(CeedOperatorCheckField(ceed, qf_field, rstr, basis)); 9472b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, op_field)); 948e15f9bd0SJeremy L Thompson 949bafebce1SSebastian Grimberg if (vec == CEED_VECTOR_ACTIVE) { 9502b104005SJeremy L Thompson CeedSize l_size; 9511c66c397SJeremy L Thompson 952bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionGetLVectorSize(rstr, &l_size)); 9532b104005SJeremy L Thompson if (is_input) { 9542b104005SJeremy L Thompson if (op->input_size == -1) op->input_size = l_size; 9551203703bSJeremy L Thompson CeedCheck(l_size == op->input_size, ceed, CEED_ERROR_INCOMPATIBLE, 956249f8407SJeremy L Thompson "LVector size %" CeedSize_FMT " does not match previous size %" CeedSize_FMT "", l_size, op->input_size); 9572b104005SJeremy L Thompson } else { 9582b104005SJeremy L Thompson if (op->output_size == -1) op->output_size = l_size; 9591203703bSJeremy L Thompson CeedCheck(l_size == op->output_size, ceed, CEED_ERROR_INCOMPATIBLE, 960249f8407SJeremy L Thompson "LVector size %" CeedSize_FMT " does not match previous size %" CeedSize_FMT "", l_size, op->output_size); 9612b104005SJeremy L Thompson } 9622b730f8bSJeremy L Thompson } 9632b104005SJeremy L Thompson 964bafebce1SSebastian Grimberg CeedCall(CeedVectorReferenceCopy(vec, &(*op_field)->vec)); 965bafebce1SSebastian Grimberg CeedCall(CeedElemRestrictionReferenceCopy(rstr, &(*op_field)->elem_rstr)); 966bafebce1SSebastian Grimberg if (rstr != CEED_ELEMRESTRICTION_NONE && !op->has_restriction) { 967d1d35e2fSjeremylt op->num_elem = num_elem; 968d1d35e2fSjeremylt op->has_restriction = true; // Restriction set, but num_elem may be 0 969e15f9bd0SJeremy L Thompson } 970bafebce1SSebastian Grimberg CeedCall(CeedBasisReferenceCopy(basis, &(*op_field)->basis)); 9712a3ff1c9SZach Atkins if (op->num_qpts == 0 && !is_at_points) op->num_qpts = num_qpts; // no consistent number of qpts for OperatorAtPoints 972d1d35e2fSjeremylt op->num_fields += 1; 9732b730f8bSJeremy L Thompson CeedCall(CeedStringAllocCopy(field_name, (char **)&(*op_field)->field_name)); 974e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 975d7b241e6Sjeremylt } 976d7b241e6Sjeremylt 977d7b241e6Sjeremylt /** 978ca94c3ddSJeremy L Thompson @brief Get the `CeedOperator` Field of a `CeedOperator`. 97943bbe138SJeremy L Thompson 980ca94c3ddSJeremy L Thompson Note: Calling this function asserts that setup is complete and sets the `CeedOperator` as immutable. 981f04ea552SJeremy L Thompson 982ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 983f74ec584SJeremy L Thompson @param[out] num_input_fields Variable to store number of input fields 984ca94c3ddSJeremy L Thompson @param[out] input_fields Variable to store input fields 985f74ec584SJeremy L Thompson @param[out] num_output_fields Variable to store number of output fields 986ca94c3ddSJeremy L Thompson @param[out] output_fields Variable to store output fields 98743bbe138SJeremy L Thompson 98843bbe138SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 98943bbe138SJeremy L Thompson 990e9b533fbSJeremy L Thompson @ref Advanced 99143bbe138SJeremy L Thompson **/ 9922b730f8bSJeremy L Thompson int CeedOperatorGetFields(CeedOperator op, CeedInt *num_input_fields, CeedOperatorField **input_fields, CeedInt *num_output_fields, 99343bbe138SJeremy L Thompson CeedOperatorField **output_fields) { 9941203703bSJeremy L Thompson bool is_composite; 9951203703bSJeremy L Thompson CeedQFunction qf; 9961203703bSJeremy L Thompson 9971203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 9986e536b99SJeremy L Thompson CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Not defined for composite operator"); 9992b730f8bSJeremy L Thompson CeedCall(CeedOperatorCheckReady(op)); 100043bbe138SJeremy L Thompson 10011203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 10021203703bSJeremy L Thompson CeedCall(CeedQFunctionGetFields(qf, num_input_fields, NULL, num_output_fields, NULL)); 100343bbe138SJeremy L Thompson if (input_fields) *input_fields = op->input_fields; 100443bbe138SJeremy L Thompson if (output_fields) *output_fields = op->output_fields; 100543bbe138SJeremy L Thompson return CEED_ERROR_SUCCESS; 100643bbe138SJeremy L Thompson } 100743bbe138SJeremy L Thompson 100843bbe138SJeremy L Thompson /** 1009ca94c3ddSJeremy L Thompson @brief Set the arbitrary points in each element for a `CeedOperator` at points. 101048acf710SJeremy L Thompson 1011ca94c3ddSJeremy L Thompson Note: Calling this function asserts that setup is complete and sets the `CeedOperator` as immutable. 101248acf710SJeremy L Thompson 1013ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` at points 1014ca94c3ddSJeremy L Thompson @param[in] rstr_points `CeedElemRestriction` for the coordinates of each point by element 1015ca94c3ddSJeremy L Thompson @param[in] point_coords `CeedVector` holding coordinates of each point 101648acf710SJeremy L Thompson 101748acf710SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 101848acf710SJeremy L Thompson 101948acf710SJeremy L Thompson @ref Advanced 102048acf710SJeremy L Thompson **/ 102148acf710SJeremy L Thompson int CeedOperatorAtPointsSetPoints(CeedOperator op, CeedElemRestriction rstr_points, CeedVector point_coords) { 10221203703bSJeremy L Thompson bool is_at_points, is_immutable; 10231203703bSJeremy L Thompson Ceed ceed; 10242a3ff1c9SZach Atkins 10251203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 10262a3ff1c9SZach Atkins CeedCall(CeedOperatorIsAtPoints(op, &is_at_points)); 10271203703bSJeremy L Thompson CeedCall(CeedOperatorIsImmutable(op, &is_immutable)); 10281203703bSJeremy L Thompson CeedCheck(is_at_points, ceed, CEED_ERROR_MINOR, "Only defined for operator at points"); 10291203703bSJeremy L Thompson CeedCheck(!is_immutable, ceed, CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable"); 103048acf710SJeremy L Thompson 103148acf710SJeremy L Thompson if (!op->first_points_rstr) { 103248acf710SJeremy L Thompson CeedCall(CeedElemRestrictionReferenceCopy(rstr_points, &op->first_points_rstr)); 103348acf710SJeremy L Thompson } else { 103448acf710SJeremy L Thompson bool are_compatible; 103548acf710SJeremy L Thompson 103648acf710SJeremy L Thompson CeedCall(CeedElemRestrictionAtPointsAreCompatible(op->first_points_rstr, rstr_points, &are_compatible)); 10371203703bSJeremy L Thompson CeedCheck(are_compatible, ceed, CEED_ERROR_INCOMPATIBLE, 1038ca94c3ddSJeremy L Thompson "CeedElemRestriction must have compatible offsets with previously set field CeedElemRestriction"); 103948acf710SJeremy L Thompson } 104048acf710SJeremy L Thompson 104148acf710SJeremy L Thompson CeedCall(CeedElemRestrictionReferenceCopy(rstr_points, &op->rstr_points)); 104248acf710SJeremy L Thompson CeedCall(CeedVectorReferenceCopy(point_coords, &op->point_coords)); 104348acf710SJeremy L Thompson return CEED_ERROR_SUCCESS; 104448acf710SJeremy L Thompson } 104548acf710SJeremy L Thompson 104648acf710SJeremy L Thompson /** 1047b594f9faSZach Atkins @brief Get a boolean value indicating if the `CeedOperator` was created with `CeedOperatorCreateAtPoints` 1048b594f9faSZach Atkins 1049b594f9faSZach Atkins @param[in] op `CeedOperator` 1050b594f9faSZach Atkins @param[out] is_at_points Variable to store at points status 1051b594f9faSZach Atkins 1052b594f9faSZach Atkins @return An error code: 0 - success, otherwise - failure 1053b594f9faSZach Atkins 1054b594f9faSZach Atkins @ref User 1055b594f9faSZach Atkins **/ 1056b594f9faSZach Atkins int CeedOperatorIsAtPoints(CeedOperator op, bool *is_at_points) { 1057b594f9faSZach Atkins *is_at_points = op->is_at_points; 1058b594f9faSZach Atkins return CEED_ERROR_SUCCESS; 1059b594f9faSZach Atkins } 1060b594f9faSZach Atkins 1061b594f9faSZach Atkins /** 1062ca94c3ddSJeremy L Thompson @brief Get the arbitrary points in each element for a `CeedOperator` at points. 106348acf710SJeremy L Thompson 1064ca94c3ddSJeremy L Thompson Note: Calling this function asserts that setup is complete and sets the `CeedOperator` as immutable. 106548acf710SJeremy L Thompson 1066ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` at points 1067ca94c3ddSJeremy L Thompson @param[out] rstr_points Variable to hold `CeedElemRestriction` for the coordinates of each point by element 1068ca94c3ddSJeremy L Thompson @param[out] point_coords Variable to hold `CeedVector` holding coordinates of each point 106948acf710SJeremy L Thompson 107048acf710SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 107148acf710SJeremy L Thompson 107248acf710SJeremy L Thompson @ref Advanced 107348acf710SJeremy L Thompson **/ 107448acf710SJeremy L Thompson int CeedOperatorAtPointsGetPoints(CeedOperator op, CeedElemRestriction *rstr_points, CeedVector *point_coords) { 10752a3ff1c9SZach Atkins bool is_at_points; 10762a3ff1c9SZach Atkins 10772a3ff1c9SZach Atkins CeedCall(CeedOperatorIsAtPoints(op, &is_at_points)); 10786e536b99SJeremy L Thompson CeedCheck(is_at_points, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Only defined for operator at points"); 107948acf710SJeremy L Thompson CeedCall(CeedOperatorCheckReady(op)); 108048acf710SJeremy L Thompson 108148acf710SJeremy L Thompson if (rstr_points) CeedCall(CeedElemRestrictionReferenceCopy(op->rstr_points, rstr_points)); 108248acf710SJeremy L Thompson if (point_coords) CeedCall(CeedVectorReferenceCopy(op->point_coords, point_coords)); 108348acf710SJeremy L Thompson return CEED_ERROR_SUCCESS; 108448acf710SJeremy L Thompson } 108548acf710SJeremy L Thompson 108648acf710SJeremy L Thompson /** 1087be9c6463SJeremy L Thompson @brief Get a `CeedOperator` Field of a `CeedOperator` from its name. 1088be9c6463SJeremy L Thompson 1089be9c6463SJeremy L Thompson `op_field` is set to `NULL` if the field is not found. 1090de5900adSJames Wright 1091ca94c3ddSJeremy L Thompson Note: Calling this function asserts that setup is complete and sets the `CeedOperator` as immutable. 1092de5900adSJames Wright 1093ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1094ca94c3ddSJeremy L Thompson @param[in] field_name Name of desired `CeedOperator` Field 1095ca94c3ddSJeremy L Thompson @param[out] op_field `CeedOperator` Field corresponding to the name 1096de5900adSJames Wright 1097de5900adSJames Wright @return An error code: 0 - success, otherwise - failure 1098de5900adSJames Wright 1099de5900adSJames Wright @ref Advanced 1100de5900adSJames Wright **/ 1101de5900adSJames Wright int CeedOperatorGetFieldByName(CeedOperator op, const char *field_name, CeedOperatorField *op_field) { 11026f8994e9SJeremy L Thompson const char *name; 1103de5900adSJames Wright CeedInt num_input_fields, num_output_fields; 1104de5900adSJames Wright CeedOperatorField *input_fields, *output_fields; 1105de5900adSJames Wright 1106be9c6463SJeremy L Thompson *op_field = NULL; 11071c66c397SJeremy L Thompson CeedCall(CeedOperatorGetFields(op, &num_input_fields, &input_fields, &num_output_fields, &output_fields)); 1108de5900adSJames Wright for (CeedInt i = 0; i < num_input_fields; i++) { 1109de5900adSJames Wright CeedCall(CeedOperatorFieldGetName(input_fields[i], &name)); 1110de5900adSJames Wright if (!strcmp(name, field_name)) { 1111de5900adSJames Wright *op_field = input_fields[i]; 1112de5900adSJames Wright return CEED_ERROR_SUCCESS; 1113de5900adSJames Wright } 1114de5900adSJames Wright } 1115de5900adSJames Wright for (CeedInt i = 0; i < num_output_fields; i++) { 1116de5900adSJames Wright CeedCall(CeedOperatorFieldGetName(output_fields[i], &name)); 1117de5900adSJames Wright if (!strcmp(name, field_name)) { 1118de5900adSJames Wright *op_field = output_fields[i]; 1119de5900adSJames Wright return CEED_ERROR_SUCCESS; 1120de5900adSJames Wright } 1121de5900adSJames Wright } 1122be9c6463SJeremy L Thompson return CEED_ERROR_SUCCESS; 1123de5900adSJames Wright } 1124de5900adSJames Wright 1125de5900adSJames Wright /** 1126ca94c3ddSJeremy L Thompson @brief Get the name of a `CeedOperator` Field 112728567f8fSJeremy L Thompson 1128ca94c3ddSJeremy L Thompson @param[in] op_field `CeedOperator` Field 112928567f8fSJeremy L Thompson @param[out] field_name Variable to store the field name 113028567f8fSJeremy L Thompson 113128567f8fSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 113228567f8fSJeremy L Thompson 1133e9b533fbSJeremy L Thompson @ref Advanced 113428567f8fSJeremy L Thompson **/ 11356f8994e9SJeremy L Thompson int CeedOperatorFieldGetName(CeedOperatorField op_field, const char **field_name) { 11366f8994e9SJeremy L Thompson *field_name = op_field->field_name; 113728567f8fSJeremy L Thompson return CEED_ERROR_SUCCESS; 113828567f8fSJeremy L Thompson } 113928567f8fSJeremy L Thompson 114028567f8fSJeremy L Thompson /** 1141ca94c3ddSJeremy L Thompson @brief Get the `CeedElemRestriction` of a `CeedOperator` Field 114243bbe138SJeremy L Thompson 1143ca94c3ddSJeremy L Thompson @param[in] op_field `CeedOperator` Field 1144ca94c3ddSJeremy L Thompson @param[out] rstr Variable to store `CeedElemRestriction` 114543bbe138SJeremy L Thompson 114643bbe138SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 114743bbe138SJeremy L Thompson 1148e9b533fbSJeremy L Thompson @ref Advanced 114943bbe138SJeremy L Thompson **/ 11502b730f8bSJeremy L Thompson int CeedOperatorFieldGetElemRestriction(CeedOperatorField op_field, CeedElemRestriction *rstr) { 1151437c7c90SJeremy L Thompson *rstr = op_field->elem_rstr; 115243bbe138SJeremy L Thompson return CEED_ERROR_SUCCESS; 115343bbe138SJeremy L Thompson } 115443bbe138SJeremy L Thompson 115543bbe138SJeremy L Thompson /** 1156ca94c3ddSJeremy L Thompson @brief Get the `CeedBasis` of a `CeedOperator` Field 115743bbe138SJeremy L Thompson 1158ca94c3ddSJeremy L Thompson @param[in] op_field `CeedOperator` Field 1159ca94c3ddSJeremy L Thompson @param[out] basis Variable to store `CeedBasis` 116043bbe138SJeremy L Thompson 116143bbe138SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 116243bbe138SJeremy L Thompson 1163e9b533fbSJeremy L Thompson @ref Advanced 116443bbe138SJeremy L Thompson **/ 116543bbe138SJeremy L Thompson int CeedOperatorFieldGetBasis(CeedOperatorField op_field, CeedBasis *basis) { 116643bbe138SJeremy L Thompson *basis = op_field->basis; 116743bbe138SJeremy L Thompson return CEED_ERROR_SUCCESS; 116843bbe138SJeremy L Thompson } 116943bbe138SJeremy L Thompson 117043bbe138SJeremy L Thompson /** 1171ca94c3ddSJeremy L Thompson @brief Get the `CeedVector` of a `CeedOperator` Field 117243bbe138SJeremy L Thompson 1173ca94c3ddSJeremy L Thompson @param[in] op_field `CeedOperator` Field 1174ca94c3ddSJeremy L Thompson @param[out] vec Variable to store `CeedVector` 117543bbe138SJeremy L Thompson 117643bbe138SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 117743bbe138SJeremy L Thompson 1178e9b533fbSJeremy L Thompson @ref Advanced 117943bbe138SJeremy L Thompson **/ 118043bbe138SJeremy L Thompson int CeedOperatorFieldGetVector(CeedOperatorField op_field, CeedVector *vec) { 118143bbe138SJeremy L Thompson *vec = op_field->vec; 118243bbe138SJeremy L Thompson return CEED_ERROR_SUCCESS; 118343bbe138SJeremy L Thompson } 118443bbe138SJeremy L Thompson 118543bbe138SJeremy L Thompson /** 1186ab747706SJeremy L Thompson @brief Get the data of a `CeedOperator` Field. 1187ab747706SJeremy L Thompson 1188ab747706SJeremy L Thompson Any arguments set as `NULL` are ignored. 1189ab747706SJeremy L Thompson 1190ab747706SJeremy L Thompson @param[in] op_field `CeedOperator` Field 1191ab747706SJeremy L Thompson @param[out] field_name Variable to store the field name 1192ab747706SJeremy L Thompson @param[out] rstr Variable to store `CeedElemRestriction` 1193ab747706SJeremy L Thompson @param[out] basis Variable to store `CeedBasis` 1194ab747706SJeremy L Thompson @param[out] vec Variable to store `CeedVector` 1195ab747706SJeremy L Thompson 1196ab747706SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1197ab747706SJeremy L Thompson 1198ab747706SJeremy L Thompson @ref Advanced 1199ab747706SJeremy L Thompson **/ 12006f8994e9SJeremy L Thompson int CeedOperatorFieldGetData(CeedOperatorField op_field, const char **field_name, CeedElemRestriction *rstr, CeedBasis *basis, CeedVector *vec) { 1201ab747706SJeremy L Thompson if (field_name) CeedCall(CeedOperatorFieldGetName(op_field, field_name)); 1202ab747706SJeremy L Thompson if (rstr) CeedCall(CeedOperatorFieldGetElemRestriction(op_field, rstr)); 1203ab747706SJeremy L Thompson if (basis) CeedCall(CeedOperatorFieldGetBasis(op_field, basis)); 1204ab747706SJeremy L Thompson if (vec) CeedCall(CeedOperatorFieldGetVector(op_field, vec)); 1205ab747706SJeremy L Thompson return CEED_ERROR_SUCCESS; 1206ab747706SJeremy L Thompson } 1207ab747706SJeremy L Thompson 1208ab747706SJeremy L Thompson /** 1209ca94c3ddSJeremy L Thompson @brief Add a sub-operator to a composite `CeedOperator` 1210288c0443SJeremy L Thompson 1211ca94c3ddSJeremy L Thompson @param[in,out] composite_op Composite `CeedOperator` 1212ca94c3ddSJeremy L Thompson @param[in] sub_op Sub-operator `CeedOperator` 121352d6035fSJeremy L Thompson 121452d6035fSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 121552d6035fSJeremy L Thompson 12167a982d89SJeremy L. Thompson @ref User 121752d6035fSJeremy L Thompson */ 12182b730f8bSJeremy L Thompson int CeedCompositeOperatorAddSub(CeedOperator composite_op, CeedOperator sub_op) { 12191203703bSJeremy L Thompson bool is_immutable; 12201203703bSJeremy L Thompson Ceed ceed; 12211203703bSJeremy L Thompson 12221203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(composite_op, &ceed)); 12231203703bSJeremy L Thompson CeedCheck(composite_op->is_composite, ceed, CEED_ERROR_MINOR, "CeedOperator is not a composite operator"); 12241203703bSJeremy L Thompson CeedCheck(composite_op->num_suboperators < CEED_COMPOSITE_MAX, ceed, CEED_ERROR_UNSUPPORTED, "Cannot add additional sub-operators"); 12251203703bSJeremy L Thompson CeedCall(CeedOperatorIsImmutable(composite_op, &is_immutable)); 12261203703bSJeremy L Thompson CeedCheck(!is_immutable, ceed, CEED_ERROR_MAJOR, "Operator cannot be changed after set as immutable"); 12272b730f8bSJeremy L Thompson 12282b730f8bSJeremy L Thompson { 12292b730f8bSJeremy L Thompson CeedSize input_size, output_size; 12301c66c397SJeremy L Thompson 12312b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetActiveVectorLengths(sub_op, &input_size, &output_size)); 12322b730f8bSJeremy L Thompson if (composite_op->input_size == -1) composite_op->input_size = input_size; 12332b730f8bSJeremy L Thompson if (composite_op->output_size == -1) composite_op->output_size = output_size; 12342b730f8bSJeremy L Thompson // Note, a size of -1 means no active vector restriction set, so no incompatibility 12351203703bSJeremy L Thompson CeedCheck((input_size == -1 || input_size == composite_op->input_size) && (output_size == -1 || output_size == composite_op->output_size), ceed, 12361203703bSJeremy L Thompson CEED_ERROR_MAJOR, 1237249f8407SJeremy L Thompson "Sub-operators must have compatible dimensions; composite operator of shape (%" CeedSize_FMT ", %" CeedSize_FMT 1238249f8407SJeremy L Thompson ") not compatible with sub-operator of " 1239249f8407SJeremy L Thompson "shape (%" CeedSize_FMT ", %" CeedSize_FMT ")", 12402b730f8bSJeremy L Thompson composite_op->input_size, composite_op->output_size, input_size, output_size); 12412b730f8bSJeremy L Thompson } 12422b730f8bSJeremy L Thompson 1243d1d35e2fSjeremylt composite_op->sub_operators[composite_op->num_suboperators] = sub_op; 12442b730f8bSJeremy L Thompson CeedCall(CeedOperatorReference(sub_op)); 1245d1d35e2fSjeremylt composite_op->num_suboperators++; 1246e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 124752d6035fSJeremy L Thompson } 124852d6035fSJeremy L Thompson 124952d6035fSJeremy L Thompson /** 1250ca94c3ddSJeremy L Thompson @brief Get the number of sub-operators associated with a `CeedOperator` 125175f0d5a4SJeremy L Thompson 1252ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1253ca94c3ddSJeremy L Thompson @param[out] num_suboperators Variable to store number of sub-operators 125475f0d5a4SJeremy L Thompson 125575f0d5a4SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 125675f0d5a4SJeremy L Thompson 125775f0d5a4SJeremy L Thompson @ref Backend 125875f0d5a4SJeremy L Thompson **/ 1259c6ebc35dSJeremy L Thompson int CeedCompositeOperatorGetNumSub(CeedOperator op, CeedInt *num_suboperators) { 12601203703bSJeremy L Thompson bool is_composite; 12611203703bSJeremy L Thompson 12621203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 12636e536b99SJeremy L Thompson CeedCheck(is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Only defined for a composite operator"); 126475f0d5a4SJeremy L Thompson *num_suboperators = op->num_suboperators; 126575f0d5a4SJeremy L Thompson return CEED_ERROR_SUCCESS; 126675f0d5a4SJeremy L Thompson } 126775f0d5a4SJeremy L Thompson 126875f0d5a4SJeremy L Thompson /** 1269ca94c3ddSJeremy L Thompson @brief Get the list of sub-operators associated with a `CeedOperator` 127075f0d5a4SJeremy L Thompson 1271ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1272ca94c3ddSJeremy L Thompson @param[out] sub_operators Variable to store list of sub-operators 127375f0d5a4SJeremy L Thompson 127475f0d5a4SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 127575f0d5a4SJeremy L Thompson 127675f0d5a4SJeremy L Thompson @ref Backend 127775f0d5a4SJeremy L Thompson **/ 1278c6ebc35dSJeremy L Thompson int CeedCompositeOperatorGetSubList(CeedOperator op, CeedOperator **sub_operators) { 12791203703bSJeremy L Thompson bool is_composite; 12801203703bSJeremy L Thompson 12811203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 12826e536b99SJeremy L Thompson CeedCheck(is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Only defined for a composite operator"); 128375f0d5a4SJeremy L Thompson *sub_operators = op->sub_operators; 128475f0d5a4SJeremy L Thompson return CEED_ERROR_SUCCESS; 128575f0d5a4SJeremy L Thompson } 128675f0d5a4SJeremy L Thompson 128775f0d5a4SJeremy L Thompson /** 1288ca94c3ddSJeremy L Thompson @brief Check if a `CeedOperator` is ready to be used. 12894db537f9SJeremy L Thompson 1290ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to check 12914db537f9SJeremy L Thompson 12924db537f9SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 12934db537f9SJeremy L Thompson 12944db537f9SJeremy L Thompson @ref User 12954db537f9SJeremy L Thompson **/ 12964db537f9SJeremy L Thompson int CeedOperatorCheckReady(CeedOperator op) { 12971203703bSJeremy L Thompson bool is_at_points, is_composite; 12984db537f9SJeremy L Thompson Ceed ceed; 12991203703bSJeremy L Thompson CeedQFunction qf = NULL; 13004db537f9SJeremy L Thompson 13012b730f8bSJeremy L Thompson if (op->is_interface_setup) return CEED_ERROR_SUCCESS; 13024db537f9SJeremy L Thompson 13031203703bSJeremy L Thompson CeedCall(CeedOperatorGetCeed(op, &ceed)); 13041203703bSJeremy L Thompson CeedCall(CeedOperatorIsAtPoints(op, &is_at_points)); 13051203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 13061203703bSJeremy L Thompson if (!is_composite) CeedCall(CeedOperatorGetQFunction(op, &qf)); 13071203703bSJeremy L Thompson if (is_composite) { 13081203703bSJeremy L Thompson CeedInt num_suboperators; 13091203703bSJeremy L Thompson 13101203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 13111203703bSJeremy L Thompson if (!num_suboperators) { 131243622462SJeremy L Thompson // Empty operator setup 131343622462SJeremy L Thompson op->input_size = 0; 131443622462SJeremy L Thompson op->output_size = 0; 131543622462SJeremy L Thompson } else { 13161203703bSJeremy L Thompson CeedOperator *sub_operators; 13171203703bSJeremy L Thompson 13181203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 13191203703bSJeremy L Thompson for (CeedInt i = 0; i < num_suboperators; i++) { 13201203703bSJeremy L Thompson CeedCall(CeedOperatorCheckReady(sub_operators[i])); 13214db537f9SJeremy L Thompson } 13222b104005SJeremy L Thompson // Sub-operators could be modified after adding to composite operator 13232b104005SJeremy L Thompson // Need to verify no lvec incompatibility from any changes 13242b104005SJeremy L Thompson CeedSize input_size, output_size; 13252b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetActiveVectorLengths(op, &input_size, &output_size)); 132643622462SJeremy L Thompson } 13274db537f9SJeremy L Thompson } else { 13281203703bSJeremy L Thompson CeedInt num_input_fields, num_output_fields; 13291203703bSJeremy L Thompson 13306574a04fSJeremy L Thompson CeedCheck(op->num_fields > 0, ceed, CEED_ERROR_INCOMPLETE, "No operator fields set"); 13311203703bSJeremy L Thompson CeedCall(CeedQFunctionGetFields(qf, &num_input_fields, NULL, &num_output_fields, NULL)); 13321203703bSJeremy L Thompson CeedCheck(op->num_fields == num_input_fields + num_output_fields, ceed, CEED_ERROR_INCOMPLETE, "Not all operator fields set"); 13336574a04fSJeremy L Thompson CeedCheck(op->has_restriction, ceed, CEED_ERROR_INCOMPLETE, "At least one restriction required"); 13342a3ff1c9SZach Atkins CeedCheck(op->num_qpts > 0 || is_at_points, ceed, CEED_ERROR_INCOMPLETE, 1335ca94c3ddSJeremy L Thompson "At least one non-collocated CeedBasis is required or the number of quadrature points must be set"); 13362b730f8bSJeremy L Thompson } 13374db537f9SJeremy L Thompson 13384db537f9SJeremy L Thompson // Flag as immutable and ready 13394db537f9SJeremy L Thompson op->is_interface_setup = true; 13401203703bSJeremy L Thompson if (qf && qf != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionSetImmutable(qf)); 13411203703bSJeremy L Thompson if (op->dqf && op->dqf != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionSetImmutable(op->dqf)); 13421203703bSJeremy L Thompson if (op->dqfT && op->dqfT != CEED_QFUNCTION_NONE) CeedCall(CeedQFunctionSetImmutable(op->dqfT)); 13434db537f9SJeremy L Thompson return CEED_ERROR_SUCCESS; 13444db537f9SJeremy L Thompson } 13454db537f9SJeremy L Thompson 13464db537f9SJeremy L Thompson /** 1347ca94c3ddSJeremy L Thompson @brief Get vector lengths for the active input and/or output `CeedVector` of a `CeedOperator`. 13484385fb7fSSebastian Grimberg 1349ca94c3ddSJeremy L Thompson Note: Lengths of `-1` indicate that the CeedOperator does not have an active input and/or output. 1350c9366a6bSJeremy L Thompson 1351ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1352ca94c3ddSJeremy L Thompson @param[out] input_size Variable to store active input vector length, or `NULL` 1353ca94c3ddSJeremy L Thompson @param[out] output_size Variable to store active output vector length, or `NULL` 1354c9366a6bSJeremy L Thompson 1355c9366a6bSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1356c9366a6bSJeremy L Thompson 1357c9366a6bSJeremy L Thompson @ref User 1358c9366a6bSJeremy L Thompson **/ 13592b730f8bSJeremy L Thompson int CeedOperatorGetActiveVectorLengths(CeedOperator op, CeedSize *input_size, CeedSize *output_size) { 1360c9366a6bSJeremy L Thompson bool is_composite; 1361c9366a6bSJeremy L Thompson 13622b104005SJeremy L Thompson if (input_size) *input_size = op->input_size; 13632b104005SJeremy L Thompson if (output_size) *output_size = op->output_size; 1364c9366a6bSJeremy L Thompson 13652b730f8bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 13662b104005SJeremy L Thompson if (is_composite && (op->input_size == -1 || op->output_size == -1)) { 13671203703bSJeremy L Thompson CeedInt num_suboperators; 13681203703bSJeremy L Thompson CeedOperator *sub_operators; 13691203703bSJeremy L Thompson 13701203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 13711203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 13721203703bSJeremy L Thompson for (CeedInt i = 0; i < num_suboperators; i++) { 1373c9366a6bSJeremy L Thompson CeedSize sub_input_size, sub_output_size; 13741c66c397SJeremy L Thompson 13751203703bSJeremy L Thompson CeedCall(CeedOperatorGetActiveVectorLengths(sub_operators[i], &sub_input_size, &sub_output_size)); 13762b104005SJeremy L Thompson if (op->input_size == -1) op->input_size = sub_input_size; 13772b104005SJeremy L Thompson if (op->output_size == -1) op->output_size = sub_output_size; 13782b104005SJeremy L Thompson // Note, a size of -1 means no active vector restriction set, so no incompatibility 13796e536b99SJeremy L Thompson CeedCheck((sub_input_size == -1 || sub_input_size == op->input_size) && (sub_output_size == -1 || sub_output_size == op->output_size), 13806e536b99SJeremy L Thompson CeedOperatorReturnCeed(op), CEED_ERROR_MAJOR, 1381249f8407SJeremy L Thompson "Sub-operators must have compatible dimensions; composite operator of shape (%" CeedSize_FMT ", %" CeedSize_FMT 1382249f8407SJeremy L Thompson ") not compatible with sub-operator of " 1383249f8407SJeremy L Thompson "shape (%" CeedSize_FMT ", %" CeedSize_FMT ")", 13842b104005SJeremy L Thompson op->input_size, op->output_size, input_size, output_size); 1385c9366a6bSJeremy L Thompson } 13862b730f8bSJeremy L Thompson } 1387c9366a6bSJeremy L Thompson return CEED_ERROR_SUCCESS; 1388c9366a6bSJeremy L Thompson } 1389c9366a6bSJeremy L Thompson 1390c9366a6bSJeremy L Thompson /** 1391ca94c3ddSJeremy L Thompson @brief Set reuse of `CeedQFunction` data in `CeedOperatorLinearAssemble*()` functions. 13924385fb7fSSebastian Grimberg 1393ca94c3ddSJeremy L Thompson When `reuse_assembly_data = false` (default), the `CeedQFunction` associated with this `CeedOperator` is re-assembled every time a `CeedOperatorLinearAssemble*()` function is called. 1394ca94c3ddSJeremy L Thompson When `reuse_assembly_data = true`, the `CeedQFunction` associated with this `CeedOperator` is reused between calls to @ref CeedOperatorSetQFunctionAssemblyDataUpdateNeeded(). 13958b919e6bSJeremy L Thompson 1396ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1397beecbf24SJeremy L Thompson @param[in] reuse_assembly_data Boolean flag setting assembly data reuse 13988b919e6bSJeremy L Thompson 13998b919e6bSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 14008b919e6bSJeremy L Thompson 14018b919e6bSJeremy L Thompson @ref Advanced 14028b919e6bSJeremy L Thompson **/ 14032b730f8bSJeremy L Thompson int CeedOperatorSetQFunctionAssemblyReuse(CeedOperator op, bool reuse_assembly_data) { 14048b919e6bSJeremy L Thompson bool is_composite; 14058b919e6bSJeremy L Thompson 14062b730f8bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 14078b919e6bSJeremy L Thompson if (is_composite) { 14088b919e6bSJeremy L Thompson for (CeedInt i = 0; i < op->num_suboperators; i++) { 14092b730f8bSJeremy L Thompson CeedCall(CeedOperatorSetQFunctionAssemblyReuse(op->sub_operators[i], reuse_assembly_data)); 14108b919e6bSJeremy L Thompson } 14118b919e6bSJeremy L Thompson } else { 14127d5185d7SSebastian Grimberg CeedQFunctionAssemblyData data; 14137d5185d7SSebastian Grimberg 14147d5185d7SSebastian Grimberg CeedCall(CeedOperatorGetQFunctionAssemblyData(op, &data)); 14157d5185d7SSebastian Grimberg CeedCall(CeedQFunctionAssemblyDataSetReuse(data, reuse_assembly_data)); 1416beecbf24SJeremy L Thompson } 1417beecbf24SJeremy L Thompson return CEED_ERROR_SUCCESS; 1418beecbf24SJeremy L Thompson } 1419beecbf24SJeremy L Thompson 1420beecbf24SJeremy L Thompson /** 1421ca94c3ddSJeremy L Thompson @brief Mark `CeedQFunction` data as updated and the `CeedQFunction` as requiring re-assembly. 1422beecbf24SJeremy L Thompson 1423ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 14246e15d496SJeremy L Thompson @param[in] needs_data_update Boolean flag setting assembly data reuse 1425beecbf24SJeremy L Thompson 1426beecbf24SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1427beecbf24SJeremy L Thompson 1428beecbf24SJeremy L Thompson @ref Advanced 1429beecbf24SJeremy L Thompson **/ 14302b730f8bSJeremy L Thompson int CeedOperatorSetQFunctionAssemblyDataUpdateNeeded(CeedOperator op, bool needs_data_update) { 1431beecbf24SJeremy L Thompson bool is_composite; 1432beecbf24SJeremy L Thompson 14332b730f8bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 1434beecbf24SJeremy L Thompson if (is_composite) { 14351203703bSJeremy L Thompson CeedInt num_suboperators; 14361203703bSJeremy L Thompson CeedOperator *sub_operators; 14371203703bSJeremy L Thompson 14381203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 14391203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 14401203703bSJeremy L Thompson for (CeedInt i = 0; i < num_suboperators; i++) { 14411203703bSJeremy L Thompson CeedCall(CeedOperatorSetQFunctionAssemblyDataUpdateNeeded(sub_operators[i], needs_data_update)); 1442beecbf24SJeremy L Thompson } 1443beecbf24SJeremy L Thompson } else { 14447d5185d7SSebastian Grimberg CeedQFunctionAssemblyData data; 14457d5185d7SSebastian Grimberg 14467d5185d7SSebastian Grimberg CeedCall(CeedOperatorGetQFunctionAssemblyData(op, &data)); 14477d5185d7SSebastian Grimberg CeedCall(CeedQFunctionAssemblyDataSetUpdateNeeded(data, needs_data_update)); 14488b919e6bSJeremy L Thompson } 14498b919e6bSJeremy L Thompson return CEED_ERROR_SUCCESS; 14508b919e6bSJeremy L Thompson } 14518b919e6bSJeremy L Thompson 14528b919e6bSJeremy L Thompson /** 1453ca94c3ddSJeremy L Thompson @brief Set name of `CeedOperator` for @ref CeedOperatorView() output 1454ea6b5821SJeremy L Thompson 1455ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 1456ea61e9acSJeremy L Thompson @param[in] name Name to set, or NULL to remove previously set name 1457ea6b5821SJeremy L Thompson 1458ea6b5821SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1459ea6b5821SJeremy L Thompson 1460ea6b5821SJeremy L Thompson @ref User 1461ea6b5821SJeremy L Thompson **/ 1462ea6b5821SJeremy L Thompson int CeedOperatorSetName(CeedOperator op, const char *name) { 1463ea6b5821SJeremy L Thompson char *name_copy; 1464ea6b5821SJeremy L Thompson size_t name_len = name ? strlen(name) : 0; 1465ea6b5821SJeremy L Thompson 14662b730f8bSJeremy L Thompson CeedCall(CeedFree(&op->name)); 1467ea6b5821SJeremy L Thompson if (name_len > 0) { 14682b730f8bSJeremy L Thompson CeedCall(CeedCalloc(name_len + 1, &name_copy)); 1469ea6b5821SJeremy L Thompson memcpy(name_copy, name, name_len); 1470ea6b5821SJeremy L Thompson op->name = name_copy; 1471ea6b5821SJeremy L Thompson } 1472ea6b5821SJeremy L Thompson return CEED_ERROR_SUCCESS; 1473ea6b5821SJeremy L Thompson } 1474ea6b5821SJeremy L Thompson 1475ea6b5821SJeremy L Thompson /** 1476935f026aSJeremy L Thompson @brief Core logic for viewing a `CeedOperator` 14777a982d89SJeremy L. Thompson 1478935f026aSJeremy L Thompson @param[in] op `CeedOperator` to view brief summary 1479ca94c3ddSJeremy L Thompson @param[in] stream Stream to write; typically `stdout` or a file 1480*8bf1b130SJames Wright @param[in] is_full Whether to write full operator view or terse 14817a982d89SJeremy L. Thompson 14827a982d89SJeremy L. Thompson @return Error code: 0 - success, otherwise - failure 14837a982d89SJeremy L. Thompson **/ 1484*8bf1b130SJames Wright static int CeedOperatorView_Core(CeedOperator op, FILE *stream, bool is_full) { 14851203703bSJeremy L Thompson bool has_name = op->name, is_composite; 14867a982d89SJeremy L. Thompson 14871203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 14881203703bSJeremy L Thompson if (is_composite) { 14891203703bSJeremy L Thompson CeedInt num_suboperators; 14901203703bSJeremy L Thompson CeedOperator *sub_operators; 14911203703bSJeremy L Thompson 14921203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 14931203703bSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 14942b730f8bSJeremy L Thompson fprintf(stream, "Composite CeedOperator%s%s\n", has_name ? " - " : "", has_name ? op->name : ""); 14957a982d89SJeremy L. Thompson 14961203703bSJeremy L Thompson for (CeedInt i = 0; i < num_suboperators; i++) { 14971203703bSJeremy L Thompson has_name = sub_operators[i]->name; 1498935f026aSJeremy L Thompson fprintf(stream, " SubOperator %" CeedInt_FMT "%s%s%s\n", i, has_name ? " - " : "", has_name ? sub_operators[i]->name : "", is_full ? ":" : ""); 1499935f026aSJeremy L Thompson if (is_full) CeedCall(CeedOperatorSingleView(sub_operators[i], 1, stream)); 15007a982d89SJeremy L. Thompson } 15017a982d89SJeremy L. Thompson } else { 15022b730f8bSJeremy L Thompson fprintf(stream, "CeedOperator%s%s\n", has_name ? " - " : "", has_name ? op->name : ""); 1503935f026aSJeremy L Thompson if (is_full) CeedCall(CeedOperatorSingleView(op, 0, stream)); 15047a982d89SJeremy L. Thompson } 1505e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 15067a982d89SJeremy L. Thompson } 15073bd813ffSjeremylt 15083bd813ffSjeremylt /** 1509935f026aSJeremy L Thompson @brief View a `CeedOperator` 1510935f026aSJeremy L Thompson 1511935f026aSJeremy L Thompson @param[in] op `CeedOperator` to view 1512935f026aSJeremy L Thompson @param[in] stream Stream to write; typically `stdout` or a file 1513935f026aSJeremy L Thompson 1514935f026aSJeremy L Thompson @return Error code: 0 - success, otherwise - failure 1515935f026aSJeremy L Thompson 1516935f026aSJeremy L Thompson @ref User 1517935f026aSJeremy L Thompson **/ 1518935f026aSJeremy L Thompson int CeedOperatorView(CeedOperator op, FILE *stream) { 1519935f026aSJeremy L Thompson CeedCall(CeedOperatorView_Core(op, stream, true)); 1520935f026aSJeremy L Thompson return CEED_ERROR_SUCCESS; 1521935f026aSJeremy L Thompson } 1522935f026aSJeremy L Thompson 1523935f026aSJeremy L Thompson /** 1524935f026aSJeremy L Thompson @brief View a brief summary `CeedOperator` 1525935f026aSJeremy L Thompson 1526935f026aSJeremy L Thompson @param[in] op `CeedOperator` to view brief summary 1527935f026aSJeremy L Thompson @param[in] stream Stream to write; typically `stdout` or a file 1528935f026aSJeremy L Thompson 1529935f026aSJeremy L Thompson @return Error code: 0 - success, otherwise - failure 1530935f026aSJeremy L Thompson 1531935f026aSJeremy L Thompson @ref User 1532935f026aSJeremy L Thompson **/ 1533935f026aSJeremy L Thompson int CeedOperatorViewTerse(CeedOperator op, FILE *stream) { 1534935f026aSJeremy L Thompson CeedCall(CeedOperatorView_Core(op, stream, false)); 1535935f026aSJeremy L Thompson return CEED_ERROR_SUCCESS; 1536935f026aSJeremy L Thompson } 1537935f026aSJeremy L Thompson 1538935f026aSJeremy L Thompson /** 1539ca94c3ddSJeremy L Thompson @brief Get the `Ceed` associated with a `CeedOperator` 1540b7c9bbdaSJeremy L Thompson 1541ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1542ca94c3ddSJeremy L Thompson @param[out] ceed Variable to store `Ceed` 1543b7c9bbdaSJeremy L Thompson 1544b7c9bbdaSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1545b7c9bbdaSJeremy L Thompson 1546b7c9bbdaSJeremy L Thompson @ref Advanced 1547b7c9bbdaSJeremy L Thompson **/ 1548b7c9bbdaSJeremy L Thompson int CeedOperatorGetCeed(CeedOperator op, Ceed *ceed) { 15496e536b99SJeremy L Thompson *ceed = CeedOperatorReturnCeed(op); 1550b7c9bbdaSJeremy L Thompson return CEED_ERROR_SUCCESS; 1551b7c9bbdaSJeremy L Thompson } 1552b7c9bbdaSJeremy L Thompson 1553b7c9bbdaSJeremy L Thompson /** 15546e536b99SJeremy L Thompson @brief Return the `Ceed` associated with a `CeedOperator` 15556e536b99SJeremy L Thompson 15566e536b99SJeremy L Thompson @param[in] op `CeedOperator` 15576e536b99SJeremy L Thompson 15586e536b99SJeremy L Thompson @return `Ceed` associated with the `op` 15596e536b99SJeremy L Thompson 15606e536b99SJeremy L Thompson @ref Advanced 15616e536b99SJeremy L Thompson **/ 15626e536b99SJeremy L Thompson Ceed CeedOperatorReturnCeed(CeedOperator op) { return op->ceed; } 15636e536b99SJeremy L Thompson 15646e536b99SJeremy L Thompson /** 1565ca94c3ddSJeremy L Thompson @brief Get the number of elements associated with a `CeedOperator` 1566b7c9bbdaSJeremy L Thompson 1567ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1568b7c9bbdaSJeremy L Thompson @param[out] num_elem Variable to store number of elements 1569b7c9bbdaSJeremy L Thompson 1570b7c9bbdaSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1571b7c9bbdaSJeremy L Thompson 1572b7c9bbdaSJeremy L Thompson @ref Advanced 1573b7c9bbdaSJeremy L Thompson **/ 1574b7c9bbdaSJeremy L Thompson int CeedOperatorGetNumElements(CeedOperator op, CeedInt *num_elem) { 15751203703bSJeremy L Thompson bool is_composite; 15761203703bSJeremy L Thompson 15771203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 15786e536b99SJeremy L Thompson CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Not defined for composite operator"); 1579b7c9bbdaSJeremy L Thompson *num_elem = op->num_elem; 1580b7c9bbdaSJeremy L Thompson return CEED_ERROR_SUCCESS; 1581b7c9bbdaSJeremy L Thompson } 1582b7c9bbdaSJeremy L Thompson 1583b7c9bbdaSJeremy L Thompson /** 1584ca94c3ddSJeremy L Thompson @brief Get the number of quadrature points associated with a `CeedOperator` 1585b7c9bbdaSJeremy L Thompson 1586ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1587b7c9bbdaSJeremy L Thompson @param[out] num_qpts Variable to store vector number of quadrature points 1588b7c9bbdaSJeremy L Thompson 1589b7c9bbdaSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1590b7c9bbdaSJeremy L Thompson 1591b7c9bbdaSJeremy L Thompson @ref Advanced 1592b7c9bbdaSJeremy L Thompson **/ 1593b7c9bbdaSJeremy L Thompson int CeedOperatorGetNumQuadraturePoints(CeedOperator op, CeedInt *num_qpts) { 15941203703bSJeremy L Thompson bool is_composite; 15951203703bSJeremy L Thompson 15961203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 15976e536b99SJeremy L Thompson CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Not defined for composite operator"); 1598b7c9bbdaSJeremy L Thompson *num_qpts = op->num_qpts; 1599b7c9bbdaSJeremy L Thompson return CEED_ERROR_SUCCESS; 1600b7c9bbdaSJeremy L Thompson } 1601b7c9bbdaSJeremy L Thompson 1602b7c9bbdaSJeremy L Thompson /** 1603ca94c3ddSJeremy L Thompson @brief Estimate number of FLOPs required to apply `CeedOperator` on the active `CeedVector` 16046e15d496SJeremy L Thompson 1605ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to estimate FLOPs for 1606ea61e9acSJeremy L Thompson @param[out] flops Address of variable to hold FLOPs estimate 16076e15d496SJeremy L Thompson 16086e15d496SJeremy L Thompson @ref Backend 16096e15d496SJeremy L Thompson **/ 16109d36ca50SJeremy L Thompson int CeedOperatorGetFlopsEstimate(CeedOperator op, CeedSize *flops) { 16116e15d496SJeremy L Thompson bool is_composite; 16121c66c397SJeremy L Thompson 16132b730f8bSJeremy L Thompson CeedCall(CeedOperatorCheckReady(op)); 16146e15d496SJeremy L Thompson 16156e15d496SJeremy L Thompson *flops = 0; 16162b730f8bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 16176e15d496SJeremy L Thompson if (is_composite) { 16186e15d496SJeremy L Thompson CeedInt num_suboperators; 16191c66c397SJeremy L Thompson 1620c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 16216e15d496SJeremy L Thompson CeedOperator *sub_operators; 1622c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 16236e15d496SJeremy L Thompson 16246e15d496SJeremy L Thompson // FLOPs for each suboperator 16256e15d496SJeremy L Thompson for (CeedInt i = 0; i < num_suboperators; i++) { 16269d36ca50SJeremy L Thompson CeedSize suboperator_flops; 16271c66c397SJeremy L Thompson 16282b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetFlopsEstimate(sub_operators[i], &suboperator_flops)); 16296e15d496SJeremy L Thompson *flops += suboperator_flops; 16306e15d496SJeremy L Thompson } 16316e15d496SJeremy L Thompson } else { 16321c66c397SJeremy L Thompson CeedInt num_input_fields, num_output_fields, num_elem = 0; 16331203703bSJeremy L Thompson CeedQFunction qf; 16341203703bSJeremy L Thompson CeedQFunctionField *qf_input_fields, *qf_output_fields; 16351203703bSJeremy L Thompson CeedOperatorField *op_input_fields, *op_output_fields; 16361c66c397SJeremy L Thompson 16371203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 16381203703bSJeremy L Thompson CeedCall(CeedQFunctionGetFields(qf, &num_input_fields, &qf_input_fields, &num_output_fields, &qf_output_fields)); 16391203703bSJeremy L Thompson CeedCall(CeedOperatorGetFields(op, NULL, &op_input_fields, NULL, &op_output_fields)); 16402b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetNumElements(op, &num_elem)); 16414385fb7fSSebastian Grimberg 16426e15d496SJeremy L Thompson // Input FLOPs 16436e15d496SJeremy L Thompson for (CeedInt i = 0; i < num_input_fields; i++) { 16441203703bSJeremy L Thompson CeedVector vec; 16456e15d496SJeremy L Thompson 16461203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(op_input_fields[i], &vec)); 16471203703bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 16481203703bSJeremy L Thompson CeedEvalMode eval_mode; 16491203703bSJeremy L Thompson CeedSize rstr_flops, basis_flops; 16501203703bSJeremy L Thompson CeedElemRestriction rstr; 16511203703bSJeremy L Thompson CeedBasis basis; 16521203703bSJeremy L Thompson 16531203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetElemRestriction(op_input_fields[i], &rstr)); 16541203703bSJeremy L Thompson CeedCall(CeedElemRestrictionGetFlopsEstimate(rstr, CEED_NOTRANSPOSE, &rstr_flops)); 1655edb2538eSJeremy L Thompson *flops += rstr_flops; 16561203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetBasis(op_input_fields[i], &basis)); 16571203703bSJeremy L Thompson CeedCall(CeedQFunctionFieldGetEvalMode(qf_input_fields[i], &eval_mode)); 16581203703bSJeremy L Thompson CeedCall(CeedBasisGetFlopsEstimate(basis, CEED_NOTRANSPOSE, eval_mode, &basis_flops)); 16596e15d496SJeremy L Thompson *flops += basis_flops * num_elem; 16606e15d496SJeremy L Thompson } 16616e15d496SJeremy L Thompson } 16626e15d496SJeremy L Thompson // QF FLOPs 16631c66c397SJeremy L Thompson { 16649d36ca50SJeremy L Thompson CeedInt num_qpts; 16659d36ca50SJeremy L Thompson CeedSize qf_flops; 16661203703bSJeremy L Thompson CeedQFunction qf; 16671c66c397SJeremy L Thompson 16682b730f8bSJeremy L Thompson CeedCall(CeedOperatorGetNumQuadraturePoints(op, &num_qpts)); 16691203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 16701203703bSJeremy L Thompson CeedCall(CeedQFunctionGetFlopsEstimate(qf, &qf_flops)); 16716e536b99SJeremy L Thompson CeedCheck(qf_flops > -1, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPLETE, 16726e536b99SJeremy L Thompson "Must set CeedQFunction FLOPs estimate with CeedQFunctionSetUserFlopsEstimate"); 16736e15d496SJeremy L Thompson *flops += num_elem * num_qpts * qf_flops; 16741c66c397SJeremy L Thompson } 16751c66c397SJeremy L Thompson 16766e15d496SJeremy L Thompson // Output FLOPs 16776e15d496SJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 16781203703bSJeremy L Thompson CeedVector vec; 16796e15d496SJeremy L Thompson 16801203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(op_output_fields[i], &vec)); 16811203703bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) { 16821203703bSJeremy L Thompson CeedEvalMode eval_mode; 16831203703bSJeremy L Thompson CeedSize rstr_flops, basis_flops; 16841203703bSJeremy L Thompson CeedElemRestriction rstr; 16851203703bSJeremy L Thompson CeedBasis basis; 16861203703bSJeremy L Thompson 16871203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetElemRestriction(op_output_fields[i], &rstr)); 16881203703bSJeremy L Thompson CeedCall(CeedElemRestrictionGetFlopsEstimate(rstr, CEED_TRANSPOSE, &rstr_flops)); 1689edb2538eSJeremy L Thompson *flops += rstr_flops; 16901203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetBasis(op_output_fields[i], &basis)); 16911203703bSJeremy L Thompson CeedCall(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode)); 16921203703bSJeremy L Thompson CeedCall(CeedBasisGetFlopsEstimate(basis, CEED_TRANSPOSE, eval_mode, &basis_flops)); 16936e15d496SJeremy L Thompson *flops += basis_flops * num_elem; 16946e15d496SJeremy L Thompson } 16956e15d496SJeremy L Thompson } 16966e15d496SJeremy L Thompson } 16976e15d496SJeremy L Thompson return CEED_ERROR_SUCCESS; 16986e15d496SJeremy L Thompson } 16996e15d496SJeremy L Thompson 17006e15d496SJeremy L Thompson /** 1701ca94c3ddSJeremy L Thompson @brief Get `CeedQFunction` global context for a `CeedOperator`. 17029fd66db6SSebastian Grimberg 1703ca94c3ddSJeremy L Thompson The caller is responsible for destroying `ctx` returned from this function via @ref CeedQFunctionContextDestroy(). 1704512bb800SJeremy L Thompson 1705ca94c3ddSJeremy 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`. 1706ca94c3ddSJeremy L Thompson This `CeedQFunctionContext` will be destroyed if `ctx` is the only reference to this `CeedQFunctionContext`. 17070126412dSJeremy L Thompson 1708ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 1709ca94c3ddSJeremy L Thompson @param[out] ctx Variable to store `CeedQFunctionContext` 17100126412dSJeremy L Thompson 17110126412dSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 17120126412dSJeremy L Thompson 1713859c15bbSJames Wright @ref Advanced 17140126412dSJeremy L Thompson **/ 17150126412dSJeremy L Thompson int CeedOperatorGetContext(CeedOperator op, CeedQFunctionContext *ctx) { 17161203703bSJeremy L Thompson bool is_composite; 17171203703bSJeremy L Thompson CeedQFunction qf; 17181203703bSJeremy L Thompson CeedQFunctionContext qf_ctx; 17191203703bSJeremy L Thompson 17201203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 17216e536b99SJeremy L Thompson CeedCheck(!is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, "Cannot retrieve CeedQFunctionContext for composite operator"); 17221203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 17231203703bSJeremy L Thompson CeedCall(CeedQFunctionGetInnerContext(qf, &qf_ctx)); 17241203703bSJeremy L Thompson if (qf_ctx) CeedCall(CeedQFunctionContextReferenceCopy(qf_ctx, ctx)); 17250126412dSJeremy L Thompson return CEED_ERROR_SUCCESS; 17260126412dSJeremy L Thompson } 17270126412dSJeremy L Thompson 17280126412dSJeremy L Thompson /** 1729ca94c3ddSJeremy L Thompson @brief Get label for a registered `CeedQFunctionContext` field, or `NULL` if no field has been registered with this `field_name`. 17303668ca4bSJeremy L Thompson 1731ca94c3ddSJeremy L Thompson Fields are registered via `CeedQFunctionContextRegister*()` functions (eg. @ref CeedQFunctionContextRegisterDouble()). 1732859c15bbSJames Wright 1733ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 17343668ca4bSJeremy L Thompson @param[in] field_name Name of field to retrieve label 17353668ca4bSJeremy L Thompson @param[out] field_label Variable to field label 17363668ca4bSJeremy L Thompson 17373668ca4bSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 17383668ca4bSJeremy L Thompson 17393668ca4bSJeremy L Thompson @ref User 17403668ca4bSJeremy L Thompson **/ 174117b0d5c6SJeremy L Thompson int CeedOperatorGetContextFieldLabel(CeedOperator op, const char *field_name, CeedContextFieldLabel *field_label) { 17421c66c397SJeremy L Thompson bool is_composite, field_found = false; 17431c66c397SJeremy L Thompson 17442b730f8bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 17452b730f8bSJeremy L Thompson 17463668ca4bSJeremy L Thompson if (is_composite) { 1747a98a090bSJeremy L Thompson // Composite operator 1748a98a090bSJeremy L Thompson // -- Check if composite label already created 17493668ca4bSJeremy L Thompson for (CeedInt i = 0; i < op->num_context_labels; i++) { 17503668ca4bSJeremy L Thompson if (!strcmp(op->context_labels[i]->name, field_name)) { 17513668ca4bSJeremy L Thompson *field_label = op->context_labels[i]; 17523668ca4bSJeremy L Thompson return CEED_ERROR_SUCCESS; 17533668ca4bSJeremy L Thompson } 17543668ca4bSJeremy L Thompson } 17553668ca4bSJeremy L Thompson 1756a98a090bSJeremy L Thompson // -- Create composite label if needed 17573668ca4bSJeremy L Thompson CeedInt num_sub; 17583668ca4bSJeremy L Thompson CeedOperator *sub_operators; 17593668ca4bSJeremy L Thompson CeedContextFieldLabel new_field_label; 17603668ca4bSJeremy L Thompson 17612b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, &new_field_label)); 1762c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub)); 1763c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 17642b730f8bSJeremy L Thompson CeedCall(CeedCalloc(num_sub, &new_field_label->sub_labels)); 17653668ca4bSJeremy L Thompson new_field_label->num_sub_labels = num_sub; 17663668ca4bSJeremy L Thompson 17673668ca4bSJeremy L Thompson for (CeedInt i = 0; i < num_sub; i++) { 17683668ca4bSJeremy L Thompson if (sub_operators[i]->qf->ctx) { 17693668ca4bSJeremy L Thompson CeedContextFieldLabel new_field_label_i; 17701c66c397SJeremy L Thompson 17712b730f8bSJeremy L Thompson CeedCall(CeedQFunctionContextGetFieldLabel(sub_operators[i]->qf->ctx, field_name, &new_field_label_i)); 17723668ca4bSJeremy L Thompson if (new_field_label_i) { 1773a98a090bSJeremy L Thompson field_found = true; 17743668ca4bSJeremy L Thompson new_field_label->sub_labels[i] = new_field_label_i; 17753668ca4bSJeremy L Thompson new_field_label->name = new_field_label_i->name; 17763668ca4bSJeremy L Thompson new_field_label->description = new_field_label_i->description; 17772b730f8bSJeremy L Thompson if (new_field_label->type && new_field_label->type != new_field_label_i->type) { 17787bfe0f0eSJeremy L Thompson // LCOV_EXCL_START 17792b730f8bSJeremy L Thompson CeedCall(CeedFree(&new_field_label)); 17806e536b99SJeremy L Thompson return CeedError(CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, "Incompatible field types on sub-operator contexts. %s != %s", 17812b730f8bSJeremy L Thompson CeedContextFieldTypes[new_field_label->type], CeedContextFieldTypes[new_field_label_i->type]); 17827bfe0f0eSJeremy L Thompson // LCOV_EXCL_STOP 17837bfe0f0eSJeremy L Thompson } else { 17847bfe0f0eSJeremy L Thompson new_field_label->type = new_field_label_i->type; 17857bfe0f0eSJeremy L Thompson } 17862b730f8bSJeremy L Thompson if (new_field_label->num_values != 0 && new_field_label->num_values != new_field_label_i->num_values) { 17877bfe0f0eSJeremy L Thompson // LCOV_EXCL_START 17882b730f8bSJeremy L Thompson CeedCall(CeedFree(&new_field_label)); 17896e536b99SJeremy L Thompson return CeedError(CeedOperatorReturnCeed(op), CEED_ERROR_INCOMPATIBLE, 17906e536b99SJeremy L Thompson "Incompatible field number of values on sub-operator contexts. %zu != %zu", new_field_label->num_values, 17916e536b99SJeremy L Thompson new_field_label_i->num_values); 17927bfe0f0eSJeremy L Thompson // LCOV_EXCL_STOP 17937bfe0f0eSJeremy L Thompson } else { 17947bfe0f0eSJeremy L Thompson new_field_label->num_values = new_field_label_i->num_values; 17957bfe0f0eSJeremy L Thompson } 17963668ca4bSJeremy L Thompson } 17973668ca4bSJeremy L Thompson } 17983668ca4bSJeremy L Thompson } 1799a98a090bSJeremy L Thompson // -- Cleanup if field was found 1800a98a090bSJeremy L Thompson if (field_found) { 1801a98a090bSJeremy L Thompson *field_label = new_field_label; 1802a98a090bSJeremy L Thompson } else { 18033668ca4bSJeremy L Thompson // LCOV_EXCL_START 18042b730f8bSJeremy L Thompson CeedCall(CeedFree(&new_field_label->sub_labels)); 18052b730f8bSJeremy L Thompson CeedCall(CeedFree(&new_field_label)); 18063668ca4bSJeremy L Thompson *field_label = NULL; 18073668ca4bSJeremy L Thompson // LCOV_EXCL_STOP 18085ac9af79SJeremy L Thompson } 18095ac9af79SJeremy L Thompson } else { 18101203703bSJeremy L Thompson CeedQFunction qf; 18111203703bSJeremy L Thompson CeedQFunctionContext ctx; 18121203703bSJeremy L Thompson 1813a98a090bSJeremy L Thompson // Single, non-composite operator 18141203703bSJeremy L Thompson CeedCall(CeedOperatorGetQFunction(op, &qf)); 18151203703bSJeremy L Thompson CeedCall(CeedQFunctionGetInnerContext(qf, &ctx)); 18161203703bSJeremy L Thompson if (ctx) { 18171203703bSJeremy L Thompson CeedCall(CeedQFunctionContextGetFieldLabel(ctx, field_name, field_label)); 1818a98a090bSJeremy L Thompson } else { 1819a98a090bSJeremy L Thompson *field_label = NULL; 1820a98a090bSJeremy L Thompson } 18215ac9af79SJeremy L Thompson } 18225ac9af79SJeremy L Thompson 18235ac9af79SJeremy L Thompson // Set label in operator 18245ac9af79SJeremy L Thompson if (*field_label) { 18255ac9af79SJeremy L Thompson (*field_label)->from_op = true; 18265ac9af79SJeremy L Thompson 18273668ca4bSJeremy L Thompson // Move new composite label to operator 18283668ca4bSJeremy L Thompson if (op->num_context_labels == 0) { 18292b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, &op->context_labels)); 18303668ca4bSJeremy L Thompson op->max_context_labels = 1; 18313668ca4bSJeremy L Thompson } else if (op->num_context_labels == op->max_context_labels) { 18322b730f8bSJeremy L Thompson CeedCall(CeedRealloc(2 * op->num_context_labels, &op->context_labels)); 18333668ca4bSJeremy L Thompson op->max_context_labels *= 2; 18343668ca4bSJeremy L Thompson } 18355ac9af79SJeremy L Thompson op->context_labels[op->num_context_labels] = *field_label; 18363668ca4bSJeremy L Thompson op->num_context_labels++; 18373668ca4bSJeremy L Thompson } 18383668ca4bSJeremy L Thompson return CEED_ERROR_SUCCESS; 18393668ca4bSJeremy L Thompson } 18403668ca4bSJeremy L Thompson 18413668ca4bSJeremy L Thompson /** 1842ca94c3ddSJeremy L Thompson @brief Set `CeedQFunctionContext` field holding double precision values. 18434385fb7fSSebastian Grimberg 1844ca94c3ddSJeremy L Thompson For composite operators, the values are set in all sub-operator `CeedQFunctionContext` that have a matching `field_name`. 1845d8dd9a91SJeremy L Thompson 1846ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 18472788fa27SJeremy L Thompson @param[in] field_label Label of field to set 1848ea61e9acSJeremy L Thompson @param[in] values Values to set 1849d8dd9a91SJeremy L Thompson 1850d8dd9a91SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1851d8dd9a91SJeremy L Thompson 1852d8dd9a91SJeremy L Thompson @ref User 1853d8dd9a91SJeremy L Thompson **/ 185417b0d5c6SJeremy L Thompson int CeedOperatorSetContextDouble(CeedOperator op, CeedContextFieldLabel field_label, double *values) { 18552b730f8bSJeremy L Thompson return CeedOperatorContextSetGeneric(op, field_label, CEED_CONTEXT_FIELD_DOUBLE, values); 1856d8dd9a91SJeremy L Thompson } 1857d8dd9a91SJeremy L Thompson 1858d8dd9a91SJeremy L Thompson /** 1859ca94c3ddSJeremy L Thompson @brief Get `CeedQFunctionContext` field holding double precision values, read-only. 18604385fb7fSSebastian Grimberg 1861ca94c3ddSJeremy L Thompson For composite operators, the values correspond to the first sub-operator `CeedQFunctionContext` that has a matching `field_name`. 18622788fa27SJeremy L Thompson 1863ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 18642788fa27SJeremy L Thompson @param[in] field_label Label of field to get 18652788fa27SJeremy L Thompson @param[out] num_values Number of values in the field label 18662788fa27SJeremy L Thompson @param[out] values Pointer to context values 18672788fa27SJeremy L Thompson 18682788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 18692788fa27SJeremy L Thompson 18702788fa27SJeremy L Thompson @ref User 18712788fa27SJeremy L Thompson **/ 187217b0d5c6SJeremy L Thompson int CeedOperatorGetContextDoubleRead(CeedOperator op, CeedContextFieldLabel field_label, size_t *num_values, const double **values) { 18732788fa27SJeremy L Thompson return CeedOperatorContextGetGenericRead(op, field_label, CEED_CONTEXT_FIELD_DOUBLE, num_values, values); 18742788fa27SJeremy L Thompson } 18752788fa27SJeremy L Thompson 18762788fa27SJeremy L Thompson /** 1877ca94c3ddSJeremy L Thompson @brief Restore `CeedQFunctionContext` field holding double precision values, read-only. 18782788fa27SJeremy L Thompson 1879ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 18802788fa27SJeremy L Thompson @param[in] field_label Label of field to restore 18812788fa27SJeremy L Thompson @param[out] values Pointer to context values 18822788fa27SJeremy L Thompson 18832788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 18842788fa27SJeremy L Thompson 18852788fa27SJeremy L Thompson @ref User 18862788fa27SJeremy L Thompson **/ 188717b0d5c6SJeremy L Thompson int CeedOperatorRestoreContextDoubleRead(CeedOperator op, CeedContextFieldLabel field_label, const double **values) { 18882788fa27SJeremy L Thompson return CeedOperatorContextRestoreGenericRead(op, field_label, CEED_CONTEXT_FIELD_DOUBLE, values); 18892788fa27SJeremy L Thompson } 18902788fa27SJeremy L Thompson 18912788fa27SJeremy L Thompson /** 1892ca94c3ddSJeremy L Thompson @brief Set `CeedQFunctionContext` field holding `int32` values. 18934385fb7fSSebastian Grimberg 1894ca94c3ddSJeremy L Thompson For composite operators, the values are set in all sub-operator `CeedQFunctionContext` that have a matching `field_name`. 1895d8dd9a91SJeremy L Thompson 1896ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 1897ea61e9acSJeremy L Thompson @param[in] field_label Label of field to set 1898ea61e9acSJeremy L Thompson @param[in] values Values to set 1899d8dd9a91SJeremy L Thompson 1900d8dd9a91SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1901d8dd9a91SJeremy L Thompson 1902d8dd9a91SJeremy L Thompson @ref User 1903d8dd9a91SJeremy L Thompson **/ 190423dbfd29SJeremy L Thompson int CeedOperatorSetContextInt32(CeedOperator op, CeedContextFieldLabel field_label, int32_t *values) { 19052b730f8bSJeremy L Thompson return CeedOperatorContextSetGeneric(op, field_label, CEED_CONTEXT_FIELD_INT32, values); 1906d8dd9a91SJeremy L Thompson } 1907d8dd9a91SJeremy L Thompson 1908d8dd9a91SJeremy L Thompson /** 1909ca94c3ddSJeremy L Thompson @brief Get `CeedQFunctionContext` field holding `int32` values, read-only. 19104385fb7fSSebastian Grimberg 1911ca94c3ddSJeremy L Thompson For composite operators, the values correspond to the first sub-operator `CeedQFunctionContext` that has a matching `field_name`. 19122788fa27SJeremy L Thompson 1913ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 19142788fa27SJeremy L Thompson @param[in] field_label Label of field to get 1915ca94c3ddSJeremy L Thompson @param[out] num_values Number of `int32` values in `values` 19162788fa27SJeremy L Thompson @param[out] values Pointer to context values 19172788fa27SJeremy L Thompson 19182788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 19192788fa27SJeremy L Thompson 19202788fa27SJeremy L Thompson @ref User 19212788fa27SJeremy L Thompson **/ 192223dbfd29SJeremy L Thompson int CeedOperatorGetContextInt32Read(CeedOperator op, CeedContextFieldLabel field_label, size_t *num_values, const int32_t **values) { 19232788fa27SJeremy L Thompson return CeedOperatorContextGetGenericRead(op, field_label, CEED_CONTEXT_FIELD_INT32, num_values, values); 19242788fa27SJeremy L Thompson } 19252788fa27SJeremy L Thompson 19262788fa27SJeremy L Thompson /** 1927ca94c3ddSJeremy L Thompson @brief Restore `CeedQFunctionContext` field holding `int32` values, read-only. 19282788fa27SJeremy L Thompson 1929ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 19302788fa27SJeremy L Thompson @param[in] field_label Label of field to get 19312788fa27SJeremy L Thompson @param[out] values Pointer to context values 19322788fa27SJeremy L Thompson 19332788fa27SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 19342788fa27SJeremy L Thompson 19352788fa27SJeremy L Thompson @ref User 19362788fa27SJeremy L Thompson **/ 193723dbfd29SJeremy L Thompson int CeedOperatorRestoreContextInt32Read(CeedOperator op, CeedContextFieldLabel field_label, const int32_t **values) { 19382788fa27SJeremy L Thompson return CeedOperatorContextRestoreGenericRead(op, field_label, CEED_CONTEXT_FIELD_INT32, values); 19392788fa27SJeremy L Thompson } 19402788fa27SJeremy L Thompson 19412788fa27SJeremy L Thompson /** 1942ca94c3ddSJeremy L Thompson @brief Set `CeedQFunctionContext` field holding boolean values. 19435b6ec284SJeremy L Thompson 1944ca94c3ddSJeremy L Thompson For composite operators, the values are set in all sub-operator `CeedQFunctionContext` that have a matching `field_name`. 19455b6ec284SJeremy L Thompson 1946ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` 19475b6ec284SJeremy L Thompson @param[in] field_label Label of field to set 19485b6ec284SJeremy L Thompson @param[in] values Values to set 19495b6ec284SJeremy L Thompson 19505b6ec284SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 19515b6ec284SJeremy L Thompson 19525b6ec284SJeremy L Thompson @ref User 19535b6ec284SJeremy L Thompson **/ 19545b6ec284SJeremy L Thompson int CeedOperatorSetContextBoolean(CeedOperator op, CeedContextFieldLabel field_label, bool *values) { 19555b6ec284SJeremy L Thompson return CeedOperatorContextSetGeneric(op, field_label, CEED_CONTEXT_FIELD_BOOL, values); 19565b6ec284SJeremy L Thompson } 19575b6ec284SJeremy L Thompson 19585b6ec284SJeremy L Thompson /** 1959ca94c3ddSJeremy L Thompson @brief Get `CeedQFunctionContext` field holding boolean values, read-only. 19605b6ec284SJeremy L Thompson 1961ca94c3ddSJeremy L Thompson For composite operators, the values correspond to the first sub-operator `CeedQFunctionContext` that has a matching `field_name`. 19625b6ec284SJeremy L Thompson 1963ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 19645b6ec284SJeremy L Thompson @param[in] field_label Label of field to get 1965ca94c3ddSJeremy L Thompson @param[out] num_values Number of boolean values in `values` 19665b6ec284SJeremy L Thompson @param[out] values Pointer to context values 19675b6ec284SJeremy L Thompson 19685b6ec284SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 19695b6ec284SJeremy L Thompson 19705b6ec284SJeremy L Thompson @ref User 19715b6ec284SJeremy L Thompson **/ 19725b6ec284SJeremy L Thompson int CeedOperatorGetContextBooleanRead(CeedOperator op, CeedContextFieldLabel field_label, size_t *num_values, const bool **values) { 19735b6ec284SJeremy L Thompson return CeedOperatorContextGetGenericRead(op, field_label, CEED_CONTEXT_FIELD_BOOL, num_values, values); 19745b6ec284SJeremy L Thompson } 19755b6ec284SJeremy L Thompson 19765b6ec284SJeremy L Thompson /** 1977ca94c3ddSJeremy L Thompson @brief Restore `CeedQFunctionContext` field holding boolean values, read-only. 19785b6ec284SJeremy L Thompson 1979ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` 19805b6ec284SJeremy L Thompson @param[in] field_label Label of field to get 19815b6ec284SJeremy L Thompson @param[out] values Pointer to context values 19825b6ec284SJeremy L Thompson 19835b6ec284SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 19845b6ec284SJeremy L Thompson 19855b6ec284SJeremy L Thompson @ref User 19865b6ec284SJeremy L Thompson **/ 19875b6ec284SJeremy L Thompson int CeedOperatorRestoreContextBooleanRead(CeedOperator op, CeedContextFieldLabel field_label, const bool **values) { 19885b6ec284SJeremy L Thompson return CeedOperatorContextRestoreGenericRead(op, field_label, CEED_CONTEXT_FIELD_BOOL, values); 19895b6ec284SJeremy L Thompson } 19905b6ec284SJeremy L Thompson 19915b6ec284SJeremy L Thompson /** 1992ca94c3ddSJeremy L Thompson @brief Apply `CeedOperator` to a `CeedVector`. 1993d7b241e6Sjeremylt 1994ea61e9acSJeremy L Thompson This computes the action of the operator on the specified (active) input, yielding its (active) output. 1995ca94c3ddSJeremy L Thompson All inputs and outputs must be specified using @ref CeedOperatorSetField(). 1996d7b241e6Sjeremylt 1997ca94c3ddSJeremy L Thompson Note: Calling this function asserts that setup is complete and sets the `CeedOperator` as immutable. 1998f04ea552SJeremy L Thompson 1999ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to apply 2000ca94c3ddSJeremy L Thompson @param[in] in `CeedVector` containing input state or @ref CEED_VECTOR_NONE if there are no active inputs 2001ca94c3ddSJeremy 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 2002ca94c3ddSJeremy L Thompson @param[in] request Address of @ref CeedRequest for non-blocking completion, else @ref CEED_REQUEST_IMMEDIATE 2003b11c1e72Sjeremylt 2004b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 2005dfdf5a53Sjeremylt 20067a982d89SJeremy L. Thompson @ref User 2007b11c1e72Sjeremylt **/ 20082b730f8bSJeremy L Thompson int CeedOperatorApply(CeedOperator op, CeedVector in, CeedVector out, CeedRequest *request) { 20091203703bSJeremy L Thompson bool is_composite; 20101203703bSJeremy L Thompson 20112b730f8bSJeremy L Thompson CeedCall(CeedOperatorCheckReady(op)); 2012d7b241e6Sjeremylt 20131203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 20141203703bSJeremy L Thompson if (is_composite) { 2015250756a7Sjeremylt // Composite Operator 2016250756a7Sjeremylt if (op->ApplyComposite) { 20172b730f8bSJeremy L Thompson CeedCall(op->ApplyComposite(op, in, out, request)); 2018250756a7Sjeremylt } else { 2019d1d35e2fSjeremylt CeedInt num_suboperators; 2020d1d35e2fSjeremylt CeedOperator *sub_operators; 20211c66c397SJeremy L Thompson 20221c66c397SJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 2023c6ebc35dSJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 2024250756a7Sjeremylt 2025250756a7Sjeremylt // Zero all output vectors 20263ca2b39bSJeremy L Thompson if (out != CEED_VECTOR_NONE) CeedCall(CeedVectorSetValue(out, 0.0)); 2027d1d35e2fSjeremylt for (CeedInt i = 0; i < num_suboperators; i++) { 20281203703bSJeremy L Thompson CeedInt num_output_fields; 20291203703bSJeremy L Thompson CeedOperatorField *output_fields; 20301c66c397SJeremy L Thompson 20311203703bSJeremy L Thompson CeedCall(CeedOperatorGetFields(sub_operators[i], NULL, NULL, &num_output_fields, &output_fields)); 20321203703bSJeremy L Thompson for (CeedInt j = 0; j < num_output_fields; j++) { 20331203703bSJeremy L Thompson CeedVector vec; 20341203703bSJeremy L Thompson 20351203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(output_fields[j], &vec)); 2036250756a7Sjeremylt if (vec != CEED_VECTOR_ACTIVE && vec != CEED_VECTOR_NONE) { 20372b730f8bSJeremy L Thompson CeedCall(CeedVectorSetValue(vec, 0.0)); 2038250756a7Sjeremylt } 2039250756a7Sjeremylt } 2040250756a7Sjeremylt } 2041250756a7Sjeremylt // Apply 2042f754c177SSebastian Grimberg for (CeedInt i = 0; i < num_suboperators; i++) { 2043f754c177SSebastian Grimberg CeedCall(CeedOperatorApplyAdd(sub_operators[i], in, out, request)); 2044cae8b89aSjeremylt } 2045cae8b89aSjeremylt } 20463ca2b39bSJeremy L Thompson } else { 20473ca2b39bSJeremy L Thompson // Standard Operator 20483ca2b39bSJeremy L Thompson if (op->Apply) { 20493ca2b39bSJeremy L Thompson CeedCall(op->Apply(op, in, out, request)); 20503ca2b39bSJeremy L Thompson } else { 20511203703bSJeremy L Thompson CeedInt num_output_fields; 20521203703bSJeremy L Thompson CeedOperatorField *output_fields; 20531203703bSJeremy L Thompson 20541203703bSJeremy L Thompson CeedCall(CeedOperatorGetFields(op, NULL, NULL, &num_output_fields, &output_fields)); 20553ca2b39bSJeremy L Thompson // Zero all output vectors 20561203703bSJeremy L Thompson for (CeedInt i = 0; i < num_output_fields; i++) { 20571203703bSJeremy L Thompson CeedVector vec; 20581c66c397SJeremy L Thompson 20591203703bSJeremy L Thompson CeedCall(CeedOperatorFieldGetVector(output_fields[i], &vec)); 20603ca2b39bSJeremy L Thompson if (vec == CEED_VECTOR_ACTIVE) vec = out; 20613ca2b39bSJeremy L Thompson if (vec != CEED_VECTOR_NONE) CeedCall(CeedVectorSetValue(vec, 0.0)); 20623ca2b39bSJeremy L Thompson } 20633ca2b39bSJeremy L Thompson // Apply 20641203703bSJeremy L Thompson if (op->num_elem > 0) CeedCall(op->ApplyAdd(op, in, out, request)); 20653ca2b39bSJeremy L Thompson } 2066250756a7Sjeremylt } 2067e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 2068cae8b89aSjeremylt } 2069cae8b89aSjeremylt 2070cae8b89aSjeremylt /** 2071ca94c3ddSJeremy L Thompson @brief Apply `CeedOperator` to a `CeedVector` and add result to output `CeedVector`. 2072cae8b89aSjeremylt 2073ea61e9acSJeremy L Thompson This computes the action of the operator on the specified (active) input, yielding its (active) output. 2074ca94c3ddSJeremy L Thompson All inputs and outputs must be specified using @ref CeedOperatorSetField(). 2075cae8b89aSjeremylt 2076ca94c3ddSJeremy L Thompson @param[in] op `CeedOperator` to apply 2077ca94c3ddSJeremy L Thompson @param[in] in `CeedVector` containing input state or @ref CEED_VECTOR_NONE if there are no active inputs 2078ca94c3ddSJeremy 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 2079ca94c3ddSJeremy L Thompson @param[in] request Address of @ref CeedRequest for non-blocking completion, else @ref CEED_REQUEST_IMMEDIATE 2080cae8b89aSjeremylt 2081cae8b89aSjeremylt @return An error code: 0 - success, otherwise - failure 2082cae8b89aSjeremylt 20837a982d89SJeremy L. Thompson @ref User 2084cae8b89aSjeremylt **/ 20852b730f8bSJeremy L Thompson int CeedOperatorApplyAdd(CeedOperator op, CeedVector in, CeedVector out, CeedRequest *request) { 20861203703bSJeremy L Thompson bool is_composite; 20871203703bSJeremy L Thompson 20882b730f8bSJeremy L Thompson CeedCall(CeedOperatorCheckReady(op)); 2089cae8b89aSjeremylt 20901203703bSJeremy L Thompson CeedCall(CeedOperatorIsComposite(op, &is_composite)); 20911203703bSJeremy L Thompson if (is_composite) { 2092250756a7Sjeremylt // Composite Operator 2093250756a7Sjeremylt if (op->ApplyAddComposite) { 20942b730f8bSJeremy L Thompson CeedCall(op->ApplyAddComposite(op, in, out, request)); 2095cae8b89aSjeremylt } else { 2096d1d35e2fSjeremylt CeedInt num_suboperators; 2097d1d35e2fSjeremylt CeedOperator *sub_operators; 2098250756a7Sjeremylt 20991c66c397SJeremy L Thompson CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 21001c66c397SJeremy L Thompson CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 2101d1d35e2fSjeremylt for (CeedInt i = 0; i < num_suboperators; i++) { 21022b730f8bSJeremy L Thompson CeedCall(CeedOperatorApplyAdd(sub_operators[i], in, out, request)); 21031d7d2407SJeremy L Thompson } 2104250756a7Sjeremylt } 21051203703bSJeremy L Thompson } else if (op->num_elem > 0) { 21063ca2b39bSJeremy L Thompson // Standard Operator 21073ca2b39bSJeremy L Thompson CeedCall(op->ApplyAdd(op, in, out, request)); 2108250756a7Sjeremylt } 2109e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 2110d7b241e6Sjeremylt } 2111d7b241e6Sjeremylt 2112d7b241e6Sjeremylt /** 2113536b928cSSebastian Grimberg @brief Destroy temporary assembly data associated with a `CeedOperator` 2114536b928cSSebastian Grimberg 2115536b928cSSebastian Grimberg @param[in,out] op `CeedOperator` whose assembly data to destroy 2116536b928cSSebastian Grimberg 2117536b928cSSebastian Grimberg @return An error code: 0 - success, otherwise - failure 2118536b928cSSebastian Grimberg 2119536b928cSSebastian Grimberg @ref User 2120536b928cSSebastian Grimberg **/ 2121536b928cSSebastian Grimberg int CeedOperatorAssemblyDataStrip(CeedOperator op) { 2122536b928cSSebastian Grimberg bool is_composite; 2123536b928cSSebastian Grimberg 2124536b928cSSebastian Grimberg CeedCall(CeedQFunctionAssemblyDataDestroy(&op->qf_assembled)); 2125536b928cSSebastian Grimberg CeedCall(CeedOperatorAssemblyDataDestroy(&op->op_assembled)); 2126536b928cSSebastian Grimberg CeedCall(CeedOperatorIsComposite(op, &is_composite)); 2127536b928cSSebastian Grimberg if (is_composite) { 2128536b928cSSebastian Grimberg CeedInt num_suboperators; 2129536b928cSSebastian Grimberg CeedOperator *sub_operators; 2130536b928cSSebastian Grimberg 2131536b928cSSebastian Grimberg CeedCall(CeedCompositeOperatorGetNumSub(op, &num_suboperators)); 2132536b928cSSebastian Grimberg CeedCall(CeedCompositeOperatorGetSubList(op, &sub_operators)); 2133536b928cSSebastian Grimberg for (CeedInt i = 0; i < num_suboperators; i++) { 2134536b928cSSebastian Grimberg CeedCall(CeedQFunctionAssemblyDataDestroy(&sub_operators[i]->qf_assembled)); 2135536b928cSSebastian Grimberg CeedCall(CeedOperatorAssemblyDataDestroy(&sub_operators[i]->op_assembled)); 2136536b928cSSebastian Grimberg } 2137536b928cSSebastian Grimberg } 2138536b928cSSebastian Grimberg return CEED_ERROR_SUCCESS; 2139536b928cSSebastian Grimberg } 2140536b928cSSebastian Grimberg 2141536b928cSSebastian Grimberg /** 2142ca94c3ddSJeremy L Thompson @brief Destroy a `CeedOperator` 2143d7b241e6Sjeremylt 2144ca94c3ddSJeremy L Thompson @param[in,out] op `CeedOperator` to destroy 2145b11c1e72Sjeremylt 2146b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 2147dfdf5a53Sjeremylt 21487a982d89SJeremy L. Thompson @ref User 2149b11c1e72Sjeremylt **/ 2150d7b241e6Sjeremylt int CeedOperatorDestroy(CeedOperator *op) { 2151ad6481ceSJeremy L Thompson if (!*op || --(*op)->ref_count > 0) { 2152ad6481ceSJeremy L Thompson *op = NULL; 2153ad6481ceSJeremy L Thompson return CEED_ERROR_SUCCESS; 2154ad6481ceSJeremy L Thompson } 2155f883f0a5SSebastian Grimberg // Backend destroy 2156f883f0a5SSebastian Grimberg if ((*op)->Destroy) { 2157f883f0a5SSebastian Grimberg CeedCall((*op)->Destroy(*op)); 2158f883f0a5SSebastian Grimberg } 2159fe2413ffSjeremylt // Free fields 21602b730f8bSJeremy L Thompson for (CeedInt i = 0; i < (*op)->num_fields; i++) { 2161d1d35e2fSjeremylt if ((*op)->input_fields[i]) { 2162437c7c90SJeremy L Thompson if ((*op)->input_fields[i]->elem_rstr != CEED_ELEMRESTRICTION_NONE) { 2163437c7c90SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&(*op)->input_fields[i]->elem_rstr)); 216415910d16Sjeremylt } 2165356036faSJeremy L Thompson if ((*op)->input_fields[i]->basis != CEED_BASIS_NONE) { 21662b730f8bSJeremy L Thompson CeedCall(CeedBasisDestroy(&(*op)->input_fields[i]->basis)); 216771352a93Sjeremylt } 21682b730f8bSJeremy L Thompson if ((*op)->input_fields[i]->vec != CEED_VECTOR_ACTIVE && (*op)->input_fields[i]->vec != CEED_VECTOR_NONE) { 21692b730f8bSJeremy L Thompson CeedCall(CeedVectorDestroy(&(*op)->input_fields[i]->vec)); 217071352a93Sjeremylt } 21712b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->input_fields[i]->field_name)); 21722b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->input_fields[i])); 2173fe2413ffSjeremylt } 21742b730f8bSJeremy L Thompson } 21752b730f8bSJeremy L Thompson for (CeedInt i = 0; i < (*op)->num_fields; i++) { 2176d1d35e2fSjeremylt if ((*op)->output_fields[i]) { 2177437c7c90SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&(*op)->output_fields[i]->elem_rstr)); 2178356036faSJeremy L Thompson if ((*op)->output_fields[i]->basis != CEED_BASIS_NONE) { 21792b730f8bSJeremy L Thompson CeedCall(CeedBasisDestroy(&(*op)->output_fields[i]->basis)); 218071352a93Sjeremylt } 21812b730f8bSJeremy L Thompson if ((*op)->output_fields[i]->vec != CEED_VECTOR_ACTIVE && (*op)->output_fields[i]->vec != CEED_VECTOR_NONE) { 21822b730f8bSJeremy L Thompson CeedCall(CeedVectorDestroy(&(*op)->output_fields[i]->vec)); 218371352a93Sjeremylt } 21842b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->output_fields[i]->field_name)); 21852b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->output_fields[i])); 21862b730f8bSJeremy L Thompson } 2187fe2413ffSjeremylt } 2188f883f0a5SSebastian Grimberg CeedCall(CeedFree(&(*op)->input_fields)); 2189f883f0a5SSebastian Grimberg CeedCall(CeedFree(&(*op)->output_fields)); 2190f883f0a5SSebastian Grimberg // Destroy AtPoints data 219148acf710SJeremy L Thompson CeedCall(CeedVectorDestroy(&(*op)->point_coords)); 219248acf710SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&(*op)->rstr_points)); 219348acf710SJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(&(*op)->first_points_rstr)); 2194c6b536a8SSebastian Grimberg // Destroy assembly data (must happen before destroying sub_operators) 2195f883f0a5SSebastian Grimberg CeedCall(CeedOperatorAssemblyDataStrip(*op)); 2196d1d35e2fSjeremylt // Destroy sub_operators 21972b730f8bSJeremy L Thompson for (CeedInt i = 0; i < (*op)->num_suboperators; i++) { 2198d1d35e2fSjeremylt if ((*op)->sub_operators[i]) { 21992b730f8bSJeremy L Thompson CeedCall(CeedOperatorDestroy(&(*op)->sub_operators[i])); 220052d6035fSJeremy L Thompson } 22012b730f8bSJeremy L Thompson } 2202f883f0a5SSebastian Grimberg CeedCall(CeedFree(&(*op)->sub_operators)); 22032b730f8bSJeremy L Thompson CeedCall(CeedQFunctionDestroy(&(*op)->qf)); 22042b730f8bSJeremy L Thompson CeedCall(CeedQFunctionDestroy(&(*op)->dqf)); 22052b730f8bSJeremy L Thompson CeedCall(CeedQFunctionDestroy(&(*op)->dqfT)); 22063668ca4bSJeremy L Thompson // Destroy any composite labels 22075ac9af79SJeremy L Thompson if ((*op)->is_composite) { 22083668ca4bSJeremy L Thompson for (CeedInt i = 0; i < (*op)->num_context_labels; i++) { 22092b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->context_labels[i]->sub_labels)); 22102b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->context_labels[i])); 22113668ca4bSJeremy L Thompson } 22125ac9af79SJeremy L Thompson } 22132b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->context_labels)); 2214fe2413ffSjeremylt 22155107b09fSJeremy L Thompson // Destroy fallback 22162b730f8bSJeremy L Thompson CeedCall(CeedOperatorDestroy(&(*op)->op_fallback)); 22175107b09fSJeremy L Thompson 22182b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*op)->name)); 2219f883f0a5SSebastian Grimberg CeedCall(CeedDestroy(&(*op)->ceed)); 22202b730f8bSJeremy L Thompson CeedCall(CeedFree(op)); 2221e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 2222d7b241e6Sjeremylt } 2223d7b241e6Sjeremylt 2224d7b241e6Sjeremylt /// @} 2225