xref: /libCEED/examples/petsc/qfunctions/bps/common.h (revision 8ec64e9ae9d5df169dba8c8ee61d8ec8907b8f80)
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 /// @file
9 /// libCEED QFunctions for BP examples using PETSc
10 
11 #ifndef common_h
12 #define common_h
13 
14 #include <ceed.h>
15 
16 // -----------------------------------------------------------------------------
17 CEED_QFUNCTION(Error)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
18   const CeedScalar *u = in[0], *target = in[1], *q_data = in[2];
19   CeedScalar       *error = out[0];
20   for (CeedInt i = 0; i < Q; i++) {
21     error[i] = (u[i] - target[i]) * (u[i] - target[i]) * q_data[i];
22   }
23   return 0;
24 }
25 
26 // -----------------------------------------------------------------------------
27 CEED_QFUNCTION(Error3)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
28   const CeedScalar *u = in[0], *target = in[1], *q_data = in[2];
29   CeedScalar       *error = out[0];
30   for (CeedInt i = 0; i < Q; i++) {
31     error[i + 0 * Q] = (u[i + 0 * Q] - target[i + 0 * Q]) * (u[i + 0 * Q] - target[i + 0 * Q]) * q_data[i];
32     error[i + 1 * Q] = (u[i + 1 * Q] - target[i + 1 * Q]) * (u[i + 1 * Q] - target[i + 1 * Q]) * q_data[i];
33     error[i + 2 * Q] = (u[i + 2 * Q] - target[i + 2 * Q]) * (u[i + 2 * Q] - target[i + 2 * Q]) * q_data[i];
34   }
35   return 0;
36 }
37 // -----------------------------------------------------------------------------
38 
39 #endif  // common_h
40