ceed-qfunctioncontext.c (8d780e656ab974843537adc972c46a0508fa9677) ceed-qfunctioncontext.c (ca94c3ddc8f82b7d93a79f9e4812e99b8be840ff)
1// Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
2// All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3//
4// SPDX-License-Identifier: BSD-2-Clause
5//
6// This file is part of CEED: http://github.com/ceed
7
8#include <ceed-impl.h>

--- 9 unchanged lines hidden (view full) ---

18
19/// ----------------------------------------------------------------------------
20/// CeedQFunctionContext Library Internal Functions
21/// ----------------------------------------------------------------------------
22/// @addtogroup CeedQFunctionDeveloper
23/// @{
24
25/**
1// Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
2// All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3//
4// SPDX-License-Identifier: BSD-2-Clause
5//
6// This file is part of CEED: http://github.com/ceed
7
8#include <ceed-impl.h>

--- 9 unchanged lines hidden (view full) ---

18
19/// ----------------------------------------------------------------------------
20/// CeedQFunctionContext Library Internal Functions
21/// ----------------------------------------------------------------------------
22/// @addtogroup CeedQFunctionDeveloper
23/// @{
24
25/**
26 @brief Get index for QFunctionContext field
26 @brief Get index for `CeedQFunctionContext` field
27
27
28 @param[in] ctx CeedQFunctionContext
28 @param[in] ctx `CeedQFunctionContext`
29 @param[in] field_name Name of field
29 @param[in] field_name Name of field
30 @param[out] field_index Index of field, or -1 if field is not registered
30 @param[out] field_index Index of field, or `-1` if field is not registered
31
32 @return An error code: 0 - success, otherwise - failure
33
34 @ref Developer
35**/
36int CeedQFunctionContextGetFieldIndex(CeedQFunctionContext ctx, const char *field_name, CeedInt *field_index) {
37 *field_index = -1;
38 for (CeedInt i = 0; i < ctx->num_fields; i++) {
39 if (!strcmp(ctx->field_labels[i]->name, field_name)) *field_index = i;
40 }
41 return CEED_ERROR_SUCCESS;
42}
43
44/**
31
32 @return An error code: 0 - success, otherwise - failure
33
34 @ref Developer
35**/
36int CeedQFunctionContextGetFieldIndex(CeedQFunctionContext ctx, const char *field_name, CeedInt *field_index) {
37 *field_index = -1;
38 for (CeedInt i = 0; i < ctx->num_fields; i++) {
39 if (!strcmp(ctx->field_labels[i]->name, field_name)) *field_index = i;
40 }
41 return CEED_ERROR_SUCCESS;
42}
43
44/**
45 @brief Common function for registering QFunctionContext fields
45 @brief Common function for registering `CeedQFunctionContext` fields
46
46
47 @param[in,out] ctx CeedQFunctionContext
47 @param[in,out] ctx `CeedQFunctionContext`
48 @param[in] field_name Name of field to register
49 @param[in] field_offset Offset of field to register
48 @param[in] field_name Name of field to register
49 @param[in] field_offset Offset of field to register
50 @param[in] field_description Description of field, or NULL for none
51 @param[in] field_type Field data type, such as double, int32, or bool
50 @param[in] field_description Description of field, or `NULL` for none
51 @param[in] field_type @ref CeedContextFieldType
52 @param[in] num_values Number of values to register, must be contiguous in memory
53
54 @return An error code: 0 - success, otherwise - failure
55
56 @ref Developer
57**/
58int CeedQFunctionContextRegisterGeneric(CeedQFunctionContext ctx, const char *field_name, size_t field_offset, const char *field_description,
59 CeedContextFieldType field_type, size_t num_values) {

--- 34 unchanged lines hidden (view full) ---

94 ctx->field_labels[ctx->num_fields]->offset = field_offset;
95 ctx->field_labels[ctx->num_fields]->size = field_size * num_values;
96 ctx->field_labels[ctx->num_fields]->num_values = num_values;
97 ctx->num_fields++;
98 return CEED_ERROR_SUCCESS;
99}
100
101/**
52 @param[in] num_values Number of values to register, must be contiguous in memory
53
54 @return An error code: 0 - success, otherwise - failure
55
56 @ref Developer
57**/
58int CeedQFunctionContextRegisterGeneric(CeedQFunctionContext ctx, const char *field_name, size_t field_offset, const char *field_description,
59 CeedContextFieldType field_type, size_t num_values) {

--- 34 unchanged lines hidden (view full) ---

94 ctx->field_labels[ctx->num_fields]->offset = field_offset;
95 ctx->field_labels[ctx->num_fields]->size = field_size * num_values;
96 ctx->field_labels[ctx->num_fields]->num_values = num_values;
97 ctx->num_fields++;
98 return CEED_ERROR_SUCCESS;
99}
100
101/**
102 @brief Destroy user data held by CeedQFunctionContext, using function set by CeedQFunctionContextSetDataDestroy, if applicable
102 @brief Destroy user data held by `CeedQFunctionContext`, using function set by @ref CeedQFunctionContextSetDataDestroy(), if applicable
103
103
104 @param[in,out] ctx CeedQFunctionContext to destroy user data
104 @param[in,out] ctx `CeedQFunctionContext` to destroy user data
105
106 @return An error code: 0 - success, otherwise - failure
107
108 @ref Developer
109**/
110static int CeedQFunctionContextDestroyData(CeedQFunctionContext ctx) {
111 if (ctx->DataDestroy) {
112 CeedCall(ctx->DataDestroy(ctx));

--- 17 unchanged lines hidden (view full) ---

130
131/// ----------------------------------------------------------------------------
132/// CeedQFunctionContext Backend API
133/// ----------------------------------------------------------------------------
134/// @addtogroup CeedQFunctionBackend
135/// @{
136
137/**
105
106 @return An error code: 0 - success, otherwise - failure
107
108 @ref Developer
109**/
110static int CeedQFunctionContextDestroyData(CeedQFunctionContext ctx) {
111 if (ctx->DataDestroy) {
112 CeedCall(ctx->DataDestroy(ctx));

--- 17 unchanged lines hidden (view full) ---

130
131/// ----------------------------------------------------------------------------
132/// CeedQFunctionContext Backend API
133/// ----------------------------------------------------------------------------
134/// @addtogroup CeedQFunctionBackend
135/// @{
136
137/**
138 @brief Get the Ceed associated with a CeedQFunctionContext
138 @brief Get the `Ceed` associated with a `CeedQFunctionContext`
139
139
140 @param[in] ctx CeedQFunctionContext
141 @param[out] ceed Variable to store Ceed
140 @param[in] ctx `CeedQFunctionContext`
141 @param[out] ceed Variable to store `Ceed`
142
143 @return An error code: 0 - success, otherwise - failure
144
145 @ref Backend
146**/
147int CeedQFunctionContextGetCeed(CeedQFunctionContext ctx, Ceed *ceed) {
148 *ceed = ctx->ceed;
149 return CEED_ERROR_SUCCESS;
150}
151
152/**
142
143 @return An error code: 0 - success, otherwise - failure
144
145 @ref Backend
146**/
147int CeedQFunctionContextGetCeed(CeedQFunctionContext ctx, Ceed *ceed) {
148 *ceed = ctx->ceed;
149 return CEED_ERROR_SUCCESS;
150}
151
152/**
153 @brief Check for valid data in a CeedQFunctionContext
153 @brief Check for valid data in a `CeedQFunctionContext`
154
154
155 @param[in] ctx CeedQFunctionContext to check validity
155 @param[in] ctx `CeedQFunctionContext` to check validity
156 @param[out] has_valid_data Variable to store validity
157
158 @return An error code: 0 - success, otherwise - failure
159
160 @ref Backend
161**/
162int CeedQFunctionContextHasValidData(CeedQFunctionContext ctx, bool *has_valid_data) {
156 @param[out] has_valid_data Variable to store validity
157
158 @return An error code: 0 - success, otherwise - failure
159
160 @ref Backend
161**/
162int CeedQFunctionContextHasValidData(CeedQFunctionContext ctx, bool *has_valid_data) {
163 CeedCheck(ctx->HasValidData, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support HasValidData");
163 CeedCheck(ctx->HasValidData, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support CeedQFunctionContextHasValidData");
164 CeedCall(ctx->HasValidData(ctx, has_valid_data));
165 return CEED_ERROR_SUCCESS;
166}
167
168/**
164 CeedCall(ctx->HasValidData(ctx, has_valid_data));
165 return CEED_ERROR_SUCCESS;
166}
167
168/**
169 @brief Check for borrowed data of a specific CeedMemType in a CeedQFunctionContext
169 @brief Check for borrowed data of a specific @ref CeedMemType in a `CeedQFunctionContext`
170
170
171 @param[in] ctx CeedQFunctionContext to check
171 @param[in] ctx `CeedQFunctionContext` to check
172 @param[in] mem_type Memory type to check
173 @param[out] has_borrowed_data_of_type Variable to store result
174
175 @return An error code: 0 - success, otherwise - failure
176
177 @ref Backend
178**/
179int CeedQFunctionContextHasBorrowedDataOfType(CeedQFunctionContext ctx, CeedMemType mem_type, bool *has_borrowed_data_of_type) {
172 @param[in] mem_type Memory type to check
173 @param[out] has_borrowed_data_of_type Variable to store result
174
175 @return An error code: 0 - success, otherwise - failure
176
177 @ref Backend
178**/
179int CeedQFunctionContextHasBorrowedDataOfType(CeedQFunctionContext ctx, CeedMemType mem_type, bool *has_borrowed_data_of_type) {
180 CeedCheck(ctx->HasBorrowedDataOfType, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support HasBorrowedDataOfType");
180 CeedCheck(ctx->HasBorrowedDataOfType, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support CeedQFunctionContextHasBorrowedDataOfType");
181 CeedCall(ctx->HasBorrowedDataOfType(ctx, mem_type, has_borrowed_data_of_type));
182 return CEED_ERROR_SUCCESS;
183}
184
185/**
181 CeedCall(ctx->HasBorrowedDataOfType(ctx, mem_type, has_borrowed_data_of_type));
182 return CEED_ERROR_SUCCESS;
183}
184
185/**
186 @brief Get the state of a CeedQFunctionContext
186 @brief Get the state of a `CeedQFunctionContext`
187
187
188 @param[in] ctx CeedQFunctionContext to retrieve state
188 @param[in] ctx `CeedQFunctionContext` to retrieve state
189 @param[out] state Variable to store state
190
191 @return An error code: 0 - success, otherwise - failure
192
193 @ref Backend
194**/
195int CeedQFunctionContextGetState(CeedQFunctionContext ctx, uint64_t *state) {
196 *state = ctx->state;
197 return CEED_ERROR_SUCCESS;
198}
199
200/**
189 @param[out] state Variable to store state
190
191 @return An error code: 0 - success, otherwise - failure
192
193 @ref Backend
194**/
195int CeedQFunctionContextGetState(CeedQFunctionContext ctx, uint64_t *state) {
196 *state = ctx->state;
197 return CEED_ERROR_SUCCESS;
198}
199
200/**
201 @brief Get backend data of a CeedQFunctionContext
201 @brief Get backend data of a `CeedQFunctionContext`
202
202
203 @param[in] ctx CeedQFunctionContext
203 @param[in] ctx `CeedQFunctionContext`
204 @param[out] data Variable to store data
205
206 @return An error code: 0 - success, otherwise - failure
207
208 @ref Backend
209**/
210int CeedQFunctionContextGetBackendData(CeedQFunctionContext ctx, void *data) {
211 *(void **)data = ctx->data;
212 return CEED_ERROR_SUCCESS;
213}
214
215/**
204 @param[out] data Variable to store data
205
206 @return An error code: 0 - success, otherwise - failure
207
208 @ref Backend
209**/
210int CeedQFunctionContextGetBackendData(CeedQFunctionContext ctx, void *data) {
211 *(void **)data = ctx->data;
212 return CEED_ERROR_SUCCESS;
213}
214
215/**
216 @brief Set backend data of a CeedQFunctionContext
216 @brief Set backend data of a `CeedQFunctionContext`
217
217
218 @param[in,out] ctx CeedQFunctionContext
218 @param[in,out] ctx `CeedQFunctionContext`
219 @param[in] data Data to set
220
221 @return An error code: 0 - success, otherwise - failure
222
223 @ref Backend
224**/
225int CeedQFunctionContextSetBackendData(CeedQFunctionContext ctx, void *data) {
226 ctx->data = data;
227 return CEED_ERROR_SUCCESS;
228}
229
230/**
219 @param[in] data Data to set
220
221 @return An error code: 0 - success, otherwise - failure
222
223 @ref Backend
224**/
225int CeedQFunctionContextSetBackendData(CeedQFunctionContext ctx, void *data) {
226 ctx->data = data;
227 return CEED_ERROR_SUCCESS;
228}
229
230/**
231 @brief Get label for a registered QFunctionContext field, or `NULL` if no field has been registered with this `field_name`
231 @brief Get label for a registered `CeedQFunctionContext` field, or `NULL` if no field has been registered with this `field_name`
232
232
233 @param[in] ctx CeedQFunctionContext
233 @param[in] ctx `CeedQFunctionContext`
234 @param[in] field_name Name of field to retrieve label
235 @param[out] field_label Variable to field label
236
237 @return An error code: 0 - success, otherwise - failure
238
239 @ref Backend
240**/
241int CeedQFunctionContextGetFieldLabel(CeedQFunctionContext ctx, const char *field_name, CeedContextFieldLabel *field_label) {

--- 5 unchanged lines hidden (view full) ---

247 *field_label = ctx->field_labels[field_index];
248 } else {
249 *field_label = NULL;
250 }
251 return CEED_ERROR_SUCCESS;
252}
253
254/**
234 @param[in] field_name Name of field to retrieve label
235 @param[out] field_label Variable to field label
236
237 @return An error code: 0 - success, otherwise - failure
238
239 @ref Backend
240**/
241int CeedQFunctionContextGetFieldLabel(CeedQFunctionContext ctx, const char *field_name, CeedContextFieldLabel *field_label) {

--- 5 unchanged lines hidden (view full) ---

247 *field_label = ctx->field_labels[field_index];
248 } else {
249 *field_label = NULL;
250 }
251 return CEED_ERROR_SUCCESS;
252}
253
254/**
255 @brief Set QFunctionContext field
255 @brief Set `CeedQFunctionContext` field
256
256
257 @param[in,out] ctx CeedQFunctionContext
257 @param[in,out] ctx `CeedQFunctionContext`
258 @param[in] field_label Label of field to set
259 @param[in] field_type Type of field to set
260 @param[in] values Value to set
261
262 @return An error code: 0 - success, otherwise - failure
263
264 @ref Backend
265**/

--- 13 unchanged lines hidden (view full) ---

279 CeedCall(CeedQFunctionContextGetData(ctx, CEED_MEM_HOST, &data));
280 memcpy(&data[field_label->offset], values, field_label->size);
281 CeedCall(CeedQFunctionContextRestoreData(ctx, &data));
282 }
283 return CEED_ERROR_SUCCESS;
284}
285
286/**
258 @param[in] field_label Label of field to set
259 @param[in] field_type Type of field to set
260 @param[in] values Value to set
261
262 @return An error code: 0 - success, otherwise - failure
263
264 @ref Backend
265**/

--- 13 unchanged lines hidden (view full) ---

279 CeedCall(CeedQFunctionContextGetData(ctx, CEED_MEM_HOST, &data));
280 memcpy(&data[field_label->offset], values, field_label->size);
281 CeedCall(CeedQFunctionContextRestoreData(ctx, &data));
282 }
283 return CEED_ERROR_SUCCESS;
284}
285
286/**
287 @brief Get QFunctionContext field data, read-only
287 @brief Get `CeedQFunctionContext` field data, read-only
288
288
289 @param[in] ctx CeedQFunctionContext
289 @param[in] ctx `CeedQFunctionContext`
290 @param[in] field_label Label of field to read
291 @param[in] field_type Type of field to read
292 @param[out] num_values Number of values in the field label
293 @param[out] values Pointer to context values
294
295 @return An error code: 0 - success, otherwise - failure
296
297 @ref Backend

--- 19 unchanged lines hidden (view full) ---

317 case CEED_CONTEXT_FIELD_BOOL:
318 *num_values = field_label->size / sizeof(bool);
319 break;
320 }
321 return CEED_ERROR_SUCCESS;
322}
323
324/**
290 @param[in] field_label Label of field to read
291 @param[in] field_type Type of field to read
292 @param[out] num_values Number of values in the field label
293 @param[out] values Pointer to context values
294
295 @return An error code: 0 - success, otherwise - failure
296
297 @ref Backend

--- 19 unchanged lines hidden (view full) ---

317 case CEED_CONTEXT_FIELD_BOOL:
318 *num_values = field_label->size / sizeof(bool);
319 break;
320 }
321 return CEED_ERROR_SUCCESS;
322}
323
324/**
325 @brief Restore QFunctionContext field data, read-only
325 @brief Restore `CeedQFunctionContext` field data, read-only
326
326
327 @param[in] ctx CeedQFunctionContext
327 @param[in] ctx `CeedQFunctionContext`
328 @param[in] field_label Label of field to restore
329 @param[in] field_type Type of field to restore
330 @param[out] values Pointer to context values
331
332 @return An error code: 0 - success, otherwise - failure
333
334 @ref Backend
335**/

--- 4 unchanged lines hidden (view full) ---

340 "QFunctionContext field with name \"%s\" registered as %s, not registered as %s", field_label->name,
341 CeedContextFieldTypes[field_label->type], CeedContextFieldTypes[field_type]);
342
343 CeedCall(CeedQFunctionContextRestoreDataRead(ctx, values));
344 return CEED_ERROR_SUCCESS;
345}
346
347/**
328 @param[in] field_label Label of field to restore
329 @param[in] field_type Type of field to restore
330 @param[out] values Pointer to context values
331
332 @return An error code: 0 - success, otherwise - failure
333
334 @ref Backend
335**/

--- 4 unchanged lines hidden (view full) ---

340 "QFunctionContext field with name \"%s\" registered as %s, not registered as %s", field_label->name,
341 CeedContextFieldTypes[field_label->type], CeedContextFieldTypes[field_type]);
342
343 CeedCall(CeedQFunctionContextRestoreDataRead(ctx, values));
344 return CEED_ERROR_SUCCESS;
345}
346
347/**
348 @brief Set QFunctionContext field holding double precision values
348 @brief Set `CeedQFunctionContext` field holding double precision values
349
349
350 @param[in,out] ctx CeedQFunctionContext
350 @param[in,out] ctx `CeedQFunctionContext`
351 @param[in] field_label Label for field to set
352 @param[in] values Values to set
353
354 @return An error code: 0 - success, otherwise - failure
355
356 @ref Backend
357**/
358int CeedQFunctionContextSetDouble(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, double *values) {
359 CeedCheck(field_label, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label");
360 CeedCall(CeedQFunctionContextSetGeneric(ctx, field_label, CEED_CONTEXT_FIELD_DOUBLE, values));
361 return CEED_ERROR_SUCCESS;
362}
363
364/**
351 @param[in] field_label Label for field to set
352 @param[in] values Values to set
353
354 @return An error code: 0 - success, otherwise - failure
355
356 @ref Backend
357**/
358int CeedQFunctionContextSetDouble(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, double *values) {
359 CeedCheck(field_label, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label");
360 CeedCall(CeedQFunctionContextSetGeneric(ctx, field_label, CEED_CONTEXT_FIELD_DOUBLE, values));
361 return CEED_ERROR_SUCCESS;
362}
363
364/**
365 @brief Get QFunctionContext field holding double precision values, read-only
365 @brief Get `CeedQFunctionContext` field holding double precision values, read-only
366
366
367 @param[in] ctx CeedQFunctionContext
367 @param[in] ctx `CeedQFunctionContext`
368 @param[in] field_label Label for field to get
369 @param[out] num_values Number of values in the field label
370 @param[out] values Pointer to context values
371
372 @return An error code: 0 - success, otherwise - failure
373
374 @ref Backend
375**/
376int CeedQFunctionContextGetDoubleRead(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, size_t *num_values, const double **values) {
377 CeedCheck(field_label, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label");
378 CeedCall(CeedQFunctionContextGetGenericRead(ctx, field_label, CEED_CONTEXT_FIELD_DOUBLE, num_values, values));
379 return CEED_ERROR_SUCCESS;
380}
381
382/**
368 @param[in] field_label Label for field to get
369 @param[out] num_values Number of values in the field label
370 @param[out] values Pointer to context values
371
372 @return An error code: 0 - success, otherwise - failure
373
374 @ref Backend
375**/
376int CeedQFunctionContextGetDoubleRead(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, size_t *num_values, const double **values) {
377 CeedCheck(field_label, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label");
378 CeedCall(CeedQFunctionContextGetGenericRead(ctx, field_label, CEED_CONTEXT_FIELD_DOUBLE, num_values, values));
379 return CEED_ERROR_SUCCESS;
380}
381
382/**
383 @brief Restore QFunctionContext field holding double precision values, read-only
383 @brief Restore `CeedQFunctionContext` field holding double precision values, read-only
384
384
385 @param[in] ctx CeedQFunctionContext
385 @param[in] ctx `CeedQFunctionContext`
386 @param[in] field_label Label for field to restore
387 @param[out] values Pointer to context values
388
389 @return An error code: 0 - success, otherwise - failure
390
391 @ref Backend
392**/
393int CeedQFunctionContextRestoreDoubleRead(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, const double **values) {
394 CeedCheck(field_label, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label");
395 CeedCall(CeedQFunctionContextRestoreGenericRead(ctx, field_label, CEED_CONTEXT_FIELD_DOUBLE, values));
396 return CEED_ERROR_SUCCESS;
397}
398
399/**
386 @param[in] field_label Label for field to restore
387 @param[out] values Pointer to context values
388
389 @return An error code: 0 - success, otherwise - failure
390
391 @ref Backend
392**/
393int CeedQFunctionContextRestoreDoubleRead(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, const double **values) {
394 CeedCheck(field_label, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label");
395 CeedCall(CeedQFunctionContextRestoreGenericRead(ctx, field_label, CEED_CONTEXT_FIELD_DOUBLE, values));
396 return CEED_ERROR_SUCCESS;
397}
398
399/**
400 @brief Set QFunctionContext field holding int32 values
400 @brief Set CeedQFunctionContext field holding `int32` values
401
402 @param[in,out] ctx CeedQFunctionContext
403 @param[in] field_label Label for field to set
404 @param[in] values Values to set
405
406 @return An error code: 0 - success, otherwise - failure
407
408 @ref Backend
409**/
410int CeedQFunctionContextSetInt32(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, int32_t *values) {
411 CeedCheck(field_label, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label");
412 CeedCall(CeedQFunctionContextSetGeneric(ctx, field_label, CEED_CONTEXT_FIELD_INT32, values));
413 return CEED_ERROR_SUCCESS;
414}
415
416/**
401
402 @param[in,out] ctx CeedQFunctionContext
403 @param[in] field_label Label for field to set
404 @param[in] values Values to set
405
406 @return An error code: 0 - success, otherwise - failure
407
408 @ref Backend
409**/
410int CeedQFunctionContextSetInt32(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, int32_t *values) {
411 CeedCheck(field_label, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label");
412 CeedCall(CeedQFunctionContextSetGeneric(ctx, field_label, CEED_CONTEXT_FIELD_INT32, values));
413 return CEED_ERROR_SUCCESS;
414}
415
416/**
417 @brief Get QFunctionContext field holding int32 values, read-only
417 @brief Get `CeedQFunctionContext` field holding `int32` values, read-only
418
418
419 @param[in] ctx CeedQFunctionContext
419 @param[in] ctx `CeedQFunctionContext`
420 @param[in] field_label Label for field to get
421 @param[out] num_values Number of values in the field label
422 @param[out] values Pointer to context values
423
424 @return An error code: 0 - success, otherwise - failure
425
426 @ref Backend
427**/
428int CeedQFunctionContextGetInt32Read(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, size_t *num_values, const int32_t **values) {
429 CeedCheck(field_label, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label");
430 CeedCall(CeedQFunctionContextGetGenericRead(ctx, field_label, CEED_CONTEXT_FIELD_INT32, num_values, values));
431 return CEED_ERROR_SUCCESS;
432}
433
434/**
420 @param[in] field_label Label for field to get
421 @param[out] num_values Number of values in the field label
422 @param[out] values Pointer to context values
423
424 @return An error code: 0 - success, otherwise - failure
425
426 @ref Backend
427**/
428int CeedQFunctionContextGetInt32Read(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, size_t *num_values, const int32_t **values) {
429 CeedCheck(field_label, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label");
430 CeedCall(CeedQFunctionContextGetGenericRead(ctx, field_label, CEED_CONTEXT_FIELD_INT32, num_values, values));
431 return CEED_ERROR_SUCCESS;
432}
433
434/**
435 @brief Restore QFunctionContext field holding int32 values, read-only
435 @brief Restore `CeedQFunctionContext` field holding `int32` values, read-only
436
436
437 @param[in] ctx CeedQFunctionContext
437 @param[in] ctx `CeedQFunctionContext`
438 @param[in] field_label Label for field to restore
439 @param[out] values Pointer to context values
440
441 @return An error code: 0 - success, otherwise - failure
442
443 @ref Backend
444**/
445int CeedQFunctionContextRestoreInt32Read(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, const int32_t **values) {
446 CeedCheck(field_label, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label");
447 CeedCall(CeedQFunctionContextRestoreGenericRead(ctx, field_label, CEED_CONTEXT_FIELD_INT32, values));
448 return CEED_ERROR_SUCCESS;
449}
450
451/**
438 @param[in] field_label Label for field to restore
439 @param[out] values Pointer to context values
440
441 @return An error code: 0 - success, otherwise - failure
442
443 @ref Backend
444**/
445int CeedQFunctionContextRestoreInt32Read(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, const int32_t **values) {
446 CeedCheck(field_label, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label");
447 CeedCall(CeedQFunctionContextRestoreGenericRead(ctx, field_label, CEED_CONTEXT_FIELD_INT32, values));
448 return CEED_ERROR_SUCCESS;
449}
450
451/**
452 @brief Set QFunctionContext field holding boolean values
452 @brief Set `CeedQFunctionContext` field holding boolean values
453
453
454 @param[in,out] ctx CeedQFunctionContext
454 @param[in,out] ctx `CeedQFunctionContext`
455 @param[in] field_label Label for field to set
456 @param[in] values Values to set
457
458 @return An error code: 0 - success, otherwise - failure
459
460 @ref Backend
461**/
462int CeedQFunctionContextSetBoolean(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, bool *values) {
463 CeedCheck(field_label, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label");
464 CeedCall(CeedQFunctionContextSetGeneric(ctx, field_label, CEED_CONTEXT_FIELD_BOOL, values));
465 return CEED_ERROR_SUCCESS;
466}
467
468/**
455 @param[in] field_label Label for field to set
456 @param[in] values Values to set
457
458 @return An error code: 0 - success, otherwise - failure
459
460 @ref Backend
461**/
462int CeedQFunctionContextSetBoolean(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, bool *values) {
463 CeedCheck(field_label, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label");
464 CeedCall(CeedQFunctionContextSetGeneric(ctx, field_label, CEED_CONTEXT_FIELD_BOOL, values));
465 return CEED_ERROR_SUCCESS;
466}
467
468/**
469 @brief Get QFunctionContext field holding boolean values, read-only
469 @brief Get `CeedQFunctionContext` field holding boolean values, read-only
470
470
471 @param[in] ctx CeedQFunctionContext
471 @param[in] ctx `CeedQFunctionContext`
472 @param[in] field_label Label for field to get
473 @param[out] num_values Number of values in the field label
474 @param[out] values Pointer to context values
475
476 @return An error code: 0 - success, otherwise - failure
477
478 @ref Backend
479**/
480int CeedQFunctionContextGetBooleanRead(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, size_t *num_values, const bool **values) {
481 CeedCheck(field_label, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label");
482 CeedCall(CeedQFunctionContextGetGenericRead(ctx, field_label, CEED_CONTEXT_FIELD_BOOL, num_values, values));
483 return CEED_ERROR_SUCCESS;
484}
485
486/**
472 @param[in] field_label Label for field to get
473 @param[out] num_values Number of values in the field label
474 @param[out] values Pointer to context values
475
476 @return An error code: 0 - success, otherwise - failure
477
478 @ref Backend
479**/
480int CeedQFunctionContextGetBooleanRead(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, size_t *num_values, const bool **values) {
481 CeedCheck(field_label, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label");
482 CeedCall(CeedQFunctionContextGetGenericRead(ctx, field_label, CEED_CONTEXT_FIELD_BOOL, num_values, values));
483 return CEED_ERROR_SUCCESS;
484}
485
486/**
487 @brief Restore QFunctionContext field holding boolean values, read-only
487 @brief Restore `CeedQFunctionContext` field holding boolean values, read-only
488
488
489 @param[in] ctx CeedQFunctionContext
489 @param[in] ctx `CeedQFunctionContext`
490 @param[in] field_label Label for field to restore
491 @param[out] values Pointer to context values
492
493 @return An error code: 0 - success, otherwise - failure
494
495 @ref Backend
496**/
497int CeedQFunctionContextRestoreBooleanRead(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, const bool **values) {
498 CeedCheck(field_label, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label");
499 CeedCall(CeedQFunctionContextRestoreGenericRead(ctx, field_label, CEED_CONTEXT_FIELD_BOOL, values));
500 return CEED_ERROR_SUCCESS;
501}
502
503/**
490 @param[in] field_label Label for field to restore
491 @param[out] values Pointer to context values
492
493 @return An error code: 0 - success, otherwise - failure
494
495 @ref Backend
496**/
497int CeedQFunctionContextRestoreBooleanRead(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, const bool **values) {
498 CeedCheck(field_label, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label");
499 CeedCall(CeedQFunctionContextRestoreGenericRead(ctx, field_label, CEED_CONTEXT_FIELD_BOOL, values));
500 return CEED_ERROR_SUCCESS;
501}
502
503/**
504 @brief Get additional destroy routine for CeedQFunctionContext user data
504 @brief Get additional destroy routine for `CeedQFunctionContext` user data
505
505
506 @param[in] ctx CeedQFunctionContext to get user destroy function
506 @param[in] ctx `CeedQFunctionContext` to get user destroy function
507 @param[out] f_mem_type Memory type to use when passing data into `f`
508 @param[out] f Additional routine to use to destroy user data
509
510 @return An error code: 0 - success, otherwise - failure
511
512 @ref Backend
513**/
514int CeedQFunctionContextGetDataDestroy(CeedQFunctionContext ctx, CeedMemType *f_mem_type, CeedQFunctionContextDataDestroyUser *f) {
515 if (f_mem_type) *f_mem_type = ctx->data_destroy_mem_type;
516 if (f) *f = ctx->data_destroy_function;
517 return CEED_ERROR_SUCCESS;
518}
519
520/**
507 @param[out] f_mem_type Memory type to use when passing data into `f`
508 @param[out] f Additional routine to use to destroy user data
509
510 @return An error code: 0 - success, otherwise - failure
511
512 @ref Backend
513**/
514int CeedQFunctionContextGetDataDestroy(CeedQFunctionContext ctx, CeedMemType *f_mem_type, CeedQFunctionContextDataDestroyUser *f) {
515 if (f_mem_type) *f_mem_type = ctx->data_destroy_mem_type;
516 if (f) *f = ctx->data_destroy_function;
517 return CEED_ERROR_SUCCESS;
518}
519
520/**
521 @brief Increment the reference counter for a CeedQFunctionContext
521 @brief Increment the reference counter for a `CeedQFunctionContext`
522
522
523 @param[in,out] ctx CeedQFunctionContext to increment the reference counter
523 @param[in,out] ctx `CeedQFunctionContext` to increment the reference counter
524
525 @return An error code: 0 - success, otherwise - failure
526
527 @ref Backend
528**/
529int CeedQFunctionContextReference(CeedQFunctionContext ctx) {
530 ctx->ref_count++;
531 return CEED_ERROR_SUCCESS;
532}
533
534/// @}
535
536/// ----------------------------------------------------------------------------
537/// CeedQFunctionContext Public API
538/// ----------------------------------------------------------------------------
539/// @addtogroup CeedQFunctionUser
540/// @{
541
542/**
524
525 @return An error code: 0 - success, otherwise - failure
526
527 @ref Backend
528**/
529int CeedQFunctionContextReference(CeedQFunctionContext ctx) {
530 ctx->ref_count++;
531 return CEED_ERROR_SUCCESS;
532}
533
534/// @}
535
536/// ----------------------------------------------------------------------------
537/// CeedQFunctionContext Public API
538/// ----------------------------------------------------------------------------
539/// @addtogroup CeedQFunctionUser
540/// @{
541
542/**
543 @brief Create a CeedQFunctionContext for storing CeedQFunction user context data
543 @brief Create a `CeedQFunctionContext` for storing `CeedQFunctionContext` user context data
544
544
545 @param[in] ceed Ceed object where the CeedQFunctionContext will be created
546 @param[out] ctx Address of the variable where the newly created CeedQFunctionContext will be stored
545 @param[in] ceed `Ceed` object used to create the `CeedQFunctionContext`
546 @param[out] ctx Address of the variable where the newly created `CeedQFunctionContext` will be stored
547
548 @return An error code: 0 - success, otherwise - failure
549
550 @ref User
551**/
552int CeedQFunctionContextCreate(Ceed ceed, CeedQFunctionContext *ctx) {
553 if (!ceed->QFunctionContextCreate) {
554 Ceed delegate;
555
556 CeedCall(CeedGetObjectDelegate(ceed, &delegate, "Context"));
547
548 @return An error code: 0 - success, otherwise - failure
549
550 @ref User
551**/
552int CeedQFunctionContextCreate(Ceed ceed, CeedQFunctionContext *ctx) {
553 if (!ceed->QFunctionContextCreate) {
554 Ceed delegate;
555
556 CeedCall(CeedGetObjectDelegate(ceed, &delegate, "Context"));
557 CeedCheck(delegate, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support ContextCreate");
557 CeedCheck(delegate, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support CeedQFunctionContextCreate");
558 CeedCall(CeedQFunctionContextCreate(delegate, ctx));
559 return CEED_ERROR_SUCCESS;
560 }
561
562 CeedCall(CeedCalloc(1, ctx));
563 CeedCall(CeedReferenceCopy(ceed, &(*ctx)->ceed));
564 (*ctx)->ref_count = 1;
565 CeedCall(ceed->QFunctionContextCreate(*ctx));
566 return CEED_ERROR_SUCCESS;
567}
568
569/**
558 CeedCall(CeedQFunctionContextCreate(delegate, ctx));
559 return CEED_ERROR_SUCCESS;
560 }
561
562 CeedCall(CeedCalloc(1, ctx));
563 CeedCall(CeedReferenceCopy(ceed, &(*ctx)->ceed));
564 (*ctx)->ref_count = 1;
565 CeedCall(ceed->QFunctionContextCreate(*ctx));
566 return CEED_ERROR_SUCCESS;
567}
568
569/**
570 @brief Copy the pointer to a CeedQFunctionContext.
570 @brief Copy the pointer to a `CeedQFunctionContext`.
571
571
572 Both pointers should be destroyed with `CeedQFunctionContextDestroy()`.
572 Both pointers should be destroyed with @ref CeedQFunctionContextDestroy().
573
573
574 Note: If the value of `ctx_copy` passed to this function is non-NULL, then it is assumed that `ctx_copy` is a pointer to a
575 CeedQFunctionContext. This CeedQFunctionContext will be destroyed if `ctx_copy` is the only reference to this CeedQFunctionContext.
574 Note: If the value of `*ctx_copy` passed to this function is non-`NULL`, then it is assumed that `*ctx_copy` is a pointer to a `CeedQFunctionContext`.
575 This `CeedQFunctionContext` will be destroyed if `*ctx_copy` is the only reference to this `CeedQFunctionContext`.
576
577 @param[in] ctx CeedQFunctionContext to copy reference to
578 @param[in,out] ctx_copy Variable to store copied reference
579
580 @return An error code: 0 - success, otherwise - failure
581
582 @ref User
583**/
584int CeedQFunctionContextReferenceCopy(CeedQFunctionContext ctx, CeedQFunctionContext *ctx_copy) {
585 CeedCall(CeedQFunctionContextReference(ctx));
586 CeedCall(CeedQFunctionContextDestroy(ctx_copy));
587 *ctx_copy = ctx;
588 return CEED_ERROR_SUCCESS;
589}
590
591/**
576
577 @param[in] ctx CeedQFunctionContext to copy reference to
578 @param[in,out] ctx_copy Variable to store copied reference
579
580 @return An error code: 0 - success, otherwise - failure
581
582 @ref User
583**/
584int CeedQFunctionContextReferenceCopy(CeedQFunctionContext ctx, CeedQFunctionContext *ctx_copy) {
585 CeedCall(CeedQFunctionContextReference(ctx));
586 CeedCall(CeedQFunctionContextDestroy(ctx_copy));
587 *ctx_copy = ctx;
588 return CEED_ERROR_SUCCESS;
589}
590
591/**
592 @brief Set the data used by a CeedQFunctionContext, freeing any previously allocated data if applicable.
592 @brief Set the data used by a `CeedQFunctionContext`, freeing any previously allocated data if applicable.
593
593
594 The backend may copy values to a different memtype, such as during @ref CeedQFunctionApply().
594 The backend may copy values to a different @ref CeedMemType, such as during @ref CeedQFunctionApply().
595 See also @ref CeedQFunctionContextTakeData().
596
595 See also @ref CeedQFunctionContextTakeData().
596
597 @param[in,out] ctx CeedQFunctionContext
597 @param[in,out] ctx `CeedQFunctionContext`
598 @param[in] mem_type Memory type of the data being passed
599 @param[in] copy_mode Copy mode for the data
600 @param[in] size Size of data, in bytes
601 @param[in] data Data to be used
602
603 @return An error code: 0 - success, otherwise - failure
604
605 @ref User
606**/
607int CeedQFunctionContextSetData(CeedQFunctionContext ctx, CeedMemType mem_type, CeedCopyMode copy_mode, size_t size, void *data) {
598 @param[in] mem_type Memory type of the data being passed
599 @param[in] copy_mode Copy mode for the data
600 @param[in] size Size of data, in bytes
601 @param[in] data Data to be used
602
603 @return An error code: 0 - success, otherwise - failure
604
605 @ref User
606**/
607int CeedQFunctionContextSetData(CeedQFunctionContext ctx, CeedMemType mem_type, CeedCopyMode copy_mode, size_t size, void *data) {
608 CeedCheck(ctx->SetData, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support ContextSetData");
608 CeedCheck(ctx->SetData, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support CeedQFunctionContextSetData");
609 CeedCheck(ctx->state % 2 == 0, ctx->ceed, 1, "Cannot grant CeedQFunctionContext data access, the access lock is already in use");
610
611 CeedCall(CeedQFunctionContextDestroyData(ctx));
612 ctx->ctx_size = size;
613 CeedCall(ctx->SetData(ctx, mem_type, copy_mode, data));
614 ctx->state += 2;
615 return CEED_ERROR_SUCCESS;
616}
617
618/**
609 CeedCheck(ctx->state % 2 == 0, ctx->ceed, 1, "Cannot grant CeedQFunctionContext data access, the access lock is already in use");
610
611 CeedCall(CeedQFunctionContextDestroyData(ctx));
612 ctx->ctx_size = size;
613 CeedCall(ctx->SetData(ctx, mem_type, copy_mode, data));
614 ctx->state += 2;
615 return CEED_ERROR_SUCCESS;
616}
617
618/**
619 @brief Take ownership of the data in a CeedQFunctionContext via the specified memory type.
619 @brief Take ownership of the data in a `CeedQFunctionContext` via the specified memory type.
620
621 The caller is responsible for managing and freeing the memory.
622
620
621 The caller is responsible for managing and freeing the memory.
622
623 @param[in] ctx CeedQFunctionContext to access
623 @param[in] ctx `CeedQFunctionContext` to access
624 @param[in] mem_type Memory type on which to access the data.
625 If the backend uses a different memory type, this will perform a copy.
626 @param[out] data Data on memory type mem_type
627
628 @return An error code: 0 - success, otherwise - failure
629
630 @ref User
631**/
632int CeedQFunctionContextTakeData(CeedQFunctionContext ctx, CeedMemType mem_type, void *data) {
633 void *temp_data = NULL;
634 bool has_valid_data = true, has_borrowed_data_of_type = true;
635
636 CeedCall(CeedQFunctionContextHasValidData(ctx, &has_valid_data));
637 CeedCheck(has_valid_data, ctx->ceed, CEED_ERROR_BACKEND, "CeedQFunctionContext has no valid data to take, must set data");
638
624 @param[in] mem_type Memory type on which to access the data.
625 If the backend uses a different memory type, this will perform a copy.
626 @param[out] data Data on memory type mem_type
627
628 @return An error code: 0 - success, otherwise - failure
629
630 @ref User
631**/
632int CeedQFunctionContextTakeData(CeedQFunctionContext ctx, CeedMemType mem_type, void *data) {
633 void *temp_data = NULL;
634 bool has_valid_data = true, has_borrowed_data_of_type = true;
635
636 CeedCall(CeedQFunctionContextHasValidData(ctx, &has_valid_data));
637 CeedCheck(has_valid_data, ctx->ceed, CEED_ERROR_BACKEND, "CeedQFunctionContext has no valid data to take, must set data");
638
639 CeedCheck(ctx->TakeData, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support TakeData");
639 CeedCheck(ctx->TakeData, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support CeedQFunctionContextTakeData");
640 CeedCheck(ctx->state % 2 == 0, ctx->ceed, 1, "Cannot grant CeedQFunctionContext data access, the access lock is already in use");
641
642 CeedCall(CeedQFunctionContextHasBorrowedDataOfType(ctx, mem_type, &has_borrowed_data_of_type));
643 CeedCheck(has_borrowed_data_of_type, ctx->ceed, CEED_ERROR_BACKEND,
644 "CeedQFunctionContext has no borrowed %s data, must set data with CeedQFunctionContextSetData", CeedMemTypes[mem_type]);
645
646 CeedCall(ctx->TakeData(ctx, mem_type, &temp_data));
647 if (data) (*(void **)data) = temp_data;
648 return CEED_ERROR_SUCCESS;
649}
650
651/**
640 CeedCheck(ctx->state % 2 == 0, ctx->ceed, 1, "Cannot grant CeedQFunctionContext data access, the access lock is already in use");
641
642 CeedCall(CeedQFunctionContextHasBorrowedDataOfType(ctx, mem_type, &has_borrowed_data_of_type));
643 CeedCheck(has_borrowed_data_of_type, ctx->ceed, CEED_ERROR_BACKEND,
644 "CeedQFunctionContext has no borrowed %s data, must set data with CeedQFunctionContextSetData", CeedMemTypes[mem_type]);
645
646 CeedCall(ctx->TakeData(ctx, mem_type, &temp_data));
647 if (data) (*(void **)data) = temp_data;
648 return CEED_ERROR_SUCCESS;
649}
650
651/**
652 @brief Get read/write access to a CeedQFunctionContext via the specified memory type.
652 @brief Get read/write access to a `CeedQFunctionContext` via the specified memory type.
653
654 Restore access with @ref CeedQFunctionContextRestoreData().
655
653
654 Restore access with @ref CeedQFunctionContextRestoreData().
655
656 @param[in] ctx CeedQFunctionContext to access
656 @param[in] ctx `CeedQFunctionContext` to access
657 @param[in] mem_type Memory type on which to access the data.
658 If the backend uses a different memory type, this will perform a copy.
659 @param[out] data Data on memory type mem_type
660
657 @param[in] mem_type Memory type on which to access the data.
658 If the backend uses a different memory type, this will perform a copy.
659 @param[out] data Data on memory type mem_type
660
661 @note The CeedQFunctionContextGetData() and @ref CeedQFunctionContextRestoreData() functions provide access to array pointers in the desired memory
662space.
663 Pairing get/restore allows the Context to track access.
661 @note The @ref CeedQFunctionContextGetData() and @ref CeedQFunctionContextRestoreData() functions provide access to array pointers in the desired memory space.
662 Pairing get/restore allows the `CeedQFunctionContext` to track access.
664
665 @return An error code: 0 - success, otherwise - failure
666
667 @ref User
668**/
669int CeedQFunctionContextGetData(CeedQFunctionContext ctx, CeedMemType mem_type, void *data) {
670 bool has_valid_data = true;
671
663
664 @return An error code: 0 - success, otherwise - failure
665
666 @ref User
667**/
668int CeedQFunctionContextGetData(CeedQFunctionContext ctx, CeedMemType mem_type, void *data) {
669 bool has_valid_data = true;
670
672 CeedCheck(ctx->GetData, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support GetData");
671 CeedCheck(ctx->GetData, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support CeedQFunctionContextGetData");
673 CeedCheck(ctx->state % 2 == 0, ctx->ceed, 1, "Cannot grant CeedQFunctionContext data access, the access lock is already in use");
674 CeedCheck(ctx->num_readers == 0, ctx->ceed, 1, "Cannot grant CeedQFunctionContext data access, a process has read access");
675
676 CeedCall(CeedQFunctionContextHasValidData(ctx, &has_valid_data));
677 CeedCheck(has_valid_data, ctx->ceed, CEED_ERROR_BACKEND, "CeedQFunctionContext has no valid data to get, must set data");
678
679 CeedCall(ctx->GetData(ctx, mem_type, data));
680 ctx->state++;
681 return CEED_ERROR_SUCCESS;
682}
683
684/**
672 CeedCheck(ctx->state % 2 == 0, ctx->ceed, 1, "Cannot grant CeedQFunctionContext data access, the access lock is already in use");
673 CeedCheck(ctx->num_readers == 0, ctx->ceed, 1, "Cannot grant CeedQFunctionContext data access, a process has read access");
674
675 CeedCall(CeedQFunctionContextHasValidData(ctx, &has_valid_data));
676 CeedCheck(has_valid_data, ctx->ceed, CEED_ERROR_BACKEND, "CeedQFunctionContext has no valid data to get, must set data");
677
678 CeedCall(ctx->GetData(ctx, mem_type, data));
679 ctx->state++;
680 return CEED_ERROR_SUCCESS;
681}
682
683/**
685 @brief Get read only access to a CeedQFunctionContext via the specified memory type.
684 @brief Get read only access to a `CeedQFunctionContext` via the specified memory type.
686
687 Restore access with @ref CeedQFunctionContextRestoreData().
688
685
686 Restore access with @ref CeedQFunctionContextRestoreData().
687
689 @param[in] ctx CeedQFunctionContext to access
688 @param[in] ctx `CeedQFunctionContext` to access
690 @param[in] mem_type Memory type on which to access the data.
691 If the backend uses a different memory type, this will perform a copy.
692 @param[out] data Data on memory type mem_type
693
689 @param[in] mem_type Memory type on which to access the data.
690 If the backend uses a different memory type, this will perform a copy.
691 @param[out] data Data on memory type mem_type
692
694 @note The CeedQFunctionContextGetDataRead() and @ref CeedQFunctionContextRestoreDataRead() functions provide access to array pointers in the desired
695memory space.
696 Pairing get/restore allows the Context to track access.
693 @note The @ref CeedQFunctionContextGetDataRead() and @ref CeedQFunctionContextRestoreDataRead() functions provide access to array pointers in the desired memory space.
694 Pairing get/restore allows the `CeedQFunctionContext` to track access.
697
698 @return An error code: 0 - success, otherwise - failure
699
700 @ref User
701**/
702int CeedQFunctionContextGetDataRead(CeedQFunctionContext ctx, CeedMemType mem_type, void *data) {
703 bool has_valid_data = true;
704
695
696 @return An error code: 0 - success, otherwise - failure
697
698 @ref User
699**/
700int CeedQFunctionContextGetDataRead(CeedQFunctionContext ctx, CeedMemType mem_type, void *data) {
701 bool has_valid_data = true;
702
705 CeedCheck(ctx->GetDataRead, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support GetDataRead");
703 CeedCheck(ctx->GetDataRead, ctx->ceed, CEED_ERROR_UNSUPPORTED, "Backend does not support CeedQFunctionContextGetDataRead");
706 CeedCheck(ctx->state % 2 == 0, ctx->ceed, 1, "Cannot grant CeedQFunctionContext data access, the access lock is already in use");
707
708 CeedCall(CeedQFunctionContextHasValidData(ctx, &has_valid_data));
709 CeedCheck(has_valid_data, ctx->ceed, CEED_ERROR_BACKEND, "CeedQFunctionContext has no valid data to get, must set data");
710
711 CeedCall(ctx->GetDataRead(ctx, mem_type, data));
712 ctx->num_readers++;
713 return CEED_ERROR_SUCCESS;
714}
715
716/**
717 @brief Restore data obtained using @ref CeedQFunctionContextGetData()
718
704 CeedCheck(ctx->state % 2 == 0, ctx->ceed, 1, "Cannot grant CeedQFunctionContext data access, the access lock is already in use");
705
706 CeedCall(CeedQFunctionContextHasValidData(ctx, &has_valid_data));
707 CeedCheck(has_valid_data, ctx->ceed, CEED_ERROR_BACKEND, "CeedQFunctionContext has no valid data to get, must set data");
708
709 CeedCall(ctx->GetDataRead(ctx, mem_type, data));
710 ctx->num_readers++;
711 return CEED_ERROR_SUCCESS;
712}
713
714/**
715 @brief Restore data obtained using @ref CeedQFunctionContextGetData()
716
719 @param[in] ctx CeedQFunctionContext to restore
717 @param[in] ctx `CeedQFunctionContext` to restore
720 @param[in,out] data Data to restore
721
722 @return An error code: 0 - success, otherwise - failure
723
724 @ref User
725**/
726int CeedQFunctionContextRestoreData(CeedQFunctionContext ctx, void *data) {
727 CeedCheck(ctx->state % 2 == 1, ctx->ceed, 1, "Cannot restore CeedQFunctionContext array access, access was not granted");
728
729 if (ctx->RestoreData) CeedCall(ctx->RestoreData(ctx));
730 *(void **)data = NULL;
731 ctx->state++;
732 return CEED_ERROR_SUCCESS;
733}
734
735/**
736 @brief Restore data obtained using @ref CeedQFunctionContextGetDataRead()
737
718 @param[in,out] data Data to restore
719
720 @return An error code: 0 - success, otherwise - failure
721
722 @ref User
723**/
724int CeedQFunctionContextRestoreData(CeedQFunctionContext ctx, void *data) {
725 CeedCheck(ctx->state % 2 == 1, ctx->ceed, 1, "Cannot restore CeedQFunctionContext array access, access was not granted");
726
727 if (ctx->RestoreData) CeedCall(ctx->RestoreData(ctx));
728 *(void **)data = NULL;
729 ctx->state++;
730 return CEED_ERROR_SUCCESS;
731}
732
733/**
734 @brief Restore data obtained using @ref CeedQFunctionContextGetDataRead()
735
738 @param[in] ctx CeedQFunctionContext to restore
736 @param[in] ctx `CeedQFunctionContext` to restore
739 @param[in,out] data Data to restore
740
741 @return An error code: 0 - success, otherwise - failure
742
743 @ref User
744**/
745int CeedQFunctionContextRestoreDataRead(CeedQFunctionContext ctx, void *data) {
746 CeedCheck(ctx->num_readers > 0, ctx->ceed, 1, "Cannot restore CeedQFunctionContext array access, access was not granted");
747
748 ctx->num_readers--;
749 if (ctx->num_readers == 0 && ctx->RestoreDataRead) CeedCall(ctx->RestoreDataRead(ctx));
750 *(void **)data = NULL;
751 return CEED_ERROR_SUCCESS;
752}
753
754/**
737 @param[in,out] data Data to restore
738
739 @return An error code: 0 - success, otherwise - failure
740
741 @ref User
742**/
743int CeedQFunctionContextRestoreDataRead(CeedQFunctionContext ctx, void *data) {
744 CeedCheck(ctx->num_readers > 0, ctx->ceed, 1, "Cannot restore CeedQFunctionContext array access, access was not granted");
745
746 ctx->num_readers--;
747 if (ctx->num_readers == 0 && ctx->RestoreDataRead) CeedCall(ctx->RestoreDataRead(ctx));
748 *(void **)data = NULL;
749 return CEED_ERROR_SUCCESS;
750}
751
752/**
755 @brief Register QFunctionContext a field holding double precision values
753 @brief Register a `CeedQFunctionContext` field holding double precision values
756
754
757 @param[in,out] ctx CeedQFunctionContext
755 @param[in,out] ctx `CeedQFunctionContext`
758 @param[in] field_name Name of field to register
759 @param[in] field_offset Offset of field to register
760 @param[in] num_values Number of values to register, must be contiguous in memory
756 @param[in] field_name Name of field to register
757 @param[in] field_offset Offset of field to register
758 @param[in] num_values Number of values to register, must be contiguous in memory
761 @param[in] field_description Description of field, or NULL for none
759 @param[in] field_description Description of field, or `NULL` for none
762
763 @return An error code: 0 - success, otherwise - failure
764
765 @ref User
766**/
767int CeedQFunctionContextRegisterDouble(CeedQFunctionContext ctx, const char *field_name, size_t field_offset, size_t num_values,
768 const char *field_description) {
769 return CeedQFunctionContextRegisterGeneric(ctx, field_name, field_offset, field_description, CEED_CONTEXT_FIELD_DOUBLE, num_values);
770}
771
772/**
760
761 @return An error code: 0 - success, otherwise - failure
762
763 @ref User
764**/
765int CeedQFunctionContextRegisterDouble(CeedQFunctionContext ctx, const char *field_name, size_t field_offset, size_t num_values,
766 const char *field_description) {
767 return CeedQFunctionContextRegisterGeneric(ctx, field_name, field_offset, field_description, CEED_CONTEXT_FIELD_DOUBLE, num_values);
768}
769
770/**
773 @brief Register QFunctionContext a field holding int32 values
771 @brief Register a `CeedQFunctionContext` field holding `int32` values
774
775 @param[in,out] ctx CeedQFunctionContext
776 @param[in] field_name Name of field to register
777 @param[in] field_offset Offset of field to register
778 @param[in] num_values Number of values to register, must be contiguous in memory
772
773 @param[in,out] ctx CeedQFunctionContext
774 @param[in] field_name Name of field to register
775 @param[in] field_offset Offset of field to register
776 @param[in] num_values Number of values to register, must be contiguous in memory
779 @param[in] field_description Description of field, or NULL for none
777 @param[in] field_description Description of field, or `NULL` for none
780
781 @return An error code: 0 - success, otherwise - failure
782
783 @ref User
784**/
785int CeedQFunctionContextRegisterInt32(CeedQFunctionContext ctx, const char *field_name, size_t field_offset, size_t num_values,
786 const char *field_description) {
787 return CeedQFunctionContextRegisterGeneric(ctx, field_name, field_offset, field_description, CEED_CONTEXT_FIELD_INT32, num_values);
788}
789
790/**
778
779 @return An error code: 0 - success, otherwise - failure
780
781 @ref User
782**/
783int CeedQFunctionContextRegisterInt32(CeedQFunctionContext ctx, const char *field_name, size_t field_offset, size_t num_values,
784 const char *field_description) {
785 return CeedQFunctionContextRegisterGeneric(ctx, field_name, field_offset, field_description, CEED_CONTEXT_FIELD_INT32, num_values);
786}
787
788/**
791 @brief Register QFunctionContext a field holding boolean values
789 @brief Register a `CeedQFunctionContext` field holding boolean values
792
790
793 @param[in,out] ctx CeedQFunctionContext
791 @param[in,out] ctx `CeedQFunctionContext`
794 @param[in] field_name Name of field to register
795 @param[in] field_offset Offset of field to register
796 @param[in] num_values Number of values to register, must be contiguous in memory
792 @param[in] field_name Name of field to register
793 @param[in] field_offset Offset of field to register
794 @param[in] num_values Number of values to register, must be contiguous in memory
797 @param[in] field_description Description of field, or NULL for none
795 @param[in] field_description Description of field, or `NULL` for none
798
799 @return An error code: 0 - success, otherwise - failure
800
801 @ref User
802**/
803int CeedQFunctionContextRegisterBoolean(CeedQFunctionContext ctx, const char *field_name, size_t field_offset, size_t num_values,
804 const char *field_description) {
805 return CeedQFunctionContextRegisterGeneric(ctx, field_name, field_offset, field_description, CEED_CONTEXT_FIELD_BOOL, num_values);
806}
807
808/**
796
797 @return An error code: 0 - success, otherwise - failure
798
799 @ref User
800**/
801int CeedQFunctionContextRegisterBoolean(CeedQFunctionContext ctx, const char *field_name, size_t field_offset, size_t num_values,
802 const char *field_description) {
803 return CeedQFunctionContextRegisterGeneric(ctx, field_name, field_offset, field_description, CEED_CONTEXT_FIELD_BOOL, num_values);
804}
805
806/**
809 @brief Get labels for all registered QFunctionContext fields
807 @brief Get labels for all registered `CeedQFunctionContext` fields
810
808
811 @param[in] ctx CeedQFunctionContext
809 @param[in] ctx `CeedQFunctionContext`
812 @param[out] field_labels Variable to hold array of field labels
813 @param[out] num_fields Length of field descriptions array
814
815 @return An error code: 0 - success, otherwise - failure
816
817 @ref User
818**/
819int CeedQFunctionContextGetAllFieldLabels(CeedQFunctionContext ctx, const CeedContextFieldLabel **field_labels, CeedInt *num_fields) {
820 *field_labels = ctx->field_labels;
821 *num_fields = ctx->num_fields;
822 return CEED_ERROR_SUCCESS;
823}
824
825/**
810 @param[out] field_labels Variable to hold array of field labels
811 @param[out] num_fields Length of field descriptions array
812
813 @return An error code: 0 - success, otherwise - failure
814
815 @ref User
816**/
817int CeedQFunctionContextGetAllFieldLabels(CeedQFunctionContext ctx, const CeedContextFieldLabel **field_labels, CeedInt *num_fields) {
818 *field_labels = ctx->field_labels;
819 *num_fields = ctx->num_fields;
820 return CEED_ERROR_SUCCESS;
821}
822
823/**
826 @brief Get the descriptive information about a CeedContextFieldLabel
824 @brief Get the descriptive information about a `CeedContextFieldLabel`
827
825
828 @param[in] label CeedContextFieldLabel
826 @param[in] label @ref CeedContextFieldLabel
829 @param[out] field_name Name of labeled field
830 @param[out] field_offset Offset of field registered
831 @param[out] num_values Number of values registered
832 @param[out] field_description Description of field, or NULL for none
827 @param[out] field_name Name of labeled field
828 @param[out] field_offset Offset of field registered
829 @param[out] num_values Number of values registered
830 @param[out] field_description Description of field, or NULL for none
833 @param[out] field_type CeedContextFieldType
831 @param[out] field_type @ref CeedContextFieldType
834
835 @return An error code: 0 - success, otherwise - failure
836
837 @ref User
838**/
839int CeedContextFieldLabelGetDescription(CeedContextFieldLabel label, const char **field_name, size_t *field_offset, size_t *num_values,
840 const char **field_description, CeedContextFieldType *field_type) {
841 if (field_name) *field_name = label->name;
842 if (field_offset) *field_offset = label->offset;
843 if (num_values) *num_values = label->num_values;
844 if (field_description) *field_description = label->description;
845 if (field_type) *field_type = label->type;
846 return CEED_ERROR_SUCCESS;
847}
848
849/**
850 @brief Get data size for a Context
851
832
833 @return An error code: 0 - success, otherwise - failure
834
835 @ref User
836**/
837int CeedContextFieldLabelGetDescription(CeedContextFieldLabel label, const char **field_name, size_t *field_offset, size_t *num_values,
838 const char **field_description, CeedContextFieldType *field_type) {
839 if (field_name) *field_name = label->name;
840 if (field_offset) *field_offset = label->offset;
841 if (num_values) *num_values = label->num_values;
842 if (field_description) *field_description = label->description;
843 if (field_type) *field_type = label->type;
844 return CEED_ERROR_SUCCESS;
845}
846
847/**
848 @brief Get data size for a Context
849
852 @param[in] ctx CeedQFunctionContext
850 @param[in] ctx `CeedQFunctionContext`
853 @param[out] ctx_size Variable to store size of context data values
854
855 @return An error code: 0 - success, otherwise - failure
856
857 @ref User
858**/
859int CeedQFunctionContextGetContextSize(CeedQFunctionContext ctx, size_t *ctx_size) {
860 *ctx_size = ctx->ctx_size;
861 return CEED_ERROR_SUCCESS;
862}
863
864/**
851 @param[out] ctx_size Variable to store size of context data values
852
853 @return An error code: 0 - success, otherwise - failure
854
855 @ref User
856**/
857int CeedQFunctionContextGetContextSize(CeedQFunctionContext ctx, size_t *ctx_size) {
858 *ctx_size = ctx->ctx_size;
859 return CEED_ERROR_SUCCESS;
860}
861
862/**
865 @brief View a CeedQFunctionContext
863 @brief View a `CeedQFunctionContext`
866
864
867 @param[in] ctx CeedQFunctionContext to view
865 @param[in] ctx `CeedQFunctionContext` to view
868 @param[in] stream Filestream to write to
869
870 @return An error code: 0 - success, otherwise - failure
871
872 @ref User
873**/
874int CeedQFunctionContextView(CeedQFunctionContext ctx, FILE *stream) {
875 fprintf(stream, "CeedQFunctionContext\n");
876 fprintf(stream, " Context Data Size: %ld\n", ctx->ctx_size);
877 for (CeedInt i = 0; i < ctx->num_fields; i++) {
878 // LCOV_EXCL_START
879 fprintf(stream, " Labeled %s field: %s\n", CeedContextFieldTypes[ctx->field_labels[i]->type], ctx->field_labels[i]->name);
880 // LCOV_EXCL_STOP
881 }
882 return CEED_ERROR_SUCCESS;
883}
884
885/**
866 @param[in] stream Filestream to write to
867
868 @return An error code: 0 - success, otherwise - failure
869
870 @ref User
871**/
872int CeedQFunctionContextView(CeedQFunctionContext ctx, FILE *stream) {
873 fprintf(stream, "CeedQFunctionContext\n");
874 fprintf(stream, " Context Data Size: %ld\n", ctx->ctx_size);
875 for (CeedInt i = 0; i < ctx->num_fields; i++) {
876 // LCOV_EXCL_START
877 fprintf(stream, " Labeled %s field: %s\n", CeedContextFieldTypes[ctx->field_labels[i]->type], ctx->field_labels[i]->name);
878 // LCOV_EXCL_STOP
879 }
880 return CEED_ERROR_SUCCESS;
881}
882
883/**
886 @brief Set additional destroy routine for CeedQFunctionContext user data
884 @brief Set additional destroy routine for `CeedQFunctionContext` user data
887
885
888 @param[in,out] ctx CeedQFunctionContext to set user destroy function
886 @param[in,out] ctx `CeedQFunctionContext` to set user destroy function
889 @param[in] f_mem_type Memory type to use when passing data into `f`
890 @param[in] f Additional routine to use to destroy user data
891
892 @return An error code: 0 - success, otherwise - failure
893
894 @ref User
895**/
896int CeedQFunctionContextSetDataDestroy(CeedQFunctionContext ctx, CeedMemType f_mem_type, CeedQFunctionContextDataDestroyUser f) {
897 CeedCheck(f, ctx->ceed, 1, "Must provide valid callback function for destroying user data");
898 ctx->data_destroy_mem_type = f_mem_type;
899 ctx->data_destroy_function = f;
900 return CEED_ERROR_SUCCESS;
901}
902
903/**
887 @param[in] f_mem_type Memory type to use when passing data into `f`
888 @param[in] f Additional routine to use to destroy user data
889
890 @return An error code: 0 - success, otherwise - failure
891
892 @ref User
893**/
894int CeedQFunctionContextSetDataDestroy(CeedQFunctionContext ctx, CeedMemType f_mem_type, CeedQFunctionContextDataDestroyUser f) {
895 CeedCheck(f, ctx->ceed, 1, "Must provide valid callback function for destroying user data");
896 ctx->data_destroy_mem_type = f_mem_type;
897 ctx->data_destroy_function = f;
898 return CEED_ERROR_SUCCESS;
899}
900
901/**
904 @brief Destroy a CeedQFunctionContext
902 @brief Destroy a `CeedQFunctionContext`
905
903
906 @param[in,out] ctx CeedQFunctionContext to destroy
904 @param[in,out] ctx `CeedQFunctionContext` to destroy
907
908 @return An error code: 0 - success, otherwise - failure
909
910 @ref User
911**/
912int CeedQFunctionContextDestroy(CeedQFunctionContext *ctx) {
913 if (!*ctx || --(*ctx)->ref_count > 0) {
914 *ctx = NULL;

--- 18 unchanged lines hidden ---
905
906 @return An error code: 0 - success, otherwise - failure
907
908 @ref User
909**/
910int CeedQFunctionContextDestroy(CeedQFunctionContext *ctx) {
911 if (!*ctx || --(*ctx)->ref_count > 0) {
912 *ctx = NULL;

--- 18 unchanged lines hidden ---