| ceed-qfunctioncontext.c (78a97f55f6a0b493f351ed551b9ecfb9c33a05ae) | ceed-qfunctioncontext.c (2788fa279822b86b73c7d9989c768f3b4c4cdffb) |
|---|---|
| 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> --- 245 unchanged lines hidden (view full) --- 254} 255 256/** 257 @brief Set QFunctionContext field 258 259 @param[in,out] ctx CeedQFunctionContext 260 @param[in] field_label Label of field to set 261 @param[in] field_type Type of field to set | 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> --- 245 unchanged lines hidden (view full) --- 254} 255 256/** 257 @brief Set QFunctionContext field 258 259 @param[in,out] ctx CeedQFunctionContext 260 @param[in] field_label Label of field to set 261 @param[in] field_type Type of field to set |
| 262 @param[in] value Value to set | 262 @param[in] values Value to set |
| 263 264 @return An error code: 0 - success, otherwise - failure 265 266 @ref Backend 267**/ | 263 264 @return An error code: 0 - success, otherwise - failure 265 266 @ref Backend 267**/ |
| 268int CeedQFunctionContextSetGeneric(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, CeedContextFieldType field_type, void *value) { | 268int CeedQFunctionContextSetGeneric(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, CeedContextFieldType field_type, void *values) { |
| 269 // Check field type 270 if (field_label->type != field_type) { 271 // LCOV_EXCL_START 272 return CeedError(ctx->ceed, CEED_ERROR_UNSUPPORTED, "QFunctionContext field with name \"%s\" registered as %s, not registered as %s", 273 field_label->name, CeedContextFieldTypes[field_label->type], CeedContextFieldTypes[field_type]); 274 // LCOV_EXCL_STOP 275 } 276 277 char *data; 278 CeedCall(CeedQFunctionContextGetData(ctx, CEED_MEM_HOST, &data)); | 269 // Check field type 270 if (field_label->type != field_type) { 271 // LCOV_EXCL_START 272 return CeedError(ctx->ceed, CEED_ERROR_UNSUPPORTED, "QFunctionContext field with name \"%s\" registered as %s, not registered as %s", 273 field_label->name, CeedContextFieldTypes[field_label->type], CeedContextFieldTypes[field_type]); 274 // LCOV_EXCL_STOP 275 } 276 277 char *data; 278 CeedCall(CeedQFunctionContextGetData(ctx, CEED_MEM_HOST, &data)); |
| 279 memcpy(&data[field_label->offset], value, field_label->size); | 279 memcpy(&data[field_label->offset], values, field_label->size); |
| 280 CeedCall(CeedQFunctionContextRestoreData(ctx, &data)); 281 282 return CEED_ERROR_SUCCESS; 283} 284 285/** | 280 CeedCall(CeedQFunctionContextRestoreData(ctx, &data)); 281 282 return CEED_ERROR_SUCCESS; 283} 284 285/** |
| 286 @brief Get QFunctionContext field data, read-only 287 288 @param[in] ctx CeedQFunctionContext 289 @param[in] field_label Label of field to read 290 @param[in] field_type Type of field to read 291 @param[out] num_values Number of values in the field label 292 @param[out] values Pointer to context values 293 294 @return An error code: 0 - success, otherwise - failure 295 296 @ref Backend 297**/ 298int CeedQFunctionContextGetGenericRead(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, CeedContextFieldType field_type, 299 size_t *num_values, void *values) { 300 // Check field type 301 if (field_label->type != field_type) { 302 // LCOV_EXCL_START 303 return CeedError(ctx->ceed, CEED_ERROR_UNSUPPORTED, "QFunctionContext field with name \"%s\" registered as %s, not registered as %s", 304 field_label->name, CeedContextFieldTypes[field_label->type], CeedContextFieldTypes[field_type]); 305 // LCOV_EXCL_STOP 306 } 307 308 char *data; 309 CeedCall(CeedQFunctionContextGetDataRead(ctx, CEED_MEM_HOST, &data)); 310 *(void **)values = &data[field_label->offset]; 311 switch (field_type) { 312 case CEED_CONTEXT_FIELD_INT32: 313 *num_values = field_label->size / sizeof(int); 314 break; 315 case CEED_CONTEXT_FIELD_DOUBLE: 316 *num_values = field_label->size / sizeof(double); 317 break; 318 } 319 320 return CEED_ERROR_SUCCESS; 321} 322 323/** 324 @brief Restore QFunctionContext field data, read-only 325 326 @param[in] ctx CeedQFunctionContext 327 @param[in] field_label Label of field to restore 328 @param[in] field_type Type of field to restore 329 @param[out] values Pointer to context values 330 331 @return An error code: 0 - success, otherwise - failure 332 333 @ref Backend 334**/ 335int CeedQFunctionContextRestoreGenericRead(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, CeedContextFieldType field_type, 336 void *values) { 337 // Check field type 338 if (field_label->type != field_type) { 339 // LCOV_EXCL_START 340 return CeedError(ctx->ceed, CEED_ERROR_UNSUPPORTED, "QFunctionContext field with name \"%s\" registered as %s, not registered as %s", 341 field_label->name, CeedContextFieldTypes[field_label->type], CeedContextFieldTypes[field_type]); 342 // LCOV_EXCL_STOP 343 } 344 345 CeedCall(CeedQFunctionContextRestoreDataRead(ctx, values)); 346 347 return CEED_ERROR_SUCCESS; 348} 349 350/** |
|
| 286 @brief Set QFunctionContext field holding a double precision value 287 288 @param[in,out] ctx CeedQFunctionContext | 351 @brief Set QFunctionContext field holding a double precision value 352 353 @param[in,out] ctx CeedQFunctionContext |
| 289 @param[in] field_label Label for field to register | 354 @param[in] field_label Label for field to set |
| 290 @param[in] values Values to set 291 292 @return An error code: 0 - success, otherwise - failure 293 294 @ref Backend 295**/ 296int CeedQFunctionContextSetDouble(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, double *values) { 297 if (!field_label) { 298 // LCOV_EXCL_START 299 return CeedError(ctx->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label"); 300 // LCOV_EXCL_STOP 301 } 302 303 CeedCall(CeedQFunctionContextSetGeneric(ctx, field_label, CEED_CONTEXT_FIELD_DOUBLE, values)); 304 305 return CEED_ERROR_SUCCESS; 306} 307 308/** | 355 @param[in] values Values to set 356 357 @return An error code: 0 - success, otherwise - failure 358 359 @ref Backend 360**/ 361int CeedQFunctionContextSetDouble(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, double *values) { 362 if (!field_label) { 363 // LCOV_EXCL_START 364 return CeedError(ctx->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label"); 365 // LCOV_EXCL_STOP 366 } 367 368 CeedCall(CeedQFunctionContextSetGeneric(ctx, field_label, CEED_CONTEXT_FIELD_DOUBLE, values)); 369 370 return CEED_ERROR_SUCCESS; 371} 372 373/** |
| 374 @brief Get QFunctionContext field holding a double precision value, read-only 375 376 @param[in] ctx CeedQFunctionContext 377 @param[in] field_label Label for field to get 378 @param[out] num_values Number of values in the field label 379 @param[out] values Pointer to context values 380 381 @return An error code: 0 - success, otherwise - failure 382 383 @ref Backend 384**/ 385int CeedQFunctionContextGetDoubleRead(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, size_t *num_values, const double **values) { 386 if (!field_label) { 387 // LCOV_EXCL_START 388 return CeedError(ctx->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label"); 389 // LCOV_EXCL_STOP 390 } 391 392 CeedCall(CeedQFunctionContextGetGenericRead(ctx, field_label, CEED_CONTEXT_FIELD_DOUBLE, num_values, values)); 393 394 return CEED_ERROR_SUCCESS; 395} 396 397/** 398 @brief Restore QFunctionContext field holding a double precision value, read-only 399 400 @param[in] ctx CeedQFunctionContext 401 @param[in] field_label Label for field to restore 402 @param[out] values Pointer to context values 403 404 @return An error code: 0 - success, otherwise - failure 405 406 @ref Backend 407**/ 408int CeedQFunctionContextRestoreDoubleRead(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, const double **values) { 409 if (!field_label) { 410 // LCOV_EXCL_START 411 return CeedError(ctx->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label"); 412 // LCOV_EXCL_STOP 413 } 414 415 CeedCall(CeedQFunctionContextRestoreGenericRead(ctx, field_label, CEED_CONTEXT_FIELD_DOUBLE, values)); 416 417 return CEED_ERROR_SUCCESS; 418} 419 420/** |
|
| 309 @brief Set QFunctionContext field holding an int32 value 310 311 @param[in,out] ctx CeedQFunctionContext | 421 @brief Set QFunctionContext field holding an int32 value 422 423 @param[in,out] ctx CeedQFunctionContext |
| 312 @param[in] field_label Label for field to register | 424 @param[in] field_label Label for field to set |
| 313 @param[in] values Values to set 314 315 @return An error code: 0 - success, otherwise - failure 316 317 @ref Backend 318**/ 319int CeedQFunctionContextSetInt32(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, int *values) { 320 if (!field_label) { 321 // LCOV_EXCL_START 322 return CeedError(ctx->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label"); 323 // LCOV_EXCL_STOP 324 } 325 326 CeedCall(CeedQFunctionContextSetGeneric(ctx, field_label, CEED_CONTEXT_FIELD_INT32, values)); 327 328 return CEED_ERROR_SUCCESS; 329} 330 331/** | 425 @param[in] values Values to set 426 427 @return An error code: 0 - success, otherwise - failure 428 429 @ref Backend 430**/ 431int CeedQFunctionContextSetInt32(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, int *values) { 432 if (!field_label) { 433 // LCOV_EXCL_START 434 return CeedError(ctx->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label"); 435 // LCOV_EXCL_STOP 436 } 437 438 CeedCall(CeedQFunctionContextSetGeneric(ctx, field_label, CEED_CONTEXT_FIELD_INT32, values)); 439 440 return CEED_ERROR_SUCCESS; 441} 442 443/** |
| 444 @brief Get QFunctionContext field holding a int32 value, read-only 445 446 @param[in] ctx CeedQFunctionContext 447 @param[in] field_label Label for field to get 448 @param[out] num_values Number of values in the field label 449 @param[out] values Pointer to context values 450 451 @return An error code: 0 - success, otherwise - failure 452 453 @ref Backend 454**/ 455int CeedQFunctionContextGetInt32Read(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, size_t *num_values, const int **values) { 456 if (!field_label) { 457 // LCOV_EXCL_START 458 return CeedError(ctx->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label"); 459 // LCOV_EXCL_STOP 460 } 461 462 CeedCall(CeedQFunctionContextGetGenericRead(ctx, field_label, CEED_CONTEXT_FIELD_INT32, num_values, values)); 463 464 return CEED_ERROR_SUCCESS; 465} 466 467/** 468 @brief Restore QFunctionContext field holding a int32 value, read-only 469 470 @param[in] ctx CeedQFunctionContext 471 @param[in] field_label Label for field to restore 472 @param[out] values Pointer to context values 473 474 @return An error code: 0 - success, otherwise - failure 475 476 @ref Backend 477**/ 478int CeedQFunctionContextRestoreInt32Read(CeedQFunctionContext ctx, CeedContextFieldLabel field_label, const int **values) { 479 if (!field_label) { 480 // LCOV_EXCL_START 481 return CeedError(ctx->ceed, CEED_ERROR_UNSUPPORTED, "Invalid field label"); 482 // LCOV_EXCL_STOP 483 } 484 485 CeedCall(CeedQFunctionContextRestoreGenericRead(ctx, field_label, CEED_CONTEXT_FIELD_INT32, values)); 486 487 return CEED_ERROR_SUCCESS; 488} 489 490/** |
|
| 332 @brief Get additional destroy routine for CeedQFunctionContext user data 333 334 @param[in] ctx CeedQFunctionContext to get user destroy function 335 @param[out] f_mem_type Memory type to use when passing data into `f` 336 @param[out] f Additional routine to use to destroy user data 337 338 @return An error code: 0 - success, otherwise - failure 339 --- 469 unchanged lines hidden --- | 491 @brief Get additional destroy routine for CeedQFunctionContext user data 492 493 @param[in] ctx CeedQFunctionContext to get user destroy function 494 @param[out] f_mem_type Memory type to use when passing data into `f` 495 @param[out] f Additional routine to use to destroy user data 496 497 @return An error code: 0 - success, otherwise - failure 498 --- 469 unchanged lines hidden --- |