Skip to content

Commit

Permalink
wip - delete after OperatorFieldGet*
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylt committed Aug 19, 2024
1 parent 79df7ad commit 54e15cd
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 66 deletions.
140 changes: 111 additions & 29 deletions backends/ref/ceed-ref-operator.c

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions examples/fluids/problems/advection.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@ PetscErrorCode CreateKSPMassOperator_AdvectionStabilized(User user, CeedOperator

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

PetscCallCeed(ceed, CeedOperatorGetFieldByName(sub_ops[sub_op_index], "qdata", &field));
PetscCallCeed(ceed, CeedOperatorFieldGetElemRestriction(field, &elem_restr_qd_i));
PetscCallCeed(ceed, CeedOperatorFieldGetVector(field, &q_data));
PetscCallCeed(ceed, CeedOperatorFieldGetData(field, NULL, &elem_restr_qd_i, NULL, &q_data));

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

PetscCallCeed(ceed, CeedVectorDestroy(&q_data));
PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_q));
PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_qd_i));
PetscCallCeed(ceed, CeedBasisDestroy(&basis_q));
PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_mass));
PetscFunctionReturn(PETSC_SUCCESS);
}
Expand Down
10 changes: 6 additions & 4 deletions examples/fluids/problems/newtonian.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,10 @@ PetscErrorCode CreateKSPMassOperator_NewtonianStabilized(User user, CeedOperator

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

PetscCallCeed(ceed, CeedOperatorGetFieldByName(sub_ops[sub_op_index], "qdata", &field));
PetscCallCeed(ceed, CeedOperatorFieldGetElemRestriction(field, &elem_restr_qd_i));
PetscCallCeed(ceed, CeedOperatorFieldGetVector(field, &q_data));
PetscCallCeed(ceed, CeedOperatorFieldGetData(field, NULL, &elem_restr_qd_i, NULL, &q_data));

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

PetscCallCeed(ceed, CeedVectorDestroy(&q_data));
PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_q));
PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_qd_i));
PetscCallCeed(ceed, CeedBasisDestroy(&basis_q));
PetscCallCeed(ceed, CeedQFunctionContextDestroy(&qf_ctx));
PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_mass));
PetscFunctionReturn(PETSC_SUCCESS);
Expand Down
5 changes: 3 additions & 2 deletions examples/fluids/src/differential_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ PetscErrorCode DifferentialFilterCreateOperators(Ceed ceed, User user, CeedData
char field_name[PETSC_MAX_PATH_LEN];
PetscCall(PetscSNPrintf(field_name, PETSC_MAX_PATH_LEN, "v%" PetscInt_FMT, i));
PetscCallCeed(ceed, CeedOperatorGetFieldByName(diff_filter->op_rhs_ctx->op, field_name, &op_field));
PetscCallCeed(ceed, CeedOperatorFieldGetElemRestriction(op_field, &elem_restr_filter));
PetscCallCeed(ceed, CeedOperatorFieldGetBasis(op_field, &basis_filter));
PetscCallCeed(ceed, CeedOperatorFieldGetData(op_field, NULL, &elem_restr_filter, &basis_filter, NULL));
}

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

PetscCallCeed(ceed, CeedCompositeOperatorAddSub(op_lhs, op_lhs_sub));
PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_filter));
PetscCallCeed(ceed, CeedBasisDestroy(&basis_filter));
PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_lhs));
PetscCallCeed(ceed, CeedOperatorDestroy(&op_lhs_sub));
}
Expand Down
12 changes: 8 additions & 4 deletions examples/fluids/src/setuplibceed.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ static PetscErrorCode CreateKSPMassOperator_Unstabilized(User user, CeedOperator

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

PetscCallCeed(ceed, CeedOperatorGetFieldByName(sub_ops[sub_op_index], "qdata", &field));
PetscCallCeed(ceed, CeedOperatorFieldGetElemRestriction(field, &elem_restr_qd_i));
PetscCallCeed(ceed, CeedOperatorFieldGetVector(field, &q_data));
PetscCallCeed(ceed, CeedOperatorFieldGetData(field, NULL, &elem_restr_qd_i, NULL, &q_data));
}

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

PetscCallCeed(ceed, CeedVectorDestroy(&q_data));
PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_q));
PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_qd_i));
PetscCallCeed(ceed, CeedBasisDestroy(&basis_q));
PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_mass));
PetscFunctionReturn(PETSC_SUCCESS);
}
Expand Down Expand Up @@ -198,10 +200,12 @@ static PetscErrorCode AddBCSubOperators(User user, Ceed ceed, DM dm, SimpleBC bc
PetscCallCeed(ceed, CeedOperatorGetFieldByName(sub_ops[sub_op_index], "q", &field));
PetscCallCeed(ceed, CeedOperatorFieldGetElemRestriction(field, &elem_restr_q));
PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(elem_restr_q, &num_comp_q));
PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_q));

PetscCallCeed(ceed, CeedOperatorGetFieldByName(sub_ops[sub_op_index], "x", &field));
PetscCallCeed(ceed, CeedOperatorFieldGetElemRestriction(field, &elem_restr_x));
PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(elem_restr_x, &num_comp_x));
PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_x));
}

{ // Get bases
Expand Down
58 changes: 46 additions & 12 deletions interface/ceed-operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ static int CeedOperatorFieldView(CeedOperatorField op_field, CeedQFunctionField
if (basis == CEED_BASIS_NONE) fprintf(stream, "%s No basis\n", pre);
if (vec == CEED_VECTOR_ACTIVE) fprintf(stream, "%s Active vector\n", pre);
else if (vec == CEED_VECTOR_NONE) fprintf(stream, "%s No vector\n", pre);

CeedCall(CeedVectorDestroy(&vec));
CeedCall(CeedBasisDestroy(&basis));
return CEED_ERROR_SUCCESS;
}

Expand Down Expand Up @@ -207,8 +210,10 @@ int CeedOperatorGetActiveBases(CeedOperator op, CeedBasis *active_input_basis, C

CeedCall(CeedOperatorFieldGetBasis(op_input_fields[i], &basis));
CeedCheck(!*active_input_basis || *active_input_basis == basis, ceed, CEED_ERROR_MINOR, "Multiple active input CeedBases found");
*active_input_basis = basis;
if (!*active_input_basis) CeedCall(CeedBasisReferenceCopy(basis, active_input_basis));
CeedCall(CeedBasisDestroy(&basis));
}
CeedCall(CeedVectorDestroy(&vec));
}
CeedCheck(*active_input_basis, ceed, CEED_ERROR_INCOMPLETE, "No active input CeedBasis found");
}
Expand All @@ -225,8 +230,10 @@ int CeedOperatorGetActiveBases(CeedOperator op, CeedBasis *active_input_basis, C

CeedCall(CeedOperatorFieldGetBasis(op_output_fields[i], &basis));
CeedCheck(!*active_output_basis || *active_output_basis == basis, ceed, CEED_ERROR_MINOR, "Multiple active output CeedBases found");
*active_output_basis = basis;
if (!*active_output_basis) CeedCall(CeedBasisReferenceCopy(basis, active_output_basis));
CeedCall(CeedBasisDestroy(&basis));
}
CeedCall(CeedVectorDestroy(&vec));
}
CeedCheck(*active_output_basis, ceed, CEED_ERROR_INCOMPLETE, "No active output CeedBasis found");
}
Expand Down Expand Up @@ -282,8 +289,10 @@ int CeedOperatorGetActiveElemRestrictions(CeedOperator op, CeedElemRestriction *

CeedCall(CeedOperatorFieldGetElemRestriction(op_input_fields[i], &rstr));
CeedCheck(!*active_input_rstr || *active_input_rstr == rstr, ceed, CEED_ERROR_MINOR, "Multiple active input CeedElemRestrictions found");
*active_input_rstr = rstr;
if (!*active_input_rstr) CeedCall(CeedElemRestrictionReferenceCopy(rstr, active_input_rstr));
CeedCall(CeedElemRestrictionDestroy(&rstr));
}
CeedCall(CeedVectorDestroy(&vec));
}
CeedCheck(*active_input_rstr, ceed, CEED_ERROR_INCOMPLETE, "No active input CeedElemRestriction found");
}
Expand All @@ -300,8 +309,10 @@ int CeedOperatorGetActiveElemRestrictions(CeedOperator op, CeedElemRestriction *

CeedCall(CeedOperatorFieldGetElemRestriction(op_output_fields[i], &rstr));
CeedCheck(!*active_output_rstr || *active_output_rstr == rstr, ceed, CEED_ERROR_MINOR, "Multiple active output CeedElemRestrictions found");
*active_output_rstr = rstr;
if (!*active_output_rstr) CeedCall(CeedElemRestrictionReferenceCopy(rstr, active_output_rstr));
CeedCall(CeedElemRestrictionDestroy(&rstr));
}
CeedCall(CeedVectorDestroy(&vec));
}
CeedCheck(*active_output_rstr, ceed, CEED_ERROR_INCOMPLETE, "No active output CeedElemRestriction found");
}
Expand Down Expand Up @@ -563,6 +574,7 @@ int CeedOperatorHasTensorBases(CeedOperator op, bool *has_tensor_bases) {
CeedCall(CeedBasisIsTensor(basis, &is_tensor));
*has_tensor_bases &= is_tensor;
}
CeedCall(CeedBasisDestroy(&basis));
}
for (CeedInt i = 0; i < num_outputs; i++) {
bool is_tensor;
Expand All @@ -573,6 +585,7 @@ int CeedOperatorHasTensorBases(CeedOperator op, bool *has_tensor_bases) {
CeedCall(CeedBasisIsTensor(basis, &is_tensor));
*has_tensor_bases &= is_tensor;
}
CeedCall(CeedBasisDestroy(&basis));
}
return CEED_ERROR_SUCCESS;
}
Expand Down Expand Up @@ -1138,7 +1151,9 @@ int CeedOperatorFieldGetName(CeedOperatorField op_field, const char **field_name
}

/**
@brief Get the `CeedElemRestriction` of a `CeedOperator` Field
@brief Get the `CeedElemRestriction` of a `CeedOperator` Field.
Note: Caller is responsible for destroying the `rstr` with @ref CeedElemRestrictionDestroy().
@param[in] op_field `CeedOperator` Field
@param[out] rstr Variable to store `CeedElemRestriction`
Expand All @@ -1148,12 +1163,15 @@ int CeedOperatorFieldGetName(CeedOperatorField op_field, const char **field_name
@ref Advanced
**/
int CeedOperatorFieldGetElemRestriction(CeedOperatorField op_field, CeedElemRestriction *rstr) {
*rstr = op_field->elem_rstr;
*rstr = NULL;
CeedCall(CeedElemRestrictionReferenceCopy(op_field->elem_rstr, rstr));
return CEED_ERROR_SUCCESS;
}

/**
@brief Get the `CeedBasis` of a `CeedOperator` Field
@brief Get the `CeedBasis` of a `CeedOperator` Field.
Note: Caller is responsible for destroying the `basis` with @ref CeedBasisDestroy().
@param[in] op_field `CeedOperator` Field
@param[out] basis Variable to store `CeedBasis`
Expand All @@ -1163,12 +1181,15 @@ int CeedOperatorFieldGetElemRestriction(CeedOperatorField op_field, CeedElemRest
@ref Advanced
**/
int CeedOperatorFieldGetBasis(CeedOperatorField op_field, CeedBasis *basis) {
*basis = op_field->basis;
*basis = NULL;
CeedCall(CeedBasisReferenceCopy(op_field->basis, basis));
return CEED_ERROR_SUCCESS;
}

/**
@brief Get the `CeedVector` of a `CeedOperator` Field
@brief Get the `CeedVector` of a `CeedOperator` Field.
Note: Caller is responsible for destroying the `vec` with @ref CeedVectorDestroy().
@param[in] op_field `CeedOperator` Field
@param[out] vec Variable to store `CeedVector`
Expand All @@ -1178,14 +1199,17 @@ int CeedOperatorFieldGetBasis(CeedOperatorField op_field, CeedBasis *basis) {
@ref Advanced
**/
int CeedOperatorFieldGetVector(CeedOperatorField op_field, CeedVector *vec) {
*vec = op_field->vec;
*vec = NULL;
CeedCall(CeedVectorReferenceCopy(op_field->vec, vec));
return CEED_ERROR_SUCCESS;
}

/**
@brief Get the data of a `CeedOperator` Field.
Any arguments set as `NULL` are ignored.
Any arguments set as `NULL` are ignored..
Note: Caller is responsible for destroying the `rstr`, `basis`, and `vec`.
@param[in] op_field `CeedOperator` Field
@param[out] field_name Variable to store the field name
Expand Down Expand Up @@ -1652,12 +1676,15 @@ int CeedOperatorGetFlopsEstimate(CeedOperator op, CeedSize *flops) {

CeedCall(CeedOperatorFieldGetElemRestriction(op_input_fields[i], &rstr));
CeedCall(CeedElemRestrictionGetFlopsEstimate(rstr, CEED_NOTRANSPOSE, &rstr_flops));
CeedCall(CeedElemRestrictionDestroy(&rstr));
*flops += rstr_flops;
CeedCall(CeedOperatorFieldGetBasis(op_input_fields[i], &basis));
CeedCall(CeedQFunctionFieldGetEvalMode(qf_input_fields[i], &eval_mode));
CeedCall(CeedBasisGetFlopsEstimate(basis, CEED_NOTRANSPOSE, eval_mode, &basis_flops));
CeedCall(CeedBasisDestroy(&basis));
*flops += basis_flops * num_elem;
}
CeedCall(CeedVectorDestroy(&vec));
}
// QF FLOPs
{
Expand Down Expand Up @@ -1686,12 +1713,15 @@ int CeedOperatorGetFlopsEstimate(CeedOperator op, CeedSize *flops) {

CeedCall(CeedOperatorFieldGetElemRestriction(op_output_fields[i], &rstr));
CeedCall(CeedElemRestrictionGetFlopsEstimate(rstr, CEED_TRANSPOSE, &rstr_flops));
CeedCall(CeedElemRestrictionDestroy(&rstr));
*flops += rstr_flops;
CeedCall(CeedOperatorFieldGetBasis(op_output_fields[i], &basis));
CeedCall(CeedQFunctionFieldGetEvalMode(qf_output_fields[i], &eval_mode));
CeedCall(CeedBasisGetFlopsEstimate(basis, CEED_TRANSPOSE, eval_mode, &basis_flops));
CeedCall(CeedBasisDestroy(&basis));
*flops += basis_flops * num_elem;
}
CeedCall(CeedVectorDestroy(&vec));
}
}
return CEED_ERROR_SUCCESS;
Expand Down Expand Up @@ -2036,6 +2066,7 @@ int CeedOperatorApply(CeedOperator op, CeedVector in, CeedVector out, CeedReques
if (vec != CEED_VECTOR_ACTIVE && vec != CEED_VECTOR_NONE) {
CeedCall(CeedVectorSetValue(vec, 0.0));
}
CeedCall(CeedVectorDestroy(&vec));
}
}
// Apply
Expand All @@ -2054,11 +2085,14 @@ int CeedOperatorApply(CeedOperator op, CeedVector in, CeedVector out, CeedReques
CeedCall(CeedOperatorGetFields(op, NULL, NULL, &num_output_fields, &output_fields));
// Zero all output vectors
for (CeedInt i = 0; i < num_output_fields; i++) {
bool is_active;
CeedVector vec;

CeedCall(CeedOperatorFieldGetVector(output_fields[i], &vec));
if (vec == CEED_VECTOR_ACTIVE) vec = out;
is_active = vec == CEED_VECTOR_ACTIVE;
if (is_active) vec = out;
if (vec != CEED_VECTOR_NONE) CeedCall(CeedVectorSetValue(vec, 0.0));
if (!is_active) CeedCall(CeedVectorDestroy(&vec));
}
// Apply
if (op->num_elem > 0) CeedCall(op->ApplyAdd(op, in, out, request));
Expand Down
Loading

0 comments on commit 54e15cd

Please sign in to comment.