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 ierr = CeedQFunctionSetUserFlopsEstimate(qf, 0); CeedChk(ierr); 34 35 // Context data 36 CeedQFunctionContext ctx; 37 IdentityCtx ctx_data = {.size = 1}; 38 ierr = CeedQFunctionContextCreate(ceed, &ctx); CeedChk(ierr); 39 ierr = CeedQFunctionContextSetData(ctx, CEED_MEM_HOST, CEED_COPY_VALUES, 40 sizeof(ctx_data), (void *)&ctx_data); 41 CeedChk(ierr); 42 ierr = CeedQFunctionContextRegisterInt32(ctx, "size", 43 offsetof(IdentityCtx, size), 1, "field size of identity QFunction"); 44 CeedChk(ierr); 45 ierr = CeedQFunctionSetContext(qf, ctx); CeedChk(ierr); 46 ierr = CeedQFunctionContextDestroy(&ctx); CeedChk(ierr); 47 48 return CEED_ERROR_SUCCESS; 49 } 50 51 /** 52 @brief Register identity QFunction that copies inputs directly into outputs 53 **/ 54 CEED_INTERN int CeedQFunctionRegister_Identity(void) { 55 return CeedQFunctionRegister("Identity", Identity_loc, 1, Identity, 56 CeedQFunctionInit_Identity); 57 } 58