xref: /libCEED/rust/libceed-sys/c-src/gallery/identity/ceed-identity.c (revision 547dbd6f5071ad3a6569362aeaf8c427ad429b62)
10219ea01SJeremy L Thompson // Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC.
20219ea01SJeremy L Thompson // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
30219ea01SJeremy L Thompson // All Rights reserved. See files LICENSE and NOTICE for details.
40219ea01SJeremy L Thompson //
50219ea01SJeremy L Thompson // This file is part of CEED, a collection of benchmarks, miniapps, software
60219ea01SJeremy L Thompson // libraries and APIs for efficient high-order finite element and spectral
70219ea01SJeremy L Thompson // element discretizations for exascale applications. For more information and
80219ea01SJeremy L Thompson // source code availability see http://github.com/ceed.
90219ea01SJeremy L Thompson //
100219ea01SJeremy L Thompson // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
110219ea01SJeremy L Thompson // a collaborative effort of two U.S. Department of Energy organizations (Office
120219ea01SJeremy L Thompson // of Science and the National Nuclear Security Administration) responsible for
130219ea01SJeremy L Thompson // the planning and preparation of a capable exascale ecosystem, including
140219ea01SJeremy L Thompson // software, applications, hardware, advanced system engineering and early
150219ea01SJeremy L Thompson // testbed platforms, in support of the nation's exascale computing imperative.
160219ea01SJeremy L Thompson 
17ec3da8bcSJed Brown #include <ceed/ceed.h>
18ec3da8bcSJed Brown #include <ceed/backend.h>
19*547dbd6fSJeremy L Thompson #include <stddef.h>
200219ea01SJeremy L Thompson #include <string.h>
210219ea01SJeremy L Thompson #include "ceed-identity.h"
220219ea01SJeremy L Thompson 
230219ea01SJeremy L Thompson /**
240219ea01SJeremy L Thompson   @brief Set fields identity QFunction that copies inputs directly into outputs
250219ea01SJeremy L Thompson **/
260219ea01SJeremy L Thompson static int CeedQFunctionInit_Identity(Ceed ceed, const char *requested,
270219ea01SJeremy L Thompson                                       CeedQFunction qf) {
28*547dbd6fSJeremy L Thompson   int ierr;
29*547dbd6fSJeremy L Thompson 
300219ea01SJeremy L Thompson   // Check QFunction name
310219ea01SJeremy L Thompson   const char *name = "Identity";
320219ea01SJeremy L Thompson   if (strcmp(name, requested))
33f0d2f928Sjeremylt     // LCOV_EXCL_START
34e15f9bd0SJeremy L Thompson     return CeedError(ceed, CEED_ERROR_UNSUPPORTED,
35e15f9bd0SJeremy L Thompson                      "QFunction '%s' does not match requested name: %s",
360219ea01SJeremy L Thompson                      name, requested);
37f0d2f928Sjeremylt   // LCOV_EXCL_STOP
380219ea01SJeremy L Thompson 
3960f77c51Sjeremylt   // QFunction fields 'input' and 'output' with requested emodes added
4060f77c51Sjeremylt   //   by the library rather than being added here
410219ea01SJeremy L Thompson 
42*547dbd6fSJeremy L Thompson   // Context data
43*547dbd6fSJeremy L Thompson   CeedQFunctionContext ctx;
44*547dbd6fSJeremy L Thompson   IdentityCtx ctx_data = {.size = 1};
45*547dbd6fSJeremy L Thompson   ierr = CeedQFunctionContextCreate(ceed, &ctx); CeedChk(ierr);
46*547dbd6fSJeremy L Thompson   ierr = CeedQFunctionContextSetData(ctx, CEED_MEM_HOST, CEED_COPY_VALUES,
47*547dbd6fSJeremy L Thompson                                      sizeof(ctx_data), (void *)&ctx_data);
48*547dbd6fSJeremy L Thompson   CeedChk(ierr);
49*547dbd6fSJeremy L Thompson   ierr = CeedQFunctionContextRegisterInt32(ctx, "size", offsetof(IdentityCtx,
50*547dbd6fSJeremy L Thompson          size), "field size of identity QFunction"); CeedChk(ierr);
51*547dbd6fSJeremy L Thompson   ierr = CeedQFunctionSetContext(qf, ctx); CeedChk(ierr);
52*547dbd6fSJeremy L Thompson   ierr = CeedQFunctionContextDestroy(&ctx); CeedChk(ierr);
53*547dbd6fSJeremy L Thompson 
54e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
550219ea01SJeremy L Thompson }
560219ea01SJeremy L Thompson 
570219ea01SJeremy L Thompson /**
580219ea01SJeremy L Thompson   @brief Register identity QFunction that copies inputs directly into outputs
590219ea01SJeremy L Thompson **/
601d013790SJed Brown CEED_INTERN int CeedQFunctionRegister_Identity(void) {
611d013790SJed Brown   return CeedQFunctionRegister("Identity", Identity_loc, 1, Identity,
620219ea01SJeremy L Thompson                                CeedQFunctionInit_Identity);
630219ea01SJeremy L Thompson }
64