Skip to content

Commit 678fcfc

Browse files
authored
Merge pull request #946 from CEED/jeremy/label-to-backend
Move CeedQFunctionContextGetFieldLabel to backend interface
2 parents f80f6cc + 3e1e85a commit 678fcfc

4 files changed

Lines changed: 94 additions & 93 deletions

File tree

include/ceed/backend.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,15 @@ CEED_EXTERN int CeedQFunctionContextGetBackendData(CeedQFunctionContext ctx,
250250
void *data);
251251
CEED_EXTERN int CeedQFunctionContextSetBackendData(CeedQFunctionContext ctx,
252252
void *data);
253+
CEED_EXTERN int CeedQFunctionContextGetFieldLabel(CeedQFunctionContext ctx,
254+
const char *field_name, CeedContextFieldLabel *field_label);
253255
CEED_EXTERN int CeedQFunctionContextSetGeneric(CeedQFunctionContext ctx,
254256
CeedContextFieldLabel field_label,
255257
CeedContextFieldType field_type, void *value);
258+
CEED_EXTERN int CeedQFunctionContextSetDouble(CeedQFunctionContext ctx,
259+
CeedContextFieldLabel field_label, double *values);
260+
CEED_EXTERN int CeedQFunctionContextSetInt32(CeedQFunctionContext ctx,
261+
CeedContextFieldLabel field_label, int *values);
256262
CEED_EXTERN int CeedQFunctionContextReference(CeedQFunctionContext ctx);
257263

258264
CEED_EXTERN int CeedQFunctionAssemblyDataCreate(Ceed ceed, CeedQFunctionAssemblyData *data);

include/ceed/ceed.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -677,17 +677,11 @@ CEED_EXTERN int CeedQFunctionContextRegisterDouble(CeedQFunctionContext ctx,
677677
CEED_EXTERN int CeedQFunctionContextRegisterInt32(CeedQFunctionContext ctx,
678678
const char *field_name, size_t field_offset, size_t num_values,
679679
const char *field_description);
680-
CEED_EXTERN int CeedQFunctionContextGetFieldLabel(CeedQFunctionContext ctx,
681-
const char *field_name, CeedContextFieldLabel *field_label);
682680
CEED_EXTERN int CeedQFunctionContextGetAllFieldLabels(CeedQFunctionContext ctx,
683681
const CeedContextFieldLabel **field_labels, CeedInt *num_fields);
684682
CEED_EXTERN int CeedContextFieldLabelGetDescription(CeedContextFieldLabel label,
685683
const char **field_name, const char **field_description, size_t *num_values,
686684
CeedContextFieldType *field_type);
687-
CEED_EXTERN int CeedQFunctionContextSetDouble(CeedQFunctionContext ctx,
688-
CeedContextFieldLabel field_label, double *values);
689-
CEED_EXTERN int CeedQFunctionContextSetInt32(CeedQFunctionContext ctx,
690-
CeedContextFieldLabel field_label, int *values);
691685
CEED_EXTERN int CeedQFunctionContextGetContextSize(CeedQFunctionContext ctx,
692686
size_t *ctx_size);
693687
CEED_EXTERN int CeedQFunctionContextView(CeedQFunctionContext ctx,

interface/ceed-qfunctioncontext.c

Lines changed: 87 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,36 @@ int CeedQFunctionContextSetBackendData(CeedQFunctionContext ctx, void *data) {
221221
return CEED_ERROR_SUCCESS;
222222
}
223223

224+
/**
225+
@brief Get label for a registered QFunctionContext field, or `NULL` if no
226+
field has been registered with this `field_name`
227+
228+
@param[in] ctx CeedQFunctionContext
229+
@param[in] field_name Name of field to retrieve label
230+
@param[out] field_label Variable to field label
231+
232+
@return An error code: 0 - success, otherwise - failure
233+
234+
@ref Backend
235+
**/
236+
int CeedQFunctionContextGetFieldLabel(CeedQFunctionContext ctx,
237+
const char *field_name,
238+
CeedContextFieldLabel *field_label) {
239+
int ierr;
240+
241+
CeedInt field_index;
242+
ierr = CeedQFunctionContextGetFieldIndex(ctx, field_name, &field_index);
243+
CeedChk(ierr);
244+
245+
if (field_index != -1) {
246+
*field_label = ctx->field_labels[field_index];
247+
} else {
248+
*field_label = NULL;
249+
}
250+
251+
return CEED_ERROR_SUCCESS;
252+
}
253+
224254
/**
225255
@brief Set QFunctionContext field
226256
@@ -231,7 +261,7 @@ int CeedQFunctionContextSetBackendData(CeedQFunctionContext ctx, void *data) {
231261
232262
@return An error code: 0 - success, otherwise - failure
233263
234-
@ref User
264+
@ref Backend
235265
**/
236266
int CeedQFunctionContextSetGeneric(CeedQFunctionContext ctx,
237267
CeedContextFieldLabel field_label,
@@ -257,6 +287,62 @@ int CeedQFunctionContextSetGeneric(CeedQFunctionContext ctx,
257287
return CEED_ERROR_SUCCESS;
258288
}
259289

290+
/**
291+
@brief Set QFunctionContext field holding a double precision value
292+
293+
@param ctx CeedQFunctionContext
294+
@param field_label Label for field to register
295+
@param values Values to set
296+
297+
@return An error code: 0 - success, otherwise - failure
298+
299+
@ref Backend
300+
**/
301+
int CeedQFunctionContextSetDouble(CeedQFunctionContext ctx,
302+
CeedContextFieldLabel field_label, double *values) {
303+
int ierr;
304+
305+
if (!field_label)
306+
// LCOV_EXCL_START
307+
return CeedError(ctx->ceed, CEED_ERROR_UNSUPPORTED,
308+
"Invalid field label");
309+
// LCOV_EXCL_STOP
310+
311+
ierr = CeedQFunctionContextSetGeneric(ctx, field_label,
312+
CEED_CONTEXT_FIELD_DOUBLE,
313+
values); CeedChk(ierr);
314+
315+
return CEED_ERROR_SUCCESS;
316+
}
317+
318+
/**
319+
@brief Set QFunctionContext field holding an int32 value
320+
321+
@param ctx CeedQFunctionContext
322+
@param field_label Label for field to register
323+
@param values Values to set
324+
325+
@return An error code: 0 - success, otherwise - failure
326+
327+
@ref Backend
328+
**/
329+
int CeedQFunctionContextSetInt32(CeedQFunctionContext ctx,
330+
CeedContextFieldLabel field_label, int *values) {
331+
int ierr;
332+
333+
if (!field_label)
334+
// LCOV_EXCL_START
335+
return CeedError(ctx->ceed, CEED_ERROR_UNSUPPORTED,
336+
"Invalid field label");
337+
// LCOV_EXCL_STOP
338+
339+
ierr = CeedQFunctionContextSetGeneric(ctx, field_label,
340+
CEED_CONTEXT_FIELD_INT32,
341+
values); CeedChk(ierr);
342+
343+
return CEED_ERROR_SUCCESS;
344+
}
345+
260346
/**
261347
@brief Increment the reference counter for a CeedQFunctionContext
262348
@@ -653,36 +739,6 @@ int CeedQFunctionContextGetAllFieldLabels(CeedQFunctionContext ctx,
653739
return CEED_ERROR_SUCCESS;
654740
}
655741

656-
/**
657-
@brief Get label for a registered QFunctionContext field, or `NULL` if no
658-
field has been registered with this `field_name`
659-
660-
@param[in] ctx CeedQFunctionContext
661-
@param[in] field_name Name of field to retrieve label
662-
@param[out] field_label Variable to field label
663-
664-
@return An error code: 0 - success, otherwise - failure
665-
666-
@ref User
667-
**/
668-
int CeedQFunctionContextGetFieldLabel(CeedQFunctionContext ctx,
669-
const char *field_name,
670-
CeedContextFieldLabel *field_label) {
671-
int ierr;
672-
673-
CeedInt field_index;
674-
ierr = CeedQFunctionContextGetFieldIndex(ctx, field_name, &field_index);
675-
CeedChk(ierr);
676-
677-
if (field_index != -1) {
678-
*field_label = ctx->field_labels[field_index];
679-
} else {
680-
*field_label = NULL;
681-
}
682-
683-
return CEED_ERROR_SUCCESS;
684-
}
685-
686742
/**
687743
@brief Get the descriptive information about a CeedContextFieldLabel
688744
@@ -708,62 +764,6 @@ int CeedContextFieldLabelGetDescription(CeedContextFieldLabel label,
708764
return CEED_ERROR_SUCCESS;
709765
}
710766

711-
/**
712-
@brief Set QFunctionContext field holding a double precision value
713-
714-
@param ctx CeedQFunctionContext
715-
@param field_label Label for field to register
716-
@param values Values to set
717-
718-
@return An error code: 0 - success, otherwise - failure
719-
720-
@ref User
721-
**/
722-
int CeedQFunctionContextSetDouble(CeedQFunctionContext ctx,
723-
CeedContextFieldLabel field_label, double *values) {
724-
int ierr;
725-
726-
if (!field_label)
727-
// LCOV_EXCL_START
728-
return CeedError(ctx->ceed, CEED_ERROR_UNSUPPORTED,
729-
"Invalid field label");
730-
// LCOV_EXCL_STOP
731-
732-
ierr = CeedQFunctionContextSetGeneric(ctx, field_label,
733-
CEED_CONTEXT_FIELD_DOUBLE,
734-
values); CeedChk(ierr);
735-
736-
return CEED_ERROR_SUCCESS;
737-
}
738-
739-
/**
740-
@brief Set QFunctionContext field holding an int32 value
741-
742-
@param ctx CeedQFunctionContext
743-
@param field_label Label for field to register
744-
@param values Values to set
745-
746-
@return An error code: 0 - success, otherwise - failure
747-
748-
@ref User
749-
**/
750-
int CeedQFunctionContextSetInt32(CeedQFunctionContext ctx,
751-
CeedContextFieldLabel field_label, int *values) {
752-
int ierr;
753-
754-
if (!field_label)
755-
// LCOV_EXCL_START
756-
return CeedError(ctx->ceed, CEED_ERROR_UNSUPPORTED,
757-
"Invalid field label");
758-
// LCOV_EXCL_STOP
759-
760-
ierr = CeedQFunctionContextSetGeneric(ctx, field_label,
761-
CEED_CONTEXT_FIELD_INT32,
762-
values); CeedChk(ierr);
763-
764-
return CEED_ERROR_SUCCESS;
765-
}
766-
767767
/**
768768
@brief Get data size for a Context
769769

tests/t407-qfunction.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/// Test registering and setting QFunctionContext fields
33
/// \test Test registering and setting QFunctionContext fields
44
#include <ceed.h>
5+
#include <ceed/backend.h>
56
#include <stddef.h>
67
#include <string.h>
78

0 commit comments

Comments
 (0)