xref: /libCEED/rust/libceed-sys/c-src/gallery/identity/ceed-identity.c (revision ea61e9ac44808524e4667c1525a05976f536c19c)
13d8e8822SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
30219ea01SJeremy L Thompson //
43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
50219ea01SJeremy L Thompson //
63d8e8822SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
70219ea01SJeremy L Thompson 
8ec3da8bcSJed Brown #include <ceed/backend.h>
92b730f8bSJeremy L Thompson #include <ceed/ceed.h>
102b730f8bSJeremy L Thompson #include <ceed/jit-source/gallery/ceed-identity.h>
11547dbd6fSJeremy L Thompson #include <stddef.h>
120219ea01SJeremy L Thompson #include <string.h>
130219ea01SJeremy L Thompson 
140219ea01SJeremy L Thompson /**
150219ea01SJeremy L Thompson   @brief Set fields identity QFunction that copies inputs directly into outputs
160219ea01SJeremy L Thompson **/
172b730f8bSJeremy L Thompson static int CeedQFunctionInit_Identity(Ceed ceed, const char *requested, CeedQFunction qf) {
180219ea01SJeremy L Thompson   // Check QFunction name
190219ea01SJeremy L Thompson   const char *name = "Identity";
202b730f8bSJeremy L Thompson   if (strcmp(name, requested)) {
21f0d2f928Sjeremylt     // LCOV_EXCL_START
222b730f8bSJeremy L Thompson     return CeedError(ceed, CEED_ERROR_UNSUPPORTED, "QFunction '%s' does not match requested name: %s", name, requested);
23f0d2f928Sjeremylt     // LCOV_EXCL_STOP
242b730f8bSJeremy L Thompson   }
250219ea01SJeremy L Thompson 
26*ea61e9acSJeremy L Thompson   // QFunction fields 'input' and 'output' with requested emodes added by the library rather than being added here
270219ea01SJeremy L Thompson 
282b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionSetUserFlopsEstimate(qf, 0));
296e15d496SJeremy L Thompson 
30547dbd6fSJeremy L Thompson   // Context data
31547dbd6fSJeremy L Thompson   CeedQFunctionContext ctx;
32547dbd6fSJeremy L Thompson   IdentityCtx          ctx_data = {.size = 1};
332b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionContextCreate(ceed, &ctx));
342b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionContextSetData(ctx, CEED_MEM_HOST, CEED_COPY_VALUES, sizeof(ctx_data), (void *)&ctx_data));
352b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionContextRegisterInt32(ctx, "size", offsetof(IdentityCtx, size), 1, "field size of identity QFunction"));
362b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionSetContext(qf, ctx));
372b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionContextDestroy(&ctx));
38547dbd6fSJeremy L Thompson 
39e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
400219ea01SJeremy L Thompson }
410219ea01SJeremy L Thompson 
420219ea01SJeremy L Thompson /**
430219ea01SJeremy L Thompson   @brief Register identity QFunction that copies inputs directly into outputs
440219ea01SJeremy L Thompson **/
451d013790SJed Brown CEED_INTERN int CeedQFunctionRegister_Identity(void) {
462b730f8bSJeremy L Thompson   return CeedQFunctionRegister("Identity", Identity_loc, 1, Identity, CeedQFunctionInit_Identity);
470219ea01SJeremy L Thompson }
48