Skip to content

ctx - expand CeedContextFieldType to support additional field types - #2008

Draft
ksd-2005 wants to merge 2 commits into
CEED:mainfrom
ksd-2005:dharan/context-field-types
Draft

ctx - expand CeedContextFieldType to support additional field types#2008
ksd-2005 wants to merge 2 commits into
CEED:mainfrom
ksd-2005:dharan/context-field-types

Conversation

@ksd-2005

@ksd-2005 ksd-2005 commented Aug 19, 2026

Copy link
Copy Markdown

Purpose:

Adds seven new CeedContextFieldType values - BYTE, INT8, INT, INT64, SIZE, SCALAR,
and FLOAT - alongside the existing DOUBLE, INT32, and BOOL, with matching
CeedQFunctionContextRegisterCeed* / Set* / Get*Read / Restore*Read functions on both
CeedQFunctionContext and CeedOperator.

As we agreed in the issue discussion, this renumbers the existing CeedContextFieldType enum
(an intentional ABI break, approved ahead of the 1.0 release) and gives every accessor function
a Ceed-prefixed name for the libCEED-typedef'd types, as per @jeremylt 's and @zatkins-dev 's suggestion.

CEED_CONTEXT_FIELD_SCALAR, FLOAT, and DOUBLE are kept as distinct field types.

One thing I want to mention is:
The discussion we had earlier didn't say an exact enum ordering for the final 10-type set - the only ordering anyone said was the case order of
the switch @jeremylt posted (BOOL, BYTE, INT8, INT, INT32, INT64, SIZE, SCALAR, FLOAT, DOUBLE).
I've used

typedef enum {
  /// Byte value, C type of char
  CEED_CONTEXT_FIELD_BYTE = 1,
  /// CeedScalar value
  CEED_CONTEXT_FIELD_SCALAR = 2,
  /// Single precision value
  CEED_CONTEXT_FIELD_FLOAT = 3,
  /// Double precision value
  CEED_CONTEXT_FIELD_DOUBLE = 4,
  ///8 bit integer value
  CEED_CONTEXT_FIELD_INT8 = 5,
  /// CeedInt value
  CEED_CONTEXT_FIELD_INT = 6,
  /// 32 bit integer value
  CEED_CONTEXT_FIELD_INT32 = 7,
  /// 64 bit integer value
  CEED_CONTEXT_FIELD_INT64 = 8,
  /// CeedSize value
  CEED_CONTEXT_FIELD_SIZE = 9,
  /// Boolean value
  CEED_CONTEXT_FIELD_BOOL = 10,
} CeedContextFieldType;

I am happy to change the ordering if anything else was intended.

This PR is currently a draft. The below tasks remain, before it's ready for full review:

  • Extend tests/t407-qfunction.c to cover all ten field types (currently covers three)
  • Confirm the enum ordering above
  • make prove-all clean run including examples/fluids

These will be completed by tomorrow afternoon

Closes: #2004

LLM/GenAI Disclosure:

I used Claude to help me understand the existing CeedQFunctionContext
in interface/ceed-qfunctioncontext.c and interface/ceed-operator.c before
writing this change, and to review my diff against the design decisions from the issue thread -
it pointed out a few bugs (a CeedSize/size_t signature mismatch that failed to compile, a
stale CeedContextFieldTypes[] string table) which I then fixed myself.

ALL CODE SOURCE CHANGES IN THIS PR ARE WRITTEN BY ME.

By submitting this PR, the author certifies to its contents as described by the Developer's Certificate of Origin.

…ieldType

Added a Ceed prefix to accessors for the libCEED-typedef'd types.
Updated  Clang.jl compat to 0.19 and regenerated bindings
Clang.jl 0.16 depends on the deprecated Clang_jll, which no longer
resolves in the current registry. Regenerate for CeedContextFieldType
expansion.
@ksd-2005

ksd-2005 commented Aug 19, 2026

Copy link
Copy Markdown
Author

Please also let me know, if I have to change any coding style( I followed the exact way in which other functions are written in the codebase, but i want to know if I can change anything else), or can improve by making the code concise anywhere, I would like to learn on ways to improve the code.

@jeremylt

Copy link
Copy Markdown
Member

Thanks for the PR. It's evening for me here in the EU so I'll look in the morning and let you know!

@zatkins-dev

Copy link
Copy Markdown
Collaborator

A note on the ordering: I think I would prefer the order for the switch, it's a bit more intuitive to be. I also think that the enum needs a zero value -- we often use CeedCalloc to get memory and that automatically zeros the allocated memory. Enum values should be valid in that case.

@zatkins-dev

Copy link
Copy Markdown
Collaborator

Also, thank you for the very clear explanation of AI use!

@zatkins-dev zatkins-dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great start, a couple high-level things on a first look.

Comment thread include/ceed/backend.h
CEED_EXTERN int CeedQFunctionContextSetCeedFloat(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, float *values);
CEED_EXTERN int CeedQFunctionContextGetCeedFloatRead(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, size_t *num_values,
const float **values);
CEED_EXTERN int CeedQFunctionContextRestoreCeedFloatRead(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, const float **values);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to note, only the Ceed types should have the Ceed prefix on the type name for these functions.

For example, CeedScalar should be as you have it, but float should be

Suggested change
CEED_EXTERN int CeedQFunctionContextRestoreCeedFloatRead(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, const float **values);
CEED_EXTERN int CeedQFunctionContextRestoreFloatRead(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, const float **values);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats going to be a pretty big diff, so I'll let you handle it locally instead of me suggesting all of them.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, to clarify, I meant only the four types with Ceed in their name should have that added to the signature, so CeedInt, CeedScalar, CeedSize, and CeedInt8

@zatkins-dev

Copy link
Copy Markdown
Collaborator

I'm not sure that the Julia changes need to all be here -- some of that should probably be a separate PR.

Comment thread include/ceed/ceed.h
CEED_EXTERN int CeedQFunctionContextRestoreData(CeedQFunctionContext ctx, void *data);
CEED_EXTERN int CeedQFunctionContextRestoreDataRead(CeedQFunctionContext ctx, void *data);
CEED_EXTERN int CeedQFunctionContextRegisterDouble(CeedQFunctionContext ctx, const char *field_name, size_t field_offset, size_t num_values,
CEED_EXTERN int CeedQFunctionContextRegisterCeedByte(CeedQFunctionContext ctx, const char *field_name, size_t field_offset, size_t num_values,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, these (and the other fn definitions and declarations) should use the ordering of the enum provided

Comment thread include/ceed/types.h
/// @ingroup CeedQFunction
typedef enum {
/// Byte value, C type of char
CEED_CONTEXT_FIELD_BYTE = 1,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As Zach said, I'd use the order I provided, starting at 0

ccall((:CeedQFunctionSetData, libceed), Cint, (CeedQFunction, Ptr{Cvoid}), qf, data)
end

function CeedQFunctionIsImmutable(qf, is_immutable)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a bunch of other stuff added here - I'd only add the Julia changes that correspond to C API changes in this PR

ccall((:CeedHouseholderApplyQ, libceed), Cint, (Ptr{CeedScalar}, Ptr{CeedScalar}, Ptr{CeedScalar}, CeedTransposeMode, CeedInt, CeedInt, CeedInt, CeedInt, CeedInt), mat_A, mat_Q, tau, t_mode, m, n, k, row, col)
end

function CeedMatrixPseudoinverse(ceed, mat, m, n, mat_pinv)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definitely should not be exposed here

Comment on lines +2058 to +2062
function CeedOperatorLinearAssembleQFunctionBuildOrUpdateFallback(op, build_objects, assembled, rstr, request)
ccall((:CeedOperatorLinearAssembleQFunctionBuildOrUpdateFallback, libceed), Cint, (CeedOperator, Bool, Ptr{CeedVector}, Ptr{CeedElemRestriction}, Ptr{CeedRequest}), op, build_objects, assembled, rstr, request)
end

function CeedOperatorAssembleSingle(op, offset, values)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These also don't belong

Comment on lines +2014 to +2019
function CeedOperatorHasTensorBases(op, has_tensor_bases)
ccall((:CeedOperatorHasTensorBases, libceed), Cint, (CeedOperator, Ptr{Bool}), op, has_tensor_bases)
end

function CeedOperatorIsImmutable(op, is_immutable)
ccall((:CeedOperatorIsImmutable, libceed), Cint, (CeedOperator, Ptr{Bool}), op, is_immutable)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And these are internal utilities that don't belong... really just only add the fn's from this PR and non other to be safe

@ref Backend
**/
int CeedQFunctionContextRestoreCeedByteRead(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, const char **values) {
CeedCheck(field_label, CeedQFunctionContextReturnCeed(ctx), CEED_ERROR_UNSUPPORTED, "Invalid field label");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes emphasize that probably this check should move from being duplicated in all of these functions to being in CeedQFunctionContextRestoreGenericRead

@ref Backend
**/
int CeedQFunctionContextSetCeedByte(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, char * values) {
CeedCheck(field_label, CeedQFunctionContextReturnCeed(ctx), CEED_ERROR_UNSUPPORTED, "Invalid field label");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment here, all these replicated checks probably should go to CeedQFunctionContextSetGeneric

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support additional CeedContextFieldType values

3 participants