xref: /libCEED/rust/libceed-sys/c-src/gallery/identity/ceed-identity.c (revision ca94c3ddc8f82b7d93a79f9e4812e99b8be840ff)
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 
849aac155SJeremy L Thompson #include <ceed.h>
9ec3da8bcSJed Brown #include <ceed/backend.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 /**
15*ca94c3ddSJeremy L Thompson   @brief Set fields identity `CeedQFunction` 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";
206574a04fSJeremy L Thompson   CeedCheck(!strcmp(name, requested), ceed, CEED_ERROR_UNSUPPORTED, "QFunction '%s' does not match requested name: %s", name, requested);
210219ea01SJeremy L Thompson 
22ea61e9acSJeremy L Thompson   // QFunction fields 'input' and 'output' with requested emodes added by the library rather than being added here
230219ea01SJeremy L Thompson 
242b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionSetUserFlopsEstimate(qf, 0));
256e15d496SJeremy L Thompson 
26547dbd6fSJeremy L Thompson   // Context data
27547dbd6fSJeremy L Thompson   CeedQFunctionContext ctx;
28547dbd6fSJeremy L Thompson   IdentityCtx          ctx_data = {.size = 1};
292b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionContextCreate(ceed, &ctx));
302b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionContextSetData(ctx, CEED_MEM_HOST, CEED_COPY_VALUES, sizeof(ctx_data), (void *)&ctx_data));
312b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionContextRegisterInt32(ctx, "size", offsetof(IdentityCtx, size), 1, "field size of identity QFunction"));
322b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionSetContext(qf, ctx));
332b730f8bSJeremy L Thompson   CeedCall(CeedQFunctionContextDestroy(&ctx));
34547dbd6fSJeremy L Thompson 
35e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
360219ea01SJeremy L Thompson }
370219ea01SJeremy L Thompson 
380219ea01SJeremy L Thompson /**
39*ca94c3ddSJeremy L Thompson   @brief Register identity `CeedQFunction` that copies inputs directly into outputs
400219ea01SJeremy L Thompson **/
411d013790SJed Brown CEED_INTERN int CeedQFunctionRegister_Identity(void) {
422b730f8bSJeremy L Thompson   return CeedQFunctionRegister("Identity", Identity_loc, 1, Identity, CeedQFunctionInit_Identity);
430219ea01SJeremy L Thompson }
44