@@ -118,6 +118,9 @@ static int CeedOperatorFieldView(CeedOperatorField op_field, CeedQFunctionField
118118 if (basis == CEED_BASIS_NONE ) fprintf (stream , "%s No basis\n" , pre );
119119 if (vec == CEED_VECTOR_ACTIVE ) fprintf (stream , "%s Active vector\n" , pre );
120120 else if (vec == CEED_VECTOR_NONE ) fprintf (stream , "%s No vector\n" , pre );
121+
122+ CeedCall (CeedVectorDestroy (& vec ));
123+ CeedCall (CeedBasisDestroy (& basis ));
121124 return CEED_ERROR_SUCCESS ;
122125}
123126
@@ -207,8 +210,10 @@ int CeedOperatorGetActiveBases(CeedOperator op, CeedBasis *active_input_basis, C
207210
208211 CeedCall (CeedOperatorFieldGetBasis (op_input_fields [i ], & basis ));
209212 CeedCheck (!* active_input_basis || * active_input_basis == basis , ceed , CEED_ERROR_MINOR , "Multiple active input CeedBases found" );
210- * active_input_basis = basis ;
213+ if (!* active_input_basis ) CeedCall (CeedBasisReferenceCopy (basis , active_input_basis ));
214+ CeedCall (CeedBasisDestroy (& basis ));
211215 }
216+ CeedCall (CeedVectorDestroy (& vec ));
212217 }
213218 CeedCheck (* active_input_basis , ceed , CEED_ERROR_INCOMPLETE , "No active input CeedBasis found" );
214219 }
@@ -225,8 +230,10 @@ int CeedOperatorGetActiveBases(CeedOperator op, CeedBasis *active_input_basis, C
225230
226231 CeedCall (CeedOperatorFieldGetBasis (op_output_fields [i ], & basis ));
227232 CeedCheck (!* active_output_basis || * active_output_basis == basis , ceed , CEED_ERROR_MINOR , "Multiple active output CeedBases found" );
228- * active_output_basis = basis ;
233+ if (!* active_output_basis ) CeedCall (CeedBasisReferenceCopy (basis , active_output_basis ));
234+ CeedCall (CeedBasisDestroy (& basis ));
229235 }
236+ CeedCall (CeedVectorDestroy (& vec ));
230237 }
231238 CeedCheck (* active_output_basis , ceed , CEED_ERROR_INCOMPLETE , "No active output CeedBasis found" );
232239 }
@@ -282,8 +289,10 @@ int CeedOperatorGetActiveElemRestrictions(CeedOperator op, CeedElemRestriction *
282289
283290 CeedCall (CeedOperatorFieldGetElemRestriction (op_input_fields [i ], & rstr ));
284291 CeedCheck (!* active_input_rstr || * active_input_rstr == rstr , ceed , CEED_ERROR_MINOR , "Multiple active input CeedElemRestrictions found" );
285- * active_input_rstr = rstr ;
292+ if (!* active_input_rstr ) CeedCall (CeedElemRestrictionReferenceCopy (rstr , active_input_rstr ));
293+ CeedCall (CeedElemRestrictionDestroy (& rstr ));
286294 }
295+ CeedCall (CeedVectorDestroy (& vec ));
287296 }
288297 CeedCheck (* active_input_rstr , ceed , CEED_ERROR_INCOMPLETE , "No active input CeedElemRestriction found" );
289298 }
@@ -300,8 +309,10 @@ int CeedOperatorGetActiveElemRestrictions(CeedOperator op, CeedElemRestriction *
300309
301310 CeedCall (CeedOperatorFieldGetElemRestriction (op_output_fields [i ], & rstr ));
302311 CeedCheck (!* active_output_rstr || * active_output_rstr == rstr , ceed , CEED_ERROR_MINOR , "Multiple active output CeedElemRestrictions found" );
303- * active_output_rstr = rstr ;
312+ if (!* active_output_rstr ) CeedCall (CeedElemRestrictionReferenceCopy (rstr , active_output_rstr ));
313+ CeedCall (CeedElemRestrictionDestroy (& rstr ));
304314 }
315+ CeedCall (CeedVectorDestroy (& vec ));
305316 }
306317 CeedCheck (* active_output_rstr , ceed , CEED_ERROR_INCOMPLETE , "No active output CeedElemRestriction found" );
307318 }
@@ -563,6 +574,7 @@ int CeedOperatorHasTensorBases(CeedOperator op, bool *has_tensor_bases) {
563574 CeedCall (CeedBasisIsTensor (basis , & is_tensor ));
564575 * has_tensor_bases &= is_tensor ;
565576 }
577+ CeedCall (CeedBasisDestroy (& basis ));
566578 }
567579 for (CeedInt i = 0 ; i < num_outputs ; i ++ ) {
568580 bool is_tensor ;
@@ -573,6 +585,7 @@ int CeedOperatorHasTensorBases(CeedOperator op, bool *has_tensor_bases) {
573585 CeedCall (CeedBasisIsTensor (basis , & is_tensor ));
574586 * has_tensor_bases &= is_tensor ;
575587 }
588+ CeedCall (CeedBasisDestroy (& basis ));
576589 }
577590 return CEED_ERROR_SUCCESS ;
578591}
@@ -1138,7 +1151,9 @@ int CeedOperatorFieldGetName(CeedOperatorField op_field, const char **field_name
11381151}
11391152
11401153/**
1141- @brief Get the `CeedElemRestriction` of a `CeedOperator` Field
1154+ @brief Get the `CeedElemRestriction` of a `CeedOperator` Field.
1155+
1156+ Note: Caller is responsible for destroying the `rstr` with @ref CeedElemRestrictionDestroy().
11421157
11431158 @param[in] op_field `CeedOperator` Field
11441159 @param[out] rstr Variable to store `CeedElemRestriction`
@@ -1148,12 +1163,15 @@ int CeedOperatorFieldGetName(CeedOperatorField op_field, const char **field_name
11481163 @ref Advanced
11491164**/
11501165int CeedOperatorFieldGetElemRestriction (CeedOperatorField op_field , CeedElemRestriction * rstr ) {
1151- * rstr = op_field -> elem_rstr ;
1166+ * rstr = NULL ;
1167+ CeedCall (CeedElemRestrictionReferenceCopy (op_field -> elem_rstr , rstr ));
11521168 return CEED_ERROR_SUCCESS ;
11531169}
11541170
11551171/**
1156- @brief Get the `CeedBasis` of a `CeedOperator` Field
1172+ @brief Get the `CeedBasis` of a `CeedOperator` Field.
1173+
1174+ Note: Caller is responsible for destroying the `basis` with @ref CeedBasisDestroy().
11571175
11581176 @param[in] op_field `CeedOperator` Field
11591177 @param[out] basis Variable to store `CeedBasis`
@@ -1163,12 +1181,15 @@ int CeedOperatorFieldGetElemRestriction(CeedOperatorField op_field, CeedElemRest
11631181 @ref Advanced
11641182**/
11651183int CeedOperatorFieldGetBasis (CeedOperatorField op_field , CeedBasis * basis ) {
1166- * basis = op_field -> basis ;
1184+ * basis = NULL ;
1185+ CeedCall (CeedBasisReferenceCopy (op_field -> basis , basis ));
11671186 return CEED_ERROR_SUCCESS ;
11681187}
11691188
11701189/**
1171- @brief Get the `CeedVector` of a `CeedOperator` Field
1190+ @brief Get the `CeedVector` of a `CeedOperator` Field.
1191+
1192+ Note: Caller is responsible for destroying the `vec` with @ref CeedVectorDestroy().
11721193
11731194 @param[in] op_field `CeedOperator` Field
11741195 @param[out] vec Variable to store `CeedVector`
@@ -1178,14 +1199,17 @@ int CeedOperatorFieldGetBasis(CeedOperatorField op_field, CeedBasis *basis) {
11781199 @ref Advanced
11791200**/
11801201int CeedOperatorFieldGetVector (CeedOperatorField op_field , CeedVector * vec ) {
1181- * vec = op_field -> vec ;
1202+ * vec = NULL ;
1203+ CeedCall (CeedVectorReferenceCopy (op_field -> vec , vec ));
11821204 return CEED_ERROR_SUCCESS ;
11831205}
11841206
11851207/**
11861208 @brief Get the data of a `CeedOperator` Field.
11871209
1188- Any arguments set as `NULL` are ignored.
1210+ Any arguments set as `NULL` are ignored..
1211+
1212+ Note: Caller is responsible for destroying the `rstr`, `basis`, and `vec`.
11891213
11901214 @param[in] op_field `CeedOperator` Field
11911215 @param[out] field_name Variable to store the field name
@@ -1652,12 +1676,15 @@ int CeedOperatorGetFlopsEstimate(CeedOperator op, CeedSize *flops) {
16521676
16531677 CeedCall (CeedOperatorFieldGetElemRestriction (op_input_fields [i ], & rstr ));
16541678 CeedCall (CeedElemRestrictionGetFlopsEstimate (rstr , CEED_NOTRANSPOSE , & rstr_flops ));
1679+ CeedCall (CeedElemRestrictionDestroy (& rstr ));
16551680 * flops += rstr_flops ;
16561681 CeedCall (CeedOperatorFieldGetBasis (op_input_fields [i ], & basis ));
16571682 CeedCall (CeedQFunctionFieldGetEvalMode (qf_input_fields [i ], & eval_mode ));
16581683 CeedCall (CeedBasisGetFlopsEstimate (basis , CEED_NOTRANSPOSE , eval_mode , & basis_flops ));
1684+ CeedCall (CeedBasisDestroy (& basis ));
16591685 * flops += basis_flops * num_elem ;
16601686 }
1687+ CeedCall (CeedVectorDestroy (& vec ));
16611688 }
16621689 // QF FLOPs
16631690 {
@@ -1686,12 +1713,15 @@ int CeedOperatorGetFlopsEstimate(CeedOperator op, CeedSize *flops) {
16861713
16871714 CeedCall (CeedOperatorFieldGetElemRestriction (op_output_fields [i ], & rstr ));
16881715 CeedCall (CeedElemRestrictionGetFlopsEstimate (rstr , CEED_TRANSPOSE , & rstr_flops ));
1716+ CeedCall (CeedElemRestrictionDestroy (& rstr ));
16891717 * flops += rstr_flops ;
16901718 CeedCall (CeedOperatorFieldGetBasis (op_output_fields [i ], & basis ));
16911719 CeedCall (CeedQFunctionFieldGetEvalMode (qf_output_fields [i ], & eval_mode ));
16921720 CeedCall (CeedBasisGetFlopsEstimate (basis , CEED_TRANSPOSE , eval_mode , & basis_flops ));
1721+ CeedCall (CeedBasisDestroy (& basis ));
16931722 * flops += basis_flops * num_elem ;
16941723 }
1724+ CeedCall (CeedVectorDestroy (& vec ));
16951725 }
16961726 }
16971727 return CEED_ERROR_SUCCESS ;
@@ -2036,6 +2066,7 @@ int CeedOperatorApply(CeedOperator op, CeedVector in, CeedVector out, CeedReques
20362066 if (vec != CEED_VECTOR_ACTIVE && vec != CEED_VECTOR_NONE ) {
20372067 CeedCall (CeedVectorSetValue (vec , 0.0 ));
20382068 }
2069+ CeedCall (CeedVectorDestroy (& vec ));
20392070 }
20402071 }
20412072 // Apply
@@ -2059,6 +2090,7 @@ int CeedOperatorApply(CeedOperator op, CeedVector in, CeedVector out, CeedReques
20592090 CeedCall (CeedOperatorFieldGetVector (output_fields [i ], & vec ));
20602091 if (vec == CEED_VECTOR_ACTIVE ) vec = out ;
20612092 if (vec != CEED_VECTOR_NONE ) CeedCall (CeedVectorSetValue (vec , 0.0 ));
2093+ CeedCall (CeedVectorDestroy (& vec ));
20622094 }
20632095 // Apply
20642096 if (op -> num_elem > 0 ) CeedCall (op -> ApplyAdd (op , in , out , request ));
0 commit comments