Skip to content

Commit 2361dc6

Browse files
committed
wip - delete after OperatorFieldGet*
1 parent 79df7ad commit 2361dc6

File tree

6 files changed

+99
-36
lines changed

6 files changed

+99
-36
lines changed

examples/fluids/problems/advection.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,10 @@ PetscErrorCode CreateKSPMassOperator_AdvectionStabilized(User user, CeedOperator
3737

3838
PetscCallCeed(ceed, CeedCompositeOperatorGetSubList(user->op_rhs_ctx->op, &sub_ops));
3939
PetscCallCeed(ceed, CeedOperatorGetFieldByName(sub_ops[sub_op_index], "q", &field));
40-
PetscCallCeed(ceed, CeedOperatorFieldGetElemRestriction(field, &elem_restr_q));
41-
PetscCallCeed(ceed, CeedOperatorFieldGetBasis(field, &basis_q));
40+
PetscCallCeed(ceed, CeedOperatorFieldGetData(field, NULL, &elem_restr_q, &basis_q, NULL));
4241

4342
PetscCallCeed(ceed, CeedOperatorGetFieldByName(sub_ops[sub_op_index], "qdata", &field));
44-
PetscCallCeed(ceed, CeedOperatorFieldGetElemRestriction(field, &elem_restr_qd_i));
45-
PetscCallCeed(ceed, CeedOperatorFieldGetVector(field, &q_data));
43+
PetscCallCeed(ceed, CeedOperatorFieldGetData(field, NULL, &elem_restr_qd_i, NULL, &q_data));
4644

4745
PetscCallCeed(ceed, CeedOperatorGetContext(sub_ops[sub_op_index], &qf_ctx));
4846
}
@@ -74,6 +72,10 @@ PetscErrorCode CreateKSPMassOperator_AdvectionStabilized(User user, CeedOperator
7472
PetscCallCeed(ceed, CeedOperatorSetField(*op_mass, "v", elem_restr_q, basis_q, CEED_VECTOR_ACTIVE));
7573
PetscCallCeed(ceed, CeedOperatorSetField(*op_mass, "Grad_v", elem_restr_q, basis_q, CEED_VECTOR_ACTIVE));
7674

75+
PetscCallCeed(ceed, CeedVectorDestroy(&q_data));
76+
PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_q));
77+
PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_qd_i));
78+
PetscCallCeed(ceed, CeedBasisDestroy(&basis_q));
7779
PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_mass));
7880
PetscFunctionReturn(PETSC_SUCCESS);
7981
}

examples/fluids/problems/newtonian.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,10 @@ PetscErrorCode CreateKSPMassOperator_NewtonianStabilized(User user, CeedOperator
173173

174174
PetscCallCeed(ceed, CeedCompositeOperatorGetSubList(user->op_rhs_ctx->op, &sub_ops));
175175
PetscCallCeed(ceed, CeedOperatorGetFieldByName(sub_ops[sub_op_index], "q", &field));
176-
PetscCallCeed(ceed, CeedOperatorFieldGetElemRestriction(field, &elem_restr_q));
177-
PetscCallCeed(ceed, CeedOperatorFieldGetBasis(field, &basis_q));
176+
PetscCallCeed(ceed, Data(field, NULL, &elem_restr_q, &basis_q, NULL));
178177

179178
PetscCallCeed(ceed, CeedOperatorGetFieldByName(sub_ops[sub_op_index], "qdata", &field));
180-
PetscCallCeed(ceed, CeedOperatorFieldGetElemRestriction(field, &elem_restr_qd_i));
181-
PetscCallCeed(ceed, CeedOperatorFieldGetVector(field, &q_data));
179+
PetscCallCeed(ceed, CeedOperatorFieldGetData(field, NULL, &elem_restr_qd_i, NULL, &q_data));
182180

183181
PetscCallCeed(ceed, CeedOperatorGetContext(sub_ops[sub_op_index], &qf_ctx));
184182
}
@@ -203,6 +201,10 @@ PetscErrorCode CreateKSPMassOperator_NewtonianStabilized(User user, CeedOperator
203201
PetscCallCeed(ceed, CeedOperatorSetField(*op_mass, "v", elem_restr_q, basis_q, CEED_VECTOR_ACTIVE));
204202
PetscCallCeed(ceed, CeedOperatorSetField(*op_mass, "Grad_v", elem_restr_q, basis_q, CEED_VECTOR_ACTIVE));
205203

204+
PetscCallCeed(ceed, CeedVectorDestroy(&q_data));
205+
PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_q));
206+
PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_qd_i));
207+
PetscCallCeed(ceed, CeedBasisDestroy(&basis_q));
206208
PetscCallCeed(ceed, CeedQFunctionContextDestroy(&qf_ctx));
207209
PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_mass));
208210
PetscFunctionReturn(PETSC_SUCCESS);

examples/fluids/src/differential_filter.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ PetscErrorCode DifferentialFilterCreateOperators(Ceed ceed, User user, CeedData
137137
char field_name[PETSC_MAX_PATH_LEN];
138138
PetscCall(PetscSNPrintf(field_name, PETSC_MAX_PATH_LEN, "v%" PetscInt_FMT, i));
139139
PetscCallCeed(ceed, CeedOperatorGetFieldByName(diff_filter->op_rhs_ctx->op, field_name, &op_field));
140-
PetscCallCeed(ceed, CeedOperatorFieldGetElemRestriction(op_field, &elem_restr_filter));
141-
PetscCallCeed(ceed, CeedOperatorFieldGetBasis(op_field, &basis_filter));
140+
PetscCallCeed(ceed, CeedOperatorFieldGetData(op_field, NULL, &elem_restr_filter, &basis_filter, NULL));
142141
}
143142

144143
PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_lhs, NULL, NULL, &op_lhs_sub));
@@ -151,6 +150,8 @@ PetscErrorCode DifferentialFilterCreateOperators(Ceed ceed, User user, CeedData
151150
PetscCallCeed(ceed, CeedOperatorSetField(op_lhs_sub, "Grad_v", elem_restr_filter, basis_filter, CEED_VECTOR_ACTIVE));
152151

153152
PetscCallCeed(ceed, CeedCompositeOperatorAddSub(op_lhs, op_lhs_sub));
153+
PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_filter));
154+
PetscCallCeed(ceed, CeedBasisDestroy(&basis_filter));
154155
PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_lhs));
155156
PetscCallCeed(ceed, CeedOperatorDestroy(&op_lhs_sub));
156157
}

examples/fluids/src/setuplibceed.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,10 @@ static PetscErrorCode CreateKSPMassOperator_Unstabilized(User user, CeedOperator
3030

3131
PetscCallCeed(ceed, CeedCompositeOperatorGetSubList(user->op_rhs_ctx->op, &sub_ops));
3232
PetscCallCeed(ceed, CeedOperatorGetFieldByName(sub_ops[sub_op_index], "q", &field));
33-
PetscCallCeed(ceed, CeedOperatorFieldGetElemRestriction(field, &elem_restr_q));
34-
PetscCallCeed(ceed, CeedOperatorFieldGetBasis(field, &basis_q));
33+
PetscCallCeed(ceed, CeedOperatorFieldGetData(field, NULL, &elem_restr_q, &basis_q, NULL));
3534

3635
PetscCallCeed(ceed, CeedOperatorGetFieldByName(sub_ops[sub_op_index], "qdata", &field));
37-
PetscCallCeed(ceed, CeedOperatorFieldGetElemRestriction(field, &elem_restr_qd_i));
38-
PetscCallCeed(ceed, CeedOperatorFieldGetVector(field, &q_data));
36+
PetscCallCeed(ceed, CeedOperatorFieldGetData(field, NULL, &elem_restr_qd_i, NULL, &q_data));
3937
}
4038

4139
PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(elem_restr_q, &num_comp_q));
@@ -47,6 +45,10 @@ static PetscErrorCode CreateKSPMassOperator_Unstabilized(User user, CeedOperator
4745
PetscCallCeed(ceed, CeedOperatorSetField(*op_mass, "qdata", elem_restr_qd_i, CEED_BASIS_NONE, q_data));
4846
PetscCallCeed(ceed, CeedOperatorSetField(*op_mass, "v", elem_restr_q, basis_q, CEED_VECTOR_ACTIVE));
4947

48+
PetscCallCeed(ceed, CeedVectorDestroy(&q_data));
49+
PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_q));
50+
PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_qd_i));
51+
PetscCallCeed(ceed, CeedBasisDestroy(&basis_q));
5052
PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_mass));
5153
PetscFunctionReturn(PETSC_SUCCESS);
5254
}
@@ -198,10 +200,12 @@ static PetscErrorCode AddBCSubOperators(User user, Ceed ceed, DM dm, SimpleBC bc
198200
PetscCallCeed(ceed, CeedOperatorGetFieldByName(sub_ops[sub_op_index], "q", &field));
199201
PetscCallCeed(ceed, CeedOperatorFieldGetElemRestriction(field, &elem_restr_q));
200202
PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(elem_restr_q, &num_comp_q));
203+
PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_q));
201204

202205
PetscCallCeed(ceed, CeedOperatorGetFieldByName(sub_ops[sub_op_index], "x", &field));
203206
PetscCallCeed(ceed, CeedOperatorFieldGetElemRestriction(field, &elem_restr_x));
204207
PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(elem_restr_x, &num_comp_x));
208+
PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_x));
205209
}
206210

207211
{ // Get bases

interface/ceed-operator.c

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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
**/
11501165
int 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
**/
11651183
int 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
**/
11801201
int 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

Comments
 (0)