xref: /libCEED/rust/libceed-sys/c-src/gallery/identity/ceed-identity.c (revision 85c7f5ed8e46d9c675b01a6417ecbe2db9ae7de0)
1 // Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC.
2 // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
3 // All Rights reserved. See files LICENSE and NOTICE for details.
4 //
5 // This file is part of CEED, a collection of benchmarks, miniapps, software
6 // libraries and APIs for efficient high-order finite element and spectral
7 // element discretizations for exascale applications. For more information and
8 // source code availability see http://github.com/ceed.
9 //
10 // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
11 // a collaborative effort of two U.S. Department of Energy organizations (Office
12 // of Science and the National Nuclear Security Administration) responsible for
13 // the planning and preparation of a capable exascale ecosystem, including
14 // software, applications, hardware, advanced system engineering and early
15 // testbed platforms, in support of the nation's exascale computing imperative.
16 
17 #include <ceed/ceed.h>
18 #include <ceed/backend.h>
19 #include <stddef.h>
20 #include <string.h>
21 #include "ceed-identity.h"
22 
23 /**
24   @brief Set fields identity QFunction that copies inputs directly into outputs
25 **/
26 static int CeedQFunctionInit_Identity(Ceed ceed, const char *requested,
27                                       CeedQFunction qf) {
28   int ierr;
29 
30   // Check QFunction name
31   const char *name = "Identity";
32   if (strcmp(name, requested))
33     // LCOV_EXCL_START
34     return CeedError(ceed, CEED_ERROR_UNSUPPORTED,
35                      "QFunction '%s' does not match requested name: %s",
36                      name, requested);
37   // LCOV_EXCL_STOP
38 
39   // QFunction fields 'input' and 'output' with requested emodes added
40   //   by the library rather than being added here
41 
42   // Context data
43   CeedQFunctionContext ctx;
44   IdentityCtx ctx_data = {.size = 1};
45   ierr = CeedQFunctionContextCreate(ceed, &ctx); CeedChk(ierr);
46   ierr = CeedQFunctionContextSetData(ctx, CEED_MEM_HOST, CEED_COPY_VALUES,
47                                      sizeof(ctx_data), (void *)&ctx_data);
48   CeedChk(ierr);
49   ierr = CeedQFunctionContextRegisterInt32(ctx, "size", offsetof(IdentityCtx,
50          size), "field size of identity QFunction"); CeedChk(ierr);
51   ierr = CeedQFunctionSetContext(qf, ctx); CeedChk(ierr);
52   ierr = CeedQFunctionContextDestroy(&ctx); CeedChk(ierr);
53 
54   return CEED_ERROR_SUCCESS;
55 }
56 
57 /**
58   @brief Register identity QFunction that copies inputs directly into outputs
59 **/
60 CEED_INTERN int CeedQFunctionRegister_Identity(void) {
61   return CeedQFunctionRegister("Identity", Identity_loc, 1, Identity,
62                                CeedQFunctionInit_Identity);
63 }
64