xref: /libCEED/gallery/poisson/ceed-poisson2dapply.c (revision 6e15d496119073f7bc35f61df7ac100e9376600e)
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/ceed.h>
9 #include <ceed/backend.h>
10 #include <string.h>
11 #include "ceed-poisson2dapply.h"
12 
13 /**
14   @brief Set fields for Ceed QFunction applying the 2D Poisson operator
15 **/
16 static int CeedQFunctionInit_Poisson2DApply(Ceed ceed, const char *requested,
17     CeedQFunction qf) {
18   int ierr;
19 
20   // Check QFunction name
21   const char *name = "Poisson2DApply";
22   if (strcmp(name, requested))
23     // LCOV_EXCL_START
24     return CeedError(ceed, CEED_ERROR_UNSUPPORTED,
25                      "QFunction '%s' does not match requested name: %s",
26                      name, requested);
27   // LCOV_EXCL_STOP
28 
29   // Add QFunction fields
30   const CeedInt dim = 2;
31   ierr = CeedQFunctionAddInput(qf, "du", dim, CEED_EVAL_GRAD); CeedChk(ierr);
32   ierr = CeedQFunctionAddInput(qf, "qdata", dim*(dim+1)/2, CEED_EVAL_NONE);
33   CeedChk(ierr);
34   ierr = CeedQFunctionAddOutput(qf, "dv", dim, CEED_EVAL_GRAD); CeedChk(ierr);
35 
36   ierr = CeedQFunctionSetUserFlopsEstimate(qf, 6); CeedChk(ierr);
37 
38   return CEED_ERROR_SUCCESS;
39 }
40 
41 /**
42   @brief Register Ceed QFunction for applying the 2D Poisson operator
43 **/
44 CEED_INTERN int CeedQFunctionRegister_Poisson2DApply(void) {
45   return CeedQFunctionRegister("Poisson2DApply", Poisson2DApply_loc, 1,
46                                Poisson2DApply, CeedQFunctionInit_Poisson2DApply);
47 }
48