Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(op): Add CeedCompositeOperatorGetSubByName() #1690

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/ceed/ceed.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ CEED_EXTERN int CeedOperatorIsAtPoints(CeedOperator op, bool *is_at_points);
CEED_EXTERN int CeedCompositeOperatorAddSub(CeedOperator composite_op, CeedOperator sub_op);
CEED_EXTERN int CeedCompositeOperatorGetNumSub(CeedOperator op, CeedInt *num_suboperators);
CEED_EXTERN int CeedCompositeOperatorGetSubList(CeedOperator op, CeedOperator **sub_operators);
CEED_EXTERN int CeedCompositeOperatorGetSubByName(CeedOperator op, const char *op_name, CeedOperator *sub_op);
jrwrigh marked this conversation as resolved.
Show resolved Hide resolved
CEED_EXTERN int CeedOperatorCheckReady(CeedOperator op);
CEED_EXTERN int CeedOperatorGetActiveVectorLengths(CeedOperator op, CeedSize *input_size, CeedSize *output_size);
CEED_EXTERN int CeedOperatorSetQFunctionAssemblyReuse(CeedOperator op, bool reuse_assembly_data);
Expand Down
34 changes: 34 additions & 0 deletions interface/ceed-operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,40 @@ int CeedCompositeOperatorGetSubList(CeedOperator op, CeedOperator **sub_operator
return CEED_ERROR_SUCCESS;
}

/**
@brief Get a sub `CeedOperator` of a composite `CeedOperator` from its name.

`sub_op` is set to `NULL` if the sub operator is not found.

Note: Calling this function asserts that setup is complete and sets the `CeedOperator` as immutable.

@param[in] op Composite `CeedOperator`
@param[in] op_name Name of desired sub `CeedOperator`
@param[out] sub_op Sub `CeedOperator` corresponding to the name

@return An error code: 0 - success, otherwise - failure

@ref Advanced
**/
int CeedCompositeOperatorGetSubByName(CeedOperator op, const char *op_name, CeedOperator *sub_op) {
bool is_composite;
CeedInt num_sub_ops;
CeedOperator *sub_ops;

CeedCall(CeedOperatorIsComposite(op, &is_composite));
CeedCheck(is_composite, CeedOperatorReturnCeed(op), CEED_ERROR_MINOR, "Only defined for a composite operator");
*sub_op = NULL;
CeedCall(CeedCompositeOperatorGetNumSub(op, &num_sub_ops));
CeedCall(CeedCompositeOperatorGetSubList(op, &sub_ops));
for (CeedInt i = 0; i < num_sub_ops; i++) {
if (sub_ops[i]->name && !strcmp(op_name, sub_ops[i]->name)) {
*sub_op = sub_ops[i];
return CEED_ERROR_SUCCESS;
}
}
return CEED_ERROR_SUCCESS;
}

/**
@brief Check if a `CeedOperator` is ready to be used.

Expand Down
12 changes: 12 additions & 0 deletions tests/t520-operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ int main(int argc, char **argv) {
CeedOperatorSetField(op_mass_tet, "rho", elem_restriction_q_data_tet, CEED_BASIS_NONE, q_data_tet);
CeedOperatorSetField(op_mass_tet, "u", elem_restriction_u_tet, basis_u_tet, CEED_VECTOR_ACTIVE);
CeedOperatorSetField(op_mass_tet, "v", elem_restriction_u_tet, basis_u_tet, CEED_VECTOR_ACTIVE);
CeedOperatorSetName(op_mass_tet, "mass tet");

// Set up Hex Elements
// -- Restrictions
Expand Down Expand Up @@ -154,6 +155,7 @@ int main(int argc, char **argv) {
CeedOperatorSetField(op_mass_hex, "rho", elem_restriction_q_data_hex, CEED_BASIS_NONE, q_data_hex);
CeedOperatorSetField(op_mass_hex, "u", elem_restriction_u_hex, basis_u_hex, CEED_VECTOR_ACTIVE);
CeedOperatorSetField(op_mass_hex, "v", elem_restriction_u_hex, basis_u_hex, CEED_VECTOR_ACTIVE);
CeedOperatorSetName(op_mass_hex, "mass hex");

// Set up Composite Operators
// -- Create
Expand All @@ -168,6 +170,16 @@ int main(int argc, char **argv) {
CeedCompositeOperatorAddSub(op_mass, op_mass_tet);
CeedCompositeOperatorAddSub(op_mass, op_mass_hex);

{ // Test CeedCompositeOperatorGetSubByName
CeedOperator op_byname;

CeedCompositeOperatorGetSubByName(op_mass, "mass hex", &op_byname);
if (op_byname != op_mass_hex) printf("CeedCompositeOperatorGetSubByName returned incorrect Sub Operator");

CeedCompositeOperatorGetSubByName(op_mass, "asdf", &op_byname);
if (op_byname != NULL) printf("CeedCompositeOperatorGetSubByName returned non-NULL for non-existent Sub Operator");
}

// Apply Setup Operator
CeedOperatorApply(op_setup, x, CEED_VECTOR_NONE, CEED_REQUEST_IMMEDIATE);

Expand Down