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/ceed.h> 9 #include <ceed/backend.h> 10 #include <stddef.h> 11 #include <string.h> 12 #include "ceed-identity.h" 13 14 /** 15 @brief Set fields identity QFunction that copies inputs directly into outputs 16 **/ 17 static int CeedQFunctionInit_Identity(Ceed ceed, const char *requested, 18 CeedQFunction qf) { 19 int ierr; 20 21 // Check QFunction name 22 const char *name = "Identity"; 23 if (strcmp(name, requested)) 24 // LCOV_EXCL_START 25 return CeedError(ceed, CEED_ERROR_UNSUPPORTED, 26 "QFunction '%s' does not match requested name: %s", 27 name, requested); 28 // LCOV_EXCL_STOP 29 30 // QFunction fields 'input' and 'output' with requested emodes added 31 // by the library rather than being added here 32 33 // Context data 34 CeedQFunctionContext ctx; 35 IdentityCtx ctx_data = {.size = 1}; 36 ierr = CeedQFunctionContextCreate(ceed, &ctx); CeedChk(ierr); 37 ierr = CeedQFunctionContextSetData(ctx, CEED_MEM_HOST, CEED_COPY_VALUES, 38 sizeof(ctx_data), (void *)&ctx_data); 39 CeedChk(ierr); 40 ierr = CeedQFunctionContextRegisterInt32(ctx, "size", 41 offsetof(IdentityCtx, size), 1, "field size of identity QFunction"); 42 CeedChk(ierr); 43 ierr = CeedQFunctionSetContext(qf, ctx); CeedChk(ierr); 44 ierr = CeedQFunctionContextDestroy(&ctx); CeedChk(ierr); 45 46 return CEED_ERROR_SUCCESS; 47 } 48 49 /** 50 @brief Register identity QFunction that copies inputs directly into outputs 51 **/ 52 CEED_INTERN int CeedQFunctionRegister_Identity(void) { 53 return CeedQFunctionRegister("Identity", Identity_loc, 1, Identity, 54 CeedQFunctionInit_Identity); 55 } 56