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