xref: /libCEED/examples/petsc/qfunctions/bps/common.h (revision 6c88e6a2c47a72cd5c3efacc26a364b9cb7d40db)
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,
18                       const CeedScalar *const *in, CeedScalar *const *out) {
19   const CeedScalar *u = in[0], *target = in[1], *q_data = in[2];
20   CeedScalar *error = out[0];
21   for (CeedInt i=0; i<Q; i++) {
22     error[i] = (u[i] - target[i])*q_data[i]*q_data[i];
23   }
24   return 0;
25 }
26 
27 // -----------------------------------------------------------------------------
28 CEED_QFUNCTION(Error3)(void *ctx, CeedInt Q,
29                        const CeedScalar *const *in, CeedScalar *const *out) {
30   const CeedScalar *u = in[0], *target = in[1], *q_data = in[2];
31   CeedScalar *error = out[0];
32   for (CeedInt i=0; i<Q; i++) {
33     error[i+0*Q] = (u[i+0*Q] - target[i+0*Q])*q_data[i]*q_data[i];
34     error[i+1*Q] = (u[i+1*Q] - target[i+1*Q])*q_data[i]*q_data[i];
35     error[i+2*Q] = (u[i+2*Q] - target[i+2*Q])*q_data[i]*q_data[i];
36   }
37   return 0;
38 }
39 // -----------------------------------------------------------------------------
40 
41 #endif // common_h
42