1*3d8e8822SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. 2*3d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 30219ea01SJeremy L Thompson // 4*3d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause 50219ea01SJeremy L Thompson // 6*3d8e8822SJeremy L Thompson // This file is part of CEED: http://github.com/ceed 70219ea01SJeremy L Thompson 8ec3da8bcSJed Brown #include <ceed/ceed.h> 9ec3da8bcSJed Brown #include <ceed/backend.h> 10547dbd6fSJeremy L Thompson #include <stddef.h> 110219ea01SJeremy L Thompson #include <string.h> 120219ea01SJeremy L Thompson #include "ceed-identity.h" 130219ea01SJeremy L Thompson 140219ea01SJeremy L Thompson /** 150219ea01SJeremy L Thompson @brief Set fields identity QFunction that copies inputs directly into outputs 160219ea01SJeremy L Thompson **/ 170219ea01SJeremy L Thompson static int CeedQFunctionInit_Identity(Ceed ceed, const char *requested, 180219ea01SJeremy L Thompson CeedQFunction qf) { 19547dbd6fSJeremy L Thompson int ierr; 20547dbd6fSJeremy L Thompson 210219ea01SJeremy L Thompson // Check QFunction name 220219ea01SJeremy L Thompson const char *name = "Identity"; 230219ea01SJeremy L Thompson if (strcmp(name, requested)) 24f0d2f928Sjeremylt // LCOV_EXCL_START 25e15f9bd0SJeremy L Thompson return CeedError(ceed, CEED_ERROR_UNSUPPORTED, 26e15f9bd0SJeremy L Thompson "QFunction '%s' does not match requested name: %s", 270219ea01SJeremy L Thompson name, requested); 28f0d2f928Sjeremylt // LCOV_EXCL_STOP 290219ea01SJeremy L Thompson 3060f77c51Sjeremylt // QFunction fields 'input' and 'output' with requested emodes added 3160f77c51Sjeremylt // by the library rather than being added here 320219ea01SJeremy L Thompson 33547dbd6fSJeremy L Thompson // Context data 34547dbd6fSJeremy L Thompson CeedQFunctionContext ctx; 35547dbd6fSJeremy L Thompson IdentityCtx ctx_data = {.size = 1}; 36547dbd6fSJeremy L Thompson ierr = CeedQFunctionContextCreate(ceed, &ctx); CeedChk(ierr); 37547dbd6fSJeremy L Thompson ierr = CeedQFunctionContextSetData(ctx, CEED_MEM_HOST, CEED_COPY_VALUES, 38547dbd6fSJeremy L Thompson sizeof(ctx_data), (void *)&ctx_data); 39547dbd6fSJeremy L Thompson CeedChk(ierr); 407bfe0f0eSJeremy L Thompson ierr = CeedQFunctionContextRegisterInt32(ctx, "size", 417bfe0f0eSJeremy L Thompson offsetof(IdentityCtx, size), 1, "field size of identity QFunction"); 427bfe0f0eSJeremy L Thompson CeedChk(ierr); 43547dbd6fSJeremy L Thompson ierr = CeedQFunctionSetContext(qf, ctx); CeedChk(ierr); 44547dbd6fSJeremy L Thompson ierr = CeedQFunctionContextDestroy(&ctx); CeedChk(ierr); 45547dbd6fSJeremy L Thompson 46e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 470219ea01SJeremy L Thompson } 480219ea01SJeremy L Thompson 490219ea01SJeremy L Thompson /** 500219ea01SJeremy L Thompson @brief Register identity QFunction that copies inputs directly into outputs 510219ea01SJeremy L Thompson **/ 521d013790SJed Brown CEED_INTERN int CeedQFunctionRegister_Identity(void) { 531d013790SJed Brown return CeedQFunctionRegister("Identity", Identity_loc, 1, Identity, 540219ea01SJeremy L Thompson CeedQFunctionInit_Identity); 550219ea01SJeremy L Thompson } 56